javax.swing.Icon#getIconWidth ( )源码实例Demo

下面列出了javax.swing.Icon#getIconWidth ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Spark   文件: ImageCombiner.java
/**
 * Creates an Image from the specified Icon
 * 
 * @param icon
 *            that should be converted to an image
 * @return the new image
 */
public static Image iconToImage(Icon icon) {
    if (icon instanceof ImageIcon) {
        return ((ImageIcon) icon).getImage();
    } else {
        int w = icon.getIconWidth();
        int h = icon.getIconHeight();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        BufferedImage image = gc.createCompatibleImage(w, h);
        Graphics2D g = image.createGraphics();
        icon.paintIcon(null, g, 0, 0);
        g.dispose();
        return image;
    }
}
 
源代码2 项目: xyTalk-pc   文件: GraphicUtils.java
/**
    * Converts a File holding an Image into a Buffered Image
    * 
    * @param file
    *            {@link File}
    * @return {@link BufferedImage}
    */
   public static BufferedImage getBufferedImage(File file) {
// Why wasn't this using it's code that pulled from the file? Hrm.
   //Icon icon = SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32);
   Icon icon = null;

BufferedImage bi = new BufferedImage(icon.getIconWidth(),
	icon.getIconHeight(), BufferedImage.OPAQUE);
Graphics bg = bi.getGraphics();

ImageIcon i = (ImageIcon) icon;

bg.drawImage(i.getImage(), 0, 0, null);
bg.dispose();

return bi;
   }
 
源代码3 项目: xyTalk-pc   文件: ImageCombiner.java
/**
 * Creates an Image from the specified Icon
 * 
 * @param icon
 *            that should be converted to an image
 * @return the new image
 */
public static Image iconToImage(Icon icon) {
    if (icon instanceof ImageIcon) {
        return ((ImageIcon) icon).getImage();
    } else {
        int w = icon.getIconWidth();
        int h = icon.getIconHeight();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        BufferedImage image = gc.createCompatibleImage(w, h);
        Graphics2D g = image.createGraphics();
        icon.paintIcon(null, g, 0, 0);
        g.dispose();
        return image;
    }
}
 
源代码4 项目: netbeans   文件: CustomScopePanel.java
@Override
public Image getIcon(int type) {
    Icon icon = data.getIcon();
    if (icon instanceof ImageIcon) {
        return ((ImageIcon) icon).getImage();
    } else {
        int w = icon.getIconWidth();
        int h = icon.getIconHeight();
        GraphicsEnvironment ge =
                GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice gd = ge.getDefaultScreenDevice();
        GraphicsConfiguration gc = gd.getDefaultConfiguration();
        BufferedImage image = gc.createCompatibleImage(w, h);
        Graphics2D g = image.createGraphics();
        icon.paintIcon(null, g, 0, 0);
        g.dispose();
        return image;
    }
}
 
源代码5 项目: open-ig   文件: IGButton.java
@Override
public void paint(Graphics g) {
	Graphics2D g2 = (Graphics2D)g;
	g.setFont(getFont());
	g.setColor(getForeground());
	if (getModel().isPressed()) {
		largeButtonPressed.paintTo(g2, 0, 0, getWidth(), getHeight(), true, getText());
	} else {
		largeButton.paintTo(g2, 0, 0, getWidth(), getHeight(), false, getText());
	}
	Icon icon = getIcon();
	if (icon != null) {
		int w = (getWidth() - icon.getIconWidth()) / 2;
		int h = (getHeight() - icon.getIconHeight()) / 2;
		icon.paintIcon(this, g, w, h);
	}
	if (!isEnabled()) {
		RenderTools.fill(g2, 0, 0, getWidth(), getHeight(), disabledPattern);
	}
}
 
源代码6 项目: hottub   文件: SampleTreeCellRenderer.java
/**
 * paint is subclassed to draw the background correctly.  JLabel
 * currently does not allow backgrounds other than white, and it
 * will also fill behind the icon.  Something that isn't desirable.
 */
