KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ixenon > free > install > ProgressFrame


1 /* $Id$
2  *
3  * Copyright (c) 1999 Xenonsoft Limited. All Rights Reserved.
4  *
5  * This software is protected by copyright. You are hereby notified from
6  * now by reading this message. This software is also the confidential
7  * and proprietary information of Xenonsoft Limited. ("Confidential
8  * Information").
9  *
10  * This software is distributed under the Xenonsoft Public end user
11  * License ("XPeL"), where the machine-readable source code is provided
12  * under the "Open Source" model.
13  * For more information, please read the file "LICENSE-XPL.txt"
14  */

15
16 // ProgressFrame.java
17

18 // Description:
19
// Installer frame for free installer application
20
//
21
// Author:
22
// Peter Pilgrim
23
// Thu Jan 21 00:14:18 GMT 1999
24
//
25
// RCS HEADER
26
//
27
// $Author$
28
// $Date$
29
// $Source$
30
// $Revision$ $State$ $Locker$
31
//
32
// History
33
// ================================================================================
34
// $Log$
35

36 package ixenon.free.install;
37
38 import java.awt.*;
39 import java.awt.event.*;
40 // import java.beans.*;
41
import java.util.*;
42 import java.io.*;
43
44 import javax.swing.*; // for JFrame, JOptionPane
45
import javax.swing.event.*;
46 import javax.swing.text.*; // for Document, SimpleAttributeSet
47
import javax.swing.border.*; // for BevelBorder
48

49 import ixenon.free.util.*; // for ApplicationResources
50
import ixenon.free.swing.*; // for DigitalClock
51

52
53 /** The main application frame for the free installer project. The
54  * frame consists of the frame divided into left and right hand side
55  * areas. The left hand side holds a splash image, which can be an
56  * application specific gif or jpeg. The right hand side contains
57  * selection component. From top to bottom, a combo box allows
58  * a locale and language to be selected. A combo box allows the
59  * installation mode to be selected.
60  *
61  */

62 public class ProgressFrame extends JFrame
63 {
64     private JLabel label;
65     private JTextPane textPane;
66     private JProgressBar progressBarNode;
67     private JProgressBar progressBarFile;
68
69     /**
70      * Create the progress frame GUI component
71      * @param title the title string for the frame
72      */

73     public ProgressFrame( String JavaDoc title )
74     {
75     super(title);
76
77     //
78
// Get application resources
79
//
80
ApplicationResources appres = ApplicationResources.getInstance();
81     
82     String JavaDoc frameIconName = appres.getResourceString( "installerFrame.icon", "appres/images/FreeInstaller-icon.gif" );
83
84     //
85
// Set up fonts
86
//
87
Font entryFont = new Font( "DialogInput", Font.BOLD, 12 );
88     Font labelFont = new Font( "Dialog", Font.BOLD, 12 );
89     Font textFont = new Font( "Monospaced", Font.PLAIN, 12 );
90
91     getContentPane().setLayout( new BorderLayout(9,9));
92
93     Image img1 = appres.getImage( "images", frameIconName, null );
94     setIconImage( img1 );
95     
96     JPanel panel = new JPanel();
97     panel.setLayout( new BorderLayout( 3, 3 ) );
98
99     // Create a scrollable text pane in the centre panel
100
textPane = new JTextPane();
101     textPane.setFont(textFont);
102     textPane.setBackground(Color.black);
103     textPane.setEditable(false);
104
105     JScrollPane scrollTextPane = new JScrollPane(textPane) {
106         public Dimension getPreferredSize() {
107         Dimension size = getSize();
108         if (size.width < 650)
109             size.width = 650;
110         if (size.height < 450)
111             size.height = 450;
112         return (size);
113         }
114     };
115     
116     panel.add( scrollTextPane, BorderLayout.CENTER );
117     
118     JPanel lowerBox = new JPanel();
119     lowerBox.setLayout( new BorderLayout(1,1) );
120     
121     // Create the progress bar in the south panel
122
JPanel anyPanel = new JPanel();
123     anyPanel.setLayout( new BorderLayout(1,1) );
124
125     progressBarNode = new JProgressBar() {
126         public Dimension getPreferredSize() {
127         Dimension size = getSize();
128         if (size.width < 100)
129             size.width = 100;
130         if (size.height != 24)
131             size.height = 24;
132         return (size);
133         }
134     };
135     progressBarNode.setMinimum(0);
136     progressBarNode.setValue(100);
137     progressBarNode.setMinimum(100);
138     anyPanel.add( progressBarNode, BorderLayout.WEST );
139     
140     progressBarFile = new JProgressBar() {
141         public Dimension getPreferredSize() {
142         Dimension size = getSize();
143         if (size.width < 100)
144             size.width = 100;
145         if (size.height != 24)
146             size.height = 24;
147         return (size);
148         }
149     };
150     progressBarFile.setMinimum(0);
151     progressBarFile.setValue(100);
152     progressBarFile.setMinimum(100);
153     anyPanel.add( progressBarFile, BorderLayout.CENTER );
154
155     lowerBox.add( anyPanel, BorderLayout.WEST );
156     
157     // Create a status area
158
Border loweredBorder = new BevelBorder( BevelBorder.LOWERED );
159     label = new JLabel( "-*- Status -*-" );
160     label.setFont(labelFont);
161     label.setBorder(loweredBorder);
162     lowerBox.add( label, BorderLayout.CENTER );
163     
164     // Create digital clock
165
DigitalClock clock = new DigitalClock();
166     clock.start();
167     clock.setBorder(loweredBorder);
168     lowerBox.add( clock, BorderLayout.EAST );
169
170     panel.add( lowerBox, BorderLayout.SOUTH );
171     
172     getContentPane().add( panel, BorderLayout.CENTER );
173
174     setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); /* !!! */
175
176     printInfo( "**** OUTPUT FROM INSTALLATION PROCESS ****\n" );
177     // printWarning( "warning test!");
178
// printError( "error test!");
179
}
180
181     /** Set the status text */
182     public void setStatusText( String JavaDoc newText )
183     {
184     label.setText(newText);
185     }
186
187     /** get the node copying progress bar component */
188     public JProgressBar getProgressBarNode()
189     {
190     return (progressBarNode);
191     }
192
193     /** get the file copying progress bar component */
194     public JProgressBar getProgressBarFile()
195     {
196     return (progressBarFile);
197     }
198
199     /** Sets the visibility of this component so that it is <EM>always</EM>
200      * centered.
201      * @param visible true if this the component is visible.
202      */

