|
@@ -35,10 +35,7 @@ import classes.CpsObject;
|
|
|
import classes.HolonElement;
|
|
|
import classes.HolonObject;
|
|
|
import classes.HolonSwitch;
|
|
|
-<<<<<<< HEAD
|
|
|
-=======
|
|
|
import classes.HolonTransformer;
|
|
|
->>>>>>> b21529a76393a3f2ba0825f9a04ab5b2a8e80a33
|
|
|
import ui.controller.Control;
|
|
|
import ui.model.*;
|
|
|
|
|
@@ -54,9 +51,9 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
private int cy;
|
|
|
ArrayList<HolonElement> dataSelected = new ArrayList<HolonElement>();
|
|
|
|
|
|
- private boolean dragging = false; //for dragging
|
|
|
- private boolean drawEdge = false; //for drawing edges
|
|
|
- private boolean click = false; // for double click
|
|
|
+ private boolean dragging = false; // for dragging
|
|
|
+ private boolean drawEdge = false; // for drawing edges
|
|
|
+ private boolean click = false; // for double click
|
|
|
private CpsObject tempCps = null;
|
|
|
private Rectangle selectRect = new Rectangle();
|
|
|
|
|
@@ -74,7 +71,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
itemDelete.addActionListener(new ActionListener() {
|
|
|
@Override
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
- //Remove the selected Object object
|
|
|
+ // Remove the selected Object object
|
|
|
model.getObjectsOnCanvas().remove(tempCps);
|
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
cps.getConnectedTo().remove(tempCps);
|
|
@@ -97,7 +94,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
*/
|
|
|
public void paintComponent(Graphics g) {
|
|
|
super.paintComponent(g);
|
|
|
- //Rendering
|
|
|
+ // Rendering
|
|
|
g2 = (Graphics2D) g;
|
|
|
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
g2.setRenderingHints(rh);
|
|
@@ -113,28 +110,16 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
// drawEdges
|
|
|
g2.setColor(Color.BLACK);
|
|
|
if (drawEdge)
|
|
|
-<<<<<<< HEAD
|
|
|
- g2.drawLine(tempCps.getPos().x + controller.getScaleDiv2(), tempCps.getPos().y + controller.getScaleDiv2(),
|
|
|
- x, y);
|
|
|
-=======
|
|
|
g2.drawLine(tempCps.getPosition().x + controller.getScaleDiv2(),
|
|
|
tempCps.getPosition().y + controller.getScaleDiv2(), x, y);
|
|
|
->>>>>>> b21529a76393a3f2ba0825f9a04ab5b2a8e80a33
|
|
|
|
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
for (CpsObject con : cps.getConnectedTo()) {
|
|
|
if (con.getID() != model.getSelectedObjectID() && cps.getID() != model.getSelectedObjectID())
|
|
|
-<<<<<<< HEAD
|
|
|
- g2.drawLine(cps.getPos().x + controller.getScaleDiv2(), cps.getPos().y + controller.getScaleDiv2(),
|
|
|
- con.getPos().x + controller.getScaleDiv2(), con.getPos().y + controller.getScaleDiv2());
|
|
|
-=======
|
|
|
-
|
|
|
g2.drawLine(cps.getPosition().x + controller.getScaleDiv2(),
|
|
|
cps.getPosition().y + controller.getScaleDiv2(),
|
|
|
con.getPosition().x + controller.getScaleDiv2(),
|
|
|
con.getPosition().y + controller.getScaleDiv2());
|
|
|
-
|
|
|
->>>>>>> b21529a76393a3f2ba0825f9a04ab5b2a8e80a33
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -143,17 +128,10 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
for (CpsObject con : cps.getConnectedTo()) {
|
|
|
if (con.getID() == model.getSelectedObjectID())
|
|
|
-<<<<<<< HEAD
|
|
|
- g2.drawLine(cps.getPos().x + controller.getScaleDiv2(), cps.getPos().y + controller.getScaleDiv2(),
|
|
|
- con.getPos().x + controller.getScaleDiv2(), con.getPos().y + controller.getScaleDiv2());
|
|
|
-=======
|
|
|
-
|
|
|
g2.drawLine(cps.getPosition().x + controller.getScaleDiv2(),
|
|
|
cps.getPosition().y + controller.getScaleDiv2(),
|
|
|
con.getPosition().x + controller.getScaleDiv2(),
|
|
|
con.getPosition().y + controller.getScaleDiv2());
|
|
|
-
|
|
|
->>>>>>> b21529a76393a3f2ba0825f9a04ab5b2a8e80a33
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -169,7 +147,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
|
|
|
@Override
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
- //If double clicked on a Switch change the Image to on/off
|
|
|
+ // If double clicked on a Switch change the Image to on/off
|
|
|
if (doubleClick() && tempCps != null && tempCps.getClass() == HolonSwitch.class) {
|
|
|
System.out.println("trans double click");
|
|
|
if (tempCps.getImage().compareTo("/Images/switch-on.png") == 0) {
|
|
@@ -208,19 +186,18 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
cy = cps.getPosition().y;
|
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
|
tempCps = cps;
|
|
|
- //If drawing an Edge (CTRL down)
|
|
|
+ // If drawing an Edge (CTRL down)
|
|
|
if (e.isControlDown())
|
|
|
-<<<<<<< HEAD
|
|
|
+
|
|
|
drawEdge = true;
|
|
|
if (tempCps.getClass() == HolonObject.class) {
|
|
|
HolonObject tempObj = ((HolonObject) tempCps);
|
|
|
dataSelected = tempObj.getElements();
|
|
|
} else {
|
|
|
- dataSelected = null;
|
|
|
+ dataSelected = new ArrayList<>();
|
|
|
}
|
|
|
-=======
|
|
|
- drawEdge = true;
|
|
|
->>>>>>> b21529a76393a3f2ba0825f9a04ab5b2a8e80a33
|
|
|
+
|
|
|
+ drawEdge = true;
|
|
|
}
|
|
|
}
|
|
|
// Object Selection Highlighting (selectRect)
|
|
@@ -235,8 +212,8 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
drawEdge = false;
|
|
|
drawDeleteEdge();
|
|
|
}
|
|
|
-
|
|
|
- //if Dragged reposition the Object
|
|
|
+
|
|
|
+ // if Dragged reposition the Object
|
|
|
if (dragging) {
|
|
|
x = e.getX();
|
|
|
y = e.getY();
|
|
@@ -259,22 +236,22 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
|
|
|
@Override
|
|
|
public void mouseDragged(MouseEvent e) {
|
|
|
- //If Edge is drawn
|
|
|
+ // If Edge is drawn
|
|
|
if (drawEdge) {
|
|
|
x = e.getX();
|
|
|
y = e.getY();
|
|
|
repaint();
|
|
|
} else {
|
|
|
try {
|
|
|
- //Drag Position
|
|
|
+ // Drag Position
|
|
|
tempCps.setPosition(e.getX() - controller.getScaleDiv2(), e.getY() - controller.getScaleDiv2());
|
|
|
dragging = true;
|
|
|
- //Highlighting Position
|
|
|
+ // Highlighting Position
|
|
|
selectRect.setLocation(tempCps.getPosition().x - (controller.getScale() / 20),
|
|
|
- tempCps.getPosition().y - (controller.getScale() / 20));
|
|
|
- //TipText Position and name
|
|
|
+ tempCps.getPosition().y - (controller.getScale() / 20));
|
|
|
+ // TipText Position and name
|
|
|
objectTT.setTipText(tempCps.getName());
|
|
|
- objectTT.setLocation(tempCps.getPosition().x, tempCps.getPosition().y+controller.getScale());
|
|
|
+ objectTT.setLocation(tempCps.getPosition().x, tempCps.getPosition().y + controller.getScale());
|
|
|
repaint();
|
|
|
} catch (Exception e2) {
|
|
|
}
|
|
@@ -285,7 +262,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
public void mouseMoved(MouseEvent e) {
|
|
|
x = e.getX();
|
|
|
y = e.getY();
|
|
|
- //Everytghin for the tooltip :)
|
|
|
+ // Everytghin for the tooltip :)
|
|
|
boolean on = false;
|
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
|
|
@@ -294,7 +271,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
|
|
|
|
objectTT.setTipText(cps.getName());
|
|
|
- objectTT.setLocation(cx, cy+controller.getScale());
|
|
|
+ objectTT.setLocation(cx, cy + controller.getScale());
|
|
|
on = true;
|
|
|
}
|
|
|
}
|
|
@@ -340,26 +317,26 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* Checks if a double click was made
|
|
|
*
|
|
|
* @return true if doublecklick, false if not
|
|
|
*/
|
|
|
- private boolean doubleClick(){
|
|
|
+ private boolean doubleClick() {
|
|
|
if (click) {
|
|
|
- click = false;
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- click = true;
|
|
|
- Timer t = new Timer("doubleclickTimer", false);
|
|
|
- t.schedule(new TimerTask() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- click = false;
|
|
|
- }
|
|
|
- }, 500);
|
|
|
- }
|
|
|
+ click = false;
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ click = true;
|
|
|
+ Timer t = new Timer("doubleclickTimer", false);
|
|
|
+ t.schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ click = false;
|
|
|
+ }
|
|
|
+ }, 500);
|
|
|
+ }
|
|
|
return false;
|
|
|
}
|
|
|
}
|