7 package org.libcsdbg.jtracer;
9 import java.util.Vector;
10 import java.util.Hashtable;
11 import java.util.Enumeration;
14 import java.io.FileOutputStream;
15 import java.io.PrintStream;
16 import java.io.IOException;
19 import java.net.InetSocketAddress;
20 import java.net.MalformedURLException;
23 import java.awt.Color;
24 import java.awt.Insets;
25 import java.awt.Dimension;
26 import java.awt.Image;
28 import javax.swing.ImageIcon;
29 import javax.swing.filechooser.FileSystemView;
41 public class Registry extends Hashtable<String, Hashtable<String, Object>>
53 Registry() throws MalformedURLException
57 Hashtable<String, Object> section =
new Hashtable<String, Object>();
58 section.put(
"font",
new Font(
"Dialog", Font.PLAIN, 12));
59 section.put(
"fgcolor", Color.decode(
"0x646464"));
60 section.put(
"click-delay", 100);
61 put(
"component", section);
63 section =
new Hashtable<String, Object>();
64 section.put(
"font",
new Font(
"Dialog", Font.PLAIN, 12));
65 section.put(
"fgcolor", Color.decode(
"0x646464"));
66 put(
"message", section);
68 section =
new Hashtable<String, Object>();
69 section.put(
"font",
new Font(
"Dialog", Font.PLAIN, 12));
70 section.put(
"fgcolor-debug", Color.decode(
"0x646464"));
71 section.put(
"fgcolor-status", Color.decode(
"0x76a6c7"));
72 section.put(
"fgcolor-data", Color.decode(
"0x7dc91b"));
73 section.put(
"fgcolor-alert", Color.decode(
"0xe94615"));
74 section.put(
"fgcolor-error", Color.decode(
"0xe94615"));
76 section.put(
"font-trace",
new Font(
"Dialog", Font.PLAIN, 12));
77 section.put(
"fgcolor-delimiter", Color.decode(
"0x707070"));
78 section.put(
"fgcolor-plain", Color.decode(
"0x707070"));
79 section.put(
"fgcolor-keyword", Color.decode(
"0xb66127"));
80 section.put(
"fgcolor-type", Color.decode(
"0x467697"));
81 section.put(
"fgcolor-number", Color.decode(
"0xdfa613"));
82 section.put(
"fgcolor-file", Color.decode(
"0x5da90b"));
83 section.put(
"fgcolor-scope", Color.decode(
"0xa0a0a0"));
84 section.put(
"fgcolor-function", Color.decode(
"0x404040"));
86 section.put(
"fgcolor-selection", Color.white);
87 section.put(
"bgcolor-selection", Color.decode(
"0x76a6c7"));
88 section.put(
"padding", 4);
89 section.put(
"line-height", 0.25f);
90 section.put(
"margin",
new Insets(6, 2, 0, 2));
93 section =
new Hashtable<String, Object>();
94 section.put(
"font",
new Font(
"Dialog", Font.BOLD, 10));
95 section.put(
"fgcolor", Color.white);
96 section.put(
"fgcolor-error", Color.decode(
"0x9d1f18"));
97 section.put(
"bgcolor", Color.decode(
"0xff8818"));
98 section.put(
"bgcolor-counter-active", Color.decode(
"0xff7000"));
99 section.put(
"bgcolor-uptime-active", Color.decode(
"0x5da90b"));
100 put(
"statusbar", section);
102 section =
new Hashtable<String, Object>();
103 section.put(
"all-local",
new InetSocketAddress(4242));
104 put(
"server", section);
106 section =
new Hashtable<String, Object>();
107 section.put(
"size",
new Dimension(560, 280));
108 section.put(
"timeout", 5000);
109 put(
"session", section);
111 section =
new Hashtable<String, Object>();
112 section.put(
"name",
"jTracer");
113 section.put(
"version",
"1.03");
114 section.put(
"debug",
"on");
115 section.put(
"console",
"on");
116 section.put(
"size",
new Dimension(560, 280));
117 section.put(
"lnf",
"javax.swing.plaf.metal.MetalLookAndFeel");
118 section.put(
"browser",
"firefox");
119 section.put(
"mailer",
"thunderbird");
122 "url-online-documentation",
123 new URL(
"http://libcsdbg.sourceforge.net/jTracer/")
128 new URL(
"https://sourceforge.net/p/libcsdbg/tickets/")
132 "url-submit-feedback",
133 new URL(
"https://sourceforge.net/p/libcsdbg/discussion/")
136 put(
"generic", section);
151 public Object
get(String section, String key)
153 return get(section).
get(key);
166 public boolean test(String section, String key)
168 String entry = (String)
get(section, key);
172 return entry.toLowerCase().equals(
"on");
185 Hashtable<String, Object> sect =
get(nm);
204 if (File.separator.equals(
"/"))
205 return new File(
getPrefix(),
"res/" + path);
207 path =
"res/" + path;
208 path.replace(
"/", File.separator);
229 return new ImageIcon(f.getCanonicalPath());
232 catch (Throwable t) {
248 String browser = (String)
get(
"generic",
"browser");
249 ProcessBuilder proc =
new ProcessBuilder(browser, url.toString());
253 catch (Throwable t) {
267 String mailer = (String)
get(
"generic",
"mailer");
268 ProcessBuilder proc =
new ProcessBuilder(mailer, url.toString());
272 catch (Throwable t) {
283 public void setup() throws IOException
285 if (
test(
"generic",
"console"))
288 long id = System.currentTimeMillis();
292 System.out.println(
"\r\nOutput log: " + log.getCanonicalPath());
293 FileOutputStream fs =
new FileOutputStream(log,
true);
294 PrintStream ps =
new PrintStream(fs,
true);
307 Vector<Image> retval =
new Vector<Image>();
308 for (
int i = 16; i <= 128; i *= 2) {
309 ImageIcon icon =
loadIcon(
"icon" + i +
".png");
311 retval.add(icon.getImage());
348 String path = retval.getCanonicalPath();
351 if (!retval.isDirectory())
352 msg =
"The user home directory '" + path +
"' doesn't exist";
354 else if (!retval.canRead())
355 msg =
"Can't access the user home directory '" + path +
"'";
358 throw new IOException(msg);
375 retval =
new File(
"C:\\Program Files\\jTracer");
377 String path = retval.getCanonicalPath();
380 if (!retval.isDirectory())
381 msg =
"The installation directory '" + path +
"' doesn't exist";
383 else if (!retval.canRead())
384 msg =
"Can't access the installation directory '" + path +
"'";
387 throw new IOException(msg);
398 public synchronized static void debug(Throwable err)
400 Registry conf = Registry.getCurrent();
401 if (conf != null && !conf.
test(
"generic",
"debug"))
404 Thread thr = Thread.currentThread();
405 System.err.println(
"at thread " + thr.getName() +
":" + thr.getId());
406 err.printStackTrace();
415 public synchronized static void debug(String msg)
417 Registry conf = Registry.getCurrent();
418 if (conf != null && !conf.
test(
"generic",
"debug"))
421 Thread thr = Thread.currentThread();
422 System.err.println(
"at thread " + thr.getName() +
":" + thr.getId());
423 System.err.println(msg);
429 return System.getProperty(
"os.name");
439 return os.matches(
"Linux");
static void setCurrent(Registry cur)
Set the current registry.
void setup()
Setup any process specific resources before the main application frame is launched.
ImageIcon loadIcon(String nm)
Load an icon from the current theme.
static String getOsName()
Vector< Image > getProjectIcons()
Get a cross-platform set of project icons.
void mail(URL url)
Open a URL on the registered mail composer.
static final long serialVersionUID
Class version.
static Registry current
Current registry.
boolean test(String section, String key)
Get a boolean entry.
static synchronized void debug(Throwable err)
Output debug text for an exception.
void browse(URL url)
Open a URL on the registered web browser.
static Registry getCurrent()
Get the current registry.
Enumeration getSectionKeys(String nm)
Get all the keys of a section.
File getResource(String path)
Get a resource file.
static File getPrefix()
Get the installation prefix.
static File getHomeDirectory()
Get the user home directory.
static synchronized void debug(String msg)
Output a debug message.