001 /* MetalComboBoxEditor.java 002 Copyright (C) 2005 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package javax.swing.plaf.metal; 040 041 import java.awt.Component; 042 import java.awt.Dimension; 043 import java.awt.Graphics; 044 import java.awt.Insets; 045 046 import javax.swing.JTextField; 047 import javax.swing.border.AbstractBorder; 048 import javax.swing.plaf.basic.BasicComboBoxEditor; 049 import javax.swing.plaf.metal.MetalLookAndFeel; 050 051 /** 052 * An editor used by the {@link MetalComboBoxUI} class. 053 */ 054 public class MetalComboBoxEditor extends BasicComboBoxEditor 055 { 056 /** 057 * A border used for the {@link JTextField} component. 058 */ 059 static class MetalComboBoxEditorBorder extends AbstractBorder 060 { 061 /** 062 * Creates a new border instance. 063 */ 064 public MetalComboBoxEditorBorder() 065 { 066 // Nothing to do here. 067 } 068 069 /** 070 * Paints the border for the specified component. 071 * 072 * @param c the component (ignored). 073 * @param g the graphics device. 074 * @param x the x-coordinate. 075 * @param y the y-coordinate. 076 * @param w the width. 077 * @param h the height. 078 */ 079 public void paintBorder(Component c, Graphics g, int x, int y, int w, 080 int h) 081 { 082 g.translate(x, y); 083 if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme) 084 { 085 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 086 g.drawLine(0, 0, w - 1, 0); 087 g.drawLine(0, 0, 0, h - 1); 088 g.drawLine(0, h - 1, w - 1, h - 1); 089 g.setColor(MetalLookAndFeel.getControlShadow()); 090 g.drawLine(1, 1, w - 2, 1); 091 g.drawLine(1, 1, 1, h - 2); 092 g.drawLine(1, h - 2, w - 1, h - 2); 093 g.drawLine(w - 1, 1, w - 1, h - 2); 094 } 095 else 096 { 097 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 098 g.drawLine(0, 0, w - 1, 0); 099 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 }