Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
GoalsDialog |
|
| 1.6666666666666667;1.667 |
1 | /* $Id: GoalsDialog.java 17818 2010-01-12 18:39:46Z 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.cognitive.ui; | |
40 | ||
41 | import java.awt.Dimension; | |
42 | import java.awt.GridBagConstraints; | |
43 | import java.awt.GridBagLayout; | |
44 | import java.util.Hashtable; | |
45 | import java.util.List; | |
46 | ||
47 | import javax.swing.BorderFactory; | |
48 | import javax.swing.JLabel; | |
49 | import javax.swing.JPanel; | |
50 | import javax.swing.JScrollPane; | |
51 | import javax.swing.JSlider; | |
52 | import javax.swing.SwingConstants; | |
53 | import javax.swing.event.ChangeEvent; | |
54 | import javax.swing.event.ChangeListener; | |
55 | ||
56 | import org.argouml.cognitive.Designer; | |
57 | import org.argouml.cognitive.Goal; | |
58 | import org.argouml.cognitive.GoalModel; | |
59 | import org.argouml.cognitive.Translator; | |
60 | import org.argouml.util.ArgoDialog; | |
61 | ||
62 | ||
63 | /** | |
64 | * The dialog to set the user's goals. | |
65 | * | |
66 | */ | |
67 | public class GoalsDialog extends ArgoDialog implements ChangeListener { | |
68 | ||
69 | private static final int DIALOG_WIDTH = 320; | |
70 | private static final int DIALOG_HEIGHT = 400; | |
71 | ||
72 | ||
73 | 0 | private JPanel mainPanel = new JPanel(); |
74 | ||
75 | 0 | private Hashtable<JSlider, Goal> slidersToGoals = |
76 | new Hashtable<JSlider, Goal>(); | |
77 | ||
78 | 0 | private Hashtable<JSlider, JLabel> slidersToDigits = |
79 | new Hashtable<JSlider, JLabel>(); | |
80 | ||
81 | /** | |
82 | * The constructor. | |
83 | */ | |
84 | public GoalsDialog() { | |
85 | 0 | super(Translator.localize("dialog.title.design-goals"), false); |
86 | ||
87 | 0 | initMainPanel(); |
88 | ||
89 | 0 | JScrollPane scroll = new JScrollPane(mainPanel); |
90 | 0 | scroll.setPreferredSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT)); |
91 | ||
92 | 0 | setContent(scroll); |
93 | 0 | } |
94 | ||
95 | ||
96 | private void initMainPanel() { | |
97 | 0 | GoalModel gm = Designer.theDesigner().getGoalModel(); |
98 | 0 | List<Goal> goals = gm.getGoalList(); |
99 | ||
100 | 0 | GridBagLayout gb = new GridBagLayout(); |
101 | 0 | mainPanel.setLayout(gb); |
102 | 0 | mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
103 | ||
104 | 0 | GridBagConstraints c = new GridBagConstraints(); |
105 | 0 | c.fill = GridBagConstraints.BOTH; |
106 | 0 | c.weightx = 1.0; |
107 | 0 | c.weighty = 0.0; |
108 | 0 | c.ipadx = 3; c.ipady = 3; |
109 | ||
110 | ||
111 | ||
112 | // c.gridy = 0; | |
113 | // c.gridx = 0; | |
114 | // JLabel priLabel = new JLabel("Priority:"); | |
115 | // gb.setConstraints(priLabel, c); | |
116 | // _mainPanel.add(priLabel); | |
117 | ||
118 | // c.gridy = 0; | |
119 | // c.gridx = 1; | |
120 | // JLabel offLabel = new JLabel("Off"); | |
121 | // gb.setConstraints(offLabel, c); | |
122 | // _mainPanel.add(offLabel); | |
123 | ||
124 | // c.gridy = 0; | |
125 | // c.gridx = 2; | |
126 | // JLabel lowLabel = new JLabel("Low"); | |
127 | // gb.setConstraints(lowLabel, c); | |
128 | // _mainPanel.add(lowLabel); | |
129 | ||
130 | // c.gridy = 0; | |
131 | // c.gridx = 3; | |
132 | // JLabel twoLabel = new JLabel("ad"); | |
133 | // gb.setConstraints(twoLabel, c); | |
134 | // _mainPanel.add(twoLabel); | |
135 | ||
136 | // c.gridy = 0; | |
137 | // c.gridx = 4; | |
138 | // JLabel threeLabel = new JLabel("asd"); | |
139 | // gb.setConstraints(threeLabel, c); | |
140 | // _mainPanel.add(threeLabel); | |
141 | ||
142 | // c.gridy = 0; | |
143 | // c.gridx = 5; | |
144 | // JLabel fourLabel = new JLabel("asd"); | |
145 | // gb.setConstraints(fourLabel, c); | |
146 | // _mainPanel.add(fourLabel); | |
147 | ||
148 | // c.gridy = 0; | |
149 | // c.gridx = 6; | |
150 | // JLabel highLabel = new JLabel("High"); | |
151 | // gb.setConstraints(highLabel, c); | |
152 | // _mainPanel.add(highLabel); | |
153 | ||
154 | ||
155 | 0 | c.gridy = 1; |
156 | 0 | for (Goal goal : goals) { |
157 | 0 | JLabel decLabel = new JLabel(goal.getName()); |
158 | 0 | JLabel valueLabel = new JLabel(" " + goal.getPriority()); |
159 | 0 | JSlider decSlide = |
160 | new JSlider(SwingConstants.HORIZONTAL, | |
161 | 0, 5, goal.getPriority()); | |
162 | 0 | decSlide.setPaintTicks(true); |
163 | 0 | decSlide.setPaintLabels(true); |
164 | 0 | decSlide.addChangeListener(this); |
165 | 0 | Dimension origSize = decSlide.getPreferredSize(); |
166 | 0 | Dimension smallSize = |
167 | new Dimension(origSize.width / 2, origSize.height); | |
168 | 0 | decSlide.setSize(smallSize); |
169 | 0 | decSlide.setPreferredSize(smallSize); |
170 | ||
171 | 0 | slidersToGoals.put(decSlide, goal); |
172 | 0 | slidersToDigits.put(decSlide, valueLabel); |
173 | ||
174 | 0 | c.gridx = 0; |
175 | 0 | c.gridwidth = 1; |
176 | 0 | c.weightx = 0.0; |
177 | 0 | c.ipadx = 3; |
178 | 0 | gb.setConstraints(decLabel, c); |
179 | 0 | mainPanel.add(decLabel); |
180 | ||
181 | 0 | c.gridx = 1; |
182 | 0 | c.gridwidth = 1; |
183 | 0 | c.weightx = 0.0; |
184 | 0 | c.ipadx = 0; |
185 | 0 | gb.setConstraints(valueLabel, c); |
186 | 0 | mainPanel.add(valueLabel); |
187 | ||
188 | 0 | c.gridx = 2; |
189 | 0 | c.gridwidth = 6; |
190 | 0 | c.weightx = 1.0; |
191 | 0 | gb.setConstraints(decSlide, c); |
192 | 0 | mainPanel.add(decSlide); |
193 | ||
194 | 0 | c.gridy++; |
195 | 0 | } |
196 | 0 | } |
197 | ||
198 | /* | |
199 | * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent) | |
200 | */ | |
201 | public void stateChanged(ChangeEvent ce) { | |
202 | 0 | JSlider srcSlider = (JSlider) ce.getSource(); |
203 | 0 | Goal goal = slidersToGoals.get(srcSlider); |
204 | 0 | JLabel valLab = slidersToDigits.get(srcSlider); |
205 | 0 | int pri = srcSlider.getValue(); |
206 | 0 | goal.setPriority(pri); |
207 | 0 | if (pri == 0) { |
208 | 0 | valLab.setText(Translator.localize("label.off")); |
209 | } else { | |
210 | 0 | valLab.setText(" " + pri); |
211 | } | |
212 | 0 | } |
213 | ||
214 | /** | |
215 | * The UID. | |
216 | */ | |
217 | private static final long serialVersionUID = -1871200638199122363L; | |
218 | } |