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

Quick Search    Search Deep

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


1   /*   FILE: VShapeST.java
2    *   DATE OF CREATION:   Aug 01 2001
3    *   AUTHOR :            Emmanuel Pietriga (emmanuel.pietriga@xrce.xerox.com)
4    *   MODIF:              Thu Jul 10 17:04:57 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.AlphaComposite;
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  /**
33   * Custom shape - defined by its N vertices (every vertex is between 0 (distance from shape's center=0) and 1.0 (distance from shape's center equals bounding circle radius)) - angle between each vertices is 2*Pi/N - can be reoriented - transparency
34   * @author Emmanuel Pietriga
35   **/
36  
37  public class VShapeST extends VShape implements Transparent,Cloneable {
38  
39      /**semi transparency (default is 0.5)*/
40      AlphaComposite acST;
41      /**alpha channel*/
42      float alpha=0.5f;
43  
44      /**
45       *@param v list of vertex distance to the shape's center in the 0-1.0 range (relative to bounding circle)
46       */
47      public VShapeST(float[] v){
48    super(v);
49    acST=AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha);  //transparency set to 0.5
50      }
51  
52      /**
53       *@param x coordinate in virtual space
54       *@param y coordinate in virtual space
55       *@param z altitude
56       *@param s size (width=height) in virtual space
57       *@param v list of vertex distance to the shape's center in the 0-1.0 range (relative to bounding circle) --vertices are layed out counter clockwise, with the first vertex placed at the same Y coord as the shape's center (provided orient=0)
58       *@param c fill color
59       */
60      public VShapeST(long x,long y,float z,long s,float[] v,Color c,float or){
61    super(x,y,z,s,v,c,or);
62    acST=AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha);  //transparency set to 0.5
63      }
64  
65      /**
66       *set alpha channel value (transparency)
67       *@param a [0;1.0] 0 is fully transparent, 1 is opaque
68       */
69      public void setTransparencyValue(float a){
70    alpha=a;
71    acST=AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha);  //transparency set to alpha
72    try{vsm.repaintNow();}catch(NullPointerException e){/*System.err.println("VSM null in Glyph "+e);*/}
73      }
74  
75      /**get alpha value (transparency) for this glyph*/
76      public float getTransparencyValue(){return alpha;}
77  
78      /**used to find out if glyph completely fills the view (in which case it is not necessary to repaint objects at a lower altitude)*/
79      public boolean fillsView(long w,long h,int camIndex){
80    if ((alpha==1.0) && (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;}
81    else {return false;}
82      }
83  
84      /**draw glyph 
85       *@param i camera index in the virtual space
86       */
87      public void draw(Graphics2D g,int vW,int vH,int i,Stroke stdS,AffineTransform stdT){
88    if (pc[i].cs>1){//repaint only if object is visible
89        if (filled){
90      g.setColor(this.color);  
91      g.setComposite(acST);
92      g.fillPolygon(pc[i].p);
93      g.setComposite(acO);
94        }
95        g.setColor(borderColor);
96        if (paintBorder){
97      if (stroke!=null) {
98          g.setStroke(stroke);
99          g.drawPolygon(pc[i].p);
100         g.setStroke(stdS);
101     }
102     else {
103         g.drawPolygon(pc[i].p);
104     }
105       }
106       this.textDraw(g,i);
107   }
108   else g.fillRect(pc[i].cx,pc[i].cy,1,1);
109     }
110 
111     /**returns a clone of this object (only basic information is cloned for now: shape, orientation, position, size)*/
112     public Object clone(){
113   VShapeST res=new VShapeST(vx,vy,0,vs,(float[])vertices.clone(),color,orient);
114   res.borderColor=this.borderColor;
115   res.selectedColor=this.selectedColor;
116   res.mouseInsideColor=this.mouseInsideColor;
117   res.bColor=this.bColor;
118   res.setTransparencyValue(alpha);
119   return res;
120     }
121 
122 }