Search in sources :

Example 1 with NSPoint

use of org.rococoa.cocoa.foundation.NSPoint in project cyberduck by iterate-ch.

the class ToolbarWindowController method resize.

/**
 * Resize window frame to fit the content view of the currently selected tab.
 */
private void resize() {
    final NSRect windowFrame = NSWindow.contentRectForFrameRect_styleMask(window.frame(), window.styleMask());
    final double height = this.getMinWindowHeight();
    final NSRect frameRect = new NSRect(new NSPoint(windowFrame.origin.x.doubleValue(), windowFrame.origin.y.doubleValue() + windowFrame.size.height.doubleValue() - height), new NSSize(windowFrame.size.width.doubleValue(), height));
    window.setFrame_display_animate(NSWindow.frameRectForContentRect_styleMask(frameRect, window.styleMask()), true, window.isVisible());
}
Also used : NSSize(org.rococoa.cocoa.foundation.NSSize) NSPoint(org.rococoa.cocoa.foundation.NSPoint) NSRect(org.rococoa.cocoa.foundation.NSRect)

Example 2 with NSPoint

use of org.rococoa.cocoa.foundation.NSPoint in project cyberduck by iterate-ch.

the class NSImageIconCache method badge.

/**
 * Overlay badge image.
 *
 * @param badge Overlay
 * @param icon  Icon
 * @return Cached icon
 */
private NSImage badge(final NSImage badge, final NSImage icon) {
    NSImage f = NSImage.imageWithSize(icon.size());
    f.lockFocus();
    icon.drawInRect(new NSRect(new NSPoint(0, 0), icon.size()), NSZeroRect, NSGraphics.NSCompositeSourceOver, 1.0f);
    badge.drawInRect(new NSRect(new NSPoint(0, 0), badge.size()), NSZeroRect, NSGraphics.NSCompositeSourceOver, 1.0f);
    f.unlockFocus();
    return f;
}
Also used : NSImage(ch.cyberduck.binding.application.NSImage) NSPoint(org.rococoa.cocoa.foundation.NSPoint) NSRect(org.rococoa.cocoa.foundation.NSRect)

Example 3 with NSPoint

use of org.rococoa.cocoa.foundation.NSPoint in project cyberduck by iterate-ch.

the class FolderController method getAccessoryView.

public NSView getAccessoryView(final NSAlert alert) {
    if (this.hasLocation()) {
        view = NSView.create(new NSRect(alert.window().frame().size.width.doubleValue(), 0));
        regionPopup = NSPopUpButton.buttonWithFrame(new NSRect(alert.window().frame().size.width.doubleValue(), 26));
        regions.stream().sorted(Comparator.comparing(Location.Name::toString)).forEach(region -> {
            regionPopup.addItemWithTitle(region.toString());
            regionPopup.itemWithTitle(region.toString()).setRepresentedObject(region.getIdentifier());
            if (region.equals(defaultRegion)) {
                regionPopup.selectItem(regionPopup.lastItem());
            }
        });
        // Override accessory view with location menu added
        regionPopup.setFrameOrigin(new NSPoint(0, 0));
        view.addSubview(regionPopup);
        inputField.setFrameOrigin(new NSPoint(0, this.getFrame(alert, view).size.height.doubleValue() + view.subviews().count().doubleValue() * SUBVIEWS_VERTICAL_SPACE));
        view.addSubview(inputField);
        return view;
    }
    return super.getAccessoryView(alert);
}
Also used : NSPoint(org.rococoa.cocoa.foundation.NSPoint) NSRect(org.rococoa.cocoa.foundation.NSRect)

Example 4 with NSPoint

use of org.rococoa.cocoa.foundation.NSPoint in project cyberduck by iterate-ch.

the class InfoController method setAclTable.

