/** Builds and lays out the UI. */
 private void buildGUI() {
   setBackground(UIUtilities.BACKGROUND_COLOR);
   JToolBar bar = new JToolBar();
   bar.setBackground(UIUtilities.BACKGROUND_COLOR);
   bar.setBorder(null);
   bar.setRollover(true);
   bar.setFloatable(false);
   JButton b = new JButton(control.getAction(RendererControl.SAVE));
   UIUtilities.unifiedButtonLookAndFeel(b);
   b.setText(ManageRndSettingsAction.NAME_SAVE);
   b.setBackground(UIUtilities.BACKGROUND_COLOR);
   bar.add(b);
   /*
   b = new JButton(control.getAction(RendererControl.VIEW));
   UIUtilities.unifiedButtonLookAndFeel(b);
   b.setBackground(UIUtilities.BACKGROUND_COLOR);
   bar.add(b);
   */
   setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
   add(bar);
   add(Box.createHorizontalStrut(5));
   JPanel p = UIUtilities.buildComponentPanelRight(selectedPlane);
   p.setBackground(UIUtilities.BACKGROUND_COLOR);
   add(p);
 }
  /**
   * Initializes the components.
   *
   * @param nameSpace The name space to use to determine the name.
   * @param index The value of the results.
   */
  private void initComponents(String nameSpace, int index) {
    attachments = new ArrayList<FileAnnotationData>();
    this.nameSpace = nameSpace;
    resultsButton = new JButton();
    resultsButton.setText(convertNameSpace(nameSpace) + " #" + index);
    resultsButton.setOpaque(false);
    resultsButton.setForeground(UIUtilities.HYPERLINK_COLOR);
    resultsButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    UIUtilities.unifiedButtonLookAndFeel(resultsButton);
    resultsButton.setActionCommand("" + VIEW);
    resultsButton.addActionListener(this);

    cancelButton = new JButton();
    cancelButton.setText("Cancel");
    cancelButton.setToolTipText("Cancel results loading.");
    cancelButton.setOpaque(false);
    cancelButton.setForeground(UIUtilities.HYPERLINK_COLOR);
    cancelButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    UIUtilities.unifiedButtonLookAndFeel(cancelButton);
    cancelButton.setActionCommand("" + CANCEL);
    cancelButton.addActionListener(this);

    IconManager icons = IconManager.getInstance();
    deleteButton = new JMenuItem(icons.getIcon(IconManager.DELETE_12));
    deleteButton.setText("Delete");
    deleteButton.setToolTipText("Delete the results.");
    deleteButton.setActionCommand("" + DELETE);
    deleteButton.addActionListener(this);
    downloadButton = new JMenuItem(icons.getIcon(IconManager.DOWNLOAD_12));
    downloadButton.setText("Download...");
    downloadButton.setToolTipText("Download the selected file.");
    downloadButton.setActionCommand("" + DOWNLOAD);
    downloadButton.addActionListener(this);

    menuButton = new JButton(icons.getIcon(IconManager.UP_DOWN_9_12));
    UIUtilities.unifiedButtonLookAndFeel(menuButton);
    menuButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    menuButton.addMouseListener(
        new MouseAdapter() {

          public void mousePressed(MouseEvent e) {
            Point p = e.getPoint();
            showMenu(menuButton, p);
          }
        });
    infoButton = new JMenuItem(icons.getIcon(IconManager.INFO));
    infoButton.setText("Info...");
    infoButton.addMouseListener(
        new MouseAdapter() {

          public void mousePressed(MouseEvent e) {
            Point p = e.getPoint();
            displayInformation(p);
          }
        });

    setBackground(UIUtilities.BACKGROUND_COLOR);
  }
 /**
  * Creates a new instance.
  *
  * @param model The model. Mustn't be <code>null</code>.
  * @param createSingleFigure Passed <code>true</code> to set the tool to create a single figure at
  *     a time, <code>false</code> otherwise.
  */
 public CreateFigureAction(MeasurementViewer model, boolean createSingleFigure) {
   super(model);
   this.createSingleFigure = createSingleFigure;
   if (createSingleFigure) {
     name = NAME_CREATE_SINGLE;
     putValue(Action.NAME, NAME_CREATE_SINGLE);
     putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION_CREATE_SINGLE));
   } else {
     name = NAME_CREATE_MULTIPLE;
     putValue(Action.NAME, NAME_CREATE_MULTIPLE);
     putValue(
         Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION_CREATE_MULTIPLE));
   }
 }
 /** Brings up the dialog to choose the photo to upload. */
 private void uploadPicture() {
   UploadPictureDialog d =
       new UploadPictureDialog(MetadataViewerAgent.getRegistry().getTaskBar().getFrame());
   d.addPropertyChangeListener(this);
   d.pack();
   UIUtilities.centerAndShow(d);
 }
 /**
  * Creates a new instance.
  *
  * @param model Reference to the Model. Mustn't be <code>null</code>.
  */
 public RefreshExperimenterData(TreeViewer model) {
   super(model);
   putValue(Action.NAME, NAME);
   putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION));
   IconManager im = IconManager.getInstance();
   putValue(Action.SMALL_ICON, im.getIcon(IconManager.REFRESH));
 }
 /**
  * Adds the connection speed options to the display.
  *
  * @param index The default index.
  * @param comp The component to add to the display.
  * @return See above.
  */
 private JPanel buildConnectionSpeed(int index, JComponent comp) {
   JPanel p = new JPanel();
   p.setBorder(BorderFactory.createTitledBorder("Connection Speed"));
   buttonsGroup = new ButtonGroup();
   JRadioButton button = new JRadioButton();
   button.setText("LAN");
   button.setActionCommand("" + HIGH_SPEED);
   button.addActionListener(this);
   button.setSelected(index == LoginCredentials.HIGH);
   buttonsGroup.add(button);
   p.add(button);
   button = new JRadioButton();
   button.setText("High (Broadband)");
   button.setActionCommand("" + MEDIUM_SPEED);
   button.setSelected(index == LoginCredentials.MEDIUM);
   button.addActionListener(this);
   buttonsGroup.add(button);
   p.add(button);
   button = new JRadioButton();
   button.setText("Low (Dial-up)");
   button.setActionCommand("" + LOW_SPEED);
   button.setSelected(index == LoginCredentials.LOW);
   button.addActionListener(this);
   buttonsGroup.add(button);
   p.add(button);
   if (comp == null) return p;
   JPanel content = new JPanel();
   content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
   content.add(comp);
   p = UIUtilities.buildComponentPanel(p);
   content.add(p);
   return content;
 }
 /**
  * Creates a new instance.
  *
  * @param model Reference to the Model. Mustn't be <code>null</code>.
  */
 public CollapseAction(Browser model) {
   super(model);
   setEnabled(true);
   putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION));
   IconManager im = IconManager.getInstance();
   putValue(Action.SMALL_ICON, im.getIcon(IconManager.COLLAPSE));
 }
 /**
  * Creates a new instance.
  *
  * @param model Reference to the Model. Mustn't be <code>null</code>.
  */
 public TaggingAction(DataBrowser model) {
   super(model);
   putValue(Action.NAME, NAME);
   putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION));
   IconManager im = IconManager.getInstance();
   putValue(Action.SMALL_ICON, im.getIcon(IconManager.TAG));
 }
 /**
  * Creates a new instance.
  *
  * @param model Reference to the Model. Mustn't be <code>null</code>.
  */
 public TaggingAction(TreeViewer model) {
   super(model);
   name = NAME;
   putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION));
   description = (String) getValue(Action.SHORT_DESCRIPTION);
   IconManager im = IconManager.getInstance();
   putValue(Action.SMALL_ICON, im.getIcon(IconManager.TAG));
 }
