Skip to content
Snippets Groups Projects
ListSelectionPanel.java 5.07 KiB
Newer Older
  • Learn to ignore specific revisions
  • tjc's avatar
    tjc committed
    /* ListSelectionPanel.java
     *
     * created: Fri Oct  9 1998
     *
     * This file is part of Artemis
     *
     * Copyright(C) 1998,1999,2000,2001  Genome Research Limited
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * as published by the Free Software Foundation; either version 2
     * of the License, or(at your option) any later version.
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
     *
    
    tjc's avatar
    tjc committed
     * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/ListSelectionPanel.java,v 1.5 2007-07-09 13:03:45 tjc Exp $
    
    tjc's avatar
    tjc committed
     */
    
    package uk.ac.sanger.artemis.components;
    
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.Box;
    import javax.swing.DefaultListModel;
    import javax.swing.JButton;
    
    tjc's avatar
    tjc committed
    import javax.swing.JCheckBox;
    
    tjc's avatar
    tjc committed
    import javax.swing.JLabel;
    import javax.swing.JList;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    
    import uk.ac.sanger.artemis.EntryGroup;
    
    tjc's avatar
    tjc committed
    import uk.ac.sanger.artemis.io.GFFDocumentEntry;
    
    tjc's avatar
    tjc committed
    
    class ListSelectionPanel extends JPanel
    {
    
      /** */
      private static final long serialVersionUID = 1L;
      private DefaultListModel listModel;
    
    tjc's avatar
    tjc committed
      private JCheckBox save;
      
    
      /**
       * Panel used to select from and order a list. 
       * @param entry_group
       * @param names
       * @param description
       */
    
    tjc's avatar
    tjc committed
      public ListSelectionPanel(final EntryGroup entry_group,
    
                                final Object names[],
    
    tjc's avatar
    tjc committed
                                final String[] description,
                                final boolean saveOption)
    
    tjc's avatar
    tjc committed
      {
        listModel = new DefaultListModel();
    
        for(int i = 0; i < names.length; i++)
          listModel.addElement(names[i]);
    
    
        final JLabel label = new JLabel("Qualifier order :");
    
    tjc's avatar
    tjc committed
        final JList name_list = new JList(listModel);
        final JScrollPane jsp = new JScrollPane(name_list);
    
        JButton remove_butt = new JButton("REMOVE");
        remove_butt.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent e)
          {
            while(!name_list.isSelectionEmpty())
              listModel.remove(name_list.getSelectedIndex());
          }
        });
    
        Box bdown = Box.createVerticalBox();
        bdown = Box.createVerticalBox();
        JButton upButt = new JButton("UP");
        upButt.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent e)
          {
            Object obj = name_list.getSelectedValue();
            int index = name_list.getSelectedIndex();
    
            if(index <= 0)
              return;
            listModel.removeElementAt(index);
            listModel.insertElementAt(obj, index - 1);
            name_list.setSelectedIndex(index - 1);
          }
        });
        bdown.add(upButt);
    
        JButton downButt = new JButton("DOWN");
        downButt.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent e)
          {
            Object obj = name_list.getSelectedValue();
            int index = name_list.getSelectedIndex();
    
            if(index >= listModel.getSize() - 1)
              return;
            listModel.removeElementAt(index);
            listModel.insertElementAt(obj, index + 1);
            name_list.setSelectedIndex(index + 1);
          }
        });
        bdown.add(downButt);
        add(bdown, BorderLayout.WEST);
    
        bdown = Box.createVerticalBox();
    
      
        bdown.add(Box.createVerticalStrut(15));
        for(int i=0; i<description.length; i++)
        	bdown.add(new JLabel(description[i]));
    
    tjc's avatar
    tjc committed
        bdown.add(label);
        bdown.add(jsp);
    
    tjc's avatar
    tjc committed
        add(bdown, BorderLayout.CENTER);
    
    
    tjc's avatar
    tjc committed
        boolean isGFF = false;
        if(entry_group.getDefaultEntry().getEMBLEntry() instanceof GFFDocumentEntry)
          isGFF = true;
    
    tjc's avatar
    tjc committed
        final QualifierChoice qualifier_choice = new QualifierChoice(
    
    tjc's avatar
    tjc committed
            entry_group.elementAt(0).getEntryInformation(), null, null, isGFF);
    
    tjc's avatar
    tjc committed
        
    
    tjc's avatar
    tjc committed
        JButton add_butt = new JButton("ADD");
        add_butt.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent e)
          {
    
    tjc's avatar
    tjc committed
            listModel.addElement(qualifier_choice.getSelectedItem().toString());
    
    tjc's avatar
    tjc committed
          }
        });
    
    tjc's avatar
    tjc committed
        
        if(saveOption)
          save = new JCheckBox("Save between sessions", false);
    
    tjc's avatar
    tjc committed
    
        bdown = Box.createVerticalBox();
        bdown.add(Box.createVerticalGlue());
    
    tjc's avatar
    tjc committed
        bdown.add(qualifier_choice);
    
    tjc's avatar
    tjc committed
        bdown.add(add_butt);
    
        bdown.add(remove_butt);
    
    tjc's avatar
    tjc committed
        if(saveOption)
          bdown.add(save);
    
    tjc's avatar
    tjc committed
        add(bdown, BorderLayout.EAST);
      }
      
      public Object[] getResultArray()
      {
        return listModel.toArray();
      }
      
    
      public String getResultString()
      {
        Object listNames[] = listModel.toArray();
        String listNamesString = "";
        for(int i=0; i<listNames.length; i++)
        	listNamesString = listNamesString + listNames[i] + " ";
        return listNamesString;
      }
    
    tjc's avatar
    tjc committed
        
      public boolean isSaveOption()
      {
        return save.isSelected();
      }
    
    tjc's avatar
    tjc committed
    }