示例#1
0
文件: LJ3MDApp.java 项目: eskilj/mvp
  //    int frame = 0;
  public void paint(Graphics g) {
    // System.out.println("frame: " + (frame++));
    lStatus.setText(
        "t = "
            + df.format(md.dt * md.step)
            + ", "
            + "N = "
            + md.N
            + ", "
            + "E/N = "
            + df.format(md.E / md.N)
            + ", "
            + "U/N = "
            + df.format(md.U / md.N)
            + ", "
            + "K/N = "
            + df.format(md.K / md.N)
            + ", "
            + "p = "
            + df.format(md.p)
            + ";");
    tAvK.setText(df.format(md.avK.getAve() / md.N) + "  ");
    tAvU.setText(df.format(md.avU.getAve() / md.N) + "  ");
    tTemp.setText(df.format((2 * md.K) / (3 * (md.N - 1))) + "  ");
    tAvp.setText(df.format(md.avp.getAve()) + "  ");
    canvas.refresh(md.getXWrap(), md.N, true, false);
    cpnl.repaint();
    spnl.repaint();

    try {

      PrintWriter wavefunc =
          new PrintWriter(new FileOutputStream(new File("energyData.txt"), true));
      wavefunc.print(md.E / md.N + " " + md.K / md.N + " " + md.U / md.N);
      wavefunc.println();
      wavefunc.close();
    } catch (IOException ex) {
    }

    try {

      PrintWriter tempwriter =
          new PrintWriter(new FileOutputStream(new File("tempData.txt"), true));
      tempwriter.print(df.format((2 * md.K) / (3 * (md.N - 1))));
      tempwriter.println();
      tempwriter.close();
    } catch (IOException ex) {
    }
  }
