- if (alignPanel.getSeqPanel() != null
- && alignPanel.getSeqPanel().seqCanvas != null
- && alignPanel.getSeqPanel().seqCanvas.fr != null)
- {
- transferSettings(alignPanel.getSeqPanel().seqCanvas.fr);
- }
- }
-
- // // /////////////
- // // Feature Editing Dialog
- // // Will be refactored in next release.
-
- static String lastFeatureAdded;
-
- static String lastFeatureGroupAdded;
-
- static String lastDescriptionAdded;
-
- FeatureColourI oldcol, fcol;
-
- int featureIndex = 0;
-
- /**
- * Presents a dialog allowing the user to add new features, or amend or delete
- * existing features. Currently this can be on
- * <ul>
- * <li>double-click on a sequence - Amend/Delete features at position</li>
- * <li>Create sequence feature from pop-up menu on selected region</li>
- * <li>Create features for pattern matches from Find</li>
- * </ul>
- *
- * @param sequences
- * the sequences features are to be created on (if creating
- * features), or a single sequence (if amending features)
- * @param features
- * the current features at the position (if amending), or template
- * new features with start/end position set (if creating)
- * @param create
- * true to create features, false to amend or delete
- * @param featureType
- * the feature type to set on new features; if null, defaults to the
- * type of the last new feature created if any, failing that to
- * "feature_1"
- * @param alignPanel
- * @return
- */
- protected boolean amendFeatures(final List<SequenceI> sequences,
- final List<SequenceFeature> features, boolean create,
- final AlignmentPanel alignPanel, String featureType)
- {
-
- featureIndex = 0;
-
- final JPanel mainPanel = new JPanel(new BorderLayout());
- final JTextField name = new JTextField(25);
- final JTextField source = new JTextField(25);
- final JTextArea description = new JTextArea(3, 25);
- final JSpinner start = new JSpinner();
- final JSpinner end = new JSpinner();
- start.setPreferredSize(new Dimension(80, 20));
- end.setPreferredSize(new Dimension(80, 20));
- final FeatureRenderer me = this;
- final JLabel colour = new JLabel();
- colour.setOpaque(true);
- // colour.setBorder(BorderFactory.createEtchedBorder());
- colour.setMaximumSize(new Dimension(30, 16));
- colour.addMouseListener(new MouseAdapter()
- {
- FeatureColourChooser fcc = null;
-
- @Override
- public void mousePressed(MouseEvent evt)
- {
- if (fcol.isSimpleColour())
- {
- Color col = JColorChooser.showDialog(Desktop.desktop,
- MessageManager.getString("label.select_feature_colour"),
- fcol.getColour());
- if (col != null)
- {
- fcol = new FeatureColour(col);
- updateColourButton(mainPanel, colour, new FeatureColour(col));
- }
- }
- else
- {
- if (fcc == null)
- {
- final String type = features.get(featureIndex).getType();
- fcc = new FeatureColourChooser(me, type);
- fcc.setRequestFocusEnabled(true);
- fcc.requestFocus();
-
- fcc.addActionListener(new ActionListener()
- {
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- fcol = fcc.getLastColour();
- fcc = null;
- setColour(type, fcol);
- updateColourButton(mainPanel, colour, fcol);
- }
- });
-
- }
- }
- }
- });
- JPanel gridPanel = new JPanel(new GridLayout(3, 1));
-
- if (!create && features.size() > 1)
- {
- /*
- * more than one feature at selected position - add a drop-down
- * to choose the feature to amend
- */
- gridPanel = new JPanel(new GridLayout(4, 1));
- JPanel choosePanel = new JPanel();
- choosePanel.add(new JLabel(MessageManager
- .getString("label.select_feature")
- + ":"));
- final JComboBox<String> overlaps = new JComboBox<String>();
- for (SequenceFeature sf : features)
- {
- String text = sf.getType() + "/" + sf.getBegin() + "-"
- + sf.getEnd() + " (" + sf.getFeatureGroup() + ")";
- overlaps.addItem(text);
- }
- choosePanel.add(overlaps);
-
- overlaps.addItemListener(new ItemListener()
- {
- @Override
- public void itemStateChanged(ItemEvent e)
- {
- int index = overlaps.getSelectedIndex();
- if (index != -1)
- {
- featureIndex = index;
- SequenceFeature sf = features.get(index);
- name.setText(sf.getType());
- description.setText(sf.getDescription());
- source.setText(sf.getFeatureGroup());
- start.setValue(new Integer(sf.getBegin()));
- end.setValue(new Integer(sf.getEnd()));
-
- SearchResultsI highlight = new SearchResults();
- highlight.addResult(sequences.get(0), sf.getBegin(),
- sf.getEnd());
-
- alignPanel.getSeqPanel().seqCanvas.highlightSearchResults(highlight);
-
- }
- FeatureColourI col = getFeatureStyle(name.getText());
- if (col == null)
- {
- col = new FeatureColour(ColorUtils
- .createColourFromName(name.getText()));
- }
- oldcol = fcol = col;
- updateColourButton(mainPanel, colour, col);
- }
- });
-
- gridPanel.add(choosePanel);
- }
- // ////////
- // ////////////////////////////////////
-
- JPanel namePanel = new JPanel();
- gridPanel.add(namePanel);
- namePanel.add(new JLabel(MessageManager.getString("label.name:"),
- JLabel.RIGHT));
- namePanel.add(name);
-
- JPanel groupPanel = new JPanel();
- gridPanel.add(groupPanel);
- groupPanel.add(new JLabel(MessageManager.getString("label.group:"),
- JLabel.RIGHT));
- groupPanel.add(source);
-
- JPanel colourPanel = new JPanel();
- gridPanel.add(colourPanel);
- colourPanel.add(new JLabel(MessageManager.getString("label.colour"),
- JLabel.RIGHT));
- colourPanel.add(colour);
- colour.setPreferredSize(new Dimension(150, 15));
- colour.setFont(new java.awt.Font("Verdana", Font.PLAIN, 9));
- colour.setForeground(Color.black);
- colour.setHorizontalAlignment(SwingConstants.CENTER);
- colour.setVerticalAlignment(SwingConstants.CENTER);
- colour.setHorizontalTextPosition(SwingConstants.CENTER);
- colour.setVerticalTextPosition(SwingConstants.CENTER);
- mainPanel.add(gridPanel, BorderLayout.NORTH);
-
- JPanel descriptionPanel = new JPanel();
- descriptionPanel.add(new JLabel(MessageManager
- .getString("label.description:"),
- JLabel.RIGHT));
- description.setFont(JvSwingUtils.getTextAreaFont());
- description.setLineWrap(true);
- descriptionPanel.add(new JScrollPane(description));
-
- if (!create)
- {
- mainPanel.add(descriptionPanel, BorderLayout.SOUTH);
-
- JPanel startEndPanel = new JPanel();
- startEndPanel.add(new JLabel(MessageManager.getString("label.start"),
- JLabel.RIGHT));
- startEndPanel.add(start);
- startEndPanel.add(new JLabel(MessageManager.getString("label.end"),
- JLabel.RIGHT));
- startEndPanel.add(end);
- mainPanel.add(startEndPanel, BorderLayout.CENTER);
- }
- else
- {
- mainPanel.add(descriptionPanel, BorderLayout.CENTER);
- }
-
- SequenceFeature firstFeature = features.get(0);
- if (featureType != null)
- {
- lastFeatureAdded = featureType;
- }
- else
- {
- if (lastFeatureAdded == null)
- {
- if (firstFeature.type != null)
- {
- lastFeatureAdded = firstFeature.type;
- }
- else
- {
- lastFeatureAdded = "feature_1";
- }
- }
- }
-
- if (lastFeatureGroupAdded == null)