annotate SMART/Java/Installer/SmartInstaller.java @ 22:1e3f2c2657a3

Deleted selected files
author m-zytnicki
date Mon, 29 Apr 2013 03:26:07 -0400
parents 769e306b7933
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 import java.util.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 import java.awt.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 import java.awt.event.ActionEvent;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 import java.awt.event.ActionListener;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 import java.io.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 import javax.swing.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 import javax.swing.filechooser.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 import javax.swing.border.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 import javax.swing.SwingUtilities;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 import java.net.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 public class SmartInstaller extends JPanel implements ActionListener {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 int BUFFER = 1024;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 JFrame mainFrame;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 JTextArea logArea;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 // configuration chooser buttons
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 String configurations[] = {"32 bits", "64 bits"};
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 JRadioButton configurationButtons[];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 // program chooser buttons
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 String programChoosers[] = {"R", "R Color Brewer Package", "R HMisc Package", "Python 2.6", "S-MART"};
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 JCheckBox programChooserButtons[];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 JButton goButton;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 // install directory
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 JButton installDirectoryChooserButton;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 JTextField installDirectoryChooserTextField;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 public SmartInstaller() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 super();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 Box box = Box.createVerticalBox();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 // Header
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 JPanel headerPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 JTextArea headerArea = new JTextArea("This is the S-MART installation tool.\r\nIt will download and install the needed softwares, as well as S-MART itself.\r\nYou can unselect the software that you already have installed.\r\nDuring the installation, accept all the default parameters.");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41 TitledBorder headerBorder = BorderFactory.createTitledBorder("Welcome to the S-MART installer!");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42 headerArea.setEditable(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 headerArea.setBackground(headerPanel.getBackground());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 headerPanel.add(headerArea);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 headerPanel.setBorder(headerBorder);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 // Configuration
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 JPanel configurationPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 configurationPanel.setLayout(new GridLayout(1, 0));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 configurationButtons = new JRadioButton[configurations.length];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 ButtonGroup configurationGroup = new ButtonGroup();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 for (int i = 0; i < configurations.length; i++) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 JRadioButton button = new JRadioButton(configurations[i]);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 configurationPanel.add(button);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56 configurationButtons[i] = button;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57 configurationGroup.add(button);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 configurationButtons[0].setSelected(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 TitledBorder configurationBorder = BorderFactory.createTitledBorder("Configuration");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 configurationPanel.setBorder(configurationBorder);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 // Program chooser panel
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 JPanel programPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 programPanel.setLayout(new GridLayout(0, 1));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 JLabel programLabel = new JLabel("Choose which programs to install:");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 programPanel.add(programLabel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 programChooserButtons = new JCheckBox[programChoosers.length];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 for (int i = 0; i < programChoosers.length; i++) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72 JCheckBox button = new JCheckBox(programChoosers[i]);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73 button.setSelected(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 programPanel.add(button);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 programChooserButtons[i] = button;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77 TitledBorder programBorder = BorderFactory.createTitledBorder("Programs");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78 programPanel.setBorder(programBorder);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 // Install directory chooser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 JPanel installDirectoryChooserPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82 installDirectoryChooserPanel.setLayout(new GridLayout(1, 0));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83 JLabel installDirectoryChooserLabel = new JLabel("Choose a directory to install S-MART: ");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 installDirectoryChooserTextField = new JTextField();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 installDirectoryChooserButton = new JButton("Open...");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 installDirectoryChooserButton.addActionListener(this);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88 installDirectoryChooserPanel.add(installDirectoryChooserLabel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 installDirectoryChooserPanel.add(installDirectoryChooserTextField);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 installDirectoryChooserPanel.add(installDirectoryChooserButton);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 TitledBorder installDirectoryChooserBorder = BorderFactory.createTitledBorder("Installation directory");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92 installDirectoryChooserPanel.setBorder(installDirectoryChooserBorder);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 // GO!
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 JPanel goPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 goButton = new JButton("GO!");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97 goButton.addActionListener(this);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98 goButton.setSelected(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 goPanel.add(goButton);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 TitledBorder goBorder = BorderFactory.createTitledBorder("Start install");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 goPanel.setBorder(goBorder);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103 // Log
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 logArea = new JTextArea(10, 120);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 logArea.setFont(new Font("Monospaced", logArea.getFont().getStyle(), logArea.getFont().getSize()));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 JScrollPane logScroll = new JScrollPane(logArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 TitledBorder logBorder = BorderFactory.createTitledBorder("Log");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108 logScroll.setBorder(logBorder);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 GridLayout horizontalLayout = new GridLayout(1, 0);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 box.add(headerPanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113 box.add(configurationPanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114 box.add(programPanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 box.add(installDirectoryChooserPanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 box.add(goPanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 box.add(logScroll);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119 add(box);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 public void actionPerformed(ActionEvent e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 // Install directories chooser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 if (e.getSource() == goButton) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127 boolean[] selectedPrograms = new boolean[programChoosers.length];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128 for (int i = 0; i < programChoosers.length; i++) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 selectedPrograms[i] = programChooserButtons[i].isSelected();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 SmartInstallerTask task = new SmartInstallerTask(logArea, selectedPrograms, installDirectoryChooserTextField.getText(), (configurationButtons[0].isSelected())? 0: 1);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132 task.execute();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 // Install directories chooser
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 else if (e.getSource() == installDirectoryChooserButton) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 JFileChooser chooser = new JFileChooser();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138 if (chooser.showOpenDialog(mainFrame) == JFileChooser.APPROVE_OPTION) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 installDirectoryChooserTextField.setText(chooser.getSelectedFile().getPath());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 private static void createAndShowGUI() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145 // Create and set up the window.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 JFrame mainFrame = new JFrame("S-Mart Installer");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 //Create and set up the content pane.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 JComponent newContentPane = new SmartInstaller();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 newContentPane.setOpaque(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 mainFrame.setContentPane(newContentPane);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 // Display the window.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 mainFrame.pack();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 mainFrame.setVisible(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 public static void main(String[] args) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 javax.swing.SwingUtilities.invokeLater(new Runnable() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 public void run() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 createAndShowGUI();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 });
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167 }