PageRenderTime 103ms CodeModel.GetById 40ms app.highlight 10ms RepoModel.GetById 51ms app.codeStats 0ms

/src/mpv5/ui/dialogs/PropertyDialog.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 131 lines | 80 code | 16 blank | 35 comment | 1 complexity | c75d24d85220459ffb27498369dfd5fd MD5 | raw file
  1/*
  2 * To change this template, choose Tools | Templates
  3 * and open the template in the editor.
  4 */
  5
  6/*
  7 * PropertyDialog.java
  8 *
  9 * Created on Sep 2, 2010, 3:02:18 PM
 10 */
 11package mpv5.ui.dialogs;
 12
 13import java.awt.event.ActionEvent;
 14import java.awt.event.ActionListener;
 15import javax.swing.JDialog;
 16import mpv5.db.objects.User;
 17import mpv5.globals.GlobalSettings;
 18import mpv5.globals.LocalSettings;
 19import mpv5.globals.Messages;
 20
 21/**
 22 *
 23 * @author andreas.weber
 24 */
 25public class PropertyDialog extends javax.swing.JDialog {
 26
 27    /**
 28     * Change a Global property
 29     */
 30    public static final int GLOBAL = 0;
 31    /**
 32     * Change a Local property
 33     */
 34    public static final int LOCAL = 1;
 35    /**
 36     * Change a User property
 37     */
 38    public static final int USER = 2;
 39    private final int scope;
 40
 41    /** Creates new form PropertyDialog
 42     * @param scope
 43     * @param property
 44     * @param value
 45     */
 46    public PropertyDialog(int scope, String property, Object value) {
 47        initComponents();
 48        setModalityType(JDialog.ModalityType.APPLICATION_MODAL);
 49        labeledTextField1.getTextField().setEditable(false);
 50        labeledTextField1.setText(Messages.PROPERTY);
 51        labeledTextField2.setText(Messages.VALUE);
 52        labeledTextField2.getTextField().addActionListener(new ActionListener() {
 53
 54            public void actionPerformed(ActionEvent e) {
 55                dispose();
 56            }
 57        });
 58
 59        labeledTextField1.setText(property);
 60        labeledTextField2.setText(value);
 61        this.scope = scope;
 62        setVisible(true);
 63    }
 64
 65    @Override
 66    public void dispose() {
 67        save();
 68        super.dispose();
 69    }
 70
 71    private void save() {
 72        switch (scope) {
 73            case GLOBAL:
 74                GlobalSettings.setProperty(labeledTextField1.getText(), labeledTextField2.getText());
 75                break;
 76            case LOCAL:
 77                LocalSettings.setProperty(labeledTextField1.getText(), labeledTextField2.getText());
 78                break;
 79            case USER:
 80                User.getCurrentUser().getProperties().changeProperty(labeledTextField1.getText(), labeledTextField2.getText());
 81                break;
 82            default:;
 83        }
 84    }
 85
 86    /** This method is called from within the constructor to
 87     * initialize the form.
 88     * WARNING: Do NOT modify this code. The content of this method is
 89     * always regenerated by the Form Editor.
 90     */
 91    @SuppressWarnings("unchecked")
 92    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 93    private void initComponents() {
 94
 95        labeledTextField1 = new mpv5.ui.beans.LabeledTextField();
 96        labeledTextField2 = new mpv5.ui.beans.LabeledTextField();
 97
 98        setName("Form"); // NOI18N
 99
100        labeledTextField1.setName("labeledTextField1"); // NOI18N
101
102        labeledTextField2.setName("labeledTextField2"); // NOI18N
103
104        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
105        getContentPane().setLayout(layout);
106        layout.setHorizontalGroup(
107            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
108            .addGroup(layout.createSequentialGroup()
109                .addContainerGap()
110                .addComponent(labeledTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
111                .addGap(18, 18, 18)
112                .addComponent(labeledTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 207, Short.MAX_VALUE)
113                .addContainerGap())
114        );
115        layout.setVerticalGroup(
116            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
117            .addGroup(layout.createSequentialGroup()
118                .addContainerGap()
119                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
120                    .addComponent(labeledTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
121                    .addComponent(labeledTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
122                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
123        );
124
125        pack();
126    }// </editor-fold>//GEN-END:initComponents
127    // Variables declaration - do not modify//GEN-BEGIN:variables
128    private mpv5.ui.beans.LabeledTextField labeledTextField1;
129    private mpv5.ui.beans.LabeledTextField labeledTextField2;
130    // End of variables declaration//GEN-END:variables
131}