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

Quick Search    Search Deep

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


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