commonsrc.ingenias.editor.events.CenterRelationships Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core Show documentation
Show all versions of core Show documentation
The INGENIAS Meta-Editor core. It is a set of facilities to generate an editor from a detailed xml description
/**
* 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.cell.*;
import ingenias.editor.entities.*;
import java.awt.*;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Hashtable;
import java.util.Set;
import org.jgraph.graph.*;
import org.jgraph.*;
import org.jgraph.event.*;
import ingenias.editor.ObservableModel;
import java.util.*;
/**
*
* Avoids that an entity gets outta of the screen.
* It does so by setting X to 1 when X<0 and Y to 1 when Y<0
*
*/
public class CenterRelationships
implements org.jgraph.event.GraphModelListener {
private boolean enabled = true;
String workingObject = null;
JGraph graph;
public CenterRelationships(JGraph graph) {
this.graph = graph;
}
public void graphChanged(org.jgraph.event.GraphModelEvent gme) {
/* if (enabled && this.workingObject == null) {
this.workingObject = "hola";
this.updateEdges( (ingenias.editor.Model) gme.getSource());
this.workingObject = null;
}*/
}
/* public Point getCenter(Vector points) {
Iterator it = points.iterator();
int x = 0;
int y = 0;
while (it.hasNext()) {
Point point = (Point) it.next();
x = x + point.x;
y = y + point.y;
}
return new Point( (int) (x / points.size()), (int) (y / points.size()));
}*/
public static DefaultGraphCell getCellDefaultGraphCellFromDefaultEdge(DefaultEdge edge, ingenias.editor.Model m) {
DefaultEdge de = edge;
DefaultGraphCell target = (DefaultGraphCell) ( (DefaultPort) m.getTarget(de)).
getParent();
DefaultGraphCell source = (DefaultGraphCell) ( (DefaultPort) m.getSource(de)).
getParent();
DefaultGraphCell defaultGraphCellExtreme = null;
if (NAryEdge.class.isAssignableFrom(target.getClass())) {
defaultGraphCellExtreme = source;
}
if (NAryEdge.class.isAssignableFrom(source.getClass())) {
defaultGraphCellExtreme = target;
}
return defaultGraphCellExtreme;
}
public static NAryEdge getCellNAryEdgeFromDefaultEdge(DefaultEdge edge, ingenias.editor.Model m) {
DefaultEdge de = edge;
DefaultGraphCell target = (DefaultGraphCell) ( (DefaultPort) m.getTarget(de)).
getParent();
DefaultGraphCell source = (DefaultGraphCell) ( (DefaultPort) m.getSource(de)).
getParent();
NAryEdge nary = null;
if (NAryEdge.class.isAssignableFrom(target.getClass())) {
nary = (NAryEdge) target;
}
if (NAryEdge.class.isAssignableFrom(source.getClass())) {
nary = (NAryEdge) source;
}
return nary;
}
/*private void updateEdges(ingenias.editor.Model model) {
Hashtable