Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TabDocumentation |
|
| 2.0;2 |
1 | /* $Id: TabDocumentation.java 18022 2010-02-16 08:24:42Z 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 | * bobtarling | |
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.uml.ui; | |
40 | ||
41 | import java.awt.Color; | |
42 | ||
43 | import javax.swing.ImageIcon; | |
44 | import javax.swing.JScrollPane; | |
45 | import javax.swing.JTextArea; | |
46 | import javax.swing.UIManager; | |
47 | ||
48 | import org.argouml.application.api.Argo; | |
49 | import org.argouml.configuration.Configuration; | |
50 | import org.argouml.i18n.Translator; | |
51 | import org.argouml.model.Model; | |
52 | import org.argouml.swingext.UpArrowIcon; | |
53 | import org.argouml.ui.TabModelTarget; | |
54 | import org.tigris.gef.presentation.Fig; | |
55 | import org.tigris.swidgets.Horizontal; | |
56 | import org.tigris.swidgets.Vertical; | |
57 | ||
58 | /** | |
59 | * This the tab in the details pane for documentation.<p> | |
60 | * | |
61 | * All data in this tab is stored as Tagged Values, | |
62 | * and saved and reloaded correctly.<p> | |
63 | * | |
64 | * Selecting the menu Edit>Settings... and setting the user name | |
65 | * does not affect the author field | |
66 | * in the documentation tab. <p> | |
67 | * | |
68 | * Enabling output from the documentation fields when generating code as | |
69 | * embedded in javadocs and for html/diagram creation is considered important | |
70 | * by users.<p> | |
71 | * | |
72 | * When importing sources, already saved javadoc statements are not | |
73 | * automatically added to the documenation Jtext window. When Adding notes to | |
74 | * classes the notes are not included in the documentation text window.<p> | |
75 | * | |
76 | * The "Since" field is not validated for real date. Change to DateField?<p> | |
77 | * | |
78 | * Note that all fields in the TabDocumentation are added automatically | |
79 | * to the tagged value tab view.<p> | |
80 | * | |
81 | * Refactored by: raphael-langerhorst@gmx.at; 5th April 03<p> | |
82 | * Changes: <ul> | |
83 | * <li>uses LabelledLayout instead of GridBagLayout | |
84 | * <li>uses the new event pump introduced late 2002 by Jaap</ul><p> | |
85 | * | |
86 | * UMLModelElementTaggedValueDocument is used to access the tagged values of an | |
87 | * MModelElement. | |
88 | */ | |
89 | public class TabDocumentation extends PropPanel implements TabModelTarget { | |
90 | ||
91 | 900 | private static String orientation = Configuration.getString(Configuration |
92 | .makeKey("layout", "tabdocumentation")); | |
93 | ||
94 | /** | |
95 | * Construct new documentation tab | |
96 | */ | |
97 | public TabDocumentation() { | |
98 | 900 | super(Translator.localize("tab.documentation"), (ImageIcon) null); |
99 | 900 | setOrientation(( |
100 | orientation.equals("West") || orientation.equals("East")) | |
101 | ? Vertical.getInstance() : Horizontal.getInstance()); | |
102 | 900 | setIcon(new UpArrowIcon()); |
103 | ||
104 | 900 | addField(Translator.localize("label.author"), new UMLTextField2( |
105 | new UMLModelElementTaggedValueDocument(Argo.AUTHOR_TAG))); | |
106 | ||
107 | 900 | addField(Translator.localize("label.version"), new UMLTextField2( |
108 | new UMLModelElementTaggedValueDocument(Argo.VERSION_TAG))); | |
109 | ||
110 | 900 | addField(Translator.localize("label.since"), new UMLTextField2( |
111 | new UMLModelElementTaggedValueDocument(Argo.SINCE_TAG))); | |
112 | ||
113 | 900 | addField(Translator.localize("label.deprecated"), |
114 | new UMLDeprecatedCheckBox()); | |
115 | ||
116 | 900 | UMLTextArea2 see = new UMLTextArea2( |
117 | new UMLModelElementTaggedValueDocument(Argo.SEE_TAG)); | |
118 | 900 | see.setRows(2); |
119 | 900 | see.setLineWrap(true); |
120 | 900 | see.setWrapStyleWord(true); |
121 | 900 | JScrollPane spSee = new JScrollPane(); |
122 | 900 | spSee.getViewport().add(see); |
123 | 900 | addField(Translator.localize("label.see"), spSee); |
124 | ||
125 | //make new column with LabelledLayout | |
126 | 900 | add(LabelledLayout.getSeparator()); |
127 | ||
128 | 900 | UMLTextArea2 doc = new UMLTextArea2( |
129 | new UMLModelElementTaggedValueDocument(Argo.DOCUMENTATION_TAG)); | |
130 | 900 | doc.setRows(2); |
131 | 900 | doc.setLineWrap(true); |
132 | 900 | doc.setWrapStyleWord(true); |
133 | 900 | JScrollPane spDocs = new JScrollPane(); |
134 | 900 | spDocs.getViewport().add(doc); |
135 | 900 | addField(Translator.localize("label.documentation"), spDocs); |
136 | ||
137 | // Comment.name text field - editing disabled | |
138 | 900 | UMLTextArea2 comment = new UMLTextArea2( |
139 | new UMLModelElementCommentDocument(false)); | |
140 | 900 | disableTextArea(comment); |
141 | 900 | JScrollPane spComment = new JScrollPane(); |
142 | 900 | spComment.getViewport().add(comment); |
143 | 900 | addField(Translator.localize("label.comment.name"), spComment); |
144 | ||
145 | // Comment.body text field - editing disabled | |
146 | 900 | UMLTextArea2 commentBody = new UMLTextArea2( |
147 | new UMLModelElementCommentDocument(true)); | |
148 | 900 | disableTextArea(commentBody); |
149 | 900 | JScrollPane spCommentBody = new JScrollPane(); |
150 | 900 | spCommentBody.getViewport().add(commentBody); |
151 | 900 | addField(Translator.localize("label.comment.body"), spCommentBody); |
152 | ||
153 | /* Since there are no buttons on this panel, we have to set | |
154 | * the size of the buttonpanel, otherwise the | |
155 | * title would not be aligned right. */ | |
156 | 900 | setButtonPanelSize(18); |
157 | 900 | } |
158 | ||
159 | private void disableTextArea(final JTextArea textArea) { | |
160 | 1800 | textArea.setRows(2); |
161 | 1800 | textArea.setLineWrap(true); |
162 | 1800 | textArea.setWrapStyleWord(true); |
163 | 1800 | textArea.setEnabled(false); |
164 | 1800 | textArea.setDisabledTextColor(textArea.getForeground()); |
165 | // Only change the background colour if it is supplied by the LAF. | |
166 | // Otherwise leave look and feel to handle this itself. | |
167 | 1800 | final Color inactiveColor = |
168 | UIManager.getColor("TextField.inactiveBackground"); | |
169 | 1800 | if (inactiveColor != null) { |
170 | // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4919687 | |
171 | 1800 | textArea.setBackground(new Color(inactiveColor.getRGB())); |
172 | } | |
173 | 1800 | } |
174 | ||
175 | /** | |
176 | * Checks if the tab should be enabled. Returns true if the target | |
177 | * returned by getTarget is a modelelement or if that target shows up as Fig | |
178 | * on the active diagram and has a modelelement as owner. | |
179 | * | |
180 | * @return true if this tab should be enabled, otherwise false. | |
181 | */ | |
182 | public boolean shouldBeEnabled() { | |
183 | 0 | Object target = getTarget(); |
184 | 0 | return shouldBeEnabled(target); |
185 | } | |
186 | ||
187 | /* | |
188 | * @see org.argouml.uml.ui.PropPanel#shouldBeEnabled(java.lang.Object) | |
189 | */ | |
190 | @Override | |
191 | public boolean shouldBeEnabled(Object target) { | |
192 | 1327 | target = (target instanceof Fig) ? ((Fig) target).getOwner() : target; |
193 | 1327 | return Model.getFacade().isAModelElement(target); |
194 | } | |
195 | ||
196 | } | |
197 |