Skip to content

Commit dd24737

Browse files
committed
graphic: simplify RenderOption selection
No need to support multiple selections, the set never grows to contain more than one element.
1 parent 724e916 commit dd24737

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

lib/src/main/java/jtamaro/graphic/GuiGraphicPropertiesPanel.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import javax.swing.JLabel;
77
import javax.swing.JPanel;
88
import javax.swing.JScrollPane;
9-
import javax.swing.JSplitPane;
109

1110
/**
1211
* Swing panel component that renders the properties of a graphic.
@@ -35,7 +34,7 @@ public GuiGraphicPropertiesPanel(RenderOptions renderOptions) {
3534

3635
setGraphic(null);
3736

38-
renderOptions.addRenderOptionsListener(() -> setGraphic(renderOptions.getLeadSelection()));
37+
renderOptions.addRenderOptionsListener(() -> setGraphic(renderOptions.getSelection()));
3938
}
4039

4140
public void setGraphic(Graphic graphic) {

lib/src/main/java/jtamaro/graphic/RenderOptions.java

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
package jtamaro.graphic;
22

33
import java.util.ArrayList;
4-
import java.util.Collections;
5-
import java.util.IdentityHashMap;
64
import java.util.List;
7-
import java.util.Set;
85

96
/**
107
* Graphic render configuration.
@@ -20,9 +17,7 @@ public final class RenderOptions {
2017

2118
private final int fixedHeight;
2219

23-
private final Set<Graphic> selection;
24-
25-
private Graphic leadSelection;
20+
private Graphic selection;
2621

2722
private final List<Listener> listeners;
2823

@@ -34,7 +29,7 @@ public RenderOptions(int padding, int fixedWidth, int fixedHeight) {
3429
this.padding = padding;
3530
this.fixedWidth = fixedWidth;
3631
this.fixedHeight = fixedHeight;
37-
selection = Collections.newSetFromMap(new IdentityHashMap<>());
32+
selection = null;
3833
listeners = new ArrayList<>();
3934
}
4035

@@ -60,27 +55,21 @@ public int getFixedHeight() {
6055
}
6156

6257
public void clearSelection() {
63-
selection.clear();
64-
leadSelection = null;
58+
selection = null;
6559
fireRenderOptionsChanged();
6660
}
6761

6862
void select(Graphic g) {
69-
selection.add(g);
70-
leadSelection = g;
63+
selection = g;
7164
fireRenderOptionsChanged();
7265
}
7366

7467
boolean isSelected(Graphic g) {
75-
return selection.contains(g);
76-
}
77-
78-
Graphic getLeadSelection() {
79-
return leadSelection;
68+
return selection == g;
8069
}
8170

82-
boolean isLeadSelection(Graphic g) {
83-
return selection.contains(g);
71+
Graphic getSelection() {
72+
return selection;
8473
}
8574

8675
public void addRenderOptionsListener(Listener li) {
@@ -96,8 +85,7 @@ private void fireRenderOptionsChanged() {
9685
/**
9786
* Graphic render configuration listener.
9887
*
99-
* <p>For internal usage only!
100-
*
88+
* @apiNote For internal usage only!
10189
* @hidden
10290
*/
10391
public interface Listener {

0 commit comments

Comments
 (0)