|
@@ -16,6 +16,7 @@ import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Locale;
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
import java.util.Set;
|
|
import java.util.Set;
|
|
|
|
+import java.util.logging.Logger;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Stream;
|
|
import java.util.stream.Stream;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -42,6 +43,7 @@ import holeg.model.HolonElement;
|
|
import holeg.model.HolonObject;
|
|
import holeg.model.HolonObject;
|
|
import holeg.model.HolonElement.Priority;
|
|
import holeg.model.HolonElement.Priority;
|
|
import holeg.preferences.ColorPreference;
|
|
import holeg.preferences.ColorPreference;
|
|
|
|
+import holeg.preferences.ImagePreference;
|
|
import holeg.ui.controller.Control;
|
|
import holeg.ui.controller.Control;
|
|
import holeg.ui.model.GuiSettings;
|
|
import holeg.ui.model.GuiSettings;
|
|
import holeg.ui.view.component.TrippleCheckBox;
|
|
import holeg.ui.view.component.TrippleCheckBox;
|
|
@@ -53,6 +55,7 @@ import holeg.utility.pooling.Pool;
|
|
import net.miginfocom.swing.MigLayout;
|
|
import net.miginfocom.swing.MigLayout;
|
|
|
|
|
|
public class InspectorTable extends JPanel {
|
|
public class InspectorTable extends JPanel {
|
|
|
|
+ private static final Logger log = Logger.getLogger(InspectorTable.class.getName());
|
|
private final Pool<ElementRow> rowPool = new Pool<>() {
|
|
private final Pool<ElementRow> rowPool = new Pool<>() {
|
|
@Override
|
|
@Override
|
|
public ElementRow create() {
|
|
public ElementRow create() {
|
|
@@ -173,7 +176,6 @@ public class InspectorTable extends JPanel {
|
|
Comparator<ElementRow> priorityComp = Comparator.comparing((ElementRow a) -> a.element.getPriority());
|
|
Comparator<ElementRow> priorityComp = Comparator.comparing((ElementRow a) -> a.element.getPriority());
|
|
Comparator<ElementRow> activeComp = (ElementRow a, ElementRow b) -> Boolean.compare(a.element.active,
|
|
Comparator<ElementRow> activeComp = (ElementRow a, ElementRow b) -> Boolean.compare(a.element.active,
|
|
b.element.active);
|
|
b.element.active);
|
|
- ;
|
|
|
|
|
|
|
|
headerButtonList.add(new SortButton<>("Object", objectComp));
|
|
headerButtonList.add(new SortButton<>("Object", objectComp));
|
|
headerButtonList.add(new SortButton<>("Id", idComp));
|
|
headerButtonList.add(new SortButton<>("Id", idComp));
|
|
@@ -220,7 +222,7 @@ public class InspectorTable extends JPanel {
|
|
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
|
|
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
|
|
buttonPanel.add(Box.createRigidArea(new Dimension(2, 0)));
|
|
buttonPanel.add(Box.createRigidArea(new Dimension(2, 0)));
|
|
|
|
|
|
- addButton.setIcon(new ImageIcon(Import.loadImage("images/buttons/plus.png", 16, 16)));
|
|
|
|
|
|
+ addButton.setIcon(new ImageIcon(Import.loadImage(ImagePreference.Button.Inspector.Add, 16, 16)));
|
|
addButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
|
addButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
|
addButton.addActionListener(clicked -> {
|
|
addButton.addActionListener(clicked -> {
|
|
Optional<HolonObject> last = GuiSettings.getSelectedObjects().stream()
|
|
Optional<HolonObject> last = GuiSettings.getSelectedObjects().stream()
|
|
@@ -228,13 +230,13 @@ public class InspectorTable extends JPanel {
|
|
.map(obj -> (HolonObject) obj);
|
|
.map(obj -> (HolonObject) obj);
|
|
last.ifPresent(obj -> {
|
|
last.ifPresent(obj -> {
|
|
obj.add(new HolonElement(obj, "Element", 0.0f));
|
|
obj.add(new HolonElement(obj, "Element", 0.0f));
|
|
- control.calculateStateForCurrentIteration();
|
|
|
|
- updateInspectorUi();
|
|
|
|
|
|
+ control.updateStateForCurrentIteration();
|
|
|
|
+ control.OnSelectionChanged.broadcast();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
buttonPanel.add(addButton);
|
|
buttonPanel.add(addButton);
|
|
|
|
|
|
- duplicateButton.setIcon(new ImageIcon(Import.loadImage("images/buttons/duplicate.png", 16, 16)));
|
|
|
|
|
|
+ duplicateButton.setIcon(new ImageIcon(Import.loadImage(ImagePreference.Button.Inspector.Duplicate, 16, 16)));
|
|
duplicateButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
|
duplicateButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
|
duplicateButton.addActionListener(clicked -> {
|
|
duplicateButton.addActionListener(clicked -> {
|
|
rowPool.getBorrowedStream().forEach(row -> {
|
|
rowPool.getBorrowedStream().forEach(row -> {
|
|
@@ -242,21 +244,25 @@ public class InspectorTable extends JPanel {
|
|
row.element.parentObject.add(new HolonElement(row.element));
|
|
row.element.parentObject.add(new HolonElement(row.element));
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- control.calculateStateForCurrentIteration();
|
|
|
|
- updateInspectorUi();
|
|
|
|
|
|
+ control.updateStateForCurrentIteration();
|
|
|
|
+ control.OnSelectionChanged.broadcast();
|
|
});
|
|
});
|
|
buttonPanel.add(duplicateButton);
|
|
buttonPanel.add(duplicateButton);
|
|
|
|
|
|
- deleteButton.setIcon(new ImageIcon(Import.loadImage("images/buttons/minus.png", 16, 16)));
|
|
|
|
|
|
+ deleteButton.setIcon(new ImageIcon(Import.loadImage(ImagePreference.Button.Inspector.Remove, 16, 16)));
|
|
deleteButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
|
deleteButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
|
deleteButton.addActionListener(clicked -> {
|
|
deleteButton.addActionListener(clicked -> {
|
|
|
|
+ log.info("DeleteButton");
|
|
rowPool.getBorrowedStream().forEach(row -> {
|
|
rowPool.getBorrowedStream().forEach(row -> {
|
|
if (row.isSelected()) {
|
|
if (row.isSelected()) {
|
|
row.element.parentObject.remove(row.element);
|
|
row.element.parentObject.remove(row.element);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
- control.calculateStateForCurrentIteration();
|
|
|
|
- updateInspectorUi();
|
|
|
|
|
|
+ log.info("row deleted");
|
|
|
|
+ control.updateStateForCurrentIteration();
|
|
|
|
+ log.info("updated");
|
|
|
|
+ control.OnSelectionChanged.broadcast();
|
|
|
|
+ log.info("selectionChanged");
|
|
});
|
|
});
|
|
buttonPanel.add(deleteButton);
|
|
buttonPanel.add(deleteButton);
|
|
|
|
|
|
@@ -280,6 +286,7 @@ public class InspectorTable extends JPanel {
|
|
|
|
|
|
private void assignElementsToRowPool(Set<AbstractCanvasObject> selection) {
|
|
private void assignElementsToRowPool(Set<AbstractCanvasObject> selection) {
|
|
List<HolonElement> elementList = extractElements(selection).toList();
|
|
List<HolonElement> elementList = extractElements(selection).toList();
|
|
|
|
+ rowPool.getBorrowedStream().forEach(InspectorTable.ElementRow::clear);
|
|
rowPool.clear();
|
|
rowPool.clear();
|
|
for (HolonElement element : elementList) {
|
|
for (HolonElement element : elementList) {
|
|
ElementRow row = rowPool.get();
|
|
ElementRow row = rowPool.get();
|
|
@@ -297,7 +304,6 @@ public class InspectorTable extends JPanel {
|
|
try {
|
|
try {
|
|
abortThread = true;
|
|
abortThread = true;
|
|
populateRowsThread.join();
|
|
populateRowsThread.join();
|
|
- populateRowsThread.join();
|
|
|
|
abortThread = false;
|
|
abortThread = false;
|
|
} catch (InterruptedException e) {
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -403,14 +409,17 @@ public class InspectorTable extends JPanel {
|
|
}
|
|
}
|
|
|
|
|
|
public void setElement(HolonElement element) {
|
|
public void setElement(HolonElement element) {
|
|
|
|
+ objectNameTextField.setText(element.parentObject.getName());
|
|
|
|
+ idObjectTextField.setText(Integer.toString(element.parentObject.getId()));
|
|
|
|
+ elementNameTextField.setText(element.getName());
|
|
|
|
+ comboBox.setSelectedItem(element.getPriority());
|
|
|
|
+ activeCheckBox.setSelected(element.active);
|
|
|
|
+ energyTextField.setValue(element.getEnergy());
|
|
this.element = element;
|
|
this.element = element;
|
|
setSelected(false);
|
|
setSelected(false);
|
|
- objectNameTextField.setText(this.element.parentObject.getName());
|
|
|
|
- idObjectTextField.setText(Integer.toString(this.element.parentObject.getId()));
|
|
|
|
- elementNameTextField.setText(this.element.getName());
|
|
|
|
- energyTextField.setValue(this.element.getEnergy());
|
|
|
|
- comboBox.setSelectedItem(this.element.getPriority());
|
|
|
|
- activeCheckBox.setSelected(this.element.active);
|
|
|
|
|
|
+ }
|
|
|
|
+ public void clear(){
|
|
|
|
+ this.element = null;
|
|
}
|
|
}
|
|
|
|
|
|
private void createEditFields() {
|
|
private void createEditFields() {
|
|
@@ -436,7 +445,9 @@ public class InspectorTable extends JPanel {
|
|
// ObjectName and ID
|
|
// ObjectName and ID
|
|
objectNameTextField = new JTextField();
|
|
objectNameTextField = new JTextField();
|
|
objectNameTextField.getDocument().addDocumentListener((SimpleDocumentListener) e -> {
|
|
objectNameTextField.getDocument().addDocumentListener((SimpleDocumentListener) e -> {
|
|
- this.element.parentObject.setName(objectNameTextField.getText());
|
|
|
|
|
|
+ if(this.element != null){
|
|
|
|
+ this.element.parentObject.setName(objectNameTextField.getText());
|
|
|
|
+ }
|
|
});
|
|
});
|
|
objectNameTextField.addActionListener(ae -> updateInspectorUi());
|
|
objectNameTextField.addActionListener(ae -> updateInspectorUi());
|
|
cellsInRow[1] = objectNameTextField;
|
|
cellsInRow[1] = objectNameTextField;
|
|
@@ -449,7 +460,9 @@ public class InspectorTable extends JPanel {
|
|
// Name
|
|
// Name
|
|
elementNameTextField = new JTextField();
|
|
elementNameTextField = new JTextField();
|
|
elementNameTextField.getDocument().addDocumentListener((SimpleDocumentListener) e -> {
|
|
elementNameTextField.getDocument().addDocumentListener((SimpleDocumentListener) e -> {
|
|
- this.element.setName(elementNameTextField.getText());
|
|
|
|
|
|
+ if(this.element != null){
|
|
|
|
+ this.element.setName(elementNameTextField.getText());
|
|
|
|
+ }
|
|
});
|
|
});
|
|
elementNameTextField.setBackground(Color.white);
|
|
elementNameTextField.setBackground(Color.white);
|
|
cellsInRow[3] = elementNameTextField;
|
|
cellsInRow[3] = elementNameTextField;
|
|
@@ -462,7 +475,7 @@ public class InspectorTable extends JPanel {
|
|
energyTextField.addPropertyChangeListener(actionEvent -> {
|
|
energyTextField.addPropertyChangeListener(actionEvent -> {
|
|
try {
|
|
try {
|
|
float energy = Float.parseFloat(energyTextField.getText());
|
|
float energy = Float.parseFloat(energyTextField.getText());
|
|
- if (this.element.getEnergy() != energy) {
|
|
|
|
|
|
+ if (this.element != null && this.element.getEnergy() != energy) {
|
|
this.element.setEnergy(energy);
|
|
this.element.setEnergy(energy);
|
|
control.updateStateForCurrentIteration();
|
|
control.updateStateForCurrentIteration();
|
|
}
|
|
}
|
|
@@ -474,12 +487,14 @@ public class InspectorTable extends JPanel {
|
|
cellsInRow[4] = energyTextField;
|
|
cellsInRow[4] = energyTextField;
|
|
|
|
|
|
// Priority
|
|
// Priority
|
|
- comboBox = new JComboBox<Priority>(Priority.values());
|
|
|
|
|
|
+ comboBox = new JComboBox<>(Priority.values());
|
|
comboBox.setBackground(Color.white);
|
|
comboBox.setBackground(Color.white);
|
|
comboBox.setEditable(false);
|
|
comboBox.setEditable(false);
|
|
comboBox.addActionListener(ae -> {
|
|
comboBox.addActionListener(ae -> {
|
|
- this.element.setPriority((Priority) comboBox.getSelectedItem());
|
|
|
|
- control.updateStateForCurrentIteration();
|
|
|
|
|
|
+ if(this.element != null){
|
|
|
|
+ this.element.setPriority((Priority) comboBox.getSelectedItem());
|
|
|
|
+ control.updateStateForCurrentIteration();
|
|
|
|
+ }
|
|
});
|
|
});
|
|
cellsInRow[5] = comboBox;
|
|
cellsInRow[5] = comboBox;
|
|
|
|
|
|
@@ -493,8 +508,10 @@ public class InspectorTable extends JPanel {
|
|
activeCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
|
|
activeCheckBox.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
|
|
activeCheckBox.setOpaque(false);
|
|
activeCheckBox.setOpaque(false);
|
|
activeCheckBox.addActionListener(actionEvent -> {
|
|
activeCheckBox.addActionListener(actionEvent -> {
|
|
- this.element.active = activeCheckBox.isSelected();
|
|
|
|
- control.updateStateForCurrentIteration();
|
|
|
|
|
|
+ if(this.element != null){
|
|
|
|
+ this.element.active = activeCheckBox.isSelected();
|
|
|
|
+ control.updateStateForCurrentIteration();
|
|
|
|
+ }
|
|
});
|
|
});
|
|
checkBoxWrapperPanel.add(activeCheckBox, BorderLayout.CENTER);
|
|
checkBoxWrapperPanel.add(activeCheckBox, BorderLayout.CENTER);
|
|
cellsInRow[6] = checkBoxWrapperPanel;
|
|
cellsInRow[6] = checkBoxWrapperPanel;
|
|
@@ -508,7 +525,7 @@ public class InspectorTable extends JPanel {
|
|
|
|
|
|
private class SortButton<T> extends JButton {
|
|
private class SortButton<T> extends JButton {
|
|
private SortState state = SortState.None;
|
|
private SortState state = SortState.None;
|
|
- private Comparator<T> comp;
|
|
|
|
|
|
+ private final Comparator<T> comp;
|
|
|
|
|
|
public SortButton(String text, Comparator<T> comp) {
|
|
public SortButton(String text, Comparator<T> comp) {
|
|
super(text);
|
|
super(text);
|
|
@@ -534,7 +551,7 @@ public class InspectorTable extends JPanel {
|
|
this.state = state;
|
|
this.state = state;
|
|
String text = this.getText();
|
|
String text = this.getText();
|
|
// remove order symbols from text
|
|
// remove order symbols from text
|
|
- text = text.replaceAll("\u25bc|\u25b2", "");
|
|
|
|
|
|
+ text = text.replaceAll("[\u25bc\u25b2]", "");
|
|
// update text
|
|
// update text
|
|
switch (state) {
|
|
switch (state) {
|
|
case Descending -> this.setText(text + "\u25bc");
|
|
case Descending -> this.setText(text + "\u25bc");
|