+ 3 display styles: WINDOWS, PQ1, PQ2
x drawed under border, now draws only between borders
This commit is contained in:
@@ -6,6 +6,9 @@ import java.awt.FontMetrics;
|
|||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
|
||||||
public class MyProgBar extends Component {
|
public class MyProgBar extends Component {
|
||||||
|
final static int WINDOWS = 1;
|
||||||
|
final static int PQ1 = 2;
|
||||||
|
final static int PQ2 = 3;
|
||||||
int minVal;
|
int minVal;
|
||||||
int maxVal;
|
int maxVal;
|
||||||
int curVal;
|
int curVal;
|
||||||
@@ -14,22 +17,25 @@ public class MyProgBar extends Component {
|
|||||||
Color txColor = Color.white;
|
Color txColor = Color.white;
|
||||||
int Height = 18;
|
int Height = 18;
|
||||||
int Width = 40;
|
int Width = 40;
|
||||||
|
private int mode;
|
||||||
|
|
||||||
public MyProgBar(int min, int max, int pos) {
|
public MyProgBar(int min, int max, int pos, int mode) {
|
||||||
// super();
|
|
||||||
this.minVal = min;
|
this.minVal = min;
|
||||||
this.maxVal = max;
|
this.maxVal = max;
|
||||||
this.curVal = pos;
|
this.curVal = pos;
|
||||||
|
this.mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MyProgBar(int min, int max, int pos) {
|
||||||
|
this(min, max, pos, MyProgBar.WINDOWS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyProgBar(int min, int max) {
|
public MyProgBar(int min, int max) {
|
||||||
// super();
|
this(min, max, min, MyProgBar.WINDOWS);
|
||||||
this(min, max, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyProgBar() {
|
public MyProgBar() {
|
||||||
// super();
|
this(0, 100, 0, MyProgBar.WINDOWS);
|
||||||
this(0, 100, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
@@ -41,9 +47,28 @@ public class MyProgBar extends Component {
|
|||||||
g.setColor(bgColor);
|
g.setColor(bgColor);
|
||||||
g.fill3DRect(0,0,getSize().width-1,getSize().height-1, false);
|
g.fill3DRect(0,0,getSize().width-1,getSize().height-1, false);
|
||||||
g.setColor(fgColor);
|
g.setColor(fgColor);
|
||||||
g.fill3DRect(0,0,(int)((double)(getSize().width-1)/(maxVal-minVal)*(curVal-minVal)),getSize().height-1, true);
|
int pright = (int)((double)(getSize().width-2)/(maxVal-minVal)*(curVal-minVal));
|
||||||
|
g.fill3DRect(1,1,pright,getSize().height-2, true);
|
||||||
g.setXORMode(txColor);
|
g.setXORMode(txColor);
|
||||||
|
int tleft;
|
||||||
|
switch (mode) {
|
||||||
|
default:
|
||||||
|
case MyProgBar.WINDOWS:
|
||||||
g.drawString(percString, getSize().width/2-fm.stringWidth(percString)/2, getSize().height/2-fm.getHeight()/2+fm.getAscent());
|
g.drawString(percString, getSize().width/2-fm.stringWidth(percString)/2, getSize().height/2-fm.getHeight()/2+fm.getAscent());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MyProgBar.PQ1:
|
||||||
|
tleft = pright+2;
|
||||||
|
if (tleft+fm.stringWidth(percString)>=getSize().width-1) tleft = getSize().width-1-fm.stringWidth(percString);
|
||||||
|
g.drawString(percString, tleft, getSize().height/2-fm.getHeight()/2+fm.getAscent());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MyProgBar.PQ2:
|
||||||
|
tleft = (pright-1)/2-fm.stringWidth(percString)/2+1;
|
||||||
|
if (tleft <= 2) tleft = 2;
|
||||||
|
g.drawString(percString, tleft, getSize().height/2-fm.getHeight()/2+fm.getAscent());
|
||||||
|
break;
|
||||||
|
}
|
||||||
g.setPaintMode();
|
g.setPaintMode();
|
||||||
g.setColor(Color.black);
|
g.setColor(Color.black);
|
||||||
g.drawRect(0,0,getSize().width-1,getSize().height-1);
|
g.drawRect(0,0,getSize().width-1,getSize().height-1);
|
||||||
|
|||||||
Reference in New Issue
Block a user