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

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

New features

  • When clicking on a category, the category is opened in a tab. When clicking on the same category again, no tab is opened but the previously opened tab is shown. The user can close the tabs (close current tab, close others, close all).
  • Ability to clip the images. There are still some bugs (unable to clip the images when zooming, and the rectangle stays when changing the image).
File size: 7.4 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.util.HashMap;
9
10import javax.swing.ImageIcon;
11import javax.swing.JComponent;
12import javax.swing.JFrame;
13import javax.swing.JLabel;
14import javax.swing.JMenu;
15import javax.swing.JMenuBar;
16import javax.swing.JMenuItem;
17import javax.swing.JPanel;
18import javax.swing.JProgressBar;
19import javax.swing.JScrollPane;
20import javax.swing.JSplitPane;
21
22import fr.mael.jiwigo.transverse.util.Messages;
23import fr.mael.jiwigo.transverse.util.Outil;
24import fr.mael.jiwigo.ui.mainframe.tab.JTabbedPaneWithCloseIcons;
25
26/**
27   Copyright (c) 2010, Mael
28   All rights reserved.
29
30   Redistribution and use in source and binary forms, with or without
31   modification, are permitted provided that the following conditions are met:
32    * Redistributions of source code must retain the above copyright
33      notice, this list of conditions and the following disclaimer.
34    * Redistributions in binary form must reproduce the above copyright
35      notice, this list of conditions and the following disclaimer in the
36      documentation and/or other materials provided with the distribution.
37    * Neither the name of jiwigo nor the
38      names of its contributors may be used to endorse or promote products
39      derived from this software without specific prior written permission.
40
41   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
42   ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
43   WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44   DISCLAIMED. IN NO EVENT SHALL Mael BE LIABLE FOR ANY
45   DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
46   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
49   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
50   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51   
52 * @author mael
53 * Frame principale
54 */
55public class MainFrame extends JFrame implements ActionListener {
56    /**
57     * Logger
58     */
59    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
60            .getLog(MainFrame.class);
61    /**
62     * l'arbre des catégories
63     */
64    private CategoriesTree categoriesTree;
65    /**
66     * Splitpane avec à gauche l'arbre et à droite les miniatures pour la catégorie
67     * courante
68     */
69    private JSplitPane splitPane;
70    /**
71     * Panel contenant les miniatures de la catégorie courante
72     */
73    public static ThumbnailCategoryPanel imagesPanel;
74    /**
75     *  Scrollpane contenant le panel ci dessus
76     */
77    private JScrollPane scrollPaneImagesPanel;
78    /**
79     * label qui affiche des messages
80     */
81    private JLabel labelMessage;
82
83    /**
84     * Barre de menu
85     */
86    private JMenuBar jMenuBar;
87
88    /**
89     * Menu d'édition
90     */
91    private JMenu jMenuEdition;
92
93    /**
94     * menu des preferences
95     */
96    private JMenuItem jMenuItemPreferences;
97
98    /**
99     * singleton
100     */
101    private static MainFrame instance;
102
103    private JProgressBar progressBar;
104
105    private JTabbedPaneWithCloseIcons tabbedPane;
106
107    private HashMap<Integer, Integer> mapsIdPos = new HashMap<Integer, Integer>();
108
109    /**
110     * @return le singleton
111     */
112    public static MainFrame getInstance() {
113        if (instance == null) {
114            instance = new MainFrame();
115        }
116        return instance;
117    }
118
119    /**
120     * COnstructeur privé, permettant de n'avoir accès qu'au singleton
121     */
122    private MainFrame() {
123        this.setTitle("Jiwigo v" + Messages.getMessage("version"));
124        this.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(Outil.getURL("fr/mael/jiwigo/img/icon.png")));
125        this.setLayout(new BorderLayout());
126        jMenuBar = new JMenuBar();
127        labelMessage = new JLabel(Messages.getMessage("welcomeMessage"));
128        splitPane = new JSplitPane();
129        categoriesTree = new CategoriesTree();
130        splitPane.setLeftComponent(categoriesTree);
131        //      imagesPanel = new ThumbnailCategoryPanel(null);
132        //      reduceSizeOfComponent(imagesPanel);
133        //      scrollPaneImagesPanel = new JScrollPane(imagesPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
134        //              JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
135        //      scrollPaneImagesPanel.setPreferredSize(new Dimension(900, 600));
136
137        tabbedPane = new JTabbedPaneWithCloseIcons();
138        //      tabbedPane.add(scrollPaneImagesPanel);
139        splitPane.setRightComponent(tabbedPane);
140
141        this.add(splitPane, BorderLayout.CENTER);
142        JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
143        progressBar = new JProgressBar(0, 100);
144        panel.add(progressBar);
145        panel.add(labelMessage);
146
147        jMenuEdition = new JMenu(Messages.getMessage("mainFrame_editionMenu"));
148        jMenuBar.add(jMenuEdition);
149        jMenuItemPreferences = new JMenuItem(Messages.getMessage("mainFrame_preferencesMenu"));
150        jMenuItemPreferences.addActionListener(this);
151        jMenuEdition.add(jMenuItemPreferences);
152
153        this.setJMenuBar(jMenuBar);
154        this.add(panel, BorderLayout.SOUTH);
155        //      this.pack();
156        this.setSize(900, 600);
157        this.setLocationRelativeTo(null);
158        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
159        this.setResizable(true);
160    }
161
162    public void addTabb(ThumbnailCategoryPanel panel) {
163        JScrollPane scrollPaneImagesPanel = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
164                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
165        scrollPaneImagesPanel.setPreferredSize(new Dimension(900, 600));
166        boolean found = false;
167        for (int i = 0; i < tabbedPane.getTabCount(); i++) {
168            JScrollPane scroll = (JScrollPane) tabbedPane.getComponentAt(i);
169            ThumbnailCategoryPanel thumbPan = (ThumbnailCategoryPanel) scroll.getViewport().getComponents()[0];
170            if (thumbPan.getCategory().getIdentifiant().equals(panel.getCategory().getIdentifiant())) {
171                tabbedPane.setSelectedIndex(i);
172                found = true;
173                break;
174            }
175        }
176        if (!found) {
177            tabbedPane.addTab(panel.getCategory().getNom(), scrollPaneImagesPanel, new ImageIcon(Outil
178                    .getURL("fr/mael/jiwigo/img/closetab.png")));
179        }
180
181        //      if (mapsIdPos.get(panel.getCategory().getIdentifiant()) == null) {
182        //          tabbedPane.addTab(panel.getCategory().getNom(), scrollPaneImagesPanel);
183        //          mapsIdPos.put(panel.getCategory().getIdentifiant(), tabbedPane.getTabCount() - 1);
184        //      } else {
185        //          tabbedPane.setSelectedIndex(mapsIdPos.get(panel.getCategory().getIdentifiant()));
186        //      }
187
188    }
189
190    /**
191     * affichage de la frame
192     */
193    public void showUi() {
194        this.setVisible(true);
195    }
196
197    /**
198     * Affichage d'un message d'erreur
199     * @param message
200     */
201    public void setErrorMessage(String message) {
202        this.labelMessage.setText(message);
203    }
204
205    /**
206     * Affichage d'un message de réussite
207     * @param message
208     */
209    public void setReussiteMessage(String message) {
210        this.labelMessage.setText(message);
211    }
212
213    @Override
214    public void actionPerformed(ActionEvent arg0) {
215        if (arg0.getSource().equals(jMenuItemPreferences)) {
216            new PreferencesDialog(this);
217        }
218
219    }
220
221    public static void reduceSizeOfComponent(JComponent comp) {
222        comp.setMaximumSize(comp.getPreferredSize());
223    }
224
225    /**
226     * @return the progressBar
227     */
228    public JProgressBar getProgressBar() {
229        return progressBar;
230    }
231
232    /**
233     * @return the mapsIdPos
234     */
235    public HashMap<Integer, Integer> getMapsIdPos() {
236        return mapsIdPos;
237    }
238
239}
Note: See TracBrowser for help on using the repository browser.