Source Code Cross Referenced for LogViewer.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » gui » 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 » Swing Library » jEdit » org.gjt.sp.jedit.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * LogViewer.java
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 1999, 2004 Slava Pestov
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:
023:        package org.gjt.sp.jedit.gui;
024:
025:        //{{{ Imports
026:        import java.awt.*;
027:        import java.awt.event.*;
028:        import javax.swing.*;
029:        import javax.swing.border.EmptyBorder;
030:        import javax.swing.event.*;
031:        import org.gjt.sp.jedit.*;
032:        import org.gjt.sp.jedit.msg.PropertiesChanged;
033:        import org.gjt.sp.util.Log;
034:
035:        //}}}
036:
037:        /**
038:         * @version $Id: LogViewer.java 8702 2007-01-21 23:16:41Z kpouer $
039:         */
040:        public class LogViewer extends JPanel implements  DefaultFocusComponent,
041:                EBComponent {
042:            //{{{ LogViewer constructor
043:            public LogViewer() {
044:                super (new BorderLayout());
045:
046:                JPanel caption = new JPanel();
047:                caption.setLayout(new BoxLayout(caption, BoxLayout.X_AXIS));
048:                caption.setBorder(new EmptyBorder(6, 6, 6, 6));
049:
050:                String settingsDirectory = jEdit.getSettingsDirectory();
051:                if (settingsDirectory != null) {
052:                    String[] args = { MiscUtilities.constructPath(
053:                            settingsDirectory, "activity.log") };
054:                    JLabel label = new JLabel(jEdit.getProperty(
055:                            "log-viewer.caption", args));
056:                    caption.add(label);
057:                }
058:
059:                caption.add(Box.createHorizontalGlue());
060:
061:                tailIsOn = jEdit.getBooleanProperty("log-viewer.tail", false);
062:                tail = new JCheckBox(
063:                        jEdit.getProperty("log-viewer.tail.label"), tailIsOn);
064:                tail.addActionListener(new ActionHandler());
065:                caption.add(tail);
066:
067:                caption.add(Box.createHorizontalStrut(12));
068:
069:                copy = new JButton(jEdit.getProperty("log-viewer.copy"));
070:                copy.addActionListener(new ActionHandler());
071:                caption.add(copy);
072:
073:                ListModel model = Log.getLogListModel();
074:                model.addListDataListener(new ListHandler());
075:                list = new LogList(model);
076:
077:                add(BorderLayout.NORTH, caption);
078:                JScrollPane scroller = new JScrollPane(list);
079:                Dimension dim = scroller.getPreferredSize();
080:                dim.width = Math.min(600, dim.width);
081:                scroller.setPreferredSize(dim);
082:                add(BorderLayout.CENTER, scroller);
083:
084:                propertiesChanged();
085:            } //}}}
086:
087:            //{{{ setBounds() method
088:            public void setBounds(int x, int y, int width, int height) {
089:                super .setBounds(x, y, width, height);
090:                scrollLaterIfRequired();
091:            } //}}}
092:
093:            //{{{ handleMessage() method
094:            public void handleMessage(EBMessage msg) {
095:                if (msg instanceof  PropertiesChanged)
096:                    propertiesChanged();
097:            } //}}}
098:
099:            //{{{ addNotify() method
100:            public void addNotify() {
101:                super .addNotify();
102:                if (tailIsOn)
103:                    scrollToTail();
104:
105:                EditBus.addToBus(this );
106:            } //}}}
107:
108:            //{{{ removeNotify() method
109:            public void removeNotify() {
110:                super .removeNotify();
111:
112:                EditBus.removeFromBus(this );
113:            } //}}}
114:
115:            //{{{ focusOnDefaultComponent() method
116:            public void focusOnDefaultComponent() {
117:                list.requestFocus();
118:            } //}}}
119:
120:            //{{{ Private members
121:            private final JList list;
122:            private final JButton copy;
123:            private final JCheckBox tail;
124:            private boolean tailIsOn;
125:
126:            //{{{ propertiesChanged() method
127:            private void propertiesChanged() {
128:                list.setFont(jEdit.getFontProperty("view.font"));
129:                list.setFixedCellHeight(list.getFontMetrics(list.getFont())
130:                        .getHeight());
131:            } //}}}
132:
133:            //{{{ scrollToTail() method
134:            /** Scroll to the tail of the logs. */
135:            private void scrollToTail() {
136:                int index = list.getModel().getSize();
137:                if (index != 0)
138:                    list.ensureIndexIsVisible(index - 1);
139:            } //}}}
140:
141:            //{{{ scrollLaterIfRequired() method
142:            private void scrollLaterIfRequired() {
143:                if (tailIsOn)
144:                    SwingUtilities.invokeLater(new Runnable() {
145:                        public void run() {
146:                            scrollToTail();
147:                        }
148:                    });
149:            } //}}}
150:
151:            //}}}
152:
153:            //{{{ ActionHandler class
154:            class ActionHandler implements  ActionListener {
155:                public void actionPerformed(ActionEvent e) {
156:                    Object src = e.getSource();
157:                    if (src == tail) {
158:                        tailIsOn = !tailIsOn;
159:                        jEdit.setBooleanProperty("log-viewer.tail", tailIsOn);
160:                        if (tailIsOn) {
161:                            scrollToTail();
162:                        }
163:                    } else if (src == copy) {
164:                        StringBuilder buf = new StringBuilder();
165:                        Object[] selected = list.getSelectedValues();
166:                        if (selected != null && selected.length != 0) {
167:                            for (int i = 0; i < selected.length; i++) {
168:                                buf.append(selected[i]);
169:                                buf.append('\n');
170:                            }
171:                        } else {
172:                            ListModel model = list.getModel();
173:                            for (int i = 0; i < model.getSize(); i++) {
174:                                buf.append(model.getElementAt(i));
175:                                buf.append('\n');
176:                            }
177:                        }
178:                        Registers.setRegister('$', buf.toString());
179:                    }
180:                }
181:            } //}}}
182:
183:            //{{{ ListHandler class
184:            class ListHandler implements  ListDataListener {
185:                public void intervalAdded(ListDataEvent e) {
186:                    contentsChanged(e);
187:                }
188:
189:                public void intervalRemoved(ListDataEvent e) {
190:                    contentsChanged(e);
191:                }
192:
193:                public void contentsChanged(ListDataEvent e) {
194:                    scrollLaterIfRequired();
195:                }
196:            } //}}}
197:
198:            //{{{ LogList class
199:            class LogList extends JList {
200:                LogList(ListModel model) {
201:                    super (model);
202:                    setVisibleRowCount(24);
203:                    getSelectionModel().setSelectionMode(
204:                            ListSelectionModel.SINGLE_INTERVAL_SELECTION);
205:                    setAutoscrolls(true);
206:                }
207:
208:                public void processMouseEvent(MouseEvent evt) {
209:                    if (evt.getID() == MouseEvent.MOUSE_PRESSED) {
210:                        startIndex = list.locationToIndex(evt.getPoint());
211:                    }
212:                    super .processMouseEvent(evt);
213:                }
214:
215:                public void processMouseMotionEvent(MouseEvent evt) {
216:                    if (evt.getID() == MouseEvent.MOUSE_DRAGGED) {
217:                        int row = list.locationToIndex(evt.getPoint());
218:                        if (row != -1) {
219:                            if (startIndex == -1) {
220:                                list.setSelectionInterval(row, row);
221:                                startIndex = row;
222:                            } else
223:                                list.setSelectionInterval(startIndex, row);
224:                            list.ensureIndexIsVisible(row);
225:                            evt.consume();
226:                        }
227:                    } else
228:                        super .processMouseMotionEvent(evt);
229:                }
230:
231:                private int startIndex;
232:            } //}}}
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.