public void actionPerformed(ActionEvent ae) {
   String cmd = ae.getActionCommand();
   if (JOkCancelPanel.OK.equals(cmd)) {
     // update evaluator
     evaluator.name = tfName.getText();
     evaluator.type = (byte) cbType.getSelectedIndex();
     evaluator.ignoreDiagonals = cbDiagonals.isSelected();
     evaluator.investments = (byte) cbInvestment.getSelectedIndex();
     evaluator.orgFile = orgFile;
     setVisible(false);
   } else if (JOkCancelPanel.CANCEL.equals(cmd)) {
     // don't update evaluator
     setVisible(false);
   } else if (CMD_CHOOSE_FILE.equals(cmd)) {
     // get a file dialog
     JFrame f = new JFrame();
     JFileChooser jfc = Application.getFileChooser();
     int res = jfc.showOpenDialog(f);
     Application.setWorkingDirectory(jfc.getCurrentDirectory());
     if (res == JFileChooser.CANCEL_OPTION) {
       return;
     }
     orgFile = jfc.getSelectedFile();
     lOrgFileName.setText("File: " + orgFile.getName());
   }
 }
Exemple #2
0
  public SpectrumPlot(double[] periods) {
    Application app = Application.getInstance();
    if (app.isUseFrequencies()) {
      xValues = new double[periods.length];
      for (int i = 0; i < periods.length; ++i) {
        xValues[xValues.length - i - 1] = 1 / periods[i];
      }
    } else {
      xValues = periods;
    }

    this.reference1 = readReference(Application.PropertySpecRef1);
    this.reference2 = readReference(Application.PropertySpecRef2);
    this.logScale = Application.getInstance().getProperty(Application.PropertySpecLogScale, false);
    // this.setBackground(BackgroundColor);
  }
Exemple #3
0
 public static void main(String[] args) {
   final Application app = new Application();
   if (args.length == 2 && args[0].equals("--screenshot")) {
     String fileName = args[1];
     app.initApplication();
     app.takeScreenshotOfDocument(fileName);
     app.quit();
   } else {
     if (args.length == 1) app.filesToLoad.add(new File(args[0]));
     SwingUtilities.invokeLater(
         new Runnable() {
           public void run() {
             app.run();
           }
         });
   }
 }
  public void actionPerformed(ActionEvent e) {
    /*
     * The menu is assigned to several menu bars. The listener is kept as
     * a separate class than the listeners already assigned to the actions
     * for the menu when created.
     */
    JMenu menuOfEventTrigger = Application.frame.getJMenuBar().getMenu(1);

    if (e.getSource() == menuOfEventTrigger.getItem(0)) LectureManager.goToFirstPage();
    else if (e.getSource() == menuOfEventTrigger.getItem(1)) LectureManager.goToLastPage();
    else if (e.getSource() == menuOfEventTrigger.getItem(2)) {
      Application.dialogLabel.setText(DialogLabelText.changeLectureMessage);

      byte selectedButton =
          (byte)
              (JOptionPane.showConfirmDialog(
                  null,
                  Application.dialogLabel,
                  "Change Lecture",
                  JOptionPane.YES_NO_OPTION,
                  JOptionPane.QUESTION_MESSAGE));

      if (selectedButton == JOptionPane.YES_OPTION) {
        Application.frame.setJMenuBar(Application.centralProgramMenuBar);

        CardLayout mainPanelLayout = (CardLayout) (Application.mainPanel.getLayout());
        Application.currentPanelName = Application.LECTURE_SELECT_NAME;
        mainPanelLayout.show(Application.mainPanel, Application.currentPanelName);
      }
    }
    // When the user clicks on the button to quit Lecture Mode.
    else if (e.getSource() == menuOfEventTrigger.getItem(3)) {
      Application.dialogLabel.setText(DialogLabelText.quitLectureModeMessage);

      byte selectedButton =
          (byte)
              (JOptionPane.showConfirmDialog(
                  null,
                  Application.dialogLabel,
                  "Quit Lecture Mode",
                  JOptionPane.YES_NO_OPTION,
                  JOptionPane.QUESTION_MESSAGE));

      if (selectedButton == JOptionPane.YES_OPTION) {
        Application.frame.setJMenuBar(Application.centralProgramMenuBar);

        Application.restartMainMenuThread();

        CardLayout mainPanelLayout = (CardLayout) (Application.mainPanel.getLayout());
        Application.currentPanelName = Application.MAIN_MENU_NAME;
        mainPanelLayout.show(Application.mainPanel, Application.currentPanelName);
      }
    }
  }
