Skip to content

Commit

Permalink
Back topology mode queries by AppStatePersisted rather than TopologyM…
Browse files Browse the repository at this point in the history
…odeSelectionPanel
  • Loading branch information
kwvanderlinde committed Nov 12, 2024
1 parent 806f259 commit 9a4f5e7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,9 @@
import net.rptools.maptool.model.Zone;

public class TopologyModeSelectionPanel extends JToolBar {
/** The instance. Used to update the button when the ZoneRenderer is changed. */
private static TopologyModeSelectionPanel instance;

public static TopologyModeSelectionPanel getInstance() {
return instance;
}

private final Map<Zone.TopologyType, JToggleButton> modeButtons;

public TopologyModeSelectionPanel() {
instance = this;

setFloatable(false);
setRollover(true);
setBorder(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.util.List;
import javax.annotation.Nullable;
import javax.swing.SwingUtilities;
import net.rptools.maptool.client.AppStatePersisted;
import net.rptools.maptool.client.AppStyle;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.swing.TopologyModeSelectionPanel;
import net.rptools.maptool.client.ui.zone.renderer.ZoneRenderer;
import net.rptools.maptool.model.Token;
import net.rptools.maptool.model.Zone;
Expand All @@ -36,7 +36,6 @@ public final class TopologyTool<StateT> extends AbstractDrawingLikeTool {
private final String tooltipKey;
private final boolean isFilled;
private final Strategy<StateT> strategy;
private final TopologyModeSelectionPanel modeSelectionPanel;

/** The current state of the tool. If {@code null}, nothing is being drawn right now. */
private @Nullable StateT state;
Expand All @@ -46,17 +45,11 @@ public final class TopologyTool<StateT> extends AbstractDrawingLikeTool {
private boolean centerOnOrigin;

public TopologyTool(
String instructionKey,
String tooltipKey,
boolean isFilled,
Strategy<StateT> strategy,
TopologyModeSelectionPanel modeSelectionPanel) {
String instructionKey, String tooltipKey, boolean isFilled, Strategy<StateT> strategy) {
this.instructionKey = instructionKey;
this.tooltipKey = tooltipKey;
this.isFilled = isFilled;
this.strategy = strategy;
this.modeSelectionPanel = modeSelectionPanel;

// Consistency with topology tools before refactoring. Can be updated as part of #5002.
this.centerOnOrigin = this.strategy instanceof OvalStrategy;
}
Expand Down Expand Up @@ -110,7 +103,7 @@ private void submit(Shape shape) {
}

MapTool.serverCommand()
.updateTopology(getZone(), area, isEraser(), modeSelectionPanel.getMode());
.updateTopology(getZone(), area, isEraser(), AppStatePersisted.getTopologyTypes());
}

private Area getTokenTopology(Zone.TopologyType topologyType) {
Expand Down
29 changes: 10 additions & 19 deletions src/main/java/net/rptools/maptool/client/ui/ToolbarPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,24 +380,21 @@ protected void activate() {
private OptionPanel createTopologyPanel() {
OptionPanel panel = new OptionPanel();

var topologyModeSelectionPanel = new TopologyModeSelectionPanel();
panel
.addTool(
new TopologyTool<>(
"tool.recttopology.instructions",
"tool.recttopology.tooltip",
true,
new RectangleStrategy(),
topologyModeSelectionPanel))
new RectangleStrategy()))
.setIcon(RessourceManager.getBigIcon(Icons.TOOLBAR_TOPOLOGY_BOX));
panel
.addTool(
new TopologyTool<>(
"tool.recttopology.instructions",
"tool.recttopologyhollow.tooltip",
false,
new RectangleStrategy(),
topologyModeSelectionPanel))
new RectangleStrategy()))
.setIcon(RessourceManager.getBigIcon(Icons.TOOLBAR_TOPOLOGY_BOX_HOLLOW));
panel
.addTool(
Expand All @@ -406,8 +403,7 @@ private OptionPanel createTopologyPanel() {
"tool.ovaltopology.tooltip",
true,
// 10 steps to keep number of topology vertices reasonable.
new OvalStrategy(10),
topologyModeSelectionPanel))
new OvalStrategy(10)))
.setIcon(RessourceManager.getBigIcon(Icons.TOOLBAR_TOPOLOGY_OVAL));
panel
.addTool(
Expand All @@ -416,58 +412,53 @@ private OptionPanel createTopologyPanel() {
"tool.ovaltopologyhollow.tooltip",
false,
// 10 steps to keep number of topology vertices reasonable.
new OvalStrategy(10),
topologyModeSelectionPanel))
new OvalStrategy(10)))
.setIcon(RessourceManager.getBigIcon(Icons.TOOLBAR_TOPOLOGY_OVAL_HOLLOW));
panel
.addTool(
new TopologyTool<>(
"tool.poly.instructions",
"tool.polytopo.tooltip",
true,
new PolyLineStrategy(false),
topologyModeSelectionPanel))
new PolyLineStrategy(false)))
.setIcon(RessourceManager.getBigIcon(Icons.TOOLBAR_TOPOLOGY_POLYGON));
panel
.addTool(
new TopologyTool<>(
"tool.poly.instructions",
"tool.polylinetopo.tooltip",
false,
new PolyLineStrategy(false),
topologyModeSelectionPanel))
new PolyLineStrategy(false)))
.setIcon(RessourceManager.getBigIcon(Icons.TOOLBAR_TOPOLOGY_POLYLINE));
panel
.addTool(
new TopologyTool<>(
"tool.crosstopology.instructions",
"tool.crosstopology.tooltip",
false,
new CrossStrategy(),
topologyModeSelectionPanel))
new CrossStrategy()))
.setIcon(RessourceManager.getBigIcon(Icons.TOOLBAR_TOPOLOGY_CROSS));
panel
.addTool(
new TopologyTool<>(
"tool.isorectangletopology.instructions",
"tool.isorectangletopology.tooltip",
true,
new IsoRectangleStrategy(),
topologyModeSelectionPanel))
new IsoRectangleStrategy()))
.setIcon(RessourceManager.getBigIcon(Icons.TOOLBAR_TOPOLOGY_DIAMOND));
panel
.addTool(
new TopologyTool<>(
"tool.isorectangletopology.instructions",
"tool.isorectangletopologyhollow.tooltip",
false,
new IsoRectangleStrategy(),
topologyModeSelectionPanel))
new IsoRectangleStrategy()))
.setIcon(RessourceManager.getBigIcon(Icons.TOOLBAR_TOPOLOGY_DIAMOND_HOLLOW));

// Add with separator to separate mode button group from shape button group.
addSeparator(panel, 11);

final var topologyModeSelectionPanel = new TopologyModeSelectionPanel();
panel.add(topologyModeSelectionPanel);

return panel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;
import net.rptools.maptool.client.AppStatePersisted;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.macro.MacroContext;
import net.rptools.maptool.client.swing.TopologyModeSelectionPanel;
import net.rptools.maptool.client.swing.colorpicker.ColorPicker;
import net.rptools.maptool.client.ui.AssetPaint;
import net.rptools.maptool.client.ui.zone.renderer.ZoneRenderer;
Expand Down Expand Up @@ -591,8 +591,7 @@ private void VblTool(Drawable drawable, boolean pathOnly, boolean isEraser) {
}

MapTool.serverCommand()
.updateTopology(
renderer.getZone(), area, isEraser, TopologyModeSelectionPanel.getInstance().getMode());
.updateTopology(renderer.getZone(), area, isEraser, AppStatePersisted.getTopologyTypes());
}

private Path2D getPath(Drawable drawable) {
Expand Down

0 comments on commit 9a4f5e7

Please sign in to comment.