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

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

changes to the way ant-installer loads and reloads the language packs, and a new attribute to the select input which triggers it to change the language to the input value

File size: 4.9 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
55 private JPanel jPanel1 = new JPanel();
56 private JProgressBar jProgressBar1 = new JProgressBar();
57 private JLabel textLabel = new JLabel();
58 private Border border1;
59 private int max = 0;
60 private static int PAGE_WIDTH = 160;
61 private static int PAGE_HEIGHT = 110; // 35 is text + bar
62 private String title = org.tp23.antinstaller.Installer.langPack.getString("extracting");
63 private JLabel imagePanel = new JLabel();
64 GridBagLayout gridBagLayout1 = new GridBagLayout();
65 private boolean useIcon = true;
66
67
68
69 public ProgressIndicator(int max) {
70 this.max = max;
71 jbInit();
72 }
73
74 public ProgressIndicator(int max, String title) {
75 this.max = max;
76 this.title = title;
77 jbInit();
78 }
79
80 private void setLocation() {
81 GraphicsConfiguration config = getGraphicsConfiguration();
82 int x = (int) config.getBounds().getCenterX() - (PAGE_WIDTH / 2);
83 int y = (int) config.getBounds().getCenterY() - (PAGE_HEIGHT / 2);
84 setLocation(x, y);
85 }
86
87
88 private void jbInit() {
89 border1 = BorderFactory.createCompoundBorder(
90 BorderFactory.createBevelBorder(BevelBorder.RAISED),
91 BorderFactory.createEmptyBorder(4, 4, 4, 4));
92 jPanel1.setLayout(gridBagLayout1);
93 int row = 0;
94 this.getContentPane().add(jPanel1, BorderLayout.CENTER);
95 if (useIcon) {
96 PAGE_HEIGHT = 110;
97 setImage();
98 jPanel1.add(imagePanel, new GridBagConstraints(0, row++, 1, 1, 0.1, 0.9
99 , GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
100 this.setSize(new Dimension(PAGE_WIDTH, PAGE_HEIGHT));
101 }
102 else {
103 PAGE_HEIGHT = 40;
104 this.setSize(new Dimension(PAGE_WIDTH, 35));
105 }
106 jPanel1.setBorder(border1);
107 jPanel1.setMaximumSize(new Dimension(PAGE_WIDTH, PAGE_HEIGHT));
108 jPanel1.setMinimumSize(new Dimension(PAGE_WIDTH, PAGE_HEIGHT));
109 jPanel1.setPreferredSize(new Dimension(PAGE_WIDTH, PAGE_HEIGHT));
110 textLabel.setText(title);
111 this.setTitle(title);
112 jPanel1.add(textLabel, new GridBagConstraints(0, row++, 1, 1, 0.1, 0.1
113 , GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
114 jPanel1.add(jProgressBar1, new GridBagConstraints(0, row++, 1, 1, 0.1, 0.1
115 , GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
116 jProgressBar1.setMinimum(0);
117 jProgressBar1.setMaximum(max);
118 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
119 this.setSize(new Dimension(PAGE_WIDTH, PAGE_HEIGHT));
120 this.setResizable(false);
121 this.setUndecorated(true);
122 setLocation();
123 }
124
125 public void tick() {
126 jProgressBar1.setValue(jProgressBar1.getValue() + 1);
127 }
128
129 private void setImage() {
130 try {
131 ByteArrayOutputStream baos = new ByteArrayOutputStream();
132 InputStream in = this.getClass().getResourceAsStream(IMAGE_RESOURCE);
133 byte[] buffer = new byte[2048];
134 int read = -1;
135 while ( (read = in.read(buffer)) != -1) {
136 baos.write(buffer, 0, read);
137 }
138 ImageIcon icon = new ImageIcon(baos.toByteArray());
139 imagePanel.setHorizontalAlignment(JLabel.CENTER);
140 imagePanel.setIcon(icon);
141 }
142 catch (Exception ex) {
143 }
144 }
145
146 /**
147 * TODO move to JUnit
148 * @param args
149 */
150 public static void main(String[] args) {
151 try {
152 ProgressIndicator indicator = null;
153 indicator = new ProgressIndicator(200);
154 indicator.show();
155 UIManager.setLookAndFeel("org.tp23.jgoodies.plaf.plastic.PlasticXPLookAndFeel");
156 }
157 catch (Exception ex) {
158 // not concerned about Look and Feel
159 }
160
161 }
162}
Note: See TracBrowser for help on using the repository browser.