KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > j2d > LineShape


1 /**
2  * <p> Project: com.nightlabs.gui </p>
3  * <p> Copyright: Copyright (c) 2004 </p>
4  * <p> Company: NightLabs GmbH (Germany) </p>
5  * <p> Creation Date: 12.01.2005 </p>
6  * <p> Author: Daniel Mazurek </p>
7 **/

8 package com.nightlabs.editor2d.j2d;
9
10 import java.awt.Shape JavaDoc;
11 import java.awt.geom.PathIterator JavaDoc;
12 import java.awt.geom.Point2D JavaDoc;
13
14
15 public class LineShape
16 extends GeneralShape
17 {
18
19   /**
20    *
21    */

22   public LineShape() {
23     super();
24   }
25
26   /**
27    * @param rule
28    */

29   public LineShape(int rule) {
30     super(rule);
31   }
32
33   /**
34    * @param rule
35    * @param initialCapacity
36    */

37   public LineShape(int rule, int initialCapacity) {
38     super(rule, initialCapacity);
39   }
40
41   /**
42    * @param rule
43    * @param initialTypes
44    * @param initialCoords
45    */

46   public LineShape(int rule, int initialTypes, int initialCoords) {
47     super(rule, initialTypes, initialCoords);
48   }
49
50   /**
51    * @param s
52    */

53   public LineShape(Shape JavaDoc s) {
54     super(s);
55   }
56
57   /**
58    * @param windingRule
59    * @param pointTypes
60    * @param numTypes
61    * @param pointCoords
62    * @param numCoords
63    */

64   public LineShape(int windingRule, byte[] pointTypes, int numTypes,
65       float[] pointCoords, int numCoords) {
66     super(windingRule, pointTypes, numTypes, pointCoords, numCoords);
67   }
68
69   public void addPoint(int x, int y)
70   {
71     lineTo(x,y);
72   }
73   
74   public void addPoint(float x, float y)
75   {
76     lineTo(x,y);
77   }
78   
79   /**
80    * Returns the coordinates most recently added to the end of the path
81    * as a {@link Point2D} object.
82    * @return a <code>Point2D</code> object containing the ending
83    * coordinates of the path or <code>null</code> if there are no points
84    * in the path.
85    */

86   public synchronized void setLastPoint(float x, float y)
87   {
88       if (numTypes < 1 || numCoords < 2) {
89           return;
90       }
91       int index = numCoords;
92       if (pointTypes[numTypes - 1] == PathIterator.SEG_CLOSE) {
93       loop:
94           for (int i = numTypes - 2; i > 0; i--) {
95               switch (pointTypes[i]) {
96               case PathIterator.SEG_MOVETO:
97                   break loop;
98               case PathIterator.SEG_LINETO:
99                   index -= 2;
100                   break;
101               case PathIterator.SEG_QUADTO:
102                   index -= 4;
103                   break;
104               case PathIterator.SEG_CUBICTO:
105                   index -= 6;
106                   break;
107               case PathIterator.SEG_CLOSE:
108                   break;
109               }
110           }
111       }
112 // return new Point2D.Float(pointCoords[index - 2],
113
// pointCoords[index - 1]);
114
pointCoords[index - 2] = x;
115       pointCoords[index - 1] = y;
116   }
117 }
118
Popular Tags