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 218850
Collapse All | Expand All

(-)a/versioning.util/src/org/netbeans/modules/versioning/history/SummaryCellRenderer.java (-123 / +319 lines)
Lines 85-98 Link Here
85
import org.netbeans.api.editor.mimelookup.MimeLookup;
85
import org.netbeans.api.editor.mimelookup.MimeLookup;
86
import org.netbeans.api.editor.mimelookup.MimePath;
86
import org.netbeans.api.editor.mimelookup.MimePath;
87
import org.netbeans.api.editor.settings.FontColorSettings;
87
import org.netbeans.api.editor.settings.FontColorSettings;
88
import org.netbeans.modules.versioning.history.AbstractSummaryView.LogEntry;
88
import org.netbeans.modules.versioning.history.AbstractSummaryView.LogEntry.Event;
89
import org.netbeans.modules.versioning.history.AbstractSummaryView.LogEntry.Event;
89
import org.netbeans.modules.versioning.history.AbstractSummaryView.RevisionItem;
90
import org.netbeans.modules.versioning.history.AbstractSummaryView.RevisionItem;
90
import org.netbeans.modules.versioning.history.AbstractSummaryView.SummaryViewMaster.SearchHighlight;
91
import org.netbeans.modules.versioning.history.AbstractSummaryView.SummaryViewMaster.SearchHighlight;
91
import org.netbeans.modules.versioning.util.Utils;
92
import org.netbeans.modules.versioning.util.Utils;
92
import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
93
import org.netbeans.modules.versioning.util.VCSHyperlinkProvider;
93
import org.netbeans.modules.versioning.util.VCSHyperlinkSupport;
94
import org.netbeans.modules.versioning.util.VCSHyperlinkSupport;
95
import org.netbeans.modules.versioning.util.VCSHyperlinkSupport.IssueLinker;
94
import org.netbeans.modules.versioning.util.VCSKenaiAccessor;
96
import org.netbeans.modules.versioning.util.VCSKenaiAccessor;
95
import org.openide.ErrorManager;
97
import org.openide.ErrorManager;
98
import org.openide.util.Exceptions;
96
import org.openide.util.Lookup;
99
import org.openide.util.Lookup;
97
import org.openide.util.NbBundle;
100
import org.openide.util.NbBundle;
98
101
Lines 116-124 Link Here
116
    private MoreRevisionsRenderer mr = new MoreRevisionsRenderer();
119
    private MoreRevisionsRenderer mr = new MoreRevisionsRenderer();
117
    private DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
120
    private DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
118
    private ListCellRenderer remainingFilesRenderer = new RemainingFilesRenderer();
121
    private ListCellRenderer remainingFilesRenderer = new RemainingFilesRenderer();
119
122
    
120
    private AttributeSet searchHiliteAttrs;
123
    private AttributeSet searchHiliteAttrs;
121
124
    
122
    private static final Icon ICON_COLLAPSED = UIManager.getIcon("Tree.collapsedIcon"); //NOI18N
125
    private static final Icon ICON_COLLAPSED = UIManager.getIcon("Tree.collapsedIcon"); //NOI18N
123
    private static final Icon ICON_EXPANDED = UIManager.getIcon("Tree.expandedIcon"); //NOI18N
126
    private static final Icon ICON_EXPANDED = UIManager.getIcon("Tree.expandedIcon"); //NOI18N
124
    private static final int INDENT = ICON_EXPANDED.getIconWidth() + 3;
127
    private static final int INDENT = ICON_EXPANDED.getIconWidth() + 3;
Lines 233-239 Link Here
233
        }
236
        }
234
        return maxWidth;
237
        return maxWidth;
235
    }
238
    }
236
    
