001: package com.xoetrope.awt;
002:
003: import java.awt.Component;
004: import java.awt.Dimension;
005: import java.awt.Graphics;
006:
007: import net.xoetrope.xui.XAttributedComponent;
008:
009: /**
010: * Draws a simple shape
011: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
012: * the GNU Public License (GPL), please see license.txt for more details. If
013: * you make commercial use of this software you must purchase a commercial
014: * license from Xoetrope.</p>
015: * <p>$Revision: 1.4 $</p>
016: */
017: public class XShape extends Component implements XAttributedComponent {
018: protected int mode = 0;
019:
020: public static final int RECTANGLE = 0;
021: public static final int ORTHO_LINE = 1;
022: public static final int EXTRABOLD_HORIZONTAL = 2;
023: public static final int BOLD_HORIZONTAL = 3;
024: public static final int NORMAL_HORIZONTAL = 4;
025: public static final int THIN_HORIZONTAL = 5;
026: public static final int EXTRABOLD_VERTICAL = 6;
027: public static final int BOLD_VERTICAL = 7;
028: public static final int NORMAL_VERTICAL = 8;
029: public static final int THIN_VERTICAL = 9;
030: public static final int RIGHT_TOP_LINE = 10;
031: public static final int LEFT_TOP_LINE = 11;
032: public static final int ELLIPSE = 12;
033: public static final int SOLID_ELLIPSE = 13;
034: public static final int SOLID_DIAMOND = 14;
035: public static final int DIAMOND = 15;
036:
037: /**
038: * Constructor for a new XShape
039: */
040: public XShape() {
041: }
042:
043: /**
044: * Fills the shape with the background color
045: * @param g the graphics context
046: */
047: public void paint(Graphics g) {
048: Dimension d = getSize();
049:
050: g.setColor(getForeground());
051:
052: switch (mode) {
053: case RECTANGLE:
054: g.fillRect(0, 0, d.width, d.height);
055: break;
056: case ORTHO_LINE:
057: g.fillRect(0, 0, getSize().width, getSize().height);
058: break;
059:
060: case EXTRABOLD_HORIZONTAL:
061: g.drawLine(0, 0 + 3, d.width, 3);
062: case BOLD_HORIZONTAL:
063: g.drawLine(0, 0 + 2, d.width, 2);
064: case NORMAL_HORIZONTAL:
065: g.drawLine(0, 0 + 1, d.width, 1);
066: case THIN_HORIZONTAL:
067: g.drawLine(0, 0, d.width, 0);
068: break;
069:
070: case EXTRABOLD_VERTICAL:
071: g.drawLine(3, 0, 3, d.height);
072: case BOLD_VERTICAL:
073: g.drawLine(2, 0, 2, d.height);
074: case NORMAL_VERTICAL:
075: g.drawLine(1, 0, 1, d.height);
076: case THIN_VERTICAL:
077: g.drawLine(0, 0, 0, d.height);
078: break;
079:
080: case RIGHT_TOP_LINE:
081: g.drawLine(d.width, 0, 0, d.height);
082: break;
083: case LEFT_TOP_LINE:
084: g.drawLine(0, 0, d.width, d.height);
085: break;
086:
087: case ELLIPSE:
088: g.drawOval(0, 0, d.width, d.height);
089: break;
090: case SOLID_ELLIPSE:
091: g.fillOval(0, 0, d.width, d.height);
092: break;
093:
094: case SOLID_DIAMOND:
095: case DIAMOND: {
096: int[] xpts = new int[4];
097: int[] ypts = new int[4];
098: xpts[0] = 0 + d.width / 2;
099: xpts[1] = 0 + d.width;
100: xpts[2] = 0 + d.width / 2;
101: xpts[3] = 0;
102: ypts[0] = 0;
103: ypts[1] = 0 + d.height / 2;
104: ypts[2] = 0 + d.height;
105: ypts[3] = 0 + d.height / 2;
106: if (mode == SOLID_DIAMOND)
107: g.fillPolygon(xpts, ypts, 4);
108: else
109: g.drawPolygon(xpts, ypts, 4);
110: }
111: break;
112: }
113: }
114:
115: /**
116: * Get shape identifier. The ID is an enumerated constant
117: * @param shapeId the new shape ID.
118: */
119: public void setShape(int shapeId) {
120: mode = shapeId;
121: repaint();
122: }
123:
124: /**
125: * Get shape identifier.
126: * @return the enumerated constant for this shape
127: */
128: public int getShape() {
129: return mode;
130: }
131:
132: /**
133: * Set one or more attributes of the component. Currently this handles the
134: * attributes
135: * <OL>
136: * <LI>cue, value=Cue image filename</LI>
137: * <LI>bars, value=number of bars</LI>
138: * <LI>progress, value=the current progress value</LI>
139: * <LI>max, value=the maximum progress value</LI>
140: * </OL>
141: * @param attribName the attribute name
142: * @param attribValue the attribute value
143: * @return 0 for success, non zero otherwise
144: */
145: public int setAttribute(String attribName, Object attribValue) {
146: if (attribName.equalsIgnoreCase("mode"))
147: mode = new Integer((String) attribValue).intValue();
148:
149: repaint(100);
150: return 0;
151: }
152: }
|