Source Code Cross Referenced for BrowserHistoryPanel.java in  » IDE » DrJava » edu » rice » cs » drjava » ui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE » DrJava » edu.rice.cs.drjava.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*BEGIN_COPYRIGHT_BLOCK
002:         *
003:         * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004:         * All rights reserved.
005:         * 
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions are met:
008:         *    * Redistributions of source code must retain the above copyright
009:         *      notice, this list of conditions and the following disclaimer.
010:         *    * Redistributions in binary form must reproduce the above copyright
011:         *      notice, this list of conditions and the following disclaimer in the
012:         *      documentation and/or other materials provided with the distribution.
013:         *    * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014:         *      names of its contributors may be used to endorse or promote products
015:         *      derived from this software without specific prior written permission.
016:         * 
017:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018:         * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019:         * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020:         * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021:         * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023:         * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024:         * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025:         * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026:         * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027:         * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028:         *
029:         * This software is Open Source Initiative approved Open Source Software.
030:         * Open Source Initative Approved is a trademark of the Open Source Initiative.
031:         * 
032:         * This file is part of DrJava.  Download the current version of this project
033:         * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034:         * 
035:         * END_COPYRIGHT_BLOCK*/
036:
037:        package edu.rice.cs.drjava.ui;
038:
039:        import java.util.Vector;
040:        import java.util.ArrayList;
041:        import java.util.Enumeration;
042:
043:        import javax.swing.*;
044:        import javax.swing.event.*;
045:        import javax.swing.tree.*;
046:        import javax.swing.table.*;
047:        import javax.swing.text.BadLocationException;
048:        import java.awt.event.*;
049:        import java.awt.*;
050:        import javax.swing.text.BadLocationException;
051:        import javax.swing.text.Position;
052:
053:        import edu.rice.cs.drjava.model.RegionManager;
054:        import edu.rice.cs.drjava.model.RegionManagerListener;
055:        import edu.rice.cs.drjava.model.DocumentRegion;
056:        import edu.rice.cs.drjava.model.OpenDefinitionsDocument;
057:        import edu.rice.cs.drjava.config.*;
058:        import edu.rice.cs.util.swing.Utilities;
059:        import edu.rice.cs.util.UnexpectedException;
060:
061:        /**
062:         * Panel for displaying browser history.
063:         * Currently not used because of synchronization problems.
064:         * This class is a swing view class and hence should only be accessed from the event-handling thread.
065:         * @version $Id$
066:         */
067:        public class BrowserHistoryPanel extends
068:                RegionsListPanel<DocumentRegion> {
069:            protected JButton _backButton;
070:            protected JButton _forwardButton;
071:            protected JButton _goToButton;
072:            protected JButton _removeButton;
073:            protected JButton _removeAllButton;
074:            protected AbstractAction _backAction;
075:            protected AbstractAction _forwardAction;
076:
077:            /** Constructs a new browser history panel.
078:             *  This is swing view class and hence should only be accessed from the event-handling thread.
079:             *  @param frame the MainFrame
080:             */
081:            public BrowserHistoryPanel(MainFrame frame) {
082:                super (frame, "Browser History");
083:                _model.getBrowserHistoryManager().addListener(
084:                        new RegionManagerListener<DocumentRegion>() {
085:                            public void regionAdded(DocumentRegion r, int index) {
086:                                addRegion(r, index);
087:                                _list.ensureIndexIsVisible(index);
088:                            }
089:
090:                            public void regionChanged(DocumentRegion r,
091:                                    int index) {
092:                                regionRemoved(r);
093:                                regionAdded(r, index);
094:                            }
095:
096:                            public void regionRemoved(DocumentRegion r) {
097:                                removeRegion(r);
098:                            }
099:                        });
100:            }
101:
102:            /** Action performed when the Enter key is pressed. Should be overridden. */
103:            protected void performDefaultAction() {
104:                goToRegion();
105:            }
106:
107:            /** Go to region. */
108:            protected void goToRegion() {
109:                ArrayList<DocumentRegion> r = getSelectedRegions();
110:                if (r.size() == 1) {
111:                    _model.getBrowserHistoryManager()
112:                            .setCurrentRegion(r.get(0));
113:                    updateButtons();
114:                    RegionListUserObj<DocumentRegion> userObj = getUserObjForRegion(r
115:                            .get(0));
116:                    if (userObj != null) {
117:                        _list.ensureIndexIsVisible(_listModel.indexOf(userObj));
118:                    }
119:                    _frame.scrollToDocumentAndOffset(r.get(0).getDocument(), r
120:                            .get(0).getStartOffset(), false, false);
121:                }
122:            }
123:
124:            /** Go to the previous region. */
125:            protected void backRegion() {
126:                RegionManager rm = _model.getBrowserHistoryManager();
127:
128:                // add current location to history
129:                _frame.addToBrowserHistory();
130:
131:                // then move back    
132:                DocumentRegion r = rm.prevCurrentRegion();
133:                updateButtons();
134:                RegionListUserObj<DocumentRegion> userObj = getUserObjForRegion(r);
135:                if (userObj != null) {
136:                    _list.ensureIndexIsVisible(_listModel.indexOf(userObj));
137:                }
138:                _frame.scrollToDocumentAndOffset(r.getDocument(), r
139:                        .getStartOffset(), false, false);
140:            }
141:
142:            /** Go to the next region. */
143:            protected void forwardRegion() {
144:                RegionManager rm = _model.getBrowserHistoryManager();
145:
146:                // add current location to history
147:                _frame.addToBrowserHistory();
148:
149:                // then move forward
150:                DocumentRegion r = rm.nextCurrentRegion();
151:                updateButtons();
152:                RegionListUserObj<DocumentRegion> userObj = getUserObjForRegion(r);
153:                if (userObj != null) {
154:                    _list.ensureIndexIsVisible(_listModel.indexOf(userObj));
155:                }
156:                _frame.scrollToDocumentAndOffset(r.getDocument(), r
157:                        .getStartOffset(), false, false);
158:            }
159:
160:            /** @return the action to go back in the browser history. */
161:            AbstractAction getBackAction() {
162:                return _backAction;
163:            }
164:
165:            /** @return the action to go forwardin the browser history. */
166:            AbstractAction getForwardAction() {
167:                return _forwardAction;
168:            }
169:
170:            /** Creates the buttons for controlling the regions. Should be overridden. */
171:            protected JComponent[] makeButtons() {
172:                _backAction = new AbstractAction("Back") {
173:                    public void actionPerformed(ActionEvent ae) {
174:                        backRegion();
175:                    }
176:                };
177:                _backButton = new JButton(_backAction);
178:
179:                _forwardAction = new AbstractAction("Forward") {
180:                    public void actionPerformed(ActionEvent ae) {
181:                        forwardRegion();
182:                    }
183:                };
184:                _forwardButton = new JButton(_forwardAction);
185:
186:                Action goToAction = new AbstractAction("Go to") {
187:                    public void actionPerformed(ActionEvent ae) {
188:                        goToRegion();
189:                    }
190:                };
191:                _goToButton = new JButton(goToAction);
192:
193:                Action removeAction = new AbstractAction("Remove") {
194:                    public void actionPerformed(ActionEvent ae) {
195:                        for (DocumentRegion r : getSelectedRegions()) {
196:                            _model.getBrowserHistoryManager().removeRegion(r);
197:                        }
198:                    }
199:                };
200:                _removeButton = new JButton(removeAction);
201:
202:                Action removeAllAction = new AbstractAction("Remove All") {
203:                    public void actionPerformed(ActionEvent ae) {
204:                        _model.getBrowserHistoryManager().clearRegions();
205:                    }
206:                };
207:                _removeAllButton = new JButton(removeAllAction);
208:
209:                JComponent[] buts = new JComponent[] { _backButton,
210:                        _forwardButton, _goToButton, _removeButton,
211:                        _removeAllButton };
212:
213:                return buts;
214:            }
215:
216:            /** Update button state and text. */
217:            protected void updateButtons() {
218:                ArrayList<DocumentRegion> regs = getSelectedRegions();
219:                _goToButton.setEnabled(regs.size() == 1);
220:                _removeButton.setEnabled(regs.size() > 0);
221:                _removeAllButton.setEnabled(_listModel.size() > 0);
222:                _backAction.setEnabled((_listModel.size() > 0)
223:                        && (!_model.getBrowserHistoryManager()
224:                                .isCurrentRegionFirst()));
225:                _forwardAction.setEnabled((_listModel.size() > 0)
226:                        && (!_model.getBrowserHistoryManager()
227:                                .isCurrentRegionLast()));
228:            }
229:
230:            /** Makes the popup menu actions. Should be overridden if additional actions besides "Go to" and "Remove" are added. */
231:            protected AbstractAction[] makePopupMenuActions() {
232:                AbstractAction[] acts = new AbstractAction[] {
233:                        new AbstractAction("Go to") {
234:                            public void actionPerformed(ActionEvent e) {
235:                                goToRegion();
236:                            }
237:                        },
238:
239:                        new AbstractAction("Remove") {
240:                            public void actionPerformed(ActionEvent e) {
241:                                for (DocumentRegion r : getSelectedRegions()) {
242:                                    _model.getBrowserHistoryManager()
243:                                            .removeRegion(r);
244:                                }
245:                            }
246:                        } };
247:                return acts;
248:            }
249:
250:            /** @return the usser object in the list associated with the region, or null if not found */
251:            protected RegionListUserObj<DocumentRegion> getUserObjForRegion(
252:                    DocumentRegion r) {
253:                for (int i = 0; i < _listModel.size(); ++i) {
254:                    @SuppressWarnings("unchecked")
255:                    RegionListUserObj<DocumentRegion> userObj = (RegionListUserObj<DocumentRegion>) _listModel
256:                            .get(i);
257:                    if (userObj.region() == r) {
258:                        return userObj;
259:                    }
260:                }
261:                return null;
262:            }
263:
264:            /** Factory method to create user objects put in the tree.
265:             *  If subclasses extend RegionListUserObj, they need to override this method. */
266:            protected RegionListUserObj<DocumentRegion> makeRegionListUserObj(
267:                    DocumentRegion r) {
268:                return new BrowserHistoryListUserObj(r);
269:            }
270:
271:            /** Class that gets put into the tree. The toString() method determines what's displayed in the three. */
272:            protected class BrowserHistoryListUserObj extends
273:                    RegionListUserObj<DocumentRegion> {
274:                public BrowserHistoryListUserObj(DocumentRegion r) {
275:                    super (r);
276:                }
277:
278:                public String toString() {
279:                    final StringBuilder sb = new StringBuilder();
280:                    _region.getDocument().acquireReadLock();
281:                    try {
282:                        sb.append("<html>");
283:                        if (_region == _model.getBrowserHistoryManager()
284:                                .getCurrentRegion()) {
285:                            sb.append("<font color=\"red\">");
286:                        }
287:                        sb.append(_region.getDocument().toString());
288:                        sb.append(':');
289:                        sb.append(lineNumber());
290:                        try {
291:                            sb.append(": ");
292:                            int length = Math.min(120, _region.getEndOffset()
293:                                    - _region.getStartOffset());
294:                            sb.append(_region.getDocument().getText(
295:                                    _region.getStartOffset(), length).trim());
296:                        } catch (BadLocationException bpe) { /* ignore, just don't display line */
297:                        }
298:                        if (_region.equals(_model.getBrowserHistoryManager()
299:                                .getCurrentRegion())) {
300:                            sb.append("</font>");
301:                        }
302:                        sb.append("</html>");
303:                    } finally {
304:                        _region.getDocument().releaseReadLock();
305:                    }
306:                    return sb.toString();
307:                }
308:
309:                public boolean equals(Object other) {
310:                    @SuppressWarnings("unchecked")
311:                    BrowserHistoryListUserObj o = (BrowserHistoryListUserObj) other;
312:                    return (o.region().getDocument().equals(region()
313:                            .getDocument()))
314:                            && (o.region().getStartOffset() == region()
315:                                    .getStartOffset())
316:                            && (o.region().getEndOffset() == region()
317:                                    .getEndOffset());
318:                }
319:            }
320:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.