001: package net.sourceforge.tracelog.ui;
002:
003: import java.util.LinkedList;
004: import java.util.List;
005:
006: import net.sourceforge.tracelog.config.ConfigFile;
007: import net.sourceforge.tracelog.config.ConfigFileFactory;
008: import net.sourceforge.tracelog.config.LogGroup;
009: import net.sourceforge.tracelog.config.UserConfig;
010:
011: import org.eclipse.swt.SWT;
012: import org.eclipse.swt.graphics.Font;
013: import org.eclipse.swt.layout.GridData;
014: import org.eclipse.swt.widgets.TabFolder;
015: import org.eclipse.swt.widgets.TabItem;
016:
017: public class ShellMainLogViewer extends AbstractWidget {
018: // private static Logger log = Logger.getLogger(ShellMainLogViewer.class);
019:
020: private static final int DEFAULT_FONT_SIZE = 9;
021: private ConfigFile configFile;
022: private int logFontSize;
023: private List<ShellMainLogGroupTabFolder> logGroupList;
024: private TabFolder tabFolder;
025:
026: ShellMainLogViewer() {
027: super ();
028: this .configFile = ConfigFileFactory.getInstance()
029: .getConfigFile();
030: this .logGroupList = new LinkedList<ShellMainLogGroupTabFolder>();
031: this .logFontSize = DEFAULT_FONT_SIZE;
032: }
033:
034: public boolean allLogsStopped() {
035: for (ShellMainLogGroupTabFolder shellMainLogGroupTabFolder : logGroupList) {
036: // one of the main log has already started
037: if (shellMainLogGroupTabFolder.isMainLogStarted()) {
038: return false;
039: }
040: }
041:
042: return true;
043: }
044:
045: public void clearAllGroupLogs() {
046: for (ShellMainLogGroupTabFolder shellMainLogGroupTabFolder : logGroupList) {
047: shellMainLogGroupTabFolder.clearAllLogViewers();
048: }
049: }
050:
051: /**
052: * Decreases log font size.
053: */
054: public void decreaseLogFont() {
055: if (logFontSize > DEFAULT_FONT_SIZE) {
056: logFontSize--;
057: updateAllLogViewerFonts();
058: }
059: }
060:
061: public void destroy() {
062: for (ShellMainLogGroupTabFolder shellMainLogGroupTabFolder : logGroupList) {
063: shellMainLogGroupTabFolder.destroy();
064: }
065:
066: if (tabFolder != null) {
067: tabFolder.dispose();
068: }
069:
070: logGroupList.clear();
071: }
072:
073: /**
074: * Increases log font size.
075: */
076: public void increaseLogFont() {
077: if (logFontSize < 19) {
078: logFontSize++;
079: updateAllLogViewerFonts();
080: }
081: }
082:
083: /**
084: * Sets up the tab items in the tab folder and then starts all log daemons.
085: */
086: public void run() {
087: UserConfig userConfig = configFile.getUserConfig();
088:
089: List<LogGroup> logGroups = userConfig.getLogGroups();
090:
091: boolean createGroupTab = (logGroups.size() > 1);
092:
093: tabFolder = new TabFolder(parentShell, SWT.NONE);
094: tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
095:
096: for (LogGroup logGroup : logGroups) {
097: // create group tab if there is more than one log group
098: if (createGroupTab) {
099: // sub tab folder for log files within a log group
100: TabFolder subTabFolder = new TabFolder(tabFolder,
101: SWT.NONE);
102: subTabFolder.setLayoutData(new GridData(
103: GridData.FILL_BOTH));
104:
105: // group tab item
106: TabItem groupTI = new TabItem(tabFolder, SWT.NONE);
107: groupTI.setText(logGroup.getGroupName());
108: groupTI.setControl(subTabFolder);
109:
110: createLogViewer(logGroup, subTabFolder);
111: } else {
112: createLogViewer(logGroup, tabFolder);
113: }
114: }
115:
116: updateAllLogViewerFonts();
117:
118: mediator
119: .handleEvent(ActionMediator.EVENT_UPDATE_LOG_SIZE_HANDLER);
120: }
121:
122: public void toggleStartStopAllGroupLogs(boolean toStopAllGroupLogs) {
123: for (ShellMainLogGroupTabFolder shellMainLogGroupTabFolder : logGroupList) {
124: shellMainLogGroupTabFolder
125: .toogleStartStopMainLog(toStopAllGroupLogs);
126: }
127: }
128:
129: public void updateAllLogSizeHandlers(int purgePercentage,
130: int logLineThreshold) {
131: for (ShellMainLogGroupTabFolder shellMainLogGroupTabFolder : logGroupList) {
132: shellMainLogGroupTabFolder.updateLogSizeHandler(
133: purgePercentage, logLineThreshold);
134: }
135: }
136:
137: public void updateAllLogViewerFonts() {
138: for (ShellMainLogGroupTabFolder shellMainLogGroupTabFolder : logGroupList) {
139: shellMainLogGroupTabFolder.updateLogFont(getLogFont());
140: }
141: }
142:
143: private void createLogViewer(LogGroup logGroup, TabFolder tabFolder) {
144: ShellMainLogGroupTabFolder shellMainLogGroupTabFolder = new ShellMainLogGroupTabFolder(
145: mediator, logGroup.getLogFiles(), tabFolder);
146: shellMainLogGroupTabFolder.run();
147:
148: logGroupList.add(shellMainLogGroupTabFolder);
149: }
150:
151: /**
152: * Creates and return new font object.
153: *
154: * @return Font object.
155: */
156: private Font getLogFont() {
157: return new Font(display, "Courier New", logFontSize, SWT.NORMAL);
158: }
159: }
|