Example #1
0
 private void stopPollThread() {
   if (pollThread != null) {
     pollThread.interrupt();
     try {
       pollThread.join(2000);
     } catch (InterruptedException e) {
       // XXX
     } finally {
       pollThread = null;
     }
   }
 }
    // ===========================================================
    private void buildConfig(String[] config, int threadsNumber) {
      if (config.length == 0) //  Do nothing
      return;
      //  first time rebuild lines (ended by '\'
      ArrayList<String> lines = rebuildLines(config);

      int threadCounter = 0;
      for (String line : lines) {
        StringTokenizer stk = new StringTokenizer(line, ",");
        PollThread thread = new PollThread(threadCounter++);
        while (stk.hasMoreTokens()) thread.add(stk.nextToken());
        add(thread);
      }
      for (int i = threadCounter; i < threadsNumber; i++) add(new PollThread(i));
    }
 /*
  * (non-Javadoc)
  *
  * @see io.socket.IOTransport#sendBulk(java.lang.String[])
  */
 @Override
 public void sendBulk(String[] texts) throws IOException {
   queue.addAll(Arrays.asList(texts));
   if (isBlocked()) {
     pollThread.interrupt();
     urlConnection.disconnect();
   }
 }
 public void machineStateChanged(MachineStateChangeEvent evt) {
   MachineState state = evt.getState();
   // TODO: Do we handle reset correctly?
   if (state.isBuilding() || !state.isConnected()) {
     if (updateThread != null) {
       updateThread.interrupt();
     }
     if (pollThread != null) {
       pollThread.interrupt();
     }
     SwingUtilities.invokeLater(
         new Runnable() {
           public void run() {
             dispose();
           }
         });
   }
 }
 public void windowClosing(WindowEvent e) {
   updateThread.interrupt();
   pollThread.interrupt();
 }
  private ControlPanelWindow(MachineInterface newMachine) {
    super("Control Panel");

    Image icon = Base.getImage("images/icon.gif", this);
    setIconImage(icon);

    // save our machine!
    machine = newMachine;

    machine.runCommand(new InvalidatePosition());

    // Listen to it-- stop and close if we're in build mode.
    Base.getMachineLoader().addMachineListener(this);

    // default behavior
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    // no menu bar.
    setJMenuBar(createMenuBar());

    chooser = new JColorChooser(Color.BLACK);

    ActionListener okListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Color ledColor = chooser.getColor();
            Base.logger.severe("running setLedStrip");
            try {
              machine.getDriver().setLedStrip(ledColor, 0);
            } catch (replicatorg.drivers.RetryException f) {
              Base.logger.severe("foo" + f.toString());
            }
            // machine.runCommand(new SetLedStrip(ledColor, 0));
            ledStripButton.setText(ShowColorChooserAction.buttonStringFromColor(ledColor));
          }
        };

    ledStripButton =
        new JButton(new ShowColorChooserAction(this, chooser, okListener, null, Color.BLACK));

    // create all our GUI interfaces
    mainPanel = new JPanel();
    mainPanel.setLayout(new MigLayout("gap 5, ins 5, flowy"));

    jogPanel = new JogPanel(machine);
    mainPanel.add(jogPanel, "split 4, growx, growy");
    mainPanel.add(createActivationPanel(), "split, growx");
    if (newMachine.getMachineType() == MachineType.THE_REPLICATOR) {
      mainPanel.add(ledStripButton, "growx");
      //			mainPanel.add(createBeepPanel(), "growx");
    }
    mainPanel.add(alternateToolsPanel(), "newline, growy");

    this.setResizable(false);
    add(mainPanel);

    // add our listener hooks.
    addWindowListener(this);
    // addWindowFocusListener(this);
    // addWindowStateListener(this);

    // start our various threads.
    updateThread = new UpdateThread(this);
    updateThread.start();
    pollThread = new PollThread(machine);
    pollThread.start();
  }
Example #7
0
 private void startPollThread() {
   pollThread = new PollThread(this, stream, postsAdapter, client);
   pollThread.start();
 }
 /*
  * (non-Javadoc)
  *
  * @see io.socket.IOTransport#disconnect()
  */
 @Override
 public void disconnect() {
   this.setConnect(false);
   pollThread.interrupt();
 }
 /*
  * (non-Javadoc)
  *
  * @see io.socket.IOTransport#connect()
  */
 @Override
 public void connect() {
   this.setConnect(true);
   pollThread = new PollThread();
   pollThread.start();
 }