1 package ch
.cyberduck
.ui
;
4 * ch.cyberduck.ui.ProgressPanel.java
11 * Copyright (c) 2003 David Kocher. All rights reserved.
12 * http://icu.unizh.ch/~dkocher/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * Bug fixes, suggestions and comments should be sent to:
25 * dkocher@cyberduck.ch
29 import java
.awt
.Dimension
;
30 import java
.awt
.BorderLayout
;
31 import java
.awt
.FlowLayout
;
32 import java
.awt
.event
.ActionEvent
;
33 import java
.util
.Observable
;
34 import java
.util
.Observer
;
36 import ch
.cyberduck
.Cyberduck
;
37 import ch
.cyberduck
.connection
.Bookmark
;
38 import ch
.cyberduck
.connection
.Status
;
39 import ch
.cyberduck
.ui
.common
.DraggableLabel
;
40 import ch
.cyberduck
.ui
.common
.GUIFactory
;
43 * The ProgressPanel is the stanard detailed view of a bookmark displayed
44 * in the bottom of the app's splitpane.
45 * It contains a progressbar and labels with URL and local path
46 * Must be registered to the BookmarkPanel as an Observer to be notified about
50 public class ProgressPanel
extends JPanel
implements Observer
{
51 private Bookmark selected
;
53 private JButton connectButton
;
54 private JLabel labelb
;
55 private JLabel labelc
;
56 private JLabel percentLabel
;
57 private JLabel progressLabel
;
58 private JProgressBar progressBar
;
59 private Action connectAction
, stopAction
;
61 private JPanel paramPanel
, buttonPanel
;
63 public ProgressPanel() {
64 Cyberduck
.DEBUG("[ProgressPanel]");
68 public void update(Observable o
, Object argument
) {
69 if(o
instanceof Bookmark
) {
70 if(argument
.equals(Bookmark
.SELECTION
)) {
71 this.selected
= (Bookmark
)o
;
75 if(o
instanceof Status
) {
76 if (argument
.equals(Status
.CURRENT
)) {
77 this.progressBar
.setModel(selected
.status
.getProgressModel());
78 this.percentLabel
.setText((int)(progressBar
.getPercentComplete()*100) + "% ");
79 this.progressLabel
.setText(selected
.status
.getMessage(Status
.DATA
));
81 else if (argument
.equals(Status
.PROGRESS
)) {
82 this.progressLabel
.setText(selected
.status
.getMessage(Status
.DATA
));
88 ((Observer
)connectAction
).update(o
, argument
);
89 ((Observer
)stopAction
).update(o
, argument
);
92 public JButton
getDefaultButton() {
93 return this.connectButton
;
97 * Update labels and progressbar with informations of the currently
100 private void refresh() {
101 progressBar
.setModel(selected
.status
.getProgressModel());
103 labelb
.setText(selected
.getAddressAsString());
104 labelc
.setText("Local: " + selected
.getLocalPathAsString());
105 percentLabel
.setText((int)(progressBar
.getPercentComplete()*100) + "% ");
106 progressLabel
.setText(selected
.status
.getMessage(Status
.DATA
));
107 labelc
.setVisible(selected
.isDownload());
108 progressLabel
.setVisible(selected
.isDownload());
111 private class ParameterPanel
extends JPanel
{
112 public ParameterPanel() {
116 private void init() {
117 this.setLayout(new BorderLayout());
118 JPanel barPanel
= new JPanel();
119 barPanel
.setLayout(new FlowLayout(FlowLayout
.LEFT
));
120 progressBar
= new JProgressBar(0, 1);
121 progressBar
.setStringPainted(false);
122 progressBar
.setBorderPainted(true);
123 barPanel
.add(progressBar
);
124 barPanel
.add(percentLabel
= GUIFactory
.labelBuilder("", GUIFactory
.FONT_SMALL
));
126 JPanel labelPanel
= new JPanel();
127 labelPanel
.setLayout(new FlowLayout(FlowLayout
.LEFT
));
129 Box labelBox
= new Box(BoxLayout
.Y_AXIS
);
130 //labelBox.add(labela = new DraggableLabel("", GUIFactory.FONT_SMALL));
131 labelBox
.add(labelb
= new DraggableLabel("", GUIFactory
.FONT_SMALL
));
132 labelBox
.add(labelc
= GUIFactory
.labelBuilder("", GUIFactory
.FONT_SMALL
));
133 labelBox
.add(progressLabel
= GUIFactory
.labelBuilder("", GUIFactory
.FONT_SMALL
));
134 labelPanel
.add(labelBox
);
136 this.add(labelPanel
, BorderLayout
.CENTER
);
137 this.add(barPanel
, BorderLayout
.SOUTH
);
142 private class ButtonPanel
extends JPanel
{
143 public ButtonPanel() {
147 private void init() {
148 this.setLayout(new FlowLayout(FlowLayout
.RIGHT
));
149 this.add(GUIFactory
.buttonBuilder(GUIFactory
.FONT_SMALL
, stopAction
= new StopAction()));
150 this.add(connectButton
= GUIFactory
.buttonBuilder(GUIFactory
.FONT_SMALL
, connectAction
= new ConnectAction()));
152 public Dimension
getMinimumSize() {
153 return new Dimension(super.getMinimumSize().width
, 80);
158 * Initialize the graphical user interface
160 private void init() {
161 this.setLayout(new BoxLayout(this, BoxLayout
.Y_AXIS
));
162 this.add(paramPanel
= new ParameterPanel());
163 this.add(buttonPanel
= new ButtonPanel());
167 public java.awt.Dimension getMinimumSize() {
168 int h = (int)paramPanel.getMinimumSize().height + (int)buttonPanel.getMinimumSize().height;
169 int w = (int)super.getMinimumSize().width;
170 java.awt.Dimension d = new java.awt.Dimension(w, h);
171 // java.awt.Dimension d = new java.awt.Dimension((int)super.getMinimumSize().width, 150);
172 Cyberduck.DEBUG("[ProgressPanel] getMinimumSize():" + d.toString());
177 // ************************************************************************************************************
179 private class ConnectAction
extends AbstractAction
implements java
.util
.Observer
{
180 public ConnectAction() {
184 public ConnectAction(String label
) {
186 this.putValue(SHORT_DESCRIPTION
, "Connect to remote host");
187 this.setEnabled(false);
188 //ActionMap.instance().put(this.getValue(NAME), this);
191 public void actionPerformed(ActionEvent ae
) {
195 public void update(java
.util
.Observable o
, Object arg
) {
196 if (arg
.equals(Status
.ACTIVE
) ||
197 arg
.equals(Status
.STOP
) ||
198 arg
.equals(Status
.COMPLETE
) ||
199 arg
.equals(Bookmark
.SELECTION
))
201 String name
= "Connect";
202 if(selected
.isDownload()) {
203 if(selected
.getHandler().equals(Status
.RELOAD
))
205 if(selected
.getHandler().equals(Status
.RESUME
))
207 if(selected
.getHandler().equals(Status
.INITIAL
))
210 if(selected
.isListing()) {
211 if(selected
.getHandler().equals(Status
.RELOAD
))
216 this.putValue(NAME
, name
);
217 this.setEnabled(selected
.isValid() && selected
.status
.isStopped());
223 private class StopAction
extends AbstractAction
implements java
.util
.Observer
{
224 public StopAction() {
228 public StopAction(String label
) {
230 this.putValue(SHORT_DESCRIPTION
, "Stop transfer");
231 //this.putValue(SMALL_ICON, Cyberduck.getIcon(Cyberduck.getResource("stop_small.gif")));
232 this.setEnabled(false);
233 //ActionMap.instance().put(this.getValue(NAME), this);
236 public void actionPerformed(ActionEvent ae
) {
237 Cyberduck
.DEBUG(ae
.paramString());
238 selected
.status
.setCanceled(true);
240 //((Action)ActionMap.instance().get("Stop")).actionPerformed(new ActionEvent(selected, ae.getID(), ae.getActionCommand()));
243 public void update(java
.util
.Observable o
, Object arg
) {
244 if (arg
.equals(Status
.ACTIVE
) ||
245 arg
.equals(Status
.STOP
) ||
246 arg
.equals(Status
.COMPLETE
) ||
247 arg
.equals(Bookmark
.SELECTION
))
249 //this.putValue(NAME, "Stop");
250 this.setEnabled(!selected
.status
.isStopped());
256 private class EditAction extends AbstractAction implements java.util.Observer {
257 public EditAction() {
260 public EditAction(String label) {
262 this.putValue(SHORT_DESCRIPTION, "Edit bookmark");
263 this.setEnabled(false);
264 //ActionMap.instance().put(this.getValue(NAME), this);
267 public void actionPerformed(ActionEvent ae) {
268 Cyberduck.DEBUG(ae.paramString());
272 public void update(java.util.Observable o, Object arg) {
273 if (arg.equals(Status.ACTIVE) ||
274 arg.equals(Status.STOP) ||
275 arg.equals(Status.COMPLETE) ||
276 arg.equals(Bookmark.SELECTION))
278 this.setEnabled(selected.status.isStopped());
285 private class ShowInFinderAction extends javax.swing.AbstractAction implements java.util.Observer {
286 public ShowInFinderAction() {
287 super("Reveal In Finder");
288 this.putValue(SHORT_DESCRIPTION, "Show file in Finder (Mac only)");
289 this.setEnabled(System.getProperty("os.name").indexOf("Mac") != -1);
290 //ActionMap.instance().put(this.getValue(NAME), this);
293 public void actionPerformed(ActionEvent ae) {
294 Cyberduck.DEBUG(ae.paramString());
296 com.apple.mrj.MRJFileUtils.openURL("file://" + selected.getLocalDirectory());
298 catch(java.io.IOException e) {
303 public void update(java.util.Observable o, Object arg) {
304 if(arg.equals(Bookmark.SELECTION)) {
305 boolean macos = System.getProperty("os.name").indexOf("Mac OS") != -1;
306 this.setEnabled(((Bookmark)o).isDownload() && macos);