Source Code Cross Referenced for Gui4jCardLayout.java in  » XML-UI » gui4j » org » gui4j » component » 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 » gui4j » org.gui4j.component 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.gui4j.component;
002:
003:        import java.awt.CardLayout;
004:        import java.util.ArrayList;
005:        import java.util.Iterator;
006:        import java.util.List;
007:
008:        import javax.swing.JPanel;
009:
010:        import org.apache.commons.logging.Log;
011:        import org.apache.commons.logging.LogFactory;
012:        import org.gui4j.Gui4jCallBase;
013:        import org.gui4j.core.Gui4jCall;
014:        import org.gui4j.core.Gui4jComponentContainer;
015:        import org.gui4j.core.Gui4jComponentInstance;
016:        import org.gui4j.core.Gui4jQualifiedComponent;
017:        import org.gui4j.core.Gui4jSwingContainer;
018:        import org.gui4j.core.Gui4jThreadManager;
019:        import org.gui4j.event.Gui4jEventListener;
020:
021:        public final class Gui4jCardLayout extends Gui4jJComponent {
022:            private static final String DFLT = "dflt";
023:
024:            protected static final Log mLogger = LogFactory
025:                    .getLog(Gui4jCardLayout.class);
026:            protected final List mConditions; // List(Gui4jCall)
027:            protected final List mGui4jComponents; // List(Gui4jComponentInPath)
028:            protected final Gui4jQualifiedComponent mGui4jComponentDefault;
029:
030:            private Gui4jCall[] mRefresh;
031:
032:            /**
033:             * Constructor for Gui4jSwitch.
034:             * @param gui4jComponentContainer
035:             * @param id
036:             * @param gui4jComponentDefault
037:             */
038:            public Gui4jCardLayout(
039:                    Gui4jComponentContainer gui4jComponentContainer, String id,
040:                    Gui4jQualifiedComponent gui4jComponentDefault) {
041:                super (gui4jComponentContainer, JPanel.class, id);
042:                mConditions = new ArrayList();
043:                mGui4jComponents = new ArrayList();
044:                assert gui4jComponentDefault != null;
045:                mGui4jComponentDefault = gui4jComponentDefault;
046:            }
047:
048:            public void setRefresh(Gui4jCall[] refresh) {
049:                mRefresh = refresh;
050:            }
051:
052:            public void addPlacement(Gui4jCall condition,
053:                    Gui4jQualifiedComponent gui4jComponentInPath) {
054:                assert condition != null;
055:                assert gui4jComponentInPath != null;
056:                mConditions.add(condition);
057:                mGui4jComponents.add(gui4jComponentInPath);
058:            }
059:
060:            /* (non-Javadoc)
061:             * @see org.gui4j.core.Gui4jAbstractComponent#createComponentInstance(org.gui4j.core.Gui4jSwingContainer, org.gui4j.Gui4jCallBase, org.gui4j.core.Gui4jQualifiedComponent)
062:             */
063:            protected Gui4jComponentInstance createComponentInstance(
064:                    Gui4jSwingContainer gui4jSwingContainer,
065:                    Gui4jCallBase gui4jCallBase,
066:                    Gui4jQualifiedComponent gui4jComponentInPath) {
067:                CardLayout cardLayout = new CardLayout();
068:                JPanel panel = new JPanel(cardLayout);
069:                Gui4jComponentInstance gui4jComponentInstance = new Gui4jComponentInstance(
070:                        gui4jSwingContainer, panel, gui4jComponentInPath);
071:                {
072:                    Gui4jComponentInstance subInstance = gui4jSwingContainer
073:                            .getGui4jComponentInstance(gui4jComponentInPath
074:                                    .getGui4jComponentPath(),
075:                                    mGui4jComponentDefault);
076:                    panel.add(subInstance.getComponent(), DFLT);
077:                }
078:                int idx = 0;
079:                for (Iterator it = mGui4jComponents.iterator(); it.hasNext(); idx++) {
080:                    Gui4jQualifiedComponent qualifiedComponent = (Gui4jQualifiedComponent) it
081:                            .next();
082:                    if (!qualifiedComponent.equals(mGui4jComponentDefault)) {
083:                        Gui4jComponentInstance subInstance = gui4jSwingContainer
084:                                .getGui4jComponentInstance(gui4jComponentInPath
085:                                        .getGui4jComponentPath(),
086:                                        qualifiedComponent);
087:                        panel.add(subInstance.getComponent(), "" + idx);
088:                    }
089:                }
090:                SwitchListener listener = new SwitchListener(
091:                        gui4jComponentInstance);
092:                registerEvents(gui4jSwingContainer, gui4jCallBase, mRefresh,
093:                        listener);
094:                listener.eventOccured();
095:                return gui4jComponentInstance;
096:            }
097:
098:            class SwitchListener implements  Gui4jEventListener {
099:                private final Gui4jComponentInstance mGui4jComponentInstance;
100:                private final Gui4jCallBase mGui4jCallBase;
101:
102:                // private final Gui4jSwingContainer mGui4jSwingContainer;
103:
104:                public SwitchListener(
105:                        Gui4jComponentInstance gui4jComponentInstance) {
106:                    this .mGui4jComponentInstance = gui4jComponentInstance;
107:                    this .mGui4jCallBase = gui4jComponentInstance
108:                            .getGui4jCallBase();
109:                    // this.mGui4jSwingContainer =
110:                    // gui4jComponentInstance.getGui4jSwingContainer();
111:                }
112:
113:                public void eventOccured() {
114:                    // evaluate conditions in given order and display first
115:                    // element where the condition is valid
116:                    boolean found = false;
117:                    int idx = 0;
118:                    for (Iterator itCondition = mConditions.iterator(), itComponent = mGui4jComponents
119:                            .iterator(); !found && itCondition.hasNext(); idx++) {
120:                        Gui4jCall condition = (Gui4jCall) itCondition.next();
121:                        Gui4jQualifiedComponent gui4jComponentInPath = (Gui4jQualifiedComponent) itComponent
122:                                .next();
123:                        Boolean result = (Boolean) condition.getValueNoParams(
124:                                mGui4jCallBase, Boolean.FALSE);
125:                        if (Boolean.TRUE.equals(result)) {
126:                            useGui4jComponent(idx, gui4jComponentInPath);
127:                            found = true;
128:                        }
129:                    }
130:                    if (!found) {
131:                        useGui4jComponent(idx, mGui4jComponentDefault);
132:                    }
133:                }
134:
135:                private void useGui4jComponent(int idx,
136:                        Gui4jQualifiedComponent gui4jComponentInPath) {
137:                    mLogger.debug("Using component "
138:                            + gui4jComponentInPath.getQualifiedId()
139:                            + " for cardLayout with id " + getId());
140:                    final JPanel panel = (JPanel) mGui4jComponentInstance
141:                            .getComponent();
142:                    final CardLayout cardLayout = (CardLayout) panel
143:                            .getLayout();
144:                    final String cardName = gui4jComponentInPath
145:                            .equals(mGui4jComponentDefault) ? DFLT : "" + idx;
146:                    Runnable run = new Runnable() {
147:                        public void run() {
148:                            cardLayout.show(panel, cardName);
149:                        }
150:                    };
151:                    Gui4jThreadManager.executeInSwingThreadAndWait(run);
152:                }
153:
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.