Ejemplo n.º 1
0
 public InviteMsgTimer() {
   try {
     dist = Distribution.getDistributionFromConfigFile("Antenna/InviteIntervall");
     refreshRate = Configuration.getIntegerParameter("Antenna/refreshRate");
   } catch (CorruptConfigurationEntryException e) {
     Tools.fatalError(e.getMessage());
   }
 }
Ejemplo n.º 2
0
 /** Creates a new Drop Rate Reliability Model instance. */
 public LossyDelivery() {
   try {
     dropRate = Configuration.getDoubleParameter("LossyDelivery/dropRate");
   } catch (CorruptConfigurationEntryException e) {
     Main.fatalError(
         "Missing configuration entry for the Message Transmission Model:\n" + e.getMessage());
   }
 }
Ejemplo n.º 3
0
 /**
  * This method overwrites the values in the config file by the ones set in the project selector
  * configuration.
  */
 private void setFrameworkConfig() {
   for (ConfigEntry e : projectEntries) {
     if (e.valueComponent == null) {
       continue; // this entry does not have a value - its probably a section header
     }
     String value = "";
     if (e.valueComponent instanceof JComboBox) {
       value = (String) ((JComboBox) e.valueComponent).getSelectedItem();
     } else {
       value = ((JTextComponent) e.valueComponent).getText();
     }
     Configuration.setFrameworkConfigurationEntry(e.key, value);
   }
 }
Ejemplo n.º 4
0
  /**
   * The default constructor for this class.
   *
   * <p>The first time this constructor is called, it initializes the static parameters of this
   * class. This approach is necessary as to give proper error reporting if one of the
   * initialization steps fails.
   *
   * @throws CorruptConfigurationEntryException If one of the initialization steps fails.
   */
  public QUDG() throws CorruptConfigurationEntryException {
    // only call the first time a QUDG object is created
    if (!initialized) {
      // speed up by comparing the squared distances (needs not take the square root to get the
      // distance)
      r_min = Configuration.getDoubleParameter("QUDG/rMin");
      r_min_squared = r_min * r_min;

      r_max = Configuration.getDoubleParameter("QUDG/rMax");
      r_max_squared = r_max * r_max;

      // Sanity check
      double geomNodeRMax = Configuration.getDoubleParameter("GeometricNodeCollection/rMax");
      if (r_max > geomNodeRMax) { // dangerous! This is probably not what the user wants!
        Main.minorError(
            "WARNING: The maximum transmission range used for the QUDG connectivity model is larger than the maximum transmission range specified for the GeometricNodeCollection.\nAs a result, not all connections will be found! Either fix the problem in the project-specific configuration file or the '-overwrite' command line argument.");
      }
      if (r_max <= r_min) {
        Main.minorError(
            "WARNING: The maximum transmission range used for the QUDG connectivity model is not larger than the minimum tansmission range.\nEither fix the problem in the project-specific configuration file or the '-overwrite' command line argument.");
      }

      // TODO: rewrite the docu of this class
      String type = Configuration.getStringParameter("QUDG/ProbabilityType");
      if (type.toLowerCase().equals("constant")) {
        probabilityType = 0;
        probability = Configuration.getDoubleParameter("QUDG/connectionProbability");
      } else if (type.toLowerCase().equals("linear")) {
        probabilityType = 1;
        m = 1 / (r_min - r_max);
        q = r_max / (r_max - r_min);
      } else if (type.toLowerCase().equals("quadratic")) {
        probabilityType = 2;
        throw new NotYetImplementedException(
            "QUDG does not yet support quadratic probability distributions.");
      } else {
        // TODO: rewrite the following exception, rewrite docu as well
        throw new CorruptConfigurationEntryException(
            "The QUDG connectivity model requires an entry in the project"
                + " configuration file that specifies the kind of probability to be applied if the distance between two nodes "
                + "lies between rMin and rMax. Possible values for ProbabilityType are 'constant', 'linear', and 'quadratic'.\n\n"
                + "'constant' requires yet another entry 'connectionProbability', which specifies the constant probability at which the connection exists.\n\n"
                + "'linear' applies a linear regression that decreases from 1 to 0 from rMin to rMax.\n\n"
                + "'quadratic' applies a quadratic regression that decreases from 1 to 0 from rMin to rMax.\n\n");
      }

      probability = Configuration.getDoubleParameter("QUDG/connectionProbability");
      initialized = true;
    }
  }
