Source Code Cross Referenced for QuickNotepad.java in  » Swing-Library » jEdit » jars » QuickNotepad » 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 » jars.QuickNotepad 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * QuickNotepad.java
003:         * part of the QuickNotepad plugin for the jEdit text editor
004:         * Copyright (C) 2001 John Gellene
005:         * jgellene@nyc.rr.com
006:         *
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         *
021:         * $Id: QuickNotepad.java 9481 2007-05-02 00:34:44Z k_satoda $
022:         */
023:
024:        // {{{ imports
025:        import java.awt.BorderLayout;
026:        import java.awt.Dimension;
027:        import java.awt.Font;
028:        import java.io.BufferedReader;
029:        import java.io.File;
030:        import java.io.FileNotFoundException;
031:        import java.io.FileReader;
032:        import java.io.FileWriter;
033:        import java.io.IOException;
034:
035:        import javax.swing.JFileChooser;
036:        import javax.swing.JPanel;
037:        import javax.swing.JScrollPane;
038:
039:        import org.gjt.sp.jedit.EBComponent;
040:        import org.gjt.sp.jedit.EBMessage;
041:        import org.gjt.sp.jedit.EditBus;
042:        import org.gjt.sp.jedit.GUIUtilities;
043:        import org.gjt.sp.jedit.View;
044:        import org.gjt.sp.jedit.jEdit;
045:        import org.gjt.sp.jedit.gui.DefaultFocusComponent;
046:        import org.gjt.sp.jedit.gui.DockableWindowManager;
047:        import org.gjt.sp.jedit.msg.PropertiesChanged;
048:        import org.gjt.sp.util.Log;
049:        import org.gjt.sp.util.StandardUtilities;
050:
051:        // }}}
052:
053:        // {{{ QuickNotePad class
054:        /**
055:         * 
056:         * QuickNotePad - a dockable JPanel, a demonstration of a jEdit plugin.
057:         *
058:         */
059:        public class QuickNotepad extends JPanel implements  EBComponent,
060:                QuickNotepadActions, DefaultFocusComponent {
061:
062:            // {{{ Instance Variables
063:            private static final long serialVersionUID = 6412255692894321789L;
064:
065:            private String filename;
066:
067:            private String defaultFilename;
068:
069:            private View view;
070:
071:            private boolean floating;
072:
073:            private QuickNotepadTextArea textArea;
074:
075:            private QuickNotepadToolPanel toolPanel;
076:
077:            // }}}
078:
079:            // {{{ Constructor
080:            /**
081:             * 
082:             * @param view the current jedit window
083:             * @param position a variable passed in from the script in actions.xml,
084:             * 	which can be DockableWindowManager.FLOATING, TOP, BOTTOM, LEFT, RIGHT, etc.
085:             * 	see @ref DockableWindowManager for possible values.
086:             */
087:            public QuickNotepad(View view, String position) {
088:                super (new BorderLayout());
089:                this .view = view;
090:                this .floating = position.equals(DockableWindowManager.FLOATING);
091:
092:                if (jEdit.getSettingsDirectory() != null) {
093:                    this .filename = jEdit
094:                            .getProperty(QuickNotepadPlugin.OPTION_PREFIX
095:                                    + "filepath");
096:                    if (this .filename == null || this .filename.length() == 0) {
097:                        this .filename = new String(jEdit.getSettingsDirectory()
098:                                + File.separator + "qn.txt");
099:                        jEdit.setProperty(QuickNotepadPlugin.OPTION_PREFIX
100:                                + "filepath", this .filename);
101:                    }
102:                    this .defaultFilename = this .filename;
103:                }
104:
105:                this .toolPanel = new QuickNotepadToolPanel(this );
106:                add(BorderLayout.NORTH, this .toolPanel);
107:
108:                if (floating)
109:                    this .setPreferredSize(new Dimension(500, 250));
110:
111:                textArea = new QuickNotepadTextArea();
112:                textArea.setFont(QuickNotepadOptionPane.makeFont());
113:
114:                JScrollPane pane = new JScrollPane(textArea);
115:                add(BorderLayout.CENTER, pane);
116:
117:                readFile();
118:            }
119:
120:            // }}}
121:
122:            // {{{ Member Functions
123:
124:            // {{{ focusOnDefaultComponent
125:            public void focusOnDefaultComponent() {
126:                textArea.requestFocus();
127:            }
128:
129:            // }}}
130:
131:            // {{{ getFileName
132:            public String getFilename() {
133:                return filename;
134:            }
135:
136:            // }}}
137:
138:            // EBComponent implementation
139:
140:            // {{{ handleMessage
141:            public void handleMessage(EBMessage message) {
142:                if (message instanceof  PropertiesChanged) {
143:                    propertiesChanged();
144:                }
145:            }
146:
147:            // }}}
148:
149:            // {{{ propertiesChanged
150:            private void propertiesChanged() {
151:                String propertyFilename = jEdit
152:                        .getProperty(QuickNotepadPlugin.OPTION_PREFIX
153:                                + "filepath");
154:                if (!StandardUtilities.objectsEqual(defaultFilename,
155:                        propertyFilename)) {
156:                    saveFile();
157:                    toolPanel.propertiesChanged();
158:                    defaultFilename = propertyFilename;
159:                    filename = defaultFilename;
160:                    readFile();
161:                }
162:                Font newFont = QuickNotepadOptionPane.makeFont();
163:                if (!newFont.equals(textArea.getFont())) {
164:                    textArea.setFont(newFont);
165:                }
166:            }
167:
168:            // }}}
169:
170:            // These JComponent methods provide the appropriate points
171:            // to subscribe and unsubscribe this object to the EditBus.
172:
173:            // {{{ addNotify
174:            public void addNotify() {
175:                super .addNotify();
176:                EditBus.addToBus(this );
177:            }
178:
179:            // }}}
180:
181:            // {{{ removeNotify
182:            public void removeNotify() {
183:                saveFile();
184:                super .removeNotify();
185:                EditBus.removeFromBus(this );
186:            }
187:
188:            // }}}
189:
190:            // QuickNotepadActions implementation
191:
192:            // {{{
193:            public void saveFile() {
194:                if (filename == null || filename.length() == 0)
195:                    return;
196:                try {
197:                    FileWriter out = new FileWriter(filename);
198:                    out.write(textArea.getText());
199:                    out.close();
200:                } catch (IOException ioe) {
201:                    Log.log(Log.ERROR, QuickNotepad.class,
202:                            "Could not write notepad text to " + filename);
203:                }
204:            }
205:
206:            // }}}
207:
208:            // {{{ chooseFile
209:            public void chooseFile() {
210:                String[] paths = GUIUtilities.showVFSFileDialog(view, null,
211:                        JFileChooser.OPEN_DIALOG, false);
212:                if (paths != null && !paths[0].equals(filename)) {
213:                    saveFile();
214:                    filename = paths[0];
215:                    toolPanel.propertiesChanged();
216:                    readFile();
217:                }
218:            }
219:
220:            // }}}
221:
222:            // {{{ copyToBuffer
223:            public void copyToBuffer() {
224:                jEdit.newFile(view);
225:                view.getEditPane().getTextArea().setText(textArea.getText());
226:            }
227:
228:            // }}}
229:            // {{{ readFile()
230:            /**
231:             * Helper method
232:             */
233:            private void readFile() {
234:                if (filename == null || filename.length() == 0)
235:                    return;
236:
237:                BufferedReader bf = null;
238:                try {
239:                    bf = new BufferedReader(new FileReader(filename));
240:                    StringBuffer sb = new StringBuffer(2048);
241:                    String str;
242:                    while ((str = bf.readLine()) != null) {
243:                        sb.append(str).append('\n');
244:                    }
245:                    bf.close();
246:                    textArea.setText(sb.toString());
247:                } catch (FileNotFoundException fnf) {
248:                    Log.log(Log.ERROR, QuickNotepad.class, "notepad file "
249:                            + filename + " does not exist");
250:                } catch (IOException ioe) {
251:                    Log.log(Log.ERROR, QuickNotepad.class,
252:                            "could not read notepad file " + filename);
253:                }
254:            }
255:            // }}}
256:            // }}}
257:        }
258:        // }}}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.