Source Code Cross Referenced for XStyleEditorDialog.java in  » XML-UI » XUI » net » xoetrope » builder » editor » dialog » 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 » XML UI » XUI » net.xoetrope.builder.editor.dialog 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.xoetrope.builder.editor.dialog;
002:
003:        import java.awt.BorderLayout;
004:        import java.awt.Color;
005:        import java.awt.Component;
006:        import java.awt.Dimension;
007:        import java.awt.Font;
008:        import java.awt.GridLayout;
009:        import java.awt.event.ActionEvent;
010:        import java.awt.event.ActionListener;
011:        import javax.swing.JButton;
012:        import javax.swing.JColorChooser;
013:        import javax.swing.JDialog;
014:        import javax.swing.JLabel;
015:        import javax.swing.JPanel;
016:        import javax.swing.JTextField;
017:        import javax.swing.border.EmptyBorder;
018:
019:        import net.xoetrope.builder.editor.XEditorProject;
020:        import net.xoetrope.builder.editor.XEditorStyleManager;
021:        import net.xoetrope.builder.editor.XEditorUtilities;
022:        import net.xoetrope.builder.editor.XPaletteComponentFactory;
023:        import net.xoetrope.builder.editor.events.StyleListener;
024:        import net.xoetrope.xui.style.XStyle;
025:        import net.xoetrope.xui.XProjectManager;
026:        import javax.swing.JOptionPane;
027:
028:        /**
029:         * <p> Copyright (c) Xoetrope Ltd., 2002-2003</p>
030:         * <p> $Revision: 1.6 $</p>
031:         * <p> License: see License.txt</p>
032:         */
033:        public class XStyleEditorDialog extends JDialog implements 
034:                ActionListener {
035:            private JLabel styleForegroundClr, styleBackgroundClr, styleFont;
036:            private JButton btnOK, btnCancel;
037:            private JTextField txtStyleName;
038:            private JPanel pnlControls;
039:
040:            private XEditorProject currentProject;
041:
042:            private StyleListener styleListener;
043:            private XEditorStyleManager styleManager;
044:            private boolean status = false;
045:            private XStyle currentStyle;
046:            private String addStylePath;
047:
048:            private boolean addMode;
049:
050:            public XStyleEditorDialog(boolean addMode, XStyle aStyle,
051:                    String styleName) {
052:                setModal(true);
053:                this .addMode = addMode;
054:                setTitle(addMode ? "Add style" : "Edit style");
055:                setSize(230, 180);
056:                if (addMode)
057:                    currentStyle = (XStyle) aStyle.clone();
058:                else
059:                    currentStyle = aStyle;
060:
061:                getContentPane().setLayout(new BorderLayout());
062:                pnlControls = new JPanel(new GridLayout(0, 1));
063:                pnlControls.setPreferredSize(new Dimension(230, 1));
064:                pnlControls.setBorder(new EmptyBorder(8, 8, 8, 8));
065:
066:                txtStyleName = XPaletteComponentFactory.addProperty(
067:                        "Style name :", null, false, pnlControls, this , 69);
068:                txtStyleName.setEnabled(addMode);
069:                styleBackgroundClr = XPaletteComponentFactory
070:                        .addLabelProperty("Background: ", pnlControls,
071:                                "showColorDlg", this , true);
072:                styleForegroundClr = XPaletteComponentFactory
073:                        .addLabelProperty("Foreground: ", pnlControls,
074:                                "showColorDlg", this , true);
075:                styleFont = XPaletteComponentFactory.addLabelProperty("Font: ",
076:                        pnlControls, "showFontDlg", this , true);
077:                styleFont.setText("Sample text");
078:                styleBackgroundClr.setBackground(currentStyle
079:                        .getStyleAsColor(XStyle.COLOR_BACK));
080:                styleForegroundClr.setBackground(currentStyle
081:                        .getStyleAsColor(XStyle.COLOR_FORE));
082:                if (addMode)
083:                    addStylePath = styleName;
084:                else
085:                    txtStyleName.setText(styleName);
086:
087:                styleFont.setForeground(currentStyle
088:                        .getStyleAsColor(XStyle.COLOR_FORE));
089:                styleFont.setBackground(currentStyle
090:                        .getStyleAsColor(XStyle.COLOR_BACK));
091:                int fontitalic = currentStyle.getStyleAsInt(XStyle.FONT_ITALIC);
092:                int fontweight = currentStyle.getStyleAsInt(XStyle.FONT_WEIGHT);
093:                int fontStyle = 0;
094:                if (fontweight == 1)
095:                    fontStyle = Font.BOLD;
096:                if (fontitalic == 1)
097:                    fontStyle = fontStyle | Font.ITALIC;
098:                styleFont.setFont(new Font(currentStyle
099:                        .getStyleAsString(XStyle.FONT_FACE), fontStyle,
100:                        currentStyle.getStyleAsInt(XStyle.FONT_SIZE)));
101:
102:                /* Add the buttons... */
103:                JPanel panel = new JPanel(new GridLayout(1, 3));
104:                panel.setBorder(new EmptyBorder(8, 8, 8, 8));
105:                getContentPane().add(panel, BorderLayout.SOUTH);
106:                panel.setName("XPageBuilder_OptionalProperty");
107:
108:                btnCancel = setupButton(panel, "Cancel", "newStyle", true);
109:                btnOK = setupButton(panel, "OK", "saveStyle", true);
110:
111:                getContentPane().add(pnlControls, BorderLayout.CENTER);
112:                pnlControls.doLayout();
113:                doLayout();
114:            }
115:
116:            public boolean getStatus() {
117:                return status;
118:            }
119:
120:            public XStyle getStyle() {
121:                return currentStyle;
122:            }
123:
124:            public String getStyleName() {
125:                return txtStyleName.getText();
126:            }
127:
128:            public void actionPerformed(ActionEvent e) {
129:                Object source = e.getSource();
130:                if (source instanceof  JButton) {
131:                    JButton popupBtn = (JButton) source;
132:                    String actionCmd = popupBtn.getActionCommand();
133:                    if (source == btnOK) {
134:                        if (addMode) {
135:                            styleManager = (XEditorStyleManager) XProjectManager
136:                                    .getStyleManager();
137:                            String tempName = addStylePath;
138:                            if (tempName.length() > 0)
139:                                tempName += "/";
140:                            tempName += txtStyleName.getText();
141:                            XStyle newStyle = styleManager.getStyle(tempName,
142:                                    false);
143:                            if (newStyle != null)
144:                                JOptionPane.showMessageDialog(this ,
145:                                        "This style already exists!");
146:                            else {
147:                                status = true;
148:                                setVisible(false);
149:                            }
150:                        } else {
151:                            status = true;
152:                            setVisible(false);
153:                        }
154:                    } else if (source == btnCancel) {
155:                        status = false;
156:                        setVisible(false);
157:                    } else if (actionCmd.compareTo("showColorDlg") == 0) {
158:                        JColorChooser colorChooser = new JColorChooser();
159:                        XEditorUtilities.setDefaultFont(colorChooser);
160:                        Component targetProperty = popupBtn.getParent()
161:                                .getComponent(1);
162:                        Color newColor = colorChooser.showDialog(popupBtn,
163:                                "Select required color", targetProperty
164:                                        .getBackground());
165:                        if (newColor != null) {
166:                            targetProperty.setBackground(newColor);
167:                            if (targetProperty.equals(styleForegroundClr)) {
168:                                styleFont.setForeground(newColor);
169:                                currentStyle.setStyle(XStyle.COLOR_FORE,
170:                                        newColor);
171:                            } else if (targetProperty
172:                                    .equals(styleBackgroundClr)) {
173:                                styleFont.setBackground(newColor);
174:                                currentStyle.setStyle(XStyle.COLOR_BACK,
175:                                        newColor);
176:                            }
177:                        }
178:                    } else if (actionCmd.compareTo("showFontDlg") == 0) {
179:                        XFontChooserDialog fcd = new XFontChooserDialog(null,
180:                                styleFont.getFont(),
181:                                "Select the required font!", "Sample text");
182:                        fcd.setLocationRelativeTo(this );
183:                        Font newFont = fcd.showDialog();
184:                        if (newFont != null) {
185:                            styleFont.setFont(newFont);
186:                            currentStyle.setStyle(XStyle.FONT_FACE, newFont
187:                                    .getFamily());
188:                            currentStyle.setStyle(XStyle.FONT_SIZE, newFont
189:                                    .getSize());
190:                            currentStyle.setStyle(XStyle.FONT_WEIGHT, newFont
191:                                    .isBold() ? 1 : 0);
192:                            currentStyle.setStyle(XStyle.FONT_ITALIC, newFont
193:                                    .isItalic() ? 1 : 0);
194:                        }
195:                    }
196:                }
197:            }
198:
199:            /**
200:             * Adds a button for the dialog
201:             * @param panel the panel to which the button will be added
202:             * @param caption the button caption
203:             * @param command the command name
204:             * @param isEnabled true to enable the button
205:             * @return the new button
206:             */
207:            private JButton setupButton(JPanel panel, String caption,
208:                    String command, boolean isEnabled) {
209:                JButton btn = new JButton(caption);
210:                btn.addActionListener(this );
211:                btn.setPreferredSize(new Dimension(100, 25));
212:                panel.add(btn);
213:
214:                return btn;
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.