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 / DefaultJShowPackageStatusAndAskContinuePanel.java @ 40560

History | View | Annotate | Download (5.27 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.InstallerManager;
43
import org.gvsig.installer.lib.api.PackageInfo;
44
import org.gvsig.installer.swing.api.SwingInstallerManager;
45
import org.gvsig.installer.swing.api.execution.JShowPackageStatusAndAskContinuePanel;
46

    
47
public class DefaultJShowPackageStatusAndAskContinuePanel extends
48
                JShowPackageStatusAndAskContinuePanel implements ActionListener {
49

    
50
        private static final long serialVersionUID = -3142143854199963997L;
51
        private List<String> packages;
52
        private boolean doCancel = true;
53
        DefaultSwingInstallerManager swingInstallerManager;
54

    
55
        public DefaultJShowPackageStatusAndAskContinuePanel(
56
                        SwingInstallerManager manager, List<PackageInfo> packages,
57
                        String message) {
58
                this.swingInstallerManager = (DefaultSwingInstallerManager) manager;
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
                        if (!pkg.isOfficial()) {
68
                                this.packages.add(pkg.getName() + " ("
69
                                                + swingInstallerManager.getText("_not_official") + ")");
70
                        } else {
71
                            
72
                            if (InstallerManager.STATE.FINAL.equalsIgnoreCase(pkg.getState())) {
73
                                continue;
74
                            } else if (InstallerManager.STATE.TESTING.equalsIgnoreCase(pkg.getState())) {
75
                                continue;
76
                } else if (pkg.getState().toLowerCase().startsWith(InstallerManager.STATE.RC.toLowerCase())) {
77
                    continue;
78
                } else if (pkg.getState().toLowerCase().startsWith(InstallerManager.STATE.BETA.toLowerCase())) {
79
                    continue;
80
                } else {
81
                    this.packages.add(pkg.getName() + " (" + pkg.getState() + ")");
82
                }
83
                        }
84
                }
85
        }
86

    
87
        private void createUI(SwingInstallerManager manager, String message) {
88
                this.setLayout(new BorderLayout());
89

    
90
                JButton cancelButton = new JButton(swingInstallerManager
91
                                .getText("_cancel"));
92
                cancelButton.setActionCommand("cancel");
93
                cancelButton.addActionListener(this);
94
                //
95
                final JButton continueButton = new JButton(swingInstallerManager
96
                                .getText("_continue"));
97
                continueButton.setActionCommand("continue");
98
                continueButton.addActionListener(this);
99

    
100
                JList list = new JList(this.packages.toArray());
101

    
102
                JScrollPane listScroller = new JScrollPane(list);
103
                listScroller.setPreferredSize(new Dimension(250, 80));
104
                listScroller.setAlignmentX(LEFT_ALIGNMENT);
105

    
106
                JPanel listPane = new JPanel();
107
                listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
108
                
109
                String html_msg = getHtmlText(message);
110
                JLabel label = new JLabel(html_msg);
111
                label.setLabelFor(list);
112
                listPane.add(label);
113
                listPane.add(Box.createRigidArea(new Dimension(0, 5)));
114
                listPane.add(listScroller);
115
                listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
116

    
117
                JPanel buttonPane = new JPanel();
118
                buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
119
                buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
120
                buttonPane.add(Box.createHorizontalGlue());
121
                buttonPane.add(cancelButton);
122
                buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
123
                buttonPane.add(continueButton);
124

    
125
                this.add(listPane, BorderLayout.CENTER);
126
                this.add(buttonPane, BorderLayout.PAGE_END);
127
                
128
                this.setPreferredSize(new Dimension(500, 300));
129
        }
130

    
131

    
132
        /*
133
         * Utility method to HTML code (this allows multiline in Swing
134
         * components)
135
         */
136
    public static String getHtmlText(String txt) {
137
        String resp = txt.replace("\n", "<br><br>");
138
        resp = "<html>" + resp + "</html>";
139
        return resp;
140
    }
141

    
142
    @Override
143
        public boolean cancelled() {
144
                return doCancel;
145
        }
146

    
147
        @Override
148
        public boolean needShow() {
149
                return this.packages.size() > 0;
150
        }
151

    
152
        public void actionPerformed(ActionEvent e) {
153
                if ("cancel".equals(e.getActionCommand())) {
154
                        doCancel = true;
155
                } else {
156
                        doCancel = false;
157
                }
158
                this.setVisible(false);
159
        }
160
}