root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / com / izforge / izpack / panels / ImgPacksPanel.java @ 15280
History | View | Annotate | Download (7.48 KB)
1 |
/*
|
---|---|
2 |
* $Id: ImgPacksPanel.java,v 1.1 2006/06/14 07:29:07 cesar Exp $
|
3 |
* IzPack
|
4 |
* Copyright (C) 2001-2004 Julien Ponge, Volker Friedritz
|
5 |
*
|
6 |
* File : ImgPacksPanel.java
|
7 |
* Description : A panel to select the packs to install.
|
8 |
* Author's email : julien@izforge.com
|
9 |
* Author's email : volker.friedritz@gmx.de
|
10 |
* Author's Website : http://www.izforge.com
|
11 |
*
|
12 |
* Portions are Copyright (C) 2002 Marcus Wolschon
|
13 |
* Portions are Copyright (C) 2002 Jan Blok (jblok@profdata.nl - PDM - www.profdata.nl)
|
14 |
*
|
15 |
* This program is free software; you can redistribute it and/or
|
16 |
* modify it under the terms of the GNU General Public License
|
17 |
* as published by the Free Software Foundation; either version 2
|
18 |
* of the License, or any later version.
|
19 |
*
|
20 |
* This program is distributed in the hope that it will be useful,
|
21 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
* GNU General Public License for more details.
|
24 |
*
|
25 |
* You should have received a copy of the GNU General Public License
|
26 |
* along with this program; if not, write to the Free Software
|
27 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
28 |
*/
|
29 |
package com.izforge.izpack.panels; |
30 |
|
31 |
import java.awt.Component; |
32 |
import java.awt.Dimension; |
33 |
import java.awt.GridBagConstraints; |
34 |
import java.awt.GridBagLayout; |
35 |
import java.awt.Insets; |
36 |
import java.net.URL; |
37 |
import java.util.ArrayList; |
38 |
import java.util.Iterator; |
39 |
|
40 |
import javax.swing.Box; |
41 |
import javax.swing.ImageIcon; |
42 |
import javax.swing.JLabel; |
43 |
import javax.swing.JScrollPane; |
44 |
import javax.swing.event.ListSelectionEvent; |
45 |
|
46 |
import com.izforge.izpack.installer.InstallData; |
47 |
import com.izforge.izpack.installer.InstallerFrame; |
48 |
import com.izforge.izpack.installer.ResourceManager; |
49 |
import com.izforge.izpack.util.IoHelper; |
50 |
|
51 |
/**
|
52 |
* The ImgPacks panel class. Allows the packages selection with a small picture
|
53 |
* displayed for every pack.
|
54 |
* This new version combines the old PacksPanel and the ImgPacksPanel so that
|
55 |
* the positive characteristics of both are combined.
|
56 |
* This class handles only the layout and some related stuff. Common
|
57 |
* stuff are handled by the base class.
|
58 |
*
|
59 |
* @author Julien Ponge
|
60 |
* @author Volker Friedritz
|
61 |
* @author Klaus Bartz
|
62 |
*/
|
63 |
public class ImgPacksPanel extends PacksPanelBase |
64 |
{ |
65 |
|
66 |
/** The images to display. */
|
67 |
private ArrayList images; |
68 |
|
69 |
/** The description scroll. */
|
70 |
private JScrollPane descriptionScroller; |
71 |
|
72 |
/** The img label. */
|
73 |
private JLabel imgLabel; |
74 |
|
75 |
/** The current image index. */
|
76 |
private int index = 0; |
77 |
|
78 |
/** The layout. */
|
79 |
private GridBagLayout layout; |
80 |
|
81 |
/** The layout constraints. */
|
82 |
private GridBagConstraints gbConstraints; |
83 |
|
84 |
/**
|
85 |
* The constructor.
|
86 |
*
|
87 |
* @param parent The parent window.
|
88 |
* @param idata The installation data.
|
89 |
*/
|
90 |
public ImgPacksPanel(InstallerFrame parent, InstallData idata)
|
91 |
{ |
92 |
super(parent, idata);
|
93 |
} |
94 |
|
95 |
/* (non-Javadoc)
|
96 |
* @see com.izforge.izpack.panels.PacksPanelBase#createNormalLayout()
|
97 |
*/
|
98 |
protected void createNormalLayout() |
99 |
{ |
100 |
preLoadImages(); |
101 |
layout = new GridBagLayout(); |
102 |
gbConstraints = new GridBagConstraints(); |
103 |
setLayout(layout); |
104 |
|
105 |
// Create constraint for first component as standard constraint.
|
106 |
parent.buildConstraints(gbConstraints, 0, 0, 1, 1, 0.25, 0.0); |
107 |
gbConstraints.insets = new Insets(5, 5, 5, 5); |
108 |
gbConstraints.anchor = GridBagConstraints.WEST;
|
109 |
// Create the info label.
|
110 |
createLabel( "PacksPanel.info", "preferences", layout, gbConstraints); |
111 |
|
112 |
// Create the snap label.
|
113 |
parent.buildConstraints(gbConstraints, 1, 0, 1, 1, 0.50, 0.0); |
114 |
createLabel( "ImgPacksPanel.snap", "tip", layout, gbConstraints); |
115 |
|
116 |
// Create packs table with a scroller.
|
117 |
tableScroller = new JScrollPane(); |
118 |
parent.buildConstraints(gbConstraints, 0, 1, 1, 2, 0.50, 0.0); |
119 |
gbConstraints.fill = GridBagConstraints.BOTH;
|
120 |
packsTable = createPacksTable(250, tableScroller, layout, gbConstraints );
|
121 |
|
122 |
// Create the image label with a scroller.
|
123 |
imgLabel = new JLabel((ImageIcon) images.get(0)); |
124 |
JScrollPane imgScroller = new JScrollPane(imgLabel); |
125 |
imgScroller.setPreferredSize(getPreferredSizeFromImages()); |
126 |
parent.buildConstraints(gbConstraints, 1, 1, 1, 1, 0.5, 1.0); |
127 |
layout.addLayoutComponent(imgScroller, gbConstraints); |
128 |
add(imgScroller); |
129 |
|
130 |
// Create a vertical strut.
|
131 |
|
132 |
Component strut = Box.createVerticalStrut(20); |
133 |
parent.buildConstraints(gbConstraints, 1, 2, 1, 3, 0.0, 0.0); |
134 |
layout.addLayoutComponent(strut, gbConstraints); |
135 |
add(strut); |
136 |
|
137 |
// Create the dependency area with a scroller.
|
138 |
if( dependenciesExist )
|
139 |
{ |
140 |
JScrollPane depScroller = new JScrollPane(); |
141 |
depScroller.setPreferredSize(new Dimension(250, 40)); |
142 |
parent.buildConstraints(gbConstraints, 0, 3, 1, 1, 0.50, 0.50); |
143 |
dependencyArea = createTextArea("ImgPacksPanel.dependencyList",
|
144 |
depScroller, layout, gbConstraints ); |
145 |
} |
146 |
|
147 |
|
148 |
// Create the description area with a scroller.
|
149 |
descriptionScroller = new JScrollPane(); |
150 |
descriptionScroller.setPreferredSize(new Dimension(200, 60)); |
151 |
|
152 |
parent.buildConstraints(gbConstraints, 1, 3, 1, 1, 0.50, 0.50); |
153 |
descriptionArea = createTextArea("PacksPanel.description",
|
154 |
descriptionScroller, layout, gbConstraints ); |
155 |
// Create the tip label.
|
156 |
parent.buildConstraints(gbConstraints, 0, 4, 2, 1, 0.0, 0.0); |
157 |
createLabel( "PacksPanel.tip", "tip", layout, gbConstraints); |
158 |
// Create the space label.
|
159 |
parent.buildConstraints(gbConstraints, 0, 5, 2, 1, 0.0, 0.0); |
160 |
spaceLabel = createPanelWithLabel( "PacksPanel.space", layout, gbConstraints );
|
161 |
if( IoHelper.supported("getFreeSpace")) |
162 |
{ // Create the free space label only if free space is supported.
|
163 |
parent.buildConstraints(gbConstraints, 0, 6, 2, 1, 0.0, 0.0); |
164 |
freeSpaceLabel = createPanelWithLabel( "PacksPanel.freespace", layout, gbConstraints );
|
165 |
} |
166 |
|
167 |
} |
168 |
/** Pre-loads the images. */
|
169 |
private void preLoadImages() |
170 |
{ |
171 |
int size = idata.availablePacks.size();
|
172 |
images = new ArrayList(size); |
173 |
for (int i = 0; i < size; i++) |
174 |
try
|
175 |
{ |
176 |
URL url =
|
177 |
ResourceManager.getInstance().getURL("ImgPacksPanel.img." + i);
|
178 |
ImageIcon img = new ImageIcon(url); |
179 |
images.add(img); |
180 |
} catch (Exception err) |
181 |
{ |
182 |
err.printStackTrace(); |
183 |
} |
184 |
} |
185 |
|
186 |
/** Try to find a good preferredSize for imgScroller by checking all
|
187 |
* loaded images' width and height.
|
188 |
*/
|
189 |
private Dimension getPreferredSizeFromImages() |
190 |
{ |
191 |
int maxWidth = 80, maxHeight = 60; |
192 |
ImageIcon icon;
|
193 |
|
194 |
for (Iterator it = images.iterator(); it.hasNext(); ) |
195 |
{ |
196 |
icon = (ImageIcon) it.next();
|
197 |
maxWidth = Math.max(maxWidth, icon.getIconWidth());
|
198 |
maxHeight = Math.max(maxHeight, icon.getIconHeight());
|
199 |
} |
200 |
|
201 |
maxWidth = Math.min(maxWidth + 20, idata.guiPrefs.width - 150); |
202 |
maxHeight = Math.min(maxHeight + 20, idata.guiPrefs.height - 150); |
203 |
|
204 |
return new Dimension(maxWidth, maxHeight); |
205 |
} |
206 |
|
207 |
/* (non-Javadoc)
|
208 |
* @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
|
209 |
*/
|
210 |
public void valueChanged(ListSelectionEvent e) |
211 |
{ |
212 |
super.valueChanged(e);
|
213 |
int i = packsTable.getSelectedRow();
|
214 |
if( i >= 0 ) |
215 |
imgLabel.setIcon((ImageIcon) images.get(i));
|
216 |
|
217 |
} |
218 |
|
219 |
|
220 |
|
221 |
} |