1 33 34 package edu.rice.cs.drjava.ui; 35 36 import java.util.Vector ; 37 import java.util.ArrayList ; 38 import java.util.Enumeration ; 39 40 import javax.swing.*; 41 import javax.swing.event.*; 42 import javax.swing.tree.*; 43 import javax.swing.table.*; 44 import javax.swing.text.BadLocationException ; 45 import java.awt.event.*; 46 import java.awt.*; 47 import javax.swing.text.BadLocationException ; 48 import javax.swing.text.Position ; 49 50 import edu.rice.cs.drjava.model.RegionManagerListener; 51 import edu.rice.cs.drjava.model.DocumentRegion; 52 import edu.rice.cs.drjava.model.OpenDefinitionsDocument; 53 import edu.rice.cs.drjava.config.*; 54 import edu.rice.cs.util.swing.Utilities; 55 import edu.rice.cs.util.UnexpectedException; 56 57 62 public class BookmarksPanel extends RegionsTreePanel<DocumentRegion> { 63 protected JButton _goToButton; 64 protected JButton _removeButton; 65 protected JButton _removeAllButton; 66 67 71 public BookmarksPanel(MainFrame frame) { 72 super(frame, "Bookmarks"); 73 _model.getBookmarkManager().addListener(new RegionManagerListener<DocumentRegion>() { 74 public void regionAdded(DocumentRegion r, int index) { addRegion(r); } 75 public void regionChanged(DocumentRegion r, int index) { 76 regionRemoved(r); 77 regionAdded(r, index); 78 } 79 public void regionRemoved(DocumentRegion r) { removeRegion(r); } 80 }); 81 } 82 83 84 protected void performDefaultAction() { 85 goToRegion(); 86 } 87 88 89 protected JComponent[] makeButtons() { 90 Action goToAction = new AbstractAction("Go to") { 91 public void actionPerformed(ActionEvent ae) { 92 goToRegion(); 93 } 94 }; 95 _goToButton = new JButton(goToAction); 96 97 Action removeAction = new AbstractAction("Remove") { 98 public void actionPerformed(ActionEvent ae) { 99 for (DocumentRegion r: getSelectedRegions()) { 100 _model.getBookmarkManager().removeRegion(r); 101 } 102 } 103 }; 104 _removeButton = new JButton(removeAction); 105 106 Action removeAllAction = new AbstractAction("Remove All") { 107 public void actionPerformed(ActionEvent ae) { 108 _model.getBookmarkManager().clearRegions(); 109 } 110 }; 111 _removeAllButton = new JButton(removeAllAction); 112 113 JComponent[] buts = new JComponent[] { 114 _goToButton, 115 _removeButton, 116 _removeAllButton 117 }; 118 119 return buts; 120 } 121 122 123 protected void updateButtons() { 124 ArrayList <DocumentRegion> regs = getSelectedRegions(); 125 _goToButton.setEnabled(regs.size()==1); 126 _removeButton.setEnabled(regs.size()>0); 127 _removeAllButton.setEnabled((_regionRootNode!=null) && (_regionRootNode.getDepth()>0)); 128 } 129 130 131 protected AbstractAction[] makePopupMenuActions() { 132 AbstractAction[] acts = new AbstractAction[] { 133 new AbstractAction("Go to") { 134 public void actionPerformed(ActionEvent e) { 135 goToRegion(); 136 } 137 }, 138 139 new AbstractAction("Remove") { 140 public void actionPerformed(ActionEvent e) { 141 for (DocumentRegion r: getSelectedRegions()) { 142 _model.getBookmarkManager().removeRegion(r); 143 } 144 } 145 } 146 }; 147 return acts; 148 } 149 } 150 | Popular Tags |