Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UMLComboBoxNavigator |
|
| 1.8333333333333333;1.833 |
1 | /* $Id: UMLComboBoxNavigator.java 18735 2010-09-13 11:37:06Z bobtarling $ | |
2 | ***************************************************************************** | |
3 | * Copyright (c) 2009 Contributors - see below | |
4 | * All rights reserved. This program and the accompanying materials | |
5 | * are made available under the terms of the Eclipse Public License v1.0 | |
6 | * which accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * tfmorris | |
11 | ***************************************************************************** | |
12 | * | |
13 | * Some portions of this file was previously release using the BSD License: | |
14 | */ | |
15 | ||
16 | // Copyright (c) 1996-2007 The Regents of the University of California. All | |
17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
18 | // software and its documentation without fee, and without a written | |
19 | // agreement is hereby granted, provided that the above copyright notice | |
20 | // and this paragraph appear in all copies. This software program and | |
21 | // documentation are copyrighted by The Regents of the University of | |
22 | // California. The software program and documentation are supplied "AS | |
23 | // IS", without any accompanying services from The Regents. The Regents | |
24 | // does not warrant that the operation of the program will be | |
25 | // uninterrupted or error-free. The end-user understands that the program | |
26 | // was developed for research purposes and is advised not to rely | |
27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
38 | ||
39 | package org.argouml.uml.ui; | |
40 | ||
41 | import java.awt.BorderLayout; | |
42 | import java.awt.Dimension; | |
43 | import java.awt.event.ActionListener; | |
44 | import java.awt.event.ItemEvent; | |
45 | import java.awt.event.ItemListener; | |
46 | ||
47 | import javax.swing.ImageIcon; | |
48 | import javax.swing.JButton; | |
49 | import javax.swing.JComboBox; | |
50 | import javax.swing.JPanel; | |
51 | ||
52 | import org.argouml.application.helpers.ResourceLoaderWrapper; | |
53 | import org.argouml.ui.targetmanager.TargetManager; | |
54 | ||
55 | /** | |
56 | * This class implements a panel that adds a navigation button to the right of | |
57 | * the combo box | |
58 | * | |
59 | * @author Curt Arnold | |
60 | * @since 0.9 | |
61 | * @deprecated in 0.31.5 by Bob Tarling. Property panel controls are now | |
62 | * internal to the property panel component | |
63 | */ | |
64 | @Deprecated | |
65 | public class UMLComboBoxNavigator extends JPanel implements ActionListener, | |
66 | ItemListener { | |
67 | ||
68 | 900 | private static ImageIcon icon = ResourceLoaderWrapper |
69 | .lookupIconResource("ComboNav"); | |
70 | ||
71 | private JComboBox theComboBox; | |
72 | ||
73 | private JButton theButton; | |
74 | ||
75 | ||
76 | /** | |
77 | * Constructor | |
78 | * | |
79 | * @param tooltip | |
80 | * Tooltip key for button | |
81 | * @param box | |
82 | * Associated combo box | |
83 | */ | |
84 | public UMLComboBoxNavigator(String tooltip, JComboBox box) { | |
85 | 2289 | super(new BorderLayout()); |
86 | 2289 | theButton = new JButton(icon); |
87 | 2289 | theComboBox = box; |
88 | 2289 | theButton.setPreferredSize(new Dimension(icon.getIconWidth() + 6, icon |
89 | .getIconHeight() + 6)); | |
90 | 2289 | theButton.setToolTipText(tooltip); |
91 | 2289 | theButton.addActionListener(this); |
92 | 2289 | box.addActionListener(this); |
93 | 2289 | box.addItemListener(this); |
94 | 2289 | add(theComboBox, BorderLayout.CENTER); |
95 | 2289 | add(theButton, BorderLayout.EAST); |
96 | 2289 | Object item = theComboBox.getSelectedItem(); |
97 | 2289 | setButtonEnabled(item); |
98 | 2289 | } |
99 | ||
100 | /** | |
101 | * Enforce that the preferred height is the minimum height. | |
102 | * This works around a bug in Windows LAF of JRE5 where a change | |
103 | * in the preferred/min size of a combo has changed and has a knock | |
104 | * on effect here. | |
105 | * If the layout manager for prop panels finds the preferred | |
106 | * height is greater than the minimum height then it will allow | |
107 | * this component to resize in error. | |
108 | * See issue 4333 - Sun has now fixed this bug in JRE6 and so this | |
109 | * method can be removed once JRE5 is no longer supported. | |
110 | * @return the preferred size | |
111 | */ | |
112 | @Override | |
113 | public Dimension getPreferredSize() { | |
114 | 4008 | return new Dimension( |
115 | super.getPreferredSize().width, | |
116 | getMinimumSize().height); | |
117 | } | |
118 | ||
119 | ||
120 | ||
121 | /** | |
122 | * Fired when the button is pushed. Navigates to the currently selected item | |
123 | * in the combo box. | |
124 | * | |
125 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) | |
126 | */ | |
127 | public void actionPerformed(final java.awt.event.ActionEvent event) { | |
128 | // button action: | |
129 | 0 | if (event.getSource() == theButton) { |
130 | 0 | Object item = theComboBox.getSelectedItem(); |
131 | 0 | if (item != null) { |
132 | 0 | TargetManager.getInstance().setTarget(item); |
133 | } | |
134 | ||
135 | } | |
136 | 0 | if (event.getSource() == theComboBox) { |
137 | 0 | Object item = theComboBox.getSelectedItem(); |
138 | 0 | setButtonEnabled(item); |
139 | } | |
140 | 0 | } |
141 | ||
142 | public void itemStateChanged(ItemEvent event) { | |
143 | 3033 | if (event.getSource() == theComboBox) { |
144 | 3033 | Object item = theComboBox.getSelectedItem(); |
145 | 3033 | setButtonEnabled(item); |
146 | ||
147 | } | |
148 | 3033 | } |
149 | ||
150 | private void setButtonEnabled(Object item) { | |
151 | 5322 | if (item != null) { |
152 | 3033 | theButton.setEnabled(true); |
153 | } else { | |
154 | 2289 | theButton.setEnabled(false); |
155 | } | |
156 | 5322 | } |
157 | ||
158 | public void setEnabled(boolean enabled) { | |
159 | 0 | theComboBox.setEnabled(enabled); |
160 | 0 | theComboBox.setEditable(enabled); |
161 | 0 | } |
162 | } |