Java Code Examples for javax.swing.plaf.IconUIResource

The following examples show how to use javax.swing.plaf.IconUIResource. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private static void hackIcon(ImageIcon icon) {
    try {
        // Create a dummy image observer
        JPanel p = new JPanel();
        
        // Set the image observer to the multi-resolution image
        icon.setImageObserver(p);
        
        // Mac OS X specific
        if (Platform.isMac()) {
            Method getInvertedIcon = icon.getClass().getMethod("getInvertedIcon"); // NOI18N
            getInvertedIcon.setAccessible(true);
            IconUIResource invertedIcon = (IconUIResource)getInvertedIcon.invoke(icon);
            Field delegate = invertedIcon.getClass().getDeclaredField("delegate"); // NOI18N
            delegate.setAccessible(true);
            ImageIcon imageIcon = (ImageIcon)delegate.get(invertedIcon);
            // Set the image observer to the inverted multi-resolution image
            imageIcon.setImageObserver(p);
        }
    } catch (Throwable t) {
        Logger logger = Logger.getLogger(MultiResolutionImageHack.class.getName());
        logger.log(Level.FINE, "Failed to apply MultiResolutionToolkitImageCacheHack", t); // NOI18N
    }
}
 
Example 2
Source Project: dragonwell8_jdk   Source File: bug6604281.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            try {
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                fail(e.getMessage());
            }

            // Prepare image
            BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);

            Graphics2D graphics = (Graphics2D) image.getGraphics();

            graphics.setColor(Color.BLUE);
            graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
            graphics.setColor(Color.RED);
            graphics.drawLine(0, 0, image.getWidth(), image.getHeight());

            // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
            JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));

            JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));

            button2.setEnabled(false);

            if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
                fail("Two similar buttons have different size");
            }
        }
    });
}
 
Example 3
Source Project: TencentKona-8   Source File: bug6604281.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            try {
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                fail(e.getMessage());
            }

            // Prepare image
            BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);

            Graphics2D graphics = (Graphics2D) image.getGraphics();

            graphics.setColor(Color.BLUE);
            graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
            graphics.setColor(Color.RED);
            graphics.drawLine(0, 0, image.getWidth(), image.getHeight());

            // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
            JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));

            JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));

            button2.setEnabled(false);

            if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
                fail("Two similar buttons have different size");
            }
        }
    });
}
 
Example 4
Source Project: jdk8u60   Source File: bug6604281.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            try {
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                fail(e.getMessage());
            }

            // Prepare image
            BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);

            Graphics2D graphics = (Graphics2D) image.getGraphics();

            graphics.setColor(Color.BLUE);
            graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
            graphics.setColor(Color.RED);
            graphics.drawLine(0, 0, image.getWidth(), image.getHeight());

            // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
            JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));

            JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));

            button2.setEnabled(false);

            if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
                fail("Two similar buttons have different size");
            }
        }
    });
}
 
Example 5
Source Project: openjdk-jdk8u   Source File: bug6604281.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            try {
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                fail(e.getMessage());
            }

            // Prepare image
            BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);

            Graphics2D graphics = (Graphics2D) image.getGraphics();

            graphics.setColor(Color.BLUE);
            graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
            graphics.setColor(Color.RED);
            graphics.drawLine(0, 0, image.getWidth(), image.getHeight());

            // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
            JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));

            JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));

            button2.setEnabled(false);

            if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
                fail("Two similar buttons have different size");
            }
        }
    });
}
 
Example 6
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            try {
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                fail(e.getMessage());
            }

            // Prepare image
            BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);

            Graphics2D graphics = (Graphics2D) image.getGraphics();

            graphics.setColor(Color.BLUE);
            graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
            graphics.setColor(Color.RED);
            graphics.drawLine(0, 0, image.getWidth(), image.getHeight());

            // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
            JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));

            JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));

            button2.setEnabled(false);

            if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
                fail("Two similar buttons have different size");
            }
        }
    });
}
 
