1 package ch
.cyberduck
.ui
.cocoa
;
4 * Copyright (c) 2007 David Kocher. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to:
18 * dkocher@cyberduck.ch
21 import ch
.cyberduck
.binding
.ProxyController
;
22 import ch
.cyberduck
.binding
.application
.NSAlert
;
23 import ch
.cyberduck
.binding
.application
.NSColor
;
24 import ch
.cyberduck
.binding
.application
.NSFont
;
25 import ch
.cyberduck
.binding
.application
.NSView
;
26 import ch
.cyberduck
.binding
.foundation
.NSArray
;
27 import ch
.cyberduck
.binding
.foundation
.NSAttributedString
;
28 import ch
.cyberduck
.binding
.foundation
.NSBundle
;
29 import ch
.cyberduck
.binding
.foundation
.NSDictionary
;
30 import ch
.cyberduck
.core
.FactoryException
;
32 import org
.apache
.log4j
.Logger
;
37 public abstract class BundleController
extends ProxyController
{
38 private static Logger log
= Logger
.getLogger(BundleController
.class);
40 public static final NSDictionary TRUNCATE_MIDDLE_ATTRIBUTES
= NSDictionary
.dictionaryWithObjectsForKeys(
41 NSArray
.arrayWithObject(TableCellAttributes
.PARAGRAPH_STYLE_LEFT_ALIGNMENT_TRUNCATE_MIDDLE
),
42 NSArray
.arrayWithObject(NSAttributedString
.ParagraphStyleAttributeName
)
45 public static final NSDictionary FIXED_WITH_FONT_ATTRIBUTES
= NSDictionary
.dictionaryWithObjectsForKeys(
46 NSArray
.arrayWithObject(NSFont
.userFixedPitchFontOfSize(9.0f
)),
47 NSArray
.arrayWithObject(NSAttributedString
.FontAttributeName
)
50 protected static final NSDictionary MENU_HELP_FONT_ATTRIBUTES
= NSDictionary
.dictionaryWithObjectsForKeys(
51 NSArray
.arrayWithObjects(NSFont
.userFontOfSize(NSFont
.smallSystemFontSize()), NSColor
.darkGrayColor(),
52 TableCellAttributes
.PARAGRAPH_STYLE_LEFT_ALIGNMENT_TRUNCATE_MIDDLE
),
53 NSArray
.arrayWithObjects(NSAttributedString
.FontAttributeName
, NSAttributedString
.ForegroundColorAttributeName
,
54 NSAttributedString
.ParagraphStyleAttributeName
)
57 protected void loadBundle() {
58 final String bundleName
= this.getBundleName();
59 if(null == bundleName
) {
60 log
.debug(String
.format("No bundle to load for controller %s", this.toString()));
63 this.loadBundle(bundleName
);
66 protected void loadBundle(final String bundleName
) {
68 log
.warn(String
.format("Bundle %s already loaded", bundleName
));
71 if(log
.isInfoEnabled()) {
72 log
.info(String
.format("Loading bundle %s", bundleName
));
74 // Unarchives the contents of the nib file and links them to a specific owner object
75 if(!NSBundle
.loadNibNamed(bundleName
, this.id())) {
76 throw new FactoryException(String
.format("Couldn't load %s.nib", bundleName
));
84 * After loading the NIB, awakeFromNib from NSNibLoading protocol was called.
85 * Not the case on 10.6 because the method is implemented by NSObject.
87 private boolean awaked
;
90 * Called by the runtime after the NIB file has been loaded sucessfully
92 public void awakeFromNib() {
93 log
.debug("awakeFromNib");
98 * @return The top level view object or null if unknown
100 protected NSView
view() {
104 protected abstract String
getBundleName();
106 protected int alert(final NSAlert alert
) {
107 return alert
.runModal();