|
@@ -9,8 +9,11 @@ import ui.model.Model;
|
|
|
|
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JButton;
|
|
import javax.swing.JButton;
|
|
|
|
+import javax.swing.JFileChooser;
|
|
|
|
+import javax.swing.JFrame;
|
|
import javax.swing.SwingConstants;
|
|
import javax.swing.SwingConstants;
|
|
import javax.swing.Timer;
|
|
import javax.swing.Timer;
|
|
|
|
+import javax.swing.border.Border;
|
|
import javax.swing.text.StyledDocument;
|
|
import javax.swing.text.StyledDocument;
|
|
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.BorderLayout;
|
|
@@ -24,8 +27,15 @@ import java.awt.event.ActionListener;
|
|
import java.awt.event.MouseAdapter;
|
|
import java.awt.event.MouseAdapter;
|
|
import java.awt.event.MouseEvent;
|
|
import java.awt.event.MouseEvent;
|
|
import java.awt.event.MouseListener;
|
|
import java.awt.event.MouseListener;
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.Hashtable;
|
|
import java.util.Hashtable;
|
|
|
|
+
|
|
|
|
+import javax.imageio.ImageIO;
|
|
import javax.swing.BoxLayout;
|
|
import javax.swing.BoxLayout;
|
|
|
|
+import javax.swing.GroupLayout.Alignment;
|
|
|
|
+
|
|
import java.awt.GridLayout;
|
|
import java.awt.GridLayout;
|
|
|
|
|
|
public class StatisticGraphPanel extends JPanel {
|
|
public class StatisticGraphPanel extends JPanel {
|
|
@@ -42,13 +52,13 @@ public class StatisticGraphPanel extends JPanel {
|
|
private final JLabel maximumLabel = new JLabel("0");
|
|
private final JLabel maximumLabel = new JLabel("0");
|
|
private JPanel topPanel = new JPanel();
|
|
private JPanel topPanel = new JPanel();
|
|
private JButton closeButton = new JButton("X");
|
|
private JButton closeButton = new JButton("X");
|
|
|
|
+ private JButton savImgButton = new JButton("Save as Image");
|
|
|
|
|
|
// Variables
|
|
// Variables
|
|
String graphName;
|
|
String graphName;
|
|
private final JPanel legendPanel = new JPanel();
|
|
private final JPanel legendPanel = new JPanel();
|
|
private JPanel that;
|
|
private JPanel that;
|
|
private Hashtable<String, StatisticGraphPanel> graphHashtable;
|
|
private Hashtable<String, StatisticGraphPanel> graphHashtable;
|
|
- private JPanel tempP; // for makeLegend
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* Constructor.
|
|
* Constructor.
|
|
@@ -69,9 +79,10 @@ public class StatisticGraphPanel extends JPanel {
|
|
|
|
|
|
// ******************** Component Propertys ***************//
|
|
// ******************** Component Propertys ***************//
|
|
// Graph
|
|
// Graph
|
|
|
|
+ // this.setPreferredSize(new Dimension(280, 300));
|
|
sGraph.setPreferredSize(new Dimension(280, 180));
|
|
sGraph.setPreferredSize(new Dimension(280, 180));
|
|
sGraph.setMinimumSize(new Dimension(100, 150));
|
|
sGraph.setMinimumSize(new Dimension(100, 150));
|
|
- //this.setMaximumSize(new Dimension(1000, 1000));
|
|
|
|
|
|
+ // this.setMaximumSize(new Dimension(1000, 1000));
|
|
|
|
|
|
// Graph Name
|
|
// Graph Name
|
|
graphNameLabel = new JLabel(graphName);
|
|
graphNameLabel = new JLabel(graphName);
|
|
@@ -79,17 +90,36 @@ public class StatisticGraphPanel extends JPanel {
|
|
|
|
|
|
// Panel on top (Name and Close Button)
|
|
// Panel on top (Name and Close Button)
|
|
topPanel.setLayout(new BorderLayout(0, 0));
|
|
topPanel.setLayout(new BorderLayout(0, 0));
|
|
- topPanel.add(graphNameLabel, BorderLayout.CENTER);
|
|
|
|
|
|
+ topPanel.add(graphNameLabel, BorderLayout.WEST);
|
|
topPanel.add(closeButton, BorderLayout.EAST);
|
|
topPanel.add(closeButton, BorderLayout.EAST);
|
|
|
|
+ topPanel.add(savImgButton, BorderLayout.CENTER);
|
|
|
|
+ savImgButton.addActionListener(new ActionListener() {
|
|
|
|
+ @Override
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
+ BufferedImage img = new BufferedImage(that.getWidth(), that.getHeight(), BufferedImage.TYPE_INT_RGB);
|
|
|
|
+ that.print(img.getGraphics());
|
|
|
|
+ try {
|
|
|
|
+ JFileChooser fileChooser = new JFileChooser();
|
|
|
|
+ if (fileChooser.showSaveDialog(new JFrame()) == JFileChooser.APPROVE_OPTION) {
|
|
|
|
+ String file = fileChooser.getSelectedFile().getPath();
|
|
|
|
+ ImageIO.write(img, "jpg", new File(file+".jpg"));
|
|
|
|
+ }
|
|
|
|
+ } catch (IOException e1) {
|
|
|
|
+ // TODO Auto-generated catch block
|
|
|
|
+ e1.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
topPanel.setBorder(null);
|
|
topPanel.setBorder(null);
|
|
|
|
|
|
// Maximum Label
|
|
// Maximum Label
|
|
maximumLabel.setVerticalAlignment(SwingConstants.TOP);
|
|
maximumLabel.setVerticalAlignment(SwingConstants.TOP);
|
|
maximumLabel.setMinimumSize(new Dimension(30, 10));
|
|
maximumLabel.setMinimumSize(new Dimension(30, 10));
|
|
-
|
|
|
|
- //Legend Panel
|
|
|
|
|
|
+
|
|
|
|
+ // Legend Panel
|
|
legendPanel.setLayout(new GridLayout(0, 5, 0, 0));
|
|
legendPanel.setLayout(new GridLayout(0, 5, 0, 0));
|
|
-
|
|
|
|
|
|
+
|
|
// ******************** Component Listener ****************//
|
|
// ******************** Component Listener ****************//
|
|
|
|
|
|
that = this;
|
|
that = this;
|
|
@@ -141,18 +171,17 @@ public class StatisticGraphPanel extends JPanel {
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
JLabel b = new JLabel(set.getCpsObject().getName() + ": " + property);
|
|
JLabel b = new JLabel(set.getCpsObject().getName() + ": " + property);
|
|
b.setBackground(set.getColor());
|
|
b.setBackground(set.getColor());
|
|
- int color = Math.max(Math.max(set.getColor().getRed(), set.getColor().getGreen()),set.getColor().getBlue());
|
|
|
|
- if (color<=128) {
|
|
|
|
|
|
+ int color = Math.max(Math.max(set.getColor().getRed(), set.getColor().getGreen()), set.getColor().getBlue());
|
|
|
|
+ if (color <= 128) {
|
|
b.setForeground(Color.WHITE);
|
|
b.setForeground(Color.WHITE);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
b.setOpaque(true);
|
|
b.setOpaque(true);
|
|
b.addMouseListener(new MouseAdapter() {
|
|
b.addMouseListener(new MouseAdapter() {
|
|
-
|
|
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void mousePressed(MouseEvent e) {
|
|
public void mousePressed(MouseEvent e) {
|
|
if (MouseEvent.BUTTON3 == e.getButton()) {
|
|
if (MouseEvent.BUTTON3 == e.getButton()) {
|