1 package net.sourceforge.tracelog.ui; 2 3 import net.sourceforge.tracelog.config.ConfigFile; 4 import net.sourceforge.tracelog.config.ConfigFileFactory; 5 import net.sourceforge.tracelog.config.UserConfig; 6 import net.sourceforge.tracelog.listeners.GenericListener; 7 8 import org.eclipse.swt.SWT; 9 import org.eclipse.swt.events.MouseEvent; 10 import org.eclipse.swt.graphics.Cursor; 11 import org.eclipse.swt.layout.GridData; 12 import org.eclipse.swt.layout.GridLayout; 13 import org.eclipse.swt.widgets.Button; 14 import org.eclipse.swt.widgets.Composite; 15 import org.eclipse.swt.widgets.FileDialog; 16 import org.eclipse.swt.widgets.Label; 17 import org.eclipse.swt.widgets.MessageBox; 18 import org.eclipse.swt.widgets.Text; 19 20 public class ShellOptionGeneral extends AbstractWidget { 21 private Composite generalComposite; 22 private ConfigFile configFile; 23 24 27 ShellOptionGeneral() { 28 super(); 29 this.configFile = ConfigFileFactory.getInstance().getConfigFile(); 30 } 31 32 35 public void run() { 36 37 generalComposite = new Composite(parentComposite, SWT.NONE); 38 39 generalComposite.setLayout(new GridLayout()); 40 generalComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); 41 42 UIUtil.createTitle(generalComposite, "General"); 43 44 setTextEditorField(); 45 46 generalComposite.setSize(parentComposite.computeSize(parentComposite.getSize().x, SWT.DEFAULT)); 47 } 48 49 private void setTextEditorField() { 50 Composite entryFieldsComposite = new Composite(generalComposite, SWT.NONE); 51 GridLayout gridLayout = new GridLayout(5, true); 52 entryFieldsComposite.setLayout(gridLayout); 53 entryFieldsComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 54 55 GridData span3Cells = new GridData(GridData.FILL_HORIZONTAL); 56 span3Cells.horizontalSpan = 3; 57 58 Cursor cursorHand = new Cursor(display, SWT.CURSOR_HAND); 59 60 Label label = new Label(entryFieldsComposite, SWT.NONE); 61 label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 62 label.setAlignment(SWT.RIGHT); 63 label.setText("Text Editor Path : "); 64 65 final Text editorText = new Text(entryFieldsComposite, SWT.BORDER); 66 editorText.setBackground(display.getSystemColor(SWT.COLOR_WHITE)); 67 editorText.setLayoutData(span3Cells); 68 editorText.setText(configFile.getUserConfig().getTextEditorPath()); 69 70 Button logFilePathButton = new Button(entryFieldsComposite, SWT.PUSH); 71 logFilePathButton.setText("Browse..."); 72 logFilePathButton.setCursor(cursorHand); 73 logFilePathButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 74 75 logFilePathButton.addMouseListener(new GenericListener() { 76 public void mouseUp(MouseEvent e) { 77 FileDialog fileDialog = new FileDialog(parentShell, SWT.OPEN); 78 String fileName = fileDialog.open(); 79 if (fileName == null) { 80 fileName = ""; 81 } 82 83 editorText.setText(fileName); 84 } 85 }); 86 87 Label spacer = new Label(entryFieldsComposite, SWT.NONE); 88 GridData spacerGD = new GridData(GridData.FILL_HORIZONTAL); 89 spacerGD.horizontalSpan = 4; 90 spacer.setLayoutData(spacerGD); 91 92 Button saveBtn = new Button(entryFieldsComposite, SWT.PUSH); 93 saveBtn.setText("Save"); 94 saveBtn.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 95 96 saveBtn.addMouseListener(new GenericListener() { 97 public void mouseUp(MouseEvent e) { 98 String editorPath = editorText.getText().trim(); 99 100 boolean isEmpty = editorPath.isEmpty(); 101 if (isEmpty) { 103 editorText.setText("notepad.exe"); 104 editorPath = editorText.getText(); 105 } 106 107 UserConfig userConfig = configFile.getUserConfig(); 108 userConfig.setTextEditorPath(editorPath); 109 configFile.saveUserConfig(userConfig); 110 111 MessageBox mb = new MessageBox(parentShell, SWT.OK | SWT.ICON_INFORMATION); 112 mb.setText("General Dialog"); 113 114 if (isEmpty) { 115 mb.setMessage("No text editor is specified. Notepad editor will be used."); 116 } 117 else { 118 mb.setMessage("Successfully saved."); 119 } 120 121 mb.open(); 122 } 123 }); 124 } 125 } 126 | Popular Tags |