KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > ui > BookmarksPanel


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.ui;
35
36 import java.util.Vector JavaDoc;
37 import java.util.ArrayList JavaDoc;
38 import java.util.Enumeration JavaDoc;
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 JavaDoc;
45 import java.awt.event.*;
46 import java.awt.*;
47 import javax.swing.text.BadLocationException JavaDoc;
48 import javax.swing.text.Position JavaDoc;
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 /**
58  * Panel for displaying bookmarks.
59  * This class is a swing view class and hence should only be accessed from the event-handling thread.
60  * @version $Id$
61  */

62 public class BookmarksPanel extends RegionsTreePanel<DocumentRegion> {
63   protected JButton _goToButton;
64   protected JButton _removeButton;
65   protected JButton _removeAllButton;
66   
67   /** Constructs a new bookmarks panel.
68    * This is swing view class and hence should only be accessed from the event-handling thread.
69    * @param frame the MainFrame
70    */

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   /** Action performed when the Enter key is pressed. Should be overridden. */
84   protected void performDefaultAction() {
85     goToRegion();
86   }
87   
88   /** Creates the buttons for controlling the regions. Should be overridden. */
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   /** Update button state and text. */
123   protected void updateButtons() {
124     ArrayList JavaDoc<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   /** Makes the popup menu actions. Should be overridden if additional actions besides "Go to" and "Remove" are added. */
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