|
@@ -18,6 +18,8 @@ import ui.view.NewPopUp.Option;
|
|
|
|
|
|
import javax.swing.*;
|
|
|
import javax.swing.border.LineBorder;
|
|
|
+import javax.swing.event.AncestorEvent;
|
|
|
+import javax.swing.event.AncestorListener;
|
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
|
import javax.swing.table.DefaultTableModel;
|
|
|
import javax.swing.table.JTableHeader;
|
|
@@ -197,6 +199,7 @@ public class GUI implements CategoryListener {
|
|
|
private final JPanel panelHolonEl = new JPanel();
|
|
|
private final JComboBox comboBox = new JComboBox();
|
|
|
// Buttons
|
|
|
+
|
|
|
private final JButton btnAdd = new JButton("New");
|
|
|
private final JPopupMenu btnAddPopUp = new JPopupMenu("New");
|
|
|
private final JMenuItem mItemNew = new JMenuItem("New..");
|
|
@@ -208,6 +211,7 @@ public class GUI implements CategoryListener {
|
|
|
private final JButton btnAddHolEL = new JButton("New");
|
|
|
private final JButton btnDelHolEL = new JButton("Delete");
|
|
|
private final JButton resetGraphBtn = new JButton("Reset");
|
|
|
+
|
|
|
private final JToolBar toolBar = new JToolBar();
|
|
|
private final JToolBar toolBarHolonEl = new JToolBar();
|
|
|
private final JToolBar toolBarGraph = new JToolBar();
|
|
@@ -223,9 +227,9 @@ public class GUI implements CategoryListener {
|
|
|
private final HolonCanvas holonCanvas;
|
|
|
private final UnitGraph unitGraph;
|
|
|
/** Textfield to show the period of an element */
|
|
|
- private final JTextField unitGraphLocalPeriod = new JTextField();
|
|
|
+ private final JTextField unitGraphLocalPeriod = new JTextField(6);
|
|
|
private final JCheckBox unitGraphStretchMode=new JCheckBox();
|
|
|
- private final JLabel unitGraphStretchModeLbl=new JLabel(" Use global");//Some padding
|
|
|
+ private final JLabel unitGraphStretchModeLbl=new JLabel(" Use global: ");//Some padding
|
|
|
private final JSplitPane splitPane3 = new JSplitPane();
|
|
|
private final JSlider sizeSlider = new JSlider();
|
|
|
private final JLabel lblImageSize = new JLabel(Languages.getLanguage()[94]);
|
|
@@ -310,6 +314,7 @@ public class GUI implements CategoryListener {
|
|
|
control.initListener(this);
|
|
|
controller.setCanvas(canvas);
|
|
|
model.setConsole(console);
|
|
|
+ model.setTableProperties(tableProperties);
|
|
|
algorithmMenu = new AlgorithmMenu(model, control, this);
|
|
|
initialize();
|
|
|
updateCategories(model.getCategories());
|
|
@@ -413,6 +418,7 @@ public class GUI implements CategoryListener {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
try {
|
|
|
controller.loadAutoSave(controller.getUndoSave());
|
|
|
+ controller.calculateStateForCurrentTimeStep();
|
|
|
canvas.repaint();
|
|
|
unitGraph.update(model.getObjectsOnCanvas());
|
|
|
updateUpperNodes();
|
|
@@ -432,6 +438,7 @@ public class GUI implements CategoryListener {
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
try {
|
|
|
controller.loadAutoSave(controller.getRedoSave());
|
|
|
+ controller.calculateStateForCurrentTimeStep();
|
|
|
canvas.repaint();
|
|
|
unitGraph.update(model.getObjectsOnCanvas());
|
|
|
updateUpperNodes();
|
|
@@ -632,6 +639,7 @@ public class GUI implements CategoryListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if(tabTemp == null)return;
|
|
|
JScrollPane scrollPane = getScrollPaneFromTabbedPane();
|
|
|
Component canvasOrUpperNodeCanvas = scrollPane
|
|
|
.getViewport().getComponent(0);
|
|
@@ -644,10 +652,12 @@ public class GUI implements CategoryListener {
|
|
|
canvasOrUpperNodeCanvas
|
|
|
.getMousePosition());
|
|
|
unitGraph.update(model.getSelectedCpsObjects());
|
|
|
+ controller.calculateStateForCurrentTimeStep();
|
|
|
scrollPane.getViewport().getComponent(0).repaint();
|
|
|
} else {
|
|
|
controller.paste(null, canvas.getMousePosition());
|
|
|
unitGraph.update(model.getSelectedCpsObjects());
|
|
|
+ controller.calculateStateForCurrentTimeStep();
|
|
|
canvas.repaint();
|
|
|
}
|
|
|
} catch (HeadlessException | JsonParseException
|
|
@@ -676,13 +686,16 @@ public class GUI implements CategoryListener {
|
|
|
if (scrollPane.getViewport().getComponent(0) instanceof UpperNodeCanvas) {
|
|
|
controller.cut(((UpperNodeCanvas) scrollPane
|
|
|
.getViewport().getComponent(0)).upperNode);
|
|
|
+ controller.calculateStateForCurrentTimeStep();
|
|
|
+ scrollPane.getViewport().getComponent(0).repaint();
|
|
|
} else {
|
|
|
controller.cut(null);
|
|
|
+ controller.calculateStateForCurrentTimeStep();
|
|
|
+ canvas.repaint();
|
|
|
}
|
|
|
if (!model.getClipboradObjects().isEmpty()) {
|
|
|
canvas.itemPaste.setEnabled(true);
|
|
|
}
|
|
|
- canvas.repaint();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
@@ -1098,6 +1111,29 @@ public class GUI implements CategoryListener {
|
|
|
//refresh HolonElementTable
|
|
|
updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void mouseExited(MouseEvent e) {
|
|
|
+ /**
|
|
|
+ * Stop Editing, if mouse exits the Table
|
|
|
+ */
|
|
|
+ JTable holElem = model.getTableHolonElement();
|
|
|
+ JTableHeader holElemHead = holElem.getTableHeader();
|
|
|
+ if(e.getX()<=0 || e.getX()>=holElemHead.getWidth()
|
|
|
+ || e.getY() <= 0){
|
|
|
+ CellEditor cellEditor = holElem.getCellEditor();
|
|
|
+ if (cellEditor != null) {
|
|
|
+ if (cellEditor.getCellEditorValue() != null) {
|
|
|
+ /** TODO: Maybe try to save current Data */
|
|
|
+ cellEditor.stopCellEditing();
|
|
|
+ } else {
|
|
|
+ cellEditor.cancelCellEditing();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
});
|
|
|
model.getTableHolonElement().getTableHeader().setReorderingAllowed(false);
|
|
|
|
|
@@ -1130,35 +1166,45 @@ public class GUI implements CategoryListener {
|
|
|
graphLabel.add(medGraph, BorderLayout.CENTER);
|
|
|
graphLabel.add(minGraph, BorderLayout.SOUTH);
|
|
|
|
|
|
+ GridBagLayout gbl=new GridBagLayout();
|
|
|
+ toolBarGraph.setLayout(gbl);
|
|
|
+ GridBagConstraints c=new GridBagConstraints();
|
|
|
+ c.weightx=0;
|
|
|
+ gbl.setConstraints(lblSelectedElement, c);
|
|
|
+ //TODO here
|
|
|
toolBarGraph.add(lblSelectedElement);
|
|
|
- toolBarGraph.add(elementGraph);
|
|
|
+ c.gridwidth=GridBagConstraints.REMAINDER;
|
|
|
+ gbl.setConstraints(elementGraph, c);
|
|
|
+ toolBarGraph.add(elementGraph/*, BorderLayout.AFTER_LINE_ENDS*/);//TODO
|
|
|
|
|
|
- Component horizontalStrut = Box.createHorizontalStrut(20);
|
|
|
+ //Component horizontalStrut = Box.createHorizontalStrut(20);
|
|
|
/*
|
|
|
Component horizontalStrut = Box.createHorizontalStrut(toolBarGraph
|
|
|
.getWidth() - resetGraphBtn.getWidth() - unitGraphLocalPeriod.getWidth()
|
|
|
-unitGraphLocalPeriodLbl.getWidth());
|
|
|
|
|
|
*/
|
|
|
- toolBarGraph.add(horizontalStrut);//What is this for?
|
|
|
+ //toolBarGraph.add(horizontalStrut);//What is this for?
|
|
|
|
|
|
/** Add local Graph length Textfield an Label */
|
|
|
unitGraphLocalPeriod.setPreferredSize(new Dimension(30, 20));//TODO
|
|
|
unitGraphLocalPeriod.setText(""+unitGraph.getLocalPeriod());
|
|
|
- resetGraphBtn.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
-
|
|
|
- toolBarGraph.add(unitGraphLocalPeriodLbl);
|
|
|
- unitGraphLocalPeriodLbl.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
- toolBarGraph.add(unitGraphLocalPeriod);
|
|
|
-
|
|
|
- resetGraphBtn.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
- toolBarGraph.add(resetGraphBtn);
|
|
|
-
|
|
|
- toolBarGraph.add(unitGraphStretchModeLbl);
|
|
|
- unitGraphStretchModeLbl.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
|
|
|
- toolBarGraph.add(unitGraphStretchMode);
|
|
|
- unitGraphStretchMode.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
+ c.gridwidth=GridBagConstraints.NORTHWEST;
|
|
|
+ gbl.setConstraints(unitGraphLocalPeriodLbl, c);
|
|
|
+ toolBarGraph.add(unitGraphLocalPeriodLbl);//TODO
|
|
|
+ //unitGraphLocalPeriodLbl.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
+ gbl.setConstraints(unitGraphLocalPeriod, c);
|
|
|
+ toolBarGraph.add(unitGraphLocalPeriod);//TODO
|
|
|
+ gbl.setConstraints(unitGraphStretchModeLbl, c);
|
|
|
+ toolBarGraph.add(unitGraphStretchModeLbl);//TODO
|
|
|
+ //unitGraphStretchModeLbl.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
+ gbl.setConstraints(unitGraphStretchMode, c);
|
|
|
+ toolBarGraph.add(unitGraphStretchMode);//TODO
|
|
|
+ //unitGraphStretchMode.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
+ gbl.setConstraints(resetGraphBtn, c);
|
|
|
+ //resetGraphBtn.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
+ toolBarGraph.add(resetGraphBtn);//TODO
|
|
|
unitGraphStretchMode.addActionListener(e ->
|
|
|
{unitGraph.setStretching(unitGraphStretchMode.isSelected());}
|
|
|
);
|
|
@@ -1316,8 +1362,30 @@ public class GUI implements CategoryListener {
|
|
|
xBThis = e.getX();
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void mouseExited(MouseEvent e) {
|
|
|
+ /**
|
|
|
+ * Stop Editing, if mouse exits the Table
|
|
|
+ */
|
|
|
+ JTable holElem = model.getTableHolonElement();
|
|
|
+ if(e.getX()<=0 || e.getX()>=holElem.getWidth()
|
|
|
+ /*|| e.getY() <= 0*/|| e.getY()>= holElem.getHeight()){
|
|
|
+ CellEditor cellEditor = holElem.getCellEditor();
|
|
|
+ if (cellEditor != null) {
|
|
|
+ if (cellEditor.getCellEditorValue() != null) {
|
|
|
+ /** TODO: Maybe try to save current Data */
|
|
|
+ cellEditor.stopCellEditing();
|
|
|
+ } else {
|
|
|
+ cellEditor.cancelCellEditing();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
/*
|
|
|
* Triggered every time a change is made
|
|
|
*/
|
|
@@ -2242,14 +2310,16 @@ public class GUI implements CategoryListener {
|
|
|
fileChooser.setFileFilter(holonFilter);
|
|
|
|
|
|
if (fileChooser.showSaveDialog(frmCyberPhysical) == JFileChooser.APPROVE_OPTION) {
|
|
|
- String file = fileChooser.getSelectedFile().getPath();
|
|
|
+ File selectedFile = fileChooser.getSelectedFile();
|
|
|
+ String fileName = selectedFile.getName();
|
|
|
+ String fullPath = fileChooser.getSelectedFile().getPath();
|
|
|
if (fileChooser.getFileFilter().equals(holonFilter)) {
|
|
|
- if (!file.contains("."))
|
|
|
- file += ".holon";
|
|
|
+ if (!fileName.contains("."))
|
|
|
+ fullPath += ".holon";
|
|
|
}
|
|
|
- if (!file.endsWith(".holon")) {
|
|
|
- String suffix = file.substring(file.lastIndexOf("."),
|
|
|
- file.length());
|
|
|
+ if (!fullPath.endsWith(".holon")) {
|
|
|
+ String suffix = fullPath.substring(fullPath.lastIndexOf("."),
|
|
|
+ fullPath.length());
|
|
|
String[] options = new String[] { "keep .holon",
|
|
|
"use " + suffix };
|
|
|
|
|
@@ -2264,11 +2334,11 @@ public class GUI implements CategoryListener {
|
|
|
options[1]);
|
|
|
|
|
|
if (response == 0)
|
|
|
- file = file.replace(suffix, ".holon");
|
|
|
+ fullPath = fullPath.replace(suffix, ".holon");
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- controller.saveFile(new File(file).getAbsolutePath());
|
|
|
+ controller.saveFile(new File(fullPath).getAbsolutePath());
|
|
|
} catch (IOException | ArchiveException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -2311,6 +2381,7 @@ public class GUI implements CategoryListener {
|
|
|
private void menuUndoActionPerformed() {
|
|
|
try {
|
|
|
controller.loadAutoSave(controller.getUndoSave());
|
|
|
+ controller.calculateStateForCurrentTimeStep();
|
|
|
canvas.repaint();
|
|
|
|
|
|
repaintGraphAfterUndoRedo();
|
|
@@ -2330,6 +2401,7 @@ public class GUI implements CategoryListener {
|
|
|
private void menuRedoActionPerformed() {
|
|
|
try {
|
|
|
controller.loadAutoSave(controller.getRedoSave());
|
|
|
+ controller.calculateStateForCurrentTimeStep();
|
|
|
canvas.repaint();
|
|
|
|
|
|
repaintGraphAfterUndoRedo();
|
|
@@ -2907,7 +2979,8 @@ public class GUI implements CategoryListener {
|
|
|
*/
|
|
|
private void chooseTabTemp() {
|
|
|
// is the uppernode on tabbedPaneOriginal or tabbedPaneSplit
|
|
|
- if (tabbedPaneOriginal.getMousePosition() != null) {
|
|
|
+ /* TODO: Fix or Remove SplitView */
|
|
|
+ if (tabbedPaneOriginal.getMousePosition() != null || initSplit) {
|
|
|
tabTemp = tabbedPaneOriginal;
|
|
|
} else {
|
|
|
tabTemp = tabbedPaneSplit;
|