--- /dev/null
+package jalview.jbgui;
+
+import jalview.ws.dbsources.PDBRestClient.PDBDocField;
+
+import java.awt.Rectangle;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.table.AbstractTableModel;
+
+@SuppressWarnings("serial")
+public class PDBDocFieldPreferences extends JScrollPane
+{
+
+ protected JTable tbl_pdbDocFieldConfig = new JTable();
+
+ protected JScrollPane scrl_pdbDocFieldConfig = new JScrollPane(
+ tbl_pdbDocFieldConfig);
+
+ private HashMap<String, PDBDocField> map = new HashMap<String, PDBDocField>();
+
+ private static Collection<PDBDocField> searchSummaryFields = new HashSet<PDBDocField>();
+
+ private static Collection<PDBDocField> structureSummaryFields = new HashSet<PDBDocField>();
+
+ static
+ {
+ searchSummaryFields.add(PDBDocField.PDB_ID);
+ searchSummaryFields.add(PDBDocField.TITLE);
+ structureSummaryFields.add(PDBDocField.PDB_ID);
+ structureSummaryFields.add(PDBDocField.TITLE);
+ }
+
+ public PDBDocFieldPreferences(Rectangle position)
+ {
+ this.setBounds(position);
+ this.getViewport().add(tbl_pdbDocFieldConfig);
+
+ Object[][] data = new Object[PDBDocField.values().length - 1][3];
+ int x = 0;
+ for (PDBDocField field : PDBDocField.values())
+ {
+ if (field.getName().equalsIgnoreCase("all"))
+ {
+ continue;
+ }
+
+ data[x++] = new Object[]
+ { field.getName(), searchSummaryFields.contains(field),
+ structureSummaryFields.contains(field) };
+ map.put(field.getName(), field);
+ }
+
+ PDBFieldTableModel model = new PDBFieldTableModel(data);
+ tbl_pdbDocFieldConfig.setModel(model);
+ }
+
+ public static Collection<PDBDocField> getSearchSummaryFields()
+ {
+ return searchSummaryFields;
+ }
+
+ public static void setSearchSummaryFields(
+ Collection<PDBDocField> searchSummaryFields)
+ {
+ PDBDocFieldPreferences.searchSummaryFields = searchSummaryFields;
+ }
+
+ public static Collection<PDBDocField> getStructureSummaryFields()
+ {
+ return structureSummaryFields;
+ }
+
+ public static void setStructureSummaryFields(
+ Collection<PDBDocField> structureSummaryFields)
+ {
+ PDBDocFieldPreferences.structureSummaryFields = structureSummaryFields;
+ }
+
+ class PDBFieldTableModel extends AbstractTableModel
+ {
+
+ public PDBFieldTableModel(Object[][] data)
+ {
+ this.data = data;
+ }
+
+ private String[] columnNames = new String[]
+ { "PDB Feild", "Show in search summary",
+ "Show in structure chooser summary" };
+
+ private Object[][] data;
+
+ public int getColumnCount()
+ {
+ return columnNames.length;
+ }
+
+ public int getRowCount()
+ {
+ return data.length;
+ }
+
+ public String getColumnName(int col)
+ {
+ return columnNames[col];
+ }
+
+ public Object getValueAt(int row, int col)
+ {
+ return data[row][col];
+ }
+
+ /*
+ * JTable uses this method to determine the default renderer/ editor for
+ * each cell. If we didn't implement this method, then the last column would
+ * contain text ("true"/"false"), rather than a check box.
+ */
+ public Class getColumnClass(int c)
+ {
+ return getValueAt(0, c).getClass();
+ }
+
+ /*
+ * Don't need to implement this method unless your table's editable.
+ */
+ public boolean isCellEditable(int row, int col)
+ {
+ // Note that the data/cell address is constant,
+ // no matter where the cell appears onscreen.
+ return col == 1 || col == 2;
+
+ }
+
+ /*
+ * Don't need to implement this method unless your table's data can change.
+ */
+ public void setValueAt(Object value, int row, int col)
+ {
+ data[row][col] = value;
+ fireTableCellUpdated(row, col);
+
+ String name = getValueAt(row, 0).toString();
+ boolean selected = ((Boolean) value).booleanValue();
+
+ PDBDocField pdbField = map.get(name);
+
+ if (col == 1)
+ {
+ if (searchSummaryFields.contains(pdbField) && !selected)
+ {
+ searchSummaryFields.remove(pdbField);
+ }
+
+ if (!searchSummaryFields.contains(pdbField) && selected)
+ {
+ searchSummaryFields.add(pdbField);
+ }
+ }
+ else if (col == 2)
+ {
+ if (structureSummaryFields.contains(pdbField) && !selected)
+ {
+ structureSummaryFields.remove(pdbField);
+ }
+
+ if (!structureSummaryFields.contains(pdbField) && selected)
+ {
+ structureSummaryFields.add(pdbField);
+ }
+ }
+
+ }
+ }
+}