Ignore:
Timestamp:
Jan 21, 2011, 7:18:42 PM (13 years ago)
Author:
mlg
Message:

Changes ImagesManagement access from static to object.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/jiwigo/trunk/src/main/java/fr/mael/jiwigo/ui/mainframe/MainFrame.java

    r7222 r8829  
    99import java.awt.event.KeyListener;
    1010import java.util.HashMap;
     11
    1112import javax.swing.ImageIcon;
    1213import javax.swing.JComponent;
     
    2021import javax.swing.JScrollPane;
    2122import javax.swing.JSplitPane;
     23
    2224import fr.mael.jiwigo.transverse.util.Messages;
    2325import fr.mael.jiwigo.transverse.util.Outil;
     26import fr.mael.jiwigo.ui.MyCollapsiblePanel;
     27import fr.mael.jiwigo.ui.browser.BrowserPanel;
    2428import fr.mael.jiwigo.ui.field.HintTextField;
    2529import fr.mael.jiwigo.ui.mainframe.tab.JTabbedPaneWithCloseIcons;
    26 
     30import fr.mael.jiwigo.ui.search.ImageSearchPanel;
    2731
    2832/**
     
    5761public class MainFrame extends JFrame implements ActionListener, KeyListener {
    5862
    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();
     63    /**
     64     * Logger
     65     */
     66    public static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory
     67            .getLog(MainFrame.class);
     68    /**
     69     * the categories tree
     70     */
     71    private CategoriesTree categoriesTree;
     72    /**
     73     * Splitpane. On the left : the categories tree and on the right the thumbnails
     74     * for the current category
     75     */
     76    private JSplitPane splitPane;
     77    /**
     78     * Panel that contains the thumbnail of the current category
     79     */
     80    public static ThumbnailCategoryPanel imagesPanel;
     81    /**
     82     *  Scrollpane that contains the panel above
     83     */
     84    private JScrollPane scrollPaneImagesPanel;
     85    /**
     86     * label that displays messages
     87     */
     88    private JLabel labelMessage;
     89
     90    /**
     91     * label that displays additional messages
     92     */
     93    private JLabel labelAdditionalMessage;
     94
     95    /**
     96     * menu bar
     97     */
     98    private JMenuBar jMenuBar;
     99
     100    /**
     101     * edition menu
     102     */
     103    private JMenu jMenuEdition;
     104
     105    /**
     106     * preferences menu
     107     */
     108    private JMenuItem jMenuItemPreferences;
     109    /**
     110     * menu to search images
     111     */
     112    private JMenuItem jMenuItemSearch;
     113
     114    /**
     115     * singleton
     116     */
     117    private static MainFrame instance;
     118
     119    private JProgressBar progressBar;
     120
     121    private JTabbedPaneWithCloseIcons tabbedPane;
     122
     123    private HashMap<Integer, Integer> mapsIdPos = new HashMap<Integer, Integer>();
     124
     125    private HintTextField fieldSearch;
     126
     127    private BrowserPanel browserPanel;
     128
     129    private MyCollapsiblePanel collapsiblePanel;
     130
     131    private ImageSearchPanel imageSearchPanel;
     132
     133    private boolean imageSearchPanelVisible = false;
     134
     135    private boolean browserVisible = false;
     136
     137    /**
     138     * @return the singleton
     139     */
     140    public static MainFrame getInstance() {
     141        if (instance == null) {
     142            instance = new MainFrame();
     143        }
     144        return instance;
     145    }
     146
     147    /**
     148     * private constructor to use a singleton
     149     */
     150    private MainFrame() {
     151        this.setTitle("Jiwigo v" + Messages.getMessage("version"));
     152        this.setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(Outil.getURL("fr/mael/jiwigo/img/icon.png")));
     153        this.setLayout(new BorderLayout());
     154        jMenuBar = new JMenuBar();
     155        labelMessage = new JLabel(Messages.getMessage("welcomeMessage"));
     156        labelAdditionalMessage = new JLabel();
     157        splitPane = new JSplitPane();
     158        categoriesTree = new CategoriesTree();
     159        splitPane.setLeftComponent(categoriesTree);
     160
     161        imageSearchPanel = new ImageSearchPanel();
     162
     163        tabbedPane = new JTabbedPaneWithCloseIcons();
     164        collapsiblePanel = new MyCollapsiblePanel(tabbedPane);
     165        splitPane.setRightComponent(collapsiblePanel);
     166
     167        this.add(splitPane, BorderLayout.CENTER);
     168        JPanel panelBas = new JPanel(new BorderLayout());
     169        JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
     170        progressBar = new JProgressBar(0, 100);
     171        panel.add(progressBar);
     172        panel.add(labelAdditionalMessage);
     173        panel.add(labelMessage);
     174        panelBas.add(panel, BorderLayout.WEST);
     175
     176        fieldSearch = new HintTextField(Messages.getMessage("mainFrame_recherche"));
     177        fieldSearch.setPreferredSize(new Dimension(150, 25));
     178        fieldSearch.addKeyListener(this);
     179        panelBas.add(fieldSearch, BorderLayout.EAST);
     180
     181        jMenuEdition = new JMenu(Messages.getMessage("mainFrame_editionMenu"));
     182        jMenuBar.add(jMenuEdition);
     183        jMenuItemPreferences = new JMenuItem(Messages.getMessage("mainFrame_preferencesMenu"));
     184        jMenuItemPreferences.addActionListener(this);
     185        jMenuEdition.add(jMenuItemPreferences);
     186        jMenuItemSearch = new JMenuItem("Search");
     187        jMenuItemSearch.addActionListener(this);
     188        jMenuEdition.add(jMenuItemSearch);
     189
     190        this.setJMenuBar(jMenuBar);
     191        this.add(panelBas, BorderLayout.SOUTH);
     192        this.setSize(900, 600);
     193        this.setLocationRelativeTo(null);
     194        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     195        this.setResizable(true);
     196    }
     197
     198    public void setBrowserVisible() {
     199        splitPane.setRightComponent(collapsiblePanel);
     200        splitPane.revalidate();
     201        splitPane.repaint();
     202        imageSearchPanelVisible = false;
     203        browserVisible = true;
     204    }
     205
     206    public void setImageSearchPanelVisible() {
     207        splitPane.setRightComponent(imageSearchPanel);
     208        splitPane.revalidate();
     209        splitPane.repaint();
     210        imageSearchPanelVisible = true;
     211        browserVisible = false;
     212    }
     213
     214    public void addTabb(IThumbnailPanel panel) {
     215        JScrollPane scrollPaneImagesPanel = new JScrollPane((JPanel) panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
     216                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
     217        scrollPaneImagesPanel.setPreferredSize(new Dimension(900, 600));
     218        boolean found = false;
     219        boolean isSearch = false;
     220        if (panel instanceof ThumbnailSearchPanel) {
     221            isSearch = true;
     222        }
     223
     224        for (int i = 0; i < tabbedPane.getTabCount(); i++) {
     225            JScrollPane scroll = (JScrollPane) tabbedPane.getComponentAt(i);
     226            IThumbnailPanel thumbPan = (IThumbnailPanel) scroll.getViewport().getComponents()[0];
     227            if (thumbPan.getCategory().getIdentifiant().equals(panel.getCategory().getIdentifiant())) {
     228                //only if it's not for a re
     229                if (!(panel instanceof ThumbnailSearchPanel)) {
     230                    tabbedPane.setSelectedIndex(i);
     231                    found = true;
     232                    break;
    125233                }
    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         }
     234            }
     235        }
     236        //if it's not for a research, the title of the tab
     237        //is the name of the category
     238        if (!found && !isSearch) {
     239            tabbedPane.addTab(panel.getCategory().getNom(), scrollPaneImagesPanel, new ImageIcon(Outil
     240                    .getURL("fr/mael/jiwigo/img/closetab.png")));
     241            //if it's for a research, the title of the tab
     242            //if the query string
     243        } else if (!found && isSearch) {
     244            String queryString = ((ThumbnailSearchPanel) panel).getQueryString();
     245            tabbedPane.addTab(Messages.getMessage("mainFrame_search") + queryString, scrollPaneImagesPanel,
     246                    new ImageIcon(Outil.getURL("fr/mael/jiwigo/img/closetab.png")));
     247        }
     248
     249    }
     250
     251    public void revalidate() {
     252
     253    }
     254
     255    /**
     256     * displays the frame
     257     */
     258    public void showUi() {
     259        this.setVisible(true);
     260    }
     261
     262    /**
     263     * Affichage d'un message de réussite
     264     * @param message
     265     */
     266    public void setMessage(String message) {
     267        this.labelMessage.setText(message);
     268    }
     269
     270    public void setAdditionalMessage(String additionalMessage) {
     271        this.labelAdditionalMessage.setText(additionalMessage);
     272    }
     273
     274    @Override
     275    public void actionPerformed(ActionEvent arg0) {
     276        if (arg0.getSource().equals(jMenuItemPreferences)) {
     277            new PreferencesDialog(this);
     278        } else if (arg0.getSource().equals(jMenuItemSearch)) {
     279            setImageSearchPanelVisible();
     280        }
     281
     282    }
     283
     284    public static void reduceSizeOfComponent(JComponent comp) {
     285        comp.setMaximumSize(comp.getPreferredSize());
     286    }
     287
     288    /**
     289     * @return the progressBar
     290     */
     291    public JProgressBar getProgressBar() {
     292        return progressBar;
     293    }
     294
     295    /**
     296     * @return the mapsIdPos
     297     */
     298    public HashMap<Integer, Integer> getMapsIdPos() {
     299        return mapsIdPos;
     300    }
     301
     302    @Override
     303    public void keyPressed(KeyEvent paramKeyEvent) {
     304        if (paramKeyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
     305            String queryString = fieldSearch.getText();
     306            ThumbnailSearchPanel searchPanel = new ThumbnailSearchPanel(queryString);
     307            addTabb(searchPanel);
     308        }
     309    }
     310
     311    @Override
     312    public void keyReleased(KeyEvent paramKeyEvent) {
     313    }
     314
     315    @Override
     316    public void keyTyped(KeyEvent paramKeyEvent) {
     317    }
     318
     319    /**
     320     * @return the collapsiblePanel
     321     */
     322    public MyCollapsiblePanel getCollapsiblePanel() {
     323        return collapsiblePanel;
     324    }
     325
     326    /**
     327     * @return the imageSearchPanelVisible
     328     */
     329    public boolean isImageSearchPanelVisible() {
     330        return imageSearchPanelVisible;
     331    }
     332
     333    /**
     334     * @return the browserVisible
     335     */
     336    public boolean isBrowserVisible() {
     337        return browserVisible;
     338    }
    283339
    284340}
Note: See TracChangeset for help on using the changeset viewer.