1
14
15 package demo.yext.export;
16
17
18 import javax.swing.JButton;
19 import javax.swing.JToolBar;
20
21 import y.base.Node;
22 import y.io.LinkInfo;
23 import y.io.LinkMap;
24 import y.option.OptionHandler;
25 import y.view.EditMode;
26 import y.view.HitInfo;
27 import y.view.ViewMode;
28
29 import yext.export.io.SWFOutputHandler;
30
31
32
36 public class SWFExportDemo extends AbstractExportDemo
37 {
38 private static final String SWF_URL = "swf_url";
39 private static final String SWF_TARGET = "swf_target";
40
41 LinkMap linkMap;
43
44
45 public SWFExportDemo() {
46 view.addViewMode(new RightClickMode());
48 }
49
50
53 protected JToolBar createToolBar() {
54 JToolBar jtb = super.createToolBar();
55 jtb.addSeparator();
56 linkMap = new LinkMap();
59 jtb.add(new JButton(new ExportAction("SWF Export", new SWFOutputHandler(linkMap))));
60 return jtb;
61 }
62
63
67 protected EditMode createEditMode()
68 {
69 EditMode em = new EditMode() {
70 public String getNodeTip(Node v) {
71 String url = null;
72 LinkInfo info = linkMap.get(v);
73 if( null != info ) {
74 url = info.getAttribute(SWF_URL);
75 }
76 if(url != null)
77 {
78 return "<html>URL: <b>" + url + "</b></html>";
79 }
80 else
81 {
82 return "<html>No URL assigned to node. <br><b>Right click on node</b></html>";
83 }
84 }
85 };
86 em.showNodeTips(true);
87 return em;
88 }
89
90
91
97 class RightClickMode extends ViewMode {
98 public void mouseReleasedRight(double x, double y)
99 {
100 HitInfo hitInfo = getGraph2D().getHitInfo(x,y, false);
101
102 if(hitInfo.getHitNodeLabel() != null)
103 {
104 editLinkInfo(hitInfo.getHitNodeLabel(), "node label");
105 }
106 else if(hitInfo.getHitEdgeLabel() != null)
107 {
108 editLinkInfo(hitInfo.getHitEdgeLabel(), "edge label");
109 }
110 else if(hitInfo.getHitNode() != null)
111 {
112 editLinkInfo(hitInfo.getHitNode(), "node");
113 }
114 else if(hitInfo.getHitEdge() != null)
115 {
116 editLinkInfo(hitInfo.getHitEdge(), "edge");
117 }
118
119 }
120
121 void editLinkInfo(Object key, String type)
122 {
123 String url = null;
124 OptionHandler op = new OptionHandler("Hyperlink for " + type);
125 LinkInfo info = linkMap.get(key);
126 if( null != info ) {
127 url = info.getAttribute(SWF_URL);
128 }
129 if(url != null)
130 {
131 op.addString("Hyperlink URL",url);
132 }
133 else
134 {
135 op.addString("Hyperlink URL","");
136 }
137 if(op.showEditor(view.getFrame()))
138 {
139 url = op.getString("Hyperlink URL");
140 if(url.length() > 0)
141 {
142 LinkInfo newInfo = new LinkInfo();
143 newInfo.setAttribute(SWF_URL,url);
144 newInfo.setAttribute(SWF_TARGET,"_self");
145 linkMap.put(key, newInfo);
146 }
147 else
148 {
149 linkMap.remove(key);
150 }
151 }
152 }
153 }
154
155
158 public static void main(String[] args) {
159 initLnF();
160 (new SWFExportDemo()).start();
161 }
162 }