📄 metaliconfactory.java
字号:
Color savedColor = g.getColor(); g.setColor(MetalLookAndFeel.getBlack()); g.drawLine(x + 2, y + 5, x + 9, y + 5); g.drawLine(x + 10, y + 6, x + 15, y + 6); g.drawLine(x + 15, y + 5, x + 15, y + 14); g.drawLine(x + 2, y + 14, x + 15, y + 14); g.drawLine(x + 1, y + 6, x + 1, y + 14); g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow()); g.drawLine(x + 11, y + 3, x + 15, y + 3); g.drawLine(x + 10, y + 4, x + 15, y + 4); g.setColor(MetalLookAndFeel.getPrimaryControl()); g.fillRect(x + 3, y + 7, 7, 7); g.fillRect(x + 10, y + 8, 5, 6); g.drawLine(x + 10, y + 5, x + 14, y + 5); g.setColor(MetalLookAndFeel.getPrimaryControlHighlight()); g.drawLine(x + 10, y + 7, x + 14, y + 7); g.drawLine(x + 2, y + 6, x + 9, y + 6); g.drawLine(x + 2, y + 6, x + 2, y + 13); g.setColor(savedColor); } } /** * An icon used for the "up folder" button on a {@link JFileChooser} under * the {@link MetalLookAndFeel}. * * @see MetalIconFactory#getFileChooserNewFolderIcon() */ private static class FileChooserUpFolderIcon extends FileChooserNewFolderIcon implements Icon, Serializable { /** * Creates a new icon. */ public FileChooserUpFolderIcon() { // Nothing to do here. } /** * Paints the icon using colors from the {@link MetalLookAndFeel}. * * @param c the component (ignored). * @param g the graphics device. * @param x the x-coordinate for the top-left of the icon. * @param y the y-coordinate for the top-left of the icon. */ public void paintIcon(Component c, Graphics g, int x, int y) { Color savedColor = g.getColor(); // draw the folder super.paintIcon(c, g, x, y); // now draw the up arrow g.setColor(MetalLookAndFeel.getBlack()); g.drawLine(x + 8, y + 9, x + 8, y + 16); int xx = x + 8; for (int i = 0; i < 4; i++) g.drawLine(xx - i, y + 9 + i, xx + i, y + 9 + i); g.setColor(savedColor); } } /** * An icon representing a file (drawn as a piece of paper with the top-right * corner turned down). */ public static class FileIcon16 implements Icon, Serializable { /** * Returns the width of the icon, in pixels. * * @return The width of the icon. */ public int getIconWidth() { return 16; } /** * Returns the height of the icon, in pixels. The height returned is * <code>16</code> plus the value returned by * {@link #getAdditionalHeight()}. * * @return The height of the icon. */ public int getIconHeight() { return 16 + getAdditionalHeight(); } /** * Paints the icon at the location (x, y). * * @param c the component. * @param g the graphics context. * @param x the x coordinate. * @param y the y coordinate. */ public void paintIcon(Component c, Graphics g, int x, int y) { // TODO: pick up appropriate UI colors g.setColor(Color.black); g.drawLine(x, y, x + 9, y); g.drawLine(x, y + 1, x, y + 15); g.drawLine(x, y + 15, x + 12, y + 15); g.drawLine(x + 12, y + 15, x + 12, y + 6); g.drawLine(x + 12, y + 6, x + 9, y); g.drawLine(x + 7, y + 2, x + 11, y + 6); g.drawLine(x + 8, y + 1, x + 9, y + 1); g.setColor(new Color(204, 204, 255)); g.drawLine(x + 1, y + 1, x + 7, y + 1); g.drawLine(x + 1, y + 1, x + 1, y + 14); g.drawLine(x + 1, y + 14, x + 11, y + 14); g.drawLine(x + 11, y + 14, x + 11, y + 7); g.drawLine(x + 8, y + 2, x + 10, y + 4); } /** * Returns the additional height for the icon. The * {@link #getIconHeight()} method adds this value to the icon height it * returns. Subclasses can override this method to adjust the icon height. * * @return The additional height (<code>0</code> unless overridden). */ public int getAdditionalHeight() { return 0; } /** * Returns the shift (???). * * @return The shift. */ public int getShift() { return 0; } } /** * An icon representing a folder. */ public static class FolderIcon16 implements Icon, Serializable { /** * Returns the width of the icon, in pixels. * * @return The width of the icon. */ public int getIconWidth() { return 16; } /** * Returns the height of the icon, in pixels. The height returned is * <code>16</code> plus the value returned by * {@link #getAdditionalHeight()}. * * @return The height of the icon. */ public int getIconHeight() { return 16 + getAdditionalHeight(); } /** * Paints the icon at the location (x, y). * * @param c the component. * @param g the graphics device. * @param x the x coordinate. * @param y the y coordinate. */ public void paintIcon(Component c, Graphics g, int x, int y) { // TODO: pick up appropriate UI colors g.setColor(Color.black); g.drawLine(x, y + 3, x, y + 12); g.drawLine(x, y + 12, x + 15, y + 12); g.drawLine(x + 15, y + 12, x + 15, y + 2); g.drawLine(x + 14, y + 3, x + 9, y + 3); g.drawLine(x + 8, y + 2, x + 1, y + 2); g.setColor(new Color(204, 204, 255)); g.fillRect(x + 2, y + 4, 7, 8); g.fillRect(x + 9, y + 5, 6, 7); g.setColor(new Color(102, 102, 153)); g.drawLine(x + 9, y + 2, x + 14, y + 2); g.setColor(new Color(50, 50, 120)); g.drawLine(x + 9, y + 1, x + 15, y + 1); g.drawLine(x + 10, y, x + 15, y); } /** * Returns the additional height for the icon. The * {@link #getIconHeight()} method adds this value to the icon height it * returns. Subclasses can override this method to adjust the icon height. * * @return The additional height (<code>0</code> unless overridden). */ public int getAdditionalHeight() { return 0; } /** * Returns the shift (???). * * @return The shift. */ public int getShift() { return 0; } } /** * An icon used by the {@link MetalInternalFrameUI} class when the frame * is displayed as a palette. * * @since 1.3 */ public static class PaletteCloseIcon implements Icon, Serializable, UIResource { /** * Returns the width of the icon, in pixels. * * @return The width of the icon. */ public int getIconWidth() { return 7; } /** * Returns the height of the icon, in pixels. * * @return The height of the icon. */ public int getIconHeight() { return 7; } /** * Paints the icon using colors from the {@link MetalLookAndFeel}. * * @param c the component (ignored). * @param g the graphics device. * @param x the x-coordinate for the top-left of the icon. * @param y the y-coordinate for the top-left of the icon. */ public void paintIcon(Component c, Graphics g, int x, int y) { Color savedColor = g.getColor(); AbstractButton button = (AbstractButton) c; if (button.getModel().isPressed()) g.setColor(MetalLookAndFeel.getBlack()); else g.setColor(MetalLookAndFeel.getControlDarkShadow()); g.fillRect(x + 2, y + 2, 3, 3); g.drawLine(x + 1, y, x + 1, y + 2); g.drawLine(x, y + 1, x + 2, y + 1); g.drawLine(x + 5, y, x + 5, y + 2); g.drawLine(x + 4, y + 1, x + 6, y + 1); g.drawLine(x + 1, y + 4, x + 1, y + 6); g.drawLine(x, y + 5, x + 2, y + 5); g.drawLine(x + 5, y + 4, x + 5, y + 6); g.drawLine(x + 4, y + 5, x + 6, y + 5); g.setColor(MetalLookAndFeel.getControlHighlight()); g.drawLine(x + 2, y + 6, x + 3, y + 5); g.drawLine(x + 5, y + 3, x + 6, y + 2); g.drawLine(x + 6, y + 6, x + 6, y + 6); g.setColor(savedColor); } } /** * An {@link Icon} implementation for {@link JCheckBox}es in the * Metal Look & Feel. * * @author Roman Kennke (roman@kennke.org) */ static class RadioButtonIcon implements Icon, UIResource, Serializable { /** * Returns the width of the icon in pixels. * * @return the width of the icon in pixels */ public int getIconWidth() { return 13; } /** * Returns the height of the icon in pixels. * * @return the height of the icon in pixels */ public int getIconHeight() { return 13; } /** * Paints the icon, taking into account whether or not the component is * enabled, selected and/or armed. * * @param c the Component to draw on (must be an instance of * {@link JRadioButton}) * @param g the Graphics context to draw with * @param x the X position * @param y the Y position */ public void paintIcon(Component c, Graphics g, int x, int y) { if (UIManager.get("RadioButton.gradient") != null) MetalUtils.paintGradient(g, x, y, getIconWidth(), getIconHeight(), SwingConstants.VERTICAL, "RadioButton.gradient"); Color savedColor = g.getColor(); JRadioButton b = (JRadioButton) c; // draw outer circle if (b.isEnabled()) g.setColor(MetalLookAndFeel.getControlDarkShadow()); else g.setColor(MetalLookAndFeel.getControlDisabled()); g.drawLine(x + 2, y + 1, x + 3, y + 1); g.drawLine(x + 4, y, x + 7, y); g.drawLine(x + 8, y + 1, x + 9, y + 1); g.drawLine(x + 10, y + 2, x + 10, y + 3); g.drawLine(x + 11, y + 4, x + 11, y + 7); g.drawLine(x + 10, y + 8, x + 10, y + 9); g.drawLine(x + 8, y + 10, x + 9, y + 10); g.drawLine(x + 4, y + 11, x + 7, y + 11); g.drawLine(x + 2, y + 10, x + 3, y + 10); g.drawLine(x + 1, y + 9, x + 1, y + 8); g.drawLine(x, y + 7, x, y + 4); g.drawLine(x + 1, y + 2, x + 1, y + 3); if (b.getModel().isArmed()) { g.setColor(MetalLookAndFeel.getControlShadow()); g.drawLine(x + 4, y + 1, x + 7, y + 1); g.drawLine(x + 4, y + 10, x + 7, y + 10); g.drawLine(x + 1, y + 4, x + 1, y + 7); g.drawLine(x + 10, y + 4, x + 10, y + 7); g.fillRect(x + 2, y + 2, 8, 8); } else { // only draw inner highlight if not filled if (b.isEnabled()) { g.setColor(MetalLookAndFeel.getWhite()); g.drawLine(x + 2, y + 8, x + 2, y + 9); g.drawLine(x + 1, y + 4, x + 1, y + 7); g.drawLine(x + 2, y + 2, x + 2, y + 3); g.drawLine(x + 3, y + 2, x + 3, y + 2); g.drawLine(x + 4, y + 1, x + 7, y + 1); g.drawLine(x + 8, y + 2, x + 9, y + 2); } } // draw outer highlight if (b.isEnabled()) { g.setColor(MetalLookAndFeel.getWhite()); // outer g.drawLine(x + 10, y + 1, x + 10, y + 1); g.drawLine(x + 11, y + 2, x + 11, y + 3); g.drawLine(x + 12, y + 4, x + 12, y + 7); g.drawLine(x + 11, y + 8, x + 11, y + 9); g.drawLine(x + 10, y + 10, x + 10, y + 10); g.drawLine(x + 8, y + 11, x + 9, y + 11); g.drawLine(x + 4, y + 12, x + 7, y + 12); g.drawLine(x + 2, y + 11, x + 3, y + 11); } if (b.isSelected()) { if (b.isEnabled()) g.setColor(MetalLookAndFeel.getBlack()); else g.setColor(MetalLookAndFeel.getControlDisabled()); g.drawLine(x + 4, y + 3, x + 7, y + 3); g.fillRect(x + 3, y + 4, 6, 4); g.drawLine(x + 4, y + 8, x + 7, y + 8); } g.setColor(savedColor); } } /** * An icon displayed for {@link JRadioButtonMenuItem} components. */ private static class RadioButtonMenuItemIcon implements Icon, Serializable { /** * Creates a new icon instance. */ public RadioButtonMenuItemIcon() { // Nothing to do here. } /** * Returns the width of the icon, in pixels. * * @return The width of the icon. */ public int getIconWidth() { return 10; } /** * Returns the height of the icon, in pixels. * * @return The height of the icon. */ public int getIconHeight() { return 10; } /** * Paints the icon. * * @param c the component. * @param g the graphics device. * @param x the x-coordinate. * @param y the y-coordinate. */ public void paintIcon(Component c, Graphics g, int x, int y) { Color savedColor = g.getColor(); JRadioButtonMenuItem item = (JRadioButtonMenuItem) c;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -