Explorar el Código

Merge branch 'master' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons

Edgardo Palza hace 8 años
padre
commit
513ee334fa

+ 23 - 9
src/ui/view/GUI.java

@@ -1578,19 +1578,33 @@ public class GUI<E> implements CategoryListener {
 			int dialogResult = JOptionPane.showConfirmDialog(null, "Old autosave file was found, should it be loaded?",
 					warningText, dialogButton);
 			if (dialogResult == JOptionPane.YES_OPTION) {
+				if(dest.exists()){
 				model.setAutoSaveNr(dest.listFiles().length - 1);
 				mntmRedo.doClick();
-			} else {
-				controller.deleteDirectory(dest);
-				dest.mkdirs();
-				try {
-					controller.autoSave();
-				} catch (IOException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
+				}else{
+					JOptionPane.showMessageDialog(frmCyberPhysical, "Autosave could not be loaded.");
+					setUpAutoSave(dest);
 				}
+			} else {
+				setUpAutoSave(dest);
 			}
-
+		}
+	}
+	
+	/**
+	 * Sets up autosave if no old one is loaded at the beginning
+	 * 
+	 * @param dest
+	 * 			path to save-folder
+	 */
+	public void setUpAutoSave(File dest){
+		controller.deleteDirectory(dest);
+		dest.mkdirs();
+		try {
+			controller.autoSave();
+		} catch (IOException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
 		}
 	}
 

+ 0 - 16
src/ui/view/StatisticGraph.java

@@ -58,23 +58,7 @@ public class StatisticGraph extends JPanel {
 		this.controller = control;
 		this.model = model;
 
-		// addObject(new TrackedDataSet(model.getObjectsOnCanvas().get(0),
-		// TrackedDataSet.CONSUMPTION, Color.RED));
-		// addObject(new TrackedDataSet(model.getObjectsOnCanvas().get(0),
-		// TrackedDataSet.PRODUCTION, Color.GREEN));
-		// addObject(new TrackedDataSet(model.getObjectsOnCanvas().get(0),
-		// TrackedDataSet.ACTIVATED_ELEMENTS, Color.CYAN));
-		addObject(new TrackedDataSet(model.getObjectsOnCanvas().get(0), TrackedDataSet.ON_OFF, Color.BLUE));
-
 		this.setBackground(Color.WHITE);
-
-		Timer timer = new Timer(200, new ActionListener() {
-			@Override
-			public void actionPerformed(ActionEvent ae) {
-				repaint();
-			}
-		});
-		timer.start();
 	}
 
 	/**

+ 111 - 0
src/ui/view/StatisticGraphPanel.java

@@ -0,0 +1,111 @@
+package ui.view;
+
+import javax.swing.JPanel;
+
+import classes.TrackedDataSet;
+import ui.controller.Control;
+import ui.model.Model;
+import javax.swing.JLabel;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.SwingConstants;
+import java.awt.BorderLayout;
+import javax.swing.border.LineBorder;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+public class StatisticGraphPanel extends JPanel {
+
+	private static final long serialVersionUID = 1L;
+
+	// Model/Controller
+	private Model model;
+	private Control controller;
+
+	// Components
+	private StatisticGraph sGraph;
+	private final JLabel graphNameLabel;
+	private final JLabel maximumLabel = new JLabel("0");
+	private JPanel topPanel = new JPanel();
+	private JButton closeButton = new JButton("X");
+
+	// Variables
+	String graphName;
+	private final JPanel Legendpanel = new JPanel();
+
+	/**
+	 * Constructor.
+	 * 
+	 * @param mod
+	 *            the Model
+	 * @param cont
+	 *            the Controller
+	 */
+	public StatisticGraphPanel(Model mod, Control cont, String name) {
+		super();
+		setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
+		this.model = mod;
+		this.controller = cont;
+		this.sGraph = new StatisticGraph(mod, cont);
+		this.graphName = name;
+		setLayout(new BorderLayout(0, 0));
+
+		// ******************** Component Propertys ***************//
+		//Graph Name
+		graphNameLabel = new JLabel(graphName);
+		graphNameLabel.setHorizontalTextPosition(JLabel.CENTER);
+
+		//Panel on top (Name and Close Button)
+		topPanel.setLayout(new BorderLayout(0, 0));
+		topPanel.add(graphNameLabel, BorderLayout.CENTER);
+		topPanel.add(closeButton, BorderLayout.EAST);
+		topPanel.setBorder(null);
+		
+		//Maximum Label
+		maximumLabel.setVerticalAlignment(SwingConstants.TOP);
+		maximumLabel.setPreferredSize(new Dimension(30,10));
+		// ******************** Component Listener ****************//
+		
+		JPanel that = this;
+		closeButton.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				JPanel parent = (JPanel) that.getParent();
+				parent.remove(that);
+				parent.revalidate();
+			}
+		});
+		
+		// ******************** add everything ********************//
+		this.add(sGraph);
+		this.add(topPanel, BorderLayout.NORTH);
+		this.add(maximumLabel, BorderLayout.WEST);
+		this.add(Legendpanel, BorderLayout.SOUTH);
+	}
+
+	/**
+	 * Adds the Set to the Graph.
+	 * 
+	 * @param set
+	 */
+	public void addObjec(TrackedDataSet set) {
+		sGraph.addObject(set);
+	}
+
+	/**
+	 * Repaint the Graph.
+	 * 
+	 * public void repaint() { sGraph.repaint(); }
+	 */
+
+	/**
+	 * Set the Maximum Label
+	 *
+	 * @param max
+	 */
+	public void setMaximumLabel(int max) {
+		maximumLabel.setText(Integer.toString(max));
+	}
+}