Ejemplo n.º 5
0
  /**
   * Generate the GUI components to show the config for a given project
   *
   * @param projectName
   */
  private void generateGUIGonfiguration(String projectName) {
    boolean configExists = true;

    Element frameworkElement = null;

    String configFileName =
        Configuration.sourceDirPrefix
            + "/"
            + Configuration.projectDirInSourceFolder
            + "/"
            + projectName
            + "/"
            + Configuration.configfileFileName;
    File configFile = new File(configFileName);
    if (!configFile.exists()) {
      configExists = false;
    } else
      try {
        Document doc = new SAXBuilder().build(configFile);
        Element root = doc.getRootElement();
        frameworkElement = root.getChild("Framework");
        Element custom = root.getChild("Custom");
        if (custom == null) {
          Main.fatalError(
              "Invalid configuration file: A Custom entry is missing.\n"
                  + "The file needs to be of the following form: \n"
                  + "<Document>\n  <Framework>...</Framework>\n  <Custom></Custom>\n</Document>");
        }
        if (frameworkElement == null) {
          Main.fatalError(
              "Invalid configuration file: A 'framework' entry is missing.\n"
                  + "The file needs to be of the following form: \n"
                  + "<Document>\n  <Framework>...</Framework>\n  <Custom></Custom>\n</Document>");
        }
      } catch (JDOMException e1) {
        Main.fatalError("Invalid configuration file:\n\n" + e1.getMessage());
      } catch (IOException e1) {
        Main.fatalError("Cannot open or read from configuration file:\n\n" + e1.getMessage());
      }

    projectEntries = new Vector<ConfigEntry>();

    String sectionName = "";

    Class<?> configClass = Configuration.class;
    // We assume here that the fields are returned in the order they are listed in the java file!
    Field[] fields = configClass.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
      Field field = fields[i];
      try {
        // read the annotations for this field
        Configuration.DefaultInConfigFile dan =
            field.getAnnotation(Configuration.DefaultInConfigFile.class);
        Configuration.OptionalInConfigFile oan =
            field.getAnnotation(Configuration.OptionalInConfigFile.class);
        Configuration.SectionInConfigFile san =
            field.getAnnotation(Configuration.SectionInConfigFile.class);
        if (dan != null || oan != null) {
          if (san != null) { // get the title
            sectionName = san.value();
            projectEntries.add(
                new ConfigEntry(
                    sectionName, "", Configuration.SectionInConfigFile.class, "", false, field));
          }
          String description = dan != null ? dan.value() : oan.value(); // the description text
          // test whether the XML file contains an entry for this field
          String value = null;
          if (configExists) {
            Element e = frameworkElement.getChild(field.getName());
            if (e != null) {
              value = e.getAttributeValue("value"); // null if not there
            }
          }
          if (value == null) {
            // there was no entry in the config-file. Take the default value.
            projectEntries.add(
                new ConfigEntry(
                    field.getName(),
                    Configuration.getConfigurationText(field.get(null)),
                    field.getType(),
                    description,
                    oan != null,
                    field));
          } else { // there is an entry in the XML file
            projectEntries.add(
                new ConfigEntry(
                    field.getName(),
                    value,
                    field.getType(),
                    description,
                    oan != null,
                    field)); // elem.comment
          }
        } else if (field.getName().equals("edgeType")) {
          // NOTE: the edgeType member does not carry any annotations (exception)
          String comment = "The default type of edges to be used";
          String value = null;
          if (configExists) {
            Element e = frameworkElement.getChild(field.getName());
            if (e != null) {
              value = e.getAttributeValue("value"); // null if not there
            }
          }
          if (value == null) {
            // there was no entry in the config-file. Take the default value.
            projectEntries.add(
                new ConfigEntry(
                    field.getName(),
                    Configuration.getEdgeType(),
                    field.getType(),
                    comment,
                    oan != null,
                    field));
          } else {
            projectEntries.add(
                new ConfigEntry(
                    field.getName(), value, field.getType(), comment, oan != null, field));
          }
        }
      } catch (IllegalArgumentException e) {
        Main.fatalError(e);
      } catch (IllegalAccessException e) {
        Main.fatalError(e);
      }
    }

    // for each entry, create the corresponding GUI components

    asynchronousSimulationCB = null;
    mobilityCB = null;
    for (ConfigEntry e : projectEntries) {
      String ttt =
          e.comment.equals("")
              ? null
              : e.comment; // the tool tip text, don't show at all, if no text to display

      // creating the text field
      UnborderedJTextField label;
      if (e.entryClass == Configuration.SectionInConfigFile.class) {
        label = new UnborderedJTextField(e.key.toString(), Font.BOLD);
      } else {
        label = new UnborderedJTextField("         " + e.key.toString(), Font.PLAIN);
      }
      label.setToolTipText(ttt);
      e.textComponent = label;

      if (e.entryClass == boolean.class) {
        String[] ch = {"true", "false"};
        MultiLineToolTipJComboBox booleanChoice = new MultiLineToolTipJComboBox(ch);
        if ((e.value).compareTo("true") != 0) {
          booleanChoice.setSelectedItem("false");
        } else {
          booleanChoice.setSelectedItem("true");
        }
        booleanChoice.addActionListener(
            userInputListener); // ! add this listener AFTER setting the value!
        booleanChoice.setToolTipText(ttt);
        e.valueComponent = booleanChoice;
        // special case: mobility can only be changed if simulation is in sync mode.
        if (e.key.equals("asynchronousMode")) {
          asynchronousSimulationCB = booleanChoice;
          if (mobilityCB != null && (e.value).equals("true")) {
            mobilityCB.setSelectedItem("false");
            mobilityCB.setEnabled(false);
          }
        }
        if (e.key.equals("mobility")) {
          mobilityCB = booleanChoice;
          if (asynchronousSimulationCB != null
              && asynchronousSimulationCB.getSelectedItem().equals("true")) {
            mobilityCB.setSelectedItem("false");
            mobilityCB.setEnabled(false);
          }
        }
      } else if (e.entryClass == Configuration.SectionInConfigFile.class) {
        e.valueComponent = null; // there's no component for the section
      } else {
        // special case for some text fields that expect the name of an implementation. They
        // should show the available implementations in a drop down field
        ImplementationChoiceInConfigFile ian =
            e.field.getAnnotation(ImplementationChoiceInConfigFile.class);
        if (ian != null) {
          Vector<String> ch = Global.getImplementations(ian.value(), true);
          MultiLineToolTipJComboBox choice = new MultiLineToolTipJComboBox(ch);
          choice.setEditable(
              true); // let the user the freedom to enter other stuff (which is likely to be
                     // wrong...)
          choice.setSelectedItem(e.value);
          choice.addActionListener(
              userInputListener); // ! add this listener AFTER setting the value!
          choice.setToolTipText(ttt);
          e.valueComponent = choice;
        } else {
          if (e.key.equals("javaCmd")) { // special case - this field may contain a lot of text
            JTextArea textArea = new MultiLineToolTipJTextArea(e.value.toString());
            textArea.setToolTipText(ttt);
            textArea.setBorder((new JTextField()).getBorder()); // copy the border
            textArea.setLineWrap(true);
            // textArea.setPreferredSize(new Dimension(50, 30));
            textArea.addKeyListener(userInputListener);
            e.valueComponent = textArea;
          } else {
            MultiLineToolTipJTextField textField =
                new MultiLineToolTipJTextField(e.value.toString());
            textField.setToolTipText(ttt);
            textField.addKeyListener(userInputListener);
            e.valueComponent = textField;
          }
        }
      }
    }
    // and finally add all the entries
    insertProjectEntries();

    customConfigurationPanel.removeAll();

    // And add the custom entries

    //   this code snipped was used to redirect the mouse wheel applied on this
    //   text field to the entire tab when the custom config was below the framework config
    //		// remove all mouse wheel listeners from the text input
    //		for(MouseWheelListener mwl : customParameters.getMouseWheelListeners()) {
    //			customParameters.removeMouseWheelListener(mwl);
    //		}
    //		// and add the 'global' one
    //		customParameters.addMouseWheelListener(new
    // MouseWheelForwarder(scrollableConfigurationPane.getMouseWheelListeners()));

    customParameters.setTabSize(3);
    customParameters.setLineWrap(true);
    customParameters.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

    if (configExists) {
      customParameters.setText(getCustomText(configFile));
    } else {
      customParameters.setText("");
    }

    customParameters.addKeyListener(
        userInputListener); // ! add this listener AFTER setting the text !

    JScrollPane customScroll =
        new JScrollPane(
            customParameters,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    customScroll.setWheelScrollingEnabled(true);
    customConfigurationPanel.add(customScroll);

    userInputListener.reset();

    super.repaint();
  }