001: package net.sourceforge.tracelog.ui;
002:
003: import net.sourceforge.tracelog.listeners.GenericListener;
004: import net.sourceforge.tracelog.utils.Util;
005:
006: import org.eclipse.swt.SWT;
007: import org.eclipse.swt.events.FocusEvent;
008: import org.eclipse.swt.events.ModifyEvent;
009: import org.eclipse.swt.events.ModifyListener;
010: import org.eclipse.swt.events.MouseEvent;
011: import org.eclipse.swt.graphics.Image;
012: import org.eclipse.swt.layout.GridData;
013: import org.eclipse.swt.layout.GridLayout;
014: import org.eclipse.swt.widgets.Button;
015: import org.eclipse.swt.widgets.Combo;
016: import org.eclipse.swt.widgets.Composite;
017: import org.eclipse.swt.widgets.Label;
018: import org.eclipse.swt.widgets.MessageBox;
019: import org.eclipse.swt.widgets.Text;
020:
021: public class ShellMainButtonBar extends AbstractWidget {
022: private static final int DEFAULT_LINE_THRESHOLD = 1000;
023: private Image imageStart;
024: private Image imageStop;
025: private Text lineThreshold;
026: private Combo purgePctCombo;
027: private Button startStopBtn;
028: private boolean toStopAllGroupLogs;
029:
030: ShellMainButtonBar() {
031: super ();
032: this .imageStop = new Image(display, Util
033: .getOwnResource(projectProperties.getIconStop()));
034: this .imageStart = new Image(display, Util
035: .getOwnResource(projectProperties.getIconStart()));
036: this .toStopAllGroupLogs = false;
037:
038: }
039:
040: public int getLineThreshold() {
041: String s = lineThreshold.getText();
042: int i = 0;
043:
044: try {
045: i = Integer.parseInt(s);
046:
047: if (i < 100) {
048: throw new NumberFormatException(
049: "Line count less than 100.");
050: }
051: } catch (NumberFormatException e) {
052: MessageBox mb = new MessageBox(parentShell, SWT.OK
053: | SWT.ICON_ERROR);
054: mb.setText("Error");
055: mb
056: .setMessage("Invalid line count: "
057: + s
058: + ". Please specify a numeric value greater than 100.");
059: mb.open();
060:
061: i = DEFAULT_LINE_THRESHOLD;
062: lineThreshold.setText(String
063: .valueOf(DEFAULT_LINE_THRESHOLD));
064: }
065:
066: return i;
067: }
068:
069: public int getPurgePercentage() {
070: String s = purgePctCombo.getItem(purgePctCombo
071: .getSelectionIndex());
072: s = s.replaceFirst("\\%", "");
073: return Integer.parseInt(s);
074: }
075:
076: public void resetStartStopButton() {
077: startStopBtn.setImage(imageStop);
078: startStopBtn.setToolTipText("Stop All Group Logs");
079: }
080:
081: public void run() {
082: GridLayout gridLayout = new GridLayout(6, false);
083: gridLayout.marginHeight = 0;
084: gridLayout.marginWidth = 0;
085: gridLayout.horizontalSpacing = 2;
086: gridLayout.verticalSpacing = 0;
087:
088: Composite barComposite = new Composite(parentShell, SWT.NONE);
089: barComposite.setLayout(gridLayout);
090: barComposite.setLayoutData(new GridData(
091: GridData.FILL_HORIZONTAL));
092:
093: Button optionBtn = new Button(barComposite, SWT.FLAT);
094: optionBtn.setToolTipText("Options...");
095: optionBtn.setImage(new Image(display, Util
096: .getOwnResource(projectProperties.getIconConfig())));
097:
098: Button zoomInBtn = new Button(barComposite, SWT.FLAT);
099: zoomInBtn.setImage(new Image(display, Util
100: .getOwnResource(projectProperties.getIconZoomIn())));
101: zoomInBtn.setToolTipText("Increase Font Size");
102:
103: Button zoomOutBtn = new Button(barComposite, SWT.FLAT);
104: zoomOutBtn.setImage(new Image(display, Util
105: .getOwnResource(projectProperties.getIconZoomOut())));
106: zoomOutBtn.setToolTipText("Decrease Font Size");
107:
108: startStopBtn = new Button(barComposite, SWT.FLAT);
109: startStopBtn.setImage(imageStop);
110: startStopBtn.setToolTipText("Stop All Group Logs");
111:
112: Button clearBtn = new Button(barComposite, SWT.FLAT);
113: clearBtn.setImage(new Image(display, Util
114: .getOwnResource(projectProperties.getIconClearAll())));
115: clearBtn.setToolTipText("Clear All Group Logs");
116:
117: Composite logPurgeComposite = new Composite(barComposite,
118: SWT.NONE);
119: logPurgeComposite.setLayout(new GridLayout(5, false));
120: logPurgeComposite.setLayoutData(new GridData(
121: GridData.FILL_HORIZONTAL
122: | GridData.HORIZONTAL_ALIGN_END));
123:
124: new Label(logPurgeComposite, SWT.NONE).setText("Purge");
125: purgePctCombo = new Combo(logPurgeComposite, SWT.READ_ONLY);
126: purgePctCombo.setItems(new String[] { "25%", "50%", "75%",
127: "100%" });
128:
129: purgePctCombo.select(0);
130: purgePctCombo.pack();
131: new Label(logPurgeComposite, SWT.NONE)
132: .setText("of the log when reaches ");
133: lineThreshold = new Text(logPurgeComposite, SWT.BORDER);
134: lineThreshold.setText(String.valueOf(DEFAULT_LINE_THRESHOLD));
135: lineThreshold.pack();
136: new Label(logPurgeComposite, SWT.NONE).setText("lines.");
137:
138: purgePctCombo.addModifyListener(new ModifyListener() {
139: public void modifyText(ModifyEvent e) {
140: mediator
141: .handleEvent(ActionMediator.EVENT_UPDATE_LOG_SIZE_HANDLER);
142: }
143: });
144:
145: lineThreshold.addFocusListener(new GenericListener() {
146: public void focusLost(FocusEvent e) {
147: mediator
148: .handleEvent(ActionMediator.EVENT_UPDATE_LOG_SIZE_HANDLER);
149: }
150: });
151:
152: optionBtn.addMouseListener(new GenericListener() {
153: public void mouseUp(MouseEvent e) {
154: mediator
155: .handleEvent(ActionMediator.EVENT_DISPLAY_OPTIONS);
156: }
157: });
158:
159: // increase font size
160: zoomInBtn.addMouseListener(new GenericListener() {
161: public void mouseUp(MouseEvent e) {
162: mediator
163: .handleEvent(ActionMediator.EVENT_INCREASE_FONT_SIZE);
164: }
165: });
166:
167: // decrease font size
168: zoomOutBtn.addMouseListener(new GenericListener() {
169: public void mouseUp(MouseEvent e) {
170: mediator
171: .handleEvent(ActionMediator.EVENT_DECREASE_FONT_SIZE);
172: }
173: });
174:
175: // start/stop all group logs
176: startStopBtn.addMouseListener(new GenericListener() {
177: public void mouseUp(MouseEvent e) {
178: // toggle this state
179: toStopAllGroupLogs = !toStopAllGroupLogs;
180: mediator
181: .handleEvent(ActionMediator.EVENT_START_STOP_ALL_GROUP_LOGS);
182: }
183: });
184:
185: // clear all group logs
186: clearBtn.addMouseListener(new GenericListener() {
187: public void mouseUp(MouseEvent e) {
188: mediator
189: .handleEvent(ActionMediator.EVENT_CLEAR_ALL_GROUP_LOGS);
190: }
191: });
192: }
193:
194: public void setupStartStopLogButton(boolean showStartState) {
195: if (showStartState) {
196: startStopBtn.setImage(imageStart);
197: startStopBtn.setToolTipText("Start All Group Logs");
198: } else {
199: startStopBtn.setImage(imageStop);
200: startStopBtn.setToolTipText("Stop All Group Logs");
201: }
202: }
203:
204: public boolean toStopAllGroupLogs() {
205: return toStopAllGroupLogs;
206: }
207: }
|