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 (-45 / +67 lines)
Lines 357-362 Link Here
357
        
357
        
358
        return result;
358
        return result;
359
    }
359
    }
360
361
    private String getCommitMessage (AnnotateLine al, boolean escape) {
362
        StringBuilder annotation=new StringBuilder();
363
        if (commitMessages != null) {
364
            String message = (String) commitMessages.get(al.getRevision());
365
            if (message != null) {
366
                if (escape) {
367
                    String escaped = null;
368
                    try {
369
                        escaped = XMLUtil.toElementContent(message);
370
                    } catch (CharConversionException e1) {
371
                        ErrorManager err = ErrorManager.getDefault();
372
                        err.annotate(e1, "CVS.AB: can not HTML escape: " + message); // NOI18N
373
                        err.notify(ErrorManager.INFORMATIONAL, e1);
374
                    }
375
                    if (escaped != null) {
376
                        String lined = escaped.replaceAll(System.getProperty("line.separator"), "<br>");  // NOI18N
377
                        annotation.append(lined); // NOI18N
378
                    }
379
                } else {
380
                    annotation.append(message);
381
                }
382
            }
383
        }
384
        return annotation.toString();
385
    }
386
    /**
387
     *
388
     * @return
389
     */
390
    JTextComponent getTextComponent () {
391
        return textComponent;
392
    }
360
    
393
    
361
    /**
394
    /**
362
     * Registers "close" popup menu, tooltip manager
395
     * Registers "close" popup menu, tooltip manager
Lines 378-385 Link Here
378
            private void maybeShowPopup(MouseEvent e) {
411
            private void maybeShowPopup(MouseEvent e) {
379
                if (e.isPopupTrigger()) {
412
                if (e.isPopupTrigger()) {
380
                    e.consume();
413
                    e.consume();
381
                    createPopup().show(e.getComponent(),
414
                    createPopup(e).show(e.getComponent(),
382
                               e.getX(), e.getY());
415
                               e.getX(), e.getY());
416
                } else if (e.getID() == MouseEvent.MOUSE_RELEASED && e.getButton() == MouseEvent.BUTTON1) {
417
                    e.consume();
418
                    showTooltipWindow(e);
383
                }
419
                }
384
            }
420
            }
385
        });
421
        });
Lines 389-395 Link Here
389
425
390
    }
426
    }
391
427
392
    private JPopupMenu createPopup() {
428
    private JPopupMenu createPopup(MouseEvent e) {
393
        final ResourceBundle loc = NbBundle.getBundle(AnnotationBar.class);
429
        final ResourceBundle loc = NbBundle.getBundle(AnnotationBar.class);
394
        final JPopupMenu popupMenu = new JPopupMenu();
430
        final JPopupMenu popupMenu = new JPopupMenu();
395
        final JMenuItem diffMenu = new JMenuItem(loc.getString("CTL_MenuItem_DiffToRevision"));
431
        final JMenuItem diffMenu = new JMenuItem(loc.getString("CTL_MenuItem_DiffToRevision"));
Lines 747-753 Link Here
747
            return null;
783
            return null;
748
        int line = getLineFromMouseEvent(e);
784
        int line = getLineFromMouseEvent(e);
749
785
750
        StringBuffer annotation = new StringBuffer();
786
        StringBuilder annotation = new StringBuilder();
751
        if (elementAnnotations != null) {
787
        if (elementAnnotations != null) {
752
            AnnotateLine al = getAnnotateLine(line);
788
            AnnotateLine al = getAnnotateLine(line);
753
789
Lines 763-786 Link Here
763
799
764
                // always return unique string to avoid tooltip sharing on mouse move over same revisions -->
800
                // 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
801
                annotation.append("<html><!-- line=" + line++ + " -->" + al.getRevision()  + " <b>" + escapedAuthor + "</b> " + al.getDateString()); // NOI18N
766
                if (commitMessages != null) {
802
                annotation.append("<p>" + getCommitMessage(al, true));
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("\r\n", "\n").replaceAll("\r", "\n") //NOI18N
779
                                    .replaceAll("\n", "<br>"); //NOI18N
780
                            annotation.append("<p>" + lined); // NOI18N
781
                        }
782
                    }
783
                }
784
            }
803
            }
785
        } else {
804
        } else {
786
            annotation.append(elementAnnotationsSubstitute);
805
            annotation.append(elementAnnotationsSubstitute);
Lines 885-890 Link Here
885
            doc.readUnlock();
904
            doc.readUnlock();
886
        }
905
        }
887
    }
906
    }
907
    
908
    /**
909
     *
910
     * @param event
911
     */
912
    private void showTooltipWindow (MouseEvent event) {
913
        Point p = new Point(event.getPoint());
914
        SwingUtilities.convertPointToScreen(p, this);
915
        Point p2 = new Point(p);
916
        SwingUtilities.convertPointFromScreen(p2, textComponent);
917
        
918
        // annotation for target line
919
        AnnotateLine al = null;
920
        if (elementAnnotations != null) {
921
            al = getAnnotateLine(getLineFromMouseEvent(event));
922
        }
923
924
        /**
925
         * al.getCommitMessage() != null - since commit messages are initialized separately from the AL constructor
926
         */
927
        if (al != null && al.getRevision() != null) {
928
            String commitMessage = getCommitMessage(al, false);
929
            TooltipWindow ttw = new TooltipWindow(this, al, commitMessage);
930
            ttw.show(new Point(p.x - p2.x, p.y));
931
        }
932
    }
933
888
934
889
    private Color backgroundColor() {
935
    private Color backgroundColor() {
890
        if (textComponent != null) {
936
        if (textComponent != null) {
Lines 1020-1047 Link Here
1020
    public void componentShown(ComponentEvent e) {
1066
    public void componentShown(ComponentEvent e) {
1021
    }
1067
    }
1022
1068
1023
    private static class CvsAnnotation extends Annotation {
1024
        
1025
        private final String text;
1026
1027
        private Line line;
1028
1029
        public CvsAnnotation(String tooltip, Line line) {
1030
            text = tooltip;
1031
            this.line = line;
1032
        }
1033
1034
        public void attach() {
1035
            attach(line);
1036
            line = null;
1037
        }
1038
1039
        public String getShortDescription() {
1040
            return text;
1041
        }
1042
1043
        public String getAnnotationType() {
1044
            return "org-netbeans-modules-versioning-system-cvss-Annotation";  // NOI18N
1045
        }        
1046
    }
1047
}
1069
}
(-)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