示例#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());
          }
        });
  }
示例#2
0
  /**
   * Formats the passed annotation.
   *
   * @param annotation The value to format.
   * @param name The full name.
   * @return See above.
   */
  private String formatToolTip(AnnotationData annotation, String name) {
    ToolTipGenerator tt = new ToolTipGenerator();
    if (model.isMultiSelection()) {
      Map<DataObject, Boolean> m = null;
      Entry<DataObject, Boolean> e;
      Iterator<Entry<DataObject, Boolean>> j;
      String text = "";
      if (annotation instanceof TagAnnotationData) {
        m = model.getTaggedObjects(annotation);
        text += "Can remove Tag from ";
      } else if (annotation instanceof FileAnnotationData) {
        m = model.getObjectsWith(annotation);
        text += "Can remove Attachment from ";
      } else if (annotation instanceof XMLAnnotationData) {
        m = model.getObjectsWith(annotation);
        text += "Can remove XML files from ";
      } else if (annotation instanceof TermAnnotationData) {
        m = model.getObjectsWith(annotation);
        text += "Can remove Term from ";
      }
      if (m == null) return "";
      j = m.entrySet().iterator();
      Collection<Boolean> l = m.values();
      int n = 0;
      Iterator<Boolean> k = l.iterator();
      while (k.hasNext()) {
        if (k.next().booleanValue()) n++;
      }
      tt.addLineNoBr(text + "" + n + " ");
      int index = 0;
      String s;
      while (j.hasNext()) {
        e = j.next();
        if (index == 0) {
          tt.addLine(model.getObjectTypeAsString(e.getKey()) + "s", true);
          index++;
        }
        tt.addLine(
            "ID " + e.getKey().getId(),
            UIUtilities.formatPartialName(model.getObjectName(e.getKey())),
            true);
        // Indicates who annotates the object if not the user
        // currently logged in.
        s = formatAnnotators(e.getKey(), annotation);
        if (s != null) tt.addLine(s);
      }
      return tt.toString();
    }

    if (name != null) {
      tt.addLine("Name", name, true);
    }

    ExperimenterData exp = null;

    if (annotation.getId() > 0) {
      exp = model.getOwner(annotation);
      tt.addLine("ID", "" + annotation.getId(), true);
    }

    String ns = annotation.getNameSpace();
    if (!CommonsLangUtils.isEmpty(ns) && !EditorUtil.isInternalNS(ns)) {
      tt.addLine("Namespace", ns, true);
    }

    String desc = annotation.getDescription();
    if (!CommonsLangUtils.isEmpty(desc)) {
      tt.addLine("Description", desc, true);
    }

    if (exp != null) {
      tt.addLine("Owner", EditorUtil.formatExperimenter(exp), true);
    }

    Timestamp created = annotation.getCreated();
    if (created != null) {
      tt.addLine("Date", UIUtilities.formatDefaultDate(created), true);
    }

    if (data instanceof FileAnnotationData) {
      FileAnnotationData fa = (FileAnnotationData) data;
      long size = ((FileAnnotationData) annotation).getFileSize();
      tt.addLine("File ID", "" + fa.getFileID(), true);
      tt.addLine("Size", UIUtilities.formatFileSize(size) + "kb", true);
      checkAnnotators(tt, annotation);
    } else if (data instanceof TagAnnotationData
        || data instanceof XMLAnnotationData
        || data instanceof TermAnnotationData
        || data instanceof LongAnnotationData
        || data instanceof DoubleAnnotationData
        || data instanceof BooleanAnnotationData) {
      checkAnnotators(tt, annotation);
    }
    return tt.toString();
  }