X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFeatureEditor.java;h=844eee4f74c3ccddb2325ed6e6a8bd4e9d1e739d;hb=23deaf6a1371e81b2e6547d5df697bf60e442e84;hp=60f26e62cf9c63f6c130d2665bfe33c6625cd3e7;hpb=c8441b851dcd36fbbc1c6bc64e16a64bda1f8359;p=jalview.git diff --git a/src/jalview/gui/FeatureEditor.java b/src/jalview/gui/FeatureEditor.java index 60f26e6..844eee4 100644 --- a/src/jalview/gui/FeatureEditor.java +++ b/src/jalview/gui/FeatureEditor.java @@ -1,17 +1,25 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ 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.gui; -import jalview.api.FeatureColourI; -import jalview.datamodel.SearchResults; -import jalview.datamodel.SearchResultsI; -import jalview.datamodel.SequenceFeature; -import jalview.datamodel.SequenceI; -import jalview.gui.JalviewColourChooser.ColourChooserListener; -import jalview.io.FeaturesFile; -import jalview.schemes.FeatureColour; -import jalview.util.ColorUtils; -import jalview.util.MessageManager; -import jalview.util.dialogrunner.RunResponse; - import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -33,10 +41,24 @@ import javax.swing.JScrollPane; import javax.swing.JSpinner; import javax.swing.JTextArea; import javax.swing.JTextField; +import javax.swing.SpinnerNumberModel; import javax.swing.SwingConstants; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import jalview.api.FeatureColourI; +import jalview.datamodel.SearchResults; +import jalview.datamodel.SearchResultsI; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceI; +import jalview.gui.JalviewColourChooser.ColourChooserListener; +import jalview.io.FeaturesFile; +import jalview.schemes.FeatureColour; +import jalview.util.ColorUtils; +import jalview.util.MessageManager; + /** * Provides a dialog allowing the user to add new features, or amend or delete * existing features @@ -168,10 +190,34 @@ public class FeatureEditor }); description = new JTextArea(3, 25); + start = new JSpinner(); end = new JSpinner(); start.setPreferredSize(new Dimension(80, 20)); end.setPreferredSize(new Dimension(80, 20)); + + /* + * ensure that start can never be more than end + */ + start.addChangeListener(new ChangeListener() + { + @Override + public void stateChanged(ChangeEvent e) + { + Integer startVal = (Integer) start.getValue(); + ((SpinnerNumberModel) end.getModel()).setMinimum(startVal); + } + }); + end.addChangeListener(new ChangeListener() + { + @Override + public void stateChanged(ChangeEvent e) + { + Integer endVal = (Integer) end.getValue(); + ((SpinnerNumberModel) start.getModel()).setMaximum(endVal); + } + }); + final JLabel colour = new JLabel(); colour.setOpaque(true); colour.setMaximumSize(new Dimension(30, 16)); @@ -266,6 +312,8 @@ public class FeatureEditor group.setText(sf.getFeatureGroup()); start.setValue(new Integer(sf.getBegin())); end.setValue(new Integer(sf.getEnd())); + ((SpinnerNumberModel) start.getModel()).setMaximum(sf.getEnd()); + ((SpinnerNumberModel) end.getModel()).setMinimum(sf.getBegin()); SearchResultsI highlight = new SearchResults(); highlight.addResult(sequences.get(0), sf.getBegin(), @@ -353,6 +401,11 @@ public class FeatureEditor start.setValue(new Integer(firstFeature.getBegin())); end.setValue(new Integer(firstFeature.getEnd())); + ((SpinnerNumberModel) start.getModel()) + .setMaximum(firstFeature.getEnd()); + ((SpinnerNumberModel) end.getModel()) + .setMinimum(firstFeature.getBegin()); + description.setText(firstFeature.getDescription()); featureColour = fr.getFeatureStyle(featureType); oldColour = featureColour; @@ -374,18 +427,19 @@ public class FeatureEditor */ public void showDialog() { - RunResponse okAction = forCreate ? getCreateAction() : getAmendAction(); - RunResponse cancelAction = getCancelAction(); + Runnable okAction = forCreate ? getCreateAction() : getAmendAction(); + Runnable cancelAction = getCancelAction(); /* * set dialog action handlers for OK (create/Amend) and Cancel options * also for Delete if applicable (when amending features) */ - JvOptionPane dialog = JvOptionPane.newOptionDialog(Desktop.desktop) - .response(okAction).response(cancelAction); + JvOptionPane dialog = JvOptionPane.newOptionDialog(ap.alignFrame) + .setResponseHandler(0, okAction) + .setResponseHandler(2, cancelAction); if (!forCreate) { - dialog.response(getDeleteAction()); + dialog.setResponseHandler(1, getDeleteAction()); } String title = null; @@ -408,9 +462,8 @@ public class FeatureEditor } dialog.showInternalDialog(mainPanel, title, - JvOptionPane.YES_NO_CANCEL_OPTION, - JvOptionPane.QUESTION_MESSAGE, null, options, - MessageManager.getString("action.ok")); + JvOptionPane.YES_NO_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE, + null, options, MessageManager.getString("action.ok")); } /** @@ -421,9 +474,9 @@ public class FeatureEditor * * @return */ - protected RunResponse getCancelAction() + protected Runnable getCancelAction() { - RunResponse okAction = new RunResponse(JvOptionPane.CANCEL_OPTION) + Runnable okAction = new Runnable() { @Override public void run() @@ -445,12 +498,13 @@ public class FeatureEditor * * @return */ - protected RunResponse getCreateAction() + protected Runnable getCreateAction() { - RunResponse okAction = new RunResponse(JvOptionPane.OK_OPTION) + Runnable okAction = new Runnable() { boolean useLastDefaults = features.get(0).getType() == null; + @Override public void run() { final String enteredType = name.getText().trim(); @@ -503,10 +557,11 @@ public class FeatureEditor * * @return */ - protected RunResponse getDeleteAction() + protected Runnable getDeleteAction() { - RunResponse deleteAction = new RunResponse(JvOptionPane.NO_OPTION) + Runnable deleteAction = new Runnable() { + @Override public void run() { SequenceFeature sf = features.get(featureIndex); @@ -605,16 +660,17 @@ public class FeatureEditor * * @return */ - protected RunResponse getAmendAction() + protected Runnable getAmendAction() { - RunResponse okAction = new RunResponse(JvOptionPane.OK_OPTION) + Runnable okAction = new Runnable() { boolean useLastDefaults = features.get(0).getType() == null; - + String featureType = name.getText(); - + String featureGroup = group.getText(); - + + @Override public void run() { final String enteredType = name.getText().trim();