diff --git a/versioning.system.cvss/src/org/netbeans/modules/versioning/system/cvss/ui/actions/annotate/AnnotationBar.java b/versioning.system.cvss/src/org/netbeans/modules/versioning/system/cvss/ui/actions/annotate/AnnotationBar.java --- a/versioning.system.cvss/src/org/netbeans/modules/versioning/system/cvss/ui/actions/annotate/AnnotationBar.java +++ b/versioning.system.cvss/src/org/netbeans/modules/versioning/system/cvss/ui/actions/annotate/AnnotationBar.java @@ -357,6 +357,35 @@ return result; } + + private String getCommitMessage (AnnotateLine al) { + StringBuffer annotation=new StringBuffer(); + if (commitMessages != null) { + String message = (String) commitMessages.get(al.getRevision()); + if (message != null) { + String escaped = null; + try { + escaped = XMLUtil.toElementContent(message); + } catch (CharConversionException e1) { + ErrorManager err = ErrorManager.getDefault(); + err.annotate(e1, "CVS.AB: can not HTML escape: " + message); // NOI18N + err.notify(ErrorManager.INFORMATIONAL, e1); + } + if (escaped != null) { + String lined = escaped.replaceAll(System.getProperty("line.separator"), "
"); // NOI18N + annotation.append(lined); // NOI18N + } + } + } + return annotation.toString(); + } + /** + * + * @return + */ + JTextComponent getTextComponent () { + return textComponent; + } /** * Registers "close" popup menu, tooltip manager @@ -376,10 +405,18 @@ } private void maybeShowPopup(MouseEvent e) { +// if (e.isPopupTrigger()) { +// e.consume(); +// createPopup().show(e.getComponent(), +// e.getX(), e.getY()); +// } if (e.isPopupTrigger()) { e.consume(); - createPopup().show(e.getComponent(), + createPopup(e).show(e.getComponent(), e.getX(), e.getY()); + } else if (e.getID() == MouseEvent.MOUSE_RELEASED && e.getButton() == MouseEvent.BUTTON1) { + e.consume(); + showTooltipWindow(e); } } }); @@ -389,7 +426,7 @@ } - private JPopupMenu createPopup() { + private JPopupMenu createPopup(MouseEvent e) { final ResourceBundle loc = NbBundle.getBundle(AnnotationBar.class); final JPopupMenu popupMenu = new JPopupMenu(); final JMenuItem diffMenu = new JMenuItem(loc.getString("CTL_MenuItem_DiffToRevision")); @@ -662,26 +699,40 @@ * @return the preferred width of this component */ private int getBarWidth() { - String longestString = ""; // NOI18N if (elementAnnotations == null) { - longestString = elementAnnotationsSubstitute; + char[] data = elementAnnotationsSubstitute.toCharArray(); + int w = getGraphics().getFontMetrics().charsWidth(data, 0, data.length); + return w; } else { synchronized(elementAnnotations) { Iterator it = elementAnnotations.values().iterator(); + + // collect all possible strings + Set allUniqueDisplayNames = new HashSet(); while (it.hasNext()) { AnnotateLine line = (AnnotateLine) it.next(); String displayName = line.getRevision() + " " + line.getAuthor(); // NOI18N - if (displayName.length() > longestString.length()) { - longestString = displayName; + allUniqueDisplayNames.add(displayName); + } + if (!allUniqueDisplayNames.isEmpty()) { + // calculate the largest width + + // NOTE: texts with the same number of chars may have different widths in non-monospaced fonts + // for example: 'nr' and 'nm' - so we have to calculate the widest one + FontMetrics fontMetrics = getGraphics().getFontMetrics(); + int maxWidth = -1; + for (String displayName : allUniqueDisplayNames) { + char[] data = displayName.toCharArray(); + int w = fontMetrics.charsWidth(data, 0, data.length); + maxWidth = Math.max(maxWidth, w); } + return maxWidth; + } else { + return 0; } } } - char[] data = longestString.toCharArray(); - int w = getGraphics().getFontMetrics().charsWidth(data, 0, data.length); - return w; } - /** * Pair method to {@link #annotate}. It releases * all resources. @@ -763,23 +814,7 @@ // always return unique string to avoid tooltip sharing on mouse move over same revisions --> annotation.append("" + al.getRevision() + " " + escapedAuthor + " " + al.getDateString()); // NOI18N - if (commitMessages != null) { - String message = (String) commitMessages.get(al.getRevision()); - if (message != null) { - String escaped = null; - try { - escaped = XMLUtil.toElementContent(message); - } catch (CharConversionException e1) { - ErrorManager err = ErrorManager.getDefault(); - err.annotate(e1, "CVS.AB: can not HTML escape: " + message); // NOI18N - err.notify(ErrorManager.INFORMATIONAL, e1); - } - if (escaped != null) { - String lined = escaped.replaceAll(System.getProperty("line.separator"), "
"); // NOI18N - annotation.append("

" + lined); // NOI18N - } - } - } + annotation.append("

" + getCommitMessage(al)); } } else { annotation.append(elementAnnotationsSubstitute); @@ -884,6 +919,33 @@ doc.readUnlock(); } } + + /** + * + * @param event + */ + private void showTooltipWindow (MouseEvent event) { + Point p = new Point(event.getPoint()); + SwingUtilities.convertPointToScreen(p, this); + Point p2 = new Point(p); + SwingUtilities.convertPointFromScreen(p2, textComponent); + + // annotation for target line + AnnotateLine al = null; + if (elementAnnotations != null) { + al = getAnnotateLine(getLineFromMouseEvent(event)); + } + + /** + * al.getCommitMessage() != null - since commit messages are initialized separately from the AL constructor + */ + if (al != null && al.getRevision() != null) { + String commitMessage = getCommitMessage(al); + TooltipWindow ttw = new TooltipWindow(this, al, commitMessage); + ttw.show(new Point(p.x - p2.x, p.y)); + } + } + private Color backgroundColor() { if (textComponent != null) { @@ -1019,28 +1081,4 @@ public void componentShown(ComponentEvent e) { } - private static class CvsAnnotation extends Annotation { - - private final String text; - - private Line line; - - public CvsAnnotation(String tooltip, Line line) { - text = tooltip; - this.line = line; - } - - public void attach() { - attach(line); - line = null; - } - - public String getShortDescription() { - return text; - } - - public String getAnnotationType() { - return "org-netbeans-modules-versioning-system-cvss-Annotation"; // NOI18N - } - } } diff --git a/git/src/org/netbeans/modules/git/ui/blame/TooltipWindow.java b/versioning.system.cvss/src/org/netbeans/modules/versioning/system/cvss/ui/actions/annotate/TooltipWindow.java copy from git/src/org/netbeans/modules/git/ui/blame/TooltipWindow.java copy to versioning.system.cvss/src/org/netbeans/modules/versioning/system/cvss/ui/actions/annotate/TooltipWindow.java --- a/git/src/org/netbeans/modules/git/ui/blame/TooltipWindow.java +++ b/versioning.system.cvss/src/org/netbeans/modules/versioning/system/cvss/ui/actions/annotate/TooltipWindow.java @@ -41,7 +41,7 @@ * Version 2 license, then the option applies only if the new code is * made subject to such option by the copyright holder. */ -package org.netbeans.modules.git.ui.blame; +package org.netbeans.modules.versioning.system.cvss.ui.actions.annotate; import java.awt.AWTEvent; import java.awt.BorderLayout; @@ -64,8 +64,6 @@ import java.awt.event.WindowEvent; import java.awt.event.WindowFocusListener; import java.text.DateFormat; -import java.util.Date; -import java.util.List; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JScrollPane; @@ -78,13 +76,7 @@ import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; -import org.netbeans.modules.git.Git; -import org.netbeans.modules.versioning.util.VCSHyperlinkSupport; -import org.netbeans.modules.versioning.util.VCSHyperlinkSupport.AuthorLinker; -import org.netbeans.modules.versioning.util.VCSHyperlinkSupport.IssueLinker; -import org.netbeans.modules.versioning.util.VCSHyperlinkSupport.StyledDocumentHyperlink; -import org.netbeans.modules.versioning.util.VCSHyperlinkProvider; -import org.netbeans.modules.versioning.util.VCSKenaiAccessor.KenaiUser; +import org.netbeans.lib.cvsclient.command.annotate.AnnotateLine; /** * Window displaying the line annotation with links to bugtracking in the commit message. @@ -100,22 +92,18 @@ private final AnnotationBar master; private JTextPane textPane; private final AnnotateLine annotateLine; - /** - * Start of the commit message inside the full displayed message - */ - private int messageOffset; - - private VCSHyperlinkSupport linkerSupport = new VCSHyperlinkSupport(); /** * Currently showing popup */ private JWindow contentWindow; private TooltipContentPanel cp; + private final String commitMessage; - public TooltipWindow(AnnotationBar master, final AnnotateLine al) { + public TooltipWindow(AnnotationBar master, final AnnotateLine al, String commitMessage) { this.annotateLine = al; this.master = master; + this.commitMessage = commitMessage; } public void show(Point location) { @@ -131,7 +119,7 @@ } // showing the popup tooltip - cp = new TooltipContentPanel(master.getTextComponent()); + cp = new TooltipContentPanel(master.getTextComponent(), this.commitMessage); Window w = SwingUtilities.windowForComponent(master.getTextComponent()); contentWindow = new JWindow(w); @@ -210,8 +198,7 @@ public void mouseMoved(MouseEvent e) { if (e.getSource().equals(textPane)) { textPane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - linkerSupport.computeBounds(textPane, 0); - linkerSupport.mouseMoved(e.getPoint(), textPane, messageOffset); +// NOTE: hyperlinking not supported for CVS? } textPane.setToolTipText(""); // NOI18N } @@ -219,10 +206,7 @@ @Override public void mouseClicked(MouseEvent e) { if (e.getSource().equals(textPane)) { - linkerSupport.computeBounds(textPane, 0); - if(linkerSupport.mouseClicked(e.getPoint(), 0)) { - shutdown(); // close this window - } +// NOTE: hyperlinking not supported for CVS? } } @@ -260,7 +244,7 @@ private class TooltipContentPanel extends JComponent { - public TooltipContentPanel(JTextComponent parentPane) { + public TooltipContentPanel(JTextComponent parentPane, String commitMessage) { try { textPane = new JTextPane(); StyledDocument doc = (StyledDocument) textPane.getDocument(); @@ -276,55 +260,24 @@ // revision doc.insertString( doc.getLength(), - annotateLine.getRevisionInfo().getRevision().substring(0, 7) + " - ", + annotateLine.getRevision() + " - ", normalStyle); // author { String author = annotateLine.getAuthor().toString(); - StyledDocumentHyperlink l = linkerSupport.getLinker(AuthorLinker.class, 0); - if (master.isKenai()) { - KenaiUser kenaiUser = master.getKenaiUser(author); - if (kenaiUser != null) { - l = new AuthorLinker( - kenaiUser, - authorStyle, - doc, - author, - KenaiUser.getChatLink( - master.getCurrentFileObject(), - annotateLine.getLineNum())); - linkerSupport.add(l, 0); - } - } - if (l != null) { - l.insertString(doc, authorStyle); - } else { - doc.insertString(doc.getLength(), author, normalStyle); - } + //NOTE kenai is not supported for CVS? + doc.insertString(doc.getLength(), author, normalStyle); } // date doc.insertString(doc.getLength(), " ", normalStyle); - doc.insertString(doc.getLength(), DateFormat.getDateInstance().format(new Date(annotateLine.getRevisionInfo().getCommitTime())), normalStyle); + doc.insertString(doc.getLength(), DateFormat.getDateInstance().format(annotateLine.getDate()), normalStyle); doc.insertString(doc.getLength(), "\n", normalStyle); // commit msg - { - StyledDocumentHyperlink l = null; - String commitMessage = annotateLine.getRevisionInfo().getFullMessage(); - List providers = Git.getInstance().getHyperlinkProviders(); - for (VCSHyperlinkProvider hp : providers) { - l = IssueLinker.create(hp, hyperlinkStyle, master.getRepositoryRoot(), doc, commitMessage); - if (l != null) { - linkerSupport.add(l, 0); - break; - } - } - if (l != null) { - l.insertString(doc, normalStyle); - } else { - doc.insertString(doc.getLength(), commitMessage, normalStyle); - } + { + //NOTE: hyperlinks are not supported for CVS? + doc.insertString(doc.getLength(), commitMessage, normalStyle); } textPane.setDocument(doc); textPane.setEditable(false);