239
237
    public Collection<VCSHyperlinkProvider> getHyperlinkProviders() {
240
    public Collection<VCSHyperlinkProvider> getHyperlinkProviders() {
238
        if (hpInstances == null) {
241
        if (hpInstances == null) {
239
            Lookup.Result<VCSHyperlinkProvider> hpResult = Lookup.getDefault().lookupResult(VCSHyperlinkProvider.class);
242
            Lookup.Result<VCSHyperlinkProvider> hpResult = Lookup.getDefault().lookupResult(VCSHyperlinkProvider.class);
Lines 250-268 Link Here
250
        return kenaiUser;
253
        return kenaiUser;
251
    }
254
    }
252
255
256
    /**
257
     * Composite panel for displaying revision, author, commit message and other info.
258
     */
259
    public class RevisionItemCell extends JPanel{
260
261
        private JTextPane authorControl;
262
263
        private JTextPane dateControl;
264
        private JTextPane revisionControl;
265
        private JTextPane commitMessageControl;
266
        private JPanel northPanel;
267
        private JPanel authorDatePanel;
268
269
        public RevisionItemCell() {
270
271
            northPanel = new javax.swing.JPanel();
272
            authorDatePanel = new javax.swing.JPanel();
273
            dateControl = new JTextPane();
274
            authorControl = new JTextPane();
275
            revisionControl = new JTextPane();
276
            commitMessageControl = new JTextPane();
277
278
            this.setBorder(null);
279
            this.setLayout(new BorderLayout(0, 0));
280
            this.add(commitMessageControl, java.awt.BorderLayout.CENTER);
281
            this.add(northPanel, java.awt.BorderLayout.NORTH);
282
            dateControl.setBorder(null);
283
            dateControl.setLayout(null);
284
            authorControl.setBorder(null);
285
            authorControl.setLayout(null);
286
            revisionControl.setBorder(null);
287
            revisionControl.setLayout(null);
288
            commitMessageControl.setBorder(null);
289
            commitMessageControl.setLayout(null);
290
            
291
292
            northPanel.setBorder(BorderFactory.createEmptyBorder());
293
            northPanel.setLayout(new BorderLayout(5, 0));
294
            northPanel.add(authorDatePanel, java.awt.BorderLayout.EAST);
295
            northPanel.add(revisionControl, java.awt.BorderLayout.CENTER);
296
297
            authorDatePanel.setLayout(new BorderLayout(5, 0));
298
            authorDatePanel.setBorder(BorderFactory.createEmptyBorder());
299
            authorDatePanel.add(authorControl, BorderLayout.CENTER);
300
            authorDatePanel.add(dateControl,BorderLayout.EAST);
301
            
302
            northPanel.setOpaque(false);
303
            revisionControl.setOpaque(false);
304
            dateControl.setOpaque(false);
305
            authorControl.setOpaque(false);
306
            commitMessageControl.setOpaque(false);
307
            authorDatePanel.setOpaque(false);
308
            
309
            this.setFocusable(false);
310
            northPanel.setFocusable(false);
311
            authorDatePanel.setFocusable(false);
312
            
313
        }
314
315
        public JTextPane getAuthorControl() {
316
            return authorControl;
317
        }
318
319
        public JTextPane getDateControl() {
320
            return dateControl;
321
        }
322
323
        public JTextPane getRevisionControl() {
324
            return revisionControl;
325
        }
326
327
        public JTextPane getCommitMessageControl() {
328
            return commitMessageControl;
329
        }
330
331
        public JPanel getNorthPanel() {
332
            return northPanel;
333
        }
334
335
    }
336
253
    private class RevisionRenderer extends JPanel implements ListCellRenderer {
337
    private class RevisionRenderer extends JPanel implements ListCellRenderer {
254
338
255
        private String id;
339
        private String id;
256
        private final Style selectedStyle;
257
        private final Style normalStyle;
258
        private final Style indentStyle;
259
        private final Style noindentStyle;
260
        private final Style issueHyperlinkStyle;
261
        private final Style linkStyle;
262
        private final Style authorStyle;
263
        private final Style hiliteStyle;
264
        private boolean lastSelection = false;
340
        private boolean lastSelection = false;
265
        private final JTextPane textPane;
341
        private final RevisionItemCell revisionCell = new RevisionItemCell();
266
        private final JButton expandButton;
342
        private final JButton expandButton;
267
        private String commitMessage = ""; //NOI18N
343
        private String commitMessage = ""; //NOI18N
268
        private boolean lastMessageExpanded;
344
        private boolean lastMessageExpanded;
Lines 272-317 Link Here
272
348
273
        public RevisionRenderer() {
349
        public RevisionRenderer() {
274
            selectionForeground = new JList().getSelectionForeground();
350
            selectionForeground = new JList().getSelectionForeground();
275
            textPane = new JTextPane();
276
            expandButton = new LinkButton(ICON_COLLAPSED);
351
            expandButton = new LinkButton(ICON_COLLAPSED);
277
            expandButton.setBorder(BorderFactory.createEmptyBorder());
352
            expandButton.setBorder(BorderFactory.createEmptyBorder());
278
353
279
            selectedStyle = textPane.addStyle("selected", null); //NOI18N
354
            this.setBorder(BorderFactory.createMatteBorder(3, 0, 0, 0, UIManager.getColor("List.background"))); //NOI18N
280
            StyleConstants.setForeground(selectedStyle, selectionForeground);
355
            this.setLayout(new BorderLayout(3, 0));
281
            StyleConstants.setBackground(selectedStyle, selectionBackground);
282
            normalStyle = textPane.addStyle("normal", null); //NOI18N
283
            StyleConstants.setForeground(normalStyle, UIManager.getColor("List.foreground")); //NOI18N
284
            indentStyle = textPane.addStyle("indent", null); //NOI18N
285
            StyleConstants.setLeftIndent(indentStyle, 50);
286
            noindentStyle = textPane.addStyle("noindent", null); //NOI18N
287
            StyleConstants.setLeftIndent(noindentStyle, 0);
288
356
289
            issueHyperlinkStyle = textPane.addStyle("issuehyperlink", normalStyle); //NOI18N
290
            StyleConstants.setForeground(issueHyperlinkStyle, Color.BLUE);
291
            StyleConstants.setUnderline(issueHyperlinkStyle, true);
292
293
            linkStyle = textPane.addStyle("link", normalStyle); //NOI18N
294
            StyleConstants.setForeground(linkStyle, Color.BLUE);
295
            StyleConstants.setBold(linkStyle, true);
296
297
            authorStyle = textPane.addStyle("author", normalStyle); //NOI18N
298
            StyleConstants.setForeground(authorStyle, Color.BLUE);
299
300
            hiliteStyle = textPane.addStyle("hilite", normalStyle); //NOI18N
301
            
302
            Color c = (Color) searchHiliteAttrs.getAttribute(StyleConstants.Background);
303
            if (c != null) StyleConstants.setBackground(hiliteStyle, c);
304
            c = (Color) searchHiliteAttrs.getAttribute(StyleConstants.Foreground);
305
            if (c != null) StyleConstants.setForeground(hiliteStyle, c);
306
307
            textPane.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
308
            setLayout(new BorderLayout(0, 0));
309
            setBorder(BorderFactory.createMatteBorder(3, 0, 0, 0, UIManager.getColor("List.background"))); //NOI18N
310
            
311
            add(expandButton, BorderLayout.WEST);
312
            expandButton.setMaximumSize(expandButton.getPreferredSize());
357
            expandButton.setMaximumSize(expandButton.getPreferredSize());
313
            expandButton.setMinimumSize(expandButton.getPreferredSize());
358
            expandButton.setMinimumSize(expandButton.getPreferredSize());
314
            add(textPane, BorderLayout.CENTER);
359
            this.add(expandButton, BorderLayout.WEST);
360
            this.add(revisionCell, BorderLayout.CENTER);
315
        }
361
        }
316
362
317
        @Override
363
        @Override
Lines 319-350 Link Here
319
            AbstractSummaryView.RevisionItem item = (AbstractSummaryView.RevisionItem) value;
365
            AbstractSummaryView.RevisionItem item = (AbstractSummaryView.RevisionItem) value;
320
            AbstractSummaryView.LogEntry entry = item.getUserData();
366
            AbstractSummaryView.LogEntry entry = item.getUserData();
321
367
322
            StyledDocument sd = textPane.getStyledDocument();
323
            Collection<SearchHighlight> highlights = summaryView.getMaster().getSearchHighlights();
368
            Collection<SearchHighlight> highlights = summaryView.getMaster().getSearchHighlights();
324
            if (sd.getLength() == 0 || selected != lastSelection || item.messageExpanded != lastMessageExpanded || item.revisionExpanded != lastRevisionExpanded
369
            if (revisionCell.getRevisionControl().getStyledDocument().getLength() == 0 || revisionCell.getDateControl().getStyledDocument().getLength() == 0 ||revisionCell.getAuthorControl().getStyledDocument().getLength() == 0|| revisionCell.getCommitMessageControl().getStyledDocument().getLength() == 0 || selected != lastSelection || item.messageExpanded != lastMessageExpanded || item.revisionExpanded != lastRevisionExpanded
325
                    || !highlights.equals(lastHighlights)) {
370
                    || !highlights.equals(lastHighlights)) 
371
            {
326
                lastSelection = selected;
372
                lastSelection = selected;
327
                lastMessageExpanded = item.messageExpanded;
373
                lastMessageExpanded = item.messageExpanded;
328
                lastRevisionExpanded = item.revisionExpanded;
374
                lastRevisionExpanded = item.revisionExpanded;
329
                lastHighlights = highlights;
375
                lastHighlights = highlights;
330
376
331
                Style style;
332
                Color backgroundColor;
377
                Color backgroundColor;
333
                Color foregroundColor;
334
378
335
                if (selected) {
379
                if (selected) {
336
                    foregroundColor = selectionForeground;
337
                    backgroundColor = selectionBackground;
380
                    backgroundColor = selectionBackground;
338
                    style = selectedStyle;
339
                } else {
381
                } else {
340
                    foregroundColor = UIManager.getColor("List.foreground"); //NOI18N
341
                    backgroundColor = UIManager.getColor("List.background"); //NOI18N
382
                    backgroundColor = UIManager.getColor("List.background"); //NOI18N
342
                    backgroundColor = entry.isLessInteresting() ? darkerUninteresting(backgroundColor) : darker(backgroundColor);
383
                    backgroundColor = entry.isLessInteresting() ? darkerUninteresting(backgroundColor) : darker(backgroundColor);
343
                    style = normalStyle;
344
                }
384
                }
345
                textPane.setOpaque(false);
385
                this.setBackground(backgroundColor);
346
                textPane.setBackground(new Color(0, 0, 0, 0));
386
                revisionCell.setBackground(backgroundColor);
347
                setBackground(backgroundColor);
387
348
                if (item.revisionExpanded) {
388
                if (item.revisionExpanded) {
349
                    expandButton.setIcon(ICON_EXPANDED);
389
                    expandButton.setIcon(ICON_EXPANDED);
350
                } else {
390
                } else {
Lines 357-391 Link Here
357
                }
397
                }
358
398
359
                try {
399
                try {
360
                    // clear document
400
                    addRevision(revisionCell.getRevisionControl(), item, selected, highlights);
361
                    sd.remove(0, sd.getLength());
401
                    addCommitMessage(revisionCell.getCommitMessageControl(), item, selected, highlights);
362
                    sd.setParagraphAttributes(0, sd.getLength(), noindentStyle, false);
402
                    addAuthor(revisionCell.getAuthorControl(), item, selected, highlights);
403
                    addDate(revisionCell.getDateControl(), item, selected, highlights);
404
                } catch (BadLocationException e) {
405
                    ErrorManager.getDefault().notify(e);
406
                }
407
            }
408
            lastWidth = resizePane(revisionCell.getCommitMessageControl().getText(), list, lastWidth);
363
409
364
                    // add revision
410
            return this;
365
                    sd.insertString(0, item.getUserData().getRevision(), null);
411
        }
366
                    sd.setCharacterAttributes(0, sd.getLength(), normalStyle, false);
412
367
                    if (!selected) {
413
        @SuppressWarnings("empty-statement")
368
                        for (AbstractSummaryView.LogEntry.RevisionHighlight highlight : item.getUserData().getRevisionHighlights()) {
414
        private int resizePane(String text, JList list, int lastWidth) {
369
                            Style s = textPane.addStyle(null, normalStyle);
415
            if (text == null) {
370
                            StyleConstants.setForeground(s, highlight.getForeground());
416
                text = ""; //NOI18N
371
                            StyleConstants.setBackground(s, highlight.getBackground());
417
            }
372
                            sd.setCharacterAttributes(highlight.getStart(), highlight.getLength(), s, false);
418
            int width = summaryView.getMaster().getComponent().getWidth();
373
                        }
419
            if (width > 0 && width != lastWidth) {
374
                        for (SearchHighlight highlight : highlights) {
420
                String[] rows = text.split("\n"); //NOI18N
375
                            if (highlight.getKind() == SearchHighlight.Kind.REVISION) {
421
                FontMetrics fm = list.getFontMetrics(list.getFont());
376
                                int doclen = sd.getLength();
422
                int lines = 0;
377
                                String highlightMessage = highlight.getSearchText();
423
                for (String row : rows) {
378
                                String revisionText = item.getUserData().getRevision().toLowerCase();
424
                    Rectangle2D rect = fm.getStringBounds(row, revisionCell.getGraphics());
379
                                int idx = revisionText.indexOf(highlightMessage);
425
                    lines += (int) (rect.getWidth() / (width - 80) + 1);
380
                                if (idx > -1) {
426
                }
381
                                    sd.setCharacterAttributes(doclen - revisionText.length() + idx, highlightMessage.length(), hiliteStyle, false);
427
                int ph = fm.getHeight() * (lines+1)+4;
382
                                }
428
                revisionCell.setPreferredSize(new Dimension(width - 50 - ICON_COLLAPSED.getIconWidth(), ph));
429
                setPreferredSize(revisionCell.getPreferredSize());
430
            }
431
            return width;
432
        }
433
434
435
        private void addRevision(JTextPane pane, RevisionItem item, boolean selected, Collection<SearchHighlight> highlights) throws BadLocationException {
436
        {
437
                StyledDocument sd = pane.getStyledDocument();
438
                // clear document
439
                clearSD(pane, sd);
440
441
                Style selectedStyle = createSelectedStyle(pane);
442
                Style normalStyle = createNormalStyle(pane);
443
                Style hiliteStyle = createHiliteStyleStyle(pane, normalStyle, searchHiliteAttrs);
444
                Style style;
445
                if (selected) {
446
                    style = selectedStyle;
447
                } else {
448
                    style = normalStyle;
449
                }
450
451
                
452
                // add revision
453
                sd.insertString(0, item.getUserData().getRevision(), style);
454
                if (!selected) {
455
                    for (AbstractSummaryView.LogEntry.RevisionHighlight highlight : item.getUserData().getRevisionHighlights()) {
456
                        Style s = pane.addStyle(null, normalStyle);
457
                        StyleConstants.setForeground(s, highlight.getForeground());
458
                        StyleConstants.setBackground(s, highlight.getBackground());
459
                        sd.setCharacterAttributes(highlight.getStart(), highlight.getLength(), s, false);
460
                    }
461
                    for (SearchHighlight highlight : highlights) {
462
                        if (highlight.getKind() == SearchHighlight.Kind.REVISION) {
463
                            int doclen = sd.getLength();
464
                            String highlightMessage = highlight.getSearchText();
465
                            String revisionText = item.getUserData().getRevision().toLowerCase();
466
                            int idx = revisionText.indexOf(highlightMessage);
467
                            if (idx > -1) {
468
                                sd.setCharacterAttributes(doclen - revisionText.length() + idx, highlightMessage.length(), hiliteStyle, false);
383
                            }
469
                            }
384
                        }
470
                        }
385
                    }
471
                    }
472
                }
473
            }
474
        }
386
475
387
                    // add author
476
        private void addAuthor(JTextPane pane, RevisionItem item, boolean selected, Collection<SearchHighlight> highlights) throws BadLocationException {
388
                    sd.insertString(sd.getLength(), FIELDS_SEPARATOR, style);
477
        {
478
                LogEntry entry=item.getUserData();
479
                StyledDocument sd = pane.getStyledDocument();
480
                // clear document
481
                clearSD(pane, sd);
482
                
483
484
                Style selectedStyle = createSelectedStyle(pane);
485
                Style normalStyle = createNormalStyle(pane);
486
                Style style;
487
                if (selected) {
488
                    style = selectedStyle;
489
                } else {
490
                    style = normalStyle;
491
                }
492
493
                Style authorStyle = createAuthorStyle(pane, normalStyle);
494
                Style hiliteStyle = createHiliteStyleStyle(pane, normalStyle, searchHiliteAttrs);
495
                // add author
389
                    String author = entry.getAuthor();
496
                    String author = entry.getAuthor();
390
                    VCSHyperlinkSupport.StyledDocumentHyperlink l = linkerSupport.getLinker(VCSHyperlinkSupport.AuthorLinker.class, id);
497
                    VCSHyperlinkSupport.StyledDocumentHyperlink l = linkerSupport.getLinker(VCSHyperlinkSupport.AuthorLinker.class, id);
391
                    if(l == null) {
498
                    if(l == null) {
Lines 394-400 Link Here
394
                            l = new VCSHyperlinkSupport.AuthorLinker(kenaiUser, authorStyle, sd, author);
501
                            l = new VCSHyperlinkSupport.AuthorLinker(kenaiUser, authorStyle, sd, author);
395
                            linkerSupport.add(l, id);
502
                            linkerSupport.add(l, id);
396
                        }
503
                        }
397
                    }
398
                    int pos = sd.getLength();
504
                    int pos = sd.getLength();
399
                    if(l != null) {
505
                    if(l != null) {
400
                        l.insertString(sd, selected ? style : null);
506
                        l.insertString(sd, selected ? style : null);
Lines 414-436 Link Here
414
                            }
520
                            }
415
                        }
521
                        }
416
                    }
522
                    }
523
                }
524
            }
