001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2007 Vladimir Ralev
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021:
022: package com.izforge.izpack.installer;
023:
024: import java.awt.Dimension;
025: import java.awt.event.ActionEvent;
026: import java.awt.event.ActionListener;
027:
028: import javax.swing.JButton;
029: import javax.swing.JDialog;
030: import javax.swing.JLabel;
031: import javax.swing.JPanel;
032: import javax.swing.JProgressBar;
033: import javax.swing.SwingUtilities;
034:
035: /**
036: * Displays progress and stats while downloading repository files.
037: *
038: * @author <a href="vralev@redhat.com">Vladimir Ralev</a>
039: * @version $Revision: 1.1 $
040: */
041: public class DownloadPanel extends JDialog implements ActionListener {
042: private static final long serialVersionUID = -4458769435196053866L;
043:
044: JLabel statusLabel = new JLabel("", JLabel.RIGHT);
045:
046: JLabel fileLabel = new JLabel("File", JLabel.LEFT);
047:
048: JButton button = new JButton("Cancel");
049:
050: JProgressBar progressBar = new JProgressBar();
051:
052: String statusText;
053:
054: String fileText;
055:
056: LoggedInputStream lis;
057:
058: public DownloadPanel(LoggedInputStream lis) {
059: Dimension dialogSize = new Dimension(406, 150);
060: this .setLayout(null);
061: this .setMinimumSize(dialogSize);
062: this .setMaximumSize(dialogSize);
063: this .setPreferredSize(dialogSize);
064: this .setAlwaysOnTop(true);
065: this .setResizable(false);
066: this .setSize(dialogSize);
067: this .lis = lis;
068:
069: progressBar = new JProgressBar();
070: progressBar.setIndeterminate(false);
071: JPanel contents = (JPanel) getContentPane();
072: contents.setLayout(null);
073: contents.setSize(dialogSize);
074:
075: setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
076:
077: contents.add(fileLabel);
078: contents.add(statusLabel);
079: contents.add(progressBar);
080: contents.add(button);
081:
082: button.addActionListener(this );
083:
084: fileLabel.setBounds(10, 10, 260, 20);
085: statusLabel.setBounds(270, 10, 120, 20);
086: progressBar.setBounds(10, 35, 380, 20);
087: button.setBounds(200 - 50, 70, 100, 25);
088: pack();
089: }
090:
091: public void setStatusLabel(String text) {
092: statusText = text;
093: if (!SwingUtilities.isEventDispatchThread())
094: SwingUtilities.invokeLater(new Runnable() {
095: public void run() {
096: statusLabel.setText(statusText);
097: }
098: });
099:
100: }
101:
102: public void setFileLabel(String text) {
103: int maxStr = 35;
104: int lastSeparator = text.lastIndexOf("/");
105: text = text.substring(lastSeparator + 1, text.length());
106: int length = text.length();
107:
108: if (length > maxStr)
109: fileText = ".." + text.substring(length - maxStr, length);
110: else
111: fileText = text;
112:
113: if (!SwingUtilities.isEventDispatchThread())
114: SwingUtilities.invokeLater(new Runnable() {
115: public void run() {
116: fileLabel.setText(fileText);
117: }
118: });
119:
120: }
121:
122: public void actionPerformed(ActionEvent e) {
123: lis.setCancelled(true);
124: this .dispose();
125: }
126:
127: public void setProgressMax(int total) {
128: progressBar.setIndeterminate(false);
129: progressBar.setStringPainted(true);
130: progressBar.setMaximum(total);
131: progressBar.setMinimum(0);
132: }
133:
134: public void setProgressCurrent(int curr) {
135: progressBar.setValue(curr);
136: }
137: }
|