Source Code Cross Referenced for GotoDialogSupport.java in  » Swing-Library » abeille-forms-designer » org » netbeans » editor » ext » 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 » abeille forms designer » org.netbeans.editor.ext 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *                 Sun Public License Notice
003:         * 
004:         * The contents of this file are subject to the Sun Public License
005:         * Version 1.0 (the "License"). You may not use this file except in
006:         * compliance with the License. A copy of the License is available at
007:         * http://www.sun.com/
008:         * 
009:         * The Original Code is NetBeans. The Initial Developer of the Original
010:         * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
011:         * Microsystems, Inc. All Rights Reserved.
012:         */
013:
014:        package org.netbeans.editor.ext;
015:
016:        import java.awt.Dialog;
017:        import java.awt.Dimension;
018:        import java.awt.Rectangle;
019:        import java.awt.Toolkit;
020:        import java.awt.event.ActionEvent;
021:        import java.awt.event.ActionListener;
022:        import java.awt.event.KeyEvent;
023:        import java.awt.event.KeyListener;
024:
025:        import javax.swing.Action;
026:        import javax.swing.JButton;
027:        import javax.swing.text.JTextComponent;
028:
029:        import org.netbeans.editor.BaseDocument;
030:        import org.netbeans.editor.BaseKit;
031:        import org.netbeans.editor.DialogSupport;
032:        import org.netbeans.editor.EditorState;
033:        import org.netbeans.editor.LocaleSupport;
034:        import org.netbeans.editor.Utilities;
035:
036:        /**
037:         * Support for displaying goto dialog
038:         * 
039:         * @author Miloslav Metelka, Petr Nejedly
040:         * @version 1.00
041:         */
042:
043:        public class GotoDialogSupport implements  ActionListener {
044:
045:            /** The EditorSettings key storing the last location of the dialog. */
046:            private static final String BOUNDS_KEY = "GotoDialogSupport.bounds-goto-line"; // NOI18N
047:
048:            private JButton[] gotoButtons;
049:            private GotoDialogPanel gotoPanel;
050:            private static Dialog gotoDialog;
051:
052:            public GotoDialogSupport() {
053:                JButton gotoButton = new JButton(LocaleSupport
054:                        .getString("goto-button-goto")); // NOI18N
055:                JButton cancelButton = new JButton(LocaleSupport
056:                        .getString("goto-button-cancel")); // NOI18N
057:                gotoButton.getAccessibleContext().setAccessibleDescription(
058:                        LocaleSupport.getString("ACSD_goto-button-goto")); // NOI18N
059:                cancelButton.getAccessibleContext().setAccessibleDescription(
060:                        LocaleSupport.getString("ACSD_goto-button-cancel")); // NOI18N
061:                /*
062:                 * gotoButton.setMnemonic(
063:                 * LocaleSupport.getChar("goto-button-goto-mnemonic", 'G') ); //NOI18N
064:                 */
065:
066:                gotoButtons = new JButton[] { gotoButton, cancelButton };
067:                gotoPanel = new GotoDialogPanel();
068:
069:                gotoPanel.getGotoCombo().getEditor().getEditorComponent()
070:                        .addKeyListener(new KeyListener() {
071:                            public void keyPressed(KeyEvent evt) {
072:                            }
073:
074:                            public void keyReleased(KeyEvent evt) {
075:                            }
076:
077:                            public void keyTyped(KeyEvent evt) {
078:                                if (evt.getKeyChar() == '\n') {
079:                                    actionPerformed(new ActionEvent(
080:                                            gotoButtons[0], 0, null));
081:                                }
082:                            }
083:                        });
084:
085:            }
086:
087:            protected synchronized Dialog createGotoDialog() {
088:                if (gotoDialog == null) {
089:                    gotoDialog = DialogSupport.createDialog(LocaleSupport
090:                            .getString("goto-title"), // NOI18N
091:                            gotoPanel, false, // non-modal
092:                            gotoButtons, false, // sidebuttons,
093:                            0, // defaultIndex = 0 => gotoButton
094:                            1, // cancelIndex = 1 => cancelButton
095:                            this  // listener
096:                            );
097:
098:                    gotoDialog.pack();
099:
100:                    // Position the dialog according to the history
101:                    Rectangle lastBounds = (Rectangle) EditorState
102:                            .get(BOUNDS_KEY);
103:                    if (lastBounds != null) {
104:                        gotoDialog.setBounds(lastBounds);
105:                    } else { // no history, center it on the screen
106:                        Dimension dim = gotoDialog.getPreferredSize();
107:                        Dimension screen = Toolkit.getDefaultToolkit()
108:                                .getScreenSize();
109:                        int x = Math.max(0, (screen.width - dim.width) / 2);
110:                        int y = Math.max(0, (screen.height - dim.height) / 2);
111:                        gotoDialog.setLocation(x, y);
112:                    }
113:
114:                    return gotoDialog;
115:                } else {
116:                    gotoDialog.toFront();
117:                    return null;
118:                }
119:            }
120:
121:            protected synchronized void disposeGotoDialog() {
122:                if (gotoDialog != null) {
123:                    EditorState.put(BOUNDS_KEY, gotoDialog.getBounds());
124:                    gotoDialog.dispose();
125:                    Utilities.returnFocus();
126:                }
127:
128:                gotoDialog = null;
129:            }
130:
131:            public void showGotoDialog() {
132:                Dialog dialog = createGotoDialog();
133:                if (dialog == null) { // already visible
134:                    // TODO:beep()
135:                    return;
136:                }
137:                gotoPanel.popupNotify();
138:                dialog.setVisible(true);
139:            }
140:
141:            public void actionPerformed(ActionEvent evt) {
142:                Object src = evt.getSource();
143:                if (src == gotoButtons[0] || src == gotoPanel) { // Find button
144:                    if (performGoto()) {
145:                        gotoPanel.updateHistory(); // A.N.: support for history
146:                        disposeGotoDialog();
147:                    }
148:                } else { // Cancel button
149:                    disposeGotoDialog();
150:                }
151:            }
152:
153:            /**
154:             * Perform the goto operation.
155:             * 
156:             * @return whether the dialog should be made invisible or not
157:             */
158:            protected boolean performGoto() {
159:                JTextComponent c = Utilities.getLastActiveComponent();
160:                if (c != null) {
161:                    try {
162:                        int line = Integer.parseInt((String) gotoPanel
163:                                .getValue());
164:
165:                        BaseDocument doc = Utilities.getDocument(c);
166:                        if (doc != null) {
167:                            // Obtain the offset where to jump
168:                            int pos = Utilities.getRowStartFromLineOffset(doc,
169:                                    line - 1);
170:
171:                            BaseKit kit = Utilities.getKit(c);
172:                            if (kit != null) {
173:                                Action a = kit
174:                                        .getActionByName(ExtKit.gotoAction);
175:                                if (a instanceof  ExtKit.GotoAction) {
176:                                    pos = ((ExtKit.GotoAction) a)
177:                                            .getOffsetFromLine(doc, line - 1);
178:                                }
179:                            }
180:
181:                            if (pos != -1) {
182:                                c.getCaret().setDot(pos);
183:                            } else {
184:                                c.getToolkit().beep();
185:                                return false;
186:                            }
187:                        }
188:                    } catch (NumberFormatException e) {
189:                        c.getToolkit().beep();
190:                        return false;
191:                    }
192:                }
193:                return true;
194:            }
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.