⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trbase.java

📁 科学计算程序 (用于光学镊子
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package tr;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.io.*;
import java.util.StringTokenizer;
import java.util.Vector;
import java.net.URL;



/**
 * <p>Title: Holotrap</p>
 * <p>Description: A software to generate holograms for interactive trap manipulation</p>
 * <p>Research Group: Grup de Recerca en Optica Fisica (Universitat de Barcelona)</p>
 * @author Encarni Pleguezuelos Aguilera
 * @version 1.1
 * Copyright (C) 2006  Grup de Recerca en 襭tica F韘ica (Universitat de Barcelona).
 * <p>
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * <p>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <p>
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */


public class TRBase extends Applet {
  private boolean isStandalone = false;
  JPanel jPanelBase = new JPanel();
  BorderLayout borderLayout1 = new BorderLayout();
  BorderLayout borderLayout2 = new BorderLayout();
  JPanel jPanelEste = new JPanel();
  JPanel jPanelNorte = new JPanel();
  JPanel jPanelSur = new JPanel();
  JPanel jPanelOeste = new JPanel();
  JLabel jLabel1 = new JLabel();
  JButton jButton1 = new JButton();
  JTextField fieldFil = new JTextField();
  JTextField fieldCol = new JTextField();
  JTextField fieldFactorX = new JTextField();
  JTextField fieldFactorY = new JTextField();
  JTextField fieldFactorZ = new JTextField();//lite
  JTextField fieldFinestra = new JTextField();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JButton botonInit = new JButton();
  JButton quitar = new JButton();
  JLabel jLabel4 = new JLabel();
  static JComboBox jComboBox1 = new JComboBox();
  PanelCoord panelCoord = new PanelCoord();
  static Vector npuntos = new Vector();
  static int nfil, ncol;
  int dim0 = 512*384;
  String path;
  double kk;
  JLabel jLabel5 = new JLabel();
  static JTextField labelvel = new JTextField();
  static boolean value = false;
  static boolean fileOpen = false;//noastnocurva
  JLabel labelFactorX = new JLabel();
  JLabel labelFactorY = new JLabel();
  JLabel labelFactorZ = new JLabel();
  JLabel labelFinestra = new JLabel();
  static boolean big = false;
  ButtonGroup grupo = new ButtonGroup();
  JRadioButton metDavis = new JRadioButton();
  JRadioButton metFases = new JRadioButton();
  static JSlider zSlider = new JSlider();
  JLabel etiqz = new JLabel("Trap depth");
  JLabel labelVortex = new JLabel("l vortex");
  static JTextField fieldVortex = new JTextField();
  JButton license = new JButton("Licensing GNU GPL terms");
  JTextPane jTextPane_Lic = new JTextPane();

  //Obtener el valor de un par锟絤etro
  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  }

  //Construir el applet
  public TRBase() {
  }
  //Inicializar el applet
  public void init() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  //Component initialization
  private void jbInit() throws Exception {
    //Comment if there is no QICam available
    //panelCoord.initCamera();
    //panelCoord.initGrab();
    this.setLayout(borderLayout1);
    jPanelBase.setLayout(borderLayout2);
    jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel1.setHorizontalTextPosition(SwingConstants.CENTER);
    jLabel1.setText("Hologram generation");
    jButton1.setText("Exit");
    carga_licencia();
    jButton1.addActionListener(new TRBase_jButton1_actionAdapter(this));
    license.addActionListener(new TRBase_license_actionAdapter(this));
    fieldFil.setMinimumSize(new Dimension(4, 20));
    fieldFil.setPreferredSize(new Dimension(45, 20));
    fieldFil.setText("768");//768
    fieldFil.setEditable(false);
    fieldFil.setHorizontalAlignment(SwingConstants.RIGHT);
    fieldCol.setMinimumSize(new Dimension(4, 20));
    fieldCol.setPreferredSize(new Dimension(45, 20));
    fieldCol.setText("1024");//1024
    fieldCol.setEditable(false);
    fieldCol.setHorizontalAlignment(SwingConstants.RIGHT);
    fieldFactorX.setMinimumSize(new Dimension(4, 20));
    fieldFactorX.setPreferredSize(new Dimension(45, 20));
    fieldFactorX.setText("-0.45");
    fieldFactorX.addKeyListener(new TRBase_fieldFactorX_keyAdapter(this));
    fieldFactorX.setHorizontalAlignment(SwingConstants.RIGHT);
    fieldFactorY.setMinimumSize(new Dimension(4, 20));
    fieldFactorY.setPreferredSize(new Dimension(45, 20));
    fieldFactorY.setText("0.475");
    fieldFactorY.addKeyListener(new TRBase_fieldFactorY_keyAdapter(this));
    fieldFactorY.setHorizontalAlignment(SwingConstants.RIGHT);

    fieldFactorZ.setMinimumSize(new Dimension(4, 20));
    fieldFactorZ.setPreferredSize(new Dimension(35, 20));
    fieldFactorZ.setText("1");
    fieldFactorZ.addKeyListener(new TRBase_fieldFactorZ_keyAdapter(this));
    fieldFactorZ.setHorizontalAlignment(SwingConstants.RIGHT);
    //fieldFactorZ.setEnabled(false);//lite

    fieldVortex.setMinimumSize(new Dimension(4, 20));
    fieldVortex.setPreferredSize(new Dimension(35, 20));
    fieldVortex.setText("0");
    fieldVortex.addKeyListener(new TRBase_fieldVortex_keyAdapter(this));
    fieldVortex.setHorizontalAlignment(SwingConstants.RIGHT);
    //fieldVortex.setEnabled(false);//lite

    jLabel2.setMaximumSize(new Dimension(100, 16));
    jLabel2.setMinimumSize(new Dimension(100, 16));
    jLabel2.setPreferredSize(new Dimension(100, 16));
    jLabel2.setText("Rows");
    jLabel3.setMaximumSize(new Dimension(100, 16));
    jLabel3.setMinimumSize(new Dimension(100, 16));
    jLabel3.setPreferredSize(new Dimension(100, 16));
    jLabel3.setText("Columns");
    labelFactorX.setMaximumSize(new Dimension(100, 16));
    labelFactorX.setMinimumSize(new Dimension(100, 16));
    labelFactorX.setPreferredSize(new Dimension(100, 16));
    labelFactorX.setText("Col factor");
    labelFactorY.setMaximumSize(new Dimension(100, 16));
    labelFactorY.setMinimumSize(new Dimension(100, 16));
    labelFactorY.setPreferredSize(new Dimension(100, 16));
    labelFactorY.setText("Row factor");
    labelFactorZ.setMaximumSize(new Dimension(100, 16));
    labelFactorZ.setMinimumSize(new Dimension(100, 16));
    labelFactorZ.setPreferredSize(new Dimension(100, 16));
    labelFactorZ.setText("Depth (umx10e3)");
    labelVortex.setMaximumSize(new Dimension(100, 16));
    labelVortex.setMinimumSize(new Dimension(100, 16));
    labelVortex.setPreferredSize(new Dimension(100, 16));
    botonInit.setMaximumSize(new Dimension(130, 26));
    botonInit.setMinimumSize(new Dimension(130, 26));
    botonInit.setPreferredSize(new Dimension(130, 26));
    botonInit.setText("Init");
    botonInit.addActionListener(new TRBase_botonInit_actionAdapter(this));
    quitar.setMaximumSize(new Dimension(130, 26));
    quitar.setMinimumSize(new Dimension(130, 26));
    quitar.setPreferredSize(new Dimension(130, 26));
    quitar.setText("Delete trap");
    quitar.addActionListener(new TRBase_quitar_actionAdapter(this));
    jPanelEste.setMinimumSize(new Dimension(213, 36));
    jPanelEste.setPreferredSize(new Dimension(213, 36));
    jLabel4.setMaximumSize(new Dimension(100, 16));
    jLabel4.setMinimumSize(new Dimension(100, 16));
    jLabel4.setPreferredSize(new Dimension(85, 16));
    jLabel4.setText("Trap");
    etiqz.setPreferredSize(new Dimension(140,26));
    zSlider.setPreferredSize(new Dimension(150,50));
    zSlider.addKeyListener(new TRBase_zSlider_keyAdapter(this));
    zSlider.addMouseMotionListener(new TRBase_zSlider_mouseMotionAdapter(this));
    zSlider.setMajorTickSpacing(5000);
    zSlider.setPaintLabels(true);
    zSlider.setPaintTicks(true);
    zSlider.setMaximum(5000);
    zSlider.setMinimum(-5000);
    zSlider.setEnabled(false);
    jPanelOeste.setMinimumSize(new Dimension(75, 10));
    jPanelOeste.setPreferredSize(new Dimension(75, 10));
    jPanelNorte.setMinimumSize(new Dimension(149, 52));
    jPanelNorte.setPreferredSize(new Dimension(149, 52));
    jComboBox1.addActionListener(new TRBase_jComboBox1_actionAdapter(this));
    jLabel5.setText("Fps:");
    jLabel5.setMaximumSize(new Dimension(100, 16));
    jLabel5.setMinimumSize(new Dimension(100, 16));
    jLabel5.setPreferredSize(new Dimension(100, 16));
    labelvel.setText("0");
    labelvel.setHorizontalAlignment(SwingConstants.RIGHT);
    labelvel.setMinimumSize(new Dimension(4, 20));
    labelvel.setPreferredSize(new Dimension(35, 20));
    labelvel.setEditable(false);
    jComboBox1.setPreferredSize(new Dimension(50, 25));
    metDavis.setText("Random distrib");
    metDavis.setMaximumSize(new Dimension(130, 26));
    metDavis.setMinimumSize(new Dimension(130, 26));
    metDavis.setPreferredSize(new Dimension(135, 26));
    metDavis.addActionListener(new TRBase_metDavis_actionAdapter(this));
    metFases.setText("Lenses & gratings");
    metFases.setMaximumSize(new Dimension(130, 26));
    metFases.setMinimumSize(new Dimension(130, 26));
    metFases.setPreferredSize(new Dimension(135, 26));
    metFases.addActionListener(new TRBase_metFases_actionAdapter(this));
    grupo.add(metDavis);
    grupo.add(metFases);
    metDavis.setSelected(true);
    metDavis.setEnabled(false);//lite
    metFases.setEnabled(false);//lite
    this.add(jPanelBase,  BorderLayout.CENTER);
    jPanelBase.add(jPanelEste,  BorderLayout.EAST);
    jPanelBase.add(panelCoord, BorderLayout.CENTER);
    jPanelBase.add(jPanelNorte, BorderLayout.NORTH);
    jPanelBase.add(jPanelSur,  BorderLayout.SOUTH);
    jPanelBase.add(jPanelOeste,  BorderLayout.WEST);
    jPanelNorte.add(jLabel1, null);
    jPanelSur.add(license, null);
    jPanelSur.add(jButton1, null);
    jPanelEste.add(jLabel2, null);
    jPanelEste.add(fieldFil, null);
    jPanelEste.add(jLabel3, null);
    jPanelEste.add(fieldCol, null);
    jPanelEste.add(labelFactorY,null);
    jPanelEste.add(fieldFactorY,null);
    jPanelEste.add(labelFactorX,null);
    jPanelEste.add(fieldFactorX,null);
    jPanelEste.add(botonInit, null);
    jPanelEste.add(jLabel4, null);
    jPanelEste.add(jComboBox1, null);
    jPanelEste.add(etiqz,null);
    jPanelEste.add(zSlider,null);
    jPanelEste.add(labelFactorZ,null);
    jPanelEste.add(fieldFactorZ);
    jPanelEste.add(labelVortex,null);
    jPanelEste.add(fieldVortex,null);
    jPanelEste.add(quitar,null);
    jPanelEste.add(jLabel5, null);
    jPanelEste.add(labelvel, null);
    jPanelEste.add(metDavis,null);
    jPanelEste.add(metFases,null);
  }
  //Iniciar el applet
  public void start() {
  }
  //Detener el applet
  public void stop() {
  }
  //Destruir el applet
  public void destroy() {
    //Comment if there is no QICam available
    //panelCoord.StopGrab();
  }
  //Obtener informaci锟絥 del applet
  public String getAppletInfo() {
    return "Informaci髇 del applet";
  }
  //Obtener informaci锟絥 del par锟絤etro
  public String[][] getParameterInfo() {
    return null;
  }
  //M锟絫odo Main
  public static void main(String[] args) {
    TRBase applet = new TRBase();
    applet.isStandalone = true;
    Frame frame;
    frame = new Frame();
    frame.setTitle("Hologram generation");
    frame.add(applet, BorderLayout.CENTER);
    applet.init();
    applet.start();
    frame.setSize(984,620);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
    frame.setVisible(true);
  }

  void jButton1_actionPerformed(ActionEvent e) {
    System.exit(0);
  }

  void quitar_actionPerformed(ActionEvent e) {
    panelCoord.quitaTrampa();
  }

  void license_actionPerformed(ActionEvent e){
    //Shows licensing terms.
    JFrame licenseFrame = new JFrame("License terms");
    licenseFrame.setSize(new Dimension(500,300));
    JScrollPane jScrollPane_Doc = new JScrollPane();
    jTextPane_Lic.setEditable(false);
    jTextPane_Lic.setMargin(new Insets(10, 10, 10, 10));
    licenseFrame.getContentPane().add(jScrollPane_Doc,  BorderLayout.CENTER);
    jScrollPane_Doc.getViewport().add(jTextPane_Lic, null);
    licenseFrame.setResizable(false);
    licenseFrame.setVisible(true);

  }


  private void carga_licencia(){
    String s = null;
    URL info_page = null;
    try {
      s="license.txt";
      info_page = getClass().getResource(s);
      // ...  use the URL to initialize the editor pane  ...
    } catch (Exception eee) {
      System.err.println("Couldn't create help URL: " + s);
    }
    try{
      jTextPane_Lic.setPage(info_page);
    } catch (IOException e) {
      System.err.println("Attempted to read a bad URL: " + info_page);
    }
  }


  void botonInit_actionPerformed(ActionEvent e) {
    //Takes column and row values and reads the modulator map
    ncol = Integer.valueOf(fieldCol.getText()).intValue();
    nfil = Integer.valueOf(fieldFil.getText()).intValue();
    if(ncol*nfil == 1024*768) {
      big = true;
    }else dim0 = nfil*ncol;
    FrameHolo.factorEscY = Double.valueOf(fieldFactorY.getText()).doubleValue();
    FrameHolo.factorEscX = Double.valueOf(fieldFactorX.getText()).doubleValue();
    JFrame fr = new JFrame();
    Object[] options = {"OK"};

    JOptionPane hola = new JOptionPane();// noastnocurva
    int answer = hola.showConfirmDialog(null,"Select default phase and aberration files","Warning",JOptionPane.YES_NO_OPTION);
    if (answer == JOptionPane.NO_OPTION){

      hola = new JOptionPane("Choose a phase map",
                             JOptionPane.INFORMATION_MESSAGE,
                             JOptionPane.DEFAULT_OPTION, null, options);
      JDialog dialog = hola.createDialog(fr, "");
      dialog.setVisible(true);
      leeCurva();//nocurva

      hola = new JOptionPane("Choose the aberration correction",
                             JOptionPane.INFORMATION_MESSAGE,
                             JOptionPane.DEFAULT_OPTION, null, options);
      dialog = hola.createDialog(fr, "");
      dialog.setVisible(true);
      leeAst();//noast
    }else{
      leeDefaultFiles();
    }
  }

  void jComboBox1_actionPerformed(ActionEvent e) {
    panelCoord.indexSel = jComboBox1.getSelectedIndex();
    if(panelCoord.indexSel >=0){
      Double temp = (Double)FrameHolo.zTrampas.elementAt(panelCoord.indexSel);
      int valor = temp.intValue();
      zSlider.setValue(valor);
    }
    panelCoord.repaint();
  }

  void fieldFactorX_keyTyped(KeyEvent e) {
    if(e.getKeyChar()==KeyEvent.VK_ENTER){
      double factX = Double.valueOf(fieldFactorX.getText()).doubleValue();
      FrameHolo.invcol = factX/FrameHolo.col0;
    }
  }

  void fieldFactorY_keyTyped(KeyEvent e) {
    if(e.getKeyChar()==KeyEvent.VK_ENTER){
      double factY = Double.valueOf(fieldFactorY.getText()).doubleValue();
      FrameHolo.invfil = factY/FrameHolo.fil0;
    }
  }

  void fieldFactorZ_keyTyped(KeyEvent e){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -