1 /*------------------------------------------------------------------------------
2 Name: GraphicChat.java
3 Project: xmlBlaster.org
4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
5 ------------------------------------------------------------------------------*/
6
7 package javaclients.graphical;
8
9 import javax.swing.JToolBar;
10
11 import CH.ifa.draw.figures.*;
12 import CH.ifa.draw.contrib.*;
13
14 import CH.ifa.draw.framework.Drawing;
15 import CH.ifa.draw.framework.DrawingView;
16 import CH.ifa.draw.framework.Tool;
17 import CH.ifa.draw.util.UndoableTool;
18 import CH.ifa.draw.standard.CreationTool;
19 import CH.ifa.draw.contrib.html.HTMLTextAreaFigure;
20 import CH.ifa.draw.contrib.html.HTMLTextAreaTool;
21
22 import java.util.logging.Logger;
23 import java.util.logging.Level;
24 import org.xmlBlaster.client.I_Callback;
25 import org.xmlBlaster.client.I_XmlBlasterAccess;
26 import org.xmlBlaster.client.key.UpdateKey;
27 import org.xmlBlaster.client.qos.UpdateQos;
28 import org.xmlBlaster.util.Global;
29
30 /**
31 * @author <a href="mailto:michele@laghi.eu">Michele Laghi</a>
32 */
33 public class GraphicChat extends MDI_DrawApplication implements I_Callback {
34
35 private Global global;
36 private static Logger log = Logger.getLogger(GraphicChat.class.getName());
37 private String ME = "GraphicChat";
38 private I_XmlBlasterAccess accessor;
39
40 public GraphicChat(Global global) {
41 super("GraphicChat");
42 this.global = global;
43
44 }
45
46 public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) {
47 log.info("update for '" + cbSessionId + "', '" + updateKey.getOid() + "' length of msg is '" + content.length + "'");
48 return "OK";
49 }
50
51 protected void init() {
52 this.accessor = this.global.getXmlBlasterAccess();
53 }
54
55
56 protected Drawing createDrawing() {
57 XmlBlasterDrawing drawing = new XmlBlasterDrawing(this.global);
58 // drawing.init(this.global);
59 return drawing;
60 }
61
62 protected void createTools(JToolBar palette) {
63 super.createTools(palette);
64 Tool tool = new UndoableTool(new TextTool(this, new TextFigure()));
65 palette.add(createToolButton(IMAGES + "TEXT", "Text Tool", tool));
66
67 tool = new UndoableTool(new CreationTool(this, new RectangleFigure()));
68 palette.add(createToolButton(IMAGES + "RECT", "Rectangle Tool", tool));
69
70 tool = new UndoableTool(new CreationTool(this, new RoundRectangleFigure()));
71 palette.add(createToolButton(IMAGES + "RRECT", "Round Rectangle Tool", tool));
72
73 tool = new UndoableTool(new CreationTool(this, new EllipseFigure()));
74 palette.add(createToolButton(IMAGES + "ELLIPSE", "Ellipse Tool", tool));
75
76 tool = new UndoableTool(new PolygonTool(this));
77 palette.add(createToolButton(IMAGES + "POLYGON", "Polygon Tool", tool));
78
79 tool = new UndoableTool(new CreationTool(this, new TriangleFigure()));
80 palette.add(createToolButton(IMAGES + "TRIANGLE", "Triangle Tool", tool));
81
82 tool = new UndoableTool(new CreationTool(this, new DiamondFigure()));
83 palette.add(createToolButton(IMAGES + "DIAMOND", "Diamond Tool", tool));
84
85 tool = new UndoableTool(new CreationTool(this, new LineFigure()));
86 palette.add(createToolButton(IMAGES + "LINE", "Line Tool", tool));
87
88 tool = new TextAreaTool(this, new TextAreaFigure());
89 palette.add(createToolButton(IMAGES + "TEXTAREA", "TextArea Tool", tool));
90
91 tool = new HTMLTextAreaTool(this, new HTMLTextAreaFigure());
92 palette.add(createToolButton(IMAGES + "TEXTAREA", "HTML TextArea Tool", tool));
93 }
94
95 /**
96 * invoked on exit
97 */
98 protected void destroy() {
99 log.info("destroy invoked");
100 DrawingView[] views = this.views();
101 for (int i=0; i < views.length; i++) {
102 views[i].drawing().release();
103 }
104 super.destroy();
105 }
106
107 protected void fireViewDestroyingEvent(DrawingView view) {
108 log.info("Destroying view '" + view.drawing().getTitle() + "'");
109 Drawing drawing = view.drawing();
110 super.fireViewDestroyingEvent(view);
111 drawing.release();
112 }
113
114
115 /**
116 * Factory method to create a StorageFormatManager for supported storage formats.
117 * Different applications might want to use different storage formats and can return
118 * their own format manager by overriding this method.
119 *
120 * TODO: Read storage formats from a config file.
121 */
122 /*
123 public StorageFormatManager createStorageFormatManager() {
124 StorageFormatManager storageFormatManager = new StorageFormatManager();
125 SVGStorageFormat format = new SVGStorageFormat();
126 storageFormatManager.addStorageFormat(format);
127 storageFormatManager.setDefaultStorageFormat(format);
128 return storageFormatManager;
129 }
130 */
131
132
133
134
135 //-- main -----------------------------------------------------------
136
137 public static void main(String[] args) {
138
139 Global glob = new Global();
140 if (glob.init(args) != 0) { // Get help with -help
141 System.out.println(glob.usage());
142 System.err.println("Example: java javaclients.graphical.GraphicChat -chatMaster true\n");
143 System.exit(1);
144 }
145
146 GraphicChat window = new GraphicChat(glob);
147 window.open();
148 }
149
150 }
syntax highlighted by Code2HTML, v. 0.9.1