change logging process
@@ -46,6 +46,7 @@ | ||
46 | 46 | import jp.sourceforge.nine.action.util.ActionArgument; |
47 | 47 | import jp.sourceforge.nine.action.util.ArgumentActionEvent; |
48 | 48 | import jp.sourceforge.nine.js.KeyboardSettings; |
49 | +import jp.sourceforge.nine.util.NineLogger; | |
49 | 50 | import jp.sourceforge.nine.util.NineUtilities; |
50 | 51 | |
51 | 52 | import static java.awt.event.InputEvent.CTRL_DOWN_MASK; |
@@ -94,8 +95,7 @@ | ||
94 | 95 | String n = String.format("./resource/keyboard/keyboard_%s.txt", layout); |
95 | 96 | m.setup(new File(n)); |
96 | 97 | } catch (IOException e) { |
97 | - e.printStackTrace(); | |
98 | - Main.logger.severe(e.getLocalizedMessage()); | |
98 | + NineLogger.instance.severe(e); | |
99 | 99 | } |
100 | 100 | } |
101 | 101 |
@@ -115,17 +115,13 @@ | ||
115 | 115 | try { |
116 | 116 | evaluateKeyStrokeSetting(items, keyStrokeLayout.get(exp), altKey); |
117 | 117 | } catch (IllegalArgumentException e) { |
118 | - e.printStackTrace(); | |
119 | - Main.logger.warning(e.getLocalizedMessage()); | |
118 | + NineLogger.instance.warning(e); | |
120 | 119 | } catch (SecurityException e) { |
121 | - e.printStackTrace(); | |
122 | - Main.logger.warning(e.getLocalizedMessage()); | |
120 | + NineLogger.instance.warning(e); | |
123 | 121 | } catch (IllegalAccessException e) { |
124 | - e.printStackTrace(); | |
125 | - Main.logger.warning(e.getLocalizedMessage()); | |
122 | + NineLogger.instance.warning(e); | |
126 | 123 | } catch (NoSuchFieldException e) { |
127 | - e.printStackTrace(); | |
128 | - Main.logger.warning(e.getLocalizedMessage()); | |
124 | + NineLogger.instance.warning(e); | |
129 | 125 | } |
130 | 126 | break; |
131 | 127 | } |
@@ -138,7 +134,7 @@ | ||
138 | 134 | } |
139 | 135 | items.keyCode = key.toUpperCase().charAt(0); |
140 | 136 | } else { |
141 | - Main.logger.warning(String.format(CONFIG_LETTER_MISSING, key)); | |
137 | + NineLogger.instance.warning(String.format(CONFIG_LETTER_MISSING, key), null); | |
142 | 138 | } |
143 | 139 | } |
144 | 140 | } |
@@ -25,7 +25,7 @@ | ||
25 | 25 | import java.util.Map; |
26 | 26 | import java.util.regex.Pattern; |
27 | 27 | |
28 | -import jp.sourceforge.nine.Main; | |
28 | +import jp.sourceforge.nine.util.NineLogger; | |
29 | 29 | |
30 | 30 | public class KeyStrokeMapMaker { |
31 | 31 | private final Map<String, String> map; |
@@ -69,7 +69,7 @@ | ||
69 | 69 | if (buf.length() == 0) { return; } |
70 | 70 | String[] items = delimitaPattern.split(buf, 2); |
71 | 71 | if (items.length < 2) { |
72 | - Main.logger.warning(line); | |
72 | + NineLogger.instance.warning(line, null); | |
73 | 73 | return; |
74 | 74 | } |
75 | 75 | map.put(items[0], items[1]); |
@@ -27,6 +27,7 @@ | ||
27 | 27 | |
28 | 28 | import jp.sourceforge.nine.Main; |
29 | 29 | import jp.sourceforge.nine.js.ActionDefinitions; |
30 | +import jp.sourceforge.nine.util.NineLogger; | |
30 | 31 | |
31 | 32 | public class ActionMaker { |
32 | 33 |
@@ -65,21 +66,21 @@ | ||
65 | 66 | actions.add(action); |
66 | 67 | } catch (ClassNotFoundException e) { |
67 | 68 | // TODO: |
68 | - e.printStackTrace(); | |
69 | + NineLogger.instance.warning(e); | |
69 | 70 | } catch (SecurityException e) { |
70 | - e.printStackTrace(); | |
71 | + NineLogger.instance.warning(e); | |
71 | 72 | } catch (NoSuchMethodException e) { |
72 | - e.printStackTrace(); | |
73 | + NineLogger.instance.warning(e); | |
73 | 74 | } catch (IllegalArgumentException e) { |
74 | - e.printStackTrace(); | |
75 | + NineLogger.instance.warning(e); | |
75 | 76 | } catch (InstantiationException e) { |
76 | - e.printStackTrace(); | |
77 | + NineLogger.instance.warning(e); | |
77 | 78 | } catch (IllegalAccessException e) { |
78 | - e.printStackTrace(); | |
79 | + NineLogger.instance.warning(e); | |
79 | 80 | } catch (InvocationTargetException e) { |
80 | - e.printStackTrace(); | |
81 | + NineLogger.instance.warning(e); | |
81 | 82 | } catch (InvalidActionNameException e) { |
82 | - e.printStackTrace(); | |
83 | + NineLogger.instance.warning(e); | |
83 | 84 | } |
84 | 85 | } |
85 | 86 | ret = new Action[actions.size()]; |
@@ -47,6 +47,7 @@ | ||
47 | 47 | import jp.sourceforge.nine.buffer.BufferManager; |
48 | 48 | import jp.sourceforge.nine.editorkit.EditorKitMaker; |
49 | 49 | import jp.sourceforge.nine.js.NineJsContext; |
50 | +import jp.sourceforge.nine.util.NineLogger; | |
50 | 51 | import jp.sourceforge.nine.util.NineUtilities; |
51 | 52 | import jp.sourceforge.nine.util.RowLimitListener; |
52 | 53 |
@@ -74,9 +75,6 @@ | ||
74 | 75 | /** A document object of the buffer for log messages */ |
75 | 76 | static MarkableDocument messageDoc = null; |
76 | 77 | |
77 | - public final static Logger logger = | |
78 | - Logger.getLogger("jp.sourceforge.nine.defaultLogger"); | |
79 | - | |
80 | 78 | /** |
81 | 79 | * Launches this application. |
82 | 80 | * <p>Loads scripting configuration, and jar files in the |
@@ -138,7 +136,7 @@ | ||
138 | 136 | private static void setupLogMessageDocument() { |
139 | 137 | messageDoc = new MarkableDocument(); |
140 | 138 | messageDoc.addDocumentListener(new RowLimitListener(1000)); |
141 | - logger.addHandler(new MessagesDocumentHandler()); | |
139 | + Logger.getLogger(NineLogger.NAME).addHandler(new MessagesDocumentHandler()); | |
142 | 140 | } |
143 | 141 | |
144 | 142 | /** |
@@ -299,11 +297,9 @@ | ||
299 | 297 | } |
300 | 298 | }); |
301 | 299 | } catch (MalformedURLException e) { |
302 | - e.printStackTrace(); | |
303 | - logger.severe(e.getLocalizedMessage()); | |
300 | + NineLogger.instance.severe(e); | |
304 | 301 | } catch (NotFoundPluginFolderException e) { |
305 | - e.printStackTrace(); | |
306 | - logger.severe(e.getLocalizedMessage()); | |
302 | + NineLogger.instance.severe(e); | |
307 | 303 | } |
308 | 304 | pluginClassLoader = cl; |
309 | 305 | } |
@@ -27,6 +27,8 @@ | ||
27 | 27 | import javax.swing.text.ViewFactory; |
28 | 28 | import javax.swing.text.WrappedPlainView; |
29 | 29 | |
30 | +import jp.sourceforge.nine.util.NineLogger; | |
31 | + | |
30 | 32 | public class NineWrappedPlainView extends WrappedPlainView { |
31 | 33 | private final boolean wordWrap; |
32 | 34 | private int tabBase; |
@@ -153,7 +155,7 @@ | ||
153 | 155 | if (drawChars == null) { |
154 | 156 | drawChars = getDrawCharsMethod(); |
155 | 157 | if (drawChars == null) { |
156 | - Main.logger.severe("SwingUtilities2 is not found"); | |
158 | + NineLogger.instance.severe("SwingUtilities2 is not found", null); | |
157 | 159 | } |
158 | 160 | } |
159 | 161 |
@@ -31,7 +31,7 @@ | ||
31 | 31 | import java.util.Map; |
32 | 32 | import java.util.Set; |
33 | 33 | |
34 | -import jp.sourceforge.nine.Main; | |
34 | +import jp.sourceforge.nine.util.NineLogger; | |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * An object which keeps settings of color. |
@@ -68,7 +68,7 @@ | ||
68 | 68 | warningWrongColorName(foregroundColorName); |
69 | 69 | c = Color.BLACK; |
70 | 70 | foregroundColorName = "Black"; |
71 | - Main.logger.warning("foregound color has been changed to black."); | |
71 | + NineLogger.instance.warning("foregound color has been changed to black.", null); | |
72 | 72 | } |
73 | 73 | return c; |
74 | 74 | } |
@@ -79,7 +79,7 @@ | ||
79 | 79 | warningWrongColorName(backgroundColorName); |
80 | 80 | c = Color.WHITE; |
81 | 81 | backgroundColorName = "White"; |
82 | - Main.logger.warning("background color has been changed to white."); | |
82 | + NineLogger.instance.warning("background color has been changed to white.", null); | |
83 | 83 | } |
84 | 84 | return c; |
85 | 85 | } |
@@ -86,7 +86,7 @@ | ||
86 | 86 | |
87 | 87 | private void warningWrongColorName(String colorName) { |
88 | 88 | String m = "'%s' is a wrong color name."; |
89 | - Main.logger.warning(String.format(m, colorName)); | |
89 | + NineLogger.instance.warning(String.format(m, colorName), null); | |
90 | 90 | } |
91 | 91 | |
92 | 92 | private Color getColor(String color) { |
@@ -183,7 +183,7 @@ | ||
183 | 183 | String msg = "Color name '%s' is not found in '%s'. Color data is not generated."; |
184 | 184 | Iterator<String> it = colors.iterator(); |
185 | 185 | while (it.hasNext()) { |
186 | - Main.logger.warning(String.format(msg, it.next(), DATA_FILE)); | |
186 | + NineLogger.instance.warning(String.format(msg, it.next(), DATA_FILE), null); | |
187 | 187 | } |
188 | 188 | } |
189 | 189 |
@@ -199,7 +199,7 @@ | ||
199 | 199 | } else { |
200 | 200 | c = getForeground(); |
201 | 201 | String m = "Such color category is not found: %s"; |
202 | - Main.logger.warning(String.format(m, colorType)); | |
202 | + NineLogger.instance.warning(String.format(m, colorType), null); | |
203 | 203 | } |
204 | 204 | return c; |
205 | 205 | } |
@@ -24,7 +24,7 @@ | ||
24 | 24 | import java.io.IOException; |
25 | 25 | import java.lang.reflect.Method; |
26 | 26 | |
27 | -import jp.sourceforge.nine.Main; | |
27 | +import jp.sourceforge.nine.util.NineLogger; | |
28 | 28 | |
29 | 29 | import org.mozilla.javascript.Context; |
30 | 30 | import org.mozilla.javascript.ContextFactory; |
@@ -40,14 +40,11 @@ | ||
40 | 40 | try { |
41 | 41 | instance.execute(); |
42 | 42 | } catch (FileNotFoundException e) { |
43 | - e.printStackTrace(); | |
44 | - Main.logger.severe(e.getLocalizedMessage()); | |
43 | + NineLogger.instance.severe(e); | |
45 | 44 | } catch (IOException e) { |
46 | - e.printStackTrace(); | |
47 | - Main.logger.severe(e.getLocalizedMessage()); | |
45 | + NineLogger.instance.severe(e); | |
48 | 46 | } catch (EcmaError e) { |
49 | - e.printStackTrace(); | |
50 | - Main.logger.severe(e.getLocalizedMessage()); | |
47 | + NineLogger.instance.severe(e); | |
51 | 48 | } |
52 | 49 | } |
53 | 50 |
@@ -29,11 +29,11 @@ | ||
29 | 29 | import javax.swing.text.JTextComponent; |
30 | 30 | import javax.swing.text.Position; |
31 | 31 | |
32 | -import jp.sourceforge.nine.Main; | |
33 | 32 | import jp.sourceforge.nine.MainTextPane; |
34 | 33 | import jp.sourceforge.nine.action.util.ArgumentActionEvent; |
35 | 34 | import jp.sourceforge.nine.keymap.JmKeymap; |
36 | 35 | import jp.sourceforge.nine.keymap.JmKeymapMaker; |
36 | +import jp.sourceforge.nine.util.NineLogger; | |
37 | 37 | import jp.sourceforge.nine.util.NineUtilities; |
38 | 38 | |
39 | 39 | import org.mozilla.javascript.Context; |
@@ -145,8 +145,7 @@ | ||
145 | 145 | ret = (MainTextPane) o; |
146 | 146 | } |
147 | 147 | } catch (EvaluatorException e) { |
148 | - e.printStackTrace(); | |
149 | - Main.logger.warning(e.getLocalizedMessage()); | |
148 | + NineLogger.instance.warning(e); | |
150 | 149 | } |
151 | 150 | return ret; |
152 | 151 | } |
@@ -156,8 +155,7 @@ | ||
156 | 155 | Object o = Context.jsToJava(event, ActionEvent.class); |
157 | 156 | return o instanceof ArgumentActionEvent; |
158 | 157 | } catch (EvaluatorException e) { |
159 | - e.printStackTrace(); | |
160 | - Main.logger.warning(e.getLocalizedMessage()); | |
158 | + NineLogger.instance.warning(e); | |
161 | 159 | } |
162 | 160 | return false; |
163 | 161 | } |
@@ -170,8 +168,7 @@ | ||
170 | 168 | ret = (ArgumentActionEvent) o; |
171 | 169 | } |
172 | 170 | } catch (EvaluatorException e) { |
173 | - e.printStackTrace(); | |
174 | - Main.logger.warning(e.getLocalizedMessage()); | |
171 | + NineLogger.instance.warning(e); | |
175 | 172 | } |
176 | 173 | return ret; |
177 | 174 | } |
@@ -180,7 +177,7 @@ | ||
180 | 177 | try { |
181 | 178 | externalJar.add(new URL("file://" + jarPath)); |
182 | 179 | } catch (MalformedURLException e) { |
183 | - Main.logger.warning(e.getLocalizedMessage()); | |
180 | + NineLogger.instance.warning(e); | |
184 | 181 | } |
185 | 182 | } |
186 | 183 |
@@ -76,6 +76,7 @@ | ||
76 | 76 | import jp.sourceforge.nine.editorkit.TextEditorKit; |
77 | 77 | import jp.sourceforge.nine.js.FrameSettings; |
78 | 78 | import jp.sourceforge.nine.keymap.JmKeymapMaker; |
79 | +import jp.sourceforge.nine.util.NineLogger; | |
79 | 80 | import jp.sourceforge.nine.util.NineUtilities; |
80 | 81 | import jp.sourceforge.nine.util.NineUtilities.OS; |
81 | 82 |
@@ -315,15 +316,13 @@ | ||
315 | 316 | Class<? extends TextEditorKit> c = |
316 | 317 | l.loadClass(nm).asSubclass(TextEditorKit.class); |
317 | 318 | k = c.newInstance(); |
318 | - if (k != null) { | |
319 | - kitRegistory.put(type, k); | |
320 | - } | |
319 | + if (k != null) { kitRegistory.put(type, k); } | |
321 | 320 | } catch (ClassNotFoundException e) { |
322 | - e.printStackTrace(); | |
321 | + NineLogger.instance.warning(e); | |
323 | 322 | } catch (InstantiationException e) { |
324 | - e.printStackTrace(); | |
323 | + NineLogger.instance.warning(e); | |
325 | 324 | } catch (IllegalAccessException e) { |
326 | - e.printStackTrace(); | |
325 | + NineLogger.instance.warning(e); | |
327 | 326 | } |
328 | 327 | } |
329 | 328 | if (k != null) { k = (TextEditorKit) k.clone(); } |
@@ -341,26 +340,14 @@ | ||
341 | 340 | return bufferWindow; |
342 | 341 | } |
343 | 342 | |
344 | - /* | |
345 | - * (non-Javadoc) | |
346 | - * @see jp.sourceforge.nine.MainBufferPane#getWindow() | |
347 | - */ | |
348 | 343 | public BufferWindow getWindow() { |
349 | 344 | return bufferWindow; |
350 | 345 | } |
351 | 346 | |
352 | - /* | |
353 | - * (non-Javadoc) | |
354 | - * @see jp.sourceforge.nine.MainBufferPane#getBufferFile() | |
355 | - */ | |
356 | 347 | public File getBufferFile() { |
357 | 348 | return bufferFile; |
358 | 349 | } |
359 | 350 | |
360 | - /* | |
361 | - * (non-Javadoc) | |
362 | - * @see jp.sourceforge.nine.MainBufferPane#getBufferName() | |
363 | - */ | |
364 | 351 | public String getBufferName() { |
365 | 352 | return bufferName; |
366 | 353 | } |
@@ -23,9 +23,9 @@ | ||
23 | 23 | import java.io.File; |
24 | 24 | import java.text.MessageFormat; |
25 | 25 | |
26 | -import jp.sourceforge.nine.Main; | |
27 | 26 | import jp.sourceforge.nine.action.util.PromptLabelKey; |
28 | 27 | import jp.sourceforge.nine.util.MessageUtility; |
28 | +import jp.sourceforge.nine.util.NineLogger; | |
29 | 29 | import jp.sourceforge.nine.util.NineUtilities; |
30 | 30 | |
31 | 31 | @PromptLabelKey("make-directory") |
@@ -67,7 +67,7 @@ | ||
67 | 67 | // get failure |
68 | 68 | NineUtilities.beep(getTextComponent(e)); |
69 | 69 | String s = String.format("%s %s was failed", ACTION_NAME, txt); |
70 | - Main.logger.warning(s); | |
70 | + NineLogger.instance.warning(s, null); | |
71 | 71 | minibuffer.reset(s); |
72 | 72 | } |
73 | 73 | } |
@@ -27,7 +27,6 @@ | ||
27 | 27 | import javax.swing.text.JTextComponent; |
28 | 28 | |
29 | 29 | import jp.sourceforge.nine.BasicTextPane; |
30 | -import jp.sourceforge.nine.Main; | |
31 | 30 | import jp.sourceforge.nine.MainBufferPane; |
32 | 31 | import jp.sourceforge.nine.MinibufferPanel; |
33 | 32 | import jp.sourceforge.nine.RootPanel; |
@@ -34,6 +33,7 @@ | ||
34 | 33 | import jp.sourceforge.nine.action.ReplaceableAction.AltAction; |
35 | 34 | import jp.sourceforge.nine.action.util.ActionInfo; |
36 | 35 | import jp.sourceforge.nine.action.util.KeymapModifier; |
36 | +import jp.sourceforge.nine.util.NineLogger; | |
37 | 37 | import jp.sourceforge.nine.util.NineUtilities; |
38 | 38 | |
39 | 39 | public class QuotedInsertAction extends ScriptableTextAction { |
@@ -85,8 +85,7 @@ | ||
85 | 85 | p.insert(new String(new char[] { (char) v }), pos); |
86 | 86 | } |
87 | 87 | } catch (NumberFormatException e) { |
88 | - e.printStackTrace(); | |
89 | - Main.logger.warning(e.getLocalizedMessage()); | |
88 | + NineLogger.instance.warning(e); | |
90 | 89 | } |
91 | 90 | } |
92 | 91 |
@@ -24,9 +24,9 @@ | ||
24 | 24 | import javax.swing.text.JTextComponent; |
25 | 25 | import javax.swing.text.Position; |
26 | 26 | |
27 | -import jp.sourceforge.nine.Main; | |
28 | 27 | import jp.sourceforge.nine.MainTextPane; |
29 | 28 | import jp.sourceforge.nine.util.MessageUtility; |
29 | +import jp.sourceforge.nine.util.NineLogger; | |
30 | 30 | import jp.sourceforge.nine.util.NineUtilities; |
31 | 31 | |
32 | 32 | /** |
@@ -55,7 +55,7 @@ | ||
55 | 55 | exchangePointAndMark(textPane, mark); |
56 | 56 | } catch (BadLocationException ex) { |
57 | 57 | NineUtilities.beep(t); |
58 | - Main.logger.warning(ex.getLocalizedMessage()); | |
58 | + NineLogger.instance.warning(ex); | |
59 | 59 | } |
60 | 60 | } |
61 | 61 | } |
@@ -24,7 +24,6 @@ | ||
24 | 24 | import java.io.IOException; |
25 | 25 | import java.text.MessageFormat; |
26 | 26 | |
27 | -import jp.sourceforge.nine.Main; | |
28 | 27 | import jp.sourceforge.nine.MainTextPane; |
29 | 28 | import jp.sourceforge.nine.action.util.KillBufferCommand; |
30 | 29 | import jp.sourceforge.nine.action.util.PromptLabelKey; |
@@ -31,6 +30,7 @@ | ||
31 | 30 | import jp.sourceforge.nine.action.util.SaveBufferCommand; |
32 | 31 | import jp.sourceforge.nine.buffer.BufferManager; |
33 | 32 | import jp.sourceforge.nine.util.MessageUtility; |
33 | +import jp.sourceforge.nine.util.NineLogger; | |
34 | 34 | import jp.sourceforge.nine.util.NineUtilities; |
35 | 35 | |
36 | 36 | @PromptLabelKey("write-file") |
@@ -81,8 +81,7 @@ | ||
81 | 81 | manager.addBuffer(m); |
82 | 82 | } |
83 | 83 | } catch (IOException ex) { |
84 | - ex.printStackTrace(); | |
85 | - Main.logger.warning(ex.getLocalizedMessage()); | |
84 | + NineLogger.instance.warning(ex); | |
86 | 85 | } |
87 | 86 | } |
88 | 87 |
@@ -25,11 +25,11 @@ | ||
25 | 25 | import java.nio.charset.UnsupportedCharsetException; |
26 | 26 | import java.text.MessageFormat; |
27 | 27 | |
28 | -import jp.sourceforge.nine.Main; | |
29 | 28 | import jp.sourceforge.nine.MainTextPane; |
30 | 29 | import jp.sourceforge.nine.action.util.ActionArgument; |
31 | 30 | import jp.sourceforge.nine.action.util.PromptLabelKey; |
32 | 31 | import jp.sourceforge.nine.util.MessageUtility; |
32 | +import jp.sourceforge.nine.util.NineLogger; | |
33 | 33 | import jp.sourceforge.nine.util.NineUtilities; |
34 | 34 | |
35 | 35 | @PromptLabelKey("universal-coding-system-argument") |
@@ -58,13 +58,11 @@ | ||
58 | 58 | ActionArgument.generate(cs); |
59 | 59 | minibuffer.reset(getRequiringCommandLabel(cs)); |
60 | 60 | } catch (IllegalCharsetNameException ex) { |
61 | - ex.printStackTrace(); | |
62 | 61 | NineUtilities.beep(minibuffer); |
63 | - Main.logger.warning(ex.getLocalizedMessage()); | |
62 | + NineLogger.instance.warning(ex); | |
64 | 63 | } catch (UnsupportedCharsetException ex) { |
65 | - ex.printStackTrace(); | |
66 | 64 | NineUtilities.beep(minibuffer); |
67 | - Main.logger.warning(ex.getLocalizedMessage()); | |
65 | + NineLogger.instance.warning(ex); | |
68 | 66 | } |
69 | 67 | } |
70 | 68 |
@@ -32,6 +32,7 @@ | ||
32 | 32 | import jp.sourceforge.nine.action.util.PromptLabelKey; |
33 | 33 | import jp.sourceforge.nine.action.util.SaveBufferCommand; |
34 | 34 | import jp.sourceforge.nine.buffer.BufferManager; |
35 | +import jp.sourceforge.nine.util.NineLogger; | |
35 | 36 | import jp.sourceforge.nine.util.NineUtilities; |
36 | 37 | |
37 | 38 | @PromptLabelKey("save-buffers-kill-nine") |
@@ -62,10 +63,7 @@ | ||
62 | 63 | private void quit() { |
63 | 64 | // TODO: |
64 | 65 | SwingUtilities.invokeLater(new Runnable() { |
65 | - public void run() { | |
66 | -// Main.quit(); | |
67 | - Main.application.quit(); | |
68 | - } | |
66 | + public void run() { Main.application.quit(); } | |
69 | 67 | }); |
70 | 68 | } |
71 | 69 |
@@ -135,8 +133,7 @@ | ||
135 | 133 | try { |
136 | 134 | c.execute(); |
137 | 135 | } catch (IOException ex) { |
138 | - ex.printStackTrace(); | |
139 | - Main.logger.warning(ex.getLocalizedMessage()); | |
136 | + NineLogger.instance.warning(ex); | |
140 | 137 | } |
141 | 138 | } |
142 | 139 |
@@ -65,7 +65,8 @@ | ||
65 | 65 | * @return the {@code RootPanel} for component or {@code null}. |
66 | 66 | */ |
67 | 67 | public static RootPanel getRootPanel(JComponent component) { |
68 | - Container c = component.getParent(); | |
68 | + Container c = component instanceof Container ? | |
69 | + (Container) component : component.getParent(); | |
69 | 70 | if (c == null) { return null; } |
70 | 71 | do { |
71 | 72 | if (c instanceof RootPanel) { |
@@ -0,0 +1,99 @@ | ||
1 | +/* | |
2 | + * Copyright (C) 2009, mshio <mshio@users.sourceforge.jp> | |
3 | + * | |
4 | + * This program is free software: you can redistribute it and/or | |
5 | + * modify it under the terms of the GNU General Public License | |
6 | + * as published by the Free Software Foundation; either version 2 | |
7 | + * of the License, or any later version. | |
8 | + * | |
9 | + * This program is distributed in the hope that it will be useful, | |
10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | + * GNU General Public License for more details. | |
13 | + * | |
14 | + * You should have received a copy of the GNU General Public License | |
15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | + * --- | |
17 | + * Require JDK 1.5 (or later) | |
18 | + */ | |
19 | +package jp.sourceforge.nine.util; | |
20 | + | |
21 | +import java.util.logging.Level; | |
22 | +import java.util.logging.Logger; | |
23 | + | |
24 | +public class NineLogger { | |
25 | + public static final String NAME = "jp.sourceforge.nine.defaultLogger"; | |
26 | + public static final NineLogger instance = new NineLogger(); | |
27 | + | |
28 | + // TODO: these parameters will be set in the script file. | |
29 | + private boolean isVerbose = true; | |
30 | + private boolean stackTrace = true; | |
31 | + | |
32 | + private Logger getLogger() { | |
33 | + return Logger.getLogger(NAME); | |
34 | + } | |
35 | + | |
36 | + public void warning(Throwable thrown) { | |
37 | + doLog(Level.WARNING, thrown.getLocalizedMessage(), thrown); | |
38 | + } | |
39 | + | |
40 | + public void warning(String msg, Throwable thrown) { | |
41 | + doLog(Level.WARNING, msg, thrown); | |
42 | + } | |
43 | + | |
44 | + public void severe(Throwable thrown) { | |
45 | + doLog(Level.SEVERE, thrown.getLocalizedMessage(), thrown); | |
46 | + } | |
47 | + | |
48 | + public void severe(String msg, Throwable thrown) { | |
49 | + doLog(Level.SEVERE, msg, thrown); | |
50 | + } | |
51 | + | |
52 | + public void info(String msg) { | |
53 | + doLog(Level.INFO, msg, null); | |
54 | + } | |
55 | + | |
56 | + private void doLog(Level level, String msg, Throwable thrown) { | |
57 | + Logger logger = getLogger(); | |
58 | + | |
59 | + CallingMeClass c = getCallingMeClass(); | |
60 | + | |
61 | + if (isVerbose && thrown != null) { | |
62 | + logger.logp(level, c.className, c.methodName, msg, thrown); | |
63 | + } else { | |
64 | + logger.logp(level, c.className, c.methodName, msg); | |
65 | + } | |
66 | + if (stackTrace && thrown != null) { | |
67 | + thrown.printStackTrace(); | |
68 | + } | |
69 | + } | |
70 | + | |
71 | + private CallingMeClass getCallingMeClass() { | |
72 | + final String myName = this.getClass().getName(); | |
73 | + CallingMeClass ret = null; | |
74 | + boolean traceMe = true; | |
75 | + for (StackTraceElement e : new Throwable().getStackTrace()) { | |
76 | + String n = e.getClassName(); | |
77 | + if (traceMe) { | |
78 | + if (n.equals(myName)) { traceMe = false; } | |
79 | + } else { | |
80 | + if (! n.equals(myName)) { | |
81 | + ret = new CallingMeClass(n, e.getMethodName()); | |
82 | + break; | |
83 | + } | |
84 | + } | |
85 | + } | |
86 | + return ret; | |
87 | + } | |
88 | + | |
89 | + | |
90 | + class CallingMeClass { | |
91 | + final String className; | |
92 | + final String methodName; | |
93 | + | |
94 | + CallingMeClass(String className, String methodName) { | |
95 | + this.className = className; | |
96 | + this.methodName = methodName; | |
97 | + } | |
98 | + } | |
99 | +} |
@@ -24,7 +24,6 @@ | ||
24 | 24 | |
25 | 25 | import javax.swing.table.TableModel; |
26 | 26 | |
27 | -import jp.sourceforge.nine.Main; | |
28 | 27 | import jp.sourceforge.nine.MainBufferPane; |
29 | 28 | import jp.sourceforge.nine.MainTablePane; |
30 | 29 | import jp.sourceforge.nine.action.NineMinibufferAction; |
@@ -32,6 +31,7 @@ | ||
32 | 31 | import jp.sourceforge.nine.dired.DiredTableModel; |
33 | 32 | import jp.sourceforge.nine.dired.TableColumnType; |
34 | 33 | import jp.sourceforge.nine.util.MessageUtility; |
34 | +import jp.sourceforge.nine.util.NineLogger; | |
35 | 35 | |
36 | 36 | @PromptLabelKey("dired-flag-files-regexp") |
37 | 37 | public class DiredFlagFilesRegexpAction extends NineMinibufferAction { |
@@ -64,8 +64,7 @@ | ||
64 | 64 | } |
65 | 65 | } |
66 | 66 | } catch (PatternSyntaxException ex) { |
67 | - ex.printStackTrace(); | |
68 | - Main.logger.warning(ex.getLocalizedMessage()); | |
67 | + NineLogger.instance.warning(ex); | |
69 | 68 | } |
70 | 69 | mainTable.repaint(); |
71 | 70 | showResultMessage(count); |