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 / DefaultJShowTroubledPackagesAndAskContinuePanel.java @ 41804

History | View | Annotate | Download (4.56 KB)

1 40634 jjdelcerro
/**
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.JShowPackageStatusAndAskContinuePanel;
45
46
public class DefaultJShowTroubledPackagesAndAskContinuePanel extends
47
        JShowPackageStatusAndAskContinuePanel implements ActionListener {
48
49
        private static final long serialVersionUID = -3142143854199963997L;
50
        private List<String> packages;
51
        private boolean doCancel = true;
52
        DefaultSwingInstallerManager swingInstallerManager;
53
54
        public DefaultJShowTroubledPackagesAndAskContinuePanel(
55
                        SwingInstallerManager manager, List<PackageInfo> packages,
56
                        String message) {
57
                this.swingInstallerManager = (DefaultSwingInstallerManager) manager;
58
                this.buildPackageList(packages);
59
                this.createUI(manager, message);
60
        }
61
62
        private void buildPackageList(List<PackageInfo> packages) {
63
                this.packages = new ArrayList<String>();
64
                for (int i = 0; i < packages.size(); i++) {
65
                        PackageInfo pkg = packages.get(i);
66
            this.packages.add(pkg.getName() + " (" + pkg.getDependencies().toString() + ")");
67
                }
68
        }
69
70
        private void createUI(SwingInstallerManager manager, String message) {
71
                this.setLayout(new BorderLayout());
72
73
                JButton cancelButton = new JButton(swingInstallerManager
74
                                .getText("_cancel"));
75
                cancelButton.setActionCommand("cancel");
76
                cancelButton.addActionListener(this);
77
                //
78
                final JButton continueButton = new JButton(swingInstallerManager
79
                                .getText("_continue"));
80
                continueButton.setActionCommand("continue");
81
                continueButton.addActionListener(this);
82
83
                JList list = new JList(this.packages.toArray());
84
85
                JScrollPane listScroller = new JScrollPane(list);
86
                listScroller.setPreferredSize(new Dimension(250, 80));
87
                listScroller.setAlignmentX(LEFT_ALIGNMENT);
88
89
                JPanel listPane = new JPanel();
90
                listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
91
92
                String html_msg = getHtmlText(message);
93
                JLabel label = new JLabel(html_msg);
94
                label.setLabelFor(list);
95
                listPane.add(label);
96
                listPane.add(Box.createRigidArea(new Dimension(0, 5)));
97
                listPane.add(listScroller);
98
                listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
99
100
                JPanel buttonPane = new JPanel();
101
                buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
102
                buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
103
                buttonPane.add(Box.createHorizontalGlue());
104
                buttonPane.add(cancelButton);
105
                buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
106
                buttonPane.add(continueButton);
107
108
                this.add(listPane, BorderLayout.CENTER);
109
                this.add(buttonPane, BorderLayout.PAGE_END);
110
111
                this.setPreferredSize(new Dimension(500, 300));
112
        }
113
114
115
        /*
116
         * Utility method to HTML code (this allows multiline in Swing
117
         * components)
118
         */
119
    public static String getHtmlText(String txt) {
120
        String resp = txt.replace("\n", "<br><br>");
121
        resp = "<html>" + resp + "</html>";
122
        return resp;
123
    }
124
125
    @Override
126
        public boolean cancelled() {
127
                return doCancel;
128
        }
129
130
        @Override
131
        public boolean needShow() {
132
                return this.packages.size() > 0;
133
        }
134
135
        public void actionPerformed(ActionEvent e) {
136
                if ("cancel".equals(e.getActionCommand())) {
137
                        doCancel = true;
138
                } else {
139
                        doCancel = false;
140
                }
141
                this.setVisible(false);
142
        }
143
}