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

📄 areaviewer.java

📁 Contiki是一个开源
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        inSelectMode = true;      } else if (e.getActionCommand().equals("set pan mode")) {        // Remove all other mouse motion listeners        for (MouseMotionListener reggedListener: canvas.getMouseMotionListeners()) {          canvas.removeMouseMotionListener(reggedListener);        }        inSelectMode = false;        inTrackMode = false;        // Add the special pan mouse motion listener        canvas.addMouseMotionListener(canvasPanModeHandler);      } else if (e.getActionCommand().equals("set zoom mode")) {        // Remove all other mouse motion listeners        for (MouseMotionListener reggedListener: canvas.getMouseMotionListeners()) {          canvas.removeMouseMotionListener(reggedListener);        }        inSelectMode = false;        inTrackMode = false;        // Add the special zoom mouse motion listener        canvas.addMouseMotionListener(canvasZoomModeHandler);      } else if (e.getActionCommand().equals("set track rays mode")) {        // Remove all other mouse motion listeners        for (MouseMotionListener reggedListener: canvas.getMouseMotionListeners()) {          canvas.removeMouseMotionListener(reggedListener);        }        inSelectMode = false;        inTrackMode = true;      } else if (e.getActionCommand().equals("toggle show settings")) {        if (((JCheckBox) e.getSource()).isSelected()) {          scrollControlPanel.setVisible(true);        } else {          scrollControlPanel.setVisible(false);        }        thisPlugin.invalidate();        thisPlugin.revalidate();      }    }  };  /**   * Selects which graphical parts should be painted   */  private ActionListener selectGraphicsHandler = new ActionListener() {    public void actionPerformed(ActionEvent e) {      if (e.getActionCommand().equals("toggle background")) {        drawBackgroundImage = ((JCheckBox) e.getSource()).isSelected();      } else if (e.getActionCommand().equals("toggle obstacles")) {        drawCalculatedObstacles = ((JCheckBox) e.getSource()).isSelected();      } else if (e.getActionCommand().equals("toggle channel")) {        drawChannelProbabilities = ((JCheckBox) e.getSource()).isSelected();      } else if (e.getActionCommand().equals("toggle radios")) {        drawRadios = ((JCheckBox) e.getSource()).isSelected();      } else if (e.getActionCommand().equals("toggle radio activity")) {        drawRadioActivity = ((JCheckBox) e.getSource()).isSelected();      } else if (e.getActionCommand().equals("toggle arrow")) {        drawScaleArrow = ((JCheckBox) e.getSource()).isSelected();      }      canvas.repaint();    }  };  /**   * Helps user set a background image which can be analysed for obstacles/freespace.   */  private ActionListener obstacleHandler = new ActionListener() {    /**     * Choosable file filter that supports tif, gif, jpg, png, bmp.     */    class ImageFilter extends FileFilter {      public boolean accept(File f) {        if (f.isDirectory()) {          return true;        }        String filename = f.getName();        if (filename == null) {          return false;        }        if (filename.endsWith(".gif") || filename.endsWith(".GIF") ||            filename.endsWith(".jpg") || filename.endsWith(".JPG") ||            filename.endsWith(".jpeg") || filename.endsWith(".JPEG") ||            filename.endsWith(".png") || filename.endsWith(".PNG")){          return true;        }        return false;      }      public String getDescription() {        return "All supported images";      }    }    class ImageSettingsDialog extends JDialog {      private double      virtualStartX = 0.0,      virtualStartY = 0.0,      virtualWidth = 0.0,      virtualHeight = 0.0;      private JFormattedTextField      virtualStartXField,      virtualStartYField,      virtualWidthField,      virtualHeightField;      private boolean terminatedOK = false;      private NumberFormat doubleFormat = NumberFormat.getNumberInstance();      /**       * Creates a new dialog for settings background parameters       */      protected ImageSettingsDialog(File imageFile, Image image, Frame frame) {        super(frame, "Image settings");        setupDialog();      }      protected ImageSettingsDialog(File imageFile, Image image, Dialog dialog) {        super(dialog, "Image settings");        setupDialog();      }      protected ImageSettingsDialog(File imageFile, Image image, Window window) {        super(window, "Image settings");        setupDialog();      }      private void setupDialog() {        JPanel mainPanel, tempPanel;        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);        doubleFormat.setMinimumIntegerDigits(1);        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);        // Set layout and add components        mainPanel = new JPanel();        mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));        tempPanel = new JPanel(new GridLayout(1, 2));        tempPanel.add(new JLabel("Start X (m)     "));        virtualStartXField = new JFormattedTextField(doubleFormat);        virtualStartXField.setValue(new Double(0.0));        tempPanel.add(virtualStartXField);        mainPanel.add(tempPanel);        tempPanel = new JPanel(new GridLayout(1, 2));        tempPanel.add(new JLabel("Start Y (m)"));        virtualStartYField = new JFormattedTextField(doubleFormat);        virtualStartYField.setValue(new Double(0.0));        tempPanel.add(virtualStartYField);        mainPanel.add(tempPanel);        tempPanel = new JPanel(new GridLayout(1, 2));        tempPanel.add(new JLabel("Width (m)"));        virtualWidthField = new JFormattedTextField(doubleFormat);        virtualWidthField.setValue(new Double(100.0));        tempPanel.add(virtualWidthField);        mainPanel.add(tempPanel);        tempPanel = new JPanel(new GridLayout(1, 2));        tempPanel.add(new JLabel("Height (m)"));        virtualHeightField = new JFormattedTextField(doubleFormat);        virtualHeightField.setValue(new Double(100.0));        tempPanel.add(virtualHeightField);        mainPanel.add(tempPanel);        mainPanel.add(Box.createVerticalGlue());        mainPanel.add(Box.createVerticalStrut(10));        tempPanel = new JPanel();        tempPanel.setLayout(new BoxLayout(tempPanel, BoxLayout.X_AXIS));        tempPanel.add(Box.createHorizontalGlue());        final JButton okButton = new JButton("OK");        this.getRootPane().setDefaultButton(okButton);        final JButton cancelButton = new JButton("Cancel");        okButton.addActionListener(new ActionListener() {          public void actionPerformed(ActionEvent e) {            virtualStartX = ((Number) virtualStartXField.getValue()).doubleValue();            virtualStartY = ((Number) virtualStartYField.getValue()).doubleValue();            virtualWidth = ((Number) virtualWidthField.getValue()).doubleValue();            virtualHeight = ((Number) virtualHeightField.getValue()).doubleValue();            terminatedOK = true;            dispose();}        });        cancelButton.addActionListener(new ActionListener() {          public void actionPerformed(ActionEvent e) {            terminatedOK = false;            dispose();          }        });        tempPanel.add(okButton);        tempPanel.add(cancelButton);        mainPanel.add(tempPanel);        mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));        add(mainPanel);        // Show dialog        setModal(true);        pack();        setLocationRelativeTo(this.getParent());        setVisible(true);      }      public boolean terminatedOK() {        return terminatedOK;      }      public double getVirtualStartX() {        return virtualStartX;      }      public double getVirtualStartY() {        return virtualStartY;      }      public double getVirtualWidth() {        return virtualWidth;      }      public double getVirtualHeight() {        return virtualHeight;      }    }    public void actionPerformed(ActionEvent e) {      if (e.getActionCommand().equals("set custom bitmap")) {        if (!setCustomBitmap() || !analyzeBitmapForObstacles()) {          backgroundImage = null;          currentChannelModel.removeAllObstacles();          noneButton.setSelected(true);          repaint();        }      } else if (e.getActionCommand().equals("set predefined 1")) {        currentChannelModel.removeAllObstacles();        currentChannelModel.addRectObstacle(0, 0, 50, 5, false);        currentChannelModel.addRectObstacle(0, 5, 5, 50, false);        currentChannelModel.addRectObstacle(70, 0, 20, 5, false);        currentChannelModel.addRectObstacle(0, 70, 5, 20, false);        currentChannelModel.notifySettingsChanged();        repaint();      } else if (e.getActionCommand().equals("set predefined 2")) {        currentChannelModel.removeAllObstacles();        currentChannelModel.addRectObstacle(0, 0, 10, 10, false);        currentChannelModel.addRectObstacle(30, 0, 10, 10, false);        currentChannelModel.addRectObstacle(60, 0, 10, 10, false);        currentChannelModel.addRectObstacle(90, 0, 10, 10, false);        currentChannelModel.addRectObstacle(5, 90, 10, 10, false);        currentChannelModel.addRectObstacle(25, 90, 10, 10, false);        currentChannelModel.addRectObstacle(45, 90, 10, 10, false);        currentChannelModel.addRectObstacle(65, 90, 10, 10, false);        currentChannelModel.addRectObstacle(85, 90, 10, 10, false);        currentChannelModel.notifySettingsChanged();        repaint();      } else if (e.getActionCommand().equals("set no obstacles")) {        backgroundImage = null;        currentChannelModel.removeAllObstacles();        repaint();      } else {        logger.fatal("Unhandled action command: " + e.getActionCommand());      }    }    private boolean setCustomBitmap() {      /* Select image file */      JFileChooser fileChooser = new JFileChooser();      ImageFilter filter = new ImageFilter();      fileChooser.addChoosableFileFilter(filter);      int returnVal = fileChooser.showOpenDialog(canvas);      if (returnVal != JFileChooser.APPROVE_OPTION) {        return false;      }      File file = fileChooser.getSelectedFile();      if (!filter.accept(file)) {        logger.fatal("Non-supported file type, aborting");        return false;      }      logger.info("Opening '" + file.getAbsolutePath() + "'");      /* Load image data */      Toolkit toolkit = Toolkit.getDefaultToolkit();      Image image = toolkit.getImage(file.getAbsolutePath());      MediaTracker tracker = new MediaTracker(canvas);      tracker.addImage(image, 1);      try {        tracker.waitForAll();        if (tracker.isErrorAny() || image == null) {          logger.info("Error when loading '" + file.getAbsolutePath() + "'");          image = null;          return false;        }      } catch (InterruptedException ex) {        logger.fatal("Interrupted during image loading, aborting");        return false;      }      /* Set virtual size of image */      Container topParent = GUI.getTopParentContainer();      ImageSettingsDialog dialog;      if (topParent instanceof Frame) {        dialog = new ImageSettingsDialog(file, image, (Frame) topParent);      } else if (topParent instanceof Dialog) {        dialog = new ImageSettingsDialog(file, image, (Dialog) topParent);      } else if (topParent instanceof Window) {        dialog = new ImageSettingsDialog(file, image, (Window) topParent);      } else {        logger.fatal("Unknown parent container, aborting");        return false;      }      if (!dialog.terminatedOK()) {        logger.fatal("User canceled, aborting");        image = null;        return false;      }      /* Show loaded image */      backgroundStartX = dialog.getVirtualStartX();      backgroundStartY = dialog.getVirtualStartY();      backgroundWidth = dialog.getVirtualWidth();      backgroundHeight = dialog.getVirtualHeight();      backgroundImage = image;      backgroundImageFile = file;      return true;    }

⌨️ 快捷键说明

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