This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 218932
Collapse All | Expand All

(-)a/versioning.system.cvss/src/org/netbeans/modules/versioning/system/cvss/ui/actions/annotate/AnnotationBar.java (-51 / +89 lines)
Lines 357-362 Link Here
357
        
357
        
358
        return result;
358
        return result;
359
    }
359
    }
360
361
    private String getCommitMessage (AnnotateLine al) {
362
        StringBuffer annotation=new StringBuffer();
363
        if (commitMessages != null) {
364
            String message = (String) commitMessages.get(al.getRevision());
365
            if (message != null) {
366
                String escaped = null;
367
                try {
368
                    escaped = XMLUtil.toElementContent(message);
369
                } catch (CharConversionException e1) {
370
                    ErrorManager err = ErrorManager.getDefault();
371
                    err.annotate(e1, "CVS.AB: can not HTML escape: " + message); // NOI18N
372
                    err.notify(ErrorManager.INFORMATIONAL, e1);
373
                }
374
                if (escaped != null) {
375
                    String lined = escaped.replaceAll(System.getProperty("line.separator"), "<br>");  // NOI18N
376
                    annotation.append(lined); // NOI18N
377
                }
378
            }
379
        }
380
        return annotation.toString();
381
    }
382
    /**
383
     *
384
     * @return
385
     */
386
    JTextComponent getTextComponent () {
387
        return textComponent;
388
    }
360
    
389
    
361
    /**
390
    /**
362
     * Registers "close" popup menu, tooltip manager
391
     * Registers "close" popup menu, tooltip manager
Lines 376-385 Link Here
376
            }
405
            }
377
406
378
            private void maybeShowPopup(MouseEvent e) {
407
            private void maybeShowPopup(MouseEvent e) {
408
//                if (e.isPopupTrigger()) {
409
//                    e.consume();
410
//                    createPopup().show(e.getComponent(),
411
//                               e.getX(), e.getY());
412
//                }
379
                if (e.isPopupTrigger()) {
413
                if (e.isPopupTrigger()) {
380
                    e.consume();
414
                    e.consume();
381
                    createPopup().show(e.getComponent(),
415
                    createPopup(e).show(e.getComponent(),
382
                               e.getX(), e.getY());
416
                               e.getX(), e.getY());
417
                } else if (e.getID() == MouseEvent.MOUSE_RELEASED && e.getButton() == MouseEvent.BUTTON1) {
418
                    e.consume();
419
                    showTooltipWindow(e);
383
                }
420
                }
384
            }
421
            }
385
        });
422
        });
Lines 389-395 Link Here
389
426
390
    }
427
    }
391
428
392
    private JPopupMenu createPopup() {
429
    private JPopupMenu createPopup(MouseEvent e) {
393
        final ResourceBundle loc = NbBundle.getBundle(AnnotationBar.class);
430
        final ResourceBundle loc = NbBundle.getBundle(AnnotationBar.class);
394
        final JPopupMenu popupMenu = new JPopupMenu();
431
        final JPopupMenu popupMenu = new JPopupMenu();
395
        final JMenuItem diffMenu = new JMenuItem(loc.getString("CTL_MenuItem_DiffToRevision"));
432
        final JMenuItem diffMenu = new JMenuItem(loc.getString("CTL_MenuItem_DiffToRevision"));
Lines 662-687 Link Here
662
     * @return the preferred width of this component
699
     * @return the preferred width of this component
663
     */
700
     */
664
    private int getBarWidth() {
701
    private int getBarWidth() {
665
        String longestString = "";  // NOI18N
666
        if (elementAnnotations == null) {
702
        if (elementAnnotations == null) {
667
            longestString = elementAnnotationsSubstitute;
703
            char[] data = elementAnnotationsSubstitute.toCharArray();
704
            int w = getGraphics().getFontMetrics().charsWidth(data, 0, data.length);
705
            return w;
668
        } else {
706
        } else {
669
            synchronized(elementAnnotations) {
707
            synchronized(elementAnnotations) {
670
                Iterator it = elementAnnotations.values().iterator();
708
                Iterator it = elementAnnotations.values().iterator();
709
710
                // collect all possible strings
711
                Set<String> allUniqueDisplayNames = new HashSet<String>();
671
                while (it.hasNext()) {
712
                while (it.hasNext()) {
672
                    AnnotateLine line = (AnnotateLine) it.next();
713
                    AnnotateLine line = (AnnotateLine) it.next();
673
                    String displayName = line.getRevision() + " " + line.getAuthor(); // NOI18N
714
                    String displayName = line.getRevision() + " " + line.getAuthor(); // NOI18N
674
                    if (displayName.length() > longestString.length()) {
715
                    allUniqueDisplayNames.add(displayName);
675
                        longestString = displayName;
716
                }
717
                if (!allUniqueDisplayNames.isEmpty()) {
718
                    // calculate the largest width
719
720
                    // NOTE: texts with the same number of chars may have different widths in non-monospaced fonts
721
                    // for example: 'nr' and 'nm' - so we have to calculate the widest one
722
                    FontMetrics fontMetrics = getGraphics().getFontMetrics();
723
                    int maxWidth = -1;
724
                    for (String displayName : allUniqueDisplayNames) {
725
                        char[] data = displayName.toCharArray();
726
                        int w = fontMetrics.charsWidth(data, 0, data.length);
727
                        maxWidth = Math.max(maxWidth, w);
676
                    }
728
                    }
729
                    return maxWidth;
730
                } else {
731
                    return 0;
677
                }
732
                }
678
            }
733
            }
679
        }
734
        }
680
        char[] data = longestString.toCharArray();
681
        int w = getGraphics().getFontMetrics().charsWidth(data, 0,  data.length);
682
        return w;
683
    }
735
    }
