|
@@ -53,7 +53,7 @@ import holeg.utility.pooling.Pool;
|
|
|
import net.miginfocom.swing.MigLayout;
|
|
|
|
|
|
public class InspectorTable extends JPanel {
|
|
|
- private Pool<ElementRow> rowPool = new Pool<ElementRow>() {
|
|
|
+ private final Pool<ElementRow> rowPool = new Pool<>() {
|
|
|
@Override
|
|
|
public ElementRow create() {
|
|
|
return new ElementRow();
|
|
@@ -63,7 +63,7 @@ public class InspectorTable extends JPanel {
|
|
|
private final int maxDisplayedRowsNumber = 100;
|
|
|
private int actualPage = 0;
|
|
|
private int maxPageNumberForThisSelection = 0;
|
|
|
- private Control control;
|
|
|
+ private final Control control;
|
|
|
private final int columnHeight = 20;
|
|
|
// UI
|
|
|
private final TrippleCheckBox selectAllCheckBox = new TrippleCheckBox();
|
|
@@ -76,7 +76,7 @@ public class InspectorTable extends JPanel {
|
|
|
private final JButton pageDecreaseButton = new JButton();
|
|
|
private final JLabel pageInformationLabel = new JLabel();
|
|
|
private final JPanel pageSelectionPanel = new JPanel();
|
|
|
- private ArrayList<SortButton<ElementRow>> headerButtonList = new ArrayList<>();
|
|
|
+ private final ArrayList<SortButton<ElementRow>> headerButtonList = new ArrayList<>();
|
|
|
private final static NumberFormatter doubleFormatter = generateNumberFormatter();
|
|
|
|
|
|
// sorting
|
|
@@ -91,7 +91,7 @@ public class InspectorTable extends JPanel {
|
|
|
private boolean abortThread = false;
|
|
|
|
|
|
public InspectorTable(Control control) {
|
|
|
- control.OnSelectionChanged.addListener(() -> updateInspectorUi());
|
|
|
+ control.OnSelectionChanged.addListener(this::updateInspectorUi);
|
|
|
this.control = control;
|
|
|
init();
|
|
|
addHeader();
|
|
@@ -136,16 +136,10 @@ public class InspectorTable extends JPanel {
|
|
|
};
|
|
|
|
|
|
private void performPageAction(PageAction action) {
|
|
|
- int newPageNumber;
|
|
|
- switch (action) {
|
|
|
- case Decrease:
|
|
|
- newPageNumber = Math.max(actualPage - 1, 0);
|
|
|
- break;
|
|
|
- case Increase:
|
|
|
- default:
|
|
|
- newPageNumber = Math.min(actualPage + 1, maxPageNumberForThisSelection);
|
|
|
- break;
|
|
|
- }
|
|
|
+ int newPageNumber = switch (action) {
|
|
|
+ case Decrease -> Math.max(actualPage - 1, 0);
|
|
|
+ default -> Math.min(actualPage + 1, maxPageNumberForThisSelection);
|
|
|
+ };
|
|
|
if (newPageNumber != actualPage) {
|
|
|
actualPage = newPageNumber;
|
|
|
updateTableUi();
|
|
@@ -172,26 +166,22 @@ public class InspectorTable extends JPanel {
|
|
|
}
|
|
|
|
|
|
private void initHeaderButtons() {
|
|
|
- Comparator<ElementRow> objectComp = (ElementRow a, ElementRow b) -> a.element.parentObject.getName()
|
|
|
- .compareTo(b.element.parentObject.getName());
|
|
|
- Comparator<ElementRow> idComp = (ElementRow a, ElementRow b) -> Integer.compare(a.element.parentObject.getId(),
|
|
|
- b.element.parentObject.getId());
|
|
|
- Comparator<ElementRow> deviceComp = (ElementRow a, ElementRow b) -> a.element.getName()
|
|
|
- .compareTo(b.element.getName());
|
|
|
+ Comparator<ElementRow> objectComp = Comparator.comparing((ElementRow a) -> a.element.parentObject.getName());
|
|
|
+ Comparator<ElementRow> idComp = Comparator.comparingInt((ElementRow a) -> a.element.parentObject.getId());
|
|
|
+ Comparator<ElementRow> deviceComp = Comparator.comparing((ElementRow a) -> a.element.getName());
|
|
|
Comparator<ElementRow> energyComp = (ElementRow a, ElementRow b) -> Float.compare(a.element.getEnergy(),
|
|
|
b.element.getEnergy());
|
|
|
- Comparator<ElementRow> priorityComp = (ElementRow a, ElementRow b) -> a.element.getPriority()
|
|
|
- .compareTo(b.element.getPriority());
|
|
|
+ Comparator<ElementRow> priorityComp = Comparator.comparing((ElementRow a) -> a.element.getPriority());
|
|
|
Comparator<ElementRow> activeComp = (ElementRow a, ElementRow b) -> Boolean.compare(a.element.active,
|
|
|
b.element.active);
|
|
|
;
|
|
|
|
|
|
- headerButtonList.add(new SortButton<ElementRow>("Object", objectComp));
|
|
|
- headerButtonList.add(new SortButton<ElementRow>("Id", idComp));
|
|
|
- headerButtonList.add(new SortButton<ElementRow>("Device", deviceComp));
|
|
|
- headerButtonList.add(new SortButton<ElementRow>("Energy", energyComp));
|
|
|
- headerButtonList.add(new SortButton<ElementRow>("Priority", priorityComp));
|
|
|
- headerButtonList.add(new SortButton<ElementRow>("Activ", activeComp));
|
|
|
+ headerButtonList.add(new SortButton<>("Object", objectComp));
|
|
|
+ headerButtonList.add(new SortButton<>("Id", idComp));
|
|
|
+ headerButtonList.add(new SortButton<>("Device", deviceComp));
|
|
|
+ headerButtonList.add(new SortButton<>("Energy", energyComp));
|
|
|
+ headerButtonList.add(new SortButton<>("Priority", priorityComp));
|
|
|
+ headerButtonList.add(new SortButton<>("Active", activeComp));
|
|
|
}
|
|
|
|
|
|
private void addHeader() {
|
|
@@ -273,7 +263,6 @@ public class InspectorTable extends JPanel {
|
|
|
buttonPanel.add(deleteButton);
|
|
|
|
|
|
pageIncreaseButton.setIcon(new ImageIcon(Import.loadImage("images/buttons/page_increase.png", 16, 16)));
|
|
|
- ;
|
|
|
pageIncreaseButton.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
|
|
|
pageIncreaseButton.addActionListener(clicked -> this.performPageAction(PageAction.Increase));
|
|
|
|
|
@@ -320,10 +309,8 @@ public class InspectorTable extends JPanel {
|
|
|
int numberOfRows = rowPool.getBorrowedCount();
|
|
|
this.removeAll();
|
|
|
addHeader();
|
|
|
- rowPool.getBorrowedStream().sorted(actual_comp).skip(actualPage * maxDisplayedRowsNumber)
|
|
|
- .limit(maxDisplayedRowsNumber).takeWhile(row -> !abortThread).forEach(row -> {
|
|
|
- row.addContainerToInspector();
|
|
|
- });
|
|
|
+ rowPool.getBorrowedStream().sorted(actual_comp).skip((long) actualPage * maxDisplayedRowsNumber)
|
|
|
+ .limit(maxDisplayedRowsNumber).takeWhile(row -> !abortThread).forEach(ElementRow::addContainerToInspector);
|
|
|
if (numberOfRows > maxDisplayedRowsNumber) {
|
|
|
int lastDisplayedElementNumber = Math.min(numberOfRows, (actualPage + 1) * maxDisplayedRowsNumber);
|
|
|
pageInformationLabel.setText(String.format("%d - %d from %d", 1 + actualPage * maxDisplayedRowsNumber,
|
|
@@ -340,7 +327,7 @@ public class InspectorTable extends JPanel {
|
|
|
selectAllCheckBox.setSelectionState(State.unselected);
|
|
|
revalidate();
|
|
|
repaint();
|
|
|
- this.OnElementSelectionChanged.broadcast(new HashSet<HolonElement>());
|
|
|
+ this.OnElementSelectionChanged.broadcast(new HashSet<>());
|
|
|
});
|
|
|
populateRowsThread.start();
|
|
|
|
|
@@ -375,7 +362,7 @@ public class InspectorTable extends JPanel {
|
|
|
// Extract elements from a list of AbstractCanvasObjects
|
|
|
static Stream<HolonElement> extractElements(Collection<AbstractCanvasObject> toInspect) {
|
|
|
Stream<HolonElement> recursiveLayer = toInspect.stream().filter(object -> object instanceof GroupNode).flatMap(
|
|
|
- obj -> ((GroupNode) obj).getAllHolonObjectsRecursive().flatMap(hO -> hO.elementsStream()));
|
|
|
+ obj -> ((GroupNode) obj).getAllHolonObjectsRecursive().flatMap(HolonObject::elementsStream));
|
|
|
Stream<HolonElement> thisLayer = toInspect.stream().filter(obj -> obj instanceof HolonObject).flatMap(obj -> {
|
|
|
HolonObject ho = (HolonObject) obj;
|
|
|
return ho.elementsStream();
|
|
@@ -385,7 +372,7 @@ public class InspectorTable extends JPanel {
|
|
|
|
|
|
private class ElementRow {
|
|
|
private HolonElement element = null;
|
|
|
- private Container[] cellsInRow = new Container[7];
|
|
|
+ private final Container[] cellsInRow = new Container[7];
|
|
|
// TextBoxes
|
|
|
private JTextField elementNameTextField;
|
|
|
private JCheckBox selectionBox;
|
|
@@ -493,6 +480,7 @@ public class InspectorTable extends JPanel {
|
|
|
comboBox.setEditable(false);
|
|
|
comboBox.addActionListener(ae -> {
|
|
|
this.element.setPriority((Priority) comboBox.getSelectedItem());
|
|
|
+ control.updateStateForCurrentIteration();
|
|
|
});
|
|
|
cellsInRow[5] = comboBox;
|
|
|
|
|
@@ -507,7 +495,7 @@ public class InspectorTable extends JPanel {
|
|
|
activeCheckBox.setOpaque(false);
|
|
|
activeCheckBox.addActionListener(actionEvent -> {
|
|
|
this.element.active = activeCheckBox.isSelected();
|
|
|
- control.calculateStateForCurrentIteration();
|
|
|
+ control.updateStateForCurrentIteration();
|
|
|
});
|
|
|
checkBoxWrapperPanel.add(activeCheckBox, BorderLayout.CENTER);
|
|
|
cellsInRow[6] = checkBoxWrapperPanel;
|
|
@@ -550,28 +538,17 @@ public class InspectorTable extends JPanel {
|
|
|
text = text.replaceAll("\u25bc|\u25b2", "");
|
|
|
// update text
|
|
|
switch (state) {
|
|
|
- case Descending:
|
|
|
- this.setText(text + "\u25bc");
|
|
|
- break;
|
|
|
- case Ascending:
|
|
|
- this.setText(text + "\u25b2");
|
|
|
- break;
|
|
|
- case None:
|
|
|
- default:
|
|
|
- this.setText(text);
|
|
|
- break;
|
|
|
+ case Descending -> this.setText(text + "\u25bc");
|
|
|
+ case Ascending -> this.setText(text + "\u25b2");
|
|
|
+ default -> this.setText(text);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public Comparator<T> getComp() {
|
|
|
- switch (state) {
|
|
|
- case Descending:
|
|
|
- return comp.reversed();
|
|
|
- case Ascending:
|
|
|
- case None:
|
|
|
- default:
|
|
|
- return comp;
|
|
|
- }
|
|
|
+ return switch (state) {
|
|
|
+ case Descending -> comp.reversed();
|
|
|
+ default -> comp;
|
|
|
+ };
|
|
|
}
|
|
|
}
|
|
|
}
|