Beispiel #1
0
 public void add(Bug bug) {
   BugLabel bugLabel = new BugLabel(bug, this);
   bug.setContext(bugLabel);
   add(bugLabel, BorderLayout.CENTER);
   bugLabel.addMouseMotionListener(this);
   bugLabel.addMouseListener(this);
   bugLabel.repaint();
 }
Beispiel #2
0
 @Override
 public void mouseDragged(MouseEvent e) {
   Component dragged = e.getComponent();
   if (dragged instanceof BugLabel) {
     BugLabel bugLabel = (BugLabel) dragged;
     bugLabel.bug.setXY(e.getX() + bugLabel.getX(), e.getY() + bugLabel.getY());
     parent.worldStatusPanel.updateStats();
   } else if (dragged instanceof JouleLabel) {
     JouleLabel jouleLabel = (JouleLabel) dragged;
     jouleLabel.joule.setXY(e.getX() + jouleLabel.getX(), e.getY() + jouleLabel.getY());
   } else {
     System.err.println("Unexpected Drag Event: " + e.toString());
   }
 }
Beispiel #3
0
 @Override
 public void mouseClicked(MouseEvent e) {
   Component clicked = e.getComponent();
   if (clicked instanceof BugLabel) {
     BugLabel bug = (BugLabel) clicked;
     if (selectedBug == null) {
       selectedBug = bug;
       bug.select(true);
       bug.repaint();
       Graphics2D g = (Graphics2D) bug.getParent().getGraphics();
       AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.2f);
       g.setComposite(ac);
       g.setColor(Color.gray);
       g.fillRect(10, 15, 900, 600);
     } else if (e.getClickCount() == 1) {
       if (selectedBug == bug) {
         selectedBug.select(false);
         selectedBug.repaint();
         selectedBug = null;
       } else {
         selectedBug.select(false);
         selectedBug.repaint();
         bug.select(true);
         bug.repaint();
         selectedBug = bug;
       }
     }
     if (e.getClickCount() == 2) {
       new BugFrame(bug.bug);
     }
     parent.worldStatusPanel.updateStats();
   } else if (clicked instanceof JouleLabel) {
     // JouleLabel joule = (JouleLabel)clicked;
   } else {
     System.err.println("Unexpected Click Event: " + e);
   }
 }