@Override
public void paint(Graphics g) {
    Color bColor;
    Icon currentI = getIcon();

    if (selected) {
        bColor = SELECTED_BACKGROUND_COLOR;
    } else if (getParent() != null) /* Pick background color up from parent (which will come from
    the JTree we're contained in). */ {
        bColor = getParent().getBackground();
    } else {
        bColor = getBackground();
    }
    g.setColor(bColor);
    if (currentI != null && getText() != null) {
        int offset = (currentI.getIconWidth() + getIconTextGap());

        if (getComponentOrientation().isLeftToRight()) {
            g.fillRect(offset, 0, getWidth() - 1 - offset,
                    getHeight() - 1);
        } else {
            g.fillRect(0, 0, getWidth() - 1 - offset, getHeight() - 1);
        }
    } else {
        g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
    }
    super.paint(g);
}
 
源代码7 项目: jdk8u-dev-jdk   文件: SampleTreeCellRenderer.java
/**
 * paint is subclassed to draw the background correctly.  JLabel
 * currently does not allow backgrounds other than white, and it
 * will also fill behind the icon.  Something that isn't desirable.
 */
@Override
public void paint(Graphics g) {
    Color bColor;
    Icon currentI = getIcon();

    if (selected) {
        bColor = SELECTED_BACKGROUND_COLOR;
    } else if (getParent() != null) /* Pick background color up from parent (which will come from
    the JTree we're contained in). */ {
        bColor = getParent().getBackground();
    } else {
        bColor = getBackground();
    }
    g.setColor(bColor);
    if (currentI != null && getText() != null) {
        int offset = (currentI.getIconWidth() + getIconTextGap());

        if (getComponentOrientation().isLeftToRight()) {
            g.fillRect(offset, 0, getWidth() - 1 - offset,
                    getHeight() - 1);
        } else {
            g.fillRect(0, 0, getWidth() - 1 - offset, getHeight() - 1);
        }
    } else {
        g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
    }
    super.paint(g);
}
 
源代码8 项目: triplea   文件: CompositeIcon.java
@Override
public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
  int dx = 0;
  for (final Icon icon : icons) {
    icon.paintIcon(c, g, x + dx, y);
    dx += GAP;
    dx += icon.getIconWidth();
  }
}
 
源代码9 项目: netbeans   文件: WindowsDPIWorkaroundIcon.java
/**
 * @param delegate an icon implementation from
 *        {@code com.sun.java.swing.plaf.windows.WindowsIconFactory}, in its initial state at
 *        the time of LAF initialization (before display configuration changes are likely to
 *        have happened)
 */
public WindowsDPIWorkaroundIcon(Icon delegate) {
    if (delegate == null) {
        throw new NullPointerException();
    }
    this.delegate = delegate;
    /* As part of bug JDK-8211715, icons in WindowsIconFactory may actually change their
    reported size if the display configuration is changed while the application is running.
    Assuming this workaround is applied early in the application's life cycle, before any
    display configuration changes have happened, the initial value is the correct one. */
    this.width = delegate.getIconWidth();
    this.height = delegate.getIconHeight();
}
 
源代码10 项目: netbeans   文件: CustomToolbar.java
public void addButton(AbstractButton button) {
    Icon icon = button.getIcon();
    Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 10);
    button.setPreferredSize(size);
    button.setMargin(new Insets(5, 4, 5, 4));
    toolbar.add(button);
}
 
源代码11 项目: netbeans   文件: VariablesViewButtons.java
private static JButton createButton (String iconPath, String tooltip) {
    Icon icon = ImageUtilities.loadImageIcon(iconPath, false);
    final JButton button = new JButton(icon);
    // ensure small size, just for the icon
    Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
    button.setPreferredSize(size);
    button.setMargin(new Insets(1, 1, 1, 1));
    button.setBorder(new EmptyBorder(button.getBorder().getBorderInsets(button)));
    button.setToolTipText(tooltip);
    button.setFocusable(false);
    return button;
}
 
