Пример #1
0
  //    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
 /**
  * Pattern widget
  *
  * @return Pattern widget
  */
 public JTextField getPatternWidget() {
   if (patternFld == null) {
     patternFld = new JTextField(pattern, 20);
     patternFld.setToolTipText(
         "<html>A string pattern to match or a comma separated numeric range:<br><i>e.g., -5.0,0</i></html>");
   }
   return patternFld;
 }
Пример #3
0
 static String waitForInputString() {
   try {
     while (!hasEntered) {
       Thread.sleep(100);
     }
     return inputField.getText();
   } catch (Exception e) {
     return "";
   }
 }
 public void save(PrintStream stream) {
   saved = true;
   stream.println("<?xml version=\"1.0\"?>");
   stream.println("<scale>");
   stream.println("  <name>" + nameTF.getText() + "</name>");
   for (Enumeration en = sp.notes.elements(); en.hasMoreElements(); ) {
     ScalePanel.Notik cur = (ScalePanel.Notik) en.nextElement();
     stream.println("  <note>" + cur.n + "</note>");
   }
   stream.println("</scale>");
 }
Пример #5
0
  public LJ3MDApp() {
    tNum.setHorizontalAlignment(JTextField.CENTER);
    tTemp.setHorizontalAlignment(JTextField.CENTER);
    tRho.setHorizontalAlignment(JTextField.CENTER);
    tSpeed.setHorizontalAlignment(JTextField.CENTER);

    tAvK.setHorizontalAlignment(JTextField.RIGHT);
    tAvU.setHorizontalAlignment(JTextField.RIGHT);
    tAvp.setHorizontalAlignment(JTextField.RIGHT);

    float[] aveKing = new float[501];
    float[] avePot = new float[501];
    float[] aveEn = new float[501];

    JFrame box = new JFrame();
    box.setLayout(new BorderLayout());
    box.setSize(1000, 1000);
    box.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    cpnl = new JPanel(); // create a panel for controls
    cpnl.setLayout(new GridLayout(18, 2));
    box.add(cpnl, BorderLayout.EAST);

    // add controls
    cpnl.add(bStart);
    bStart.addActionListener(this);

    cpnl.add(bReset);
    bReset.addActionListener(this);

    cpnl.add(new JLabel(" N:"));
    tNum.addActionListener(this);
    cpnl.add(tNum);

    cpnl.add(new JLabel(" Density (\u03c1):"));
    tRho.addActionListener(this);
    cpnl.add(tRho);

    cpnl.add(new JLabel(" Steps/frame:"));
    tSpeed.addActionListener(this);
    cpnl.add(tSpeed);

    cpnl.add(bTstat);
    bTstat.addActionListener(this);

    cpnl.add(bPot);
    bPot.addActionListener(this);

    cpnl.add(new JLabel(" < K/N > :"));
    tAvK.setEditable(false);
    cpnl.add(tAvK);

    cpnl.add(new JLabel(" Temperature:"));
    tTemp.setEditable(false);
    cpnl.add(tTemp);

    cpnl.add(new JLabel(" < U/N > :"));
    tAvU.setEditable(false);
    cpnl.add(tAvU);

    cpnl.add(new JLabel(" < pressure > :"));
    tAvp.setEditable(false);
    cpnl.add(tAvp);

    cpnl.add(bRetime);
    bRetime.addActionListener(this);

    spnl = new JPanel(); // create a panel for status
    box.add(spnl, BorderLayout.SOUTH);
    lStatus.setFont(new Font("Courier", 0, 12));
    spnl.add(lStatus);

    canvas = new XYZCanvas();
    box.add(canvas, BorderLayout.CENTER);

    timer = new Timer(delay, this);
    timer.start();
    //        timer.stop();
    box.setVisible(true);
  }
Пример #6
0
  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();
  }
