From: tcofoegbu Date: Mon, 1 May 2017 13:16:43 +0000 (+0100) Subject: JAL-2376 copied out patch from Phyre branch X-Git-Tag: Release_2_10_2~3^2~89^2^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b838581d0bef5793a819a317a827d66421ee48a2;p=jalview.git JAL-2376 copied out patch from Phyre branch --- diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index ee22ae4..3e516a6 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -53,7 +53,6 @@ import java.util.Vector; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JLabel; -import javax.swing.JOptionPane; import javax.swing.table.AbstractTableModel; /** @@ -542,26 +541,26 @@ public class StructureChooser extends GStructureChooser implements if (haveData) { cmb_filterOption.addItem(new FilterOption("Best Quality", - "overall_quality", VIEWS_FILTER)); + "overall_quality", VIEWS_FILTER, false)); cmb_filterOption.addItem(new FilterOption("Best Resolution", - "resolution", VIEWS_FILTER)); + "resolution", VIEWS_FILTER, false)); cmb_filterOption.addItem(new FilterOption("Most Protein Chain", - "number_of_protein_chains", VIEWS_FILTER)); + "number_of_protein_chains", VIEWS_FILTER, false)); cmb_filterOption.addItem(new FilterOption("Most Bound Molecules", - "number_of_bound_molecules", VIEWS_FILTER)); + "number_of_bound_molecules", VIEWS_FILTER, false)); cmb_filterOption.addItem(new FilterOption("Most Polymer Residues", - "number_of_polymer_residues", VIEWS_FILTER)); + "number_of_polymer_residues", VIEWS_FILTER, true)); } cmb_filterOption.addItem(new FilterOption("Enter PDB Id", "-", - VIEWS_ENTER_ID)); + VIEWS_ENTER_ID, false)); cmb_filterOption.addItem(new FilterOption("From File", "-", - VIEWS_FROM_FILE)); - FilterOption cachedOption = new FilterOption("Cached PDB Entries", "-", - VIEWS_LOCAL_PDB); - cmb_filterOption.addItem(cachedOption); + VIEWS_FROM_FILE, false)); - if (/*!haveData &&*/cachedPDBExists) + if (cachedPDBExists) { + FilterOption cachedOption = new FilterOption("Cached PDB Entries", + "-", VIEWS_LOCAL_PDB, false); + cmb_filterOption.addItem(cachedOption); cmb_filterOption.setSelectedItem(cachedOption); } diff --git a/src/jalview/jbgui/GStructureChooser.java b/src/jalview/jbgui/GStructureChooser.java index 3a064d2..041fefd 100644 --- a/src/jalview/jbgui/GStructureChooser.java +++ b/src/jalview/jbgui/GStructureChooser.java @@ -33,6 +33,7 @@ import jalview.util.MessageManager; import java.awt.BorderLayout; import java.awt.CardLayout; +import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.GridLayout; @@ -54,11 +55,14 @@ import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JLabel; +import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.JSeparator; import javax.swing.JTabbedPane; import javax.swing.JTable; import javax.swing.JTextField; +import javax.swing.ListCellRenderer; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; @@ -488,6 +492,19 @@ public abstract class GStructureChooser extends JPanel implements }); cmb_filterOption.addItemListener(this); + + // add CustomComboSeparatorsRenderer to filter option combo-box + cmb_filterOption.setRenderer(new CustomComboSeparatorsRenderer( + (ListCellRenderer) cmb_filterOption.getRenderer()) + { + @Override + protected boolean addSeparatorAfter(JList list, FilterOption value, + int index) + { + return value.isAddSeparatorAfter(); + } + }); + chk_invertFilter.addItemListener(this); pnl_actions.add(chk_rememberSettings); @@ -643,11 +660,28 @@ public abstract class GStructureChooser extends JPanel implements private String view; - public FilterOption(String name, String value, String view) + private boolean addSeparatorAfter; + + /** + * Model for structure filter option + * + * @param name + * - the name of the Option + * @param value + * - the value of the option + * @param view + * - the category of the filter option + * @param addSeparatorAfter + * - if true, a horizontal separator is rendered immediately after + * this filter option, otherwise + */ + public FilterOption(String name, String value, String view, + boolean addSeparatorAfter) { this.name = name; this.value = value; this.view = view; + this.addSeparatorAfter = addSeparatorAfter; } public String getName() @@ -685,6 +719,16 @@ public abstract class GStructureChooser extends JPanel implements { return this.name; } + + public boolean isAddSeparatorAfter() + { + return addSeparatorAfter; + } + + public void setAddSeparatorAfter(boolean addSeparatorAfter) + { + this.addSeparatorAfter = addSeparatorAfter; + } } /** @@ -800,6 +844,54 @@ public abstract class GStructureChooser extends JPanel implements return cmb_filterOption; } + /** + * Custom ListCellRenderer for adding a separator between different categories + * of structure chooser filter option drop-down. + * + * @author tcnofoegbu + * + */ + public abstract class CustomComboSeparatorsRenderer implements + ListCellRenderer + { + private ListCellRenderer regent; + + private JPanel separatorPanel = new JPanel(new BorderLayout()); + + private JSeparator jSeparator = new JSeparator(); + + public CustomComboSeparatorsRenderer(ListCellRenderer listCellRenderer) + { + this.regent = listCellRenderer; + } + + @Override + public Component getListCellRendererComponent(JList list, + Object value, + int index, boolean isSelected, boolean cellHasFocus) + { + + Component comp = regent.getListCellRendererComponent(list, value, + index, isSelected, cellHasFocus); + if (index != -1 + && addSeparatorAfter(list, (FilterOption) value, index)) + { + separatorPanel.removeAll(); + separatorPanel.add(comp, BorderLayout.CENTER); + separatorPanel.add(jSeparator, BorderLayout.SOUTH); + return separatorPanel; + } + else + { + return comp; + } + } + + protected abstract boolean addSeparatorAfter(JList list, + FilterOption value, + int index); + } + protected abstract void stateChanged(ItemEvent e); protected abstract void ok_ActionPerformed(); @@ -816,4 +908,4 @@ public abstract class GStructureChooser extends JPanel implements public abstract void tabRefresh(); public abstract void validateSelections(); -} +} \ No newline at end of file