Esempio n. 1
0
  /** 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());
          }
        });
  }
Esempio n. 2
0
  /** Initializes the various buttons. */
  private void initButtons() {
    IconManager icons = IconManager.getInstance();
    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) {
            showMenu(menuButton, e.getPoint());
          }
        });
    infoButton = new JMenuItem(icons.getIcon(IconManager.INFO));
    infoButton.setText("Info...");
    infoButton.addMouseListener(
        new MouseAdapter() {

          public void mousePressed(MouseEvent e) {
            popMenu.setVisible(false);
            displayInformation(label, e.getPoint());
          }
        });
    unlinkButton = new JMenuItem(icons.getIcon(IconManager.MINUS_12));
    unlinkButton.setText("Remove");
    unlinkButton.addActionListener(this);
    unlinkButton.setActionCommand("" + REMOVE);
    if (data instanceof FileAnnotationData) {
      FileAnnotationData fa = (FileAnnotationData) data;
      unlinkButton.setToolTipText("Remove the attachment.");

      if (fa.getId() > 0) {
        unlinkButton.setEnabled(deletable);
        downloadButton = new JMenuItem(icons.getIcon(IconManager.DOWNLOAD_12));
        downloadButton.setText("Download...");
        downloadButton.setToolTipText("Download the selected file.");
        downloadButton.setActionCommand("" + DOWNLOAD);
        downloadButton.addActionListener(this);

        String ns = fa.getNameSpace();
        openButton = new JMenuItem(icons.getIcon(IconManager.VIEW_DOC_12));
        openButton.setText("View");
        openButton.setToolTipText("View the file.");
        openButton.setActionCommand("" + OPEN);
        openButton.addActionListener(this);
        if (FileAnnotationData.COMPANION_FILE_NS.equals(ns)
            || FileAnnotationData.MEASUREMENT_NS.equals(ns)) unlinkButton = null;
      }
    } else if (data instanceof TagAnnotationData
        || data instanceof XMLAnnotationData
        || data instanceof TermAnnotationData
        || data instanceof LongAnnotationData
        || data instanceof DoubleAnnotationData
        || data instanceof BooleanAnnotationData) {
      unlinkButton.setToolTipText("Remove the annotation.");
      editButton = new JMenuItem(icons.getIcon(IconManager.EDIT_12));
      if (isModulo) editButton.setText("View");
      else editButton.setText("Edit");
      editButton.setActionCommand("" + EDIT);
      editButton.addActionListener(this);
      editButton.addMouseListener(
          new MouseAdapter() {

            /**
             * Sets the location of the mouse click.
             *
             * @see MouseAdapter#mousePressed(MouseEvent)
             */
            public void mousePressed(MouseEvent e) {
              popupPoint = e.getPoint();
            }
          });
    }
  }