Source Code Cross Referenced for ImgPacksPanel.java in  » Installer » IzPack » com » izforge » izpack » panels » 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 » Installer » IzPack » com.izforge.izpack.panels 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003:         * 
004:         * http://izpack.org/
005:         * http://izpack.codehaus.org/
006:         * 
007:         * Copyright 2004 Volker Friedritz
008:         * Copyright 2002 Marcus Wolschon
009:         * Copyright 2002 Jan Blok
010:         * 
011:         * Licensed under the Apache License, Version 2.0 (the "License");
012:         * you may not use this file except in compliance with the License.
013:         * You may obtain a copy of the License at
014:         * 
015:         *     http://www.apache.org/licenses/LICENSE-2.0
016:         *     
017:         * Unless required by applicable law or agreed to in writing, software
018:         * distributed under the License is distributed on an "AS IS" BASIS,
019:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020:         * See the License for the specific language governing permissions and
021:         * limitations under the License.
022:         */
023:
024:        package com.izforge.izpack.panels;
025:
026:        import java.awt.Component;
027:        import java.awt.Dimension;
028:        import java.awt.GridBagConstraints;
029:        import java.awt.GridBagLayout;
030:        import java.awt.Insets;
031:        import java.net.URL;
032:        import java.util.HashMap;
033:        import java.util.Iterator;
034:
035:        import javax.swing.BorderFactory;
036:        import javax.swing.Box;
037:        import javax.swing.ImageIcon;
038:        import javax.swing.JLabel;
039:        import javax.swing.JScrollPane;
040:        import javax.swing.event.ListSelectionEvent;
041:
042:        import com.izforge.izpack.Pack;
043:        import com.izforge.izpack.installer.InstallData;
044:        import com.izforge.izpack.installer.InstallerFrame;
045:        import com.izforge.izpack.installer.ResourceManager;
046:        import com.izforge.izpack.util.IoHelper;
047:
048:        /**
049:         * The ImgPacks panel class. Allows the packages selection with a small picture displayed for every
050:         * pack. This new version combines the old PacksPanel and the ImgPacksPanel so that the positive
051:         * characteristics of both are combined. This class handles only the layout and some related stuff.
052:         * Common stuff are handled by the base class.
053:         * 
054:         * @author Julien Ponge
055:         * @author Volker Friedritz
056:         * @author Klaus Bartz
057:         */
058:        public class ImgPacksPanel extends PacksPanelBase {
059:
060:            /**
061:             * 
062:             */
063:            private static final long serialVersionUID = 3977858492633659444L;
064:
065:            /** The images to display. */
066:            private HashMap<String, ImageIcon> images;
067:
068:            /** The img label. */
069:            private JLabel imgLabel;
070:
071:            /**
072:             * The constructor.
073:             * 
074:             * @param parent The parent window.
075:             * @param idata The installation data.
076:             */
077:            public ImgPacksPanel(InstallerFrame parent, InstallData idata) {
078:                super (parent, idata);
079:            }
080:
081:            /*
082:             * (non-Javadoc)
083:             * 
084:             * @see com.izforge.izpack.panels.PacksPanelBase#createNormalLayout()
085:             */
086:            protected void createNormalLayout() {
087:                preLoadImages();
088:                GridBagLayout layout = new GridBagLayout();
089:                GridBagConstraints gbConstraints = new GridBagConstraints();
090:                setLayout(layout);
091:
092:                // Create constraint for first component as standard constraint.
093:                parent.buildConstraints(gbConstraints, 0, 0, 1, 1, 0.25, 0.0);
094:                gbConstraints.insets = new Insets(5, 5, 5, 5);
095:                gbConstraints.anchor = GridBagConstraints.WEST;
096:                // Create the info label.
097:                createLabel("PacksPanel.info", "preferences", layout,
098:                        gbConstraints);
099:
100:                // Create the snap label.
101:                parent.buildConstraints(gbConstraints, 1, 0, 1, 1, 0.50, 0.0);
102:                createLabel("ImgPacksPanel.snap", "tip", layout, gbConstraints);
103:
104:                // Create packs table with a scroller.
105:                tableScroller = new JScrollPane();
106:                parent.buildConstraints(gbConstraints, 0, 1, 1, 2, 0.50, 0.0);
107:                gbConstraints.fill = GridBagConstraints.BOTH;
108:                packsTable = createPacksTable(250, tableScroller, layout,
109:                        gbConstraints);
110:
111:                // Create the image label with a scroller.
112:                // Use the image of the first pack having an image as initial image
113:                Iterator pack_it = idata.availablePacks.iterator();
114:                Pack firstImgPack = null;
115:                boolean imgFound = false;
116:                while (!imgFound && pack_it.hasNext()) {
117:                    firstImgPack = (Pack) pack_it.next();
118:                    imgFound = firstImgPack.packImgId != null;
119:                }
120:                if (imgFound) {
121:                    imgLabel = new JLabel(images.get(firstImgPack.packImgId));
122:                } else {
123:                    imgLabel = new JLabel();
124:                }
125:                JScrollPane imgScroller = new JScrollPane(imgLabel);
126:                imgScroller.setPreferredSize(getPreferredSizeFromImages());
127:                parent.buildConstraints(gbConstraints, 1, 1, 1, 1, 0.5, 1.0);
128:                layout.addLayoutComponent(imgScroller, gbConstraints);
129:                add(imgScroller);
130:
131:                // Create a vertical strut.
132:
133:                Component strut = Box.createVerticalStrut(20);
134:                parent.buildConstraints(gbConstraints, 1, 2, 1, 3, 0.0, 0.0);
135:                layout.addLayoutComponent(strut, gbConstraints);
136:                add(strut);
137:
138:                // Create the dependency area with a scroller.
139:                if (dependenciesExist) {
140:                    JScrollPane depScroller = new JScrollPane();
141:                    depScroller.setPreferredSize(new Dimension(250, 40));
142:                    parent.buildConstraints(gbConstraints, 0, 3, 1, 1, 0.50,
143:                            0.50);
144:                    dependencyArea = createTextArea(
145:                            "ImgPacksPanel.dependencyList", depScroller,
146:                            layout, gbConstraints);
147:                }
148:
149:                // Create the description area with a scroller.
150:                JScrollPane descriptionScroller = new JScrollPane();
151:                descriptionScroller.setPreferredSize(new Dimension(200, 60));
152:                descriptionScroller
153:                        .setBorder(BorderFactory.createEmptyBorder());
154:
155:                parent.buildConstraints(gbConstraints, 1, 3, 1, 1, 0.50, 0.50);
156:                descriptionArea = createTextArea("PacksPanel.description",
157:                        descriptionScroller, layout, gbConstraints);
158:                // Create the tip label.
159:                parent.buildConstraints(gbConstraints, 0, 4, 2, 1, 0.0, 0.0);
160:                createLabel("PacksPanel.tip", "tip", layout, gbConstraints);
161:                // Create the space label.
162:                parent.buildConstraints(gbConstraints, 0, 5, 2, 1, 0.0, 0.0);
163:                spaceLabel = createPanelWithLabel("PacksPanel.space", layout,
164:                        gbConstraints);
165:                if (IoHelper.supported("getFreeSpace")) { // Create the free space label only if free space is supported.
166:                    parent
167:                            .buildConstraints(gbConstraints, 0, 6, 2, 1, 0.0,
168:                                    0.0);
169:                    freeSpaceLabel = createPanelWithLabel(
170:                            "PacksPanel.freespace", layout, gbConstraints);
171:                }
172:
173:            }
174:
175:            /** Pre-loads the images. */
176:            private void preLoadImages() {
177:                int size = idata.availablePacks.size();
178:                images = new HashMap<String, ImageIcon>(size);
179:                Iterator pack_it = idata.availablePacks.iterator();
180:                while (pack_it.hasNext()) {
181:                    Pack pack = (Pack) pack_it.next();
182:                    if (pack.packImgId != null) {
183:                        try {
184:                            URL url = ResourceManager.getInstance().getURL(
185:                                    pack.packImgId);
186:                            ImageIcon img = new ImageIcon(url);
187:                            images.put(pack.packImgId, img);
188:                        } catch (Exception err) {
189:                            err.printStackTrace();
190:                        }
191:                    }
192:                }
193:            }
194:
195:            /**
196:             * Try to find a good preferredSize for imgScroller by checking all loaded images' width and
197:             * height.
198:             */
199:            private Dimension getPreferredSizeFromImages() {
200:                int maxWidth = 80;
201:                int maxHeight = 60;
202:                ImageIcon icon;
203:
204:                for (ImageIcon imageIcon : images.values()) {
205:                    icon = imageIcon;
206:                    maxWidth = Math.max(maxWidth, icon.getIconWidth());
207:                    maxHeight = Math.max(maxHeight, icon.getIconHeight());
208:                }
209:
210:                maxWidth = Math.min(maxWidth + 20, idata.guiPrefs.width - 150);
211:                maxHeight = Math.min(maxHeight + 20,
212:                        idata.guiPrefs.height - 150);
213:
214:                return new Dimension(maxWidth, maxHeight);
215:            }
216:
217:            /*
218:             * (non-Javadoc)
219:             * 
220:             * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
221:             */
222:            public void valueChanged(ListSelectionEvent e) {
223:                // this MUST be called before calling the super's valueChanged() since
224:                // that method refreshes the tablemodel and thus deselects the 
225:                // just selected row
226:                int i = packsTable.getSelectedRow();
227:                super .valueChanged(e);
228:                if (i < 0) {
229:                    return;
230:                }
231:                if (i >= 0) {
232:                    Pack pack = (Pack) idata.availablePacks.get(i);
233:                    imgLabel.setIcon(images.get(pack.packImgId));
234:                }
235:            }
236:
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.