Ignore:
Timestamp:
Sep 19, 2010, 11:40:53 PM (14 years ago)
Author:
mlg
Message:

New feature : research
Add a research functionnality : it's juste a field on the bottom right of the main frame. To make a research, the user have to type text in that field and press enter. It opens a new tab. A new tab is opened for each research. The tab contains the query string.

File:
1 edited

Legend:

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

    r6958 r6972  
    66import java.awt.event.ActionEvent;
    77import java.awt.event.ActionListener;
     8import java.awt.event.KeyEvent;
     9import java.awt.event.KeyListener;
    810import java.util.HashMap;
    911
     
    2224import fr.mael.jiwigo.transverse.util.Messages;
    2325import fr.mael.jiwigo.transverse.util.Outil;
     26import fr.mael.jiwigo.ui.field.HintTextField;
    2427import fr.mael.jiwigo.ui.mainframe.tab.JTabbedPaneWithCloseIcons;
    2528
     
    5356 * Frame principale
    5457 */
    55 public class MainFrame extends JFrame implements ActionListener {
     58public class MainFrame extends JFrame implements ActionListener, KeyListener {
    5659    /**
    5760     * Logger
     
    106109
    107110    private HashMap<Integer, Integer> mapsIdPos = new HashMap<Integer, Integer>();
     111
     112    private HintTextField fieldSearch;
    108113
    109114    /**
     
    129134        categoriesTree = new CategoriesTree();
    130135        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));
    136136
    137137        tabbedPane = new JTabbedPaneWithCloseIcons();
    138         //      tabbedPane.add(scrollPaneImagesPanel);
    139138        splitPane.setRightComponent(tabbedPane);
    140139
    141140        this.add(splitPane, BorderLayout.CENTER);
     141        JPanel panelBas = new JPanel(new BorderLayout());
    142142        JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    143143        progressBar = new JProgressBar(0, 100);
    144144        panel.add(progressBar);
    145145        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);
    146152
    147153        jMenuEdition = new JMenu(Messages.getMessage("mainFrame_editionMenu"));
     
    152158
    153159        this.setJMenuBar(jMenuBar);
    154         this.add(panel, BorderLayout.SOUTH);
    155         //      this.pack();
     160        this.add(panelBas, BorderLayout.SOUTH);
    156161        this.setSize(900, 600);
    157162        this.setLocationRelativeTo(null);
     
    160165    }
    161166
    162     public void addTabb(ThumbnailCategoryPanel panel) {
    163         JScrollPane scrollPaneImagesPanel = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
     167    public void addTabb(IThumbnailPanel panel) {
     168        JScrollPane scrollPaneImagesPanel = new JScrollPane((JPanel) panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
    164169                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    165170        scrollPaneImagesPanel.setPreferredSize(new Dimension(900, 600));
    166171        boolean found = false;
     172        boolean isSearch = false;
     173        if (panel instanceof ThumbnailSearchPanel) {
     174            isSearch = true;
     175        }
    167176        for (int i = 0; i < tabbedPane.getTabCount(); i++) {
    168177            JScrollPane scroll = (JScrollPane) tabbedPane.getComponentAt(i);
    169             ThumbnailCategoryPanel thumbPan = (ThumbnailCategoryPanel) scroll.getViewport().getComponents()[0];
     178            IThumbnailPanel thumbPan = (IThumbnailPanel) scroll.getViewport().getComponents()[0];
    170179            if (thumbPan.getCategory().getIdentifiant().equals(panel.getCategory().getIdentifiant())) {
    171                 tabbedPane.setSelectedIndex(i);
    172                 found = true;
    173                 break;
     180                //only if it's not for a re
     181                if (!(panel instanceof ThumbnailSearchPanel)) {
     182                    tabbedPane.setSelectedIndex(i);
     183                    found = true;
     184                    break;
     185                }
    174186            }
    175187        }
    176         if (!found) {
     188        //if it's not for a research, the title of the tab
     189        //is the name of the category
     190        if (!found && !isSearch) {
    177191            tabbedPane.addTab(panel.getCategory().getNom(), scrollPaneImagesPanel, new ImageIcon(Outil
    178192                    .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         //      }
     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        }
    187200
    188201    }
     
    237250    }
    238251
     252    @Override
     253    public void keyPressed(KeyEvent paramKeyEvent) {
     254        if (paramKeyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
     255            String queryString = fieldSearch.getText();
     256            ThumbnailSearchPanel searchPanel = new ThumbnailSearchPanel(queryString);
     257            addTabb(searchPanel);
     258        }
     259    }
     260
     261    @Override
     262    public void keyReleased(KeyEvent paramKeyEvent) {
     263    }
     264
     265    @Override
     266    public void keyTyped(KeyEvent paramKeyEvent) {
     267    }
     268
    239269}
Note: See TracChangeset for help on using the changeset viewer.