01: package com.opensymphony.workflow.designer.actions;
02:
03: import java.awt.*;
04: import java.awt.event.ActionEvent;
05: import javax.swing.*;
06:
07: import com.opensymphony.workflow.designer.ResultEdge;
08: import com.opensymphony.workflow.designer.WorkflowGraph;
09: import org.jgraph.graph.CellView;
10: import org.jgraph.graph.GraphConstants;
11:
12: public class ResultEdgeLineWidth extends JMenuItem {
13: ResultEdgeLineWidthHandler customHandler;
14:
15: static class ResultEdgeLineWidthHandler extends AbstractAction {
16: private WorkflowGraph graph;
17: private Point location;
18: private int width;
19:
20: ResultEdgeLineWidthHandler(WorkflowGraph graph, Point location,
21: int lineWidth, String name) {
22: super (name);
23: this .graph = graph;
24: this .location = location;
25: this .width = lineWidth;
26: }
27:
28: public void actionPerformed(ActionEvent e) {
29: Object cell = graph.getFirstCellForLocation(location.x,
30: location.y);
31: if (cell == null) {
32: return;
33: } else {
34: CellView view = (graph.getGraphLayoutCache()
35: .getMapping(cell, false));
36: if (graph.getModel().isEdge(cell)) {
37: GraphConstants.setLineWidth(((ResultEdge) cell)
38: .getAttributes(), width);
39: view.update();
40: view.refresh(graph.getModel(), graph
41: .getGraphLayoutCache(), false);
42: graph.getSelectionModel().setSelectionCell(
43: view.getCell());
44: }
45: }
46: }
47: }
48:
49: public ResultEdgeLineWidth(WorkflowGraph graph, Point location,
50: int lineWidth) {
51: super (lineWidth + " pt");
52: setIcon(new LineIcon(lineWidth));
53: customHandler = new ResultEdgeLineWidthHandler(graph, location,
54: lineWidth, this .getName());
55: addActionListener(customHandler);
56: }
57:
58: class LineIcon implements Icon {
59: private int lineWidth;
60:
61: public LineIcon(int lineWidth) {
62: this .lineWidth = lineWidth;
63: }
64:
65: public void paintIcon(Component c, Graphics g, int x, int y) {
66: g.setColor(Color.BLACK);
67: g.fillRect(1, (getHeight() - lineWidth) / 2, 16, lineWidth);
68: }
69:
70: public int getIconWidth() {
71: return 16;
72: }
73:
74: public int getIconHeight() {
75: return getHeight();
76: }
77: }
78:
79: }
|