|
@@ -8,14 +8,14 @@ import java.awt.Image;
|
|
import java.awt.Point;
|
|
import java.awt.Point;
|
|
import java.awt.event.MouseEvent;
|
|
import java.awt.event.MouseEvent;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.HashSet;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Set;
|
|
import java.util.TimerTask;
|
|
import java.util.TimerTask;
|
|
|
|
|
|
-import javax.swing.CellEditor;
|
|
|
|
import javax.swing.JMenuItem;
|
|
import javax.swing.JMenuItem;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPopupMenu;
|
|
import javax.swing.JPopupMenu;
|
|
-import javax.swing.JTable;
|
|
|
|
import javax.swing.Timer;
|
|
import javax.swing.Timer;
|
|
|
|
|
|
import classes.AbstractCanvasObject;
|
|
import classes.AbstractCanvasObject;
|
|
@@ -43,7 +43,7 @@ public abstract class AbstractCanvas extends JPanel {
|
|
* Version
|
|
* Version
|
|
*/
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
private static final long serialVersionUID = 1L;
|
|
-
|
|
|
|
|
|
+
|
|
final JMenuItem itemCut = new JMenuItem("Cut");
|
|
final JMenuItem itemCut = new JMenuItem("Cut");
|
|
final JMenuItem itemCopy = new JMenuItem("Copy");
|
|
final JMenuItem itemCopy = new JMenuItem("Copy");
|
|
final JMenuItem itemPaste = new JMenuItem("Paste");
|
|
final JMenuItem itemPaste = new JMenuItem("Paste");
|
|
@@ -52,7 +52,7 @@ public abstract class AbstractCanvas extends JPanel {
|
|
final JMenuItem itemUngroup = new JMenuItem("Ungroup");
|
|
final JMenuItem itemUngroup = new JMenuItem("Ungroup");
|
|
final JMenuItem itemAlign = new JMenuItem("Align selected");
|
|
final JMenuItem itemAlign = new JMenuItem("Align selected");
|
|
final JMenuItem itemCreateTemplate = new JMenuItem("Create Template");
|
|
final JMenuItem itemCreateTemplate = new JMenuItem("Create Template");
|
|
-
|
|
|
|
|
|
+
|
|
final int ANIMTIME = 500; // animation Time
|
|
final int ANIMTIME = 500; // animation Time
|
|
private final int animFPS = 60;
|
|
private final int animFPS = 60;
|
|
final int animDelay = 1000 / animFPS; // animation Delay
|
|
final int animDelay = 1000 / animFPS; // animation Delay
|
|
@@ -63,13 +63,13 @@ public abstract class AbstractCanvas extends JPanel {
|
|
// Selection
|
|
// Selection
|
|
AbstractCanvasObject tempCps = null;
|
|
AbstractCanvasObject tempCps = null;
|
|
UpdateController updCon;
|
|
UpdateController updCon;
|
|
-
|
|
|
|
- //Replacement
|
|
|
|
|
|
+
|
|
|
|
+ // Replacement
|
|
/**
|
|
/**
|
|
* the CpsObject that might be replaced by drag&drop
|
|
* the CpsObject that might be replaced by drag&drop
|
|
*/
|
|
*/
|
|
protected AbstractCanvasObject mayBeReplaced = null;
|
|
protected AbstractCanvasObject mayBeReplaced = null;
|
|
-
|
|
|
|
|
|
+
|
|
// PopUpMenu
|
|
// PopUpMenu
|
|
JPopupMenu popmenu = new JPopupMenu();
|
|
JPopupMenu popmenu = new JPopupMenu();
|
|
// Tooltip
|
|
// Tooltip
|
|
@@ -77,7 +77,7 @@ public abstract class AbstractCanvas extends JPanel {
|
|
Vector2Int toolTipPos = new Vector2Int(); // Tooltip Position
|
|
Vector2Int toolTipPos = new Vector2Int(); // Tooltip Position
|
|
String toolTipText = "";
|
|
String toolTipText = "";
|
|
List<HolonElement> dataSelected = new ArrayList<>();
|
|
List<HolonElement> dataSelected = new ArrayList<>();
|
|
- ArrayList<AbstractCanvasObject> tempSelected = new ArrayList<>();
|
|
|
|
|
|
+ protected Set<AbstractCanvasObject> tempSelected = new HashSet<>();
|
|
boolean showConnectionInformation;
|
|
boolean showConnectionInformation;
|
|
boolean dragging = false; // for dragging
|
|
boolean dragging = false; // for dragging
|
|
boolean dragged = false; // if an object/objects was/were dragged
|
|
boolean dragged = false; // if an object/objects was/were dragged
|
|
@@ -104,16 +104,14 @@ public abstract class AbstractCanvas extends JPanel {
|
|
|
|
|
|
// ------------------------------------------ METHODS
|
|
// ------------------------------------------ METHODS
|
|
// ------------------------------------------
|
|
// ------------------------------------------
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
- class ACpsHandle{
|
|
|
|
|
|
+ class ACpsHandle {
|
|
public AbstractCanvasObject object;
|
|
public AbstractCanvasObject object;
|
|
- ACpsHandle(AbstractCanvasObject object){
|
|
|
|
|
|
+
|
|
|
|
+ ACpsHandle(AbstractCanvasObject object) {
|
|
this.object = object;
|
|
this.object = object;
|
|
}
|
|
}
|
|
|
|
+
|
|
public String toString() {
|
|
public String toString() {
|
|
return object.toString();
|
|
return object.toString();
|
|
}
|
|
}
|
|
@@ -130,6 +128,7 @@ public abstract class AbstractCanvas extends JPanel {
|
|
g2.drawRect(sx, y, x - sx, sy - y);
|
|
g2.drawRect(sx, y, x - sx, sy - y);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @deprecated
|
|
* @deprecated
|
|
* @param g
|
|
* @param g
|
|
@@ -160,8 +159,6 @@ public abstract class AbstractCanvas extends JPanel {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
void setRightClickMenu(MouseEvent e) {
|
|
void setRightClickMenu(MouseEvent e) {
|
|
if (e.getButton() == MouseEvent.BUTTON3) {
|
|
if (e.getButton() == MouseEvent.BUTTON3) {
|
|
itemPaste.setEnabled(true);
|
|
itemPaste.setEnabled(true);
|
|
@@ -180,7 +177,7 @@ public abstract class AbstractCanvas extends JPanel {
|
|
itemUngroup.setEnabled(true);
|
|
itemUngroup.setEnabled(true);
|
|
else
|
|
else
|
|
itemUngroup.setEnabled(false);
|
|
itemUngroup.setEnabled(false);
|
|
- if (model.getSelectedCpsObjects().size() == 0) {
|
|
|
|
|
|
+ if (model.getSelectedObjects().size() == 0) {
|
|
controller.addSelectedObject(tempCps);
|
|
controller.addSelectedObject(tempCps);
|
|
}
|
|
}
|
|
if (tempCps instanceof HolonObject) {
|
|
if (tempCps instanceof HolonObject) {
|
|
@@ -211,17 +208,15 @@ public abstract class AbstractCanvas extends JPanel {
|
|
void markObjects() {
|
|
void markObjects() {
|
|
if (doMark) {
|
|
if (doMark) {
|
|
doMark = false;
|
|
doMark = false;
|
|
- for (AbstractCanvasObject cps : tempSelected) {
|
|
|
|
- if (!model.getSelectedCpsObjects().contains(cps)) {
|
|
|
|
- controller.addSelectedObject(cps);
|
|
|
|
- }
|
|
|
|
|
|
+ if (!tempSelected.isEmpty()) {
|
|
|
|
+ controller.toggleSelectedObjects(tempSelected);
|
|
|
|
+ controller.getObjectsInDepth();
|
|
|
|
+ tempSelected.clear();
|
|
}
|
|
}
|
|
- controller.getObjectsInDepth();
|
|
|
|
- tempSelected.clear();
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
int[] determineMousePositionOnEdge(Edge p) {
|
|
int[] determineMousePositionOnEdge(Edge p) {
|
|
int lx, ly, hx, hy;
|
|
int lx, ly, hx, hy;
|
|
|
|
|
|
@@ -280,97 +275,97 @@ public abstract class AbstractCanvas extends JPanel {
|
|
|
|
|
|
void triggerUpdateController() {
|
|
void triggerUpdateController() {
|
|
updCon.paintProperties(tempCps);
|
|
updCon.paintProperties(tempCps);
|
|
- updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
|
|
|
|
updCon.refreshTableProperties(model.getPropertyTable());
|
|
updCon.refreshTableProperties(model.getPropertyTable());
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Checks if {@code draggedCps} or a new cpsObject at Position (x,y) could replace exactly one object
|
|
|
|
- * in {@code objects}.
|
|
|
|
- * Saves the object that would be replaced in {@link AbstractCanvas}.{@code MayBeReplaced}
|
|
|
|
- * @param objects list of objects that could be replaced
|
|
|
|
|
|
+ * Checks if {@code draggedCps} or a new cpsObject at Position (x,y) could
|
|
|
|
+ * replace exactly one object in {@code objects}. Saves the object that would be
|
|
|
|
+ * replaced in {@link AbstractCanvas}.{@code MayBeReplaced}
|
|
|
|
+ *
|
|
|
|
+ * @param objects list of objects that could be replaced
|
|
* @param draggedCps Object that might replace
|
|
* @param draggedCps Object that might replace
|
|
- * @param x Position of the objects that might replace
|
|
|
|
- * @param y Position of the objects that might replace
|
|
|
|
- * @return true if exactly one Object could be replaced
|
|
|
|
|
|
+ * @param x Position of the objects that might replace
|
|
|
|
+ * @param y Position of the objects that might replace
|
|
|
|
+ * @return true if exactly one Object could be replaced
|
|
*/
|
|
*/
|
|
- protected boolean checkForReplacement(ArrayList<AbstractCanvasObject> objects, AbstractCanvasObject draggedCps, int x, int y){
|
|
|
|
-
|
|
|
|
|
|
+ protected boolean checkForReplacement(ArrayList<AbstractCanvasObject> objects, AbstractCanvasObject draggedCps,
|
|
|
|
+ int x, int y) {
|
|
|
|
+
|
|
/** distance treshold for replacement */
|
|
/** distance treshold for replacement */
|
|
- int treshhold = controller.getScale()/2;
|
|
|
|
-
|
|
|
|
|
|
+ int treshhold = controller.getScale() / 2;
|
|
|
|
+
|
|
/** number of Objects that might be replaced (should be 1) */
|
|
/** number of Objects that might be replaced (should be 1) */
|
|
int replaceCounter = 0;
|
|
int replaceCounter = 0;
|
|
-
|
|
|
|
|
|
+
|
|
/** last object that could be replaced */
|
|
/** last object that could be replaced */
|
|
AbstractCanvasObject toBeReplaced = null;
|
|
AbstractCanvasObject toBeReplaced = null;
|
|
-
|
|
|
|
|
|
+
|
|
/** Position of object that might be replaced */
|
|
/** Position of object that might be replaced */
|
|
Vector2Int p;
|
|
Vector2Int p;
|
|
-
|
|
|
|
|
|
+
|
|
/** for each cps on Canvas */
|
|
/** for each cps on Canvas */
|
|
- if(draggedCps == null || !(draggedCps instanceof Node) && !(draggedCps instanceof Node)){
|
|
|
|
- for (AbstractCanvasObject cps : objects){
|
|
|
|
|
|
+ if (draggedCps == null || !(draggedCps instanceof Node) && !(draggedCps instanceof Node)) {
|
|
|
|
+ for (AbstractCanvasObject cps : objects) {
|
|
/** same object -> ignore */
|
|
/** same object -> ignore */
|
|
- if(cps == draggedCps)continue;
|
|
|
|
-
|
|
|
|
|
|
+ if (cps == draggedCps)
|
|
|
|
+ continue;
|
|
|
|
+
|
|
/** set Position of object that might be replaced */
|
|
/** set Position of object that might be replaced */
|
|
p = cps.getPosition();
|
|
p = cps.getPosition();
|
|
-
|
|
|
|
|
|
+
|
|
/** if near enough */
|
|
/** if near enough */
|
|
- if(Math.abs(x-p.getX())<treshhold && Math.abs(y-p.getY())<treshhold){
|
|
|
|
|
|
+ if (Math.abs(x - p.getX()) < treshhold && Math.abs(y - p.getY()) < treshhold) {
|
|
replaceCounter++;
|
|
replaceCounter++;
|
|
toBeReplaced = cps;
|
|
toBeReplaced = cps;
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * if too many Objects could be replaced:
|
|
|
|
- * stop searching, because it would not be clear which one should
|
|
|
|
- * be replaced
|
|
|
|
|
|
+ * if too many Objects could be replaced: stop searching, because it would not
|
|
|
|
+ * be clear which one should be replaced
|
|
*/
|
|
*/
|
|
- if(replaceCounter>1)break;
|
|
|
|
|
|
+ if (replaceCounter > 1)
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* return true if exactly one obect would be replaced
|
|
* return true if exactly one obect would be replaced
|
|
*/
|
|
*/
|
|
- if( replaceCounter == 1 && toBeReplaced != null){
|
|
|
|
|
|
+ if (replaceCounter == 1 && toBeReplaced != null) {
|
|
mayBeReplaced = toBeReplaced;
|
|
mayBeReplaced = toBeReplaced;
|
|
return true;
|
|
return true;
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
mayBeReplaced = null;
|
|
mayBeReplaced = null;
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
- * Checks if an inserted new Object could replace exactly one object on the canvas.
|
|
|
|
- * Saves the object that would be replaced in {@link AbstractCanvas}.{@code MayBeReplaced}
|
|
|
|
|
|
+ * Checks if an inserted new Object could replace exactly one object on the
|
|
|
|
+ * canvas. Saves the object that would be replaced in
|
|
|
|
+ * {@link AbstractCanvas}.{@code MayBeReplaced}
|
|
|
|
+ *
|
|
* @param x Position of the objects that might replace
|
|
* @param x Position of the objects that might replace
|
|
* @param y Position of the objects that might replace
|
|
* @param y Position of the objects that might replace
|
|
- * @return true if exactly one Object could be replaced
|
|
|
|
|
|
+ * @return true if exactly one Object could be replaced
|
|
*/
|
|
*/
|
|
public abstract boolean checkForReplacement(int x, int y);
|
|
public abstract boolean checkForReplacement(int x, int y);
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* highlights the object that mayBeReplaced
|
|
* highlights the object that mayBeReplaced
|
|
|
|
+ *
|
|
* @param g2
|
|
* @param g2
|
|
*/
|
|
*/
|
|
protected void highlightMayBeReplaced(Graphics2D g2) {
|
|
protected void highlightMayBeReplaced(Graphics2D g2) {
|
|
- if(mayBeReplaced != null){
|
|
|
|
|
|
+ if (mayBeReplaced != null) {
|
|
g2.setColor(Color.RED);
|
|
g2.setColor(Color.RED);
|
|
- g2.fillRect(
|
|
|
|
- (int) (mayBeReplaced.getPosition().getX()
|
|
|
|
- - controller.getScaleDiv2() - (scalediv20 + 3)),
|
|
|
|
- (int) (mayBeReplaced.getPosition().getY()
|
|
|
|
- - controller.getScaleDiv2() - (scalediv20 + 3)),
|
|
|
|
|
|
+ g2.fillRect((int) (mayBeReplaced.getPosition().getX() - controller.getScaleDiv2() - (scalediv20 + 3)),
|
|
|
|
+ (int) (mayBeReplaced.getPosition().getY() - controller.getScaleDiv2() - (scalediv20 + 3)),
|
|
(int) (controller.getScale() + ((scalediv20 + 3) * 2)),
|
|
(int) (controller.getScale() + ((scalediv20 + 3) * 2)),
|
|
(int) (controller.getScale() + ((scalediv20 + 3) * 2)));
|
|
(int) (controller.getScale() + ((scalediv20 + 3) * 2)));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Align alle Objects on the Canvas to a Grid with objects every 10 pixels
|
|
* Align alle Objects on the Canvas to a Grid with objects every 10 pixels
|
|
*/
|
|
*/
|
|
@@ -378,62 +373,35 @@ public abstract class AbstractCanvas extends JPanel {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Aligns the Object the a grid
|
|
* Aligns the Object the a grid
|
|
- * @param cps Object that should be aligned
|
|
|
|
- * @param distance distance between the AlignmentGrid Lines. (objects every 'distance' pixels
|
|
|
|
|
|
+ *
|
|
|
|
+ * @param cps Object that should be aligned
|
|
|
|
+ * @param distance distance between the AlignmentGrid Lines. (objects every
|
|
|
|
+ * 'distance' pixels
|
|
*/
|
|
*/
|
|
protected void align(AbstractCanvasObject cps, int distance) {
|
|
protected void align(AbstractCanvasObject cps, int distance) {
|
|
/** Position of the AbstractCpsObject which should be aligned */
|
|
/** Position of the AbstractCpsObject which should be aligned */
|
|
Vector2Int p = cps.getPosition();
|
|
Vector2Int p = cps.getPosition();
|
|
-
|
|
|
|
- //calculate how many pixels the cps should be decreased to align
|
|
|
|
|
|
+
|
|
|
|
+ // calculate how many pixels the cps should be decreased to align
|
|
/** x offset relative to a grid with lines every distance pixels */
|
|
/** x offset relative to a grid with lines every distance pixels */
|
|
int x_off = cps.getPosition().getX() % distance;
|
|
int x_off = cps.getPosition().getX() % distance;
|
|
-
|
|
|
|
|
|
+
|
|
/** y offset relative to a grid with lines every distance pixels */
|
|
/** y offset relative to a grid with lines every distance pixels */
|
|
int y_off = cps.getPosition().getY() % distance;
|
|
int y_off = cps.getPosition().getY() % distance;
|
|
-
|
|
|
|
- //align to the other Line, if it is nearer
|
|
|
|
- if(x_off > distance/2)
|
|
|
|
|
|
+
|
|
|
|
+ // align to the other Line, if it is nearer
|
|
|
|
+ if (x_off > distance / 2)
|
|
x_off -= distance;
|
|
x_off -= distance;
|
|
- if(y_off > distance/2)
|
|
|
|
|
|
+ if (y_off > distance / 2)
|
|
y_off -= distance;
|
|
y_off -= distance;
|
|
-
|
|
|
|
|
|
+
|
|
/** set new Position */
|
|
/** set new Position */
|
|
- cps.setPosition(p.getX()-x_off, p.getY()-y_off);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Stops Editing in HolonElementTable and PropertyTable
|
|
|
|
- */
|
|
|
|
- protected void stopEditing() {
|
|
|
|
- /**
|
|
|
|
- * Stop Editing, if mouse exits the Table
|
|
|
|
- */
|
|
|
|
- JTable holElem = model.getTableHolonElement();
|
|
|
|
- CellEditor cellEditor = holElem.getCellEditor();
|
|
|
|
- if (cellEditor != null) {
|
|
|
|
- if (cellEditor.getCellEditorValue() != null) {
|
|
|
|
- /** TODO: Maybe try to save current Data */
|
|
|
|
- cellEditor.stopCellEditing();
|
|
|
|
- } else {
|
|
|
|
- cellEditor.cancelCellEditing();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- JTable propertys = model.getTableProperties();
|
|
|
|
- cellEditor = propertys.getCellEditor();
|
|
|
|
- if (cellEditor != null) {
|
|
|
|
- if (cellEditor.getCellEditorValue() != null) {
|
|
|
|
- /** TODO: Maybe try to save current Data */
|
|
|
|
- cellEditor.stopCellEditing();
|
|
|
|
- } else {
|
|
|
|
- cellEditor.cancelCellEditing();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ cps.setPosition(p.getX() - x_off, p.getY() - y_off);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Closes a tab of the UpperNode with ID upperNodeID
|
|
* Closes a tab of the UpperNode with ID upperNodeID
|
|
|
|
+ *
|
|
* @param upperNodeId
|
|
* @param upperNodeId
|
|
*/
|
|
*/
|
|
public abstract void closeUpperNodeTab(int upperNodeId);
|
|
public abstract void closeUpperNodeTab(int upperNodeId);
|