mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Refactor ComponentSkin.skins to compSkins in FSkin
This commit is contained in:
@@ -78,14 +78,6 @@ public enum FSkin {
|
|||||||
|
|
||||||
|
|
||||||
public static class ComponentSkin<T extends Component> {
|
public static class ComponentSkin<T extends Component> {
|
||||||
private static final HashMap<Component, ComponentSkin<?>> skins = new HashMap<Component, ComponentSkin<?>>();
|
|
||||||
|
|
||||||
private static void reapplyAll() {
|
|
||||||
for (ComponentSkin<?> compSkin : skins.values()) {
|
|
||||||
compSkin.reapply();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected T comp;
|
protected T comp;
|
||||||
private SkinColor foreground, background;
|
private SkinColor foreground, background;
|
||||||
private SkinFont font;
|
private SkinFont font;
|
||||||
@@ -458,75 +450,77 @@ public enum FSkin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final HashMap<Component, ComponentSkin<?>> compSkins = new HashMap<Component, ComponentSkin<?>>();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends Component> ComponentSkin<T> get(T comp) {
|
public static <T extends Component> ComponentSkin<T> get(T comp) {
|
||||||
ComponentSkin<T> compSkin = (ComponentSkin<T>) ComponentSkin.skins.get(comp);
|
ComponentSkin<T> compSkin = (ComponentSkin<T>) compSkins.get(comp);
|
||||||
if (compSkin == null) {
|
if (compSkin == null) {
|
||||||
compSkin = new ComponentSkin<T>(comp);
|
compSkin = new ComponentSkin<T>(comp);
|
||||||
ComponentSkin.skins.put(comp, compSkin);
|
compSkins.put(comp, compSkin);
|
||||||
}
|
}
|
||||||
return compSkin;
|
return compSkin;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends Window> WindowSkin<T> get(T comp) {
|
public static <T extends Window> WindowSkin<T> get(T comp) {
|
||||||
WindowSkin<T> compSkin = (WindowSkin<T>) ComponentSkin.skins.get(comp);
|
WindowSkin<T> compSkin = (WindowSkin<T>) compSkins.get(comp);
|
||||||
if (compSkin == null) {
|
if (compSkin == null) {
|
||||||
compSkin = new WindowSkin<T>(comp);
|
compSkin = new WindowSkin<T>(comp);
|
||||||
ComponentSkin.skins.put(comp, compSkin);
|
compSkins.put(comp, compSkin);
|
||||||
}
|
}
|
||||||
return compSkin;
|
return compSkin;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends JComponent> JComponentSkin<T> get(T comp) {
|
public static <T extends JComponent> JComponentSkin<T> get(T comp) {
|
||||||
JComponentSkin<T> compSkin = (JComponentSkin<T>) ComponentSkin.skins.get(comp);
|
JComponentSkin<T> compSkin = (JComponentSkin<T>) compSkins.get(comp);
|
||||||
if (compSkin == null) {
|
if (compSkin == null) {
|
||||||
compSkin = new JComponentSkin<T>(comp);
|
compSkin = new JComponentSkin<T>(comp);
|
||||||
ComponentSkin.skins.put(comp, compSkin);
|
compSkins.put(comp, compSkin);
|
||||||
}
|
}
|
||||||
return compSkin;
|
return compSkin;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends JLabel> JLabelSkin<T> get(T comp) {
|
public static <T extends JLabel> JLabelSkin<T> get(T comp) {
|
||||||
JLabelSkin<T> compSkin = (JLabelSkin<T>) ComponentSkin.skins.get(comp);
|
JLabelSkin<T> compSkin = (JLabelSkin<T>) compSkins.get(comp);
|
||||||
if (compSkin == null) {
|
if (compSkin == null) {
|
||||||
compSkin = new JLabelSkin<T>(comp);
|
compSkin = new JLabelSkin<T>(comp);
|
||||||
ComponentSkin.skins.put(comp, compSkin);
|
compSkins.put(comp, compSkin);
|
||||||
}
|
}
|
||||||
return compSkin;
|
return compSkin;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends AbstractButton> AbstractButtonSkin<T> get(T comp) {
|
public static <T extends AbstractButton> AbstractButtonSkin<T> get(T comp) {
|
||||||
AbstractButtonSkin<T> compSkin = (AbstractButtonSkin<T>) ComponentSkin.skins.get(comp);
|
AbstractButtonSkin<T> compSkin = (AbstractButtonSkin<T>) compSkins.get(comp);
|
||||||
if (compSkin == null) {
|
if (compSkin == null) {
|
||||||
compSkin = new AbstractButtonSkin<T>(comp);
|
compSkin = new AbstractButtonSkin<T>(comp);
|
||||||
ComponentSkin.skins.put(comp, compSkin);
|
compSkins.put(comp, compSkin);
|
||||||
}
|
}
|
||||||
return compSkin;
|
return compSkin;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends JTextComponent> JTextComponentSkin<T> get(T comp) {
|
public static <T extends JTextComponent> JTextComponentSkin<T> get(T comp) {
|
||||||
JTextComponentSkin<T> compSkin = (JTextComponentSkin<T>) ComponentSkin.skins.get(comp);
|
JTextComponentSkin<T> compSkin = (JTextComponentSkin<T>) compSkins.get(comp);
|
||||||
if (compSkin == null) {
|
if (compSkin == null) {
|
||||||
compSkin = new JTextComponentSkin<T>(comp);
|
compSkin = new JTextComponentSkin<T>(comp);
|
||||||
ComponentSkin.skins.put(comp, compSkin);
|
compSkins.put(comp, compSkin);
|
||||||
}
|
}
|
||||||
return compSkin;
|
return compSkin;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends JTable> JTableSkin<T> get(T comp) {
|
public static <T extends JTable> JTableSkin<T> get(T comp) {
|
||||||
JTableSkin<T> compSkin = (JTableSkin<T>) ComponentSkin.skins.get(comp);
|
JTableSkin<T> compSkin = (JTableSkin<T>) compSkins.get(comp);
|
||||||
if (compSkin == null) {
|
if (compSkin == null) {
|
||||||
compSkin = new JTableSkin<T>(comp);
|
compSkin = new JTableSkin<T>(comp);
|
||||||
ComponentSkin.skins.put(comp, compSkin);
|
compSkins.put(comp, compSkin);
|
||||||
}
|
}
|
||||||
return compSkin;
|
return compSkin;
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends FPanel> FPanelSkin<T> get(T comp) {
|
public static <T extends FPanel> FPanelSkin<T> get(T comp) {
|
||||||
FPanelSkin<T> compSkin = (FPanelSkin<T>) ComponentSkin.skins.get(comp);
|
FPanelSkin<T> compSkin = (FPanelSkin<T>) compSkins.get(comp);
|
||||||
if (compSkin == null) {
|
if (compSkin == null) {
|
||||||
compSkin = new FPanelSkin<T>(comp);
|
compSkin = new FPanelSkin<T>(comp);
|
||||||
ComponentSkin.skins.put(comp, compSkin);
|
compSkins.put(comp, compSkin);
|
||||||
}
|
}
|
||||||
return compSkin;
|
return compSkin;
|
||||||
}
|
}
|
||||||
@@ -535,10 +529,10 @@ public enum FSkin {
|
|||||||
if (comp instanceof IDisposable) { //dispose component itself if possible
|
if (comp instanceof IDisposable) { //dispose component itself if possible
|
||||||
((IDisposable)comp).dispose();
|
((IDisposable)comp).dispose();
|
||||||
}
|
}
|
||||||
ComponentSkin<?> compSkin = ComponentSkin.skins.get(comp);
|
ComponentSkin<?> compSkin = compSkins.get(comp);
|
||||||
if (compSkin != null) {
|
if (compSkin != null) {
|
||||||
compSkin.comp = null;
|
compSkin.comp = null;
|
||||||
ComponentSkin.skins.remove(comp);
|
compSkins.remove(comp);
|
||||||
}
|
}
|
||||||
if (comp instanceof Container) {
|
if (comp instanceof Container) {
|
||||||
//dispose skins for child components
|
//dispose skins for child components
|
||||||
@@ -1741,7 +1735,9 @@ public enum FSkin {
|
|||||||
loadFull(false);
|
loadFull(false);
|
||||||
|
|
||||||
//reapply skin to all skinned components
|
//reapply skin to all skinned components
|
||||||
ComponentSkin.reapplyAll();
|
for (ComponentSkin<?> compSkin : compSkins.values()) {
|
||||||
|
compSkin.reapply();
|
||||||
|
}
|
||||||
|
|
||||||
//refresh certain components skinned via look and feel
|
//refresh certain components skinned via look and feel
|
||||||
Singletons.getControl().getForgeMenu().refresh();
|
Singletons.getControl().getForgeMenu().refresh();
|
||||||
|
|||||||
Reference in New Issue
Block a user