KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > diff > DiffTooltipActionsPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.versioning.diff;
20
21 import org.netbeans.api.diff.Difference;
22
23 import javax.swing.*;
24 import java.awt.*;
25 import java.awt.event.ActionListener JavaDoc;
26 import java.awt.event.ActionEvent JavaDoc;
27 import org.openide.util.NbBundle;
28
29 /**
30  * Contains Diff actions toolbar: Goto Previous, Goto Next, Rollback, Diff.
31  *
32  * @author Maros Sandor
33  */

34 class DiffTooltipActionsPanel extends JToolBar implements ActionListener JavaDoc {
35     
36     private final Icon iconPrevious = new ImageIcon(org.openide.util.Utilities.loadImage("org/netbeans/modules/versioning/diff/diff-prev.png")); // NOI18N
37
private final Icon iconNext = new ImageIcon(org.openide.util.Utilities.loadImage("org/netbeans/modules/versioning/diff/diff-next.png")); // NOI18N
38
private final Icon iconDiff = new ImageIcon(org.openide.util.Utilities.loadImage("org/netbeans/modules/versioning/diff/diff.png")); // NOI18N
39
private final Icon iconRollback = new ImageIcon(org.openide.util.Utilities.loadImage("org/netbeans/modules/versioning/diff/rollback.png")); // NOI18N
40

41     private final DiffActionTooltipWindow master;
42     private final Difference diff;
43     
44     private final JButton prevButton;
45     private final JButton nextButton;
46     private final JButton rollButton;
47     private final JButton diffButton;
48
49     public DiffTooltipActionsPanel(DiffActionTooltipWindow master, Difference diff) {
50         this.master = master;
51         this.diff = diff;
52
53         Color tooltipBackround = UIManager.getColor("ToolTip.background"); // NOI18N
54
if (tooltipBackround == null) tooltipBackround = Color.WHITE;
55         
56         setRollover(true);
57         setFloatable(false);
58         setBackground(tooltipBackround);
59
60         prevButton = new JButton(iconPrevious);
61         nextButton = new JButton(iconNext);
62         rollButton = new JButton(iconRollback);
63         diffButton = new JButton(iconDiff);
64         
65         prevButton.setToolTipText(NbBundle.getMessage(DiffTooltipActionsPanel.class, "TT_GoToPreviousDifference"));
66         nextButton.setToolTipText(NbBundle.getMessage(DiffTooltipActionsPanel.class, "TT_GoToNextDifference"));
67         diffButton.setToolTipText(NbBundle.getMessage(DiffTooltipActionsPanel.class, "TT_Open_Diff_Window"));
68         if (diff.getType() == Difference.ADD) {
69             rollButton.setToolTipText(NbBundle.getMessage(DiffTooltipActionsPanel.class, "TT_Delete_Added_Text"));
70         } else if (diff.getType() == Difference.CHANGE) {
71             rollButton.setToolTipText(NbBundle.getMessage(DiffTooltipActionsPanel.class, "TT_Replace_With_Original_Text"));
72         } else {
73             rollButton.setToolTipText(NbBundle.getMessage(DiffTooltipActionsPanel.class, "TT_Restore_Original_Text"));
74         }
75         
76         prevButton.addActionListener(this);
77         nextButton.addActionListener(this);
78         rollButton.addActionListener(this);
79         diffButton.addActionListener(this);
80
81         prevButton.setBackground(tooltipBackround);
82         nextButton.setBackground(tooltipBackround);
83         rollButton.setBackground(tooltipBackround);
84         diffButton.setBackground(tooltipBackround);
85
86         add(prevButton);
87         add(nextButton);
88         add(rollButton);
89         add(diffButton);
90
91         Difference [] diffs = master.getMaster().getCurrentDiff();
92         prevButton.setEnabled(diffs[0] != diff);
93         nextButton.setEnabled(diffs[diffs.length - 1] != diff);
94         rollButton.setEnabled(master.getMaster().canRollback(diff));
95         
96         setBorder(BorderFactory.createCompoundBorder(
97                 BorderFactory.createMatteBorder(1, 1, 1, 1, Color.BLACK),
98                 BorderFactory.createEmptyBorder(2, 2, 2, 2)));
99     }
100
101     public void actionPerformed(ActionEvent JavaDoc e) {
102         if (e.getSource() == prevButton) {
103             master.shutdown();
104             master.getMaster().onPrevious(diff);
105         } else if (e.getSource() == nextButton) {
106             master.shutdown();
107             master.getMaster().onNext(diff);
108         } if (e.getSource() == rollButton) {
109             master.shutdown();
110             master.getMaster().onRollback(diff);
111         } else if (e.getSource() == diffButton) {
112             master.shutdown();
113             master.getMaster().onDiff(diff);
114         }
115     }
116 }
117
Popular Tags