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

org.helm.notation2.parser.HELMNotationParserUI Maven / Gradle / Ivy

The newest version!
/**
 * *****************************************************************************
 * Copyright C 2015, The Pistoia Alliance
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *****************************************************************************
 */
package org.helm.notation2.parser;

import java.awt.Font;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UnsupportedLookAndFeelException;

import org.helm.notation2.parser.exceptionparser.ExceptionState;
import org.jdom2.JDOMException;

/**
 * HELMNotationParserUI class to show
 *
 * @author hecht
 */
public class HELMNotationParserUI extends JFrame {

  /**
   * Creates new form ContactEditorUI
   */
  public HELMNotationParserUI() {
    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")
  private void initComponents() {

    jScrollPane1 = new javax.swing.JScrollPane();
    input = new javax.swing.JTextArea();
    inputLabel = new javax.swing.JLabel();
    outputLabel = new javax.swing.JLabel();
    jScrollPane2 = new javax.swing.JScrollPane();
    output = new javax.swing.JTextArea();
    jRadioHELM = new javax.swing.JRadioButton();
    jRadioJSON = new javax.swing.JRadioButton();
    jButton1 = new javax.swing.JButton();
    bg = new javax.swing.ButtonGroup();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("HELMNotationParser");
    input.setColumns(20);
    input.setRows(5);
    jScrollPane1.setViewportView(input);

    inputLabel.setText("HELM-Input:");
    inputLabel.setFont(new Font("Arial", Font.BOLD, 20));
    inputLabel.setHorizontalAlignment(JLabel.CENTER);
    inputLabel.setVerticalAlignment(JLabel.CENTER);

    outputLabel.setText("Output:");
    outputLabel.setFont(new Font("Arial", Font.BOLD, 20));
    outputLabel.setHorizontalAlignment(JLabel.CENTER);
    outputLabel.setVerticalAlignment(JLabel.CENTER);

    output.setColumns(20);
    output.setRows(5);
    jScrollPane2.setViewportView(output);

    jRadioHELM.setText("HELM2");
    jRadioHELM.addActionListener(new java.awt.event.ActionListener() {
      @Override
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jRadioButton1ActionPerformed(evt);
      }
    });

    jRadioJSON.setText("JSON");
    jRadioJSON.addActionListener(new java.awt.event.ActionListener() {
      @Override
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jRadioButton2ActionPerformed(evt);
      }
    });

    bg.add(jRadioHELM);
    bg.add(jRadioJSON);
    jRadioHELM.setSelected(true);
    jButton1.setText("Translate");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      @Override
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false).addComponent(inputLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(31, 31, 31).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jRadioHELM, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jButton1).addComponent(jRadioJSON, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 458, javax.swing.GroupLayout.PREFERRED_SIZE)).addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGap(132, 132, 132).addComponent(outputLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 458, javax.swing.GroupLayout.PREFERRED_SIZE))).addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(0, 0, 0).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(inputLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(outputLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGap(9, 9, 9).addComponent(jRadioHELM).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jRadioJSON).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jButton1).addContainerGap(778, Short.MAX_VALUE)).addComponent(jScrollPane1).addComponent(jScrollPane2))));

    pack();
  } // 

  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    String helmInput = input.getText();
    if (!(helmInput.contains("V2.0"))) {
      /* Translate into HELM2-format */
    	      helmInput = converter.doConvert(helmInput);
    	

    }

    /* read input */
    try {
      parser.parse(helmInput);
      writeOutputmessage();
    } catch (ExceptionState e) {
      output.setText("Invalid HELM-String (" + e.getMessage() + ")");
    }

  }

  private void writeOutputmessage() {
    if (jRadioHELM.isSelected()) {
      output.setText(parser.getHELM2Notation().toHELM2());
    } else if (jRadioJSON.isSelected()) {
      output.setText(parser.getJSON());
    } else {
      output.setText("No Output-Option was specified");
    }

  }

  private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
  }

  private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
  }

  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
      if ("Nimbus".equals(info.getName())) {
        try {
          javax.swing.UIManager.setLookAndFeel(info.getClassName());
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
            | UnsupportedLookAndFeelException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        break;
      }
    }

    // 

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        new HELMNotationParserUI().setVisible(true);
      }
    });
  }

  // Variables declaration - do not modify
  private javax.swing.JButton jButton1;

  private javax.swing.JLabel inputLabel;

  private javax.swing.JLabel outputLabel;

  private javax.swing.JRadioButton jRadioHELM;

  private javax.swing.JRadioButton jRadioJSON;

  private javax.swing.ButtonGroup bg;

  private javax.swing.JScrollPane jScrollPane1;

  private javax.swing.JScrollPane jScrollPane2;

  private javax.swing.JTextArea input;

  private javax.swing.JTextArea output;

  private ConverterHELM1ToHELM2 converter = new ConverterHELM1ToHELM2();

  private ParserHELM2 parser = new ParserHELM2();
  // End of variables declaration
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy