001: package com.opensymphony.workflow.designer.swing;
002:
003: import java.awt.*;
004: import java.awt.dnd.DnDConstants;
005: import java.awt.dnd.DragSource;
006: import javax.swing.*;
007:
008: import com.opensymphony.workflow.config.WorkspaceManager;
009: import com.opensymphony.workflow.designer.actions.*;
010: import com.opensymphony.workflow.designer.dnd.DragData;
011: import com.opensymphony.workflow.designer.dnd.TypeDragGesture;
012: import com.opensymphony.workflow.designer.ResourceManager;
013: import com.opensymphony.workflow.designer.ActionManager;
014: import com.opensymphony.workflow.designer.swing.status.StatusBar;
015: import com.opensymphony.workflow.designer.swing.status.StatusDisplay;
016: import com.opensymphony.workflow.designer.swing.status.MemoryDisplay;
017: import com.opensymphony.workflow.designer.swing.plaf.BlueButtonUI;
018: import com.jgoodies.plaf.HeaderStyle;
019: import com.jgoodies.plaf.Options;
020: import com.jgoodies.plaf.LookUtils;
021:
022: /**
023: * @author jackflit
024: * Date: 2003-11-27
025: */
026: public class BarFactory {
027: public static JMenuBar createMenubar(WorkspaceManager manager,
028: String mode) {
029: JMenuItem item;
030: JMenuBar menuBar = new JMenuBar();
031: JMenu fileMenu = new JMenu(ResourceManager
032: .getString("menu.file"));
033:
034: if (mode == null || mode.equals("new")) {
035: JMenu itemNew = new JMenu(ResourceManager
036: .getString("menu.new"));
037: itemNew.setIcon(ResourceManager.getIcon("newfile"));
038: itemNew.setHorizontalTextPosition(JMenu.RIGHT);
039: fileMenu.add(itemNew);
040:
041: if (mode == null) {
042: Action newSpace = new NewWorkspace();
043: item = new JMenuItem(ActionManager.register("newspace",
044: newSpace));
045: itemNew.add(item);
046: }
047:
048: NewWorkflow newWorkflow = new NewWorkflow();
049: manager.addWorkspaceListener(newWorkflow);
050: item = new JMenuItem(ActionManager.register("newflow",
051: newWorkflow));
052: itemNew.add(item);
053:
054: if (mode == null) {
055: item = new JMenuItem(ActionManager.register(
056: "openspace", new OpenWorkspace()));
057: fileMenu.add(item);
058:
059: CloseWorkspace closeSpace = new CloseWorkspace();
060: manager.addWorkspaceListener(closeSpace);
061: item = new JMenuItem(ActionManager.register(
062: "closespace", closeSpace));
063: fileMenu.add(item);
064:
065: CloseWorkflow closeWorkflow = new CloseWorkflow();
066: item = new JMenuItem(ActionManager.register(
067: "closeflow", closeWorkflow));
068: fileMenu.add(item);
069:
070: ImportWorkflow importWorkflow = new ImportWorkflow();
071: manager.addWorkspaceListener(importWorkflow);
072: item = new JMenuItem(ActionManager.register(
073: "importflow", importWorkflow));
074: fileMenu.add(item);
075: }
076: }
077:
078: PNGExport export = new PNGExport();
079: manager.addWorkspaceListener(export);
080: item = new JMenuItem(ActionManager
081: .register("pngexport", export));
082: fileMenu.add(item);
083:
084: fileMenu.addSeparator();
085:
086: ValidateWorkflow validateWorkflow = new ValidateWorkflow();
087: manager.addWorkspaceListener(validateWorkflow);
088: item = new JMenuItem(ActionManager.register("validateflow",
089: validateWorkflow));
090: fileMenu.add(item);
091:
092: ValidateSaveWorkflow validateSaveWorkflow = new ValidateSaveWorkflow();
093: manager.addWorkspaceListener(validateSaveWorkflow);
094: item = new JMenuItem(ActionManager.register("validatesaveflow",
095: validateSaveWorkflow));
096: fileMenu.add(item);
097:
098: fileMenu.addSeparator();
099:
100: SaveWorkspace save = new SaveWorkspace();
101: manager.addWorkspaceListener(save);
102: item = new JMenuItem(ActionManager.register("savespace", save));
103: fileMenu.add(item);
104:
105: item = new JMenuItem(ActionManager.register("quit", new Quit()));
106: if (!LookUtils.IS_OS_MAC) {
107: fileMenu.addSeparator();
108: fileMenu.add(item);
109: }
110:
111: JMenu viewMenu = new JMenu(ResourceManager
112: .getString("menu.layout"));
113: AutoLayout auto = new AutoLayout(null);
114: manager.addWorkspaceListener(auto);
115: item = new JMenuItem(ActionManager.register("autolayout", auto));
116: viewMenu.add(item);
117:
118: JMenu editMenu = new JMenu(ResourceManager
119: .getString("menu.edit"));
120: item = new JMenuItem(ActionManager.register("undo",
121: new EditUndo()));
122: editMenu.add(item);
123: item = new JMenuItem(ActionManager.register("redo",
124: new EditRedo()));
125: editMenu.add(item);
126:
127: menuBar.add(fileMenu);
128: menuBar.add(editMenu);
129: menuBar.add(viewMenu);
130:
131: return menuBar;
132: }
133:
134: public static StatusBar createStatusBar() {
135: StatusBar bar = new StatusBar();
136: StatusDisplay progress = new StatusDisplay();
137: bar.add(progress);
138: bar.add(Box.createHorizontalStrut(30));
139: bar.add(Box.createHorizontalGlue());
140: MemoryDisplay memory = new MemoryDisplay();
141: memory.setMaximumSize(new Dimension(180, memory
142: .getMaximumSize().height));
143: bar.add(memory);
144: return bar;
145: }
146:
147: public static JPanel createToolbar() {
148: JToolBar bar = new JToolBar();
149: bar.putClientProperty("JToolBar.isRollover", Boolean.TRUE);
150: bar.putClientProperty(Options.HEADER_STYLE_KEY,
151: HeaderStyle.BOTH);
152: JButton step = new JButton(ResourceManager.getIcon("newstep"));
153: step.setUI(new BlueButtonUI());
154: step.setToolTipText(ResourceManager.getString("createstep"));
155: bar.add(step);
156: DragSource ds = new DragSource();
157: ds.createDefaultDragGestureRecognizer(step,
158: DnDConstants.ACTION_COPY, new TypeDragGesture(ds,
159: DragData.STEP));
160:
161: JButton join = new JButton(ResourceManager.getIcon("newjoin"));
162: join.setUI(new BlueButtonUI());
163: join.setToolTipText(ResourceManager.getString("createjoin"));
164: bar.add(join);
165: ds = new DragSource();
166: ds.createDefaultDragGestureRecognizer(join,
167: DnDConstants.ACTION_COPY, new TypeDragGesture(ds,
168: DragData.JOIN));
169:
170: JButton split = new JButton(ResourceManager.getIcon("newsplit"));
171: split.setToolTipText(ResourceManager.getString("createsplit"));
172: split.setUI(new BlueButtonUI());
173: bar.add(split);
174: ds = new DragSource();
175: ds.createDefaultDragGestureRecognizer(split,
176: DnDConstants.ACTION_COPY, new TypeDragGesture(ds,
177: DragData.SPLIT));
178:
179: JPanel panel = new JPanel(new BorderLayout());
180: panel.add(bar, BorderLayout.NORTH);
181:
182: return panel;
183: }
184: }
|