KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > yagga > miniinstaller > gui > WritePanel


1 /*
2  * This file is part of MiniInstaller, a self installer builder for Java
3  * Copyright (C) 2002 Walter Gamba
4  * mailto:walter@yagga.net
5  * http://www.yagga.net/java/miniinstaller
6  *
7  * MiniInstaller is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * MiniInstaller 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
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  * As the time of writing, the GNU General Public Licene can be
22  * found at http://www.gnu.org/licenses/gpl.txt
23  *
24  */

25
26 package net.yagga.miniinstaller.gui;
27
28 import net.yagga.util.*;
29 import java.awt.*;
30 import javax.swing.*;
31
32 /**
33  * Class that displays short text and/or images.
34  * There can be three parameters:
35  * <OL>
36  * <LI>title/caption
37  * <LI>text
38  * <LI>image
39  * </OL>
40  * It can display:<BR>
41  * - only title, centered<BR>
42  * - only image, centered<BR>
43  * - images AND title, as splash panel: text NOrTH and img CENTER<BR>
44  * - images AND title, as alert: text CENTER and IMG WEST<BR>
45  * - title AND text, title NORTH and text CENTERED<BR>
46  * - title, text image: title NORTH, text CENTERED and image WEST<BR>
47  * @author Walter Gamba
48  */

49 public class WritePanel extends JPanel implements InstallPanel{
50   BorderLayout borderLayout1 = new BorderLayout();
51   JTextArea taMsg=new JTextArea();
52   JLabel lbImg = new JLabel();
53   JLabel lbTitle = new JLabel();
54
55   public static final int ICON_ALERT=1;
56
57   String JavaDoc title=null;
58   String JavaDoc text=null;
59   Icon img=null;
60   //when there is an image, and is to be centered..
61
boolean splashPanel=false;
62
63   /**
64    * @param msg can be null
65      * @alertIcon extend this method to display various icons
66    */

67   public WritePanel(String JavaDoc msg, int alertIcon) {
68     this.text=msg;
69       title="";
70     switch(alertIcon){
71       case ICON_ALERT:
72                 title="ALERT!";
73         img=ResourceMgr.retrieveImageIcon("img/alert.gif");
74         break;
75     }
76     try {
77       jbInit();
78     }
79     catch (Exception JavaDoc ex) {
80       ex.printStackTrace();
81     }
82   }
83   /**
84    * @param msg can be null
85    * @param imgFile can be null
86    */

87   public WritePanel(String JavaDoc msg, String JavaDoc imgFile) {
88     splashPanel=true;
89     this.title=msg;
90     if(imgFile!=null)
91         img=ResourceMgr.retrieveImageIcon(imgFile);
92     try {
93       jbInit();
94     }
95     catch (Exception JavaDoc ex) {
96       ex.printStackTrace();
97     }
98   }
99
100   /**
101    * @param msg can be null
102    * @param text can be null
103    * @param imgFile can be null
104    */

105   public WritePanel(String JavaDoc title, String JavaDoc text, String JavaDoc imgFile) {
106     splashPanel=true;
107     this.title=title;
108     this.text=text;
109       if(imgFile!=null)
110         img=ResourceMgr.retrieveImageIcon(imgFile);
111     try {
112       jbInit();
113     }
114     catch (Exception JavaDoc ex) {
115       ex.printStackTrace();
116     }
117   }
118
119   void jbInit() throws Exception JavaDoc {
120         if(text!=null && text.trim().equals("") )
121             text=null;
122
123         this.setPreferredSize(InstallFrame.panelDim);
124         borderLayout1.preferredLayoutSize(this);
125     this.setLayout(borderLayout1);
126       //if only one element..
127
if(img!=null && title==null && text==null){
128         lbImg.setIcon(img);
129       lbImg.setBackground(SystemColor.control);
130       this.add(lbImg, BorderLayout.CENTER);
131       //return;
132
}
133       else if(img==null && title!=null && text==null){
134         taMsg.setText(title);
135       taMsg.setEditable(false);
136       taMsg.setOpaque(false);
137       taMsg.setWrapStyleWord(true);
138       taMsg.setLineWrap(true);
139             taMsg.setFont(GuiProperties.textFont);
140       this.add(taMsg, BorderLayout.CENTER);
141       //return;
142
}
143       else if(text==null && img!=null && title!=null){
144         lbImg.setIcon(img);
145       lbImg.setBackground(InstallFrame.BK_COL);
146         lbImg.setHorizontalAlignment(SwingConstants.CENTER);
147         lbTitle.setText(title);
148             lbTitle.setHorizontalAlignment(SwingConstants.LEFT);
149             lbTitle.setAlignmentY(0.0f);
150         lbTitle.setFont(GuiProperties.smallTitleFont);
151         if(splashPanel){
152         //lbTitle.setFont(new Font("TimesRoman", 3, 20));
153
this.add(lbImg, BorderLayout.CENTER);
154                 if(!title.trim().equals(""))
155                     this.add(lbTitle, BorderLayout.NORTH);
156         }
157             else{
158                 this.add(lbImg, BorderLayout.WEST);
159                 if(!title.trim().equals(""))
160                     this.add(lbTitle, BorderLayout.CENTER);
161         }
162       }
163       else{
164         if(img!=null){
165           lbImg.setIcon(img);
166         lbImg.setBackground(SystemColor.control);
167                 this.add(lbImg, BorderLayout.WEST);
168         }
169         taMsg.setText(text);
170       taMsg.setEditable(false);
171       taMsg.setOpaque(false);
172       taMsg.setWrapStyleWord(true);
173       taMsg.setLineWrap(true);
174
175         lbTitle.setText(title);
176             taMsg.setFont(GuiProperties.textFont);
177             lbTitle.setFont(GuiProperties.smallTitleFont);
178             lbTitle.setHorizontalAlignment(SwingConstants.LEFT);
179             lbTitle.setAlignmentY(0.0f);
180             this.add(lbTitle, BorderLayout.NORTH);
181             this.add(taMsg, BorderLayout.CENTER);
182       }
183
184       lbTitle.setFont(GuiProperties.smallTitleFont);
185       if(splashPanel){
186       //taMsg.setj.setHorizontalAlignment(SwingConstants.CENTER);
187
lbTitle.setHorizontalAlignment(SwingConstants.CENTER);
188       }
189     refresh();
190   }
191
192   public void refresh(){
193     this.setBackground(InstallFrame.BK_COL);
194     taMsg.setForeground(InstallFrame.FG_COL);
195     this.lbTitle.setForeground(InstallFrame.TIT_COL);
196         this.taMsg.setForeground(InstallFrame.FG_COL);
197         setMinimumSize(InstallFrame.panelDim);
198         setPreferredSize(InstallFrame.panelDim);
199         setMaximumSize(InstallFrame.panelDim);
200     this.validate();
201   }
202
203 }
Popular Tags