+ 31 - 16
src/ui/view/splitPane.java

@@ -37,6 +37,7 @@ import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 
+import javax.swing.border.CompoundBorder;
 import javax.swing.border.LineBorder;
 import javax.swing.JPopupMenu;
 import java.awt.Component;
@@ -44,8 +45,11 @@ import java.awt.Dimension;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import javax.swing.JMenuItem;
+import javax.swing.BorderFactory;
+import javax.swing.Box;
 import javax.swing.BoxLayout;
 import java.awt.FlowLayout;
+import java.awt.BorderLayout;
 
 public class splitPane extends JSplitPane implements GraphListener {
 	private JTextField graphNrTxtField;
@@ -76,7 +80,6 @@ public class splitPane extends JSplitPane implements GraphListener {
 		dataPane.setViewportView(panel);
 		
 		JScrollPane treeScrollPane = new JScrollPane();
-		
 		JLabel lblObject = new JLabel("Object(s):");
 		
 		showObjectlbl = new JLabel("...");
@@ -339,10 +342,25 @@ public class splitPane extends JSplitPane implements GraphListener {
 		JButton btnAdd = new JButton("Add");
 		btnAdd.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent e) {
-				StatisticGraph tmp = new StatisticGraph(controller.getModel(), controller);
-				graphPanel.add(tmp);
-				graphPanel.revalidate();
-				graphPanel.updateUI();
+				/*
+				 DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)objectTree.getLastSelectedPathComponent();
+				 if(selectedNode == null){
+					 return;
+				 }else{
+					 if(selectedNode.getLevel() == 3){
+
+					 }
+				 }
+				 */
+				 StatisticGraph tmp = new StatisticGraph(controller.getModel(), controller);
+				 tmp.setPreferredSize(new Dimension(280,120));
+				 tmp.setMaximumSize(new Dimension(1000,120));
+				 tmp.setMinimumSize(new Dimension(100,45));
+				 tmp.setBorder(new LineBorder(new Color(0, 0, 0), 2));
+				 graphPanel.add(tmp);
+				 graphPanel.add(Box.createRigidArea(new Dimension(50,50)));
+				 graphPanel.revalidate();
+				 graphPanel.updateUI();
 			}
 		});
 		
@@ -354,11 +372,9 @@ public class splitPane extends JSplitPane implements GraphListener {
 			gl_panel.createParallelGroup(Alignment.LEADING)
 				.addGroup(gl_panel.createSequentialGroup()
 					.addContainerGap()
-					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
-						.addGroup(gl_panel.createSequentialGroup()
-							.addComponent(treeScrollPane, GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
-							.addContainerGap())
-						.addGroup(gl_panel.createSequentialGroup()
+					.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING, false)
+						.addComponent(treeScrollPane, Alignment.LEADING)
+						.addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
 							.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
 								.addComponent(lblGraph)
 								.addComponent(lblObject)
@@ -386,8 +402,8 @@ public class splitPane extends JSplitPane implements GraphListener {
 									.addPreferredGap(ComponentPlacement.RELATED)
 									.addComponent(lblB)
 									.addPreferredGap(ComponentPlacement.RELATED)
-									.addComponent(blueField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)))
-							.addGap(32))))
+									.addComponent(blueField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)))))
+					.addGap(32))
 		);
 		gl_panel.setVerticalGroup(
 			gl_panel.createParallelGroup(Alignment.LEADING)
@@ -516,11 +532,10 @@ public class splitPane extends JSplitPane implements GraphListener {
 		setRightComponent(graphScrollPane);
 		
 		graphPanel = new JPanel();
-		graphScrollPane.setViewportView(graphPanel);
 		graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.Y_AXIS));
-		
-		JPanel panel_1 = new JPanel();
-		graphPanel.add(panel_1);
+		graphPanel.revalidate();
+		graphPanel.updateUI();
+		graphScrollPane.setViewportView(graphPanel);
 		repaintGraph();
 	}
 	@Override