KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > swing > BarFactory


1 package com.opensymphony.workflow.designer.swing;
2
3 import java.awt.*;
4 import java.awt.dnd.DnDConstants JavaDoc;
5 import java.awt.dnd.DragSource JavaDoc;
6 import javax.swing.*;
7
8 import com.opensymphony.workflow.config.WorkspaceManager;
9 import com.opensymphony.workflow.designer.actions.*;
10 import com.opensymphony.workflow.designer.dnd.DragData;
11 import com.opensymphony.workflow.designer.dnd.TypeDragGesture;
12 import com.opensymphony.workflow.designer.ResourceManager;
13 import com.opensymphony.workflow.designer.ActionManager;
14 import com.opensymphony.workflow.designer.swing.status.StatusBar;
15 import com.opensymphony.workflow.designer.swing.status.StatusDisplay;
16 import com.opensymphony.workflow.designer.swing.status.MemoryDisplay;
17 import com.opensymphony.workflow.designer.swing.plaf.BlueButtonUI;
18 import com.jgoodies.plaf.HeaderStyle;
19 import com.jgoodies.plaf.Options;
20 import com.jgoodies.plaf.LookUtils;
21
22 /**
23  * @author jackflit
24  * Date: 2003-11-27
25  */

26 public class BarFactory
27 {
28   public static JMenuBar createMenubar(WorkspaceManager manager)
29   {
30     JMenuBar menuBar = new JMenuBar();
31
32     JMenu fileMenu = new JMenu(ResourceManager.getString("menu.file"));
33
34     JMenu itemNew = new JMenu(ResourceManager.getString("menu.new"));
35     itemNew.setIcon(ResourceManager.getIcon("newfile"));
36     itemNew.setHorizontalTextPosition(JMenu.RIGHT);
37     fileMenu.add(itemNew);
38
39     JMenuItem item;
40
41     Action newSpace = new NewWorkspace();
42     item = new JMenuItem(ActionManager.register("newspace", newSpace));
43     itemNew.add(item);
44
45     NewWorkflow newWorkflow = new NewWorkflow();
46     manager.addWorkspaceListener(newWorkflow);
47     item = new JMenuItem(ActionManager.register("newflow", newWorkflow));
48     itemNew.add(item);
49
50     item = new JMenuItem(ActionManager.register("openspace", new OpenWorkspace()));
51     fileMenu.add(item);
52
53     CloseWorkspace closeSpace = new CloseWorkspace();
54     manager.addWorkspaceListener(closeSpace);
55     item = new JMenuItem(ActionManager.register("closespace", closeSpace));
56     fileMenu.add(item);
57
58     CloseWorkflow closeWorkflow = new CloseWorkflow();
59     item = new JMenuItem(ActionManager.register("closeflow", closeWorkflow));
60     fileMenu.add(item);
61
62     ImportWorkflow importWorkflow = new ImportWorkflow();
63     manager.addWorkspaceListener(importWorkflow);
64     item = new JMenuItem(ActionManager.register("importflow", importWorkflow));
65     fileMenu.add(item);
66
67     PNGExport export = new PNGExport();
68     manager.addWorkspaceListener(export);
69     item = new JMenuItem(ActionManager.register("pngexport", export));
70     fileMenu.add(item);
71
72     fileMenu.addSeparator();
73
74     SaveWorkspace save = new SaveWorkspace();
75     manager.addWorkspaceListener(save);
76     item = new JMenuItem(ActionManager.register("savespace", save));
77     fileMenu.add(item);
78
79     item = new JMenuItem(ActionManager.register("quit", new Quit()));
80     if(!LookUtils.IS_OS_MAC)
81     {
82       fileMenu.addSeparator();
83       fileMenu.add(item);
84     }
85
86     JMenu viewMenu = new JMenu(ResourceManager.getString("menu.layout"));
87     AutoLayout auto = new AutoLayout(null);
88     manager.addWorkspaceListener(auto);
89     item = new JMenuItem(ActionManager.register("autolayout", auto));
90     viewMenu.add(item);
91
92     JMenu editMenu = new JMenu(ResourceManager.getString("menu.edit"));
93     item = new JMenuItem(ActionManager.register("undo", new EditUndo()));
94     editMenu.add(item);
95     item = new JMenuItem(ActionManager.register("redo", new EditRedo()));
96     editMenu.add(item);
97     
98     menuBar.add(fileMenu);
99     menuBar.add(editMenu);
100     menuBar.add(viewMenu);
101
102     return menuBar;
103   }
104
105   public static StatusBar createStatusBar()
106   {
107     StatusBar bar = new StatusBar();
108     StatusDisplay progress = new StatusDisplay();
109     bar.add(progress);
110     bar.add(Box.createHorizontalStrut(30));
111     bar.add(Box.createHorizontalGlue());
112     MemoryDisplay memory = new MemoryDisplay();
113     memory.setMaximumSize(new Dimension(180, memory.getMaximumSize().height));
114     bar.add(memory);
115     return bar;
116   }
117
118   public static JPanel createToolbar()
119   {
120     JToolBar bar = new JToolBar();
121     bar.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
122     bar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
123     JButton step = new JButton(ResourceManager.getIcon("newstep"));
124       step.setUI(new BlueButtonUI());
125     step.setToolTipText(ResourceManager.getString("createstep"));
126     bar.add(step);
127     DragSource JavaDoc ds = new DragSource JavaDoc();
128     ds.createDefaultDragGestureRecognizer(step, DnDConstants.ACTION_COPY, new TypeDragGesture(ds, DragData.STEP));
129
130     JButton join = new JButton(ResourceManager.getIcon("newjoin"));
131       join.setUI(new BlueButtonUI());
132     join.setToolTipText(ResourceManager.getString("createjoin"));
133     bar.add(join);
134     ds = new DragSource JavaDoc();
135     ds.createDefaultDragGestureRecognizer(join, DnDConstants.ACTION_COPY, new TypeDragGesture(ds, DragData.JOIN));
136
137     JButton split = new JButton(ResourceManager.getIcon("newsplit"));
138     split.setToolTipText(ResourceManager.getString("createsplit"));
139       split.setUI(new BlueButtonUI());
140     bar.add(split);
141     ds = new DragSource JavaDoc();
142     ds.createDefaultDragGestureRecognizer(split, DnDConstants.ACTION_COPY, new TypeDragGesture(ds, DragData.SPLIT));
143
144     JPanel panel = new JPanel(new BorderLayout());
145     panel.add(bar, BorderLayout.NORTH);
146
147     return panel;
148   }
149 }
150
Popular Tags