Exemple #5
0
  private List<Double> readReference(String key) {
    List<Double> refs = new ArrayList();

    String[] values = Application.getInstance().getProperty(key, "").split(",");
    for (String v : values) {
      if (refs.size() >= xValues.length) {
        LOG.warn("more reference values than periods specified in parameter: " + key);
        break;
      }
      refs.add(Double.parseDouble(v));
    }
    if (!refs.isEmpty() && refs.size() < xValues.length) {
      LOG.warn("fewer reference values than periods specified in parameter: " + key);
    }
    return refs;
  }
Exemple #6
0
  /**
   * Load the application information from the properties file specified by the application adaptor.
   * The resource bundle information is stored in a Map for convenient access.
   *
   * @param path Path to the source information.
   * @return The map containing the application information
   */
  private Map loadApplicationInfo(final String path) {
    Map infoMap;

    try {
      infoMap = Util.loadResourceBundle(path);
    } catch (MissingResourceException exception) {
      final String message = "No application \"About Box\" information resource found at: " + path;
      Logger.getLogger("global").log(Level.WARNING, message, exception);
      System.err.println(message);

      // substitute with default information
      infoMap = new HashMap();
      infoMap.put("name", Application.getAdaptor().getClass().getName());
    }

    return infoMap;
  }
Exemple #7
0
  @Override
  protected void paintComponent(Graphics g) {
    java.util.List<Network> networks = getNetworkParts();
    positions = new int[networks.size()];
    Graphics2D g2 = (Graphics2D) g;

    g2.setFont(SMALL_BOLD_FONT);

    g2.setPaint(addressGradientPaint);
    g2.fill(g2.getClipBounds());
    // g2.drawImage(addressGradient, 0, 0, getWidth(), 26, null);

    int x = 14;

    for (int i = 0; i < networks.size(); i++) {
      Network part = networks.get(i);
      if (i == armed) {
        g2.setColor(TEXT_ARMED_COLOR);
      } else {
        g2.setColor(TEXT_NORMAL_COLOR);
      }
      String displayName = part.getDisplayName();
      SwingUtils.drawShadowText(g2, displayName, x, 16);

      int width = (int) g2.getFontMetrics().stringWidth(displayName);
      x += width + 5;
      positions[i] = x + 10;
      g2.drawImage(addressArrow, x, 0, null);
      x += 15;
    }

    String version = Application.getInstance().getVersion();
    int versionX = getWidth() - g2.getFontMetrics().stringWidth(version) - 10;
    SwingUtils.drawShadowText(g2, version, versionX, 16);

    if (renderException != null) {
      g2.drawImage(addressExclamation, versionX - 30, 0, null);
    }
  }
