devtools: factor frame handling out
This commit is contained in:
@@ -28,7 +28,7 @@ import java.awt.Color;
|
||||
import javax.swing.JButton;
|
||||
import lombok.Getter;
|
||||
|
||||
class DevToolsButton extends JButton
|
||||
public class DevToolsButton extends JButton
|
||||
{
|
||||
@Getter
|
||||
private boolean active;
|
||||
@@ -53,4 +53,20 @@ class DevToolsButton extends JButton
|
||||
setBackground(null);
|
||||
}
|
||||
}
|
||||
|
||||
void addFrame(DevToolsFrame frame)
|
||||
{
|
||||
frame.setDevToolsButton(this);
|
||||
addActionListener(ev ->
|
||||
{
|
||||
if (isActive())
|
||||
{
|
||||
frame.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
frame.open();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Abex
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.client.plugins.devtools;
|
||||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import javax.swing.JFrame;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Setter;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
|
||||
public class DevToolsFrame extends JFrame
|
||||
{
|
||||
@Setter(AccessLevel.PACKAGE)
|
||||
protected DevToolsButton devToolsButton;
|
||||
|
||||
public DevToolsFrame()
|
||||
{
|
||||
setIconImage(ClientUI.ICON);
|
||||
|
||||
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter()
|
||||
{
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e)
|
||||
{
|
||||
close();
|
||||
devToolsButton.setActive(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void open()
|
||||
{
|
||||
setVisible(true);
|
||||
toFront();
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void close()
|
||||
{
|
||||
setVisible(false);
|
||||
}
|
||||
}
|
||||
@@ -129,30 +129,10 @@ class DevToolsPanel extends PluginPanel
|
||||
});
|
||||
|
||||
container.add(plugin.getWidgetInspector());
|
||||
plugin.getWidgetInspector().addActionListener((ev) ->
|
||||
{
|
||||
if (plugin.getWidgetInspector().isActive())
|
||||
{
|
||||
widgetInspector.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
widgetInspector.open();
|
||||
}
|
||||
});
|
||||
plugin.getWidgetInspector().addFrame(widgetInspector);
|
||||
|
||||
container.add(plugin.getVarInspector());
|
||||
plugin.getVarInspector().addActionListener((ev) ->
|
||||
{
|
||||
if (plugin.getVarInspector().isActive())
|
||||
{
|
||||
varInspector.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
varInspector.open();
|
||||
}
|
||||
});
|
||||
plugin.getVarInspector().addFrame(varInspector);
|
||||
|
||||
container.add(plugin.getSoundEffects());
|
||||
|
||||
@@ -164,17 +144,7 @@ class DevToolsPanel extends PluginPanel
|
||||
container.add(notificationBtn);
|
||||
|
||||
container.add(plugin.getScriptInspector());
|
||||
plugin.getScriptInspector().addActionListener((ev) ->
|
||||
{
|
||||
if (plugin.getScriptInspector().isActive())
|
||||
{
|
||||
scriptInspector.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
scriptInspector.open();
|
||||
}
|
||||
});
|
||||
plugin.getScriptInspector().addFrame(scriptInspector);
|
||||
|
||||
final JButton newInfoboxBtn = new JButton("Infobox");
|
||||
newInfoboxBtn.addActionListener(e ->
|
||||
@@ -198,17 +168,7 @@ class DevToolsPanel extends PluginPanel
|
||||
container.add(clearInfoboxBtn);
|
||||
|
||||
container.add(plugin.getInventoryInspector());
|
||||
plugin.getInventoryInspector().addActionListener((ev) ->
|
||||
{
|
||||
if (plugin.getInventoryInspector().isActive())
|
||||
{
|
||||
inventoryInspector.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
inventoryInspector.open();
|
||||
}
|
||||
});
|
||||
plugin.getInventoryInspector().addFrame(inventoryInspector);
|
||||
|
||||
final JButton disconnectBtn = new JButton("Disconnect");
|
||||
disconnectBtn.addActionListener(e -> clientThread.invoke(() -> client.setGameState(GameState.CONNECTION_LOST)));
|
||||
|
||||
@@ -28,8 +28,6 @@ import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.AdjustmentEvent;
|
||||
import java.awt.event.AdjustmentListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -39,7 +37,6 @@ import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollBar;
|
||||
import javax.swing.JScrollPane;
|
||||
@@ -65,7 +62,7 @@ import net.runelite.client.ui.ColorScheme;
|
||||
|
||||
@Slf4j
|
||||
@Singleton
|
||||
class InventoryInspector extends JFrame
|
||||
class InventoryInspector extends DevToolsFrame
|
||||
{
|
||||
private static final int MAX_LOG_ENTRIES = 25;
|
||||
|
||||
@@ -80,7 +77,7 @@ class InventoryInspector extends JFrame
|
||||
private final InventoryDeltaPanel deltaPanel;
|
||||
|
||||
@Inject
|
||||
InventoryInspector(Client client, EventBus eventBus, DevToolsPlugin plugin, ItemManager itemManager, ClientThread clientThread)
|
||||
InventoryInspector(Client client, EventBus eventBus, ItemManager itemManager, ClientThread clientThread)
|
||||
{
|
||||
this.client = client;
|
||||
this.eventBus = eventBus;
|
||||
@@ -92,18 +89,6 @@ class InventoryInspector extends JFrame
|
||||
setTitle("RuneLite Inventory Inspector");
|
||||
setIconImage(ClientUI.ICON);
|
||||
|
||||
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
// Reset highlight on close
|
||||
addWindowListener(new WindowAdapter()
|
||||
{
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e)
|
||||
{
|
||||
close();
|
||||
plugin.getInventoryInspector().setActive(false);
|
||||
}
|
||||
});
|
||||
|
||||
tree.setBorder(new EmptyBorder(2, 2, 2, 2));
|
||||
tree.setRootVisible(false);
|
||||
tree.setShowsRootHandles(true);
|
||||
@@ -175,19 +160,19 @@ class InventoryInspector extends JFrame
|
||||
pack();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open()
|
||||
{
|
||||
eventBus.register(this);
|
||||
setVisible(true);
|
||||
toFront();
|
||||
repaint();
|
||||
super.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
eventBus.unregister(this);
|
||||
clearTracker();
|
||||
setVisible(false);
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -31,8 +31,6 @@ import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.AdjustmentEvent;
|
||||
import java.awt.event.AdjustmentListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashSet;
|
||||
@@ -42,7 +40,6 @@ import javax.swing.BorderFactory;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFormattedTextField;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
@@ -68,14 +65,13 @@ import static net.runelite.api.widgets.WidgetInfo.TO_GROUP;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.DynamicGridLayout;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
import net.runelite.client.util.Text;
|
||||
|
||||
@Slf4j
|
||||
public class ScriptInspector extends JFrame
|
||||
public class ScriptInspector extends DevToolsFrame
|
||||
{
|
||||
// These scripts are the only ones that fire every client tick regardless of location.
|
||||
private final static String DEFAULT_BLACKLIST = "3174,1004";
|
||||
@@ -139,28 +135,16 @@ public class ScriptInspector extends JFrame
|
||||
}
|
||||
|
||||
@Inject
|
||||
ScriptInspector(Client client, EventBus eventBus, DevToolsPlugin plugin, ConfigManager configManager)
|
||||
ScriptInspector(Client client, EventBus eventBus, ConfigManager configManager)
|
||||
{
|
||||
this.eventBus = eventBus;
|
||||
this.client = client;
|
||||
this.configManager = configManager;
|
||||
|
||||
setTitle("RuneLite Script Inspector");
|
||||
setIconImage(ClientUI.ICON);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter()
|
||||
{
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e)
|
||||
{
|
||||
close();
|
||||
plugin.getScriptInspector().setActive(false);
|
||||
}
|
||||
});
|
||||
|
||||
tracker.setLayout(new DynamicGridLayout(0, 1, 0, 3));
|
||||
|
||||
final JPanel leftSide = new JPanel();
|
||||
@@ -344,14 +328,14 @@ public class ScriptInspector extends JFrame
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open()
|
||||
{
|
||||
eventBus.register(this);
|
||||
setVisible(true);
|
||||
toFront();
|
||||
repaint();
|
||||
super.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
configManager.setConfiguration("devtools", "highlights",
|
||||
@@ -360,7 +344,7 @@ public class ScriptInspector extends JFrame
|
||||
Text.toCSV(Lists.transform(new ArrayList<>(blacklist), String::valueOf)));
|
||||
currentNode = null;
|
||||
eventBus.unregister(this);
|
||||
setVisible(false);
|
||||
super.close();
|
||||
}
|
||||
|
||||
private void addScriptLog(ScriptTreeNode treeNode)
|
||||
|
||||
@@ -32,15 +32,12 @@ import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.AdjustmentEvent;
|
||||
import java.awt.event.AdjustmentListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollBar;
|
||||
@@ -62,13 +59,12 @@ import net.runelite.api.events.VarbitChanged;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.DynamicGridLayout;
|
||||
import net.runelite.client.ui.FontManager;
|
||||
|
||||
@Slf4j
|
||||
class VarInspector extends JFrame
|
||||
class VarInspector extends DevToolsFrame
|
||||
{
|
||||
@Getter
|
||||
private enum VarType
|
||||
@@ -106,28 +102,16 @@ class VarInspector extends JFrame
|
||||
private Map<Integer, Object> varcs = null;
|
||||
|
||||
@Inject
|
||||
VarInspector(Client client, ClientThread clientThread, EventBus eventBus, DevToolsPlugin plugin)
|
||||
VarInspector(Client client, ClientThread clientThread, EventBus eventBus)
|
||||
{
|
||||
this.client = client;
|
||||
this.clientThread = clientThread;
|
||||
this.eventBus = eventBus;
|
||||
|
||||
setTitle("RuneLite Var Inspector");
|
||||
setIconImage(ClientUI.ICON);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
||||
addWindowListener(new WindowAdapter()
|
||||
{
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e)
|
||||
{
|
||||
close();
|
||||
plugin.getVarInspector().setActive(false);
|
||||
}
|
||||
});
|
||||
|
||||
tracker.setLayout(new DynamicGridLayout(0, 1, 0, 3));
|
||||
|
||||
final JPanel trackerWrapper = new JPanel();
|
||||
@@ -332,6 +316,7 @@ class VarInspector extends JFrame
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open()
|
||||
{
|
||||
if (oldVarps == null)
|
||||
@@ -361,16 +346,15 @@ class VarInspector extends JFrame
|
||||
});
|
||||
|
||||
eventBus.register(this);
|
||||
setVisible(true);
|
||||
toFront();
|
||||
repaint();
|
||||
super.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
super.close();
|
||||
tracker.removeAll();
|
||||
eventBus.unregister(this);
|
||||
setVisible(false);
|
||||
varcs = null;
|
||||
varbits = null;
|
||||
}
|
||||
|
||||
@@ -32,8 +32,6 @@ import com.google.inject.Singleton;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.Enumeration;
|
||||
@@ -43,7 +41,6 @@ import java.util.Stack;
|
||||
import java.util.stream.Stream;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JSplitPane;
|
||||
@@ -73,13 +70,12 @@ import net.runelite.api.widgets.WidgetType;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import net.runelite.client.util.ColorUtil;
|
||||
|
||||
@Slf4j
|
||||
@Singleton
|
||||
class WidgetInspector extends JFrame
|
||||
class WidgetInspector extends DevToolsFrame
|
||||
{
|
||||
private static final Map<Integer, WidgetInfo> widgetIdMap = new HashMap<>();
|
||||
|
||||
@@ -123,7 +119,6 @@ class WidgetInspector extends JFrame
|
||||
ClientThread clientThread,
|
||||
WidgetInfoTableModel infoTableModel,
|
||||
DevToolsConfig config,
|
||||
DevToolsPlugin plugin,
|
||||
EventBus eventBus,
|
||||
Provider<WidgetInspectorOverlay> overlay,
|
||||
OverlayManager overlayManager)
|
||||
@@ -138,18 +133,6 @@ class WidgetInspector extends JFrame
|
||||
eventBus.register(this);
|
||||
|
||||
setTitle("RuneLite Widget Inspector");
|
||||
setIconImage(ClientUI.ICON);
|
||||
|
||||
// Reset highlight on close
|
||||
addWindowListener(new WindowAdapter()
|
||||
{
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e)
|
||||
{
|
||||
close();
|
||||
plugin.getWidgetInspector().setActive(false);
|
||||
}
|
||||
});
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
@@ -402,21 +385,21 @@ class WidgetInspector extends JFrame
|
||||
return widgetIdMap.get(packedId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open()
|
||||
{
|
||||
setVisible(true);
|
||||
toFront();
|
||||
repaint();
|
||||
super.open();
|
||||
overlayManager.add(this.overlay.get());
|
||||
clientThread.invokeLater(this::addPickerWidget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
overlayManager.remove(this.overlay.get());
|
||||
clientThread.invokeLater(this::removePickerWidget);
|
||||
setSelectedWidget(null, -1, false);
|
||||
setVisible(false);
|
||||
super.close();
|
||||
}
|
||||
|
||||
private void removePickerWidget()
|
||||
|
||||
Reference in New Issue
Block a user