source: extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/DialogPrivacyLevel.java @ 10750

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

Fixes a bug on the privacy level.

File size: 5.3 KB
Line 
1package fr.mael.jiwigo.ui.mainframe;
2
3import java.awt.BorderLayout;
4import java.awt.FlowLayout;
5import java.awt.event.ActionEvent;
6import java.awt.event.ActionListener;
7import java.util.HashMap;
8
9import javax.swing.AbstractListModel;
10import javax.swing.ComboBoxModel;
11import javax.swing.JButton;
12import javax.swing.JCheckBox;
13import javax.swing.JComboBox;
14import javax.swing.JDialog;
15import javax.swing.JLabel;
16import javax.swing.JPanel;
17
18import fr.mael.jiwigo.transverse.ImagesManagement;
19import fr.mael.jiwigo.transverse.util.Messages;
20
21/**
22 *
23   Copyright (c) 2010, Mael
24   All rights reserved.
25
26   Redistribution and use in source and binary forms, with or without
27   modification, are permitted provided that the following conditions are met:
28    * Redistributions of source code must retain the above copyright
29      notice, this list of conditions and the following disclaimer.
30    * Redistributions in binary form must reproduce the above copyright
31      notice, this list of conditions and the following disclaimer in the
32      documentation and/or other materials provided with the distribution.
33    * Neither the name of jiwigo nor the
34      names of its contributors may be used to endorse or promote products
35      derived from this software without specific prior written permission.
36
37   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
38   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
39   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40   DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
41   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
42   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
46   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 * @author mael
48 *
49 * Function that allows the use to choose a privacy level for the pictures
50 * he adds
51 */
52public class DialogPrivacyLevel extends JDialog implements ActionListener {
53    /**
54     * Button ok
55     */
56    private JButton buttonOk;
57
58    /**
59     * Combo to allow the user to choose the privacy level
60     */
61    private JComboBox comboPrivacyLevel;
62
63    /**
64     * Checkbox to remember the choice
65     */
66    private JCheckBox checkBoxRemember;
67
68    /**
69     * label
70     */
71    private JLabel labelChoice;
72
73    private HashMap<Integer, Integer> mapLevels = new HashMap<Integer, Integer>();
74
75    /**
76     * Constructor
77     */
78    public DialogPrivacyLevel() {
79        super(MainFrame.getInstance());
80        setModal(true);
81        mapLevels.put(0, 0);
82        mapLevels.put(1, 1);
83        mapLevels.put(2, 2);
84        mapLevels.put(3, 4);
85        mapLevels.put(4, 8);
86        checkBoxRemember = new JCheckBox(Messages.getMessage("dialogPrivacy_remember"));
87        labelChoice = new JLabel(Messages.getMessage("dialogPrivacy_choosePrivacy"));
88        JPanel panelChoice = new JPanel(new FlowLayout());
89        comboPrivacyLevel = new JComboBox(new privacyLevelModel());
90        comboPrivacyLevel.setSelectedIndex(0);
91        panelChoice.add(comboPrivacyLevel);
92        panelChoice.add(checkBoxRemember);
93        JPanel panelButton = new JPanel(new FlowLayout());
94        buttonOk = new JButton("Ok");
95        buttonOk.addActionListener(this);
96        panelButton.add(buttonOk);
97        this.setLayout(new BorderLayout());
98        this.add(panelChoice, BorderLayout.NORTH);
99        this.add(panelButton, BorderLayout.CENTER);
100
101        this.pack();
102        this.setLocationRelativeTo(null);
103        this.setVisible(true);
104
105    }
106
107    @Override
108    public void actionPerformed(ActionEvent arg0) {
109        if (arg0.getSource().equals(buttonOk)) {
110            System.out.println(mapLevels.get(comboPrivacyLevel.getSelectedIndex()));
111            ImagesManagement.getInstance().setPrivacyLevel(mapLevels.get(comboPrivacyLevel.getSelectedIndex()));
112            if (checkBoxRemember.isSelected()) {
113                ImagesManagement.getInstance().setRememberPrivacyLevel(true);
114            }
115            this.dispose();
116        }
117
118    }
119
120    /**
121     * @author mael
122     * Internal class that represents the model of the combobox that allows
123     * to choose a privacy level
124     */
125    class privacyLevelModel extends AbstractListModel implements ComboBoxModel {
126
127        String[] privacies = new String[5];
128
129        String selection = null;
130
131        public privacyLevelModel() {
132
133            privacies[0] = Messages.getMessage("dialogPrivacy_none");
134            privacies[1] = Messages.getMessage("dialogPrivacy_contacts") + ", "
135                    + Messages.getMessage("dialogPrivacy_friends") + ", " + Messages.getMessage("dialogPrivacy_family")
136                    + ", " + Messages.getMessage("dialogPrivacy_admin");
137            privacies[2] = Messages.getMessage("dialogPrivacy_friends") + ", "
138                    + Messages.getMessage("dialogPrivacy_family") + ", " + Messages.getMessage("dialogPrivacy_admin");
139            privacies[3] = Messages.getMessage("dialogPrivacy_family") + ", "
140                    + Messages.getMessage("dialogPrivacy_admin");
141            privacies[4] = Messages.getMessage("dialogPrivacy_admin");
142        }
143
144        public Object getElementAt(int index) {
145            return privacies[index];
146        }
147
148        public int getSize() {
149            return privacies.length;
150        }
151
152        public void setSelectedItem(Object anItem) {
153            selection = (String) anItem;
154        }
155
156        public Object getSelectedItem() {
157            if (selection != null)
158                return selection;
159            else
160                return null;
161        }
162    }
163}
Note: See TracBrowser for help on using the repository browser.