KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > upgrade > gui > ImagePanel


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.tools.upgrade.gui;
25
26 import java.awt.*;
27 import java.awt.image.ImageObserver JavaDoc;
28
29 // Referenced classes of package com.sun.wizards.awt:
30
// InsetsPanel
31

32 public class ImagePanel extends InsetsPanel
33 {
34
35     public static final int LEFT = 1;
36     public static final int CENTER = 2;
37     public static final int RIGHT = 3;
38     public static final int TOP = 1;
39     public static final int BOTTOM = 3;
40     protected Image image;
41     protected int hAlign;
42     protected int vAlign;
43     protected boolean loaded;
44
45     public ImagePanel()
46     {
47         image = null;
48         hAlign = 2;
49         vAlign = 2;
50         loaded = false;
51     }
52
53     public ImagePanel(int i, int j)
54     {
55         image = null;
56         hAlign = 2;
57         vAlign = 2;
58         loaded = false;
59         hAlign = i;
60         vAlign = j;
61     }
62
63     public ImagePanel(Insets insets)
64     {
65         //super(insets);
66
image = null;
67         hAlign = 2;
68         vAlign = 2;
69         loaded = false;
70     }
71
72     public ImagePanel(LayoutManager layoutmanager)
73     {
74         super(layoutmanager);
75         image = null;
76         hAlign = 2;
77         vAlign = 2;
78         loaded = false;
79     }
80
81     public Dimension getMinimumSize()
82     {
83         return getPreferredSize();
84     }
85
86     public Dimension getPreferredSize()
87     {
88         Dimension dimension = new Dimension(0, 0);
89         if(image != null)
90         {
91             dimension.width = image.getWidth(this);
92             dimension.height = image.getHeight(this);
93         }
94         return dimension;
95     }
96
97     public synchronized boolean imageUpdate(Image image1, int i, int j, int k, int l, int i1)
98     {
99         if((i & 0x20) != 0)
100         {
101             loaded = true;
102             repaint();
103             return false;
104         } else
105         {
106             return true;
107         }
108     }
109
110     public void paint(Graphics g)
111     {
112         super.paint(g);
113         if(loaded)
114         {
115             int i = 0;
116             int j = 0;
117             int k = image.getWidth(this);
118             int l = image.getHeight(this);
119             Dimension dimension = getSize();
120             g.setClip(0, 0, dimension.width, dimension.height);
121             switch(hAlign)
122             {
123             case 1: // '\001'
124
i = super.insets.left;
125                 break;
126
127             case 2: // '\002'
128
i = (dimension.width - (super.insets.left + super.insets.right) - k) / 2 + super.insets.left;
129                 break;
130
131             case 3: // '\003'
132
i = dimension.width - k - super.insets.right;
133                 break;
134             }
135             switch(vAlign)
136             {
137             case 1: // '\001'
138
j = super.insets.top;
139                 break;
140
141             case 2: // '\002'
142
j = (dimension.height - (super.insets.top + super.insets.bottom) - l) / 2 + super.insets.top;
143                 break;
144
145             case 3: // '\003'
146
j = dimension.height - l - super.insets.bottom;
147                 break;
148             }
149             g.drawImage(image, i, j, this);
150         }
151     }
152
153     public void setAlignment(int i, int j)
154     {
155         hAlign = i;
156         vAlign = j;
157     }
158
159     public void setImage(Image image1)
160     {
161         loaded = false;
162         image = image1;
163         prepareImage(image1, this);
164     }
165 }
166
Popular Tags