GNU Classpath (0.95) | |
Frames | No Frames |
1: /* MetalComboBoxEditor.java 2: Copyright (C) 2005 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package javax.swing.plaf.metal; 40: 41: import java.awt.Component; 42: import java.awt.Dimension; 43: import java.awt.Graphics; 44: import java.awt.Insets; 45: 46: import javax.swing.JTextField; 47: import javax.swing.border.AbstractBorder; 48: import javax.swing.plaf.basic.BasicComboBoxEditor; 49: import javax.swing.plaf.metal.MetalLookAndFeel; 50: 51: /** 52: * An editor used by the {@link MetalComboBoxUI} class. 53: */ 54: public class MetalComboBoxEditor extends BasicComboBoxEditor 55: { 56: /** 57: * A border used for the {@link JTextField} component. 58: */ 59: static class MetalComboBoxEditorBorder extends AbstractBorder 60: { 61: /** 62: * Creates a new border instance. 63: */ 64: public MetalComboBoxEditorBorder() 65: { 66: // Nothing to do here. 67: } 68: 69: /** 70: * Paints the border for the specified component. 71: * 72: * @param c the component (ignored). 73: * @param g the graphics device. 74: * @param x the x-coordinate. 75: * @param y the y-coordinate. 76: * @param w the width. 77: * @param h the height. 78: */ 79: public void paintBorder(Component c, Graphics g, int x, int y, int w, 80: int h) 81: { 82: g.translate(x, y); 83: if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme) 84: { 85: g.setColor(MetalLookAndFeel.getControlDarkShadow()); 86: g.drawLine(0, 0, w - 1, 0); 87: g.drawLine(0, 0, 0, h - 1); 88: g.drawLine(0, h - 1, w - 1, h - 1); 89: g.setColor(MetalLookAndFeel.getControlShadow()); 90: g.drawLine(1, 1, w - 2, 1); 91: g.drawLine(1, 1, 1, h - 2); 92: g.drawLine(1, h - 2, w - 1, h - 2); 93: g.drawLine(w - 1, 1, w - 1, h - 2); 94: } 95: else 96: { 97: g.setColor(MetalLookAndFeel.getControlDarkShadow()); 98: g.drawLine(0, 0, w - 1, 0); 99: g.drawLine(0, 0, 0, h - 2); 100: g.drawLine(0, h - 2, w - 1, h - 2); 101: g.setColor(MetalLookAndFeel.getControlHighlight()); 102: g.drawLine(1, 1, w - 1, 1); 103: g.drawLine(1, 1, 1, h - 1); 104: g.drawLine(1, h - 1, w - 1, h - 1); 105: g.setColor(MetalLookAndFeel.getControl()); 106: g.drawLine(1, h - 2, 1, h - 2); 107: } 108: g.translate(-x, -y); 109: } 110: 111: /** 112: * Measures the width of this border. 113: * 114: * @param c the component whose border is to be measured. 115: * 116: * @return an Insets object whose <code>left</code>, <code>right</code>, 117: * <code>top</code> and <code>bottom</code> fields indicate the 118: * width of the border at the respective edge, which is zero 119: * for the default implementation provided by AbstractButton. 120: * 121: * @see #getBorderInsets(java.awt.Component, java.awt.Insets) 122: */ 123: public Insets getBorderInsets(Component c) 124: { 125: return editorBorderInsets; 126: } 127: } 128: 129: /** 130: * A subclass of {@link MetalComboBoxEditor} that implements the 131: * {@link javax.swing.plaf.UIResource} interface. 132: */ 133: public static class UIResource extends MetalComboBoxEditor 134: implements javax.swing.plaf.UIResource 135: { 136: /** 137: * Creates a new instance. 138: */ 139: public UIResource() 140: { 141: // Nothing to do here. 142: } 143: } 144: 145: /** 146: * A special textfield implementation for the MetalComboBoxEditor. 147: */ 148: private class EditorTextField extends JTextField 149: { 150: EditorTextField(String s, int columns) 151: { 152: super(s, columns); 153: } 154: 155: /** 156: * Tests seem to show that the textfield in MetalComboBoxEditors have 157: * a height + 4. 158: */ 159: public Dimension getPreferredSize() 160: { 161: Dimension size = super.getPreferredSize(); 162: size.height += 4; 163: return size; 164: } 165: 166: /** 167: * Tests seem to show that the textfield in MetalComboBoxEditors have 168: * a height + 4. 169: */ 170: public Dimension getMinimumSize() 171: { 172: Dimension size = super.getMinimumSize(); 173: size.height += 4; 174: return size; 175: } 176: } 177: 178: /** The editor's border insets. */ 179: protected static Insets editorBorderInsets = new Insets(2, 2, 2, 0); 180: 181: /** 182: * Creates a new editor. 183: */ 184: public MetalComboBoxEditor() 185: { 186: editor = new EditorTextField("", 9); 187: editor.setBorder(new MetalComboBoxEditorBorder()); 188: } 189: 190: }
GNU Classpath (0.95) |