|
@@ -4,7 +4,11 @@ import java.awt.BorderLayout;
|
|
import java.awt.Color;
|
|
import java.awt.Color;
|
|
import java.awt.Component;
|
|
import java.awt.Component;
|
|
import java.awt.FlowLayout;
|
|
import java.awt.FlowLayout;
|
|
|
|
+import java.awt.GridBagConstraints;
|
|
|
|
+import java.awt.GridBagLayout;
|
|
|
|
+import java.awt.Insets;
|
|
import java.awt.Dialog.ModalityType;
|
|
import java.awt.Dialog.ModalityType;
|
|
|
|
+import java.awt.Dimension;
|
|
import java.awt.event.ItemEvent;
|
|
import java.awt.event.ItemEvent;
|
|
import java.awt.image.BufferedImage;
|
|
import java.awt.image.BufferedImage;
|
|
import java.math.RoundingMode;
|
|
import java.math.RoundingMode;
|
|
@@ -12,6 +16,7 @@ import java.text.NumberFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Locale;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
import javax.swing.BorderFactory;
|
|
import javax.swing.BorderFactory;
|
|
import javax.swing.Box;
|
|
import javax.swing.Box;
|
|
@@ -43,6 +48,10 @@ import classes.CpsUpperNode;
|
|
import classes.Flexibility;
|
|
import classes.Flexibility;
|
|
import classes.HolonElement;
|
|
import classes.HolonElement;
|
|
import classes.HolonObject;
|
|
import classes.HolonObject;
|
|
|
|
+import ui.controller.Control;
|
|
|
|
+import ui.controller.FlexManager;
|
|
|
|
+import ui.controller.FlexManager.FlexState;
|
|
|
|
+import ui.controller.FlexManager.FlexWrapper;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
|
|
|
|
|
|
|
|
@@ -52,11 +61,12 @@ public class FlexWindow extends JFrame {
|
|
|
|
|
|
|
|
|
|
private JTabbedPane contentPanel = new JTabbedPane();
|
|
private JTabbedPane contentPanel = new JTabbedPane();
|
|
- private JPanel usageViewPanel;
|
|
|
|
|
|
+ private JScrollPane usageViewPanel;
|
|
|
|
|
|
|
|
+ private Control controller;
|
|
private Model model;
|
|
private Model model;
|
|
|
|
|
|
-
|
|
|
|
|
|
+ public boolean isClosed = false;
|
|
|
|
|
|
//Flexibility Intermediate
|
|
//Flexibility Intermediate
|
|
private Flexibility intermediateFlex = new Flexibility(null);
|
|
private Flexibility intermediateFlex = new Flexibility(null);
|
|
@@ -68,18 +78,25 @@ public class FlexWindow extends JFrame {
|
|
private DefaultMutableTreeNode listOfAllSelectedHolonObjects;
|
|
private DefaultMutableTreeNode listOfAllSelectedHolonObjects;
|
|
private JTree stateTree;
|
|
private JTree stateTree;
|
|
private DefaultTreeModel treeModel;
|
|
private DefaultTreeModel treeModel;
|
|
|
|
+ private FlexManager flexmanager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- public FlexWindow(JFrame parentFrame, Model model){
|
|
|
|
|
|
+ public FlexWindow(JFrame parentFrame, ui.controller.Control controller){
|
|
this.intermediateFlex.name = "name";
|
|
this.intermediateFlex.name = "name";
|
|
|
|
+ this.controller = controller;
|
|
|
|
+ this.model = controller.getModel();
|
|
//InitWindow
|
|
//InitWindow
|
|
createMenuBar();
|
|
createMenuBar();
|
|
initWindowPanel(parentFrame);
|
|
initWindowPanel(parentFrame);
|
|
- this.model = model;
|
|
|
|
selectedCpsObjectsChanged();
|
|
selectedCpsObjectsChanged();
|
|
- System.out.println("Ich wurde erstellt.");
|
|
|
|
|
|
+ this.addWindowListener(new java.awt.event.WindowAdapter() {
|
|
|
|
+ @Override
|
|
|
|
+ public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
|
|
|
+ isClosed = true;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
//this.pack();
|
|
//this.pack();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -91,7 +108,7 @@ public class FlexWindow extends JFrame {
|
|
this.setTitle("Flexibility");
|
|
this.setTitle("Flexibility");
|
|
this.setLocationRelativeTo(parentFrame);
|
|
this.setLocationRelativeTo(parentFrame);
|
|
this.setVisible(true);
|
|
this.setVisible(true);
|
|
-
|
|
|
|
|
|
+ //this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
|
createNothingSelectedPanel();
|
|
createNothingSelectedPanel();
|
|
createSelectedPanel();
|
|
createSelectedPanel();
|
|
createUsageViewPanel();
|
|
createUsageViewPanel();
|
|
@@ -134,30 +151,128 @@ public class FlexWindow extends JFrame {
|
|
|
|
|
|
|
|
|
|
private void createUsageViewPanel() {
|
|
private void createUsageViewPanel() {
|
|
- usageViewPanel = new JPanel();
|
|
|
|
- usageViewPanel.setLayout(new BoxLayout(usageViewPanel, BoxLayout.PAGE_AXIS));
|
|
|
|
- usageViewPanel.add(new JLabel("Test bla"));
|
|
|
|
- addFlexToUsageView(this.intermediateFlex);
|
|
|
|
- addFlexToUsageView(this.intermediateFlex);
|
|
|
|
- addFlexToUsageView(this.intermediateFlex);
|
|
|
|
- addFlexToUsageView(this.intermediateFlex);
|
|
|
|
- addFlexToUsageView(this.intermediateFlex);
|
|
|
|
- }
|
|
|
|
|
|
+ flexmanager = controller.getSimManager().getActualFlexManager();
|
|
|
|
+ //GridBagApprouch
|
|
|
|
+ JPanel gridbagPanel = new JPanel(new GridBagLayout());
|
|
|
|
+ usageViewPanel = new JScrollPane(gridbagPanel);
|
|
|
|
+ gridbagPanel.setBackground(Color.white);
|
|
|
|
+ //5breit
|
|
|
|
+ FlexState[] titles = FlexState.values();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i<5; i++){
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ List<FlexWrapper> listOfFlexWithState = flexmanager.getAllFlexWrapperWithState(titles[i]);
|
|
|
|
+ JLabel label = new JLabel(titles[i].toString() + "[" + listOfFlexWithState.size()+ "]");
|
|
|
|
+ GridBagConstraints labelC = new GridBagConstraints();
|
|
|
|
+ labelC.gridx = 1;
|
|
|
|
+ labelC.gridy = i*2;
|
|
|
|
+ labelC.anchor = GridBagConstraints.LINE_START;
|
|
|
|
+ labelC.fill = GridBagConstraints.HORIZONTAL;
|
|
|
|
+ labelC.weightx = 0.5;
|
|
|
|
+ labelC.weighty = 0.0;
|
|
|
|
+ gridbagPanel.add(label, labelC);
|
|
|
|
+
|
|
|
|
+ JPanel listPanel = new JPanel(new GridBagLayout());
|
|
|
|
+ createFlexPanel(listPanel, listOfFlexWithState);
|
|
|
|
+ GridBagConstraints panelC = new GridBagConstraints();
|
|
|
|
+ panelC.gridx = 0;
|
|
|
|
+ panelC.gridwidth = 2;
|
|
|
|
+ panelC.gridy = i*2 +1;
|
|
|
|
+ panelC.fill = GridBagConstraints.BOTH;
|
|
|
|
+ gridbagPanel.add(listPanel, panelC);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ JButton expandButton = new JButton("-");
|
|
|
|
+ GridBagConstraints buttonC = new GridBagConstraints();
|
|
|
|
+ buttonC.gridx = 0;
|
|
|
|
+ buttonC.gridy = i*2;
|
|
|
|
+ gridbagPanel.add(expandButton, buttonC);
|
|
|
|
+ expandButton.addActionListener(clicked -> {
|
|
|
|
+ listPanel.setVisible(!listPanel.isVisible());
|
|
|
|
+ expandButton.setText(listPanel.isVisible()?"-":"+");
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ //Add Spacer
|
|
|
|
+ JLabel spacer = new JLabel();
|
|
|
|
+ GridBagConstraints c = new GridBagConstraints();
|
|
|
|
+ c.gridx = 0;
|
|
|
|
+ c.gridy = 5*2;
|
|
|
|
+ c.fill = GridBagConstraints.VERTICAL;
|
|
|
|
+ c.weightx = 0.0;
|
|
|
|
+ c.weighty = 1;
|
|
|
|
+ gridbagPanel.add(spacer, c);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
- private void addFlexToUsageView(Flexibility flex) {
|
|
|
|
- JPanel newFlexRow = new JPanel(new FlowLayout( FlowLayout.CENTER));
|
|
|
|
- newFlexRow.add(new JLabel(flex.name));
|
|
|
|
- JButton useFlexButton = new JButton("Use Flex");
|
|
|
|
- useFlexButton.addActionListener(clicked ->{
|
|
|
|
- System.out.println("Use Flex button pressed");
|
|
|
|
- });
|
|
|
|
- newFlexRow.add(useFlexButton);
|
|
|
|
|
|
|
|
- usageViewPanel.add(newFlexRow);
|
|
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ private void createFlexPanel(JPanel listPanel, List<FlexWrapper> flexWrapperList) {
|
|
|
|
+ listPanel.setBackground(Color.white);
|
|
|
|
+
|
|
|
|
+ Insets insets = new Insets(2,2,2,2);
|
|
|
|
+
|
|
|
|
+ //String[] flexesString = flexWrapperList.stream().map(flexWrapper -> flexWrapper.getFlex().name).toArray(String[]::new);
|
|
|
|
+ for(int i = 0; i < flexWrapperList.size(); i++) {
|
|
|
|
+ FlexWrapper actual = flexWrapperList.get(i);
|
|
|
|
+ GridBagConstraints c = new GridBagConstraints();
|
|
|
|
+ c.gridx = Math.floorMod(i, 5);
|
|
|
|
+ c.weightx = 0.0;
|
|
|
|
+ c.insets = insets;
|
|
|
|
+ JButton labelButton = new JButton(actual.getFlex().name);
|
|
|
|
+ labelButton.setPreferredSize(new Dimension(70,70));
|
|
|
|
+ labelButton.setBorder(BorderFactory.createLineBorder(Color.black));
|
|
|
|
+ listPanel.add(labelButton, c);
|
|
|
|
+ labelButton.addActionListener(clicked ->{
|
|
|
|
+ actual.order();
|
|
|
|
+ controller.calculateStateAndVisualForCurrentTimeStep();
|
|
|
|
+ controller.updateCanvas();
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ //AddSpacer
|
|
|
|
+ JLabel spacer = new JLabel();
|
|
|
|
+ GridBagConstraints c = new GridBagConstraints();
|
|
|
|
+ c.gridx = 5;
|
|
|
|
+ c.gridy = 0;
|
|
|
|
+ c.fill = GridBagConstraints.VERTICAL;
|
|
|
|
+ c.weightx = 1;
|
|
|
|
+ c.weighty = 0;
|
|
|
|
+
|
|
|
|
+ listPanel.add(spacer, c);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public void updateFlexOrderMenu() {
|
|
|
|
+ createUsageViewPanel();
|
|
|
|
+ contentPanel.setComponentAt(contentPanel.indexOfTab("Order"), usageViewPanel);
|
|
|
|
+ contentPanel.revalidate();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
private void createSelectedPanel() {
|
|
private void createSelectedPanel() {
|
|
//Liste aller Flexibilities
|
|
//Liste aller Flexibilities
|
|
listOfAllSelectedHolonObjects = new DefaultMutableTreeNode("HolonObjects");
|
|
listOfAllSelectedHolonObjects = new DefaultMutableTreeNode("HolonObjects");
|
|
@@ -180,6 +295,8 @@ public class FlexWindow extends JFrame {
|
|
}
|
|
}
|
|
|
|
|
|
public void selectedCpsObjectsChanged() {
|
|
public void selectedCpsObjectsChanged() {
|
|
|
|
+ //TODO:Maybe wrong place
|
|
|
|
+ updateFlexOrderMenu();
|
|
if(model.getSelectedCpsObjects().isEmpty()) {
|
|
if(model.getSelectedCpsObjects().isEmpty()) {
|
|
contentPanel.setComponentAt(contentPanel.indexOfTab("Settings"), nothingSelectedPanel);
|
|
contentPanel.setComponentAt(contentPanel.indexOfTab("Settings"), nothingSelectedPanel);
|
|
contentPanel.revalidate();
|
|
contentPanel.revalidate();
|
|
@@ -263,6 +380,7 @@ public class FlexWindow extends JFrame {
|
|
if(toDeleteFlex != null) {
|
|
if(toDeleteFlex != null) {
|
|
System.out.println("ToDelete:" + toDeleteFlex);
|
|
System.out.println("ToDelete:" + toDeleteFlex);
|
|
toDeleteFlex.getElement().flexList.remove(toDeleteFlex);
|
|
toDeleteFlex.getElement().flexList.remove(toDeleteFlex);
|
|
|
|
+ controller.getSimManager().calculateStateForTimeStep(model.getCurIteration(), true);
|
|
selectedCpsObjectsChanged();
|
|
selectedCpsObjectsChanged();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -466,6 +584,7 @@ public class FlexWindow extends JFrame {
|
|
|
|
|
|
|
|
|
|
if(!model.getSelectedCpsObjects().contains(holonObjectSelector.getSelectedItem()))model.getSelectedCpsObjects().add((AbstractCpsObject)holonObjectSelector.getSelectedItem());
|
|
if(!model.getSelectedCpsObjects().contains(holonObjectSelector.getSelectedItem()))model.getSelectedCpsObjects().add((AbstractCpsObject)holonObjectSelector.getSelectedItem());
|
|
|
|
+ controller.getSimManager().calculateStateForTimeStep(model.getCurIteration(), false);
|
|
selectedCpsObjectsChanged();
|
|
selectedCpsObjectsChanged();
|
|
addDialog.dispose();
|
|
addDialog.dispose();
|
|
});
|
|
});
|