/** * Creates a new search field with a default prompt. */ public JXSearchField() { this(UIManagerExt.getString("SearchField.prompt")); }
/** * {@inheritDoc} */ @Override public void initialize() { super.initialize(); //must add resource bundle after adding component values UIManagerExt.addResourceBundle( "org.jdesktop.swingx.plaf.basic.resources.swingx"); }
/** * Returns a color from the defaults. If the value for {@code key} is not * a {@code Color}, {@code null} is returned. * * @param key * an {@code Object} specifying the color * @return the {@code Color} object * @throws NullPointerException * if {@code key} is {@code null} */ public static Color getColor(Object key) { return getColor(key, null); }
@Override protected void init(Shape point, Shape trajectory, Color b, Color h) { super.init(dim == null ? UIManagerExt.getShape("JXBusyLabel.pointShape") : getScaledDefaultPoint(dim.height), dim == null ? UIManagerExt.getShape("JXBusyLabel.trajectoryShape") : getScaledDefaultTrajectory(dim.height), UIManagerExt.getSafeColor("JXBusyLabel.baseColor", Color.LIGHT_GRAY), UIManagerExt.getSafeColor("JXBusyLabel.highlightColor", Color.BLACK)); } };
@Override protected void addBasicDefaults(LookAndFeelAddons addon, DefaultsList defaults) { super.addBasicDefaults(addon, defaults); Font font = UIManagerExt.getSafeFont("Label.font", new Font("Dialog", Font.PLAIN, 12)); font = font.deriveFont(Font.BOLD, 13f); defaults.add(JXTipOfTheDay.uiClassID, BasicTipOfTheDayUI.class.getName()); defaults.add("TipOfTheDay.font", UIManagerExt.getSafeFont("TextPane.font", new FontUIResource("Serif", Font.PLAIN, 12))); defaults.add("TipOfTheDay.tipFont", new FontUIResource(font)); defaults.add("TipOfTheDay.background", new ColorUIResource(Color.WHITE)); defaults.add("TipOfTheDay.icon", LookAndFeel.makeIcon(BasicTipOfTheDayUI.class, "resources/TipOfTheDay24.gif")); defaults.add("TipOfTheDay.border", new BorderUIResource( BorderFactory.createLineBorder(new Color(117, 117, 117)))); UIManagerExt.addResourceBundle( "org.jdesktop.swingx.plaf.basic.resources.TipOfTheDay"); }
monthView.setBackground(UIManagerExt.getColor("JXMonthView.background")); monthView.setForeground(UIManagerExt.getColor("JXMonthView.foreground")); monthView.setMonthStringBackground(UIManagerExt.getColor("JXMonthView.monthStringBackground")); monthView.setMonthStringForeground(UIManagerExt.getColor("JXMonthView.monthStringForeground")); monthView.setDaysOfTheWeekForeground(UIManagerExt.getColor("JXMonthView.daysOfTheWeekForeground")); monthView.setSelectionBackground(UIManagerExt.getColor("JXMonthView.selectedBackground")); monthView.setSelectionForeground(UIManagerExt.getColor("JXMonthView.selectedForeground")); monthView.setFlaggedDayForeground(UIManagerExt.getColor("JXMonthView.flaggedDayForeground")); monthView.setBoxPaddingX(UIManagerExt.getInt("JXMonthView.boxPaddingX")); monthView.setBoxPaddingY(UIManagerExt.getInt("JXMonthView.boxPaddingY"));
/** * test that the getInt doesn't choke on non-numbers */ @Test public void testGetIntLenientWithUnparseable() { String key = "badInt"; Locale locale = JComponent.getDefaultLocale(); String columnString = UIManagerExt.getString(key, locale); if (columnString == null) { LOG.info("cant run test - no resource found for key: " + key); return; } try { Integer.decode(columnString); LOG.info("cant run test - valid integer: " + columnString); } catch (Exception ex) { // must not bark UIManagerExt.getInt(key, locale); } } }
/** * test that the getBoolean doesn't choke on non-Booleans */ @Test public void testGetBooleanLenientWithUnparseable() { String key = "badBoolean"; Locale locale = JComponent.getDefaultLocale(); String columnString = UIManagerExt.getString(key, locale); if (columnString == null) { LOG.info("cant run test - no resource found for key: " + key); return; } UIManagerExt.getBoolean(key, locale); }
/** * Ensure that the {@code getSafeXXX} methods always return * {@code UIResource}. */ @Test public void testGetSafeMethodsReturnUIResource() { assertTrue(UIManagerExt.getSafeBorder("", BorderFactory .createEmptyBorder()) instanceof UIResource); assertTrue(UIManagerExt.getSafeColor("", Color.RED) instanceof UIResource); assertTrue(UIManagerExt.getSafeDimension("", new Dimension()) instanceof UIResource); assertTrue(UIManagerExt.getSafeFont("", new Font("Dialog", Font.BOLD, 12)) instanceof UIResource); assertTrue(UIManagerExt.getSafeIcon("", new ImageIcon()) instanceof UIResource); assertTrue(UIManagerExt.getSafeInsets("", new Insets(0, 0, 0, 0)) instanceof UIResource); }
protected void paintSeparator(Graphics2D g, JXStatusBar bar, int x, int y, int w, int h) { Color fg = UIManagerExt.getSafeColor("Separator.foreground", Color.BLACK); Color bg = UIManagerExt.getSafeColor("Separator.background", Color.WHITE); x += w / 2; g.setColor(fg); g.drawLine(x, y, x, h); g.setColor(bg); g.drawLine(x+1, y, x+1, h); }
/** * Returns an integer from the defaults. If the value for {@code key} is not * an {@code int}, {@code 0} is returned. * * @param key * an {@code Object} specifying the integer * @return the {@code int} * @throws NullPointerException * if {@code key} is {@code null} */ public static int getInt(Object key) { return getInt(key, null); }
@Override protected void addBasicDefaults(LookAndFeelAddons addon, DefaultsList defaults) { super.addBasicDefaults(addon, defaults); defaults.add(JXTitledPanel.uiClassID, "org.jdesktop.swingx.plaf.basic.BasicTitledPanelUI"); defaults.add("JXTitledPanel.titleFont", UIManagerExt.getSafeFont("Button.font", new FontUIResource("Dialog", Font.PLAIN, 12))); defaults.add("JXTitledPanel.titleForeground", new ColorUIResource(Color.WHITE)); defaults.add("JXTitledPanel.titlePainter", new PainterUIResource<JXTitledPanel>( new MattePainter( new GradientPaint(0, 0, Color.LIGHT_GRAY, 0, 1, Color.GRAY), true))); defaults.add("JXTitledPanel.captionInsets", new InsetsUIResource(4, 12, 4, 12)); defaults.add("JXTitledPanel.rightDecorationInsets", new InsetsUIResource(1,1,1,1)); defaults.add("JXTitledPanel.leftDecorationInsets", new InsetsUIResource(1,1,1,1)); }
/** * Returns an Boolean from the defaults. If the value for {@code key} is not * a {@code boolean}, {@code false} is returned. * * @param key * an {@code Object} specifying the Boolean * @return the {@code boolean} * @throws NullPointerException * if {@code key} is {@code null} */ public static boolean getBoolean(Object key) { return getBoolean(key, null); }
/** * {@inheritDoc} */ @Override public void uninitialize() { //must remove resource bundle before adding component values UIManagerExt.removeResourceBundle( "org.jdesktop.swingx.plaf.basic.resources.swingx"); super.uninitialize(); }
/** * Convenience method for setting a component's background painter property with a value from * the defaults. The painter is only set if the painter is {@code null} or an instance of * {@code UIResource}. * * @param c * component to set the painter on * @param painter * key specifying the painter * @throws NullPointerException * if the component or painter is {@code null} * @throws IllegalArgumentException * if the component does not contain the "backgroundPainter" property or the * property cannot be set */ public static void installBackgroundPainter(JComponent c, String painter) { Class<?> clazz = c.getClass(); try { Method getter = clazz.getMethod("getBackgroundPainter"); Method setter = clazz.getMethod("setBackgroundPainter", Painter.class); Painter<?> p = (Painter<?>) getter.invoke(c); if (p == null || p instanceof UIResource) { setter.invoke(c, UIManagerExt.getPainter(painter)); } } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalArgumentException("cannot set painter on " + c.getClass()); } }
@Override protected void addBasicDefaults(LookAndFeelAddons addon, DefaultsList defaults) { super.addBasicDefaults(addon, defaults); Font font = UIManagerExt.getSafeFont("Label.font", new Font("Dialog", Font.PLAIN, 12)); font = font.deriveFont(Font.BOLD, 13f); defaults.add(JXTipOfTheDay.uiClassID, BasicTipOfTheDayUI.class.getName()); defaults.add("TipOfTheDay.font", UIManagerExt.getSafeFont("TextPane.font", new FontUIResource("Serif", Font.PLAIN, 12))); defaults.add("TipOfTheDay.tipFont", new FontUIResource(font)); defaults.add("TipOfTheDay.background", new ColorUIResource(Color.WHITE)); defaults.add("TipOfTheDay.icon", LookAndFeel.makeIcon(BasicTipOfTheDayUI.class, "resources/TipOfTheDay24.gif")); defaults.add("TipOfTheDay.border", new BorderUIResource( BorderFactory.createLineBorder(new Color(117, 117, 117)))); UIManagerExt.addResourceBundle( "org.jdesktop.swingx.plaf.basic.resources.TipOfTheDay"); }
monthView.setBackground(UIManagerExt.getColor("JXMonthView.background")); monthView.setForeground(UIManagerExt.getColor("JXMonthView.foreground")); monthView.setMonthStringBackground(UIManagerExt.getColor("JXMonthView.monthStringBackground")); monthView.setMonthStringForeground(UIManagerExt.getColor("JXMonthView.monthStringForeground")); monthView.setDaysOfTheWeekForeground(UIManagerExt.getColor("JXMonthView.daysOfTheWeekForeground")); monthView.setSelectionBackground(UIManagerExt.getColor("JXMonthView.selectedBackground")); monthView.setSelectionForeground(UIManagerExt.getColor("JXMonthView.selectedForeground")); monthView.setFlaggedDayForeground(UIManagerExt.getColor("JXMonthView.flaggedDayForeground")); monthView.setBoxPaddingX(UIManagerExt.getInt("JXMonthView.boxPaddingX")); monthView.setBoxPaddingY(UIManagerExt.getInt("JXMonthView.boxPaddingY"));
/** * test that we get an int from the localized resource. */ @Test public void testGetIntFromResource() { String key = "goodInt"; Locale locale = JComponent.getDefaultLocale(); String columnString = UIManagerExt.getString(key, locale); if (columnString == null) { LOG.info("cant run test - no resource found for key: " + key); return; } Object value = UIManagerExt.getInt(key, locale); assertNotNull(value); assertEquals(Integer.decode(columnString), value); }
/** * test that we get a boolean from the localized resource. */ @Test public void testGetBooleanFromResource() { String key = "goodBoolean"; Locale locale = JComponent.getDefaultLocale(); String columnString = UIManagerExt.getString(key, locale); if (columnString == null) { LOG.info("cant run test - no resource found for key: " + key); return; } Object value = UIManagerExt.getBoolean(key, locale); assertNotNull(value); assertEquals(Boolean.valueOf(columnString), value); }
@Override protected void init(Shape point, Shape trajectory, Color b, Color h) { super.init(dim == null ? UIManagerExt.getShape("JXBusyLabel.pointShape") : getScaledDefaultPoint(dim.height), dim == null ? UIManagerExt.getShape("JXBusyLabel.trajectoryShape") : getScaledDefaultTrajectory(dim.height), UIManagerExt.getSafeColor("JXBusyLabel.baseColor", Color.LIGHT_GRAY), UIManagerExt.getSafeColor("JXBusyLabel.highlightColor", Color.BLACK)); } };