📄 slider.java
字号:
package com.ismyway.fairyui;
import javax.microedition.lcdui.Graphics;
import com.ismyway.anyview.others.Settings;
import com.ismyway.util.Theme;
public class Slider extends Row {
int x2, showwidth, fillwidth;
byte stopover = 0;
private SpinButton left, right, fleft, fright;
private int min = 0, max = 100, step = 1, current = 0, faststep = 10;
private String suffix = "";
private boolean fastmode = false;
private boolean hexMode = false;
private ValueChangeListener valueChangeListener = null;
public boolean isHexMode() {
return hexMode;
}
public void setHexMode(boolean hexMode) {
this.hexMode = hexMode;
}
public final String getSuffix() {
return suffix;
}
public final void setSuffix(String suffix) {
this.suffix = suffix;
}
public Slider() {
}
public void setParameters(int min, int max, int current) {
this.min = min;
this.max = max;
this.current = current;
}
public void paint(Graphics g, int adjustx, int adjusty) {
g.setColor(filledColor);
g.fillRect(getLeft(), getTop() - adjusty, getWidth(), getHeight());
g.setColor(Theme.TextColor);
if (fastmode) {
fleft.paint(g, adjustx, adjusty);
}
left.paint(g, adjustx, adjusty);
g.setColor(Theme.TextColor);
g.drawRect(x2, getTop() - adjusty + 2, showwidth, 16);
g.setColor(Theme.TextShade);
g.fillRect(x2 + 1, getTop() - adjusty + 3, fillwidth, 15);
int fw = getFont().stringWidth(current + suffix);
if (hexMode) {
fw = getFont().stringWidth(Integer.toHexString(current).toUpperCase() + suffix);
}
int fx = (showwidth - fw) / 2;
g.setFont(getFont());
g.setColor(Theme.TextColor);
if (hexMode) {
g.drawString(Integer.toHexString(current).toUpperCase() + suffix, x2 + fx, getTop() - adjusty + 1, ANCHOR);
} else {
g.drawString(current + suffix, x2 + fx, getTop() - adjusty + 1, ANCHOR);
}
right.paint(g, adjustx, adjusty);
if (fastmode) {
fright.paint(g, adjustx, adjusty);
}
// g.drawRect(x3, getTop() - adjusty + 2, 16, 16);
// if (stopover == 1) {
// g.setColor(Theme.ComponentLight);
// g.drawRect(x3 + 1, getTop() - adjusty + 3, 15, 15);
// Theme.drawArrow(g, x3 + 7, getTop() - adjusty + 7, Theme.RIGHT, Theme.TextColor);
// } else {
// Theme.drawArrow(g, x3 + 7, getTop() - adjusty + 7, Theme.RIGHT, Theme.ComponentDark);
// }
//g.fillRect(getLeft() - adjustx, getTop() - adjusty, getWidth(), getHeight());
}
public void validate() {
setHeight(20);
if (fastmode) {
fleft = new SpinButton(this);
fleft.setDir((byte) Theme.LEFT);
fleft.setFastmode(true);
fleft.setLocation(Settings.VECPADDING, getTop() + 2);
left = new SpinButton(this);
left.setDir((byte) Theme.LEFT);
left.setLocation(Settings.VECPADDING * 2 + 16, getTop() + 2);
fright = new SpinButton(this);
fright.setDir((byte) Theme.RIGHT);
fright.setFastmode(true);
fright.setLocation(getWidth() - Settings.VECPADDING - 16, getTop() + 2);
right = new SpinButton(this);
right.setDir((byte) Theme.RIGHT);
right.setLocation(getWidth() - Settings.VECPADDING * 2 - 32, getTop() + 2);
x2 = Settings.VECPADDING * 3 + 32;
showwidth = getWidth() - Settings.VECPADDING * 6 - 64;
components.clear();
fleft.setParent(this);
left.setParent(this);
right.setParent(this);
fright.setParent(this);
components.add(fleft);
components.add(left);
components.add(right);
components.add(fright);
} else {
left = new SpinButton(this);
left.setDir((byte) Theme.LEFT);
left.setLocation(Settings.VECPADDING, getTop() + 2);
right = new SpinButton(this);
right.setDir((byte) Theme.RIGHT);
right.setLocation(getWidth() - Settings.VECPADDING - 16, getTop() + 2);
x2 = Settings.VECPADDING * 2 + 16;
showwidth = getWidth() - Settings.VECPADDING * 4 - 32;
components.clear();
left.setParent(this);
right.setParent(this);
components.add(left);
components.add(right);
}
fillwidth = (current - min) * (showwidth - 1) / (max - min);
}
public boolean changeRange() {
if (fastmode && fleft.isSelected()) {
current -= faststep;
current = current < min ? min : current;
} else if (left.isSelected()) {
current -= step;
current = current < min ? min : current;
} else if (right.isSelected()) {
current += step;
current = current > max ? max : current;
} else if (fastmode && fright.isSelected()) {
current += faststep;
current = current > max ? max : current;
}
fillwidth = (current - min) * (showwidth - 1) / (max - min);
if (null != valueChangeListener) {
valueChangeListener.valueChanged(this);
}
return true;
}
public int getCurrent() {
return current;
}
public void setCurrent(int current) {
this.current = current;
fillwidth = (current - min) * (showwidth - 1) / (max - min);
}
public int getFaststep() {
return faststep;
}
public void setFaststep(int faststep) {
this.faststep = faststep;
}
public int getStep() {
return step;
}
public void setStep(int step) {
this.step = step;
}
public boolean isFastmode() {
return fastmode;
}
public void setFastmode(boolean fastmode) {
this.fastmode = fastmode;
}
public ValueChangeListener getValueChangeListener() {
return valueChangeListener;
}
public void setValueChangeListener(ValueChangeListener valueChangeListener) {
this.valueChangeListener = valueChangeListener;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -