001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package com.artenum.so6.dataflow;
034:
035: import com.artenum.so6.dataflow.graph.So6GraphPanel;
036: import com.artenum.so6.dataflow.graph.So6GroupDragListener;
037: import com.artenum.so6.dataflow.graph.So6LayoutManager;
038: import com.artenum.so6.dataflow.util.DataflowConfiguration;
039: import com.artenum.so6.dataflow.xml.So6NetworkHandler;
040:
041: import org.libresource.so6.core.engine.util.CryptUtil;
042:
043: import java.awt.BorderLayout;
044: import java.awt.event.ActionEvent;
045: import java.awt.event.ActionListener;
046:
047: import java.io.File;
048: import java.io.InputStream;
049:
050: import java.net.URL;
051:
052: import java.util.Hashtable;
053: import java.util.Properties;
054:
055: import javax.swing.JButton;
056: import javax.swing.JFrame;
057: import javax.swing.JOptionPane;
058: import javax.swing.JPanel;
059: import javax.swing.JScrollPane;
060:
061: /**
062: * @author seb
063: */
064: public class Dataflow extends JPanel {
065: private So6LayoutManager layoutManager;
066: private So6NetworkHandler handler;
067: private So6GraphPanel panel;
068: public String filePositionPath = "graphPos.bin";
069:
070: public Dataflow() {
071: layoutManager = new So6LayoutManager();
072: handler = new So6NetworkHandler();
073: handler.getModel().setLayoutManager(layoutManager);
074:
075: try {
076: layoutManager.loadPosition(filePositionPath);
077: } catch (Exception e) {
078: System.out.println("Unable to load position");
079: }
080:
081: JButton savePos = new JButton("Save position");
082: savePos.addActionListener(new ActionListener() {
083: public void actionPerformed(ActionEvent e) {
084: try {
085: layoutManager.savePosition(filePositionPath);
086: } catch (Exception save) {
087: System.out.println("Unable to save position");
088: save.printStackTrace();
089: }
090: }
091: });
092:
093: //
094: panel = new So6GraphPanel(handler.getModel());
095: panel.setSelectionStroke(StyleManager.getInstance()
096: .getGroupSelectionStroke());
097:
098: So6GroupDragListener groupDragListener = new So6GroupDragListener(
099: handler.getModel(), panel);
100: panel.setGroupDragListener(groupDragListener);
101: panel.enableGroupDragging(true);
102: panel.enableGroupSelection(true);
103: panel.setBackground(StyleManager.getInstance().getBGColor());
104:
105: //
106: setLayout(new BorderLayout());
107: add(panel, BorderLayout.CENTER);
108: add(savePos, BorderLayout.SOUTH);
109: }
110:
111: public void load(File fileToLoad) throws Exception {
112: handler.parseXmlFile(fileToLoad);
113: handler.getModel().reload();
114: handler.getModel().getLayoutManager().applyLayout();
115: handler.getModel().updateNodes();
116: }
117:
118: public void load(InputStream inputStream) throws Exception {
119: handler.parseStream(inputStream);
120: handler.getModel().reload();
121: handler.getModel().getLayoutManager().applyLayout();
122: handler.getModel().updateNodes();
123: }
124:
125: public static void main(String[] args) {
126: File xmlFile = null;
127:
128: if ((args.length == 0) || (args.length == 3)) {
129: DataflowConfiguration dfc = null;
130:
131: if (args.length == 3) {
132: dfc = new DataflowConfiguration(args[0], args[1],
133: args[2]);
134: } else {
135: dfc = new DataflowConfiguration();
136: }
137:
138: //
139: Hashtable keys = dfc.editProperties();
140:
141: if (keys == null) {
142: System.exit(0);
143: }
144:
145: try {
146: Properties props = new Properties();
147: String serviceURL = (String) keys.get("server")
148: + "/ls-so6/so6";
149: props.setProperty(ClientIHttpClient.SO6_SERVICE_URL,
150: serviceURL);
151: props.setProperty(ClientIHttpClient.SO6_LOGIN,
152: (String) keys.get("login"));
153: props.setProperty(ClientIHttpClient.SO6_PASSWORD,
154: CryptUtil.encode((String) keys.get("passwd")));
155: props.setProperty(ClientIHttpClient.SO6_QUEUE_ID,
156: (String) keys.get("uri"));
157:
158: ClientIHttpClient client = new ClientIHttpClient(props);
159: xmlFile = new File(client
160: .getNetworkFromQueue((String) keys.get("uri")));
161:
162: //
163: ActionManager.getInstance().setReloadFromClient(client,
164: (String) keys.get("uri"));
165:
166: // so6.service.url=http://localhost:9000/ls-so6/so6
167: System.setProperty(ClientIHttpClient.SO6_SERVICE_URL,
168: serviceURL);
169: } catch (Exception e1) {
170: e1.printStackTrace();
171: System.exit(0);
172: }
173: } else if (args.length > 1) {
174: JOptionPane.showMessageDialog(null,
175: "Please specify a file or a url to load.");
176: System.exit(0);
177: }
178:
179: Dataflow dataflow = new Dataflow();
180: ActionManager.getInstance().setDataflow(dataflow);
181:
182: JFrame f = new JFrame("Dataflow viewer");
183: f.getContentPane().add(new JScrollPane(dataflow),
184: BorderLayout.CENTER);
185: f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
186: f.setSize(500, 500);
187: f.repaint();
188:
189: //
190: if (xmlFile == null) {
191: xmlFile = new File(args[0]);
192: }
193:
194: try {
195: if (xmlFile.exists()) {
196: dataflow.load(xmlFile);
197: } else {
198: ActionManager.getInstance().setReloadFromURL(args[0]);
199: dataflow.load(new URL(args[0]).openStream());
200: }
201: } catch (Exception e) {
202: JOptionPane.showMessageDialog(f,
203: "Error while trying to load data");
204: e.printStackTrace();
205: }
206:
207: //
208: f.show();
209: }
210: }
|