Example #1
0
 private void onApply(boolean applyToAllRows) {
   try {
     applyGroupPropToTable(applyToAllRows);
   } catch (NumberFormatException e) {
     JOptionPane.showMessageDialog(this, "Invalid value: " + e.getMessage());
   }
 }
 public static int parseInteger(String s) {
   try {
     return (Integer.parseInt(s));
   } catch (NumberFormatException ex) {
     JOptionPane.showMessageDialog(
         null, ex.getMessage(), "Invalid number", JOptionPane.ERROR_MESSAGE);
     return (-1);
   }
 }
  private static int getGeoKeyAsInt(final int key, final GeoTiffIIOMetadataDecoder metadata) {

    try {
      return Integer.parseInt(metadata.getGeoKey(key));
    } catch (NumberFormatException ne) {
      SystemUtils.LOG.log(Level.FINE, ne.getMessage(), ne);
      return GeoTiffConstants.UNDEFINED;
    }
  }
Example #4
0
 /**
  * Return a integer parsed from the value associated with the given key, or "def" in key wasn't
  * found.
  */
 public static int parseProperty(Properties preferences, String key, int def) {
   String val = preferences.getProperty(key);
   if (val == null) return def;
   try {
     return Integer.parseInt(val);
   } catch (NumberFormatException nfe) {
     nfe.printStackTrace();
     return def;
   }
 }
Example #5
0
 /** @return the pot */
 public static int getPort() {
   int port = 0;
   try {
     port = Integer.parseInt(pot.getText());
   } catch (NumberFormatException f) {
     f.printStackTrace();
     new WhatIDo("Entrer un port valide", f.toString());
   }
   return port;
 }
 /**
  * Returns the editted value.
  *
  * @return the editted value.
  * @throws TagFormatException if the tag value cannot be retrieved with the expected type.
  */
 public TagValue getTagValue() throws TagFormatException {
   try {
     long numer = Long.parseLong(m_numer.getText());
     long denom = Long.parseLong(m_denom.getText());
     Rational rational = new Rational(numer, denom);
     return new TagValue(m_value.getTag(), rational);
   } catch (NumberFormatException e) {
     e.printStackTrace();
     throw new TagFormatException(
         m_numer.getText() + "/" + m_denom.getText() + " is not a valid rational");
   }
 }
    public void actionPerformed(ActionEvent e) {
      JTextField fieldEdited = (JTextField) e.getSource();
      try {
        systemOrder = Integer.parseInt(fieldEdited.getText());
      } catch (NumberFormatException nfex) {
        System.out.println("Number format exception in getting system order");
        nfex.printStackTrace();
      }

      String updatedStatusText = prepareStatusText();
      statusAreaTop.setText(updatedStatusText);
    }
Example #8
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == cancel) dispose();
   else
     try {
       long wohin = Long.parseLong(postf.getText(), 16);
       long wieweit = Long.parseLong(sizetf.getText(), 16);
       if (parent.hv.goTo(wohin, wieweit)) dispose();
     } catch (NumberFormatException ex) {
       postf.setText(ex.toString());
       return;
     }
 }
  /** Utility method that will load mortgage data from a file. */
  private void loadMortgages() {
    // create a list of mortgages so we can dynamically add as many as our
    // data file allows. the first entry is always our default
    // "user entered" value so the combo box works consistently...
    final LinkedList mortgages = new LinkedList();
    mortgages.add(LABEL_USER_ENTERED_CHOICE);

    try {
      final InputStream resource =
          getClass().getClassLoader().getResourceAsStream(FILENAME_MORTGAGE_DATA);
      if (resource == null) {
        throw new IOException(FILENAME_MORTGAGE_DATA + " not found");
      }
      final BufferedReader reader = new BufferedReader(new InputStreamReader(resource));

      String line;
      while ((line = reader.readLine()) != null) {
        // split the line of data into tokens separated by commas; if
        // there are two tokens found, we assume we have a valid line
        // of data that can be parsed into rate and term values
        final String[] values = line.split(",");
        if (values.length == 2) {
          final double rate = Double.parseDouble(values[0].trim());
          final int term = Integer.parseInt(values[1].trim());

          // add a new set of mortgage terms to the list; the term
          // must be divided by 12 to convert to the number of years
          mortgages.add(new Mortgage(rate, term / 12));
        }
      }
    } catch (IOException ex) {
      JOptionPane.showMessageDialog(
          getRootPane(), ERR_DATA_FILE_IOERR, ERR_DATA_FILE_ERROR, JOptionPane.ERROR_MESSAGE);
      ex.printStackTrace(System.err);
    } catch (NumberFormatException ex) {
      JOptionPane.showMessageDialog(
          getRootPane(), ERR_DATA_FILE_CORRUPT, ERR_DATA_FILE_ERROR, JOptionPane.ERROR_MESSAGE);
      ex.printStackTrace(System.err);
    }

    fieldMortgageChoices.setModel(new DefaultComboBoxModel(mortgages.toArray()));
  }
