public void tile() {
    /* Let the superclass do most of the work. */
    super.tile();

    if (!hasHorizontalScroller()) {
      if (null != _scalePopUpButton) {
        _scalePopUpButton.removeFromSuperview();
        _scalePopUpButton = null;
      }
    } else {
      if (_scalePopUpButton == null) makeScalePopUpButton();

      NSScroller horizScroller = horizontalScroller();
      NSMutableRect horizScrollerFrame = new NSMutableRect(horizScroller.frame());
      NSRect incrementLineFrame = horizScroller.rectForPart(NSScroller.IncrementLine);
      NSMutableRect buttonFrame = new NSMutableRect(_scalePopUpButton.frame());

      /* Adjust the horizontal scroller size and set the button size and location. */
      buttonFrame.setX(horizScrollerFrame.x());
      buttonFrame.setHeight(incrementLineFrame.height());
      buttonFrame.setY(horizScrollerFrame.y() + incrementLineFrame.y());

      horizScrollerFrame.setWidth(horizScrollerFrame.width() - (buttonFrame.width() + 1.0f));
      horizScrollerFrame.setX(horizScrollerFrame.x() + (buttonFrame.width() + 1.0f));
      horizScroller.setFrame(horizScrollerFrame);

      _scalePopUpButton.setFrame(buttonFrame);
    }
  }
Ejemplo n.º 2
0
 @Action
 public void encodingSelectionChanged(final NSPopUpButton sender) {
   log.debug("encodingSelectionChanged:" + sender);
   if (sender.selectedItem().title().equals(DEFAULT)) {
     host.setEncoding(null);
   } else {
     host.setEncoding(sender.selectedItem().title());
   }
   this.itemChanged();
 }
Ejemplo n.º 3
0
 @Action
 public void transferPopupClicked(final NSPopUpButton sender) {
   if (sender.selectedItem().title().equals(DEFAULT)) {
     host.setMaxConnections(null);
   } else if (sender.selectedItem().title().equals(TRANSFER_BROWSERCONNECTION)) {
     host.setMaxConnections(1);
   } else if (sender.selectedItem().title().equals(TRANSFER_NEWCONNECTION)) {
     host.setMaxConnections(-1);
   }
   this.itemChanged();
 }
Ejemplo n.º 4
0
 @Action
 public void connectmodePopupClicked(final NSPopUpButton sender) {
   if (sender.selectedItem().title().equals(DEFAULT)) {
     host.setFTPConnectMode(null);
   } else if (sender.selectedItem().title().equals(CONNECTMODE_ACTIVE)) {
     host.setFTPConnectMode(FTPConnectMode.PORT);
   } else if (sender.selectedItem().title().equals(CONNECTMODE_PASSIVE)) {
     host.setFTPConnectMode(FTPConnectMode.PASV);
   }
   this.itemChanged();
 }
  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();
      }
    }
  }
Ejemplo n.º 6
0
 @Action
 public void protocolSelectionChanged(final NSPopUpButton sender) {
   log.debug("protocolSelectionChanged:" + sender);
   final Protocol selected =
       ProtocolFactory.forName(protocolPopup.selectedItem().representedObject());
   host.setPort(selected.getDefaultPort());
   if (!host.getProtocol().isHostnameConfigurable()) {
     // Previously selected protocol had a default hostname. Change to default
     // of newly selected protocol.
     host.setHostname(selected.getDefaultHostname());
   }
   if (!selected.isHostnameConfigurable()) {
     // Hostname of newly selected protocol is not configurable. Change to default.
     host.setHostname(selected.getDefaultHostname());
   }
   if (StringUtils.isNotBlank(selected.getDefaultHostname())) {
     // Prefill with default hostname
     host.setHostname(selected.getDefaultHostname());
   }
   if (!selected.isWebUrlConfigurable()) {
     host.setWebURL(null);
   }
   host.setProtocol(selected);
   this.itemChanged();
   this.init();
   this.reachable();
 }