525
        }
417
526
418
                    // add date
527
        private void addDate(JTextPane pane, RevisionItem item, boolean selected, Collection<SearchHighlight> highlights) throws BadLocationException {
419
                    sd.insertString(sd.getLength(), FIELDS_SEPARATOR + entry.getDate(), null);
528
            
529
                LogEntry entry = item.getUserData();
530
                StyledDocument sd = pane.getStyledDocument();
531
                // clear document
532
                clearSD(pane, sd);
420
533
421
                    // add commit msg
534
                Style selectedStyle = createSelectedStyle(pane);
422
                    boolean messageChanged = !entry.getMessage().equals(commitMessage);
535
                Style normalStyle = createNormalStyle(pane);
423
                    commitMessage = entry.getMessage();
536
                Style style;
424
                    if (commitMessage.endsWith("\n")) commitMessage = commitMessage.substring(0, commitMessage.length() - 1); //NOI18N
537
                if (selected) {
425
                    sd.insertString(sd.getLength(), "\n", null); //NOI18N
538
                    style = selectedStyle;
426
                    int nlc, i;
539
                } else {
427
                    for (i = 0, nlc = -1; i != -1 ; i = commitMessage.indexOf('\n', i + 1), nlc++);
540
                    style = normalStyle;
428
                    if (nlc > 0 && !item.messageExpanded) {
541
                }
429
                        commitMessage = commitMessage.substring(0, commitMessage.indexOf("\n")); //NOI18N
430
                    }
431
542
543
            // add date
544
            sd.insertString(sd.getLength(), entry.getDate(), style);
545
        }
