KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sourceforge.tracelog.ui;
2
3 import net.sourceforge.tracelog.listeners.GenericListener;
4 import net.sourceforge.tracelog.utils.Util;
5
6 import org.eclipse.swt.SWT;
7 import org.eclipse.swt.events.MouseEvent;
8 import org.eclipse.swt.graphics.Image;
9 import org.eclipse.swt.graphics.Point;
10 import org.eclipse.swt.layout.GridData;
11 import org.eclipse.swt.layout.GridLayout;
12 import org.eclipse.swt.widgets.Button;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Control;
15 import org.eclipse.swt.widgets.Event;
16 import org.eclipse.swt.widgets.Listener;
17 import org.eclipse.swt.widgets.Shell;
18 import org.eclipse.swt.widgets.Tree;
19 import org.eclipse.swt.widgets.TreeItem;
20
21 public class ShellOption extends AbstractWidget {
22     // private Logger log = Logger.getLogger(ShellOption.class);
23
private Shell optionShell;
24     private GridLayout defaultGL;
25
26     private Composite frameComposite;
27     private Composite categoryComposite;
28     private Composite contentComposite;
29     private Composite buttonComposite;
30
31     /**
32      * Package-access constructor.
33      */

34     ShellOption() {
35         super();
36         this.optionShell = null;
37
38         defaultGL = new GridLayout();
39         defaultGL.horizontalSpacing = 0;
40         defaultGL.verticalSpacing = 0;
41         defaultGL.marginHeight = 0;
42         defaultGL.marginWidth = 0;
43     }
44
45     public void run() {
46         // optionShell = new Shell(parentShell, SWT.DIALOG_TRIM |
47
// SWT.SYSTEM_MODAL);
48
optionShell = new Shell(parentShell, SWT.SHELL_TRIM | SWT.SYSTEM_MODAL);
49         optionShell.setImage(new Image(display, Util.getOwnResource(projectProperties.getShellIconPath())));
50         optionShell.setLayout(defaultGL);
51         optionShell.setText("Options");
52         optionShell.setMinimumSize(800, 600);
53
54         frameComposite = new Composite(optionShell, SWT.BORDER);
55         frameComposite.setLayout(new GridLayout(2, false));
56         frameComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
57
58         categoryComposite = new Composite(frameComposite, SWT.BORDER);
59         categoryComposite.setLayout(defaultGL);
60         GridData categoryGD = new GridData(GridData.FILL_VERTICAL);
61         categoryGD.widthHint = 150;
62         categoryComposite.setLayoutData(categoryGD);
63         categoryComposite.setBackground(Util.COLOR_WHITE);
64
65         contentComposite = new Composite(frameComposite, SWT.NONE);
66         contentComposite.setLayout(defaultGL);
67         contentComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
68
69         GridData buttonGD = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END);
70         buttonGD.horizontalSpan = 2;
71
72         buttonComposite = new Composite(frameComposite, SWT.NONE);
73         buttonComposite.setLayout(defaultGL);
74         buttonComposite.setLayoutData(buttonGD);
75
76         setupCategoryList();
77         setupButton();
78
79         // show general category by default
80
widgetFactory.createOptionShellGeneral(optionShell, contentComposite, mediator).run();
81
82         optionShell.pack();
83
84         Util.centerAlignedShell(parentShell, optionShell);
85         optionShell.open();
86     }
87
88     private void setupCategoryList() {
89         final Tree tree = new Tree(categoryComposite, SWT.NONE);
90
91         final TreeItem generalTI = new TreeItem(tree, SWT.FLAT);
92         generalTI.setText("General");
93
94         final TreeItem logConfigTI = new TreeItem(tree, SWT.FLAT);
95         logConfigTI.setText("Log Configuration");
96
97         final TreeItem logFileTI = new TreeItem(logConfigTI, SWT.FLAT);
98         logFileTI.setText("Log Files");
99
100         tree.addListener(SWT.MouseDown, new Listener() {
101             public void handleEvent(Event e) {
102                 TreeItem item = tree.getItem(new Point(e.x, e.y));
103
104                 if (item != null) {
105                     clearContent();
106
107                     if (item.equals(generalTI)) {
108                         widgetFactory.createOptionShellGeneral(optionShell, contentComposite, mediator).run();
109                     }
110                     else if (item.equals(logFileTI)) {
111                         widgetFactory.createOptionShellLogConfig(optionShell, contentComposite, mediator).run();
112                     }
113                 }
114             }
115         });
116     }
117
118     private void clearContent() {
119         for (Control control : contentComposite.getChildren()) {
120             control.dispose();
121         }
122     }
123
124     private void setupButton() {
125         Button closeBtn = new Button(buttonComposite, SWT.PUSH);
126         closeBtn.setText("Close");
127         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
128         gd.minimumWidth = 100;
129
130         closeBtn.setLayoutData(gd);
131
132         closeBtn.addMouseListener(new GenericListener() {
133             public void mouseUp(MouseEvent e) {
134                 optionShell.dispose();
135             }
136         });
137     }
138 }
139
Popular Tags