1 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 ; 26 import java.awt.event.ActionEvent ; 27 import org.openide.util.NbBundle; 28 29 34 class DiffTooltipActionsPanel extends JToolBar implements ActionListener { 35 36 private final Icon iconPrevious = new ImageIcon(org.openide.util.Utilities.loadImage("org/netbeans/modules/versioning/diff/diff-prev.png")); private final Icon iconNext = new ImageIcon(org.openide.util.Utilities.loadImage("org/netbeans/modules/versioning/diff/diff-next.png")); private final Icon iconDiff = new ImageIcon(org.openide.util.Utilities.loadImage("org/netbeans/modules/versioning/diff/diff.png")); private final Icon iconRollback = new ImageIcon(org.openide.util.Utilities.loadImage("org/netbeans/modules/versioning/diff/rollback.png")); 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"); 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 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 |