1 4 package net.sourceforge.tracelog.ui; 5 6 import java.util.List ; 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_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 ShellOption shellOption; 39 40 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 ("Unidentified widget: " + widget); 81 } 82 } 83 catch (Exception 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 <LogFile> logFiles = shellOptionLogConfig.getLogFiles(); 140 shellMainLogViewer.saveLogFiles(logFiles); 141 shellMainLogViewer.redraw(); 142 } 143 144 private void setLogFiles() { 145 List <LogFile> logFiles = shellMainLogViewer.getLogFiles(); 146 shellOptionLogConfig.setLogFiles(logFiles); 147 } 148 149 161 private void displayOptionShell() { 162 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 |