/* * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2) * Copyright (C) 2014 The Jalview Authors * * This file is part of Jalview. * * Jalview 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 3 * of the License, or (at your option) any later version. * * Jalview 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 Jalview. If not, see . * The Jalview Authors are detailed in the 'AUTHORS' file. */ package jalview.jbgui; import jalview.gui.AlignmentPanel; import jalview.gui.Desktop; import jalview.util.MessageManager; import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; 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.JTable; import javax.swing.JTextField; import javax.swing.ListSelectionModel; @SuppressWarnings("serial") /** * GUI layout for structure chooser * @author tcnofoegbu * */ public abstract class GStructureChooser extends JPanel implements ItemListener { protected String frameTitle = MessageManager .getString("label.structure_chooser"); protected JInternalFrame mainFrame = new JInternalFrame(frameTitle); protected JComboBox cmb_filterOption = new JComboBox(); protected AlignmentPanel ap; protected JLabel lbl_result = new JLabel( MessageManager.getString("label.select") /* "Select : " */); protected JButton btn_ok = new JButton(); protected JButton btn_cancel = new JButton(); protected JButton btn_pdbFromFile = new JButton(); protected JTextField txt_search = new JTextField(18); private JPanel pnl_actions = new JPanel(); private JPanel pnl_filter = new JPanel(); private JPanel pnl_idInput = new JPanel(); private JPanel pnl_fileChooser = new JPanel(); protected JPanel pnl_switchableViews = new JPanel(new CardLayout()); protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews .getLayout()); private BorderLayout mainLayout = new BorderLayout(); protected JCheckBox chk_rememberSettings = new JCheckBox( MessageManager.getString("label.dont_ask_me_again")); protected JCheckBox chk_invertFilter = new JCheckBox( MessageManager.getString("label.invert")); protected ImageIcon loadingImage = new ImageIcon(getClass().getResource( "/images/loading.gif")); protected JLabel lbl_loading = new JLabel(loadingImage); protected static final String VIEWS_FILTER = "VIEWS_FILTER"; protected static final String VIEWS_FROM_FILE = "VIEWS_FROM_FILE"; protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID"; protected JList jList_FoundStructures = new JList(); protected JTable tbl_summary = new JTable(); protected JScrollPane scrl_foundStructures = new JScrollPane( tbl_summary); public GStructureChooser() { try { jbInit(); mainFrame.setVisible(false); mainFrame.invalidate(); mainFrame.pack(); } catch (Exception e) { e.printStackTrace(); } } /** * Initializes the GUI default properties * * @throws Exception */ private void jbInit() throws Exception { btn_ok.setFont(new java.awt.Font("Verdana", 0, 12)); btn_ok.setText(MessageManager.getString("action.view")); btn_ok.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { ok_ActionPerformed(); } }); btn_cancel.setFont(new java.awt.Font("Verdana", 0, 12)); btn_cancel.setText(MessageManager.getString("action.cancel")); btn_cancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { mainFrame.dispose(); } }); btn_pdbFromFile.setFont(new java.awt.Font("Verdana", 0, 12)); String btn_title = MessageManager.getString("label.select_pdb_file"); btn_pdbFromFile.setText(" " + btn_title + " "); btn_pdbFromFile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { pdbFromFile_actionPerformed(); } }); jList_FoundStructures .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); jList_FoundStructures.setLayoutOrientation(JList.VERTICAL); jList_FoundStructures.setVisibleRowCount(-1); scrl_foundStructures.setPreferredSize(new Dimension(500, 300)); scrl_foundStructures .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); cmb_filterOption.setFont(new java.awt.Font("Verdana", 0, 12)); chk_invertFilter.setFont(new java.awt.Font("Verdana", 0, 12)); chk_rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12)); cmb_filterOption.addItemListener(this); chk_invertFilter.addItemListener(this); pnl_actions.add(chk_rememberSettings); pnl_actions.add(btn_ok); pnl_actions.add(btn_cancel); pnl_filter.add(lbl_result); pnl_filter.add(cmb_filterOption); lbl_loading.setVisible(false); pnl_filter.add(lbl_loading); pnl_filter.add(chk_invertFilter); pnl_idInput.setLayout(new FlowLayout()); pnl_idInput.add(txt_search); pnl_fileChooser.setLayout(new FlowLayout()); pnl_fileChooser.add(btn_pdbFromFile); pnl_switchableViews.add(pnl_fileChooser, VIEWS_FROM_FILE); pnl_switchableViews.add(pnl_idInput, VIEWS_ENTER_ID); pnl_switchableViews.add(scrl_foundStructures, VIEWS_FILTER); this.setLayout(mainLayout); this.add(pnl_filter, java.awt.BorderLayout.NORTH); this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER); this.add(pnl_actions, java.awt.BorderLayout.SOUTH); mainFrame.setVisible(true); mainFrame.setContentPane(this); mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400); } @Override /** * Event listener for the 'filter' combo-box and 'invert' check-box */ public void itemStateChanged(ItemEvent e) { stateChanged(e); } /** * This inner class provides the data model for the structure filter combo-box * * @author tcnofoegbu * */ public class FilterOption { private String name; private String value; private String view; public FilterOption(String name, String value, String view) { this.name = name; this.value = value; this.view = view; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } public String getView() { return view; } public void setView(String view) { this.view = view; } public String toString() { return this.name; } } public JComboBox getCmbFilterOption() { return cmb_filterOption; } protected abstract void stateChanged(ItemEvent e); protected abstract void updateCurrentView(); protected abstract void ok_ActionPerformed(); protected abstract void populateFilterComboBox(); protected abstract void pdbFromFile_actionPerformed(); }