Source Code Cross Referenced for PanelWindowContainer.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » gui » 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 » org.gjt.sp.jedit.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * PanelWindowContainer.java - holds dockable windows
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 2000, 2004 Slava Pestov
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:
023:        package org.gjt.sp.jedit.gui;
024:
025:        //{{{ Imports
026:        import javax.swing.border.*;
027:        import javax.swing.plaf.metal.*;
028:        import javax.swing.*;
029:        import java.awt.event.*;
030:        import java.awt.font.*;
031:        import java.awt.geom.AffineTransform;
032:        import java.awt.*;
033:        import java.util.*;
034:        import java.util.List;
035:
036:        import org.gjt.sp.jedit.*;
037:        import org.gjt.sp.util.StandardUtilities;
038:
039:        //}}}
040:
041:        /**
042:         * A container for dockable windows. This class should never be used
043:         * directly.
044:         * @author Slava Pestov
045:         * @version $Id: PanelWindowContainer.java 9062 2007-03-02 08:05:04Z kpouer $
046:         * @since jEdit 4.0pre1
047:         */
048:        public class PanelWindowContainer implements  DockableWindowContainer {
049:            //{{{ PanelWindowContainer constructor
050:            public PanelWindowContainer(DockableWindowManager wm,
051:                    String position, int dimension) {
052:                this .wm = wm;
053:                this .position = position;
054:
055:                //{{{ Button box setup
056:                buttonPanel = new JPanel(new ButtonLayout());
057:                buttonPanel.setBorder(new EmptyBorder(1, 1, 1, 1));
058:
059:                closeBox = new JButton(GUIUtilities.loadIcon("closebox.gif"));
060:                closeBox.setRequestFocusEnabled(false);
061:                closeBox.setToolTipText(jEdit
062:                        .getProperty("view.docking.close-tooltip"));
063:                if (OperatingSystem.isMacOSLF())
064:                    closeBox.putClientProperty("JButton.buttonType", "toolbar");
065:
066:                closeBox.setMargin(new Insets(0, 0, 0, 0));
067:
068:                closeBox.addActionListener(new ActionHandler());
069:
070:                menuBtn = new JButton(GUIUtilities.loadIcon("ToolbarMenu.gif"));
071:                menuBtn.setRequestFocusEnabled(false);
072:                menuBtn.setToolTipText(jEdit
073:                        .getProperty("view.docking.menu-tooltip"));
074:                if (OperatingSystem.isMacOSLF())
075:                    menuBtn.putClientProperty("JButton.buttonType", "toolbar");
076:
077:                menuBtn.setMargin(new Insets(0, 0, 0, 0));
078:
079:                menuBtn.addMouseListener(new MenuMouseHandler());
080:
081:                buttonGroup = new ButtonGroup();
082:                // JDK 1.4 workaround
083:                buttonGroup.add(nullButton = new JToggleButton());
084:                //}}}
085:
086:                dockables = new ArrayList<DockableWindowManager.Entry>();
087:                buttons = new ArrayList<AbstractButton>();
088:                dockablePanel = new DockablePanel(this );
089:
090:                this .dimension = dimension;
091:            } //}}}
092:
093:            //{{{ getDockableWindowManager() method
094:            /**
095:             * @since jEdit 4.3pre2
096:             */
097:            public DockableWindowManager getDockableWindowManager() {
098:                return wm;
099:            } //}}}
100:
101:            //{{{ register() method
102:            public void register(DockableWindowManager.Entry entry) {
103:                dockables.add(entry);
104:
105:                //{{{ Create button
106:                int rotation;
107:                if (position.equals(DockableWindowManager.TOP)
108:                        || position.equals(DockableWindowManager.BOTTOM))
109:                    rotation = RotatedTextIcon.NONE;
110:                else if (position.equals(DockableWindowManager.LEFT))
111:                    rotation = RotatedTextIcon.CCW;
112:                else if (position.equals(DockableWindowManager.RIGHT))
113:                    rotation = RotatedTextIcon.CW;
114:                else
115:                    throw new InternalError("Invalid position: " + position);
116:
117:                JToggleButton button = new JToggleButton();
118:                button.setMargin(new Insets(1, 1, 1, 1));
119:                button.setRequestFocusEnabled(false);
120:                button.setIcon(new RotatedTextIcon(rotation, button.getFont(),
121:                        entry.shortTitle()));
122:                button.setActionCommand(entry.factory.name);
123:                button.addActionListener(new ActionHandler());
124:                button.addMouseListener(new MenuMouseHandler());
125:                if (OperatingSystem.isMacOSLF())
126:                    button.putClientProperty("JButton.buttonType", "toolbar");
127:                //}}}
128:
129:                buttonGroup.add(button);
130:                buttons.add(button);
131:                entry.btn = button;
132:
133:                wm.revalidate();
134:            } //}}}
135:
136:            //{{{ unregister() method
137:            public void unregister(DockableWindowManager.Entry entry) {
138:                if (entry.factory.name.equals(mostRecent))
139:                    mostRecent = null;
140:
141:                if (entry.btn != null) {
142:                    buttonPanel.remove(entry.btn);
143:                    buttons.remove(entry.btn);
144:                    entry.btn = null;
145:                }
146:
147:                dockables.remove(entry);
148:                if (entry.win != null)
149:                    dockablePanel.remove(entry.win);
150:
151:                if (current == entry) {
152:                    current = null;
153:                    show(null);
154:                } else {
155:                    wm.revalidate();
156:                    dockablePanel.repaint();
157:                    buttonPanel.repaint();
158:                }
159:            } //}}}
160:
161:            //{{{ remove() method
162:            public void remove(DockableWindowManager.Entry entry) {
163:                if (entry.factory.name.equals(mostRecent))
164:                    mostRecent = null;
165:
166:                if (entry.win != null) {
167:                    dockablePanel.remove(entry.win);
168:                    entry.win = null;
169:                }
170:
171:                if (current == entry) {
172:                    current = null;
173:                    show(null);
174:                } else {
175:                    wm.revalidate();
176:                    dockablePanel.repaint();
177:                }
178:            } //}}}
179:
180:            //{{{ showMostRecent() method
181:            public void showMostRecent() {
182:                if (dockables.isEmpty()) {
183:                    Toolkit.getDefaultToolkit().beep();
184:                    return;
185:                }
186:
187:                if (mostRecent == null) {
188:                    mostRecent = dockables.get(0).factory.name;
189:                }
190:
191:                wm.showDockableWindow(mostRecent);
192:            } //}}}
193:
194:            //{{{ show() method
195:            public void show(DockableWindowManager.Entry entry) {
196:                if (current == entry) {
197:                    if (entry != null) {
198:                        if (entry.win instanceof  DefaultFocusComponent) {
199:                            ((DefaultFocusComponent) entry.win)
200:                                    .focusOnDefaultComponent();
201:                        } else {
202:                            entry.win.requestDefaultFocus();
203:                        }
204:                    }
205:                    return;
206:                }
207:
208:                if (entry != null) {
209:                    if (current == null) {
210:                        // we didn't have a component previously, so
211:                        // create a border
212:                        dockablePanel.setBorder(new DockBorder(position));
213:                    }
214:
215:                    mostRecent = entry.factory.name;
216:                    this .current = entry;
217:
218:                    if (entry.win.getParent() != dockablePanel)
219:                        dockablePanel.add(entry.factory.name, entry.win);
220:
221:                    dockablePanel.showDockable(entry.factory.name);
222:
223:                    entry.btn.setSelected(true);
224:
225:                    if (entry.win instanceof  DefaultFocusComponent) {
226:                        ((DefaultFocusComponent) entry.win)
227:                                .focusOnDefaultComponent();
228:                    } else {
229:                        entry.win.requestDefaultFocus();
230:                    }
231:                } else {
232:                    current = null;
233:                    nullButton.setSelected(true);
234:                    // removing last component, so remove border
235:                    dockablePanel.setBorder(null);
236:
237:                    wm.getView().getTextArea().requestFocus();
238:                }
239:
240:                wm.revalidate();
241:                dockablePanel.repaint();
242:            } //}}}
243:
244:            //{{{ isVisible() method
245:            public boolean isVisible(DockableWindowManager.Entry entry) {
246:                return current == entry;
247:            } //}}}
248:
249:            //{{{ getCurrent() method
250:            /**
251:             * Returns the name of the dockable in this container.
252:             * @since jEdit 4.2pre1
253:             */
254:            public String getCurrent() {
255:                if (current == null)
256:                    return null;
257:                else
258:                    return current.factory.name;
259:            } //}}}
260:
261:            //{{{ getDimension() method
262:            /**
263:             * Returns the width or height (depending on position) of the dockable
264:             * window container.
265:             * @since jEdit 4.2pre1
266:             */
267:            public int getDimension() {
268:                return dimension;
269:            } //}}}
270:
271:            //{{{ getPosition() method
272:            /**
273:             * @since jEdit 4.3pre2
274:             */
275:            public String getPosition() {
276:                return position;
277:            } //}}}
278:
279:            //{{{ getDockables() method
280:            public String[] getDockables() {
281:                String[] retVal = new String[dockables.size()];
282:                for (int i = 0; i < dockables.size(); i++) {
283:                    DockableWindowManager.Entry entry = dockables.get(i);
284:                    retVal[i] = entry.factory.name;
285:                }
286:                return retVal;
287:            } //}}}
288:
289:            //{{{ Package-private members
290:            static final int SPLITTER_WIDTH = 10;
291:            DockablePanel dockablePanel;
292:            JPanel buttonPanel;
293:
294:            //{{{ save() method
295:            void save() {
296:                jEdit.setIntegerProperty(
297:                        "view.dock." + position + ".dimension", dimension);
298:                if (current == null)
299:                    jEdit.unsetProperty("view.dock." + position + ".last");
300:                else {
301:                    jEdit.setProperty("view.dock." + position + ".last",
302:                            current.factory.name);
303:                }
304:            } //}}}
305:
306:            //{{{ setDimension() method
307:            void setDimension(int dimension) {
308:                if (dimension > SPLITTER_WIDTH)
309:                    this .dimension = dimension - SPLITTER_WIDTH;
310:            } //}}}
311:
312:            //{{{ sortDockables() method
313:            void sortDockables() {
314:                buttonPanel.removeAll();
315:                buttonPanel.add(closeBox);
316:                buttonPanel.add(menuBtn);
317:                Collections.sort(buttons, new DockableWindowCompare());
318:                for (int i = 0; i < buttons.size(); i++) {
319:                    buttonPanel.add(buttons.get(i));
320:                }
321:            } //}}}
322:
323:            //{{{ getWrappedDimension() method
324:            /**
325:             * Returns the width or height of wrapped rows or columns.
326:             */
327:            int getWrappedDimension(int dimension) {
328:                return ((ButtonLayout) buttonPanel.getLayout())
329:                        .getWrappedDimension(buttonPanel, dimension);
330:            } //}}}
331:
332:            //}}}
333:
334:            //{{{ Private members
335:            private DockableWindowManager wm;
336:            private String position;
337:            private JButton closeBox;
338:            private JButton menuBtn;
339:            private ButtonGroup buttonGroup;
340:            private JToggleButton nullButton;
341:            private int dimension;
342:            private final List<DockableWindowManager.Entry> dockables;
343:            private final List<AbstractButton> buttons;
344:            private DockableWindowManager.Entry current;
345:            private JPopupMenu popup;
346:
347:            // remember the most recent dockable
348:            private String mostRecent;
349:
350:            //}}}
351:
352:            //{{{ Inner classes
353:
354:            //{{{ DockableWindowCompare class
355:            static class DockableWindowCompare implements 
356:                    Comparator<AbstractButton> {
357:                public int compare(AbstractButton o1, AbstractButton o2) {
358:                    String name1 = o1.getActionCommand();
359:                    String name2 = o2.getActionCommand();
360:                    return StandardUtilities.compareStrings(jEdit.getProperty(
361:                            name1 + ".title", ""), jEdit.getProperty(name2
362:                            + ".title", ""), true);
363:                }
364:            } //}}}
365:
366:            //{{{ ActionHandler class
367:            class ActionHandler implements  ActionListener {
368:                public void actionPerformed(ActionEvent evt) {
369:                    if (popup != null && popup.isVisible())
370:                        popup.setVisible(false);
371:
372:                    if (evt.getSource() == closeBox)
373:                        show(null);
374:                    else {
375:                        if (wm.isDockableWindowVisible(evt.getActionCommand()))
376:                            show(null);
377:                        else
378:                            wm.showDockableWindow(evt.getActionCommand());
379:                    }
380:                }
381:            } //}}}
382:
383:            //{{{ MenuMouseHandler class
384:            class MenuMouseHandler extends MouseAdapter {
385:                public void mousePressed(MouseEvent evt) {
386:                    if (popup != null && popup.isVisible()) {
387:                        popup.setVisible(false);
388:                        return;
389:                    }
390:
391:                    Component comp = (Component) evt.getSource();
392:                    String dockable;
393:                    if (comp instanceof  JToggleButton)
394:                        dockable = ((JToggleButton) comp).getActionCommand();
395:                    else
396:                        dockable = getCurrent();
397:
398:                    if (comp == menuBtn || GUIUtilities.isPopupTrigger(evt)) {
399:                        if (dockable == null) {
400:                            popup = wm.createPopupMenu(
401:                                    PanelWindowContainer.this , null, false);
402:                        } else {
403:                            popup = wm.createPopupMenu(
404:                                    PanelWindowContainer.this , dockable, false);
405:                        }
406:
407:                        int x, y;
408:                        boolean point;
409:                        if (comp == menuBtn) {
410:                            x = 0;
411:                            y = menuBtn.getHeight();
412:                            point = false;
413:                        } else {
414:                            x = evt.getX();
415:                            y = evt.getY();
416:                            point = true;
417:                        }
418:                        GUIUtilities.showPopupMenu(popup, comp, x, y, point);
419:                    }
420:                }
421:            } //}}}
422:
423:            //{{{ DockBorder class
424:            static class DockBorder implements  Border {
425:                String position;
426:                Insets insets;
427:                Color color1;
428:                Color color2;
429:                Color color3;
430:
431:                //{{{ DockBorder constructor
432:                DockBorder(String position) {
433:                    this .position = position;
434:                    insets = new Insets(
435:                            position.equals(DockableWindowManager.BOTTOM) ? SPLITTER_WIDTH
436:                                    : 0,
437:                            position.equals(DockableWindowManager.RIGHT) ? SPLITTER_WIDTH
438:                                    : 0,
439:                            position.equals(DockableWindowManager.TOP) ? SPLITTER_WIDTH
440:                                    : 0,
441:                            position.equals(DockableWindowManager.LEFT) ? SPLITTER_WIDTH
442:                                    : 0);
443:                } //}}}
444:
445:                //{{{ paintBorder() method
446:                public void paintBorder(Component c, Graphics g, int x, int y,
447:                        int width, int height) {
448:                    updateColors();
449:
450:                    if (color1 == null || color2 == null || color3 == null)
451:                        return;
452:
453:                    if (position.equals(DockableWindowManager.BOTTOM))
454:                        paintHorizBorder(g, x, y, width);
455:                    else if (position.equals(DockableWindowManager.RIGHT))
456:                        paintVertBorder(g, x, y, height);
457:                    else if (position.equals(DockableWindowManager.TOP)) {
458:                        paintHorizBorder(g, x, y + height - SPLITTER_WIDTH,
459:                                width);
460:                    } else if (position.equals(DockableWindowManager.LEFT)) {
461:                        paintVertBorder(g, x + width - SPLITTER_WIDTH, y,
462:                                height);
463:                    }
464:                } //}}}
465:
466:                //{{{ getBorderInsets() method
467:                public Insets getBorderInsets(Component c) {
468:                    return insets;
469:                } //}}}
470:
471:                //{{{ isBorderOpaque() method
472:                public boolean isBorderOpaque() {
473:                    return false;
474:                } //}}}
475:
476:                //{{{ paintHorizBorder() method
477:                private void paintHorizBorder(Graphics g, int x, int y,
478:                        int width) {
479:                    g.setColor(color3);
480:                    g.fillRect(x, y, width, SPLITTER_WIDTH);
481:
482:                    for (int i = 0; i < width / 4 - 1; i++) {
483:                        g.setColor(color1);
484:                        g.drawLine(x + (i << 2) + 2, y + 3, x + (i << 2) + 2,
485:                                y + 3);
486:                        g.setColor(color2);
487:                        g.drawLine(x + (i << 2) + 3, y + 4, x + (i << 2) + 3,
488:                                y + 4);
489:                        g.setColor(color1);
490:                        g.drawLine(x + (i << 2) + 4, y + 5, x + (i << 2) + 4,
491:                                y + 5);
492:                        g.setColor(color2);
493:                        g.drawLine(x + (i << 2) + 5, y + 6, x + (i << 2) + 5,
494:                                y + 6);
495:                    }
496:                } //}}}
497:
498:                //{{{ paintVertBorder() method
499:                private void paintVertBorder(Graphics g, int x, int y,
500:                        int height) {
501:                    g.setColor(color3);
502:                    g.fillRect(x, y, SPLITTER_WIDTH, height);
503:
504:                    for (int i = 0; i < height / 4 - 1; i++) {
505:                        g.setColor(color1);
506:                        g.drawLine(x + 3, y + (i << 2) + 2, x + 3, y + (i << 2)
507:                                + 2);
508:                        g.setColor(color2);
509:                        g.drawLine(x + 4, y + (i << 2) + 3, x + 4, y + (i << 2)
510:                                + 3);
511:                        g.setColor(color1);
512:                        g.drawLine(x + 5, y + (i << 2) + 4, x + 5, y + (i << 2)
513:                                + 4);
514:                        g.setColor(color2);
515:                        g.drawLine(x + 6, y + (i << 2) + 5, x + 6, y + (i << 2)
516:                                + 5);
517:                    }
518:                } //}}}
519:
520:                //{{{ updateColors() method
521:                private void updateColors() {
522:                    if (UIManager.getLookAndFeel() instanceof  MetalLookAndFeel) {
523:                        color1 = MetalLookAndFeel.getControlHighlight();
524:                        color2 = MetalLookAndFeel.getControlDarkShadow();
525:                        color3 = MetalLookAndFeel.getControl();
526:                    } else {
527:                        color1 = color2 = color3 = null;
528:                    }
529:                } //}}}
530:            } //}}}
531:
532:            //{{{ RotatedTextIcon class
533:            public static class RotatedTextIcon implements  Icon {
534:                public static final int NONE = 0;
535:                public static final int CW = 1;
536:                public static final int CCW = 2;
537:
538:                //{{{ RotatedTextIcon constructor
539:                public RotatedTextIcon(int rotate, Font font, String text) {
540:                    this .rotate = rotate;
541:                    this .font = font;
542:
543:                    FontRenderContext fontRenderContext = new FontRenderContext(
544:                            null, true, true);
545:                    this .text = text;
546:                    glyphs = font.createGlyphVector(fontRenderContext, text);
547:                    width = (int) glyphs.getLogicalBounds().getWidth() + 4;
548:                    //height = (int)glyphs.getLogicalBounds().getHeight();
549:
550:                    LineMetrics lineMetrics = font.getLineMetrics(text,
551:                            fontRenderContext);
552:                    ascent = lineMetrics.getAscent();
553:                    height = (int) lineMetrics.getHeight();
554:
555:                    renderHints = new RenderingHints(
556:                            RenderingHints.KEY_ANTIALIASING,
557:                            RenderingHints.VALUE_ANTIALIAS_ON);
558:                    renderHints.put(RenderingHints.KEY_FRACTIONALMETRICS,
559:                            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
560:                    renderHints.put(RenderingHints.KEY_RENDERING,
561:                            RenderingHints.VALUE_RENDER_QUALITY);
562:                } //}}}
563:
564:                //{{{ getIconWidth() method
565:                public int getIconWidth() {
566:                    return (int) (rotate == RotatedTextIcon.CW
567:                            || rotate == RotatedTextIcon.CCW ? height : width);
568:                } //}}}
569:
570:                //{{{ getIconHeight() method
571:                public int getIconHeight() {
572:                    return (int) (rotate == RotatedTextIcon.CW
573:                            || rotate == RotatedTextIcon.CCW ? width : height);
574:                } //}}}
575:
576:                //{{{ paintIcon() method
577:                public void paintIcon(Component c, Graphics g, int x, int y) {
578:                    Graphics2D g2d = (Graphics2D) g;
579:                    g2d.setFont(font);
580:                    AffineTransform oldTransform = g2d.getTransform();
581:                    RenderingHints oldHints = g2d.getRenderingHints();
582:
583:                    g2d.setRenderingHints(renderHints);
584:                    g2d.setColor(c.getForeground());
585:
586:                    //{{{ No rotation
587:                    if (rotate == RotatedTextIcon.NONE) {
588:                        g2d.drawGlyphVector(glyphs, x + 2, y + ascent);
589:                    } //}}}
590:                    //{{{ Clockwise rotation
591:                    else if (rotate == RotatedTextIcon.CW) {
592:                        AffineTransform trans = new AffineTransform();
593:                        trans.concatenate(oldTransform);
594:                        trans.translate(x, y + 2);
595:                        trans.rotate(Math.PI / 2, height / 2, width / 2);
596:                        g2d.setTransform(trans);
597:                        g2d.drawGlyphVector(glyphs, (height - width) / 2,
598:                                (width - height) / 2 + ascent);
599:                    } //}}}
600:                    //{{{ Counterclockwise rotation
601:                    else if (rotate == RotatedTextIcon.CCW) {
602:                        AffineTransform trans = new AffineTransform();
603:                        trans.concatenate(oldTransform);
604:                        trans.translate(x, y - 2);
605:                        trans.rotate(Math.PI * 3 / 2, height / 2, width / 2);
606:                        g2d.setTransform(trans);
607:                        g2d.drawGlyphVector(glyphs, (height - width) / 2,
608:                                (width - height) / 2 + ascent);
609:                    } //}}}
610:
611:                    g2d.setTransform(oldTransform);
612:                    g2d.setRenderingHints(oldHints);
613:                } //}}}
614:
615:                //{{{ Private members
616:                private int rotate;
617:                private Font font;
618:                private String text;
619:                private GlyphVector glyphs;
620:                private float width;
621:                private float height;
622:                private float ascent;
623:                private RenderingHints renderHints;
624:                //}}}
625:            } //}}}
626:
627:            //{{{ ButtonLayout class
628:            class ButtonLayout implements  LayoutManager {
629:                //{{{ addLayoutComponent() method
630:                public void addLayoutComponent(String name, Component comp) {
631:                } //}}}
632:
633:                //{{{ removeLayoutComponent() method
634:                public void removeLayoutComponent(Component comp) {
635:                } //}}}
636:
637:                //{{{ getWrappedDimension() method
638:                /**
639:                 * Returns the width or height of wrapped rows or columns.
640:                 */
641:                int getWrappedDimension(JComponent parent, int dimension) {
642:                    Insets insets = parent.getBorder().getBorderInsets(parent);
643:
644:                    Component[] comp = parent.getComponents();
645:                    if (comp.length <= 2)
646:                        return 0;
647:
648:                    Dimension dim = comp[2].getPreferredSize();
649:
650:                    if (position.equals(DockableWindowManager.TOP)
651:                            || position.equals(DockableWindowManager.BOTTOM)) {
652:                        int width = dimension - insets.right;
653:                        Dimension returnValue = preferredLayoutSizeLR(insets,
654:                                comp, dim, width);
655:                        return returnValue.height;
656:                    } else {
657:                        Dimension returnValue = preferredLayoutSizeTB(
658:                                dimension, insets, comp, dim);
659:                        return returnValue.width;
660:                    }
661:                } //}}}
662:
663:                //{{{ preferredLayoutSize() method
664:                public Dimension preferredLayoutSize(Container parent) {
665:                    Insets insets = ((JComponent) parent).getBorder()
666:                            .getBorderInsets(parent);
667:
668:                    Component[] comp = parent.getComponents();
669:                    if (comp.length <= 2) {
670:                        // nothing 'cept close box
671:                        return new Dimension(0, 0);
672:                    }
673:
674:                    Dimension dim = comp[2].getPreferredSize();
675:
676:                    if (position.equals(DockableWindowManager.TOP)
677:                            || position.equals(DockableWindowManager.BOTTOM)) {
678:                        int width = parent.getWidth() - insets.right;
679:                        Dimension returnValue = preferredLayoutSizeLR(insets,
680:                                comp, dim, width);
681:                        return returnValue;
682:                    } else {
683:                        Dimension returnValue = preferredLayoutSizeTB(parent
684:                                .getHeight(), insets, comp, dim);
685:                        return returnValue;
686:                    }
687:                } //}}}
688:
689:                //{{{ minimumLayoutSize() method
690:                public Dimension minimumLayoutSize(Container parent) {
691:                    return preferredLayoutSize(parent);
692:                } //}}}
693:
694:                //{{{ layoutContainer() method
695:                public void layoutContainer(Container parent) {
696:                    Insets insets = ((JComponent) parent).getBorder()
697:                            .getBorderInsets(parent);
698:
699:                    Component[] comp = parent.getComponents();
700:                    if (comp.length <= 2) {
701:                        for (int i = 0; i < comp.length; i++) {
702:                            comp[i].setVisible(false);
703:                        }
704:                        return;
705:                    }
706:
707:                    comp[0].setVisible(true);
708:                    comp[1].setVisible(true);
709:
710:                    Dimension dim = comp[2].getPreferredSize();
711:
712:                    if (position.equals(DockableWindowManager.TOP)
713:                            || position.equals(DockableWindowManager.BOTTOM)) {
714:                        int width = parent.getWidth() - insets.right;
715:                        int rowHeight = Math.max(dim.height, closeBox
716:                                .getPreferredSize().width);
717:                        int x = (rowHeight << 1) + insets.left;
718:                        int y = insets.top;
719:                        closeBox.setBounds(insets.left, insets.top, rowHeight,
720:                                rowHeight);
721:                        menuBtn.setBounds(insets.left + rowHeight, insets.top,
722:                                rowHeight, rowHeight);
723:
724:                        for (int i = 2; i < comp.length; i++) {
725:                            int btnWidth = comp[i].getPreferredSize().width;
726:                            if (btnWidth + x > width) {
727:                                x = insets.left;
728:                                y += rowHeight;
729:                            }
730:                            comp[i].setBounds(x, y, btnWidth, rowHeight);
731:                            x += btnWidth;
732:                        }
733:
734:                        /* if(y + rowHeight != parent.getHeight())
735:                        {
736:                        	parent.setSize(
737:                        		parent.getWidth(),
738:                        		y + rowHeight);
739:                        	((JComponent)parent).revalidate();
740:                        } */
741:                    } else {
742:                        int height = parent.getHeight() - insets.bottom;
743:                        int colWidth = Math.max(dim.width, closeBox
744:                                .getPreferredSize().height);
745:                        int x = insets.left;
746:                        int y = (colWidth << 1) + insets.top;
747:                        closeBox.setBounds(insets.left, insets.top, colWidth,
748:                                colWidth);
749:                        menuBtn.setBounds(insets.left, insets.top + colWidth,
750:                                colWidth, colWidth);
751:
752:                        for (int i = 2; i < comp.length; i++) {
753:                            int btnHeight = comp[i].getPreferredSize().height;
754:                            if (btnHeight + y > height) {
755:                                x += colWidth;
756:                                y = insets.top;
757:                            }
758:                            comp[i].setBounds(x, y, colWidth, btnHeight);
759:                            y += btnHeight;
760:                        }
761:
762:                        /* if(x + colWidth != parent.getWidth())
763:                        {
764:                        	parent.setSize(x + colWidth,
765:                        		parent.getHeight());
766:                        	((JComponent)parent).revalidate();
767:                        } */
768:                    }
769:                } //}}}
770:
771:                //{{{ preferredLayoutSizeLR() method
772:                private Dimension preferredLayoutSizeLR(Insets insets,
773:                        Component[] comp, Dimension dim, int width) {
774:                    int rowHeight = Math.max(dim.height, closeBox
775:                            .getPreferredSize().width);
776:                    int x = (rowHeight << 1) + insets.left;
777:                    Dimension returnValue = new Dimension(0, rowHeight
778:                            + insets.top + insets.bottom);
779:
780:                    for (int i = 2; i < comp.length; i++) {
781:                        int btnWidth = comp[i].getPreferredSize().width;
782:                        if (btnWidth + x > width) {
783:                            returnValue.height += rowHeight;
784:                            x = insets.left;
785:                        }
786:
787:                        x += btnWidth;
788:                    }
789:                    return returnValue;
790:                } //}}}
791:
792:                //{{{ preferredLayoutSizeTB() method
793:                private Dimension preferredLayoutSizeTB(int dimension,
794:                        Insets insets, Component[] comp, Dimension dim) {
795:                    int height = dimension - insets.bottom;
796:                    int colWidth = Math.max(dim.width, closeBox
797:                            .getPreferredSize().height);
798:                    int y = (colWidth << 1) + insets.top;
799:                    Dimension returnValue = new Dimension(colWidth
800:                            + insets.left + insets.right, 0);
801:
802:                    for (int i = 2; i < comp.length; i++) {
803:                        int btnHeight = comp[i].getPreferredSize().height;
804:                        if (btnHeight + y > height) {
805:                            returnValue.width += colWidth;
806:                            y = insets.top;
807:                        }
808:
809:                        y += btnHeight;
810:                    }
811:                    return returnValue;
812:                } //}}}
813:            } //}}}
814:
815:            //}}}
816:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.