*/\r
\r
import java.awt.BorderLayout;\r
-import java.awt.FlowLayout;\r
import java.awt.GridLayout;\r
import java.awt.event.ActionEvent;\r
import java.awt.event.ActionListener;\r
import java.awt.event.MouseAdapter;\r
import java.awt.event.MouseEvent;\r
+import java.io.File;\r
import java.io.IOException;\r
import java.io.PrintWriter;\r
import java.util.ArrayList;\r
+import java.util.Iterator;\r
import java.util.List;\r
\r
import javax.swing.Box;\r
import javax.swing.JButton;\r
import javax.swing.JComponent;\r
import javax.swing.JLabel;\r
+import javax.swing.JOptionPane;\r
import javax.swing.JPanel;\r
import javax.swing.JScrollPane;\r
import javax.swing.JTable;\r
import javax.swing.border.TitledBorder;\r
import javax.swing.table.DefaultTableModel;\r
\r
+import jp.naist.se.stigmata.BirthmarkContext;\r
+import jp.naist.se.stigmata.BirthmarkSet;\r
import jp.naist.se.stigmata.ComparisonPair;\r
import jp.naist.se.stigmata.ComparisonResultSet;\r
+import jp.naist.se.stigmata.format.FormatManager;\r
+import jp.naist.se.stigmata.result.CertainPairComparisonResultSet;\r
import jp.naist.se.stigmata.spi.ResultFormatSpi;\r
+import jp.naist.se.stigmata.ui.swing.actions.SaveAction;\r
+import jp.naist.se.stigmata.ui.swing.actions.UpdateBirthmarkCellColorAction;\r
+import jp.naist.se.stigmata.utils.AsciiDataWritable;\r
\r
/**\r
* \r
* @author Haruaki TAMADA\r
* @version $Revision$ $Date$\r
*/\r
-public class PairComparisonResultSetPane extends JPanel implements BirthmarkDataWritable{\r
+public class PairComparisonResultSetPane extends JPanel{\r
private static final long serialVersionUID = 3298346465652354302L;\r
\r
private StigmataFrame frame;\r
-\r
- private ComparisonResultSet resultset;\r
-\r
- private DefaultTableModel model = new DefaultTableModel();\r
-\r
+ private ComparisonResultSet comparison;\r
+ private DefaultTableModel model = new PairComparisonResultSetTableModel();\r
private JTable table = new JTable(model);\r
-\r
- private List<ComparisonPair> list = new ArrayList<ComparisonPair>();\r
-\r
- double average, maximum, minimum;\r
+ private JLabel averageLabel, maximumLabel, minimumLabel;\r
+ private double average, maximum, minimum;\r
\r
public PairComparisonResultSetPane(StigmataFrame frame, ComparisonResultSet resultset){\r
this.frame = frame;\r
- this.resultset = resultset;\r
+ this.comparison = resultset;\r
\r
- initData();\r
initComponent();\r
+ initData(model, resultset);\r
}\r
\r
- public void writeData(PrintWriter out, ResultFormatSpi service) throws IOException{\r
- service.getComparisonResultFormat().printResult(out, resultset);\r
+ private void obfuscateClassNames(){\r
+ ClassNameObfuscator obfuscator = new ClassNameObfuscator();\r
+ List<ComparisonPair> newList = new ArrayList<ComparisonPair>();\r
+ BirthmarkContext context = comparison.getContext();\r
+\r
+ for(Iterator<ComparisonPair> i = comparison.iterator(); i.hasNext(); ){\r
+ ComparisonPair pair = i.next();\r
+ BirthmarkSet set1 = obfuscator.obfuscateClassName(pair.getTarget1());\r
+ BirthmarkSet set2 = obfuscator.obfuscateClassName(pair.getTarget2());\r
+\r
+ context = comparison.getContext();\r
+ newList.add(new ComparisonPair(set1, set2, context));\r
+ }\r
+\r
+ try{\r
+ File file = frame.getSaveFile(Messages.getStringArray("obfuscationmapping.extension"),\r
+ Messages.getString("obfuscationmapping.description"));\r
+ if(file == null){\r
+ return;\r
+ }\r
+ obfuscator.outputNameMappings(file);\r
+ }catch(IOException e){\r
+ JOptionPane.showMessageDialog(\r
+ this, e.getMessage(), Messages.getString("error.dialog.title"),\r
+ JOptionPane.ERROR_MESSAGE\r
+ );\r
+ return;\r
+ }\r
+\r
+ DefaultTableModel newModel = new PairComparisonResultSetTableModel();\r
+ initData(newModel, new CertainPairComparisonResultSet(newList.toArray(new ComparisonPair[newList.size()]), context));\r
+ model = newModel;\r
+ table.setModel(newModel);\r
}\r
\r
- private void initData(){\r
+ private void initData(DefaultTableModel model, ComparisonResultSet comparison){\r
maximum = 0d;\r
minimum = 1d;\r
average = 0d;\r
model.setColumnIdentifiers(Messages.getStringArray("comparepair.table.columns"));\r
\r
- for(ComparisonPair pair : resultset){\r
- list.add(pair);\r
-\r
+ for(Iterator<ComparisonPair> i = comparison.iterator(); i.hasNext(); ){\r
+ ComparisonPair pair = i.next();\r
double similarity = pair.calculateSimilarity();\r
if(similarity > maximum) maximum = similarity;\r
if(similarity < minimum) minimum = similarity;\r
average += similarity;\r
\r
- model.addRow(new Object[] { pair.getTarget1().getClassName(),\r
- pair.getTarget2().getClassName(), new Double(similarity) });\r
+ model.addRow(new Object[] { pair.getTarget1().getName(),\r
+ pair.getTarget2().getName(), new Double(similarity) });\r
}\r
- average = average / list.size();\r
+ average = average / comparison.getPairCount();\r
+ \r
+ averageLabel.setText(Double.toString(average));\r
+ maximumLabel.setText(Double.toString(maximum));\r
+ minimumLabel.setText(Double.toString(minimum));\r
}\r
\r
private void initComponent(){\r
- JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));\r
+ JComponent buttonPanel = Box.createHorizontalBox();\r
JPanel similarityPane = new JPanel(new GridLayout(1, 3));\r
JComponent southPanel = Box.createVerticalBox();\r
- JButton saveButton = Utility.createButton("savecomparison");\r
+ JButton saveButton = Utility.createButton(\r
+ "savecomparison", new SaveAction(frame, new AsciiDataWritable(){\r
+ public void writeAsciiData(PrintWriter out, String format) throws IOException{\r
+ ResultFormatSpi service = FormatManager.getInstance().getService(format);\r
+ if(service == null){\r
+ service = FormatManager.getDefaultFormatService();\r
+ }\r
+ service.getComparisonResultFormat().printResult(out, comparison);\r
+ }\r
+ })\r
+ );\r
+ JButton updateColorButton = Utility.createButton(\r
+ "updatecellcolor", new UpdateBirthmarkCellColorAction(this, comparison.getEnvironment())\r
+ );\r
JButton obfuscateButton = Utility.createButton("obfuscate");\r
JScrollPane scroll = new JScrollPane();\r
- JLabel avg = new JLabel(Double.toString(average));\r
- JLabel max = new JLabel(Double.toString(maximum));\r
- JLabel min = new JLabel(Double.toString(minimum));\r
+ averageLabel = new JLabel(Double.toString(average), JLabel.RIGHT);\r
+ maximumLabel = new JLabel(Double.toString(maximum), JLabel.RIGHT);\r
+ minimumLabel = new JLabel(Double.toString(minimum), JLabel.RIGHT);\r
\r
scroll.setViewportView(table);\r
+ table.setDefaultRenderer(Double.class, new CompareTableCellRenderer(comparison.getEnvironment()));\r
similarityPane.setBorder(new TitledBorder(Messages.getString("similarity.border")));\r
- avg.setBorder(new TitledBorder(Messages.getString("average.border")));\r
- max.setBorder(new TitledBorder(Messages.getString("maximum.border")));\r
- min.setBorder(new TitledBorder(Messages.getString("minimum.border")));\r
+ averageLabel.setBorder(new TitledBorder(Messages.getString("average.border")));\r
+ maximumLabel.setBorder(new TitledBorder(Messages.getString("maximum.border")));\r
+ minimumLabel.setBorder(new TitledBorder(Messages.getString("minimum.border")));\r
\r
setLayout(new BorderLayout());\r
add(scroll, BorderLayout.CENTER);\r
add(southPanel, BorderLayout.SOUTH);\r
- similarityPane.add(avg);\r
- similarityPane.add(max);\r
- similarityPane.add(min);\r
+ similarityPane.add(averageLabel);\r
+ similarityPane.add(maximumLabel);\r
+ similarityPane.add(minimumLabel);\r
southPanel.add(similarityPane);\r
southPanel.add(buttonPanel);\r
+ buttonPanel.add(Box.createHorizontalGlue());\r
buttonPanel.add(saveButton);\r
+ buttonPanel.add(Box.createHorizontalGlue());\r
+ buttonPanel.add(updateColorButton);\r
+ buttonPanel.add(Box.createHorizontalGlue());\r
buttonPanel.add(obfuscateButton);\r
+ buttonPanel.add(Box.createHorizontalGlue());\r
\r
table.addMouseListener(new MouseAdapter(){\r
public void mouseClicked(MouseEvent e){\r
int col = table.columnAtPoint(e.getPoint());\r
if(col >= 1 && col < table.getColumnCount() && row >= 0\r
&& row < table.getRowCount()){\r
- ComparisonPair pair = list.get(row);\r
+ ComparisonPair pair = comparison.getPairAt(row);\r
\r
- frame.compareDetails(pair.getTarget1(), pair.getTarget2(), resultset\r
- .getContext());\r
+ frame.compareDetails(pair.getTarget1(), pair.getTarget2(), comparison.getContext());\r
}\r
}\r
}\r
});\r
- saveButton.addActionListener(new ActionListener(){\r
- public void actionPerformed(ActionEvent e){\r
- frame.saveAction(PairComparisonResultSetPane.this);\r
- }\r
- });\r
\r
obfuscateButton.addActionListener(new ActionListener(){\r
public void actionPerformed(ActionEvent e){\r
- \r
+ obfuscateClassNames();\r
}\r
});\r
}\r
+\r
+ private static class PairComparisonResultSetTableModel extends DefaultTableModel{\r
+ private static final long serialVersionUID = 93457234571623497L;\r
+\r
+ @Override\r
+ public boolean isCellEditable(int row, int column){\r
+ return false;\r
+ }\r
+\r
+ @Override\r
+ public Class<?> getColumnClass(int column){\r
+ if(column == 2){\r
+ return Double.class;\r
+ }\r
+ else{\r
+ return String.class;\r
+ }\r
+ }\r
+ }\r
}\r