Skip to content

Commit

Permalink
Apply ToolBox.updateTools() to all tools, not just class-based tools
Browse files Browse the repository at this point in the history
  • Loading branch information
kwvanderlinde committed Nov 10, 2024
1 parent dc948f9 commit 8cc976a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/net/rptools/maptool/client/tool/Toolbox.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import java.awt.EventQueue;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.ButtonGroup;
import net.rptools.maptool.client.MapTool;
Expand All @@ -28,13 +30,21 @@
/** */
public class Toolbox {
private ZoneRenderer currentRenderer;

/** The selected tool, if any. Will be one of {@link #tools} or {@code null}. */
private Tool currentTool;

/** Contains all tools in the toolbox regardless of how they were registered. */
private final List<Tool> tools = new ArrayList<>();

/** Remembers which tool was registered for which class. Values are members of {@link #tools}. */
private final Map<Class<? extends Tool>, Tool> toolMap =
new HashMap<Class<? extends Tool>, Tool>();

private final ButtonGroup buttonGroup = new ButtonGroup();

public void updateTools() {
for (Tool tool : toolMap.values()) {
for (Tool tool : tools) {
tool.setEnabled(tool.isAvailable());
tool.updateButtonState();
}
Expand Down Expand Up @@ -82,6 +92,7 @@ public <T extends Tool> T createTool(Class<T> toolClass) {
* @param tool The tool to add.
*/
public void addTool(Tool tool) {
tools.add(tool);
if (tool.hasGroup()) {
buttonGroup.add(tool);
}
Expand Down

0 comments on commit 8cc976a

Please sign in to comment.