/* * * This file is part of Artemis * * Copyright(C) 2008 Genome Research Limited * * This program 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 2 * of the License, or(at your option) any later version. * * This program 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 this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ package uk.ac.sanger.artemis.components; import java.awt.BorderLayout; import java.awt.Cursor; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.Box; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JTabbedPane; import javax.swing.JTextField; import javax.swing.SwingConstants; import uk.ac.sanger.artemis.Entry; import uk.ac.sanger.artemis.EntryGroup; import uk.ac.sanger.artemis.EntryGroupChangeEvent; import uk.ac.sanger.artemis.EntryGroupChangeListener; import uk.ac.sanger.artemis.Feature; import uk.ac.sanger.artemis.FeatureKeyQualifierPredicate; import uk.ac.sanger.artemis.FeaturePredicate; import uk.ac.sanger.artemis.FeaturePredicateConjunction; import uk.ac.sanger.artemis.FeaturePredicateVector; import uk.ac.sanger.artemis.FeatureVector; import uk.ac.sanger.artemis.FilteredEntryGroup; import uk.ac.sanger.artemis.GotoEventSource; import uk.ac.sanger.artemis.Selection; import uk.ac.sanger.artemis.io.EntryInformation; import uk.ac.sanger.artemis.io.EntryInformationException; import uk.ac.sanger.artemis.io.GFFDocumentEntry; import uk.ac.sanger.artemis.io.Key; import uk.ac.sanger.artemis.io.Qualifier; import uk.ac.sanger.artemis.io.QualifierVector; import uk.ac.sanger.artemis.util.ReadOnlyException; import uk.ac.sanger.artemis.util.StringVector; public class FindAndReplace extends JFrame implements EntryGroupChangeListener { private static final long serialVersionUID = 1L; private EntryGroup entry_group; /** * Find, replace and delete qualifiers * @param selection * @param goto_event_source * @param entry_group * @param base_plot_group */ public FindAndReplace(final Selection selection, final GotoEventSource goto_event_source, final EntryGroup entry_group, final BasePlotGroup base_plot_group) { super("Search"); this.entry_group = entry_group; final JTabbedPane tabPane = new JTabbedPane(); getContentPane().add(tabPane, BorderLayout.CENTER); addFindReplaceTab(selection, goto_event_source, base_plot_group, tabPane); addFindDeleteDuplicateTab(selection, goto_event_source, entry_group, base_plot_group, tabPane); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { entry_group.removeEntryGroupChangeListener(FindAndReplace.this); FindAndReplace.this.dispose(); } }); final Box xbox = Box.createHorizontalBox(); final JButton closeButton = new JButton("Close"); closeButton.setHorizontalAlignment(SwingConstants.LEFT); closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { entry_group.removeEntryGroupChangeListener(FindAndReplace.this); FindAndReplace.this.dispose(); } }); xbox.add(closeButton); xbox.add(Box.createHorizontalGlue()); getContentPane().add(xbox, BorderLayout.SOUTH); pack(); Utilities.centreFrame(this); setVisible(true); } /** * Find and replace option for qualifier text * @param selection * @param goto_event_source * @param base_plot_group * @param tabPane */ private void addFindReplaceTab(final Selection selection, final GotoEventSource goto_event_source, final BasePlotGroup base_plot_group, final JTabbedPane tabPane) { GridBagLayout gridbag = new GridBagLayout(); final JPanel panel = new JPanel(gridbag); tabPane.addTab("Qualifier Text", panel); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.WEST; c.ipadx = 5; c.ipady = 5; /*final FeatureVector features = entry_group.getAllFeatures (); for(int i=0; i0) ? "Duplicate qualifiers in "+ncount+" feature(s) deleted." : "No duplicate qualifiers found."), "Duplicate Qualifiers", JOptionPane.INFORMATION_MESSAGE); } }); c.gridx = 1; panel.add(deleteButton, c); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent event) { entry_group.removeEntryGroupChangeListener(FindAndReplace.this); FindAndReplace.this.dispose(); } }); } /** * Implementation of the EntryGroupChangeListener interface. We listen to * EntryGroupChange events so that we can get rid of the FinAndReplace when the * EntryGroup is no longer in use(for example when the EntryEdit is * closed). **/ public void entryGroupChanged(EntryGroupChangeEvent event) { switch(event.getType()) { case EntryGroupChangeEvent.DONE_GONE: entry_group.removeEntryGroupChangeListener(this); dispose(); break; } } /** * Construct a FeaturePredicate from a string with conditional (& / |). * @param text * @param key * @param qualifierName * @param isSubString * @param isCaseInsensitive * @return */ private FeaturePredicate constructFeaturePredicateFromBooleanList( String text, final Key key, final String qualifierName, final boolean isSubString, final boolean isCaseInsensitive, final boolean deleteQualifier) { text = text.replaceAll(" && ", " & "); text = text.replaceAll(" (a|A)(n|N)(d|D) ", " & "); text = text.replaceAll(" \\|\\| ", " \\| "); text = text.replaceAll(" (o|O)(r|R) ", " \\| "); final String valuesAnd[] = text.split("&"); final FeaturePredicateVector andPredicates = new FeaturePredicateVector(); final FeaturePredicateVector orPredicates = new FeaturePredicateVector(); // process string for(int i=0; i-1) { String valuesOr[] = valuesAnd[i].trim().split("\\|"); for(int j=0; j