21import java.awt.BasicStroke;
22import java.awt.BorderLayout;
24import java.awt.Component;
25import java.awt.Dimension;
29import java.awt.Stroke;
30import java.awt.event.ActionEvent;
31import java.awt.event.ActionListener;
32import java.awt.event.MouseEvent;
33import java.awt.geom.Ellipse2D;
34import java.awt.geom.Point2D;
35import java.awt.geom.RoundRectangle2D;
36import java.util.ArrayList;
37import java.util.HashMap;
38import java.util.HashSet;
42import java.util.concurrent.ExecutionException;
44import javax.swing.JMenuItem;
45import javax.swing.JPanel;
46import javax.swing.JPopupMenu;
47import javax.swing.JSeparator;
49import com.google.common.base.Function;
51import denoptim.graph.APClass;
52import denoptim.graph.AttachmentPoint;
53import denoptim.graph.DGraph;
54import denoptim.graph.Edge;
55import denoptim.graph.Ring;
56import denoptim.graph.Template;
57import denoptim.graph.Vertex;
58import edu.uci.ics.jung.graph.SparseMultigraph;
59import edu.uci.ics.jung.graph.util.EdgeType;
60import edu.uci.ics.jung.visualization.Layer;
61import edu.uci.ics.jung.visualization.VisualizationViewer;
62import edu.uci.ics.jung.visualization.control.AbstractPopupGraphMousePlugin;
63import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
64import edu.uci.ics.jung.visualization.control.GraphMouseListener;
65import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
66import edu.uci.ics.jung.visualization.decorators.EdgeShape;
67import edu.uci.ics.jung.visualization.picking.PickedInfo;
68import edu.uci.ics.jung.visualization.renderers.BasicEdgeArrowRenderingSupport;
69import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position;
87 VisualizationViewer<JVertex, JEdge>
viewer;
88 private DefaultModalGraphMouse<JVertex, JEdge>
gm;
161 + Integer.toString(
ap.
getID());
173 this.expandable =
true;
278 this.srcAPC =
"null";
279 this.trgAPC =
"none";
302 this.srcAPC =
"null";
306 this.trgAPC =
"null";
332 this.setLayout(
new BorderLayout());
333 this.setBackground(Color.decode(
"#D9D9D9"));
334 this.setToolTipText(
"No graph to visualize");
348 for (Component c : this.getComponents())
427 edu.uci.ics.jung.graph.Graph<
JVertex,
JEdge> g =
new SparseMultigraph<>();
428 Map<Vertex, JVertex> vMap =
new HashMap<Vertex,JVertex>();
437 if (ap.isAvailableThroughout())
443 g.addEdge(e, vMap.get(v), vap, EdgeType.DIRECTED);
444 vap.edgeToParent = e;
450 g.addEdge(
new JEdge(e.getSrcAP(),
452 e.getBondType().toString()),
453 vMap.get(e.getSrcAP().getOwner()),
454 vMap.get(e.getTrgAP().getOwner()), EdgeType.DIRECTED);
459 r.getHeadVertex().getEdgeToParent().getSrcAP(),
460 r.getTailVertex().getEdgeToParent().getSrcAP(),
461 r.getBondType().toString()),
462 vMap.get(r.getHeadVertex()),
463 vMap.get(r.getTailVertex()), EdgeType.UNDIRECTED);
484 for (
JVertex v : graph.getVertices())
562 Dimension dimLayout =
null;
563 Dimension dimViewer =
null;
564 if (this.getSize().height<150)
566 dimLayout =
new Dimension(150, 150);
567 layout.setSize(dimLayout);
568 dimViewer =
new Dimension(150, 150);
570 double w = this.getSize().width *
scaling
571 - GUIPreferences.graphNodeSize * 1.5;
572 double h = this.getSize().height *
scaling
573 - GUIPreferences.graphNodeSize * 1.5;
574 dimLayout =
new Dimension((
int) w, (
int) h);
575 layout.setSize(dimLayout);
576 dimViewer = this.getSize();
581 if (prevStatus !=
null)
590 viewer.addGraphMouseListener(
new GraphMouseListener<JVertex>() {
593 public void graphReleased(
JVertex v, MouseEvent me)
597 public void graphPressed(
JVertex v, MouseEvent me)
601 public void graphClicked(
JVertex v, MouseEvent me)
611 viewer.getRenderer().getVertexLabelRenderer().setPosition(
613 viewer.getRenderContext().setVertexShapeTransformer(
615 viewer.getRenderContext().setVertexFillPaintTransformer(
617 viewer.getRenderContext().setVertexLabelTransformer(
619 viewer.getRenderContext().setVertexFontTransformer(
620 new Function<JVertex, Font>(){
623 return new Font(
"Helvetica", Font.PLAIN,
628 viewer.getRenderContext().setEdgeShapeTransformer(EdgeShape.line(g));
629 viewer.getRenderContext().setEdgeStrokeTransformer(
631 viewer.getRenderContext().setEdgeDrawPaintTransformer(
633 viewer.getRenderContext().setArrowFillPaintTransformer(
635 viewer.getRenderContext().setArrowDrawPaintTransformer(
637 viewer.getRenderer().getEdgeRenderer().setEdgeArrowRenderingSupport(
638 new BasicEdgeArrowRenderingSupport<JVertex, JEdge>());
639 viewer.getRenderContext().setEdgeLabelTransformer(
641 viewer.getRenderContext().setEdgeFontTransformer(
642 new Function<JEdge, Font>(){
644 public Font apply(
JEdge e) {
645 return new Font(
"Helvetica", Font.PLAIN,
650 gm =
new DefaultModalGraphMouse<JVertex, JEdge> ();
651 gm.setMode(ModalGraphMouse.Mode.PICKING);
654 viewer.addKeyListener(
gm.getModeKeyListener());
676 Point2D centerViewer =
viewer.getRenderContext()
677 .getMultiLayerTransformer()
678 .inverseTransform(Layer.LAYOUT,
viewer.getCenter());
679 viewer.getRenderContext().getMultiLayerTransformer()
680 .getTransformer(Layer.LAYOUT).translate(
681 -(centerGraph.getX() - centerViewer.getX()),
682 -(centerGraph.getY() - centerViewer.getY()));
689 double minX = Double.MAX_VALUE;
690 double minY = Double.MAX_VALUE;
691 double maxX = -Double.MAX_VALUE;
692 double maxY = -Double.MAX_VALUE;
697 Point2D p =
layout.getVertexPosition(v);
706 }
catch (ExecutionException e)
711 return new Point2D.Double(minX + (maxX-minX)/2.0,
712 minY + (maxY-minY)/2.0);
724 popup.show((Component) e.getSource(), e.getX(), e.getY());
730 @SuppressWarnings(
"serial")
736 JMenuItem mnuRelax =
new JMenuItem(
"Refine node locations");
737 mnuRelax.setToolTipText(String.format(
"<html><body width='%1s'>"
738 +
"Relaxe the position of graph nodes as to avoid node "
739 +
"overlap. Depending on the complexity of the graph, you "
740 +
"might consider moving specific portions of the graph "
741 +
"before attempting any refinement, or consider tunning "
742 +
"this refinement multiple times</html>", 300));
743 mnuRelax.addActionListener(
new ActionListener() {
744 public void actionPerformed(ActionEvent e) {
751 this.add(
new JSeparator());
753 JMenuItem mnuShrink =
new JMenuItem(
"Shrink Plottable Area");
754 mnuShrink.setToolTipText(String.format(
"<html><body width='%1s'>"
755 +
"Re-plot the graph using a shrinked plottable region."
756 +
"This will force nosed to fit into a smaller space."
758 mnuShrink.addActionListener(
new ActionListener() {
759 public void actionPerformed(ActionEvent e) {
766 JMenuItem mnuEnlarge =
new JMenuItem(
"Enlarge Plottable Area");
767 mnuEnlarge.setToolTipText(String.format(
"<html><body width='%1s'>"
768 +
"Re-plot the graph using an enlarged plottable region."
769 +
"This will allow nodes to be places farther apart."
771 mnuEnlarge.addActionListener(
new ActionListener() {
772 public void actionPerformed(ActionEvent e) {
777 this.add(mnuEnlarge);
779 this.add(
new JSeparator());
781 JMenuItem mnuCenterView =
new JMenuItem(
"Center View");
782 mnuCenterView.setToolTipText(String.format(
783 "<html><body width='%1s'>"
784 +
"Center the graph to the vindow.</html>", 300));
785 mnuCenterView.addActionListener(
new ActionListener() {
786 public void actionPerformed(ActionEvent e) {
790 this.add(mnuCenterView);
792 JMenuItem mnuMoveMode =
new JMenuItem(
"Mouse mode: move");
793 mnuMoveMode.setToolTipText(String.format(
794 "<html><body width='%1s'>"
795 +
"Makes mouse move the graph view.</html>", 300));
796 mnuMoveMode.addActionListener(
new ActionListener() {
797 public void actionPerformed(ActionEvent e) {
801 this.add(mnuMoveMode);
803 JMenuItem mnuPickMode =
new JMenuItem(
"Mouse mode: pick");
804 mnuPickMode.setToolTipText(String.format(
805 "<html><body width='%1s'>"
806 +
"Makes the mouse select vertex on click.</html>", 300));
807 mnuPickMode.addActionListener(
new ActionListener() {
808 public void actionPerformed(ActionEvent e) {
812 this.add(mnuPickMode);
814 this.add(
new JSeparator());
816 JMenuItem mnuShowAPC =
new JMenuItem(
"Show APClasses");
817 mnuShowAPC.setToolTipText(String.format(
"<html><body width='%1s'>"
819 +
"attachment point classes on edges and attachment points "
821 +
"the selected nodes.</html>", 300));
822 mnuShowAPC.addActionListener(
new ActionListener() {
823 public void actionPerformed(ActionEvent e) {
826 this.add(mnuShowAPC);
827 JMenuItem mnuHideAPC =
new JMenuItem(
"Hide APClasses");
828 mnuHideAPC.setToolTipText(String.format(
"<html><body width='%1s'>"
829 +
"Remove labels with "
830 +
"attachment point classes from edges "
831 +
"and attachment points related to "
832 +
"the selected nodes.</html>", 300));
833 mnuHideAPC.addActionListener(
new ActionListener() {
834 public void actionPerformed(ActionEvent e) {
837 this.add(mnuHideAPC);
839 this.add(
new JSeparator());
841 JMenuItem mnuShowAPID =
new JMenuItem(
"Show AP IDs");
842 mnuShowAPID.setToolTipText(String.format(
"<html><body width='%1s'>"
843 +
"Add labels declaring which attachment points are used "
844 +
"to form an edge. Acts on any edge related to the "
845 +
"selected nodes.</html>", 300));
846 mnuShowAPID.addActionListener(
new ActionListener() {
847 public void actionPerformed(ActionEvent e) {
850 this.add(mnuShowAPID);
851 JMenuItem mnuHideAPID =
new JMenuItem(
"Hide AP IDs");
852 mnuHideAPID.setToolTipText(String.format(
"<html><body width='%1s'>"
853 +
"Remove labales attachment point identifiers from the "
854 +
"edges related to the selecgted nodes.</html>", 300));
855 mnuHideAPID.addActionListener(
new ActionListener() {
856 public void actionPerformed(ActionEvent e) {
859 this.add(mnuHideAPID);
861 this.add(
new JSeparator());
863 JMenuItem mnuShowBT =
new JMenuItem(
"Show Bond Types");
864 mnuShowBT.setToolTipText(String.format(
"<html><body width='%1s'>"
865 +
"Add labels defining the bond type on "
866 +
"the edges related to the selected nodes."
868 mnuShowBT.addActionListener(
new ActionListener() {
869 public void actionPerformed(ActionEvent e) {
873 JMenuItem mnuHideBT =
new JMenuItem(
"Hide Bond Types");
874 mnuHideBT.setToolTipText(String.format(
"<html><body width='%1s'>"
875 +
"Remove labels defining the bond type from the edges"
876 +
"related to the selected nodes.</html>", 300));
877 mnuHideBT.addActionListener(
new ActionListener() {
878 public void actionPerformed(ActionEvent e) {
883 this.add(
new JSeparator());
885 JMenuItem mnuShowBBID =
new JMenuItem(
"Show Building Block IDs");
886 mnuShowBBID.setToolTipText(String.format(
"<html><body width='%1s'>"
888 +
"building block IDs to the selected nodes.</html>", 300));
889 mnuShowBBID.addActionListener(
new ActionListener() {
890 public void actionPerformed(ActionEvent e) {
893 this.add(mnuShowBBID);
894 JMenuItem mnuHideBBID =
new JMenuItem(
"Hide Building Block IDs");
895 mnuHideBBID.setToolTipText(String.format(
"<html><body width='%1s'>"
896 +
"Hide building block IDs in the selected nodes."
898 mnuHideBBID.addActionListener(
new ActionListener() {
899 public void actionPerformed(ActionEvent e) {
902 this.add(mnuHideBBID);
904 this.add(
new JSeparator());
906 JMenuItem mnuHideAll =
new JMenuItem(
"Hide All Labels");
907 mnuHideAll.setToolTipText(String.format(
"<html><body width='%1s'>"
908 +
"Hide all labels related to the selected nodes.</html>",
910 mnuHideAll.addActionListener(
new ActionListener() {
911 public void actionPerformed(ActionEvent e) {
915 this.add(mnuHideAll);
936 if (lst.contains(jv.idStr))
938 jv.displayBBID =
true;
949 if (lstBT.contains(je.id))
951 je.displayBndTyp =
true;
953 if (lstAPC.contains(je.id))
955 je.displayAPCs =
true;
957 if (lstAPID.contains(je.id))
959 je.displayAPIDs =
true;
976 label =
" AP" + v.
label;
981 label =
"<html><body style='text-align: center'>"
1002 return new RoundRectangle2D.Double(
1005 return new RoundRectangle2D.Double(
1010 return new RoundRectangle2D.Double(
1020 private final PickedInfo<JVertex>
pi;
1035 return Color.decode(
"#4484CE");
1037 return Color.decode(
"#F53240");
1039 return Color.decode(
"#57BC90");
1041 return Color.decode(
"#F19F4D");
1043 return Color.decode(
"#FECE00");
1045 return Color.decode(
"#BF1EE3");
1057 return new BasicStroke(1.0f, BasicStroke.CAP_BUTT,
1058 BasicStroke.JOIN_ROUND, 1.5f);
1069 return Color.decode(
"#FECE00");
1071 return Color.decode(
"#000000");
1095 label = label + e.
bt;
1099 if (!label.isEmpty()) label = label +
"<br>";
1100 label = label + e.srcAPC +
"<br>" + e.
trgAPC;
1104 if (!label.isEmpty()) label = label +
"<br>";
1105 label = label + e.srcAPID +
":" + e.
trgAPID;
1109 if (!label.isEmpty())
1113 if (!label.contains(
"<br>"))
1115 label =
" <br>" + label;
1117 label =
"<html><body style='text-align: center'>"
1118 + label +
"</body></html>";
1145 e.displayAPCs = show;
1155 e.displayAPIDs = show;
1165 e.displayBndTyp = show;
1173 v.displayBBID = show;
1188 Set<JEdge> selEdges =
new HashSet<>(
1189 viewer.getPickedEdgeState().getPicked());
1190 List<JVertex> lstNodes =
new ArrayList<JVertex>(
1191 viewer.getPickedVertexState().getPicked());
1192 for (
int i=0; i<lstNodes.size(); i++)
1194 for (
int j=i+1; j<lstNodes.size(); j++)
1221 return viewer.getPickedVertexState().getPicked();
1232 return !
viewer.getPickedVertexState().getPicked().isEmpty();
String toString()
Do not use this to make SDF representations.
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
APClass getAPClass()
Returns the Attachment Point class.
String toString()
Produces a string with the information included in this object.
int getID()
Returns a unique integer that is used to sort list of attachment points.
Container for the list of vertices and the edges that connect them.
List< Vertex > getVertexList()
List< Edge > getEdgeList()
This class represents the edge between two vertices.
This class represents the closure of a ring in a spanning tree.
ArrayList< AttachmentPoint > getAttachmentPoints()
Return the list of attachment points visible from outside the template, i.e., the so-called outer APs...
AttachmentPoint getInnerAPFromOuterAP(AttachmentPoint outerAP)
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
int getBuildingBlockId()
Returns the index of the building block that should correspond to the position of the building block ...
Vertex.BBType getBuildingBlockType()
This layout extends the SpringLayout to change its behaviour.
The collection of tunable preferences.
static int graphNodeSize
Graph visualization: size of nodes.
static int graphLabelFontSize
Graph visualization: font size of labels.
An edge in the JUNG Graph.
boolean toAp
Flag defining whether this edge is representing a AttachmentPoint.
JEdge(AttachmentPoint srcAP, AttachmentPoint trgAP, String bt)
Constructor for a JUNG edge representing a Edge or a chord that closes a Ring.
JEdge(AttachmentPoint srcAP)
Constructor for a JUNG edge representing a AttachmentPoint.
String bt
The bond type for edges that correspond to connections between Vertexs or "none" when for edges repre...
boolean displayAPCs
Flag requiring to display APClasses.
boolean displayBndTyp
Flag requiring to display Bond type.
String srcAPID
String representing the index of the source AP in the list of APs of the vertex owning the source AP.
String trgAPC
String representing the APClass on the target AP of directed edged this JUNG edge represents.
String trgAPID
String representing the index of the target AP in the list of APs of the vertex owning the source AP.
boolean displayAPIDs
Flag requiring to display APClasses.
String srcAPC
String representing the APClass on the source AP of directed edges or on the AP this edge represents.
a vertex in the JUNG Graph.
JVertex(Vertex v)
Constructor for vertex that represents a given Vertex.
JEdge edgeToParent
Reference to the JEdge linking this vertex to its parent vertex.
boolean expandable
Flag enabling opening vertex inner view (i.e., expand templates) in graph viewer.
boolean displayBBID
Flag requiring to display building block ID.
JVertex(AttachmentPoint ap)
Constructor for vertex that represents a given AttachmentPoint.
Vertex dnpVertex
The reference to the corresponding Vertex or null.
JVertexType vtype
A shortcut to record which type of DENOPTIM object this vertex represents.
String idStr
The string used as identifier of this JVertex in different instances representing the same graph.
String label
The string used as label when graphically depicting this vertex.
AttachmentPoint ap
The reference to the corresponding AttachmentPoint or null.
A Panel that holds the JUNG representation of a graph.
VisualizationViewer< JVertex, JEdge > viewer
void loadGraphToViewer(DGraph dnGraph)
Load the given DGraph to this graph viewer.
void inheritFeatures(JUNGGraphSnapshot prevStatus, boolean lock)
JUNGGraphSnapshot getGraphStatusSnapshot()
Returns a copy of the graph loaded into the viewer.
void loadGraphToViewer(DGraph dnGraph, JUNGGraphSnapshot prevStatus)
Load the given DGraph to the graph viewer.
edu.uci.ics.jung.graph.Graph< JVertex, JEdge > convertDnGraphToGSGraph(DGraph dnpGraph, Template tmpl)
Created a JUNG graph object that represents a DGraph, and allows to load a graphical representation i...
void initialize()
Builds the initialized component.
void loadGraphToViewer(Template tmpl)
Load the DGraph contained in a Template into the graph viewer.
void loadGraphToViewer(edu.uci.ics.jung.graph.Graph< JVertex, JEdge > g)
Load the given graph to the graph viewer.
void cleanup()
Removes the currently loaded graph viewer.
GraphViewerPanel()
Constructor.
DNPSpringLayout< JVertex, JEdge > layout
Set< JVertex > getSelectedNodes()
Finds selected nodes from the viewer.
edu.uci.ics.jung.graph.Graph< JVertex, JEdge > loadedGraph
void loadGraphToViewer(edu.uci.ics.jung.graph.Graph< JVertex, JEdge > g, JUNGGraphSnapshot prevStatus, boolean lock, double reScaling)
Load the given graph to the graph viewer.
void setMouseMode(ModalGraphMouse.Mode mode)
void loadGraphToViewer(edu.uci.ics.jung.graph.Graph< JVertex, JEdge > g, JUNGGraphSnapshot prevStatus, boolean lock)
Load the given graph to the graph viewer.
static final String PROPERTYMOUSEMODE
Set< JEdge > getSelectedEdges()
Finds of selected edges from the viewer.
DefaultModalGraphMouse< JVertex, JEdge > gm
static void renumberAPs(Template tmpl, edu.uci.ics.jung.graph.Graph< JVertex, JEdge > graph)
static final String PROPERTYNODECLICKED
edu.uci.ics.jung.graph.Graph< JVertex, JEdge > convertDnGraphToGSGraph(DGraph dnG)
Created a JUNG graph object that represents a DGraph, and allows to load a graphical representation i...
void alterLabels(LabelType labelType, boolean show)
Adds or removes labels from the elements selected in the graph view.
void fireMouseModePropertyChange(int i)
Files a property change relative to the mode of mouse transformation.
Point2D getLayoutCenter()
boolean hasSelected()
Check is there is any node selected in the viewer.
void loadGraphToViewer(edu.uci.ics.jung.graph.Graph< JVertex, JEdge > g, JUNGGraphSnapshot prevStatus)
Load the given graph to the graph viewer.
static final long serialVersionUID
Version UID.
This class collects information on how a graph was displayed in a JUNG visialisation server (i....
Map< String, Point2D > vertexPosition
Positions of nodes.
ArrayList< String > getEdgeIDsWithLabel(LabelType labelName)
ArrayList< String > getVertexeIDsWithLabel(LabelType labelName)