|
@@ -70,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);
|
|
@@ -92,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);
|
|
@@ -106,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);
|
|
|
|
|
|
@@ -148,6 +149,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseClicked(MouseEvent e) {
|
|
public void mouseClicked(MouseEvent e) {
|
|
|
|
+ //If double clicked on a Switch change the Image to on/off
|
|
if (doubleClick() && tempCps != null && tempCps.getClass() == HolonSwitch.class) {
|
|
if (doubleClick() && tempCps != null && tempCps.getClass() == HolonSwitch.class) {
|
|
System.out.println("trans double click");
|
|
System.out.println("trans double click");
|
|
if (tempCps.getImage().compareTo("/Images/switch-on.png") == 0) {
|
|
if (tempCps.getImage().compareTo("/Images/switch-on.png") == 0) {
|
|
@@ -182,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();
|
|
|
|
|
|
@@ -205,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);
|
|
@@ -232,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+controller.getScale());
|
|
objectTT.setLocation(tempCps.getPosition().x, tempCps.getPosition().y+controller.getScale());
|
|
repaint();
|
|
repaint();
|
|
} catch (Exception e2) {
|
|
} catch (Exception e2) {
|
|
- // TODO: handle exception
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -258,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()) {
|
|
|
|
|
|
@@ -282,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,
|
|
@@ -300,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) {
|
|
@@ -316,6 +311,11 @@ 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) {
|
|
if (click) {
|
|
click = false;
|
|
click = false;
|