KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > navigation > vwmodel > NavigableComponent


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.web.jsf.navigation.vwmodel;
20
21 import org.netbeans.modules.web.jsf.navigation.vwmodel.Page;
22 import java.awt.Image JavaDoc;
23 import com.sun.rave.designtime.DesignBean;
24 import java.awt.Graphics JavaDoc;
25 import java.awt.Transparency JavaDoc;
26 import java.awt.image.BufferedImage JavaDoc;
27 import java.awt.image.ColorModel JavaDoc;
28 import org.openide.util.Utilities;
29
30 /**
31  * Represents any given NavigableComponent. This used to be Page Bean.
32  * @author joelle
33  */

34 public class NavigableComponent {
35     // internal page-edge
36

37     private Image JavaDoc bufferedIcon = null;
38
39     NavigableComponent(DesignBean bean, String JavaDoc action, Page on, String JavaDoc name, Image JavaDoc icon) {
40         this.bean = bean;
41         this.setAction(action);
42         this.on = on;
43         this.setName(name);
44         this.setIcon(icon);
45     }
46     //This should not be public, but going to do this for temporary workaround.
47
private DesignBean bean;
48     private Page on;
49     private String JavaDoc name;
50     private String JavaDoc action;
51     private Image JavaDoc icon;
52     boolean error; // If true, action is set to a nonexistent case/outcome
53
boolean dynamic; // If true, action is set to a dynamic case
54

55     // Layout information - for performance reasons provided here
56
// for direct manipulation by the layout algorithms so they don't
57
// have to duplicate data structures to annotate elements with
58
// layout info and temporary tags etc.
59

60     // dimensions of bounding box for the label
61
protected int lx;
62     protected int ly;
63     protected int lw;
64     protected int lh;
65     protected int lby; // text baseline
66

67     public String JavaDoc toString() {
68         return "PageBean[" + getName() + "," + getOn() + "," + bean + "," + getIcon() + "," +
69                 lx + ", " + ly + "," + lw + "," + lh + ", " + lby +
70                 "]";
71     }
72
73     public String JavaDoc getName() {
74         return this.name;
75     }
76
77     public DesignBean getBean() {
78         return this.bean;
79     }
80
81     public void setName(String JavaDoc name) {
82         this.name = name;
83     }
84
85     public String JavaDoc getAction() {
86         return this.action;
87     }
88
89     public void setAction(String JavaDoc action) {
90         this.action = action;
91     }
92
93     public Image JavaDoc getBufferedIcon(){
94         if (bufferedIcon == null){
95             bufferedIcon = toBufferedImage(getIcon());
96             //bufferedIcon = new javax.swing.ImageIcon(icon).getImage();
97
}
98         return bufferedIcon;
99     }
100
101     /** The method creates a BufferedImage which represents the same Image as the
102      * original but buffered to avoid repeated loading of the icon while repainting.
103      */

104     private Image JavaDoc toBufferedImage(Image JavaDoc img) {
105         // load the image
106
new javax.swing.ImageIcon JavaDoc(img);
107         BufferedImage JavaDoc rep = createBufferedImage(img.getWidth(null), img.getHeight(null));
108         Graphics JavaDoc g = rep.createGraphics();
109         g.drawImage(img, 0, 0, null);
110         g.dispose();
111         img.flush();
112         return rep;
113     }
114
115     /** Creates BufferedImage with Transparency.TRANSLUCENT */
116     private BufferedImage JavaDoc createBufferedImage(int width, int height) {
117         if (Utilities.getOperatingSystem() == Utilities.OS_MAC) {
118             return new BufferedImage JavaDoc(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
119         }
120         ColorModel JavaDoc model = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().
121                 getDefaultScreenDevice().getDefaultConfiguration().getColorModel(Transparency.TRANSLUCENT);
122         BufferedImage JavaDoc buffImage = new BufferedImage JavaDoc(model,
123                 model.createCompatibleWritableRaster(width, height), model.isAlphaPremultiplied(), null);
124         return buffImage;
125     }
126
127     protected Page getOn() {
128         return on;
129     }
130
131     protected Image JavaDoc getIcon() {
132         return icon;
133     }
134
135     protected void setIcon(Image JavaDoc icon) {
136         this.icon = icon;
137     }
138 }
Popular Tags