source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/selfextract/ProgressIndicator.java@ 15210

Last change on this file since 15210 was 15210, checked in by oranfry, 16 years ago

Lots of changes to the installer. Now only look in LanguagePack resource bundle for strings.

File size: 5.0 KB
Line 
1/*
2 * Copyright 2005 Paul Hinds
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.tp23.antinstaller.selfextract;
17
18import java.awt.BorderLayout;
19import java.awt.Cursor;
20import java.awt.Dimension;
21import java.awt.GraphicsConfiguration;
22import java.awt.GridBagConstraints;
23import java.awt.GridBagLayout;
24import java.awt.Insets;
25import java.io.ByteArrayOutputStream;
26import java.io.InputStream;
27import java.util.ResourceBundle;
28
29import javax.swing.BorderFactory;
30import javax.swing.ImageIcon;
31import javax.swing.JFrame;
32import javax.swing.JLabel;
33import javax.swing.JPanel;
34import javax.swing.JProgressBar;
35import javax.swing.UIManager;
36import javax.swing.border.BevelBorder;
37import javax.swing.border.Border;
38
39
40
41/**
42 *
43 * <p>Frame to indicate progress of the extraction of a SelfExctracting archive </p>
44 * <p> </p>
45 * <p>Copyright: Copyright (c) 2004</p>
46 * <p>Company: tp23</p>
47 * @author Paul Hinds
48 * @version $Id: ProgressIndicator.java,v 1.3 2007/01/28 08:44:40 teknopaul Exp $
49 */
50public class ProgressIndicator
51 extends JFrame {
52
53 public static final String IMAGE_RESOURCE = "/resources/extract-image.png";
54 private static final ResourceBundle res = ResourceBundle.getBundle("resources.LanguagePack");
55
56 private JPanel jPanel1 = new JPanel();
57 private JProgressBar jProgressBar1 = new JProgressBar();
58 private JLabel textLabel = new JLabel();
59 private Border border1;
60 private int max = 0;
61 private static int PAGE_WIDTH = 160;
62 private static int PAGE_HEIGHT = 110; // 35 is text + bar
63 private String title = res.getString("extracting");
64 private JLabel imagePanel = new JLabel();
65 GridBagLayout gridBagLayout1 = new GridBagLayout();
66 private boolean useIcon = true;
67
68
69
70 public ProgressIndicator(int max) {
71 this.max = max;
72 jbInit();
73 }
74
75 public ProgressIndicator(int max, String title) {
76 this.max = max;
77 this.title = title;
78 jbInit();
79 }
80
81 private void setLocation() {
82 GraphicsConfiguration config = getGraphicsConfiguration();
83 int x = (int) config.getBounds().getCenterX() - (PAGE_WIDTH / 2);
84 int y = (int) config.getBounds().getCenterY() - (PAGE_HEIGHT / 2);
85 setLocation(x, y);
86 }
87
88
89 private void jbInit() {
90 border1 = BorderFactory.createCompoundBorder(
91 BorderFactory.createBevelBorder(BevelBorder.RAISED),
92 BorderFactory.createEmptyBorder(4, 4, 4, 4));
93 jPanel1.setLayout(gridBagLayout1);
94 int row = 0;
95 this.getContentPane().add(jPanel1, BorderLayout.CENTER);
96 if (useIcon) {
97 PAGE_HEIGHT = 110;
98 setImage();
99 jPanel1.add(imagePanel, new GridBagConstraints(0, row++, 1, 1, 0.1, 0.9
100 , GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
101 this.setSize(new Dimension(PAGE_WIDTH, PAGE_HEIGHT));
102 }
103 else {
104 PAGE_HEIGHT = 40;
105 this.setSize(new Dimension(PAGE_WIDTH, 35));
106 }
107 jPanel1.setBorder(border1);
108 jPanel1.setMaximumSize(new Dimension(PAGE_WIDTH, PAGE_HEIGHT));
109 jPanel1.setMinimumSize(new Dimension(PAGE_WIDTH, PAGE_HEIGHT));
110 jPanel1.setPreferredSize(new Dimension(PAGE_WIDTH, PAGE_HEIGHT));
111 textLabel.setText(title);
112 this.setTitle(title);
113 jPanel1.add(textLabel, new GridBagConstraints(0, row++, 1, 1, 0.1, 0.1
114 , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
115 jPanel1.add(jProgressBar1, new GridBagConstraints(0, row++, 1, 1, 0.1, 0.1
116 , GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
117 jProgressBar1.setMinimum(0);
118 jProgressBar1.setMaximum(max);
119 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
120 this.setSize(new Dimension(PAGE_WIDTH, PAGE_HEIGHT));
121 this.setResizable(false);
122 this.setUndecorated(true);
123 setLocation();
124 }
125
126 public void tick() {
127 jProgressBar1.setValue(jProgressBar1.getValue() + 1);
128 }
129
130 private void setImage() {
131 try {
132 ByteArrayOutputStream baos = new ByteArrayOutputStream();
133 InputStream in = this.getClass().getResourceAsStream(IMAGE_RESOURCE);
134 byte[] buffer = new byte[2048];
135 int read = -1;
136 while ( (read = in.read(buffer)) != -1) {
137 baos.write(buffer, 0, read);
138 }
139 ImageIcon icon = new ImageIcon(baos.toByteArray());
140 imagePanel.setHorizontalAlignment(JLabel.CENTER);
141 imagePanel.setIcon(icon);
142 }
143 catch (Exception ex) {
144 }
145 }
146
147 /**
148 * TODO move to JUnit
149 * @param args
150 */
151 public static void main(String[] args) {
152 try {
153 ProgressIndicator indicator = null;
154 indicator = new ProgressIndicator(200);
155 indicator.show();
156 UIManager.setLookAndFeel("org.tp23.jgoodies.plaf.plastic.PlasticXPLookAndFeel");
157 }
158 catch (Exception ex) {
159 // not concerned about Look and Feel
160 }
161
162 }
163}
Note: See TracBrowser for help on using the repository browser.