--- /dev/null
+package jp.naist.se.stigmata.ui.swing;\r
+\r
+/*\r
+ * $Id$\r
+ */\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.Color;\r
+import java.awt.Dimension;\r
+import java.awt.FlowLayout;\r
+import java.awt.Graphics2D;\r
+import java.awt.RenderingHints;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.awt.geom.Line2D;\r
+import java.awt.image.BufferedImage;\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.util.HashSet;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+import javax.imageio.ImageIO;\r
+import javax.swing.Box;\r
+import javax.swing.ImageIcon;\r
+import javax.swing.JButton;\r
+import javax.swing.JColorChooser;\r
+import javax.swing.JDialog;\r
+import javax.swing.JLabel;\r
+import javax.swing.JOptionPane;\r
+import javax.swing.JPanel;\r
+\r
+/**\r
+ * \r
+ * @author Haruaki TAMADA\r
+ * @version $Revision$ $Date$\r
+ */\r
+public class SimilarityDistributionGraphPane extends JPanel{\r
+ private static final long serialVersionUID = 2314463453465L;\r
+\r
+ private StigmataFrame stigmata;\r
+ private Map<Integer, Integer> distributions;\r
+ private int totalCount = 0;\r
+ private int maxFrequency = 0;\r
+ private JLabel iconLabel;\r
+ private BufferedImage image;\r
+ private Color color = Color.RED;\r
+ private JColorChooser chooser;\r
+\r
+ public SimilarityDistributionGraphPane(StigmataFrame stigmata, Map<Integer, Integer> distributions){\r
+ this.stigmata = stigmata;\r
+\r
+ this.distributions = distributions;\r
+ initializeLayouts();\r
+ initializeData();\r
+\r
+ drawGraph();\r
+ }\r
+\r
+ public String[] getSupportedFormats(){\r
+ String[] formats = ImageIO.getWriterFormatNames();\r
+ Set<String> set = new HashSet<String>();\r
+ for(String f: formats){\r
+ if(f != null){\r
+ set.add(f.toLowerCase());\r
+ }\r
+ }\r
+ return set.toArray(new String[set.size()]);\r
+ }\r
+\r
+ private void drawGraph(){\r
+ Graphics2D g = image.createGraphics();\r
+ g.setColor(getBackground());\r
+ g.fillRect(0, 0, image.getWidth(), image.getHeight());\r
+\r
+ int width = image.getWidth();\r
+ int height = image.getHeight();\r
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);\r
+\r
+ drawBorder(g, width, height);\r
+\r
+ g.setColor(color);\r
+ Dimension d = new Dimension(width - 20, height - 20);\r
+ double w = (d.width / 100d);\r
+\r
+ Integer v1 = distributions.get(0);\r
+ if(v1 == null) v1 = new Integer(0);\r
+ double x = 20;\r
+ for(int i = 0; i <= 100; i++){\r
+ Integer v2 = distributions.get(i);\r
+ if(v2 == null) new Integer(0);\r
+\r
+ double hh1 = v1 * ((double)height / totalCount);\r
+ double hh2 = v2 * ((double)height / totalCount);\r
+\r
+ g.draw(new Line2D.Double(x, d.height - hh1, x + w, d.height - hh2));\r
+ x += w;\r
+ v1 = v2;\r
+ }\r
+ iconLabel.setIcon(new ImageIcon(image));\r
+ }\r
+\r
+ private void drawBorder(Graphics2D g, int width, int height){\r
+ g.setColor(Color.BLACK);\r
+ g.draw(new Line2D.Double(0, height - 20, width, height - 20));\r
+ g.draw(new Line2D.Double(20, 0, 20, height));\r
+\r
+ g.setColor(Color.GRAY);\r
+ // x axis\r
+ double h = (height - 20) / 2d;\r
+ g.draw(new Line2D.Double(20, h, width, h));\r
+ h = h / 2;\r
+ g.draw(new Line2D.Double(20, h, width, h));\r
+ g.draw(new Line2D.Double(20, h * 3, width, h * 3));\r
+\r
+ // y axis\r
+ double w = (width - 20d) / 2d;\r
+ g.draw(new Line2D.Double(w + 20, 0, w + 20, height - 20));\r
+ w = w / 2;\r
+ g.draw(new Line2D.Double(w + 20, 0, w + 20, height - 20));\r
+ g.draw(new Line2D.Double(w * 3 + 20, 0, w * 3 + 20, height - 20));\r
+\r
+ g.drawString("0", 10, height - 5);\r
+ g.drawString("50%", (width - 20) / 2 + 10, height - 5);\r
+ g.drawString(Messages.getString("similarity.label"), width - 60, height - 5);\r
+ g.drawString("50%", 0, (height - 20) / 2);\r
+ }\r
+\r
+ private void initializeData(){\r
+ maxFrequency = 0;\r
+ for(int i = 0; i <= 100; i++){\r
+ Integer frequency = distributions.get(new Integer(i));\r
+ if(frequency == null){\r
+ frequency = new Integer(0);\r
+ distributions.put(new Integer(i), frequency);\r
+ }\r
+ if(maxFrequency < frequency.intValue()){\r
+ maxFrequency = frequency.intValue();\r
+ }\r
+ totalCount += frequency.intValue();\r
+ }\r
+ }\r
+\r
+ private void initializeLayouts(){\r
+ chooser = new JColorChooser();\r
+ chooser.setColor(Color.RED);\r
+ image = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB);\r
+\r
+ JPanel center = new JPanel(new FlowLayout(FlowLayout.CENTER));\r
+ iconLabel = new JLabel();\r
+ Box south = Box.createHorizontalBox();\r
+ JButton storeImageButton = Utility.createButton("savegraph");\r
+ JButton switchColorButton = Utility.createButton("changecolor");\r
+ storeImageButton.addActionListener(new ActionListener(){\r
+ public void actionPerformed(ActionEvent e){\r
+ storeGraphImage();\r
+ }\r
+ });\r
+ switchColorButton.addActionListener(new ActionListener(){\r
+ public void actionPerformed(ActionEvent e){\r
+ switchColor();\r
+ }\r
+ });\r
+\r
+ setLayout(new BorderLayout());\r
+ center.add(iconLabel = new JLabel());\r
+ south.add(Box.createHorizontalGlue());\r
+ south.add(switchColorButton);\r
+ south.add(Box.createHorizontalGlue());\r
+ south.add(storeImageButton);\r
+ south.add(Box.createHorizontalGlue());\r
+\r
+ add(center, BorderLayout.CENTER);\r
+ add(south, BorderLayout.SOUTH);\r
+ }\r
+\r
+ private void switchColor(){\r
+ chooser.setColor(color);\r
+ JDialog dialog = JColorChooser.createDialog(\r
+ stigmata, Messages.getString("changecolor.title"), \r
+ true, chooser, \r
+ new ActionListener(){ // ok\r
+ public void actionPerformed(ActionEvent e){\r
+ color = chooser.getColor();\r
+ drawGraph();\r
+ }\r
+ },\r
+ new ActionListener(){ // cancel\r
+ public void actionPerformed(ActionEvent e){\r
+ }\r
+ }\r
+ );\r
+ dialog.setVisible(true);\r
+ }\r
+\r
+ private void storeGraphImage(){\r
+ String[] exts = getSupportedFormats();\r
+ File file = stigmata.getSaveFile(\r
+ exts, Messages.getString("savegraph.description")\r
+ );\r
+ try{\r
+ String format = file.getName();\r
+ format = format.substring(format.lastIndexOf('.') + 1);\r
+\r
+ ImageIO.write(image, format, file);\r
+ } catch(IOException e){\r
+ JOptionPane.showMessageDialog(\r
+ this,\r
+ Messages.getString("error.io", e.getMessage()),\r
+ Messages.getString("error.dialog.title"),\r
+ JOptionPane.ERROR_MESSAGE\r
+ );\r
+ }\r
+ }\r
+}\r
+++ /dev/null
-package jp.naist.se.stigmata.ui.swing;\r
-\r
-/*\r
- * $Id$\r
- */\r
-\r
-import java.awt.Color;\r
-import java.awt.Dimension;\r
-import java.awt.Graphics;\r
-import java.awt.Graphics2D;\r
-import java.awt.RenderingHints;\r
-import java.awt.geom.Line2D;\r
-import java.awt.image.BufferedImage;\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.util.HashSet;\r
-import java.util.Map;\r
-import java.util.Set;\r
-\r
-import javax.imageio.ImageIO;\r
-import javax.swing.JPanel;\r
-\r
-/**\r
- * \r
- * @author Haruaki TAMADA\r
- * @version $Revision$ $Date$\r
- */\r
-public class SimilarityGraphPane extends JPanel{\r
- private static final long serialVersionUID = 2314463453465L;\r
-\r
- private Map<Integer, Integer> distributions;\r
- private int totalCount = 0;\r
- private int maxFrequency = 0;\r
-\r
- public SimilarityGraphPane(Map<Integer, Integer> distributions){\r
- setPreferredSize(new Dimension(300, 300));\r
-\r
- this.distributions = distributions;\r
- initialize();\r
- }\r
-\r
- public String[] getSupportedFormats(){\r
- String[] formats = ImageIO.getWriterFormatNames();\r
- Set<String> set = new HashSet<String>();\r
- for(String f: formats){\r
- if(f != null){\r
- set.add(f.toLowerCase());\r
- }\r
- }\r
- \r
- return set.toArray(new String[set.size()]);\r
- }\r
-\r
- public void paintComponent(Graphics g1){\r
- Graphics2D g = (Graphics2D)g1;\r
- Dimension dd = getSize();\r
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);\r
-\r
- Dimension d = new Dimension(dd);\r
- paintBorder(g);\r
-\r
- g.setColor(Color.red);\r
- d.width = d.width - 20;\r
- d.height = d.height - 20;\r
-\r
- double w = (double)(d.width / 100d);\r
-\r
- Integer val1 = distributions.get(new Integer(0));\r
- double x = 20;\r
- for(int i = 1; i <= 100; i++){\r
- Integer val2 = distributions.get(new Integer(i));\r
- if(val2 == null) val2 = new Integer(0);\r
-\r
- double hh1 = val1.intValue() * ((double)d.height / (double)totalCount);\r
- double hh2 = val2.intValue() * ((double)d.height / (double)totalCount);\r
-\r
- g.draw(new Line2D.Double(x, d.height - hh1, x + w, d.height - hh2));\r
- x += w;\r
- val1 = val2;\r
- }\r
- }\r
-\r
- private void initialize(){\r
- maxFrequency = 0;\r
- for(int i = 0; i <= 100; i++){\r
- Integer frequency = distributions.get(new Integer(i));\r
- if(frequency == null){\r
- frequency = new Integer(0);\r
- distributions.put(new Integer(i), frequency);\r
- }\r
- if(maxFrequency < frequency.intValue()){\r
- maxFrequency = frequency.intValue();\r
- }\r
- totalCount += frequency.intValue();\r
- }\r
- }\r
-\r
- private void paintBorder(Graphics2D g){\r
- Dimension d = getSize();\r
- g.setColor(Color.BLACK);\r
- g.draw(new Line2D.Double(0, d.height - 20, d.width, d.height - 20));\r
- g.draw(new Line2D.Double(20, 0, 20, d.height));\r
-\r
- g.setColor(Color.GRAY);\r
- // x axis\r
- double h = (d.height - 20) / 2d;\r
- g.draw(new Line2D.Double(20, h, d.width, h));\r
- h = h / 2;\r
- g.draw(new Line2D.Double(20, h, d.width, h));\r
- g.draw(new Line2D.Double(20, h * 3, d.width, h * 3));\r
-\r
- // y axis\r
- double w = (d.width - 20d) / 2d;\r
- g.draw(new Line2D.Double(w + 20, 0, w + 20, d.height - 20));\r
- w = w / 2;\r
- g.draw(new Line2D.Double(w + 20, 0, w + 20, d.height - 20));\r
- g.draw(new Line2D.Double(w * 3 + 20, 0, w * 3 + 20, d.height - 20));\r
-\r
- g.drawString("0", 10, d.height - 5);\r
- g.drawString("50%", (d.width - 20) / 2 + 10, d.height - 5);\r
- g.drawString(Messages.getString("similarity.label"), d.width - 60, d.height - 5);\r
- g.drawString("50%", 0, (d.height - 20) / 2);\r
- }\r
-\r
- public void storeGraphImage(File file) throws IOException{\r
- BufferedImage image = new BufferedImage(300, 300, BufferedImage.TYPE_INT_ARGB);\r
- Graphics2D g = image.createGraphics();\r
- paintComponent(g);\r
- String format = file.getName();\r
- format = format.substring(format.lastIndexOf('.') + 1);\r
-\r
- ImageIO.write(image, format, file);\r
- }\r
-}\r
\r
import java.awt.BorderLayout;\r
import java.awt.Dimension;\r
-import java.awt.FlowLayout;\r
import java.awt.Font;\r
import java.awt.event.ActionEvent;\r
import java.awt.event.ActionListener;\r
import java.util.List;\r
import java.util.Map;\r
\r
-import javax.swing.Box;\r
-import javax.swing.JButton;\r
import javax.swing.JCheckBoxMenuItem;\r
import javax.swing.JFileChooser;\r
import javax.swing.JFrame;\r
}\r
\r
public void showSimilarityDistributionGraph(Map<Integer, Integer> distributions){\r
- final SimilarityGraphPane graph = new SimilarityGraphPane(distributions);\r
- JPanel graphPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));\r
- graphPanel.add(graph);\r
- JPanel panel = new JPanel(new BorderLayout());\r
- panel.add(graphPanel, BorderLayout.CENTER);\r
-\r
- JButton save = Utility.createButton("savegraph");\r
- Box south = Box.createHorizontalBox();\r
- south.add(Box.createHorizontalGlue());\r
- south.add(save);\r
- south.add(Box.createHorizontalGlue());\r
- panel.add(south, BorderLayout.SOUTH);\r
- save.addActionListener(new ActionListener(){\r
- public void actionPerformed(ActionEvent e){\r
- storeGraphImage(graph);\r
- }\r
- });\r
+ SimilarityDistributionGraphPane graph = new SimilarityDistributionGraphPane(this, distributions);\r
\r
graphCount++;\r
- Utility.addNewTab("graph", tabPane, panel, new Object[] { new Integer(graphCount), }, null);\r
+ Utility.addNewTab("graph", tabPane, graph, new Object[] { new Integer(graphCount), }, null);\r
tabPane.setSelectedIndex(tabPane.getTabCount() - 1);\r
}\r
\r
return mapping;\r
}\r
\r
- private void storeGraphImage(SimilarityGraphPane graph){\r
- String[] exts = graph.getSupportedFormats();\r
- File file = getSaveFile(\r
- exts, Messages.getString("savegraph.description")\r
- );\r
- try{\r
- graph.storeGraphImage(file);\r
- } catch(IOException e){\r
- JOptionPane.showMessageDialog(\r
- this,\r
- Messages.getString("error.io", e.getMessage()),\r
- Messages.getString("error.dialog.title"),\r
- JOptionPane.ERROR_MESSAGE\r
- );\r
- }\r
- }\r
-\r
private File findFile(boolean open, String[] exts, String desc){\r
JFileChooser chooser = new JFileChooser(getCurrentDirectory());\r
for(int i = 0; i < exts.length; i++){\r
maximum.border=Maximum\r
\r
savegraph.button.label=Save Graph...\r
-savegraph.button.label=Save graph\r
savegraph.button.icon=disk.png\r
savegraph.extensions=png, jpg, gif\r
savegraph.description=Save graph as image file ({0})\r
\r
+changecolor.button.label=Change Color...\r
+changecolor.button.icon=color_swatch.png\r
+changecolor.title=Switch Color\r
+\r
comparepair.tab.label=Compare Pair {0}\r
comparepair.tab.tooltip=Compare pair between {1} and {2} by {0} birthmark.\r
comparepair.target1.label=Target 1\r
showgraph.button.label=\83O\83\89\83t\r
showgraph.button.tooltip=\83o\81[\83X\83}\81[\83N\82Ì\97Þ\8e\97\90«\82Ì\95ª\95z\90}\r
\r
+changecolor.button.label=\90F\82Ì\95Ï\8dX\r
+changecolor.title=\90F\82Ì\95Ï\8dX\r
+\r
################################################\r
#BirthmarksViewPane\r
################################################\r