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

Last change on this file since 6831 was 6831, checked in by mlg, 14 years ago

Bug correction :
bug:0001837 : there is now a default translation file (in english), so the application won't crash when a translation is not found
bug:0001833 : the accents are manage when creating a new category
bug:0001832 : on a right click on the categories list, the selection is now visible
bug:0001830 : there is no bug on refreshing the categories tree

Features :
feature:001828 : exif and iptc tags are kept after resizing an image
feature:001827 : pwg.images.addChunk is now fully used : images are split into chunks before being sent

Other features :

  • The user can manage his preferences :

-The web images size
-The chunks size

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