Source Code Cross Referenced for DefaultTitleComponent.java in  » Swing-Library » wizard-framework » org » pietschy » wizard » 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 » Swing Library » wizard framework » org.pietschy.wizard 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Wizard Framework
003:         * Copyright 2004 - 2005 Andrew Pietsch
004:         *
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         *
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         *
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
018:         *
019:         * $Id: DefaultTitleComponent.java,v 1.4 2005/05/16 23:06:57 pietschy Exp $
020:         */package org.pietschy.wizard;
021:
022:        import javax.swing.*;
023:        import java.beans.PropertyChangeListener;
024:        import java.beans.PropertyChangeEvent;
025:        import java.awt.*;
026:        import java.util.Iterator;
027:
028:        /**
029:         * This class displays the details of the current {@link WizardStep}.  It displays the steps name, summary
030:         * and icon.  During construction, the title component iterates over all of the wizards steps to determine
031:         * its appropriate size.
032:         */
033:        public class DefaultTitleComponent extends JPanel {
034:            private static final Color COLOR_GRAY_230 = new Color(230, 230, 230);
035:
036:            private JLabel title;
037:            private JEditorPane summary;
038:            private JLabel iconLabel;
039:
040:            private WizardModel model;
041:
042:            private boolean gradientBackground = false;
043:            private Color fadeColor = COLOR_GRAY_230;
044:
045:            protected DefaultTitleComponent(Wizard wizard) {
046:                model = wizard.getModel();
047:
048:                setLayout(new BorderLayout());
049:
050:                JPanel p = new JPanel(new BorderLayout());
051:                p.setBackground(Color.WHITE);
052:                title = new JLabel();
053:                title.setFont(title.getFont().deriveFont(Font.BOLD));
054:
055:                summary = new HTMLPane(false);
056:                summary.setFont(title.getFont().deriveFont(Font.PLAIN));
057:                summary.setEditable(false);
058:                summary.setEnabled(false);
059:                summary.setForeground(Color.BLACK);
060:                summary.setDisabledTextColor(Color.BLACK);
061:                summary.setBorder(BorderFactory.createEmptyBorder(
062:                        Wizard.BORDER_WIDTH / 2, Wizard.BORDER_WIDTH, 0,
063:                        Wizard.BORDER_WIDTH));
064:
065:                // lock in the preferred size
066:                summary.setText("<html>Blah</html>");
067:                Dimension preferredSize = summary.getPreferredSize();
068:                preferredSize.width = 0;
069:                preferredSize.height *= 2;
070:                summary.setPreferredSize(preferredSize);
071:
072:                // determine the largest icon size.
073:                int maxIconHeight = 0;
074:                int maxIconWidth = 0;
075:                for (Iterator iter = model.stepIterator(); iter.hasNext();) {
076:                    Icon icon = ((WizardStep) iter.next()).getIcon();
077:                    if (icon != null) {
078:                        maxIconWidth = Math.max(maxIconWidth, icon
079:                                .getIconWidth());
080:                        maxIconHeight = Math.max(maxIconHeight, icon
081:                                .getIconHeight());
082:                    }
083:                }
084:
085:                iconLabel = new JLabel();
086:                Dimension maximumSize = new Dimension(maxIconWidth,
087:                        maxIconHeight);
088:                iconLabel.setMaximumSize(maximumSize);
089:                iconLabel.setPreferredSize(maximumSize);
090:                if (iconLabel.getComponentOrientation().isLeftToRight())
091:                    iconLabel.setHorizontalAlignment(SwingConstants.RIGHT);
092:                else
093:                    iconLabel.setHorizontalAlignment(SwingConstants.LEFT);
094:                iconLabel.setVerticalAlignment(SwingConstants.CENTER);
095:
096:                p.add(title, BorderLayout.PAGE_START);
097:                p.add(summary, BorderLayout.CENTER);
098:                p.setOpaque(false);
099:
100:                add(p, BorderLayout.CENTER);
101:                add(iconLabel, BorderLayout.LINE_END);
102:
103:                setOpaque(true);
104:                setBackground(Color.WHITE);
105:
106:                setBorder(BorderFactory.createCompoundBorder(BorderFactory
107:                        .createEtchedBorder(), BorderFactory.createEmptyBorder(
108:                        Wizard.BORDER_WIDTH, Wizard.BORDER_WIDTH,
109:                        Wizard.BORDER_WIDTH, Wizard.BORDER_WIDTH)));
110:
111:                model.addPropertyChangeListener(new PropertyChangeListener() {
112:                    public void propertyChange(PropertyChangeEvent evt) {
113:                        if (evt.getPropertyName().equals("activeStep")) {
114:                            WizardStep activeStep = DefaultTitleComponent.this .model
115:                                    .getActiveStep();
116:                            title.setText(activeStep.getName());
117:                            summary.setText(activeStep.getSummary());
118:                            iconLabel.setIcon(activeStep.getIcon());
119:                        }
120:                    }
121:                });
122:            }
123:
124:            /**
125:             * Checks if the title is using a gradient background.  Subclasses can control the appearance of the
126:             * gradient by overriding {@link #prepareGradient()}.
127:             *
128:             * @return <tt>true</tt> if the background will use a gradient, <tt>false</tt> if the background will be painted
129:             * using the background color.
130:             * @see #prepareGradient()
131:             */
132:            public boolean isGradientBackground() {
133:                return gradientBackground;
134:            }
135:
136:            /**
137:             * Configures the title to use a gradient background.  Subclasses can control the appearance of the
138:             * gradient by overriding {@link #prepareGradient()}.
139:             *
140:             * @param gradientBackground <tt>true</tt> to paint a gradient background.
141:             * @see #prepareGradient()
142:             */
143:            public void setGradientBackground(boolean gradientBackground) {
144:                this .gradientBackground = gradientBackground;
145:            }
146:
147:            protected void paintComponent(Graphics g) {
148:                if (isGradientBackground()) {
149:                    Paint gradientPaint = prepareGradient();
150:
151:                    Graphics2D g2 = (Graphics2D) g;
152:                    Paint oldPaint = g2.getPaint();
153:
154:                    g2.setPaint(gradientPaint);
155:                    g2.fillRect(0, 0, getWidth(), getHeight());
156:                    g2.setPaint(oldPaint);
157:                } else {
158:                    super .paintComponent(g);
159:                }
160:            }
161:
162:            /**
163:             * Prepares the background paint for the component.  By default it returns a {@link java.awt.GradientPaint} as
164:             * per the following.
165:             * <pre>
166:             * new GradientPaint(getWidth()/2, 0, Color.WHITE,
167:             *                   getWidth(), getHeight(), COLOR_GRAY_230))
168:             * </pre>
169:             *
170:             * If this method returns null, the component will be filled with the current backgrount color.
171:             *
172:             * @return the background paint to use for this component or <tt>null</tt> to use the default background color.
173:             */
174:            protected Paint prepareGradient() {
175:                return new GradientPaint(getWidth() / 2, 0, getBackground(),
176:                        getWidth(), getHeight(), getFadeColor());
177:            }
178:
179:            /**
180:             * Gets the color the gradient will fade to.  By default this is gray(230,230,230).
181:             * @return the second color of the gradient.  The first color is the background of the component.
182:             */
183:            private Color getFadeColor() {
184:                return fadeColor;
185:            }
186:
187:            /**
188:             * Sets the color the gradient will fade to.
189:             * @param fadeColor the second color of the gradient.  The first color is the background of the component.
190:             */
191:            public void setFadeColor(Color fadeColor) {
192:                this.fadeColor = fadeColor;
193:            }
194:
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.