package me.legrange.panstamp.gui; import java.util.logging.Level; import java.util.logging.Logger; import me.legrange.panstamp.gui.model.Model; import me.legrange.panstamp.tools.store.DataStoreException; /** * * @author gideon */ public class PreferencesDialog extends javax.swing.JDialog { /** * Creates new form PreferencesDialog */ public PreferencesDialog(java.awt.Frame parent, Model model) throws DataStoreException { super(parent, true); this.model = model; initComponents(); setLocationRelativeTo(null); directoryTextField.setText(model.getFileLibary()); } /** * 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() { configTabs = new javax.swing.JTabbedPane(); networkPanel = new javax.swing.JPanel(); directoryLabel = new javax.swing.JLabel(); directoryTextField = new javax.swing.JTextField(); okButton = new javax.swing.JButton(); cancelButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setTitle("Preferences"); setResizable(false); directoryLabel.setText("XML Definition Directory:"); javax.swing.GroupLayout networkPanelLayout = new javax.swing.GroupLayout(networkPanel); networkPanel.setLayout(networkPanelLayout); networkPanelLayout.setHorizontalGroup( networkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(networkPanelLayout.createSequentialGroup() .addContainerGap() .addGroup(networkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(networkPanelLayout.createSequentialGroup() .addComponent(directoryLabel) .addGap(0, 328, Short.MAX_VALUE)) .addComponent(directoryTextField)) .addContainerGap()) ); networkPanelLayout.setVerticalGroup( networkPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(networkPanelLayout.createSequentialGroup() .addContainerGap() .addComponent(directoryLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(directoryTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(27, Short.MAX_VALUE)) ); configTabs.addTab("Preferences", networkPanel); okButton.setText("OK"); okButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { okButtonActionPerformed(evt); } }); cancelButton.setText("Cancel"); cancelButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelButtonActionPerformed(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() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(configTabs) .addGroup(layout.createSequentialGroup() .addGap(6, 6, 6) .addComponent(okButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(cancelButton) .addContainerGap()))) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(configTabs, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cancelButton) .addComponent(okButton)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed try { String dir = directoryTextField.getText().trim(); if (!dir.isEmpty()) { model.setFileLibrary(dir); } else { model.clearFileLibry(); } dispose(); } catch (DataStoreException ex) { Logger.getLogger(PreferencesDialog.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_okButtonActionPerformed private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed dispose(); }//GEN-LAST:event_cancelButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cancelButton; private javax.swing.JTabbedPane configTabs; private javax.swing.JLabel directoryLabel; private javax.swing.JTextField directoryTextField; private javax.swing.JPanel networkPanel; private javax.swing.JButton okButton; // End of variables declaration//GEN-END:variables private final Model model; }