Skip to content
Snippets Groups Projects
Commit 706bfcc1 authored by tjc's avatar tjc
Browse files

tidy

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@8307 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent d146420a
No related branches found
No related tags found
No related merge requests found
...@@ -20,36 +20,42 @@ ...@@ -20,36 +20,42 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* *
* $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/KeyChoice.java,v 1.4 2008-05-29 15:16:28 tjc Exp $ * $Header: //tmp/pathsoft/artemis/uk/ac/sanger/artemis/components/KeyChoice.java,v 1.5 2008-07-21 15:43:16 tjc Exp $
*/ */
package uk.ac.sanger.artemis.components; package uk.ac.sanger.artemis.components;
import uk.ac.sanger.artemis.*; import uk.ac.sanger.artemis.Options;
import uk.ac.sanger.artemis.util.StringVector;
import uk.ac.sanger.artemis.io.Key; import uk.ac.sanger.artemis.io.Key;
import uk.ac.sanger.artemis.io.KeyVector; import uk.ac.sanger.artemis.io.KeyVector;
import uk.ac.sanger.artemis.io.EntryInformation; import uk.ac.sanger.artemis.io.EntryInformation;
import java.awt.*; import java.awt.Font;
import java.awt.event.*; import java.awt.event.ItemListener;
import javax.swing.*; import javax.swing.JComboBox;
import javax.swing.JPanel;
/** /**
* This component is a Choice component that shows the possible feature keys. * This component is a Choice component that shows the possible feature keys.
* *
* @author Kim Rutherford * @author Kim Rutherford
* @version $Id: KeyChoice.java,v 1.4 2008-05-29 15:16:28 tjc Exp $ * @version $Id: KeyChoice.java,v 1.5 2008-07-21 15:43:16 tjc Exp $
**/ **/
public class KeyChoice extends JPanel { public class KeyChoice extends JPanel
{
private static final long serialVersionUID = 1L;
/** The JComboBox component that will show the feature keys. */
private JComboBox key_chooser = null;
/** /**
* Create a new KeyChoice component with CDS as the default key. * Create a new KeyChoice component with CDS as the default key.
* @param entry_information The object to get the list of possible * @param entry_information The object to get the list of possible
* keys from. * keys from.
**/ **/
public KeyChoice (final EntryInformation entry_information) { public KeyChoice (final EntryInformation entry_information)
{
this (entry_information, Key.CDS); this (entry_information, Key.CDS);
} }
...@@ -59,10 +65,8 @@ public class KeyChoice extends JPanel { ...@@ -59,10 +65,8 @@ public class KeyChoice extends JPanel {
* keys from. * keys from.
**/ **/
public KeyChoice (final EntryInformation entry_information, public KeyChoice (final EntryInformation entry_information,
final Key default_key) { final Key default_key)
this.entry_information = entry_information; {
this.default_key = default_key;
final Font font = Options.getOptions ().getFont (); final Font font = Options.getOptions ().getFont ();
setFont (font); setFont (font);
...@@ -70,36 +74,34 @@ public class KeyChoice extends JPanel { ...@@ -70,36 +74,34 @@ public class KeyChoice extends JPanel {
key_chooser.setEditable(true); key_chooser.setEditable(true);
final int MAX_VISIBLE_ROWS = 30; final int MAX_VISIBLE_ROWS = 30;
key_chooser.setMaximumRowCount (MAX_VISIBLE_ROWS); key_chooser.setMaximumRowCount (MAX_VISIBLE_ROWS);
updateChoice (); addChoice (entry_information, default_key);
} }
/** /**
* Return the currently selected key. * Return the currently selected key.
**/ **/
public Key getSelectedItem () { public Key getSelectedItem ()
final Key key; {
return new Key ((String) key_chooser.getSelectedItem ());
key = new Key ((String) key_chooser.getSelectedItem ());
return key;
} }
/** /**
* Set the selected Key. * Set the selected Key.
**/ **/
public void setKey (final Key new_key) { public void setKey (final Key new_key)
{
final int key_index = keyIndex (new_key); final int key_index = keyIndex (new_key);
if (key_index == -1) { if (key_index == -1)
{
// add the key // add the key
key_chooser.addItem (new_key.toString ()); key_chooser.addItem (new_key.toString ());
key_chooser.setSelectedItem (new_key.toString ()); key_chooser.setSelectedItem (new_key.toString ());
} else { }
else
key_chooser.setSelectedIndex (key_index); key_chooser.setSelectedIndex (key_index);
}
} }
/** /**
...@@ -107,7 +109,8 @@ public class KeyChoice extends JPanel { ...@@ -107,7 +109,8 @@ public class KeyChoice extends JPanel {
* component of this KeyChoice. * component of this KeyChoice.
* @param l The item listener. * @param l The item listener.
**/ **/
public void addItemListener(ItemListener l) { public void addItemListener(ItemListener l)
{
key_chooser.addItemListener (l); key_chooser.addItemListener (l);
} }
...@@ -117,67 +120,45 @@ public class KeyChoice extends JPanel { ...@@ -117,67 +120,45 @@ public class KeyChoice extends JPanel {
* events from the Choice component of this KeyChoice. * events from the Choice component of this KeyChoice.
* @param l The item listener. * @param l The item listener.
**/ **/
public void removeItemListener(ItemListener l) { public void removeItemListener(ItemListener l)
{
key_chooser.removeItemListener (l); key_chooser.removeItemListener (l);
} }
/** /**
* Update the key_chooser. * Add the key_chooser.
**/ **/
private void updateChoice () { private void addChoice (final EntryInformation entry_information,
removeAll (); final Key default_key)
{
final Font font = Options.getOptions ().getFont (); final Font font = Options.getOptions ().getFont ();
key_chooser.setFont (font); key_chooser.setFont (font);
add (key_chooser); KeyVector keys = entry_information.getSortedValidKeys();
KeyVector keys = getSortedKeys ();
if (keys == null) { if (keys == null)
{
keys = new KeyVector (); keys = new KeyVector ();
keys.add (Key.CDS); keys.add (Key.CDS);
} }
for (int i = 0 ; i < keys.size () ; ++i) { for (int i = 0 ; i < keys.size () ; ++i)
key_chooser.addItem ( ((Key)keys.get(i)).toString ()); key_chooser.addItem ( ((Key)keys.get(i)).toString ());
}
if (keyIndex (default_key) != -1) { if (keyIndex (default_key) != -1)
setKey (default_key); setKey (default_key);
} add (key_chooser);
// XXX change to revalidate().
validate ();
if (getParent () != null) {
// XXX change to revalidate().
getParent ().validate ();
if (getParent ().getParent () != null) {
// XXX change to revalidate().
getParent ().getParent ().validate ();
}
}
}
/**
* Return a alphanumerically sorted vector containing the String
* representations of the common keys (those listed in the common_keys
* property of the options file). If there is no common_keys option then
* all the legal keys are returned.
**/
private KeyVector getSortedKeys () {
return entry_information.getSortedValidKeys ();
} }
/** /**
* Return the index in the key_chooser component of the given Key. * Return the index in the key_chooser component of the given Key.
**/ **/
private int keyIndex (final Key key) { private int keyIndex (final Key key)
for (int i = 0 ; i < key_chooser.getItemCount () ; ++i) { {
if (key.toString ().equals ((String)key_chooser.getItemAt (i))) { for (int i = 0 ; i < key_chooser.getItemCount () ; ++i)
{
if (key.toString ().equals ((String)key_chooser.getItemAt (i)))
return i; return i;
}
} }
return -1; return -1;
} }
...@@ -187,24 +168,4 @@ public class KeyChoice extends JPanel { ...@@ -187,24 +168,4 @@ public class KeyChoice extends JPanel {
key_chooser.setEnabled(isEnabled); key_chooser.setEnabled(isEnabled);
repaint(); repaint();
} }
}
/** \ No newline at end of file
* The Key that was passed to the constructor.
**/
private Key default_key = null;
/**
* The JComboBox component that will show the feature keys.
**/
private JComboBox key_chooser = null;
/**
* This toggle sets whether to show common keys or uncommon keys.
**/
private JCheckBox common_keys_checkbox = null;
/**
* The EntryInformation object that was passed to the constructor.
**/
private EntryInformation entry_information = null;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment