001/* 002 * Copyright 2010-2015 Institut Pasteur. 003 * 004 * This file is part of Icy. 005 * 006 * Icy is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Icy is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Icy. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package icy.gui.component.sequence; 020 021import icy.common.listener.AcceptListener; 022import icy.gui.component.sequence.SequenceChooser.SequenceChooserListener; 023import icy.sequence.Sequence; 024import icy.util.StringUtil; 025 026import java.awt.BorderLayout; 027import java.util.ArrayList; 028 029import javax.swing.JLabel; 030import javax.swing.JPanel; 031import javax.swing.border.EmptyBorder; 032 033public class SequenceChooserPanel extends JPanel 034{ 035 /** 036 * 037 */ 038 private static final long serialVersionUID = 486511549781132187L; 039 040 protected JLabel titleLabel; 041 protected SequenceChooser sequenceChooser; 042 043 /** 044 * Create the panel. 045 */ 046 public SequenceChooserPanel(String title) 047 { 048 super(); 049 050 initialize(title); 051 } 052 053 private void initialize(String title) 054 { 055 setLayout(new BorderLayout(0, 0)); 056 057 sequenceChooser = new SequenceChooser(); 058 add(sequenceChooser, BorderLayout.CENTER); 059 060 if (!StringUtil.isEmpty(title)) 061 { 062 titleLabel = new JLabel(title); 063 titleLabel.setBorder(new EmptyBorder(4, 0, 0, 8)); 064 add(titleLabel, BorderLayout.WEST); 065 } 066 } 067 068 /** 069 * @return the filter 070 */ 071 public AcceptListener getFilter() 072 { 073 return sequenceChooser.getFilter(); 074 } 075 076 /** 077 * @param filter 078 * the filter to set 079 */ 080 public void setFilter(AcceptListener filter) 081 { 082 sequenceChooser.setFilter(filter); 083 } 084 085 /** 086 * @return current sequence selected in combo. null if no sequence is selected or if the 087 * sequence do not exists anymore. 088 */ 089 public Sequence getSelectedSequence() 090 { 091 return sequenceChooser.getSelectedSequence(); 092 } 093 094 /** 095 * @param sequence 096 * The sequence to select in the combo box 097 */ 098 public void setSelectedSequence(Sequence sequence) 099 { 100 sequenceChooser.setSelectedSequence(sequence); 101 } 102 103 public ArrayList<SequenceChooserListener> getListeners() 104 { 105 return sequenceChooser.getListeners(); 106 } 107 108 public void addListener(SequenceChooserListener listener) 109 { 110 sequenceChooser.addListener(listener); 111 } 112 113 public void removeListener(SequenceChooserListener listener) 114 { 115 sequenceChooser.removeListener(listener); 116 } 117 118}