Exemple #8
0
  public boolean openDocument(File file) {
    // Check if the document is already open.
    String path;
    try {
      path = file.getCanonicalPath();
      for (NodeBoxDocument doc : Application.getInstance().getDocuments()) {
        try {
          if (doc.getDocumentFile() == null) continue;
          if (doc.getDocumentFile().getCanonicalPath().equals(path)) {
            // The document is already open. Bring it to the front.
            doc.toFront();
            doc.requestFocus();
            NodeBoxMenuBar.addRecentFile(file);
            return true;
          }
        } catch (IOException e) {
          logger.log(
              Level.WARNING,
              "The document " + doc.getDocumentFile() + " refers to path with errors",
              e);
        }
      }
    } catch (IOException e) {
      logger.log(Level.WARNING, "The document " + file + " refers to path with errors", e);
    }

    try {
      NodeBoxDocument doc = NodeBoxDocument.load(file);
      addDocument(doc);
      NodeBoxMenuBar.addRecentFile(file);
      return true;
    } catch (RuntimeException e) {
      logger.log(Level.SEVERE, "Error while loading " + file, e);
      ExceptionDialog d = new ExceptionDialog(null, e);
      d.setVisible(true);
      return false;
    }
  }
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == submit) {
     if (rb1.isSelected()) {
       JFrame frame = Application.getFrame();
       if (typeCodes.isEmpty()) {
         JOptionPane.showMessageDialog(
             frame,
             "Please select at least one toponym type.",
             "Error",
             JOptionPane.ERROR_MESSAGE);
       } else {
         Application.getMainCitiesPanel(this, typeCodes, 0, 0.0);
       }
     } else if (rb2.isSelected()) {
       JFrame frame = Application.getFrame();
       try {
         nCities = new Integer(nCitiesField.getText());
         if (nCities <= 0) throw new NumberFormatException();
         typeCodes = new ArrayList<String>();
         Application.getMainCitiesPanel(this, typeCodes, nCities, 0.0);
       } catch (NumberFormatException ex) {
         JOptionPane.showMessageDialog(
             frame, "Please enter a positive integer number.", "Error", JOptionPane.ERROR_MESSAGE);
       }
     } else {
       JFrame frame = Application.getFrame();
       try {
         Double dist = new Double(distField.getText());
         if (dist <= 0) throw new NumberFormatException();
         typeCodes = new ArrayList<String>();
         Application.getMainCitiesPanel(this, typeCodes, 0, dist);
       } catch (NumberFormatException ex) {
         JOptionPane.showMessageDialog(
             frame, "Please enter a positive number.", "Error", JOptionPane.ERROR_MESSAGE);
       }
     }
   } else {
     Application.getOptionPanel(this, countryName);
   }
 }
 @SuppressWarnings("restriction")
 public static void appleForeground() {
   Application.getApplication().requestForeground(true);
 }
 @Override
 public void initView(Application a, View p) {
   if (a.isSharingToolsAmongViews()) {
     ((DrawView) p).setEditor(getSharedEditor());
   }
 }
