1|package com.infocom.print;
  2|
  3|
  4|/**
  5| * Class: PFFrame <p>
  6| *
  7| * Render a rectangle on a <code>PFPage</code>. This class
  8| * will render a rectangle with the following attributes:
  9| * Line color, fill color and line tickness.<p>
 10| *
 11| * @author Jean-Pierre Dube <jpdube@videotron.ca>
 12| * @version 1.0
 13| * @since 1.0
 14| * @see PFPrintObject
 15| */
 16|
 17|import java.awt.Graphics2D;
 18|import java.awt.Color;
 19|import java.awt.geom.Rectangle2D;
 20|import java.awt.Stroke;
 21|import java.awt.BasicStroke;
 22|import java.awt.Shape;
 23|
 24|
 25|
 26|public class PFFrame extends PFPrintObject {
 27|
 28|   //--- Private instances declarations
 29|   private double tickness = 1.0;
 30|   private Color lineColor = Color.black;
 31|   private Color fillColor = null;
 32|   private Rectangle2D.Double rectangle;
 33|
 34|
 35|   /**
 36|    * Constructor: PFFrame <p>
 37|    *
 38|    * Default constructor
 39|    *
 40|    */
 41|   public PFFrame () {
 42|
 43|   }
 44|
 45|
 46|   /**
 47|    * Method: setTickness <p>
 48|    *
 49|    * Set the line tickness in pixels.
 50|    *
 51|    * @param parTickness a value of type float
 52|    */
 53|   public void setTickness (double parTickness) {
 54|
 55|      tickness = parTickness;
 56|
 57|   }
 58|
 59|
 60|   /**
 61|    * Method: getTickness <p>
 62|    *
 63|    * Get the line tickness in pixels
 64|    *
 65|    * @return a value of type float
 66|    */
 67|   public double getTickness () {
 68|
 69|      return (tickness);
 70|
 71|   }
 72|
 73|
 74|   /**
 75|    * Method: setLineColor <p>
 76|    *
 77|    * Set the line color usin the java.awt.Color object.
 78|    *
 79|    * @param parLineColor a value of type Color
 80|    */
 81|   public void setLineColor (Color parLineColor) {
 82|
 83|      lineColor = parLineColor;
 84|
 85|   }
 86|
 87|
 88|   /**
 89|    * Method: getLineColor <p>
 90|    *
 91|    * Get the line color for the rectangle
 92|    *
 93|    * @return a value of type Color
 94|    */
 95|   public Color getLineColor () {
 96|
 97|      return (lineColor);
 98|
 99|   }
100|
101|
102|   /**
103|    * Method: setFillColor <p>
104|    *
105|    * Set the fill color usin the java.awt.Color object.
106|    *
107|    * @param parFillColor a value of type Color
108|    */
109|   public void setFillColor (Color parFillColor) {
110|
111|      fillColor = parFillColor;
112|
113|   }
114|
115|
116|   /**
117|    * Method: getFillColor <p>
118|    *
119|    * Return the fill color
120|    *
121|    * @return a value of type Color
122|    */
123|   public Color getFillColor () {
124|
125|      return (fillColor);
126|
127|   }
128|
129|
130|   /**
131|    * Method: print <p>
132|    *
133|    * Render this rectangle using the line color, fill color
134|    * and line tickness specified by the user.
135|    *
136|    * @param parG a value of type Graphics2D
137|    */
138|   public void print (Graphics2D parG) {
139|
140|
141|      Color saveForeground = parG.getColor ();
142|
143|
144|      //--- Print the child objects
145|      computePositionAndSize ();
146|
147|
148|      rectangle = new Rectangle2D.Double (getDrawingOrigin ().getX ().getPoints (),
149|                                          getDrawingOrigin ().getY ().getPoints (),
150|                                          getDrawingSize ().getWidth ().getPoints (),
151|                                          getDrawingSize ().getHeight ().getPoints ());
152|
153|      //--- Draw the rectangle
154|      if (fillColor != null) {
155|         parG.setColor (fillColor);
156|         parG.fill (rectangle);
157|      }
158|
159|      //--- Set the line tickness
160|      Stroke lineStroke = new BasicStroke ((float) tickness);
161|      parG.setStroke (lineStroke);
162|      parG.setColor (lineColor);
163|      parG.draw (rectangle);
164|
165|      //--- Restore colors
166|      parG.setColor (saveForeground);
167|
168|      //--- Render child objects
169|      printChilds (parG);
170|   }
171|
172|}// PFFrame