Beispiel #1
0
 public MotionSensor(
     String title, float winPosX, float winPosY, final MessageManagerInterface em) {
   mw = new MessageWindow(title, winPosX, winPosY);
   JButton button = new JButton();
   button.setText("Motion Sensor");
   button.setEnabled(true);
   button.addActionListener(
       new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
           Message msg = new Message(Configuration.MOTION_SENSOR_ID, "WB");
           // Here we send the message to the message manager.
           try {
             em.SendMessage(msg);
             mw.WriteMessage("Detected Motion!");
           } // try
           catch (Exception e) {
             System.out.println("Motion Sensor Error:: " + e);
           } // catch
         }
       });
   JFrame buttonFrame = new JFrame();
   buttonFrame.setBounds(mw.GetX(), mw.GetY(), 50, 80);
   buttonFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
   JPanel buttonPanel = new JPanel();
   buttonFrame.add(buttonPanel);
   buttonPanel.add(button);
   buttonFrame.setVisible(true);
 }
  /**
   * Remove the connection from the connection registry and clean up any remaining shrapnel
   *
   * @param nodeId
   */
  public void disconnectNode(short nodeId) {
    synchronized (connections) {
      Short n = Short.valueOf(nodeId);
      MessageWindow mw = messageWindows.get(n);
      if (mw != null) {
        mw.lock.lock();
        mw.disconnected = true;
        try {
          mw.full.signalAll();
          messageWindows.remove(n);
        } finally {
          mw.lock.unlock();
        }
      }

      NodeConnection nc = connections.get(nodeId);
      if (nc != null) {
        nc.nuke();
      }
      connections.remove(nodeId);
    }
    clusterManager.connectionStateChange();
  }