Example 7
Source Project: openjdk-jdk9   Source File: bug6604281.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            try {
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                fail(e.getMessage());
            }

            // Prepare image
            BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);

            Graphics2D graphics = (Graphics2D) image.getGraphics();

            graphics.setColor(Color.BLUE);
            graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
            graphics.setColor(Color.RED);
            graphics.drawLine(0, 0, image.getWidth(), image.getHeight());

            // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
            JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));

            JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));

            button2.setEnabled(false);

            if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
                fail("Two similar buttons have different size");
            }
        }
    });
}
 
Example 8
Source Project: jdk8u-jdk   Source File: bug6604281.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            try {
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                fail(e.getMessage());
            }

            // Prepare image
            BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);

            Graphics2D graphics = (Graphics2D) image.getGraphics();

            graphics.setColor(Color.BLUE);
            graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
            graphics.setColor(Color.RED);
            graphics.drawLine(0, 0, image.getWidth(), image.getHeight());

            // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
            JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));

            JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));

            button2.setEnabled(false);

            if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
                fail("Two similar buttons have different size");
            }
        }
    });
}
 
Example 9
Source Project: hottub   Source File: bug6604281.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            try {
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                fail(e.getMessage());
            }

            // Prepare image
            BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);

            Graphics2D graphics = (Graphics2D) image.getGraphics();

            graphics.setColor(Color.BLUE);
            graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
            graphics.setColor(Color.RED);
            graphics.drawLine(0, 0, image.getWidth(), image.getHeight());

            // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
            JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));

            JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));

            button2.setEnabled(false);

            if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
                fail("Two similar buttons have different size");
            }
        }
    });
}
 
Example 10
Source Project: openjdk-8-source   Source File: bug6604281.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            try {
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                fail(e.getMessage());
            }

            // Prepare image
            BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);

            Graphics2D graphics = (Graphics2D) image.getGraphics();

            graphics.setColor(Color.BLUE);
            graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
            graphics.setColor(Color.RED);
            graphics.drawLine(0, 0, image.getWidth(), image.getHeight());

            // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
            JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));

            JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));

            button2.setEnabled(false);

            if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
                fail("Two similar buttons have different size");
            }
        }
    });
}
 
Example 11
Source Project: openjdk-8   Source File: bug6604281.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            try {
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                fail(e.getMessage());
            }

            // Prepare image
            BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);

            Graphics2D graphics = (Graphics2D) image.getGraphics();

            graphics.setColor(Color.BLUE);
            graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
            graphics.setColor(Color.RED);
            graphics.drawLine(0, 0, image.getWidth(), image.getHeight());

            // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
            JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));

            JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));

            button2.setEnabled(false);

            if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
                fail("Two similar buttons have different size");
            }
        }
    });
}
 
Example 12
Source Project: jdk8u_jdk   Source File: bug6604281.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            try {
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                fail(e.getMessage());
            }

            // Prepare image
            BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);

            Graphics2D graphics = (Graphics2D) image.getGraphics();

            graphics.setColor(Color.BLUE);
            graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
            graphics.setColor(Color.RED);
            graphics.drawLine(0, 0, image.getWidth(), image.getHeight());

            // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
            JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));

            JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));

            button2.setEnabled(false);

            if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
                fail("Two similar buttons have different size");
            }
        }
    });
}
 
Example 13
Source Project: jdk8u-jdk   Source File: bug6604281.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            try {
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                fail(e.getMessage());
            }

            // Prepare image
            BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);

            Graphics2D graphics = (Graphics2D) image.getGraphics();

            graphics.setColor(Color.BLUE);
            graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
            graphics.setColor(Color.RED);
            graphics.drawLine(0, 0, image.getWidth(), image.getHeight());

            // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
            JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));

            JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));

            button2.setEnabled(false);

            if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
                fail("Two similar buttons have different size");
            }
        }
    });
}
 
