KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > tracelog > ui > ActionMediator


1 /*
2  * ActionMediator.java May 7, 2007
3  */

4 package net.sourceforge.tracelog.ui;
5
6 import java.util.List JavaDoc;
7
8 import net.sourceforge.tracelog.config.LogFile;
9
10 import org.apache.log4j.Logger;
11 import org.eclipse.swt.events.ModifyEvent;
12 import org.eclipse.swt.widgets.Label;
13
14 public class ActionMediator implements IMediator {
15     private static Logger log = Logger.getLogger(ActionMediator.class);
16     // public static final int EVENT_CLEAR_LOG_SCREEN = 0;
17
// public static final int EVENT_INCREASE_FONT_SIZE = 1;
18
// public static final int EVENT_DECREASE_FONT_SIZE = 2;
19
public static final int EVENT_DISPLAY_OPTIONS = 3;
20     public static final int EVENT_DISPLAY_CHANGE_HISTORY = 4;
21     public static final int EVENT_DISPLAY_ABOUT = 5;
22     public static final int EVENT_DISPLAY_MAIN_SHELL = 6;
23     public static final int EVENT_SET_LOG_FILES = 7;
24     public static final int EVENT_SAVE_SERVER_LOG_CONFIGURATION = 8;
25     public static final int EVENT_UPDATE_TRAY_ICON = 9;
26     public static final int EVENT_DISPLAY_COLOR_CHOOSER = 10;
27     public static final int EVENT_UPDATE_LOG_SIZE_HANDLER = 11;
28     public static final int EVENT_DISPLAY_OPTION_GENERAL = 12;
29
30     private ShellMain shellMain;
31     private ShellTray shellTray;
32     private ShellAbout shellAbout;
33     private ShellHistory shellHistory;
34     private ShellOptionLogConfig shellOptionLogConfig;
35     private ShellMainLogViewer shellMainLogViewer;
36     private ShellOptionLogConfigColorChooser shellOptionLogConfigColorChooser;
37     // private ShellOptionGeneral shellOptionGeneral;
38
private ShellOption shellOption;
39
40     // private ShellMainMenuBar shellMainMenuBar;
41
private ShellMainButtonBar shellMainButtonBar;
42
43     ActionMediator() {
44     }
45
46     public void register(AbstractWidget widget) {
47         try {
48             if (widget instanceof ShellTray) {
49                 shellTray = (ShellTray) widget;
50             }
51             else if (widget instanceof ShellOptionLogConfigColorChooser) {
52                 shellOptionLogConfigColorChooser = (ShellOptionLogConfigColorChooser) widget;
53             }
54             else if (widget instanceof ShellMain) {
55                 shellMain = (ShellMain) widget;
56             }
57             else if (widget instanceof ShellAbout) {
58                 shellAbout = (ShellAbout) widget;
59             }
60             else if (widget instanceof ShellHistory) {
61                 shellHistory = (ShellHistory) widget;
62             }
63             else if (widget instanceof ShellOptionLogConfig) {
64                 shellOptionLogConfig = (ShellOptionLogConfig) widget;
65             }
66             else if (widget instanceof ShellMainLogViewer) {
67                 shellMainLogViewer = (ShellMainLogViewer) widget;
68             }
69             else if (widget instanceof ShellMainMenuBar) {
70             }
71             else if (widget instanceof ShellMainButtonBar) {
72                 shellMainButtonBar = (ShellMainButtonBar) widget;
73             }
74             else if (widget instanceof ShellOption) {
75                 shellOption = (ShellOption) widget;
76             }
77             else if (widget instanceof ShellOptionGeneral) {
78             }
79             else {
80                 throw new Exception JavaDoc("Unidentified widget: " + widget);
81             }
82         }
83         catch (Exception JavaDoc e) {
84             log.error(e.getMessage());
85         }
86     }
87
88     public void handleEvent(int event) {
89         switch (event) {
90             case EVENT_DISPLAY_OPTIONS:
91                 displayOptionShell();
92                 break;
93             case EVENT_DISPLAY_CHANGE_HISTORY:
94                 displayChangeHistory();
95                 break;
96             case EVENT_DISPLAY_ABOUT:
97                 displayAbout();
98                 break;
99             case EVENT_DISPLAY_MAIN_SHELL:
100                 displayMainShell();
101                 break;
102             case EVENT_SET_LOG_FILES:
103                 setLogFiles();
104                 break;
105             case EVENT_SAVE_SERVER_LOG_CONFIGURATION:
106                 saveServerLogConfiguration();
107                 break;
108             case EVENT_UPDATE_TRAY_ICON:
109                 updateTrayIcon();
110                 break;
111             case EVENT_DISPLAY_COLOR_CHOOSER:
112                 displayColorChooser();
113                 break;
114             case EVENT_UPDATE_LOG_SIZE_HANDLER:
115                 updateLogSizeHandler();
116                 break;
117             default:
118                 break;
119         }
120     }
121
122     private void updateLogSizeHandler() {
123         int lineThreshold = shellMainButtonBar.getLineThreshold();
124         int purgePercentage = shellMainButtonBar.getPurgePercentage();
125         shellMainLogViewer.updateLogSizeHandler(purgePercentage, lineThreshold);
126     }
127
128     private void displayColorChooser() {
129         Label text = shellOptionLogConfig.getText();
130         shellOptionLogConfigColorChooser.displayColorChooser(text);
131     }
132
133     private void updateTrayIcon() {
134         ModifyEvent event = shellMainLogViewer.getEvent();
135         shellTray.updateTrayIcon(event);
136     }
137
138     private void saveServerLogConfiguration() {
139         List JavaDoc<LogFile> logFiles = shellOptionLogConfig.getLogFiles();
140         shellMainLogViewer.saveLogFiles(logFiles);
141         shellMainLogViewer.redraw();
142     }
143
144     private void setLogFiles() {
145         List JavaDoc<LogFile> logFiles = shellMainLogViewer.getLogFiles();
146         shellOptionLogConfig.setLogFiles(logFiles);
147     }
148
149     // private void clearLogScreen() {
150
// shellMainLogViewer.clearSelectedLogScreen();
151
// }
152
//
153
// private void increaseFontSize() {
154
// shellMainLogViewer.increaseLogFont();
155
// }
156
//
157
// private void decreaseFontSize() {
158
// shellMainLogViewer.decreaseLogFont();
159
// }
160

161     private void displayOptionShell() {
162         // shellOptionLogConfig.run();
163
shellOption.run();
164     }
165
166     private void displayChangeHistory() {
167         shellHistory.run();
168     }
169
170     private void displayAbout() {
171         shellAbout.run();
172     }
173
174     private void displayMainShell() {
175         shellMain.run();
176     }
177 }
178
Popular Tags