Source Code Cross Referenced for DrawingFrame.java in  » Testing » jacareto » jacareto » cleverphl » 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 » Testing » jacareto » jacareto.cleverphl.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Jacareto Copyright (c) 2002-2005
003:         * Applied Computer Science Research Group, Darmstadt University of
004:         * Technology, Institute of Mathematics & Computer Science,
005:         * Ludwigsburg University of Education, and Computer Based
006:         * Learning Research Group, Aachen University. All rights reserved.
007:         *
008:         * Jacareto is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public
010:         * License as published by the Free Software Foundation; either
011:         * version 2 of the License, or (at your option) any later version.
012:         *
013:         * Jacareto 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 GNU
016:         * General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public
019:         * License along with Jacareto; if not, write to the Free
020:         * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021:         *
022:         */
023:
024:        package jacareto.cleverphl.gui;
025:
026:        import jacareto.catching.EventListener;
027:        import jacareto.catching.WindowActivationCatcher;
028:        import jacareto.catching.WindowActivationCatcherObserver;
029:        import jacareto.cleverphl.CleverPHL;
030:        import jacareto.cleverphl.session.Session;
031:        import jacareto.comp.Components;
032:        import jacareto.comp.glasspanes.DrawingPane;
033:        import jacareto.comp.glasspanes.GlassPaneCompound;
034:        import jacareto.comp.glasspanes.GlassPaneManager;
035:        import jacareto.comp.manipulation.ManipulationManagement;
036:        import jacareto.record.DrawingRecordable;
037:        import jacareto.system.Environment;
038:        import jacareto.system.Language;
039:
040:        import org.jhotdraw.contrib.DiamondFigure;
041:        import org.jhotdraw.contrib.TextAreaFigure;
042:        import org.jhotdraw.contrib.TextAreaTool;
043:        import org.jhotdraw.contrib.TriangleFigure;
044:        import org.jhotdraw.figures.ArrowTip;
045:        import org.jhotdraw.figures.BorderTool;
046:        import org.jhotdraw.figures.EllipseFigure;
047:        import org.jhotdraw.figures.LineFigure;
048:        import org.jhotdraw.figures.RectangleFigure;
049:        import org.jhotdraw.figures.RoundRectangleFigure;
050:        import org.jhotdraw.figures.TextFigure;
051:        import org.jhotdraw.figures.TextTool;
052:        import org.jhotdraw.framework.Figure;
053:        import org.jhotdraw.framework.FigureAttributeConstant;
054:        import org.jhotdraw.framework.FigureEnumeration;
055:        import org.jhotdraw.framework.Tool;
056:        import org.jhotdraw.standard.CreationTool;
057:        import org.jhotdraw.standard.SelectionTool;
058:        import org.jhotdraw.standard.ToolButton;
059:        import org.jhotdraw.util.ColorMap;
060:        import org.jhotdraw.util.PaletteButton;
061:        import org.jhotdraw.util.PaletteListener;
062:
063:        import java.awt.BorderLayout;
064:        import java.awt.Color;
065:        import java.awt.FlowLayout;
066:        import java.awt.Graphics;
067:        import java.awt.GridBagConstraints;
068:        import java.awt.GridBagLayout;
069:        import java.awt.Insets;
070:        import java.awt.Window;
071:        import java.awt.event.ActionEvent;
072:        import java.awt.event.ActionListener;
073:        import java.awt.event.WindowEvent;
074:        import java.awt.event.WindowListener;
075:
076:        import java.util.Iterator;
077:        import java.util.Vector;
078:
079:        import javax.swing.JButton;
080:        import javax.swing.JColorChooser;
081:        import javax.swing.JComboBox;
082:        import javax.swing.JComponent;
083:        import javax.swing.JDialog;
084:        import javax.swing.JFrame;
085:        import javax.swing.JLabel;
086:        import javax.swing.JPanel;
087:        import javax.swing.JTextField;
088:        import javax.swing.JToolBar;
089:        import javax.swing.SwingConstants;
090:        import javax.swing.SwingUtilities;
091:        import javax.swing.border.EmptyBorder;
092:
093:        /**
094:         * The drawing frame of CleverPHL.
095:         *
096:         * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
097:         * @version 1.01
098:         */
099:        public class DrawingFrame extends CleverPHLFrame implements 
100:                WindowListener, PaletteListener,
101:                WindowActivationCatcherObserver {
102:            /** The environment. */
103:            private Environment env;
104:
105:            /** The drawing pane. */
106:            private DrawingPane pane;
107:
108:            /** The actual window. */
109:            private Window actualWindow;
110:
111:            /** The language. */
112:            private Language language;
113:
114:            /** Shows the actual colors. */
115:            private ColorShow lineColorShow;
116:
117:            /** Shows the actual colors. */
118:            private ColorShow fillColorShow;
119:
120:            /** The name of the actual window. */
121:            private String actualWindowName;
122:
123:            /** The component which shows the window's name. */
124:            private JTextField windowNameField;
125:
126:            /** The prototype figures in the palette. */
127:            private Vector figures;
128:
129:            /** The tools for the actual pane. */
130:            private Vector tools;
131:
132:            /** The palette. */
133:            private JToolBar palette;
134:
135:            /** The button for the default tool. */
136:            private ToolButton defaultToolButton;
137:
138:            /** The attribute panel. */
139:            private JComponent attributePanel;
140:            private String IMAGES = "/org/jhotdraw/images/";
141:
142:            /** The event listener used for window activations. */
143:            private EventListener eventListener;
144:
145:            /**
146:             * Creates a new drawing frame.
147:             *
148:             * @param cleverPHL the CleverPHL instance
149:             */
150:            public DrawingFrame(CleverPHL cleverPHL) {
151:                super (cleverPHL, "CleverPHL.DrawingFrame", null);
152:
153:                this .env = cleverPHL.getEnvironment();
154:
155:                language = env.getLanguage();
156:
157:                fillColorShow = new ColorShow();
158:                lineColorShow = new ColorShow();
159:
160:                createFigures();
161:
162:                createAttributePanel();
163:
164:                setTitle(language.getString("CleverPHL.DrawingFrame.Title"));
165:                addWindowListener(this );
166:
167:                //setSize (400, 300);
168:                //setLocation (50, 300);
169:                palette = new JToolBar(SwingConstants.VERTICAL);
170:                getContentPane().setLayout(new BorderLayout());
171:                getContentPane().add(palette, BorderLayout.WEST);
172:                getContentPane().add(attributePanel, BorderLayout.CENTER);
173:
174:                setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
175:            }
176:
177:            /**
178:             * Sets the drawing pane which should be linked with the drawing frame.
179:             *
180:             * @param pane the new drawing pane
181:             */
182:            public void setDrawingPane(DrawingPane pane) {
183:                int oldToolNumber = -1;
184:
185:                if (this .pane != null) {
186:                    oldToolNumber = tools.indexOf(this .pane.tool());
187:                }
188:
189:                this .pane = pane;
190:                actualWindow = SwingUtilities.getWindowAncestor(pane);
191:
192:                Components components = getCleverPHL().getSessionList()
193:                        .getActual().getComponents();
194:                actualWindowName = components.getName(actualWindow);
195:                windowNameField.setText(actualWindowName);
196:                windowNameField.setCaretPosition(0);
197:                createTools();
198:
199:                if (oldToolNumber > -1) {
200:                    pane.setTool((Tool) tools.get(oldToolNumber));
201:                }
202:            }
203:
204:            /**
205:             * Creates the toolbar.
206:             */
207:            private void createTools() {
208:                Tool tool;
209:                Figure figure;
210:
211:                tools = new Vector(5, 5);
212:
213:                palette.removeAll();
214:
215:                tool = new SelectionTool(pane);
216:                defaultToolButton = createToolButton(IMAGES + "SEL",
217:                        "Selection Tool", tool);
218:                palette.add(defaultToolButton);
219:                tools.add(tool);
220:
221:                figure = (Figure) figures.get(0);
222:                tool = new TextTool(pane, figure);
223:                palette
224:                        .add(createToolButton(IMAGES + "TEXT", "Text Tool",
225:                                tool));
226:                tools.add(tool);
227:
228:                figure = (Figure) figures.get(1);
229:                tool = new TextAreaTool(pane, figure);
230:                palette.add(createToolButton(IMAGES + "TEXTAREA",
231:                        "TextArea Tool", tool));
232:                tools.add(tool);
233:
234:                figure = (Figure) figures.get(2);
235:                tool = new CreationTool(pane, figure);
236:                palette.add(createToolButton(IMAGES + "RECT", "Rectangle Tool",
237:                        tool));
238:                tools.add(tool);
239:
240:                figure = (Figure) figures.get(3);
241:                tool = new CreationTool(pane, figure);
242:                palette.add(createToolButton(IMAGES + "RRECT",
243:                        "Round Rectangle Tool", tool));
244:                tools.add(tool);
245:
246:                figure = (Figure) figures.get(4);
247:                tool = new CreationTool(pane, figure);
248:                palette.add(createToolButton(IMAGES + "ELLIPSE",
249:                        "Ellipse Tool", tool));
250:                tools.add(tool);
251:
252:                /*tool =  new PolygonTool(pane);
253:                palette.add(createToolButton(IMAGES + "POLYGON", "Polygon Tool", tool));
254:                figures.add (figure);
255:                 */
256:                figure = (Figure) figures.get(5);
257:                tool = new CreationTool(pane, figure);
258:                palette.add(createToolButton(IMAGES + "TRIANGLE",
259:                        "Triangle Tool", tool));
260:                tools.add(tool);
261:
262:                figure = (Figure) figures.get(6);
263:                tool = new CreationTool(pane, figure);
264:                palette.add(createToolButton(IMAGES + "DIAMOND",
265:                        "Diamond Tool", tool));
266:                tools.add(tool);
267:
268:                figure = (Figure) figures.get(7);
269:                tool = new CreationTool(pane, figure);
270:                palette
271:                        .add(createToolButton(IMAGES + "LINE", "Line Tool",
272:                                tool));
273:                tools.add(tool);
274:
275:                tool = new BorderTool(pane);
276:                palette.add(createToolButton(IMAGES + "BORDDEC", "Border Tool",
277:                        tool));
278:                tools.add(tool);
279:
280:                validate();
281:                repaint();
282:            }
283:
284:            /**
285:             * Creates the figures.
286:             */
287:            private void createFigures() {
288:                figures = new Vector(5, 5);
289:                figures.add(new TextFigure());
290:                figures.add(new TextAreaFigure());
291:                figures.add(new RectangleFigure());
292:                figures.add(new RoundRectangleFigure());
293:                figures.add(new EllipseFigure());
294:                figures.add(new TriangleFigure());
295:                figures.add(new DiamondFigure());
296:                figures.add(new LineFigure());
297:                setLineColor(ColorMap.color(3));
298:                setFillColor(new Color(0, 0, 0, 0));
299:            }
300:
301:            /**
302:             * Sets an attribute of all prototype figures.
303:             *
304:             * @param attribute the attribute id
305:             * @param value the new value
306:             */
307:            private void setFigureAttribute(FigureAttributeConstant attribute,
308:                    Object value) {
309:                Iterator it = figures.iterator();
310:
311:                while (it.hasNext()) {
312:                    Figure figure = (Figure) it.next();
313:
314:                    if (figure != null) {
315:                        figure.setAttribute(attribute, value);
316:                    }
317:                }
318:            }
319:
320:            /**
321:             * Sets the fill color.
322:             *
323:             * @param color the new fill color.
324:             */
325:            private void setFillColor(Color color) {
326:                setFigureAttribute(FigureAttributeConstant.FILL_COLOR, color);
327:                fillColorShow.setColor(color);
328:            }
329:
330:            /**
331:             * Sets the line color.
332:             *
333:             * @param color the new line color.
334:             */
335:            private void setLineColor(Color color) {
336:                setFigureAttribute(FigureAttributeConstant.FRAME_COLOR, color);
337:                setFigureAttribute(FigureAttributeConstant.TEXT_COLOR, color);
338:                lineColorShow.setColor(color);
339:            }
340:
341:            /**
342:             * Creates a tool button.
343:             *
344:             * @param imageName the name of the image
345:             * @param name the tool's name
346:             * @param tool the tool
347:             *
348:             * @return DOCUMENT ME!
349:             */
350:            private ToolButton createToolButton(String imageName, String name,
351:                    Tool tool) {
352:                return new ToolButton(this , imageName, name, tool);
353:            }
354:
355:            /**
356:             * Creates the attribute panel.
357:             */
358:            private void createAttributePanel() {
359:                attributePanel = new JPanel();
360:                attributePanel.setLayout(new GridBagLayout());
361:                attributePanel.setBorder(new EmptyBorder(5, 5, 5, 5));
362:
363:                GridBagConstraints c = new GridBagConstraints();
364:
365:                c.gridx = 0;
366:                c.gridy = 0;
367:                c.weightx = 10;
368:                c.weighty = 20;
369:                c.gridwidth = 1;
370:                c.gridheight = 1;
371:                c.fill = GridBagConstraints.HORIZONTAL;
372:                c.anchor = GridBagConstraints.WEST;
373:                c.insets = new Insets(5, 5, 5, 5);
374:
375:                //attributePanel.add (windowNameLabel, c);
376:                c.fill = GridBagConstraints.BOTH;
377:                c.gridx = 1;
378:                c.gridwidth = 3;
379:                c.weightx = 90;
380:                windowNameField = new JTextField(25);
381:                windowNameField.setEditable(false);
382:
383:                c.gridx = 0;
384:                c.gridwidth = 1;
385:                c.weightx = 10;
386:                c.weighty = 20;
387:                c.gridy = 1;
388:                attributePanel.add(new JLabel(language
389:                        .getString("CleverPHL.DrawingFrame.LineColor")
390:                        + ":"), c);
391:                c.gridx = 1;
392:                c.weightx = 30;
393:                c.fill = GridBagConstraints.BOTH;
394:                attributePanel.add(lineColorShow, c);
395:                c.gridx = 2;
396:                c.weightx = 30;
397:                c.fill = GridBagConstraints.NONE;
398:
399:                JButton lineColorButton = new JButton(language
400:                        .getString("CleverPHL.DrawingFrame.SelectColor")
401:                        + "...");
402:                lineColorButton.addActionListener(new ActionListener() {
403:                    public void actionPerformed(ActionEvent event) {
404:                        Color newColor = JColorChooser
405:                                .showDialog(
406:                                        pane,
407:                                        language
408:                                                .getString("CleverPHL.DrawingFrame.ChooseLineColor"),
409:                                        lineColorShow.getColor());
410:
411:                        if (newColor != null) {
412:                            setLineColor(newColor);
413:                        }
414:                    }
415:                });
416:                attributePanel.add(lineColorButton, c);
417:                c.gridx = 3;
418:                c.weightx = 30;
419:                c.fill = GridBagConstraints.NONE;
420:
421:                JButton lineTransparencyButton = new JButton(language
422:                        .getString("CleverPHL.DrawingFrame.SetTransparent"));
423:                lineTransparencyButton.addActionListener(new ActionListener() {
424:                    public void actionPerformed(ActionEvent event) {
425:                        setLineColor(new Color(0, 0, 0, 0));
426:                    }
427:                });
428:                attributePanel.add(lineTransparencyButton, c);
429:
430:                c.gridx = 0;
431:                c.gridwidth = 1;
432:                c.weightx = 10;
433:                c.gridy = 2;
434:                attributePanel.add(new JLabel(language
435:                        .getString("CleverPHL.DrawingFrame.FillColor")
436:                        + ":"), c);
437:                c.gridx = 1;
438:                c.weightx = 30;
439:                c.fill = GridBagConstraints.BOTH;
440:                attributePanel.add(fillColorShow, c);
441:                c.gridx = 2;
442:                c.weightx = 30;
443:                c.fill = GridBagConstraints.NONE;
444:
445:                JButton fillColorButton = new JButton(language
446:                        .getString("CleverPHL.DrawingFrame.SelectColor")
447:                        + "...");
448:                fillColorButton.addActionListener(new ActionListener() {
449:                    public void actionPerformed(ActionEvent event) {
450:                        Color newColor = JColorChooser
451:                                .showDialog(
452:                                        pane,
453:                                        language
454:                                                .getString("CleverPHL.DrawingFrame.ChooseFillColor"),
455:                                        fillColorShow.getColor());
456:
457:                        if (newColor != null) {
458:                            setFillColor(newColor);
459:                        }
460:                    }
461:                });
462:                attributePanel.add(fillColorButton, c);
463:                c.gridx = 3;
464:                c.weightx = 30;
465:                c.fill = GridBagConstraints.NONE;
466:
467:                JButton fillTransparencyButton = new JButton(language
468:                        .getString("CleverPHL.DrawingFrame.SetTransparent"));
469:                fillTransparencyButton.addActionListener(new ActionListener() {
470:                    public void actionPerformed(ActionEvent event) {
471:                        setFillColor(new Color(0, 0, 0, 0));
472:                    }
473:                });
474:                attributePanel.add(fillTransparencyButton, c);
475:
476:                c.gridx = 0;
477:                c.weightx = 10;
478:                c.gridy = 3;
479:                c.fill = GridBagConstraints.HORIZONTAL;
480:                attributePanel.add(new JLabel(language
481:                        .getString("CleverPHL.DrawingFrame.ArrowTip")
482:                        + ":"), c);
483:                c.gridx = 1;
484:                c.weightx = 90;
485:                c.gridwidth = 3;
486:
487:                JComboBox arrowTipBox = new JComboBox();
488:                arrowTipBox.addItem(language
489:                        .getString("CleverPHL.DrawingFrame.ArrowTips.None"));
490:                arrowTipBox.addItem(language
491:                        .getString("CleverPHL.DrawingFrame.ArrowTips.End"));
492:                arrowTipBox.addItem(language
493:                        .getString("CleverPHL.DrawingFrame.ArrowTips.Start"));
494:                arrowTipBox.addItem(language
495:                        .getString("CleverPHL.DrawingFrame.ArrowTips.Both"));
496:                arrowTipBox.addActionListener(new ActionListener() {
497:                    public void actionPerformed(ActionEvent event) {
498:                        LineFigure figure = (LineFigure) figures.get(7);
499:
500:                        switch (((JComboBox) event.getSource())
501:                                .getSelectedIndex()) {
502:                        case 0:
503:                            figure.setStartDecoration(null);
504:                            figure.setEndDecoration(null);
505:
506:                            break;
507:
508:                        case 1:
509:                            figure.setStartDecoration(null);
510:                            figure.setEndDecoration(new ArrowTip());
511:
512:                            break;
513:
514:                        case 2:
515:                            figure.setStartDecoration(new ArrowTip());
516:                            figure.setEndDecoration(null);
517:
518:                            break;
519:
520:                        case 3:
521:                            figure.setStartDecoration(new ArrowTip());
522:                            figure.setEndDecoration(new ArrowTip());
523:
524:                            break;
525:                        }
526:                    }
527:                });
528:                attributePanel.add(arrowTipBox, c);
529:
530:                c.fill = GridBagConstraints.NONE;
531:                c.anchor = GridBagConstraints.CENTER;
532:                c.gridx = 0;
533:                c.gridy = 4;
534:                c.gridwidth = 4;
535:
536:                JButton recordButton = new JButton(language
537:                        .getString("CleverPHL.DrawingFrame.RecordButtonText"));
538:                recordButton.addActionListener(new ActionListener() {
539:                    public void actionPerformed(ActionEvent event) {
540:                        record();
541:                    }
542:                });
543:
544:                JPanel buttonPanel = new JPanel(new FlowLayout());
545:                buttonPanel.add(recordButton);
546:                attributePanel.add(buttonPanel, c);
547:            }
548:
549:            /**
550:             * Records the current figure set of all windows.
551:             */
552:            private void record() {
553:                Session session = cleverPHL.getSessionList().getActual();
554:                Components components = session.getComponents();
555:                GlassPaneManager gpManager = components.getGlassPaneManager();
556:
557:                GlassPaneCompound[] compounds = gpManager
558:                        .getGlassPaneCompounds();
559:
560:                for (int i = 0; i < compounds.length; i++) {
561:                    DrawingPane drawingPane = (DrawingPane) compounds[i]
562:                            .getGlassPane(GlassPaneCompound.DRAWING_PANE);
563:                    Window window = compounds[i].getWindow();
564:
565:                    if ((drawingPane != null) && (window != null)) {
566:                        FigureEnumeration enumeration = drawingPane.drawing()
567:                                .figures();
568:                        String windowName = components.getName(window);
569:
570:                        if ((windowName != null) && !windowName.equals("")) {
571:                            session.insertRecordable(new DrawingRecordable(env,
572:                                    windowName, enumeration));
573:                        }
574:                    }
575:                }
576:            }
577:
578:            /**
579:             * Does nothing.
580:             *
581:             * @param w DOCUMENT ME!
582:             */
583:            public void windowActivated(WindowEvent w) {
584:            }
585:
586:            /**
587:             * Does nothing.
588:             *
589:             * @param w DOCUMENT ME!
590:             */
591:            public void windowClosed(WindowEvent w) {
592:            }
593:
594:            /**
595:             * Does nothing.
596:             *
597:             * @param w DOCUMENT ME!
598:             */
599:            public void windowDeactivated(WindowEvent w) {
600:            }
601:
602:            /**
603:             * Does nothing.
604:             *
605:             * @param w DOCUMENT ME!
606:             */
607:            public void windowDeiconified(WindowEvent w) {
608:            }
609:
610:            /**
611:             * Does nothing.
612:             *
613:             * @param w DOCUMENT ME!
614:             */
615:            public void windowIconified(WindowEvent w) {
616:            }
617:
618:            /**
619:             * Does nothing.
620:             *
621:             * @param w DOCUMENT ME!
622:             */
623:            public void windowOpened(WindowEvent w) {
624:            }
625:
626:            /**
627:             * Exits the system.
628:             *
629:             * @param w DOCUMENT ME!
630:             */
631:            public void windowClosing(WindowEvent w) {
632:                close();
633:            }
634:
635:            /**
636:             * Opens the frame.
637:             */
638:            public void open() {
639:                setVisible(true);
640:            }
641:
642:            /**
643:             * Closes the frame.
644:             */
645:            public void close() {
646:                setVisible(false);
647:
648:                Session session = getCleverPHL().getSessionList().getActual();
649:
650:                if (session != null) {
651:                    session.getManipulationManagement().setMode(
652:                            ManipulationManagement.USE_COMPONENTS);
653:                }
654:            }
655:
656:            public void setVisible(boolean isVisible) {
657:                Session session = cleverPHL.getSessionList().getActual();
658:
659:                if (isVisible && (session == null)) {
660:                    isVisible = false;
661:                }
662:
663:                super .setVisible(isVisible);
664:
665:                if (isVisible) {
666:                    Components components = session.getComponents();
667:
668:                    if (eventListener == null) {
669:                        eventListener = new EventListener(env, components,
670:                                null, EventListener.INIT_EMPTY);
671:
672:                        WindowActivationCatcher catcher = new WindowActivationCatcher(
673:                                env);
674:                        eventListener.addCatcher(catcher);
675:                        catcher.addWaitingInstance(this );
676:                    } else {
677:                        eventListener.setComponents(components);
678:                    }
679:
680:                    eventListener.start();
681:                } else {
682:                    if (eventListener != null) {
683:                        eventListener.stop();
684:                    }
685:                }
686:            }
687:
688:            /**
689:             * Called when a palette element has been selected.
690:             *
691:             * @param button DOCUMENT ME!
692:             */
693:            public void paletteUserSelected(PaletteButton button) {
694:                Tool tool = ((ToolButton) button).tool();
695:                pane.setTool(tool);
696:            }
697:
698:            public void paletteUserOver(PaletteButton button, boolean inside) {
699:            }
700:
701:            /**
702:             * This function will be called by the activation catcher when a window has been activated.
703:             *
704:             * @param window the window which has been activated
705:             */
706:            public void handleActivation(Window window) {
707:                if ((window != actualWindow)
708:                        && ((window instanceof  JFrame) || (window instanceof  JDialog))) {
709:                    GlassPaneManager manager = cleverPHL.getSessionList()
710:                            .getActual().getComponents().getGlassPaneManager();
711:                    DrawingPane pane = (DrawingPane) manager
712:                            .getGlassPaneCompound(window).getGlassPane(
713:                                    GlassPaneCompound.DRAWING_PANE);
714:
715:                    if (pane != null) {
716:                        setDrawingPane(pane);
717:                    }
718:                }
719:            }
720:
721:            /**
722:             * Internal class which shows a color.
723:             */
724:            class ColorShow extends JPanel {
725:                //~ Instance fields ------------------------------------------------------------------------
726:
727:                private Color color;
728:
729:                //~ Constructors ---------------------------------------------------------------------------
730:
731:                /**
732:                 * Creates a ColorShow object.
733:                 *
734:                 * @param initialColor the first color shown by this instance
735:                 */
736:                public ColorShow(Color initialColor) {
737:                    this .color = initialColor;
738:                }
739:
740:                /**
741:                 * Creates a ColorShow object.
742:                 */
743:                public ColorShow() {
744:                    this (null);
745:                }
746:
747:                //~ Methods --------------------------------------------------------------------------------
748:
749:                /**
750:                 * Sets the color.
751:                 *
752:                 * @param color the new color
753:                 */
754:                public void setColor(Color color) {
755:                    this .color = color;
756:                    repaint();
757:                }
758:
759:                /**
760:                 * Returns the actual color.
761:                 *
762:                 * @return the color shown by this instance
763:                 */
764:                public Color getColor() {
765:                    return color;
766:                }
767:
768:                public void paintComponent(Graphics g) {
769:                    int height = getHeight();
770:                    int width = getWidth();
771:                    g.setColor(getBackground());
772:                    g.fillRect(0, 0, width, height);
773:
774:                    int colorFieldSideLength = ((width < height) ? width
775:                            : height) / 2;
776:                    int x = (getWidth() - colorFieldSideLength) / 2;
777:                    int y = (getHeight() - colorFieldSideLength) / 2;
778:
779:                    if ((color.getRed() == 0) && (color.getGreen() == 0)
780:                            && (color.getBlue() == 0)
781:                            && (color.getAlpha() == 0)) {
782:                        g.setColor(Color.red);
783:                        g.drawRect(x, y, colorFieldSideLength - 1,
784:                                colorFieldSideLength - 1);
785:                        g.drawLine(x, y, (x + colorFieldSideLength) - 1,
786:                                (y + colorFieldSideLength) - 1);
787:                        g.drawLine(x, (y + colorFieldSideLength) - 1,
788:                                (x + colorFieldSideLength) - 1, y);
789:                    } else {
790:                        g.setColor(color);
791:                        g.fillRect(x, y, colorFieldSideLength,
792:                                colorFieldSideLength);
793:                    }
794:                }
795:            }
796:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.