Example 14
Source Project: jdk8u-dev-jdk   Source File: bug6604281.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws InvocationTargetException, InterruptedException {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            SynthLookAndFeel laf = new SynthLookAndFeel();
            try {
                UIManager.setLookAndFeel(laf);
            } catch (Exception e) {
                fail(e.getMessage());
            }

            // Prepare image
            BufferedImage image = new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);

            Graphics2D graphics = (Graphics2D) image.getGraphics();

            graphics.setColor(Color.BLUE);
            graphics.fillRect(0, 0, image.getWidth(), image.getHeight());
            graphics.setColor(Color.RED);
            graphics.drawLine(0, 0, image.getWidth(), image.getHeight());

            // Use IconUIResource as an icon, because with ImageIcon bug is not reproduced
            JButton button1 = new JButton(new IconUIResource(new ImageIcon(image)));

            JButton button2 = new JButton(new IconUIResource(new ImageIcon(image)));

            button2.setEnabled(false);

            if (button1.getPreferredSize().getHeight() != button2.getPreferredSize().getHeight()) {
                fail("Two similar buttons have different size");
            }
        }
    });
}
 
Example 15
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());

  Icon emptyIcon = new EmptyIcon();
  UIManager.put("Tree.expandedIcon", new IconUIResource(emptyIcon));
  UIManager.put("Tree.collapsedIcon", new IconUIResource(emptyIcon));

  JTree tree = new JTree();
  for (int i = 0; i < tree.getRowCount(); i++) {
    tree.expandRow(i);
  }

  JCheckBox check = new JCheckBox("JTree: paint expanded, collapsed Icon");
  check.addActionListener(e -> {
    Icon ei;
    Icon ci;
    if (((JCheckBox) e.getSource()).isSelected()) {
      UIDefaults lnfdef = UIManager.getLookAndFeelDefaults();
      ei = lnfdef.getIcon("Tree.expandedIcon");
      ci = lnfdef.getIcon("Tree.collapsedIcon");
    } else {
      ei = emptyIcon;
      ci = emptyIcon;
    }
    UIManager.put("Tree.expandedIcon", new IconUIResource(ei));
    UIManager.put("Tree.collapsedIcon", new IconUIResource(ci));
    SwingUtilities.updateComponentTreeUI(tree);
  });

  JPanel p = new JPanel(new GridLayout(1, 2));
  p.add(new JScrollPane(tree));
  p.add(new JScrollPane(new JTree()));

  add(check, BorderLayout.NORTH);
  add(p);
  setPreferredSize(new Dimension(320, 240));
}
 
Example 16
Source Project: Darcula   Source File: DarculaLaf.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public UIDefaults getDefaults() {
  try {
    final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults");
    superMethod.setAccessible(true);
    final UIDefaults metalDefaults =
        (UIDefaults)superMethod.invoke(new MetalLookAndFeel());
    final UIDefaults defaults = (UIDefaults)superMethod.invoke(base);
    initInputMapDefaults(defaults);
    initIdeaDefaults(defaults);
    patchStyledEditorKit();
    patchComboBox(metalDefaults, defaults);
    defaults.remove("Spinner.arrowButtonBorder");
    defaults.put("Spinner.arrowButtonSize", new Dimension(16, 5));
    defaults.put("Tree.collapsedIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/treeNodeCollapsed.png")));
    defaults.put("Tree.expandedIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/treeNodeExpanded.png")));
    defaults.put("Menu.arrowIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/menuItemArrowIcon.png")));
    defaults.put("CheckBoxMenuItem.checkIcon", EmptyIcon.create(16));
    defaults.put("RadioButtonMenuItem.checkIcon", EmptyIcon.create(16));
    defaults.put("InternalFrame.icon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/internalFrame.png")));
    defaults.put("OptionPane.informationIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/option_pane_info.png")));
    defaults.put("OptionPane.questionIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/option_pane_question.png")));
    defaults.put("OptionPane.warningIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/option_pane_warning.png")));
    defaults.put("OptionPane.errorIcon", new IconUIResource(IconLoader.getIcon("/com/bulenkov/darcula/icons/option_pane_error.png")));
    if (SystemInfo.isMac && !"true".equalsIgnoreCase(System.getProperty("apple.laf.useScreenMenuBar", "false"))) {
      defaults.put("MenuBarUI", "com.bulenkov.darcula.ui.DarculaMenuBarUI");
      defaults.put("MenuUI", "javax.swing.plaf.basic.BasicMenuUI");
    }
    return defaults;
  }
  catch (Exception ignore) {
    log(ignore);
  }
  return super.getDefaults();
}
 
