summaryrefslogtreecommitdiff
path: root/java/gjt/Bargauge.java
diff options
context:
space:
mode:
authorpjain <pjain@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-04-07 18:12:58 +0000
committerpjain <pjain@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-04-07 18:12:58 +0000
commit28fdfa0225c92310a6f0d60f0cf8c334380e0828 (patch)
treeba4b0a7a26bf46ea298496a434496695db55bdc1 /java/gjt/Bargauge.java
parent9c4a1450aec6c149f6491194a48f34a57ed4c39b (diff)
downloadATCD-28fdfa0225c92310a6f0d60f0cf8c334380e0828.tar.gz
Added gjt to CVS
Diffstat (limited to 'java/gjt/Bargauge.java')
-rw-r--r--java/gjt/Bargauge.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/java/gjt/Bargauge.java b/java/gjt/Bargauge.java
new file mode 100644
index 00000000000..27be8afad7b
--- /dev/null
+++ b/java/gjt/Bargauge.java
@@ -0,0 +1,80 @@
+package gjt;
+
+import java.awt.*;
+
+/**
+ * A bargauge which can be filled (wholly or partially) with a
+ * client-specified color. Fill color is specified at
+ * construction time; both fill color and fill percent may be
+ * set after construction time.<p>
+ *
+ * @version 1.0, Apr 1 1996
+ * @author David Geary
+ * @see ThreeDRectangle
+ * @see gjt.test.BargaugeTest
+ */
+public class Bargauge extends Canvas {
+ private double percentFill = 0;
+ private ThreeDRectangle border = new ThreeDRectangle(this);
+ private Color fillColor;
+
+ public Bargauge(Color fillColor) {
+ setFillColor(fillColor);
+ }
+ public void setFillColor(Color fillColor) {
+ this.fillColor = fillColor;
+ }
+ public void setFillPercent(double percentage) {
+ Assert.notFalse(percentage >= 0 && percentage <= 100);
+ percentFill = percentage;
+ }
+ public void resize(int w, int h) {
+ reshape(location().x, location().y, w, h);
+ }
+ public void reshape(int x, int y, int w, int h) {
+ super.reshape(x,y,w,h);
+ border.resize(w,h);
+ }
+ public Dimension minimumSize() { return preferredSize(); }
+
+ public Dimension preferredSize() {
+ int w = border.getThickness() * 3;
+ return new Dimension(w, w*4);
+ }
+ public void paint(Graphics g) {
+ border.raise();
+ border.paint();
+ fill();
+ }
+ public void fill() {
+ Graphics g = getGraphics();
+
+ if((g != null) && (percentFill > 0)) {
+ Rectangle b = border.getInnerBounds();
+ int fillw = b.width;
+ int fillh = b.height;
+
+ if(b.width > b.height) fillw *= percentFill/100;
+ else fillh *= percentFill/100;
+
+ g.setColor(fillColor);
+ border.clearInterior();
+
+ if(b.width > b.height)
+ g.fillRect(b.x, b.y, fillw, b.height);
+ else
+ g.fillRect(b.x, b.y + b.height - fillh,
+ b.width, fillh);
+ }
+ }
+ protected String paramString() {
+ Dimension size = size();
+ Orientation orient = size.width > size.height ?
+ Orientation.HORIZONTAL :
+ Orientation.VERTICAL;
+ String str = "fill percent=" + percentFill + "," +
+ "orientation=" + orient + "," +
+ "color" + fillColor;
+ return str;
+ }
+}