7 package org.libcsdbg.jtracer.installer;
19 import java.util.Vector;
20 import java.util.zip.ZipEntry;
21 import java.util.jar.JarInputStream;
24 import java.io.FileInputStream;
25 import java.io.FileOutputStream;
26 import java.io.FileWriter;
27 import java.io.DataInputStream;
28 import java.io.DataOutputStream;
29 import java.io.IOException;
33 import java.nio.channels.FileLock;
34 import java.nio.file.Files;
36 import java.awt.event.KeyEvent;
37 import java.awt.event.ActionEvent;
38 import java.awt.event.ActionListener;
40 import java.awt.Color;
41 import java.awt.Dimension;
42 import java.awt.Insets;
43 import java.awt.BorderLayout;
44 import java.awt.GridBagLayout;
45 import java.awt.GridBagConstraints;
47 import javax.swing.event.HyperlinkEvent;
48 import javax.swing.event.HyperlinkListener;
49 import javax.swing.JFrame;
50 import javax.swing.JLabel;
51 import javax.swing.JPanel;
52 import javax.swing.JEditorPane;
53 import javax.swing.JScrollPane;
54 import javax.swing.JCheckBox;
55 import javax.swing.JProgressBar;
56 import javax.swing.JFileChooser;
57 import javax.swing.UIManager;
58 import javax.swing.WindowConstants;
98 private FileLock
lock = null;
110 Registry conf = Registry.getCurrent();
111 screens =
new Vector<JPanel>();
113 String pkg = (String) conf.
get(
"installed",
"package");
114 setTitle(
"Installation of " + pkg);
125 catch (Throwable t) {
131 viewport =
new JPanel(
new BorderLayout());
132 viewport.add(screens.get(0), BorderLayout.CENTER);
135 setSize((Dimension) conf.
get(
"generic",
"size"));
136 setLocationRelativeTo(null);
137 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
148 Registry conf = Registry.getCurrent();
149 GridBagLayout lm =
new GridBagLayout();
150 GridBagConstraints c =
new GridBagConstraints();
151 JPanel retval =
new JPanel(lm);
153 String pkg = (String) conf.
get(
"installed",
"package");
154 caption =
new JLabel(
"Installing " + pkg);
155 caption.setFont((Font) conf.
get(
"caption",
"font"));
156 caption.setForeground((Color) conf.
get(
"caption",
"fgcolor"));
158 c.gridx = c.gridy = 0;
160 c.insets =
new Insets(12, 12, 0, 12);
161 c.fill = GridBagConstraints.HORIZONTAL;
162 c.anchor = GridBagConstraints.WEST;
177 GridBagLayout lm =
new GridBagLayout();
178 GridBagConstraints c =
new GridBagConstraints();
179 JPanel retval =
new JPanel(lm);
182 info.setMnemonic(KeyEvent.VK_A);
185 cancel.setMnemonic(KeyEvent.VK_C);
187 next =
new Button(
"Next",
this);
188 next.setMnemonic(KeyEvent.VK_N);
191 previous.setMnemonic(KeyEvent.VK_P);
192 previous.setEnabled(
false);
194 c.gridx = c.gridy = 0;
195 c.insets =
new Insets(12, 12, 6, 12);
196 lm.setConstraints(info, c);
202 c.anchor = GridBagConstraints.WEST;
203 lm.setConstraints(cancel, c);
208 c.anchor = GridBagConstraints.CENTER;
214 lm.setConstraints(next, c);
228 Registry conf = Registry.getCurrent();
229 GridBagLayout lm =
new GridBagLayout();
230 GridBagConstraints c =
new GridBagConstraints();
231 JPanel scr =
new JPanel(lm);
233 Font fnt = (Font) conf.
get(
"component",
"font");
234 Color fg = (Color) conf.
get(
"component",
"fgcolor");
241 page = conf.getResource(
"var/package.html");
243 page = conf.getResource(
"var/license.html");
245 JEditorPane pager =
new JEditorPane(page.toURI().toURL());
246 pager.putClientProperty(JEditorPane.W3C_LENGTH_UNITS,
true);
247 pager.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
true);
248 pager.addHyperlinkListener(
this);
249 pager.setEditable(
false);
250 pager.setMargin(
new Insets(0, 0, 0, 0));
251 JScrollPane
viewport =
new JScrollPane(pager);
254 c.gridx = c.gridy = 0;
255 c.weightx = c.weighty = 1;
256 c.insets =
new Insets(12, 12, 0, 12);
257 c.fill = GridBagConstraints.BOTH;
263 JLabel l =
new JLabel(
"User data in: ");
266 c.gridx = c.gridy = 0;
267 c.insets =
new Insets(12, 12, 0, 0);
268 c.anchor = GridBagConstraints.EAST;
269 lm.setConstraints(l, c);
272 l =
new JLabel(
"Install in: ");
276 lm.setConstraints(l, c);
279 String pkg = (String) conf.
get(
"installed",
"name");
287 home.setForeground(fg);
288 home.setEnabled(
false);
294 c.anchor = GridBagConstraints.CENTER;
295 c.fill = GridBagConstraints.HORIZONTAL;
296 lm.setConstraints(
home, c);
302 prefix =
new TextField(
"C:\\Program Files\\" + pkg +
"\\");
305 prefix.setForeground(fg);
307 lm.setConstraints(prefix, c);
310 select =
new Button(
"Select",
this);
311 select.setMnemonic(KeyEvent.VK_S);
316 c.fill = GridBagConstraints.NONE;
317 lm.setConstraints(select, c);
320 JCheckBox storeApi =
new JCheckBox(
"Install all documentation",
true);
321 storeApi.setFont(fnt);
322 storeApi.setForeground(fg);
325 c.anchor = GridBagConstraints.WEST;
326 lm.setConstraints(storeApi, c);
329 JCheckBox themes =
new JCheckBox(
"Install all secondary themes",
true);
331 themes.setForeground(fg);
333 lm.setConstraints(themes, c);
336 JCheckBox appIcon =
new JCheckBox(
"Install desktop icon",
true);
337 appIcon.setFont(fnt);
338 appIcon.setForeground(fg);
340 lm.setConstraints(appIcon, c);
343 progress =
new JLabel(
"Installation progress: Unpacking");
344 progress.setFont(fnt);
345 progress.setForeground(fg);
346 progress.setVisible(
false);
350 c.insets =
new Insets(24, 12, 0, 12);
351 c.anchor = GridBagConstraints.WEST;
355 fnt = (Font) conf.
get(
"progressbar",
"font");
356 fg = (Color) conf.
get(
"progressbar",
"fgcolor");
357 setupBar =
new JProgressBar(0, 100);
358 setupBar.setStringPainted(
true);
359 setupBar.setFont(fnt);
360 setupBar.setForeground(fg);
361 setupBar.setVisible(
false);
365 c.fill = GridBagConstraints.HORIZONTAL;
372 c.fill = GridBagConstraints.BOTH;
373 lm.setConstraints(l, c);
387 System.out.println(
"Current stage: " +
current);
388 Registry conf = Registry.getCurrent();
390 viewport.removeAll();
391 viewport.add(screens.get(
current), BorderLayout.CENTER);
397 String pkg = (String) conf.get(
"installed",
"package");
398 caption.setText(
"Installing " + pkg);
400 previous.setEnabled(
false);
404 String license = (String) conf.get(
"installed",
"license");
405 caption.setText(license);
407 previous.setEnabled(
true);
408 next.setText(
"Next");
409 next.setActionCommand(
"Next");
410 next.setMnemonic(KeyEvent.VK_N);
414 caption.setText(
"Select options");
416 next.setText(
"Install");
417 next.setActionCommand(
"Install");
418 next.setMnemonic(KeyEvent.VK_I);
423 public static void extractJar(File jar, File dir, JProgressBar bar)
throws IOException
426 String path = System.getProperty(
"java.io.tmpdir");
427 dir =
new File(path,
".jTracer.installer");
431 boolean autodel =
false;
436 jar =
new File(System.getProperty(
"java.class.path"));
439 JarInputStream in =
new JarInputStream(
new FileInputStream(jar));
442 float bytes = 0, sz = jar.length();
443 while ((entry = in.getNextEntry()) != null) {
444 File from =
new File(entry.getName());
445 File to =
new File(dir, entry.getName());
447 if (entry.isDirectory()) {
448 String parts[] = entry.getName().split(
"/");
449 File subdir =
new File(dir,
"");
451 for (
int i = 0; i < parts.length; i++) {
452 subdir =
new File(subdir, parts[i]);
453 System.out.println(parts[i]);
456 bytes += to.length();
458 bar.setValue((int) ((bytes / sz) * 100));
461 subdir.deleteOnExit();
464 System.out.println(subdir.getAbsolutePath());
468 System.out.println(from.getAbsolutePath() +
" -> " + to.getAbsolutePath());
490 DataOutputStream out =
new DataOutputStream(
new FileOutputStream(to));
491 while (in.available() == 1) {
493 int data = in.read();
500 bar.setValue((int) ((bytes / sz) * 100));
522 public static void main(String[] argv)
526 System.out.println(
"Linux");
528 System.out.println(
"Windows");
535 File lockf = conf.getResource(
"var/.lock");
536 FileOutputStream fs =
new FileOutputStream(lockf);
538 app.lock = fs.getChannel().tryLock();
539 if (app.
lock == null) {
540 String nm = (String) conf.get(
"generic",
"name");
541 Alert.error(null, nm +
" is already running",
true);
544 lockf.deleteOnExit();
545 UIManager.setLookAndFeel((String) conf.get(
"generic",
"lnf"));
546 app.setVisible(
true);
549 catch (Throwable t) {
588 Registry conf = Registry.getCurrent();
589 File pkg = conf.getResource(
"config/package.jar");
590 File dest =
new File(
home.getText());
594 progress.setText(
"Installation progress: Configuring");
595 File exec =
new File(dest,
"jTracer-1.03.jar");
596 exec.setExecutable(
true,
false);
599 File theme =
new File(dest,
"res/theme/default");
600 File link =
new File(dest,
"res/theme/current");
601 Files.createSymbolicLink(link.toPath(), theme.toPath());
603 File launcher =
new File(prefix.getText() +
"/bin/jTracer");
604 launcher.createNewFile();
605 launcher.setExecutable(
true,
false);
606 FileWriter out =
new FileWriter(launcher);
607 out.write(
"#!/bin/bash\n\n");
608 out.write(
"java -jar " + exec.getAbsolutePath() +
" &\n");
612 progress.setText(
"Installation progress: Complete");
613 System.out.println(
"finished");
616 catch (Throwable t) {
621 next.setEnabled(
true);
622 next.setText(
"Finish");
623 next.setActionCommand(
"Finish");
624 next.setMnemonic(KeyEvent.VK_F);
637 String cmd = event.getActionCommand();
639 if (cmd.equals(
"Cancel")) {
640 Registry conf = Registry.getCurrent();
642 String pkg = (String) conf.
get(
"installed",
"package");
643 String msg =
"Really cancel the installation of " + pkg +
"?";
649 else if (cmd.equals(
"Previous")) {
657 else if (cmd.equals(
"Next")) {
665 else if (cmd.equals(
"Select")) {
666 JFileChooser chooser =
new JFileChooser();
667 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
669 int retval = chooser.showDialog(
this,
"Select");
670 if (retval == JFileChooser.APPROVE_OPTION)
671 prefix.setText(chooser.getSelectedFile().getPath());
674 else if (cmd.equals(
"Install")) {
675 progress.setVisible(
true);
676 setupBar.setVisible(
true);
678 next.setEnabled(
false);
679 previous.setEnabled(
false);
680 select.setEnabled(
false);
681 prefix.setEnabled(
false);
683 setupBar.setValue(0);
688 else if (cmd.equals(
"Finish"))
691 else if (cmd.startsWith(
"About")) {
695 about.setLocationRelativeTo(
this);
696 about.setVisible(
true);
700 catch (Throwable t) {
714 if (event.getEventType() != HyperlinkEvent.EventType.ACTIVATED)
717 URL url = event.getURL();
718 String proto = url.getProtocol();
719 Registry conf = Registry.getCurrent();
721 if (proto.equals(
"file")) {
723 about.setVisible(
false);
726 else if (proto.equals(
"mailto"))
729 else if (proto.equals(
"http"))
733 catch (Throwable t) {
void run()
/ public void spawn() { if (EventQueue.isDispatchThread()) { return; }
void actionPerformed(ActionEvent event)
Handler for action events fired from the wizard control buttons.
int current
Current screen index.
JLabel caption
Wizard screen caption.
void hyperlinkUpdate(HyperlinkEvent event)
Handler for hyperlink events.
Object get(String section, String key)
Get an entry.
A dialog that shows an HTML page with project information (version, short description, license, copyright e.t.c) and links to various online project resources.
static void extractJar(File jar, File dir, JProgressBar bar)
JPanel createCaption()
Create the wizard screen caption.
void showScreen()
Update the viewport with the current wizard screen.
FileLock lock
Unique installer lock.
Button previous
Wizard control buttons.
JPanel createControls()
Create the wizard control buttons.
Vector< Image > getProjectIcons()
Get a cross-platform set of project icons.
void mail(URL url)
Open a URL on the registered mail composer.
static File getHomeDirectory()
Get the user home directory.
TextField home
Installation path fields.
static void main(String[] argv)
Process entry point.
User alert or simple prompt dialog with configurable styles.
static boolean prompt(JFrame owner, String msg)
Show an alert prompting the user to make a choice.
Vector< JPanel > screens
Wizard screen enumeration.
void createScreen(int i)
Create a wizard screen.
JLabel progress
Installation progress indicator.
static final long serialVersionUID
Class version.
Main application window frame and process entry point.
JProgressBar setupBar
Installation progress bar.
Thread installer
Installer thread.
JPanel viewport
Content viewport.