546
547
        private void addCommitMessage(JTextPane pane, RevisionItem item, boolean selected, Collection<SearchHighlight> highlights) throws BadLocationException {
548
        {       
549
                LogEntry entry=item.getUserData();
550
                StyledDocument sd=pane.getStyledDocument();
551
                // clear document
552
                clearSD(pane, sd);
553
                
554
                Style selectedStyle = createSelectedStyle(pane);
555
                Style normalStyle = createNormalStyle(pane);
556
                Style linkStyle = createLinkStyle(pane, normalStyle);
557
                Style hiliteStyle = createHiliteStyleStyle(pane, normalStyle, searchHiliteAttrs);
558
                Style issueHyperlinkStyle = createIssueHyperlinkStyle(pane, normalStyle);
559
                
560
                Style style;
561
                if (selected) {
562
                    style = selectedStyle;
563
                } else {
564
                    style = normalStyle;
565
                }
566
567
                
568
                // add commit msg
569
                boolean messageChanged = !entry.getMessage().equals(commitMessage);
570
                commitMessage = entry.getMessage();
571
                if (commitMessage.endsWith("\n")) {
572
                    commitMessage = commitMessage.substring(0, commitMessage.length() - 1); //NOI18N
573
                }
574
575
                int nlc, i;
576
                for (i = 0, nlc = -1; i != -1; i = commitMessage.indexOf('\n', i + 1), nlc++);
577
                if (nlc > 0 && !item.messageExpanded) {
578
                    commitMessage = commitMessage.substring(0, commitMessage.indexOf("\n")); //NOI18N
579
                }
580
581
                int pos = 0;
582
                {
432
                    // compute issue hyperlinks
583
                    // compute issue hyperlinks
433
                    l = linkerSupport.getLinker(VCSHyperlinkSupport.IssueLinker.class, id);
584
                    IssueLinker l = linkerSupport.getLinker(VCSHyperlinkSupport.IssueLinker.class, id);
434
                    if (messageChanged) {
585
                    if (messageChanged) {
435
                        lastWidth = -1;
586
                        lastWidth = -1;
436
                        if (l != null) {
587
                        if (l != null) {
Lines 448-459 Link Here
448
                            }
599
                            }
449
                        }
600
                        }
450
                    }
601
                    }
451
                    pos = sd.getLength();
602
452
                    if(l != null) {
603
                    if(l != null) {
453
                        l.insertString(sd, style);
604
                        l.insertString(sd, style);
454
                    } else {
605
                    } else {
455
                        sd.insertString(sd.getLength(), commitMessage, style);
606
                        sd.insertString(sd.getLength(), commitMessage, style);
456
                    }
607
                    }
608
                }
