All Downloads are FREE. Search and download functionalities are using the official Maven repository.

decodes.decoder.PBinToShefGrid Maven / Gradle / Ivy

Go to download

A collection of software for aggregatting and processing environmental data such as from NOAA GOES satellites.

The newest version!

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PBinToShef.java
 *
 * Created on Jan 4, 2012, 2:04:26 PM
 */

package decodes.decoder;

import ilex.util.Logger;

import java.awt.EventQueue;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.text.Caret;

/**
 *
 * @author iblagoev
 */
public class PBinToShefGrid extends JFrame {

	
	
    /** Creates new form PBinToShef */
    public PBinToShefGrid() {
    	super("P-Bin to SHEF");
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // 
    
    boolean signed = false;
    private void initComponents() {
        GridBagConstraints gridBagConstraints;

        
        resultTextField = new JTextField();
        mainPanel = new JPanel();
        inputLabel = new JLabel();
        inputTextField = new JTextField();
        outputLabel = new JLabel();
        signedCheckBox = new JCheckBox();
        convertButton = new JButton();

        resultTextField.setEditable(false);
        
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new GridLayout());

        mainPanel.setLayout(new GridBagLayout());
        
        signedCheckBox.setText("Signed");
      signedCheckBox.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
              signedCheckBoxActionPerformed(evt);
          }

          
  		private void signedCheckBoxActionPerformed(ActionEvent evt) {
  			signed = signedCheckBox.isSelected();
  		}
        });
        
        convertButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
					convertActionPerformed(evt);
				} catch (ScriptFormatException e) {
					e.printStackTrace();
				} catch (FieldParseException e) {
					e.printStackTrace();
				}
            }
            
  		private void convertActionPerformed(ActionEvent evt) throws ScriptFormatException, FieldParseException {
  			
  			String input;
  			//check if the input string contains valid characters
  			while(true)
  			{
  				input = inputTextField.getText();
//  				System.out.println(input.length());
  				
  				//input.trim();
  				//for some reason trim() did not work
  				input = input.replace(String.valueOf((char)32), "");
  				
//  				System.out.println(input);
//  				System.out.println(input.length());
  				
  				if(input.equals(""))
  				{
  					JOptionPane.showMessageDialog(null,  "Please enter a value", "Warning!", JOptionPane.WARNING_MESSAGE);
  					return;
  				}
  				
  				//byte[] str = input.getBytes();
	  			
  				for(int i = 0; i127)
	  				{
	  					JOptionPane.showMessageDialog( null, "Invalid Input", "Error!", JOptionPane.ERROR_MESSAGE );
	  					return;
	  				}
	  			}
	  			break;
  			}
  			byte field[] = input.getBytes();
  			
  			NumberParser np = new NumberParser();
  			
  			if(signed)
  				np.setDataType('i');
  			else
  				np.setDataType('b');
  			resultTextField.setText("" + np.parseDataValue(field));
  		}
        });
        
        inputTextField.addKeyListener(
        		  new KeyAdapter() {
        		     public void keyPressed(KeyEvent e) {
        		       if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        		          convertButton.doClick();
        		       }
        		     }
        		  });
        
        signedCheckBox.addKeyListener(
      		  new KeyAdapter() {
      		     public void keyPressed(KeyEvent e) {
      		       if (e.getKeyCode() == KeyEvent.VK_ENTER) {
      		          convertButton.doClick();
      		       }
      		     }
      		  });
        		

        inputLabel.setText("Input:");
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        //gridBagConstraints.anchor = null;
        gridBagConstraints.insets = new Insets(16, 34, 0, 0);
        mainPanel.add(inputLabel, gridBagConstraints);

        inputTextField.setText("");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.ipadx = 235;
        //gridBagConstraints.anchor = null;
        gridBagConstraints.insets = new Insets(6, 34, 0, 0);
        mainPanel.add(inputTextField, gridBagConstraints);

        resultTextField.setText("");
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.ipadx = 235;
        //gridBagConstraints.anchor = null;
        gridBagConstraints.insets = new Insets(6, 34, 0, 0);
        mainPanel.add(resultTextField, gridBagConstraints);

        outputLabel.setText("Result:");
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        //gridBagConstraints.anchor = null;
        gridBagConstraints.insets = new Insets(4, 34, 0, 0);
        mainPanel.add(outputLabel, gridBagConstraints);

        signedCheckBox.setText("Signed");
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridheight = 2;
        //gridBagConstraints.anchor = null;
        gridBagConstraints.insets = new Insets(5, 18, 0, 49);
        mainPanel.add(signedCheckBox, gridBagConstraints);

        convertButton.setText("Convert");
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.ipadx = 51;
        gridBagConstraints.ipady = 15;
        //gridBagConstraints.anchor = null;
        gridBagConstraints.insets = new Insets(18, 34, 44, 0);
        mainPanel.add(convertButton, gridBagConstraints);

        getContentPane().add(mainPanel);
        
        pack();
    }// 

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PBinToShefGrid().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private JButton convertButton;
    private JCheckBox signedCheckBox;
    private JLabel inputLabel;
    private JLabel outputLabel;
    private JPanel mainPanel;
    private JTextField inputTextField;
    private JTextField resultTextField;
    // End of variables declaration

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy