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