KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > tracelog > ui > ShellMainButtonBar


1 /*
2  * ShellMainButtonBar.java May 7, 2007
3  */

4 package net.sourceforge.tracelog.ui;
5
6 import net.sourceforge.tracelog.listeners.GenericListener;
7 import net.sourceforge.tracelog.utils.Util;
8
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.events.FocusEvent;
11 import org.eclipse.swt.events.ModifyEvent;
12 import org.eclipse.swt.events.ModifyListener;
13 import org.eclipse.swt.events.MouseEvent;
14 import org.eclipse.swt.graphics.Image;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Button;
18 import org.eclipse.swt.widgets.Combo;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Label;
21 import org.eclipse.swt.widgets.MessageBox;
22 import org.eclipse.swt.widgets.Text;
23
24 public class ShellMainButtonBar extends AbstractWidget {
25     private Combo purgePctCombo;
26     private Text lineThreshold;
27     private static final int DEFAULT_LINE_THRESHOLD = 1000;
28
29     ShellMainButtonBar() {
30         super();
31     }
32
33     public void run() {
34         GridLayout gridLayout = new GridLayout(2, true);
35         gridLayout.marginHeight = 0;
36         gridLayout.marginWidth = 0;
37         gridLayout.horizontalSpacing = 2;
38         gridLayout.verticalSpacing = 0;
39
40         Composite barComposite = new Composite(parentShell, SWT.NONE);
41         barComposite.setLayout(gridLayout);
42         barComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
43
44         Button optionBtn = new Button(barComposite, SWT.FLAT);
45         optionBtn.setToolTipText("Options...");
46         optionBtn.setImage(new Image(display, Util.getOwnResource(projectProperties.getIconConfig())));
47
48         Composite logPurgeComposite = new Composite(barComposite, SWT.NONE);
49         logPurgeComposite.setLayout(new GridLayout(5, false));
50         logPurgeComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END));
51
52         new Label(logPurgeComposite, SWT.NONE).setText("Purge");
53         purgePctCombo = new Combo(logPurgeComposite, SWT.READ_ONLY);
54         purgePctCombo.setItems(new String JavaDoc[] {
55                 "25%",
56                 "50%",
57                 "75%",
58                 "100%"
59         });
60
61         purgePctCombo.select(0);
62         purgePctCombo.pack();
63         new Label(logPurgeComposite, SWT.NONE).setText("of the log when reaches ");
64         lineThreshold = new Text(logPurgeComposite, SWT.BORDER);
65         lineThreshold.setText(String.valueOf(DEFAULT_LINE_THRESHOLD));
66         lineThreshold.pack();
67         new Label(logPurgeComposite, SWT.NONE).setText("lines.");
68
69         purgePctCombo.addModifyListener(new ModifyListener() {
70             public void modifyText(ModifyEvent e) {
71                 mediator.handleEvent(ActionMediator.EVENT_UPDATE_LOG_SIZE_HANDLER);
72             }
73         });
74
75         lineThreshold.addFocusListener(new GenericListener() {
76             public void focusLost(FocusEvent e) {
77                 mediator.handleEvent(ActionMediator.EVENT_UPDATE_LOG_SIZE_HANDLER);
78             }
79         });
80
81         optionBtn.addMouseListener(new GenericListener() {
82             public void mouseUp(MouseEvent e) {
83                 mediator.handleEvent(ActionMediator.EVENT_DISPLAY_OPTIONS);
84             }
85         });
86
87     }
88
89     public int getPurgePercentage() {
90         String JavaDoc s = purgePctCombo.getItem(purgePctCombo.getSelectionIndex());
91         s = s.replaceFirst("\\%", "");
92         return Integer.parseInt(s);
93     }
94
95     public int getLineThreshold() {
96         String JavaDoc s = lineThreshold.getText();
97         int i = 0;
98
99         try {
100             i = Integer.parseInt(s);
101
102             if (i < 100) {
103                 throw new NumberFormatException JavaDoc("Line count less than 100.");
104             }
105         }
106         catch (NumberFormatException JavaDoc e) {
107             MessageBox mb = new MessageBox(parentShell, SWT.OK | SWT.ICON_ERROR);
108             mb.setText("Error");
109             mb.setMessage("Invalid line count: " + s + ". Please specify a numeric value greater than 100.");
110             mb.open();
111
112             i = DEFAULT_LINE_THRESHOLD;
113             lineThreshold.setText(String.valueOf(DEFAULT_LINE_THRESHOLD));
114         }
115
116         return i;
117     }
118 }
119
Popular Tags