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

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

Adds an exception management + changes privacy level dialog.

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"), JLabel.CENTER);
88        JPanel panelChoice = new JPanel(new FlowLayout(FlowLayout.CENTER));
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(labelChoice, BorderLayout.NORTH);
99        this.add(panelChoice, BorderLayout.CENTER);
100        this.add(panelButton, BorderLayout.SOUTH);
101
102        this.pack();
103        this.setLocationRelativeTo(null);
104        this.setVisible(true);
105
106    }
107
108    @Override
109    public void actionPerformed(ActionEvent arg0) {
110        if (arg0.getSource().equals(buttonOk)) {
111            System.out.println(mapLevels.get(comboPrivacyLevel.getSelectedIndex()));
112            ImagesManagement.getInstance().setPrivacyLevel(mapLevels.get(comboPrivacyLevel.getSelectedIndex()));
113            if (checkBoxRemember.isSelected()) {
114                ImagesManagement.getInstance().setRememberPrivacyLevel(true);
115            }
116            this.dispose();
117        }
118
119    }
120
121    /**
122     * @author mael
123     * Internal class that represents the model of the combobox that allows
124     * to choose a privacy level
125     */
126    class privacyLevelModel extends AbstractListModel implements ComboBoxModel {
127
128        String[] privacies = new String[5];
129
130        String selection = null;
131
132        public privacyLevelModel() {
133
134            privacies[0] = Messages.getMessage("dialogPrivacy_none");
135            privacies[1] = Messages.getMessage("dialogPrivacy_contacts") + ", "
136                    + Messages.getMessage("dialogPrivacy_friends") + ", " + Messages.getMessage("dialogPrivacy_family")
137                    + ", " + Messages.getMessage("dialogPrivacy_admin");
138            privacies[2] = Messages.getMessage("dialogPrivacy_friends") + ", "
139                    + Messages.getMessage("dialogPrivacy_family") + ", " + Messages.getMessage("dialogPrivacy_admin");
140            privacies[3] = Messages.getMessage("dialogPrivacy_family") + ", "
141                    + Messages.getMessage("dialogPrivacy_admin");
142            privacies[4] = Messages.getMessage("dialogPrivacy_admin");
143        }
144
145        public Object getElementAt(int index) {
146            return privacies[index];
147        }
148
149        public int getSize() {
150            return privacies.length;
151        }
152
153        public void setSelectedItem(Object anItem) {
154            selection = (String) anItem;
155        }
156
157        public Object getSelectedItem() {
158            if (selection != null)
159                return selection;
160            else
161                return null;
162        }
163    }
164}
Note: See TracBrowser for help on using the repository browser.