コード例 #1
0
 /** Populate recent bookmarks. */
 public void populateRecentBookmarks() {
   JMenu bookmarksMenu = this.recentBookmarksMenu;
   bookmarksMenu.removeAll();
   Collection<HistoryEntry<BookmarkInfo>> historyEntries =
       BookmarksHistory.getInstance().getRecentEntries(PREFERRED_MAX_MENU_SIZE);
   for (HistoryEntry<BookmarkInfo> hentry : historyEntries) {
     BookmarkInfo binfo = hentry.getItemInfo();
     String text = binfo.getTitle();
     URL url = binfo.getUrl();
     String urlText = url.toExternalForm();
     if ((text == null) || (text.length() == 0)) {
       text = urlText;
     }
     long elapsed = System.currentTimeMillis() - hentry.getTimetstamp();
     text = text + " (" + Timing.getElapsedText(elapsed) + " ago)";
     Action action = this.actionPool.createBookmarkNavigateAction(url);
     JMenuItem menuItem = ComponentSource.menuItem(text, action);
     StringBuffer toolTipText = new StringBuffer();
     toolTipText.append("<html>");
     toolTipText.append(urlText);
     String description = binfo.getDescription();
     if ((description != null) && (description.length() != 0)) {
       toolTipText.append("<br>");
       toolTipText.append(description);
     }
     menuItem.setToolTipText(toolTipText.toString());
     bookmarksMenu.add(menuItem);
   }
 }
コード例 #2
0
 /** Populate tagged bookmarks. */
 public void populateTaggedBookmarks() {
   JMenu bookmarksMenu = this.taggedBookmarksMenu;
   bookmarksMenu.removeAll();
   Collection<BookmarkInfo> bookmarkInfoList =
       BookmarksHistory.getInstance()
           .getRecentItemInfo(PREFERRED_MAX_MENU_SIZE * PREFERRED_MAX_MENU_SIZE);
   Map<String, JMenu> tagMenus = new HashMap<String, JMenu>();
   for (BookmarkInfo binfo : bookmarkInfoList) {
     URL url = binfo.getUrl();
     String urlText = url.toExternalForm();
     String[] tags = binfo.getTags();
     if (tags != null) {
       for (String tag : tags) {
         JMenu tagMenu = tagMenus.get(tag);
         if (tagMenu == null) {
           if (tagMenus.size() < PREFERRED_MAX_MENU_SIZE) {
             tagMenu = new JMenu(tag);
             tagMenus.put(tag, tagMenu);
             bookmarksMenu.add(tagMenu);
           }
         }
         if ((tagMenu != null) && (tagMenu.getItemCount() < PREFERRED_MAX_MENU_SIZE)) {
           String text = binfo.getTitle();
           if ((text == null) || (text.length() == 0)) {
             text = urlText;
           }
           Action action = this.actionPool.createBookmarkNavigateAction(url);
           JMenuItem menuItem = ComponentSource.menuItem(text, action);
           StringBuffer toolTipText = new StringBuffer();
           toolTipText.append("<html>");
           toolTipText.append(urlText);
           String description = binfo.getDescription();
           if ((description != null) && (description.length() != 0)) {
             toolTipText.append("<br>");
             toolTipText.append(description);
           }
           menuItem.setToolTipText(toolTipText.toString());
           tagMenu.add(menuItem);
         }
       }
     }
   }
 }