Source Code Cross Referenced for RightStripe.java in  » IDE-Netbeans » bpel » org » netbeans » modules » bpel » design » 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 » bpel » org.netbeans.modules.bpel.design 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the terms of the Common Development
003:         * and Distribution License (the License). You may not use this file except in
004:         * compliance with the License.
005:         * 
006:         * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007:         * or http://www.netbeans.org/cddl.txt.
008:         * 
009:         * When distributing Covered Code, include this CDDL Header Notice in each file
010:         * and include the License file at http://www.netbeans.org/cddl.txt.
011:         * If applicable, add the following below the CDDL Header, with the fields
012:         * enclosed by brackets [] replaced by your own identifying information:
013:         * "Portions Copyrighted [year] [name of copyright owner]"
014:         * 
015:         * The Original Software is NetBeans. The Initial Developer of the Original
016:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017:         * Microsystems, Inc. All Rights Reserved.
018:         */
019:
020:        package org.netbeans.modules.bpel.design;
021:
022:        import java.awt.BorderLayout;
023:        import java.awt.Color;
024:        import java.awt.Cursor;
025:        import java.awt.Dimension;
026:        import java.awt.Graphics;
027:        import java.awt.Point;
028:        import java.awt.Rectangle;
029:        import java.awt.Rectangle;
030:        import java.awt.event.ComponentEvent;
031:        import java.awt.event.ComponentListener;
032:        import java.awt.event.MouseEvent;
033:        import java.awt.event.MouseListener;
034:        import java.awt.event.MouseMotionListener;
035:        import java.util.ArrayList;
036:        import java.util.HashMap;
037:        import java.util.List;
038:        import java.util.Map;
039:        import javax.swing.JPanel;
040:        import javax.swing.ToolTipManager;
041:        import org.netbeans.modules.bpel.design.decoration.Decoration;
042:        import org.netbeans.modules.bpel.design.decoration.StripeDescriptor;
043:        import org.netbeans.modules.bpel.design.geometry.FBounds;
044:        import org.netbeans.modules.bpel.design.geometry.FPoint;
045:        import org.netbeans.modules.bpel.design.model.elements.BorderElement;
046:        import org.netbeans.modules.bpel.design.model.patterns.CompositePattern;
047:        import org.netbeans.modules.bpel.design.model.patterns.Pattern;
048:        import org.netbeans.modules.bpel.model.api.BpelModel;
049:        import org.openide.util.NbBundle;
050:
051:        /**
052:         *
053:         * @author anjeleevich
054:         */
055:        public class RightStripe extends JPanel implements  ComponentListener,
056:                MouseListener, MouseMotionListener {
057:
058:            private DesignView designView;
059:            private StatusPanel statusPanel = new StatusPanel();
060:            private DataPanel dataPanel = new DataPanel();
061:
062:            private StripeDescriptor statusStripe = new StripeDescriptor();
063:            private Map<Integer, Cell> cells = new HashMap<Integer, Cell>();
064:
065:            private boolean needsToBePrepeared = true;
066:
067:            public RightStripe(DesignView designView) {
068:                this .designView = designView;
069:
070:                setFocusable(false);
071:                setLayout(new BorderLayout(0, 0));
072:
073:                add(statusPanel, BorderLayout.NORTH);
074:                add(dataPanel, BorderLayout.CENTER);
075:
076:                dataPanel.addComponentListener(this );
077:                dataPanel.addMouseListener(this );
078:                dataPanel.addMouseMotionListener(this );
079:
080:                setToolTipText(null);
081:            }
082:
083:            private boolean isModelBroken() {
084:                return (getDesignView().getBPELModel().getState() != BpelModel.State.VALID);
085:            }
086:
087:            public void repaint() {
088:                needsToBePrepeared = true;
089:                super .repaint();
090:            }
091:
092:            public DesignView getDesignView() {
093:                return designView;
094:            };
095:
096:            private void prepareToRepaint() {
097:                if (needsToBePrepeared) {
098:                    statusStripe = new StripeDescriptor();
099:                    cells.clear();
100:
101:                    if (!isModelBroken()) {
102:                        prepareToRepaint(designView.getRootPattern());
103:                    }
104:
105:                    needsToBePrepeared = false;
106:
107:                    updateCursor(null);
108:                }
109:            }
110:
111:            private void prepareToRepaint(Pattern pattern) {
112:                if (pattern == null)
113:                    return;
114:
115:                addCellItem(pattern);
116:
117:                if (pattern instanceof  CompositePattern) {
118:                    for (Pattern child : ((CompositePattern) pattern)
119:                            .getNestedPatterns()) {
120:                        prepareToRepaint(child);
121:                    }
122:                }
123:            }
124:
125:            private Rectangle getPatternBounds(Pattern pattern) {
126:                FBounds bounds = null;
127:
128:                if (pattern instanceof  CompositePattern) {
129:                    BorderElement border = ((CompositePattern) pattern)
130:                            .getBorder();
131:                    if (border != null) {
132:                        bounds = border.getBounds();
133:                    }
134:                }
135:
136:                if (bounds == null) {
137:                    bounds = pattern.getBounds();
138:                }
139:
140:                Point p1 = designView.convertDiagramToScreen(bounds
141:                        .getTopLeft());
142:                Point p2 = designView.convertDiagramToScreen(bounds
143:                        .getBottomRight());
144:
145:                return new Rectangle(p1.x - 16, p1.y - 32, p2.x - p1.x + 32,
146:                        p2.y - p1.y + 64);
147:            }
148:
149:            private void addCellItem(Pattern pattern) {
150:                if (pattern == null)
151:                    return;
152:
153:                Decoration decoration = designView.getDecoration(pattern);
154:
155:                if (decoration == null || !decoration.hasStripe())
156:                    return;
157:
158:                int cellNumber = getCellNumber(pattern);
159:
160:                Cell cell = cells.get(cellNumber);
161:
162:                if (cell == null) {
163:                    cell = new Cell();
164:                    cells.put(cellNumber, cell);
165:                }
166:
167:                StripeDescriptor stripeDescriptor = decoration.getStripe();
168:
169:                statusStripe = StripeDescriptor.merge(statusStripe,
170:                        stripeDescriptor);
171:
172:                cell.addItem(pattern, stripeDescriptor);
173:            }
174:
175:            private int getCellNumber(Pattern pattern) {
176:                FPoint point = pattern.getBounds().getTopLeft();
177:                FBounds bounds = getDesignView().getRootPattern().getBounds();
178:
179:                int i = (int) ((point.y - bounds.y) / bounds.height
180:                        * dataPanel.getHeight() / 4.0);
181:
182:                if (i >= getCellCount()) {
183:                    i = getCellCount() - 1;
184:                }
185:
186:                if (i < 0) {
187:                    i = 0;
188:                }
189:
190:                return i;
191:
192:                //        double y = designView.convertDiagramToScreen(pattern.getBounds()
193:                //                .getTopLeft()).y;
194:                //        
195:                //        y /= designView.getHeight();
196:                //        
197:                //        return (int) (y * dataPanel.getHeight() / 4.0);
198:            }
199:
200:            private int getCellCount() {
201:                return (dataPanel.getHeight() + 1) / 4;
202:            }
203:
204:            private Cell getCell(int y) {
205:                int n = y / 4;
206:
207:                Cell result = cells.get(n);
208:
209:                if (result != null) {
210:                    return result;
211:                }
212:
213:                if (y < n * 4 + 2) {
214:                    result = cells.get(n - 1);
215:                } else {
216:                    result = cells.get(n + 1);
217:                }
218:
219:                return result;
220:            }
221:
222:            private void updateCursor(Point mousePoint) {
223:                if (mousePoint == null) {
224:                    mousePoint = dataPanel.getMousePosition();
225:                }
226:
227:                if (mousePoint != null) {
228:                    dataPanel
229:                            .setCursor((getCell(mousePoint.y) != null) ? Cursor
230:                                    .getPredefinedCursor(Cursor.HAND_CURSOR)
231:                                    : Cursor.getDefaultCursor());
232:                }
233:            }
234:
235:            public void componentResized(ComponentEvent e) {
236:                repaint();
237:            }
238:
239:            public void mouseClicked(MouseEvent e) {
240:                if (e.getClickCount() != 1)
241:                    return;
242:
243:                Cell cell = getCell(e.getY());
244:
245:                if (cell == null)
246:                    return;
247:
248:                Pattern nextPattern = cell.getNextPattern(designView
249:                        .getSelectionModel().getSelectedPattern());
250:
251:                if (nextPattern != null) {
252:                    if (nextPattern != designView.getSelectionModel()
253:                            .getSelectedPattern()) {
254:                        designView.getSelectionModel().setSelectedPattern(
255:                                nextPattern);
256:                    }
257:
258:                    Rectangle rect = getPatternBounds(nextPattern);
259:                    Rectangle visibleRect = designView.getVisibleRect();
260:
261:                    if (rect.height <= visibleRect.height) {
262:                        visibleRect.y = Math.max(0, rect.y
263:                                + (rect.height - visibleRect.height) / 2);
264:                    } else {
265:                        visibleRect.y = Math.max(0, rect.y);
266:                    }
267:
268:                    visibleRect.x = Math.max(0, rect.x
269:                            + (rect.width - visibleRect.width) / 2);
270:
271:                    designView.scrollRectToVisible(visibleRect);
272:                }
273:            }
274:
275:            public void mouseEntered(MouseEvent e) {
276:                updateCursor(e.getPoint());
277:            }
278:
279:            public void mouseMoved(MouseEvent e) {
280:                updateCursor(e.getPoint());
281:            }
282:
283:            public void componentMoved(ComponentEvent e) {
284:            }
285:
286:            public void componentShown(ComponentEvent e) {
287:            }
288:
289:            public void componentHidden(ComponentEvent e) {
290:            }
291:
292:            public void mousePressed(MouseEvent e) {
293:            }
294:
295:            public void mouseReleased(MouseEvent e) {
296:            }
297:
298:            public void mouseExited(MouseEvent e) {
299:            }
300:
301:            public void mouseDragged(MouseEvent e) {
302:            }
303:
304:            private class StatusPanel extends JPanel {
305:                public StatusPanel() {
306:                    setFocusable(false);
307:                    setPreferredSize(new Dimension(13, 24));
308:                    ToolTipManager.sharedInstance().registerComponent(this );
309:                }
310:
311:                protected void paintComponent(Graphics g) {
312:                    super .paintComponent(g);
313:
314:                    int w = getWidth();
315:                    int h = getHeight();
316:
317:                    int x0 = 2;
318:                    int y0 = 7;
319:
320:                    int size = w - 2 * x0;
321:
322:                    if (isModelBroken()) {
323:                        g.setColor(StripeDescriptor.ERROR_COLOR);
324:                    } else {
325:                        g.setColor(statusStripe.getStatusColor());
326:                    }
327:
328:                    g.fillRect(x0 + 1, y0 + 1, size - 2, size - 2);
329:                    g.setColor(BORDER_BRIGHT);
330:                    g.drawRect(x0, y0, size - 1, size - 1);
331:                    g.setColor(BORDER_DARK);
332:                    g.drawLine(x0, y0, x0 + size - 2, y0);
333:                    g.drawLine(x0, y0, x0, y0 + size - 2);
334:                }
335:
336:                public String getToolTipText(MouseEvent event) {
337:                    if (isModelBroken()) {
338:                        return NbBundle.getMessage(RightStripe.class,
339:                                "LBL_InvalidSources"); // NOI18N
340:                    }
341:
342:                    return statusStripe.getStatusText();
343:                }
344:            }
345:
346:            private class DataPanel extends JPanel {
347:                public DataPanel() {
348:                    setFocusable(false);
349:                    ToolTipManager.sharedInstance().registerComponent(this );
350:                }
351:
352:                protected void paintComponent(Graphics g) {
353:                    super .paintComponent(g);
354:
355:                    prepareToRepaint();
356:
357:                    int w = getWidth();
358:
359:                    for (Map.Entry<Integer, Cell> entity : cells.entrySet()) {
360:                        int y0 = (entity.getKey() * 4);
361:
362:                        StripeDescriptor stripeDescriptor = entity.getValue()
363:                                .getStripeDescriptor();
364:
365:                        g.setColor(stripeDescriptor.getColor());
366:
367:                        if (stripeDescriptor.isFilled()) {
368:                            g.fillRect(1, y0, w - 2, 3);
369:                        } else {
370:                            g.drawRect(1, y0, w - 3, 2);
371:                        }
372:                    }
373:                }
374:
375:                public String getToolTipText(MouseEvent event) {
376:                    Cell cell = getCell(event.getY());
377:                    return (cell == null) ? null : cell.getToolTipText();
378:                }
379:            }
380:
381:            private static class Cell {
382:                private StripeDescriptor stripeDescriptor = null;
383:                private List<Pattern> patterns = new ArrayList<Pattern>();
384:
385:                public void addItem(Pattern pattern,
386:                        StripeDescriptor stripeDescriptor) {
387:                    this .stripeDescriptor = StripeDescriptor.merge(
388:                            this .stripeDescriptor, stripeDescriptor);
389:                    patterns.add(pattern);
390:                }
391:
392:                public String getToolTipText() {
393:                    return (stripeDescriptor == null) ? null : stripeDescriptor
394:                            .getText();
395:                }
396:
397:                public StripeDescriptor getStripeDescriptor() {
398:                    return stripeDescriptor;
399:                }
400:
401:                public Pattern getNextPattern(Pattern pattern) {
402:                    int patternIndex = (pattern == null) ? -1 : patterns
403:                            .indexOf(pattern);
404:                    Pattern result = patterns.get((patternIndex + 1)
405:                            % patterns.size());
406:                    return result;
407:                }
408:            }
409:
410:            private static final Color BORDER_DARK = new Color(0xCDCABB);
411:            private static final Color BORDER_BRIGHT = Color.WHITE;
412:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.