|
@@ -40,13 +40,13 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
private Image img = null; // Contains the image to draw on MyCanvas
|
|
private Image img = null; // Contains the image to draw on MyCanvas
|
|
private int x = 0;
|
|
private int x = 0;
|
|
private int y = 0;
|
|
private int y = 0;
|
|
- //edge Object Start Point
|
|
|
|
|
|
+ // edge Object Start Point
|
|
private Model model;
|
|
private Model model;
|
|
private final Control controller;
|
|
private final Control controller;
|
|
- Graphics2D g2; //For Painting
|
|
|
|
|
|
+ Graphics2D g2; // For Painting
|
|
private int cx;
|
|
private int cx;
|
|
private int cy;
|
|
private int cy;
|
|
-
|
|
|
|
|
|
+
|
|
boolean dragging = false;
|
|
boolean dragging = false;
|
|
boolean drawEdge = false;
|
|
boolean drawEdge = false;
|
|
boolean dropDelete = false;
|
|
boolean dropDelete = false;
|
|
@@ -57,7 +57,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
private JPopupMenu popmenu = new JPopupMenu();
|
|
private JPopupMenu popmenu = new JPopupMenu();
|
|
private JMenuItem itemDelete = new JMenuItem("Delete Object");
|
|
private JMenuItem itemDelete = new JMenuItem("Delete Object");
|
|
private JToolTip objectTT = new JToolTip();
|
|
private JToolTip objectTT = new JToolTip();
|
|
-
|
|
|
|
|
|
+
|
|
public MyCanvas(final Model model, Control control) {
|
|
public MyCanvas(final Model model, Control control) {
|
|
this.add(objectTT);
|
|
this.add(objectTT);
|
|
this.controller = control;
|
|
this.controller = control;
|
|
@@ -85,43 +85,50 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
* Paints all Components on the Canvas
|
|
* Paints all Components on the Canvas
|
|
*
|
|
*
|
|
* @param Graphics
|
|
* @param Graphics
|
|
- *
|
|
|
|
|
|
+ *
|
|
*/
|
|
*/
|
|
public void paintComponent(Graphics g) {
|
|
public void paintComponent(Graphics g) {
|
|
super.paintComponent(g);
|
|
super.paintComponent(g);
|
|
g2 = (Graphics2D) g;
|
|
g2 = (Graphics2D) g;
|
|
- RenderingHints rh = new RenderingHints(
|
|
|
|
- RenderingHints.KEY_ANTIALIASING,
|
|
|
|
- RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
|
- g2.setRenderingHints(rh);
|
|
|
|
-
|
|
|
|
- //Selection
|
|
|
|
- if(selectRect != null){
|
|
|
|
|
|
+ RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
|
+ g2.setRenderingHints(rh);
|
|
|
|
+
|
|
|
|
+ // Selection
|
|
|
|
+ if (selectRect != null) {
|
|
g2.setColor(Color.GREEN);
|
|
g2.setColor(Color.GREEN);
|
|
- g2.fillRect((int)selectRect.getX(), (int)selectRect.getY(), (int)selectRect.getWidth(), (int)selectRect.getHeight());
|
|
|
|
|
|
+ g2.fillRect((int) selectRect.getX(), (int) selectRect.getY(), (int) selectRect.getWidth(),
|
|
|
|
+ (int) selectRect.getHeight());
|
|
}
|
|
}
|
|
-
|
|
|
|
- //drawEdges
|
|
|
|
|
|
+
|
|
|
|
+ // drawEdges
|
|
g2.setColor(Color.BLACK);
|
|
g2.setColor(Color.BLACK);
|
|
- if(drawEdge)g2.drawLine(tempCps.getPos().x+GlobalVariables.SCALE_DIVIDED2, tempCps.getPos().y+GlobalVariables.SCALE_DIVIDED2, x, y);
|
|
|
|
-
|
|
|
|
|
|
+ if (drawEdge)
|
|
|
|
+ g2.drawLine(tempCps.getPos().x + GlobalVariables.SCALE_DIVIDED2,
|
|
|
|
+ tempCps.getPos().y + GlobalVariables.SCALE_DIVIDED2, x, y);
|
|
|
|
+
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
for (CpsObject con : cps.getConnectedTo()) {
|
|
for (CpsObject con : cps.getConnectedTo()) {
|
|
- if(con.getID() != model.getSelectedObjectID() && cps.getID() != model.getSelectedObjectID())
|
|
|
|
- g2.drawLine(cps.getPos().x+GlobalVariables.SCALE_DIVIDED2, cps.getPos().y+GlobalVariables.SCALE_DIVIDED2, con.getPos().x+GlobalVariables.SCALE_DIVIDED2, con.getPos().y+GlobalVariables.SCALE_DIVIDED2);
|
|
|
|
|
|
+ if (con.getID() != model.getSelectedObjectID() && cps.getID() != model.getSelectedObjectID())
|
|
|
|
+ g2.drawLine(cps.getPos().x + GlobalVariables.SCALE_DIVIDED2,
|
|
|
|
+ cps.getPos().y + GlobalVariables.SCALE_DIVIDED2,
|
|
|
|
+ con.getPos().x + GlobalVariables.SCALE_DIVIDED2,
|
|
|
|
+ con.getPos().y + GlobalVariables.SCALE_DIVIDED2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- //Highlighted Edge
|
|
|
|
- g2.setColor(Color.GREEN);
|
|
|
|
|
|
+
|
|
|
|
+ // Highlighted Edge
|
|
|
|
+ g2.setColor(Color.GREEN);
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
for (CpsObject con : cps.getConnectedTo()) {
|
|
for (CpsObject con : cps.getConnectedTo()) {
|
|
- if(con.getID() == model.getSelectedObjectID())
|
|
|
|
- g2.drawLine(cps.getPos().x+GlobalVariables.SCALE_DIVIDED2, cps.getPos().y+GlobalVariables.SCALE_DIVIDED2, con.getPos().x+GlobalVariables.SCALE_DIVIDED2, con.getPos().y+GlobalVariables.SCALE_DIVIDED2);
|
|
|
|
|
|
+ if (con.getID() == model.getSelectedObjectID())
|
|
|
|
+ g2.drawLine(cps.getPos().x + GlobalVariables.SCALE_DIVIDED2,
|
|
|
|
+ cps.getPos().y + GlobalVariables.SCALE_DIVIDED2,
|
|
|
|
+ con.getPos().x + GlobalVariables.SCALE_DIVIDED2,
|
|
|
|
+ con.getPos().y + GlobalVariables.SCALE_DIVIDED2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- //Objects
|
|
|
|
|
|
+
|
|
|
|
+ // Objects
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
|
|
img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
|
|
g2.drawImage(img, cps.getPos().x, cps.getPos().y, GlobalVariables.SCALE, GlobalVariables.SCALE, null);
|
|
g2.drawImage(img, cps.getPos().x, cps.getPos().y, GlobalVariables.SCALE, GlobalVariables.SCALE, null);
|
|
@@ -150,79 +157,81 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
// TODO Auto-generated method stub
|
|
// TODO Auto-generated method stub
|
|
x = e.getX();
|
|
x = e.getX();
|
|
y = e.getY();
|
|
y = e.getY();
|
|
-
|
|
|
|
|
|
+
|
|
tempCps = null;
|
|
tempCps = null;
|
|
- //Object Selection
|
|
|
|
|
|
+ // Object Selection
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
cx = cps.getPos().x;
|
|
cx = cps.getPos().x;
|
|
cy = cps.getPos().y;
|
|
cy = cps.getPos().y;
|
|
if (x - GlobalVariables.SCALE <= cx && y - GlobalVariables.SCALE <= cy && x >= cx && y >= cy) {
|
|
if (x - GlobalVariables.SCALE <= cx && y - GlobalVariables.SCALE <= cy && x >= cx && y >= cy) {
|
|
tempCps = cps;
|
|
tempCps = cps;
|
|
- if(e.isControlDown())drawEdge = true;
|
|
|
|
|
|
+ if (e.isControlDown())
|
|
|
|
+ drawEdge = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- //Object Selection Highlighting (selectRect)
|
|
|
|
|
|
+
|
|
|
|
+ // Object Selection Highlighting (selectRect)
|
|
objectSelectionHighlighting();
|
|
objectSelectionHighlighting();
|
|
-
|
|
|
|
- repaint();
|
|
|
|
|
|
+
|
|
|
|
+ repaint();
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseReleased(MouseEvent e) {
|
|
public void mouseReleased(MouseEvent e) {
|
|
- if(drawEdge){
|
|
|
|
|
|
+ if (drawEdge) {
|
|
drawEdge = false;
|
|
drawEdge = false;
|
|
drawDeleteEdge();
|
|
drawDeleteEdge();
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (dragging) {
|
|
if (dragging) {
|
|
x = e.getX();
|
|
x = e.getX();
|
|
y = e.getY();
|
|
y = e.getY();
|
|
-
|
|
|
|
|
|
+
|
|
dragging = false;
|
|
dragging = false;
|
|
tempCps.setPos(e.getX() - GlobalVariables.SCALE_DIVIDED2, e.getY() - GlobalVariables.SCALE_DIVIDED2);
|
|
tempCps.setPos(e.getX() - GlobalVariables.SCALE_DIVIDED2, e.getY() - GlobalVariables.SCALE_DIVIDED2);
|
|
tempCps = null;
|
|
tempCps = null;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// Rechtsklick Liste
|
|
// Rechtsklick Liste
|
|
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);
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
itemDelete.setEnabled(false);
|
|
itemDelete.setEnabled(false);
|
|
}
|
|
}
|
|
popmenu.show(e.getComponent(), e.getX(), e.getY());
|
|
popmenu.show(e.getComponent(), e.getX(), e.getY());
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
repaint();
|
|
repaint();
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseDragged(MouseEvent e) {
|
|
public void mouseDragged(MouseEvent e) {
|
|
// TODO Auto-generated method stub
|
|
// TODO Auto-generated method stub
|
|
- if(drawEdge){
|
|
|
|
|
|
+ if (drawEdge) {
|
|
x = e.getX();
|
|
x = e.getX();
|
|
y = e.getY();
|
|
y = e.getY();
|
|
repaint();
|
|
repaint();
|
|
- }else{
|
|
|
|
- try {
|
|
|
|
- tempCps.setPos(e.getX() - GlobalVariables.SCALE_DIVIDED2, e.getY() - GlobalVariables.SCALE_DIVIDED2);
|
|
|
|
- dragging = true;
|
|
|
|
- selectRect.setLocation(tempCps.getPos().x-(GlobalVariables.SCALE/20), tempCps.getPos().y-(GlobalVariables.SCALE/20));
|
|
|
|
- objectTT.setTipText(tempCps.getName());
|
|
|
|
- objectTT.setLocation(tempCps.getPos().x, tempCps.getPos().y);
|
|
|
|
- repaint();
|
|
|
|
- } catch (Exception e2) {
|
|
|
|
- // TODO: handle exception
|
|
|
|
- }
|
|
|
|
|
|
+ } else {
|
|
|
|
+ try {
|
|
|
|
+ tempCps.setPos(e.getX() - GlobalVariables.SCALE_DIVIDED2, e.getY() - GlobalVariables.SCALE_DIVIDED2);
|
|
|
|
+ dragging = true;
|
|
|
|
+ selectRect.setLocation(tempCps.getPos().x - (GlobalVariables.SCALE / 20),
|
|
|
|
+ tempCps.getPos().y - (GlobalVariables.SCALE / 20));
|
|
|
|
+ objectTT.setTipText(tempCps.getName());
|
|
|
|
+ objectTT.setLocation(tempCps.getPos().x, tempCps.getPos().y);
|
|
|
|
+ repaint();
|
|
|
|
+ } catch (Exception e2) {
|
|
|
|
+ // TODO: handle exception
|
|
}
|
|
}
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseMoved(MouseEvent e) {
|
|
public void mouseMoved(MouseEvent e) {
|
|
x = e.getX();
|
|
x = e.getX();
|
|
y = e.getY();
|
|
y = e.getY();
|
|
-
|
|
|
|
|
|
+
|
|
boolean on = false;
|
|
boolean on = false;
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
for (CpsObject cps : model.getObjectsOnCanvas()) {
|
|
cx = cps.getPos().x;
|
|
cx = cps.getPos().x;
|
|
@@ -233,25 +242,28 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
|
|
on = true;
|
|
on = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if(!on){
|
|
|
|
|
|
+ if (!on) {
|
|
objectTT.setLocation(-200, -200);
|
|
objectTT.setLocation(-200, -200);
|
|
objectTT.setTipText("");
|
|
objectTT.setTipText("");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Sets the Highlighting of the Selected Object
|
|
* Sets the Highlighting of the Selected Object
|
|
*/
|
|
*/
|
|
private void objectSelectionHighlighting() {
|
|
private void objectSelectionHighlighting() {
|
|
- if(tempCps != null){
|
|
|
|
- selectRect.setBounds(tempCps.getPos().x-(GlobalVariables.SCALE/20), tempCps.getPos().y-(GlobalVariables.SCALE/20), GlobalVariables.SCALE+GlobalVariables.SCALE/10, GlobalVariables.SCALE+GlobalVariables.SCALE/10);
|
|
|
|
|
|
+ if (tempCps != null) {
|
|
|
|
+ selectRect.setBounds(tempCps.getPos().x - (GlobalVariables.SCALE / 20),
|
|
|
|
+ tempCps.getPos().y - (GlobalVariables.SCALE / 20),
|
|
|
|
+ GlobalVariables.SCALE + GlobalVariables.SCALE / 10,
|
|
|
|
+ GlobalVariables.SCALE + GlobalVariables.SCALE / 10);
|
|
controller.setSelectedObjectID(tempCps.getID());
|
|
controller.setSelectedObjectID(tempCps.getID());
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
controller.setSelectedObjectID(0);
|
|
controller.setSelectedObjectID(0);
|
|
selectRect.setRect(0, 0, 0, 0);
|
|
selectRect.setRect(0, 0, 0, 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Draws or Deletes an Edge
|
|
* Draws or Deletes an Edge
|
|
*/
|
|
*/
|