public void setAclTable(final NSTableView t) {
    this.aclTable = t;
    this.aclTable.setAllowsMultipleSelection(true);
    this.aclPermissionCellPrototype.setFont(NSFont.systemFontOfSize(NSFont.smallSystemFontSize()));
    this.aclPermissionCellPrototype.setControlSize(NSCell.NSSmallControlSize);
    this.aclPermissionCellPrototype.setCompletes(false);
    this.aclPermissionCellPrototype.setBordered(false);
    this.aclPermissionCellPrototype.setButtonBordered(false);
    this.aclTable.setColumnAutoresizingStyle(NSTableView.NSTableViewUniformColumnAutoresizingStyle);
    this.aclTable.tableColumnWithIdentifier(AclColumn.PERMISSION.name()).setDataCell(aclPermissionCellPrototype);
    this.aclTable.setDataSource((aclTableModel = new ListDataSource() {

        @Override
        public NSInteger numberOfRowsInTableView(NSTableView view) {
            return new NSInteger(acl.size());
        }

        public NSObject tableView_objectValueForTableColumn_row(NSTableView view, NSTableColumn tableColumn, NSInteger row) {
            if (row.intValue() < acl.size()) {
                final String identifier = tableColumn.identifier();
                final Acl.UserAndRole grant = acl.get(row.intValue());
                if (identifier.equals(AclColumn.GRANTEE.name())) {
                    return NSString.stringWithString(grant.getUser().getDisplayName());
                }
                if (identifier.equals(AclColumn.PERMISSION.name())) {
                    return NSString.stringWithString(grant.getRole().getName());
                }
            }
            return null;
        }

        @Override
        public void tableView_setObjectValue_forTableColumn_row(NSTableView view, NSObject value, NSTableColumn c, NSInteger row) {
            if (row.intValue() < acl.size()) {
                final Acl.UserAndRole grant = acl.get(row.intValue());
                if (c.identifier().equals(AclColumn.GRANTEE.name())) {
                    grant.getUser().setIdentifier(value.toString());
                }
                if (c.identifier().equals(AclColumn.PERMISSION.name())) {
                    grant.getRole().setName(value.toString());
                }
                if (StringUtils.isNotBlank(grant.getUser().getIdentifier()) && StringUtils.isNotBlank(grant.getRole().getName())) {
                    InfoController.this.aclInputDidEndEditing();
                }
            }
        }
    }).id());
    this.aclTable.setDelegate((aclTableDelegate = new AbstractTableDelegate<Acl.UserAndRole, AclColumn>(aclTable.tableColumnWithIdentifier(AclColumn.GRANTEE.name())) {

        @Override
        public boolean isColumnRowEditable(NSTableColumn column, NSInteger row) {
            if (column.identifier().equals(AclColumn.GRANTEE.name())) {
                final Acl.UserAndRole grant = acl.get(row.intValue());
                if (grant.getUser().isEditable()) {
                    return true;
                }
                // Group Grantee identifier is not editable
                return false;
            }
            if (column.identifier().equals(AclColumn.PERMISSION.name())) {
                final Acl.UserAndRole grant = acl.get(row.intValue());
                if (grant.getRole().isEditable()) {
                    return true;
                }
                // Static role that cannot be modified
                return false;
            }
            return true;
        }

        @Override
        public void tableRowDoubleClicked(final ID sender) {
            this.enterKeyPressed(sender);
        }

        @Override
        public void enterKeyPressed(final ID sender) {
            aclTable.editRow(aclTable.columnWithIdentifier(AclColumn.GRANTEE.name()), aclTable.selectedRow(), true);
        }

        @Override
        public void deleteKeyPressed(final ID sender) {
            aclRemoveButtonClicked(sender);
        }

        public String tableView_toolTipForCell_rect_tableColumn_row_mouseLocation(NSTableView t, NSCell cell, ID rect, NSTableColumn c, NSInteger row, NSPoint mouseLocation) {
            return this.tooltip(acl.get(row.intValue()), AclColumn.valueOf(c.identifier()));
        }

        @Override
        public String tooltip(Acl.UserAndRole c, final AclColumn column) {
            return c.getUser().getIdentifier();
        }

        @Override
        public void tableColumnClicked(NSTableView view, NSTableColumn c) {
        // 
        }

        @Override
        public void selectionDidChange(final NSNotification notification) {
            aclRemoveButton.setEnabled(aclTable.numberOfSelectedRows().intValue() > 0);
        }

        public void tableView_willDisplayCell_forTableColumn_row(NSTableView view, NSCell cell, NSTableColumn c, NSInteger row) {
            final Acl.UserAndRole grant = acl.get(row.intValue());
            if (c.identifier().equals(AclColumn.GRANTEE.name())) {
                final NSTextFieldCell textFieldCell = Rococoa.cast(cell, NSTextFieldCell.class);
                textFieldCell.setPlaceholderString(grant.getUser().getPlaceholder());
                if (grant.getUser().isEditable()) {
                    textFieldCell.setTextColor(NSColor.controlTextColor());
                } else {
                    // Group Grantee identifier is not editable
                    textFieldCell.setTextColor(NSColor.disabledControlTextColor());
                }
            }
            if (c.identifier().equals(AclColumn.PERMISSION.name())) {
                if (grant.getRole().isEditable()) {
                    cell.setEnabled(true);
                } else {
                    cell.setEnabled(false);
                }
            }
        }

        @Override
        protected boolean isTypeSelectSupported() {
            return false;
        }
    }).id());
    this.aclTable.sizeToFit();
}
Also used : NSObject(ch.cyberduck.binding.foundation.NSObject) NSNotification(ch.cyberduck.binding.foundation.NSNotification) NSPoint(org.rococoa.cocoa.foundation.NSPoint) AbstractTableDelegate(ch.cyberduck.binding.AbstractTableDelegate) NSMutableAttributedString(ch.cyberduck.binding.foundation.NSMutableAttributedString) NSString(ch.cyberduck.binding.foundation.NSString) NSAttributedString(ch.cyberduck.binding.foundation.NSAttributedString) ListDataSource(ch.cyberduck.binding.ListDataSource) NSInteger(org.rococoa.cocoa.foundation.NSInteger) ID(org.rococoa.ID)