457
609
458
                    // tooltip for message
610
                    // tooltip for message
459
                    MessageTooltip mtt = linkerSupport.getLinker(MessageTooltip.class, id);
611
                    MessageTooltip mtt = linkerSupport.getLinker(MessageTooltip.class, id);
Lines 470-490 Link Here
470
                    if (lineEnd == -1) {
622
                    if (lineEnd == -1) {
471
                        lineEnd = sd.getLength() - pos;
623
                        lineEnd = sd.getLength() - pos;
472
                    }
624
                    }
473
                    Style s = textPane.addStyle(null, style);
625
                    Style s = pane.addStyle(null, style);
474
                    StyleConstants.setBold(s, true);
626
                    StyleConstants.setBold(s, true);
475
                    sd.setCharacterAttributes(pos, lineEnd, s, false);
627
                    sd.setCharacterAttributes(pos, lineEnd, s, false);
476
                    int msglen = commitMessage.length();
628
                    int msglen = commitMessage.length();
477
                    int doclen = sd.getLength();
629
                    int doclen = sd.getLength();
478
630
631
                {
479
                    if (nlc > 0 && !item.messageExpanded) {
632
                    if (nlc > 0 && !item.messageExpanded) {
480
                        l = linkerSupport.getLinker(ExpandMsgHyperlink.class, id);
633
                        ExpandMsgHyperlink l = linkerSupport.getLinker(ExpandMsgHyperlink.class, id);
481
                        if (l == null) {
634
                        if (l == null) {
482
                            l = new ExpandMsgHyperlink(item, sd.getLength(), id);
635
                            l = new ExpandMsgHyperlink(item, sd.getLength(), id);
483
                            linkerSupport.add(l, id);
636
                            linkerSupport.add(l, id);
484
                        }
637
                        }
485
                        l.insertString(sd, linkStyle);
638
                        l.insertString(sd, linkStyle);
486
                    }
639
                    }
487
                    
640
                }
