Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ImportClasspathDialog |
|
| 3.4;3.4 | ||||
ImportClasspathDialog$AddListener |
|
| 3.4;3.4 | ||||
ImportClasspathDialog$AddListener$1 |
|
| 3.4;3.4 | ||||
ImportClasspathDialog$RemoveListener |
|
| 3.4;3.4 |
1 | /* $Id: ImportClasspathDialog.java 17871 2010-01-12 20:49:55Z 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.uml.reveng.ui; | |
40 | ||
41 | import java.awt.BorderLayout; | |
42 | import java.awt.Frame; | |
43 | import java.awt.GridLayout; | |
44 | import java.awt.event.ActionEvent; | |
45 | import java.awt.event.ActionListener; | |
46 | import java.io.File; | |
47 | import java.util.ArrayList; | |
48 | import java.util.List; | |
49 | ||
50 | import javax.swing.DefaultListModel; | |
51 | import javax.swing.JButton; | |
52 | import javax.swing.JFileChooser; | |
53 | import javax.swing.JLabel; | |
54 | import javax.swing.JList; | |
55 | import javax.swing.JPanel; | |
56 | import javax.swing.JScrollPane; | |
57 | ||
58 | import org.argouml.i18n.Translator; | |
59 | import org.argouml.uml.reveng.SettingsTypes.PathListSelection; | |
60 | import org.tigris.gef.base.Globals; | |
61 | ||
62 | /** | |
63 | * Panel to collect a list of paths for an importer. <em>NOTE:</em> Although | |
64 | * this class is public it is <em>only</em> intended for use by the package | |
65 | * org.argouml.reveng. | |
66 | * <p> | |
67 | * This was originally included in Import.java and was called | |
68 | * ImportClasspathDialog. | |
69 | */ | |
70 | 0 | public class ImportClasspathDialog extends JPanel { |
71 | ||
72 | private JList paths; | |
73 | ||
74 | private DefaultListModel pathsModel; | |
75 | ||
76 | private JButton addButton; | |
77 | ||
78 | private JButton removeButton; | |
79 | ||
80 | private JFileChooser chooser; | |
81 | ||
82 | private PathListSelection setting; | |
83 | ||
84 | ||
85 | /** | |
86 | * Construct a panel which provides controls for populating a list of | |
87 | * paths. This can be used for a Java classpath, C++ include path, etc. | |
88 | * | |
89 | * @param pathListSetting the settings object for this pathlist | |
90 | */ | |
91 | public ImportClasspathDialog(PathListSelection pathListSetting) { | |
92 | 0 | super(); |
93 | 0 | setting = pathListSetting; |
94 | 0 | setToolTipText(setting.getDescription()); |
95 | ||
96 | 0 | setLayout(new BorderLayout(0, 0)); |
97 | ||
98 | 0 | JLabel label = new JLabel(setting.getLabel()); |
99 | 0 | add(label, BorderLayout.NORTH); |
100 | ||
101 | 0 | pathsModel = new DefaultListModel(); |
102 | 0 | for (String path : setting.getDefaultPathList()) { |
103 | 0 | pathsModel.addElement(path); |
104 | } | |
105 | ||
106 | 0 | paths = new JList(pathsModel); |
107 | 0 | paths.setVisibleRowCount(5); |
108 | 0 | paths.setToolTipText(setting.getDescription()); |
109 | 0 | JScrollPane listScroller = new JScrollPane(paths); |
110 | 0 | add(listScroller, BorderLayout.CENTER); |
111 | ||
112 | // panel for controls | |
113 | 0 | JPanel controlsPanel = new JPanel(); |
114 | 0 | controlsPanel.setLayout(new GridLayout(0, 2, 50, 0)); |
115 | ||
116 | 0 | addButton = new JButton(Translator.localize("button.add")); |
117 | 0 | controlsPanel.add(addButton); |
118 | 0 | addButton.addActionListener(new AddListener()); |
119 | ||
120 | 0 | removeButton = new JButton(Translator.localize("button.remove")); |
121 | 0 | controlsPanel.add(removeButton); |
122 | 0 | removeButton.addActionListener(new RemoveListener()); |
123 | ||
124 | // TODO: Add Up/Down buttons to control the ordering of items | |
125 | ||
126 | 0 | add(controlsPanel, BorderLayout.SOUTH); |
127 | 0 | } |
128 | ||
129 | ||
130 | private void updatePathList() { | |
131 | 0 | List<String> pathList = new ArrayList<String>(); |
132 | 0 | for (int i = 0; i < pathsModel.size(); i++) { |
133 | 0 | String path = (String) pathsModel.getElementAt(i); |
134 | 0 | pathList.add(path); |
135 | } | |
136 | 0 | setting.setPathList(pathList); |
137 | 0 | } |
138 | ||
139 | 0 | class RemoveListener implements ActionListener { |
140 | /* | |
141 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) | |
142 | */ | |
143 | public void actionPerformed(ActionEvent e) { | |
144 | //This method can be called only if | |
145 | //there's a valid selection | |
146 | //so go ahead and remove whatever's selected. | |
147 | 0 | int index = paths.getSelectedIndex(); |
148 | 0 | if (index < 0) { |
149 | 0 | return; |
150 | } | |
151 | 0 | pathsModel.remove(index); |
152 | 0 | updatePathList(); |
153 | ||
154 | 0 | int size = pathsModel.getSize(); |
155 | ||
156 | 0 | if (size == 0) { //nothings left, disable firing. |
157 | 0 | removeButton.setEnabled(false); |
158 | ||
159 | } else { //Select an index. | |
160 | 0 | if (index == pathsModel.getSize()) { |
161 | //removed item in last position | |
162 | 0 | index--; |
163 | } | |
164 | ||
165 | 0 | paths.setSelectedIndex(index); |
166 | 0 | paths.ensureIndexIsVisible(index); |
167 | } | |
168 | 0 | } |
169 | ||
170 | } | |
171 | ||
172 | ||
173 | 0 | class AddListener implements ActionListener { |
174 | /* | |
175 | * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) | |
176 | */ | |
177 | public void actionPerformed(ActionEvent e) { | |
178 | ||
179 | 0 | if (chooser == null ) { |
180 | 0 | chooser = new JFileChooser(Globals.getLastDirectory()); |
181 | 0 | if (chooser == null) { |
182 | 0 | chooser = new JFileChooser(); |
183 | } | |
184 | ||
185 | 0 | chooser.setFileSelectionMode( |
186 | JFileChooser.FILES_AND_DIRECTORIES); | |
187 | 0 | chooser.setMultiSelectionEnabled(true); |
188 | 0 | chooser.addActionListener(new ActionListener() { |
189 | public void actionPerformed(ActionEvent e1) { | |
190 | 0 | if (e1.getActionCommand().equals( |
191 | JFileChooser.APPROVE_SELECTION)) { | |
192 | 0 | File[] files = chooser.getSelectedFiles(); |
193 | 0 | for (File theFile : files) { |
194 | 0 | if (theFile != null) { |
195 | 0 | pathsModel.addElement(theFile.toString()); |
196 | } | |
197 | } | |
198 | 0 | updatePathList(); |
199 | 0 | } else if (e1.getActionCommand().equals( |
200 | JFileChooser.CANCEL_SELECTION)) { | |
201 | // Just quit | |
202 | } | |
203 | ||
204 | 0 | } |
205 | }); | |
206 | } | |
207 | ||
208 | 0 | chooser.showOpenDialog(new Frame()); |
209 | 0 | } |
210 | } | |
211 | ||
212 | } |