Animations on Scroll Bar

This commit is contained in:
huangyuhui 2017-02-27 21:13:43 +08:00
parent 61afad30c8
commit f4303a0480
6 changed files with 222 additions and 280 deletions

View File

@ -203,32 +203,6 @@ public class BEButtonUI extends BasicButtonUI implements Skin {
dh -= (insets.top + insets.bottom);
}
/*if (toolbar)
//此状态下JToggleButton和JButton使用各自的背景实现2012-10-16前无论是不是JToggleButton都是使用该种实是不太合理的
if (model.isRollover() || model.isPressed())
if (c instanceof JToggleButton)
BEToggleButtonUI.ICON_9.get("rollover").draw((Graphics2D) g, dx, dy, dw, dh);
else
ICON_9.get("pressed").draw((Graphics2D) g, dx, dy, dw, dh);
else if (model.isSelected())
BEToggleButtonUI.ICON_9.get("selected").draw((Graphics2D) g, dx, dy, dw, dh);
else {
//TODO 其它状态下的按钮背景样式需要完善要不然看起来太硬
// skin.paintSkin(g, dx, dy, dw, dh, state);
}
else {
//TODO 其它状态下的按钮背景样式需要完善要不然看起来太硬
String key;
if (model.isArmed() && model.isPressed() || model.isSelected())
key = "pressed";
else if (!model.isEnabled())
key = "disabled";
else if (model.isRollover())
key = "rollover";
else
key = "normal";
ICON_9.get(key).draw((Graphics2D) g, dx, dy, dw, dh);
}*/
AnimationController.paintSkin(c, INSTANCE, g, dx, dy, dw, dh, getXPButtonState(b));
}
}
@ -247,7 +221,7 @@ public class BEButtonUI extends BasicButtonUI implements Skin {
return toolbar ? Part.TP_BUTTON : Part.BP_PUSHBUTTON;
}
static State getXPButtonState(AbstractButton b) {
public static State getXPButtonState(AbstractButton b) {
Part part = getXPButtonType(b);
ButtonModel model = b.getModel();
State state = State.NORMAL;
@ -276,13 +250,13 @@ public class BEButtonUI extends BasicButtonUI implements Skin {
else if (!model.isEnabled())
state = State.DISABLED;
else if (model.isSelected() && model.isRollover())
state = State.HOTCHECKED;
state = State.ROLLOVERCHECKED;
else if (model.isSelected())
state = State.CHECKED;
else if (model.isRollover())
state = State.HOT;
state = State.ROLLOVER;
else if (b.hasFocus())
state = State.HOT;
state = State.ROLLOVER;
} else
if ((model.isArmed() && model.isPressed())
|| model.isSelected())
@ -290,7 +264,7 @@ public class BEButtonUI extends BasicButtonUI implements Skin {
else if (!model.isEnabled())
state = State.DISABLED;
else if (model.isRollover() || model.isPressed())
state = State.HOT;
state = State.ROLLOVER;
else if (b instanceof JButton
&& ((JButton) b).isDefaultButton())
state = State.DEFAULTED;
@ -304,27 +278,7 @@ public class BEButtonUI extends BasicButtonUI implements Skin {
@Override
public void paintSkinRaw(Graphics g, int dx, int dy, int dw, int dh, TMSchema.State state) {
String key;
switch (state) {
case SELECTED:
key = "selected";
break;
case PRESSED:
key = "pressed";
break;
case DISABLED:
key = "disabled";
break;
case HOT:
key = "rollover";
break;
case NORMAL:
key = "normal";
break;
default:
return;
}
ICON_9.get(key).draw((Graphics2D) g, dx, dy, dw, dh);
ICON_9.get(state.toString()).draw((Graphics2D) g, dx, dy, dw, dh);
}
/**

View File

@ -183,7 +183,7 @@ public class BEComboBoxUI extends BasicComboBoxUI
} else if (isPopupVisible(comboBox)) {
state = State.PRESSED;
} else if (mouseInside) {
state = State.HOT;
state = State.ROLLOVER;
}
return state;
}
@ -198,7 +198,7 @@ public class BEComboBoxUI extends BasicComboBoxUI
case DISABLED:
key = "disabled";
break;
case HOT:
case ROLLOVER:
key = "rollover";
break;
case NORMAL:

View File

@ -24,8 +24,13 @@ import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicArrowButton;
import javax.swing.plaf.basic.BasicScrollBarUI;
import org.jackhuang.hmcl.laf.button.BEButtonUI;
import org.jackhuang.hmcl.laf.utils.AnimationController;
import org.jackhuang.hmcl.laf.utils.Icon9Factory;
import org.jackhuang.hmcl.laf.utils.Skin;
import org.jackhuang.hmcl.laf.utils.TMSchema;
import org.jackhuang.hmcl.laf.utils.TMSchema.State;
import org.jackhuang.hmcl.util.ui.GraphicsUtils;
/**
@ -37,7 +42,7 @@ import org.jackhuang.hmcl.util.ui.GraphicsUtils;
* @version 1.0
* @see com.sun.java.swing.plaf.windows.WindowsScrollBarUI
*/
public class BEScrollBarUI extends BasicScrollBarUI {
public class BEScrollBarUI extends BasicScrollBarUI implements Skin {
public static final Icon9Factory ICON_9 = new Icon9Factory("scroll_bar");
@ -68,7 +73,7 @@ public class BEScrollBarUI extends BasicScrollBarUI {
* up/down. It differs from BasicArrowButton in that the preferred size is
* always a square.
*/
protected class BEArrowButton extends BasicArrowButton {
protected class BEArrowButton extends BasicArrowButton implements Skin {
/**
* Instantiates a new windows arrow button.
@ -91,7 +96,6 @@ public class BEScrollBarUI extends BasicScrollBarUI {
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
String id = "arrow";
switch (direction) {
case NORTH:
break;
@ -108,8 +112,7 @@ public class BEScrollBarUI extends BasicScrollBarUI {
g2.rotate(Math.PI / 2);
break;
}
ICON_9.getWithScrollState(id, getModel().isPressed(), getModel().isRollover())
.draw(g2, 0, 0, getWidth(), getHeight());
AnimationController.paintSkin(this, this, g, 0, 0, getWidth(), getHeight(), BEButtonUI.getXPButtonState(this));
}
@Override
@ -128,6 +131,16 @@ public class BEScrollBarUI extends BasicScrollBarUI {
}
return new Dimension(size, size);
}
@Override
public void paintSkinRaw(Graphics g, int x, int y, int w, int h, TMSchema.State state) {
ICON_9.get("arrow", state.toString()).draw((Graphics2D) g, x, y, w, h);
}
@Override
public TMSchema.Part getPart(JComponent c) {
return TMSchema.Part.SBP_ARROWBTN;
}
}
//----------------------------------------------------------------------------------- END
@ -148,10 +161,21 @@ public class BEScrollBarUI extends BasicScrollBarUI {
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
if (thumbBounds.isEmpty() || !scrollbar.isEnabled())
return;
Color color = GraphicsUtils.getWebColor(isDragging ? "#616161" : isThumbRollover() ? "#919191" : "#C2C2C2");
g.setColor(color);
g.fillRect(thumbBounds.x, thumbBounds.y, thumbBounds.width, thumbBounds.height);
AnimationController.paintSkin(c, this, g, thumbBounds.x, thumbBounds.y, thumbBounds.width, thumbBounds.height, isDragging ? State.PRESSED : isThumbRollover() ? State.ROLLOVER : State.NORMAL);
}
@Override
public void paintSkinRaw(Graphics g, int x, int y, int w, int h, State state) {
Color color = GraphicsUtils.getWebColor(state == State.PRESSED ? "#616161" : state == State.ROLLOVER ? "#919191" : "#C2C2C2");
g.setColor(color);
g.fillRect(x, y, w, h);
}
@Override
public TMSchema.Part getPart(JComponent c) {
return TMSchema.Part.SBP_THUMBBTNHORZ;
}
//----------------------------------------------------------------------------------- END
}

View File

@ -101,7 +101,7 @@ public class AnimationController implements ActionListener, PropertyChangeListen
if (newState == State.DEFAULTED)
// it seems for DEFAULTED button state Vista does animation from
// HOT
oldState = State.HOT;
oldState = State.ROLLOVER;
if (oldState != null) {
long duration;
//if (newState == State.DEFAULTED) {

View File

@ -136,7 +136,7 @@ public class Icon9Factory extends RawCache<NinePatch> {
put("toggle_button", "selected", "toggle_button_selected");
put("toggle_button", "rollover", "toggle_button_rover");
put("scroll_bar", "arrow", "arrow");
put("scroll_bar", "arrow_normal", "arrow");
put("scroll_bar", "arrow_rollover", "arrow_rover");
put("scroll_bar", "arrow_pressed", "arrow_pressed");
put("scroll_bar", "scroll_pane_border", "scroll_pane_bg1");

View File

@ -16,6 +16,7 @@
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hmcl.laf.utils;
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
@ -55,7 +56,6 @@ package org.jackhuang.hmcl.laf.utils;
* encouraged.
*
*/
import java.awt.*;
import java.util.*;
@ -94,7 +94,6 @@ public class TMSchema {
WINDOW
}
/**
* An enumeration of the Windows compoent parts
*/
@ -110,12 +109,10 @@ public class TMSchema {
MP_POPUPITEM(Control.MENU, 14),
MP_POPUPSEPARATOR(Control.MENU, 15),
MP_POPUPSUBMENU(Control.MENU, 16),
BP_PUSHBUTTON(Control.BUTTON, 1),
BP_RADIOBUTTON(Control.BUTTON, 2),
BP_CHECKBOX(Control.BUTTON, 3),
BP_GROUPBOX(Control.BUTTON, 4),
CP_COMBOBOX(Control.COMBOBOX, 0),
CP_DROPDOWNBUTTON(Control.COMBOBOX, 1),
CP_BACKGROUND(Control.COMBOBOX, 2),
@ -125,27 +122,19 @@ public class TMSchema {
CP_DROPDOWNBUTTONRIGHT(Control.COMBOBOX, 6),
CP_DROPDOWNBUTTONLEFT(Control.COMBOBOX, 7),
CP_CUEBANNER(Control.COMBOBOX, 8),
EP_EDIT(Control.EDIT, 0),
EP_EDITTEXT(Control.EDIT, 1),
HP_HEADERITEM(Control.HEADER, 1),
HP_HEADERSORTARROW(Control.HEADER, 4),
LBP_LISTBOX(Control.LISTBOX, 0),
LVP_LISTVIEW(Control.LISTVIEW, 0),
PP_PROGRESS(Control.PROGRESS, 0),
PP_BAR(Control.PROGRESS, 1),
PP_BARVERT(Control.PROGRESS, 2),
PP_CHUNK(Control.PROGRESS, 3),
PP_CHUNKVERT(Control.PROGRESS, 4),
RP_GRIPPER(Control.REBAR, 1),
RP_GRIPPERVERT(Control.REBAR, 2),
SBP_SCROLLBAR(Control.SCROLLBAR, 0),
SBP_ARROWBTN(Control.SCROLLBAR, 1),
SBP_THUMBBTNHORZ(Control.SCROLLBAR, 2),
@ -157,20 +146,16 @@ public class TMSchema {
SBP_GRIPPERHORZ(Control.SCROLLBAR, 8),
SBP_GRIPPERVERT(Control.SCROLLBAR, 9),
SBP_SIZEBOX(Control.SCROLLBAR, 10),
SPNP_UP(Control.SPIN, 1),
SPNP_DOWN(Control.SPIN, 2),
TABP_TABITEM(Control.TAB, 1),
TABP_TABITEMLEFTEDGE(Control.TAB, 2),
TABP_TABITEMRIGHTEDGE(Control.TAB, 3),
TABP_PANE(Control.TAB, 9),
TP_TOOLBAR(Control.TOOLBAR, 0),
TP_BUTTON(Control.TOOLBAR, 1),
TP_SEPARATOR(Control.TOOLBAR, 5),
TP_SEPARATORVERT(Control.TOOLBAR, 6),
TKP_TRACK(Control.TRACKBAR, 1),
TKP_TRACKVERT(Control.TRACKBAR, 2),
TKP_THUMB(Control.TRACKBAR, 3),
@ -181,10 +166,8 @@ public class TMSchema {
TKP_THUMBRIGHT(Control.TRACKBAR, 8),
TKP_TICS(Control.TRACKBAR, 9),
TKP_TICSVERT(Control.TRACKBAR, 10),
TVP_TREEVIEW(Control.TREEVIEW, 0),
TVP_GLYPH(Control.TREEVIEW, 2),
WP_WINDOW(Control.WINDOW, 0),
WP_CAPTION(Control.WINDOW, 1),
WP_MINCAPTION(Control.WINDOW, 3),
@ -219,10 +202,9 @@ public class TMSchema {
if (component instanceof JComponent) {
JComponent c = (JComponent) component;
String subAppName = (String) c.getClientProperty("XPStyle.subAppName");
if (subAppName != null) {
if (subAppName != null)
str = subAppName + "::";
}
}
return str + control.toString();
}
@ -231,7 +213,6 @@ public class TMSchema {
}
}
/**
* An enumeration of the possible component states
*/
@ -258,8 +239,8 @@ public class TMSchema {
DOWNNORMAL,
DOWNPRESSED,
FOCUSED,
HOT,
HOTCHECKED,
ROLLOVER,
ROLLOVERCHECKED,
ICONHOT,
ICONNORMAL,
ICONPRESSED,
@ -308,7 +289,6 @@ public class TMSchema {
SORTEDPRESSED,
SORTEDUP;
/**
* A map of allowed states for each Part
*/
@ -319,11 +299,11 @@ public class TMSchema {
stateMap.put(Part.EP_EDITTEXT,
new State[] {
NORMAL, HOT, SELECTED, DISABLED, FOCUSED, READONLY, ASSIST
NORMAL, ROLLOVER, SELECTED, DISABLED, FOCUSED, READONLY, ASSIST
});
stateMap.put(Part.BP_PUSHBUTTON,
new State[] { NORMAL, HOT, PRESSED, DISABLED, DEFAULTED });
new State[] { NORMAL, ROLLOVER, PRESSED, DISABLED, DEFAULTED });
stateMap.put(Part.BP_RADIOBUTTON,
new State[] {
@ -338,7 +318,7 @@ public class TMSchema {
MIXEDNORMAL, MIXEDHOT, MIXEDPRESSED, MIXEDDISABLED
});
State[] comboBoxStates = new State[] { NORMAL, HOT, PRESSED, DISABLED };
State[] comboBoxStates = new State[] { NORMAL, ROLLOVER, PRESSED, DISABLED };
stateMap.put(Part.CP_COMBOBOX, comboBoxStates);
stateMap.put(Part.CP_DROPDOWNBUTTON, comboBoxStates);
stateMap.put(Part.CP_BACKGROUND, comboBoxStates);
@ -349,7 +329,7 @@ public class TMSchema {
stateMap.put(Part.CP_DROPDOWNBUTTONLEFT, comboBoxStates);
stateMap.put(Part.CP_CUEBANNER, comboBoxStates);
stateMap.put(Part.HP_HEADERITEM, new State[] { NORMAL, HOT, PRESSED,
stateMap.put(Part.HP_HEADERITEM, new State[] { NORMAL, ROLLOVER, PRESSED,
SORTEDNORMAL, SORTEDHOT, SORTEDPRESSED,
ICONNORMAL, ICONHOT, ICONPRESSED,
ICONSORTEDNORMAL, ICONSORTEDHOT, ICONSORTEDPRESSED });
@ -357,7 +337,7 @@ public class TMSchema {
stateMap.put(Part.HP_HEADERSORTARROW,
new State[] { SORTEDDOWN, SORTEDUP });
State[] scrollBarStates = new State[] { NORMAL, HOT, PRESSED, DISABLED, HOVER };
State[] scrollBarStates = new State[] { NORMAL, ROLLOVER, PRESSED, DISABLED, HOVER };
stateMap.put(Part.SBP_SCROLLBAR, scrollBarStates);
stateMap.put(Part.SBP_THUMBBTNVERT, scrollBarStates);
stateMap.put(Part.SBP_THUMBBTNHORZ, scrollBarStates);
@ -373,17 +353,15 @@ public class TMSchema {
UPHOVER, DOWNHOVER, LEFTHOVER, RIGHTHOVER
});
State[] spinnerStates = new State[] { NORMAL, HOT, PRESSED, DISABLED };
State[] spinnerStates = new State[] { NORMAL, ROLLOVER, PRESSED, DISABLED };
stateMap.put(Part.SPNP_UP, spinnerStates);
stateMap.put(Part.SPNP_DOWN, spinnerStates);
stateMap.put(Part.TVP_GLYPH, new State[] { CLOSED, OPENED });
State[] frameButtonStates = new State[] {
NORMAL, HOT, PUSHED, DISABLED, // See note 1
INACTIVENORMAL, INACTIVEHOT, INACTIVEPUSHED, INACTIVEDISABLED,
};
NORMAL, ROLLOVER, PUSHED, DISABLED, // See note 1
INACTIVENORMAL, INACTIVEHOT, INACTIVEPUSHED, INACTIVEDISABLED, };
// Note 1: The INACTIVE frame button states apply when the frame
// is inactive. They are not defined in tmschema.h
@ -396,7 +374,6 @@ public class TMSchema {
INACTIVENORMAL, INACTIVEHOT, INACTIVEPUSHED, INACTIVEDISABLED, null
};
}*/
stateMap.put(Part.WP_MINBUTTON, frameButtonStates);
stateMap.put(Part.WP_MAXBUTTON, frameButtonStates);
stateMap.put(Part.WP_RESTOREBUTTON, frameButtonStates);
@ -406,8 +383,8 @@ public class TMSchema {
stateMap.put(Part.TKP_TRACK, new State[] { NORMAL });
stateMap.put(Part.TKP_TRACKVERT, new State[] { NORMAL });
State[] sliderThumbStates =
new State[] { NORMAL, HOT, PRESSED, FOCUSED, DISABLED };
State[] sliderThumbStates
= new State[] { NORMAL, ROLLOVER, PRESSED, FOCUSED, DISABLED };
stateMap.put(Part.TKP_THUMB, sliderThumbStates);
stateMap.put(Part.TKP_THUMBBOTTOM, sliderThumbStates);
stateMap.put(Part.TKP_THUMBTOP, sliderThumbStates);
@ -415,15 +392,14 @@ public class TMSchema {
stateMap.put(Part.TKP_THUMBRIGHT, sliderThumbStates);
// States for Tabs
State[] tabStates = new State[] { NORMAL, HOT, SELECTED, DISABLED, FOCUSED };
State[] tabStates = new State[] { NORMAL, ROLLOVER, SELECTED, DISABLED, FOCUSED };
stateMap.put(Part.TABP_TABITEM, tabStates);
stateMap.put(Part.TABP_TABITEMLEFTEDGE, tabStates);
stateMap.put(Part.TABP_TABITEMRIGHTEDGE, tabStates);
stateMap.put(Part.TP_BUTTON,
new State[] {
NORMAL, HOT, PRESSED, DISABLED, CHECKED, HOTCHECKED
NORMAL, ROLLOVER, PRESSED, DISABLED, CHECKED, ROLLOVERCHECKED
});
State[] frameStates = new State[] { ACTIVE, INACTIVE };
@ -440,7 +416,7 @@ public class TMSchema {
stateMap.put(Part.MP_BARBACKGROUND,
new State[] { ACTIVE, INACTIVE });
stateMap.put(Part.MP_BARITEM,
new State[] { NORMAL, HOT, PUSHED,
new State[] { NORMAL, ROLLOVER, PUSHED,
DISABLED, DISABLEDHOT, DISABLEDPUSHED });
stateMap.put(Part.MP_POPUPCHECK,
new State[] { CHECKMARKNORMAL, CHECKMARKDISABLED,
@ -448,36 +424,34 @@ public class TMSchema {
stateMap.put(Part.MP_POPUPCHECKBACKGROUND,
new State[] { DISABLEDPUSHED, NORMAL, BITMAP });
stateMap.put(Part.MP_POPUPITEM,
new State[] { NORMAL, HOT, DISABLED, DISABLEDHOT });
new State[] { NORMAL, ROLLOVER, DISABLED, DISABLEDHOT });
stateMap.put(Part.MP_POPUPSUBMENU,
new State[] { NORMAL, DISABLED });
}
public static synchronized int getValue(Part part, State state) {
if (stateMap == null) {
if (stateMap == null)
initStates();
}
Enum[] states = stateMap.get(part);
if (states != null) {
for (int i = 0; i < states.length; i++) {
if (state == states[i]) {
if (states != null)
for (int i = 0; i < states.length; i++)
if (state == states[i])
return i + 1;
}
}
}
if (state == null || state == State.NORMAL) {
if (state == null || state == State.NORMAL)
return 1;
}
return 0;
}
@Override
public String toString() {
return name().toLowerCase();
}
}
/**
* An enumeration of the possible component attributes and the
@ -486,9 +460,7 @@ public class TMSchema {
public static enum Prop {
COLOR(Color.class, 204),
SIZE(Dimension.class, 207),
FLATMENUS(Boolean.class, 1001),
BORDERONLY(Boolean.class, 2203), // only draw the border area of the image
IMAGECOUNT(Integer.class, 2401), // the number of state images in an imagefile
@ -501,7 +473,6 @@ public class TMSchema {
NORMALSIZE(Dimension.class, 3409), // size of dest rect that exactly source
SIZINGMARGINS(Insets.class, 3601), // margins used for 9-grid sizing
CONTENTMARGINS(Insets.class, 3602), // margins that define where content can be placed
CAPTIONMARGINS(Insets.class, 3603), // margins that define where caption text can be placed
@ -535,19 +506,16 @@ public class TMSchema {
}
}
/**
* An enumeration of attribute values for some Props
*/
public static enum TypeEnum {
BT_IMAGEFILE(Prop.BGTYPE, "imagefile", 0),
BT_BORDERFILL(Prop.BGTYPE, "borderfill", 1),
TST_NONE(Prop.TEXTSHADOWTYPE, "none", 0),
TST_SINGLE(Prop.TEXTSHADOWTYPE, "single", 1),
TST_CONTINUOUS(Prop.TEXTSHADOWTYPE, "continuous", 2);
private TypeEnum(Prop prop, String enumName, int value) {
this.prop = prop;
this.enumName = enumName;
@ -566,15 +534,11 @@ public class TMSchema {
return enumName;
}
static TypeEnum getTypeEnum(Prop prop, int enumval) {
for (TypeEnum e : TypeEnum.values()) {
if (e.prop == prop && e.value == enumval) {
for (TypeEnum e : TypeEnum.values())
if (e.prop == prop && e.value == enumval)
return e;
}
}
return null;
}
}
}