ingenias.editor.events.ChangeNARYEdgeLocation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sociaalmled Show documentation
Show all versions of sociaalmled Show documentation
A editor for modelling scenarios for PHAT simulator
The newest version!
/**
* Copyright (C) 2010 Jorge J. Gomez-Sanz
*
* This file is part of the INGENME tool. INGENME is an open source meta-editor
* which produces customized editors for user-defined modeling languages
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 3 of the License
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see
**/
package ingenias.editor.events;
import ingenias.editor.Model;
import ingenias.editor.ModelJGraph;
import ingenias.editor.cell.*;
import ingenias.editor.entities.Entity;
import ingenias.editor.entities.ViewPreferences;
import java.awt.*;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.geom.Line2D;
import java.awt.geom.Line2D.Float;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.*;
import org.jgraph.graph.*;
import org.jgraph.*;
import org.jgraph.event.*;
/**
* This class reallocates a n-ary edge so the central point of the
* set of ports that it inter-connects. The position is calculated
* by adding the (x,y) of each port and dividing by the number of
* ports
*/
public class ChangeNARYEdgeLocation
implements org.jgraph.event.GraphModelListener {
private Object workingObject = null;
private boolean alreadyExecuting = true;
private int counter = 0;
JGraph graph = null;
private boolean enabled=true;
public ChangeNARYEdgeLocation(JGraph graph) {
this.graph = graph;
}
public void graphChanged(org.jgraph.event.GraphModelEvent gme) {
if (enabled && alreadyExecuting && (gme.getChange().getInserted()==null
||gme.getChange().getInserted().length==0 )) {
alreadyExecuting=false;
Hashtable changes = new Hashtable();
Map old = gme.getChange().getPreviousAttributes();
Map newAt = gme.getChange().getAttributes();
if (old != null) {
// No autocenter. Just watch that no overlapping occurs.
Iterator keys = old.keySet().iterator();
while (keys.hasNext()) {
Object current = keys.next();
Map oluomap = (Map) old.get(current);
Map newuomap = (Map) newAt.get(current);
if ((GraphConstants.getBounds(oluomap)==null
||GraphConstants.getBounds(newuomap)==null) ){
if (current instanceof NAryEdge) {
this.processChange(current,changes);
}
} else {
Rectangle rect1 = GraphConstants.getBounds(oluomap).getBounds();
Rectangle rect2 = GraphConstants.getBounds(newuomap).getBounds();
if (((rect1 == null || rect2 == null || !rect1.equals(rect2))) &&
current instanceof NAryEdge) {
this.processChange( current,changes);
}
}
}
solveOverlappings((ModelJGraph) graph, changes);
if (changes.size()>0){
graph.getModel().edit(changes, null, null, null);
}
}
alreadyExecuting=true;
}
}
public static void solveOverlappings(ModelJGraph graph,
Hashtable map) {
Hashtable