Merge pull request #431 from se7enAte9/master
Fix config flicker cause by multiline textboxes
This commit is contained in:
@@ -31,6 +31,7 @@ import java.awt.BorderLayout;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.FocusAdapter;
|
import java.awt.event.FocusAdapter;
|
||||||
@@ -108,6 +109,7 @@ import net.runelite.client.ui.components.colorpicker.RuneliteColorPicker;
|
|||||||
import net.runelite.client.util.ColorUtil;
|
import net.runelite.client.util.ColorUtil;
|
||||||
import net.runelite.client.util.ImageUtil;
|
import net.runelite.client.util.ImageUtil;
|
||||||
import net.runelite.client.util.Text;
|
import net.runelite.client.util.Text;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ConfigPanel extends PluginPanel
|
public class ConfigPanel extends PluginPanel
|
||||||
@@ -207,10 +209,40 @@ public class ConfigPanel extends PluginPanel
|
|||||||
|
|
||||||
static class configTextArea extends JTextArea
|
static class configTextArea extends JTextArea
|
||||||
{
|
{
|
||||||
|
private static final int WIDTH = 212;
|
||||||
|
private static final int HEIGHT_PADDING = 13;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void scrollRectToVisible(final Rectangle aRect)
|
public void scrollRectToVisible(final Rectangle aRect)
|
||||||
{
|
{
|
||||||
// supress scrollToRect in textarea
|
// suppress scrollToRect in textarea
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getSize()
|
||||||
|
{
|
||||||
|
if (StringUtils.isAllEmpty(getText()))
|
||||||
|
{
|
||||||
|
return super.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
final ArrayList<String> lines = new ArrayList<>();
|
||||||
|
final FontMetrics fontMetrics = getFontMetrics(getFont());
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (final Character c : getText().toCharArray())
|
||||||
|
{
|
||||||
|
sb.append(c);
|
||||||
|
if (fontMetrics.stringWidth(sb.toString()) > WIDTH || c == '\n')
|
||||||
|
{
|
||||||
|
sb.setLength(sb.length() - 1);
|
||||||
|
lines.add(sb.toString());
|
||||||
|
sb = new StringBuilder(c.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lines.add(sb.toString());
|
||||||
|
|
||||||
|
return new Dimension(WIDTH, (lines.size() * fontMetrics.getHeight()) + HEIGHT_PADDING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,6 +502,11 @@ public class ConfigPanel extends PluginPanel
|
|||||||
}
|
}
|
||||||
|
|
||||||
void openGroupConfigPanel(PluginListItem listItem, Config config, ConfigDescriptor cd)
|
void openGroupConfigPanel(PluginListItem listItem, Config config, ConfigDescriptor cd)
|
||||||
|
{
|
||||||
|
openGroupConfigPanel(listItem, config, cd, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void openGroupConfigPanel(PluginListItem listItem, Config config, ConfigDescriptor cd, boolean refresh)
|
||||||
{
|
{
|
||||||
showingPluginList = false;
|
showingPluginList = false;
|
||||||
|
|
||||||
@@ -641,7 +678,7 @@ public class ConfigPanel extends PluginPanel
|
|||||||
configEntryName.setToolTipText(null);
|
configEntryName.setToolTipText(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cid.getType() == boolean.class)
|
else if (cid.getType() == boolean.class)
|
||||||
{
|
{
|
||||||
JCheckBox checkbox = new JCheckBox();
|
JCheckBox checkbox = new JCheckBox();
|
||||||
checkbox.setBackground(ColorScheme.LIGHT_GRAY_COLOR);
|
checkbox.setBackground(ColorScheme.LIGHT_GRAY_COLOR);
|
||||||
@@ -651,7 +688,7 @@ public class ConfigPanel extends PluginPanel
|
|||||||
item.add(checkbox, BorderLayout.EAST);
|
item.add(checkbox, BorderLayout.EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cid.getType() == int.class)
|
else if (cid.getType() == int.class)
|
||||||
{
|
{
|
||||||
int value = Integer.parseInt(configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName()));
|
int value = Integer.parseInt(configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName()));
|
||||||
|
|
||||||
@@ -696,7 +733,7 @@ public class ConfigPanel extends PluginPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cid.getType() == String.class)
|
else if (cid.getType() == String.class)
|
||||||
{
|
{
|
||||||
JTextComponent textField;
|
JTextComponent textField;
|
||||||
|
|
||||||
@@ -767,7 +804,7 @@ public class ConfigPanel extends PluginPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cid.getType() == Color.class)
|
else if (cid.getType() == Color.class)
|
||||||
{
|
{
|
||||||
String existing = configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName());
|
String existing = configManager.getConfiguration(cd.getGroup().value(), cid.getItem().keyName());
|
||||||
|
|
||||||
@@ -816,7 +853,7 @@ public class ConfigPanel extends PluginPanel
|
|||||||
item.add(colorPickerBtn, BorderLayout.EAST);
|
item.add(colorPickerBtn, BorderLayout.EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cid.getType() == Dimension.class)
|
else if (cid.getType() == Dimension.class)
|
||||||
{
|
{
|
||||||
JPanel dimensionPanel = new JPanel();
|
JPanel dimensionPanel = new JPanel();
|
||||||
dimensionPanel.setLayout(new BorderLayout());
|
dimensionPanel.setLayout(new BorderLayout());
|
||||||
@@ -851,7 +888,7 @@ public class ConfigPanel extends PluginPanel
|
|||||||
item.add(dimensionPanel, BorderLayout.EAST);
|
item.add(dimensionPanel, BorderLayout.EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cid.getType().isEnum())
|
else if (cid.getType().isEnum())
|
||||||
{
|
{
|
||||||
Class<? extends Enum> type = (Class<? extends Enum>) cid.getType();
|
Class<? extends Enum> type = (Class<? extends Enum>) cid.getType();
|
||||||
JComboBox box = new JComboBox(type.getEnumConstants());
|
JComboBox box = new JComboBox(type.getEnumConstants());
|
||||||
@@ -881,7 +918,7 @@ public class ConfigPanel extends PluginPanel
|
|||||||
item.add(box, BorderLayout.EAST);
|
item.add(box, BorderLayout.EAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cid.getType() == Keybind.class || cid.getType() == ModifierlessKeybind.class)
|
else if (cid.getType() == Keybind.class || cid.getType() == ModifierlessKeybind.class)
|
||||||
{
|
{
|
||||||
Keybind startingValue = configManager.getConfiguration(cd.getGroup().value(),
|
Keybind startingValue = configManager.getConfiguration(cd.getGroup().value(),
|
||||||
cid.getItem().keyName(),
|
cid.getItem().keyName(),
|
||||||
@@ -926,8 +963,15 @@ public class ConfigPanel extends PluginPanel
|
|||||||
backButton.addActionListener(e -> openConfigList());
|
backButton.addActionListener(e -> openConfigList());
|
||||||
mainPanel.add(backButton);
|
mainPanel.add(backButton);
|
||||||
|
|
||||||
|
if (refresh)
|
||||||
|
{
|
||||||
|
scrollPane.getVerticalScrollBar().setValue(scrollBarPosition);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scrollPane.getVerticalScrollBar().setValue(0);
|
||||||
|
}
|
||||||
revalidate();
|
revalidate();
|
||||||
scrollPane.getVerticalScrollBar().setValue(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeGroupCollapse(PluginListItem listItem, Config config, JComponent component, ConfigDescriptor cd, ConfigItemsGroup cig)
|
private void changeGroupCollapse(PluginListItem listItem, Config config, JComponent component, ConfigDescriptor cd, ConfigItemsGroup cig)
|
||||||
@@ -1136,8 +1180,6 @@ public class ConfigPanel extends PluginPanel
|
|||||||
|
|
||||||
private void reloadPluginlist(PluginListItem listItem, Config config, ConfigDescriptor cd)
|
private void reloadPluginlist(PluginListItem listItem, Config config, ConfigDescriptor cd)
|
||||||
{
|
{
|
||||||
int scrollBarPosition = scrollPane.getVerticalScrollBar().getValue();
|
openGroupConfigPanel(listItem, config, cd, true);
|
||||||
openGroupConfigPanel(listItem, config, cd);
|
|
||||||
scrollPane.getVerticalScrollBar().setValue(scrollBarPosition);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user