Example 17
Source Project: Darcula   Source File: DarculaLaf.java    License: Apache License 2.0 5 votes vote down vote up
private static Object parseValue(String key, String value) {
  if ("null".equals(value)) {
    return null;
  }
  if (key.endsWith("Insets")) {
    final List<String> numbers = StringUtil.split(value, ",");
    return new InsetsUIResource(Integer.parseInt(numbers.get(0)),
        Integer.parseInt(numbers.get(1)),
        Integer.parseInt(numbers.get(2)),
        Integer.parseInt(numbers.get(3)));
  } else if (key.endsWith(".border")) {
    try {
      return Class.forName(value).newInstance();
    } catch (Exception e) {log(e);}
  } else {
    final Color color = ColorUtil.fromHex(value, null);
    final Integer invVal = getInteger(value);
    final Boolean boolVal = "true".equals(value) ? Boolean.TRUE : "false".equals(value) ? Boolean.FALSE : null;
    Icon icon = key.toLowerCase().endsWith("icon") ? null : null; //TODO: copy image loading
    if (color != null) {
      return  new ColorUIResource(color);
    } else if (invVal != null) {
      return invVal;
    } else if (icon != null) {
      return new IconUIResource(icon);
    } else if (boolVal != null) {
      return boolVal;
    }
  }
  return value;
}
 
Example 18
Source Project: consulo   Source File: ModernDarkLaf.java    License: Apache License 2.0 5 votes vote down vote up
protected Object parseValue(String key, @Nonnull String value) {
  if (key.endsWith("Insets")) {
    final List<String> numbers = StringUtil.split(value, ",");
    return new InsetsUIResource(Integer.parseInt(numbers.get(0)), Integer.parseInt(numbers.get(1)), Integer.parseInt(numbers.get(2)), Integer.parseInt(numbers.get(3)));
  }
  else if (key.endsWith(".border")) {
    try {
      return Class.forName(value).newInstance();
    }
    catch (Exception e) {
      log(e);
    }
  }
  else {
    final Color color = parseColor(value);
    final Integer invVal = getInteger(value);
    final Boolean boolVal = "true".equals(value) ? Boolean.TRUE : "false".equals(value) ? Boolean.FALSE : null;
    Icon icon = value.startsWith("AllIcons.") ? IconLoader.getIcon(value) : null;
    if (icon == null && value.endsWith(".png")) {
      icon = IconLoader.findIcon(value, getClass(), true);
    }
    if (color != null) {
      return new ColorUIResource(color);
    }
    else if (invVal != null) {
      return invVal;
    }
    else if (icon != null) {
      return new IconUIResource(icon);
    }
    else if (boolVal != null) {
      return boolVal;
    }
  }
  return value;
}
 
Example 19
Source Project: consulo   Source File: DarculaLaf.java    License: Apache License 2.0 5 votes vote down vote up
protected Object parseValue(String key, @Nonnull String value) {
  if (key.endsWith("Insets") || key.endsWith("padding")) {
    final List<String> numbers = StringUtil.split(value, ",");
    return new InsetsUIResource(Integer.parseInt(numbers.get(0)),
                                Integer.parseInt(numbers.get(1)),
                                Integer.parseInt(numbers.get(2)),
                                Integer.parseInt(numbers.get(3)));
  } else if (key.endsWith(".border")) {
    try {
      return Class.forName(value).newInstance();
    } catch (Exception e) {log(e);}
  } else {
    final Color color = parseColor(value);
    final Integer invVal = getInteger(value);
    final Boolean boolVal = "true".equals(value) ? Boolean.TRUE : "false".equals(value) ? Boolean.FALSE : null;
    Icon icon = value.startsWith("AllIcons.") ? IconLoader.getIcon(value) : null;
    if (icon == null && (value.endsWith(".png") || value.endsWith(".svg"))) {
      icon = IconLoader.findIcon(value, getClass(), true);
    }
    if (color != null) {
      return  new ColorUIResource(color);
    } else if (invVal != null) {
      return invVal;
    } else if (icon != null) {
      return new IconUIResource(icon);
    } else if (boolVal != null) {
      return boolVal;
    }
  }
  return value;
}
 
