001: /*
002: * XPrinterInfo.java
003: *
004: * Created on 08 February 2007, 15:38
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009:
010: package com.xoetrope.svg;
011:
012: import java.awt.Color;
013: import java.awt.Font;
014: import java.awt.Graphics;
015: import java.awt.Graphics2D;
016: import java.awt.geom.GeneralPath;
017: import java.awt.geom.Rectangle2D;
018: import java.awt.geom.RoundRectangle2D;
019: import java.util.ArrayList;
020: import java.util.Vector;
021: import javax.swing.JComponent;
022: import javax.swing.JTextArea;
023: import net.xoetrope.xml.XmlElement;
024:
025: /**
026: *
027: *
028: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
029: * the GNU Public License (GPL), please see license.txt for more details. If
030: * you make commercial use of this software you must purchase a commercial
031: * license from Xoetrope.</p>
032: * <p> $Revision: 1.8 $</p>
033: */
034: public class XPrinterInfo extends JComponent implements XHotSpotInfo {
035: protected ArrayList names;
036: protected ArrayList contents;
037: protected double width, height;
038: protected int fontSize, count;
039:
040: /**
041: * Creates a new instance of XPrinterInfo.
042: * @param x <CODE>double</CODE> specifying the x-cordinate of the component.
043: * @param y <CODE>double</CODE> specifying the y-cordinate of the component.
044: */
045: public XPrinterInfo() {
046: width = 160.0;
047: height = 120.0;
048: fontSize = 12;
049:
050: names = new ArrayList();
051: contents = new ArrayList();
052:
053: setOpaque(false);
054:
055: // names.add( "Status" );
056: // names.add( "Type" );
057: // names.add( "Location" );
058: //
059: // contents.add( "In-Use" );
060: // contents.add( "Laser" );
061: // contents.add( "Room 07" );
062: }
063:
064: /**
065: * Method implmented from XStatusInfo interface, used by the XInfoFileParser
066: * to pass information to classes that implement the interface.
067: * @param node <CODE>XmlElement</CODE> containing the passed xml node.
068: */
069: public void set(XmlElement node) {
070: Vector children = node.getChildren();
071: for (int i = 0; i < children.size(); i++) {
072: XmlElement childNode = (XmlElement) children.get(i);
073: names.add(childNode.getName());
074: contents.add(childNode.getContent());
075: }
076: }
077:
078: /**
079: * Returns the names ArrayList to the user.
080: * @return <CODE>ArrayList</Code> containing the names.
081: */
082: public ArrayList getNames() {
083: return names;
084: }
085:
086: /**
087: * Returns the values ArrayList to the user.
088: * @return <CODE>ArrayList</Code> containing the values.
089: */
090: public ArrayList getContents() {
091: return contents;
092: }
093:
094: /**
095: * Sets the font size to be used by this component
096: * @param fontSize <CODE>int</CODE> specifying the font size.
097: */
098: public void setFontSize(int fontSize) {
099: this .fontSize = fontSize;
100: }
101:
102: /**
103: * Paints the component within its parent component.
104: * @param g the delegate <CODE>Graphics</Code> object.
105: */
106: public void paintComponent(Graphics g) {
107: width = (double) getWidth() - 2;
108: height = (double) getHeight() - 2;
109:
110: Graphics2D g2d = (Graphics2D) g.create();
111:
112: RoundRectangle2D.Double mainRect = new RoundRectangle2D.Double(
113: 0, 0, width, height, (width * 0.09375),
114: (height * 0.125));
115: g2d.setColor(Color.white);
116: g2d.fill(mainRect);
117:
118: RoundRectangle2D.Double topRect = new RoundRectangle2D.Double(
119: 0, 0, width, (height * 0.166666), (width * 0.09375),
120: (height * 0.125));
121: Rectangle2D.Double gapRect = new Rectangle2D.Double(0,
122: height * 0.08, width, (height * 0.083333));
123:
124: g2d.setColor(Color.blue);
125: g2d.draw(mainRect);
126: g2d.fill(topRect);
127: g2d.fill(gapRect);
128:
129: g2d.setColor(Color.white);
130: g2d.setFont(new Font("Arial", Font.BOLD, fontSize));
131: g2d.drawString("Printer Info", (float) (width * 0.05),
132: (float) (height * 0.12));
133:
134: String text = "\n" + names.get(0).toString() + ": \t"
135: + contents.get(0).toString();
136: for (int i = 1; i < names.size(); i++) {
137: text = text + "\n" + names.get(i).toString() + ": \t"
138: + contents.get(i).toString();
139: }
140:
141: JTextArea textArea = new JTextArea(text,
142: (int) (width * 0.6875), (int) (height * 0.833333));
143: textArea.setBounds((int) (width * 0.05),
144: (int) (height * 0.175), (int) (width * 0.9375),
145: (int) (height * 0.666666));
146: textArea.setFont(new Font("Arial", Font.PLAIN, fontSize));
147: textArea.setWrapStyleWord(true);
148: textArea.setEditable(false);
149: textArea.setForeground(Color.blue);
150: add(textArea);
151:
152: g2d.dispose();
153: }
154: }
|