upstream: merge
upstream: merge
This commit is contained in:
@@ -41,7 +41,6 @@ import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
@@ -672,11 +671,7 @@ class ConfigPanel extends PluginPanel
|
||||
|
||||
if (units != null)
|
||||
{
|
||||
DecimalFormat df = ((JSpinner.NumberEditor) spinner.getEditor()).getFormat();
|
||||
df.setPositiveSuffix(units.value());
|
||||
df.setNegativeSuffix(units.value());
|
||||
// Force update the spinner to have it add the units initially
|
||||
spinnerTextField.setValue(value);
|
||||
spinnerTextField.setFormatterFactory(new UnitFormatterFactory(units));
|
||||
}
|
||||
|
||||
item.add(spinner, BorderLayout.EAST);
|
||||
@@ -812,11 +807,7 @@ class ConfigPanel extends PluginPanel
|
||||
|
||||
if (units != null)
|
||||
{
|
||||
DecimalFormat df = ((JSpinner.NumberEditor) widthSpinner.getEditor()).getFormat();
|
||||
df.setPositiveSuffix(units.value());
|
||||
df.setNegativeSuffix(units.value());
|
||||
// Force update the spinner to have it add the units initially
|
||||
widthSpinnerTextField.setValue(width);
|
||||
widthSpinnerTextField.setFormatterFactory(new UnitFormatterFactory(units));
|
||||
}
|
||||
|
||||
SpinnerModel heightModel = new SpinnerNumberModel(height, 0, Integer.MAX_VALUE, 1);
|
||||
@@ -827,11 +818,7 @@ class ConfigPanel extends PluginPanel
|
||||
|
||||
if (units != null)
|
||||
{
|
||||
DecimalFormat df = ((JSpinner.NumberEditor) heightSpinner.getEditor()).getFormat();
|
||||
df.setPositiveSuffix(units.value());
|
||||
df.setNegativeSuffix(units.value());
|
||||
// Force update the spinner to have it add the units initially
|
||||
heightSpinnerTextField.setValue(height);
|
||||
heightSpinnerTextField.setFormatterFactory(new UnitFormatterFactory(units));
|
||||
}
|
||||
|
||||
ChangeListener listener = e ->
|
||||
|
||||
@@ -45,12 +45,9 @@ import net.runelite.client.ui.ColorScheme;
|
||||
import net.runelite.client.ui.PluginPanel;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
import net.runelite.client.util.SwingUtil;
|
||||
import org.apache.commons.text.similarity.JaroWinklerDistance;
|
||||
|
||||
public class PluginListItem extends JPanel
|
||||
{
|
||||
private static final JaroWinklerDistance DISTANCE = new JaroWinklerDistance();
|
||||
|
||||
private static final ImageIcon CONFIG_ICON;
|
||||
private static final ImageIcon CONFIG_ICON_HOVER;
|
||||
private static final ImageIcon ON_STAR;
|
||||
@@ -61,6 +58,7 @@ public class PluginListItem extends JPanel
|
||||
@Getter
|
||||
private final PluginConfigurationDescriptor pluginConfig;
|
||||
|
||||
@Getter
|
||||
private final List<String> keywords = new ArrayList<>();
|
||||
|
||||
public JLabel nameLabel;
|
||||
@@ -201,24 +199,6 @@ public class PluginListItem extends JPanel
|
||||
onOffToggle.setSelected(enabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if all the search terms in the given list matches at least one keyword.
|
||||
*
|
||||
* @return true if all search terms matches at least one keyword, or false if otherwise.
|
||||
*/
|
||||
boolean matchesSearchTerms(String[] searchTerms)
|
||||
{
|
||||
for (String term : searchTerms)
|
||||
{
|
||||
if (keywords.stream().noneMatch((t) -> t.contains(term) ||
|
||||
DISTANCE.apply(t, term) > 0.9))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void openGroupConfigPanel()
|
||||
{
|
||||
pluginListPanel.openConfigurationPanel(pluginConfig);
|
||||
|
||||
@@ -381,7 +381,7 @@ public class PluginListPanel extends PluginPanel
|
||||
final String[] searchTerms = text.toLowerCase().split(" ");
|
||||
pluginList.forEach(listItem ->
|
||||
{
|
||||
if (pinned == listItem.isPinned() && listItem.matchesSearchTerms(searchTerms))
|
||||
if (pinned == listItem.isPinned() && Text.matchesSearchTerms(searchTerms, listItem.getKeywords()))
|
||||
{
|
||||
if (openOSRSConfig.pluginSortMode() == OpenOSRSConfig.SortStyle.ALPHABETICALLY || !openOSRSConfig.enableCategories())
|
||||
{
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Hydrox6 <ikada@protonmail.ch>
|
||||
* 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.config;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.swing.JFormattedTextField;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.runelite.client.config.Units;
|
||||
|
||||
final class UnitFormatter extends JFormattedTextField.AbstractFormatter
|
||||
{
|
||||
private final String units;
|
||||
|
||||
UnitFormatter(Units units)
|
||||
{
|
||||
this.units = units.value();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object stringToValue(final String text) throws ParseException
|
||||
{
|
||||
final String trimmedText;
|
||||
|
||||
// Using the spinner controls causes the value to have the unit on the end, so remove it
|
||||
if (text.endsWith(units))
|
||||
{
|
||||
trimmedText = text.substring(0, text.length() - units.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
trimmedText = text;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return Integer.valueOf(trimmedText);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new ParseException(trimmedText + " is not an integer.", 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valueToString(final Object value)
|
||||
{
|
||||
return value + units;
|
||||
}
|
||||
}
|
||||
|
||||
@RequiredArgsConstructor
|
||||
final class UnitFormatterFactory extends JFormattedTextField.AbstractFormatterFactory
|
||||
{
|
||||
private final Units units;
|
||||
private final Map<JFormattedTextField, JFormattedTextField.AbstractFormatter> formatters = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public JFormattedTextField.AbstractFormatter getFormatter(final JFormattedTextField tf)
|
||||
{
|
||||
return formatters.computeIfAbsent(tf, (key) -> new UnitFormatter(units));
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
*/
|
||||
package net.runelite.client.util;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.TrayIcon;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
@@ -40,6 +41,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@@ -80,10 +82,11 @@ public class ImageCapture
|
||||
*
|
||||
* @param screenshot BufferedImage to capture.
|
||||
* @param fileName Filename to use, without file extension.
|
||||
* @param subDir Directory within the player screenshots dir to store the captured screenshot to.
|
||||
* @param notify Send a notification to the system tray when the image is captured.
|
||||
* @param imageUploadStyle which method to use to upload the screenshot (Imgur or directly to clipboard).
|
||||
*/
|
||||
public void takeScreenshot(BufferedImage screenshot, String fileName, boolean notify, ImageUploadStyle imageUploadStyle)
|
||||
public void takeScreenshot(BufferedImage screenshot, String fileName, @Nullable String subDir, boolean notify, ImageUploadStyle imageUploadStyle)
|
||||
{
|
||||
if (client.getGameState() == GameState.LOGIN_SCREEN)
|
||||
{
|
||||
@@ -106,6 +109,12 @@ public class ImageCapture
|
||||
{
|
||||
playerDir += "-League";
|
||||
}
|
||||
|
||||
if (!Strings.isNullOrEmpty(subDir))
|
||||
{
|
||||
playerDir += File.separator + subDir;
|
||||
}
|
||||
|
||||
playerFolder = new File(SCREENSHOT_DIR, playerDir);
|
||||
}
|
||||
else
|
||||
@@ -157,6 +166,20 @@ public class ImageCapture
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a screenshot of the client window to the screenshot folder as a PNG,
|
||||
* and optionally uploads it to an image-hosting service.
|
||||
*
|
||||
* @param screenshot BufferedImage to capture.
|
||||
* @param fileName Filename to use, without file extension.
|
||||
* @param notify Send a notification to the system tray when the image is captured.
|
||||
* @param imageUploadStyle which method to use to upload the screenshot (Imgur or directly to clipboard).
|
||||
*/
|
||||
public void takeScreenshot(BufferedImage screenshot, String fileName, boolean notify, ImageUploadStyle imageUploadStyle)
|
||||
{
|
||||
takeScreenshot(screenshot, fileName, null, notify, imageUploadStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads a screenshot to the Imgur image-hosting service,
|
||||
* and copies the image link to the clipboard.
|
||||
|
||||
Reference in New Issue
Block a user