Example #10
0
  private void processFrames(Element element) {
    NodeList elements = element.getChildNodes();
    if (elements.getLength() > 0) {
      Map<String, ReferenceFrame> frames = new HashMap();
      for (ReferenceFrame f : FrameManager.getFrames()) {
        frames.put(f.getName(), f);
      }
      List<ReferenceFrame> reorderedFrames = new ArrayList();

      for (int i = 0; i < elements.getLength(); i++) {
        Node childNode = elements.item(i);
        if (childNode.getNodeName().equalsIgnoreCase(SessionElement.FRAME.getText())) {
          String frameName = getAttribute((Element) childNode, SessionAttribute.NAME.getText());

          ReferenceFrame f = frames.get(frameName);
          if (f != null) {
            reorderedFrames.add(f);
            try {
              String chr = getAttribute((Element) childNode, SessionAttribute.CHR.getText());
              final String startString =
                  getAttribute((Element) childNode, SessionAttribute.START.getText())
                      .replace(",", "");
              final String endString =
                  getAttribute((Element) childNode, SessionAttribute.END.getText())
                      .replace(",", "");
              int start = ParsingUtils.parseInt(startString);
              int end = ParsingUtils.parseInt(endString);
              org.broad.igv.feature.Locus locus = new Locus(chr, start, end);
              f.jumpTo(locus);
            } catch (NumberFormatException e) {
              e.printStackTrace(); // To change body of catch statement use File | Settings |
              // File Templates.
            }
          }
        }
      }
      if (reorderedFrames.size() > 0) {
        FrameManager.setFrames(reorderedFrames);
      }
    }
    IGV.getInstance().resetFrames();
  }
Example #11
0
 @Override
 public void actionPerformed(ActionEvent e) {
   try {
     if (e.getSource() == ok_button) {
       if (mainFrame != null) {
         Client client =
             new Client(serverAddress.getText(), Integer.parseInt(serverPort.getText()), 0);
         if (client.getClientThread().getClientSocket().isConnected()) mainFrame.setClient(client);
       }
       this.setVisible(false);
       this.dispose();
     } else if (e.getSource() == cancel_button) {
       mainFrame.setClient(null);
       this.setVisible(false);
       this.dispose();
     }
   } catch (NumberFormatException exception) {
     JOptionPane.showMessageDialog(this, "Invalid value: " + exception.getMessage());
   }
 }
Example #12
0
 /**
  * @return a double parsed from the value associated with the given key in the given Properties.
  *     returns "def" in key wasn't found, or if a parsing error occured. If "value" contains a "%"
  *     sign, we use a <code>NumberFormat.getPercentInstance</code> to convert it to a double.
  */
 public static double parseProperty(Properties preferences, String key, double def) {
   NumberFormat formatPercent = NumberFormat.getPercentInstance(Locale.US); // for zoom factor
   String val = preferences.getProperty(key);
   if (val == null) return def;
   if (val.indexOf("%") == -1) { // not in percent format !
     try {
       return Double.parseDouble(val);
     } catch (NumberFormatException nfe) {
       nfe.printStackTrace();
       return def;
     }
   }
   // else it's a percent format -> parse it
   try {
     Number n = formatPercent.parse(val);
     return n.doubleValue();
   } catch (ParseException ex) {
     ex.printStackTrace();
     return def;
   }
 }
