Source code: com/xerox/VTM/glyphs/VRoundRectST.java
1 /* FILE: VRoundRectST.java
2 * DATE OF CREATION: Wed May 28 16:07:24 2003
3 * AUTHOR : Emmanuel Pietriga (emmanuel@w3.org)
4 * MODIF: Thu Jul 10 16:58:45 2003 by Emmanuel Pietriga (emmanuel@w3.org, emmanuel@claribole.net)
5 * Copyright (c) Emmanuel Pietriga, 2002. All Rights Reserved
6 * Licensed under the GNU LGPL. For full terms see the file COPYING.
7 */
8
9 package com.xerox.VTM.glyphs;
10
11 import java.awt.Color;
12 import java.awt.Graphics2D;
13 import java.awt.Font;
14 import java.awt.Stroke;
15 import java.awt.AlphaComposite;
16 import java.awt.geom.AffineTransform;
17 import java.lang.Math;
18 import com.xerox.VTM.engine.*;
19
20 /**
21 * Round Rectangle - cannot be reoriented - the corners are approximated to a plain rectangle for some operations like computing mouse enter/exit events (performance reasons) - transparency
22 * @author Emmanuel Pietriga
23 **/
24
25
26 public class VRoundRectST extends VRoundRect implements Transparent,Cloneable {
27
28 /**semi transparency (default is 0.5)*/
29 AlphaComposite acST;
30 /**alpha channel*/
31 float alpha=0.5f;
32
33 public VRoundRectST(){
34 super();
35 acST=AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha); //transparency set to 0.5
36 }
37
38 /**
39 *@param x coordinate in virtual space
40 *@param y coordinate in virtual space
41 *@param z altitude
42 *@param w half width in virtual space
43 *@param h half height in virtual space
44 *@param c fill color
45 *@param w arc width in virtual space
46 *@param h arc height in virtual space
47 */
48 public VRoundRectST(long x,long y,float z,long w,long h,Color c,int aw,int ah){
49 super(x,y,z,w,h,c,aw,ah);
50 acST=AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha); //transparency set to 0.5
51 }
52
53 /**
54 *set alpha channel value (transparency)
55 *@param a [0;1.0] 0 is fully transparent, 1 is opaque
56 */
57 public void setTransparencyValue(float a){
58 alpha=a;
59 acST=AlphaComposite.getInstance(AlphaComposite.SRC_OVER,alpha); //transparency set to alpha
60 try{vsm.repaintNow();}catch(NullPointerException e){/*System.err.println("VSM null in Glyph "+e);*/}
61 }
62
63 /**get alpha value (transparency) for this glyph*/
64 public float getTransparencyValue(){return alpha;}
65
66 /**used to find out if glyph completely fills the view (in which case it is not necessary to repaint objects at a lower altitude)*/
67 public boolean fillsView(long w,long h,int camIndex){
68 if ((alpha==1.0) && (w<=pc[camIndex].cx+pc[camIndex].cw) && (0>=pc[camIndex].cx-pc[camIndex].cw) && (h<=pc[camIndex].cy+pc[camIndex].ch) && (0>=pc[camIndex].cy-pc[camIndex].ch)){return true;}
69 else {return false;}
70 }
71
72 /**draw glyph
73 *@param i camera index in the virtual space
74 */
75 public void draw(Graphics2D g,int vW,int vH,int i,Stroke stdS,AffineTransform stdT){
76 if ((pc[i].cw>1) && (pc[i].ch>1)) {//repaint only if object is visible
77 if (filled) {
78 g.setColor(this.color);
79 g.setComposite(acST);
80 g.fillRoundRect(pc[i].cx-pc[i].cw,pc[i].cy-pc[i].ch,2*pc[i].cw,2*pc[i].ch,pc[i].aw,pc[i].ah);
81 g.setComposite(acO);
82 }
83 g.setColor(borderColor);
84 if (paintBorder){
85 if (stroke!=null) {
86 if (((pc[i].cx-pc[i].cw)>0) || ((pc[i].cy-pc[i].ch)>0) || ((2*pc[i].cw-1)<vW) || ((2*pc[i].ch-1)<vH)){
87 g.setStroke(stroke); //change stroke there
88 g.drawRoundRect(pc[i].cx-pc[i].cw,pc[i].cy-pc[i].ch,2*pc[i].cw-1,2*pc[i].ch-1,pc[i].aw,pc[i].ah);
89 g.setStroke(stdS); //original stroke restored here
90 }
91 }
92 else {
93 g.drawRoundRect(pc[i].cx-pc[i].cw,pc[i].cy-pc[i].ch,2*pc[i].cw-1,2*pc[i].ch-1,pc[i].aw,pc[i].ah);
94 }
95 }
96 this.textDraw(g,i);
97 }
98 else if ((pc[i].cw<=1) ^ (pc[i].ch<=1)) {//repaint only if object is visible (^ means xor)
99 g.setColor(this.color);
100 if (pc[i].cw<=1){
101 g.fillRect(pc[i].cx,pc[i].cy-pc[i].ch,1,2*pc[i].ch);
102 }
103 else if (pc[i].ch<=1){
104 g.fillRect(pc[i].cx-pc[i].cw,pc[i].cy,2*pc[i].cw,1);
105 }
106 }
107 else g.fillRect(pc[i].cx,pc[i].cy,1,1);
108 }
109
110 /**returns a clone of this object (only basic information is cloned for now: shape, orientation, position, size)*/
111 public Object clone(){
112 VRoundRectST res=new VRoundRectST(vx,vy,0,vw,vh,color,arcWidth,arcHeight);
113 res.borderColor=this.borderColor;
114 res.selectedColor=this.selectedColor;
115 res.mouseInsideColor=this.mouseInsideColor;
116 res.bColor=this.bColor;
117 res.setTransparencyValue(alpha);
118 return res;
119 }
120
121 }