001: package net.sourceforge.tracelog.ui;
002:
003: import org.eclipse.swt.widgets.Label;
004:
005: public class ActionMediator implements IMediator {
006: // private static Logger log = Logger.getLogger(ActionMediator.class);
007:
008: public static final int EVENT_CLEAR_ALL_GROUP_LOGS = 1;
009: public static final int EVENT_DECREASE_FONT_SIZE = 2;
010: public static final int EVENT_DISPLAY_ABOUT = 3;
011: public static final int EVENT_DISPLAY_CHANGE_HISTORY = 4;
012: public static final int EVENT_DISPLAY_COLOR_CHOOSER = 5;
013: public static final int EVENT_DISPLAY_MAIN_SHELL = 6;
014: public static final int EVENT_DISPLAY_OPTIONS = 7;
015: public static final int EVENT_INCREASE_FONT_SIZE = 8;
016: public static final int EVENT_REDRAW_LOG_VIEWERS = 9;
017: public static final int EVENT_START_STOP_ALL_GROUP_LOGS = 10;
018: public static final int EVENT_UPDATE_GLOBAL_START_STOP_ICON = 11;
019: public static final int EVENT_UPDATE_LOG_SIZE_HANDLER = 12;
020:
021: private ShellAbout shellAbout;
022: private ShellHistory shellHistory;
023: private ShellMain shellMain;
024: private ShellMainButtonBar shellMainButtonBar;
025: private ShellMainLogViewer shellMainLogViewer;
026: private ShellOption shellOption;
027: private ShellOptionLogFile shellOptionLogConfig;
028: private ShellOptionLogFileColorChooser shellOptionLogConfigColorChooser;
029:
030: ActionMediator() {
031: }
032:
033: public void handleEvent(int event) {
034: switch (event) {
035: case EVENT_DISPLAY_OPTIONS:
036: displayOptionShell();
037: break;
038: case EVENT_DISPLAY_CHANGE_HISTORY:
039: displayChangeHistory();
040: break;
041: case EVENT_DISPLAY_ABOUT:
042: displayAbout();
043: break;
044: case EVENT_DISPLAY_MAIN_SHELL:
045: displayMainShell();
046: break;
047: case EVENT_DISPLAY_COLOR_CHOOSER:
048: displayColorChooser();
049: break;
050: case EVENT_UPDATE_LOG_SIZE_HANDLER:
051: updateLogSizeHandler();
052: break;
053: case EVENT_INCREASE_FONT_SIZE:
054: increaseFontSize();
055: break;
056: case EVENT_DECREASE_FONT_SIZE:
057: decreaseFontSize();
058: break;
059: case EVENT_REDRAW_LOG_VIEWERS:
060: redrawLogViewers();
061: break;
062: case EVENT_START_STOP_ALL_GROUP_LOGS:
063: startStopAllGroupLogs();
064: break;
065: case EVENT_UPDATE_GLOBAL_START_STOP_ICON:
066: updateGlobalStartStopIcon();
067: break;
068: case EVENT_CLEAR_ALL_GROUP_LOGS:
069: clearAllGroupLogs();
070: break;
071: default:
072: break;
073: }
074: }
075:
076: public void register(AbstractWidget widget) {
077: if (widget instanceof ShellOptionLogFileColorChooser) {
078: shellOptionLogConfigColorChooser = (ShellOptionLogFileColorChooser) widget;
079: } else if (widget instanceof ShellMain) {
080: shellMain = (ShellMain) widget;
081: } else if (widget instanceof ShellAbout) {
082: shellAbout = (ShellAbout) widget;
083: } else if (widget instanceof ShellHistory) {
084: shellHistory = (ShellHistory) widget;
085: } else if (widget instanceof ShellOptionLogFile) {
086: shellOptionLogConfig = (ShellOptionLogFile) widget;
087: } else if (widget instanceof ShellMainLogViewer) {
088: shellMainLogViewer = (ShellMainLogViewer) widget;
089: } else if (widget instanceof ShellMainMenuBar) {
090: } else if (widget instanceof ShellMainButtonBar) {
091: shellMainButtonBar = (ShellMainButtonBar) widget;
092: } else if (widget instanceof ShellOption) {
093: shellOption = (ShellOption) widget;
094: }
095: }
096:
097: private void clearAllGroupLogs() {
098: shellMainLogViewer.clearAllGroupLogs();
099: }
100:
101: private void decreaseFontSize() {
102: shellMainLogViewer.decreaseLogFont();
103: }
104:
105: private void displayAbout() {
106: shellAbout.run();
107: }
108:
109: private void displayChangeHistory() {
110: shellHistory.run();
111: }
112:
113: private void displayColorChooser() {
114: Label text = shellOptionLogConfig.getColorSelection();
115: shellOptionLogConfigColorChooser.displayColorChooser(text);
116: }
117:
118: private void displayMainShell() {
119: shellMain.run();
120: }
121:
122: private void displayOptionShell() {
123: shellOption.run();
124: }
125:
126: private void increaseFontSize() {
127: shellMainLogViewer.increaseLogFont();
128: }
129:
130: private void redrawLogViewers() {
131: shellMainLogViewer.destroy();
132: shellMain.createLogViewer();
133: shellMainButtonBar.resetStartStopButton();
134: }
135:
136: private void startStopAllGroupLogs() {
137: boolean toStopAllGroupLogs = shellMainButtonBar
138: .toStopAllGroupLogs();
139: shellMainLogViewer
140: .toggleStartStopAllGroupLogs(toStopAllGroupLogs);
141: }
142:
143: private void updateGlobalStartStopIcon() {
144: boolean showStartState = shellMainLogViewer.allLogsStopped();
145: shellMainButtonBar.setupStartStopLogButton(showStartState);
146: }
147:
148: private void updateLogSizeHandler() {
149: int lineThreshold = shellMainButtonBar.getLineThreshold();
150: int purgePercentage = shellMainButtonBar.getPurgePercentage();
151: shellMainLogViewer.updateAllLogSizeHandlers(purgePercentage,
152: lineThreshold);
153: }
154: }
|