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

📄 areaviewer.java

📁 传感器网络操作系统contiki。 被广泛应用于环境检测、结构健康监测等等。包括路由协议
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        // 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 setBackgroundHandler = 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) {          if (filename.endsWith(".tiff") ||              filename.endsWith(".tif") ||              filename.endsWith(".gif") ||              filename.endsWith(".jpg") ||              filename.endsWith(".jpeg") ||              filename.endsWith(".png") ||              filename.endsWith(".bmp")) {            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 owner) {        super(owner, "Image settings");                JPanel tempPanel;        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);                // Set layout and add components        doubleFormat.setMinimumIntegerDigits(1);        setLayout(new BoxLayout(this.getContentPane(), 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);        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);        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);        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);        add(tempPanel);        add(Box.createVerticalGlue());        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);        add(tempPanel);        // Show dialog        setModal(true);        pack();        setLocationRelativeTo(owner);        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 background image")) {                // Let user select image file        JFileChooser fileChooser = new JFileChooser();        ImageFilter filter = new ImageFilter();        fileChooser.addChoosableFileFilter(filter);                int returnVal = fileChooser.showOpenDialog(canvas);                if (returnVal != JFileChooser.APPROVE_OPTION) {          // User cancelled          return;        }                 File file = fileChooser.getSelectedFile();                // User selected non-supported file, aborting        if (!filter.accept(file)) {          logger.fatal("Non-supported file type, aborting");          return;        }                logger.info("Opening: " + file.getName() + ".");                // Load image using toolkit and media tracker        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()) {            logger.fatal("Error when loading image: ");            image = null;          }          if (image == null) {            logger.fatal("Image is null, aborting");            return;          }        } catch (InterruptedException ex) {          logger.fatal("Interrupted during image loading, aborting");          return;        }                // Let user set virtual size of loaded image        ImageSettingsDialog dialog = new ImageSettingsDialog(file, image, GUI.frame);                if (!dialog.terminatedOK()) {          logger.fatal("User cancelled, aborting");          return;        }        // Add background image        backgroundStartX = dialog.getVirtualStartX();        backgroundStartY = dialog.getVirtualStartY();        backgroundWidth = dialog.getVirtualWidth();        backgroundHeight = dialog.getVirtualHeight();                backgroundImage = image;        backgroundImageFile = file;      }    }  };  /**   * Helps user analyze a background for obstacles.   */  private ActionListener analyzeObstaclesHandler = new ActionListener() {        class AnalyzeImageDialog extends JDialog {            private NumberFormat intFormat = NumberFormat.getIntegerInstance();      private BufferedImage imageToAnalyze = null;      private BufferedImage obstacleImage = null;      private JPanel canvasPanel = null;      private boolean[][] obstacleArray = null;      private boolean exitedOK = false;            private JSlider redSlider, greenSlider, blueSlider, toleranceSlider, sizeSlider;            /**       * Listens to preview mouse motion event (when picking color)       */      private MouseMotionListener myMouseMotionListener = new MouseMotionListener() {        public void mouseDragged(MouseEvent e) {                  }        public void mouseMoved(MouseEvent e) {          // Convert from mouse to image pixel position          Point pixelPoint = new Point(              (int) (e.getX() * (((double) imageToAnalyze.getWidth()) / ((double) canvasPanel.getWidth()))),              (int) (e.getY() * (((double) imageToAnalyze.getHeight()) / ((double) canvasPanel.getHeight())))          );                    // Fetch color          int color = imageToAnalyze.getRGB(pixelPoint.x, pixelPoint.y);          int red = (color & 0x00ff0000) >> 16;          int green = (color & 0x0000ff00) >> 8;          int blue = color & 0x000000ff;          // Update sliders          redSlider.setValue(red);          redSlider.repaint();          greenSlider.setValue(green);          greenSlider.repaint();          blueSlider.setValue(blue);          blueSlider.repaint();        }      };            /**       * Listens to preview mouse event (when picking color)       */      private MouseListener myMouseListener = new MouseListener() {        public void mouseClicked(MouseEvent e) {                  }        public void mouseReleased(MouseEvent e) {                  }        public void mouseEntered(MouseEvent e) {                  }        public void mouseExited(MouseEvent e) {                  }        public void mousePressed(MouseEvent e) {          // Stop picking color again; remove mouse listeners and reset mouse cursor

⌨️ 快捷键说明

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