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

📄 areaviewer.java

📁 Contiki是一个开源
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * Copyright (c) 2008, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. Neither the name of the Institute nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: AreaViewer.java,v 1.4 2008/02/15 13:20:23 fros4943 Exp $ */package se.sics.mrm;import java.awt.*;import java.awt.event.*;import java.awt.geom.*;import java.awt.image.BufferedImage;import java.io.File;import java.net.URL;import java.text.DecimalFormat;import java.text.NumberFormat;import java.util.*;import javax.swing.*;import javax.swing.filechooser.FileFilter;import org.apache.log4j.Logger;import org.jdom.Element;import se.sics.cooja.*;import se.sics.cooja.interfaces.*;/** * The class AreaViewer belongs to the MRM package. * * It is used to visualize available radios, traffic between them as well * as the current radio propagation area of single radios. * Users may also add background images (such as maps) and color-analyze them * in order to add simulated obstacles in the radio medium. * * For more information about MRM see MRM.java * * @see MRM * @author Fredrik Osterlind */@ClassDescription("MRM - Area Viewer")@PluginType(PluginType.SIM_PLUGIN)public class AreaViewer extends VisPlugin {  private static final long serialVersionUID = 1L;  private static Logger logger = Logger.getLogger(AreaViewer.class);  private final JPanel canvas;  private final VisPlugin thisPlugin;  ChannelModel.TransmissionData dataTypeToVisualize = ChannelModel.TransmissionData.SIGNAL_STRENGTH;  ButtonGroup visTypeSelectionGroup;  // General drawing parameters  private Point lastHandledPosition = new Point(0,0);  private double zoomCenterX = 0.0;  private double zoomCenterY = 0.0;  private Point zoomCenterPoint = new Point();  private double currentZoomX = 1.0f;  private double currentZoomY = 1.0f;  private double currentPanX = 0.0f;  private double currentPanY = 0.0f;  private boolean drawBackgroundImage = true;  private boolean drawCalculatedObstacles = true;  private boolean drawChannelProbabilities = true;  private boolean drawRadios = true;  private boolean drawRadioActivity = true;  private boolean drawScaleArrow = true;  // Background drawing parameters (meters)  private double backgroundStartX = 0.0;  private double backgroundStartY = 0.0;  private double backgroundWidth = 0.0;  private double backgroundHeight = 0.0;  private Image backgroundImage = null;  private File backgroundImageFile = null;  // Obstacle drawing parameters (same scale as background)  private boolean needToRepaintObstacleImage = false;  private double obstacleStartX = 0.0;  private double obstacleStartY = 0.0;  private double obstacleWidth = 0.0;  private double obstacleHeight = 0.0;  private Image obstacleImage = null;  // Channel probabilities drawing parameters (meters)  private double channelStartX = 0.0;  private double channelStartY = 0.0;  private double channelWidth = 0.0;  private double channelHeight = 0.0;  private Image channelImage = null;  private JSlider resolutionSlider;  private JPanel controlPanel;  private JScrollPane scrollControlPanel;  private Simulation currentSimulation;  private MRM currentRadioMedium;  private ChannelModel currentChannelModel;  private final String antennaImageFilename = "antenna.png";  private final Image antennaImage;  private Radio selectedRadio = null;  private boolean inSelectMode = true;  private boolean inTrackMode = false;  private Vector<Line2D> trackedComponents = null;  // Coloring variables  private JPanel coloringIntervalPanel = null;  private double coloringHighest = 0;  private double coloringLowest = 0;  private boolean coloringIsFixed = true;  private Thread attenuatorThread = null;  private JCheckBox showSettingsBox;  private JCheckBox backgroundCheckBox;  private JCheckBox obstaclesCheckBox;  private JCheckBox channelCheckBox;  private JCheckBox radiosCheckBox;  private JCheckBox radioActivityCheckBox;  private JCheckBox arrowCheckBox;  private JRadioButton noneButton = null;  /**   * Initializes an AreaViewer.   *   * @param simulationToVisualize Simulation using MRM   */  public AreaViewer(Simulation simulationToVisualize, GUI gui) {    super("MRM - Area Viewer", gui);    currentSimulation = simulationToVisualize;    currentRadioMedium = (MRM) currentSimulation.getRadioMedium();    currentChannelModel = currentRadioMedium.getChannelModel();    // We want to listen to changes both in the channel model as well as in the radio medium    currentChannelModel.addSettingsObserver(channelModelSettingsObserver);    currentRadioMedium.addSettingsObserver(radioMediumSettingsObserver);    currentRadioMedium.addRadioMediumObserver(radioMediumActivityObserver);    // Set initial size etc.    setSize(500, 500);    setVisible(true);    thisPlugin = this;    // Canvas mode radio buttons + show settings checkbox    showSettingsBox = new JCheckBox ("settings", true);    showSettingsBox.setAlignmentY(Component.TOP_ALIGNMENT);    showSettingsBox.setContentAreaFilled(false);    showSettingsBox.setActionCommand("toggle show settings");    showSettingsBox.addActionListener(canvasModeHandler);    JRadioButton selectModeButton = new JRadioButton ("select");    selectModeButton.setAlignmentY(Component.BOTTOM_ALIGNMENT);    selectModeButton.setContentAreaFilled(false);    selectModeButton.setActionCommand("set select mode");    selectModeButton.addActionListener(canvasModeHandler);    selectModeButton.setSelected(true);    JRadioButton panModeButton = new JRadioButton ("pan");    panModeButton.setAlignmentY(Component.BOTTOM_ALIGNMENT);    panModeButton.setContentAreaFilled(false);    panModeButton.setActionCommand("set pan mode");    panModeButton.addActionListener(canvasModeHandler);    JRadioButton zoomModeButton = new JRadioButton ("zoom");    zoomModeButton.setAlignmentY(Component.BOTTOM_ALIGNMENT);    zoomModeButton.setContentAreaFilled(false);    zoomModeButton.setActionCommand("set zoom mode");    zoomModeButton.addActionListener(canvasModeHandler);    JRadioButton trackModeButton = new JRadioButton ("track rays");    trackModeButton.setAlignmentY(Component.BOTTOM_ALIGNMENT);    trackModeButton.setContentAreaFilled(false);    trackModeButton.setActionCommand("set track rays mode");    trackModeButton.addActionListener(canvasModeHandler);    ButtonGroup group = new ButtonGroup();    group.add(selectModeButton);    group.add(panModeButton);    group.add(zoomModeButton);    group.add(trackModeButton);    // Create canvas    canvas = new JPanel() {      private static final long serialVersionUID = 1L;      public void paintComponent(Graphics g) {        super.paintComponent(g);        repaintCanvas((Graphics2D) g);      }    };    canvas.setBorder(BorderFactory.createLineBorder(Color.BLACK));    canvas.setBackground(Color.WHITE);    canvas.setLayout(new BorderLayout());    canvas.addMouseListener(canvasMouseHandler);    // Create canvas mode panel    JPanel canvasModePanel = new JPanel();    canvasModePanel.setOpaque(false);    canvasModePanel.setLayout(new BoxLayout(canvasModePanel, BoxLayout.Y_AXIS));    canvasModePanel.setAlignmentY(Component.BOTTOM_ALIGNMENT);    canvasModePanel.add(showSettingsBox);    canvasModePanel.add(Box.createVerticalGlue());    canvasModePanel.add(selectModeButton);    canvasModePanel.add(panModeButton);    canvasModePanel.add(zoomModeButton);    canvasModePanel.add(trackModeButton);    canvas.add(BorderLayout.EAST, canvasModePanel);    // Create control graphics panel    JPanel graphicsComponentsPanel = new JPanel();    graphicsComponentsPanel.setLayout(new BoxLayout(graphicsComponentsPanel, BoxLayout.Y_AXIS));    graphicsComponentsPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));    graphicsComponentsPanel.setAlignmentX(Component.CENTER_ALIGNMENT);    graphicsComponentsPanel.add(new JLabel("Show/Hide:"));    backgroundCheckBox = new JCheckBox("Background image", true);    backgroundCheckBox.setActionCommand("toggle background");    backgroundCheckBox.addActionListener(selectGraphicsHandler);    graphicsComponentsPanel.add(backgroundCheckBox);    obstaclesCheckBox = new JCheckBox("Obstacles", true);    obstaclesCheckBox.setActionCommand("toggle obstacles");    obstaclesCheckBox.addActionListener(selectGraphicsHandler);    graphicsComponentsPanel.add(obstaclesCheckBox);    channelCheckBox = new JCheckBox("Channel", true);    channelCheckBox.setActionCommand("toggle channel");    channelCheckBox.addActionListener(selectGraphicsHandler);    graphicsComponentsPanel.add(channelCheckBox);    radiosCheckBox = new JCheckBox("Radios", true);    radiosCheckBox.setActionCommand("toggle radios");    radiosCheckBox.addActionListener(selectGraphicsHandler);    graphicsComponentsPanel.add(radiosCheckBox);    radioActivityCheckBox = new JCheckBox("Radio Activity", true);    radioActivityCheckBox.setActionCommand("toggle radio activity");    radioActivityCheckBox.addActionListener(selectGraphicsHandler);    graphicsComponentsPanel.add(radioActivityCheckBox);    arrowCheckBox = new JCheckBox("Scale arrow", true);    arrowCheckBox.setActionCommand("toggle arrow");    arrowCheckBox.addActionListener(selectGraphicsHandler);    graphicsComponentsPanel.add(arrowCheckBox);    graphicsComponentsPanel.add(Box.createRigidArea(new Dimension(0,20)));    graphicsComponentsPanel.add(new JLabel("Obstacle configuration:"));    noneButton = new JRadioButton("No obstacles");    noneButton.setActionCommand("set no obstacles");    noneButton.addActionListener(obstacleHandler);    noneButton.setSelected(true);    JRadioButton pre1Button = new JRadioButton("Predefined 1");    pre1Button.setActionCommand("set predefined 1");    pre1Button.addActionListener(obstacleHandler);    JRadioButton pre2Button = new JRadioButton("Predefined 2");    pre2Button.setActionCommand("set predefined 2");    pre2Button.addActionListener(obstacleHandler);    JRadioButton customButton = new JRadioButton("From bitmap");    customButton.setActionCommand("set custom bitmap");    customButton.addActionListener(obstacleHandler);    if (GUI.isVisualizedInApplet()) {      customButton.setEnabled(false);    }    group = new ButtonGroup();    group.add(noneButton);    group.add(pre1Button);    group.add(pre2Button);    group.add(customButton);    graphicsComponentsPanel.add(noneButton);    graphicsComponentsPanel.add(pre1Button);    graphicsComponentsPanel.add(pre2Button);    graphicsComponentsPanel.add(customButton);    // Create visualize channel output panel    JPanel visualizeChannelPanel = new JPanel();    visualizeChannelPanel.setLayout(new BoxLayout(visualizeChannelPanel, BoxLayout.Y_AXIS));    visualizeChannelPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));    visualizeChannelPanel.setAlignmentX(Component.LEFT_ALIGNMENT);    // Channel coloring intervals    visualizeChannelPanel.add(new JLabel("Channel coloring:"));    JPanel fixedVsRelative = new JPanel(new GridLayout(1, 2));    JRadioButton fixedColoringButton = new JRadioButton("Fixed");    fixedColoringButton.setSelected(true);    fixedColoringButton.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        coloringIsFixed = true;      }    });    fixedVsRelative.add(fixedColoringButton);    JRadioButton relativeColoringButton = new JRadioButton("Relative");    relativeColoringButton.setSelected(true);    relativeColoringButton.addActionListener(new ActionListener() {      public void actionPerformed(ActionEvent e) {        coloringIsFixed = false;      }    });    fixedVsRelative.add(relativeColoringButton);    ButtonGroup coloringGroup = new ButtonGroup();    coloringGroup.add(fixedColoringButton);    coloringGroup.add(relativeColoringButton);    fixedVsRelative.setAlignmentX(Component.LEFT_ALIGNMENT);    visualizeChannelPanel.add(fixedVsRelative);    coloringIntervalPanel = new JPanel() {      public void paintComponent(Graphics g) {        super.paintComponent(g);

⌨️ 快捷键说明

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