source: extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/PreferencesDialog.java

Last change on this file was 10748, checked in by mlg, 13 years ago

Adds support for addSimple
By default, addSimple will be used. It can be changed in the preferences dialog.

File size: 6.8 KB
Line 
1package fr.mael.jiwigo.ui.mainframe;
2
3import java.awt.BorderLayout;
4import java.awt.Dimension;
5import java.awt.FlowLayout;
6import java.awt.GridBagConstraints;
7import java.awt.GridBagLayout;
8import java.awt.event.ActionEvent;
9import java.awt.event.ActionListener;
10
11import javax.swing.JButton;
12import javax.swing.JCheckBox;
13import javax.swing.JDialog;
14import javax.swing.JFrame;
15import javax.swing.JLabel;
16import javax.swing.JOptionPane;
17import javax.swing.JPanel;
18import javax.swing.JTabbedPane;
19import javax.swing.JTextField;
20
21import fr.mael.jiwigo.transverse.enumeration.PreferencesEnum;
22import fr.mael.jiwigo.transverse.util.Messages;
23import fr.mael.jiwigo.transverse.util.preferences.PreferencesManagement;
24
25/**
26 *
27   Copyright (c) 2010, Mael
28   All rights reserved.
29
30   Redistribution and use in source and binary forms, with or without
31   modification, are permitted provided that the following conditions are met:
32    * Redistributions of source code must retain the above copyright
33      notice, this list of conditions and the following disclaimer.
34    * Redistributions in binary form must reproduce the above copyright
35      notice, this list of conditions and the following disclaimer in the
36      documentation and/or other materials provided with the distribution.
37    * Neither the name of jiwigo nor the
38      names of its contributors may be used to endorse or promote products
39      derived from this software without specific prior written permission.
40
41   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
42   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
43   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44   DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
45   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
46   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
50   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51   
52 * @author mael
53 *
54 */
55public class PreferencesDialog extends JDialog implements ActionListener {
56
57    /**
58     * Logger
59     */
60    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
61            .getLog(PreferencesDialog.class);
62
63    /**
64     * the tabs
65     */
66    private JTabbedPane tabPane;
67
68    /**
69     * preferences of the images tab
70     */
71    private JPanel panelImage;
72
73    /**
74     * width of the images
75     */
76    private JTextField fieldWidth;
77
78    /**
79     * height of the images
80     */
81    private JTextField fieldHeight;
82
83    /**
84     * size of the chunks
85     */
86    private JTextField fieldChunkSize;
87
88    /**
89     * label
90     */
91    private JLabel labelTaille;
92
93    /**
94     * label
95     */
96    private JLabel labelChunkSize;
97
98    /**
99     * label
100     */
101    private JLabel labelCroix;
102
103    /**
104     * label
105     */
106    private JLabel labelMethodSending;
107
108    /**
109     * save the preferences
110     */
111    private JButton boutonOk = new JButton("Ok");
112
113    /**
114     * panel that contains the buttons
115     */
116    private JPanel panelBoutons;
117
118    /**
119     * bouton to cancel
120     */
121    private JButton boutonAnnuler;
122
123    /**
124     * method to send
125     */
126    private JCheckBox checkboxMethodSending;
127
128    /**
129     * Constructor
130     * @param parent frame parent
131     */
132    public PreferencesDialog(JFrame parent) {
133        fieldWidth = new JTextField(PreferencesManagement.getValue(PreferencesEnum.WIDTH_ORIGINALE.getLabel()));
134        fieldHeight = new JTextField(PreferencesManagement.getValue(PreferencesEnum.HEIGHT_ORIGINAL.getLabel()));
135        fieldChunkSize = new JTextField(PreferencesManagement.getValue(PreferencesEnum.CHUNK_SIZE.getLabel()));
136        checkboxMethodSending = new JCheckBox(Messages.getMessage("preferences_useSimple"));
137        checkboxMethodSending.setSelected(PreferencesManagement.getValue(PreferencesEnum.SENDING_METHOD.getLabel())
138                .equals("0"));
139        labelTaille = new JLabel(Messages.getMessage("preferences_imagesSize"));
140        labelCroix = new JLabel("x");
141        labelChunkSize = new JLabel(Messages.getMessage("preferences_chunkSize"));
142        fieldWidth.setPreferredSize(new Dimension(50, 30));
143        fieldHeight.setPreferredSize(new Dimension(50, 30));
144        fieldChunkSize.setPreferredSize(new Dimension(50, 30));
145
146        panelImage = new JPanel(new GridBagLayout());
147        GridBagConstraints c = new GridBagConstraints();
148        c.gridx = 0;
149        c.gridy = 0;
150        c.anchor = GridBagConstraints.WEST;
151        panelImage.add(labelTaille, c);
152        c.gridx++;
153        panelImage.add(fieldWidth, c);
154        c.gridx++;
155        panelImage.add(labelCroix, c);
156        c.gridx++;
157        panelImage.add(fieldHeight, c);
158        c.gridy++;
159        c.gridx = 0;
160        panelImage.add(labelChunkSize, c);
161        c.gridx++;
162        panelImage.add(fieldChunkSize, c);
163        c.gridy++;
164        c.gridx = 0;
165        panelImage.add(checkboxMethodSending, c);
166
167        boutonAnnuler = new JButton(Messages.getMessage("cancel"));
168        boutonAnnuler.addActionListener(this);
169        boutonOk.addActionListener(this);
170        panelBoutons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
171        panelBoutons.add(boutonOk);
172        panelBoutons.add(boutonAnnuler);
173        boutonOk.setPreferredSize(new Dimension(90, 30));
174        boutonAnnuler.setPreferredSize(new Dimension(90, 30));
175
176        tabPane = new JTabbedPane();
177        tabPane.addTab(Messages.getMessage("preferences_tabImage"), panelImage);
178        this.setLayout(new BorderLayout());
179        this.add(tabPane, BorderLayout.CENTER);
180        this.add(panelBoutons, BorderLayout.SOUTH);
181        this.setSize(new Dimension(400, 300));
182        this.setLocationRelativeTo(null);
183        this.setVisible(true);
184    }
185
186    @Override
187    public void actionPerformed(ActionEvent e) {
188        if (e.getSource().equals(boutonAnnuler)) {
189            this.dispose();
190        } else if (e.getSource().equals(boutonOk)) {
191            try {
192                int width = Integer.valueOf(fieldWidth.getText());
193                int height = Integer.valueOf(fieldHeight.getText());
194                double chunk = Double.parseDouble(fieldChunkSize.getText().replace(",", "."));
195                PreferencesManagement.setValue(PreferencesEnum.WIDTH_ORIGINALE.getLabel(), String.valueOf(width));
196                PreferencesManagement.setValue(PreferencesEnum.HEIGHT_ORIGINAL.getLabel(), String.valueOf(height));
197                PreferencesManagement.setValue(PreferencesEnum.CHUNK_SIZE.getLabel(), String.valueOf(chunk));
198                PreferencesManagement.setValue(PreferencesEnum.SENDING_METHOD.getLabel(),
199                        checkboxMethodSending.isSelected() ? "0" : "1");
200                this.dispose();
201            } catch (NumberFormatException ex) {
202                ex.printStackTrace();
203                JOptionPane.showMessageDialog(this, Messages.getMessage("preferencesCheckValues"),
204                        Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE);
205            } catch (Exception ex) {
206                JOptionPane.showMessageDialog(this, Messages.getMessage("preferencesUnexpectedError"),
207                        Messages.getMessage("error"), JOptionPane.ERROR_MESSAGE);
208
209            }
210
211        }
212
213    }
214}
Note: See TracBrowser for help on using the repository browser.