7 package org.libcsdbg.jtracer.installer;
9 import java.util.Vector;
10 import java.util.Hashtable;
13 import java.io.FileOutputStream;
14 import java.io.PrintStream;
15 import java.io.IOException;
20 import java.awt.Color;
21 import java.awt.Dimension;
22 import java.awt.Image;
24 import javax.swing.ImageIcon;
25 import javax.swing.filechooser.FileSystemView;
37 public class Registry extends Hashtable<String, Hashtable<String, Object>>
53 Hashtable<String, Object> section =
new Hashtable<String, Object>();
54 section.put(
"font",
new Font(
"Dialog", Font.PLAIN, 12));
55 section.put(
"fgcolor", Color.decode(
"0x646464"));
56 section.put(
"click-delay",
new Integer(100));
57 put(
"component", section);
59 section =
new Hashtable<String, Object>();
60 section.put(
"font",
new Font(
"Dialog", Font.PLAIN, 12));
61 section.put(
"fgcolor", Color.decode(
"0x646464"));
62 put(
"message", section);
64 section =
new Hashtable<String, Object>();
65 section.put(
"font",
new Font(
"Dialog", Font.BOLD, 12));
66 section.put(
"fgcolor", Color.decode(
"0x646464"));
67 put(
"caption", section);
69 section =
new Hashtable<String, Object>();
70 section.put(
"font",
new Font(
"Dialog", Font.BOLD, 10));
71 section.put(
"fgcolor", Color.decode(
"0x76a6c7"));
72 put(
"progressbar", section);
74 section =
new Hashtable<String, Object>();
75 section.put(
"name",
"jTracer");
76 section.put(
"version",
"1.03");
77 section.put(
"license",
"GNU General Public License v3.0");
78 section.put(
"package",
"jTracer-1.03");
79 section.put(
"jar",
"jTracer-1.03.jar");
80 put(
"installed", section);
82 section =
new Hashtable<String, Object>();
83 section.put(
"name",
"jTracer.installer");
84 section.put(
"version",
"1.0");
85 section.put(
"debug",
"on");
86 section.put(
"console",
"on");
87 section.put(
"size",
new Dimension(520, 360));
88 section.put(
"lnf",
"javax.swing.plaf.metal.MetalLookAndFeel");
89 section.put(
"browser",
"firefox");
90 section.put(
"mailer",
"thunderbird");
91 put(
"generic", section);
106 public Object
get(String section, String key)
108 return get(section).
get(key);
121 public boolean test(String section, String key)
123 String entry = (String)
get(section, key);
127 return entry.toLowerCase().equals(
"on");
142 if (File.separator.equals(
"/"))
143 return new File(
getPrefix(),
"res/" + path);
145 path =
"res/" + path;
146 path.replace(
"/", File.separator);
162 return new ImageIcon(f.getCanonicalPath());
165 catch (Throwable t) {
181 String browser = (String)
get(
"generic",
"browser");
182 ProcessBuilder proc =
new ProcessBuilder(browser, url.toString());
186 catch (Throwable t) {
200 String mailer = (String)
get(
"generic",
"mailer");
201 ProcessBuilder proc =
new ProcessBuilder(mailer, url.toString());
205 catch (Throwable t) {
216 public void setup() throws IOException
218 if (
test(
"generic",
"console"))
221 long id = System.currentTimeMillis();
225 System.out.println(
"\r\nOutput log: " + log.getCanonicalPath());
226 FileOutputStream fs =
new FileOutputStream(log,
true);
227 PrintStream ps =
new PrintStream(fs,
true);
240 Vector<Image> retval =
new Vector<Image>();
241 for (
int i = 16; i <= 128; i *= 2) {
242 ImageIcon icon =
loadIcon(
"icon" + i +
".png");
244 retval.add(icon.getImage());
281 String path = retval.getCanonicalPath();
284 if (!retval.isDirectory())
285 msg =
"The user home directory '" + path +
"' doesn't exist";
287 else if (!retval.canRead())
288 msg =
"Can't access the user home directory '" + path +
"'";
291 throw new IOException(msg);
304 String tmpdir = System.getProperty(
"java.io.tmpdir");
305 File retval =
new File(tmpdir,
".jTracer.installer");
306 String path = retval.getCanonicalPath();
309 if (!retval.isDirectory())
310 msg =
"The installation directory '" + path +
"' doesn't exist";
312 else if (!retval.canRead())
313 msg =
"Can't access the installation directory '" + path +
"'";
316 throw new IOException(msg);
327 public synchronized static void debug(Throwable err)
329 Registry conf = Registry.getCurrent();
330 if (conf != null && !conf.
test(
"generic",
"debug"))
333 Thread thr = Thread.currentThread();
334 System.err.println(
"at thread " + thr.getName() +
":" + thr.getId());
335 err.printStackTrace();
344 public synchronized static void debug(String msg)
346 Registry conf = Registry.getCurrent();
347 if (conf != null && !conf.
test(
"generic",
"debug"))
350 Thread thr = Thread.currentThread();
351 System.err.println(
"at thread " + thr.getName() +
":" + thr.getId());
352 System.err.println(msg);
358 return System.getProperty(
"os.name");
368 return os.matches(
"Linux");
void setup()
Setup any process specific resources before the main application frame is launched.
static synchronized void debug(Throwable err)
Output debug text for an exception.
static Registry current
Current registry.
File getResource(String path)
Get a resource file.
void browse(URL url)
Open a URL on the registered web browser.
ImageIcon loadIcon(String nm)
Load an icon from the current theme.
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.
boolean test(String section, String key)
Get a boolean entry.
static File getPrefix()
Get the installation prefix.
static final long serialVersionUID
Class version.
static String getOsName()
static synchronized void debug(String msg)
Output a debug message.
static Registry getCurrent()
Get the current registry.
static void setCurrent(Registry cur)
Set the current registry.