/** 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); } }
private void writeBookmark(PrintWriter writer, HistoryEntry<BookmarkInfo> entry) { java.net.URL url = entry.getUrl(); String urlText = url.toExternalForm(); BookmarkInfo binfo = entry.getItemInfo(); String text = binfo.getTitle(); if (text == null || text.length() == 0) { text = urlText; } long elapsed = System.currentTimeMillis() - entry.getTimetstamp(); String description = binfo.getDescription(); if (description == null) { description = ""; } writer.println("<LI>"); writer.println("<DIV>"); writer.println( "<A href=\"" + urlText + "\">" + text + "</A> (" + Timing.getElapsedText(elapsed) + " ago)"); writer.println("</DIV>"); writer.println("<DIV>"); writer.println(description); writer.println("</DIV>"); writer.println("</LI>"); }
/** * Gets the chronology menu. * * @return the chronology menu */ public JMenu getChronologyMenu() { JMenu menu = new JMenu("Recent Hosts"); menu.removeAll(); Collection<HostEntry> hostEntries = NavigationHistory.getInstance().getRecentHostEntries(PREFERRED_MAX_MENU_SIZE); for (HostEntry entry : hostEntries) { String urlText = "http://" + entry.getHost(); try { URL url = new URL(urlText); long elapsed = System.currentTimeMillis() - entry.getTimestamp(); String menuText = entry.getHost() + " (" + Timing.getElapsedText(elapsed) + " ago)"; Action action = this.actionPool.createNavigateAction(url); JMenuItem menuItem = menuItem(menuText, action); menuItem.setToolTipText(url.toExternalForm()); menu.add(menuItem); } catch (MalformedURLException mfu) { logger.log(Level.WARNING, "populateRecentHosts(): Bad URL=" + urlText, mfu); } } menu.addSeparator(); menu.add(menuItem("Show All Recent Hosts", new ShowRecentHostsAction(this, window))); return menu; }