示例#2
0
文件: LJ3MDApp.java 项目: eskilj/mvp
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();
    if (src == timer) {
      for (int i = 0; i < speed; i++) // integrate a few steps
      md.vv();
      repaint();
      return;
    }

    boolean adjCanvasScale = false;

    if (src == bTstat) md.thermostat = !md.thermostat;

    if (src == bPot) {
      md.ljPotential = !md.ljPotential;
      md.clearData();

      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    if (src == tTemp || src == bReset) {
      double kT = Double.parseDouble(tTemp.getText().trim());
      if (kT < 1e-8) {
        kT = 1e-8;
        tTemp.setText("  " + kT);
      }
      md.kT = kT;
      md.clearData();
    }

    if (src == tRho || src == bReset) {
      double rho = Double.parseDouble(tRho.getText().trim());
      if (rho < 1e-3) {
        rho = 1e-3;
        tRho.setText("   " + rho);
      }
      if (rho > 1.2) {
        rho = 1.2;
        tRho.setText("   " + rho);
      }
      md.setDensity(rho);
      md.clearData();
      adjCanvasScale = true;
    }

    if (src == tSpeed || src == bReset) {
      speed = Integer.parseInt(tSpeed.getText().trim());
      if (speed < 1) {
        speed = 1;
        tSpeed.setText("   " + speed);
      }
    }

    if (src == bRetime) md.clearData();

    if (src == bStart) {
      boolean on = bStart.isSelected();
      if (on) {
        timer.restart();
        bStart.setText("Pause");
      } else {
        timer.stop();
        bStart.setText("Resume");
      }
    }

    if (src == tNum) {
      int n = Integer.parseInt(tNum.getText().trim());
      if (n < 2) {
        n = 2;
        tNum.setText(" " + n);
      }
      md.N = n;
      md.init(md.rho);
      adjCanvasScale = true;
    }

    if (src == bReset) {
      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    canvas.refresh(md.getXWrap(), md.N, true, adjCanvasScale);

    repaint();
  }
示例#3
0
  public void dataUpdate() {
    // 日付関係はUGUIUpdateManager経由で取得するように変更.
    int date = UGUIUpdateManager.getDate();
    int boardNo = UGUIUpdateManager.getBoard();
    int step = UGUIUpdateManager.getStep();
    int now = UGUIUpdateManager.getMarketStatus();

    if (now != fCurrentStatus) {
      fIsUpdated = true;
    }

    if (step <= fCurrentStep) {
      // Exchange X-Y がセットされている場合の処理.フラグ処理はあまりきれいではないが
      // X-Y の入れ換え自体が???なので勘弁してもらおう.
      if (fIsUpdated == false) {
        return;
      } else {
        fIsUpdated = false;
      }
    }

    if (boardNo == 1) {
      fDay.setText(String.valueOf(date - 1));
      fBoard.setText(String.valueOf(fParam.getBoardPerDay()));
    } else {
      fDay.setText(String.valueOf(date));
      if (now == fCurrentStatus) {
        fBoard.setText(String.valueOf(boardNo - 1));
      } else {
        fBoard.setText(String.valueOf(boardNo));
      }
    }
    fCurrentStep = step;
    fCurrentStatus = now;

    UCBoardDataCore cBoardData = (UCBoardDataCore) fCProtocol.getCommand(UCBoardDataCore.CMD_NAME);
    UCommandStatus status = cBoardData.doIt();
    ArrayList array;
    HashMap boardDataInfo;
    long maxPrice, minPrice, totalBuyVolume;
    Vector printData = new Vector();
    if (status.getStatus()) {
      array = cBoardData.getBoardDataArray();
      boardDataInfo = cBoardData.getBoardDataInfo();
      maxPrice = ((Long) boardDataInfo.get(UCBoardDataCore.LONG_MAX_PRICE)).longValue();
      minPrice = ((Long) boardDataInfo.get(UCBoardDataCore.LONG_MIN_PRICE)).longValue();
      totalBuyVolume =
          ((Long) boardDataInfo.get(UCBoardDataCore.LONG_TOTAL_BUY_VOLUME)).longValue();
      if (fIsExchangeXY == false) {
        fBoardGraph.setFixedMaxX(maxPrice);
        fBoardGraph.setFixedMinX(minPrice);
        fBoardGraph.setFixedMaxY(totalBuyVolume);
        fBoardGraph.setFixedMinY(0);
      } else {
        fBoardGraph.setFixedMaxX(totalBuyVolume);
        fBoardGraph.setFixedMinX(0);
        fBoardGraph.setFixedMaxY(maxPrice);
        fBoardGraph.setFixedMinY(minPrice);
      }
    } else {
      return;
    }
    long contractPrice =
        ((Long) boardDataInfo.get(UCBoardDataCore.LONG_CONTRACT_PRICE)).longValue();
    long contractVolume =
        ((Long) boardDataInfo.get(UCBoardDataCore.LONG_CONTRACT_VOLUME)).longValue();
    fContractPriceTextField.setText(String.valueOf(contractPrice));
    fContractVolumeTextField.setText(String.valueOf(contractVolume));
    ArrayList tmpSellData = new ArrayList();
    ArrayList tmpBuyData = new ArrayList();
    ArrayList tmpContractData = new ArrayList();
    if (fIsExchangeXY == false) {
      tmpContractData.add(new Point2D.Double(minPrice, contractVolume));
      tmpContractData.add(new Point2D.Double(contractPrice, contractVolume));
      tmpContractData.add(new Point2D.Double(contractPrice, 0));
      fBoardGraph.setXLableName("price");
      fBoardGraph.setYLableName("volume");
    } else {
      tmpContractData.add(new Point2D.Double(contractVolume, minPrice));
      tmpContractData.add(new Point2D.Double(contractVolume, contractPrice));
      tmpContractData.add(new Point2D.Double(0, contractPrice));
      fBoardGraph.setXLableName("volume");
      fBoardGraph.setYLableName("price");
    }
    Iterator iter = array.iterator();
    double tmpPrice, tmpVolume, currentSellVolume = 0, currentBuyVolume = totalBuyVolume;
    while (iter.hasNext()) {
      HashMap os = (HashMap) iter.next();
      String s = (String) os.get(UCBoardDataCore.STRING_SELL_BUY);
      if (s.equals("sell")) {
        tmpPrice = ((Long) os.get(UCBoardDataCore.LONG_PRICE)).doubleValue();
        tmpVolume = ((Long) os.get(UCBoardDataCore.LONG_VOLUME)).doubleValue();
        if (fIsExchangeXY == false) {
          tmpSellData.add(new Point2D.Double(tmpPrice, currentSellVolume));
          tmpSellData.add(new Point2D.Double(tmpPrice, currentSellVolume + tmpVolume));
        } else {
          tmpSellData.add(new Point2D.Double(currentSellVolume, tmpPrice));
          tmpSellData.add(new Point2D.Double(currentSellVolume + tmpVolume, tmpPrice));
        }
        currentSellVolume += tmpVolume;
      } else if (s.equals("buy")) {
        tmpPrice = ((Long) os.get(UCBoardDataCore.LONG_PRICE)).doubleValue();
        tmpVolume = ((Long) os.get(UCBoardDataCore.LONG_VOLUME)).doubleValue();
        if (fIsExchangeXY == false) {
          tmpBuyData.add(new Point2D.Double(tmpPrice, currentBuyVolume));
          tmpBuyData.add(new Point2D.Double(tmpPrice, currentBuyVolume - tmpVolume));
        } else {
          tmpBuyData.add(new Point2D.Double(currentBuyVolume, tmpPrice));
          tmpBuyData.add(new Point2D.Double(currentBuyVolume - tmpVolume, tmpPrice));
        }
        currentBuyVolume -= tmpVolume;
      }
    }
    ((UGraphData) fBoardGraph.getGraph().get(0)).setData(tmpSellData);
    ((UGraphData) fBoardGraph.getGraph().get(1)).setData(tmpBuyData);
  }
  public void actionPerformed(ActionEvent e) {
    JButton b = (JButton) e.getSource();
    if (b.getText() == "PLAY") {
      if (scoreP != null) scoreP.playScale(sp.getScale(), tempoP.getValue());
    } else if (b.getText() == "New") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      sp.notes.removeAllElements();
      sp.repaint();
      nameTF.setText("");
      loadedFile = null;
    } else if (b.getText() == "Save") {
      if (nameTF.getText().equals("")) {
        JOptionPane.showMessageDialog(
            this,
            new JLabel("Please type in the Scale Name"),
            "Warning",
            JOptionPane.WARNING_MESSAGE);
        return;
      }
      fileChooser.setFileFilter(filter);
      int option = fileChooser.showSaveDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        File target = fileChooser.getSelectedFile();
        if (target.getName().indexOf(".scl") == -1) target = new File(target.getPath() + ".scl");
        try {
          PrintStream stream = new PrintStream(new FileOutputStream(target), true);
          save(stream);
          stream.close();
        } catch (Exception ex) {
          JOptionPane.showMessageDialog(
              this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
        }
      }
    } else if (b.getText() == "Load") {
      try {
        saveUnsaved();
      } catch (SaveAbortedException ex) {
        return;
      }

      fileChooser.setFileFilter(filter);
      int option = fileChooser.showOpenDialog(this);
      if (option == JFileChooser.APPROVE_OPTION) {
        loadedFile = fileChooser.getSelectedFile();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        ScaleParser handler = new ScaleParser(false);
        try {
          SAXParser parser = factory.newSAXParser();
          parser.parse(loadedFile, handler);
          // System.out.println("success");
        } catch (Exception ex) {
          // System.out.println("no!!!!!! exception: "+e);
          // System.out.println(ex.getMessage());
          ex.printStackTrace();
        }
        // -----now :P:P---------------
        System.out.println("name: " + handler.getName());
        nameTF.setText(handler.getName());
        sp.notes.removeAllElements();
        int[] scale = handler.getScale();
        for (int i = 0; i < scale.length; i++) {
          sp.addNote(scale[i]);
        }
        sp.repaint();
      } else loadedFile = null;
    }
  }