Source Code Cross Referenced for PaletteContainerOperator.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » gravy » toolbox » 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 Netbeans » visualweb.api.designer » org.netbeans.modules.visualweb.gravy.toolbox 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.visualweb.gravy.toolbox;
043:
044:        import org.netbeans.modules.visualweb.gravy.*;
045:        import org.netbeans.modules.visualweb.gravy.DNDDriver;
046:        import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator; //import com.sun.rave.toolbox.PaletteContainer;
047:        import org.netbeans.modules.visualweb.gravy.actions.PropertiesAction;
048:        import org.netbeans.modules.visualweb.gravy.properties.SheetTableOperator;
049:        import java.awt.Component;
050:        import java.awt.Container;
051:        import java.awt.Point;
052:        import java.awt.Rectangle;
053:        import java.awt.event.*;
054:        import java.beans.*;
055:        import java.util.StringTokenizer;
056:        import org.netbeans.jemmy.ComponentChooser;
057:        import org.netbeans.jemmy.QueueTool;
058:        import org.netbeans.jemmy.drivers.input.MouseRobotDriver;
059:        import org.netbeans.jemmy.operators.*;
060:        import org.netbeans.jellytools.Bundle;
061:        import javax.swing.*;
062:        import org.netbeans.jemmy.Timeout;
063:
064:        /**
065:         *
066:         * @author Alexandre (Shura) Iline (alexandre.iline@sun.com)
067:         */
068:        public class PaletteContainerOperator extends ContainerOperator {
069:
070:            private static final String PALETTE_TITLE = "Palette";
071:            JListOperator theTree = null;
072:            JCheckBoxOperator categoryButton = null;
073:            private String name;
074:            static String defaultPaletteCategory = "Basic";
075:
076:            private PaletteContainerOperator(ContainerOperator cont, String name) {
077:                super (cont, new PaletteContainerChooser(name));
078:                this .name = name;
079:            }
080:
081:            /**
082:             * @param name of the section in Palette
083:             * @return Container containing CheckBox with section name and JList of the components
084:             */
085:            private static Container findPaletteContainer(String name) {
086:                return new JCheckBoxOperator(
087:                        new org.netbeans.jellytools.TopComponentOperator(
088:                                PALETTE_TITLE), name).getParent();
089:            }
090:
091:            public PaletteContainerOperator(String name) {
092:                super (findPaletteContainer(name));
093:                this .name = name;
094:            }
095:
096:            public static String getDefaultPaletteCategory() {
097:                return defaultPaletteCategory;
098:            }
099:
100:            public void showComponents() {
101:                if (categoryButton == null) {
102:                    categoryButton = new JCheckBoxOperator(this , name);
103:                }
104:                categoryButton.changeSelection(true);
105:            }
106:
107:            public void hideComponents() {
108:                if (categoryButton == null) {
109:                    categoryButton = new JCheckBoxOperator(this , name);
110:                }
111:                categoryButton.changeSelection(false);
112:            }
113:
114:            public Point getClickPoint(String componentName) {
115:                JListOperator theTree = getComponentsTree();
116:                return (theTree.getClickPoint(theTree
117:                        .findItemIndex(componentName)));
118:            }
119:
120:            /**
121:             * TODO:
122:             */
123:            public Point getClickPoint(String componentName, int index) {
124:                return (getComponentsTree().getClickPoint(getComponentsTree()
125:                        .findItemIndex(componentName, index)));
126:            }
127:
128:            public Point getClickPointOfClass(Class clz) {
129:                return (getClickPoint(getDisplayNameOfClass(clz)));
130:            }
131:
132:            public Point getClickPointOfClass(String className) {
133:                try {
134:                    return (getClickPointOfClass(Class.forName(className)));
135:                } catch (ClassNotFoundException e) {
136:                    return (getClickPoint(getShortClassName(className)));
137:                }
138:            }
139:
140:            private JViewport findViewportOfPalette() {
141:                JViewport viewPort = (JViewport) ContainerOperator
142:                        .findContainerUnder(getSource(),
143:                                new ComponentChooser() {
144:                                    public boolean checkComponent(Component comp) {
145:                                        return (JViewport.class
146:                                                .isInstance(comp));
147:                                    }
148:
149:                                    public String getDescription() {
150:                                        return ("JViewport");
151:                                    }
152:                                });
153:                return viewPort;
154:            }
155:
156:            public void dndPaletteComponent(String componentName,
157:                    ComponentOperator designer, Point designerPoint) {
158:                Point clickPoint = getClickPoint(componentName);
159:                Util.wait(1000);
160:                dndPaletteComponent(clickPoint, designer, designerPoint);
161:            }
162:
163:            public void dndComponentOfClass(String componentClassName,
164:                    ComponentOperator designer, Point designerPoint) {
165:                Point clickPoint = getClickPointOfClass(componentClassName);
166:                Util.wait(1000);
167:                dndPaletteComponent(clickPoint, designer, designerPoint);
168:            }
169:
170:            private void dndPaletteComponent(Point componentClickPoint,
171:                    ComponentOperator designer, Point designerPoint) {
172:                JViewport viewPort = findViewportOfPalette();
173:                ComponentOperator component = getComponentsTree();
174:                int compX = (component.getLocationOnScreen().x - viewPort
175:                        .getLocationOnScreen().x)
176:                        + componentClickPoint.x;
177:                int compY = (component.getLocationOnScreen().y - viewPort
178:                        .getLocationOnScreen().y)
179:                        + componentClickPoint.y;
180:
181:                System.out.println();
182:                System.out
183:                        .println("+++ coordinates of component in Palette Panel = ["
184:                                + compX + ", " + compY + "]");
185:                System.out.println();
186:
187:                viewPort.setViewPosition(new Point(compX, compY));
188:                Util.wait(1000);
189:                //TODO Somehow it goes to previous component so need to shift y a bit
190:                //componentClickPoint = new Point(componentClickPoint.x,componentClickPoint.y+5);
191:                component.clickMouse(componentClickPoint.x,
192:                        componentClickPoint.y, 1);
193:                Util.wait(2000);
194:                System.out.println();
195:                System.out
196:                        .println("+++ Component in Palette Panel should be visible and selected");
197:                System.out.println("+++ Left-top position in Palette Panel = "
198:                        + viewPort.getViewPosition());
199:                System.out.println();
200:
201:                DNDDriver dndDriver = new DNDDriver();
202:                Util.wait(1000);
203:                dndDriver.dnd(component, componentClickPoint, designer,
204:                        designerPoint, InputEvent.BUTTON1_MASK, 0);
205:                Util.wait(3000);
206:                System.out.println();
207:                System.out
208:                        .println("+++ Component should be put from Palette on Designer Pane");
209:                System.out.println();
210:
211:            }
212:
213:            public JListOperator getComponentsTree() {
214:                showComponents();
215:                if (theTree == null) {
216:                    theTree = new JListOperator(this );
217:                }
218:                return (theTree);
219:            }
220:
221:            public void addComponent(String componentName) {
222:                Point clickPoint = getClickPoint(componentName);
223:                theTree.clickMouse(clickPoint.x, clickPoint.y, 2);
224:            }
225:
226:            public void addComponent(String componentName, int index) {
227:                Point clickPoint = getClickPoint(componentName, index);
228:                theTree.clickMouse(clickPoint.x, clickPoint.y, 2);
229:            }
230:
231:            public void addComponentOfClass(Class clz) {
232:                Point clickPoint = getClickPointOfClass(clz);
233:                theTree.clickMouse(clickPoint.x, clickPoint.y, 2);
234:                TestUtils.wait(2000);
235:            }
236:
237:            public void addComponentOfClass(String className) {
238:                Point clickPoint = getClickPointOfClass(className);
239:                theTree.clickMouse(clickPoint.x, clickPoint.y, 2);
240:                TestUtils.wait(2000);
241:            }
242:
243:            public void addComponent(String componentName,
244:                    DesignerPaneOperator designer, Point location) {
245:                Point clickPoint = getClickPoint(componentName);
246:                //getComponentsTree().clickMouse(clickPoint.x, clickPoint.y, 1);
247:                JListOperator tree = getComponentsTree();
248:                if (tree.isSelectionEmpty()) {
249:                    tree.selectItem(componentName);
250:                } else {
251:                    tree.clearSelection();
252:                    tree.selectItem(componentName);
253:                }
254:                TestUtils.wait(2000);
255:                designer.clickMouse(location.x, location.y, 1);
256:                TestUtils.wait(2000);
257:                //Second click added because when component added on designer it is not in focus
258:                designer.clickMouse(1, 100, 1);
259:                TestUtils.wait(2000);
260:                designer.clickMouse(location.x + 5, location.y + 5, 1);
261:                TestUtils.wait(2000);
262:            }
263:
264:            /**
265:             *  Add component which beginning text is same as others.
266:             *  i.g., Image and Image Hyperlink. It always selects Image Hyperlink when
267:             *  use addComponent("Image", designer, new Point(x,y))
268:             *  as Image Hyperlink is listed in front of Image in Palette.
269:             *  Example: <BR>
270:             *  <pre>
271:             *   String  componentName =  "Image" ;
272:             *   int  index =  1 ;
273:             *   palette.addComponent(componentName, indes, designer, new Point(x,y));
274:             *  </pre>
275:             */
276:            public void addComponent(String componentName, int index,
277:                    DesignerPaneOperator designer, Point location) {
278:                Point clickPoint = getClickPoint(componentName, index);
279:                getComponentsTree().clickMouse(clickPoint.x, clickPoint.y, 1);
280:                TestUtils.wait(2000);
281:                designer.clickMouse(location.x, location.y, 1);
282:                TestUtils.wait(2000);
283:            }
284:
285:            public void addComponentOfClass(Class clz,
286:                    DesignerPaneOperator designer, Point location) {
287:                Point clickPoint = getClickPointOfClass(clz);
288:                getComponentsTree().clickMouse(clickPoint.x, clickPoint.y, 1);
289:                designer.clickMouse(location.x, location.y, 1);
290:                TestUtils.wait(2000);
291:            }
292:
293:            public void addComponentOfClass(String className,
294:                    DesignerPaneOperator designer, Point location) {
295:
296:                Point clickPoint = getClickPointOfClass(className);
297:                getComponentsTree().clickMouse(clickPoint.x, clickPoint.y, 1);
298:                designer.clickMouse(location.x, location.y, 1);
299:                TestUtils.wait(2000);
300:            }
301:
302:            /*
303:             public void addComponent(String componentName) {
304:             getComponentButton(componentName).clickMouse(2);
305:             }
306:            
307:             public void addComponentOfClass(Class clz) {
308:             getComponentButtonOfClass(clz).clickMouse(2);
309:             }
310:            
311:             public void addComponentOfClass(String className) {
312:             getComponentButtonOfClass(className).clickMouse(2);
313:             }
314:            
315:             public void addComponent(String componentName, DesignerPaneOperator designer, Point location) {
316:             //new DNDDriver().dnd(getComponentButton(componentName), new Point(1, 1),
317:             //designer, location);
318:             getComponentButton(componentName).clickMouse();
319:             designer.clickMouse(location.x, location.y, 1);
320:             }
321:            
322:             public void addComponentOfClass(Class clz, DesignerPaneOperator designer, Point location) {
323:             getComponentButtonOfClass(clz).clickMouse();
324:             designer.clickMouse(location.x, location.y, 1);
325:             }
326:            
327:             public void addComponentOfClass(String className, DesignerPaneOperator designer, Point location) {
328:             getComponentButtonOfClass(className).clickMouse();
329:             designer.clickMouse(location.x, location.y, 1);
330:             }
331:             */
332:            public void placeClip(String clipName, JEditorPaneOperator editor,
333:                    int caretPosition) {
334:                Rectangle rect = editor.modelToView(caretPosition);
335:                Point location = new Point(rect.x + rect.width / 2, rect.y
336:                        + rect.height / 2);
337:                dndComponentOfClass(clipName, editor, location);
338:            }
339:
340:            /*
341:             public void placeClip(String clipName, JEditorPaneOperator editor, int caretPosition) {
342:             Rectangle rect = editor.modelToView(caretPosition);
343:             Point location = new Point(rect.x + rect.width / 2, rect.y + rect.height / 2);
344:             new DNDDriver().dnd(getComponentButton(clipName), new Point(1, 1), editor, location);
345:             }
346:             */
347:            public void placeClip(String clipName, JEditorPaneOperator editor) {
348:                placeClip(clipName, editor, editor.getCaretPosition());
349:            }
350:
351:            private String getDisplayNameOfClass(Class clz) {
352:                String name = null;
353:                try {
354:                    name = java.beans.Introspector.getBeanInfo(clz)
355:                            .getBeanDescriptor().getDisplayName();
356:                } catch (IntrospectionException e) {
357:                }
358:                if (name == null) {
359:                    name = getShortClassName(clz.getName());
360:                }
361:                return (name);
362:            }
363:
364:            private String getShortClassName(String className) {
365:                String name = null;
366:                StringTokenizer token = new StringTokenizer(className, ".");
367:                while (token.hasMoreTokens()) {
368:                    name = token.nextToken();
369:                }
370:                return (name);
371:            }
372:
373:            /**
374:             *  TODO: need to be updated
375:             *
376:             */
377:            public static void showPalette() {
378:                Util.getMainMenu().pushMenu("Window|Palette");
379:                new QueueTool().waitEmpty();
380:            }
381:
382:            public static PaletteContainerOperator showPalette(String buttName,
383:                    String paletteName) {
384:                new org.netbeans.modules.visualweb.gravy.toolbox.actions.ShowPaletteAction()
385:                        .perform();
386:                new QueueTool().waitEmpty();
387:                new JToggleButtonOperator(new ToolBoxOperator(), buttName)
388:                        .push();
389:                //new JButtonOperator(new ToolBoxOperator(), buttName).push();
390:                return (new PaletteContainerOperator(paletteName));
391:            }
392:
393:            public static PaletteContainerOperator showCodeClips() {
394:                new org.netbeans.modules.visualweb.gravy.toolbox.actions.ShowPaletteAction()
395:                        .perform();
396:                new QueueTool().waitEmpty();
397:                new JToggleButtonOperator(new ToolBoxOperator(), Bundle
398:                        .getStringTrimmed("com.sun.rave.toolbox.Bundle",
399:                                "CODE_CLIPS")).push();
400:                return (new PaletteContainerOperator("Samples"));
401:            }
402:
403:            /**
404:             * TODO: maked private because doesn't work properly
405:             */
406:            private static class PaletteContainerChooser implements 
407:                    ComponentChooser {
408:                String name;
409:
410:                public PaletteContainerChooser(String name) {
411:                    this .name = name;
412:                }
413:
414:                public boolean checkComponent(Component comp) {
415:                    System.out.println("Class =" + comp.getClass() + "   Name="
416:                            + comp.getClass().getName());
417:                    if (comp
418:                            .getClass()
419:                            .getName()
420:                            .equals(
421:                                    "org.netbeans.modules.palette.ui.CategoryDescriptor$1")) {
422:                        return true;
423:                    }
424:                    return false;//(comp.getClass().getName().equals("org.netbeans.modules.palette.ui.CategoryButton"));
425:
426:                }
427:
428:                public String getDescription() {
429:                    return (/*PaletteContainer.class.getName() + */" with \""
430:                            + name + "\" name");
431:                }
432:            }
433:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.