Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
FVHTTP Server - ImpostazioniDialog.java

ImpostazioniDialog.java

Caricato da: Fraioveio
Scarica il programma completo

  1. package fvhttpserver;
  2.  
  3. import java.io.IOException;
  4. import javax.swing.JOptionPane;
  5.  
  6. public class ImpostazioniDialog extends javax.swing.JDialog {
  7.     public ImpostazioniDialog(java.awt.Frame parent) {
  8.         super(parent);
  9.         initComponents();
  10.        
  11.         Impostazioni im = Impostazioni.getImpostazioni();
  12.        
  13.         port.setText("" + im.port);
  14.         dir.setText(im.basedir);
  15.     }
  16.  
  17.     @SuppressWarnings("unchecked")
  18.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  19.     private void initComponents() {
  20.  
  21.         jLabel1 = new javax.swing.JLabel();
  22.         jLabel2 = new javax.swing.JLabel();
  23.         port = new javax.swing.JTextField();
  24.         dir = new javax.swing.JTextField();
  25.         jButton1 = new javax.swing.JButton();
  26.         jButton2 = new javax.swing.JButton();
  27.  
  28.         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  29.         setTitle("FVHTTP Server - Impostazioni");
  30.  
  31.         jLabel1.setText("Server Port:");
  32.  
  33.         jLabel2.setText("Server directory:");
  34.  
  35.         port.setText("80");
  36.  
  37.         jButton1.setText("Annulla");
  38.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  39.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  40.                 jButton1ActionPerformed(evt);
  41.             }
  42.         });
  43.  
  44.         jButton2.setText("Salva");
  45.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  46.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  47.                 jButton2ActionPerformed(evt);
  48.             }
  49.         });
  50.  
  51.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  52.         getContentPane().setLayout(layout);
  53.         layout.setHorizontalGroup(
  54.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  55.             .addGroup(layout.createSequentialGroup()
  56.                 .addContainerGap()
  57.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  58.                     .addGroup(layout.createSequentialGroup()
  59.                         .addComponent(jButton1)
  60.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 207, Short.MAX_VALUE)
  61.                         .addComponent(jButton2))
  62.                     .addGroup(layout.createSequentialGroup()
  63.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  64.                             .addComponent(jLabel2)
  65.                             .addComponent(jLabel1))
  66.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  67.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  68.                             .addComponent(port, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
  69.                             .addComponent(dir, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE))))
  70.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  71.         );
  72.         layout.setVerticalGroup(
  73.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  74.             .addGroup(layout.createSequentialGroup()
  75.                 .addContainerGap()
  76.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  77.                     .addComponent(jLabel1)
  78.                     .addComponent(port, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  79.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  80.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  81.                     .addComponent(jLabel2)
  82.                     .addComponent(dir, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  83.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  84.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  85.                     .addComponent(jButton1)
  86.                     .addComponent(jButton2))
  87.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  88.         );
  89.  
  90.         pack();
  91.     }// </editor-fold>//GEN-END:initComponents
  92.  
  93.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  94.         try {
  95.             Impostazioni.setImpostazioni(Integer.parseInt(port.getText()), dir.getText());
  96.             setVisible(false);
  97.            
  98.             Main.stopServer();
  99.             Main.startServer();
  100.             try {
  101.                 Thread.sleep(100);
  102.             } catch (InterruptedException ex) {}
  103.            
  104.             dispose();
  105.         } catch (IOException ex) {
  106.             JOptionPane.showMessageDialog(this, ex, "Errore", JOptionPane.ERROR_MESSAGE);
  107.         }
  108.     }//GEN-LAST:event_jButton2ActionPerformed
  109.  
  110.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  111.         dispose();
  112.     }//GEN-LAST:event_jButton1ActionPerformed
  113.  
  114.     // Variables declaration - do not modify//GEN-BEGIN:variables
  115.     private javax.swing.JTextField dir;
  116.     private javax.swing.JButton jButton1;
  117.     private javax.swing.JButton jButton2;
  118.     private javax.swing.JLabel jLabel1;
  119.     private javax.swing.JLabel jLabel2;
  120.     private javax.swing.JTextField port;
  121.     // End of variables declaration//GEN-END:variables
  122. }