Exemple #12
0
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    int width = getWidth() - Border.left - Border.right;
    int height = getHeight() - Border.top - Border.bottom;

    g2.translate(Border.left, Border.top);

    // create x and y axes
    g2.setColor(Color.black);
    g2.drawLine(0, height, width, height);
    g2.drawLine(0, 0, 0, height);

    g2.setFont(g2.getFont().deriveFont(10.0f));
    FontMetrics fm = g2.getFontMetrics();

    if (xValues.length == 0 || target == null || xValues[xValues.length - 1] <= 0) {
      return;
    }

    double factor;
    String yText;
    Application app = Application.getInstance();
    Shaking.Type t = app.getSpectrumParameter();
    if (t == Shaking.Type.PSA) {
      factor = Application.EarthAcceleration1;
      yText = t.toString().toUpperCase() + ", g";
    } else if (t == Shaking.Type.DRS) {
      factor = 100;
      yText = t.toString().toUpperCase() + ", cm";
    } else {
      LOG.warn("unsupported spectrum parameter: " + t.toString());
      return;
    }

    synchronized (target) {

      // determine min/max of x and y axis
      double xMin;
      double xMax;
      double dx = 0;
      if (logScale) {
        xMin = Math.log10(xValues[0]);
        xMax = Math.log10(xValues[xValues.length - 1]);
      } else {
        xMin = 0.0;
        xMax = xValues[xValues.length - 1];
      }
      if (xMax > xMin) {
        dx = (double) width / (xMax - xMin);
      }

      double yMin = 0;
      double yMax = 0;
      double dy = 0;
      boolean first = true;
      for (double v : reference1) {
        if (first) {
          first = false;
          /*yMin =*/ yMax = v;
        }
        /*yMin = Math.min(yMin, v);*/
        yMax = Math.max(yMax, v);
      }
      for (double v : reference2) {
        if (first) {
          first = false;
          /*yMin =*/ yMax = v;
        }
        /*yMin = Math.min(yMin, v);*/
        yMax = Math.max(yMax, v);
      }

      for (Shaking s : target.spectralValues) {
        if (first) {
          first = false;
          /*yMin =*/ yMax = s.expectedSI * factor;
        } else {
          /*yMin = Math.min(yMin, s.expectedSI * factor);*/
          yMax = Math.max(yMax, s.expectedSI * factor);
        }
        /*
        yMin = Math.min(yMin, s.expectedSI * factor);
        yMin = Math.min(yMin, s.percentile84 * factor);
        yMin = Math.min(yMin, s.percentile16 * factor);
        */
        yMax = Math.max(yMax, s.expectedSI * factor);
        yMax = Math.max(yMax, s.percentile84 * factor);
        yMax = Math.max(yMax, s.percentile16 * factor);
      }

      if (yMax > yMin) {
        dy = (double) height / (yMax - yMin);
      }

      List<Point> expectedPoints = new ArrayList();
      List<Point> percentile84Points = new ArrayList();
      List<Point> percentile16Points = new ArrayList();
      List<Point> ref1Points = new ArrayList();
      List<Point> ref2Points = new ArrayList();
      int x, y, iV;
      boolean isFreq = app.isUseFrequencies();
      for (int i = 0; i < xValues.length; i++) {

        if (logScale) {
          x = (int) ((Math.log10(xValues[i]) - xMin) / (xMax - xMin) * width);
        } else {
          x = (int) ((xValues[i] - xMin) / (xMax - xMin) * width);
        }

        iV = isFreq ? xValues.length - i - 1 : i;

        if (iV < target.spectralValues.size()) {
          Shaking s = target.spectralValues.get(iV);
          y = (int) ((yMax - s.expectedSI * factor) * dy);
          expectedPoints.add(new Point(x, y));
          y = (int) ((yMax - s.percentile84 * factor) * dy);
          percentile84Points.add(new Point(x, y));
          y = (int) ((yMax - s.percentile16 * factor) * dy);
          percentile16Points.add(new Point(x, y));
        }
        if (iV < reference1.size()) {
          y = (int) ((yMax - reference1.get(iV)) * dy);
          ref1Points.add(new Point(x, y));
        }
        if (iV < reference2.size()) {
          y = (int) ((yMax - reference2.get(iV)) * dy);
          ref2Points.add(new Point(x, y));
        }
      }

      // Y-axis
      String text;
      int halfAscent = fm.getAscent() / 2 - 1;
      double q = Math.log10(2 * (yMax - yMin) * 2 * fm.getHeight() / height);
      double rx = q - Math.floor(q);
      int d = rx < 0.3 ? 1 : rx > 0.7 ? 5 : 2;
      double tickStep = d * Math.pow(10, Math.floor(q - rx));
      for (double v = 0; v < yMax; v += tickStep) {
        y = height - (int) (v * dy) - 1;
        g2.drawLine(0, y, -TickLength, y);

        text = Double.toString(((int) (v * 1000.0 + 0.5)) / 1000.0);
        int w = (int) fm.getStringBounds(text, null).getWidth();
        g2.drawString(text, -TickLength - 3 - w, y + halfAscent);
      }

      // X-axis
      q = Math.log10(2 * (xMax - xMin) * 50 / width);
      rx = q - Math.floor(q);
      d = rx < 0.3 ? 1 : rx > 0.7 ? 5 : 2;
      tickStep = d * Math.pow(10, Math.floor(q - rx));
      for (double v = xMin; v < xMax; v += tickStep) {
        x = (int) ((v - xMin) * dx);
        g2.drawLine(x, height, x, height + TickLength);

        text = String.format("%.2f", logScale ? Math.pow(10, v) : v);
        // String text = Double.toString(logScale ? Math.pow(10, v) : v);//((int) (v * 1000.0 +
        // 0.5)) / 1000.0);
        int w = (int) fm.getStringBounds(text, null).getWidth();
        g2.drawString(text, x - w / 2, height + TickLength + 3 + fm.getAscent());
      }

      // axis label
      g2.setFont(g2.getFont().deriveFont(14.0f));

      AffineTransform orig = g2.getTransform();
      int w = (int) ((height + fm.getStringBounds(yText, null).getWidth()) / 2);
      g2.translate(-Border.left + fm.getAscent() + 7, w);
      g2.rotate(-Math.PI / 2);
      g2.drawString(yText, 0, 0);
      g2.setTransform(orig);

      text = "vibration " + (isFreq ? "frequency, Hz" : "period, s");
      g2.drawString(
          text,
          (int) ((width - fm.getStringBounds(text, null).getWidth()) / 2),
          height + TickLength + 3 + 2 * fm.getHeight());

      g2.setClip(0, 0, width, height);

      g2.setStroke(DefaultStroke);
      g2.setColor(Ref1Color);
      drawGraph(g2, ref1Points);
      g2.setColor(Ref2Color);
      drawGraph(g2, ref2Points);

      g2.setStroke(PercentileStroke);
      g2.setColor(ShakingColor);
      drawGraph(g2, percentile16Points);
      drawGraph(g2, percentile84Points);

      g2.setStroke(DefaultStroke);
      drawGraph(g2, expectedPoints);
    }
  }
 @SuppressWarnings("restriction")
 public static void doAppleFullscreen(JFrame window) {
   Application.getApplication().requestToggleFullScreen(window);
 }
    public void runEvaluator() {
      int nSize = r.getNodeCount();
      nodeValues = new Double[nSize];
      allValues = new Double[nSize][];
      for (int i = 0; i < nSize; i++) {
        allValues[i] = new Double[nSize];
      }

      // get Oj's
      double[] o = new double[nSize];
      if (orgFile == null) {
        for (int i = 0; i < nSize; i++) {
          o[i] = 1.0;
        }
      } else {
        try {
          FileInputStream fis = new FileInputStream(orgFile);
          InputStreamReader isr = new InputStreamReader(fis);
          BufferedReader in = new BufferedReader(isr, 8096);
          String line = in.readLine();

          // try to guess delimiters
          String delim = " ";
          if (line.indexOf('\t') != 0) {
            delim = "\t";
          } else if (line.indexOf(',') != 0) {
            delim = ",";
          }
          Hashtable values = new Hashtable();
          while (line != null) {
            StringTokenizer st = new StringTokenizer(line, delim);
            line = in.readLine();
            String key = st.nextToken().trim();
            if (st.hasMoreTokens()) {
              try {
                Double d = Double.valueOf(st.nextToken());
                values.put(key, d);
              } catch (NumberFormatException nfe) {
                // ignore?
              }
            }
          }
          fis.close();
          TreeSet missingActors = new TreeSet();
          for (int i = 0; i < nSize; i++) {
            String actorName = r.getParent().getActor(i).getName();
            Double oValue = (Double) values.get(actorName);
            if (oValue == null) {
              missingActors.add(actorName);
              o[i] = 1.0;
            } else {
              o[i] = oValue.doubleValue();
            }
          }
          if (missingActors.size() > 0) {
            String errorMsg = "Couldn't find organization values for ";
            if (missingActors.size() <= 10) {
              Iterator iter = missingActors.iterator();
              errorMsg += "'" + iter.next() + "'";
              while (iter.hasNext()) {
                errorMsg += ", '" + iter.next() + "'";
              }
              errorMsg += ".";
            } else {
              errorMsg += missingActors.size() + " actors.";
            }
            JFrame f = new JFrame();
            JOptionPane.showMessageDialog(
                f, errorMsg, "Missing Values", JOptionPane.WARNING_MESSAGE);
          }
        } catch (IOException ioe) {
          Application.handleNonFatalThrowable(ioe);
        }
      }

      // i think i need to calculate all p_ij's
      double[][] p = new double[nSize][];
      for (int i = 0; i < nSize; i++) {
        p[i] = new double[nSize];
        double i_out = 0.0;
        for (int j = 0; j < nSize; j++) {
          if ((i != j) || (!ignoreDiagonals)) {
            if (investments == OUTBOUND || investments == BOTH) {
              i_out += r.getTieStrength(i, j);
            }
            if (investments == INBOUND || investments == BOTH) {
              i_out += r.getTieStrength(j, i);
            }
          }
        }

        for (int j = 0; j < nSize; j++) {
          p[i][j] = 0.0;
          if (i_out != 0.0) {
            if (investments == OUTBOUND || investments == BOTH) {
              p[i][j] += r.getTieStrength(i, j) / i_out;
            }
            if (investments == INBOUND || investments == BOTH) {
              p[i][j] += r.getTieStrength(j, i) / i_out;
            }
          }
        }
      }

      switch (type) {
          // implementation of Burt (1992: 64) equation 2.7
        case CONSTRAINT:
          for (int i = 0; i < nSize; i++) {
            double i_total = 0.0;
            allValues[i][i] = new Double(Double.NaN);
            for (int j = 0; j < nSize; j++) {
              if (i != j) {
                double c_sum = p[i][j];
                for (int q = 0; q < nSize; q++) {
                  if ((q != i) && (q != j)) {
                    c_sum += p[i][q] * p[q][j];
                  }
                }
                double c_ij = c_sum * c_sum * o[j];
                i_total += c_ij;
                allValues[i][j] = new Double(c_ij);
              }
            }
            nodeValues[i] = new Double(i_total);
          }
          break;

        case EFFECTIVE_SIZE:
          break;
      }
    }