Пример #7
0
  public void jbInit() throws Exception {
    this.setLayout(null);
    fContractPriceTextField.setFont(new java.awt.Font("Dialog", 1, 11));
    fContractPriceTextField.setDisabledTextColor(Color.black);
    fContractPriceTextField.setEditable(false);
    fContractPriceTextField.setHorizontalAlignment(SwingConstants.RIGHT);
    fContractPriceTextField.setBounds(new java.awt.Rectangle(285, 182, 55, 21));
    fContractVolumeTextField.setFont(new java.awt.Font("Dialog", 1, 11));
    fContractVolumeTextField.setDisabledTextColor(Color.black);
    fContractVolumeTextField.setEditable(false);
    fContractVolumeTextField.setHorizontalAlignment(SwingConstants.RIGHT);
    fContractVolumeTextField.setBounds(new java.awt.Rectangle(285, 238, 55, 21));
    fContractVolumeLabel.setText(fRb.getString("CONTRACT_VOLUME"));
    fContractVolumeLabel.setForeground(Color.black);
    fContractVolumeLabel.setBounds(new java.awt.Rectangle(272, 218, 99, 17));
    fContractPriceLabel.setBounds(new java.awt.Rectangle(272, 160, 92, 17));
    fContractPriceLabel.setText(fRb.getString("CONTRACT_PRICE"));
    fContractPriceLabel.setForeground(Color.black);

    fBoardGraph.setLayout(borderLayout1);
    fDay.setBounds(new java.awt.Rectangle(337, 87, 42, 21));
    fDayLabel.setText(fRb.getString("DAY") + ":");
    fDayLabel.setForeground(Color.black);
    fDayLabel.setBounds(new java.awt.Rectangle(267, 89, 67, 17));
    fBoardLabel.setText(fRb.getString("SESSION") + ":");
    fBoardLabel.setForeground(Color.black);
    fBoardLabel.setBounds(new java.awt.Rectangle(267, 121, 68, 17));
    fBoard.setBounds(new java.awt.Rectangle(337, 119, 42, 22));
    fPreviousBoardLabel.setFont(new java.awt.Font("Dialog", 1, 12));
    fPreviousBoardLabel.setText(fRb.getString("PREVIOUS_PRICING"));
    fPreviousBoardLabel.setForeground(Color.black);
    fPreviousBoardLabel.setBounds(new java.awt.Rectangle(85, 4, 99, 17));
    fXYToggleButton.setBorder(BorderFactory.createRaisedBevelBorder());
    fXYToggleButton.setText("Exchange X-Y");
    fXYToggleButton.setBounds(new java.awt.Rectangle(268, 43, 114, 25));
    fXYToggleButton.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            fIsExchangeXY = fXYToggleButton.isSelected();
            fIsUpdated = true;
            gUpdate();
          }
        });

    this.setBorder(BorderFactory.createEtchedBorder());
    this.setBounds(new java.awt.Rectangle(325, 7, 387, 283));
    this.setLayout(null);
    fBoardGraph.setBorder(BorderFactory.createEtchedBorder());
    fBoardGraph.setBounds(new java.awt.Rectangle(5, 26, 257, 243));
    fBoardGraph.getGraph().add(new UGraphData(fSellName, fSellColor));
    fBoardGraph.getGraph().add(new UGraphData(fBuyName, fBuyColor));
    fBoardGraph.setLeftMargin(60);
    this.add(fBoardGraph, null);
    this.add(fContractVolumeTextField, null);
    this.add(fContractVolumeLabel, null);
    this.add(fContractPriceTextField, null);
    this.add(fContractPriceLabel, null);
    this.add(fBoardLabel, null);
    this.add(fDayLabel, null);
    this.add(fXYToggleButton, null);
    this.add(fPreviousBoardLabel, null);
    this.add(fDay, null);
    this.add(fBoard, null);
    fBoardGraph.setBackground(Color.white);
    fBoardGraph.setNumOfHorizontalLine(0);
    fBoardGraph.setNumOfVerticalLine(0);
    fBoardGraph.setFixedMaxX(1);
    fBoardGraph.setFixedMinX(0);
    fBoardGraph.setFixedMaxY(1);
    fBoardGraph.setFixedMinY(0);
    addComponentListener(
        new ComponentAdapter() {
          public void componentShown(ComponentEvent ce) {
            gUpdate();
          }
        });
  }
Пример #8
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 saveUnsaved() throws SaveAbortedException {
   if (!saved) {
     int option = 0;
     if (loadedFile == null)
       option =
           JOptionPane.showConfirmDialog(
               this,
               new JLabel("Save changes to UNTITLED?"),
               "Warning",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.WARNING_MESSAGE);
     else
       option =
           JOptionPane.showConfirmDialog(
               this,
               new JLabel("Save changes to " + loadedFile.getName() + "?"),
               "Warning",
               JOptionPane.YES_NO_CANCEL_OPTION,
               JOptionPane.WARNING_MESSAGE);
     if (option == JOptionPane.YES_OPTION) {
       if (loadedFile == null) // SAVE NEW FILE
       {
         if (nameTF.getText().equals("")) {
           JOptionPane.showMessageDialog(
               this,
               new JLabel("Please type in the Scale Name"),
               "Warning",
               JOptionPane.WARNING_MESSAGE);
           throw new SaveAbortedException();
         }
         fileChooser.setFileFilter(filter);
         int option2 = fileChooser.showSaveDialog(this);
         if (option2 == JFileChooser.APPROVE_OPTION) {
           File target = fileChooser.getSelectedFile();
           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 throw new SaveAbortedException();
         ;
       } else // save LOADED FILE
       {
         try {
           PrintStream stream = new PrintStream(new FileOutputStream(loadedFile), true);
           save(stream);
           stream.close();
         } catch (Exception ex) {
           JOptionPane.showMessageDialog(
               this, new JLabel("Error: " + ex.getMessage()), "Error", JOptionPane.ERROR_MESSAGE);
         }
       }
     } else if (option == JOptionPane.CANCEL_OPTION) throw new SaveAbortedException();
     ;
   }
 }
Пример #10
0
  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;
    }
  }
Пример #11
0
 /** Apply the properties */
 public void applyProperties() {
   range = null;
   pattern = patternFld.getText().trim();
   GuiUtils.ColorSwatch colorSwatch = (GuiUtils.ColorSwatch) getSwatchComps()[0];
   color = colorSwatch.getSwatchColor();
 }