java/abc-drupal-gui/src/cz/frantovo/abcDrupal/gui/HlavniOkno.java
author František Kučera <franta-hg@frantovo.cz>
Fri Jan 01 17:11:36 2010 +0100 (2010-01-01)
changeset 5 ed73b8912549
parent 4 5816c7f61a2a
permissions -rw-r--r--
Navázání DB spojení a kontrola databází SQL dotazem.
     1 /*
     2  * HlavniOkno.java
     3  *
     4  * Created on 30.12.2009, 2:22:41
     5  */
     6 package cz.frantovo.abcDrupal.gui;
     7 
     8 import com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel;
     9 import cz.frantovo.abcDrupal.Konvertor;
    10 import cz.frantovo.abcDrupal.PosluchacLogu;
    11 import cz.frantovo.abcDrupal.PromenneProstredi;
    12 import java.util.logging.Level;
    13 import java.util.logging.Logger;
    14 import javax.swing.UIManager;
    15 import javax.swing.UnsupportedLookAndFeelException;
    16 
    17 /**
    18  *
    19  * @author fiki
    20  */
    21 public class HlavniOkno extends javax.swing.JFrame implements PosluchacLogu {
    22 
    23     private static final Logger log = Logger.getLogger(HlavniOkno.class.getName());
    24 
    25     /** Creates new form HlavniOkno */
    26     public HlavniOkno() {
    27 	initComponents();
    28 	setLocationRelativeTo(null);
    29 	nactiPromenneProstredi();
    30     }
    31 
    32     private void nactiPromenneProstredi() {
    33 	String zdroj = System.getenv(PromenneProstredi.MIGRACE_ZDROJ.toString());
    34 	if (zdroj != null) {
    35 	    jdbcZdroj.setText(zdroj);
    36 	}
    37 	String cil = System.getenv(PromenneProstredi.MIGRACE_CIL.toString());
    38 	if (cil != null) {
    39 	    jdbcCil.setText(cil);
    40 	}
    41     }
    42 
    43     /** This method is called from within the constructor to
    44      * initialize the form.
    45      * WARNING: Do NOT modify this code. The content of this method is
    46      * always regenerated by the Form Editor.
    47      */
    48     @SuppressWarnings("unchecked")
    49     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    50     private void initComponents() {
    51 
    52         jLabel1 = new javax.swing.JLabel();
    53         jLabel2 = new javax.swing.JLabel();
    54         jdbcZdroj = new javax.swing.JTextField();
    55         jdbcCil = new javax.swing.JTextField();
    56         jScrollPane1 = new javax.swing.JScrollPane();
    57         vystup = new javax.swing.JTextArea();
    58         nahratData = new javax.swing.JButton();
    59 
    60         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    61         setTitle("ABC-Drupal");
    62 
    63         jLabel1.setText("Zdroj");
    64 
    65         jLabel2.setText("Cíl");
    66 
    67         jdbcZdroj.setText("jdbc:mysql://127.0.0.1:3306/itbiz?user=itbiz&password=nbusr123");
    68 
    69         jdbcCil.setText("jdbc:mysql://127.0.0.1:3306/abclinuxu?user=abclinuxu&password=nbusr123");
    70 
    71         vystup.setColumns(20);
    72         vystup.setEditable(false);
    73         vystup.setRows(5);
    74         vystup.setEnabled(false);
    75         jScrollPane1.setViewportView(vystup);
    76 
    77         nahratData.setText("Nahrát data");
    78         nahratData.addMouseWheelListener(new java.awt.event.MouseWheelListener() {
    79             public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
    80                 nahratDataMouseWheelMoved(evt);
    81             }
    82         });
    83         nahratData.addActionListener(new java.awt.event.ActionListener() {
    84             public void actionPerformed(java.awt.event.ActionEvent evt) {
    85                 nahratDataActionPerformed(evt);
    86             }
    87         });
    88 
    89         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    90         getContentPane().setLayout(layout);
    91         layout.setHorizontalGroup(
    92             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    93             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
    94                 .addContainerGap()
    95                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
    96                     .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 599, Short.MAX_VALUE)
    97                     .addGroup(layout.createSequentialGroup()
    98                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
    99                             .addComponent(jLabel1)
   100                             .addComponent(jLabel2))
   101                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
   102                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   103                             .addComponent(jdbcCil, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)
   104                             .addComponent(jdbcZdroj, javax.swing.GroupLayout.DEFAULT_SIZE, 560, Short.MAX_VALUE)))
   105                     .addComponent(nahratData))
   106                 .addContainerGap())
   107         );
   108         layout.setVerticalGroup(
   109             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   110             .addGroup(layout.createSequentialGroup()
   111                 .addContainerGap()
   112                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
   113                     .addComponent(jLabel1)
   114                     .addComponent(jdbcZdroj, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
   115                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
   116                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
   117                     .addComponent(jdbcCil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
   118                     .addComponent(jLabel2))
   119                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
   120                 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)
   121                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
   122                 .addComponent(nahratData)
   123                 .addContainerGap())
   124         );
   125 
   126         pack();
   127     }// </editor-fold>//GEN-END:initComponents
   128 
   129     private void nahratDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nahratDataActionPerformed
   130 	Konvertor k = new Konvertor(jdbcZdroj.getText(), jdbcCil.getText(), this);
   131 	nahratData.setEnabled(false);
   132 	nahratData.setToolTipText("Pokud chcete spustit migraci ještě jednou, pootočte kolečkem myši :-)");
   133 	k.konvertuj();
   134     }//GEN-LAST:event_nahratDataActionPerformed
   135 
   136     private void nahratDataMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {//GEN-FIRST:event_nahratDataMouseWheelMoved
   137 	nahratData.setEnabled(true);
   138 	nahratData.setToolTipText(null);
   139     }//GEN-LAST:event_nahratDataMouseWheelMoved
   140 
   141     /**
   142      * @param args the command line arguments
   143      */
   144     public static void main(String args[]) {
   145 	nastavLaF();
   146 
   147 	java.awt.EventQueue.invokeLater(new Runnable() {
   148 
   149 	    public void run() {
   150 		new HlavniOkno().setVisible(true);
   151 	    }
   152 	});
   153     }
   154 
   155     private static void nastavLaF() {
   156 	try {
   157 	    UIManager.setLookAndFeel(new NimbusLookAndFeel());
   158 	} catch (UnsupportedLookAndFeelException e) {
   159 	    log.log(Level.FINE, "Nepodařilo se načíst LaF. Nevadí.");
   160 	}
   161     }
   162     // Variables declaration - do not modify//GEN-BEGIN:variables
   163     private javax.swing.JLabel jLabel1;
   164     private javax.swing.JLabel jLabel2;
   165     private javax.swing.JScrollPane jScrollPane1;
   166     private javax.swing.JTextField jdbcCil;
   167     private javax.swing.JTextField jdbcZdroj;
   168     private javax.swing.JButton nahratData;
   169     private javax.swing.JTextArea vystup;
   170     // End of variables declaration//GEN-END:variables
   171 
   172     public void vypis(String zprava) {
   173 	vystup.append(zprava + "\n");
   174     }
   175 }