Source Code Cross Referenced for StyleBuilderPanel.java in  » IDE-Netbeans » visualweb.api.designer » org » netbeans » modules » visualweb » propertyeditors » css » 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.propertyeditors.css 
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:        package org.netbeans.modules.visualweb.propertyeditors.css;
042:
043:        import org.netbeans.modules.visualweb.propertyeditors.css.model.CssStyleData;
044:        import org.netbeans.modules.visualweb.propertyeditors.css.model.CssStyleParser;
045:        import com.sun.rave.designtime.DesignProperty;
046:        import com.sun.rave.designtime.markup.MarkupDesignBean;
047:        import com.sun.rave.designtime.markup.MarkupDesignContext;
048:        import java.awt.BorderLayout;
049:        import java.awt.CardLayout;
050:        import java.awt.Color;
051:        import java.awt.Dimension;
052:        import java.awt.Font;
053:        import java.awt.Graphics;
054:        import java.awt.Graphics2D;
055:        import java.awt.GridBagConstraints;
056:        import java.awt.GridBagLayout;
057:        import java.awt.Image;
058:        import java.awt.event.ComponentEvent;
059:        import java.awt.event.ComponentListener;
060:        import java.awt.font.FontRenderContext;
061:        import java.awt.geom.Rectangle2D;
062:        import java.awt.image.BufferedImage;
063:        import java.beans.PropertyChangeEvent;
064:        import java.beans.PropertyChangeListener;
065:        import java.beans.PropertyChangeSupport;
066:        import java.util.ArrayList;
067:        import java.util.List;
068:        import javax.swing.JLabel;
069:        import javax.swing.JPanel;
070:        import javax.swing.JViewport;
071:        import org.openide.ErrorManager;
072:        import org.openide.util.NbBundle;
073:
074:        /**
075:         * Style Builder main panel
076:         * @author  Winston Prakash
077:         */
078:        public class StyleBuilderPanel extends JPanel implements 
079:                PropertyChangeListener {
080:            JPanel currentEditor;
081:            String currentStyle = null;
082:            private CssStyleData cssStyleData = new CssStyleData();
083:            private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(
084:                    this );
085:
086:            DesignProperty designProperty = null;
087:            Image previewImage = null;
088:
089:            StyleEditorListPanel styleEditorListPanel = null;
090:
091:            List styleEditorList = new ArrayList();
092:            String noPreviewLabel = NbBundle.getMessage(
093:                    StyleBuilderPanel.class, "NO_PREVIEW");
094:
095:            /** Creates new form StyleBuilderPanel */
096:            public StyleBuilderPanel() {
097:                initComponents();
098:                initialize();
099:            }
100:
101:            public StyleBuilderPanel(String styleString,
102:                    DesignProperty liveProperty) {
103:                initComponents();
104:                this .designProperty = liveProperty;
105:                CssStyleParser styleParser = new CssStyleParser(cssStyleData,
106:                        liveProperty);
107:                cssStyleData = styleParser.parse(styleString);
108:                currentStyle = cssStyleData.getStyleValue();
109:                initialize();
110:                styleTextArea.setText(currentStyle);
111:                displayPreviewImage();
112:            }
113:
114:            public StyleBuilderPanel(String styleString) {
115:                this (styleString, null);
116:            }
117:
118:            private void initialize() {
119:                styleEditorListPanel = new StyleEditorListPanel(this ,
120:                        cssStyleData);
121:
122:                styleEditorList.add(new FontStyleEditor(cssStyleData));
123:                BackgroundStyleEditor bgStyleEditor = new BackgroundStyleEditor(
124:                        cssStyleData);
125:                bgStyleEditor.setDesignProperty(designProperty);
126:                styleEditorList.add(bgStyleEditor);
127:                styleEditorList.add(new TextBlockStyleEditor(cssStyleData));
128:                styleEditorList.add(new BorderStyleEditor(cssStyleData));
129:                styleEditorList.add(new MarginStyleEditor(cssStyleData));
130:                //styleEditorList.add(new ListStyleEditor());
131:                styleEditorList.add(new PositionStyleEditor(cssStyleData));
132:                //styleEditorList.add(new OtherStyleEditor());
133:
134:                for (int i = 0; i < styleEditorList.size(); i++) {
135:                    StyleEditor styleEitor = (StyleEditor) styleEditorList
136:                            .get(i);
137:                    styleEditorListPanel.addEditor(styleEitor);
138:                }
139:                styleEditorListPanel
140:                        .setSelectedEditor((StyleEditor) styleEditorList.get(0));
141:                setEditorListPanel(styleEditorListPanel);
142:                cssStyleData.addCssPropertyChangeListener(this );
143:                /*previewImage = new BufferedImage(200,50,BufferedImage.TYPE_INT_RGB);
144:                Graphics2D g2d = (Graphics2D)previewImage.getGraphics();
145:                g2d.setColor(Color.BLUE);
146:                g2d.fillRect(5,5,190,40);
147:                g2d.setColor(Color.YELLOW);
148:                g2d.drawString("This is a test Text",(float)50.,(float)30.);
149:                if(previewImage != null){
150:                    previewPanel.setPreferredSize(new Dimension(previewImage.getWidth(this)+10,previewImage.getHeight(this)+10));
151:                }*/
152:            }
153:
154:            public void propertyChange(PropertyChangeEvent evt) {
155:                styleTextArea.setText(cssStyleData.getStyleValue());
156:                propertyChangeSupport.firePropertyChange("style", currentStyle,
157:                        cssStyleData.getStyleValue()); //NOI18N
158:                currentStyle = cssStyleData.getStyleValue();
159:                displayPreviewImage();
160:            }
161:
162:            private void displayPreviewImage() {
163:                if (designProperty != null) {
164:                    try {
165:                        MarkupDesignBean liveBean = (MarkupDesignBean) designProperty
166:                                .getDesignBean();
167:                        MarkupDesignContext liveContext = (MarkupDesignContext) liveBean
168:                                .getDesignContext();
169:                        Dimension viewportDim = previewScrollPane.getViewport()
170:                                .getViewSize();
171:                        previewImage = liveContext.getCssPreviewImage(
172:                                currentStyle, null, liveBean, (int) viewportDim
173:                                        .getWidth(), (int) viewportDim
174:                                        .getHeight());
175:                        if (previewImage != null) {
176:                            previewPanel.setPreferredSize(new Dimension(
177:                                    previewImage.getWidth(this ) + 10,
178:                                    previewImage.getHeight(this ) + 10));
179:                        }
180:                        repaint();
181:                    } catch (Exception exc) {
182:                        ErrorManager.getDefault().notify(
183:                                ErrorManager.EXCEPTION, exc);
184:                    }
185:                } else {
186:
187:                }
188:            }
189:
190:            /**
191:             * Adds a PropertyChangeListener to the listener list.
192:             * The property change listener is added to the CssStyleData
193:             * @param listener The listener to add.
194:             */
195:            public void addCssPropertyChangeListener(
196:                    PropertyChangeListener listener) {
197:                propertyChangeSupport.addPropertyChangeListener(listener);
198:            }
199:
200:            /**
201:             * Removes a PropertyChangeListener from the listener list.
202:             * The property change listener is removed from the CssStyleData
203:             * @param listener The listener to remove.
204:             */
205:            public void removeCssPropertyChangeListener(
206:                    PropertyChangeListener listener) {
207:                propertyChangeSupport.removePropertyChangeListener(listener);
208:            }
209:
210:            /**
211:             * Get the Style property string.
212:             * Constructed from the CssStyleData Structure
213:             */
214:            public String getStyleString() {
215:                return cssStyleData.toString();
216:            }
217:
218:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
219:            private void initComponents() {
220:                java.awt.GridBagConstraints gridBagConstraints;
221:
222:                mainSplitPane = new javax.swing.JSplitPane();
223:                styleStringPanel = new javax.swing.JPanel();
224:                styleStringScroll = new javax.swing.JScrollPane();
225:                styleTextArea = new javax.swing.JTextArea();
226:                styleLabel = new javax.swing.JLabel();
227:                styleEditorSplitPane = new javax.swing.JSplitPane();
228:                editorListPanel = new javax.swing.JPanel();
229:                editorSplitPane = new javax.swing.JSplitPane();
230:                previewScrollPane = new javax.swing.JScrollPane();
231:                previewPanel = new PreviewPanel();
232:                previewScrollPane1 = new javax.swing.JScrollPane();
233:                editorPanel = new javax.swing.JPanel();
234:
235:                setLayout(new java.awt.BorderLayout());
236:
237:                mainSplitPane
238:                        .setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
239:                mainSplitPane.setResizeWeight(1.0);
240:                mainSplitPane
241:                        .setPreferredSize(new java.awt.Dimension(400, 650));
242:
243:                styleStringPanel.setBorder(javax.swing.BorderFactory
244:                        .createEmptyBorder(2, 2, 2, 2));
245:                styleStringPanel.setPreferredSize(new java.awt.Dimension(375,
246:                        100));
247:                styleStringPanel.setLayout(new java.awt.GridBagLayout());
248:
249:                styleStringScroll.setPreferredSize(new java.awt.Dimension(300,
250:                        100));
251:
252:                styleTextArea.setColumns(50);
253:                styleTextArea.setLineWrap(true);
254:                styleTextArea.setRows(3);
255:                styleTextArea.setMargin(new java.awt.Insets(5, 5, 5, 5));
256:                styleTextArea.setMinimumSize(new java.awt.Dimension(110, 75));
257:                styleTextArea.setPreferredSize(new java.awt.Dimension(410, 75));
258:                styleTextArea
259:                        .addFocusListener(new java.awt.event.FocusAdapter() {
260:                            public void focusLost(java.awt.event.FocusEvent evt) {
261:                                styleTextAreaFocusLost(evt);
262:                            }
263:                        });
264:                styleStringScroll.setViewportView(styleTextArea);
265:                java.util.ResourceBundle bundle = java.util.ResourceBundle
266:                        .getBundle("org/netbeans/modules/visualweb/propertyeditors/css/Bundle"); // NOI18N
267:                styleTextArea
268:                        .getAccessibleContext()
269:                        .setAccessibleName(
270:                                bundle
271:                                        .getString("STYLE_EDITOR_STYLE_TEXT_ACCESSIBLE_NAME")); // NOI18N
272:                styleTextArea
273:                        .getAccessibleContext()
274:                        .setAccessibleDescription(
275:                                bundle
276:                                        .getString("STYLE_EDITOR_STYLE_TEXT_ACCESSIBLE_DESC")); // NOI18N
277:
278:                gridBagConstraints = new java.awt.GridBagConstraints();
279:                gridBagConstraints.gridx = 1;
280:                gridBagConstraints.gridy = 0;
281:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
282:                gridBagConstraints.weightx = 1.0;
283:                gridBagConstraints.weighty = 1.0;
284:                styleStringPanel.add(styleStringScroll, gridBagConstraints);
285:
286:                styleLabel
287:                        .setDisplayedMnemonic(java.util.ResourceBundle
288:                                .getBundle(
289:                                        "org/netbeans/modules/visualweb/propertyeditors/css/Bundle")
290:                                .getString("CSS_STYLE_MNEMONIC").charAt(0));
291:                styleLabel.setLabelFor(styleTextArea);
292:                styleLabel.setText(bundle.getString("CSS_STYLE")); // NOI18N
293:                gridBagConstraints = new java.awt.GridBagConstraints();
294:                gridBagConstraints.gridx = 0;
295:                gridBagConstraints.gridy = 0;
296:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
297:                styleStringPanel.add(styleLabel, gridBagConstraints);
298:
299:                mainSplitPane.setBottomComponent(styleStringPanel);
300:
301:                editorListPanel.setBorder(javax.swing.BorderFactory
302:                        .createEmptyBorder(3, 3, 3, 3));
303:                editorListPanel.setLayout(new java.awt.BorderLayout());
304:                styleEditorSplitPane.setLeftComponent(editorListPanel);
305:
306:                editorSplitPane
307:                        .setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
308:                editorSplitPane.setResizeWeight(1.0);
309:
310:                previewScrollPane.setAutoscrolls(true);
311:                previewScrollPane.setDoubleBuffered(true);
312:                previewScrollPane.setPreferredSize(new java.awt.Dimension(400,
313:                        150));
314:
315:                previewPanel.setLayout(new java.awt.GridBagLayout());
316:                previewScrollPane.setViewportView(previewPanel);
317:
318:                editorSplitPane.setBottomComponent(previewScrollPane);
319:
320:                previewScrollPane1.setAutoscrolls(true);
321:                previewScrollPane1.setDoubleBuffered(true);
322:                previewScrollPane1.setPreferredSize(new java.awt.Dimension(400,
323:                        350));
324:
325:                editorPanel.setLayout(new java.awt.BorderLayout());
326:                previewScrollPane1.setViewportView(editorPanel);
327:
328:                editorSplitPane.setTopComponent(previewScrollPane1);
329:
330:                styleEditorSplitPane.setRightComponent(editorSplitPane);
331:
332:                mainSplitPane.setTopComponent(styleEditorSplitPane);
333:
334:                add(mainSplitPane, java.awt.BorderLayout.CENTER);
335:            }// </editor-fold>//GEN-END:initComponents
336:
337:            private void styleTextAreaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_styleTextAreaFocusLost
338:                propertyChangeSupport.firePropertyChange("style", currentStyle,
339:                        styleTextArea.getText()); //NOI18N
340:            }//GEN-LAST:event_styleTextAreaFocusLost
341:
342:            /**
343:             * Set the editor List Panel
344:             **/
345:            public void setEditorListPanel(JPanel panel) {
346:                editorListPanel.add(panel, BorderLayout.CENTER);
347:                repaint();
348:            }
349:
350:            /**
351:             * Set the Editor Panel. It is the responsibility of
352:             * the editor list panel to set the editor when the
353:             * corresponding editor is selected from its list
354:             **/
355:            public void setEditorPanel(JPanel panel) {
356:                //editorPanel.removeAll();
357:                if (currentEditor != null) {
358:                    editorPanel.remove(currentEditor);
359:                }
360:                currentEditor = panel;
361:                editorPanel.add(currentEditor, BorderLayout.CENTER);
362:                validate();
363:                repaint();
364:            }
365:
366:            class PreviewPanel extends JPanel {
367:                public PreviewPanel() {
368:
369:                }
370:
371:                public void paintComponent(Graphics graphics) {
372:                    super .paintComponent(graphics);
373:                    Graphics2D g2d = (Graphics2D) graphics;
374:                    if (previewImage != null) {
375:                        int imgX = 3;
376:                        int imgY = 3;
377:                        int imgWidth = previewImage.getWidth(this );
378:                        int imgHeight = previewImage.getHeight(this );
379:                        if (imgWidth < this .getWidth()) {
380:                            imgX = (getWidth() - imgWidth) / 2;
381:                            imgY = (getHeight() - imgHeight) / 2;
382:                        }
383:                        g2d.drawImage(previewImage, imgX, imgY, this );
384:                    } else {
385:                        FontRenderContext frc = g2d.getFontRenderContext();
386:                        Rectangle2D bounds = g2d.getFont().getStringBounds(
387:                                noPreviewLabel, frc);
388:                        int labelX = (getWidth() - (int) bounds.getWidth()) / 2;
389:                        int labelY = (getHeight() - (int) bounds.getHeight()) / 2;
390:                        g2d.drawString(noPreviewLabel, labelX, labelY);
391:                    }
392:                }
393:
394:            }
395:
396:            // Variables declaration - do not modify//GEN-BEGIN:variables
397:            private javax.swing.JPanel editorListPanel;
398:            private javax.swing.JPanel editorPanel;
399:            private javax.swing.JSplitPane editorSplitPane;
400:            private javax.swing.JSplitPane mainSplitPane;
401:            private javax.swing.JPanel previewPanel;
402:            private javax.swing.JScrollPane previewScrollPane;
403:            private javax.swing.JScrollPane previewScrollPane1;
404:            private javax.swing.JSplitPane styleEditorSplitPane;
405:            private javax.swing.JLabel styleLabel;
406:            private javax.swing.JPanel styleStringPanel;
407:            private javax.swing.JScrollPane styleStringScroll;
408:            private javax.swing.JTextArea styleTextArea;
409:            // End of variables declaration//GEN-END:variables
410:
411:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.