源代码12 项目: netbeans   文件: FiltersManager.java
private JToggleButton createToggle (Map fStates, int index) {
    boolean isSelected = filtersDesc.isSelected(index);
    Icon icon = filtersDesc.getSelectedIcon(index);
    // ensure small size, just for the icon
    JToggleButton result = new JToggleButton(icon, isSelected);
    Dimension size = new Dimension(icon.getIconWidth() + 6, icon.getIconHeight() + 4);
    result.setPreferredSize(size);
    result.setMargin(new Insets(2,3,2,3));
    result.setToolTipText(filtersDesc.getTooltip(index));
    
    fStates.put(filtersDesc.getName(index), Boolean.valueOf(isSelected));
    
    return result;
}
 
源代码13 项目: ghidra   文件: ReplaceDefaultMarkupItemAction.java
public ReplaceDefaultMarkupItemAction(VTController controller, boolean addToToolbar) {
	super(controller, "Apply (Replace Default Only)");

	Icon replacedIcon = VTPlugin.REPLACED_ICON;
	ImageIcon warningIcon = ResourceManager.loadImage("images/warning.png");
	warningIcon = ResourceManager.getScaledIcon(warningIcon, 12, 12);
	int warningIconWidth = warningIcon.getIconWidth();
	int warningIconHeight = warningIcon.getIconHeight();

	MultiIcon multiIcon = new MultiIcon(replacedIcon);
	int refreshIconWidth = replacedIcon.getIconWidth();
	int refreshIconHeight = replacedIcon.getIconHeight();

	int x = refreshIconWidth - warningIconWidth;
	int y = refreshIconHeight - warningIconHeight;

	TranslateIcon translateIcon = new TranslateIcon(warningIcon, x, y);
	multiIcon.addIcon(translateIcon);

	if (addToToolbar) {
		setToolBarData(new ToolBarData(multiIcon, MENU_GROUP));
	}
	MenuData menuData =
		new MenuData(new String[] { "Apply (Replace Default Only)" }, replacedIcon, MENU_GROUP);
	menuData.setMenuSubGroup("2");
	setPopupMenuData(menuData);
	setEnabled(false);
	setHelpLocation(new HelpLocation("VersionTrackingPlugin", "Replace_Default_Markup_Item"));
}
 
源代码14 项目: openjdk-8-source   文件: SampleTreeCellRenderer.java
/**
 * paint is subclassed to draw the background correctly.  JLabel
 * currently does not allow backgrounds other than white, and it
 * will also fill behind the icon.  Something that isn't desirable.
 */
@Override
public void paint(Graphics g) {
    Color bColor;
    Icon currentI = getIcon();

    if (selected) {
        bColor = SELECTED_BACKGROUND_COLOR;
    } else if (getParent() != null) /* Pick background color up from parent (which will come from
    the JTree we're contained in). */ {
        bColor = getParent().getBackground();
    } else {
        bColor = getBackground();
    }
    g.setColor(bColor);
    if (currentI != null && getText() != null) {
        int offset = (currentI.getIconWidth() + getIconTextGap());

        if (getComponentOrientation().isLeftToRight()) {
            g.fillRect(offset, 0, getWidth() - 1 - offset,
                    getHeight() - 1);
        } else {
            g.fillRect(0, 0, getWidth() - 1 - offset, getHeight() - 1);
        }
    } else {
        g.fillRect(0, 0, getWidth() - 1, getHeight() - 1);
    }
    super.paint(g);
}
 
源代码15 项目: netbeans   文件: VariablesViewButtons.java
public static JButton createButton (Icon icon, String tooltip) {
    final JButton button = new JButton(icon);
    // ensure small size, just for the icon
    Dimension size = new Dimension(icon.getIconWidth() + 8, icon.getIconHeight() + 8);
    button.setPreferredSize(size);
    button.setMargin(new Insets(1, 1, 1, 1));
    button.setBorder(new EmptyBorder(button.getBorder().getBorderInsets(button)));
    button.setToolTipText(tooltip);
    button.setFocusable(false);
    return button;
}
 
