⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 taskdeploy.java

📁 nesC写的heed算法
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                     config.getMinimumPixelX(), config.getMaximumPixelY());
    leaf = new ZVisualLeaf(line);
    leaf.setSelectable(false);
    leaf.setPickable(false);
    leaf.setFindable(false);
    layer.addChild(leaf);

    line = new ZLine(config.getMaximumPixelX(), config.getMinimumPixelY(), 
                     config.getMaximumPixelX(), config.getMaximumPixelY());
    leaf = new ZVisualLeaf(line);
    leaf.setSelectable(false);
    leaf.setPickable(false);
    leaf.setFindable(false);
    layer.addChild(leaf);

    line = new ZLine(config.getMinimumPixelX(), config.getMaximumPixelY(), 
                     config.getMaximumPixelX(), config.getMaximumPixelY());
    leaf = new ZVisualLeaf(line);
    leaf.setSelectable(false);
    leaf.setPickable(false);
    leaf.setFindable(false);
    layer.addChild(leaf);

    // render the static motes
    for (Enumeration e=motes.elements(); e.hasMoreElements(); ) {
      Mote m = (Mote)e.nextElement();
      leaf = new ZVisualLeaf(m);
      layer.addChild(leaf);
      leaf.addMouseListener(this);
    }

    JPanel main = new JPanel(new BorderLayout());

    // add scroll pane
    int x=0, y = 0;
    if (imageWidth > SCROLL_WIDTH) {
      x = SCROLL_WIDTH;
    }
    else {
      x = imageWidth;
    }

    if (imageHeight > SCROLL_HEIGHT) {
      y = SCROLL_HEIGHT;
    }
    else {
      y = imageHeight;
    }

    scrollPane = new ZScrollPane(canvas);
    scrollPane.setPreferredSize(new Dimension(x+20, y+20));
    parentPanel.add(scrollPane, BorderLayout.CENTER);

    view = new JPanel(new GridLayout(0,3));
    view.add(new JLabel(" X Position "));
    view.add(new JLabel(" Y Position "));
    view.add(new JLabel(" Mote ID "));
    xpos = new JLabel ("    0.0     ");
    ypos = new JLabel ("    0.0     ");
    moteId = new JLabel("   ID    ");
    view.add(xpos);
    view.add(ypos);
    view.add(moteId);
    parentPanel.add(view, BorderLayout.EAST);

    parentFrame.pack();

    formatter = new DecimalFormat("###.##");

    // create all the event handlers
    panEventHandler = new ZPanEventHandler(canvas.getCameraNode());
    zoomEventHandler = new ZoomEventHandler(canvas.getCameraNode());
    addEventHandler = new AddEventHandler(canvas, this, this, imageWidth, imageHeight, motes, parentFrame);
    moveEventHandler = new MoveEventHandler(canvas, this, imageWidth, imageHeight, true);
    removeEventHandler = new RemoveEventHandler(canvas, canvas.getLayer(), motes, this);
    selectionHandler = new ZCompositeSelectionHandler(canvas.getCameraNode(), canvas, canvas.getLayer(), ZCompositeSelectionHandler.DELETE|ZCompositeSelectionHandler.MODIFY|ZCompositeSelectionHandler.MOVE);
 
    // set the zoom and move event handlers to active
    zoomEventHandler.setActive(true);
    moveEventHandler.setActive(true);

    setMode(ADD_MODE);
    add.setSelected(true);

    selectionHandler.getSelectionDeleteHandler().addGroupListener(this);
  }
  
  /**
   * Save configuration to the given table
   *
   * @param table Table to save configuration to
   */
  public void saveConfiguration() {
    client.deleteClientInfo(config.getName());
    client.deleteMote(config.getName());
    
    client.addClientInfo(config.toTASKClientInfo());
    // insert all motes 
    for (Enumeration e=motes.elements(); e.hasMoreElements();) {
      Mote m = (Mote)e.nextElement();
      m.setConfig(config.getName());
      TASKMoteClientInfo info = m.toMoteClientInfo();
      System.out.println(info.moteId+","+info.clientInfoName);
      client.addMote(info);
    }
 
    config.saved();
    motes.saved();
  }

  /**
   * Close the current configuration, requesting a save if necessary
   */
  private void closeConfiguration() {
    checkSave();
    parentFrame.getContentPane().removeAll();
    parentFrame.repaint();
//    configClose.setEnabled(false);
  }

  /**
   * Exits the application, prompting for saving the current configuration if necessary
   */
  private void exitConfiguration() {
    checkSave();
    System.exit(0);
  }

  /**
   * Checks if the current configuration has been modified since the last save. If so, a dialog prompts
   * the user to save the configuration
   */
  public void checkSave() {
    if (config.needsSave() || motes.needsSave()) {
      int save = JOptionPane.showConfirmDialog(parentFrame, "Do you want to save this configuration?", "Save Configuration", JOptionPane.YES_NO_OPTION);
      if (save == JOptionPane.YES_OPTION) {
        saveConfiguration();
      }
      else {
        config.saved();
        motes.saved();
//        configSave.setEnabled(false);
//        configEdit.setEnabled(true);
//        configLoad.setEnabled(true);
      }
    }
  }

  /**
   * Retrieves the motes information for the given configuration
   *
   * @param name Configuration name
   */
  public Motes getMotes(String name) {
    Motes m = new Motes();
    Vector mInfos = client.getAllMoteClientInfo(name);
    if (mInfos != null) {
      for (int i=0; i<mInfos.size(); i++) {
        m.addMote(new Mote((TASKMoteClientInfo)mInfos.elementAt(i)));
      }
    }
    return m;
  }

  /**
   * Retrieves the existing configurations from the TASK Server
   *
   * @return Names of the existing configurations
   */
  public Vector getConfigurations() {
    String clientInfos[] = client.getClientInfos();
    Vector configs = new Vector();
    for (int i=0; i<clientInfos.length; i++) {
      configs.addElement(clientInfos[i]);
    }
    return configs;
  }

  /**
   * Converts the x pixel coordinate to a real x coordinate and display it
   *
   * @param x X pixel coordinate to convert
   */
  public void setXPos(int x) {
    // from MoveEventHandler
    // convert to real x coord
    // x = xP * (xmaxr - xminR) / (xmaxP - xminP)
    double tmp = config.getMaximumRealX() + (x - config.getMaximumPixelX())*(config.getMaximumRealX() - config.getMinimumRealX())/(config.getMaximumPixelX() - config.getMinimumPixelX());
    xpos.setText(formatter.format(tmp));
  }

  /**
   * Converts the y pixel coordinate to a real y coordinate and display it
   *
   * @param y Y pixel coordinate to convert
   */
  public void setYPos(int y) {
    // from MoveEventHandler
    // convert to real y coord
    // y = yP * (ymaxR - yminr) / (ymaxP - yminP)
    double tmp = config.getMaximumRealY() + (y - config.getMaximumPixelY())*(config.getMaximumRealY() - config.getMinimumRealY())/(config.getMaximumPixelY() - config.getMinimumPixelY());
    ypos.setText(formatter.format(tmp));
  }

  /**
   * Display the id of the current mote
   *
   * @param id Id of the mote to display
   */
  public void setId(int id) {
    if (id != Mote.INVALID_ID) {
      moteId.setText(String.valueOf(id));
    }
    else {
      moteId.setText("");
    }
  }

  /**
   * Method to satisfy interface - not used
   *
   * @return empty string
   */
  public Object getInfo() {
    // from AddEventHandler
    return new String();
  }

  /**
   * Method to satisfy interface - not used
   */
  public void setPixelX(int x) {
    // from AddEventHandler - leave empty
  }

  /**
   * Method to satisfy interface - not used
   */
  public void setPixelY(int y) {
    // from AddEventHandler - leave empty
  }

  /**
   * When the motes list has been changed, enable save option
   */
  public void changed() {
    // from ChangeHandler
//    configSave.setEnabled(true);
  }

  public void nodeAdded(ZGroupEvent zge) {
  }

  public void nodeRemoved(ZGroupEvent zge) {
    ZVisualLeaf zvl = (ZVisualLeaf)zge.getChild();
    ZVisualComponent zvc = zvl.getFirstVisualComponent();
    Mote m = (Mote)zvc;
    motes.removeMote(m);
  }

  /**
   * Set the mode for the interface
   *
   * @param mode Mode for the interface
   */
  public void setMode(int mode) {
    if (currentEventHandler != null) {
      currentEventHandler.setActive(false);
    }

    switch (mode) {
      case ADD_MODE: currentEventHandler = addEventHandler;
                     canvas.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
                     break;
      case PAN_MODE: currentEventHandler = panEventHandler;
                     canvas.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                     break;
      case REMOVE_MODE: currentEventHandler = selectionHandler;
                     canvas.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
                     break;
    }

    if (currentEventHandler != null) {
      currentEventHandler.setActive(true);
    }
  }

  public void mouseClicked(ZMouseEvent me) {
  }

  public void mouseEntered(ZMouseEvent me) {
  }

  public void mouseExited(ZMouseEvent me) {
  }

  public void mousePressed(ZMouseEvent me) {
  }

  public void mouseReleased(ZMouseEvent me) {
    System.out.println(me);
    int x = me.getX();
    int y = me.getY();
    ZNode zn = me.getCurrentNode();
    ZVisualLeaf zvl = (ZVisualLeaf)zn;
    ZVisualComponent zvc = zvl.getFirstVisualComponent();
    Mote m = (Mote)zvc;
    m.setCoordinates(x,y);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -