|
@@ -19,6 +19,8 @@ import java.awt.event.MouseMotionListener;
|
|
import java.awt.geom.Line2D;
|
|
import java.awt.geom.Line2D;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.LinkedList;
|
|
import java.util.LinkedList;
|
|
|
|
+import java.util.Timer;
|
|
|
|
+import java.util.TimerTask;
|
|
|
|
|
|
import javax.swing.AbstractButton;
|
|
import javax.swing.AbstractButton;
|
|
import javax.swing.ImageIcon;
|
|
import javax.swing.ImageIcon;
|
|
@@ -32,6 +34,8 @@ import javax.swing.JToolTip;
|
|
import classes.CpsObject;
|
|
import classes.CpsObject;
|
|
import classes.HolonElement;
|
|
import classes.HolonElement;
|
|
import classes.HolonObject;
|
|
import classes.HolonObject;
|
|
|
|
+import classes.HolonSwitch;
|
|
|
|
+import classes.HolonTransformer;
|
|
import ui.controller.Control;
|
|
import ui.controller.Control;
|
|
import ui.model.*;
|
|
import ui.model.*;
|
|
|
|
|
|
@@ -46,9 +50,9 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
private int cx;
|
|
private int cx;
|
|
private int cy;
|
|
private int cy;
|
|
|
|
|
|
- boolean dragging = false;
|
|
|
|
- boolean drawEdge = false;
|
|
|
|
- boolean dropDelete = false;
|
|
|
|
|
|
+ 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 CpsObject tempCps = null;
|
|
private Rectangle selectRect = new Rectangle();
|
|
private Rectangle selectRect = new Rectangle();
|
|
|
|
|
|
@@ -66,6 +70,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
itemDelete.addActionListener(new ActionListener() {
|
|
itemDelete.addActionListener(new ActionListener() {
|
|
@Override
|
|
@Override
|
|
public void actionPerformed(ActionEvent e) {
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
+ //Remove the selected Object object
|
|
model.getObjectsOnCanvas().remove(tempCps);
|
|
model.getObjectsOnCanvas().remove(tempCps);
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
cps.getConnectedTo().remove(tempCps);
|
|
cps.getConnectedTo().remove(tempCps);
|
|
@@ -88,6 +93,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
*/
|
|
*/
|
|
public void paintComponent(Graphics g) {
|
|
public void paintComponent(Graphics g) {
|
|
super.paintComponent(g);
|
|
super.paintComponent(g);
|
|
|
|
+ //Rendering
|
|
g2 = (Graphics2D) g;
|
|
g2 = (Graphics2D) g;
|
|
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
g2.setRenderingHints(rh);
|
|
g2.setRenderingHints(rh);
|
|
@@ -102,7 +108,6 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
// drawEdges
|
|
// drawEdges
|
|
g2.setColor(Color.BLACK);
|
|
g2.setColor(Color.BLACK);
|
|
if (drawEdge)
|
|
if (drawEdge)
|
|
-
|
|
|
|
g2.drawLine(tempCps.getPosition().x + controller.getScaleDiv2(),
|
|
g2.drawLine(tempCps.getPosition().x + controller.getScaleDiv2(),
|
|
tempCps.getPosition().y + controller.getScaleDiv2(), x, y);
|
|
tempCps.getPosition().y + controller.getScaleDiv2(), x, y);
|
|
|
|
|
|
@@ -144,7 +149,18 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseClicked(MouseEvent e) {
|
|
public void mouseClicked(MouseEvent e) {
|
|
- // TODO Auto-generated method stub
|
|
|
|
|
|
+ //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) {
|
|
|
|
+ tempCps.setImage("/Images/switch-off.png");
|
|
|
|
+ System.out.println("off");
|
|
|
|
+ } else {
|
|
|
|
+ tempCps.setImage("/Images/switch-on.png");
|
|
|
|
+ System.out.println("on");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ repaint();
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -168,17 +184,15 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
tempCps = null;
|
|
tempCps = null;
|
|
// Object Selection
|
|
// Object Selection
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
-
|
|
|
|
cx = cps.getPosition().x;
|
|
cx = cps.getPosition().x;
|
|
cy = cps.getPosition().y;
|
|
cy = cps.getPosition().y;
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
-
|
|
|
|
tempCps = cps;
|
|
tempCps = cps;
|
|
|
|
+ //If drawing an Edge (CTRL down)
|
|
if (e.isControlDown())
|
|
if (e.isControlDown())
|
|
- drawEdge = true;
|
|
|
|
|
|
+ drawEdge = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
// Object Selection Highlighting (selectRect)
|
|
// Object Selection Highlighting (selectRect)
|
|
objectSelectionHighlighting();
|
|
objectSelectionHighlighting();
|
|
|
|
|
|
@@ -191,19 +205,16 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
drawEdge = false;
|
|
drawEdge = false;
|
|
drawDeleteEdge();
|
|
drawDeleteEdge();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ //if Dragged reposition the Object
|
|
if (dragging) {
|
|
if (dragging) {
|
|
x = e.getX();
|
|
x = e.getX();
|
|
y = e.getY();
|
|
y = e.getY();
|
|
-
|
|
|
|
dragging = false;
|
|
dragging = false;
|
|
-
|
|
|
|
tempCps.setPosition(e.getX() - controller.getScaleDiv2(), e.getY() - controller.getScaleDiv2());
|
|
tempCps.setPosition(e.getX() - controller.getScaleDiv2(), e.getY() - controller.getScaleDiv2());
|
|
-
|
|
|
|
- tempCps = null;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- // Rechtsklick Liste
|
|
|
|
|
|
+ // Rightclick List
|
|
if (e.getButton() == e.BUTTON3) {
|
|
if (e.getButton() == e.BUTTON3) {
|
|
if (e.getButton() == e.BUTTON3 && tempCps != null) {
|
|
if (e.getButton() == e.BUTTON3 && tempCps != null) {
|
|
itemDelete.setEnabled(true);
|
|
itemDelete.setEnabled(true);
|
|
@@ -218,24 +229,24 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseDragged(MouseEvent e) {
|
|
public void mouseDragged(MouseEvent e) {
|
|
- // TODO Auto-generated method stub
|
|
|
|
|
|
+ //If Edge is drawn
|
|
if (drawEdge) {
|
|
if (drawEdge) {
|
|
x = e.getX();
|
|
x = e.getX();
|
|
y = e.getY();
|
|
y = e.getY();
|
|
repaint();
|
|
repaint();
|
|
} else {
|
|
} else {
|
|
try {
|
|
try {
|
|
-
|
|
|
|
|
|
+ //Drag Position
|
|
tempCps.setPosition(e.getX() - controller.getScaleDiv2(), e.getY() - controller.getScaleDiv2());
|
|
tempCps.setPosition(e.getX() - controller.getScaleDiv2(), e.getY() - controller.getScaleDiv2());
|
|
dragging = true;
|
|
dragging = true;
|
|
|
|
+ //Highlighting Position
|
|
selectRect.setLocation(tempCps.getPosition().x - (controller.getScale() / 20),
|
|
selectRect.setLocation(tempCps.getPosition().x - (controller.getScale() / 20),
|
|
- tempCps.getPosition().y - (controller.getScale() / 20));
|
|
|
|
-
|
|
|
|
|
|
+ tempCps.getPosition().y - (controller.getScale() / 20));
|
|
|
|
+ //TipText Position and name
|
|
objectTT.setTipText(tempCps.getName());
|
|
objectTT.setTipText(tempCps.getName());
|
|
- objectTT.setLocation(tempCps.getPosition().x, tempCps.getPosition().y);
|
|
|
|
|
|
+ objectTT.setLocation(tempCps.getPosition().x, tempCps.getPosition().y+controller.getScale());
|
|
repaint();
|
|
repaint();
|
|
} catch (Exception e2) {
|
|
} catch (Exception e2) {
|
|
- // TODO: handle exception
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -244,7 +255,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
public void mouseMoved(MouseEvent e) {
|
|
public void mouseMoved(MouseEvent e) {
|
|
x = e.getX();
|
|
x = e.getX();
|
|
y = e.getY();
|
|
y = e.getY();
|
|
-
|
|
|
|
|
|
+ //Everytghin for the tooltip :)
|
|
boolean on = false;
|
|
boolean on = false;
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
|
|
|
|
@@ -253,7 +264,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
|
|
|
|
objectTT.setTipText(cps.getName());
|
|
objectTT.setTipText(cps.getName());
|
|
- objectTT.setLocation(cx, cy);
|
|
|
|
|
|
+ objectTT.setLocation(cx, cy+controller.getScale());
|
|
on = true;
|
|
on = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -268,7 +279,6 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
*/
|
|
*/
|
|
private void objectSelectionHighlighting() {
|
|
private void objectSelectionHighlighting() {
|
|
if (tempCps != null) {
|
|
if (tempCps != null) {
|
|
-
|
|
|
|
selectRect.setBounds(tempCps.getPosition().x - (controller.getScale() / 20),
|
|
selectRect.setBounds(tempCps.getPosition().x - (controller.getScale() / 20),
|
|
tempCps.getPosition().y - (controller.getScale() / 20),
|
|
tempCps.getPosition().y - (controller.getScale() / 20),
|
|
controller.getScale() + controller.getScale() / 10,
|
|
controller.getScale() + controller.getScale() / 10,
|
|
@@ -286,7 +296,6 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
*/
|
|
*/
|
|
private void drawDeleteEdge() {
|
|
private void drawDeleteEdge() {
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
-
|
|
|
|
cx = cps.getPosition().x;
|
|
cx = cps.getPosition().x;
|
|
cy = cps.getPosition().y;
|
|
cy = cps.getPosition().y;
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
|
|
@@ -301,4 +310,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(){
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|