예제 #1
0
 /** Try to convert a string value into a numerical value. */
 private static Number createNumberFromStringValue(String value) throws NumberFormatException {
   final String suffix = value.substring(value.length() - 1);
   if ("L".equalsIgnoreCase(suffix)) {
     return Long.valueOf(value.substring(0, value.length() - 1));
   }
   if ("F".equalsIgnoreCase(suffix)) {
     return Float.valueOf(value.substring(0, value.length() - 1));
   }
   if ("D".equalsIgnoreCase(suffix)) {
     return Double.valueOf(value.substring(0, value.length() - 1));
   }
   try {
     return Integer.valueOf(value);
   } catch (NumberFormatException e) {
     // OK: Ignore exception...
   }
   try {
     return Long.valueOf(value);
   } catch (NumberFormatException e1) {
     // OK: Ignore exception...
   }
   try {
     return Double.valueOf(value);
   } catch (NumberFormatException e2) {
     // OK: Ignore exception...
   }
   throw new NumberFormatException(
       "Cannot convert string value '" + value + "' into a numerical value");
 }
예제 #2
0
  /**
   * Creates the tool context denoting the range of samples that should be analysed by a tool.
   *
   * @return a tool context, never <code>null</code>.
   */
  private ToolContext createToolContext() {
    int startOfDecode = -1;
    int endOfDecode = -1;

    final int dataLength = this.dataContainer.getValues().length;
    if (this.dataContainer.isCursorsEnabled()) {
      if (this.dataContainer.isCursorPositionSet(0)) {
        final Long cursor1 = this.dataContainer.getCursorPosition(0);
        startOfDecode = this.dataContainer.getSampleIndex(cursor1.longValue()) - 1;
      }
      if (this.dataContainer.isCursorPositionSet(1)) {
        final Long cursor2 = this.dataContainer.getCursorPosition(1);
        endOfDecode = this.dataContainer.getSampleIndex(cursor2.longValue()) + 1;
      }
    } else {
      startOfDecode = 0;
      endOfDecode = dataLength;
    }

    startOfDecode = Math.max(0, startOfDecode);
    if ((endOfDecode < 0) || (endOfDecode >= dataLength)) {
      endOfDecode = dataLength - 1;
    }

    return new DefaultToolContext(startOfDecode, endOfDecode);
  }
예제 #3
0
 public void updateValues() {
   String snipeAtCfg = JConfig.queryConfiguration("snipemilliseconds", "30000");
   String autoSubtractShipping = JConfig.queryConfiguration("snipe.subtract_shipping", "false");
   long snipeAt = Long.parseLong(snipeAtCfg);
   snipeTime.setText(Long.toString(snipeAt / 1000));
   autoSubtractShippingBox.setSelected(autoSubtractShipping.equals("true"));
 }
예제 #4
0
  public void apply() {
    long newSnipeAt = Long.parseLong(snipeTime.getText()) * 1000;

    //  Set the default snipe for everything to be whatever was typed in.
    JConfig.setConfiguration("snipemilliseconds", Long.toString(newSnipeAt));
    JConfig.setConfiguration(
        "snipe.subtract_shipping", autoSubtractShippingBox.isSelected() ? "true" : "false");
  }
예제 #5
0
 /**
  * Goes to the current cursor position of the cursor with the given index.
  *
  * @param aCursorIdx the index of the cursor to go to, >= 0 && < 10.
  */
 public void gotoCursorPosition(final int aCursorIdx) {
   if ((this.mainFrame != null) && this.dataContainer.isCursorsEnabled()) {
     final Long cursorPosition = this.dataContainer.getCursorPosition(aCursorIdx);
     if (cursorPosition != null) {
       this.mainFrame.gotoPosition(cursorPosition.longValue());
     }
   }
 }
