Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SettingsDialog |
|
| 1.6666666666666667;1.667 | ||||
SettingsDialog$1 |
|
| 1.6666666666666667;1.667 |
1 | /* $Id: SettingsDialog.java 17841 2010-01-12 19:17:52Z 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-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.ui; | |
40 | ||
41 | import java.awt.Dimension; | |
42 | import java.awt.event.ActionEvent; | |
43 | import java.awt.event.ActionListener; | |
44 | import java.awt.event.WindowEvent; | |
45 | import java.awt.event.WindowListener; | |
46 | import java.util.List; | |
47 | ||
48 | import javax.swing.JButton; | |
49 | import javax.swing.JTabbedPane; | |
50 | import javax.swing.SwingConstants; | |
51 | ||
52 | import org.argouml.application.api.GUISettingsTabInterface; | |
53 | import org.argouml.configuration.Configuration; | |
54 | import org.argouml.i18n.Translator; | |
55 | import org.argouml.util.ArgoDialog; | |
56 | ||
57 | /** | |
58 | * Action for starting the Argo settings window. | |
59 | * | |
60 | * @author Thomas N | |
61 | * @author Thierry Lach | |
62 | * @since 0.9.4 | |
63 | */ | |
64 | 0 | class SettingsDialog extends ArgoDialog implements WindowListener { |
65 | ||
66 | private JButton applyButton; | |
67 | ||
68 | private JTabbedPane tabs; | |
69 | ||
70 | private boolean windowOpen; | |
71 | ||
72 | /** | |
73 | * Constructor to build new settings dialog. | |
74 | */ | |
75 | SettingsDialog() { | |
76 | 19 | super(Translator.localize("dialog.settings"), |
77 | ArgoDialog.OK_CANCEL_OPTION, | |
78 | true); | |
79 | ||
80 | 19 | tabs = new JTabbedPane(); |
81 | ||
82 | 19 | applyButton = new JButton(Translator.localize("button.apply")); |
83 | 19 | String mnemonic = Translator.localize("button.apply.mnemonic"); |
84 | 19 | if (mnemonic != null && mnemonic.length() > 0) { |
85 | 19 | applyButton.setMnemonic(mnemonic.charAt(0)); |
86 | } | |
87 | 19 | applyButton.addActionListener(new ActionListener() { |
88 | public void actionPerformed(ActionEvent e) { | |
89 | 0 | handleSave(); |
90 | 0 | } |
91 | }); | |
92 | 19 | addButton(applyButton); |
93 | ||
94 | // Add settings from the settings registry. | |
95 | 19 | settingsTabs = GUI.getInstance().getSettingsTabs(); |
96 | 19 | for (GUISettingsTabInterface stp : settingsTabs) { |
97 | // TODO: Only fetch names and defer fetching panels until needed | |
98 | 171 | tabs.addTab( |
99 | Translator.localize(stp.getTabKey()), | |
100 | stp.getTabPanel()); | |
101 | } | |
102 | ||
103 | // Increase width to accommodate all tabs on one row. | |
104 | 19 | final int minimumWidth = 500; |
105 | 19 | tabs.setPreferredSize(new Dimension(Math.max(tabs |
106 | .getPreferredSize().width, minimumWidth), tabs | |
107 | .getPreferredSize().height)); | |
108 | ||
109 | 19 | tabs.setTabPlacement(SwingConstants.LEFT); |
110 | 19 | setContent(tabs); |
111 | 19 | addWindowListener(this); |
112 | 19 | } |
113 | ||
114 | @Override | |
115 | public void setVisible(boolean show) { | |
116 | 19 | if (show) { |
117 | 19 | handleRefresh(); |
118 | 19 | toFront(); |
119 | } | |
120 | 19 | super.setVisible(show); |
121 | // windowOpen state will be changed when window is activated | |
122 | 0 | } |
123 | ||
124 | /* | |
125 | * @see java.awt.event.ActionListener#actionPerformed( | |
126 | * java.awt.event.ActionEvent) | |
127 | */ | |
128 | public void actionPerformed(ActionEvent ev) { | |
129 | 0 | super.actionPerformed(ev); |
130 | 0 | if (ev.getSource() == getOkButton()) { |
131 | 0 | handleSave(); |
132 | 0 | } else if (ev.getSource() == getCancelButton()) { |
133 | 0 | handleCancel(); |
134 | } | |
135 | 0 | } |
136 | ||
137 | /* | |
138 | * Called when the user has pressed Save. Performs "Save" in all Tabs. | |
139 | */ | |
140 | private void handleSave() { | |
141 | 0 | for (GUISettingsTabInterface tab : settingsTabs) { |
142 | 0 | tab.handleSettingsTabSave(); |
143 | } | |
144 | 0 | windowOpen = false; |
145 | 0 | Configuration.save(); |
146 | 0 | } |
147 | ||
148 | /* | |
149 | * Called when the user has pressed Cancel. Performs "Cancel" in all Tabs. | |
150 | */ | |
151 | private void handleCancel() { | |
152 | 0 | for (GUISettingsTabInterface tab : settingsTabs) { |
153 | 0 | tab.handleSettingsTabCancel(); |
154 | } | |
155 | 0 | windowOpen = false; |
156 | 0 | } |
157 | ||
158 | /** | |
159 | * Perform "Refresh" in all Tabs. | |
160 | */ | |
161 | private void handleRefresh() { | |
162 | 19 | for (GUISettingsTabInterface tab : settingsTabs) { |
163 | 171 | tab.handleSettingsTabRefresh(); |
164 | } | |
165 | 19 | } |
166 | ||
167 | private void handleOpen() { | |
168 | // We only request focus the first time we become visible | |
169 | 38 | if (!windowOpen) { |
170 | 19 | getOkButton().requestFocusInWindow(); |
171 | 19 | windowOpen = true; |
172 | } | |
173 | 38 | } |
174 | ||
175 | /* | |
176 | * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent) | |
177 | */ | |
178 | public void windowActivated(WindowEvent e) { | |
179 | 19 | handleOpen(); |
180 | 19 | } |
181 | ||
182 | /* | |
183 | * @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent) | |
184 | */ | |
185 | public void windowClosed(WindowEvent e) { | |
186 | // ignored - we only care about open/closing | |
187 | 0 | } |
188 | ||
189 | /* | |
190 | * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent) | |
191 | */ | |
192 | public void windowDeactivated(WindowEvent e) { | |
193 | // ignored - we only care about open/closing | |
194 | 0 | } |
195 | ||
196 | /* | |
197 | * @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent) | |
198 | */ | |
199 | public void windowDeiconified(WindowEvent e) { | |
200 | // ignored - we only care about open/closing | |
201 | 0 | } |
202 | ||
203 | /* | |
204 | * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent) | |
205 | */ | |
206 | public void windowIconified(WindowEvent e) { | |
207 | // ignored - we only care about open/closing | |
208 | 0 | } |
209 | ||
210 | /* | |
211 | * @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent) | |
212 | */ | |
213 | public void windowOpened(WindowEvent e) { | |
214 | 19 | handleOpen(); |
215 | 19 | } |
216 | ||
217 | /* | |
218 | * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent) | |
219 | */ | |
220 | public void windowClosing(WindowEvent e) { | |
221 | // Handle the same as an explicit cancel | |
222 | 0 | handleCancel(); |
223 | 0 | } |
224 | ||
225 | /** | |
226 | * The serial version. | |
227 | */ | |
228 | private static final long serialVersionUID = -8233301947357843703L; | |
229 | ||
230 | private List<GUISettingsTabInterface> settingsTabs; | |
231 | } |