Source Code Cross Referenced for ManMode.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:         * ManMode.java
003:         *
004:         * Copyright (C) 2000-2004 Peter Graves
005:         * $Id: ManMode.java,v 1.4 2004/04/01 18:50:03 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 java.awt.AWTEvent;
025:        import java.awt.event.KeyEvent;
026:        import java.awt.event.MouseEvent;
027:        import javax.swing.JPopupMenu;
028:
029:        public final class ManMode extends AbstractMode implements  Constants,
030:                Mode {
031:            private static final ManMode mode = new ManMode();
032:
033:            private ManMode() {
034:                super (MAN_MODE, MAN_MODE_NAME);
035:                setProperty(Property.VERTICAL_RULE, 0);
036:                setProperty(Property.SHOW_LINE_NUMBERS, false);
037:                setProperty(Property.HIGHLIGHT_MATCHING_BRACKET, false);
038:                setProperty(Property.HIGHLIGHT_BRACKETS, false);
039:            }
040:
041:            public static final ManMode getMode() {
042:                return mode;
043:            }
044:
045:            public JPopupMenu getContextMenu(Editor editor) {
046:                return null;
047:            }
048:
049:            public Formatter getFormatter(Buffer buffer) {
050:                if (buffer.getType() != Buffer.TYPE_MAN)
051:                    return null;
052:                return new ManFormatter(buffer, ((Man) buffer).isApropos());
053:            }
054:
055:            protected void setKeyMapDefaults(KeyMap km) {
056:                km.mapKey(KeyEvent.VK_ENTER, 0, "manFollowLink");
057:                km.mapKey(KeyEvent.VK_G, CTRL_MASK | SHIFT_MASK,
058:                        "manFollowLink");
059:                km.mapKey(VK_DOUBLE_MOUSE_1, 0, "manFollowLink");
060:                km.mapKey(VK_MOUSE_2, 0, "manFollowLink");
061:            }
062:
063:            private static void followLink(Editor editor) {
064:                if (editor.getBuffer().getType() == Buffer.TYPE_MAN) {
065:                    final Man man = (Man) editor.getBuffer();
066:                    final Line line = editor.getDotLine();
067:                    if (man.isApropos()) {
068:                        String topic = null;
069:                        String section = null;
070:                        String text = line.getText();
071:                        int index = text.indexOf(' ');
072:                        if (index >= 0) {
073:                            topic = text.substring(0, index);
074:                            text = text.substring(index);
075:                            index = text.indexOf('(');
076:                            if (index >= 0) {
077:                                int begin = index + 1;
078:                                int end = text.indexOf(')', begin);
079:                                if (end >= 0)
080:                                    section = text.substring(begin, end);
081:                            }
082:                        }
083:                        if (topic != null) {
084:                            if (section != null && section.length() > 0)
085:                                man(editor, section + " " + topic);
086:                            else
087:                                man(editor, topic);
088:                        }
089:                    } else {
090:                        LineSegmentList segmentList = man.getFormatter()
091:                                .formatLine(line);
092:                        int col = editor.getDotCol();
093:                        int startCol = 0;
094:                        for (int i = 0; i < segmentList.size(); i++) {
095:                            LineSegment segment = segmentList.getSegment(i);
096:                            if (startCol <= col
097:                                    && col < startCol + segment.length()) {
098:                                String s;
099:                                if (segment.getFormat() != 0) {
100:                                    // Segment is highlighted. Use the whole segment.
101:                                    s = segment.getText();
102:                                } else {
103:                                    // Not highlighted.
104:                                    s = editor.getFilenameAtDot();
105:                                }
106:                                if (s != null) {
107:                                    if (s.startsWith("/")) {
108:                                        // Looks like a Unix filename.
109:                                        Buffer buf = editor.openFile(File
110:                                                .getInstance(s));
111:                                        if (buf != null) {
112:                                            editor.makeNext(buf);
113:                                            editor.activate(buf);
114:                                        }
115:                                    } else
116:                                        man(editor, s);
117:                                }
118:                                break;
119:                            }
120:                            startCol += segment.length();
121:                        }
122:                    }
123:                }
124:            }
125:
126:            public static String getTitle(String topic) {
127:                return "man " + topic;
128:            }
129:
130:            public static void man() {
131:                if (!Platform.isPlatformUnix())
132:                    return;
133:                final Editor editor = Editor.currentEditor();
134:                ManDialog d = new ManDialog(editor);
135:                editor.centerDialog(d);
136:                d.show();
137:                String topic = d.getInput();
138:                if (topic != null && topic.length() != 0)
139:                    man(topic);
140:            }
141:
142:            public static void man(String topic) {
143:                if (!Platform.isPlatformUnix())
144:                    return;
145:                man(Editor.currentEditor(), topic);
146:            }
147:
148:            private static void man(Editor editor, String topic) {
149:                editor.setWaitCursor();
150:                try {
151:                    final String title = ManMode.getTitle(topic);
152:                    for (BufferIterator it = new BufferIterator(); it.hasNext();) {
153:                        Buffer buf = it.nextBuffer();
154:                        if (buf.getModeId() == MAN_MODE
155:                                && title.equals(buf.getTitle())) {
156:                            editor.makeNext(buf);
157:                            editor.switchToBuffer(buf);
158:                            return;
159:                        }
160:                    }
161:                    File tempFile = Utilities.getTempFile();
162:                    String cmd = "man " + topic + " > "
163:                            + tempFile.canonicalPath();
164:                    String[] cmdarray = { "/bin/sh", "-c", cmd };
165:                    try {
166:                        Process process = Runtime.getRuntime().exec(cmdarray);
167:                        process.waitFor();
168:                    } catch (Exception e) {
169:                        Log.error(e);
170:                    }
171:                    if (tempFile.isFile() && tempFile.length() > 0) {
172:                        Man man = new Man(topic, tempFile);
173:                        man.load();
174:                        tempFile.delete();
175:                        editor.makeNext(man);
176:                        editor.switchToBuffer(man);
177:                    } else
178:                        editor.status("No entry");
179:                } finally {
180:                    editor.setDefaultCursor();
181:                }
182:            }
183:
184:            public static void manFollowLink() {
185:                final Editor editor = Editor.currentEditor();
186:                final Buffer buffer = editor.getBuffer();
187:                if (buffer.getType() != Buffer.TYPE_MAN)
188:                    return;
189:                // If this method is invoked via a mouse event mapping, move dot to
190:                // location of mouse click before following link.
191:                AWTEvent e = editor.getDispatcher().getLastEvent();
192:                if (e instanceof  MouseEvent)
193:                    editor.mouseMoveDotToPoint((MouseEvent) e);
194:                followLink(editor);
195:            }
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.