203     public void setVisible( boolean visible )
204     {
205     if (visible) {
206         Dimension size = getSize();
207         Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
208         
209         if (screen.width > 1100 ) {
210         // For hires screens.
211
size.width = screen.width*14/17;
212         size.height = screen.height*12/17;
213         }
214         int x = (screen.width-size.width)/2;
215         int y = (screen.height-size.height)/2;
216         setBounds(x, y, size.width, size.height);
217     }
218     
219     super.setVisible(visible);
220     }
221     
222     /** print an informational message to the progress frame's text pane component
223      * @param msg the message
224      */

225     public void printInfo( String JavaDoc msg )
226     {
227     SimpleAttributeSet attrs = new SimpleAttributeSet();
228     StyleConstants.setForeground( attrs, Color.green );
229     printMessage( msg, attrs );
230     }
231
232     /** print a warning message to the progress frame's text pane component
233      * @param msg the message
234      */

235     public void printWarning( String JavaDoc msg )
236     {
237     SimpleAttributeSet attrs = new SimpleAttributeSet();
238     StyleConstants.setForeground( attrs, Color.yellow );
239     printMessage( "*WARNING* : "+ msg, attrs );
240     }
241     
242     /** print an error message to the progress frame's text pane component
243      * @param msg the message
244      */

245     public void printError( String JavaDoc msg )
246     {
247     SimpleAttributeSet attrs = new SimpleAttributeSet();
248     StyleConstants.setForeground( attrs, Color.magenta );
249     StyleConstants.setBold( attrs, true );
250     printMessage( "*ERROR* : "+msg, attrs );
251     }
252
253     /** Print message to the progress frame text pane
254      * @param msg the message
255      * @param attrs the document style attribute set
256      */

257     protected void printMessage( String JavaDoc msg, AttributeSet attrs )
258     {
259     Document doc = textPane.getDocument();
260     // DEBUG: System.out.println( msg );
261
msg += "\n";
262     try {
263         doc.insertString( doc.getLength(), msg, attrs );
264         // Set the caret position so that the last insertion is visible.
265
textPane.setCaretPosition( doc.getLength() );
266     }
267     catch (BadLocationException ex) {
268         ex.printStackTrace();
269     }
270     }
271 }
272
273 // fini
274
Popular Tags