X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fjbgui%2FGStructureChooser.java;h=041fefd8317e1bd6a744778462e561e628911947;hb=480d7b96f089281a3caf77d2a4e5adec09dc5bfa;hp=67b3a207b49a8a7a52fff24bec9bfe728861c1e1;hpb=a207f4080b01543b48b80f6f3eb331b75b63bdc6;p=jalview.git diff --git a/src/jalview/jbgui/GStructureChooser.java b/src/jalview/jbgui/GStructureChooser.java index 67b3a20..041fefd 100644 --- a/src/jalview/jbgui/GStructureChooser.java +++ b/src/jalview/jbgui/GStructureChooser.java @@ -22,18 +22,21 @@ package jalview.jbgui; import jalview.datamodel.SequenceI; +import jalview.fts.api.FTSDataColumnI; +import jalview.fts.core.FTSDataColumnPreferences; +import jalview.fts.core.FTSDataColumnPreferences.PreferenceSource; +import jalview.fts.service.pdb.PDBFTSRestClient; import jalview.gui.AlignmentPanel; import jalview.gui.Desktop; import jalview.gui.JvSwingUtils; -import jalview.jbgui.PDBDocFieldPreferences.PreferenceSource; import jalview.util.MessageManager; -import jalview.ws.dbsources.PDBRestClient; -import jalview.ws.dbsources.PDBRestClient.PDBDocField; import java.awt.BorderLayout; import java.awt.CardLayout; +import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; +import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; @@ -42,6 +45,8 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -50,15 +55,20 @@ 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; import javax.swing.event.DocumentListener; +import javax.swing.event.InternalFrameEvent; +import javax.swing.table.TableColumn; @SuppressWarnings("serial") /** @@ -69,6 +79,12 @@ import javax.swing.event.DocumentListener; public abstract class GStructureChooser extends JPanel implements ItemListener { + protected JPanel statusPanel = new JPanel(); + + public JLabel statusBar = new JLabel(); + + private JPanel pnl_actionsAndStatus = new JPanel(new BorderLayout()); + protected String frameTitle = MessageManager .getString("label.structure_chooser"); @@ -150,8 +166,70 @@ public abstract class GStructureChooser extends JPanel implements protected static final String VIEWS_LOCAL_PDB = "VIEWS_LOCAL_PDB"; - protected JTable tbl_summary = new JTable() + protected JTable tbl_local_pdb = new JTable(); + + protected JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb); + + protected JTabbedPane pnl_filter = new JTabbedPane(); + + protected FTSDataColumnPreferences pdbDocFieldPrefs = new FTSDataColumnPreferences( + PreferenceSource.STRUCTURE_CHOOSER, + PDBFTSRestClient.getInstance()); + + protected FTSDataColumnI[] previousWantedFields; + + protected static Map tempUserPrefs = new HashMap(); + + private JTable tbl_summary = new JTable() { + private boolean inLayout; + + @Override + public boolean getScrollableTracksViewportWidth() + { + return hasExcessWidth(); + + } + + @Override + public void doLayout() + { + if (hasExcessWidth()) + { + autoResizeMode = AUTO_RESIZE_SUBSEQUENT_COLUMNS; + } + inLayout = true; + super.doLayout(); + inLayout = false; + autoResizeMode = AUTO_RESIZE_OFF; + } + + protected boolean hasExcessWidth() + { + return getPreferredSize().width < getParent().getWidth(); + } + + @Override + public void columnMarginChanged(ChangeEvent e) + { + if (isEditing()) + { + removeEditor(); + } + TableColumn resizingColumn = getTableHeader().getResizingColumn(); + // Need to do this here, before the parent's + // layout manager calls getPreferredSize(). + if (resizingColumn != null && autoResizeMode == AUTO_RESIZE_OFF + && !inLayout) + { + resizingColumn.setPreferredWidth(resizingColumn.getWidth()); + String colHeader = resizingColumn.getHeaderValue().toString(); + tempUserPrefs.put(colHeader, resizingColumn.getWidth()); + } + resizeAndRepaint(); + } + + @Override public String getToolTipText(MouseEvent evt) { String toolTipText = null; @@ -161,6 +239,10 @@ public abstract class GStructureChooser extends JPanel implements try { + if (getValueAt(rowIndex, colIndex) == null) + { + return null; + } toolTipText = getValueAt(rowIndex, colIndex).toString(); } catch (Exception e) { @@ -177,17 +259,6 @@ public abstract class GStructureChooser extends JPanel implements protected JScrollPane scrl_foundStructures = new JScrollPane(tbl_summary); - protected JTable tbl_local_pdb = new JTable(); - - protected JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb); - - private JTabbedPane pnl_filter = new JTabbedPane(); - - private PDBDocFieldPreferences pdbDocFieldPrefs = new PDBDocFieldPreferences( - PreferenceSource.STRUCTURE_CHOOSER); - - protected PDBDocField[] previousWantedFields; - public GStructureChooser() { try @@ -209,15 +280,21 @@ public abstract class GStructureChooser extends JPanel implements */ private void jbInit() throws Exception { + Integer width = tempUserPrefs.get("structureChooser.width") == null ? 800 + : tempUserPrefs.get("structureChooser.width"); + Integer height = tempUserPrefs.get("structureChooser.height") == null ? 400 + : tempUserPrefs.get("structureChooser.height"); tbl_summary.setAutoCreateRowSorter(true); tbl_summary.getTableHeader().setReorderingAllowed(false); tbl_summary.addMouseListener(new MouseAdapter() { + @Override public void mouseClicked(MouseEvent e) { validateSelections(); } + @Override public void mouseReleased(MouseEvent e) { validateSelections(); @@ -260,11 +337,13 @@ public abstract class GStructureChooser extends JPanel implements tbl_local_pdb.getTableHeader().setReorderingAllowed(false); tbl_local_pdb.addMouseListener(new MouseAdapter() { + @Override public void mouseClicked(MouseEvent e) { validateSelections(); } + @Override public void mouseReleased(MouseEvent e) { validateSelections(); @@ -304,6 +383,7 @@ public abstract class GStructureChooser extends JPanel implements } } evt.consume(); + break; default: return; } @@ -313,6 +393,7 @@ public abstract class GStructureChooser extends JPanel implements btn_view.setText(MessageManager.getString("action.view")); btn_view.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(ActionEvent e) { ok_ActionPerformed(); @@ -334,9 +415,10 @@ public abstract class GStructureChooser extends JPanel implements btn_cancel.setText(MessageManager.getString("action.cancel")); btn_cancel.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(ActionEvent e) { - mainFrame.dispose(); + closeAction(pnl_filter.getHeight()); } }); btn_cancel.addKeyListener(new KeyAdapter() @@ -346,7 +428,7 @@ public abstract class GStructureChooser extends JPanel implements { if (evt.getKeyCode() == KeyEvent.VK_ENTER) { - mainFrame.dispose(); + closeAction(pnl_filter.getHeight()); } } }); @@ -356,6 +438,7 @@ public abstract class GStructureChooser extends JPanel implements btn_pdbFromFile.setText(btn_title + " "); btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener() { + @Override public void actionPerformed(ActionEvent e) { pdbFromFile_actionPerformed(); @@ -373,11 +456,9 @@ public abstract class GStructureChooser extends JPanel implements } }); - scrl_foundStructures.setPreferredSize(new Dimension(500, 300)); - scrl_foundStructures - .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + scrl_foundStructures.setPreferredSize(new Dimension(width, height)); - scrl_localPDB.setPreferredSize(new Dimension(500, 300)); + scrl_localPDB.setPreferredSize(new Dimension(width, height)); scrl_localPDB .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); @@ -385,9 +466,8 @@ public abstract class GStructureChooser extends JPanel implements chk_invertFilter.setFont(new java.awt.Font("Verdana", 0, 12)); chk_rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12)); chk_rememberSettings.setVisible(false); - - txt_search.setToolTipText(MessageManager - .getString("label.enter_pdb_id")); + txt_search.setToolTipText(JvSwingUtils.wrapTooltip(true, + MessageManager.getString("label.enter_pdb_id"))); cmb_filterOption.setToolTipText(MessageManager .getString("info.select_filter_option")); txt_search.getDocument().addDocumentListener(new DocumentListener() @@ -412,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); @@ -440,18 +533,23 @@ public abstract class GStructureChooser extends JPanel implements .getString("label.configure_displayed_columns"); ChangeListener changeListener = new ChangeListener() { + @Override public void stateChanged(ChangeEvent changeEvent) { JTabbedPane sourceTabbedPane = (JTabbedPane) changeEvent .getSource(); int index = sourceTabbedPane.getSelectedIndex(); + btn_view.setVisible(true); + btn_cancel.setVisible(true); if (sourceTabbedPane.getTitleAt(index).equals(configureCols)) { btn_view.setEnabled(false); btn_cancel.setEnabled(false); - previousWantedFields = PDBDocFieldPreferences + btn_view.setVisible(false); + btn_cancel.setVisible(false); + previousWantedFields = pdbDocFieldPrefs .getStructureSummaryFields().toArray( - new PDBRestClient.PDBDocField[0]); + new FTSDataColumnI[0]); } if (sourceTabbedPane.getTitleAt(index) .equals(foundStructureSummary)) @@ -469,7 +567,7 @@ public abstract class GStructureChooser extends JPanel implements } }; pnl_filter.addChangeListener(changeListener); - pnl_filter.setPreferredSize(new Dimension(500, 300)); + pnl_filter.setPreferredSize(new Dimension(width, height)); pnl_filter.add(foundStructureSummary, scrl_foundStructures); pnl_filter.add(configureCols, pdbDocFieldPrefs); @@ -483,12 +581,46 @@ public abstract class GStructureChooser extends JPanel implements this.setLayout(mainLayout); this.add(pnl_main, java.awt.BorderLayout.NORTH); this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER); - this.add(pnl_actions, java.awt.BorderLayout.SOUTH); - + // this.add(pnl_actions, java.awt.BorderLayout.SOUTH); + statusPanel.setLayout(new GridLayout()); + pnl_actionsAndStatus.add(pnl_actions, BorderLayout.CENTER); + pnl_actionsAndStatus.add(statusPanel, BorderLayout.SOUTH); + statusPanel.add(statusBar, null); + this.add(pnl_actionsAndStatus, java.awt.BorderLayout.SOUTH); + + mainFrame + .addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() + { + @Override + public void internalFrameClosing(InternalFrameEvent e) + { + closeAction(pnl_filter.getHeight()); + } + }); mainFrame.setVisible(true); mainFrame.setContentPane(this); mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400); + Integer x = tempUserPrefs.get("structureChooser.x"); + Integer y = tempUserPrefs.get("structureChooser.y"); + if (x != null && y != null) + { + mainFrame.setLocation(x, y); + } + Desktop.addInternalFrame(mainFrame, frameTitle, width, height); + } + + protected void closeAction(int preferredHeight) + { + // System.out.println(">>>>>>>>>> closing internal frame!!!"); + // System.out.println("width : " + mainFrame.getWidth()); + // System.out.println("heigh : " + mainFrame.getHeight()); + // System.out.println("x : " + mainFrame.getX()); + // System.out.println("y : " + mainFrame.getY()); + tempUserPrefs.put("structureChooser.width", pnl_filter.getWidth()); + tempUserPrefs.put("structureChooser.height", preferredHeight); + tempUserPrefs.put("structureChooser.x", mainFrame.getX()); + tempUserPrefs.put("structureChooser.y", mainFrame.getY()); + mainFrame.dispose(); } public boolean wantedFieldsUpdated() @@ -498,9 +630,10 @@ public abstract class GStructureChooser extends JPanel implements return true; } - return Arrays.equals(PDBDocFieldPreferences.getStructureSummaryFields() - .toArray(new PDBRestClient.PDBDocField[0]), - previousWantedFields) ? false : true; + FTSDataColumnI[] currentWantedFields = pdbDocFieldPrefs + .getStructureSummaryFields().toArray(new FTSDataColumnI[0]); + return Arrays.equals(currentWantedFields, previousWantedFields) ? false + : true; } @@ -527,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() @@ -564,10 +714,21 @@ public abstract class GStructureChooser extends JPanel implements this.view = view; } + @Override public String toString() { return this.name; } + + public boolean isAddSeparatorAfter() + { + return addSeparatorAfter; + } + + public void setAddSeparatorAfter(boolean addSeparatorAfter) + { + this.addSeparatorAfter = addSeparatorAfter; + } } /** @@ -596,6 +757,7 @@ public abstract class GStructureChooser extends JPanel implements this.sequence = seq; } + @Override public String toString() { return name; @@ -672,16 +834,65 @@ public abstract class GStructureChooser extends JPanel implements } } + public JTable getResultTable() + { + return tbl_summary; + } + public JComboBox getCmbFilterOption() { return cmb_filterOption; } - protected abstract void stateChanged(ItemEvent e); + /** + * 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()); - protected abstract void updateCurrentView(); + private JSeparator jSeparator = new JSeparator(); - protected abstract void populateFilterComboBox(); + 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(); @@ -697,4 +908,4 @@ public abstract class GStructureChooser extends JPanel implements public abstract void tabRefresh(); public abstract void validateSelections(); -} +} \ No newline at end of file