mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Fix performance of list boxes
Skin border for list on ListChooser dialogs
This commit is contained in:
@@ -28,7 +28,6 @@ import java.util.List;
|
|||||||
import javax.swing.AbstractListModel;
|
import javax.swing.AbstractListModel;
|
||||||
import javax.swing.DefaultListCellRenderer;
|
import javax.swing.DefaultListCellRenderer;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.ListCellRenderer;
|
import javax.swing.ListCellRenderer;
|
||||||
import javax.swing.ListSelectionModel;
|
import javax.swing.ListSelectionModel;
|
||||||
import javax.swing.WindowConstants;
|
import javax.swing.WindowConstants;
|
||||||
@@ -42,6 +41,7 @@ import forge.FThreads;
|
|||||||
import forge.gui.toolbox.FList;
|
import forge.gui.toolbox.FList;
|
||||||
import forge.gui.toolbox.FMouseAdapter;
|
import forge.gui.toolbox.FMouseAdapter;
|
||||||
import forge.gui.toolbox.FOptionPane;
|
import forge.gui.toolbox.FOptionPane;
|
||||||
|
import forge.gui.toolbox.FScrollPane;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple class that shows a list of choices in a dialog. Two properties
|
* A simple class that shows a list of choices in a dialog. Two properties
|
||||||
@@ -102,7 +102,7 @@ public class ListChooser<T> {
|
|||||||
this.lstChoices.setCellRenderer(new TransformedCellRenderer(display));
|
this.lstChoices.setCellRenderer(new TransformedCellRenderer(display));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.optionPane = new FOptionPane(null, title, null, new JScrollPane(this.lstChoices), options, minChoices < 0 ? 0 : -1);
|
this.optionPane = new FOptionPane(null, title, null, new FScrollPane(this.lstChoices), options, minChoices < 0 ? 0 : -1);
|
||||||
this.optionPane.setButtonEnabled(0, minChoices <= 0);
|
this.optionPane.setButtonEnabled(0, minChoices <= 0);
|
||||||
|
|
||||||
if (minChoices != -1) {
|
if (minChoices != -1) {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package forge.gui.toolbox;
|
package forge.gui.toolbox;
|
||||||
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
import java.awt.event.FocusEvent;
|
||||||
|
import java.awt.event.FocusListener;
|
||||||
|
|
||||||
import javax.swing.DefaultListCellRenderer;
|
import javax.swing.DefaultListCellRenderer;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
@@ -9,7 +11,6 @@ import javax.swing.ListCellRenderer;
|
|||||||
import javax.swing.ListModel;
|
import javax.swing.ListModel;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
import forge.gui.toolbox.FSkin.SkinnedLabel;
|
|
||||||
import forge.gui.toolbox.FSkin.SkinnedList;
|
import forge.gui.toolbox.FSkin.SkinnedList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,7 +21,7 @@ import forge.gui.toolbox.FSkin.SkinnedList;
|
|||||||
public class FList<E> extends SkinnedList<E> {
|
public class FList<E> extends SkinnedList<E> {
|
||||||
public FList() {
|
public FList() {
|
||||||
super();
|
super();
|
||||||
applySkin();
|
initialize();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* A JList object using Forge skin properties.
|
* A JList object using Forge skin properties.
|
||||||
@@ -30,7 +31,7 @@ public class FList<E> extends SkinnedList<E> {
|
|||||||
*/
|
*/
|
||||||
public FList(final ListModel<E> model0) {
|
public FList(final ListModel<E> model0) {
|
||||||
super(model0);
|
super(model0);
|
||||||
applySkin();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,17 +42,32 @@ public class FList<E> extends SkinnedList<E> {
|
|||||||
*/
|
*/
|
||||||
public FList(E[] o0) {
|
public FList(E[] o0) {
|
||||||
super(o0);
|
super(o0);
|
||||||
applySkin();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void initialize() {
|
||||||
* TODO: Write javadoc for this method.
|
|
||||||
*/
|
|
||||||
private void applySkin() {
|
|
||||||
this.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
this.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
|
||||||
|
this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||||
|
this.setSelectionForeground(this.getSkin().getForeground());
|
||||||
|
this.setFont(FSkin.getFont(12));
|
||||||
|
this.setCellRenderer(new ComplexCellRenderer<E>());
|
||||||
|
|
||||||
ListCellRenderer<E> renderer = new ComplexCellRenderer<E>();
|
this.addFocusListener(new FocusListener() {
|
||||||
setCellRenderer(renderer);
|
@Override
|
||||||
|
public void focusGained(FocusEvent arg0) {
|
||||||
|
updateSelectionBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void focusLost(FocusEvent arg0) {
|
||||||
|
updateSelectionBackground();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
updateSelectionBackground();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateSelectionBackground() {
|
||||||
|
this.setSelectionBackground(FSkin.getColor(hasFocus() ? FSkin.Colors.CLR_ACTIVE : FSkin.Colors.CLR_INACTIVE));
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ComplexCellRenderer<E1> implements ListCellRenderer<E1> {
|
private class ComplexCellRenderer<E1> implements ListCellRenderer<E1> {
|
||||||
@@ -61,15 +77,9 @@ public class FList<E> extends SkinnedList<E> {
|
|||||||
public Component getListCellRendererComponent(JList<? extends E1> lst0, E1 val0, int i0,
|
public Component getListCellRendererComponent(JList<? extends E1> lst0, E1 val0, int i0,
|
||||||
boolean isSelected, boolean cellHasFocus) {
|
boolean isSelected, boolean cellHasFocus) {
|
||||||
|
|
||||||
JLabel defaultItem = (JLabel) defaultRenderer.getListCellRendererComponent(
|
JLabel lblItem = (JLabel) defaultRenderer.getListCellRendererComponent(
|
||||||
lst0, val0, i0, isSelected, cellHasFocus);
|
lst0, val0, i0, isSelected, cellHasFocus);
|
||||||
SkinnedLabel lblItem = new SkinnedLabel(defaultItem.getText());
|
|
||||||
|
|
||||||
lblItem.setBorder(new EmptyBorder(4, 3, 4, 3));
|
lblItem.setBorder(new EmptyBorder(4, 3, 4, 3));
|
||||||
lblItem.setBackground(FSkin.getColor(hasFocus() ? FSkin.Colors.CLR_ACTIVE : FSkin.Colors.CLR_INACTIVE));
|
|
||||||
lblItem.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
|
||||||
lblItem.setFont(FSkin.getFont(12));
|
|
||||||
lblItem.setOpaque(isSelected);
|
|
||||||
return lblItem;
|
return lblItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2018,6 +2018,25 @@ public enum FSkin {
|
|||||||
super.reapply(comp);
|
super.reapply(comp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static class JSkinSkin<T extends JList<?>> extends JComponentSkin<T> {
|
||||||
|
private SkinColor selectionForeground, selectionBackground;
|
||||||
|
|
||||||
|
protected JSkinSkin() {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setSelectionForeground(T comp, SkinColor skinColor) { comp.setSelectionForeground(skinColor != null ? skinColor.color : null); this.selectionForeground = skinColor; }
|
||||||
|
protected void resetSelectionForeground() { this.selectionForeground = null; }
|
||||||
|
|
||||||
|
protected void setSelectionBackground(T comp, SkinColor skinColor) { comp.setSelectionBackground(skinColor != null ? skinColor.color : null); this.selectionBackground = skinColor; }
|
||||||
|
protected void resetSelectionBackground() { this.selectionBackground = null; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void reapply(T comp) {
|
||||||
|
if (this.selectionForeground != null) { setSelectionForeground(comp, this.selectionForeground); }
|
||||||
|
if (this.selectionBackground != null) { setSelectionBackground(comp, this.selectionBackground); }
|
||||||
|
super.reapply(comp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static interface ISkinnedComponent<T extends Component> {
|
public static interface ISkinnedComponent<T extends Component> {
|
||||||
public ComponentSkin<T> getSkin();
|
public ComponentSkin<T> getSkin();
|
||||||
@@ -2222,9 +2241,9 @@ public enum FSkin {
|
|||||||
public static class SkinnedList<E> extends JList<E> implements ISkinnedComponent<JList<E>> {
|
public static class SkinnedList<E> extends JList<E> implements ISkinnedComponent<JList<E>> {
|
||||||
private static final long serialVersionUID = -2449981390420167627L;
|
private static final long serialVersionUID = -2449981390420167627L;
|
||||||
|
|
||||||
private JComponentSkin<JList<E>> skin;
|
private JSkinSkin<JList<E>> skin;
|
||||||
public JComponentSkin<JList<E>> getSkin() {
|
public JSkinSkin<JList<E>> getSkin() {
|
||||||
if (skin == null) { skin = new JComponentSkin<JList<E>>(); }
|
if (skin == null) { skin = new JSkinSkin<JList<E>>(); }
|
||||||
return skin;
|
return skin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2247,6 +2266,12 @@ public enum FSkin {
|
|||||||
public void setBorder(SkinBorder skinBorder) { getSkin().setBorder(this, skinBorder); }
|
public void setBorder(SkinBorder skinBorder) { getSkin().setBorder(this, skinBorder); }
|
||||||
@Override public void setBorder(Border border) { getSkin().resetBorder(); super.setBorder(border); }
|
@Override public void setBorder(Border border) { getSkin().resetBorder(); super.setBorder(border); }
|
||||||
|
|
||||||
|
public void setSelectionForeground(SkinColor skinColor) { getSkin().setSelectionForeground(this, skinColor); }
|
||||||
|
@Override public void setSelectionForeground(Color color) { getSkin().resetSelectionForeground(); super.setSelectionForeground(color); }
|
||||||
|
|
||||||
|
public void setSelectionBackground(SkinColor skinColor) { getSkin().setSelectionBackground(this, skinColor); }
|
||||||
|
@Override public void setSelectionBackground(Color color) { getSkin().resetSelectionBackground(); super.setSelectionBackground(color); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
getSkin().update(this);
|
getSkin().update(this);
|
||||||
@@ -2825,10 +2850,10 @@ public enum FSkin {
|
|||||||
@Override public void setBorder(Border border) { getSkin().resetBorder(); super.setBorder(border); }
|
@Override public void setBorder(Border border) { getSkin().resetBorder(); super.setBorder(border); }
|
||||||
|
|
||||||
public void setSelectionForeground(SkinColor skinColor) { getSkin().setSelectionForeground(this, skinColor); }
|
public void setSelectionForeground(SkinColor skinColor) { getSkin().setSelectionForeground(this, skinColor); }
|
||||||
public void setSelectionForeground(Color color) { getSkin().resetSelectionForeground(); super.setSelectionForeground(color); }
|
@Override public void setSelectionForeground(Color color) { getSkin().resetSelectionForeground(); super.setSelectionForeground(color); }
|
||||||
|
|
||||||
public void setSelectionBackground(SkinColor skinColor) { getSkin().setSelectionBackground(this, skinColor); }
|
public void setSelectionBackground(SkinColor skinColor) { getSkin().setSelectionBackground(this, skinColor); }
|
||||||
public void setSelectionBackground(Color color) { getSkin().resetSelectionBackground(); super.setSelectionBackground(color); }
|
@Override public void setSelectionBackground(Color color) { getSkin().resetSelectionBackground(); super.setSelectionBackground(color); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void paintComponent(Graphics g) {
|
protected void paintComponent(Graphics g) {
|
||||||
|
|||||||
Reference in New Issue
Block a user