예제 #6
0
 public final void refresh() {
   RT = Runtime.getRuntime();
   txtMaxMem.setText(Long.toString(RT.maxMemory() / 1048576));
   txtTotalMem.setText(Long.toString(RT.totalMemory() / 1048576));
   this.txtUsedMem.setText(Long.toString((RT.totalMemory() - RT.freeMemory()) / 1048576));
   this.txtStorage.setText(
       new DecimalFormat(".000").format(WorkDir.getUsableSpace() / 1000000000F));
   this.lblFolder.setText(WorkDir.getAbsolutePath());
 }
 /**
  * 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");
   }
 }
예제 #8
0
 /** Goes to the current cursor position of the last available cursor. */
 public void gotoLastAvailableCursor() {
   if ((this.mainFrame != null) && this.dataContainer.isCursorsEnabled()) {
     for (int c = CapturedData.MAX_CURSORS - 1; c >= 0; c--) {
       if (this.dataContainer.isCursorPositionSet(c)) {
         final Long cursorPosition = this.dataContainer.getCursorPosition(c);
         if (cursorPosition != null) {
           this.mainFrame.gotoPosition(cursorPosition.longValue());
         }
         break;
       }
     }
   }
 }
예제 #9
0
    @Override
    public Object stringToValue(String text) throws ParseException {
      if (text != null) text = text.trim();

      if ((text == null) || text.isEmpty()) {
        if (nullable) {
          return null;
        } else {
          throw new ParseException("Empty/null value is not allowed.", 0);
        }
      }

      long value;
      try {
        value = Long.parseLong(text);
      } catch (Exception e) {
        throw new ParseException("Parsing \"" + text + "\" to an integer value failed.", 0);
      }

      if ((value < minValue) || (value > maxValue)) {
        throw new ParseException(
            "Parsing \""
                + text
                + "\" to an integer value in the range ["
                + minValue
                + ", "
                + maxValue
                + "] failed.",
            0);
      }

      return value;
    }
예제 #10
0
 public void GetRecentPaperSize() {
   String id = Long.toString(robot_uid);
   paper_left = Double.parseDouble(prefs.get(id + "_paper_left", "0"));
   paper_right = Double.parseDouble(prefs.get(id + "_paper_right", "0"));
   paper_top = Double.parseDouble(prefs.get(id + "_paper_top", "0"));
   paper_bottom = Double.parseDouble(prefs.get(id + "_paper_bottom", "0"));
 }
예제 #11
0
    private boolean verifyFile(File aFile, List theFileAttribList) {
      Iterator it = theFileAttribList.iterator();
      int theIndex = 0;
      String theMD5 = null;
      String theVal = null;
      long theSize;
      while (it.hasNext()) {
        try {
          theVal = (String) it.next();
          if (theIndex == 6) {
            theMD5 = MD5.getMD5(aFile);
            if (!theVal.equals(MD5.getMD5(aFile))) {
              return false;
            }
            break;
          }
          if (theIndex == 5) {
            theSize = aFile.length();
            if (theSize != Long.parseLong(theVal)) {
              return false;
            }
          }

        } catch (Exception E) {
          E.printStackTrace();
        }
        theIndex++;
      }
      return true;
    }
예제 #12
0
    public void actionPerformed(ActionEvent e) {

      try {
        TransferProveedor Proveedor = new TransferProveedor();

        Proveedor.setId(Integer.parseInt(labelId.getText()));

        cajaNIF.setBackground(Color.red);
        Proveedor.setNif(Integer.parseInt(cajaNIF.getText()));
        if (Proveedor.getNif() < 0) throw new NumberFormatException();
        cajaNIF.setBackground(Color.green);

        cajaNombre.setBackground(Color.red);
        if (cajaNombre.getText().equals("")) throw new InputMismatchException();
        Proveedor.setName(cajaNombre.getText());
        cajaNombre.setBackground(Color.green);

        cajaTelefono.setBackground(Color.red);
        Proveedor.setTelephoneNumber(Long.parseLong(cajaTelefono.getText()));
        if (Proveedor.getTelephoneNumber() < 0) throw new NumberFormatException();
        cajaTelefono.setBackground(Color.green);

        cajaEmail.setBackground(Color.red);
        if (cajaEmail.getText().equals("")) throw new InputMismatchException();
        Proveedor.setEmail(cajaEmail.getText());
        cajaEmail.setBackground(Color.green);

        ControladorAplicacion.getInstancia().accion(Acciones.proveedoresEditar, Proveedor);
      } catch (NumberFormatException ex) {
        JOptionPane.showMessageDialog(EditarProveedorGUI.this, "Introduce números");
      } catch (InputMismatchException ex) {
        JOptionPane.showMessageDialog(EditarProveedorGUI.this, "No se permiten campos vacios");
      }
    }
