7 package org.libcsdbg.jtracer;
9 import java.util.Enumeration;
12 import java.io.FileOutputStream;
13 import java.io.IOException;
16 import java.net.Socket;
17 import java.net.ServerSocket;
18 import java.net.InetAddress;
19 import java.net.InetSocketAddress;
21 import java.nio.channels.FileLock;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.awt.Insets;
29 import java.awt.Dimension;
30 import java.awt.BorderLayout;
31 import java.awt.GridBagLayout;
32 import java.awt.GridBagConstraints;
33 import java.awt.GraphicsEnvironment;
34 import java.awt.GraphicsDevice;
36 import javax.swing.JFrame;
37 import javax.swing.JPanel;
38 import javax.swing.JScrollPane;
39 import javax.swing.UIManager;
55 PropertyChangeListener
76 private FileLock
lock = null;
95 Registry conf = Registry.getCurrent();
96 setTitle((String) conf.
get(
"generic",
"name"));
106 add(
tools, BorderLayout.NORTH);
107 add(
status, BorderLayout.SOUTH);
109 JPanel nowrap =
new JPanel(
new BorderLayout());
111 JScrollPane viewport =
new JScrollPane(nowrap);
112 viewport.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
114 GridBagLayout lm =
new GridBagLayout();
115 GridBagConstraints c =
new GridBagConstraints();
116 JPanel inset =
new JPanel(lm);
117 c.weightx = c.weighty = 1;
118 c.fill = GridBagConstraints.BOTH;
119 c.insets =
new Insets(0, 2, 0, 1);
120 lm.setConstraints(viewport, c);
122 add(inset, BorderLayout.CENTER);
124 addPropertyChangeListener(
"isServing", menu);
125 addPropertyChangeListener(
"isServing",
tools);
126 addPropertyChangeListener(
"hasClients", menu);
127 addPropertyChangeListener(
"hasClients",
tools);
130 firePropertyChange(
"isServing", null,
false);
131 firePropertyChange(
"hasClients", null,
false);
133 log.appendln(
"jTracer initialized",
"status");
134 log.appendln(
"Ready to start serving",
"status");
136 setSize((Dimension) conf.
get(
"generic",
"size"));
137 setLocationRelativeTo(null);
149 log.appendln(
"Starting server...",
"status");
150 server =
new Thread(
this,
"server");
151 server.setDaemon(
true);
164 log.appendln(
"Stopping server...",
"status");
173 catch (Throwable t) {
177 log.appendln(
"Service stopped. All incoming connections dropped",
"status");
195 catch (Throwable t) {
206 public static void main(String[] argv)
215 File lockf = conf.getResource(
"log/.lock");
216 FileOutputStream fs =
new FileOutputStream(lockf);
218 app.lock = fs.getChannel().tryLock();
219 if (app.
lock == null) {
220 String nm = (String) conf.
get(
"generic",
"name");
221 Alert.error(null, nm +
" is already running",
true);
224 lockf.deleteOnExit();
225 UIManager.setLookAndFeel((String) conf.
get(
"generic",
"lnf"));
226 app.setVisible(
true);
229 catch (Throwable t) {
242 Registry conf = Registry.getCurrent();
243 Enumeration keys = conf.getSectionKeys(
"server");
245 throw new Exception(
"No server configuration found");
249 listener.setReuseAddress(
true);
252 InetSocketAddress iface = null;
253 while (keys.hasMoreElements()) {
254 String key = (String) keys.nextElement();
256 iface = (InetSocketAddress) conf.
get(
"server", key);
257 listener.bind(iface);
259 InetAddress addr = iface.getAddress();
260 String msg =
"Accepting connections @";
261 msg += addr.getHostAddress() +
":" + iface.getPort();
263 if (addr.isAnyLocalAddress())
264 msg +=
" (all local)";
266 else if (addr.isMulticastAddress())
267 msg +=
" (multicast)";
270 msg +=
" (" + addr.getCanonicalHostName() +
")";
272 log.appendln(msg,
"status");
275 if (iface == null || !
listener.isBound())
276 throw new Exception(
"No server configuration found");
278 firePropertyChange(
"isServing", null,
true);
279 status.startUptimeTimer();
282 while (
server == Thread.currentThread()) {
283 status.setMessage(
"Waiting for connections",
true);
286 Socket peer = listener.accept();
288 String addr = peer.getInetAddress().getHostAddress();
289 int port = peer.getPort();
290 log.appendln(
"Connected peer @" + addr +
":" + port,
"status");
292 desktop.register(peer);
295 catch (Throwable t) {
296 log.appendln(t.toString(),
"alert");
297 if (!(t instanceof IOException))
302 status.stopUptimeTimer();
303 status.setMessage(
"Service complete",
true);
304 firePropertyChange(
"isServing", null,
false);
307 catch (Throwable t) {
312 log.appendln(
"Failed to start server (" + t.toString() +
")",
"error");
313 status.setMessage(
"Server failed",
false);
326 String cmd = event.getActionCommand();
329 if (cmd.equals(
"Start"))
332 else if (cmd.equals(
"Stop"))
335 else if (cmd.equals(
"Restart")) {
336 log.appendln(
"Restarting server (reload configuration)...",
"status");
341 else if (cmd.equals(
"Clear log"))
344 else if (cmd.equals(
"Quit")) {
345 boolean reply = Alert.prompt(
this,
"Are you sure you want to quit?");
352 else if (cmd.equals(
"Toolbar")) {
354 add(
tools, BorderLayout.NORTH);
361 else if (cmd.equals(
"Statusbar")) {
363 add(
status, BorderLayout.SOUTH);
370 else if (cmd.equals(
"Find"))
371 Alert.
error(
this,
"Not implemented yet",
false);
373 else if (cmd.equals(
"Preferences"))
374 Alert.
error(
this,
"Not implemented yet",
false);
376 else if (cmd.equals(
"Always on top")) {
377 boolean state = menu.getToggleState(2);
378 setAlwaysOnTop(state);
379 desktop.setAlwaysOnTop(-1, state);
382 else if (cmd.equals(
"Full screen")) {
383 GraphicsEnvironment env;
384 env = GraphicsEnvironment.getLocalGraphicsEnvironment();
386 GraphicsDevice dev = env.getDefaultScreenDevice();
387 if (!dev.isFullScreenSupported())
390 JFrame cur = (JFrame) dev.getFullScreenWindow();
392 dev.setFullScreenWindow(
this);
394 dev.setFullScreenWindow(null);
399 else if (cmd.equals(
"Select previous"))
402 else if (cmd.equals(
"Select next"))
405 else if (cmd.equals(
"Close")) {
408 desktop.disposeCurrent();
411 else if (cmd.equals(
"Cascade"))
414 else if (cmd.equals(
"Minimize all"))
417 else if (cmd.equals(
"Restore all"))
420 else if (cmd.equals(
"Close all")) {
421 boolean reply = Alert.prompt(
this,
"Close all client windows?");
425 desktop.disposeAll();
428 else if (cmd.startsWith(
"Select session")) {
429 String parts[] = cmd.split(
"\\s");
430 desktop.setCurrent(Integer.valueOf(parts[2]));
435 cmd.equals(
"Online documentation") ||
436 cmd.equals(
"Bug tracker") ||
437 cmd.equals(
"Submit feedback")
439 Registry conf = Registry.getCurrent();
440 String key =
"url-" + cmd.toLowerCase().replace(
' ',
'-');
441 conf.browse((URL) conf.
get(
"generic", key));
444 else if (cmd.equals(
"Check for updates"))
445 Alert.
error(
this,
"Not implemented yet",
false);
447 else if (cmd.startsWith(
"About")) {
451 about.setLocationRelativeTo(
this);
452 about.setVisible(
true);
461 catch (Throwable t) {
475 String key = event.getPropertyName();
476 Object val = event.getNewValue();
478 if (key.equals(
"sessionCount")) {
479 firePropertyChange(
"hasClients", null, (Integer) val != 0);
484 else if (key.equals(
"traceCount")) {
489 else if (key.equals(
"currentSession"))
492 else if (key.equals(
"sessionRequest"))
496 catch (Throwable t) {
ToolBar tools
Application toolbar.
AboutDialog about
About dialog.
Object get(String section, String key)
Get an entry.
void propertyChange(PropertyChangeEvent event)
Handler for events fired when UI properties change.
FileLock lock
Unique server lock.
Application statusbar with multiple indicators and configurable styles.
Main application logging pane.
static final long serialVersionUID
Class version.
Thread server
Server thread.
Vector< Image > getProjectIcons()
Get a cross-platform set of project icons.
LogPane log
Application logging pane.
void appendln(String ln, String tag)
Append a line of formatted text and a line break.
void shutdown()
Close the listening server socket and shutdown the server.
static void main(String[] argv)
Process entry point.
void stopService()
Stop the server.
StatusBar status
Application statusbar.
Main application window frame and process entry point.
void setIconified(final boolean how)
Minimize or restore all client windows.
MenuBar menu
Application menu.
void actionPerformed(ActionEvent event)
Handler for toolbar and menu action events.
static void error(JFrame owner, String msg, boolean fatal)
Show an error alert and exit if the error is marked as fatal.
void run()
Server thread implementation.
void shiftSelection(int step)
Select the previous/next not iconified client window.
C++ stack trace syntax highlighter.
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.
int getTraceCount()
Get the total number of traces.
User alert or simple prompt dialog with configurable styles.
ServerSocket listener
Listener socket.
void clear()
Remove all contents.
void startService()
Start the server.
SessionManager desktop
Main and window manager.