Exemple #10
0
 /** Brings up a preview of the image or images to save. */
 void previewImage() {
   ImgSaverPreviewer preview = new ImgSaverPreviewer(this);
   setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
   createImages(uiDelegate.getSavingType());
   setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
   preview.initialize();
   UIUtilities.centerAndShow(preview);
 }
Exemple #11
0
 /** Initializes the components. */
 private void initialize() {
   valueComponent = null;
   IconManager icons = IconManager.getInstance();
   removeButton = new JButton(icons.getIcon(IconManager.MINUS_9));
   removeButton.setToolTipText("Remove the row.");
   removeButton.addActionListener(this);
   UIUtilities.unifiedButtonLookAndFeel(removeButton);
 }
 /**
  * Creates a new instance.
  *
  * @param model Reference to the Model. Mustn't be <code>null</code>.
  */
 public LogOffAction(TreeViewer model) {
   super(model);
   name = NAME;
   putValue(Action.NAME, NAME);
   putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION));
   IconManager im = IconManager.getInstance();
   putValue(Action.SMALL_ICON, im.getIcon(IconManager.LOGIN));
 }
 /**
  * Adds a new attachment.
  *
  * @param file The attachment to add.
  */
 public void addAttachment(FileAnnotationData file) {
   long userID = MetadataViewerAgent.getUserDetails().getId();
   if (time == null) {
     time = file.getLastModified();
     resultsButton.setToolTipText("Analysis run " + UIUtilities.formatTime(time));
   }
   if (file.getOwner().getId() == userID) deleteButton.setVisible(true);
   if (!attachments.contains(file)) attachments.add(file);
 }
 /**
  * Create the button panel to the right of the summary table.
  *
  * @return see above.
  */
 private JPanel createButtonPanel() {
   JPanel panel = new JPanel();
   panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
   panel.add(Box.createRigidArea(new Dimension(0, 10)));
   JPanel channelPanel = UIUtilities.buildComponentPanel(channelSelection);
   // UIUtilities.setDefaultSize(channelPanel, new Dimension(175, 32));
   panel.add(channelPanel);
   panel.add(Box.createRigidArea(new Dimension(0, 10)));
   JPanel intensityPanel = UIUtilities.buildComponentPanel(showIntensityTable);
   UIUtilities.setDefaultSize(intensityPanel, new Dimension(175, 32));
   panel.add(intensityPanel);
   panel.add(Box.createRigidArea(new Dimension(0, 10)));
   JPanel savePanel = UIUtilities.buildComponentPanel(saveButton);
   UIUtilities.setDefaultSize(savePanel, new Dimension(175, 32));
   panel.add(savePanel);
   panel.add(Box.createVerticalGlue());
   return panel;
 }
 /** Brings up the server dialog to select an existing server or enter a new server address. */
 private void config() {
   ServerDialog d;
   String s = serverText.getText().trim();
   if (connectionSpeed) d = new ServerDialog(this, editor, s, speedIndex);
   else d = new ServerDialog(this, editor, s);
   if (editor.getRowCount() == 0 && configureServerName != null)
     editor.addRow(configureServerName);
   d.addPropertyChangeListener(this);
   UIUtilities.centerAndShow(d);
 }
 /**
  * Builds and lays out the tool bar.
  *
  * @return See above.
  */
 private JPanel buildToolBar() {
   JPanel bar = new JPanel();
   bar.setOpaque(true);
   bar.setBorder(null);
   bar.add(finishButton);
   bar.add(Box.createRigidArea(H_SPACER_SIZE));
   bar.add(cancelButton);
   JPanel p = UIUtilities.buildComponentPanelRight(bar);
   p.setOpaque(true);
   return p;
 }
    /**
     * Opens a dialog box for users to choose a local file.
     *
     * @see ActionListener#actionPerformed(ActionEvent)
     */
    public void actionPerformed(ActionEvent e) {
      List<FileFilter> filters;
      filters = new ArrayList<FileFilter>();
      filters.add(new EditorFileFilter());

      FileChooser chooser =
          new FileChooser(
              null, FileChooser.LOAD, "Open File", "Choose a file to open in the Editor", filters);
      chooser.addPropertyChangeListener(
          FileChooser.APPROVE_SELECTION_PROPERTY, ProtocolLinkEditor.this);
      UIUtilities.centerAndShow(chooser);
    }
 /** Launches a dialog to select the file to attach to the <code>DataObject</code>. */
 private void selectFileToAttach() {
   JFrame owner = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
   FileChooser chooser =
       new FileChooser(
           owner, FileChooser.LOAD, "Choose File", "Select the file to attach.", filters, true);
   chooser.setMultiSelectionEnabled(true);
   IconManager icons = IconManager.getInstance();
   chooser.setTitleIcon(icons.getIcon(IconManager.ATTACHMENT_48));
   chooser.setApproveButtonText("Attach");
   chooser.addPropertyChangeListener(FileChooser.APPROVE_SELECTION_PROPERTY, this);
   UIUtilities.centerAndShow(chooser);
 }
  /** Brings up the folder chooser. */
  private void export() {
    DowngradeChooser chooser =
        new DowngradeChooser(
            new RefWindow(),
            FileChooser.SAVE,
            "Export",
            "Select where to export the image as OME-TIFF.",
            exportFilters);
    try {
      String path =
          MetadataViewerAgent.getRegistry()
              .getTaskBar()
              .getLibFileRelative(TransformsParser.SPECIFICATION + ".jar");
      chooser.parseData(path);
    } catch (Exception e) {
      LogMessage msg = new LogMessage();
      msg.print(e);
      MetadataViewerAgent.getRegistry().getLogger().debug(this, msg);
    }
    String s = UIUtilities.removeFileExtension(view.getRefObjectName());
    if (s != null && s.trim().length() > 0) chooser.setSelectedFile(s);
    chooser.setApproveButtonText("Export");
    IconManager icons = IconManager.getInstance();
    chooser.setTitleIcon(icons.getIcon(IconManager.EXPORT_AS_OMETIFF_48));
    chooser.addPropertyChangeListener(
        new PropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
              File[] files = (File[]) evt.getNewValue();
              File folder = files[0];
              if (folder == null) folder = UIUtilities.getDefaultFolder();
              Object src = evt.getSource();
              Target target = null;
              if (src instanceof DowngradeChooser) {
                ((FileChooser) src).setVisible(false);
                ((FileChooser) src).dispose();
                target = ((DowngradeChooser) src).getSelectedSchema();
              }
              model.exportImageAsOMETIFF(folder, target);
            } else if (DowngradeChooser.HELP_DOWNGRADE_PROPERTY.equals(name)) {
              Registry reg = MetadataViewerAgent.getRegistry();
              String url = (String) reg.lookup("HelpDowngrade");
              reg.getTaskBar().openURL(url);
            }
          }
        });
    chooser.centerDialog();
  }
  /**
   * Lays out the widgets and positions the window in the middle of the screen.
   *
   * @param logo The Frame's background logo.
   * @param version The version of the software.
   * @param serverAvailable Pass <code>true</code> if the client needs to connect to a server,
   *     <code>false</code> otherwise.
   */
  private void buildGUI(Icon logo, String version, boolean serverAvailable) {
    JLabel splash = new JLabel(logo);
    layers = new JLayeredPane();
    layers.add(splash, Integer.valueOf(0));
    getContentPane().add(layers);
    int width = logo.getIconWidth();
    int height = logo.getIconHeight();
    layers.setBounds(0, 0, width, height);
    splash.setBounds(0, 0, width, height);
    int h = progressBar.getFontMetrics(progressBar.getFont()).getHeight();
    int top = 120;
    int bottom = 100;
    currentTask.setBounds(TEXT_INDENT, top, width - 2 * TEXT_INDENT, h);
    top += 20;
    progressBar.setBounds(TEXT_INDENT, top, width - 2 * TEXT_INDENT, h);

    addToLayer(currentTask);
    addToLayer(progressBar);

    mainPanel = new JPanel();
    mainPanel.setOpaque(false);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    Font f;
    versionInfo = UIUtilities.buildTextPane(version, FOOT_NOTE_COLOR);
    f = versionInfo.getFont();
    versionInfo.setFont(f.deriveFont(VERSION_FONT_STYLE, f.getSize() - 4));
    versionInfo.setOpaque(false);
    // Add login details.
    int y = height - bottom - 10;
    y = top + 2 * h;
    buildLogin();
    displayComponents(serverAvailable);
    mainPanel.add(UIUtilities.buildComponentPanelCenter(versionInfo, 0, 0, false));
    mainPanel.setBounds(0, y, width, height - top - bottom);
    addToLayer(mainPanel);
  }
 /** Adds or edits the description of the tag. */
 private void editDescription() {
   if (!(data instanceof AnnotationData)) return;
   String text = model.getAnnotationDescription((AnnotationData) data);
   originalDescription = text;
   SwingUtilities.convertPointToScreen(popupPoint, this);
   JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
   int type = EditorDialog.EDIT_TYPE;
   if (isModulo) type = EditorDialog.VIEW_TYPE;
   EditorDialog d = new EditorDialog(f, (AnnotationData) data, false, type);
   if (isModulo) d.allowEdit(false);
   d.addPropertyChangeListener(this);
   d.setOriginalDescription(originalDescription);
   d.setSize(300, 250);
   UIUtilities.showOnScreen(d, popupPoint);
 }
  /**
   * Listens to property fired by the Editor dialog.
   *
   * @see PropertyChangeListener#propertyChange(PropertyChangeEvent)
   */
  public void propertyChange(PropertyChangeEvent evt) {
    String name = evt.getPropertyName();
    if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
      File[] files = (File[]) evt.getNewValue();
      File folder = files[0];
      if (folder == null) folder = UIUtilities.getDefaultFolder();
      UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier();

      if (attachments == null || attachments.size() == 0) return;
      IconManager icons = IconManager.getInstance();
      DownloadAndZipParam param =
          new DownloadAndZipParam(attachments, folder, icons.getIcon(IconManager.DOWNLOAD_22));
      // TODO: review
      // un.notifyActivity(param);
    }
  }
