Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractArgoJPanel |
|
| 1.5454545454545454;1.545 |
1 | /* $Id: AbstractArgoJPanel.java 17995 2010-02-13 17:44:28Z 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-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.application.api; | |
40 | ||
41 | import java.awt.BorderLayout; | |
42 | import java.awt.Point; | |
43 | import java.awt.Rectangle; | |
44 | ||
45 | import javax.swing.Icon; | |
46 | import javax.swing.JDialog; | |
47 | import javax.swing.JPanel; | |
48 | import javax.swing.JTabbedPane; | |
49 | import javax.swing.SwingUtilities; | |
50 | ||
51 | import org.apache.log4j.Logger; | |
52 | import org.argouml.i18n.Translator; | |
53 | import org.argouml.util.ArgoFrame; | |
54 | import org.tigris.swidgets.Orientable; | |
55 | import org.tigris.swidgets.Orientation; | |
56 | ||
57 | /** | |
58 | * A subclass of JPanel that can act as a tab in the DetailsPane or | |
59 | * MultiEditorPane. Added functionality:<p> | |
60 | * | |
61 | * Spawning: When the tab is double-clicked, this JPanel will generate a | |
62 | * separate window of the same size and with the same contents. This is almost | |
63 | * like "tearing off" a tab.<p> | |
64 | * | |
65 | * TODO: Spawning of windows disabled in spawn()<p> | |
66 | * | |
67 | * Title: This JPanel keeps track of its own title.<p> | |
68 | * | |
69 | * Icon: This JPanel keeps track of its own icon; i.e. an arrow pointing to | |
70 | * the panel that it gives details of.<p> | |
71 | * | |
72 | * Orientation: This JPanel is Orientable.<p> | |
73 | * | |
74 | * Cloning: This JPanel may be cloned.<p> | |
75 | * | |
76 | * This class used to be named TabSpawnable. | |
77 | * Renamed since it is not a Tab, but a Panel, and being spawnable is | |
78 | * not any more its main purpose. | |
79 | */ | |
80 | public abstract class AbstractArgoJPanel extends JPanel | |
81 | implements Cloneable, Orientable { | |
82 | /** | |
83 | * Logger. | |
84 | */ | |
85 | 900 | private static final Logger LOG = |
86 | Logger.getLogger(AbstractArgoJPanel.class); | |
87 | ||
88 | private static final int OVERLAPP = 30; | |
89 | ||
90 | 11289 | private String title = "untitled"; |
91 | ||
92 | 11289 | private Icon icon = null; |
93 | ||
94 | /** | |
95 | * if true, remove tab from parent JTabbedPane. | |
96 | */ | |
97 | 11289 | private boolean tear = false; |
98 | ||
99 | private Orientation orientation; | |
100 | ||
101 | /** | |
102 | * @return the orientation | |
103 | */ | |
104 | public Orientation getOrientation() { | |
105 | 0 | return orientation; |
106 | } | |
107 | //////////////////////////////////////////////////////////////// | |
108 | // constructor | |
109 | ||
110 | /** | |
111 | * The constructor. | |
112 | * | |
113 | */ | |
114 | public AbstractArgoJPanel() { | |
115 | 0 | this(Translator.localize("tab.untitled"), false); |
116 | 0 | } |
117 | ||
118 | /** | |
119 | * The constructor. | |
120 | * | |
121 | * @param title The name as a localized string. | |
122 | */ | |
123 | // TODO: Review all callers to make sure that they localize the title | |
124 | public AbstractArgoJPanel(String title) { | |
125 | 11289 | this(title, false); |
126 | 11289 | } |
127 | ||
128 | /** | |
129 | * The constructor. | |
130 | * | |
131 | * @param title The name (a localized string). | |
132 | * @param t if true, remove tab from parent JTabbedPane | |
133 | */ | |
134 | // TODO: Review all callers to make sure that they localize the title | |
135 | // In process by Harold Braun 20070912 | |
136 | 11289 | public AbstractArgoJPanel(String title, boolean t) { |
137 | 11289 | setTitle(title); |
138 | 11289 | tear = t; |
139 | 11289 | } |
140 | ||
141 | /** | |
142 | * This is not a real clone since it doesn't copy anything from the object | |
143 | * it is cloning. The {@link #spawn} method copies the title and in | |
144 | * some cases also the Target. | |
145 | * | |
146 | * @return the new object or null if not possible. | |
147 | */ | |
148 | public Object clone() { | |
149 | try { | |
150 | 0 | return this.getClass().newInstance(); |
151 | 0 | } catch (Exception ex) { |
152 | 0 | LOG.error("exception in clone()", ex); |
153 | } | |
154 | 0 | return null; |
155 | } | |
156 | ||
157 | /* | |
158 | * @see org.tigris.swidgets.Orientable#setOrientation(Orientation) | |
159 | */ | |
160 | public void setOrientation(Orientation o) { | |
161 | 3600 | this.orientation = o; |
162 | 3600 | } |
163 | ||
164 | //////////////////////////////////////////////////////////////// | |
165 | // accessors | |
166 | ||
167 | /** | |
168 | * @return The title of the panel, a localized string. | |
169 | */ | |
170 | public String getTitle() { | |
171 | 11700 | return title; |
172 | } | |
173 | ||
174 | /** | |
175 | * @param t The title, a localized string. | |
176 | */ | |
177 | public void setTitle(String t) { | |
178 | 11289 | title = t; |
179 | 11289 | } |
180 | ||
181 | /** | |
182 | * @return the icon to be shown for this panel | |
183 | */ | |
184 | public Icon getIcon() { | |
185 | 40154 | return icon; |
186 | } | |
187 | ||
188 | /** | |
189 | * @param theIcon this icon will be shown in front of the title | |
190 | */ | |
191 | public void setIcon(Icon theIcon) { | |
192 | 8100 | this.icon = theIcon; |
193 | 8100 | } |
194 | ||
195 | //////////////////////////////////////////////////////////////// | |
196 | // actions | |
197 | ||
198 | /** | |
199 | * This should take its inspiration from | |
200 | * {@link org.tigris.gef.base.CmdSpawn}.<p> | |
201 | * | |
202 | * The spawned/cloned tab will be a JFrame. Currently this feature is | |
203 | * disabled for ArgoUML, except for the find dialog. | |
204 | * Code should behave though as if spawning might work at a | |
205 | * later stage. | |
206 | * | |
207 | * @return a copy of the frame or null if not clone-able. | |
208 | */ | |
209 | public AbstractArgoJPanel spawn() { | |
210 | ||
211 | 0 | JDialog f = new JDialog(ArgoFrame.getFrame()); |
212 | 0 | f.getContentPane().setLayout(new BorderLayout()); |
213 | // TODO: Once we have fixed all subclasses the title will | |
214 | // always be localized so this localization can be removed. | |
215 | 0 | f.setTitle(Translator.localize(title)); |
216 | 0 | AbstractArgoJPanel newPanel = (AbstractArgoJPanel) clone(); |
217 | 0 | if (newPanel == null) { |
218 | 0 | return null; //failed to clone |
219 | } | |
220 | ||
221 | // TODO: Once we have fixed all subclasses the title will | |
222 | // always be localized so this localization can be removed. | |
223 | 0 | newPanel.setTitle(Translator.localize(title)); |
224 | ||
225 | 0 | f.getContentPane().add(newPanel, BorderLayout.CENTER); |
226 | 0 | Rectangle bounds = getBounds(); |
227 | 0 | bounds.height += OVERLAPP * 2; |
228 | 0 | f.setBounds(bounds); |
229 | ||
230 | 0 | Point loc = new Point(0, 0); |
231 | 0 | SwingUtilities.convertPointToScreen(loc, this); |
232 | 0 | loc.y -= OVERLAPP; |
233 | 0 | f.setLocation(loc); |
234 | 0 | f.setVisible(true); |
235 | ||
236 | 0 | if (tear && (getParent() instanceof JTabbedPane)) { |
237 | 0 | ((JTabbedPane) getParent()).remove(this); |
238 | } | |
239 | ||
240 | 0 | return newPanel; |
241 | ||
242 | } | |
243 | ||
244 | } |