svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / DefaultJShowPackageStatusAndAskContinuePanel.java @ 35784
History | View | Annotate | Download (3.4 KB)
1 |
package org.gvsig.installer.swing.impl; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.event.ActionListener; |
7 |
import java.util.ArrayList; |
8 |
import java.util.List; |
9 |
|
10 |
import javax.swing.BorderFactory; |
11 |
import javax.swing.Box; |
12 |
import javax.swing.BoxLayout; |
13 |
import javax.swing.JButton; |
14 |
import javax.swing.JLabel; |
15 |
import javax.swing.JList; |
16 |
import javax.swing.JPanel; |
17 |
import javax.swing.JScrollPane; |
18 |
|
19 |
import org.gvsig.installer.lib.api.InstallerManager; |
20 |
import org.gvsig.installer.lib.api.PackageInfo; |
21 |
import org.gvsig.installer.swing.api.SwingInstallerManager; |
22 |
import org.gvsig.installer.swing.api.execution.JShowPackageStatusAndAskContinuePanel; |
23 |
|
24 |
public class DefaultJShowPackageStatusAndAskContinuePanel extends JShowPackageStatusAndAskContinuePanel implements ActionListener { |
25 |
|
26 |
|
27 |
/**
|
28 |
*
|
29 |
*/
|
30 |
private static final long serialVersionUID = -3142143854199963997L; |
31 |
private List<String> packages; |
32 |
private boolean doCancel = true; |
33 |
|
34 |
public DefaultJShowPackageStatusAndAskContinuePanel(SwingInstallerManager manager, List<PackageInfo> packages, String message) { |
35 |
this.buildPackageList(packages);
|
36 |
this.createUI(manager, message);
|
37 |
} |
38 |
|
39 |
private void buildPackageList(List<PackageInfo> packages) { |
40 |
this.packages = new ArrayList<String>(); |
41 |
for( int i=0 ; i<packages.size(); i++ ) { |
42 |
PackageInfo pkg = packages.get(i); |
43 |
if( !pkg.isOfficial()) {
|
44 |
this.packages.add(pkg.getName()+"(no oficial)"); |
45 |
} else if(!InstallerManager.STATE.FINAL.equalsIgnoreCase(pkg.getState()) ) { |
46 |
this.packages.add(pkg.getName()+ "("+pkg.getState()+")"); |
47 |
} |
48 |
} |
49 |
} |
50 |
|
51 |
private void createUI(SwingInstallerManager manager,String message) { |
52 |
this.setLayout( new BorderLayout()); |
53 |
|
54 |
JButton cancelButton = new JButton("Cancel"); |
55 |
cancelButton.setActionCommand("cancel");
|
56 |
cancelButton.addActionListener(this);
|
57 |
//
|
58 |
final JButton continueButton = new JButton("Continue"); |
59 |
continueButton.setActionCommand("continue");
|
60 |
continueButton.addActionListener(this);
|
61 |
|
62 |
JList list = new JList(this.packages.toArray()); |
63 |
|
64 |
JScrollPane listScroller = new JScrollPane(list); |
65 |
listScroller.setPreferredSize(new Dimension(250, 80)); |
66 |
listScroller.setAlignmentX(LEFT_ALIGNMENT); |
67 |
|
68 |
JPanel listPane = new JPanel(); |
69 |
listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); |
70 |
JLabel label = new JLabel(message); |
71 |
label.setLabelFor(list); |
72 |
listPane.add(label); |
73 |
listPane.add(Box.createRigidArea(new Dimension(0,5))); |
74 |
listPane.add(listScroller); |
75 |
listPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); |
76 |
|
77 |
JPanel buttonPane = new JPanel(); |
78 |
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); |
79 |
buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10)); |
80 |
buttonPane.add(Box.createHorizontalGlue());
|
81 |
buttonPane.add(cancelButton); |
82 |
buttonPane.add(Box.createRigidArea(new Dimension(10, 0))); |
83 |
buttonPane.add(continueButton); |
84 |
|
85 |
this.add(listPane, BorderLayout.CENTER); |
86 |
this.add(buttonPane, BorderLayout.PAGE_END); |
87 |
} |
88 |
|
89 |
public boolean cancelled() { |
90 |
return doCancel;
|
91 |
} |
92 |
|
93 |
public boolean needShow() { |
94 |
return this.packages.size()>0; |
95 |
} |
96 |
|
97 |
public void actionPerformed(ActionEvent e) { |
98 |
if ("cancel".equals(e.getActionCommand())) { |
99 |
doCancel = true;
|
100 |
} else {
|
101 |
doCancel = false;
|
102 |
} |
103 |
this.setVisible(false); |
104 |
} |
105 |
} |