488
641
489
                    if (!selected) {
642
                    if (!selected) {
490
                        for (SearchHighlight highlight : highlights) {
643
                        for (SearchHighlight highlight : highlights) {
Lines 505-549 Link Here
505
                    if (selected) {
658
                    if (selected) {
506
                        sd.setCharacterAttributes(0, Integer.MAX_VALUE, style, false);
659
                        sd.setCharacterAttributes(0, Integer.MAX_VALUE, style, false);
507
                    }
660
                    }
508
                } catch (BadLocationException e) {
509
                    ErrorManager.getDefault().notify(e);
510
                }
511
            }
661
            }
512
            lastWidth = resizePane(textPane.getText(), list, lastWidth);
662
        }
513
663
514
            return this;
664
        private Style createNormalStyle(JTextPane textPane) {
665
            Style normalStyle = textPane.addStyle("normal", null); //NOI18N
666
            StyleConstants.setForeground(normalStyle, UIManager.getColor("List.foreground")); //NOI18N
667
            return normalStyle;
668
        }
669
        private Style createIssueHyperlinkStyle(JTextPane textPane, Style normalStyle) {
670
            Style issueHyperlinkStyle = textPane.addStyle("issuehyperlink", normalStyle); //NOI18N
671
            StyleConstants.setForeground(issueHyperlinkStyle, Color.BLUE);
672
            StyleConstants.setUnderline(issueHyperlinkStyle, true);
673
            return issueHyperlinkStyle;
674
        }
