|
@@ -97,13 +97,13 @@ public class FlexWindow extends JFrame {
|
|
|
|
|
|
createMenuBar();
|
|
|
initWindowPanel(parentFrame);
|
|
|
- selectedCpsObjectsChanged();
|
|
|
this.addWindowListener(new java.awt.event.WindowAdapter() {
|
|
|
@Override
|
|
|
public void windowClosing(java.awt.event.WindowEvent windowEvent) {
|
|
|
isClosed = true;
|
|
|
}
|
|
|
});
|
|
|
+ selectAll();
|
|
|
|
|
|
}
|
|
|
|
|
@@ -140,7 +140,7 @@ public class FlexWindow extends JFrame {
|
|
|
JMenu flex = new JMenu("Flex");
|
|
|
menuBar.add(flex);
|
|
|
JMenuItem addMenuItem = new JMenuItem("Add Flexibility");
|
|
|
- addMenuItem.addActionListener(clicked -> createAddDialog());
|
|
|
+ addMenuItem.addActionListener(clicked -> createAddDialog(null));
|
|
|
flex.add(addMenuItem);
|
|
|
JMenuItem deleteMenuItem = new JMenuItem("Delete Flexibility");
|
|
|
deleteMenuItem.addActionListener(clicked -> createDeleteDialog());
|
|
@@ -322,7 +322,6 @@ public class FlexWindow extends JFrame {
|
|
|
}
|
|
|
|
|
|
public void selectedCpsObjectsChanged() {
|
|
|
-
|
|
|
updateFlexOrderMenu();
|
|
|
if(model.getSelectedCpsObjects().isEmpty()) {
|
|
|
contentPanel.setComponentAt(contentPanel.indexOfTab("Settings"), nothingSelectedPanel);
|
|
@@ -435,7 +434,7 @@ public class FlexWindow extends JFrame {
|
|
|
|
|
|
|
|
|
|
|
|
- private void createAddDialog(){
|
|
|
+ private void createAddDialog(HolonElement element){
|
|
|
if(model.getObjectsOnCanvas().isEmpty()) {
|
|
|
JOptionPane.showMessageDialog(this,
|
|
|
"No HolonObject exist.",
|
|
@@ -458,6 +457,9 @@ public class FlexWindow extends JFrame {
|
|
|
|
|
|
|
|
|
addDialog.setModalityType(ModalityType.APPLICATION_MODAL);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
HolonObject[] holonObjects = createListOfHolonObjects(model.getObjectsOnCanvas()).stream().toArray(HolonObject[]::new);
|
|
|
|
|
@@ -466,12 +468,10 @@ public class FlexWindow extends JFrame {
|
|
|
|
|
|
JComboBox<HolonObject> holonObjectSelector = new JComboBox<HolonObject>(comboBoxModel);
|
|
|
holonObjectSelector.setBounds(10,30, 800, 30);
|
|
|
- selectionPanel.add(holonObjectSelector);
|
|
|
|
|
|
DefaultComboBoxModel<HolonElement> comboBoxModelElements = new DefaultComboBoxModel<HolonElement>( holonObjects[0].getElements().stream().toArray(size -> new HolonElement[size]));
|
|
|
- JComboBox<HolonElement> holonElementSelector = new JComboBox<HolonElement>(comboBoxModelElements);
|
|
|
+ JComboBox<HolonElement> holonElementSelector = new JComboBox<HolonElement>(comboBoxModelElements);
|
|
|
holonElementSelector.setBounds(10,80, 800, 30);
|
|
|
- selectionPanel.add(holonElementSelector);
|
|
|
|
|
|
|
|
|
holonObjectSelector.addItemListener(aListener -> {
|
|
@@ -481,13 +481,27 @@ public class FlexWindow extends JFrame {
|
|
|
holonElementSelector.setModel(newComboBoxModelElements);
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ if(element == null) {
|
|
|
+ selectionPanel.add(holonObjectSelector);
|
|
|
+ selectionPanel.add(holonElementSelector);
|
|
|
+ JLabel selectObjectLabel = new JLabel("Select HolonObject:");
|
|
|
+ selectObjectLabel.setBounds(10, 10, 200, 20);
|
|
|
+ selectionPanel.add(selectObjectLabel);
|
|
|
+ JLabel selectElementLabel = new JLabel("Select HolonElement:");
|
|
|
+ selectElementLabel.setBounds(10, 60, 200, 20);
|
|
|
+ selectionPanel.add(selectElementLabel);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ JLabel selectElementLabel = new JLabel("Selected: " +element.toString());
|
|
|
+ selectElementLabel.setBounds(10, 60, 2000, 20);
|
|
|
+ selectionPanel.add(selectElementLabel);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- JLabel selectObjectLabel = new JLabel("Select HolonObject:");
|
|
|
- selectObjectLabel.setBounds(10, 10, 200, 20);
|
|
|
- selectionPanel.add(selectObjectLabel);
|
|
|
- JLabel selectElementLabel = new JLabel("Select HolonElement:");
|
|
|
- selectElementLabel.setBounds(10, 60, 200, 20);
|
|
|
- selectionPanel.add(selectElementLabel);
|
|
|
|
|
|
JPanel flexAttributesBorderPanel = new JPanel(null);
|
|
|
flexAttributesBorderPanel.setBounds(10, 120, 800, 200);
|
|
@@ -601,7 +615,12 @@ public class FlexWindow extends JFrame {
|
|
|
createFlexButton.addActionListener(clicked -> {
|
|
|
|
|
|
|
|
|
- HolonElement ele = (HolonElement) holonElementSelector.getSelectedItem();
|
|
|
+ HolonElement ele;
|
|
|
+ if(element ==null) {
|
|
|
+ ele = (HolonElement) holonElementSelector.getSelectedItem();
|
|
|
+ }else {
|
|
|
+ ele = element;
|
|
|
+ }
|
|
|
Flexibility toCreateFlex = new Flexibility(ele);
|
|
|
toCreateFlex.name = intermediateFlex.name;
|
|
|
toCreateFlex.speed = intermediateFlex.speed;
|
|
@@ -619,7 +638,7 @@ public class FlexWindow extends JFrame {
|
|
|
this.offConstrain = offConstrainCheckBox.isSelected();
|
|
|
|
|
|
|
|
|
- if(!model.getSelectedCpsObjects().contains(holonObjectSelector.getSelectedItem()))model.getSelectedCpsObjects().add((AbstractCpsObject)holonObjectSelector.getSelectedItem());
|
|
|
+
|
|
|
controller.getSimManager().calculateStateForTimeStep(model.getCurIteration(), false);
|
|
|
selectedCpsObjectsChanged();
|
|
|
addDialog.dispose();
|
|
@@ -639,17 +658,17 @@ public class FlexWindow extends JFrame {
|
|
|
}
|
|
|
|
|
|
class PopUpDemo extends JPopupMenu {
|
|
|
- JMenuItem anItem;
|
|
|
+ JMenuItem priorityItem = new JMenuItem("EditPriorities");
|
|
|
+ JMenuItem flexItem = new JMenuItem("AddFlex");
|
|
|
public PopUpDemo(JTree jTree, DefaultTreeModel model) {
|
|
|
- anItem = new JMenuItem("EditPriorities");
|
|
|
- anItem.addActionListener( clicked -> {
|
|
|
+ priorityItem.addActionListener( clicked -> {
|
|
|
TreePath[] paths = jTree.getSelectionPaths();
|
|
|
if(paths == null) {
|
|
|
jTree.setSelectionInterval(0, jTree.getRowCount());
|
|
|
paths = jTree.getSelectionPaths();
|
|
|
}
|
|
|
Priority prio = null;
|
|
|
- for (TreePath path : jTree.getSelectionPaths()) {
|
|
|
+ for (TreePath path : paths) {
|
|
|
Object treeNodeUserObject = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject();
|
|
|
if(treeNodeUserObject instanceof ElementInfo)
|
|
|
{
|
|
@@ -661,7 +680,18 @@ public class FlexWindow extends JFrame {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- add(anItem);
|
|
|
+ flexItem.addActionListener( clicked -> {
|
|
|
+ TreePath path = jTree.getSelectionPath();
|
|
|
+ if(path == null) return;
|
|
|
+ Object treeNodeUserObject = ((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject();
|
|
|
+ if(!(treeNodeUserObject instanceof ElementInfo)) return;
|
|
|
+ createAddDialog(((ElementInfo)treeNodeUserObject).ele);
|
|
|
+ });
|
|
|
+ add(priorityItem);
|
|
|
+ add(flexItem);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
private Priority makePriorityDialog() {
|
|
|
return (Priority) JOptionPane.showInputDialog(this, "Select the Priority:", "Priority?", JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , Priority.values(), "");
|