001: package net.sourceforge.tracelog.ui;
002:
003: import net.sourceforge.tracelog.config.ConfigFile;
004: import net.sourceforge.tracelog.config.ConfigFileFactory;
005: import net.sourceforge.tracelog.config.UserConfig;
006: import net.sourceforge.tracelog.listeners.GenericListener;
007: import net.sourceforge.tracelog.utils.Util;
008:
009: import org.eclipse.swt.SWT;
010: import org.eclipse.swt.events.MouseEvent;
011: import org.eclipse.swt.graphics.Cursor;
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.Composite;
016: import org.eclipse.swt.widgets.FileDialog;
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 ShellOptionGeneral extends AbstractWidget {
022: private ConfigFile configFile;
023: private Composite generalComposite;
024:
025: /**
026: * Package-access constructor.
027: */
028: ShellOptionGeneral() {
029: super ();
030: this .configFile = ConfigFileFactory.getInstance()
031: .getConfigFile();
032: }
033:
034: /**
035: * Controller to display the log config dialog.
036: */
037: public void run() {
038:
039: generalComposite = new Composite(parentComposite, SWT.NONE);
040:
041: generalComposite.setLayout(new GridLayout());
042: generalComposite
043: .setLayoutData(new GridData(GridData.FILL_BOTH));
044:
045: UIUtil.createTitle(generalComposite, "General");
046:
047: setupInstruction();
048: setTextEditorField();
049:
050: generalComposite.setSize(parentComposite.computeSize(
051: parentComposite.getSize().x, SWT.DEFAULT));
052: }
053:
054: private void setTextEditorField() {
055: Composite entryFieldsComposite = new Composite(
056: generalComposite, SWT.NONE);
057: GridLayout gridLayout = new GridLayout(5, true);
058: entryFieldsComposite.setLayout(gridLayout);
059: entryFieldsComposite.setLayoutData(new GridData(
060: GridData.FILL_HORIZONTAL));
061:
062: GridData span3Cells = new GridData(GridData.FILL_HORIZONTAL);
063: span3Cells.horizontalSpan = 3;
064:
065: Cursor cursorHand = new Cursor(display, SWT.CURSOR_HAND);
066:
067: Label label = new Label(entryFieldsComposite, SWT.NONE);
068: label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
069: label.setAlignment(SWT.RIGHT);
070: label.setText("Text Editor Path : ");
071:
072: final Text editorText = new Text(entryFieldsComposite,
073: SWT.BORDER);
074: editorText.setBackground(display
075: .getSystemColor(SWT.COLOR_WHITE));
076: editorText.setLayoutData(span3Cells);
077: editorText.setText(configFile.getUserConfig()
078: .getTextEditorPath());
079:
080: Button logFilePathButton = new Button(entryFieldsComposite,
081: SWT.PUSH);
082: logFilePathButton.setText("Browse...");
083: logFilePathButton.setCursor(cursorHand);
084: logFilePathButton.setLayoutData(new GridData(
085: GridData.FILL_HORIZONTAL));
086:
087: logFilePathButton.addMouseListener(new GenericListener() {
088: public void mouseUp(MouseEvent e) {
089: FileDialog fileDialog = new FileDialog(parentShell,
090: SWT.OPEN);
091: String fileName = fileDialog.open();
092: if (fileName == null) {
093: fileName = "";
094: }
095:
096: editorText.setText(fileName);
097: }
098: });
099:
100: Label spacer = new Label(entryFieldsComposite, SWT.NONE);
101: GridData spacerGD = new GridData(GridData.FILL_HORIZONTAL);
102: spacerGD.horizontalSpan = 4;
103: spacer.setLayoutData(spacerGD);
104:
105: Button saveBtn = new Button(entryFieldsComposite, SWT.PUSH);
106: saveBtn.setText("Save");
107: saveBtn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
108:
109: saveBtn.addMouseListener(new GenericListener() {
110: public void mouseUp(MouseEvent e) {
111: String editorPath = editorText.getText().trim();
112:
113: boolean isEmpty = editorPath.isEmpty();
114: // is empty, then default it to notepad
115: if (isEmpty) {
116: editorText.setText("notepad.exe");
117: editorPath = editorText.getText();
118: }
119:
120: UserConfig userConfig = configFile.getUserConfig();
121: userConfig.setTextEditorPath(editorPath);
122: configFile.saveUserConfig(userConfig);
123:
124: MessageBox mb = new MessageBox(parentShell, SWT.OK
125: | SWT.ICON_INFORMATION);
126: mb.setText("General Dialog");
127:
128: if (isEmpty) {
129: mb
130: .setMessage("No text editor is specified. Notepad editor will be used.");
131: } else {
132: mb.setMessage("Successfully saved.");
133: }
134:
135: mb.open();
136: }
137: });
138: }
139:
140: /**
141: * Displays the instruction label.
142: */
143: private void setupInstruction() {
144: Label label = new Label(generalComposite, SWT.WRAP);
145: label.setLayoutData(UIUtil.getGridDataFillHorizontal());
146:
147: String msg = "By setting up the text editor path below, you can open up the log file using your preferred text editor "
148: + "when you click on the \"Open Log File\" button of the right side of the log viewer."
149: + Util.LINE_BREAK + Util.LINE_BREAK;
150:
151: label.setText(msg);
152: }
153: }
|