예제 #13
0
 @Override
 public int compareTo(Object o) {
   if (o instanceof DateAxisGraphLabel) {
     return Long.compare(this.date, ((DateAxisGraphLabel) o).getDate());
   }
   return 0;
 }
 private void updateModel() {
   this.model.setExternalPostprocessingEnabled(
       this.enableExternalPostprocessingCheckBox.isSelected());
   this.model.setPathToExternalPostprocessor(this.pathTextField.getText());
   this.model.setCommandLinePattern(this.patternTextField.getText());
   this.model.setExternalPostprocessingTimeout(Long.valueOf(this.timeoutTextField.getText()));
 }
예제 #15
0
 private void checkTextfile(PlainTextResource text) {
   Matcher m = NUMBERPATTERN.matcher(text.getText());
   while (m.find()) {
     long nr = Long.parseLong(text.getText().substring(m.start(), m.end()));
     if (nr >= 0 && nr < strUsed.length) strUsed[(int) nr] = true;
   }
 }
예제 #16
0
파일: Chart.java 프로젝트: feihugis/NetCDF
  public Chart(String filename) {
    try {
      // Get Stock Symbol
      this.stockSymbol = filename.substring(0, filename.indexOf('.'));

      // Create time series
      TimeSeries open = new TimeSeries("Open Price", Day.class);
      TimeSeries close = new TimeSeries("Close Price", Day.class);
      TimeSeries high = new TimeSeries("High", Day.class);
      TimeSeries low = new TimeSeries("Low", Day.class);
      TimeSeries volume = new TimeSeries("Volume", Day.class);

      BufferedReader br = new BufferedReader(new FileReader(filename));
      String key = br.readLine();
      String line = br.readLine();
      while (line != null && !line.startsWith("<!--")) {
        StringTokenizer st = new StringTokenizer(line, ",", false);
        Day day = getDay(st.nextToken());
        double openValue = Double.parseDouble(st.nextToken());
        double highValue = Double.parseDouble(st.nextToken());
        double lowValue = Double.parseDouble(st.nextToken());
        double closeValue = Double.parseDouble(st.nextToken());
        long volumeValue = Long.parseLong(st.nextToken());

        // Add this value to our series'
        open.add(day, openValue);
        close.add(day, closeValue);
        high.add(day, highValue);
        low.add(day, lowValue);

        // Read the next day
        line = br.readLine();
      }

      // Build the datasets
      dataset.addSeries(open);
      dataset.addSeries(close);
      dataset.addSeries(low);
      dataset.addSeries(high);
      datasetOpenClose.addSeries(open);
      datasetOpenClose.addSeries(close);
      datasetHighLow.addSeries(high);
      datasetHighLow.addSeries(low);

      JFreeChart summaryChart = buildChart(dataset, "Summary", true);
      JFreeChart openCloseChart = buildChart(datasetOpenClose, "Open/Close Data", false);
      JFreeChart highLowChart = buildChart(datasetHighLow, "High/Low Data", true);
      JFreeChart highLowDifChart =
          buildDifferenceChart(datasetHighLow, "High/Low Difference Chart");

      // Create this panel
      this.setLayout(new GridLayout(2, 2));
      this.add(new ChartPanel(summaryChart));
      this.add(new ChartPanel(openCloseChart));
      this.add(new ChartPanel(highLowChart));
      this.add(new ChartPanel(highLowDifChart));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #17
0
 private SettingConfig generateSetting() {
   SettingConfig s = new SettingConfig();
   s.dir = TEXT_dir.getText();
   s.logBuffer = SizeType.get((String) SELECT_logBuffer.getSelectedItem()).getSize();
   try {
     s.delay = Integer.parseInt((String) SELECT_delay.getSelectedItem());
     if (s.delay < 100) s.delay = 100;
   } catch (Exception e) {
   }
   s.seek = CHK_seek.isSelected();
   if (s.seek) {
     try {
       s.seekType = SeekType.get((String) SELECT_seekType.getSelectedItem());
     } catch (Exception e) {
     }
     try {
       s.seekPos = Long.parseLong(TEXT_seekPos.getText());
     } catch (Exception e) {
     }
   }
   s.charset = CharsetType.get((String) SELECT_charset.getSelectedItem());
   try {
     s.overflowNum = Integer.parseInt(TEXT_limit.getText());
   } catch (Exception e) {
   }
   s.showLineNumber = CHK_showLineNumber.isSelected();
   s.softWrap = CHK_softWrap.isSelected();
   return s;
 }
  private void altCommitToOriginal(@NotNull DocumentEvent e) {
    final PsiFile origPsiFile =
        PsiDocumentManager.getInstance(myProject).getPsiFile(myOrigDocument);
    String newText = myNewDocument.getText();
    // prepare guarded blocks
    LinkedHashMap<String, String> replacementMap = new LinkedHashMap<String, String>();
    int count = 0;
    for (RangeMarker o : ContainerUtil.reverse(((DocumentEx) myNewDocument).getGuardedBlocks())) {
      String replacement = o.getUserData(REPLACEMENT_KEY);
      String tempText = "REPLACE" + (count++) + Long.toHexString(StringHash.calc(replacement));
      newText =
          newText.substring(0, o.getStartOffset()) + tempText + newText.substring(o.getEndOffset());
      replacementMap.put(tempText, replacement);
    }
    // run preformat processors
    final int hostStartOffset = myAltFullRange.getStartOffset();
    myEditor.getCaretModel().moveToOffset(hostStartOffset);
    for (CopyPastePreProcessor preProcessor :
        Extensions.getExtensions(CopyPastePreProcessor.EP_NAME)) {
      newText = preProcessor.preprocessOnPaste(myProject, origPsiFile, myEditor, newText, null);
    }
    myOrigDocument.replaceString(hostStartOffset, myAltFullRange.getEndOffset(), newText);
    // replace temp strings for guarded blocks
    for (String tempText : replacementMap.keySet()) {
      int idx =
          CharArrayUtil.indexOf(
              myOrigDocument.getCharsSequence(),
              tempText,
              hostStartOffset,
              myAltFullRange.getEndOffset());
      myOrigDocument.replaceString(idx, idx + tempText.length(), replacementMap.get(tempText));
    }
    // JAVA: fix occasional char literal concatenation
    fixDocumentQuotes(myOrigDocument, hostStartOffset - 1);
    fixDocumentQuotes(myOrigDocument, myAltFullRange.getEndOffset());

    // reformat
    PsiDocumentManager.getInstance(myProject).commitDocument(myOrigDocument);
    Runnable task =
        () -> {
          try {
            CodeStyleManager.getInstance(myProject)
                .reformatRange(origPsiFile, hostStartOffset, myAltFullRange.getEndOffset(), true);
          } catch (IncorrectOperationException e1) {
            // LOG.error(e);
          }
        };
    DocumentUtil.executeInBulk(myOrigDocument, true, task);

    PsiElement newInjected =
        InjectedLanguageManager.getInstance(myProject)
            .findInjectedElementAt(origPsiFile, hostStartOffset);
    DocumentWindow documentWindow =
        newInjected == null ? null : InjectedLanguageUtil.getDocumentWindow(newInjected);
    if (documentWindow != null) {
      myEditor.getCaretModel().moveToOffset(documentWindow.injectedToHost(e.getOffset()));
      myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
    }
  }
예제 #19
0
 // save paper limits
 public void SetRecentPaperSize() {
   String id = Long.toString(robot_uid);
   prefs.putDouble(id + "_paper_left", paper_left);
   prefs.putDouble(id + "_paper_right", paper_right);
   prefs.putDouble(id + "_paper_top", paper_top);
   prefs.putDouble(id + "_paper_bottom", paper_bottom);
   previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right);
 }
예제 #20
0
 void SaveConfig() {
   String id = Long.toString(robot_uid);
   prefs.put(id + "_limit_top", Double.toString(limit_top));
   prefs.put(id + "_limit_bottom", Double.toString(limit_bottom));
   prefs.put(id + "_limit_right", Double.toString(limit_right));
   prefs.put(id + "_limit_left", Double.toString(limit_left));
   prefs.put(id + "_m1invert", Boolean.toString(m1invert));
   prefs.put(id + "_m2invert", Boolean.toString(m2invert));
 }
예제 #21
0
 void LoadConfig() {
   String id = Long.toString(robot_uid);
   limit_top = Double.valueOf(prefs.get(id + "_limit_top", "0"));
   limit_bottom = Double.valueOf(prefs.get(id + "_limit_bottom", "0"));
   limit_left = Double.valueOf(prefs.get(id + "_limit_left", "0"));
   limit_right = Double.valueOf(prefs.get(id + "_limit_right", "0"));
   m1invert = Boolean.parseBoolean(prefs.get(id + "_m1invert", "false"));
   m2invert = Boolean.parseBoolean(prefs.get(id + "_m2invert", "false"));
 }
 /** Find the data for a given id */
 public SOAPMonitorData findData(Long id) {
   SOAPMonitorData soap = null;
   for (int row = data.size(); (row > 0) && (soap == null); row--) {
     soap = (SOAPMonitorData) data.elementAt(row - 1);
     if (soap.getId().longValue() != id.longValue()) {
       soap = null;
     }
   }
   return soap;
 }
예제 #23
0
 public void genSeed(ActionEvent e) {
   long seed = 0;
   boolean redo = false;
   do {
     redo = false;
     String seedString =
         JOptionPane.showInputDialog(
             this, "Enter a number:", Long.toString(rand.nextLong(), 36)
             // "Random Seed", JOptionPane.QUESTION_MESSAGE
             );
     if (seedString == null) return;
     try {
       seed = Long.parseLong(seedString, 36);
     } catch (NumberFormatException ex) {
       JOptionPane.showMessageDialog(this, "Use only letters and numbers, max 12 characters.");
       redo = true;
     }
   } while (redo);
   genSeed(seed);
 }
예제 #24
0
    private void downloadFile(String theFilename) {
      OutputStream outStream = null;
      InputStream is = null;
      try {
        myMessage.stateChanged("DOWNLOADLOCALBASE");
        String theFile =
            myProperties
                .getProperty("BASEURL")
                .substring(0, myProperties.getProperty("BASEURL").lastIndexOf("/"));

        theFile = theFile + "/" + (new URI((theFilename).replaceAll(" ", "%20")));
        URLConnection uCon = null;
        int size = 1024;
        URL Url;
        byte[] buf;
        int ByteRead, ByteWritten = 0;
        Url = new URL(theFile);
        String theLocalFilename = (String) myFileList.get(theFilename).get(2);
        long theFileSize = Long.parseLong((String) myFileList.get(theFilename).get(5));
        outStream =
            new BufferedOutputStream(
                new FileOutputStream(
                    myProperties.getProperty("LOCALBASEDIR")
                        + "\\"
                        + myFileList.get(theFilename).get(2)));

        uCon = Url.openConnection();
        is = uCon.getInputStream();
        buf = new byte[size];
        while ((ByteRead = is.read(buf)) != -1) {
          outStream.write(buf, 0, ByteRead);
          ByteWritten += ByteRead;
          myMessage.setProgress((int) getPercentage(ByteWritten, theFileSize));
          // System.out.println(ByteWritten);
        }
        myMessage.messageChanged("Downloaded Successfully.");
        myMessage.messageChanged(
            "File name:\""
                + theLocalFilename
                + "\"\nNo ofbytes :"
                + ByteWritten
                + "Filesize ="
                + theFileSize);
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        try {
          is.close();
          outStream.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
예제 #25
0
  private void selectArrivalMouseClicked(MouseEvent e) {
    saveArrival.setVisible(false);
    saveArrival.setEnabled(false);
    doArrive.setVisible(true);
    doArrive.setEnabled(true);

    int row = arrivalTable.getSelectedRow();
    String id = (String) arrivalTable.getValueAt(row, 0);
    long ID = Long.parseLong(id);
    arrival = entruckReceive.chooseArrival(ID);
    setArrivalVO();
  }
예제 #26
0
 void jMenuItemScheduleCommand_actionPerformed(ActionEvent e) {
   try {
     String result = JOptionPane.showInputDialog("Enter <command>,<interval>");
     if (result != null) {
       StringTokenizer st = new StringTokenizer(result, ",");
       if (st.countTokens() == 2) {
         String command = st.nextToken();
         long interval = Long.parseLong(st.nextToken());
         CommandScheduler.create(command, interval * 1000);
       }
     }
   } catch (Exception ex) {
   }
 }
  @Nullable
  private Long getQuickDocDelayFromGui() {
    String quickDocDelayAsText = myQuickDocDelayTextField.getText();
    if (StringUtil.isEmptyOrSpaces(quickDocDelayAsText)) {
      return null;
    }

    try {
      long delay = Long.parseLong(quickDocDelayAsText);
      return delay > 0 ? delay : null;
    } catch (NumberFormatException e) {
      // Ignore incorrect value.
      return null;
    }
  }
예제 #28
0
  /**
   * Complete the handshake, load robot-specific configuration, update the menu, repaint the preview
   * with the limits.
   *
   * @return true if handshake succeeds.
   */
  public boolean ConfirmPort() {
    if (portConfirmed == true) return true;
    String hello = "HELLO WORLD! I AM DRAWBOT #";
    int found = line3.lastIndexOf(hello);
    if (found >= 0) {
      portConfirmed = true;

      // get the UID reported by the robot
      String[] lines = line3.substring(found + hello.length()).split("\\r?\\n");
      if (lines.length > 0) {
        try {
          robot_uid = Long.parseLong(lines[0]);
        } catch (NumberFormatException e) {
        }
      }

      // new robots have UID=0
      if (robot_uid == 0) GetNewRobotUID();

      mainframe.setTitle("Drawbot #" + Long.toString(robot_uid) + " connected");

      // load machine specific config
      GetRecentPaperSize();
      LoadConfig();
      if (limit_top == 0 && limit_bottom == 0 && limit_left == 0 && limit_right == 0) {
        UpdateConfig();
      }

      previewPane.setMachineLimits(limit_top, limit_bottom, limit_left, limit_right);
      SendConfig();

      UpdateMenuBar();
      previewPane.setConnected(true);
    }
    return portConfirmed;
  }
예제 #29
0
  /** Generates a formatted string representation of a large integer number. */
  private String formatLong(Long value) {
    if (value == null) return "-";

    if (value < 1024) {
      return value.toString();
    } else if (value < 1048576) {
      double k = ((double) value) / 1024.0;
      return String.format("%1$.1fK", k);
    } else if (value < 1073741824) {
      double m = ((double) value) / 1048576.0;
      return String.format("%1$.1fM", m);
    } else {
      double g = ((double) value) / 1073741824.0;
      return String.format("%1$.1fG", g);
    }
  }
예제 #30
0
  @Override
  public Object convertAssignableToValidValue(Object value) {
    if (value == null) {
      return null;
    }

    try {
      if (value instanceof Number) {
        return ((Number) value).longValue();
      } else {
        return Long.valueOf(value.toString());
      }
    } catch (Exception e) {
      throw new RuntimeException("Invalid value");
    }
  }