Example #13
0
  protected void getDimensionsFromLogFile(BufferedReader reader, PicText text) {
    if (reader == null) {
      return;
    }
    String line = ""; // il rale si j'initialise pas ...
    boolean finished = false;
    while (!finished) {
      try {
        line = reader.readLine();
      } catch (IOException ioex) {
        ioex.printStackTrace();
        return;
      }
      if (line == null) {
        System.out.println("Size of text not found in log file...");
        return;
      }

      System.out.println(line);
      Matcher matcher = LogFilePattern.matcher(line);

      if (line != null && matcher.find()) {
        System.out.println("FOUND :" + line);
        finished = true;
        try {
          text.setDimensions(
              0.3515 * Double.parseDouble(matcher.group(1)), // height, pt->mm (1pt=0.3515 mm)
              0.3515 * Double.parseDouble(matcher.group(2)), // width
              0.3515 * Double.parseDouble(matcher.group(3))); // depth
          areDimensionsComputed = true;
        } catch (NumberFormatException e) {
          System.out.println("Logfile number format problem: $line" + e.getMessage());
        } catch (IndexOutOfBoundsException e) {
          System.out.println("Logfile regexp problem: $line" + e.getMessage());
        }
      }
    }
    return;
  }
    public ImageFormatter serviceRequest(IMapRequest req) throws IOException, WMSServiceException {
      int reqWidth = 512;
      int reqHeight = 512;

      this.threadId = Thread.currentThread().getId();

      MapSource myMapSource = CompoundImageryGenerator.this.mapSource;
      Logging.logger()
          .info("START CompoundServiceInstance :: serviceRequest( " + myMapSource.getName() + ")");
      try {
        Integer bgColor = CompoundImageryGenerator.DEFAULT_MISSING_DATA_COLOR;
        String bgColorStr = req.getBGColor();
        if (bgColorStr != null && 0 < bgColorStr.length()) {
          try {
            bgColor = Integer.parseInt(bgColorStr, 16);
          } catch (NumberFormatException ex) {
            Logging.logger()
                .severe("Unable to parse BGCOLOR in get imagery request: " + ex.getMessage());
            bgColor = CompoundImageryGenerator.DEFAULT_MISSING_DATA_COLOR;
          }
        } else
          Logging.logger()
              .severe(
                  "BGCOLOR was not specified in the getImagery request: using default " + bgColor);

        req.setBGColor(bgColor.toString());

        reqWidth = (req.getWidth() > 0) ? req.getWidth() : 512;
        req.setWidth(reqWidth);

        reqHeight = (req.getHeight() > 0) ? req.getHeight() : 512;
        req.setHeight(reqHeight);

        Sector reqSector =
            Sector.fromDegrees(
                req.getBBoxYMin(), req.getBBoxYMax(), req.getBBoxXMin(), req.getBBoxXMax());

        double reqPixelSize = reqSector.getDeltaLatDegrees() / reqHeight;
        MapSource reqMapSource = null;

        for (Iterator<MapSource> iterator = myMapSource.getChildren(); iterator.hasNext(); ) {
          MapSource ms = iterator.next();
          MapGenerator gen = (null != ms) ? ms.getMapGenerator() : null;
          if (null == gen) {
            Logging.logger()
                .severe("child mapSource `" + ms.getName() + "` has no associated map generator!");
            continue;
          }
          Sector bbox = gen.getBBox();
          Logging.logger()
              .info(
                  "found child mapSource `" + ms.getName() + "` with generator: " + gen.toString());
          if (!reqSector.intersects(bbox)) {
            Logging.logger()
                .info(
                    "child mapSource`"
                        + ms.getName()
                        + "`: out of coverage, skipping"
                        + bbox.toString());
            continue;
          }

          double genPixelSize = gen.getPixelSize();
          reqMapSource =
              ms; // assumes layers are configured in order according to resolutions from low to
          // high
          Logging.logger()
              .info(
                  "Comparing texel sizes: req = "
                      + reqPixelSize
                      + " , layer's = "
                      + gen.getPixelSize());
          if (reqPixelSize >= genPixelSize) {
            // satisfactory generator found
            break;
          }
        }

        ImageFormatter fmt = null;
        if (null != reqMapSource) {
          try {
            MapGenerator gen = reqMapSource.getMapGenerator();
            Logging.logger()
                .info(
                    "`"
                        + reqMapSource.getName()
                        + "` is executing request; req texel size = "
                        + reqPixelSize
                        + " where layer's texel size = "
                        + gen.getPixelSize());
            fmt = gen.getServiceInstance().serviceRequest(req);
          } catch (Exception ex) {
            Logging.logger().severe("Error while accessing a child mapSource: " + ex.getMessage());
          }
        }

        if (null == fmt) {
          Logging.logger().info("CompoundImageryGenerator will return an empty transparent image");
          fmt = createEmptyImage(req.getWidth(), req.getHeight(), new Color(bgColor));
        }
        return fmt;
      } catch (Exception ex) {
        String msg = Logging.getMessage("WMS.RequestFailed", ex.getMessage());
        Logging.logger().log(java.util.logging.Level.SEVERE, msg, ex);
        throw new WMSServiceException(msg);
      }
    }