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

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

Changes ImagesManagement access from static to object.

File size: 5.4 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    /**
74     * Constructor
75     */
76    public DialogPrivacyLevel() {
77        super(MainFrame.getInstance());
78        setModal(true);
79        checkBoxRemember = new JCheckBox(Messages.getMessage("dialogPrivacy_remember"));
80        labelChoice = new JLabel(Messages.getMessage("dialogPrivacy_choosePrivacy"));
81        JPanel panelChoice = new JPanel(new FlowLayout());
82        comboPrivacyLevel = new JComboBox(new privacyLevelModel());
83        comboPrivacyLevel.setSelectedIndex(0);
84        panelChoice.add(comboPrivacyLevel);
85        panelChoice.add(checkBoxRemember);
86        JPanel panelButton = new JPanel(new FlowLayout());
87        buttonOk = new JButton("Ok");
88        buttonOk.addActionListener(this);
89        panelButton.add(buttonOk);
90        this.setLayout(new BorderLayout());
91        this.add(panelChoice, BorderLayout.NORTH);
92        this.add(panelButton, BorderLayout.CENTER);
93
94        this.pack();
95        this.setLocationRelativeTo(null);
96        this.setVisible(true);
97
98    }
99
100    @Override
101    public void actionPerformed(ActionEvent arg0) {
102        if (arg0.getSource().equals(buttonOk)) {
103            ImagesManagement.getInstance().setPrivacyLevel(comboPrivacyLevel.getSelectedIndex() + 1);
104            if (checkBoxRemember.isSelected()) {
105                ImagesManagement.getInstance().setRememberPrivacyLevel(true);
106            }
107            this.dispose();
108        }
109
110    }
111
112    /**
113     * @author mael
114     * Internal class that represents the model of the combobox that allows
115     * to choose a privacy level
116     */
117    class privacyLevelModel extends AbstractListModel implements ComboBoxModel {
118        HashMap<Integer, String> mapLevels = new HashMap<Integer, String>();
119
120        String[] privacies = new String[5];
121
122        String selection = null;
123
124        public privacyLevelModel() {
125            HashMap<Integer, String> mapLevels = new HashMap<Integer, String>();
126            mapLevels.put(0, "dialogPrivacy_none");
127            mapLevels.put(1, "dialogPrivacy_contacts");
128            mapLevels.put(2, "dialogPrivacy_friends");
129            mapLevels.put(3, "dialogPrivacy_family");
130            mapLevels.put(4, "dialogPrivacy_admin");
131            privacies[0] = Messages.getMessage("dialogPrivacy_none");
132            privacies[1] = Messages.getMessage("dialogPrivacy_contacts") + ", "
133                    + Messages.getMessage("dialogPrivacy_friends") + ", " + Messages.getMessage("dialogPrivacy_family")
134                    + ", " + Messages.getMessage("dialogPrivacy_admin");
135            privacies[2] = Messages.getMessage("dialogPrivacy_friends") + ", "
136                    + Messages.getMessage("dialogPrivacy_family") + ", " + Messages.getMessage("dialogPrivacy_admin");
137            privacies[3] = Messages.getMessage("dialogPrivacy_family") + ", "
138                    + Messages.getMessage("dialogPrivacy_admin");
139            privacies[4] = Messages.getMessage("dialogPrivacy_admin");
140        }
141
142        public Object getElementAt(int index) {
143            return privacies[index];
144        }
145
146        public int getSize() {
147            return privacies.length;
148        }
149
150        public void setSelectedItem(Object anItem) {
151            selection = (String) anItem;
152        }
153
154        public Object getSelectedItem() {
155            if (selection != null)
156                return selection;
157            else
158                return null;
159        }
160    }
161}
Note: See TracBrowser for help on using the repository browser.