Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
NotationComboBox |
|
| 1.375;1.375 |
1 | /* $Id: NotationComboBox.java 17829 2010-01-12 18:55:38Z linus $ | |
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-2006 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.notation.ui; | |
40 | import java.awt.Dimension; | |
41 | import java.util.ListIterator; | |
42 | ||
43 | import javax.swing.JComboBox; | |
44 | ||
45 | import org.apache.log4j.Logger; | |
46 | import org.argouml.application.events.ArgoEventPump; | |
47 | import org.argouml.application.events.ArgoEventTypes; | |
48 | import org.argouml.application.events.ArgoNotationEvent; | |
49 | import org.argouml.application.events.ArgoNotationEventListener; | |
50 | import org.argouml.notation.Notation; | |
51 | import org.argouml.notation.NotationName; | |
52 | ||
53 | /** | |
54 | * This class provides a self-updating notation combo box. | |
55 | * | |
56 | * @author Thierry Lach | |
57 | * @since 0.9.4 | |
58 | */ | |
59 | public class NotationComboBox | |
60 | extends JComboBox | |
61 | implements ArgoNotationEventListener { | |
62 | ||
63 | /** | |
64 | * Logger. | |
65 | */ | |
66 | 119 | private static final Logger LOG = Logger.getLogger(NotationComboBox.class); |
67 | ||
68 | /** | |
69 | * The instance. | |
70 | */ | |
71 | private static NotationComboBox singleton; | |
72 | ||
73 | /** | |
74 | * @return the singleton | |
75 | */ | |
76 | public static NotationComboBox getInstance() { | |
77 | // Only instantiate when we need it. | |
78 | 0 | if (singleton == null) { |
79 | 0 | singleton = new NotationComboBox(); |
80 | } | |
81 | 0 | return singleton; |
82 | } | |
83 | ||
84 | /** | |
85 | * The constructor. | |
86 | */ | |
87 | public NotationComboBox() { | |
88 | 119 | super(); |
89 | 119 | setEditable(false); |
90 | 119 | setMaximumRowCount(6); |
91 | ||
92 | 119 | Dimension d = getPreferredSize(); |
93 | 119 | d.width = 200; |
94 | 119 | setMaximumSize(d); |
95 | ||
96 | 119 | ArgoEventPump.addListener(ArgoEventTypes.ANY_NOTATION_EVENT, this); |
97 | 119 | refresh(); |
98 | 119 | } |
99 | ||
100 | /* | |
101 | * @see org.argouml.application.events.ArgoNotationEventListener#notationChanged(org.argouml.application.events.ArgoNotationEvent) | |
102 | */ | |
103 | public void notationChanged(ArgoNotationEvent event) { | |
104 | 0 | } |
105 | ||
106 | /* | |
107 | * @see org.argouml.application.events.ArgoNotationEventListener#notationAdded(org.argouml.application.events.ArgoNotationEvent) | |
108 | */ | |
109 | public void notationAdded(ArgoNotationEvent event) { | |
110 | 0 | refresh(); |
111 | 0 | } |
112 | ||
113 | /* | |
114 | * @see org.argouml.application.events.ArgoNotationEventListener#notationRemoved(org.argouml.application.events.ArgoNotationEvent) | |
115 | */ | |
116 | public void notationRemoved(ArgoNotationEvent event) { | |
117 | 0 | } |
118 | ||
119 | /* | |
120 | * @see org.argouml.application.events.ArgoNotationEventListener#notationProviderAdded(org.argouml.application.events.ArgoNotationEvent) | |
121 | */ | |
122 | public void notationProviderAdded(ArgoNotationEvent event) { | |
123 | 0 | } |
124 | ||
125 | /* | |
126 | * @see org.argouml.application.events.ArgoNotationEventListener#notationProviderRemoved(org.argouml.application.events.ArgoNotationEvent) | |
127 | */ | |
128 | public void notationProviderRemoved(ArgoNotationEvent event) { | |
129 | 0 | } |
130 | ||
131 | /** | |
132 | * Refresh the combobox contents. | |
133 | */ | |
134 | public void refresh() { | |
135 | 119 | removeAllItems(); |
136 | 119 | ListIterator iterator = |
137 | Notation.getAvailableNotations().listIterator(); | |
138 | 357 | while (iterator.hasNext()) { |
139 | try { | |
140 | 238 | NotationName nn = (NotationName) iterator.next(); |
141 | 238 | addItem(nn); |
142 | 0 | } catch (Exception e) { |
143 | 0 | LOG.error("Unexpected exception", e); |
144 | 238 | } |
145 | } | |
146 | 119 | setVisible(true); |
147 | 119 | invalidate(); |
148 | 119 | } |
149 | ||
150 | /** | |
151 | * The UID. | |
152 | */ | |
153 | private static final long serialVersionUID = 4059899784583789412L; | |
154 | } |