2 * ch.cyberduck.ui.cocoa.CDMainWindow.java
5 * Copyright (c) 2002 David Kocher. All rights reserved.
6 * http://icu.unizh.ch/~dkocher/
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * Bug fixes, suggestions and comments should be sent to:
19 * dkocher@cyberduck.ch
22 package ch
.cyberduck
.ui
.cocoa
;
24 import com
.apple
.cocoa
.foundation
.*;
25 import com
.apple
.cocoa
.application
.*;
27 //import java.util.Observer;
28 //import java.util.Observable;
30 //import ch.cyberduck.core.Status;
31 //import ch.cyberduck.ui.ObserverList;
33 import org
.apache
.log4j
.Logger
;
35 public class CDMainWindow
extends NSWindow
{//implements Observer {
37 private static Logger log
= Logger
.getLogger(CDMainWindow
.class);
39 //public NSPopUpButton favoritePopUpButton;
40 public NSWindow connectionSheet
; /* IBOutlet */
41 public NSTextField quickConnectField
; /* IBOutlet */
42 public NSDrawer drawer
; /* IBOutlet */
44 private NSMutableDictionary toolbarItems
;
46 public CDMainWindow() {
48 log
.debug("CDMainWindow");
49 // ObserverList.instance().registerObserver((Observer)this);
52 public CDMainWindow(NSRect contentRect
, int styleMask
, int backingType
, boolean defer
) {
53 super(contentRect
, styleMask
, backingType
, defer
);
54 log
.debug("CDMainWindow");
55 // ObserverList.instance().registerObserver((Observer)this);
58 public CDMainWindow(NSRect contentRect
, int styleMask
, int bufferingType
, boolean defer
, NSScreen aScreen
) {
59 super(contentRect
, styleMask
, bufferingType
, defer
, aScreen
);
60 log
.debug("CDMainWindow");
61 // ObserverList.instance().registerObserver((Observer)this);
65 * @return The string that appears in the title bar of the receiver.
67 public String
title() {
68 return "Connected to <host>";
72 public void awakeFromNib() {
73 log
.debug("CDMainWindow:awakeFromNib");
75 NSArray columns = connectedView.tableColumns();
76 NSTableColumn c = columns.objectAtIndex(columns.count()-1);
77 c.setDataCell(new CDServerItemView());
79 this.setDelegate(this);
82 // ----------------------------------------------------------
84 // ----------------------------------------------------------
86 NSToolbar toolbar
= new NSToolbar("mainToolbar");
87 this.toolbarItems
= new NSMutableDictionary();
89 this.addToolbarItem(toolbarItems
, "New Connection", "New Connection", "New Connection", "Connect to remote host", this, new NSSelector("openConnectionSheet", new Class
[] {null}), NSImage
.imageNamed("server.tiff"));
91 this.addToolbarItem(toolbarItems
, "Back", "Back", "Back", "Show parent directory", this, new NSSelector("back", new Class
[] {null}), NSImage
.imageNamed("back.tiff"));
93 this.addToolbarItem(toolbarItems
, "Quick Connect", "Quick Connect", "Quick Connect", null, this, null, null);
94 NSToolbarItem quickConnectItem
= (NSToolbarItem
)toolbarItems
.objectForKey("Quick Connect");
95 quickConnectItem
.setView(quickConnectField
);
96 quickConnectItem
.setMinSize(quickConnectField
.frame().size());
97 quickConnectItem
.setMaxSize(quickConnectField
.frame().size());
99 this.addToolbarItem(toolbarItems, "Favorites", "Favorites", "Favorites", null, this, null, null);
101 NSToolbarItem favoriteItem = (NSToolbarItem)toolbarItems.objectForKey("Favorites");
102 favoriteItem.setView(favoritePopUpButton);
103 favoriteItem.setMinSize(favoritePopUpButton.frame().size());
104 favoriteItem.setMaxSize(favoritePopUpButton.frame().size());
107 this.addToolbarItem(toolbarItems
, "Refresh", "Refresh", "Refresh", "Refresh directory listing", this, new NSSelector("refreshListing", new Class
[] {null}), NSImage
.imageNamed("refresh.tiff"));
109 this.addToolbarItem(toolbarItems
, "Download", "Download", "Download", "Download file", this, new NSSelector("download", new Class
[] {null}), NSImage
.imageNamed("download.tiff"));
111 this.addToolbarItem(toolbarItems
, "Upload", "Upload", "Upload", "Upload file", this, new NSSelector("upload", new Class
[] {null}), NSImage
.imageNamed("upload.tiff"));
113 this.addToolbarItem(toolbarItems
, "Get Info", "Get Info", "Get Info", "Show file permissions", this, new NSSelector("showInfo", new Class
[] {null}), NSImage
.imageNamed("info.tiff"));
115 this.addToolbarItem(toolbarItems
, "Show Transcript", "Show Transcript", "Show Transcript", "Show connection transcript", this, new NSSelector("showTranscriptDrawer", new Class
[] {null}), NSImage
.imageNamed("transcript.tiff"));
117 this.addToolbarItem(toolbarItems
, "Delete", "Delete", "Delete", "Delete file", this, new NSSelector("deleteFile", new Class
[] {null}), NSImage
.imageNamed("delete.tiff"));
119 toolbar
.setDelegate(this);
120 toolbar
.setAllowsUserCustomization(true);
121 toolbar
.setAutosavesConfiguration(true);
122 this.setToolbar(toolbar
);
126 // ----------------------------------------------------------
127 // Toolbar delegate methods
128 // ----------------------------------------------------------
130 private void addToolbarItem(NSMutableDictionary toolbarItems
, String identifier
, String label
, String paletteLabel
, String toolTip
, Object target
, NSSelector action
, NSImage image
) {
131 NSToolbarItem item
= new NSToolbarItem(identifier
);
132 item
.setLabel(label
);
133 item
.setPaletteLabel(paletteLabel
);
134 item
.setToolTip(toolTip
);
135 item
.setImage(image
);
136 item
.setTarget(target
);
137 item
.setAction(action
);
138 item
.setEnabled(true);
140 toolbarItems
.setObjectForKey(item
, identifier
);
143 public NSArray
toolbarDefaultItemIdentifiers(NSToolbar toolbar
) {
144 return new NSArray(new Object
[] {"New Connection", NSToolbarItem
.SeparatorItemIdentifier
, "Quick Connect", NSToolbarItem
.SeparatorItemIdentifier
, "Back", "Refresh", "Download", "Upload", "Delete", "Get Info", NSToolbarItem
.FlexibleSpaceItemIdentifier
, "Show Transcript"});
147 public NSArray
toolbarAllowedItemIdentifiers(NSToolbar toolbar
) {
148 return new NSArray(new Object
[] {"New Connection", "Quick Connect", NSToolbarItem
.SeparatorItemIdentifier
, "Back", "Refresh", "Download", "Upload", "Delete", "Get Info", NSToolbarItem
.FlexibleSpaceItemIdentifier
, "Show Transcript", NSToolbarItem
.CustomizeToolbarItemIdentifier
, NSToolbarItem
.SpaceItemIdentifier
});
151 public NSToolbarItem
toolbarItemForItemIdentifier(NSToolbar toolbar
, String itemIdentifier
, boolean flag
) {
152 return (NSToolbarItem
)toolbarItems
.objectForKey(itemIdentifier
);
155 public boolean validateToolbarItem(NSToolbarItem item
) {
159 public void showTranscriptDrawer(NSObject sender
) {
163 public void openConnectionSheet(NSObject sender
) {
164 NSApplication
.sharedApplication().beginSheet(connectionSheet
, this, this,
167 "connectionSheetDidEnd",
170 NSWindow
.class, int.class, NSWindow
.class
176 public void closeConnectionSheet(NSObject sender
) {
177 // Ends a document modal session by specifying the sheet window, sheet. Also passes along a returnCode to the delegate.
178 NSApplication
.sharedApplication().endSheet(connectionSheet
, NSAlertPanel
.AlternateReturn
);
181 public void connectionSheetDidEnd(NSWindow sheet
, int returncode
, NSWindow main
) {
186 public void update(Observable o, Object arg) {
187 if(o instanceof Status) {
188 log.debug("Observable "+o+" sent argument "+ arg);
189 if(arg.equals(Status.TIME) || arg.equals(Status.PROGRESS) || arg.equals(Status.ERROR)) {
190 statusLabel.setStringValue(selected.status.getMessage(Status.TIME) + " : " + selected.status.getMessage(Status.PROGRESS) + " : " + selected.status.getMessage(Status.ERROR));
193 throw new IllegalArgumentException("Unknown observable argument: "+arg);
196 throw new IllegalArgumentException("Unknown observable: "+o);
200 // ----------------------------------------------------------
201 // Window delegate methods
202 // ----------------------------------------------------------
204 public boolean windowShouldClose(NSWindow sender
) {
205 NSAlertPanel
.beginAlertSheet(
206 "Really quit Cyberduck now?", //title
207 "Quit",// defaultbutton
208 "Cancel",//alternative button
217 NSWindow
.class, int.class, NSWindow
.class
220 null, // dismiss selector
222 "All connections to remote servers will be closed." // message
227 // ----------------------------------------------------------
229 // ----------------------------------------------------------
231 public void quitSheetDidEnd(NSWindow sheet
, int returncode
, NSWindow main
) {
232 // if multi window app only close the one window with main.close()
233 if(returncode
== NSAlertPanel
.DefaultReturn
)
234 NSApplication
.sharedApplication().terminate(this);