Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / DefaultJShowRequiredPackagesAndAskContinuePanel.java @ 40560

History | View | Annotate | Download (4.1 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.installer.swing.impl;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Dimension;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.util.ArrayList;
31
import java.util.List;
32

    
33
import javax.swing.BorderFactory;
34
import javax.swing.Box;
35
import javax.swing.BoxLayout;
36
import javax.swing.JButton;
37
import javax.swing.JLabel;
38
import javax.swing.JList;
39
import javax.swing.JPanel;
40
import javax.swing.JScrollPane;
41

    
42
import org.gvsig.installer.lib.api.PackageInfo;
43
import org.gvsig.installer.swing.api.SwingInstallerManager;
44
import org.gvsig.installer.swing.api.execution.JShowRequiredPackagesAndAskContinuePanel;
45

    
46
public class DefaultJShowRequiredPackagesAndAskContinuePanel extends
47
                JShowRequiredPackagesAndAskContinuePanel implements ActionListener {
48

    
49
        /**
50
         * 
51
         */
52
        private static final long serialVersionUID = 2135985029410816305L;
53
        private List<String> packages;
54
        private boolean doCancel = true;
55

    
56
        public DefaultJShowRequiredPackagesAndAskContinuePanel(
57
                        SwingInstallerManager manager, List<PackageInfo> packages,
58
                        String message) {
59
                this.buildPackageList(packages);
60
                this.createUI(manager, message);
61
        }
62

    
63
        private void buildPackageList(List<PackageInfo> packages) {
64
                this.packages = new ArrayList<String>();
65
                for (int i = 0; i < packages.size(); i++) {
66
                        PackageInfo pkg = packages.get(i);
67
                        this.packages.add(pkg.getName());
68
                }
69
        }
70

    
71
        private void createUI(SwingInstallerManager manager, String message) {
72
                this.setLayout(new BorderLayout());
73

    
74
                JButton cancelButton = new JButton(manager.getText("_cancel"));
75
                cancelButton.setActionCommand("cancel");
76
                cancelButton.addActionListener(this);
77
                //
78
                final JButton continueButton = new JButton(manager.getText("_continue"));
79
                continueButton.setActionCommand("continue");
80
                continueButton.addActionListener(this);
81

    
82
                JList list = new JList(this.packages.toArray());
83

    
84
                JScrollPane listScroller = new JScrollPane(list);
85
                listScroller.setPreferredSize(new Dimension(250, 80));
86
                listScroller.setAlignmentX(LEFT_ALIGNMENT);
87

    
88
                JPanel listPane = new JPanel();
89
                listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
90
                
91
                String html_msg = DefaultJShowPackageStatusAndAskContinuePanel.getHtmlText(message);
92
                JLabel label = new JLabel(html_msg);
93
                label.setLabelFor(list);
94
                listPane.add(label);
95
                listPane.add(Box.createRigidArea(new Dimension(0, 5)));
96
                listPane.add(listScroller);
97
                listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
98

    
99
                JPanel buttonPane = new JPanel();
100
                buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
101
                buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
102
                buttonPane.add(Box.createHorizontalGlue());
103
                buttonPane.add(cancelButton);
104
                buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
105
                buttonPane.add(continueButton);
106

    
107
                this.add(listPane, BorderLayout.CENTER);
108
                this.add(buttonPane, BorderLayout.PAGE_END);
109
        }
110

    
111
        @Override
112
        public boolean cancelled() {
113
                return doCancel;
114
        }
115

    
116
        @Override
117
        public boolean needShow() {
118
                return this.packages.size() > 0;
119
        }
120

    
121
        public void actionPerformed(ActionEvent e) {
122
                if ("cancel".equals(e.getActionCommand())) {
123
                        doCancel = true;
124
                } else {
125
                        doCancel = false;
126
                }
127
                this.setVisible(false);
128
        }
129
}