Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply ToolBox.updateTools() to all tools, not just class-based tools #5040

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading