Source Code Cross Referenced for ArchiveMode.java in  » IDE » J » org » armedbear » j » 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 » J » org.armedbear.j 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ArchiveMode.java
003:         *
004:         * Copyright (C) 1998-2003 Peter Graves
005:         * $Id: ArchiveMode.java,v 1.3 2003/07/05 16:03:04 piso Exp $
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 (at your option) 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:
022:        package org.armedbear.j;
023:
024:        import gnu.regexp.RE;
025:        import gnu.regexp.REMatch;
026:        import gnu.regexp.UncheckedRE;
027:        import java.awt.AWTEvent;
028:        import java.awt.event.KeyEvent;
029:        import java.awt.event.MouseEvent;
030:        import java.io.IOException;
031:        import java.io.OutputStream;
032:        import java.text.SimpleDateFormat;
033:        import java.util.Date;
034:        import java.util.zip.ZipEntry;
035:        import java.util.zip.ZipInputStream;
036:
037:        public final class ArchiveMode extends AbstractMode implements 
038:                Constants, Mode {
039:            private static final ArchiveMode mode = new ArchiveMode();
040:            private static final RE moveToFilenameRegExp = new UncheckedRE(
041:                    ":[0-5][0-9] ");
042:
043:            private ArchiveMode() {
044:                super (ARCHIVE_MODE, ARCHIVE_MODE_NAME);
045:                setProperty(Property.VERTICAL_RULE, 0);
046:                setProperty(Property.SHOW_LINE_NUMBERS, false);
047:            }
048:
049:            public static final ArchiveMode getMode() {
050:                return mode;
051:            }
052:
053:            public final Formatter getFormatter(Buffer buffer) {
054:                return new PlainTextFormatter(buffer);
055:            }
056:
057:            protected void setKeyMapDefaults(KeyMap km) {
058:                km.mapKey(KeyEvent.VK_ENTER, 0, "archiveOpenFile");
059:                km.mapKey(KeyEvent.VK_G, CTRL_MASK | SHIFT_MASK,
060:                        "archiveOpenFile");
061:                km.mapKey(VK_DOUBLE_MOUSE_1, 0, "archiveOpenFile");
062:                km.mapKey(VK_MOUSE_2, 0, "archiveOpenFile");
063:            }
064:
065:            private static String getName(String s) {
066:                REMatch match = moveToFilenameRegExp.getMatch(s);
067:                return match == null ? null : s.substring(match.getEndIndex());
068:            }
069:
070:            public static void openFileAtDot(Editor editor) {
071:                Buffer buffer = editor.getBuffer();
072:                String name = getName(editor.getDotLine().getText());
073:                if (name == null)
074:                    return;
075:                String source = null;
076:                if (buffer.getFile() != null) {
077:                    source = "[from " + buffer.getFile().netPath() + "]";
078:                } else {
079:                    Compression compression = buffer.getCompression();
080:                    if (compression != null
081:                            && compression.getType() == COMPRESSION_ZIP)
082:                        source = "[from " + compression.getEntryName() + " "
083:                                + compression.getSource() + "]";
084:                }
085:                String title = name + " " + source;
086:                for (BufferIterator it = new BufferIterator(); it.hasNext();) {
087:                    Buffer maybe = it.nextBuffer();
088:                    if (title.equals(maybe.getTitle())) {
089:                        editor.makeNext(maybe);
090:                        editor.activate(maybe);
091:                        return;
092:                    }
093:                }
094:                File toBeLoaded = null;
095:                if (buffer.getCache() != null)
096:                    toBeLoaded = buffer.getCache();
097:                else
098:                    toBeLoaded = buffer.getFile();
099:                ZipInputStream in = null;
100:                try {
101:                    in = new ZipInputStream(toBeLoaded.getInputStream());
102:                    ZipEntry zipEntry;
103:                    while ((zipEntry = in.getNextEntry()) != null) {
104:                        if (zipEntry.getName().equals(name)) {
105:                            if (zipEntry.isDirectory()) {
106:                                editor.status(name + " is a directory");
107:                            } else {
108:                                Buffer buf = null;
109:                                File cache = cacheEntry(in);
110:                                // First see if it's an image...
111:                                if (Editor.getModeList().modeAccepts(
112:                                        IMAGE_MODE, name))
113:                                    buf = ImageBuffer.createImageBuffer(null,
114:                                            cache, null);
115:                                if (buf != null) {
116:                                    buf.setCompression(new Compression(
117:                                            COMPRESSION_ZIP, zipEntry, source));
118:                                    buf.setTitle(title);
119:                                } else {
120:                                    buf = new Buffer();
121:                                    buf.type = Buffer.TYPE_NORMAL; // Default (may be changed later).
122:                                    buf.initializeUndo();
123:                                    buf.setCache(cache);
124:                                    buf.setCompression(new Compression(
125:                                            COMPRESSION_ZIP, zipEntry, source));
126:                                    buf.initialize(); // May change buffer type.
127:                                    buf.setTitle(title);
128:                                    buf.readOnly = true;
129:                                }
130:                                editor.makeNext(buf);
131:                                editor.activate(buf);
132:                            }
133:                            break;
134:                        }
135:                    }
136:                } catch (Exception e) {
137:                    Log.error(e);
138:                }
139:                try {
140:                    if (in != null)
141:                        in.close();
142:                } catch (Exception e) {
143:                    Log.error(e);
144:                }
145:            }
146:
147:            private static File cacheEntry(ZipInputStream in) {
148:                File cache = Utilities.getTempFile();
149:                if (cache != null) {
150:                    OutputStream out = null;
151:                    try {
152:                        out = cache.getOutputStream();
153:                        byte[] bytes = new byte[16384];
154:                        int bytesRead;
155:                        while ((bytesRead = in.read(bytes, 0, bytes.length)) > 0)
156:                            out.write(bytes, 0, bytesRead);
157:                    } catch (IOException e) {
158:                        Log.error(e);
159:                    }
160:                    if (out != null) {
161:                        try {
162:                            out.close();
163:                        } catch (IOException e) {
164:                            Log.error(e);
165:                        }
166:                    }
167:                }
168:                return cache;
169:            }
170:
171:            public void loadFile(Buffer buffer, File file) {
172:                if (!buffer.isLoaded()) {
173:                    ZipInputStream in = null;
174:                    try {
175:                        in = new ZipInputStream(file.getInputStream());
176:                        ZipEntry ze;
177:                        while ((ze = in.getNextEntry()) != null)
178:                            appendLine(buffer, ze);
179:                        buffer.renumber();
180:
181:                        // Is this right if we're loading from a local cache?
182:                        buffer.setLastModified(file.lastModified());
183:                        buffer.setLoaded(true);
184:                    } catch (Exception e) {
185:                        Log.error(e);
186:                    }
187:                    try {
188:                        if (in != null)
189:                            in.close();
190:                    } catch (Exception e) {
191:                        Log.error(e);
192:                    }
193:                }
194:            }
195:
196:            private static final SimpleDateFormat zipEntryDateFormatter = new SimpleDateFormat(
197:                    "MMM dd yyyy HH:mm");
198:
199:            private static void appendLine(Buffer buffer, ZipEntry ze) {
200:                FastStringBuffer sb = new FastStringBuffer();
201:                String sizeString = String.valueOf(ze.getSize());
202:                for (int i = 9 - sizeString.length(); i >= 0; i--)
203:                    sb.append(' ');
204:                sb.append(sizeString);
205:                sb.append(' ');
206:                sb.append(zipEntryDateFormatter.format(new Date(ze.getTime())));
207:                sb.append(' ');
208:                sb.append(ze.getName());
209:                buffer.appendLine(sb.toString());
210:            }
211:
212:            public static void archiveOpenFile() {
213:                final Editor editor = Editor.currentEditor();
214:                if (editor.getModeId() == ARCHIVE_MODE) {
215:                    // If this method is invoked via a mouse event mapping, move dot to
216:                    // location of mouse click first.
217:                    AWTEvent e = editor.getDispatcher().getLastEvent();
218:                    if (e instanceof  MouseEvent)
219:                        editor.mouseMoveDotToPoint((MouseEvent) e);
220:                    openFileAtDot(editor);
221:                }
222:            }
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.