675
676
        private Style createAuthorStyle(JTextPane textPane, Style normalStyle) {
677
            Style authorStyle = textPane.addStyle("author", normalStyle); //NOI18N
678
            StyleConstants.setForeground(authorStyle, Color.BLUE);
679
            return authorStyle;
515
        }
680
        }
516
        
681
        
517
        @SuppressWarnings("empty-statement")
682
        private Style createLinkStyle(JTextPane textPane, Style normalStyle) {
518
        private int resizePane(String text, JList list, int lastWidth) {
683
            Style linkStyle = textPane.addStyle("link", normalStyle); //NOI18N
519
            if(text == null) {
684
            StyleConstants.setForeground(linkStyle, Color.BLUE);
520
                text = ""; //NOI18N
685
            StyleConstants.setBold(linkStyle, true);
686
            return linkStyle;
687
        }
688
689
        private Style createNoindentStyle(JTextPane textPane) {
690
            Style noindentStyle = textPane.addStyle("noindent", null); //NOI18N
691
            StyleConstants.setLeftIndent(noindentStyle, 0);
692
            return noindentStyle;
693
        }
694
695
        private Style createSelectedStyle(JTextPane textPane) {
696
            Style selectedStyle = textPane.addStyle("selected", null); //NOI18N
697
            StyleConstants.setForeground(selectedStyle, selectionForeground);
698
            StyleConstants.setBackground(selectedStyle, selectionBackground);
699
            return selectedStyle;
700
        }
701
702
        private Style createHiliteStyleStyle(JTextPane textPane, Style normalStyle, AttributeSet searchHiliteAttrs) {
703
            Style hiliteStyle = textPane.addStyle("hilite", normalStyle); //NOI18N
704
705
            Color c = (Color) searchHiliteAttrs.getAttribute(StyleConstants.Background);
706
            if (c != null) {
707
                StyleConstants.setBackground(hiliteStyle, c);
521
            }
708
            }
522
            int width = summaryView.getMaster().getComponent().getWidth();
709
            c = (Color) searchHiliteAttrs.getAttribute(StyleConstants.Foreground);
523
            if (width > 0 && width != lastWidth) {
710
            if (c != null) {
524
                String[] rows = text.split("\n"); //NOI18N
711
                StyleConstants.setForeground(hiliteStyle, c);
525
                FontMetrics fm = list.getFontMetrics(list.getFont());
526
                int lines = 0;
527
                for (String row : rows) {
528
                    Rectangle2D rect = fm.getStringBounds(row, textPane.getGraphics());
529
                    lines += (int) (rect.getWidth() / (width - 80) + 1);
530
                }
531
                int ph = fm.getHeight() * lines + 9;
532
                textPane.setPreferredSize(new Dimension(width - 50 - ICON_COLLAPSED.getIconWidth(), ph));
533
                setPreferredSize(textPane.getPreferredSize());
534
            }
712
            }
535
            return width;
713
714
            return hiliteStyle;
536
        }
715
        }