Example 20
Source Project: littleluck   Source File: LuckResourceBundle.java    License: Apache License 2.0 4 votes vote down vote up
protected IconUIResource getIconRes(String key)
{
    return new IconUIResource(new ImageIcon(LuckRes.getImage(key)));
}
 
Example 21
Source Project: littleluck   Source File: LuckResourceBundle.java    License: Apache License 2.0 4 votes vote down vote up
protected IconUIResource getIconRes(Icon icon)
{
    return new IconUIResource(icon);
}
 
Example 22
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 4 votes vote down vote up
private MainPanel() {
  super(new BorderLayout(2, 2));

  JTree tree = new JTree();
  tree.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));

  int lci = UIManager.getInt("Tree.leftChildIndent");
  SpinnerNumberModel leftChildIndent = new SpinnerNumberModel(lci, -32, 32, 1);

  int rci = UIManager.getInt("Tree.rightChildIndent");
  SpinnerNumberModel rightChildIndent = new SpinnerNumberModel(rci, -32, 32, 1);

  Box box1 = Box.createHorizontalBox();
  box1.add(new JLabel(" Tree.leftChildIndent:"));
  box1.add(new JSpinner(leftChildIndent));
  box1.add(new JLabel(" Tree.rightChildIndent:"));
  box1.add(new JSpinner(rightChildIndent));

  Box box2 = Box.createHorizontalBox();
  box2.add(Box.createHorizontalGlue());
  box2.add(paintLines);
  box2.add(expandedIcon);
  JButton update = new JButton("update");
  box2.add(update);

  Icon emptyIcon = new EmptyIcon();
  update.addActionListener(e -> {
    UIManager.put("Tree.leftChildIndent", leftChildIndent.getNumber().intValue());
    UIManager.put("Tree.rightChildIndent", rightChildIndent.getNumber().intValue());
    Icon ei;
    Icon ci;
    if (expandedIcon.isSelected()) {
      UIDefaults lnfDef = UIManager.getLookAndFeelDefaults();
      ei = lnfDef.getIcon("Tree.expandedIcon");
      ci = lnfDef.getIcon("Tree.collapsedIcon");
    } else {
      ei = emptyIcon;
      ci = emptyIcon;
    }
    UIManager.put("Tree.expandedIcon", new IconUIResource(ei));
    UIManager.put("Tree.collapsedIcon", new IconUIResource(ci));
    UIManager.put("Tree.paintLines", paintLines.isSelected());
    SwingUtilities.updateComponentTreeUI(this);
  });

  JPanel p = new JPanel(new GridLayout(2, 1, 2, 2));
  p.add(box1);
  p.add(box2);

  setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
  add(p, BorderLayout.NORTH);
  add(new JScrollPane(tree));
  setPreferredSize(new Dimension(320, 240));
}
 
Example 23
Source Project: Darcula   Source File: DarculaCheckBoxUI.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Icon getDefaultIcon() {
  return new IconUIResource(EmptyIcon.create(20));
}
 
Example 24
Source Project: Darcula   Source File: DarculaRadioButtonUI.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Icon getDefaultIcon() {
  return new IconUIResource(EmptyIcon.create(20));
}
 
Example 25
Source Project: consulo   Source File: ModernCheckBoxUI.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Icon getDefaultIcon() {
  return new IconUIResource(JBUI.emptyIcon(20));
}
 
Example 26
Source Project: consulo   Source File: ModernRadioButtonUI.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Icon getDefaultIcon() {
  return new IconUIResource(JBUI.emptyIcon(20));
}
 
Example 27
Source Project: consulo   Source File: DarculaCheckBoxUI.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Icon getDefaultIcon() {
  return new IconUIResource(JBUI.emptyIcon(20));
}