|
@@ -19,6 +19,8 @@ import java.awt.event.MouseMotionListener;
|
|
|
import java.awt.geom.Line2D;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.LinkedList;
|
|
|
+import java.util.Timer;
|
|
|
+import java.util.TimerTask;
|
|
|
|
|
|
import javax.swing.AbstractButton;
|
|
|
import javax.swing.ImageIcon;
|
|
@@ -32,6 +34,8 @@ import javax.swing.JToolTip;
|
|
|
import classes.CpsObject;
|
|
|
import classes.HolonElement;
|
|
|
import classes.HolonObject;
|
|
|
+import classes.HolonSwitch;
|
|
|
+import classes.HolonTransformer;
|
|
|
import ui.controller.Control;
|
|
|
import ui.model.*;
|
|
|
|
|
@@ -46,9 +50,9 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
private int cx;
|
|
|
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 Rectangle selectRect = new Rectangle();
|
|
|
|
|
@@ -144,7 +148,17 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
|
|
|
@Override
|
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
+ 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
|
|
@@ -232,7 +246,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
tempCps.getPosition().y - (controller.getScale() / 20));
|
|
|
|
|
|
objectTT.setTipText(tempCps.getName());
|
|
|
- objectTT.setLocation(tempCps.getPosition().x, tempCps.getPosition().y);
|
|
|
+ objectTT.setLocation(tempCps.getPosition().x, tempCps.getPosition().y+controller.getScale());
|
|
|
repaint();
|
|
|
} catch (Exception e2) {
|
|
|
// TODO: handle exception
|
|
@@ -253,7 +267,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);
|
|
|
+ objectTT.setLocation(cx, cy+controller.getScale());
|
|
|
on = true;
|
|
|
}
|
|
|
}
|
|
@@ -301,4 +315,21 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|