537
        
716
        
538
        @Override
717
        @Override
539
        public void paint(Graphics g) {
718
        public void paint(Graphics g) {
540
            super.paint(g);
719
            super.paint(g);
541
            linkerSupport.computeBounds(textPane, id);
720
            linkerSupport.computeBounds(revisionCell.getCommitMessageControl(), id);
721
542
            ExpandLink link = linkerSupport.getLinker(ExpandLink.class, id);
722
            ExpandLink link = linkerSupport.getLinker(ExpandLink.class, id);
543
            if (link != null) {
723
            if (link != null) {
544
                link.computeBounds(expandButton);
724
                link.computeBounds(expandButton);
545
            }
725
            }
546
        }
726
        }
727
        
728
        private void clearSD(JTextPane pane, StyledDocument sd) {
729
            try {
730
                Style noindentStyle = createNoindentStyle(pane);
731
                
732
                sd.remove(0, sd.getLength());
733
                sd.setParagraphAttributes(0, sd.getLength(), noindentStyle, false);
734
            } catch (BadLocationException ex) {
735
                Exceptions.printStackTrace(ex);
736
            }
737
        }
547
    }
738
    }
548
    
739
    
549
    private static class MessageTooltip extends VCSHyperlinkSupport.Hyperlink {
740
    private static class MessageTooltip extends VCSHyperlinkSupport.Hyperlink {
Lines 1049-1054 Link Here
1049
                Rectangle endr = mtv.getBounds();
1240
                Rectangle endr = mtv.getBounds();
1050
1241
1051
                bounds = new Rectangle(tpBounds.x + startr.x, startr.y, endr.x - startr.x, startr.height);
1242
                bounds = new Rectangle(tpBounds.x + startr.x, startr.y, endr.x - startr.x, startr.height);
1243
                // NOTE the textPane is positioned within a parent panel so the relative bound has to be modified too
1244
                // FIXME this is an ugly hack because the public API of org.netbeans.modules.versioning.util.VCSHyperlinkSupport should stay stable
1245
                // SOLUTION: add parameter 'rootPane' to the computeBounds method and translate from bottom to top of the component hiearchy
1246
                bounds.translate(textPane.getX(), textPane.getY());
1247
                bounds.translate(textPane.getParent().getX(), textPane.getParent().getY());
1052
            } catch (BadLocationException ex) {
1248
            } catch (BadLocationException ex) {
1053
                throw new RuntimeException(ex);
1249
                throw new RuntimeException(ex);
1054
            }
1250
            }
(-)a/versioning.util/src/org/netbeans/modules/versioning/util/VCSHyperlinkSupport.java (+2 lines)
Lines 240-245 Link Here
240
                    Rectangle startr = tui.modelToView(textPane, docstart[i], Position.Bias.Forward).getBounds();
240
                    Rectangle startr = tui.modelToView(textPane, docstart[i], Position.Bias.Forward).getBounds();
241
                    Rectangle endr = tui.modelToView(textPane, docend[i], Position.Bias.Backward).getBounds();
241
                    Rectangle endr = tui.modelToView(textPane, docend[i], Position.Bias.Backward).getBounds();
242
                    this.bounds[i] = new Rectangle(tpBounds.x + startr.x, startr.y, endr.x - startr.x, startr.height);
242
                    this.bounds[i] = new Rectangle(tpBounds.x + startr.x, startr.y, endr.x - startr.x, startr.height);
243
                    //NOTE the textPane is positioned within a parent panel so the origin has to be modified too
244
                    this.bounds[i].translate(textPane.getX(), textPane.getY());
243
                } catch (BadLocationException ex) { }
245
                } catch (BadLocationException ex) { }
244
            }
246
            }
245
        }
247
        }

Return to bug 218850