windowsiconfactory.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 878 行 · 第 1/3 页
JAVA
878 行
}; private static class CheckBoxIcon implements Icon, Serializable { final static int csize = 13; public void paintIcon(Component c, Graphics g, int x, int y) { JCheckBox cb = (JCheckBox) c; ButtonModel model = cb.getModel(); XPStyle xp = XPStyle.getXP(); if (xp != null) { State state; if (model.isSelected()) { state = State.CHECKEDNORMAL; if (!model.isEnabled()) { state = State.CHECKEDDISABLED; } else if (model.isPressed() && model.isArmed()) { state = State.CHECKEDPRESSED; } else if (model.isRollover()) { state = State.CHECKEDHOT; } } else { state = State.UNCHECKEDNORMAL; if (!model.isEnabled()) { state = State.UNCHECKEDDISABLED; } else if (model.isPressed() && model.isArmed()) { state = State.UNCHECKEDPRESSED; } else if (model.isRollover()) { state = State.UNCHECKEDHOT; } } Part part = Part.BP_CHECKBOX; xp.getSkin(c, part).paintSkin(g, x, y, state); } else { // outer bevel if(!cb.isBorderPaintedFlat()) { // Outer top/left g.setColor(UIManager.getColor("CheckBox.shadow")); g.drawLine(x, y, x+11, y); g.drawLine(x, y+1, x, y+11); // Outer bottom/right g.setColor(UIManager.getColor("CheckBox.highlight")); g.drawLine(x+12, y, x+12, y+12); g.drawLine(x, y+12, x+11, y+12); // Inner top.left g.setColor(UIManager.getColor("CheckBox.darkShadow")); g.drawLine(x+1, y+1, x+10, y+1); g.drawLine(x+1, y+2, x+1, y+10); // Inner bottom/right g.setColor(UIManager.getColor("CheckBox.light")); g.drawLine(x+1, y+11, x+11, y+11); g.drawLine(x+11, y+1, x+11, y+10); // inside box if((model.isPressed() && model.isArmed()) || !model.isEnabled()) { g.setColor(UIManager.getColor("CheckBox.background")); } else { g.setColor(UIManager.getColor("CheckBox.interiorBackground")); } g.fillRect(x+2, y+2, csize-4, csize-4); } else { g.setColor(UIManager.getColor("CheckBox.shadow")); g.drawRect(x+1, y+1, csize-3, csize-3); if((model.isPressed() && model.isArmed()) || !model.isEnabled()) { g.setColor(UIManager.getColor("CheckBox.background")); } else { g.setColor(UIManager.getColor("CheckBox.interiorBackground")); } g.fillRect(x+2, y+2, csize-4, csize-4); } if(model.isEnabled()) { g.setColor(UIManager.getColor("CheckBox.darkShadow")); } else { g.setColor(UIManager.getColor("CheckBox.shadow")); } // paint check if (model.isSelected()) { g.drawLine(x+9, y+3, x+9, y+3); g.drawLine(x+8, y+4, x+9, y+4); g.drawLine(x+7, y+5, x+9, y+5); g.drawLine(x+6, y+6, x+8, y+6); g.drawLine(x+3, y+7, x+7, y+7); g.drawLine(x+4, y+8, x+6, y+8); g.drawLine(x+5, y+9, x+5, y+9); g.drawLine(x+3, y+5, x+3, y+5); g.drawLine(x+3, y+6, x+4, y+6); } } } public int getIconWidth() { XPStyle xp = XPStyle.getXP(); if (xp != null) { return xp.getSkin(null, Part.BP_CHECKBOX).getWidth(); } else { return csize; } } public int getIconHeight() { XPStyle xp = XPStyle.getXP(); if (xp != null) { return xp.getSkin(null, Part.BP_CHECKBOX).getHeight(); } else { return csize; } } } private static class RadioButtonIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); XPStyle xp = XPStyle.getXP(); if (xp != null) { Part part = Part.BP_RADIOBUTTON; Skin skin = xp.getSkin(b, part); State state; int index = 0; if (model.isSelected()) { state = State.CHECKEDNORMAL; if (!model.isEnabled()) { state = State.CHECKEDDISABLED; } else if (model.isPressed() && model.isArmed()) { state = State.CHECKEDPRESSED; } else if (model.isRollover()) { state = State.CHECKEDHOT; } } else { state = State.UNCHECKEDNORMAL; if (!model.isEnabled()) { state = State.UNCHECKEDDISABLED; } else if (model.isPressed() && model.isArmed()) { state = State.UNCHECKEDPRESSED; } else if (model.isRollover()) { state = State.UNCHECKEDHOT; } } skin.paintSkin(g, x, y, state); } else { // fill interior if((model.isPressed() && model.isArmed()) || !model.isEnabled()) { g.setColor(UIManager.getColor("RadioButton.background")); } else { g.setColor(UIManager.getColor("RadioButton.interiorBackground")); } g.fillRect(x+2, y+2, 8, 8); // outter left arc g.setColor(UIManager.getColor("RadioButton.shadow")); g.drawLine(x+4, y+0, x+7, y+0); g.drawLine(x+2, y+1, x+3, y+1); g.drawLine(x+8, y+1, x+9, y+1); g.drawLine(x+1, y+2, x+1, y+3); g.drawLine(x+0, y+4, x+0, y+7); g.drawLine(x+1, y+8, x+1, y+9); // outter right arc g.setColor(UIManager.getColor("RadioButton.highlight")); g.drawLine(x+2, y+10, x+3, y+10); g.drawLine(x+4, y+11, x+7, y+11); g.drawLine(x+8, y+10, x+9, y+10); g.drawLine(x+10, y+9, x+10, y+8); g.drawLine(x+11, y+7, x+11, y+4); g.drawLine(x+10, y+3, x+10, y+2); // inner left arc g.setColor(UIManager.getColor("RadioButton.darkShadow")); g.drawLine(x+4, y+1, x+7, y+1); g.drawLine(x+2, y+2, x+3, y+2); g.drawLine(x+8, y+2, x+9, y+2); g.drawLine(x+2, y+3, x+2, y+3); g.drawLine(x+1, y+4, x+1, y+7); g.drawLine(x+2, y+8, x+2, y+8); // inner right arc g.setColor(UIManager.getColor("RadioButton.light")); g.drawLine(x+2, y+9, x+3, y+9); g.drawLine(x+4, y+10, x+7, y+10); g.drawLine(x+8, y+9, x+9, y+9); g.drawLine(x+9, y+8, x+9, y+8); g.drawLine(x+10, y+7, x+10, y+4); g.drawLine(x+9, y+3, x+9, y+3); // indicate whether selected or not if(model.isSelected()) { g.setColor(UIManager.getColor("RadioButton.darkShadow")); g.fillRect(x+4, y+5, 4, 2); g.fillRect(x+5, y+4, 2, 4); } } } public int getIconWidth() { XPStyle xp = XPStyle.getXP(); if (xp != null) { return xp.getSkin(null, Part.BP_RADIOBUTTON).getWidth(); } else { return 13; } } public int getIconHeight() { XPStyle xp = XPStyle.getXP(); if (xp != null) { return xp.getSkin(null, Part.BP_RADIOBUTTON).getHeight(); } else { return 13; } } } // end class RadioButtonIcon private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); boolean isSelected = model.isSelected(); if (isSelected) { y = y - getIconHeight() / 2; g.drawLine(x+9, y+3, x+9, y+3); g.drawLine(x+8, y+4, x+9, y+4); g.drawLine(x+7, y+5, x+9, y+5); g.drawLine(x+6, y+6, x+8, y+6); g.drawLine(x+3, y+7, x+7, y+7); g.drawLine(x+4, y+8, x+6, y+8); g.drawLine(x+5, y+9, x+5, y+9); g.drawLine(x+3, y+5, x+3, y+5); g.drawLine(x+3, y+6, x+4, y+6); } } public int getIconWidth() { return 9; } public int getIconHeight() { return 9; } } // End class CheckBoxMenuItemIcon private static class RadioButtonMenuItemIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); if (b.isSelected() == true) { g.fillArc(0,0,getIconWidth()-2, getIconHeight()-2, 0, 360); } } public int getIconWidth() { return 12; } public int getIconHeight() { return 12; } } // End class RadioButtonMenuItemIcon private static class MenuItemCheckIcon implements Icon, UIResource, Serializable{ public void paintIcon(Component c, Graphics g, int x, int y) { /* For debugging: Color oldColor = g.getColor(); g.setColor(Color.orange); g.fill3DRect(x,y,getIconWidth(), getIconHeight(), true); g.setColor(oldColor); */ } public int getIconWidth() { return 9; } public int getIconHeight() { return 9; } } // End class MenuItemCheckIcon private static class MenuItemArrowIcon implements Icon, UIResource, Serializable { public void paintIcon(Component c, Graphics g, int x, int y) { /* For debugging: Color oldColor = g.getColor(); g.setColor(Color.green); g.fill3DRect(x,y,getIconWidth(), getIconHeight(), true); g.setColor(oldColor); */ } public int getIconWidth() { return 4; } public int getIconHeight() { return 8; } } // End class MenuItemArrowIcon
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?