[6821] | 1 | package fr.mael.jiwigo.ui.mainframe; |
---|
| 2 | |
---|
| 3 | import java.awt.BorderLayout; |
---|
[6832] | 4 | import java.awt.Dimension; |
---|
[6821] | 5 | import java.awt.FlowLayout; |
---|
[6831] | 6 | import java.awt.event.ActionEvent; |
---|
| 7 | import java.awt.event.ActionListener; |
---|
[6972] | 8 | import java.awt.event.KeyEvent; |
---|
| 9 | import java.awt.event.KeyListener; |
---|
[6958] | 10 | import java.util.HashMap; |
---|
[6821] | 11 | |
---|
[6958] | 12 | import javax.swing.ImageIcon; |
---|
[6832] | 13 | import javax.swing.JComponent; |
---|
[6821] | 14 | import javax.swing.JFrame; |
---|
| 15 | import javax.swing.JLabel; |
---|
[6831] | 16 | import javax.swing.JMenu; |
---|
| 17 | import javax.swing.JMenuBar; |
---|
| 18 | import javax.swing.JMenuItem; |
---|
[6821] | 19 | import javax.swing.JPanel; |
---|
[6833] | 20 | import javax.swing.JProgressBar; |
---|
[6821] | 21 | import javax.swing.JScrollPane; |
---|
| 22 | import javax.swing.JSplitPane; |
---|
| 23 | |
---|
| 24 | import fr.mael.jiwigo.transverse.util.Messages; |
---|
| 25 | import fr.mael.jiwigo.transverse.util.Outil; |
---|
[6972] | 26 | import fr.mael.jiwigo.ui.field.HintTextField; |
---|
[6958] | 27 | import fr.mael.jiwigo.ui.mainframe.tab.JTabbedPaneWithCloseIcons; |
---|
[6821] | 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 | */ |
---|
[6972] | 58 | public class MainFrame extends JFrame implements ActionListener, KeyListener { |
---|
[6821] | 59 | /** |
---|
| 60 | * Logger |
---|
| 61 | */ |
---|
| 62 | public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory |
---|
| 63 | .getLog(MainFrame.class); |
---|
| 64 | /** |
---|
[6980] | 65 | * the categories tree |
---|
[6821] | 66 | */ |
---|
| 67 | private CategoriesTree categoriesTree; |
---|
| 68 | /** |
---|
[6980] | 69 | * Splitpane. On the left : the categories tree and on the right the thumbnails |
---|
| 70 | * for the current category |
---|
[6821] | 71 | */ |
---|
| 72 | private JSplitPane splitPane; |
---|
| 73 | /** |
---|
[6980] | 74 | * Panel that contains the thumbnail of the current category |
---|
[6821] | 75 | */ |
---|
[6831] | 76 | public static ThumbnailCategoryPanel imagesPanel; |
---|
[6821] | 77 | /** |
---|
[6980] | 78 | * Scrollpane that contains the panel above |
---|
[6821] | 79 | */ |
---|
| 80 | private JScrollPane scrollPaneImagesPanel; |
---|
| 81 | /** |
---|
[6980] | 82 | * label that displays messages |
---|
[6821] | 83 | */ |
---|
| 84 | private JLabel labelMessage; |
---|
| 85 | |
---|
| 86 | /** |
---|
[6980] | 87 | * menu bar |
---|
[6831] | 88 | */ |
---|
| 89 | private JMenuBar jMenuBar; |
---|
| 90 | |
---|
| 91 | /** |
---|
[6980] | 92 | * edition menu |
---|
[6831] | 93 | */ |
---|
| 94 | private JMenu jMenuEdition; |
---|
| 95 | |
---|
| 96 | /** |
---|
[6980] | 97 | * preferences menu |
---|
[6831] | 98 | */ |
---|
| 99 | private JMenuItem jMenuItemPreferences; |
---|
| 100 | |
---|
| 101 | /** |
---|
[6821] | 102 | * singleton |
---|
| 103 | */ |
---|
| 104 | private static MainFrame instance; |
---|
| 105 | |
---|
[6833] | 106 | private JProgressBar progressBar; |
---|
| 107 | |
---|
[6958] | 108 | private JTabbedPaneWithCloseIcons tabbedPane; |
---|
| 109 | |
---|
| 110 | private HashMap<Integer, Integer> mapsIdPos = new HashMap<Integer, Integer>(); |
---|
| 111 | |
---|
[6972] | 112 | private HintTextField fieldSearch; |
---|
| 113 | |
---|
[6821] | 114 | /** |
---|
[6980] | 115 | * @return the singleton |
---|
[6821] | 116 | */ |
---|
| 117 | public static MainFrame getInstance() { |
---|
| 118 | if (instance == null) { |
---|
| 119 | instance = new MainFrame(); |
---|
| 120 | } |
---|
| 121 | return instance; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | /** |
---|
[6980] | 125 | * private constructor to use a singleton |
---|
[6821] | 126 | */ |
---|
| 127 | private MainFrame() { |
---|
[6958] | 128 | this.setTitle("Jiwigo v" + Messages.getMessage("version")); |
---|
[6821] | 129 | this.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(Outil.getURL("fr/mael/jiwigo/img/icon.png"))); |
---|
| 130 | this.setLayout(new BorderLayout()); |
---|
[6831] | 131 | jMenuBar = new JMenuBar(); |
---|
[6821] | 132 | labelMessage = new JLabel(Messages.getMessage("welcomeMessage")); |
---|
| 133 | splitPane = new JSplitPane(); |
---|
| 134 | categoriesTree = new CategoriesTree(); |
---|
| 135 | splitPane.setLeftComponent(categoriesTree); |
---|
| 136 | |
---|
[6958] | 137 | tabbedPane = new JTabbedPaneWithCloseIcons(); |
---|
| 138 | splitPane.setRightComponent(tabbedPane); |
---|
| 139 | |
---|
| 140 | this.add(splitPane, BorderLayout.CENTER); |
---|
[6972] | 141 | JPanel panelBas = new JPanel(new BorderLayout()); |
---|
[6821] | 142 | JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
---|
[6833] | 143 | progressBar = new JProgressBar(0, 100); |
---|
| 144 | panel.add(progressBar); |
---|
[6821] | 145 | panel.add(labelMessage); |
---|
[6972] | 146 | panelBas.add(panel, BorderLayout.WEST); |
---|
[6831] | 147 | |
---|
[6972] | 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 | |
---|
[6831] | 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); |
---|
[6972] | 160 | this.add(panelBas, BorderLayout.SOUTH); |
---|
[6958] | 161 | this.setSize(900, 600); |
---|
[6821] | 162 | this.setLocationRelativeTo(null); |
---|
| 163 | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
---|
[6958] | 164 | this.setResizable(true); |
---|
[6821] | 165 | } |
---|
| 166 | |
---|
[6972] | 167 | public void addTabb(IThumbnailPanel panel) { |
---|
| 168 | JScrollPane scrollPaneImagesPanel = new JScrollPane((JPanel) panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, |
---|
[6958] | 169 | JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
---|
| 170 | scrollPaneImagesPanel.setPreferredSize(new Dimension(900, 600)); |
---|
| 171 | boolean found = false; |
---|
[6972] | 172 | boolean isSearch = false; |
---|
| 173 | if (panel instanceof ThumbnailSearchPanel) { |
---|
| 174 | isSearch = true; |
---|
| 175 | } |
---|
[6958] | 176 | for (int i = 0; i < tabbedPane.getTabCount(); i++) { |
---|
| 177 | JScrollPane scroll = (JScrollPane) tabbedPane.getComponentAt(i); |
---|
[6972] | 178 | IThumbnailPanel thumbPan = (IThumbnailPanel) scroll.getViewport().getComponents()[0]; |
---|
[6958] | 179 | if (thumbPan.getCategory().getIdentifiant().equals(panel.getCategory().getIdentifiant())) { |
---|
[6972] | 180 | //only if it's not for a re |
---|
| 181 | if (!(panel instanceof ThumbnailSearchPanel)) { |
---|
| 182 | tabbedPane.setSelectedIndex(i); |
---|
| 183 | found = true; |
---|
| 184 | break; |
---|
| 185 | } |
---|
[6958] | 186 | } |
---|
| 187 | } |
---|
[6972] | 188 | //if it's not for a research, the title of the tab |
---|
| 189 | //is the name of the category |
---|
| 190 | if (!found && !isSearch) { |
---|
[6958] | 191 | tabbedPane.addTab(panel.getCategory().getNom(), scrollPaneImagesPanel, new ImageIcon(Outil |
---|
| 192 | .getURL("fr/mael/jiwigo/img/closetab.png"))); |
---|
[6972] | 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"))); |
---|
[6958] | 199 | } |
---|
| 200 | |
---|
| 201 | } |
---|
| 202 | |
---|
[6821] | 203 | /** |
---|
[6980] | 204 | * displays the frame |
---|
[6821] | 205 | */ |
---|
| 206 | public void showUi() { |
---|
| 207 | this.setVisible(true); |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | /** |
---|
| 211 | * Affichage d'un message de réussite |
---|
| 212 | * @param message |
---|
| 213 | */ |
---|
[6980] | 214 | public void setMessage(String message) { |
---|
[6821] | 215 | this.labelMessage.setText(message); |
---|
| 216 | } |
---|
| 217 | |
---|
[6831] | 218 | @Override |
---|
| 219 | public void actionPerformed(ActionEvent arg0) { |
---|
| 220 | if (arg0.getSource().equals(jMenuItemPreferences)) { |
---|
| 221 | new PreferencesDialog(this); |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | } |
---|
| 225 | |
---|
[6833] | 226 | public static void reduceSizeOfComponent(JComponent comp) { |
---|
| 227 | comp.setMaximumSize(comp.getPreferredSize()); |
---|
[6832] | 228 | } |
---|
| 229 | |
---|
[6833] | 230 | /** |
---|
| 231 | * @return the progressBar |
---|
| 232 | */ |
---|
| 233 | public JProgressBar getProgressBar() { |
---|
| 234 | return progressBar; |
---|
[6832] | 235 | } |
---|
| 236 | |
---|
[6958] | 237 | /** |
---|
| 238 | * @return the mapsIdPos |
---|
| 239 | */ |
---|
| 240 | public HashMap<Integer, Integer> getMapsIdPos() { |
---|
| 241 | return mapsIdPos; |
---|
| 242 | } |
---|
| 243 | |
---|
[6972] | 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 | |
---|
[6821] | 261 | } |
---|