Révision 12

SRC/src/fr/triangle/hyperalign/kernel/graph/EquivalenceGraphWriter.java (revision 12)
365 365
		Iterator<Object> it =  keys.iterator();
366 366
		while (it.hasNext()) {
367 367
			Object target = it.next();
368
			//System.out.println("\t buildOtherStrNodes() - TARGET "+target);
369 368
			Integer nb = targetEquis.get(target);	
369
			System.out.println("\t buildOtherStrNodes() - TARGET "+target.toString()+"/ NB = "+nb);
370 370
			if(!elementsStrDone.containsKey(target)){
371 371
				String nodeIdTarget = null;
372 372
				if(target instanceof DictionaryElement){
SRC/src/fr/triangle/hyperalign/kernel/DataManager.java (revision 12)
2948 2948
			String typeNode = element.getReference();
2949 2949

  
2950 2950
			if(filterByAuthor){
2951
				manager.writeToDebug("EquivalenceManager.buildGraph() - BY AUTHOR !");		
2952
				
2951
				//manager.writeToDebug("EquivalenceManager.buildInfoForGraph() - BY AUTHOR !");
2953 2952
				computeGraphEquivalencesByAuthor(element, targetLang, neighbourhoodWidth);
2954 2953

  
2955 2954
			}else {
2956 2955
				/////////////////////// DICO //////////////////// 
2957 2956
				if(typeNode.equals(Dictionary.DICO_DICO)){
2958
					manager.writeToDebug("EquivalenceManager.buildGraph() - ALL !");		
2959
					
2957
					//manager.writeToDebug("EquivalenceManager.buildInfoForGraph() - ALL !");		
2960 2958
					computeGraphEquivalences(element, targetLang, "1", true);
2961 2959
					//computeGraphEquivalences(sourceElements, targetElements, neighbourhoodWidth, filterByAuthor);	
2962 2960
				}else {
2963
					manager.writeToDebug("EquivalenceManager.buildGraph() - FOR "+element+" [level "+element.getReference()+"]");		
2964
					
2961
					manager.writeToDebug("EquivalenceManager.buildInfoForGraph() - FOR "+element+" [level "+element.getReference()+"]");		
2965 2962
					computeGraphEquivalences(element, targetLang, neighbourhoodWidth, false);	
2966 2963
				}
2967 2964
			}
SRC/src/fr/triangle/hyperalign/gui/HMManager.java (revision 12)
1063 1063
		} else if(textFilter.equals("align")){
1064 1064
			filter = new FileNameExtensionFilter("ALIGN", "align");
1065 1065
			ext = ".align";
1066
		}else if(textFilter.equals("png")){
1067
			filter = new FileNameExtensionFilter("PNG", "png");
1068
			ext = ".png";
1066 1069
		}else {
1067 1070
			filter = new FileNameExtensionFilter("XML-TEI", "xml");
1068 1071
			ext = ".xml";
......
1072 1075
		if(returnVal == JFileChooser.APPROVE_OPTION) {
1073 1076
			File file = chooser.getSelectedFile();
1074 1077
			String path = file.getPath();
1075
			settings.setAttribute("files", "dernierProjet", path);
1078
			//settings.setAttribute("files", "dernierProjet", path);
1076 1079
			String osName = System.getProperty("os.name");
1077 1080
			System.out.println("OS is ? "+osName+" and PATH is ? "+path);
1078 1081
			if(osName.startsWith("Mac")){
SRC/src/fr/triangle/hyperalign/gui/annot/AnnotEquiPane.java (revision 12)
511 511

  
512 512
		///LABEL about the Equivalences
513 513
		labelOccSource = new JLabel();
514
		System.out.println("AnnotEquiPane.initTriPanel() - LABEL OCC SOURCE type = "+type);
514 515
		if(type.equals(Dictionary.DICO_LEMME)){
515 516
			int nbOccSource = sourceLang.getOccurrencesForLemme(sourceElement).size();
516 517
			//int nbOccSourceInEqui = tradManager.getCurrentEquivalenceElements().size();
517 518
			labelOccSource = new JLabel(/*nbOccSourceInEqui+" "+*/res.getString("I18N_EQUIVALENCEPANE_LABEL_1")+" "+
518 519
					sourceElement.getName()+" / "+nbOccSource+" "+res.getString("I18N_EQUIVALENCEPANE_LABEL_2"));
520
			System.out.println("   -   "+res.getString("I18N_EQUIVALENCEPANE_LABEL_1")+" "+
521
					sourceElement.getName()+" / "+nbOccSource+" "+res.getString("I18N_EQUIVALENCEPANE_LABEL_2"));
519 522
		}
520 523
		triPanel.add(labelOccSource);
521 524

  
......
976 979

  
977 980
	@Override
978 981
	public void itemStateChanged(ItemEvent e) {
979
		// TODO Auto-generated method stub
980 982
		Object source = e.getItemSelectable();
981 983

  
982 984
		if (source == graphSizeBox) {
SRC/src/fr/triangle/hyperalign/gui/tree/TreePane.java (revision 12)
435 435
			//Create the scroll pane and add the tree to it. 
436 436
			treeView = new JScrollPane(tree);
437 437
			//treeView.setPreferredSize(new Dimension(200,600));
438
			
438 439
			treeView.setPreferredSize(new Dimension(this.getWidth(),this.getHeight()));
439 440
			treeView.setVerticalScrollBarPolicy(treeView.VERTICAL_SCROLLBAR_ALWAYS);
440

  
441
			treeView.revalidate();
442
			this.revalidate();
441 443
		}else {
442 444
			treeView = new JScrollPane();
443 445
			treeView.setPreferredSize(new Dimension(this.getWidth(),this.getHeight()));
446
			//System.out.println("NO TREEPANE YET - preferred size [w:"+this.getWidth()+"-h:"+this.getHeight()+"]");
447
			
444 448
		}
445 449
		return treeView;
446 450
	}
SRC/src/fr/triangle/hyperalign/gui/tree/TreeTabbedPane.java (revision 12)
11 11

  
12 12
import javax.swing.JComponent;
13 13
import javax.swing.JTabbedPane;
14
import javax.swing.event.ChangeEvent;
15
import javax.swing.event.ChangeListener;
14 16

  
15 17
import fr.triangle.hyperalign.gui.HMManager;
16 18
import fr.triangle.hyperalign.kernel.HyperalignData;
......
21 23
import fr.triangle.hyperalign.kernel.termino.TerminologyElement;
22 24
import fr.triangle.hyperalign.kernel.trad.Equivalence;
23 25

  
24
public class TreeTabbedPane extends JTabbedPane implements Observer {
26
public class TreeTabbedPane extends JTabbedPane implements Observer, ChangeListener {
25 27
	
26 28
	//Peut contenir autant d'onglets contenant un à plusieurs onglets avec des arbres
27 29
	
......
191 193
        
192 194
	}
193 195
	
196

  
197
	
198
	    
194 199
	public void update(Observable observable, Object obj) {
195 200
		// TODO Auto-generated method stub
196 201
		Integer changeType = (Integer) obj;
......
205 210
		this.res = HyperalignData.getInstance().getResourceBundle();
206 211
	}
207 212

  
213

  
214
	@Override
215
	public void stateChanged(ChangeEvent changeEvent) {
216
		JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent.getSource();
217
	      int index = sourceTabbedPane.getSelectedIndex();
218
	      System.out.println("Tab changed to: " + sourceTabbedPane.getTitleAt(index));
219
		
220
	}
208 221
	
222
	
209 223
}
SRC/src/fr/triangle/hyperalign/gui/graph/EquivalenceGraph.java (revision 12)
1 1
package fr.triangle.hyperalign.gui.graph;
2 2

  
3 3
import java.awt.BorderLayout;
4
import java.awt.Color;
5 4
import java.awt.Dimension;
6
import java.awt.Font;
5
import java.awt.Graphics2D;
7 6
import java.awt.GridBagConstraints;
8
import java.awt.GridBagLayout;
9 7
import java.awt.GridLayout;
10 8
import java.awt.event.ActionEvent;
11 9
import java.awt.event.ActionListener;
10
import java.awt.event.ItemEvent;
11
import java.awt.event.ItemListener;
12
import java.awt.geom.Rectangle2D;
13
import java.awt.image.BufferedImage;
14
import java.io.File;
15
import java.io.FileOutputStream;
12 16
import java.net.URL;
17
import java.util.HashMap;
13 18
import java.util.Iterator;
14 19
import java.util.ResourceBundle;
20
import java.util.Set;
15 21

  
22
import javax.imageio.ImageIO;
23
import javax.swing.ImageIcon;
16 24
import javax.swing.JButton;
25
import javax.swing.JCheckBox;
26
import javax.swing.JLabel;
17 27
import javax.swing.JPanel;
18 28
import javax.swing.JTextArea;
29
import javax.swing.JToolBar;
19 30

  
20
import prefuse.Constants;
21 31
import prefuse.Display;
22 32
import prefuse.Visualization;
23
import prefuse.action.Action;
24
import prefuse.action.ActionList;
25
import prefuse.action.RepaintAction;
26
import prefuse.action.assignment.ColorAction;
27
import prefuse.action.assignment.DataColorAction;
28
import prefuse.action.assignment.DataSizeAction;
29
import prefuse.action.layout.graph.ForceDirectedLayout;
30
import prefuse.activity.Activity;
31
import prefuse.controls.DragControl;
32
import prefuse.controls.FocusControl;
33
import prefuse.controls.NeighborHighlightControl;
34
import prefuse.controls.PanControl;
35
import prefuse.controls.ToolTipControl;
36
import prefuse.controls.ZoomControl;
37
import prefuse.data.Graph;
38
import prefuse.data.Table;
39
import prefuse.data.Tuple;
40
import prefuse.data.event.TupleSetListener;
41
import prefuse.data.io.DataIOException;
42
import prefuse.data.io.GraphMLReader;
43
import prefuse.data.query.SearchQueryBinding;
44
import prefuse.data.search.PrefixSearchTupleSet;
45
import prefuse.data.search.SearchTupleSet;
46
import prefuse.data.tuple.TupleSet;
47
import prefuse.render.DefaultRendererFactory;
48
import prefuse.render.LabelRenderer;
49
import prefuse.util.ColorLib;
50
import prefuse.util.FontLib;
51
import prefuse.util.ui.JSearchPanel;
52
import prefuse.visual.VisualItem;
53 33
import fr.triangle.hyperalign.gui.HMManager;
54
import fr.triangle.hyperalign.gui.Hypermachiavel;
55
import fr.triangle.hyperalign.gui.HMTags;
56
import fr.triangle.hyperalign.kernel.HyperalignData;
57 34
import fr.triangle.hyperalign.kernel.DataManager.EquivalenceManager;
58
import fr.triangle.hyperalign.kernel.termino.TerminologyElement;
35
import fr.triangle.hyperalign.kernel.HyperalignData;
59 36
import fr.triangle.hyperalign.kernel.trad.ConceptEquivalenceElement;
37
import fr.triangle.hyperalign.kernel.util.ImageConfigure;
60 38

  
61
public class EquivalenceGraph extends JPanel {
39
public class EquivalenceGraph extends JPanel implements ItemListener  {
62 40

  
63 41
	/**
64 42
	 * 
65 43
	 */
66 44
	private static final long serialVersionUID = 1L;
67
	URL [] urlsEquivalence;
68
	private static final String nodes = "graph.nodes";
69
	private static final String edges = "graph.edges";
70

  
71
	private Visualization vis;
72
	private DataColorAction fill;
73
	private JSearchPanel searchPanel;
74
	private boolean withSizes;
45
	private URL [] urlsEquivalence;
46
	private String iconPath = "fr/triangle/hyperalign/gui/icons";
47
	
75 48
	private boolean withAllConcepts;
76 49
	private HMManager manager;
77 50
	private ResourceBundle res;
51
	private HashMap<GraphPane, Visualization> graphs;
52
	private boolean withSizes;
53
	String author;
54
	String lang;
55
	String concept;
56
	String level;
57
	JCheckBox graphSizeBox;
78 58
	
79 59
	public EquivalenceGraph(HMManager manager){
80 60
		this.manager = manager;
81 61
		this.res = HyperalignData.getInstance().getResourceBundle();
82 62
		EquivalenceManager equivManager = manager.getDataManager().getEquivalenceManager();
63
		graphs = new HashMap<GraphPane, Visualization>();
83 64
		this.withSizes = equivManager.getGraphSizeOption();
84 65
		this.withAllConcepts= equivManager.getGraphAllConceptOption();
85 66
		this.urlsEquivalence = equivManager.getCurrentGraphUrls(); 
86 67
		initGui();
87 68
	}
69
	
70
	
88 71

  
89 72
	private void initGui(){
90
		for (int i = 0; i < urlsEquivalence.length; i++) {
91
			URL urlEquivalence = urlsEquivalence[i];
92
			// -- 1. load the data ------------------------------------------------
93
			Graph graph = null;
94
			try {
95
				graph = new GraphMLReader().readGraph(urlEquivalence);
96
			} catch ( DataIOException e ) {
97
				e.printStackTrace();
98
				System.err.println("Error loading graph. Exiting...");
99
				System.exit(1);
100
			}
101

  
102

  
103
			// -- 2. the visualization --------------------------------------------
104

  
105
			vis = new Visualization();
106
			vis.add("graph", graph);
107
			vis.setInteractive(edges, null, false);
108

  
109
			// -- 3. the renderers and renderer factory ---------------------------  
110
			LabelRenderer r = new LabelRenderer("name"); //name or gender
111
			r.setRoundedCorner(8, 8); // round the corners
112
			vis.setRendererFactory(new DefaultRendererFactory(r)); //
113

  
114
			// -- 4. the processing actions ---------------------------------------
115
			int[] palette = new int[] {
116
					HMTags.colorGreenBlue.getRGB(), HMTags.colorBrownLight.getRGB()
117
			};
118
			// map nominal data values to colors using our provided palette
119
			fill = new DataColorAction(EquivalenceGraph.nodes, "lang", Constants.NOMINAL, VisualItem.FILLCOLOR, palette);
120
			ColorAction text = new ColorAction(EquivalenceGraph.nodes, VisualItem.TEXTCOLOR, ColorLib.gray(0));
121
			ColorAction edges = new ColorAction(EquivalenceGraph.edges, VisualItem.STROKECOLOR, ColorLib.gray(200));
122
			ColorAction edgesText = new ColorAction(EquivalenceGraph.edges, VisualItem.TEXTCOLOR, ColorLib.blue(120));
73
		//this.setLayout(new GridLayout(1,urlsEquivalence.length));
74
		
75
		//JPanel northPanel = new JPanel();
76
		JToolBar northPanel = new JToolBar();
77
		if(urlsEquivalence.length>1){
78
			//LABEL about Concept, Lang and Level
79
			URL urlEqui = urlsEquivalence[0];
80
			initParams(urlEqui);
81
			JLabel textLabelConceptLevel = new JLabel(concept+", "+res.getString("I18N_EQUIVALENCEGRAPH_LEVEL")+level);
82
			textLabelConceptLevel.setPreferredSize(new Dimension(400,20));
123 83
			
124
			//DataSizeAction size = new DataSizeAction(EquivalenceGraph.nodes, "nb", 10, Constants.LOG_SCALE);
125
			System.out.println("withSizes ? => "+withSizes);
126
			 // 1) the DataSizeAction for the edges based on datafield "weight"
127
	        Action dataSizeAction = new DataSizeAction(EquivalenceGraph.nodes, "nb");  
128
	       
129
			//// create an action list containing all color assignments
130
			//Constants.QUANTILE_SCALE //LOG_SCALE //Constants.LINEAR_SCALE
131

  
132
			ActionList color = new ActionList();
133
			color.add(fill);
134
			color.add(text);
135
			color.add(edges);
136
			color.add(edgesText);
137
			if(withSizes){
138
				//color.add(size);
139
				color.add(dataSizeAction);
140
			}
141
			ActionList layout = new ActionList(Activity.INFINITY);
142
			layout.add(new ForceDirectedLayout("graph"));
143
			layout.add(new RepaintAction());
144

  
145
			//Specific highlights
146
			ActionList search = searchAction();
147
			ActionList focus = focusAction();
148

  
149
			// add the actions to the visualization
150
			vis.putAction("color", color);
151
			vis.putAction("layout", layout);
152
			vis.putAction("search", search);
153
			vis.putAction("focus", focus);
154

  
84
			northPanel.add(textLabelConceptLevel);
85
		
86
			//PROPORTION NODE SIZE
87
			graphSizeBox = new JCheckBox(res.getString("I18N_EQUIVALENCEPANE_GRAPHSIZE_OPTION"));
88
			graphSizeBox.setSelected(withSizes);
89
			//graphSizeBox.setPreferredSize(new Dimension(100,10));
90
			graphSizeBox.addItemListener(this);
91
			northPanel.add(graphSizeBox);
92
		
93
			//EXPORT BUTTON
94
			JPanel buttonsPane = new JPanel();
95
			ImageIcon exportButt = ImageConfigure.createImageIcon(iconPath+"/Save.gif");
96
			JButton	exportButton = new JButton(exportButt);
97
			exportButton.setToolTipText(res.getString("I18N_EQUIVALENCEPANE_EXPORT"));
98
			buttonsPane.add(exportButton);
99
			northPanel.add(buttonsPane);
155 100
			
156
		    
157
			// -- 5. the display and interactive controls -------------------------
158
			Display d = new Display(vis);
159
			if(urlsEquivalence.length>1){
160
				d.setSize(800/urlsEquivalence.length, 800/urlsEquivalence.length); // set display size  => d.setSize(800, 400); 
161
			}else {
162
				if(withAllConcepts){
163
					d.setSize(800, 700); 
164
				}else {
165
					d.setSize(800, 400); 
101
			exportButton.addActionListener(new ActionListener(){
102
				public void actionPerformed(ActionEvent e) {
103
					export();
166 104
				}
167
			}
168
			d.setForeground(Color.WHITE);
169
			d.setBackground(Color.GRAY);
170

  
171
			ToolTipControl ttc = new ToolTipControl("nb");
172
			d.addControlListener(ttc);
173

  
174
			// drag individual items around
175
			d.addControlListener(new DragControl());
176
			// pan with left-click drag on background
177
			d.addControlListener(new PanControl()); 
178
			// zoom with right-click drag
179
			d.addControlListener(new ZoomControl());
180
			d.addControlListener(new NeighborHighlightControl());
181
			d.addControlListener(new FocusControl(2));
182
			d.addControlListener(new HighlightOnMouseOverControl("filter"));
183

  
184

  
105
			});
106
		}
107
		
108
		JPanel centerPanel = new JPanel();
109
		GridLayout gridLayout = new GridLayout(1, urlsEquivalence.length);
110
		gridLayout.setHgap(30);
111
		centerPanel.setLayout(gridLayout);
112
		
113
		for (int i = 0; i < urlsEquivalence.length; i++) {
114
			URL urlEqui = urlsEquivalence[i];
115
			System.out.println("EquivalenceGraph.initGui() - widthsize = w "+this.getSize().width+" - h "+this.getSize().height);
116
			int widthsize = 1000/urlsEquivalence.length;
117
			int lengthsize = 1000/urlsEquivalence.length;
118
			/*
119
			 int widthsize = 800/urlsEquivalence.length;
120
			int lengthsize = 800/urlsEquivalence.length;
121
			*/
122
			boolean isSeveralGraphs = false;
185 123
			if(urlsEquivalence.length>1){
186
				this.setLayout(new GridLayout(1,urlsEquivalence.length));
187

  
188
				String concept = res.getString("I18N_EQUIVALENCEGRAPH_ALLCONCEPTS");
189
				String author = res.getString("I18N_EQUIVALENCEGRAPH_ALLAUTHORS");
190
				String level = "1";
191
				String lang = res.getString("I18N_EQUIVALENCEGRAPH_LANGUAGE");
192
				
193
				
194
				JPanel graphPanel = new JPanel();
195
				String path = urlEquivalence.getPath();
196
				int index = path.lastIndexOf("/");
197
				path = path.substring(index+1,path.length());
198
				
199
				index = path.indexOf("_");
200
				if(index!=-1){
201
					//GESTION DE LA LANGUE :
202
					lang += path.substring(0,index);
203
					path = path.substring(index+1,path.length());
204
					index = path.indexOf("_");
205
				
206
					if(index!=-1){
207
						//GESTION CONCEPT
208
						concept = path.substring(0,index);				
209
						path = path.substring(index+1,path.length());
210
						index = path.indexOf("_");
211
						
212
						if(urlsEquivalence.length>1){
213
							if(index!=-1){
214
								//GESTION TEXTE
215
								author = path.substring(0,index);				
216
								path = path.substring(index+1,path.length());
217
								index = path.indexOf("_");
218
								author = manager.getDataManager().getCorpusManager().getCorpus().getTextById(author).getName();
219
								
220
								if(index!=-1){
221
									//GESTION LEVEL
222
									level = path.substring(0,index);				
223
									path = path.substring(index+1,path.length());
224
								}
225
							}
226
						}else {
227
							if(index!=-1){
228
								//GESTION LEVEL
229
								level = path.substring(0,index);				
230
								path = path.substring(index+1,path.length());
231
							}
232
						}
233
					}
234
				
235
				}
236

  
237
				JTextArea textArea = new JTextArea(concept+res.getString("I18N_EQUIVALENCEGRAPH_BY")+author+", "+res.getString("I18N_EQUIVALENCEGRAPH_LEVEL")+level);
238

  
239
				graphPanel.setLayout(new GridBagLayout());
240
				GridBagConstraints c = new GridBagConstraints();
241
				c.gridx = 0;
242
				c.gridy = 0;
243
				graphPanel.add(d,c);
244
				c = new GridBagConstraints();
245
				c.gridx = 0;
246
				c.gridy = 1;
247
				graphPanel.add(textArea,c);
248
				//initSearchPane(graphPanel);
249

  
250
				this.add(graphPanel);
251

  
252
			}else {
253
				this.add(d, BorderLayout.CENTER);
254
				JSearchPanel searchPane = initSearchPane();
255
				this.add(searchPane, BorderLayout.LINE_END);
124
				isSeveralGraphs = true;
256 125
			}
257

  
258

  
259
			// assign the colors
260
			vis.run("color");
261
			// start up the animated layout
262
			vis.run("layout");
263

  
126
			GraphPane graphPane = new GraphPane(manager, this, urlEqui, isSeveralGraphs, widthsize, lengthsize, withAllConcepts, withSizes);
127
			Visualization vis = graphPane.getVis();
128
			graphs.put(graphPane, vis);
129
			centerPanel.add(graphPane);
264 130
			/*//////////// PRINT ////////////    
265 131
				 try {
266 132
		            registerKeyboardAction(new PrintDisplayAction(this),
......
268 134
		                    WHEN_IN_FOCUSED_WINDOW);
269 135
		        } catch (SecurityException se) {
270 136
		        }/////////////////////////////////*/
271

  
272 137
		}
138
		if(urlsEquivalence.length>1){
139
			this.add(northPanel, BorderLayout.PAGE_START);
140
		}
141
		 
142
		this.add(centerPanel);
273 143
		this.setVisible(true);
274 144
	}
275

  
276
	private JSearchPanel initSearchPane(){
277
		
278
	    
279
		SearchTupleSet searchTS = new PrefixSearchTupleSet();
280
		vis.addFocusGroup(Visualization.SEARCH_ITEMS, searchTS);
281

  
282

  
283
		//vis.addFocusGroup(Visualization.FOCUS_ITEMS, new DefaultTupleSet());
284
		vis.getGroup(Visualization.FOCUS_ITEMS).addTupleSetListener(
285
				new TupleSetListener() {
286
					public void tupleSetChanged(TupleSet t, Tuple[] add, Tuple[] rem) {
287
						System.out.println(">>>>>>>>> tupleSetChanged() "+t.toString());
288
						vis.cancel("color");
289
						vis.run("focus");
290
					}
291
				}
292
		);
293
		
294
		fill.add("ingroup('_search_')", HMTags.colorPinkLight.getRGB());
295
		fill.add("ingroup('_focus_')", ColorLib.rgb(100,100,230));
296
		
297
		SearchQueryBinding sq = new SearchQueryBinding((Table) vis.getGroup(nodes), "name", (SearchTupleSet) vis.getGroup(Visualization.SEARCH_ITEMS));
298
		/*sq.getPredicate().addExpressionListener(new UpdateListener() {
299
		            public void update(Object src) {
300
		            	System.out.println(">>>>>>>>> addExpressionListener()");
301
		               // vis.cancel("color");
302
		               // vis.run("search");
303
		            }
304
		        });
305
		 */
306

  
307
		searchPanel = sq.createSearchPanel();
308
		searchPanel.setShowResultCount(true);
309
		searchPanel.setPreferredSize(new Dimension(200, 20));
310
		searchPanel.setFont(FontLib.getFont("Tahoma", Font.PLAIN, 11));
311
		searchPanel.setShowCancel(false);
312
		
313
		return searchPanel;
145
	
146
	public void highlightTarget(ConceptEquivalenceElement elementToHighlight){
147
		//searchPanel.setQuery(elementToHighlight.getName());
148
		////vis.run("search");
149
		//A REFAIRE > GraphPane.highlightTarget() !!!!!
314 150
	}
315 151

  
316
	private ActionList searchAction(){
317
		int[] paletteHighlighted = new int[] {
318
				HMTags.colorPinkLight.getRGB()//Color.yellow.getRGB()
319
		};
320
		DataColorAction fillHighlighted = new DataColorAction(EquivalenceGraph.nodes, "name", Constants.NOMINAL, VisualItem.FILLCOLOR, paletteHighlighted);
321
		ColorAction textHighlighted = new ColorAction(EquivalenceGraph.nodes, VisualItem.TEXTCOLOR, ColorLib.gray(0));
322
		ColorAction edgesHighlighted = new ColorAction(EquivalenceGraph.edges, VisualItem.STROKECOLOR, ColorLib.gray(0));
323

  
324
		ActionList search = new ActionList();//ActionList.INFINITY
325
		search.add(fillHighlighted);
326
		search.add(textHighlighted);
327
		search.add(edgesHighlighted);
328
		search.add(new RepaintAction());
329
		return search;
330
	}
331

  
332
	private ActionList focusAction(){
333
		int[] paletteHighlighted = new int[] {
334
				Color.yellow.getRGB()
335
		};
336
		DataColorAction fillHighlighted = new DataColorAction(EquivalenceGraph.nodes, "name", Constants.NOMINAL, VisualItem.FILLCOLOR, paletteHighlighted);
337
		ColorAction textHighlighted = new ColorAction(EquivalenceGraph.nodes, VisualItem.TEXTCOLOR, ColorLib.gray(200));
338
		ColorAction edgesHighlighted = new ColorAction(EquivalenceGraph.edges, VisualItem.STROKECOLOR, ColorLib.gray(0));
339

  
340
		ActionList focus = new ActionList();//ActionList.INFINITY
341
		focus.add(fillHighlighted);
342
		focus.add(textHighlighted);
343
		focus.add(edgesHighlighted);
344
		focus.add(new RepaintAction());
345
		return focus;
346
	}
347

  
348
	private void showSearchItems(){
349
		TupleSet ts = vis.getFocusGroup(Visualization.SEARCH_ITEMS);
350
		TupleSet tsF = vis.getFocusGroup(Visualization.FOCUS_ITEMS);
351
		tsF.clear();
352
		Iterator<Tuple> it = ts.tuples();
152
	private void export(){
153
		URL url = manager.openFile("png");
154
		
155
		Set<GraphPane> keys = graphs.keySet();
156
		Iterator<GraphPane> it = keys.iterator();
157
		int i=0;
353 158
		while(it.hasNext()){
354
			Tuple t = it.next();
355
			tsF.addTuple(t);
159
			GraphPane gpane = it.next();
160
			Visualization vis = gpane.getVis();
161
			//URL url = gpane.getUrl();
162
			//String urlStr = url.toString().substring(0, url.toString().length()-4)+".png";
163
			//System.out.println(" >> FILE TO EXPORT url before : "+url.toString());
164
			if(i==0) {
165
				File f = new File(url.toString());
166
				if(f.exists()){
167
					createImage(f, vis);
168
				}else {
169
					System.out.println("NO NEW FILE : "+f.getPath());
170
				}
171
			}
172
			++i;
356 173
		}
357
		vis.run("search");
358 174
	}
359 175
	
176
	private void createImage(File f, Visualization vis){ 
177
		//FileOutputStream out = null; 
178
		try { 
179
			Rectangle2D bounds = vis.getBounds(Visualization.ALL_ITEMS); 
180
			
181
			// Adding some margins here 
182
			double width = bounds.getWidth() + 100; 
183
			double height = bounds.getHeight() + 100; 
184
			Display display = new Display(vis); 
185
			
186
			// I forget why this big of code is called. 
187
			display.pan(-bounds.getX() + 50, -bounds.getY() + 50); 
188
			BufferedImage img = new BufferedImage((int)width, (int)height, BufferedImage.TYPE_INT_RGB); 
189
			System.out.println("CreateImage - URL "+f.getPath());
190
			Graphics2D g = (Graphics2D)img.getGraphics(); 
191
			display.paintDisplay(g, new Dimension((int)width, (int)height)); 
192
			//out = new FileOutputStream(f); 
193
			ImageIO.write(img,"png",f); 
194
			} catch (Exception ex) { 
195
				System.out.println("Exception - create image : "+ex);
196
				/*try { 
197
					Logger.getLogger(Search.class.getName()).log(Level.SEVERE, null, ex); 
198
					out.close(); 
199
					} catch (IOException ex1) { 
200
						Logger.getLogger(Search.class.getName()).log(Level.SEVERE, null, ex1); 
201
						} 
202
				} */
203
			}
204
		}
360 205
	
361

  
362
	public void highlightTarget(ConceptEquivalenceElement elementToHighlight){
363
		searchPanel.setQuery(elementToHighlight.getName());
364
		//vis.run("search");
206
	private void initParams(URL urlEquivalence){
207
		String path = urlEquivalence.getPath();
208
		int index = path.lastIndexOf("/");
209
		path = path.substring(index+1,path.length());
210
		
211
		index = path.indexOf("_");
212
		if(index!=-1){
213
			//GESTION DE LA LANGUE :
214
			lang += path.substring(0,index);
215
			path = path.substring(index+1,path.length());
216
			index = path.indexOf("_");
217
		
218
			if(index!=-1){
219
				//GESTION CONCEPT
220
				concept = path.substring(0,index);				
221
				path = path.substring(index+1,path.length());
222
				index = path.indexOf("_");
223
				
224
				if(urlsEquivalence.length>1){
225
					if(index!=-1){
226
						//GESTION TEXTE
227
						author = path.substring(0,index);				
228
						path = path.substring(index+1,path.length());
229
						index = path.indexOf("_");
230
						author = manager.getDataManager().getCorpusManager().getCorpus().getTextById(author).getName();
231
						
232
						if(index!=-1){
233
							//GESTION LEVEL
234
							level = path.substring(0,index);				
235
							path = path.substring(index+1,path.length());
236
						}
237
					}
238
				}else {
239
					if(index!=-1){
240
						//GESTION LEVEL
241
						level = path.substring(0,index);				
242
						path = path.substring(index+1,path.length());
243
					}
244
				}
245
			}	
246
		}
365 247
	}
366

  
248
	
367 249
	public void reinitPane(URL[] urlsEquivalence, boolean withSizes, boolean withAllConcepts){
368 250
		this.withSizes = withSizes;
369 251
		this.withAllConcepts = withAllConcepts;
......
375 257
	}
376 258

  
377 259

  
260

  
261
	@Override
262
	public void itemStateChanged(ItemEvent e) {
263
		Object source = e.getItemSelectable();
264

  
265
		if (source == graphSizeBox) {
266
			if (e.getStateChange() == ItemEvent.DESELECTED){
267
				withSizes = false;
268
			}
269
			if (e.getStateChange() == ItemEvent.SELECTED){
270
				withSizes = true;
271
			}
272

  
273
		}
274
		
275
	}
276

  
277
	
278

  
279

  
378 280
}
SRC/src/fr/triangle/hyperalign/gui/graph/GraphPane.java (revision 12)
1
package fr.triangle.hyperalign.gui.graph;
2

  
3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.Dimension;
6
import java.awt.Font;
7
import java.awt.Graphics2D;
8
import java.awt.GridBagConstraints;
9
import java.awt.GridBagLayout;
10
import java.awt.GridLayout;
11
import java.awt.event.ActionEvent;
12
import java.awt.event.ActionListener;
13
import java.awt.geom.Rectangle2D;
14
import java.awt.image.BufferedImage;
15
import java.io.File;
16
import java.io.FileOutputStream;
17
import java.io.IOException;
18
import java.net.URL;
19
import java.util.Iterator;
20
import java.util.Observable;
21
import java.util.Observer;
22
import java.util.ResourceBundle;
23
import java.util.logging.Logger;
24

  
25
import javax.imageio.ImageIO;
26
import javax.swing.DefaultComboBoxModel;
27
import javax.swing.JComboBox;
28
import javax.swing.JLabel;
29
import javax.swing.JPanel;
30
import javax.swing.JTextArea;
31

  
32
import prefuse.Constants;
33
import prefuse.Display;
34
import prefuse.Visualization;
35
import prefuse.action.Action;
36
import prefuse.action.ActionList;
37
import prefuse.action.RepaintAction;
38
import prefuse.action.assignment.ColorAction;
39
import prefuse.action.assignment.DataColorAction;
40
import prefuse.action.assignment.DataSizeAction;
41
import prefuse.action.layout.graph.ForceDirectedLayout;
42
import prefuse.activity.Activity;
43
import prefuse.controls.DragControl;
44
import prefuse.controls.FocusControl;
45
import prefuse.controls.NeighborHighlightControl;
46
import prefuse.controls.PanControl;
47
import prefuse.controls.ToolTipControl;
48
import prefuse.controls.ZoomControl;
49
import prefuse.data.Graph;
50
import prefuse.data.Table;
51
import prefuse.data.Tuple;
52
import prefuse.data.event.TupleSetListener;
53
import prefuse.data.io.DataIOException;
54
import prefuse.data.io.GraphMLReader;
55
import prefuse.data.query.SearchQueryBinding;
56
import prefuse.data.search.PrefixSearchTupleSet;
57
import prefuse.data.search.SearchTupleSet;
58
import prefuse.data.tuple.TupleSet;
59
import prefuse.render.DefaultRendererFactory;
60
import prefuse.render.LabelRenderer;
61
import prefuse.util.ColorLib;
62
import prefuse.util.FontLib;
63
import prefuse.util.ui.JSearchPanel;
64
import prefuse.visual.VisualItem;
65

  
66
import fr.triangle.hyperalign.gui.HMManager;
67
import fr.triangle.hyperalign.gui.HMTags;
68
import fr.triangle.hyperalign.kernel.HyperalignData;
69
import fr.triangle.hyperalign.kernel.DataManager.EquivalenceManager;
70
import fr.triangle.hyperalign.kernel.corpus.ParallelTextElement;
71
import fr.triangle.hyperalign.kernel.corpus.text.Division;
72
import fr.triangle.hyperalign.kernel.corpus.text.HyperalignText;
73
import fr.triangle.hyperalign.kernel.trad.ConceptEquivalenceElement;
74

  
75
public class GraphPane extends JPanel implements Observer {
76
	
77
	private HMManager manager;
78
	private String iconPath = "fr/triangle/hyperalign/gui/icons";  
79
	private ResourceBundle res;
80
	private URL urlEquivalence;
81
	private Visualization vis;
82
	private static final String nodes = "graph.nodes";
83
	private static final String edges = "graph.edges";
84
	private DataColorAction fill;
85
	private JSearchPanel searchPanel;
86
	
87
	private int widthsize;
88
	private int lengthsize;
89
	
90
	String author;
91
	String lang;
92
	String concept;
93
	String level;
94
	
95
	private boolean withSizes;
96
	boolean isSeveralGraphs = false;
97
	boolean withAllConcepts = false;
98
	
99
	public GraphPane(HMManager manager, EquivalenceGraph parent, URL urlEqui, 
100
			boolean isSeveralGraphs, int widthsize, int lengthsize, 
101
			boolean withAllConcepts, boolean withSizes){
102
		this.res = HyperalignData.getInstance().getResourceBundle();
103
		this.urlEquivalence = urlEqui;
104
		this.isSeveralGraphs = isSeveralGraphs;
105
		this.withSizes = withSizes;
106
		this.manager = manager;
107
		concept = res.getString("I18N_EQUIVALENCEGRAPH_ALLCONCEPTS");
108
		author = res.getString("I18N_EQUIVALENCEGRAPH_ALLAUTHORS");
109
		level = "1";
110
		lang = res.getString("I18N_EQUIVALENCEGRAPH_LANGUAGE");
111
		
112
		EquivalenceManager equivManager = manager.getDataManager().getEquivalenceManager();
113
		this.widthsize = widthsize;
114
		this.lengthsize = lengthsize;
115
		this.withAllConcepts = withAllConcepts;
116
		HyperalignData.getInstance().addObserver(this);  
117
		initGui();
118
	}
119
	
120
	public void initGui(){
121
		
122
		// -- 1. load the data ------------------------------------------------
123
		Graph graph = null;
124
		try {
125
			graph = new GraphMLReader().readGraph(urlEquivalence);
126
		} catch ( DataIOException e ) {
127
			e.printStackTrace();
128
			System.err.println("Error loading graph. Exiting...");
129
			System.exit(1);
130
		}
131

  
132

  
133
		// -- 2. the visualization --------------------------------------------
134
		vis = new Visualization();
135
		vis.add("graph", graph);
136
		vis.setInteractive(edges, null, false);
137

  
138
		// -- 3. the renderers and renderer factory ---------------------------  
139
		LabelRenderer r = new LabelRenderer("name"); //name or gender
140
		r.setRoundedCorner(8, 8); // round the corners
141
		vis.setRendererFactory(new DefaultRendererFactory(r)); //
142

  
143
		// -- 4. the processing actions ---------------------------------------
144
		int[] palette = new int[] {
145
				HMTags.colorGreenBlue.getRGB(), HMTags.colorBrownLight.getRGB()
146
		};
147
		// map nominal data values to colors using our provided palette
148
		fill = new DataColorAction(GraphPane.nodes, "lang", Constants.NOMINAL, VisualItem.FILLCOLOR, palette);
149
		ColorAction text = new ColorAction(GraphPane.nodes, VisualItem.TEXTCOLOR, ColorLib.gray(0));
150
		ColorAction edges = new ColorAction(GraphPane.edges, VisualItem.STROKECOLOR, ColorLib.gray(100));
151
		ColorAction edgesText = new ColorAction(GraphPane.edges, VisualItem.TEXTCOLOR, ColorLib.blue(120));
152
		
153
		//DataSizeAction size = new DataSizeAction(EquivalenceGraph.nodes, "nb", 10, Constants.LOG_SCALE);
154
		System.out.println("withSizes ? => "+withSizes);
155
		 // 1) the DataSizeAction for the edges based on datafield "weight"
156
        Action dataSizeAction = new DataSizeAction(GraphPane.nodes, "nb");  
157
       
158
		//// create an action list containing all color assignments
159
		//Constants.QUANTILE_SCALE 
160
        //Constants.LOG_SCALE 
161
        //Constants.LINEAR_SCALE
162

  
163
		ActionList color = new ActionList();
164
		color.add(fill);
165
		color.add(text);
166
		color.add(edges);
167
		color.add(edgesText);
168
		if(withSizes){
169
			//color.add(size);
170
			color.add(dataSizeAction);
171
		}
172
		ActionList layout = new ActionList(Activity.INFINITY);
173
		layout.add(new ForceDirectedLayout("graph"));
174
		layout.add(new RepaintAction());
175

  
176
		//Specific highlights
177
		ActionList search = searchAction();
178
		ActionList focus = focusAction();
179

  
180
		// add the actions to the visualization
181
		vis.putAction("color", color);
182
		vis.putAction("layout", layout);
183
		vis.putAction("search", search);
184
		vis.putAction("focus", focus);
185

  
186
		//vis.addFocusGroup(Visualization.FOCUS_ITEMS, new DefaultTupleSet());
187
		
188
		/*vis.getGroup(Visualization.FOCUS_ITEMS).addTupleSetListener(
189
				new TupleSetListener() {
190
					public void tupleSetChanged(TupleSet t, Tuple[] add, Tuple[] rem) {
191
						System.out.println("GraphPane.initGui() >>>>>>>>> tupleSetChanged() "+t.toString());
192
						vis.cancel("color");
193
						vis.run("focus");
194
					}
195
				}
196
		);
197
		
198
		fill.add("ingroup('_search_')", HMTags.colorPinkLight.getRGB());
199
		fill.add("ingroup('_focus_')", ColorLib.rgb(100,100,230));
200
		
201
		SearchQueryBinding sq = new SearchQueryBinding((Table) vis.getGroup(nodes), "name", (SearchTupleSet) vis.getGroup(Visualization.SEARCH_ITEMS));
202
		*/
203
		
204
		/*sq.getPredicate().addExpressionListener(new UpdateListener() {
205
		            public void update(Object src) {
206
		            	System.out.println(">>>>>>>>> addExpressionListener()");
207
		               // vis.cancel("color");
208
		               // vis.run("search");
209
		            }
210
		        });
211
		 */
212
	    
213
		// -- 5. the display and interactive controls -------------------------
214
		Display display = new Display(vis);
215
		if(isSeveralGraphs){
216
			display.setPreferredSize(new Dimension(widthsize, lengthsize));
217
			//display.setSize(widthsize, lengthsize); 
218
			// set display size  => d.setSize(800, 400); 
219
		}else {
220
			if(withAllConcepts){
221
				display.setSize(800, 700); 
222
			}else {
223
				display.setSize(800, 400); 
224
			}
225
		}
226
		display.setForeground(Color.WHITE);
227
		display.setBackground(Color.LIGHT_GRAY);
228

  
229
		ToolTipControl ttc = new ToolTipControl("nb");
230
		display.addControlListener(ttc);
231

  
232
		// drag individual items around
233
		display.addControlListener(new DragControl());
234
		// pan with left-click drag on background
235
		display.addControlListener(new PanControl()); 
236
		// zoom with right-click drag
237
		display.addControlListener(new ZoomControl());
238
		display.addControlListener(new NeighborHighlightControl());
239
		display.addControlListener(new FocusControl(2));
240
		display.addControlListener(new HighlightOnMouseOverControl("filter"));
241

  
242

  
243
		if(isSeveralGraphs){
244
			initParams(urlEquivalence);
245
			
246
			JLabel textLabelAuthor = new JLabel(res.getString("I18N_EQUIVALENCEGRAPH_BY")+author);
247
			textLabelAuthor.setPreferredSize(new Dimension(widthsize,20));
248
			//System.out.println("DIMENSION TEXT AREA : "+widthsize+" / 20");
249
			this.setLayout(new GridBagLayout());
250
			GridBagConstraints c = new GridBagConstraints();
251
			c.gridx = 0;
252
			c.gridy = 0;
253
			this.add(display,c);
254
			c = new GridBagConstraints();
255
			c.gridx = 0;
256
			c.gridy = 1;
257
			this.add(textLabelAuthor,c);
258
			//initSearchPane(graphPanel);
259

  
260
		}else {
261
			this.add(display, BorderLayout.CENTER);
262
			//JSearchPanel searchPane = initSearchPane();
263
			//this.add(searchPane, BorderLayout.LINE_END);
264
		}
265

  
266

  
267
		// assign the colors
268
		vis.run("color");
269
		// start up the animated layout
270
		vis.run("layout");
271
	}
272
	
273
	public URL getUrl(){
274
		return 	this.urlEquivalence ;
275
	}
276

  
277
	private ActionList searchAction(){
278
		int[] paletteHighlighted = new int[] {
279
				HMTags.colorPinkLight.getRGB()//Color.yellow.getRGB()
280
		};
281
		DataColorAction fillHighlighted = new DataColorAction(GraphPane.nodes, "name", Constants.NOMINAL, VisualItem.FILLCOLOR, paletteHighlighted);
282
		ColorAction textHighlighted = new ColorAction(GraphPane.nodes, VisualItem.TEXTCOLOR, ColorLib.gray(0));
283
		ColorAction edgesHighlighted = new ColorAction(GraphPane.edges, VisualItem.STROKECOLOR, ColorLib.gray(0));
284

  
285
		ActionList search = new ActionList();//ActionList.INFINITY
286
		search.add(fillHighlighted);
287
		search.add(textHighlighted);
288
		search.add(edgesHighlighted);
289
		search.add(new RepaintAction());
290
		return search;
291
	}
292

  
293
	private ActionList focusAction(){
294
		int[] paletteHighlighted = new int[] {
295
				Color.yellow.getRGB()
296
		};
297
		DataColorAction fillHighlighted = new DataColorAction(GraphPane.nodes, "name", Constants.NOMINAL, VisualItem.FILLCOLOR, paletteHighlighted);
298
		ColorAction textHighlighted = new ColorAction(GraphPane.nodes, VisualItem.TEXTCOLOR, ColorLib.gray(200));
299
		ColorAction edgesHighlighted = new ColorAction(GraphPane.edges, VisualItem.STROKECOLOR, ColorLib.gray(0));
300

  
301
		ActionList focus = new ActionList();//ActionList.INFINITY
302
		focus.add(fillHighlighted);
303
		focus.add(textHighlighted);
304
		focus.add(edgesHighlighted);
305
		focus.add(new RepaintAction());
306
		return focus;
307
	}
308
	
309
	private void initParams(URL urlEquivalence){
310
		String path = urlEquivalence.getPath();
311
		int index = path.lastIndexOf("/");
312
		path = path.substring(index+1,path.length());
313
		
314
		index = path.indexOf("_");
315
		if(index!=-1){
316
			//GESTION DE LA LANGUE :
317
			lang += path.substring(0,index);
318
			path = path.substring(index+1,path.length());
319
			index = path.indexOf("_");
320
		
321
			if(index!=-1){
322
				//GESTION CONCEPT
323
				concept = path.substring(0,index);				
324
				path = path.substring(index+1,path.length());
325
				index = path.indexOf("_");
326
				
327
				if(isSeveralGraphs){
328
					if(index!=-1){
329
						//GESTION TEXTE
330
						author = path.substring(0,index);				
331
						path = path.substring(index+1,path.length());
332
						index = path.indexOf("_");
333
						author = manager.getDataManager().getCorpusManager().getCorpus().getTextById(author).getName();
334
						
335
						if(index!=-1){
336
							//GESTION LEVEL
337
							level = path.substring(0,index);				
338
							path = path.substring(index+1,path.length());
339
						}
340
					}
341
				}else {
342
					if(index!=-1){
343
						//GESTION LEVEL
344
						level = path.substring(0,index);				
345
						path = path.substring(index+1,path.length());
346
					}
347
				}
348
			}	
349
		}
350
	}
351
	
352

  
353
	
354
	private JSearchPanel initSearchPane(){
355
	    
356
		/*SearchTupleSet searchTS = new PrefixSearchTupleSet();
357
		
358
		Set<GraphPane> keys = graphs.keySet();
359
		Iterator<GraphPane> it = keys.iterator();
360
		while(it.hasNext()){
361
			GraphPane graphPane = it.next();
362
			Visualization vis = graphs.get(graphPane);
363
			vis.addFocusGroup(Visualization.SEARCH_ITEMS, searchTS);
364

  
365

  
366
			
367
		}
368
		
369

  
370
		searchPanel = sq.createSearchPanel();
371
		searchPanel.setShowResultCount(true);
372
		searchPanel.setPreferredSize(new Dimension(200, 20));
373
		searchPanel.setFont(FontLib.getFont("Tahoma", Font.PLAIN, 11));
374
		searchPanel.setShowCancel(false);*/
375
		
376
		return searchPanel;
377
	}
378

  
379
	private void showSearchItems(){
380
		TupleSet ts = vis.getFocusGroup(Visualization.SEARCH_ITEMS);
381
		TupleSet tsF = vis.getFocusGroup(Visualization.FOCUS_ITEMS);
382
		tsF.clear();
383
		Iterator<Tuple> it = ts.tuples();
384
		while(it.hasNext()){
385
			Tuple t = it.next();
386
			tsF.addTuple(t);
387
		}
388
		vis.run("search");
389
	}
390
	
391
	
392

  
393
	public void highlightTarget(ConceptEquivalenceElement elementToHighlight){
394
		//searchPanel.setQuery(elementToHighlight.getName());
395
		////vis.run("search");
396
	}
397
	
398
	public Visualization getVis(){
399
		return vis;
400
	}
401
	
402
	public void update(Observable observable, Object obj) {
403
		// TODO Auto-generated method stub
404
		Integer changeType = (Integer) obj;
405
		if(changeType.intValue() == HyperalignData.LOCALE_CHANGE) {
406
			this.res = HyperalignData.getInstance().getResourceBundle();
407
			this.updateLabelsI18N();
408
		}
409
	}
410

  
411
	private void updateLabelsI18N() {
412
		// TODO Auto-generated method stub
413
		res = HyperalignData.getInstance().getResourceBundle();
414
	}
415

  
416
}

Formats disponibles : Unified diff