|
@@ -7,6 +7,7 @@ import java.awt.Graphics2D;
|
|
|
import java.awt.Image;
|
|
|
import java.awt.Point;
|
|
|
import java.awt.RenderingHints;
|
|
|
+import java.awt.datatransfer.UnsupportedFlavorException;
|
|
|
import java.awt.event.ActionEvent;
|
|
|
import java.awt.event.ActionListener;
|
|
|
import java.awt.event.MouseEvent;
|
|
@@ -22,10 +23,14 @@ import java.util.TimerTask;
|
|
|
import javax.swing.ImageIcon;
|
|
|
import javax.swing.JLabel;
|
|
|
import javax.swing.JMenuItem;
|
|
|
+import javax.swing.JOptionPane;
|
|
|
import javax.swing.JPanel;
|
|
|
import javax.swing.JPopupMenu;
|
|
|
import javax.swing.JScrollPane;
|
|
|
import javax.swing.JTabbedPane;
|
|
|
+
|
|
|
+import com.google.gson.JsonParseException;
|
|
|
+
|
|
|
import classes.CpsEdge;
|
|
|
import classes.CpsNode;
|
|
|
import classes.CpsUpperNode;
|
|
@@ -113,8 +118,6 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
private Position unPos;
|
|
|
private ArrayList<Position> savePos;
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* Constructor.
|
|
|
*
|
|
@@ -136,7 +139,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
scalediv20 = model.getScale() / 20;
|
|
|
|
|
|
// Cps objecte aus dem border links schieben
|
|
|
- borderPos = (int) (model.getScale() + scalediv20 + scalediv20 + 10);
|
|
|
+ borderPos = (int) (model.getScale() + controller.getScaleDiv2() + scalediv20 + scalediv20 + 10);
|
|
|
for (AbstractCpsObject cps : upperNode.getNodes()) {
|
|
|
if (cps.getPosition().x < model.getScaleDiv2() + borderPos + 5) {
|
|
|
cps.setPosition(new Position(borderPos + 5, cps.getPosition().y));
|
|
@@ -159,7 +162,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
itemDelete.setEnabled(false);
|
|
|
itemCut.setEnabled(false);
|
|
|
itemCopy.setEnabled(false);
|
|
|
- itemPaste.setEnabled(false);
|
|
|
+ itemPaste.setEnabled(true);
|
|
|
itemGroup.setEnabled(false);
|
|
|
itemUngroup.setEnabled(false);
|
|
|
itemTrack.setEnabled(false);
|
|
@@ -225,7 +228,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
// save old Position
|
|
|
JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
|
|
|
- for (int i = 3; i < tabbedPane.getTabCount(); i++) {
|
|
|
+ for (int i = 4; i < tabbedPane.getTabCount(); i++) {
|
|
|
if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
|
|
|
.getComponent(0)).upperNode.getId() == ((CpsUpperNode) tempCps).getId()) {
|
|
|
tabbedPane.remove(i);
|
|
@@ -352,7 +355,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
// Remove UpperNodeTab if UpperNode deleted
|
|
|
if (cps instanceof CpsUpperNode) {
|
|
|
JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
|
|
|
- for (int i = 2; i < tabbedPane.getTabCount(); i++) {
|
|
|
+ for (int i = 4; i < tabbedPane.getTabCount(); i++) {
|
|
|
if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
|
|
|
.getComponent(0)).upperNode.getId() == cps.getId()) {
|
|
|
tabbedPane.remove(i);
|
|
@@ -389,7 +392,13 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
itemPaste.addActionListener(new ActionListener() {
|
|
|
@Override
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
- controller.paste(upperNode, mousePosition);
|
|
|
+ try {
|
|
|
+ controller.paste(upperNode, mousePosition);
|
|
|
+ } catch (JsonParseException | UnsupportedFlavorException | IOException e1) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ JLabel message = new JLabel("The Clipboard information cannot be pastet into Application.");
|
|
|
+ JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
|
|
|
+ }
|
|
|
repaint();
|
|
|
}
|
|
|
});
|
|
@@ -413,26 +422,28 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
g2.setRenderingHints(rh);
|
|
|
|
|
|
+ // Left Border
|
|
|
+ borderPos = (int) (model.getScale() + scalediv20 + scalediv20 + 10);
|
|
|
+
|
|
|
// Paint the Background
|
|
|
if (!upperNode.getImagePath().isEmpty()) {
|
|
|
img = new ImageIcon(upperNode.getImagePath()).getImage();
|
|
|
switch (upperNode.getBackgroundMode()) {
|
|
|
case BackgroundPopUp.IMAGE_PIXELS:
|
|
|
- g2.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null);
|
|
|
+ g2.drawImage(img, borderPos, 0, img.getWidth(null), img.getHeight(null), null);
|
|
|
break;
|
|
|
case BackgroundPopUp.STRETCHED:
|
|
|
- g2.drawImage(img, 0, 0, model.getCanvasX(), model.getCanvasY(), null);
|
|
|
+ g2.drawImage(img, borderPos, 0, model.getCanvasX(), model.getCanvasY(), null);
|
|
|
break;
|
|
|
case BackgroundPopUp.CUSTOM:
|
|
|
- g2.drawImage(img, 0, 0, upperNode.getImageWidht(), upperNode.getImageHeight(), null);
|
|
|
+ g2.drawImage(img, borderPos, 0, upperNode.getImageWidht(), upperNode.getImageHeight(), null);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Left Border
|
|
|
- borderPos = (int) (model.getScale() + scalediv20 + scalediv20 + 10);
|
|
|
+ // Draw Left Border
|
|
|
g2.setColor(new Color(230, 230, 230));
|
|
|
g2.fillRect(0, 0, borderPos, this.getHeight());
|
|
|
g2.setColor(Color.BLACK);
|
|
@@ -472,8 +483,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
count++;
|
|
|
}
|
|
|
} else {
|
|
|
- g2.drawLine(tempCps.getPosition().x + controller.getScaleDiv2(),
|
|
|
- tempCps.getPosition().y + controller.getScaleDiv2(), x, y);
|
|
|
+ g2.drawLine(tempCps.getPosition().x, tempCps.getPosition().y, x, y);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -484,7 +494,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
if (con.getState()) {
|
|
|
g2.setColor(Color.GREEN);
|
|
|
if (con.getCapacity() != -1) {
|
|
|
- g2.setStroke(new BasicStroke(Math.min(((con.getFlow() / con.getCapacity() * 3)+1), 4)));
|
|
|
+ g2.setStroke(new BasicStroke(Math.min(((con.getFlow() / con.getCapacity() * 3) + 1), 4)));
|
|
|
}
|
|
|
} else {
|
|
|
g2.setColor(Color.RED);
|
|
@@ -494,10 +504,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
g2.setColor(Color.DARK_GRAY);
|
|
|
g2.setStroke(new BasicStroke(2));
|
|
|
}
|
|
|
- g2.drawLine(con.getA().getPosition().x + controller.getScaleDiv2(),
|
|
|
- con.getA().getPosition().y + controller.getScaleDiv2(),
|
|
|
- con.getB().getPosition().x + controller.getScaleDiv2(),
|
|
|
- con.getB().getPosition().y + controller.getScaleDiv2());
|
|
|
+ g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
|
|
|
+ con.getB().getPosition().y);
|
|
|
|
|
|
if (con.getCapacity() == -1) {
|
|
|
maxCap = Character.toString('\u221e');
|
|
@@ -509,16 +517,11 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
if (showedInformation[0]) {
|
|
|
if (con.getConnected() == 0 || con.getConnected() == 1) {
|
|
|
g2.drawString(con.getFlow() + "/" + maxCap,
|
|
|
- (con.getA().getPosition().x + con.getB().getPosition().x) / 2
|
|
|
- + controller.getScaleDiv2(),
|
|
|
- (con.getA().getPosition().y + con.getB().getPosition().y) / 2
|
|
|
- + controller.getScaleDiv2());
|
|
|
+ (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
|
|
|
+ (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
|
|
|
} else {
|
|
|
- g2.drawString("not connected",
|
|
|
- (con.getA().getPosition().x + con.getB().getPosition().x) / 2
|
|
|
- + controller.getScaleDiv2(),
|
|
|
- (con.getA().getPosition().y + con.getB().getPosition().y) / 2
|
|
|
- + controller.getScaleDiv2());
|
|
|
+ g2.drawString("not connected", (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
|
|
|
+ (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -529,7 +532,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
g2.setColor(Color.BLUE);
|
|
|
for (CpsEdge con : upperNode.getNodeEdges()) {
|
|
|
if (con.getFlow() <= con.getCapacity()) {
|
|
|
- g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 3)+1, 4)));
|
|
|
+ g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 3) + 1, 4)));
|
|
|
} else {
|
|
|
g2.setStroke(new BasicStroke(2));
|
|
|
}
|
|
@@ -538,10 +541,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
|| con.getB().getId() == model.getSelectedObjectID()
|
|
|
|| model.getSelectedCpsObjects().contains(con.getB())
|
|
|
|| tempSelected.contains(con.getB()) && con != edgeHighlight) {
|
|
|
- g2.drawLine(con.getA().getPosition().x + controller.getScaleDiv2(),
|
|
|
- con.getA().getPosition().y + controller.getScaleDiv2(),
|
|
|
- con.getB().getPosition().x + controller.getScaleDiv2(),
|
|
|
- con.getB().getPosition().y + controller.getScaleDiv2());
|
|
|
+ g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
|
|
|
+ con.getB().getPosition().y);
|
|
|
|
|
|
if (con.getCapacity() == -1) {
|
|
|
maxCap = Character.toString('\u221e');
|
|
@@ -553,16 +554,12 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
if (showedInformation[0]) {
|
|
|
if (con.getConnected() == 0 || con.getConnected() == 1) {
|
|
|
g2.drawString(con.getFlow() + "/" + maxCap,
|
|
|
- (con.getA().getPosition().x + con.getB().getPosition().x) / 2
|
|
|
- + controller.getScaleDiv2(),
|
|
|
- (con.getA().getPosition().y + con.getB().getPosition().y) / 2
|
|
|
- + controller.getScaleDiv2());
|
|
|
+ (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
|
|
|
+ (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
|
|
|
} else {
|
|
|
g2.drawString("not connected",
|
|
|
- (con.getA().getPosition().x + con.getB().getPosition().x) / 2
|
|
|
- + controller.getScaleDiv2(),
|
|
|
- (con.getA().getPosition().y + con.getB().getPosition().y) / 2
|
|
|
- + controller.getScaleDiv2());
|
|
|
+ (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
|
|
|
+ (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -570,14 +567,13 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
} else if (edgeHighlight != null) {
|
|
|
g2.setColor(Color.BLUE);
|
|
|
if (edgeHighlight.getFlow() <= edgeHighlight.getCapacity()) {
|
|
|
- g2.setStroke(new BasicStroke(Math.min((edgeHighlight.getFlow() / edgeHighlight.getCapacity() * 3)+1, 4)));
|
|
|
+ g2.setStroke(
|
|
|
+ new BasicStroke(Math.min((edgeHighlight.getFlow() / edgeHighlight.getCapacity() * 3) + 1, 4)));
|
|
|
} else {
|
|
|
g2.setStroke(new BasicStroke(2));
|
|
|
}
|
|
|
- g2.drawLine(edgeHighlight.getA().getPosition().x + controller.getScaleDiv2(),
|
|
|
- edgeHighlight.getA().getPosition().y + controller.getScaleDiv2(),
|
|
|
- edgeHighlight.getB().getPosition().x + controller.getScaleDiv2(),
|
|
|
- edgeHighlight.getB().getPosition().y + controller.getScaleDiv2());
|
|
|
+ g2.drawLine(edgeHighlight.getA().getPosition().x, edgeHighlight.getA().getPosition().y,
|
|
|
+ edgeHighlight.getB().getPosition().x, edgeHighlight.getB().getPosition().y);
|
|
|
|
|
|
if (edgeHighlight.getCapacity() == -1) {
|
|
|
maxCap = Character.toString('\u221e');
|
|
@@ -588,10 +584,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
}
|
|
|
if (showedInformation[0]) {
|
|
|
g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
|
|
|
- (edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2
|
|
|
- + controller.getScaleDiv2(),
|
|
|
- (edgeHighlight.getA().getPosition().y + edgeHighlight.getB().getPosition().y) / 2
|
|
|
- + controller.getScaleDiv2());
|
|
|
+ (edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2,
|
|
|
+ (edgeHighlight.getA().getPosition().y + edgeHighlight.getB().getPosition().y) / 2);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -601,8 +595,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
if (showedInformation[3]) {
|
|
|
g2.setColor(cps.getBorderColor());
|
|
|
if (g2.getColor() != Color.WHITE) {
|
|
|
- g2.fillRect((int) (cps.getPosition().x - scalediv20 - 3),
|
|
|
- (int) (cps.getPosition().y - scalediv20 - 3),
|
|
|
+ g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20 - 3),
|
|
|
+ (int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20 - 3),
|
|
|
(int) (controller.getScale() + ((scalediv20 + 3) * 2)),
|
|
|
(int) (controller.getScale() + ((scalediv20 + 3) * 2)));
|
|
|
}
|
|
@@ -624,25 +618,29 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
|
|
|
|| model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
|
|
|
g2.setColor(Color.BLUE);
|
|
|
- g2.fillRect((int) (cps.getPosition().x - scalediv20), (int) (cps.getPosition().y - scalediv20),
|
|
|
+ g2.fillRect((int) (cps.getPosition().x - model.getScaleDiv2() - scalediv20),
|
|
|
+ (int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20),
|
|
|
(int) (controller.getScale() + (scalediv20 * 2)),
|
|
|
(int) (controller.getScale() + (scalediv20 * 2)));
|
|
|
if (showedInformation[1] && cps instanceof HolonObject) {
|
|
|
g2.setColor(Color.BLACK);
|
|
|
float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
|
|
|
- g2.drawString(Float.toString(totalEnergy), cps.getPosition().x, cps.getPosition().y - 10);
|
|
|
+ g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - model.getScaleDiv2(),
|
|
|
+ cps.getPosition().y - model.getScaleDiv2() - 10);
|
|
|
}
|
|
|
} else if (cps instanceof HolonObject) {
|
|
|
g2.setColor(((HolonObject) cps).getColor());
|
|
|
|
|
|
- g2.fillRect((int) (cps.getPosition().x - scalediv20), (int) (cps.getPosition().y - scalediv20),
|
|
|
+ g2.fillRect((int) (cps.getPosition().x - model.getScaleDiv2() - scalediv20),
|
|
|
+ (int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20),
|
|
|
(int) (controller.getScale() + (scalediv20 * 2)),
|
|
|
(int) (controller.getScale() + (scalediv20 * 2)));
|
|
|
|
|
|
if (showedInformation[1]) {
|
|
|
g2.setColor(Color.BLACK);
|
|
|
float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
|
|
|
- g2.drawString(Float.toString(totalEnergy), cps.getPosition().x, cps.getPosition().y - 10);
|
|
|
+ g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - model.getScaleDiv2(),
|
|
|
+ cps.getPosition().y - model.getScaleDiv2() - 10);
|
|
|
}
|
|
|
}
|
|
|
// draw image
|
|
@@ -653,8 +651,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
|
|
|
}
|
|
|
}
|
|
|
- g2.drawImage(img, cps.getPosition().x, cps.getPosition().y, controller.getScale(), controller.getScale(),
|
|
|
- null);
|
|
|
+ g2.drawImage(img, cps.getPosition().x - model.getScaleDiv2(), cps.getPosition().y - model.getScaleDiv2(),
|
|
|
+ controller.getScale(), controller.getScale(), null);
|
|
|
}
|
|
|
|
|
|
// Objects connected to upperNode
|
|
@@ -677,8 +675,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
}
|
|
|
if (obj != null) {
|
|
|
g2.setColor(Color.BLUE);
|
|
|
- g2.drawLine(obj.getPosition().x + model.getScaleDiv2(),
|
|
|
- obj.getPosition().y + model.getScaleDiv2(), (borderPos >> 1),
|
|
|
+ g2.drawLine(obj.getPosition().x, obj.getPosition().y, (borderPos >> 1),
|
|
|
(int) (scalediv20 + 5 + (model.getScale() + scalediv20 + 10) * count)
|
|
|
+ model.getScaleDiv2());
|
|
|
}
|
|
@@ -817,8 +814,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
|
|
|
if (e.getX() > borderPos) {
|
|
|
for (AbstractCpsObject cps : upperNode.getNodes()) {
|
|
|
- cx = cps.getPosition().x;
|
|
|
- cy = cps.getPosition().y;
|
|
|
+ cx = cps.getPosition().x - model.getScaleDiv2();
|
|
|
+ cy = cps.getPosition().y - model.getScaleDiv2();
|
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
|
tempCps = cps;
|
|
|
controller.addTextToConsole("Selected: ", Color.BLACK, 12, false, false, false);
|
|
@@ -834,12 +831,6 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
- * else if (e.getButton() != MouseEvent.BUTTON3) {
|
|
|
- * controller.setSelectedObjectID(tempCps.getID());
|
|
|
- * model.getSelectedCpsObjects().clear();
|
|
|
- * controller.addSelectedObject(tempCps); }
|
|
|
- */
|
|
|
// If drawing an Edge (CTRL down)
|
|
|
if (tempCps.getClass() == HolonObject.class) {
|
|
|
HolonObject tempObj = ((HolonObject) tempCps);
|
|
@@ -919,6 +910,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
|
|
|
@Override
|
|
|
public void mouseReleased(MouseEvent e) {
|
|
|
+ x = e.getX();
|
|
|
+ y = e.getY();
|
|
|
dragging = false;
|
|
|
if (model.getSelectedCpsObjects().size() > 1) {
|
|
|
model.getTableHolonElement().setModel(model.getMultiTable());
|
|
@@ -953,19 +946,15 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
itemDelete.setEnabled(true);
|
|
|
itemCut.setEnabled(true);
|
|
|
itemCopy.setEnabled(true);
|
|
|
- if (tempCps != null)
|
|
|
+ if (tempCps != null) {
|
|
|
itemGroup.setEnabled(true);
|
|
|
+ itemTrack.setEnabled(true);
|
|
|
+ itemUntrack.setEnabled(true);
|
|
|
+ }
|
|
|
if (tempCps instanceof CpsUpperNode)
|
|
|
itemUngroup.setEnabled(true);
|
|
|
else
|
|
|
itemUngroup.setEnabled(false);
|
|
|
- if (!(tempCps instanceof HolonSwitch)) {
|
|
|
- itemTrack.setEnabled(true);
|
|
|
- itemUntrack.setEnabled(true);
|
|
|
- } else {
|
|
|
- itemTrack.setEnabled(false);
|
|
|
- itemUntrack.setEnabled(false);
|
|
|
- }
|
|
|
if (model.getSelectedCpsObjects().size() == 0) {
|
|
|
controller.addSelectedObject(tempCps);
|
|
|
}
|
|
@@ -1016,26 +1005,24 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
}
|
|
|
if (dragging) {
|
|
|
try {
|
|
|
+ // tempCps in the upperNode? else its a connected Object from
|
|
|
+ // outside
|
|
|
if (upperNode.getNodes().contains(tempCps)) {
|
|
|
dragged = true;
|
|
|
float xDist, yDist; // Distance
|
|
|
|
|
|
- x = e.getX() - controller.getScaleDiv2();
|
|
|
- y = e.getY() - controller.getScaleDiv2();
|
|
|
-
|
|
|
- // tempCps in the upperNode? if not its a connected Object
|
|
|
- // from
|
|
|
- // outside
|
|
|
+ x = e.getX();
|
|
|
+ y = e.getY();
|
|
|
|
|
|
// Make sure its in bounds
|
|
|
if (e.getX() < controller.getScaleDiv2() + borderPos + 5)
|
|
|
- x = borderPos + 5;
|
|
|
+ x = controller.getScaleDiv2() + borderPos + 5;
|
|
|
else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
|
|
|
- x = this.getWidth() - controller.getScale();
|
|
|
+ x = this.getWidth() - controller.getScaleDiv2();
|
|
|
if (e.getY() < controller.getScaleDiv2())
|
|
|
- y = 0;
|
|
|
+ y = controller.getScaleDiv2();
|
|
|
else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
|
|
|
- y = this.getHeight() - controller.getScale();
|
|
|
+ y = this.getHeight() - controller.getScaleDiv2();
|
|
|
|
|
|
// Distance
|
|
|
xDist = x - tempCps.getPosition().x;
|
|
@@ -1046,8 +1033,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
// TipText Position and name
|
|
|
toolTip = true;
|
|
|
toolTipText = tempCps.getName() + ", " + tempCps.getId();
|
|
|
- toolTipPos.x = tempCps.getPosition().x;
|
|
|
- toolTipPos.y = tempCps.getPosition().y + model.getScale();
|
|
|
+ toolTipPos.x = tempCps.getPosition().x - model.getScaleDiv2();
|
|
|
+ toolTipPos.y = tempCps.getPosition().y + model.getScaleDiv2();
|
|
|
|
|
|
// All Selected Objects
|
|
|
for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
|
|
@@ -1056,14 +1043,14 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
y = (int) (cps.getPosition().y + yDist);
|
|
|
|
|
|
// Make sure its in bounds
|
|
|
- if (x < borderPos + 5)
|
|
|
- x = borderPos + 5;
|
|
|
- else if (x > this.getWidth() - controller.getScale())
|
|
|
- x = this.getWidth() - controller.getScale();
|
|
|
- if (y <= 0)
|
|
|
- y = 0;
|
|
|
- else if (y > this.getHeight() - controller.getScale())
|
|
|
- y = this.getHeight() - controller.getScale();
|
|
|
+ if (x < borderPos + 5 + controller.getScaleDiv2())
|
|
|
+ x = controller.getScaleDiv2() + borderPos + 5;
|
|
|
+ else if (x > this.getWidth() - controller.getScaleDiv2())
|
|
|
+ x = this.getWidth() - controller.getScaleDiv2();
|
|
|
+ if (y <= controller.getScaleDiv2())
|
|
|
+ y = controller.getScaleDiv2();
|
|
|
+ else if (y > this.getHeight() - controller.getScaleDiv2())
|
|
|
+ y = this.getHeight() - controller.getScaleDiv2();
|
|
|
|
|
|
cps.setPosition(x, y);
|
|
|
}
|
|
@@ -1090,8 +1077,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
y2 = sy;
|
|
|
}
|
|
|
if (x1 <= cps.getPosition().x + model.getScaleDiv2() && y1 <= cps.getPosition().y + model.getScaleDiv2()
|
|
|
- && x2 >= cps.getPosition().x + model.getScaleDiv2()
|
|
|
- && y2 >= cps.getPosition().y + model.getScaleDiv2()) {
|
|
|
+ && x2 >= cps.getPosition().x && y2 >= cps.getPosition().y) {
|
|
|
tempSelected.add(cps);
|
|
|
|
|
|
}
|
|
@@ -1134,21 +1120,18 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
public void mouseMoved(MouseEvent e) {
|
|
|
x = e.getX();
|
|
|
y = e.getY();
|
|
|
- // Everytghing for the tooltip :)
|
|
|
|
|
|
+ // Everytghing for the tooltip :)
|
|
|
boolean on = false;
|
|
|
for (AbstractCpsObject cps : upperNode.getNodes()) {
|
|
|
|
|
|
- cx = cps.getPosition().x;
|
|
|
- cy = cps.getPosition().y;
|
|
|
+ cx = cps.getPosition().x - controller.getScaleDiv2();
|
|
|
+ cy = cps.getPosition().y - controller.getScaleDiv2();
|
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
|
-
|
|
|
on = true;
|
|
|
- toolTipPos.x = cps.getPosition().x;
|
|
|
- toolTipPos.y = cps.getPosition().y + model.getScale();
|
|
|
+ toolTipPos.x = cps.getPosition().x - model.getScaleDiv2();
|
|
|
+ toolTipPos.y = cps.getPosition().y + model.getScaleDiv2();
|
|
|
toolTipText = cps.getName() + ", " + cps.getId();
|
|
|
-
|
|
|
- on = true;
|
|
|
}
|
|
|
}
|
|
|
int count = 0;
|
|
@@ -1194,14 +1177,13 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
// to
|
|
|
// the
|
|
|
// outside
|
|
|
- boolean found = false;
|
|
|
+ boolean found = false; // dont search for outside connetion if inside
|
|
|
+ // connection is found
|
|
|
CpsEdge e = null;
|
|
|
- AbstractCpsObject tempCPS = null;
|
|
|
-
|
|
|
for (AbstractCpsObject cps : upperNode.getNodes()) {
|
|
|
|
|
|
- cx = cps.getPosition().x;
|
|
|
- cy = cps.getPosition().y;
|
|
|
+ cx = cps.getPosition().x - controller.getScaleDiv2();
|
|
|
+ cy = cps.getPosition().y - controller.getScaleDiv2();
|
|
|
|
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy
|
|
|
&& cps != tempCps) {
|
|
@@ -1226,7 +1208,6 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
deleteNode = true;
|
|
|
}
|
|
|
if (e.getB().getClass() == CpsNode.class && e.getB().getConnections().isEmpty()) {
|
|
|
- tempCPS = e.getB();
|
|
|
deleteNode = true;
|
|
|
}
|
|
|
}
|
|
@@ -1276,7 +1257,6 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
deleteNode = true;
|
|
|
}
|
|
|
if (e.getB().getClass() == CpsNode.class && e.getB().getConnections().isEmpty()) {
|
|
|
- tempCPS = e.getB();
|
|
|
deleteNode = true;
|
|
|
}
|
|
|
}
|
|
@@ -1304,7 +1284,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
|
|
|
CpsNode n = new CpsNode("Node");
|
|
|
|
|
|
- n.setPosition(x - model.getScaleDiv2(), y - model.getScaleDiv2());
|
|
|
+ n.setPosition(x, y);
|
|
|
controller.addObjUpperNode(n, upperNode);
|
|
|
|
|
|
AbstractCpsObject r, k;
|
|
@@ -1333,7 +1313,7 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
if (node && x > borderPos) {
|
|
|
CpsNode n = new CpsNode("Node");
|
|
|
|
|
|
- n.setPosition(x - model.getScaleDiv2(), y - model.getScaleDiv2());
|
|
|
+ n.setPosition(x, y);
|
|
|
controller.addObjUpperNode(n, upperNode);
|
|
|
|
|
|
e = new CpsEdge(n, tempCps, model.getMaxCapacity());
|
|
@@ -1363,6 +1343,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
|
|
|
* @return CpsEdge the Mouse is on, null if the mouse is not on an Edge
|
|
|
*/
|
|
|
public CpsEdge mousePositionOnEdge(int x, int y) {
|
|
|
+ x += controller.getScaleDiv2();
|
|
|
+ y += controller.getScaleDiv2();
|
|
|
int lx, ly, hx, hy;
|
|
|
for (CpsEdge p : upperNode.getNodeEdges()) {
|
|
|
Line2D l = new Line2D.Float(p.getA().getPosition().x, p.getA().getPosition().y, p.getB().getPosition().x,
|