View Javadoc
1   /*
2    * JarInspector - Copyright (C) 2004 Che Inc., Rosario Argentina
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Library General Public
6    * License as published by the Free Software Foundation; either
7    * version 2 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12   * Library General Public License for more details.
13   *
14   * You should have received a copy of the GNU Library General Public
15   * License along with this library; if not, write to the Free
16   * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17   */
18  
19  package inc.che.common.gui;
20  
21  // Imports
22  import inc.che.common.config.Config;
23  
24  import java.awt.BorderLayout;
25  import java.awt.Color;
26  import java.awt.Dimension;
27  import java.awt.Font;
28  import java.awt.GridLayout;
29  
30  import javax.swing.BorderFactory;
31  import javax.swing.ImageIcon;
32  import javax.swing.JLabel;
33  import javax.swing.JPanel;
34  import javax.swing.JProgressBar;
35  import javax.swing.JWindow;
36  import javax.swing.border.EtchedBorder;
37  
38  import org.apache.log4j.Logger;
39  /***
40   *  <b>Startfenster der Anwendung</b>
41   * @version $Id: StartWindow.java,v 1.1 2005/03/06 12:56:51 stevemcmee Exp $
42   * @author <address> Steve McMee &lt;stevemcmee@users.sourceforge.net&gt;</address>
43   */
44  
45  public class StartWindow extends JWindow {
46  
47      /*** CVS ID of this file */
48      public static final String CVS_ID =
49          "$Id: StartWindow.java,v 1.1 2005/03/06 12:56:51 stevemcmee Exp $";
50  
51      /***
52       * logger instance for this class
53       */
54  
55      private static Logger log = Logger.getLogger(StartWindow.class);
56  
57      /***
58       * configuration instance for this class
59       */
60      private static Config config = Config.getInstance();
61  
62      private JProgressBar pbar;
63      private JLabel info = new JLabel();
64  
65      /***
66       * Konstruktor
67       * @param pultname Name des Pultes
68       */
69      public StartWindow(String header, ImageIcon icon, Config config) {
70          JLabel version = new JLabel(header);
71  
72          JLabel label = new JLabel(icon);
73          JPanel panel = new JPanel(new GridLayout(2, 1));
74          JPanel outerPanel = new JPanel(new BorderLayout(10, 10));
75          outerPanel.setBorder(
76              BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
77  
78          Color textColor = Color.BLACK;
79          Color pbColor = Color.GRAY;
80          Color bgColor = Color.WHITE;
81  
82          textColor =
83              config.getColorParameter("startwindow.text.color", Color.BLACK);
84          pbColor =
85              config.getColorParameter("startwindow.progress.color", Color.GRAY);
86          bgColor =
87              config.getColorParameter(
88                  "startwindow.background.color",
89                  Color.WHITE);
90  
91          panel.setBackground(bgColor);
92          //info.setBorder(BorderFactory.createLineBorder(textColor));
93          info.setBackground(bgColor);
94          info.setForeground(textColor);
95          info.setFont(
96              new Font(
97                  config.getParameter("startwindow.font.face"),
98                  Font.BOLD,
99                  config.getIntParameter("startwindow.font.size", 14)));
100         panel.add(info);
101         if (config
102             .getBooleanParameter("startwindow.progressbar.available", true)) {
103             pbar = new JProgressBar(0, 100);
104             pbar.setBackground(bgColor);
105             pbar.setForeground(pbColor);
106             pbar.setIndeterminate(false);
107             pbar.setPreferredSize(
108                 new Dimension(
109                     config.getIntParameter("startwindow.width", 538),
110                     config.getIntParameter("progressbar.height", 15)));
111             pbar.setBorderPainted(true);
112             pbar.setStringPainted(true);
113             panel.add(pbar);
114         }
115 
116         outerPanel.setLayout(new BorderLayout());
117         outerPanel.setBackground(bgColor);
118         version.setBackground(pbColor);
119         version.setForeground(textColor);
120         version.setFont(
121             new Font(
122                 config.getParameter("startwindow.font.face"),
123                 Font.BOLD,
124                 config.getIntParameter("startwindow.font.size", 14)));
125         outerPanel.add(version, BorderLayout.NORTH);
126         outerPanel.add(label, BorderLayout.CENTER);
127         outerPanel.add(panel, BorderLayout.SOUTH);
128 
129         this.getContentPane().add(outerPanel);
130         this.setSize(
131             config.getIntParameter("startwindow.width", 538),
132             config.getIntParameter("startwindow.height", 397));
133 
134         GuiUtil.center(this);
135         //        this.setLocation(config.getIntParameter("startwindow.posx",234),config.getIntParameter("startwindow.posy",171));
136 
137     }
138 
139     /***
140      * Setzt die Progressleiste
141      * @param text Text in der Infoleiste
142      * @param ratio Fortschritt der Progressleiste (0&le;=ratio&le;=100)
143      */
144     public void setProgress(String text, int ratio) {
145         setProgress(text, ratio, 0);
146     }
147 
148     /***
149      * Setzt die Progressleiste
150      * @param text Text in der Infoleiste
151      * @param ratio Fortschritt der Progressleiste (0&le;=ratio&le;=100)
152      *@param pause Pause in Sekunden
153      */
154     public void setProgress(String text, int ratio, int pause) {
155         this.info.setText("  " + text);
156         this.pbar.setValue(ratio);
157 
158         if (pause > 0) {
159             try {
160                 Thread.currentThread().sleep(pause * 1000);
161             } catch (Exception ex) {
162                 // DO NOTHING
163             }
164         }
165     }
166 
167     /***
168      * Setzt Fehlermeldung in der Infoleiste
169      * @param msg Fehlermeldung
170      */
171     public void setErrorMessage(String msg) {
172         info.setForeground(Color.RED);
173         this.info.setText(info.getText() + " " + msg);
174     }
175 
176     /***
177      * Schließt das Fenster
178      */
179     public void close() {
180         this.setVisible(false);
181         this.dispose();
182     }
183 
184     /***
185      * Zeigt das Fenster an
186      *@param sec Anzeigedauer in Sekunden
187      */
188     public void open(int sec) {
189         this.show();
190         try {
191             Thread.currentThread().sleep(sec * 1000);
192         } catch (Exception ex) {
193             // DO NOTHING
194         }
195     }
196 }