Source Code Cross Referenced for Frame.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:         * Frame.java
003:         *
004:         * Copyright (C) 1998-2003 Peter Graves
005:         * $Id: Frame.java,v 1.13 2003/07/25 16:30:36 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.Cursor;
025:        import java.awt.Dimension;
026:        import java.awt.Insets;
027:        import java.awt.Rectangle;
028:        import java.awt.Toolkit;
029:        import java.awt.event.ComponentEvent;
030:        import java.awt.event.ComponentListener;
031:        import java.awt.event.FocusEvent;
032:        import java.awt.event.FocusListener;
033:        import java.awt.event.KeyEvent;
034:        import java.awt.event.WindowEvent;
035:        import java.awt.event.WindowListener;
036:        import java.awt.event.WindowStateListener;
037:        import java.lang.reflect.Method;
038:        import javax.swing.JButton;
039:        import javax.swing.JComponent;
040:        import javax.swing.JFrame;
041:        import javax.swing.SwingUtilities;
042:
043:        public final class Frame extends JFrame implements  Constants,
044:                ComponentListener, FocusListener, WindowListener,
045:                WindowStateListener {
046:            private Editor[] editors = new Editor[2];
047:            private Editor currentEditor;
048:            private ToolBar toolbar;
049:            private boolean showToolbar;
050:            private AdjustPlacementRunnable adjustPlacementRunnable;
051:            private Rectangle rect;
052:            private int extendedState;
053:
054:            public Frame(Editor editor) {
055:                Editor.frames.add(this );
056:                addComponentListener(this );
057:                addWindowListener(this );
058:                addFocusListener(this );
059:                addWindowStateListener(this );
060:                setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
061:                statusBar = new StatusBar(this );
062:                getContentPane().add(statusBar, "South");
063:                final SessionProperties sessionProperties = Editor
064:                        .getSessionProperties();
065:                showToolbar = sessionProperties.getShowToolbar(this );
066:                currentEditor = editors[0] = editor;
067:                if (sessionProperties.getShowSidebar(this )) {
068:                    sidebar = new Sidebar(this );
069:                    sidebarSplitPane = createSidebarSplitPane();
070:                    getContentPane().add(sidebarSplitPane, "Center");
071:                } else
072:                    getContentPane().add(editors[0], "Center");
073:                titleChanged();
074:            }
075:
076:            public void titleChanged() {
077:                FastStringBuffer sb = new FastStringBuffer(Version
078:                        .getShortVersionString());
079:                String sessionName = Editor.getSessionName();
080:                if (sessionName != null) {
081:                    sb.append(" [");
082:                    sb.append(sessionName);
083:                    sb.append(']');
084:                }
085:                if (Editor.isDebugEnabled()) {
086:                    sb.append("     Java ");
087:                    sb.append(System.getProperty("java.version"));
088:                    sb.append(' ');
089:                    sb.append(System.getProperty("java.vendor"));
090:                }
091:                setTitle(sb.toString());
092:            }
093:
094:            public void storeExtendedState(int state) {
095:                extendedState = state;
096:            }
097:
098:            public int retrieveExtendedState() {
099:                return extendedState;
100:            }
101:
102:            public Rectangle getRect() {
103:                return rect;
104:            }
105:
106:            protected void processEvent(java.awt.AWTEvent e) {
107:                if (!(e instanceof  KeyEvent))
108:                    super .processEvent(e);
109:            }
110:
111:            public int getEditorCount() {
112:                int count = 0;
113:                if (editors[0] != null)
114:                    ++count;
115:                if (editors[1] != null)
116:                    ++count;
117:                return count;
118:            }
119:
120:            public Editor getEditor() {
121:                return editors[0];
122:            }
123:
124:            public final Editor getCurrentEditor() {
125:                return currentEditor;
126:            }
127:
128:            // May return null.
129:            public final Editor getOtherEditor() {
130:                return currentEditor == editors[0] ? editors[1] : editors[0];
131:            }
132:
133:            public final void setCurrentEditor(Editor editor) {
134:                Debug.assertTrue(editor != null);
135:                Debug.assertTrue(editor == editors[0] || editor == editors[1]);
136:                currentEditor = editor;
137:            }
138:
139:            public final Editor getPrimaryEditor() {
140:                return editors[0];
141:            }
142:
143:            public final Editor getSecondaryEditor() {
144:                return editors[1];
145:            }
146:
147:            public final boolean isPrimaryEditor(Editor ed) {
148:                return ed != null && ed == editors[0];
149:            }
150:
151:            public final boolean contains(Editor ed) {
152:                return ed != null && (ed == editors[0] || ed == editors[1]);
153:            }
154:
155:            public void updateTitle() {
156:                if (editors[0] != null)
157:                    editors[0].updateLocation();
158:                if (editors[1] != null)
159:                    editors[1].updateLocation();
160:            }
161:
162:            private Sidebar sidebar;
163:
164:            public final Sidebar getSidebar() {
165:                return sidebar;
166:            }
167:
168:            private SplitPane sidebarSplitPane;
169:
170:            public final SplitPane getSidebarSplitPane() {
171:                return sidebarSplitPane;
172:            }
173:
174:            private SplitPane createSidebarSplitPane() {
175:                SplitPane splitPane = new SplitPane(SplitPane.HORIZONTAL_SPLIT,
176:                        sidebar, getEditorPane());
177:                int dividerLocation = Editor.getSessionProperties()
178:                        .getSidebarWidth(this );
179:                splitPane.setDividerLocation(dividerLocation);
180:                splitPane.setBorder(null);
181:                return splitPane;
182:            }
183:
184:            private void addSidebar() {
185:                if (sidebarSplitPane != null)
186:                    getContentPane().remove(sidebarSplitPane);
187:                sidebar = new Sidebar(this );
188:                sidebarSplitPane = createSidebarSplitPane();
189:                getContentPane().add(sidebarSplitPane, "Center");
190:                validate();
191:                currentEditor.setFocusToDisplay();
192:                sidebar.setUpdateFlag(SIDEBAR_ALL);
193:            }
194:
195:            private JComponent editorPane;
196:
197:            public final JComponent getEditorPane() {
198:                if (editorPane != null)
199:                    return editorPane;
200:                else
201:                    return editors[0];
202:            }
203:
204:            public void frameToggleSidebar() {
205:                if (sidebar == null) {
206:                    // Add sidebar.
207:                    getContentPane().remove(getEditorPane());
208:                    addSidebar();
209:                } else {
210:                    // Save state before removing sidebar.
211:                    Editor.getSessionProperties().saveSidebarState(this );
212:                    // Remove sidebar.
213:                    getContentPane().remove(sidebarSplitPane);
214:                    sidebarSplitPane = null;
215:                    sidebar = null;
216:                    getContentPane().add(getEditorPane(), "Center");
217:                }
218:                validate();
219:                editors[0].updateScrollBars();
220:                if (editors[1] != null)
221:                    editors[1].updateScrollBars();
222:                currentEditor.setFocusToDisplay();
223:            }
224:
225:            private StatusBar statusBar;
226:
227:            public final StatusBar getStatusBar() {
228:                return statusBar;
229:            }
230:
231:            public void repaintStatusBar() {
232:                if (statusBar != null)
233:                    statusBar.repaint();
234:            }
235:
236:            public void setStatusText(String text) {
237:                if (statusBar != null && text != null
238:                        && !text.equals(statusBar.getText())) {
239:                    statusBar.setText(text);
240:                    statusBar.repaintNow();
241:                }
242:            }
243:
244:            public boolean getShowToolbar() {
245:                return showToolbar;
246:            }
247:
248:            public void setToolbar() {
249:                if (showToolbar && ToolBar.isToolBarEnabled()) {
250:                    // We want a toolbar.
251:                    ToolBar tb = currentEditor.getMode().getToolBar(this );
252:                    if (tb != toolbar) {
253:                        if (toolbar != null) {
254:                            getContentPane().remove(toolbar);
255:                            toolbar = null;
256:                        }
257:                        if (tb != null) {
258:                            getContentPane().add(toolbar = tb, "North");
259:                            toolbar.repaint();
260:                        }
261:                        getContentPane().validate();
262:                    }
263:                } else {
264:                    // We don't want a toolbar.
265:                    if (toolbar != null) {
266:                        getContentPane().remove(toolbar);
267:                        getContentPane().validate();
268:                    }
269:                }
270:            }
271:
272:            public void frameToggleToolbar() {
273:                showToolbar = !showToolbar;
274:                if (toolbar != null) {
275:                    if (!showToolbar) {
276:                        getContentPane().remove(toolbar);
277:                        toolbar = null;
278:                        getContentPane().validate();
279:                    }
280:                } else {
281:                    if (showToolbar && ToolBar.isToolBarEnabled()) {
282:                        ToolBar tb = currentEditor.getMode().getToolBar(this );
283:                        if (tb != null) {
284:                            getContentPane().add(toolbar = tb, "North");
285:                            toolbar.repaint();
286:                            getContentPane().validate();
287:                        }
288:                    }
289:                }
290:                // Save new state.
291:                Editor.getSessionProperties().setShowToolbar(this , showToolbar);
292:            }
293:
294:            private ToolBar defaultToolBar;
295:
296:            public ToolBar getDefaultToolBar() {
297:                if (defaultToolBar == null)
298:                    defaultToolBar = new DefaultToolBar(this );
299:
300:                return defaultToolBar;
301:            }
302:
303:            public void addToolbar(ToolBar tb) {
304:                Debug.assertTrue(toolbar == null);
305:                if (tb != null) {
306:                    toolbar = tb;
307:                    getContentPane().add(toolbar, "North");
308:                    toolbar.repaint();
309:                }
310:                // Make sure toolbar doesn't steal focus.
311:                Runnable r = new Runnable() {
312:                    public void run() {
313:                        JComponent c = getFocusedComponent();
314:                        if (c != null)
315:                            c.requestFocus();
316:                    }
317:                };
318:                SwingUtilities.invokeLater(r);
319:            }
320:
321:            public void maybeAddToolbar() {
322:                if (toolbar != null)
323:                    return;
324:                ToolBar tb = currentEditor.getMode().getToolBar(this );
325:                if (tb != null)
326:                    addToolbar(tb);
327:            }
328:
329:            public void removeToolbar() {
330:                if (toolbar != null) {
331:                    getContentPane().remove(toolbar);
332:                    toolbar = null;
333:                    getContentPane().validate();
334:                }
335:            }
336:
337:            public void setMenu() {
338:                final Mode mode = currentEditor.getMode();
339:                final MenuBar oldMenuBar = (MenuBar) getJMenuBar();
340:                if (oldMenuBar == null
341:                        || oldMenuBar.getMenuName() != mode.getMenuName()) {
342:                    setJMenuBar(mode.createMenuBar(this ));
343:                    validate();
344:                }
345:            }
346:
347:            public void placeWindow() {
348:                final SessionProperties sessionProperties = Editor
349:                        .getSessionProperties();
350:                if (editors[0] == Editor.getEditor(0)) {
351:                    // Initial window placement.
352:                    Rectangle desired = sessionProperties.getWindowPlacement(0);
353:                    if (desired.width == 0 || desired.height == 0) {
354:                        // Use reasonable defaults.
355:                        Dimension dim = Toolkit.getDefaultToolkit()
356:                                .getScreenSize();
357:                        desired.width = dim.width - 100;
358:                        if (desired.width > 800)
359:                            desired.width = 800;
360:                        desired.height = dim.height - 100;
361:                        desired.x = (dim.width - desired.width) / 2;
362:                        desired.y = (dim.height - desired.height) / 2;
363:                    }
364:                    int extendedState = sessionProperties.getExtendedState(0);
365:                    adjustPlacementRunnable = new AdjustPlacementRunnable(this ,
366:                            extendedState);
367:                    setBounds(desired);
368:                } else {
369:                    // BUG! Should not be hardcoded to 1!
370:                    Rectangle desired = sessionProperties.getWindowPlacement(1);
371:                    if (desired.width == 0 || desired.height == 0) {
372:                        // Default positioning is cascaded.
373:                        desired = Editor.getCurrentFrame().getBounds();
374:                        Insets insets = Editor.getCurrentFrame().getInsets();
375:                        desired.x += insets.left;
376:                        desired.width -= insets.left;
377:                        desired.y += insets.top;
378:                        desired.height -= insets.top;
379:                    }
380:                    setBounds(desired);
381:                    int extendedState = sessionProperties.getExtendedState(1);
382:                    if (extendedState != 0)
383:                        setExtendedState(extendedState);
384:                }
385:            }
386:
387:            public void splitWindow() {
388:                if (editors[1] == null) {
389:                    Editor.getSessionProperties().saveSidebarState(this );
390:                    final int height = editors[0].getHeight();
391:                    editors[0].saveView();
392:                    editors[1] = new Editor(this );
393:                    editors[1].activate(editors[0].getBuffer());
394:                    editors[1].updateLocation();
395:                    SplitPane sp = new SplitPane(SplitPane.VERTICAL_SPLIT,
396:                            editors[0], editors[1]);
397:                    sp.setBorder(null);
398:                    sp.setDividerLocation(height / 2);
399:                    editorPane = sp;
400:                    if (sidebar != null) {
401:                        sidebarSplitPane.setRightComponent(editorPane);
402:                        int dividerLocation = Editor.getSessionProperties()
403:                                .getSidebarWidth(this );
404:                        sidebarSplitPane.setDividerLocation(dividerLocation);
405:                    } else {
406:                        // No sidebar.
407:                        getContentPane().remove(editors[0]);
408:                        getContentPane().add(editorPane, "Center");
409:                    }
410:                    validate();
411:                    editors[0].setUpdateFlag(REFRAME);
412:                    editors[1].updateDisplay();
413:                    restoreFocus();
414:                    updateControls();
415:                }
416:            }
417:
418:            public void switchToBuffer(final Buffer buf) {
419:                Debug.bugIfNot(buf.isPaired()
420:                        || (getEditorCount() == 2 && editors[0].getBuffer()
421:                                .isPaired()));
422:                final Buffer primary;
423:                final Buffer secondary;
424:                if (buf.isPrimary()) {
425:                    primary = buf;
426:                    secondary = buf.getSecondary();
427:                } else {
428:                    Debug.bugIfNot(buf.isSecondary());
429:                    primary = buf.getPrimary();
430:                    Debug.bugIfNot(primary != null);
431:                    secondary = buf;
432:                }
433:                if (getEditorCount() == 2) {
434:                    // Window is already split.
435:                    if (secondary != null) {
436:                        // Activate primary in editor 0.
437:                        // Activate secondary in editor 1.
438:                        if (editors[0].getBuffer() != primary)
439:                            editors[0].activate(primary);
440:                        if (editors[1].getBuffer() != secondary)
441:                            editors[1].activate(secondary);
442:                        // Adjust split pane divider location.
443:                        if (editorPane instanceof  SplitPane) {
444:                            SplitPane sp = (SplitPane) editorPane;
445:                            int height = sp.getHeight();
446:                            float split = secondary.getSplit();
447:                            int dividerLocation = (int) (height * (1 - split) - sp
448:                                    .getDividerSize());
449:                            sp.setDividerLocation(dividerLocation);
450:                        }
451:                        Editor.setCurrentEditor(buf == primary ? editors[0]
452:                                : editors[1]);
453:                        editors[0].updateDisplay();
454:                        editors[1].updateDisplay();
455:                    } else {
456:                        // No secondary.
457:                        Debug.bugIfNot(secondary == null);
458:                        // We don't need a split window. Close editor 1.
459:                        Editor keep = editors[0];
460:                        Editor kill = editors[1];
461:                        // Save information about the buffer in the editor that we're
462:                        // going to close.
463:                        final Buffer b = kill.getBuffer();
464:                        if (b != null) {
465:                            b.autosave();
466:                            kill.saveView();
467:                            RecentFiles.getInstance().bufferDeactivated(b,
468:                                    kill.getDot());
469:                            b.windowClosing();
470:                        }
471:                        unsplitInternal(keep, kill);
472:                        // Activate primary in editor 0.
473:                        Debug.bugIfNot(editors[0] == keep);
474:                        keep.activate(primary);
475:                    }
476:                } else {
477:                    // Window is not split.
478:                    Debug.bugIfNot(getEditorCount() == 1);
479:                    if (secondary != null) {
480:                        // Split the window, activate primary in editor 0, activate
481:                        // secondary in editor 1.
482:                        splitWindow(primary, secondary, secondary.getSplit());
483:                        Editor.setCurrentEditor(buf == primary ? editors[0]
484:                                : editors[1]);
485:                        editors[0].updateDisplay();
486:                        editors[1].updateDisplay();
487:                        restoreFocus();
488:                    } else {
489:                        // Only one editor, no secondary.
490:                        Debug.bugIfNot(editors[0] != null);
491:                        Debug.bugIfNot(editors[1] == null);
492:                        Debug.bugIfNot(secondary == null);
493:                        // Activate primary in editor 0.
494:                        editors[0].activate(primary);
495:                    }
496:                }
497:                buf.setLastActivated(System.currentTimeMillis());
498:                if (Editor.isDebugEnabled()) {
499:                    if (buf.isPrimary()) {
500:                        Debug.bugIfNot(getPrimaryEditor().getBuffer() == buf);
501:                    } else {
502:                        Debug.bugIfNot(buf.isSecondary());
503:                        Buffer bufPrimary = buf.getPrimary();
504:                        Debug.bugIfNot(primary != null);
505:                        Debug
506:                                .bugIfNot(getPrimaryEditor().getBuffer() == bufPrimary);
507:                    }
508:                }
509:            }
510:
511:            public void splitWindow(Buffer buf1, Buffer buf2, float split) {
512:                if (editors[1] == null) {
513:                    final SessionProperties sessionProperties = Editor
514:                            .getSessionProperties();
515:                    sessionProperties.saveSidebarState(this );
516:                    final int height = editors[0].getHeight();
517:                    editors[0].saveView();
518:                    editors[0].activate(buf1);
519:                    editors[1] = new Editor(this );
520:                    editors[1].activate(buf2);
521:                    editors[1].updateLocation();
522:                    SplitPane sp = new SplitPane(SplitPane.VERTICAL_SPLIT,
523:                            editors[0], editors[1]);
524:                    sp.setBorder(null);
525:                    int dividerLocation = (int) (height * (1 - split) - sp
526:                            .getDividerSize());
527:                    sp.setDividerLocation(dividerLocation);
528:                    editorPane = sp;
529:                    if (sidebar != null) {
530:                        sidebarSplitPane.setRightComponent(editorPane);
531:                        dividerLocation = sessionProperties
532:                                .getSidebarWidth(this );
533:                        sidebarSplitPane.setDividerLocation(dividerLocation);
534:                    } else {
535:                        // No sidebar.
536:                        getContentPane().remove(editors[0]);
537:                        getContentPane().add(editorPane, "Center");
538:                    }
539:                    validate();
540:                    editors[0].setUpdateFlag(REFRAME | REPAINT);
541:                    editors[1].setUpdateFlag(REFRAME | REPAINT);
542:                    updateControls();
543:                }
544:            }
545:
546:            public final Editor activateInOtherWindow(Editor editor,
547:                    Buffer buffer) {
548:                // Switch to other window.
549:                return openInOtherWindow(editor, buffer, 0.5F, true);
550:            }
551:
552:            public final Editor activateInOtherWindow(Editor editor,
553:                    Buffer buffer, float split) {
554:                // Switch to other window.
555:                return openInOtherWindow(editor, buffer, split, true);
556:            }
557:
558:            public final Editor displayInOtherWindow(Editor editor,
559:                    Buffer buffer) {
560:                // Don't switch to other window.
561:                return openInOtherWindow(editor, buffer, 0.5F, false);
562:            }
563:
564:            private Editor openInOtherWindow(Editor editor, Buffer buffer,
565:                    float split, boolean switchWindows) {
566:                editor.saveView();
567:                Editor otherEditor = null;
568:                if (editors[1] == null) {
569:                    Debug.assertTrue(editor == editors[0]);
570:                    editors[1] = new Editor(this );
571:                    editors[1].activate(buffer);
572:                    editors[1].updateLocation();
573:                    SplitPane sp = new SplitPane(SplitPane.VERTICAL_SPLIT,
574:                            editor, editors[1]);
575:                    sp.setBorder(null);
576:                    int dividerLocation = (int) (editor.getHeight()
577:                            * (1 - split) - sp.getDividerSize());
578:                    sp.setDividerLocation(dividerLocation);
579:                    editorPane = sp;
580:                    if (sidebar != null) {
581:                        sidebarSplitPane.setRightComponent(editorPane);
582:                        sidebarSplitPane.setDividerLocation(Editor
583:                                .getSessionProperties().getSidebarWidth(this ));
584:                    } else {
585:                        // No sidebar.
586:                        getContentPane().remove(editor);
587:                        getContentPane().add(editorPane, "Center");
588:                    }
589:                    validate();
590:                    otherEditor = editors[1];
591:                } else {
592:                    // Second window is already open.
593:                    if (editor == editors[0])
594:                        otherEditor = editors[1];
595:                    else if (editor == editors[1])
596:                        otherEditor = editors[0];
597:                    else
598:                        Debug.assertTrue(false);
599:                    otherEditor.activate(buffer);
600:                    otherEditor.updateLocation();
601:                }
602:                if (switchWindows) {
603:                    Editor.setCurrentEditor(otherEditor);
604:                    setMenu();
605:                    setToolbar();
606:                }
607:                editors[0].setUpdateFlag(REFRAME | REPAINT);
608:                editors[0].updateDisplay();
609:                editors[1].setUpdateFlag(REFRAME | REPAINT);
610:                editors[1].updateDisplay();
611:                currentEditor.setFocusToDisplay();
612:                restoreFocus();
613:                updateControls();
614:                return otherEditor;
615:            }
616:
617:            public void closeEditor(Editor editor) {
618:                if (editors[1] == null)
619:                    return;
620:                if (editor != editors[0] && editor != editors[1])
621:                    return;
622:                promoteSecondaryBuffers();
623:                Editor keep = editor == editors[0] ? editors[1] : editors[0];
624:                Editor kill = editor;
625:                unsplitInternal(keep, kill);
626:            }
627:
628:            public void unsplitWindow() {
629:                if (editors[1] == null)
630:                    return;
631:                promoteSecondaryBuffers();
632:                Editor keep = currentEditor;
633:                Editor kill = getOtherEditor();
634:                unsplitInternal(keep, kill);
635:            }
636:
637:            public void unsplitWindowKeepOther() {
638:                if (editors[1] == null)
639:                    return;
640:                promoteSecondaryBuffers();
641:                Editor keep = getOtherEditor();
642:                Editor kill = currentEditor;
643:                unsplitInternal(keep, kill);
644:            }
645:
646:            public void promoteSecondaryBuffers() {
647:                Buffer buffer = editors[0].getBuffer();
648:                if (buffer.isSecondary())
649:                    buffer.promote();
650:                if (editors[1] != null) {
651:                    buffer = editors[1].getBuffer();
652:                    if (buffer.isSecondary())
653:                        buffer.promote();
654:                }
655:            }
656:
657:            private void unsplitInternal(final Editor keep, final Editor kill) {
658:                Editor.getSessionProperties().saveSidebarState(this );
659:                if (sidebar != null) {
660:                    sidebarSplitPane.setRightComponent(keep);
661:                    int dividerLocation = Editor.getSessionProperties()
662:                            .getSidebarWidth(this );
663:                    sidebarSplitPane.setDividerLocation(dividerLocation);
664:                } else {
665:                    // No sidebar.
666:                    getContentPane().remove(editorPane);
667:                    getContentPane().add(keep, "Center");
668:                }
669:                validate();
670:                editorPane = null;
671:                Editor.removeEditor(kill);
672:                editors[0] = keep;
673:                editors[1] = null;
674:                Buffer buffer = keep.getBuffer();
675:                if (buffer.isSecondary())
676:                    buffer.promote();
677:                Editor.setCurrentEditor(keep);
678:                keep.setUpdateFlag(REFRAME);
679:                keep.reframe();
680:                restoreFocus();
681:                statusBar.repaint();
682:                updateControls();
683:            }
684:
685:            public void updateControls() {
686:                boolean enable = editors[1] != null;
687:                LocationBar locationBar = editors[0].getLocationBar();
688:                if (locationBar != null) {
689:                    JButton closeButton = locationBar.getCloseButton();
690:                    if (closeButton != null)
691:                        closeButton.setEnabled(enable);
692:                }
693:                if (editors[1] != null) {
694:                    locationBar = editors[1].getLocationBar();
695:                    if (locationBar != null) {
696:                        JButton closeButton = locationBar.getCloseButton();
697:                        if (closeButton != null)
698:                            closeButton.setEnabled(enable);
699:                    }
700:                }
701:            }
702:
703:            private boolean active;
704:
705:            public final boolean isActive() {
706:                return active;
707:            }
708:
709:            public void reactivate() {
710:                if (currentEditor.getBuffer() == null)
711:                    return;
712:                boolean changed = false;
713:                for (BufferIterator it = new BufferIterator(); it.hasNext();) {
714:                    if (currentEditor.reactivate(it.nextBuffer()))
715:                        changed = true;
716:                }
717:                if (changed) {
718:                    for (int i = 0; i < Editor.getFrameCount(); i++) {
719:                        Frame frame = Editor.getFrame(i);
720:                        frame.setMenu();
721:                    }
722:                    Sidebar.repaintBufferListInAllFrames();
723:                }
724:            }
725:
726:            public void windowActivated(WindowEvent e) {
727:                active = true;
728:                Editor.setCurrentEditor(currentEditor);
729:                setFocus(currentEditor.getDisplay());
730:                repaint();
731:                // 1.4.0-rc hangs if we call reactivate() directly here.
732:                Runnable r = new Runnable() {
733:                    public void run() {
734:                        reactivate();
735:                    }
736:                };
737:                SwingUtilities.invokeLater(r);
738:            }
739:
740:            public void windowDeactivated(WindowEvent e) {
741:                active = false;
742:                // Show/hide caret.
743:                editors[0].repaint();
744:                if (editors[1] != null)
745:                    editors[1].repaint();
746:            }
747:
748:            public void windowOpened(WindowEvent e) {
749:                if (adjustPlacementRunnable != null) {
750:                    adjustPlacementRunnable.run();
751:                    adjustPlacementRunnable = null;
752:                }
753:            }
754:
755:            public void windowClosing(WindowEvent e) {
756:                editors[0].killFrame();
757:            }
758:
759:            public void windowClosed(WindowEvent e) {
760:            }
761:
762:            public void windowIconified(WindowEvent e) {
763:            }
764:
765:            public void windowDeiconified(WindowEvent e) {
766:            }
767:
768:            public void windowStateChanged(WindowEvent e) {
769:                int newState = e.getNewState();
770:                if (newState == 0) {
771:                    // Not maximized.
772:                    if (rect != null)
773:                        setBounds(rect);
774:                }
775:                storeExtendedState(newState);
776:            }
777:
778:            private JComponent focusedComponent;
779:
780:            public void setFocus(JComponent c) {
781:                boolean change = focusedComponent != c;
782:                if (c != null)
783:                    c.requestFocus();
784:                if (change) {
785:                    JComponent lastFocusedComponent = focusedComponent;
786:                    focusedComponent = c;
787:                    // Update display of current line (show/hide caret) in all
788:                    // windows, as required.
789:                    for (int i = 0; i < editors.length; i++) {
790:                        Editor editor = editors[i];
791:                        if (editor != null && editor.getDot() != null) {
792:                            Display display = editor.getDisplay();
793:                            if (display == focusedComponent
794:                                    || display == lastFocusedComponent) {
795:                                editor.updateDotLine();
796:                                display.repaintChangedLines();
797:                            }
798:                        }
799:                    }
800:                }
801:            }
802:
803:            public JComponent getFocusedComponent() {
804:                return focusedComponent;
805:            }
806:
807:            private static final Cursor waitCursor = Cursor
808:                    .getPredefinedCursor(Cursor.WAIT_CURSOR);
809:
810:            public final void setWaitCursor() {
811:                setCursor(waitCursor);
812:                editors[0].setWaitCursor();
813:                if (editors[1] != null)
814:                    editors[1].setWaitCursor();
815:            }
816:
817:            public final void setDefaultCursor() {
818:                setCursor(Cursor.getDefaultCursor());
819:                editors[0].setDefaultCursor();
820:                if (editors[1] != null)
821:                    editors[1].setDefaultCursor();
822:            }
823:
824:            public void resetDisplay() {
825:                if (toolbar != null) {
826:                    getContentPane().remove(toolbar);
827:                    toolbar = null;
828:                }
829:                defaultToolBar = null;
830:                for (int i = 0; i < editors.length; i++) {
831:                    Editor editor = editors[i];
832:                    if (editor != null) {
833:                        editor.removeLocationBar();
834:                        editor.removeVerticalScrollBar();
835:                        editor.removeHorizontalScrollBar();
836:                    }
837:                }
838:                DefaultLookAndFeel.setLookAndFeel();
839:                final Mode mode = currentEditor.getMode();
840:                setJMenuBar(mode.createMenuBar(this ));
841:                final SessionProperties sessionProperties = Editor
842:                        .getSessionProperties();
843:                if (sessionProperties.getShowToolbar(this )
844:                        && ToolBar.isToolBarEnabled()) {
845:                    ToolBar tb = mode.getToolBar(this );
846:                    if (tb != null)
847:                        addToolbar(tb);
848:                }
849:                if (sidebarSplitPane != null) {
850:                    // Save state before removing sidebar.
851:                    sessionProperties.saveSidebarState(this );
852:                    // Remove sidebar.
853:                    getContentPane().remove(sidebarSplitPane);
854:                    sidebarSplitPane = null;
855:                    sidebar = null;
856:
857:                    if (Platform.isJava14()) {
858:                        // With Sun Java 1.4.0 FCS, if the following 3 lines of code
859:                        // are removed, focus is lost when this method is called from
860:                        // Buffer.saveLocal() after the preferences file is saved.
861:                        // When this happens, focus can be recovered by switching to a
862:                        // different Sawfish workspace and back again, at which point
863:                        // any keystrokes that were lost are replayed accurately into
864:                        // the buffer.
865:
866:                        // Not that it makes any sense to do this... ;)
867:                        getContentPane().add(getEditorPane(), "Center");
868:                        currentEditor.getDisplay().requestFocus();
869:                        getContentPane().remove(getEditorPane());
870:                    }
871:
872:                    sidebar = new Sidebar(this );
873:                    sidebarSplitPane = createSidebarSplitPane();
874:                    getContentPane().add(sidebarSplitPane, "Center");
875:                    sidebar.setUpdateFlag(SIDEBAR_ALL);
876:                }
877:                for (int i = 0; i < editors.length; i++) {
878:                    Editor editor = editors[i];
879:                    if (editor != null) {
880:                        editor.addLocationBar();
881:                        editor.updateLocation();
882:                        editor.addVerticalScrollBar();
883:                        editor.addHorizontalScrollBar();
884:                        editor.getDisplay().initialize();
885:                    }
886:                }
887:                updateControls();
888:                validate();
889:            }
890:
891:            public static final void restoreFocus() {
892:                Editor.restoreFocus();
893:            }
894:
895:            private Object folderTree;
896:
897:            public final Object getFolderTree() {
898:                return folderTree;
899:            }
900:
901:            public final void setFolderTree(Object obj) {
902:                folderTree = obj;
903:            }
904:
905:            public void componentResized(ComponentEvent e) {
906:                if (extendedState != 6) {
907:                    // Not maximized.
908:                    rect = getBounds();
909:                }
910:            }
911:
912:            public void componentMoved(ComponentEvent e) {
913:                if (extendedState != 6) {
914:                    // Not maximized.
915:                    rect = getBounds();
916:                }
917:            }
918:
919:            public void componentShown(ComponentEvent e) {
920:            }
921:
922:            public void componentHidden(ComponentEvent e) {
923:            }
924:
925:            public void focusGained(FocusEvent e) {
926:                currentEditor.setFocusToDisplay();
927:            }
928:
929:            public void focusLost(FocusEvent e) {
930:            }
931:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.