1 | package fr.mael.jiwigo.ui.mainframe; |
---|
2 | |
---|
3 | import java.awt.BorderLayout; |
---|
4 | import java.awt.FlowLayout; |
---|
5 | import java.awt.event.ActionEvent; |
---|
6 | import java.awt.event.ActionListener; |
---|
7 | |
---|
8 | import javax.swing.JFrame; |
---|
9 | import javax.swing.JLabel; |
---|
10 | import javax.swing.JMenu; |
---|
11 | import javax.swing.JMenuBar; |
---|
12 | import javax.swing.JMenuItem; |
---|
13 | import javax.swing.JPanel; |
---|
14 | import javax.swing.JScrollPane; |
---|
15 | import javax.swing.JSplitPane; |
---|
16 | |
---|
17 | import fr.mael.jiwigo.transverse.util.Messages; |
---|
18 | import fr.mael.jiwigo.transverse.util.Outil; |
---|
19 | |
---|
20 | /** |
---|
21 | Copyright (c) 2010, Mael |
---|
22 | All rights reserved. |
---|
23 | |
---|
24 | Redistribution and use in source and binary forms, with or without |
---|
25 | modification, are permitted provided that the following conditions are met: |
---|
26 | * Redistributions of source code must retain the above copyright |
---|
27 | notice, this list of conditions and the following disclaimer. |
---|
28 | * Redistributions in binary form must reproduce the above copyright |
---|
29 | notice, this list of conditions and the following disclaimer in the |
---|
30 | documentation and/or other materials provided with the distribution. |
---|
31 | * Neither the name of jiwigo nor the |
---|
32 | names of its contributors may be used to endorse or promote products |
---|
33 | derived from this software without specific prior written permission. |
---|
34 | |
---|
35 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
---|
36 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
---|
37 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
---|
38 | DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY |
---|
39 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
---|
40 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
---|
41 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
---|
42 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
43 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
---|
44 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
45 | |
---|
46 | * @author mael |
---|
47 | * Frame principale |
---|
48 | */ |
---|
49 | public class MainFrame extends JFrame implements ActionListener { |
---|
50 | /** |
---|
51 | * Logger |
---|
52 | */ |
---|
53 | public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory |
---|
54 | .getLog(MainFrame.class); |
---|
55 | /** |
---|
56 | * l'arbre des catégories |
---|
57 | */ |
---|
58 | private CategoriesTree categoriesTree; |
---|
59 | /** |
---|
60 | * Splitpane avec à gauche l'arbre et à droite les miniatures pour la catégorie |
---|
61 | * courante |
---|
62 | */ |
---|
63 | private JSplitPane splitPane; |
---|
64 | /** |
---|
65 | * Panel contenant les miniatures de la catégorie courante |
---|
66 | */ |
---|
67 | public static ThumbnailCategoryPanel imagesPanel; |
---|
68 | /** |
---|
69 | * Scrollpane contenant le panel ci dessus |
---|
70 | */ |
---|
71 | private JScrollPane scrollPaneImagesPanel; |
---|
72 | /** |
---|
73 | * label qui affiche des messages |
---|
74 | */ |
---|
75 | private JLabel labelMessage; |
---|
76 | |
---|
77 | /** |
---|
78 | * Barre de menu |
---|
79 | */ |
---|
80 | private JMenuBar jMenuBar; |
---|
81 | |
---|
82 | /** |
---|
83 | * Menu d'édition |
---|
84 | */ |
---|
85 | private JMenu jMenuEdition; |
---|
86 | |
---|
87 | /** |
---|
88 | * menu des preferences |
---|
89 | */ |
---|
90 | private JMenuItem jMenuItemPreferences; |
---|
91 | |
---|
92 | /** |
---|
93 | * singleton |
---|
94 | */ |
---|
95 | private static MainFrame instance; |
---|
96 | |
---|
97 | /** |
---|
98 | * @return le singleton |
---|
99 | */ |
---|
100 | public static MainFrame getInstance() { |
---|
101 | if (instance == null) { |
---|
102 | instance = new MainFrame(); |
---|
103 | } |
---|
104 | return instance; |
---|
105 | } |
---|
106 | |
---|
107 | /** |
---|
108 | * COnstructeur privé, permettant de n'avoir accès qu'au singleton |
---|
109 | */ |
---|
110 | private MainFrame() { |
---|
111 | this.setTitle("Piwigo v" + Messages.getMessage("version")); |
---|
112 | this.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(Outil.getURL("fr/mael/jiwigo/img/icon.png"))); |
---|
113 | this.setLayout(new BorderLayout()); |
---|
114 | jMenuBar = new JMenuBar(); |
---|
115 | labelMessage = new JLabel(Messages.getMessage("welcomeMessage")); |
---|
116 | splitPane = new JSplitPane(); |
---|
117 | categoriesTree = new CategoriesTree(); |
---|
118 | splitPane.setLeftComponent(categoriesTree); |
---|
119 | imagesPanel = new ThumbnailCategoryPanel(null); |
---|
120 | scrollPaneImagesPanel = new JScrollPane(imagesPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, |
---|
121 | JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
---|
122 | splitPane.setRightComponent(scrollPaneImagesPanel); |
---|
123 | |
---|
124 | this.add(splitPane, BorderLayout.WEST); |
---|
125 | JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
---|
126 | panel.add(labelMessage); |
---|
127 | |
---|
128 | jMenuEdition = new JMenu(Messages.getMessage("mainFrame_editionMenu")); |
---|
129 | jMenuBar.add(jMenuEdition); |
---|
130 | jMenuItemPreferences = new JMenuItem(Messages.getMessage("mainFrame_preferencesMenu")); |
---|
131 | jMenuItemPreferences.addActionListener(this); |
---|
132 | jMenuEdition.add(jMenuItemPreferences); |
---|
133 | |
---|
134 | this.setJMenuBar(jMenuBar); |
---|
135 | this.add(panel, BorderLayout.SOUTH); |
---|
136 | this.pack(); |
---|
137 | this.setLocationRelativeTo(null); |
---|
138 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
---|
139 | this.setResizable(false); |
---|
140 | } |
---|
141 | |
---|
142 | /** |
---|
143 | * affichage de la frame |
---|
144 | */ |
---|
145 | public void showUi() { |
---|
146 | this.setVisible(true); |
---|
147 | } |
---|
148 | |
---|
149 | /** |
---|
150 | * Affichage d'un message d'erreur |
---|
151 | * @param message |
---|
152 | */ |
---|
153 | public void setErrorMessage(String message) { |
---|
154 | this.labelMessage.setText(message); |
---|
155 | } |
---|
156 | |
---|
157 | /** |
---|
158 | * Affichage d'un message de réussite |
---|
159 | * @param message |
---|
160 | */ |
---|
161 | public void setReussiteMessage(String message) { |
---|
162 | this.labelMessage.setText(message); |
---|
163 | } |
---|
164 | |
---|
165 | @Override |
---|
166 | public void actionPerformed(ActionEvent arg0) { |
---|
167 | if (arg0.getSource().equals(jMenuItemPreferences)) { |
---|
168 | new PreferencesDialog(this); |
---|
169 | } |
---|
170 | |
---|
171 | } |
---|
172 | |
---|
173 | } |
---|