コード例 #1
0
 public void mouseClicked(MouseEvent e) {
   if (e.isPopupTrigger()) {
     processPopupTrigger(e);
     return;
   }
   // if (e.)
   final int col = entryTable.columnAtPoint(e.getPoint()),
       row = entryTable.rowAtPoint(e.getPoint());
   if (col < PAD) {
     BibtexEntry entry = sortedEntries.get(row);
     BasePanel p = entryHome.get(entry);
     switch (col) {
       case FILE_COL:
         Object o = entry.getField(GUIGlobals.FILE_FIELD);
         if (o != null) {
           FileListTableModel tableModel = new FileListTableModel();
           tableModel.setContent((String) o);
           if (tableModel.getRowCount() == 0) return;
           FileListEntry fl = tableModel.getEntry(0);
           (new ExternalFileMenuItem(
                   frame, entry, "", fl.getLink(), null, p.metaData(), fl.getType()))
               .actionPerformed(null);
         }
         break;
       case URL_COL:
         Object link = entry.getField("url");
         try {
           if (link != null) Util.openExternalViewer(p.metaData(), (String) link, "url");
         } catch (IOException ex) {
           ex.printStackTrace();
         }
         break;
     }
   }
 }
コード例 #2
0
ファイル: CleanUpAction.java プロジェクト: jkulesza/jabref
 private void doMakePathsRelative(BibtexEntry entry, NamedCompound ce) {
   String oldValue = entry.getField(Globals.FILE_FIELD);
   if (oldValue == null) {
     return;
   }
   FileListTableModel flModel = new FileListTableModel();
   flModel.setContent(oldValue);
   if (flModel.getRowCount() == 0) {
     return;
   }
   boolean changed = false;
   for (int i = 0; i < flModel.getRowCount(); i++) {
     FileListEntry flEntry = flModel.getEntry(i);
     String oldFileName = flEntry.getLink();
     String newFileName =
         FileUtil.shortenFileName(
                 new File(oldFileName), panel.metaData().getFileDirectory(Globals.FILE_FIELD))
             .toString();
     if (!oldFileName.equals(newFileName)) {
       flEntry.setLink(newFileName);
       changed = true;
     }
   }
   if (changed) {
     String newValue = flModel.getStringRepresentation();
     assert (!oldValue.equals(newValue));
     entry.setField(Globals.FILE_FIELD, newValue);
     ce.addEdit(new UndoableFieldChange(entry, Globals.FILE_FIELD, oldValue, newValue));
   }
 }
コード例 #3
0
 private String encodeEntry(FileListEntry entry) {
   StringBuilder sb = new StringBuilder();
   sb.append(encodeString(entry.getDescription()));
   sb.append(':');
   sb.append(encodeString(entry.getLink()));
   sb.append(':');
   sb.append(encodeString(entry.getType() != null ? entry.getType().getName() : ""));
   return sb.toString();
 }
コード例 #4
0
 /**
  * Transform the file list shown in the table into a HTML string representation suitable for
  * displaying the contents in a tooltip.
  *
  * @return Tooltip representation.
  */
 public String getToolTipHTMLRepresentation() {
   StringBuilder sb = new StringBuilder("<html>");
   for (Iterator<FileListEntry> iterator = list.iterator(); iterator.hasNext(); ) {
     FileListEntry entry = iterator.next();
     sb.append(entry.getDescription()).append(" (").append(entry.getLink()).append(')');
     if (iterator.hasNext()) sb.append("<br>");
   }
   return sb.append("</html>").toString();
 }
コード例 #5
0
 public Object getValueAt(int rowIndex, int columnIndex) {
   synchronized (list) {
     FileListEntry entry = list.get(rowIndex);
     switch (columnIndex) {
       case 0:
         return entry.getDescription();
       case 1:
         return entry.getLink();
       default:
         return entry.getType() != null ? entry.getType().getName() : "";
     }
   }
 }
コード例 #6
0
  protected void createContents() {
    setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    setLayout(gridLayout);

    for (final IFCKEditorContentFile file : files) {
      FileListEntry fileListEntry =
          new FileListEntry(this, SWT.NONE, file, imageProvider, getActions(file));
      GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
      fileListEntry.setLayoutData(gridData);
    }
  }
コード例 #7
0
ファイル: CleanUpAction.java プロジェクト: jkulesza/jabref
 private static void fixWrongFileEntries(BibtexEntry entry, NamedCompound ce) {
   String oldValue = entry.getField(Globals.FILE_FIELD);
   if (oldValue == null) {
     return;
   }
   FileListTableModel flModel = new FileListTableModel();
   flModel.setContent(oldValue);
   if (flModel.getRowCount() == 0) {
     return;
   }
   boolean changed = false;
   for (int i = 0; i < flModel.getRowCount(); i++) {
     FileListEntry flEntry = flModel.getEntry(i);
     String link = flEntry.getLink();
     String description = flEntry.getDescription();
     if ("".equals(link) && (!"".equals(description))) {
       // link and description seem to be switched, quickly fix that
       flEntry.setLink(flEntry.getDescription());
       flEntry.setDescription("");
       changed = true;
     }
   }
   if (changed) {
     String newValue = flModel.getStringRepresentation();
     assert (!oldValue.equals(newValue));
     entry.setField(Globals.FILE_FIELD, newValue);
     ce.addEdit(new UndoableFieldChange(entry, Globals.FILE_FIELD, oldValue, newValue));
   }
 }
コード例 #8
0
    /**
     * If the user has signalled the opening of a context menu, the event gets redirected to this
     * method. Here we open a file link menu if the user is pointing at a file link icon. Otherwise
     * a general context menu should be shown.
     *
     * @param e The triggering mouse event.
     */
    public void processPopupTrigger(MouseEvent e) {
      BibtexEntry entry = sortedEntries.get(entryTable.rowAtPoint(e.getPoint()));
      BasePanel p = entryHome.get(entry);
      int col = entryTable.columnAtPoint(e.getPoint());
      JPopupMenu menu = new JPopupMenu();
      int count = 0;

      if (col == FILE_COL) {
        // We use a FileListTableModel to parse the field content:
        Object o = entry.getField(GUIGlobals.FILE_FIELD);
        FileListTableModel fileList = new FileListTableModel();
        fileList.setContent((String) o);
        // If there are one or more links, open the first one:
        for (int i = 0; i < fileList.getRowCount(); i++) {
          FileListEntry flEntry = fileList.getEntry(i);
          String description = flEntry.getDescription();
          if ((description == null) || (description.trim().length() == 0))
            description = flEntry.getLink();
          menu.add(
              new ExternalFileMenuItem(
                  p.frame(),
                  entry,
                  description,
                  flEntry.getLink(),
                  flEntry.getType().getIcon(),
                  p.metaData(),
                  flEntry.getType()));
          count++;
        }
      }

      if (count > 0) menu.show(entryTable, e.getX(), e.getY());
    }
コード例 #9
0
 /**
  * Convenience method for finding a label corresponding to the type of the first file link in the
  * given field content. The difference between using this method and using setContent() on an
  * instance of FileListTableModel is a slight optimization: with this method, parsing is
  * discontinued after the first entry has been found.
  *
  * @param content The file field content, as fed to this class' setContent() method.
  * @return A JLabel set up with no text and the icon of the first entry's file type, or null if no
  *     entry was found or the entry had no icon.
  */
 public static JLabel getFirstLabel(String content) {
   FileListTableModel tm = new FileListTableModel();
   FileListEntry entry = tm.setContent(content, true, true);
   if (entry == null || entry.getType() == null) return null;
   return entry.getType().getIconLabel();
 }