Fix transcript in transfer window.
[cyberduck.git] / source / ch / cyberduck / ui / cocoa / BundleController.java
blobf42303ac951d104afd379f435948aee640026883
1 package ch.cyberduck.ui.cocoa;
3 /*
4 * Copyright (c) 2007 David Kocher. All rights reserved.
5 * http://cyberduck.ch/
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;
34 /**
35 * @version $Id$
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("No bundle to load for " + this.toString());
61 return;
63 this.loadBundle(bundleName);
66 protected void loadBundle(final String bundleName) {
67 if(awaked) {
68 log.warn(String.format("Bundle %s already loaded", bundleName));
69 return;
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));
78 if(!awaked) {
79 this.awakeFromNib();
83 /**
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;
89 /**
90 * Called by the runtime after the NIB file has been loaded sucessfully
92 public void awakeFromNib() {
93 log.debug("awakeFromNib");
94 awaked = true;
97 /**
98 * @return The top level view object or null if unknown
100 protected NSView view() {
101 return null;
104 protected abstract String getBundleName();
106 protected int alert(final NSAlert alert) {
107 return alert.runModal();