import jalview.gui.Help.HelpId;
import jalview.io.JalviewFileChooser;
import jalview.io.JalviewFileView;
+ import jalview.io.gff.SequenceOntologyFactory;
-import jalview.schemabinding.version2.Filter;
-import jalview.schemabinding.version2.JalviewUserColours;
-import jalview.schemabinding.version2.MatcherSet;
import jalview.schemes.FeatureColour;
import jalview.util.MessageManager;
import jalview.util.Platform;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
+ import javax.swing.table.TableRowSorter;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Marshaller;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
public class FeatureSettings extends JPanel
implements FeatureSettingsControllerI
});
men.add(dens);
++ // fixme is Variable Colour in popup menu or not
+ /*
+ * variable colour options include colour by label, by score,
+ * by selected attribute text, or attribute value
+ */
+ final JCheckBoxMenuItem mxcol = new JCheckBoxMenuItem(
+ MessageManager.getString("label.variable_colour"));
+ mxcol.setSelected(!featureColour.isSimpleColour());
+ men.add(mxcol);
+ mxcol.addActionListener(new ActionListener()
+ {
+ JColorChooser colorChooser;
+
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ if (e.getSource() == mxcol)
+ {
+ if (featureColour.isSimpleColour())
+ {
+ FeatureTypeSettings fc = new FeatureTypeSettings(me.fr, type);
+ fc.addActionListener(this);
+ }
+ else
+ {
+ // bring up simple color chooser
+ colorChooser = new JColorChooser();
+ String title = MessageManager
+ .getString("label.select_colour");
+ JDialog dialog = JColorChooser.createDialog(me,
+ title, true, // modal
+ colorChooser, this, // OK button handler
+ null); // no CANCEL button handler
+ colorChooser.setColor(featureColour.getMaxColour());
+ dialog.setVisible(true);
+ }
+ }
+ else
+ {
+ if (e.getSource() instanceof FeatureTypeSettings)
+ {
+ /*
+ * update after OK in feature colour dialog; the updated
+ * colour will have already been set in the FeatureRenderer
+ */
+ FeatureColourI fci = fr.getFeatureColours().get(type);
+ table.setValueAt(fci, rowSelected, 1);
+ table.validate();
+ }
+ else
+ {
+ // probably the color chooser!
+ table.setValueAt(new FeatureColour(colorChooser.getColor()),
+ rowSelected, 1);
+ table.validate();
+ me.updateFeatureRenderer(
+ ((FeatureTableModel) table.getModel()).getData(),
+ false);
+ }
+ }
+ }
+ });
+
JMenuItem selCols = new JMenuItem(
MessageManager.getString("label.select_columns_containing"));
selCols.addActionListener(new ActionListener()
transparency.setToolTipText(
MessageManager.getString("label.transparency_tip"));
+ boolean nucleotide = af.getViewport().getAlignment().isNucleotide();
+ showComplement = new JCheckBox(
+ "Show " + (nucleotide ? "protein" : "CDS") + " features");
+ showComplement.setSelected(af.getViewport().isShowComplementFeatures());
+ showComplement.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ af.getViewport()
+ .setShowComplementFeatures(showComplement.isSelected());
+ refreshDisplay();
+ }
+ });
+
- JPanel transPanel = new JPanel(new GridLayout(1, 2));
- bigPanel.add(transPanel, BorderLayout.SOUTH);
+ JPanel lowerPanel = new JPanel(new GridLayout(1, 2));
+ bigPanel.add(lowerPanel, BorderLayout.SOUTH);
JPanel transbuttons = new JPanel(new GridLayout(5, 1));
transbuttons.add(optimizeOrder);
transbuttons.add(sortByScore);
transbuttons.add(sortByDens);
transbuttons.add(help);
- JPanel transPanel = new JPanel(new GridLayout(3, 1));
- transPanel.add(summaryView);
- transPanel.add(new JLabel(" Colour transparency" + ":"));
- transPanel.add(transparency);
- lowerPanel.add(transPanel);
+
+ boolean hasComplement = af.getViewport().getCodingComplement() != null;
+ JPanel transPanelLeft = new JPanel(
- new GridLayout(hasComplement ? 2 : 1, 1));
++ new GridLayout(hasComplement ? 4 : 3, 1));
++ transPanelLeft.add(summaryView);
++ transPanelLeft.add(new JLabel(" Colour transparency" + ":"));
+ transPanelLeft.add(transparency);
+ if (hasComplement)
+ {
+ transPanelLeft.add(showComplement);
+ }
- transPanel.add(transPanelLeft);
- transPanel.add(transbuttons);
++ lowerPanel.add(transPanelLeft);
+ lowerPanel.add(transbuttons);
JPanel buttonPanel = new JPanel();
buttonPanel.add(ok);
}
/**
+ * Repaints alignment, structure and overview (if shown). If there is a
+ * complementary view which is showing this view's features, then also
+ * repaints that.
+ */
+ void refreshDisplay()
+ {
+ af.alignPanel.paintAlignment(true, true);
+ AlignViewportI complement = af.getViewport().getCodingComplement();
+ if (complement != null && complement.isShowComplementFeatures())
+ {
+ AlignFrame af2 = Desktop.getAlignFrameFor(complement);
+ af2.alignPanel.paintAlignment(true, true);
+ }
+ }
+
++ /**
+ * Reorders features by 'dragging' selectedRow to 'newRow'
+ *
+ * @param newRow
+ */
+ protected void dragRow(int newRow)
+ {
+ if (summaryView.isSelected())
+ {
+ // no drag while in summary view
+ return;
+ }
+
+ if (newRow != selectedRow && selectedRow != -1 && newRow != -1)
+ {
+ /*
+ * reposition 'selectedRow' to 'newRow' (the dragged to location)
+ * this could be more than one row away for a very fast drag action
+ * so just swap it with adjacent rows until we get it there
+ */
+ Object[][] data = ((FeatureTableModel) table.getModel())
+ .getData();
+ int direction = newRow < selectedRow ? -1 : 1;
+ for (int i = selectedRow; i != newRow; i += direction)
+ {
+ Object[] temp = data[i];
+ data[i] = data[i + direction];
+ data[i + direction] = temp;
+ }
+ updateFeatureRenderer(data);
+ table.repaint();
+ selectedRow = newRow;
+ }
+ }
+
+ protected void refreshTable()
+ {
+ Object[][] data = ((FeatureTableModel) table.getModel()).getData();
+ for (Object[] row : data)
+ {
+ String type = (String) row[TYPE_COLUMN];
+ FeatureColourI colour = fr.getFeatureColours().get(type);
+ FeatureMatcherSetI filter = fr.getFeatureFilter(type);
+ if (filter == null)
+ {
+ filter = new FeatureMatcherSet();
+ }
+ row[COLOUR_COLUMN] = colour;
+ row[FILTER_COLUMN] = filter;
+ }
+ repaint();
+ }
+
// ///////////////////////////////////////////////////////////////////////
// http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
// ///////////////////////////////////////////////////////////////////////
FeatureColourI acg = makeColourFromInputs();
/*
- * save the colour, and repaint stuff
+ * save the colour, and set on subtypes if selected
*/
fr.setColour(featureType, acg);
+ if (applyColourToSubtypes)
+ {
+ for (String child : subTypes)
+ {
+ fr.setColour(child, acg);
+ }
+ }
+ refreshFeatureSettings();
- ap.paintAlignment(updateStructsAndOverview, updateStructsAndOverview);
+ refreshDisplay(updateStructsAndOverview);
updateColoursTab();
}
@Override
public void cancelPressed()
{
- fr.setColour(featureType, originalColour);
- fr.setFeatureFilter(featureType, originalFilter);
+ restoreOriginalColours();
+ restoreOriginalFilters();
- ap.paintAlignment(true, true);
+ refreshDisplay(true);
}
+ protected void restoreOriginalFilters()
+ {
+ for (Entry<String, FeatureMatcherSetI> entry : originalFilters
+ .entrySet())
+ {
+ fr.setFeatureFilter(entry.getKey(), entry.getValue());
+ }
+ }
+
+ protected void restoreOriginalColours()
+ {
+ for (Entry<String, FeatureColourI> entry : originalColours.entrySet())
+ {
+ fr.setColour(entry.getKey(), entry.getValue());
+ }
+ }
+
/**
* Action on text entry of a threshold value
*/
* (note this might now be an empty filter with no conditions)
*/
fr.setFeatureFilter(featureType, combined.isEmpty() ? null : combined);
++
+ if (applyFiltersToSubtypes)
+ {
+ for (String child : subTypes)
+ {
+ fr.setFeatureFilter(child, combined.isEmpty() ? null : combined);
+ }
+ }
+
+ refreshFeatureSettings();
- ap.paintAlignment(true, true);
+ refreshDisplay(true);
updateFiltersTab();
}