17 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
182 |
ilm |
4 |
* Copyright 2011-2019 OpenConcerto, by ILM Informatique. All rights reserved.
|
17 |
ilm |
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.laf;
|
|
|
15 |
|
|
|
16 |
import java.awt.Color;
|
|
|
17 |
import java.awt.Container;
|
|
|
18 |
import java.awt.Insets;
|
|
|
19 |
import java.awt.Rectangle;
|
|
|
20 |
import java.beans.PropertyChangeEvent;
|
|
|
21 |
import java.beans.PropertyChangeListener;
|
|
|
22 |
|
|
|
23 |
import javax.swing.Icon;
|
|
|
24 |
import javax.swing.ImageIcon;
|
|
|
25 |
import javax.swing.JButton;
|
|
|
26 |
import javax.swing.JComponent;
|
|
|
27 |
import javax.swing.plaf.ComponentUI;
|
|
|
28 |
import javax.swing.plaf.basic.BasicComboBoxUI;
|
|
|
29 |
import javax.swing.plaf.metal.MetalComboBoxUI;
|
|
|
30 |
|
|
|
31 |
public class IComboBoxUI extends MetalComboBoxUI {
|
|
|
32 |
|
80 |
ilm |
33 |
static int comboBoxButtonSize = 19;
|
17 |
ilm |
34 |
|
80 |
ilm |
35 |
public static ComponentUI createUI(JComponent c) {
|
|
|
36 |
return new IComboBoxUI();
|
|
|
37 |
}
|
17 |
ilm |
38 |
|
80 |
ilm |
39 |
// This is here because of a bug in the compiler.
|
17 |
ilm |
40 |
// When a protected-inner-class-savvy compiler comes out we
|
|
|
41 |
// should move this into MetalComboBoxLayoutManager.
|
80 |
ilm |
42 |
public void layoutComboBox(Container parent, MetalComboBoxLayoutManager manager) {
|
|
|
43 |
|
17 |
ilm |
44 |
if (arrowButton != null) {
|
80 |
ilm |
45 |
Icon icon = arrowButton.getIcon();
|
|
|
46 |
Insets buttonInsets = arrowButton.getInsets();
|
|
|
47 |
Insets insets = comboBox.getInsets();
|
|
|
48 |
int buttonWidth = icon.getIconWidth() + buttonInsets.left + buttonInsets.right;
|
|
|
49 |
arrowButton.setBounds((comboBox.getWidth() - insets.right - buttonWidth), insets.top, buttonWidth, comboBox.getHeight() - insets.top - insets.bottom);
|
|
|
50 |
} else {
|
|
|
51 |
Insets insets = comboBox.getInsets();
|
|
|
52 |
int width = comboBox.getWidth();
|
|
|
53 |
int height = comboBox.getHeight();
|
|
|
54 |
arrowButton.setBounds(insets.left, insets.top, width - (insets.left + insets.right), height - (insets.top + insets.bottom));
|
|
|
55 |
}
|
17 |
ilm |
56 |
|
80 |
ilm |
57 |
if (editor != null /* && MetalLookAndFeel.usingOcean() */) {
|
17 |
ilm |
58 |
Rectangle cvb = rectangleForCurrentValue();
|
|
|
59 |
editor.setBounds(cvb);
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
|
80 |
ilm |
63 |
protected JButton createArrowButton() {
|
|
|
64 |
// JButton button = new XPComboBoxButton(comboBox, //
|
|
|
65 |
// new MetalComboBoxIcon(), comboBox.isEditable(), currentValuePane, listBox);
|
17 |
ilm |
66 |
|
80 |
ilm |
67 |
JButton button = new JButton(new ImageIcon(IComboBoxUI.class.getResource("comboright.png")));
|
|
|
68 |
button.setBackground(new Color(239, 235, 231));
|
17 |
ilm |
69 |
|
80 |
ilm |
70 |
button.setMargin(new Insets(0, 0, 0, 0));
|
|
|
71 |
button.setBorderPainted(false);
|
|
|
72 |
button.setBorder(null);
|
17 |
ilm |
73 |
|
80 |
ilm |
74 |
return button;
|
|
|
75 |
}
|
17 |
ilm |
76 |
|
80 |
ilm |
77 |
public PropertyChangeListener createPropertyChangeListener() {
|
|
|
78 |
return new XPPropertyChangeListener();
|
|
|
79 |
}
|
17 |
ilm |
80 |
|
80 |
ilm |
81 |
/**
|
|
|
82 |
* This inner class is marked "public" due to a compiler bug. This class should be
|
|
|
83 |
* treated as a "protected" inner class. Instantiate it only within subclasses of
|
|
|
84 |
* <FooUI>.
|
|
|
85 |
*/
|
|
|
86 |
public class XPPropertyChangeListener extends BasicComboBoxUI.PropertyChangeHandler {
|
|
|
87 |
public void propertyChange(PropertyChangeEvent e) {
|
|
|
88 |
super.propertyChange(e);
|
|
|
89 |
String propertyName = e.getPropertyName();
|
17 |
ilm |
90 |
|
80 |
ilm |
91 |
if (propertyName.equals("editable")) {
|
|
|
92 |
JButton button = arrowButton;
|
|
|
93 |
// FIXME button.setIconOnly(comboBox.isEditable());
|
|
|
94 |
comboBox.repaint();
|
|
|
95 |
} else if (propertyName.equals("background")) {
|
|
|
96 |
Color color = (Color) e.getNewValue();
|
|
|
97 |
listBox.setBackground(color);
|
17 |
ilm |
98 |
|
80 |
ilm |
99 |
} else if (propertyName.equals("foreground")) {
|
|
|
100 |
Color color = (Color) e.getNewValue();
|
|
|
101 |
listBox.setForeground(color);
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
}
|
17 |
ilm |
105 |
|
80 |
ilm |
106 |
/**
|
|
|
107 |
* As of Java 2 platform v1.4 this method is no longer used. Do not call or override. All the
|
|
|
108 |
* functionality of this method is in the MetalPropertyChangeListener.
|
|
|
109 |
*
|
|
|
110 |
* @deprecated As of Java 2 platform v1.4.
|
|
|
111 |
*/
|
|
|
112 |
protected void editablePropertyChanged(PropertyChangeEvent e) {
|
|
|
113 |
}
|
17 |
ilm |
114 |
|
80 |
ilm |
115 |
/*
|
|
|
116 |
* protected LayoutManager createLayoutManager() { return new MetouiaComboBoxLayoutManager(); }
|
|
|
117 |
*/
|
17 |
ilm |
118 |
|
80 |
ilm |
119 |
/**
|
|
|
120 |
* This inner class is marked "public" due to a compiler bug. This class should be
|
|
|
121 |
* treated as a "protected" inner class. Instantiate it only within subclasses of
|
|
|
122 |
* <FooUI>.
|
|
|
123 |
*/
|
|
|
124 |
/*
|
|
|
125 |
* public class MetouiaComboBoxLayoutManager implements LayoutManager { public void
|
|
|
126 |
* addLayoutComponent(String name, Component comp) { }
|
|
|
127 |
*
|
|
|
128 |
* public void removeLayoutComponent(Component comp) { }
|
|
|
129 |
*
|
|
|
130 |
* public Dimension preferredLayoutSize(Container parent) { JComboBox cb = (JComboBox) parent;
|
|
|
131 |
* return parent.getPreferredSize(); }
|
|
|
132 |
*
|
|
|
133 |
* public Dimension minimumLayoutSize(Container parent) { JComboBox cb = (JComboBox) parent;
|
|
|
134 |
* return parent.getMinimumSize(); }
|
|
|
135 |
*
|
|
|
136 |
* public void layoutContainer(Container parent) { JComboBox cb = (JComboBox) parent; int width
|
|
|
137 |
* = cb.getWidth(); int height = cb.getHeight();
|
|
|
138 |
*
|
|
|
139 |
* Rectangle cvb;
|
|
|
140 |
*
|
|
|
141 |
* if (comboBox.isEditable()) { if (arrowButton != null) { arrowButton.setBounds(width -
|
|
|
142 |
* comboBoxButtonSize, 0, comboBoxButtonSize, height); } if (editor != null) { cvb =
|
|
|
143 |
* rectangleForCurrentValue2(); editor.setBounds(cvb); } } else { arrowButton.setBounds(0, 0,
|
|
|
144 |
* width, height); } } }
|
|
|
145 |
*
|
|
|
146 |
* protected Rectangle rectangleForCurrentValue2() { int width = comboBox.getWidth(); int height
|
|
|
147 |
* = comboBox.getHeight(); Insets insets = getInsets(); int buttonSize = height - (insets.top +
|
|
|
148 |
* insets.bottom); if (arrowButton != null) { buttonSize = comboBoxButtonSize; } if
|
|
|
149 |
* (comboBox.getComponentOrientation().isLeftToRight()) { return new Rectangle(insets.left,
|
|
|
150 |
* insets.top, width - (insets.left + insets.right + buttonSize), height - (insets.top +
|
|
|
151 |
* insets.bottom)); } else { return new Rectangle(insets.left + buttonSize, insets.top, width -
|
|
|
152 |
* (insets.left + insets.right + buttonSize), height - (insets.top + insets.bottom)); } }
|
|
|
153 |
*
|
|
|
154 |
*
|
|
|
155 |
* protected void removeListeners() { if (propertyChangeListener != null) {
|
|
|
156 |
* comboBox.removePropertyChangeListener(propertyChangeListener); } }
|
|
|
157 |
*
|
|
|
158 |
* // These two methods were overloaded and made public. This was probably a // mistake in the
|
|
|
159 |
* implementation. The functionality that they used to // provide is no longer necessary and
|
|
|
160 |
* should be removed. However, // removing them will create an uncompatible API change.
|
|
|
161 |
*
|
|
|
162 |
* public void configureEditor() { super.configureEditor(); }
|
|
|
163 |
*
|
|
|
164 |
* public void unconfigureEditor() { super.unconfigureEditor(); }
|
|
|
165 |
*
|
|
|
166 |
* public Dimension getMinimumSize(JComponent c) { if (!isMinimumSizeDirty) { return new
|
|
|
167 |
* Dimension(cachedMinimumSize); }
|
|
|
168 |
*
|
|
|
169 |
* Dimension size = null;
|
|
|
170 |
*
|
|
|
171 |
* if (!comboBox.isEditable() && arrowButton != null ) {
|
|
|
172 |
*
|
|
|
173 |
* JButton button = arrowButton; Insets buttonInsets = new Insets(0, 0, 0, 0); Insets insets =
|
|
|
174 |
* comboBox.getInsets();
|
|
|
175 |
*
|
|
|
176 |
* size = getDisplaySize(); size.width += comboBoxButtonSize + insets.left + insets.right; //
|
|
|
177 |
* Hack size.width += buttonInsets.left + buttonInsets.right; size.width += buttonInsets.right +
|
|
|
178 |
* 9;// FIXME button.getComboIcon().getIconWidth(); size.height += insets.top + insets.bottom;
|
|
|
179 |
* size.height += buttonInsets.top + buttonInsets.bottom; size.height = Math.max(21,
|
|
|
180 |
* size.height); } else if (comboBox.isEditable() && arrowButton != null && editor != null) {
|
|
|
181 |
* size = super.getMinimumSize(c); Insets margin = arrowButton.getMargin(); Insets insets =
|
|
|
182 |
* comboBox.getInsets(); if (editor instanceof JComponent) { Insets editorInsets = ((JComponent)
|
|
|
183 |
* editor).getInsets(); } size.height += margin.top + margin.bottom; size.height += insets.top +
|
|
|
184 |
* insets.bottom;
|
|
|
185 |
*
|
|
|
186 |
* // size.height = Math.max(20,size.height); } else { size = super.getMinimumSize(c); }
|
|
|
187 |
*
|
|
|
188 |
* cachedMinimumSize.setSize(size.width, size.height); isMinimumSizeDirty = false;
|
|
|
189 |
*
|
|
|
190 |
* return new Dimension(cachedMinimumSize); }
|
|
|
191 |
*/
|
17 |
ilm |
192 |
}
|