public void setHighlighted(final boolean h) { highlighted = h; statusField.setTextColor(h ? NSColor.whiteColor() : NSColor.textColor()); progressField.setTextColor(h ? NSColor.whiteColor() : NSColor.darkGrayColor()); messageField.setTextColor(h ? NSColor.whiteColor() : NSColor.darkGrayColor()); this.setMenuHighlighted(h); }
public void drawRect(NSRect rect) { NSMutableRect verticalLineRect; super.drawRect(rect); if ((_scalePopUpButton != null) && (_scalePopUpButton.superview() != null)) { verticalLineRect = new NSMutableRect(_scalePopUpButton.frame()); verticalLineRect.setX(verticalLineRect.maxX()); verticalLineRect.setWidth(1.0f); if (verticalLineRect.intersectsRect(rect)) { NSColor.blackColor().set(); NSBezierPath.bezierPathWithRect(verticalLineRect).fill(); } } }
private void init() { window.setTitle(host.getNickname()); this.updateField(hostField, host.getHostname()); hostField.setEnabled(host.getProtocol().isHostnameConfigurable()); hostField.cell().setPlaceholderString(host.getProtocol().getDefaultHostname()); this.updateField(nicknameField, host.getNickname()); final String url; if (StringUtils.isNotBlank(host.getDefaultPath())) { url = host.toURL() + Path.normalize(host.getDefaultPath()); } else { url = host.toURL(); } urlField.setAttributedStringValue(HyperlinkAttributedStringFactory.create(url)); this.updateField(portField, String.valueOf(host.getPort())); portField.setEnabled(host.getProtocol().isPortConfigurable()); this.updateField(pathField, host.getDefaultPath()); this.updateField(usernameField, host.getCredentials().getUsername()); usernameField.cell().setPlaceholderString(host.getProtocol().getUsernamePlaceholder()); usernameField.setEnabled(!host.getCredentials().isAnonymousLogin()); anonymousCheckbox.setEnabled(host.getProtocol().isAnonymousConfigurable()); anonymousCheckbox.setState( host.getCredentials().isAnonymousLogin() ? NSCell.NSOnState : NSCell.NSOffState); protocolPopup.selectItemAtIndex( protocolPopup.indexOfItemWithRepresentedObject( String.valueOf(host.getProtocol().hashCode()))); if (null == host.getMaxConnections()) { transferPopup.selectItemWithTitle(DEFAULT); } else { transferPopup.selectItemWithTitle( host.getMaxConnections() == 1 ? TRANSFER_BROWSERCONNECTION : TRANSFER_NEWCONNECTION); } encodingPopup.setEnabled(host.getProtocol().isEncodingConfigurable()); connectmodePopup.setEnabled(host.getProtocol().isConnectModeConfigurable()); if (host.getProtocol().isConnectModeConfigurable()) { if (null == host.getFTPConnectMode()) { connectmodePopup.selectItemWithTitle(DEFAULT); } else if (host.getFTPConnectMode().equals(FTPConnectMode.PASV)) { connectmodePopup.selectItemWithTitle(CONNECTMODE_PASSIVE); } else if (host.getFTPConnectMode().equals(FTPConnectMode.PORT)) { connectmodePopup.selectItemWithTitle(CONNECTMODE_ACTIVE); } } pkCheckbox.setEnabled(host.getProtocol().equals(Protocol.SFTP)); if (host.getCredentials().isPublicKeyAuthentication()) { pkCheckbox.setState(NSCell.NSOnState); this.updateField(pkLabel, host.getCredentials().getIdentity().getAbbreviatedPath()); pkLabel.setTextColor(NSColor.textColor()); } else { pkCheckbox.setState(NSCell.NSOffState); pkLabel.setStringValue(Locale.localizedString("No private key selected")); pkLabel.setTextColor(NSColor.disabledControlTextColor()); } webURLField.setEnabled(host.getProtocol().isWebUrlConfigurable()); final String webURL = host.getWebURL(); webUrlImage.setToolTip(webURL); this.updateField(webURLField, host.getDefaultWebURL().equals(webURL) ? null : webURL); this.updateField(commentField, host.getComment()); this.timezonePopup.setEnabled(!host.getProtocol().isUTCTimezone()); if (null == host.getTimezone()) { if (host.getProtocol().isUTCTimezone()) { this.timezonePopup.setTitle(UTC.getID()); } else { if (Preferences.instance().getBoolean("ftp.timezone.auto")) { this.timezonePopup.setTitle(AUTO); } else { this.timezonePopup.setTitle( TimeZone.getTimeZone(Preferences.instance().getProperty("ftp.timezone.default")) .getID()); } } } else { this.timezonePopup.setTitle(host.getTimezone().getID()); } }
/** @version $Id: ProgressController.java 10996 2013-05-02 16:39:36Z dkocher $ */ public class ProgressController extends BundleController { private Transfer transfer; /** Keeping track of the current transfer rate */ private TransferSpeedometer meter; /** * The current connection status message * * @see ch.cyberduck.core.ProgressListener#message(String) */ private String messageText; public ProgressController(final Transfer transfer) { this.transfer = transfer; this.meter = new TransferSpeedometer(transfer); this.init(); } private ProgressListener pl; private TransferListener tl; @Override protected void invalidate() { for (Session s : transfer.getSessions()) { s.removeProgressListener(pl); } transfer.removeListener(tl); filesPopup.menu().setDelegate(null); super.invalidate(); } @Override protected String getBundleName() { return "Progress.nib"; } private void init() { this.loadBundle(); this.transfer.addListener( tl = new TransferAdapter() { /** Timer to update the progress indicator */ private ScheduledFuture progressTimer; static final long delay = 0; static final long period = 500; // in milliseconds @Override public void transferWillStart() { invoke( new DefaultMainAction() { @Override public void run() { pl = new ProgressListener() { @Override public void message(final String message) { messageText = message; invoke( new DefaultMainAction() { @Override public void run() { setMessageText(); } }); } }; for (Session s : transfer.getSessions()) { s.addProgressListener(pl); } progressBar.setHidden(false); progressBar.setIndeterminate(true); progressBar.startAnimation(null); statusIconView.setImage(YELLOW_ICON); setProgressText(); setStatusText(); } }); } @Override public void transferDidEnd() { invoke( new DefaultMainAction() { @Override public void run() { for (Session s : transfer.getSessions()) { s.removeProgressListener(pl); } progressBar.stopAnimation(null); progressBar.setIndeterminate(true); progressBar.setHidden(true); messageText = null; setMessageText(); setProgressText(); setStatusText(); statusIconView.setImage(transfer.isComplete() ? GREEN_ICON : RED_ICON); } }); } @Override public void willTransferPath(final Path path) { meter.reset(); progressTimer = getTimerPool() .scheduleAtFixedRate( new Runnable() { @Override public void run() { invoke( new DefaultMainAction() { @Override public void run() { setProgressText(); final double transferred = transfer.getTransferred(); final double size = transfer.getSize(); if (transferred > 0 && size > 0) { progressBar.setIndeterminate(false); progressBar.setMaxValue(size); progressBar.setDoubleValue(transferred); } } }); } }, delay, period, TimeUnit.MILLISECONDS); } @Override public void didTransferPath(final Path path) { boolean canceled = false; while (!canceled) { canceled = progressTimer.cancel(false); } meter.reset(); } @Override public void bandwidthChanged(BandwidthThrottle bandwidth) { meter.reset(); } }); } /** Resets both the progress and status field */ @Override public void awakeFromNib() { this.setProgressText(); this.setMessageText(); this.setStatusText(); super.awakeFromNib(); } private void setMessageText() { StringBuilder b = new StringBuilder(); if (null == messageText) { // Do not display any progress text when transfer is stopped final Date timestamp = transfer.getTimestamp(); if (null != timestamp) { messageText = UserDateFormatterFactory.get().getLongFormat(timestamp.getTime()); } } if (messageText != null) { b.append(messageText); } messageField.setAttributedStringValue( NSAttributedString.attributedStringWithAttributes( b.toString(), TRUNCATE_MIDDLE_ATTRIBUTES)); } private void setProgressText() { progressField.setAttributedStringValue( NSAttributedString.attributedStringWithAttributes( meter.getProgress(), TRUNCATE_MIDDLE_ATTRIBUTES)); } private void setStatusText() { statusField.setAttributedStringValue( NSAttributedString.attributedStringWithAttributes( transfer.isRunning() ? StringUtils.EMPTY : Locale.localizedString(transfer.getStatus(), "Status"), TRUNCATE_MIDDLE_ATTRIBUTES)); } private static final NSDictionary NORMAL_FONT_ATTRIBUTES = NSDictionary.dictionaryWithObjectsForKeys( NSArray.arrayWithObjects( NSFont.systemFontOfSize(NSFont.smallSystemFontSize()), TableCellAttributes.PARAGRAPH_STYLE_LEFT_ALIGNMENT_TRUNCATE_TAIL), NSArray.arrayWithObjects( NSAttributedString.FontAttributeName, NSAttributedString.ParagraphStyleAttributeName)); private static final NSDictionary HIGHLIGHTED_FONT_ATTRIBUTES = NSDictionary.dictionaryWithObjectsForKeys( NSArray.arrayWithObjects( NSFont.systemFontOfSize(NSFont.smallSystemFontSize()), NSColor.whiteColor(), TableCellAttributes.PARAGRAPH_STYLE_LEFT_ALIGNMENT_TRUNCATE_TAIL), NSArray.arrayWithObjects( NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName, NSAttributedString.ParagraphStyleAttributeName)); private static final NSDictionary DARK_FONT_ATTRIBUTES = NSDictionary.dictionaryWithObjectsForKeys( NSArray.arrayWithObjects( NSFont.systemFontOfSize(NSFont.smallSystemFontSize()), NSColor.darkGrayColor(), TableCellAttributes.PARAGRAPH_STYLE_LEFT_ALIGNMENT_TRUNCATE_TAIL), NSArray.arrayWithObjects( NSAttributedString.FontAttributeName, NSAttributedString.ForegroundColorAttributeName, NSAttributedString.ParagraphStyleAttributeName)); private boolean highlighted; public boolean isHighlighted() { return highlighted; } public void setHighlighted(final boolean h) { highlighted = h; statusField.setTextColor(h ? NSColor.whiteColor() : NSColor.textColor()); progressField.setTextColor(h ? NSColor.whiteColor() : NSColor.darkGrayColor()); messageField.setTextColor(h ? NSColor.whiteColor() : NSColor.darkGrayColor()); this.setMenuHighlighted(h); } private void setMenuHighlighted(boolean highlighted) { for (int i = 0; i < filesPopup.numberOfItems().intValue(); i++) { filesPopup .itemAtIndex(new NSInteger(i)) .setAttributedTitle( NSAttributedString.attributedStringWithAttributes( filesPopup.itemAtIndex(new NSInteger(i)).title(), highlighted ? HIGHLIGHTED_FONT_ATTRIBUTES : NORMAL_FONT_ATTRIBUTES)); } } // ---------------------------------------------------------- // Outlets // ---------------------------------------------------------- @Outlet private NSPopUpButton filesPopup; private AbstractMenuDelegate filesPopupMenuDelegate; public void setFilesPopup(final NSPopUpButton p) { this.filesPopup = p; this.filesPopup.setTarget(this.id()); this.filesPopup.removeAllItems(); for (Path path : transfer.getRoots()) { NSMenuItem item = this.filesPopup .menu() .addItemWithTitle_action_keyEquivalent( path.getName(), Foundation.selector("reveal:"), StringUtils.EMPTY); item.setRepresentedObject(path.getAbsolute()); item.setImage(IconCache.instance().iconForPath(path, 16, false)); } this.filesPopupMenuDelegate = new TransferMenuDelegate(transfer); this.filesPopup.menu().setDelegate(this.filesPopupMenuDelegate.id()); NSNotificationCenter.defaultCenter() .addObserver( this.id(), Foundation.selector("filesPopupWillShow:"), NSPopUpButton.PopUpButtonWillPopUpNotification, this.filesPopup); NSNotificationCenter.defaultCenter() .addObserver( this.id(), Foundation.selector("filesPopupWillHide:"), "NSMenuDidEndTrackingNotification", this.filesPopup.menu()); } @Action public void filesPopupWillShow(final NSNotification sender) { this.setMenuHighlighted(false); } @Action public void filesPopupWillHide(final NSNotification sender) { this.setMenuHighlighted(highlighted); } @Outlet private NSTextField progressField; public void setProgressField(final NSTextField f) { this.progressField = f; this.progressField.setEditable(false); this.progressField.setSelectable(false); this.progressField.setTextColor(NSColor.darkGrayColor()); } @Outlet private NSTextField statusField; public void setStatusField(final NSTextField f) { this.statusField = f; this.statusField.setEditable(false); this.statusField.setSelectable(false); this.statusField.setTextColor(NSColor.darkGrayColor()); } @Outlet private NSTextField messageField; public void setMessageField(final NSTextField f) { this.messageField = f; this.messageField.setEditable(false); this.messageField.setSelectable(false); this.messageField.setTextColor(NSColor.darkGrayColor()); } @Outlet private NSProgressIndicator progressBar; public void setProgressBar(final NSProgressIndicator p) { this.progressBar = p; this.progressBar.setDisplayedWhenStopped(false); this.progressBar.setUsesThreadedAnimation(true); this.progressBar.setControlSize(NSCell.NSSmallControlSize); this.progressBar.setStyle(NSProgressIndicator.NSProgressIndicatorBarStyle); this.progressBar.setMinValue(0); } @Outlet private NSImageView statusIconView; private static final NSImage RED_ICON = IconCache.iconNamed("statusRed.tiff"); private static final NSImage GREEN_ICON = IconCache.iconNamed("statusGreen.tiff"); private static final NSImage YELLOW_ICON = IconCache.iconNamed("statusYellow.tiff"); public void setStatusIconView(final NSImageView statusIconView) { this.statusIconView = statusIconView; this.statusIconView.setImage(transfer.isComplete() ? GREEN_ICON : RED_ICON); } @Outlet private NSImageView iconImageView; public void setIconImageView(final NSImageView iconImageView) { this.iconImageView = iconImageView; this.iconImageView.setImage(IconCache.iconNamed(transfer.getImage(), 32)); } /** The view drawn in the table cell */ private NSView progressView; public void setProgressView(final NSView v) { this.progressView = v; } @Override public NSView view() { return this.progressView; } }
public void setMessageField(final NSTextField f) { this.messageField = f; this.messageField.setEditable(false); this.messageField.setSelectable(false); this.messageField.setTextColor(NSColor.darkGrayColor()); }
/** * Displays the Tracker rectangles for manipulation by the user. Returns when the user has either * finished manipulating the rectangles or has cancelled the Tracker. * * @return <code>true</code> if the user did not cancel the Tracker, <code>false</code> otherwise * @exception SWTException * <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver * </ul> */ public boolean open() { checkWidget(); Display display = this.display; cancelled = false; tracking = true; window = (NSWindow) new NSWindow().alloc(); NSArray screens = NSScreen.screens(); double /*float*/ minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE; double /*float*/ minY = Float.MAX_VALUE, maxY = Float.MIN_VALUE; int count = (int) /*64*/ screens.count(); for (int i = 0; i < count; i++) { NSScreen screen = new NSScreen(screens.objectAtIndex(i)); NSRect frame = screen.frame(); double /*float*/ x1 = frame.x, x2 = frame.x + frame.width; double /*float*/ y1 = frame.y, y2 = frame.y + frame.height; if (x1 < minX) minX = x1; if (x2 < minX) minX = x2; if (x1 > maxX) maxX = x1; if (x2 > maxX) maxX = x2; if (y1 < minY) minY = y1; if (y2 < minY) minY = y2; if (y1 > maxY) maxY = y1; if (y2 > maxY) maxY = y2; } NSRect frame = new NSRect(); frame.x = minX; frame.y = minY; frame.width = maxX - minX; frame.height = maxY - minY; window = window.initWithContentRect( frame, OS.NSBorderlessWindowMask, OS.NSBackingStoreBuffered, false); window.setOpaque(false); window.setLevel(OS.NSStatusWindowLevel); window.setContentView(null); window.setBackgroundColor(NSColor.clearColor()); NSGraphicsContext context = window.graphicsContext(); NSGraphicsContext.static_saveGraphicsState(); NSGraphicsContext.setCurrentContext(context); context.setCompositingOperation(OS.NSCompositeClear); frame.x = frame.y = 0; NSBezierPath.fillRect(frame); NSGraphicsContext.static_restoreGraphicsState(); window.orderFrontRegardless(); drawRectangles(window, rectangles, false); /* * If exactly one of UP/DOWN is specified as a style then set the cursor * orientation accordingly (the same is done for LEFT/RIGHT styles below). */ int vStyle = style & (SWT.UP | SWT.DOWN); if (vStyle == SWT.UP || vStyle == SWT.DOWN) { cursorOrientation |= vStyle; } int hStyle = style & (SWT.LEFT | SWT.RIGHT); if (hStyle == SWT.LEFT || hStyle == SWT.RIGHT) { cursorOrientation |= hStyle; } Point cursorPos; boolean down = false; NSApplication application = NSApplication.sharedApplication(); NSEvent currentEvent = application.currentEvent(); if (currentEvent != null) { switch ((int) /*64*/ currentEvent.type()) { case OS.NSLeftMouseDown: case OS.NSLeftMouseDragged: case OS.NSRightMouseDown: case OS.NSRightMouseDragged: case OS.NSOtherMouseDown: case OS.NSOtherMouseDragged: down = true; } } if (down) { cursorPos = display.getCursorLocation(); } else { if ((style & SWT.RESIZE) != 0) { cursorPos = adjustResizeCursor(true); } else { cursorPos = adjustMoveCursor(); } } if (cursorPos != null) { oldX = cursorPos.x; oldY = cursorPos.y; } Control oldTrackingControl = display.trackingControl; display.trackingControl = null; /* Tracker behaves like a Dialog with its own OS event loop. */ while (tracking && !cancelled) { display.addPool(); try { if (parent != null && parent.isDisposed()) break; display.runSkin(); display.runDeferredLayouts(); NSEvent event = application.nextEventMatchingMask( 0, NSDate.distantFuture(), OS.NSDefaultRunLoopMode, true); if (event == null) continue; int type = (int) /*64*/ event.type(); switch (type) { case OS.NSLeftMouseUp: case OS.NSRightMouseUp: case OS.NSOtherMouseUp: case OS.NSMouseMoved: case OS.NSLeftMouseDragged: case OS.NSRightMouseDragged: case OS.NSOtherMouseDragged: mouse(event); break; case OS.NSKeyDown: case OS.NSKeyUp: case OS.NSFlagsChanged: key(event); break; } boolean dispatch = true; switch (type) { case OS.NSLeftMouseDown: case OS.NSLeftMouseUp: case OS.NSRightMouseDown: case OS.NSRightMouseUp: case OS.NSOtherMouseDown: case OS.NSOtherMouseUp: case OS.NSMouseMoved: case OS.NSLeftMouseDragged: case OS.NSRightMouseDragged: case OS.NSOtherMouseDragged: case OS.NSMouseEntered: case OS.NSMouseExited: case OS.NSKeyDown: case OS.NSKeyUp: case OS.NSFlagsChanged: dispatch = false; } if (dispatch) application.sendEvent(event); if (clientCursor != null && resizeCursor == null) { display.lockCursor = false; clientCursor.handle.set(); display.lockCursor = true; } display.runAsyncMessages(false); } finally { display.removePool(); } } /* * Cleanup: If this tracker was resizing then the last cursor that it created * needs to be destroyed. */ if (resizeCursor != null) resizeCursor.dispose(); resizeCursor = null; if (oldTrackingControl != null && !oldTrackingControl.isDisposed()) { display.trackingControl = oldTrackingControl; } display.setCursor(display.findControl(true)); if (!isDisposed()) { drawRectangles(window, rectangles, true); } if (window != null) window.close(); tracking = false; window = null; return !cancelled; }