684
    
685
    /**
736
    /**
686
     * Pair method to {@link #annotate}. It releases
737
     * Pair method to {@link #annotate}. It releases
687
     * all resources.
738
     * all resources.
Lines 763-785 Link Here
763
814
764
                // always return unique string to avoid tooltip sharing on mouse move over same revisions -->
815
                // always return unique string to avoid tooltip sharing on mouse move over same revisions -->
765
                annotation.append("<html><!-- line=" + line++ + " -->" + al.getRevision()  + " <b>" + escapedAuthor + "</b> " + al.getDateString()); // NOI18N
816
                annotation.append("<html><!-- line=" + line++ + " -->" + al.getRevision()  + " <b>" + escapedAuthor + "</b> " + al.getDateString()); // NOI18N
766
                if (commitMessages != null) {
817
                annotation.append("<p>" + getCommitMessage(al)); 
767
                    String message = (String) commitMessages.get(al.getRevision());
768
                    if (message != null) {
769
                        String escaped = null;
770
                        try {
771
                            escaped = XMLUtil.toElementContent(message);
772
                        } catch (CharConversionException e1) {
773
                            ErrorManager err = ErrorManager.getDefault();
774
                            err.annotate(e1, "CVS.AB: can not HTML escape: " + message); // NOI18N
775
                            err.notify(ErrorManager.INFORMATIONAL, e1);
776
                        }
777
                        if (escaped != null) {
778
                            String lined = escaped.replaceAll(System.getProperty("line.separator"), "<br>");  // NOI18N
779
                            annotation.append("<p>" + lined); // NOI18N
780
                        }
781
                    }
782
                }
783
            }
818
            }
784
        } else {
819
        } else {
785
            annotation.append(elementAnnotationsSubstitute);
820
            annotation.append(elementAnnotationsSubstitute);
Lines 884-889 Link Here
884
            doc.readUnlock();
919
            doc.readUnlock();
885
        }
920
        }
886
    }
921
    }
922
    
923
    /**
924
     *
925
     * @param event
926
     */
927
    private void showTooltipWindow (MouseEvent event) {
928
        Point p = new Point(event.getPoint());
929
        SwingUtilities.convertPointToScreen(p, this);
930
        Point p2 = new Point(p);
931
        SwingUtilities.convertPointFromScreen(p2, textComponent);
932
        
933
        // annotation for target line
934
        AnnotateLine al = null;
935
        if (elementAnnotations != null) {
936
            al = getAnnotateLine(getLineFromMouseEvent(event));
937
        }
938
939
        /**
940
         * al.getCommitMessage() != null - since commit messages are initialized separately from the AL constructor
941
         */
942
        if (al != null && al.getRevision() != null) {
943
            String commitMessage = getCommitMessage(al);
944
            TooltipWindow ttw = new TooltipWindow(this, al, commitMessage);
945
            ttw.show(new Point(p.x - p2.x, p.y));
946
        }
947
    }
