Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/xerox/VTM/glyphs/VDiamondOr.java


1   /*   FILE: VDiamondOr.java
2    *   DATE OF CREATION:   Jul 27 2000
3    *   AUTHOR :            Emmanuel Pietriga (emmanuel.pietriga@xrce.xerox.com)
4    *   MODIF:              Thu Jul 10 16:30:28 2003 by Emmanuel Pietriga (emmanuel@w3.org, emmanuel@claribole.net)
5    *   Copyright (c) Xerox Corporation, XRCE/Contextual Computing, 2002. All Rights Reserved
6    *
7    * This library is free software; you can redistribute it and/or
8    * modify it under the terms of the GNU Lesser General Public
9    * License as published by the Free Software Foundation; either
10   * version 2.1 of the License, or (at your option) any later version.
11   * 
12   * This library is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   * Lesser General Public License for more details.
16   *
17   * For full terms see the file COPYING.
18   */
19  
20  package com.xerox.VTM.glyphs;
21  
22  import java.awt.Color;
23  import java.awt.Graphics2D;
24  import java.awt.Polygon;
25  import java.awt.Font;
26  import java.awt.Stroke;
27  import java.awt.geom.AffineTransform;
28  import java.lang.Math;
29  import com.xerox.VTM.engine.*;
30  
31  /**
32   * Diamond (losange with height equal to width) - can be reoriented
33   * @author Emmanuel Pietriga
34   **/
35  
36  public class VDiamondOr extends VDiamond implements Cloneable {
37   
38      /**vertex x coords*/
39      int[] xcoords=new int[4];
40      /**vertex y coords*/
41      int[] ycoords=new int[4];
42  
43      public VDiamondOr(){super();}
44  
45      /**
46       *@param x coordinate in virtual space
47       *@param y coordinate in virtual space
48       *@param z altitude
49       *@param s size (width=height) in virtual space
50       *@param c fill color
51       *@param or orientation
52       */
53      public VDiamondOr(long x,long y,float z,long s,Color c,float or){
54    super(x,y,z,s,c);
55    orient=or;
56    //if (orient!=0){computeOrientCoords();}
57      }
58  
59      /**get orientation*/
60      public float getOrient(){return orient;}
61  
62      /**set orientation (absolute)*/
63      public void orientTo(float angle){
64    orient=angle;
65    try{vsm.repaintNow();}catch(NullPointerException e){/*System.err.println("VSM null in Glyph "+e);*/}
66  //   vsm.constMgr.suggestAValue(this.ID,"or",orient);
67    //computeOrientCoords();
68      }
69  
70      /**set orientation (absolute)*/
71  //     public void orientToNS(float angle){
72  //   orient=angle;
73  //   //computeOrientCoords();
74  //     }
75  
76      /**used to find out if glyph completely fills the view (in which case it is not necessary to repaint objects at a lower altitude)*/
77      public boolean fillsView(long w,long h,int camIndex){
78    if ((pc[camIndex].p.contains(0,0)) && (pc[camIndex].p.contains(w,0)) && (pc[camIndex].p.contains(0,h)) && (pc[camIndex].p.contains(w,h))){return true;}
79    else {return false;}
80      }
81  
82      void computeOrientCoords(int i){
83    xcoords[0]=(int)Math.round(pc[i].cx+pc[i].cs*Math.cos(orient));
84    xcoords[1]=(int)Math.round(pc[i].cx-pc[i].cs*Math.sin(orient));
85    xcoords[2]=(int)Math.round(pc[i].cx-pc[i].cs*Math.cos(orient));
86    xcoords[3]=(int)Math.round(pc[i].cx+pc[i].cs*Math.sin(orient));
87    ycoords[0]=(int)Math.round(pc[i].cy-pc[i].cs*Math.sin(orient));
88    ycoords[1]=(int)Math.round(pc[i].cy-pc[i].cs*Math.cos(orient));
89    ycoords[2]=(int)Math.round(pc[i].cy+pc[i].cs*Math.sin(orient));
90    ycoords[3]=(int)Math.round(pc[i].cy+pc[i].cs*Math.cos(orient));
91      }
92  
93      /**project shape in camera coord sys prior to actual painting*/
94      public void project(Camera c,ViewPanel v){
95    int i=c.getIndex();
96    coef=(float)(c.focal/(c.focal+c.altitude));
97    //find coordinates of object's geom center wrt to camera center and project
98    pc[i].cx=Math.round((vx-c.posx)*coef);
99    pc[i].cy=Math.round((vy-c.posy)*coef);
100   //translate in JPanel coords
101   pc[i].cx=(v.getSize().width/2)+pc[i].cx;
102   pc[i].cy=(v.getSize().height/2)-pc[i].cy;
103   //project height and construct polygon
104   pc[i].cs=Math.round(vs*coef);
105   computeOrientCoords(i);
106   pc[i].p=new Polygon(xcoords,ycoords,4);
107     }
108 
109     /**draw glyph 
110      *@param i camera index in the virtual space
111      */
112     public void draw(Graphics2D g,int vW,int vH,int i,Stroke stdS,AffineTransform stdT){
113   if (pc[i].cs>1){//repaint only if object is visible
114       if (filled) {
115     g.setColor(this.color);
116     g.fillPolygon(pc[i].p);
117       }  
118       g.setColor(borderColor);
119       if (paintBorder){
120     if (stroke!=null) {
121         g.setStroke(stroke);
122         g.drawPolygon(pc[i].p);
123         g.setStroke(stdS);
124     }
125     else {
126         g.drawPolygon(pc[i].p);
127     }
128       }
129       this.textDraw(g,i);
130   }
131   else g.fillRect(pc[i].cx,pc[i].cy,1,1);
132     }
133 
134     /**returns a clone of this object (only basic information is cloned for now: shape, orientation, position, size)*/
135     public Object clone(){
136   VDiamondOr res=new VDiamondOr(vx,vy,0,vs,color,orient);
137   res.borderColor=this.borderColor;
138   res.selectedColor=this.selectedColor;
139   res.mouseInsideColor=this.mouseInsideColor;
140   res.bColor=this.bColor;
141   return res;
142     }
143 }