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

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

Translation of the comments
French -> English

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