948
887
949
888
    private Color backgroundColor() {
950
    private Color backgroundColor() {
889
        if (textComponent != null) {
951
        if (textComponent != null) {
Lines 1019-1046 Link Here
1019
    public void componentShown(ComponentEvent e) {
1081
    public void componentShown(ComponentEvent e) {
1020
    }
1082
    }
1021
1083
1022
    private static class CvsAnnotation extends Annotation {
1023
        
1024
        private final String text;
1025
1026
        private Line line;
1027
1028
        public CvsAnnotation(String tooltip, Line line) {
1029
            text = tooltip;
1030
            this.line = line;
1031
        }
1032
1033
        public void attach() {
1034
            attach(line);
1035
            line = null;
1036
        }
1037
1038
        public String getShortDescription() {
1039
            return text;
1040
        }
1041
1042
        public String getAnnotationType() {
1043
            return "org-netbeans-modules-versioning-system-cvss-Annotation";  // NOI18N
1044
        }        
1045
    }
1046
}
1084
}
(-)a/git/src/org/netbeans/modules/git/ui/blame/TooltipWindow.java (-63 / +16 lines)
Lines 41-47 Link Here
41
 * Version 2 license, then the option applies only if the new code is
41
 * Version 2 license, then the option applies only if the new code is
42
 * made subject to such option by the copyright holder.
42
 * made subject to such option by the copyright holder.
43
 */
43
 */
44
package org.netbeans.modules.git.ui.blame;
44
package org.netbeans.modules.versioning.system.cvss.ui.actions.annotate;
45
45
46
import java.awt.AWTEvent;
46
import java.awt.AWTEvent;
47
import java.awt.BorderLayout;
47
import java.awt.BorderLayout;
Lines 64-71 Link Here
64
import java.awt.event.WindowEvent;
64
import java.awt.event.WindowEvent;
65
import java.awt.event.WindowFocusListener;
65
import java.awt.event.WindowFocusListener;
66
import java.text.DateFormat;
66
import java.text.DateFormat;
67
import java.util.Date;
68
import java.util.List;
69
import javax.swing.BorderFactory;
67
import javax.swing.BorderFactory;
70
import javax.swing.JComponent;
68
import javax.swing.JComponent;
71
import javax.swing.JScrollPane;
69
import javax.swing.JScrollPane;
Lines 78-90 Link Here
78
import javax.swing.text.Style;
76
import javax.swing.text.Style;
79
import javax.swing.text.StyleConstants;
77
import javax.swing.text.StyleConstants;
80
import javax.swing.text.StyledDocument;
78
import javax.swing.text.StyledDocument;
81
import org.netbeans.modules.git.Git;
79
import org.netbeans.lib.cvsclient.command.annotate.AnnotateLine;
82
import org.netbeans.modules.versioning.util.VCSHyperlinkSupport;
83
import org.netbeans.modules.versioning.util.VCSHyperlinkSupport.AuthorLinker;
84
import org.netbeans.modules.versioning.util.VCSHyperlinkSupport.IssueLinker;
85
import org.netbeans.modules.versioning.util.VCSHyperlinkSupport.StyledDocumentHyperlink;
86
import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
87
import org.netbeans.modules.versioning.util.VCSKenaiAccessor.KenaiUser;
88
80
89
/**
81
/**
90
 * Window displaying the line annotation with links to bugtracking in the commit message.
82
 * Window displaying the line annotation with links to bugtracking in the commit message.
Lines 100-121 Link Here
100
    private final AnnotationBar master;
92
    private final AnnotationBar master;
101
    private JTextPane textPane;
93
    private JTextPane textPane;
102
    private final AnnotateLine annotateLine;
94
    private final AnnotateLine annotateLine;
103
    /**
104
     * Start of the commit message inside the full displayed message
105
     */
106
    private int messageOffset;
107
108
    private VCSHyperlinkSupport linkerSupport = new VCSHyperlinkSupport();
109
95
110
    /**
96
    /**
111
     * Currently showing popup
97
     * Currently showing popup
112
     */
98
     */
113
    private JWindow contentWindow;
99
    private JWindow contentWindow;
114
    private TooltipContentPanel cp;
100
    private TooltipContentPanel cp;
101
    private final String commitMessage;
115
102
116
    public TooltipWindow(AnnotationBar master, final AnnotateLine al) {
103
    public TooltipWindow(AnnotationBar master, final AnnotateLine al, String commitMessage) {
117
        this.annotateLine = al;
104
        this.annotateLine = al;
118
        this.master = master;
105
        this.master = master;
106
        this.commitMessage = commitMessage;
119
    }
107
    }
120
108
121
    public void show(Point location) {
109
    public void show(Point location) {
Lines 131-137 Link Here
131
        }
119
        }
132
120
133
        // showing the popup tooltip
121
        // showing the popup tooltip
134
        cp = new TooltipContentPanel(master.getTextComponent());
122
        cp = new TooltipContentPanel(master.getTextComponent(), this.commitMessage);
135
123
136
        Window w = SwingUtilities.windowForComponent(master.getTextComponent());
124
        Window w = SwingUtilities.windowForComponent(master.getTextComponent());
137
        contentWindow = new JWindow(w);
125
        contentWindow = new JWindow(w);
Lines 210-217 Link Here
210
    public void mouseMoved(MouseEvent e) {
198
    public void mouseMoved(MouseEvent e) {
211
        if (e.getSource().equals(textPane)) {
199
        if (e.getSource().equals(textPane)) {
212
            textPane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
200
            textPane.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
213
            linkerSupport.computeBounds(textPane, 0);
201
//          NOTE: hyperlinking not supported for CVS?
214
            linkerSupport.mouseMoved(e.getPoint(), textPane, messageOffset);
215
        }
202
        }
216
        textPane.setToolTipText("");  // NOI18N
203
        textPane.setToolTipText("");  // NOI18N
217
    }
204
    }
Lines 219-228 Link Here
219
    @Override
206
    @Override
220
    public void mouseClicked(MouseEvent e) {
207
    public void mouseClicked(MouseEvent e) {
221
        if (e.getSource().equals(textPane)) {
208
        if (e.getSource().equals(textPane)) {
222
            linkerSupport.computeBounds(textPane, 0);
209
//          NOTE: hyperlinking not supported for CVS?
223
            if(linkerSupport.mouseClicked(e.getPoint(), 0)) {
224
                shutdown(); // close this window
225
            }
226
        }
210
        }
227
    }
211
    }
228
212
Lines 260-266 Link Here
260
244
261
    private class TooltipContentPanel extends JComponent {
245
    private class TooltipContentPanel extends JComponent {
262
246
263
        public TooltipContentPanel(JTextComponent parentPane) {
247
        public TooltipContentPanel(JTextComponent parentPane, String commitMessage) {
264
            try {
248
            try {
265
                textPane = new JTextPane();
249
                textPane = new JTextPane();
266
                StyledDocument doc = (StyledDocument) textPane.getDocument();
250
                StyledDocument doc = (StyledDocument) textPane.getDocument();
Lines 276-330 Link Here
276
                // revision
260
                // revision
277
                doc.insertString(
261
                doc.insertString(
278
                        doc.getLength(),
262
                        doc.getLength(),
279
                        annotateLine.getRevisionInfo().getRevision().substring(0, 7) + " - ",
263
                        annotateLine.getRevision() + " - ",
280
                        normalStyle);
264
                        normalStyle);
281
265
282
                // author
266
                // author
283
                {
267
                {
284
                    String author = annotateLine.getAuthor().toString();
268
                    String author = annotateLine.getAuthor().toString();
285
                    StyledDocumentHyperlink l = linkerSupport.getLinker(AuthorLinker.class, 0);
269
                    //NOTE kenai is not supported for CVS?
286
                    if (master.isKenai()) {
270
                    doc.insertString(doc.getLength(), author, normalStyle);
287
                        KenaiUser kenaiUser = master.getKenaiUser(author);
288
                        if (kenaiUser != null) {
289
                            l = new AuthorLinker(
290
                                    kenaiUser,
291
                                    authorStyle,
292
                                    doc,
293
                                    author,
294
                                    KenaiUser.getChatLink(
295
                                    master.getCurrentFileObject(),
296
                                    annotateLine.getLineNum()));
297
                            linkerSupport.add(l, 0);
298
                        }
299
                    }
300
                    if (l != null) {
301
                        l.insertString(doc, authorStyle);
302
                    } else {
303
                        doc.insertString(doc.getLength(), author, normalStyle);
304
                    }
305
                }
271
                }
306
                // date
272
                // date
307
                doc.insertString(doc.getLength(), " ", normalStyle);
273
                doc.insertString(doc.getLength(), " ", normalStyle);
308
                doc.insertString(doc.getLength(), DateFormat.getDateInstance().format(new Date(annotateLine.getRevisionInfo().getCommitTime())), normalStyle);
274
                doc.insertString(doc.getLength(), DateFormat.getDateInstance().format(annotateLine.getDate()), normalStyle);
309
                doc.insertString(doc.getLength(), "\n", normalStyle);
275
                doc.insertString(doc.getLength(), "\n", normalStyle);
310
276
311
                // commit msg
277
                // commit msg
312
                {
278
                { 
313
                    StyledDocumentHyperlink l = null;
279
                    //NOTE: hyperlinks are not supported for CVS?
314
                    String commitMessage = annotateLine.getRevisionInfo().getFullMessage();
280
                    doc.insertString(doc.getLength(), commitMessage, normalStyle);
315
                    List<VCSHyperlinkProvider> providers = Git.getInstance().getHyperlinkProviders();
316
                    for (VCSHyperlinkProvider hp : providers) {
317
                        l = IssueLinker.create(hp, hyperlinkStyle, master.getRepositoryRoot(), doc, commitMessage);
318
                        if (l != null) {
319
                            linkerSupport.add(l, 0);
320
                            break;
321
                        }
322
                    }
323
                    if (l != null) {
324
                        l.insertString(doc, normalStyle);
325
                    } else {
326
                        doc.insertString(doc.getLength(), commitMessage, normalStyle);
327
                    }
328
                }
281
                }
329
                textPane.setDocument(doc);
282
                textPane.setDocument(doc);
330
                textPane.setEditable(false);
283
                textPane.setEditable(false);

Return to bug 218932