List of usage examples for javax.swing Icon getIconHeight
int getIconHeight();
From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java
/** * Create a separator to add to a toolbar. The separator needs to be * set when the layout of the toolbar is reset. * //from www . j a v a2 s .c o m * @param button The button to add to the toolBar. The height of the * separator depends of the insets of the button. * @param icon The icon to add to the button. The height of the * separator depends of the height of the icon. * @return See below. */ public static JSeparator toolBarSeparator(JButton button, Icon icon) { JSeparator separator = new JSeparator(SwingConstants.VERTICAL); if (button == null) return separator; Insets i = button.getInsets(); int h = 0; if (icon != null) h = icon.getIconHeight(); Dimension d = new Dimension(SEPARATOR_WIDTH, i.top + h + i.bottom); separator.setPreferredSize(d); separator.setSize(d); return separator; }
From source file:org.openstreetmap.josm.tools.ImageProvider.java
/** * Decorate one icon with an overlay icon. * * @param ground the base image//from ww w . j a v a2 s . c o m * @param overlay the overlay image (can be smaller than the base image) * @param pos position of the overlay image inside the base image (positioned * in one of the corners) * @return an icon that represent the overlay of the two given icons. The second icon is layed * on the first relative to the given position. */ public static ImageIcon overlay(Icon ground, Icon overlay, OverlayPosition pos) { GraphicsConfiguration conf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); int w = ground.getIconWidth(); int h = ground.getIconHeight(); int wo = overlay.getIconWidth(); int ho = overlay.getIconHeight(); BufferedImage img = conf.createCompatibleImage(w, h, Transparency.TRANSLUCENT); Graphics g = img.createGraphics(); ground.paintIcon(null, g, 0, 0); int x = 0, y = 0; switch (pos) { case NORTHWEST: x = 0; y = 0; break; case NORTHEAST: x = w - wo; y = 0; break; case SOUTHWEST: x = 0; y = h - ho; break; case SOUTHEAST: x = w - wo; y = h - ho; break; } overlay.paintIcon(null, g, x, y); return new ImageIcon(img); }
From source file:org.pentaho.ui.xul.swing.tags.SwingButton.java
@Override public void layout() { // check type to see if it's a toggleButton if (type == Type.CHECKBOX || type == Type.RADIO) { final AbstractButton oldButton = getButton(); final AbstractButton button = new JToggleButton(); button.setText(oldButton.getText()); button.setIcon(oldButton.getIcon()); button.setEnabled(oldButton.isEnabled()); button.setSelected(this.selected); setButton(button);// w w w . ja v a2 s.co m if (this.getOnclick() != null) { this.setOnclick(this.getOnclick()); } } final AbstractButton button = getButton(); // adjust orientation of label and icon if (this.orientation == Orient.VERTICAL) { button.setHorizontalTextPosition(JButton.CENTER); if (this.dir == Direction.FORWARD) { button.setVerticalTextPosition(JButton.BOTTOM); } else { button.setVerticalTextPosition(JButton.TOP); } } else { button.setVerticalTextPosition(JButton.CENTER); if (this.dir == Direction.FORWARD) { button.setHorizontalTextPosition(JButton.RIGHT); } else { button.setHorizontalTextPosition(JButton.LEFT); } } // Square button patch. if no label and icon is square, set min/max to square up button final Icon icon = button.getIcon(); if ("".equals(button.getText()) && icon != null && icon.getIconHeight() == icon.getIconWidth()) { Dimension dim = button.getPreferredSize(); button.setMinimumSize(new Dimension(dim.height, dim.height)); button.setPreferredSize(new Dimension(dim.height, dim.height)); } button.setToolTipText(this.getTooltiptext()); super.layout(); }
From source file:util.ui.UiUtilities.java
/** * Scale Icons to a specific width. The aspect ratio is kept. * * @param icon/* w w w . j a v a 2 s .c o m*/ * The icon to scale. * @param newWidth * The new width of the icon. * @return The scaled Icon. */ public static Icon scaleIcon(Icon icon, int newWidth) { if (icon == null) { return null; } return scaleIcon(icon, newWidth, (int) ((newWidth / (float) icon.getIconWidth()) * icon.getIconHeight())); }
From source file:util.ui.UiUtilities.java
/** * Scales Icons to a specific size// ww w . j a v a2 s . co m * * @param icon * Icon that should be scaled * @param width * scaled width * @param height * scaled height * @return Scaled Icon */ public static Icon scaleIcon(Icon icon, int width, int height) { if (icon == null) { return null; } int currentWidth = icon.getIconWidth(); int currentHeight = icon.getIconHeight(); if ((currentWidth == width) && (currentHeight == height)) { return icon; } try { // Create Image with Icon BufferedImage iconImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = iconImage.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); AffineTransform z = g2.getTransform(); g2.setTransform(z); icon.paintIcon(null, g2, 0, 0); g2.dispose(); BufferedImage scaled = scaleDown(iconImage, width, height); // Return new Icon return new ImageIcon(scaled); } catch (Exception ex) { ex.printStackTrace(); } return icon; }
From source file:util.ui.UiUtilities.java
/** * Creates a scaled Version of the Icon. * * The scaled Version will have a Background and a Border. * * @param ic//from ww w . j a va 2 s .c o m * @return ImageIcon * @since 2.1 */ public static ImageIcon createChannelIcon(Icon ic) { BufferedImage img = new BufferedImage(42, 22, BufferedImage.TYPE_INT_RGB); if (ic == null) { ic = new ImageIcon("./imgs/tvbrowser16.png"); } int height = 20; int width = 40; if ((ic.getIconWidth() != 0) && (ic.getIconHeight() != 0)) { double iWidth = ic.getIconWidth(); double iHeight = ic.getIconHeight(); if (iWidth / iHeight < 2.0) { width = (int) (iWidth * (20.0 / iHeight)); } else { height = (int) (iHeight * (40.0 / iWidth)); } } ic = scaleIcon(ic, width, height); Graphics2D g = img.createGraphics(); g.setColor(Color.WHITE); g.fillRect(1, 1, 40, 20); int x = 1 + 20 - ic.getIconWidth() / 2; int y = 1 + 10 - ic.getIconHeight() / 2; ic.paintIcon(null, g, x, y); g.setColor(Color.BLACK); g.drawRect(0, 0, 42, 22); return new ImageIcon(img); }