Source code: dtk/gui/TKLog.java
1
2 //Title: D3E ToolKit
3 //Version:
4 //Copyright: Copyright (c) 1999
5 //Author: John Weatherley
6 //Company:
7 //Description: D3E Toolkit
8
9
10 package dtk.gui;
11
12 import dtk.core.*;
13 import java.awt.*;
14 import javax.swing.*;
15
16 /**
17 Creates a simple box to display messages to the user and
18 to log certain events for debugging purposes to standard out.
19 */
20 public class TKLog
21 {
22 static boolean print = false;
23
24 /**
25 Prints the given message to standard output. Used for debugging.
26 Messages can be turned on and off by setting the boolean
27 <code>print</code>
28
29 @param s The message printed.
30 */
31 static public void println(String s)
32 {
33 if(print)
34 System.out.println(s);
35 }
36
37 /**
38 Prints the given message to standard output with the word "Log"
39 inserted at the beginning. Used for debugging.
40 Messages can be turned on and off by setting the boolean
41 <code>print</code>
42
43 @param s The message printed.
44 */
45 static public void logFile(String s)
46 {
47 println("Log: " + s);
48 }
49
50 /**
51 Pops up a message in a "OK" window centered around a Component.
52
53 @param s The message displayed.
54 @param c The Component around which this "OK" window is centered.
55 */
56 static public void okMsg(String s, Component c)
57 {
58 JOptionPane.showConfirmDialog(
59 c,
60 s,
61 "D3E Toolkit",
62 JOptionPane.DEFAULT_OPTION,
63 JOptionPane.PLAIN_MESSAGE);
64
65 }
66
67 /**
68 Pops up a message in a "OK" window.
69 The display is centered over the primary Toolkit Frame.
70
71 @param s The message displayed.
72 */
73 static public void okMsg(String s)
74 {
75 okMsg(s,TKToolkit.frame);
76 }
77
78
79 /**
80 Pops up an error message with the word "Error" inserted at the beginning in a "OK" window.
81 The display is centered over the primary Toolkit Frame.
82
83 @param s The message displayed.
84 */
85 static public void error(String s)
86 {
87 okMsg(" Error: " + s,TKToolkit.frame);
88 }
89
90 /**
91 Pops up an error message with the word "Error" inserted at the beginning in a "OK" window.
92 The display is centered over the given Component.
93
94 @param s The message displayed.
95 @param c The Component around which this "OK" window is centered.
96 */
97 static public void error(String s, Component c)
98 {
99 okMsg(" Error: " + s,c);
100 }
101
102 }