Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
StylePanel |
|
| 1.411764705882353;1.412 |
1 | /* $Id: StylePanel.java 17924 2010-01-27 19:50:58Z 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-2008 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.ui; | |
40 | ||
41 | import java.awt.event.ActionEvent; | |
42 | import java.awt.event.ActionListener; | |
43 | import java.awt.event.ItemEvent; | |
44 | import java.awt.event.ItemListener; | |
45 | import java.beans.PropertyChangeEvent; | |
46 | ||
47 | import javax.swing.event.DocumentEvent; | |
48 | import javax.swing.event.DocumentListener; | |
49 | import javax.swing.event.ListSelectionEvent; | |
50 | import javax.swing.event.ListSelectionListener; | |
51 | ||
52 | import org.apache.log4j.Logger; | |
53 | import org.argouml.application.api.AbstractArgoJPanel; | |
54 | import org.argouml.i18n.Translator; | |
55 | import org.argouml.model.Model; | |
56 | import org.argouml.ui.targetmanager.TargetEvent; | |
57 | import org.argouml.uml.diagram.ArgoDiagram; | |
58 | import org.argouml.uml.diagram.DiagramUtils; | |
59 | import org.tigris.gef.presentation.Fig; | |
60 | import org.tigris.swidgets.LabelledLayout; | |
61 | ||
62 | /** | |
63 | * The Presentation panel - formerly called style panel. | |
64 | * | |
65 | */ | |
66 | public class StylePanel | |
67 | extends AbstractArgoJPanel | |
68 | implements TabFigTarget, | |
69 | ItemListener, DocumentListener, ListSelectionListener, | |
70 | ActionListener { | |
71 | /** | |
72 | * Logger. | |
73 | */ | |
74 | 0 | private static final Logger LOG = Logger.getLogger(StylePanel.class); |
75 | ||
76 | private Fig panelTarget; | |
77 | ||
78 | /** | |
79 | * The constructor. | |
80 | * | |
81 | * @param tag The localization tag for the panel title. | |
82 | */ | |
83 | public StylePanel(String tag) { | |
84 | 0 | super(Translator.localize(tag)); |
85 | 0 | setLayout(new LabelledLayout()); |
86 | 0 | } |
87 | ||
88 | /** | |
89 | * Add a separator. | |
90 | */ | |
91 | protected final void addSeperator() { | |
92 | 0 | add(LabelledLayout.getSeperator()); |
93 | 0 | } |
94 | ||
95 | /** | |
96 | * This method must be overridden by implementors if they don't want to | |
97 | * refresh the whole style panel every time a property change events is | |
98 | * fired. The default behavior is to always call {@link #refresh()}. | |
99 | * @see #refresh() | |
100 | */ | |
101 | public void refresh(PropertyChangeEvent e) { | |
102 | 0 | refresh(); |
103 | 0 | } |
104 | ||
105 | /* | |
106 | * @see org.argouml.ui.TabTarget#setTarget(java.lang.Object) | |
107 | */ | |
108 | public void setTarget(Object t) { | |
109 | 0 | if (!(t instanceof Fig)) { |
110 | 0 | if (Model.getFacade().isAUMLElement(t)) { |
111 | 0 | ArgoDiagram diagram = DiagramUtils.getActiveDiagram(); |
112 | 0 | if (diagram != null) { |
113 | 0 | t = diagram.presentationFor(t); |
114 | } | |
115 | 0 | if (!(t instanceof Fig)) { |
116 | 0 | return; |
117 | } | |
118 | 0 | } else { |
119 | 0 | return; |
120 | } | |
121 | ||
122 | } | |
123 | 0 | panelTarget = (Fig) t; |
124 | 0 | refresh(); |
125 | 0 | } |
126 | ||
127 | /* | |
128 | * @see org.argouml.ui.TabTarget#getTarget() | |
129 | */ | |
130 | public Object getTarget() { | |
131 | 0 | return panelTarget; |
132 | } | |
133 | ||
134 | /* | |
135 | * @see org.argouml.ui.TabTarget#refresh() | |
136 | */ | |
137 | public void refresh() { | |
138 | //_tableModel.setTarget(_target); | |
139 | //_table.setModel(_tableModel); | |
140 | 0 | } |
141 | ||
142 | /* | |
143 | * Style panels only apply when a Fig is selected. | |
144 | * | |
145 | * @see org.argouml.ui.TabTarget#shouldBeEnabled(java.lang.Object) | |
146 | */ | |
147 | public boolean shouldBeEnabled(Object target) { | |
148 | 0 | ArgoDiagram diagram = DiagramUtils.getActiveDiagram(); |
149 | 0 | target = |
150 | (target instanceof Fig) ? target : diagram.getContainingFig(target); | |
151 | 0 | return (target instanceof Fig); |
152 | } | |
153 | ||
154 | /* | |
155 | * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent) | |
156 | */ | |
157 | public void insertUpdate(DocumentEvent e) { | |
158 | 0 | LOG.debug(getClass().getName() + " insert"); |
159 | 0 | } |
160 | ||
161 | /* | |
162 | * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent) | |
163 | */ | |
164 | public void removeUpdate(DocumentEvent e) { | |
165 | 0 | insertUpdate(e); |
166 | 0 | } |
167 | ||
168 | /* | |
169 | * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent) | |
170 | */ | |
171 | public void changedUpdate(DocumentEvent e) { | |
172 | 0 | } |
173 | ||
174 | /* | |
175 | * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) | |
176 | */ | |
177 | public void itemStateChanged(ItemEvent e) { | |
178 | 0 | } |
179 | ||
180 | /* | |
181 | * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent) | |
182 | */ | |
183 | public void valueChanged(ListSelectionEvent lse) { | |
184 | 0 | } |
185 | ||
186 | /* | |
187 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) | |
188 | */ | |
189 | public void actionPerformed(ActionEvent ae) { | |
190 | // Object src = ae.getSource(); | |
191 | //if (src == _config) doConfig(); | |
192 | 0 | } |
193 | ||
194 | /* | |
195 | * @see org.argouml.ui.targetmanager.TargetListener#targetAdded( | |
196 | * TargetEvent) | |
197 | */ | |
198 | public void targetAdded(TargetEvent e) { | |
199 | 0 | setTarget(e.getNewTarget()); |
200 | 0 | } |
201 | ||
202 | /* | |
203 | * @see org.argouml.ui.targetmanager.TargetListener#targetRemoved( | |
204 | * TargetEvent) | |
205 | */ | |
206 | public void targetRemoved(TargetEvent e) { | |
207 | 0 | setTarget(e.getNewTarget()); |
208 | ||
209 | 0 | } |
210 | ||
211 | /* | |
212 | * @see org.argouml.ui.targetmanager.TargetListener#targetSet(TargetEvent) | |
213 | */ | |
214 | public void targetSet(TargetEvent e) { | |
215 | 0 | setTarget(e.getNewTarget()); |
216 | ||
217 | 0 | } |
218 | ||
219 | /** | |
220 | * @return Returns the target of the Style Panel. | |
221 | */ | |
222 | protected Fig getPanelTarget() { | |
223 | 0 | return panelTarget; |
224 | } | |
225 | ||
226 | /** | |
227 | * The UID. | |
228 | */ | |
229 | private static final long serialVersionUID = 2183676111107689482L; | |
230 | } /* end class StylePanel */ |