/* * Created on Jun 30, 2007 * * Copyright (c) 2006-2007 Jens Gulden * * http://www.frinika.com * * This file is part of Frinika. * * Frinika is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * Frinika is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with Frinika; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package com.frinika.global; import com.frinika.gui.OptionsBinder; import com.frinika.project.gui.ProjectFrame; /** * Dialog to display global configuration. * The actual form elements are encapsulated in class ConfigDialogPanel. * @see ConfigDialogPanel * * @author Jens Gulden */ public class ConfigDialog extends javax.swing.JDialog { protected ProjectFrame parent; protected OptionsBinder optionsBinder; protected boolean hasBeenApplied = false; /** Creates new form ConfigDialog */ public ConfigDialog(ProjectFrame parent, OptionsBinder optionsBinder) { super(parent, false); this.parent = parent; this.optionsBinder = optionsBinder; initComponents(); getRootPane().setDefaultButton(buttonOk); setSize(750, 500); setLocation(300, 300); } public void show() { optionsBinder.refresh(); super.show(); } public void ok() { optionsBinder.update(); parent.repaintViews(); hasBeenApplied = false; // to force re-backup next time hide(); FrinikaConfig.store(); } public void apply() { if (!hasBeenApplied) { // first time applied optionsBinder.backup(); } hasBeenApplied = true; optionsBinder.update(); parent.repaintViews(); } public void cancel() { if (hasBeenApplied) { optionsBinder.restore(); hasBeenApplied = false; parent.repaintViews(); } hide(); } /** 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. */ // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents private void initComponents() { buttonPanel = new javax.swing.JPanel(); innerButtonPanel = new javax.swing.JPanel(); buttonOk = new javax.swing.JButton(); buttonApply = new javax.swing.JButton(); buttonCancel = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); setTitle("Frinika Configuration"); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { formWindowClosing(evt); } }); innerButtonPanel.setLayout(new java.awt.GridLayout(1, 3, 5, 0)); buttonOk.setText("OK"); buttonOk.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonOkActionPerformed(evt); } }); innerButtonPanel.add(buttonOk); buttonApply.setText("Apply"); buttonApply.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonApplyActionPerformed(evt); } }); innerButtonPanel.add(buttonApply); buttonCancel.setText("Cancel"); buttonCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonCancelActionPerformed(evt); } }); innerButtonPanel.add(buttonCancel); buttonPanel.add(innerButtonPanel); getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH); pack(); }// </editor-fold>//GEN-END:initComponents private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing cancel(); }//GEN-LAST:event_formWindowClosing private void buttonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonOkActionPerformed ok(); }//GEN-LAST:event_buttonOkActionPerformed private void buttonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyActionPerformed apply(); }//GEN-LAST:event_buttonApplyActionPerformed private void buttonCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelActionPerformed cancel(); }//GEN-LAST:event_buttonCancelActionPerformed /** * @param args the command line arguments */ /* public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ConfigDialog(new javax.swing.JFrame(), true).setVisible(true); } }); } */ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton buttonApply; private javax.swing.JButton buttonCancel; private javax.swing.JButton buttonOk; private javax.swing.JPanel buttonPanel; private javax.swing.JPanel innerButtonPanel; // End of variables declaration//GEN-END:variables }