/** * Convert collection * * @param array List of properties * @return Collection */ private List<String> toList(final NSArray array) { if(null == array) { return Collections.emptyList(); } final List<String> list = new ArrayList<>(); NSEnumerator ordered = array.objectEnumerator(); NSObject next; while(((next = ordered.nextObject()) != null)) { list.add(next.toString()); } return list; }
private Map<String, String> toMap(final NSDictionary dictionary) { if(null == dictionary) { return Collections.emptyMap(); } final Map<String, String> map = new HashMap<>(); NSEnumerator keys = dictionary.keyEnumerator(); NSObject key; while(((key = keys.nextObject()) != null)) { map.put(key.toString(), dictionary.objectForKey(key.toString()).toString()); } return map; } }
@Override public List<String> keys() { final NSArray array = dict.allKeys(); final NSEnumerator enumerator = array.objectEnumerator(); NSObject next; final List<String> keys = new ArrayList<>(); while((next = enumerator.nextObject()) != null) { if(next.isKindOfClass(Rococoa.createClass("NSString", NSString._Class.class))) { keys.add(Rococoa.cast(next, NSString.class).toString()); } } return keys; }
@Override public Map<String, String> mapForKey(final String key) { final NSObject value = dict.objectForKey(key); if(null == value) { return null; } if(value.isKindOfClass(Rococoa.createClass("NSArray", NSArray._Class.class))) { final NSDictionary dict = Rococoa.cast(value, NSDictionary.class); final NSEnumerator enumerator = dict.allKeys().objectEnumerator(); NSObject next; final Map<String, String> list = new HashMap<>(); while((next = enumerator.nextObject()) != null) { final String k = Rococoa.cast(next, NSString.class).toString(); list.put(k, Rococoa.cast(dict.objectForKey(k), NSString.class).toString()); } return list; } log.warn(String.format("Unexpected value type for serialized key %s", key)); return null; } }
@Override @SuppressWarnings("unchecked") public <T> List<T> listForKey(final String key) { final NSObject value = dict.objectForKey(key); if(null == value) { return null; } if(value.isKindOfClass(Rococoa.createClass("NSArray", NSArray._Class.class))) { final NSArray array = Rococoa.cast(value, NSArray.class); final NSEnumerator enumerator = array.objectEnumerator(); NSObject next; final List<T> list = new ArrayList<T>(); while((next = enumerator.nextObject()) != null) { if(next.isKindOfClass(Rococoa.createClass("NSDictionary", NSDictionary._Class.class))) { list.add((T) Rococoa.cast(next, NSDictionary.class)); } if(next.isKindOfClass(Rococoa.createClass("NSString", NSString._Class.class))) { list.add((T) Rococoa.cast(next, NSString.class).toString()); } } return list; } log.warn(String.format("Unexpected value type for serialized key %s", key)); return null; }
/** * @return Minimum size to fit content view of currently selected tab. */ private NSRect getContentRect() { NSRect contentRect = new NSRect(0, 0); final NSView view = tabView.selectedTabViewItem().view(); final NSEnumerator enumerator = view.subviews().objectEnumerator(); NSObject next; while(null != (next = enumerator.nextObject())) { final NSView subview = Rococoa.cast(next, NSView.class); contentRect = FoundationKitFunctionsLibrary.NSUnionRect(contentRect, subview.frame()); } return contentRect; } }
@Override public Collection<S> readCollection(final Local file) throws AccessDeniedException { if(!file.exists()) { throw new LocalAccessDeniedException(file.getAbsolute()); } final Collection<S> c = new Collection<S>(); NSArray list = NSArray.arrayWithContentsOfFile(file.getAbsolute()); if(null == list) { log.error(String.format("Invalid bookmark file %s", file)); return c; } final NSEnumerator i = list.objectEnumerator(); NSObject next; while(((next = i.nextObject()) != null)) { if(next.isKindOfClass(Rococoa.createClass("NSDictionary", NSDictionary._Class.class))) { final NSDictionary dict = Rococoa.cast(next, NSDictionary.class); final S object = this.deserialize(dict); if(null == object) { continue; } c.add(object); } } return c; }
@Override public void awakeFromNib() { // Reset NSEnumerator items = this.tabView.tabViewItems().objectEnumerator(); NSObject object; while(((object = items.nextObject()) != null)) { this.tabView.removeTabViewItem(Rococoa.cast(object, NSTabViewItem.class)); } // Insert all panels into tab view for(Map.Entry<Label, NSView> tab : this.getPanels().entrySet()) { final NSTabViewItem item = NSTabViewItem.itemWithIdentifier(tab.getKey().identifier); item.setView(tab.getValue()); item.setLabel(tab.getKey().label); this.tabView.addTabViewItem(item); } // Set up toolbar properties: Allow customization, give a default display mode, and remember state in user defaults toolbar.setAllowsUserCustomization(false); toolbar.setSizeMode(this.getToolbarSize()); toolbar.setDisplayMode(this.getToolbarMode()); toolbar.setDelegate(this.id()); window.setToolbar(toolbar); // Change selection to last selected item in preferences final int index = preferences.getInteger(String.format("%s.selected", this.getToolbarName())); this.setSelectedPanel(index < this.getPanels().size() ? index : 0); this.setTitle(this.getTitle(tabView.selectedTabViewItem())); super.awakeFromNib(); }
boolean parentFound = false; Local parent = null; while((next = iterator.nextObject()) != null) { final Local local = LocalFactory.get(next.toString()); final Local localParent = local.getParent();
final NSEnumerator collectionsEnumerator = collections.objectEnumerator(); NSObject next; while(((next = collectionsEnumerator.nextObject()) != null)) { final TransmitFavoriteCollection collection = Rococoa.cast(next, TransmitFavoriteCollection.class); if("History".equals(collection.name())) { NSEnumerator favoritesEnumerator = favorites.objectEnumerator(); NSObject favorite; while((favorite = favoritesEnumerator.nextObject()) != null) { this.parse(protocols, Rococoa.cast(favorite, TransmitFavorite.class));
@Override public void run() { final NSOpenPanel panel = NSOpenPanel.openPanel(); panel.setCanChooseDirectories(file.isDirectory()); panel.setCanChooseFiles(file.isFile()); panel.setAllowsMultipleSelection(false); panel.setMessage(MessageFormat.format(LocaleFactory.localizedString("Select {0}", "Credentials"), file.getAbbreviatedPath())); panel.setPrompt(LocaleFactory.localizedString("Choose")); final NSInteger modal = panel.runModal(file.getParent().getAbsolute(), file.getName()); if(modal.intValue() == SheetCallback.DEFAULT_OPTION) { final NSArray filenames = panel.filenames(); final NSEnumerator enumerator = filenames.objectEnumerator(); NSObject next; while((next = enumerator.nextObject()) != null) { selected.set(new FinderLocal(next.toString())); } } panel.orderOut(null); } };
protected NSRect getFrame(final NSAlert alert, final NSView accessory) { final NSRect frame = new NSRect(alert.window().frame().size.width.doubleValue(), accessory.frame().size.height.doubleValue()); final NSEnumerator enumerator = accessory.subviews().objectEnumerator(); NSObject next; while(null != (next = enumerator.nextObject())) { final NSView subview = Rococoa.cast(next, NSView.class); frame.size.height = new CGFloat(frame.size.height.doubleValue() + subview.frame().size.height.doubleValue() + SUBVIEWS_VERTICAL_SPACE * 2); } return frame; }
protected void focus(final NSAlert alert) { NSEnumerator buttons = alert.buttons().objectEnumerator(); NSObject button; while(((button = buttons.nextObject()) != null)) { final NSButton b = Rococoa.cast(button, NSButton.class); b.setTarget(this.id()); b.setAction(Foundation.selector("closeSheet:")); } final NSView accessory = this.getAccessoryView(alert); if(accessory != null) { final NSRect frame = this.getFrame(alert, accessory); accessory.setFrameSize(frame.size); alert.setAccessoryView(accessory); alert.window().makeFirstResponder(accessory); } // First call layout and then do any special positioning and sizing of the accessory view prior to running the alert alert.layout(); alert.window().recalculateKeyViewLoop(); }