Add ColorPickerManager

This commit is contained in:
Ron Young
2019-02-23 16:48:44 -06:00
committed by Tomas Slusny
parent dc1e409f09
commit b6dada85c7
6 changed files with 103 additions and 13 deletions

View File

@@ -35,8 +35,6 @@ import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Collections;
@@ -88,6 +86,7 @@ import net.runelite.client.ui.PluginPanel;
import net.runelite.client.ui.components.ComboBoxListRenderer;
import net.runelite.client.ui.components.IconButton;
import net.runelite.client.ui.components.IconTextField;
import net.runelite.client.ui.components.colorpicker.ColorPickerManager;
import net.runelite.client.ui.components.colorpicker.RuneliteColorPicker;
import net.runelite.client.util.ColorUtil;
import net.runelite.client.util.ImageUtil;
@@ -112,6 +111,7 @@ public class ConfigPanel extends PluginPanel
private final ScheduledExecutorService executorService;
private final RuneLiteConfig runeLiteConfig;
private final ChatColorConfig chatColorConfig;
private final ColorPickerManager colorPickerManager;
private final List<PluginListItem> pluginList = new ArrayList<>();
private final IconTextField searchBar = new IconTextField();
@@ -130,7 +130,7 @@ public class ConfigPanel extends PluginPanel
}
ConfigPanel(PluginManager pluginManager, ConfigManager configManager, ScheduledExecutorService executorService,
RuneLiteConfig runeLiteConfig, ChatColorConfig chatColorConfig)
RuneLiteConfig runeLiteConfig, ChatColorConfig chatColorConfig, ColorPickerManager colorPickerManager)
{
super(false);
this.pluginManager = pluginManager;
@@ -138,6 +138,7 @@ public class ConfigPanel extends PluginPanel
this.executorService = executorService;
this.runeLiteConfig = runeLiteConfig;
this.chatColorConfig = chatColorConfig;
this.colorPickerManager = colorPickerManager;
searchBar.setIcon(IconTextField.Icon.SEARCH);
searchBar.setPreferredSize(new Dimension(PluginPanel.PANEL_WIDTH - 20, 30));
@@ -421,8 +422,11 @@ public class ConfigPanel extends PluginPanel
@Override
public void mouseClicked(MouseEvent e)
{
RuneliteColorPicker colorPicker = new RuneliteColorPicker(SwingUtilities.windowForComponent(ConfigPanel.this),
colorPickerBtn.getBackground(), cid.getItem().name(), cid.getAlpha() == null);
RuneliteColorPicker colorPicker = colorPickerManager.create(
SwingUtilities.windowForComponent(ConfigPanel.this),
colorPickerBtn.getBackground(),
cid.getItem().name(),
cid.getAlpha() == null);
colorPicker.setLocation(getLocationOnScreen());
colorPicker.setOnColorChange(c ->
{

View File

@@ -41,6 +41,7 @@ import net.runelite.client.plugins.PluginManager;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.ClientUI;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.components.colorpicker.ColorPickerManager;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayMenuEntry;
import net.runelite.client.util.ImageUtil;
@@ -73,13 +74,16 @@ public class ConfigPlugin extends Plugin
@Inject
private ChatColorConfig chatColorConfig;
@Inject
private ColorPickerManager colorPickerManager;
private ConfigPanel configPanel;
private NavigationButton navButton;
@Override
protected void startUp() throws Exception
{
configPanel = new ConfigPanel(pluginManager, configManager, executorService, runeLiteConfig, chatColorConfig);
configPanel = new ConfigPanel(pluginManager, configManager, executorService, runeLiteConfig, chatColorConfig, colorPickerManager);
final BufferedImage icon = ImageUtil.getResourceStreamFromClass(getClass(), "config_icon.png");

View File

@@ -50,6 +50,7 @@ import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.screenmarkers.ui.ScreenMarkerPluginPanel;
import net.runelite.client.ui.ClientToolbar;
import net.runelite.client.ui.NavigationButton;
import net.runelite.client.ui.components.colorpicker.ColorPickerManager;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.ImageUtil;
@@ -85,6 +86,10 @@ public class ScreenMarkerPlugin extends Plugin
@Inject
private ScreenMarkerCreationOverlay overlay;
@Getter
@Inject
private ColorPickerManager colorPickerManager;
private ScreenMarkerMouseListener mouseListener;
private ScreenMarkerPluginPanel pluginPanel;
private NavigationButton navigationButton;

View File

@@ -33,8 +33,6 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
@@ -545,8 +543,11 @@ class ScreenMarkerPanel extends JPanel
private void openFillColorPicker()
{
RuneliteColorPicker colorPicker = new RuneliteColorPicker(SwingUtilities.windowForComponent(this),
marker.getMarker().getFill(), marker.getMarker().getName() + " Fill", false);
RuneliteColorPicker colorPicker = plugin.getColorPickerManager().create(
SwingUtilities.windowForComponent(this),
marker.getMarker().getFill(),
marker.getMarker().getName() + " Fill",
false);
colorPicker.setLocation(getLocationOnScreen());
colorPicker.setOnColorChange(c ->
{
@@ -559,8 +560,11 @@ class ScreenMarkerPanel extends JPanel
private void openBorderColorPicker()
{
RuneliteColorPicker colorPicker = new RuneliteColorPicker(SwingUtilities.windowForComponent(this),
marker.getMarker().getColor(), marker.getMarker().getName() + " Border", false);
RuneliteColorPicker colorPicker = plugin.getColorPickerManager().create(
SwingUtilities.windowForComponent(this),
marker.getMarker().getColor(),
marker.getMarker().getName() + " Border",
false);
colorPicker.setLocation(getLocationOnScreen());
colorPicker.setOnColorChange(c ->
{

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2019, Ron Young <https://github.com/raiyni>
* 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.ui.components.colorpicker;
import java.awt.Color;
import java.awt.Window;
import java.awt.event.WindowEvent;
import javax.inject.Inject;
import javax.inject.Singleton;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import net.runelite.client.config.ConfigManager;
@Singleton
public class ColorPickerManager
{
private final ConfigManager configManager;
@Setter(AccessLevel.PACKAGE)
@Getter(AccessLevel.PACKAGE)
private RuneliteColorPicker currentPicker;
@Inject
private ColorPickerManager(final ConfigManager configManager)
{
this.configManager = configManager;
}
public RuneliteColorPicker create(Window owner, Color previousColor, String title, boolean alphaHidden)
{
if (currentPicker != null)
{
currentPicker.dispatchEvent(new WindowEvent(currentPicker, WindowEvent.WINDOW_CLOSING));
}
currentPicker = new RuneliteColorPicker(owner, previousColor, title, alphaHidden, configManager, this);
return currentPicker;
}
}

View File

@@ -41,6 +41,7 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Objects;
import java.util.function.Consumer;
import javax.swing.JDialog;
import javax.swing.JFrame;
@@ -55,6 +56,7 @@ import javax.swing.text.Document;
import javax.swing.text.DocumentFilter;
import lombok.Getter;
import lombok.Setter;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.ui.ColorScheme;
import net.runelite.client.util.ColorUtil;
import org.pushingpixels.substance.internal.SubstanceSynapse;
@@ -89,7 +91,8 @@ public class RuneliteColorPicker extends JDialog
@Setter
private Consumer<Color> onClose;
public RuneliteColorPicker(Window parent, Color previousColor, String title, boolean alphaHidden)
RuneliteColorPicker(Window parent, Color previousColor, String title, boolean alphaHidden,
final ConfigManager configManager, final ColorPickerManager colorPickerManager)
{
super(parent, "RuneLite Color Picker - " + title, ModalityType.MODELESS);
@@ -99,6 +102,7 @@ public class RuneliteColorPicker extends JDialog
setResizable(false);
setSize(FRAME_WIDTH, FRAME_HEIGHT);
setBackground(ColorScheme.PROGRESS_COMPLETE_COLOR);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
JPanel content = new JPanel(new BorderLayout());
content.putClientProperty(SubstanceSynapse.COLORIZATION_FACTOR, 1.0);
@@ -280,6 +284,12 @@ public class RuneliteColorPicker extends JDialog
{
onClose.accept(selectedColor);
}
RuneliteColorPicker cp = colorPickerManager.getCurrentPicker();
if (Objects.equals(cp, RuneliteColorPicker.this))
{
colorPickerManager.setCurrentPicker(null);
}
}
});
}