Exemple #15
0
 /**
  * Get the file path of the information source of the about box.
  *
  * @return the file path of the application about box information
  */
 private static String getInfoSource() {
   return Application.getAdaptor().getApplicationInfoPath();
 }
Exemple #16
0
 public void windowClosing(WindowEvent e) {
   this.setVisible(false);
   Application.exitApplication();
 }
Exemple #17
0
 /** Creates a new instance of AboutBox */
 public AboutBox(final String infoSource) {
   _title = "About " + Application.getAdaptor().applicationName();
   _message = generateMessage(infoSource);
 }
  public MainCitiesCriteriaPanel() {
    super(new BorderLayout());

    CountryController countryc = Application.getCountryController();
    CitiesController citiesc = Application.getCitiesController();
    countryName = Application.getCountryName();

    label = new JLabel();
    labelPanel = new JPanel();
    labelPanel.add(label);

    label.setText("Criteria to select main cities for " + countryName.replaceAll("_", " "));

    listModel = new DefaultListModel();

    Iterator<HashMap<String, String>> iter = citiesc.getToponymTypesIterator();
    while (iter.hasNext()) {
      String topTypeName = iter.next().get("code");
      listModel.addElement(topTypeName);
    }
    list = new JList(listModel);
    list.addListSelectionListener(this);
    listPanel = new JScrollPane(list);

    NumberFormat nCitiesFormat = NumberFormat.getInstance();
    nCitiesFormat.setMaximumFractionDigits(0);
    nCitiesFormat.setMaximumIntegerDigits(4);

    NumberFormat distFormat = NumberFormat.getInstance();
    distFormat.setMaximumFractionDigits(0);
    distFormat.setMaximumIntegerDigits(3);

    nCitiesField = new JFormattedTextField(nCitiesFormat);
    distField = new JFormattedTextField(distFormat);

    nCitiesField.setMaximumSize(new Dimension(50, 1));
    distField.setMaximumSize(new Dimension(50, 1));

    rb1 = new JRadioButton("Filter by type", true);
    rb2 = new JRadioButton("Filter by number", false);
    rb3 = new JRadioButton("Filter by distance to the borders (km)", false);

    ButtonGroup bgroup = new ButtonGroup();

    bgroup.add(rb1);
    bgroup.add(rb2);
    bgroup.add(rb3);

    JPanel radioPanel = new JPanel();

    radioPanel.setLayout(new BoxLayout(radioPanel, BoxLayout.Y_AXIS));
    radioPanel.add(rb1);
    radioPanel.add(listPanel);
    radioPanel.add(rb2);
    radioPanel.add(nCitiesField);
    radioPanel.add(rb3);
    radioPanel.add(distField);

    submit = new JButton();
    back = new JButton();

    submit.setText("OK");
    back.setText("GO BACK");
    submit.addActionListener(this);
    back.addActionListener(this);

    buttonPanel = new JPanel();
    buttonPanel.add(back);
    buttonPanel.add(submit);

    add(labelPanel, BorderLayout.NORTH);
    add(radioPanel, BorderLayout.CENTER);
    add(buttonPanel, BorderLayout.SOUTH);
  }