$darkmode
DENOPTIM
JUNGGraphSnapshot.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2022 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.gui;
20
21import java.awt.geom.Point2D;
22import java.util.ArrayList;
23import java.util.HashMap;
24import java.util.Map;
25import java.util.concurrent.ExecutionException;
26
27import denoptim.gui.GraphViewerPanel.JEdge;
28import denoptim.gui.GraphViewerPanel.JVertex;
29import denoptim.gui.GraphViewerPanel.LabelType;
30import edu.uci.ics.jung.algorithms.layout.ISOMLayout;
31import edu.uci.ics.jung.graph.Graph;
32
39{
43 private Map<LabelType,ArrayList<String>> vertexesWithLabels =
44 new HashMap<LabelType,ArrayList<String>>();
45
49 private Map<LabelType,ArrayList<String>> edgesWithLabels =
50 new HashMap<LabelType,ArrayList<String>>();
51
55 Map<String,Point2D> vertexPosition = new HashMap<String,Point2D>();
56
57//-----------------------------------------------------------------------------
58
59 public JUNGGraphSnapshot(Graph<JVertex, JEdge> graph,
61 {
62 for (JEdge je : graph.getEdges())
63 {
64 if (je.displayAPCs)
65 {
67 }
68 }
69
70 for (JEdge je : graph.getEdges())
71 {
72 if (je.displayBndTyp)
73 {
75 }
76 }
77
78 for (JVertex jv : graph.getVertices())
79 {
80 if (jv.displayBBID)
81 {
83 }
84 try
85 {
86 Point2D p = layout.getVertexPosition(jv);
87 vertexPosition.put(jv.idStr, new Point2D.Double(p.getX(),p.getY()));
88 } catch (ExecutionException e)
89 {
90 //e.printStackTrace();
91 }
92 }
93 }
94
95//-----------------------------------------------------------------------------
96
97 public JUNGGraphSnapshot(Graph<JVertex, JEdge> graph,
98 ISOMLayout<JVertex, JEdge> layout)
99 {
100 for (JVertex jv : graph.getVertices())
101 {
102 Point2D p = layout.apply(jv);
103 vertexPosition.put(jv.idStr, new Point2D.Double(p.getX(),p.getY()));
104 }
105 }
106
107//-----------------------------------------------------------------------------
108
109 private void processVertex(JVertex v, LabelType lt)
110 {
111 if (vertexesWithLabels.containsKey(lt))
112 {
113 vertexesWithLabels.get(lt).add(v.idStr);
114 } else {
115 ArrayList<String> lst = new ArrayList<String>();
116 lst.add(v.idStr);
117 vertexesWithLabels.put(lt, lst);
118 }
119 }
120
121//-----------------------------------------------------------------------------
122
123 private void processEdge(JEdge e, LabelType lt)
124 {
125 if (edgesWithLabels.containsKey(lt))
126 {
127 edgesWithLabels.get(lt).add(e.id);
128 } else {
129 ArrayList<String> lst = new ArrayList<String>();
130 lst.add(e.id);
131 edgesWithLabels.put(lt, lst);
132 }
133 }
134
135//-----------------------------------------------------------------------------
136
137 public ArrayList<String> getVertexeIDsWithLabel(LabelType labelName)
138 {
139 if (vertexesWithLabels.containsKey(labelName))
140 return vertexesWithLabels.get(labelName);
141 else
142 return new ArrayList<String>();
143 }
144
145//-----------------------------------------------------------------------------
146
147 public ArrayList<String> getEdgeIDsWithLabel(LabelType labelName)
148 {
149 if (edgesWithLabels.containsKey(labelName))
150 return edgesWithLabels.get(labelName);
151 else
152 return new ArrayList<String>();
153 }
154
155//-----------------------------------------------------------------------------
156
157}
This layout extends the SpringLayout to change its behaviour.
Point2D getVertexPosition(V vertex)
Returns the current value of the position of the given vertex.
String id
String identifying this edge within a graph.
String idStr
The string used as identifier of this JVertex in different instances representing the same graph.
This class collects information on how a graph was displayed in a JUNG visialisation server (i....
Map< LabelType, ArrayList< String > > edgesWithLabels
The collection of edges with labels (by label type)
JUNGGraphSnapshot(Graph< JVertex, JEdge > graph, ISOMLayout< JVertex, JEdge > layout)
Map< String, Point2D > vertexPosition
Positions of nodes.
ArrayList< String > getEdgeIDsWithLabel(LabelType labelName)
void processVertex(JVertex v, LabelType lt)
ArrayList< String > getVertexeIDsWithLabel(LabelType labelName)
Map< LabelType, ArrayList< String > > vertexesWithLabels
The collection of vertexes with labels (by label type)
void processEdge(JEdge e, LabelType lt)
JUNGGraphSnapshot(Graph< JVertex, JEdge > graph, DNPSpringLayout< JVertex, JEdge > layout)