Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package lu.fisch.unimozer.dialogs; import japa.parser.ParseException; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URI; import java.net.URISyntaxException; import java.util.logging.Level; import java.util.logging.Logger; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import lu.fisch.unimozer.Diagram; import lu.fisch.unimozer.MyClass; import lu.fisch.unimozer.Objectizer; import lu.fisch.unimozer.Unimozer; import lu.fisch.unimozer.interactiveproject.InteractiveProject; import org.apache.commons.io.FileUtils; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; /** * * @author Ronny */ public class NewInteractiveProjectDialog extends javax.swing.JDialog { org.w3c.dom.Document document; Diagram diagram; /** * Creates new form NewVisualizerDialog */ public NewInteractiveProjectDialog(java.awt.Frame parent, boolean modal, Diagram diagram) { super(parent, modal); this.diagram = diagram; initComponents(); this.setLocationRelativeTo(parent); this.setTitle("New interactive project"); try { //reading XML input file DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); document = db .parse(getClass().getResourceAsStream("/lu/fisch/unimozer/interactiveproject/projects.xml")); NodeList nodeList = document.getElementsByTagName("name"); //filling the Dropdown Menu for (int i = 0; i < nodeList.getLength(); i++) { jProjectComboBox.addItem(nodeList.item(i).getTextContent()); } } catch (SAXException | IOException ex) { Logger.getLogger(NewInteractiveProjectDialog.class.getName()).log(Level.SEVERE, null, ex); } catch (ParserConfigurationException ex) { Logger.getLogger(NewInteractiveProjectDialog.class.getName()).log(Level.SEVERE, null, ex); } } /** * 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") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jProjectComboBox = new javax.swing.JComboBox<>(); jLabel1 = new javax.swing.JLabel(); okButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jLabel1.setText("Please select the Visulaizer Project you want to use:"); okButton.setText("OK"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(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) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent( jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent( jProjectComboBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE).addComponent(okButton))) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jProjectComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE) .addComponent(okButton).addContainerGap())); pack(); }// </editor-fold>//GEN-END:initComponents private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed this.setVisible(false); String selection = (String) jProjectComboBox.getSelectedItem(); diagram.clear(); //create interactiveproject in diagram InteractiveProject ip = new InteractiveProject(selection, diagram); diagram.setInteractiveProject(ip); ip.loadFromXML(false); }//GEN-LAST:event_okButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JComboBox<String> jProjectComboBox; private javax.swing.JButton okButton; // End of variables declaration//GEN-END:variables }