源代码16 项目: netbeans   文件: GtkViewTabDisplayerUI.java
protected void paintTabContent(Graphics g, int index, String text, int x,
                               int y, int width, int height) {
    // substract lower border
    height--;
    FontMetrics fm = getTxtFontMetrics();
    // setting font already here to compute string width correctly
    g.setFont(getTxtFont());
    int txtWidth = width;
    if (isSelected(index)) {
        Component buttons = getControlButtons();
        if( null != buttons ) {
            Dimension buttonsSize = buttons.getPreferredSize();
            if( width < buttonsSize.width+ICON_X_PAD ) {
                buttons.setVisible( false );
            } else {
                buttons.setVisible( true );
                txtWidth = width - (buttonsSize.width + ICON_X_PAD + TXT_X_PAD);
                buttons.setLocation(x + txtWidth + TXT_X_PAD, y + (height - buttonsSize.height)/2 + (TXT_Y_PAD / 2));
            }
        }
    } else {
        txtWidth = width - 2 * TXT_X_PAD;
    }
    // draw bump (dragger)
    drawBump(g, index, x + 4, y + 6, BUMP_WIDTH, height - 8);
    
    boolean slidedOut = false;
    WinsysInfoForTabbedContainer winsysInfo = displayer.getContainerWinsysInfo();
    if( null != winsysInfo && winsysInfo.isSlidedOutContainer() )
        slidedOut = false;
    if( isTabBusy( index ) && !slidedOut ) {
        Icon busyIcon = BusyTabsSupport.getDefault().getBusyIcon( isSelected( index ) );
        txtWidth -= busyIcon.getIconWidth() - 3 - TXT_X_PAD;
        busyIcon.paintIcon( displayer, g, x+TXT_X_PAD, y+(height-busyIcon.getIconHeight())/2);
        x += busyIcon.getIconWidth() + 3;
    }
    // draw text in right color
    Color txtC = UIManager.getColor("textText"); //NOI18N
    HtmlRenderer.renderString(text, g, x + TXT_X_PAD, y + fm.getAscent()
        + TXT_Y_PAD,
        txtWidth, height, getTxtFont(),
        txtC,
        HtmlRenderer.STYLE_TRUNCATE, true);
}
 
源代码17 项目: ghidra   文件: CenterTranslateIcon.java
private static int getCenterX(Icon icon, int baseIconSize) {
	return (baseIconSize / 2) - (icon.getIconWidth() / 2);
}
 
源代码18 项目: pumpernickel   文件: DecoratedListUI.java
@Override
protected void paintCell(Graphics g, int row, Rectangle rowBounds,
		ListCellRenderer cellRenderer, ListModel dataModel,
		ListSelectionModel selModel, int leadIndex) {
	super.paintCell(g, row, rowBounds, cellRenderer, dataModel, selModel,
			leadIndex);

	Object value = dataModel.getElementAt(row);
	boolean cellHasFocus = list.hasFocus() && (row == leadIndex);
	boolean isSelected = selModel.isSelectedIndex(row);

	ListDecoration[] decorations = getDecorations(list);
	for (int a = 0; a < decorations.length; a++) {
		if (decorations[a].isVisible(list, value, row, isSelected,
				cellHasFocus)) {
			Point p = decorations[a].getLocation(list, value, row,
					isSelected, cellHasFocus);
			Icon icon = decorations[a].getIcon(list, value, row,
					isSelected, cellHasFocus, false, false);
			// we assume rollover/pressed icons are same dimensions as
			// default icon
			Rectangle iconBounds = new Rectangle(rowBounds.x + p.x,
					rowBounds.y + p.y, icon.getIconWidth(),
					icon.getIconHeight());
			if (armedDecoration != null && armedDecoration.value == value
					&& armedDecoration.decoration == decorations[a]) {
				icon = decorations[a].getIcon(list, value, row, isSelected,
						cellHasFocus, false, true);
			} else if (iconBounds.contains(mouseX, mouseY)) {
				icon = decorations[a].getIcon(list, value, row, isSelected,
						cellHasFocus, true, false);
			}
			Graphics g2 = g.create();
			try {
				icon.paintIcon(list, g2, iconBounds.x, iconBounds.y);
			} finally {
				g2.dispose();
			}
		}
	}
}
 
源代码19 项目: netbeans   文件: HtmlLabelUI.java
/** Actually paint the icon and text using our own html rendering engine. */
private void paintIconAndText(Graphics g, HtmlRendererImpl r) {
    Font f = font(r);
    g.setFont(f);

    FontMetrics fm = g.getFontMetrics();

    //Find out what height we need
    int txtH = fm.getMaxAscent() + fm.getMaxDescent();
    Insets ins = r.getInsets();

    //find out the available height less the insets
    int rHeight = r.getHeight();
    int availH = rHeight - (ins.top + ins.bottom);

    int txtY;

    if (availH >= txtH) {
        //Center the text if we have space
        txtY = (txtH + ins.top + ((availH / 2) - (txtH / 2))) - fm.getMaxDescent();
    } else if (r.getHeight() > txtH) {
        txtY = txtH + (rHeight - txtH) / 2 - fm.getMaxDescent();
    } else {
        //Okay, it's not going to fit, punt.
        txtY = fm.getMaxAscent();
    }
    
    int txtX = r.getIndent();

    Icon icon = r.getIcon();

    //Check the icon non-null and height (see TabData.NO_ICON for why)
    if ((icon != null) && (icon.getIconWidth() > 0) && (icon.getIconHeight() > 0)) {
        int iconY;

        if (availH > icon.getIconHeight()) {
            //add 2 to make sure icon top pixels are not cut off by outline
            iconY = ins.top + ((availH / 2) - (icon.getIconHeight() / 2)); // + 2;
        } else if (availH == icon.getIconHeight()) {
            //They're an exact match, make it 0
            iconY = ins.top;
        } else {
            //Won't fit; make the top visible and cut the rest off (option:
            //center it and clip it on top and bottom - probably even harder
            //to recognize that way, though)
            iconY = ins.top;
        }

        //add in the insets
        int iconX = ins.left + r.getIndent() + 1; //+1 to get it out of the way of the focus border

        try {
            //Diagnostic - the CPP module currently is constructing
            //some ImageIcon from a null image in Options.  So, catch it and at
            //least give a meaningful message that indicates what node
            //is the culprit
            icon.paintIcon(r, g, iconX, iconY);
        } catch (NullPointerException npe) {
            Exceptions.attachMessage(npe,
                                     "Probably an ImageIcon with a null source image: " +
                                     icon + " - " + r.getText()); //NOI18N
            Exceptions.printStackTrace(npe);
        }

        txtX = iconX + icon.getIconWidth() + r.getIconTextGap();
    } else {
        //If there's no icon, paint the text where the icon would start
        txtX += ins.left;
    }

    String text = r.getText();

    if (text == null) {
        //No text, we're done
        return;
    }

    //Get the available horizontal pixels for text
    int txtW = (icon != null)
        ? (r.getWidth() - (ins.left + ins.right + icon.getIconWidth() + r.getIconTextGap() + r.getIndent()))
        : (r.getWidth() - (ins.left + ins.right + r.getIndent()));

    Color background = getBackgroundFor(r);
    Color foreground = ensureContrastingColor(getForegroundFor(r), background);

    if (r.isHtml()) {
        HtmlRenderer._renderHTML(text, 0, g, txtX, txtY, txtW, txtH, f, foreground, r.getRenderStyle(), true, background, r.isSelected());
    } else {
        HtmlRenderer.renderPlainString(text, g, txtX, txtY, txtW, txtH, f, foreground, r.getRenderStyle(), true);
    }
}
 
源代码20 项目: visualvm   文件: LabelRenderer.java
public void setIcon(Icon icon) {
    this.icon = icon;
    iconWidth = icon == null ? 0 : icon.getIconWidth();
    iconHeight = icon == null ? 0 : icon.getIconHeight();
    resetPreferredSize(true, false); // Icon likely won't change height
}