Example 5 with NSPoint

use of org.rococoa.cocoa.foundation.NSPoint in project cyberduck by iterate-ch.

the class VaultController method getAccessoryView.

public NSView getAccessoryView(final NSAlert alert) {
    view = NSView.create(new NSRect(alert.window().frame().size.width.doubleValue(), 0));
    confirmField = NSSecureTextField.textfieldWithFrame(new NSRect(alert.window().frame().size.width.doubleValue(), 22));
    confirmField.cell().setPlaceholderString(LocaleFactory.localizedString("Confirm Passphrase", "Cryptomator"));
    confirmField.setFrameOrigin(new NSPoint(0, 0));
    view.addSubview(confirmField);
    strengthIndicator = NSLevelIndicator.levelIndicatorWithFrame(new NSRect(alert.window().frame().size.width.doubleValue(), 18));
    if (strengthIndicator.respondsToSelector(Foundation.selector("setLevelIndicatorStyle:"))) {
        strengthIndicator.setLevelIndicatorStyle(NSLevelIndicator.NSDiscreteCapacityLevelIndicatorStyle);
    }
    strengthIndicator.setFrameOrigin(new NSPoint(0, this.getFrame(alert, view).size.height.doubleValue() + view.subviews().count().doubleValue() * SUBVIEWS_VERTICAL_SPACE));
    view.addSubview(strengthIndicator);
    passwordField = NSSecureTextField.textfieldWithFrame(new NSRect(alert.window().frame().size.width.doubleValue(), 22));
    passwordField.cell().setPlaceholderString(LocaleFactory.localizedString("Passphrase", "Cryptomator"));
    notificationCenter.addObserver(this.id(), Foundation.selector("passwordFieldTextDidChange:"), NSControl.NSControlTextDidChangeNotification, passwordField.id());
    passwordField.setFrameOrigin(new NSPoint(0, this.getFrame(alert, view).size.height.doubleValue() + view.subviews().count().doubleValue() * SUBVIEWS_VERTICAL_SPACE));
    view.addSubview(passwordField);
    final NSView accessory = super.getAccessoryView(alert);
    accessory.setFrameSize(this.getFrame(alert, accessory).size);
    accessory.setFrameOrigin(new NSPoint(0, this.getFrame(alert, view).size.height.doubleValue() + view.subviews().count().doubleValue() * SUBVIEWS_VERTICAL_SPACE));
    view.addSubview(accessory);
    return view;
}
Also used : NSPoint(org.rococoa.cocoa.foundation.NSPoint) NSRect(org.rococoa.cocoa.foundation.NSRect) NSView(ch.cyberduck.binding.application.NSView)

Aggregations

NSPoint (org.rococoa.cocoa.foundation.NSPoint)13 NSRect (org.rococoa.cocoa.foundation.NSRect)9 NSSize (org.rococoa.cocoa.foundation.NSSize)3 NSEvent (ch.cyberduck.binding.application.NSEvent)2 NSAttributedString (ch.cyberduck.binding.foundation.NSAttributedString)2 AbstractTableDelegate (ch.cyberduck.binding.AbstractTableDelegate)1 ListDataSource (ch.cyberduck.binding.ListDataSource)1 NSImage (ch.cyberduck.binding.application.NSImage)1 NSView (ch.cyberduck.binding.application.NSView)1 NSMutableAttributedString (ch.cyberduck.binding.foundation.NSMutableAttributedString)1 NSNotification (ch.cyberduck.binding.foundation.NSNotification)1 NSObject (ch.cyberduck.binding.foundation.NSObject)1 NSString (ch.cyberduck.binding.foundation.NSString)1 Path (ch.cyberduck.core.Path)1 Location (ch.cyberduck.core.features.Location)1 PathPasteboard (ch.cyberduck.core.pasteboard.PathPasteboard)1 LinkedHashSet (java.util.LinkedHashSet)1 ID (org.rococoa.ID)1 NSInteger (org.rococoa.cocoa.foundation.NSInteger)1 NSUInteger (org.rococoa.cocoa.foundation.NSUInteger)1