KickJava   Java API By Example, From Geeks To Geeks.

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


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

4 package net.sourceforge.tracelog.ui;
5
6 import net.sourceforge.tracelog.utils.ProjectProperties;
7
8 import org.apache.log4j.Logger;
9 import org.eclipse.swt.widgets.Composite;
10 import org.eclipse.swt.widgets.Shell;
11
12 public class WidgetFactory {
13     private static Logger log = Logger.getLogger(WidgetFactory.class);
14     private static WidgetFactory widgetFactory;
15     private ProjectProperties projectProperties;
16
17     private WidgetFactory() {
18         this.projectProperties = ProjectProperties.getInstance();
19     }
20
21     public static WidgetFactory getInstance() {
22         if (widgetFactory == null) {
23             widgetFactory = new WidgetFactory();
24         }
25
26         return widgetFactory;
27     }
28
29     public AbstractWidget createMainShell() {
30         return getWidget(null, null, projectProperties.getMainShell());
31     }
32
33     public AbstractWidget createOptionShell(Shell parentShell, IMediator mediator) {
34         return getWidget(parentShell, mediator, projectProperties.getOptionShell());
35     }
36
37     public AbstractWidget createOptionShellLogConfig(Shell parentShell, Composite parentComposite, IMediator mediator) {
38         return getWidget(parentShell, parentComposite, mediator, projectProperties.getOptionShellLogConfig());
39     }
40
41     public AbstractWidget createOptionShellGeneral(Shell parentShell, Composite parentComposite, IMediator mediator) {
42         return getWidget(parentShell, parentComposite, mediator, projectProperties.getOptionShellGeneral());
43     }
44
45     public AbstractWidget createAboutShell(Shell parentShell, IMediator mediator) {
46         return getWidget(parentShell, mediator, projectProperties.getAboutShell());
47     }
48
49     public AbstractWidget createHistoryShell(Shell parentShell, IMediator mediator) {
50         return getWidget(parentShell, mediator, projectProperties.getHistoryShell());
51     }
52
53     public AbstractWidget createTrayShell(IMediator mediator) {
54         return getWidget(null, mediator, projectProperties.getTrayShell());
55     }
56
57     public AbstractWidget createMainShellButtonBar(Shell parentShell, IMediator mediator) {
58         return getWidget(parentShell, mediator, projectProperties.getMainShellButtonBar());
59     }
60
61     public AbstractWidget createMainShellMenuBar(Shell parentShell, IMediator mediator) {
62         return getWidget(parentShell, mediator, projectProperties.getMainShellMenuBar());
63     }
64
65     public AbstractWidget createMainShellLogViewer(Shell parentShell, IMediator mediator) {
66         return getWidget(parentShell, mediator, projectProperties.getMainShellLogViewer());
67     }
68
69     public AbstractWidget createLogConfigShellColorChooser(Shell parentShell, Composite parentComposite, IMediator mediator) {
70         return getWidget(parentShell, parentComposite, mediator, projectProperties.getOptionShellLogConfigColorChooser());
71     }
72
73     private AbstractWidget getWidget(Shell parentShell, IMediator mediator, String JavaDoc className) {
74         return getWidget(parentShell, null, mediator, className);
75     }
76
77     private AbstractWidget getWidget(Shell parentShell, Composite parentComposite, IMediator mediator, String JavaDoc className) {
78         AbstractWidget widget = null;
79
80         try {
81             Class JavaDoc<?> clazz = Class.forName(className);
82
83             widget = (AbstractWidget) clazz.newInstance();
84
85             if (parentShell != null) {
86                 widget.setParentShell((Shell) parentShell);
87             }
88
89             if (parentComposite != null) {
90                 widget.setParentComposite(parentComposite);
91             }
92
93             widget.setMediator(mediator);
94         }
95         catch (Exception JavaDoc e) {
96             e.printStackTrace();
97             log.error(e.getMessage());
98         }
99
100         return widget;
101     }
102 }
103
Popular Tags