Ejemplo n.º 7
0
 public void downloadPathPanelDidEnd_returnCode_contextInfo(
     NSOpenPanel sheet, int returncode, ID contextInfo) {
   if (returncode == SheetCallback.DEFAULT_OPTION) {
     NSArray selected = sheet.filenames();
     if ((selected.lastObject()) != null) {
       host.setDownloadFolder(LocalFactory.createLocal(selected.lastObject().toString()));
     }
   }
   downloadPathPopup
       .itemAtIndex(new NSInteger(0))
       .setTitle(host.getDownloadFolder().getDisplayName());
   downloadPathPopup
       .itemAtIndex(new NSInteger(0))
       .setRepresentedObject(host.getDownloadFolder().getAbsolute());
   downloadPathPopup
       .itemAtIndex(new NSInteger(0))
       .setImage(IconCache.instance().iconForPath(host.getDownloadFolder(), 16));
   downloadPathPopup.selectItemAtIndex(new NSInteger(0));
   downloadPathPanel = null;
   this.itemChanged();
 }
Ejemplo n.º 8
0
 @Action
 public void timezonePopupClicked(NSPopUpButton sender) {
   String selected = sender.selectedItem().representedObject();
   if (selected.equals(AUTO)) {
     host.setTimezone(null);
   } else {
     String[] ids = TimeZone.getAvailableIDs();
     for (String id : ids) {
       TimeZone tz;
       if ((tz = TimeZone.getTimeZone(id)).getID().equals(selected)) {
         host.setTimezone(tz);
         break;
       }
     }
   }
   this.itemChanged();
 }
  protected void makeScalePopUpButton() {
    if (_scalePopUpButton == null) {
      /* Create the pop up button. */
      _scalePopUpButton = new NSPopUpButton(new NSRect(0f, 0f, 1f, 1f), false);
      _scalePopUpButton.setBezelStyle(NSButtonCell.RegularSquareBezelStyle);

      /* Fill it with the scales. */
      int numberOfDefaultItems = MenuLabels.length;
      for (int i = 0; i < numberOfDefaultItems; i++) {
        String label = NSBundle.localizedString(MenuLabels[i]);
        _scalePopUpButton.addItem(label);

        NSMenuItem item = (NSMenuItem) _scalePopUpButton.itemAtIndex(i);

        if (ScaleFactors[i] != 0f) {
          Number factor = new Float(ScaleFactors[i]);
          item.setRepresentedObject(factor);
        }
      }
      _scalePopUpButton.selectItemAtIndex(DefaultSelectedItem);

      /* Hook it up. */
      _scalePopUpButton.setTarget(this);
      _scalePopUpButton.setAction(new NSSelector("scalePopUpAction", new Class[] {getClass()}));

      /* Pick a suitable font. */
      _scalePopUpButton.setFont(NSFont.toolTipsFontOfSize(10f));

      /* Make sure the pop up is big enough to fit the cells. */
      _scalePopUpButton.sizeToFit();

      /* Don't ever let it become the first responder. */
      _scalePopUpButton.setRefusesFirstResponder(true);

      /* Put it in the scroll view. */
      addSubview(_scalePopUpButton);
    }
  }
Ejemplo n.º 10
0
 private void addDownloadPath(Selector action, Local f) {
   if (downloadPathPopup.menu().itemWithTitle(f.getDisplayName()) == null) {
     downloadPathPopup
         .menu()
         .addItemWithTitle_action_keyEquivalent(f.getDisplayName(), action, StringUtils.EMPTY);
     downloadPathPopup.lastItem().setTarget(this.id());
     downloadPathPopup.lastItem().setImage(IconCache.instance().iconForPath(f, 16));
     downloadPathPopup.lastItem().setRepresentedObject(f.getAbsolute());
     if (host.getDownloadFolder().equals(f)) {
       downloadPathPopup.selectItem(downloadPathPopup.lastItem());
     }
   }
 }
Ejemplo n.º 11
0
 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());
   }
 }