Exemple #23
0
  /**
   * Notifies that the image has been saved locally.
   *
   * @param name The path to the local file.
   */
  private void notifySave(String name) {
    NotificationDialog dialog =
        new NotificationDialog(this, "Save Image", getSaveMessage(name), true);
    dialog.addPropertyChangeListener(
        new PropertyChangeListener() {

          /** Opens the image with default viewer. */
          public void propertyChange(PropertyChangeEvent evt) {
            if (NotificationDialog.HYPERLINK_OPEN_PROPERTY.equals(evt.getPropertyName())) {
              UserNotifier un = ImViewerAgent.getRegistry().getUserNotifier();
              un.openApplication(null, (String) evt.getNewValue());
            }
          }
        });
    dialog.pack();
    UIUtilities.centerAndShow(dialog);
  }
 /**
  * Checks if the passed value is supported.
  *
  * @param value The value to handle.
  */
 private void checkType(int value) {
   IconManager icons = IconManager.getInstance();
   switch (value) {
     case PROJECT:
       name = NAME_PROJECT;
       putValue(Action.SMALL_ICON, icons.getIcon(IconManager.PROJECT));
       putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION_PROJECT));
       break;
     case DATASET:
       name = NAME_DATASET;
       putValue(Action.SMALL_ICON, icons.getIcon(IconManager.DATASET));
       putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION_DATASET));
       break;
     case TAG:
       name = NAME_TAG;
       putValue(Action.SMALL_ICON, icons.getIcon(IconManager.TAG));
       putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION_TAG));
       break;
     case TAG_SET:
       name = NAME_TAG_SET;
       putValue(Action.SMALL_ICON, icons.getIcon(IconManager.TAG_SET));
       putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION_TAG_SET));
       break;
     case SCREEN:
       name = NAME_SCREEN;
       putValue(Action.SMALL_ICON, icons.getIcon(IconManager.SCREEN));
       putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION_SCREEN));
       break;
     case GROUP:
       name = NAME_GROUP;
       putValue(Action.SMALL_ICON, icons.getIcon(IconManager.OWNER_GROUP));
       putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION_GROUP));
       break;
     case EXPERIMENTER:
       name = NAME_EXPERIMENTER;
       putValue(Action.SMALL_ICON, icons.getIcon(IconManager.OWNER));
       putValue(Action.SHORT_DESCRIPTION, UIUtilities.formatToolTipText(DESCRIPTION_EXPERIMENTER));
       break;
     default:
       throw new IllegalArgumentException("Type not supported.");
   }
 }
 /**
  * Displays information about the analysis.
  *
  * @param p The location of the mouse pressed.
  */
 private void displayInformation(Point p) {
   StringBuffer buf = new StringBuffer();
   buf.append("<html><body>");
   buf.append("<b>Analysis Run: </b>" + UIUtilities.formatTime(time));
   buf.append("<br>");
   buf.append("<b>Number of files: </b>" + attachments.size());
   buf.append("<br>");
   Iterator<FileAnnotationData> i = attachments.iterator();
   while (i.hasNext()) {
     buf.append(i.next().getFileName());
     buf.append("<br>");
   }
   buf.append("</body></html>");
   JLabel l = new JLabel();
   l.setText(buf.toString());
   TinyDialog d = new TinyDialog(null, l, TinyDialog.CLOSE_ONLY);
   d.setModal(true);
   d.getContentPane().setBackground(UIUtilities.BACKGROUND_COLOUR_EVEN);
   SwingUtilities.convertPointToScreen(p, this);
   d.pack();
   d.setLocation(p);
   d.setVisible(true);
 }
  /** Brings up the folder chooser to select where to save the files. */
  private void saveAsJPEG() {
    JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
    FileChooser chooser =
        new FileChooser(
            f,
            FileChooser.FOLDER_CHOOSER,
            "Save As",
            "Select where to save locally the images as JPEG.",
            saveAsFilters);
    String s = UIUtilities.removeFileExtension(view.getRefObjectName());
    if (s != null && s.trim().length() > 0) chooser.setSelectedFile(s);
    chooser.setApproveButtonText("Save");
    IconManager icons = IconManager.getInstance();
    chooser.setTitleIcon(icons.getIcon(IconManager.SAVE_AS_48));
    chooser.addPropertyChangeListener(
        new PropertyChangeListener() {

          public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
              // File[] files = (File[]) evt.getNewValue();
              String value = (String) evt.getNewValue();
              File folder = null; // files[0];
              if (value == null || value.trim().length() == 0)
                folder = UIUtilities.getDefaultFolder();
              else folder = new File(value);
              Object src = evt.getSource();
              if (src instanceof FileChooser) {
                ((FileChooser) src).setVisible(false);
                ((FileChooser) src).dispose();
              }
              model.saveAs(folder);
            }
          }
        });
    chooser.centerDialog();
  }
  /**
   * Builds the UI component hosting the buttons.
   *
   * @return See above.
   */
  private JPanel buildLogin() {
    // server information
    JPanel p = new JPanel();
    p.setOpaque(false);
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    p.add(serverTextPane);
    p.add(connectionSpeedText);

    JToolBar bar = new JToolBar();
    bar.setOpaque(false);
    bar.setBorder(null);
    bar.setFloatable(false);
    if (UIUtilities.isWindowsOS()) {
      bar.add(Box.createHorizontalStrut(5));
      bar.add(encryptedButton);
      bar.add(Box.createHorizontalStrut(5));
      bar.add(configButton);
    } else {
      bar.add(encryptedButton);
      bar.add(configButton);
    }

    JPanel row = new JPanel();
    row.setOpaque(false);
    row.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
    row.add(p);
    row.add(bar);

    mainPanel.add(row);
    components.add(row);
    // user name
    JPanel group = new JPanel();
    group.setOpaque(false);
    group.setLayout(new BoxLayout(group, BoxLayout.Y_AXIS));
    JTextPane l = UIUtilities.buildTextPane(USER_TEXT, TEXT_COLOR);
    row = new JPanel();
    row.setOpaque(false);
    row.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
    row.add(l);
    row.add(user);
    group.add(row);

    // password
    l = UIUtilities.buildTextPane(" " + PASSWORD_TEXT, TEXT_COLOR);
    row = new JPanel();
    row.setOpaque(false);
    row.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
    row.add(l);
    row.add(pass);
    group.add(row);

    mainPanel.add(group);
    components.add(group);
    // controls
    JPanel controls = new JPanel();
    controls.setOpaque(false);
    controls.add(Box.createHorizontalGlue());
    controls.add(login);
    controls.add(cancel);
    p = UIUtilities.buildComponentPanelCenter(controls, 0, 0, false);
    mainPanel.add(p);
    components.add(p);

    return mainPanel;
  }
  /**
   * Creates and initializes the components
   *
   * @param userName The name of the user.
   * @param hostName The default hostName.
   */
  private void initialize(String userName, String hostName) {
    components = new ArrayList<JComponent>();
    // status update.
    currentTask = new JLabel();
    Font newFont = currentTask.getFont().deriveFont(8);
    currentTask.setFont(newFont);
    currentTask.setForeground(ScreenLogin.TEXT_COLOR);
    progressBar = new JProgressBar();
    progressBar.setVisible(false);
    progressBar.setStringPainted(false);
    progressBar.setFont(newFont);

    originalName = userName;
    user = new JTextField();
    user.setName("username field");
    user.setText(userName);
    user.setToolTipText("Enter your username.");
    user.setColumns(TEXT_COLUMN);
    pass = new JPasswordField();
    pass.setName("password field");
    pass.setToolTipText("Enter your password.");
    pass.setColumns(TEXT_COLUMN);
    Map<String, String> servers = editor.getServers();
    if (CommonsLangUtils.isNotBlank(hostName)) {
      serverName = hostName;
      // if user did point to another server
      if (servers != null && servers.size() > 0) {
        int n = servers.size() - 1;
        Iterator<String> i = servers.keySet().iterator();
        int k = 0;
        String value;
        while (i.hasNext()) {
          serverName = i.next();
          if (k == n) {
            value = servers.get(serverName);
            if (value != null) {
              try {
                selectedPort = Integer.parseInt(value);
              } catch (Exception e) {
              }
            }
          }
          k++;
        }
      } else {
        editor.removeLastRow();
        editor.addRow(hostName);
      }
    } else {
      if (servers == null || servers.size() == 0) serverName = hostName;
      else {
        int n = servers.size() - 1;
        Iterator<String> i = servers.keySet().iterator();
        int k = 0;
        String value;
        while (i.hasNext()) {
          serverName = i.next();
          if (k == n) {
            value = servers.get(serverName);
            if (value != null) {
              try {
                selectedPort = Integer.parseInt(value);
              } catch (Exception e) {
              }
            }
          }
          k++;
        }
      }
    }
    if (serverName.length() == 0) serverName = DEFAULT_SERVER;
    if (!DEFAULT_SERVER.equals(serverName)) originalServerName = serverName;
    connectionSpeedText = new JLabel(getConnectionSpeed());
    connectionSpeedText.setForeground(TEXT_COLOR);
    connectionSpeedText.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
    serverText = UIUtilities.buildTextPane(serverName, TEXT_COLOR);
    serverText.setName("server name text pane");

    serverTextPane = UIUtilities.buildComponentPanelRight(serverText, false);
    serverTextPane.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));

    initializeGroups();
    ref = new ArrayList<JComponent>();
    login = new JButton("Login");
    login.setName("login button");
    defaultForeground = login.getForeground();
    login.setMnemonic('L');
    login.setToolTipText("Login");
    setButtonDefault(login);
    login.setEnabled(false);
    // UIUtilities.enterPressesWhenFocused(login);
    UIUtilities.opacityCheck(login);
    cancel = new JButton("Quit");
    cancel.setMnemonic('Q');
    cancel.setToolTipText("Cancel Login.");
    setButtonDefault(cancel);
    UIUtilities.opacityCheck(cancel);
    configButton = new JButton();
    configButton.setName("config server button");
    configButton.setMnemonic('X');
    configButton.setToolTipText("Enter the server's address.");
    configButton.setBorderPainted(false);
    configButton.setBorder(null);
    // configButton.setMargin(new Insets(1, 1, 1, 1));
    configButton.setFocusPainted(false);
    configButton.setContentAreaFilled(false);
    IconManager icons = IconManager.getInstance();
    configButton.setIcon(icons.getIcon(IconManager.CONFIG_24));
    // configButton.setPressedIcon(icons.getIcon(
    //		IconManager.CONFIG_PRESSED_24));

    encrypted = !isEncrypted();
    encryptedButton = new JButton();
    List<String> tips = new ArrayList<String>();
    tips.add("The connection to the server is always encrypted.");
    tips.add(
        "If selected, the data transfer (e.g. annotations, images) " + "will also be encrypted.");
    tips.add("But the transfer will be much slower.");

    encryptedButton.setToolTipText(UIUtilities.formatToolTipText(tips));
    encryptedButton.setBorderPainted(false);
    encryptedButton.setBorder(null);
    encryptedButton.setFocusPainted(false);
    encryptedButton.setContentAreaFilled(false);
    if (encrypted) encryptedButton.setIcon(icons.getIcon(IconManager.ENCRYPTED_24));
    else encryptedButton.setIcon(icons.getIcon(IconManager.DECRYPTED_24));
    getRootPane().setDefaultButton(login);
    enableControls();
  }
  /**
   * Listens to property fired by the Editor dialog.
   *
   * @see PropertyChangeListener#propertyChange(PropertyChangeEvent)
   */
  public void propertyChange(PropertyChangeEvent evt) {
    String name = evt.getPropertyName();
    if (EditorDialog.CREATE_NO_PARENT_PROPERTY.equals(name)) {
      // reset text and tooltip
      String text = "";
      String description = "";
      AnnotationData annotation = null;
      if (data instanceof TagAnnotationData
          || data instanceof TermAnnotationData
          || data instanceof XMLAnnotationData) {
        annotation = (AnnotationData) data;
        text = annotation.getContentAsString();
        text = EditorUtil.truncate(text, TEXT_LENGTH, false);
      }
      if (data instanceof DoubleAnnotationData) {
        annotation = (AnnotationData) data;
        text = "" + ((DoubleAnnotationData) data).getDataValue();
      }
      if (data instanceof LongAnnotationData) {
        annotation = (AnnotationData) data;
        text = "" + ((LongAnnotationData) data).getDataValue();
      }
      if (data instanceof BooleanAnnotationData) {
        annotation = (AnnotationData) data;
        text = "" + ((BooleanAnnotationData) data).getValue();
      }
      description = model.getAnnotationDescription(annotation);
      if (annotation == null) return;
      label.setText(text);
      label.setToolTipText(formatToolTip(annotation, null));
      originalName = text;
      originalDescription = description;
      firePropertyChange(AnnotationUI.EDIT_TAG_PROPERTY, null, this);
    } else if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
      if (data == null) return;
      FileAnnotationData fa = (FileAnnotationData) data;
      OriginalFile f = (OriginalFile) fa.getContent();
      File folder;
      Object o = evt.getNewValue();
      if (o instanceof String) {
        String path = (String) o;
        if (!path.endsWith(File.separator)) {
          path += File.separator;
        }
        path += fa.getFileName();
        folder = new File(path);
      } else {
        File[] files = (File[]) o;
        folder = files[0];
      }
      if (folder == null) folder = UIUtilities.getDefaultFolder();
      UserNotifier un = MetadataViewerAgent.getRegistry().getUserNotifier();

      IconManager icons = IconManager.getInstance();

      DownloadActivityParam activity =
          new DownloadActivityParam(f, folder, icons.getIcon(IconManager.DOWNLOAD_22));
      // Check Name space
      activity.setLegend(fa.getDescription());
      un.notifyActivity(model.getSecurityContext(), activity);
    }
  }
  /** Initializes the components composing the display. */
  private void initComponents() {
    isModulo = model.isModulo(data);
    imageToLoad = -1;
    initButtons();
    label = new JLabel();
    label.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    checkbox = new JCheckBox();
    if (data == null) {
      label.setText(AnnotationUI.DEFAULT_TEXT);
    } else {
      if (data instanceof FileAnnotationData) {
        FileAnnotationData f = (FileAnnotationData) data;
        String fileName = f.getFileName();
        String s = fileName;
        if (FileAnnotationData.MEASUREMENT_NS.equals(f.getNameSpace())) {
          String desc = f.getDescription();
          if (desc != null && desc.trim().length() > 0) label.setText(desc);
          else {
            label.setText(UIUtilities.formatPartialName(EditorUtil.getPartialName(fileName)));
          }
          s = label.getText();
        } else {
          label.setText(UIUtilities.formatPartialName(EditorUtil.getPartialName(fileName)));
        }

        label.setToolTipText(formatToolTip(f, s));
        Iterator<CustomizedFileFilter> i = FILTERS.iterator();
        CustomizedFileFilter filter;
        long id = f.getId();
        while (i.hasNext()) {
          filter = i.next();
          if (filter.accept(fileName)) {
            if (id > 0) imageToLoad = LOAD_FROM_SERVER;
            else imageToLoad = LOAD_FROM_LOCAL;
            break;
          }
        }
        if (id < 0) label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
        switch (imageToLoad) {
          case LOAD_FROM_LOCAL:
            if (thumbnail == null) setThumbnail(f.getFilePath());
            break;
            /*
            case LOAD_FROM_SERVER:
            	if (thumbnail == null) {
            		model.loadFile((FileAnnotationData) data, this);
            	}
            	*/
        }
      } else if (data instanceof File) {
        File f = (File) data;
        label.setText(EditorUtil.getPartialName(f.getName()));
        label.setForeground(Color.BLUE);
      } else if (data instanceof TagAnnotationData) {
        TagAnnotationData tag = (TagAnnotationData) data;
        label.setText(tag.getTagValue());
        label.setToolTipText(formatToolTip(tag, null));
        if (tag.getId() < 0) label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
      } else if (data instanceof XMLAnnotationData) {
        XMLAnnotationData tag = (XMLAnnotationData) data;
        label.setText(EditorUtil.truncate(tag.getText(), TEXT_LENGTH, false));
        label.setToolTipText(formatToolTip(tag, null));
        if (tag.getId() < 0) label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
      } else if (data instanceof TermAnnotationData) {
        TermAnnotationData tag = (TermAnnotationData) data;
        label.setText(tag.getTerm());
        label.setToolTipText(formatToolTip(tag, null));
        if (tag.getId() < 0) label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
      } else if (data instanceof LongAnnotationData) {
        LongAnnotationData tag = (LongAnnotationData) data;
        label.setText(tag.getContentAsString());
        label.setToolTipText(formatToolTip(tag, null));
        if (tag.getId() < 0) label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
      } else if (data instanceof DoubleAnnotationData) {
        DoubleAnnotationData tag = (DoubleAnnotationData) data;
        label.setText(tag.getContentAsString());
        label.setToolTipText(formatToolTip(tag, null));
        if (tag.getId() < 0) label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
      } else if (data instanceof BooleanAnnotationData) {
        BooleanAnnotationData tag = (BooleanAnnotationData) data;
        label.setText(tag.getContentAsString());
        label.setToolTipText(formatToolTip(tag, null));
        if (tag.getId() < 0) label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
      } else if (data instanceof TimeAnnotationData) {
        TimeAnnotationData tag = (TimeAnnotationData) data;
        label.setText(tag.getContentAsString());
        label.setToolTipText(formatToolTip(tag, null));
        if (tag.getId() < 0) label.setForeground(DataObjectListCellRenderer.NEW_FOREGROUND_COLOR);
      }
    }

    label.addMouseListener(
        new MouseAdapter() {

          /**
           * Posts an event to edit the file.
           *
           * @see MouseAdapter#mouseReleased(MouseEvent)
           */
          public void mouseReleased(MouseEvent e) {
            if (e.getClickCount() == 1 && e.isPopupTrigger()) {
              showMenu(label, e.getPoint());
            }
          }

          /**
           * Shows menu
           *
           * @see MouseAdapter#mouseReleased(MouseEvent)
           */
          public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) showMenu(label, e.getPoint());
          }
        });
  }