source: extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/MainFrame.java @ 7222

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

changes the informations displayed while uploading photos
bug:0001886

File size: 8.1 KB
Line 
1package fr.mael.jiwigo.ui.mainframe;
2
3import java.awt.BorderLayout;
4import java.awt.Dimension;
5import java.awt.FlowLayout;
6import java.awt.event.ActionEvent;
7import java.awt.event.ActionListener;
8import java.awt.event.KeyEvent;
9import java.awt.event.KeyListener;
10import java.util.HashMap;
11import javax.swing.ImageIcon;
12import javax.swing.JComponent;
13import javax.swing.JFrame;
14import javax.swing.JLabel;
15import javax.swing.JMenu;
16import javax.swing.JMenuBar;
17import javax.swing.JMenuItem;
18import javax.swing.JPanel;
19import javax.swing.JProgressBar;
20import javax.swing.JScrollPane;
21import javax.swing.JSplitPane;
22import fr.mael.jiwigo.transverse.util.Messages;
23import fr.mael.jiwigo.transverse.util.Outil;
24import fr.mael.jiwigo.ui.field.HintTextField;
25import fr.mael.jiwigo.ui.mainframe.tab.JTabbedPaneWithCloseIcons;
26
27
28/**
29   Copyright (c) 2010, Mael
30   All rights reserved.
31
32   Redistribution and use in source and binary forms, with or without
33   modification, are permitted provided that the following conditions are met:
34    * Redistributions of source code must retain the above copyright
35      notice, this list of conditions and the following disclaimer.
36    * Redistributions in binary form must reproduce the above copyright
37      notice, this list of conditions and the following disclaimer in the
38      documentation and/or other materials provided with the distribution.
39    * Neither the name of jiwigo nor the
40      names of its contributors may be used to endorse or promote products
41      derived from this software without specific prior written permission.
42
43   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
44   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
45   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
46   DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
47   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
48   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
50   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
52   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53   
54 * @author mael
55 * Frame principale
56 */
57public class MainFrame extends JFrame implements ActionListener, KeyListener {
58
59        /**
60         * Logger
61         */
62        public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(MainFrame.class);
63        /**
64         * the categories tree
65         */
66        private CategoriesTree categoriesTree;
67        /**
68         * Splitpane. On the left : the categories tree and on the right the thumbnails
69         * for the current category
70         */
71        private JSplitPane splitPane;
72        /**
73         * Panel that contains the thumbnail of the current category
74         */
75        public static ThumbnailCategoryPanel imagesPanel;
76        /**
77         *  Scrollpane that contains the panel above
78         */
79        private JScrollPane scrollPaneImagesPanel;
80        /**
81         * label that displays messages
82         */
83        private JLabel labelMessage;
84
85        /**
86         * label that displays additional messages
87         */
88        private JLabel labelAdditionalMessage;
89
90        /**
91         * menu bar
92         */
93        private JMenuBar jMenuBar;
94
95        /**
96         * edition menu
97         */
98        private JMenu jMenuEdition;
99
100        /**
101         * preferences menu
102         */
103        private JMenuItem jMenuItemPreferences;
104
105        /**
106         * singleton
107         */
108        private static MainFrame instance;
109
110        private JProgressBar progressBar;
111
112        private JTabbedPaneWithCloseIcons tabbedPane;
113
114        private HashMap<Integer, Integer> mapsIdPos = new HashMap<Integer, Integer>();
115
116        private HintTextField fieldSearch;
117
118
119        /**
120         * @return the singleton
121         */
122        public static MainFrame getInstance() {
123                if (instance == null) {
124                        instance = new MainFrame();
125                }
126                return instance;
127        }
128
129
130        /**
131         * private constructor to use a singleton
132         */
133        private MainFrame() {
134                this.setTitle("Jiwigo v" + Messages.getMessage("version"));
135                this.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(Outil.getURL("fr/mael/jiwigo/img/icon.png")));
136                this.setLayout(new BorderLayout());
137                jMenuBar = new JMenuBar();
138                labelMessage = new JLabel(Messages.getMessage("welcomeMessage"));
139                labelAdditionalMessage = new JLabel();
140                splitPane = new JSplitPane();
141                categoriesTree = new CategoriesTree();
142                splitPane.setLeftComponent(categoriesTree);
143
144                tabbedPane = new JTabbedPaneWithCloseIcons();
145                splitPane.setRightComponent(tabbedPane);
146
147                this.add(splitPane, BorderLayout.CENTER);
148                JPanel panelBas = new JPanel(new BorderLayout());
149                JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
150                progressBar = new JProgressBar(0, 100);
151                panel.add(progressBar);
152                panel.add(labelAdditionalMessage);
153                panel.add(labelMessage);
154                panelBas.add(panel, BorderLayout.WEST);
155
156                fieldSearch = new HintTextField(Messages.getMessage("mainFrame_recherche"));
157                fieldSearch.setPreferredSize(new Dimension(150, 25));
158                fieldSearch.addKeyListener(this);
159                panelBas.add(fieldSearch, BorderLayout.EAST);
160
161                jMenuEdition = new JMenu(Messages.getMessage("mainFrame_editionMenu"));
162                jMenuBar.add(jMenuEdition);
163                jMenuItemPreferences = new JMenuItem(Messages.getMessage("mainFrame_preferencesMenu"));
164                jMenuItemPreferences.addActionListener(this);
165                jMenuEdition.add(jMenuItemPreferences);
166
167                this.setJMenuBar(jMenuBar);
168                this.add(panelBas, BorderLayout.SOUTH);
169                this.setSize(900, 600);
170                this.setLocationRelativeTo(null);
171                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
172                this.setResizable(true);
173        }
174
175
176        public void addTabb(IThumbnailPanel panel) {
177                JScrollPane scrollPaneImagesPanel = new JScrollPane((JPanel) panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
178                scrollPaneImagesPanel.setPreferredSize(new Dimension(900, 600));
179                boolean found = false;
180                boolean isSearch = false;
181                if (panel instanceof ThumbnailSearchPanel) {
182                        isSearch = true;
183                }
184
185                for (int i = 0; i < tabbedPane.getTabCount(); i++) {
186                        JScrollPane scroll = (JScrollPane) tabbedPane.getComponentAt(i);
187                        IThumbnailPanel thumbPan = (IThumbnailPanel) scroll.getViewport().getComponents()[0];
188                        if (thumbPan.getCategory().getIdentifiant().equals(panel.getCategory().getIdentifiant())) {
189                                //only if it's not for a re
190                                if (!(panel instanceof ThumbnailSearchPanel)) {
191                                        tabbedPane.setSelectedIndex(i);
192                                        found = true;
193                                        break;
194                                }
195                        }
196                }
197                //if it's not for a research, the title of the tab
198                //is the name of the category
199                if (!found && !isSearch) {
200                        tabbedPane.addTab(panel.getCategory().getNom(), scrollPaneImagesPanel,
201                                        new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/closetab.png")));
202                        //if it's for a research, the title of the tab
203                        //if the query string
204                } else if (!found && isSearch) {
205                        String queryString = ((ThumbnailSearchPanel) panel).getQueryString();
206                        tabbedPane.addTab(Messages.getMessage("mainFrame_search") + queryString, scrollPaneImagesPanel,
207                                        new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/closetab.png")));
208                }
209
210        }
211
212
213        /**
214         * displays the frame
215         */
216        public void showUi() {
217                this.setVisible(true);
218        }
219
220
221        /**
222         * Affichage d'un message de réussite
223         * @param message
224         */
225        public void setMessage(String message) {
226                this.labelMessage.setText(message);
227        }
228
229
230        public void setAdditionalMessage(String additionalMessage) {
231                this.labelAdditionalMessage.setText(additionalMessage);
232        }
233
234
235        @Override
236        public void actionPerformed(ActionEvent arg0) {
237                if (arg0.getSource().equals(jMenuItemPreferences)) {
238                        new PreferencesDialog(this);
239                }
240
241        }
242
243
244        public static void reduceSizeOfComponent(JComponent comp) {
245                comp.setMaximumSize(comp.getPreferredSize());
246        }
247
248
249        /**
250         * @return the progressBar
251         */
252        public JProgressBar getProgressBar() {
253                return progressBar;
254        }
255
256
257        /**
258         * @return the mapsIdPos
259         */
260        public HashMap<Integer, Integer> getMapsIdPos() {
261                return mapsIdPos;
262        }
263
264
265        @Override
266        public void keyPressed(KeyEvent paramKeyEvent) {
267                if (paramKeyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
268                        String queryString = fieldSearch.getText();
269                        ThumbnailSearchPanel searchPanel = new ThumbnailSearchPanel(queryString);
270                        addTabb(searchPanel);
271                }
272        }
273
274
275        @Override
276        public void keyReleased(KeyEvent paramKeyEvent) {
277        }
278
279
280        @Override
281        public void keyTyped(KeyEvent paramKeyEvent) {
282        }
283
284}
Note: See TracBrowser for help on using the repository browser.