1 package jp.naist.se.stigmata.ui.swing;
\r
7 import java.awt.BorderLayout;
\r
8 import java.awt.event.ActionEvent;
\r
9 import java.awt.event.ActionListener;
\r
10 import java.io.File;
\r
11 import java.io.FileWriter;
\r
12 import java.io.IOException;
\r
13 import java.io.PrintWriter;
\r
14 import java.util.HashMap;
\r
15 import java.util.HashSet;
\r
16 import java.util.Map;
\r
17 import java.util.Set;
\r
19 import javax.swing.Box;
\r
20 import javax.swing.BoxLayout;
\r
21 import javax.swing.JButton;
\r
22 import javax.swing.JComboBox;
\r
23 import javax.swing.JComponent;
\r
24 import javax.swing.JMenuItem;
\r
25 import javax.swing.JOptionPane;
\r
26 import javax.swing.JPanel;
\r
27 import javax.swing.JTabbedPane;
\r
28 import javax.swing.border.TitledBorder;
\r
30 import jp.naist.se.stigmata.BirthmarkContext;
\r
31 import jp.naist.se.stigmata.BirthmarkEnvironment;
\r
32 import jp.naist.se.stigmata.ComparisonMethod;
\r
33 import jp.naist.se.stigmata.ExtractionUnit;
\r
34 import jp.naist.se.stigmata.Stigmata;
\r
35 import jp.naist.se.stigmata.filter.ComparisonPairFilterManager;
\r
36 import jp.naist.se.stigmata.reader.ClasspathContext;
\r
37 import jp.naist.se.stigmata.utils.ConfigFileExporter;
\r
38 import jp.naist.se.stigmata.utils.WellknownClassManager;
\r
42 * @author Haruaki TAMADA
\r
43 * @version $Revision$ $Date$
\r
45 public class ControlPane extends JPanel{
\r
46 private static final long serialVersionUID = 983547612346543645L;
\r
48 private StigmataFrame stigmata;
\r
49 private BirthmarkSelectablePane birthmarks;
\r
50 private TargetSelectionPane targetX;
\r
51 private TargetSelectionPane targetY;
\r
52 private ClasspathSettingsPane classpath;
\r
53 private WellknownClassesSettingsPane wellknownClassses;
\r
54 private BirthmarkDefinitionPane definition;
\r
55 private PropertyEditPane properties;
\r
56 private FilterManagementPane filters;
\r
57 private JTabbedPane controlTab;
\r
58 private JButton compareButton;
\r
59 private JButton extractButton;
\r
60 private JButton resetButton;
\r
61 private PopupButton comparePopup;
\r
62 private JComboBox unitBox;
\r
63 private Map<String, String> unitLabels = new HashMap<String, String>();
\r
64 private boolean expertmode = false;
\r
66 public ControlPane(StigmataFrame stigmata){
\r
67 this.stigmata = stigmata;
\r
71 definition = new BirthmarkDefinitionPane(stigmata);
\r
72 birthmarks = new BirthmarkSelectionCheckSetPane(stigmata);
\r
73 properties = new PropertyEditPane(stigmata);
\r
74 JComponent control = createControlPane();
\r
75 wellknownClassses = new WellknownClassesSettingsPane(stigmata);
\r
76 classpath = new ClasspathSettingsPane(stigmata);
\r
77 filters = new FilterManagementPane(stigmata);
\r
80 Utility.addNewTab("targets", controlTab, control);
\r
81 Utility.addNewTab("wellknown", controlTab, wellknownClassses);
\r
82 Utility.addNewTab("classpath", controlTab, classpath);
\r
83 Utility.addNewTab("property", controlTab, properties);
\r
87 public void addBirthmarkServiceListener(BirthmarkServiceListener listener){
\r
88 definition.addBirthmarkServiceListener(listener);
\r
91 public void removeBirthmarkServiceListener(BirthmarkServiceListener listener){
\r
92 definition.removeBirthmarkServiceListener(listener);
\r
95 public void reset(){
\r
96 this.expertmode = false;
\r
99 stigmata.setExpertMode(false);
\r
100 targetX.removeAllElements();
\r
101 targetY.removeAllElements();
\r
104 wellknownClassses.reset();
\r
108 int definitionTabIndex = controlTab.indexOfTab(Messages.getString("definition.tab.label"));
\r
109 if(definitionTabIndex >= 0){
\r
110 controlTab.removeTabAt(definitionTabIndex);
\r
112 int filterTabIndex = controlTab.indexOfTab(Messages.getString("filter.tab.label"));
\r
113 if(filterTabIndex >= 0){
\r
114 controlTab.removeTabAt(filterTabIndex);
\r
118 public void exportSettings(){
\r
119 File file = stigmata.getSaveFile(
\r
120 Messages.getStringArray("export.extensions"),
\r
121 Messages.getString("export.description")
\r
125 BirthmarkEnvironment environment = generateEnvironment();
\r
126 if(!file.getName().endsWith(".xml")){
\r
127 file = new File(file.getParent(), file.getName() + ".xml");
\r
130 ConfigFileExporter bce = new ConfigFileExporter(environment);
\r
132 PrintWriter out = new PrintWriter(new FileWriter(file));
\r
135 } catch(IOException e){
\r
136 JOptionPane.showMessageDialog(
\r
138 Messages.getString("error.io", e.getMessage()),
\r
139 Messages.getString("error.dialog.title"),
\r
140 JOptionPane.ERROR_MESSAGE
\r
146 public void setExpertMode(boolean expertmode){
\r
147 this.expertmode = expertmode;
\r
148 birthmarks.setExpertMode(expertmode);
\r
149 stigmata.setExpertMode(expertmode);
\r
152 Utility.addNewTab("definition", controlTab, definition);
\r
153 Utility.addNewTab("filter", controlTab, filters);
\r
156 removeTabByName(Messages.getString("definition.tab.label"));
\r
157 removeTabByName(Messages.getString("filter.tab.label"));
\r
162 public boolean isExpertMode(){
\r
166 private void removeTabByName(String tabname){
\r
167 int index = controlTab.indexOfTab(tabname);
\r
169 controlTab.removeTabAt(index);
\r
173 private JComponent createControlPane(){
\r
174 JComponent mainPane = new Box(BoxLayout.X_AXIS);
\r
175 JPanel center = new JPanel(new BorderLayout());
\r
176 targetX = new TargetSelectionPane(stigmata);
\r
177 targetY = new TargetSelectionPane(stigmata);
\r
179 birthmarks.setBorder(new TitledBorder(Messages.getString("birthmarkspane.border")));
\r
181 targetX.addTargetExtensions(Messages.getStringArray("targets.extensions"));
\r
182 targetX.setDescription(Messages.getString("targets.description"));
\r
183 targetX.setBorder(new TitledBorder(Messages.getString("targetx.border")));
\r
185 targetY.addTargetExtensions(Messages.getStringArray("targets.extensions"));
\r
186 targetY.setDescription(Messages.getString("targets.description"));
\r
187 targetY.setBorder(new TitledBorder(Messages.getString("targety.border")));
\r
189 center.add(mainPane, BorderLayout.CENTER);
\r
190 center.add(birthmarks, BorderLayout.SOUTH);
\r
192 mainPane.add(Box.createHorizontalGlue());
\r
193 mainPane.add(targetX);
\r
194 mainPane.add(Box.createHorizontalGlue());
\r
195 mainPane.add(targetY);
\r
196 mainPane.add(Box.createHorizontalGlue());
\r
198 DataChangeListener dcl = new DataChangeListener(){
\r
199 public void valueChanged(Object source){
\r
203 targetX.addDataChangeListener(dcl);
\r
204 targetY.addDataChangeListener(dcl);
\r
205 birthmarks.addDataChangeListener(dcl);
\r
210 private void updateEnable(){
\r
211 String[] valueX = targetX.getValues();
\r
212 String[] valueY = targetY.getValues();
\r
213 String[] targets = birthmarks.getSelectedServiceTypes();
\r
215 extractButton.setEnabled(
\r
216 ((valueX != null && valueX.length > 0) || (valueY != null && valueY.length > 0))
\r
217 && (targets != null && targets.length > 0)
\r
220 comparePopup.setEnabled(
\r
221 (valueX != null && valueX.length > 0) &&
\r
222 (valueY != null && valueY.length > 0) &&
\r
223 (targets != null && targets.length > 0)
\r
227 private void extractButtonActionPerformed(ActionEvent e){
\r
228 BirthmarkContext context = generateContext();
\r
230 String[] fileX = targetX.getValues();
\r
231 String[] fileY = targetY.getValues();
\r
232 Set<String> targets = new HashSet<String>();
\r
233 if(fileX != null && fileX.length > 0){
\r
234 for(String file: fileX){
\r
238 if(fileY != null && fileY.length > 0){
\r
239 for(String file: fileY){
\r
244 stigmata.extract(targets.toArray(new String[targets.size()]), context);
\r
247 private void compareRoundRobinWithFiltering(){
\r
248 BirthmarkContext context = generateContext();
\r
249 context.setComparisonMethod(ComparisonMethod.ROUND_ROBIN_XY);
\r
250 FilterSelectionPane pane = new FilterSelectionPane(
\r
251 context.getEnvironment().getFilterManager()
\r
253 int returnValue = JOptionPane.showConfirmDialog(
\r
254 stigmata, pane, Messages.getString("filterselection.dialog.title"),
\r
255 JOptionPane.OK_CANCEL_OPTION,
\r
256 JOptionPane.QUESTION_MESSAGE
\r
258 if(returnValue == JOptionPane.OK_OPTION){
\r
259 String[] filterSetList = pane.getSelectedFilters();
\r
260 context.setFilterTypes(filterSetList);
\r
262 String[] fileX = targetX.getValues();
\r
263 String[] fileY = targetY.getValues();
\r
264 stigmata.compareRoundRobinFilter(fileX, fileY, context);
\r
268 private void compareRoundRobin(){
\r
269 BirthmarkContext context = generateContext();
\r
270 context.setComparisonMethod(ComparisonMethod.ROUND_ROBIN_XY);
\r
271 String[] fileX = targetX.getValues();
\r
272 String[] fileY = targetY.getValues();
\r
274 stigmata.compareRoundRobin(fileX, fileY, context);
\r
277 private void compareSpecifiedPair(){
\r
278 BirthmarkContext context = generateContext();
\r
279 context.setComparisonMethod(ComparisonMethod.SPECIFIED_PAIR);
\r
280 String[] fileX = targetX.getValues();
\r
281 String[] fileY = targetY.getValues();
\r
282 stigmata.compareSpecifiedPair(fileX, fileY, context);
\r
285 private void compareGuessedPair(){
\r
286 BirthmarkContext context = generateContext();
\r
287 context.setComparisonMethod(ComparisonMethod.GUESSED_PAIR);
\r
288 String[] fileX = targetX.getValues();
\r
289 String[] fileY = targetY.getValues();
\r
291 stigmata.compareGuessedPair(fileX, fileY, context);
\r
294 private BirthmarkContext generateContext(){
\r
295 BirthmarkContext context = new BirthmarkContext(generateEnvironment());
\r
296 context.setExtractionTypes(birthmarks.getSelectedServiceTypes());
\r
297 context.setExtractionUnit(parseExtractionUnit());
\r
302 private BirthmarkEnvironment generateEnvironment(){
\r
303 BirthmarkEnvironment environment = Stigmata.getInstance().createEnvironment();
\r
304 ClasspathContext bytecode = environment.getClasspathContext();
\r
305 WellknownClassManager manager = environment.getWellknownClassManager();
\r
306 ComparisonPairFilterManager filterManager = environment.getFilterManager();
\r
308 // environment.setExtractionUnit(parseExtractionUnit());
\r
309 classpath.updateClasspathContext(bytecode);
\r
310 wellknownClassses.setWellknownClasses(manager);
\r
311 filters.updateFilterManager(filterManager);
\r
312 definition.updateEnvironment(environment);
\r
313 properties.updateEnvironment(environment);
\r
315 return environment;
\r
318 private ExtractionUnit parseExtractionUnit(){
\r
319 String label = (String)unitBox.getSelectedItem();
\r
320 String key = unitLabels.get(label);
\r
321 ExtractionUnit unit = ExtractionUnit.CLASS;
\r
323 if(key.equals("unit.archive")){
\r
324 unit = ExtractionUnit.ARCHIVE;
\r
326 else if(key.equals("unit.package")){
\r
327 unit = ExtractionUnit.PACKAGE;
\r
330 unit = ExtractionUnit.CLASS;
\r
335 private void initComponents(){
\r
336 controlTab = new JTabbedPane();
\r
337 resetButton = Utility.createButton("reset");
\r
338 extractButton = Utility.createButton("extract");
\r
339 compareButton = Utility.createButton("roundrobin");
\r
340 comparePopup = new PopupButton(compareButton);
\r
341 unitBox = new JComboBox();
\r
343 Box south = Box.createHorizontalBox();
\r
344 south.add(Box.createHorizontalGlue());
\r
345 south.add(resetButton);
\r
346 south.add(Box.createHorizontalGlue());
\r
347 south.add(extractButton);
\r
348 south.add(Box.createHorizontalGlue());
\r
349 south.add(comparePopup);
\r
350 south.add(Box.createHorizontalGlue());
\r
351 south.add(unitBox);
\r
352 south.add(Box.createHorizontalGlue());
\r
354 setLayout(new BorderLayout());
\r
355 add(south, BorderLayout.SOUTH);
\r
356 add(controlTab, BorderLayout.CENTER);
\r
358 extractButton.setEnabled(false);
\r
359 comparePopup.setEnabled(false);
\r
361 resetButton.addActionListener(new ActionListener(){
\r
362 public void actionPerformed(ActionEvent e){
\r
367 extractButton.addActionListener(new ActionListener(){
\r
368 public void actionPerformed(ActionEvent e){
\r
369 extractButtonActionPerformed(e);
\r
373 ActionListener compareListener = new ActionListener(){
\r
374 public void actionPerformed(ActionEvent e){
\r
375 String command = e.getActionCommand();
\r
377 if(command.equals("roundrobin")){
\r
378 compareRoundRobin();
\r
380 else if(command.equals("guessedpair")){
\r
381 compareGuessedPair();
\r
383 else if(command.equals("specifiedpair")){
\r
384 compareSpecifiedPair();
\r
386 else if(command.equals("roundrobin.filtering")){
\r
387 compareRoundRobinWithFiltering();
\r
391 compareButton.addActionListener(compareListener);
\r
393 String[] comparisonMethods = Messages.getStringArray("comparison.methods");
\r
394 for(int i = 1; i < comparisonMethods.length; i++){
\r
395 JMenuItem item = Utility.createJMenuItem(comparisonMethods[i]);
\r
396 comparePopup.addMenuItem(item);
\r
397 item.addActionListener(compareListener);
\r
400 String[] extractionUnits = Messages.getStringArray("extraction.units");
\r
401 for(int i = 0; i < extractionUnits.length; i++){
\r
402 String label = Messages.getString(extractionUnits[i]);
\r
403 unitLabels.put(label, extractionUnits[i]);
\r
404 unitBox.addItem(label);
\r