import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
+import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
JCheckBox showComplement;
+ JCheckBox showComplementOnTop;
+
/*
* when true, constructor is still executing - so ignore UI events
*/
}
});
- JPanel transPanel = new JPanel(new GridLayout(1, 2));
- bigPanel.add(transPanel, BorderLayout.SOUTH);
+ showComplementOnTop = new JCheckBox("on top");
+ showComplementOnTop
+ .setSelected(af.getViewport().isShowComplementFeaturesOnTop());
+ showComplementOnTop.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ af.getViewport().setShowComplementFeaturesOnTop(
+ showComplementOnTop.isSelected());
+ refreshDisplay();
+ }
+ });
+
+ JPanel lowerPanel = new JPanel(new GridLayout(1, 2));
+ bigPanel.add(lowerPanel, BorderLayout.SOUTH);
JPanel transbuttons = new JPanel(new GridLayout(5, 1));
transbuttons.add(optimizeOrder);
boolean hasComplement = af.getViewport().getCodingComplement() != null;
JPanel transPanelLeft = new JPanel(
- new GridLayout(hasComplement ? 2 : 1, 1));
+ new GridLayout(hasComplement ? 3 : 2, 1));
+ transPanelLeft.add(new JLabel(" Colour transparency" + ":"));
transPanelLeft.add(transparency);
if (hasComplement)
{
- transPanelLeft.add(showComplement);
+ JPanel cp = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ cp.add(showComplement);
+ cp.add(showComplementOnTop);
+ transPanelLeft.add(cp);
}
- transPanel.add(transPanelLeft);
- transPanel.add(transbuttons);
+ lowerPanel.add(transPanelLeft);
+ lowerPanel.add(transbuttons);
JPanel buttonPanel = new JPanel();
buttonPanel.add(ok);
Color drawnColour = null;
/*
+ * draw 'complement' features below ours if configured to do so
+ */
+ if (av.isShowComplementFeatures()
+ && !av.isShowComplementFeaturesOnTop())
+ {
+ drawnColour = drawComplementFeatures(g, seq, start, end, y1,
+ colourOnly, visiblePositions, drawnColour);
+ }
+
+ /*
* iterate over features in ordering of their rendering (last is on top)
*/
for (int renderIndex = 0; renderIndex < renderOrder.length; renderIndex++)
}
/*
- * if configured to do so, find and show complement's features
+ * draw 'complement' features above ours if configured to do so
*/
- if (av.isShowComplementFeatures())
+ if (av.isShowComplementFeatures() && av.isShowComplementFeaturesOnTop())
{
- AlignViewportI comp = av.getCodingComplement();
- FeatureRenderer fr2 = Desktop.getAlignFrameFor(comp)
- .getFeatureRenderer();
- for (int pos = visiblePositions.start; pos <= visiblePositions.end; pos++)
- {
- int column = seq.findIndex(pos);
- List<SequenceFeature> features = fr2
- .findComplementFeaturesAtResidue(seq, pos);
- for (SequenceFeature sf : features)
- {
- FeatureColourI fc = fr2.getFeatureStyle(sf.getType());
- Color featureColour = fr2.getColor(sf, fc);
- renderFeature(g, seq, column - 1, column - 1, featureColour,
- start, end, y1, colourOnly);
- drawnColour = featureColour;
- }
- }
+ drawnColour = drawComplementFeatures(g, seq, start, end, y1,
+ colourOnly, visiblePositions, drawnColour);
}
if (transparency != 1.0f && g != null)
}
/**
+ * Find any features on the CDS/protein complement of the sequence region and
+ * draw them, with visibility and colouring as configured in the complementary
+ * viewport
+ *
+ * @param g
+ * @param seq
+ * @param start
+ * @param end
+ * @param y1
+ * @param colourOnly
+ * @param visiblePositions
+ * @param drawnColour
+ * @return
+ */
+ Color drawComplementFeatures(final Graphics g, final SequenceI seq,
+ int start, int end, int y1, boolean colourOnly,
+ Range visiblePositions, Color drawnColour)
+ {
+ AlignViewportI comp = av.getCodingComplement();
+ FeatureRenderer fr2 = Desktop.getAlignFrameFor(comp)
+ .getFeatureRenderer();
+ for (int pos = visiblePositions.start; pos <= visiblePositions.end; pos++)
+ {
+ int column = seq.findIndex(pos);
+ List<SequenceFeature> features = fr2
+ .findComplementFeaturesAtResidue(seq, pos);
+ for (SequenceFeature sf : features)
+ {
+ FeatureColourI fc = fr2.getFeatureStyle(sf.getType());
+ Color featureColour = fr2.getColor(sf, fc);
+ renderFeature(g, seq, column - 1, column - 1, featureColour,
+ start, end, y1, colourOnly);
+ drawnColour = featureColour;
+ }
+ }
+ return drawnColour;
+ }
+
+ /**
* Called when alignment in associated view has new/modified features to
* discover and display.
*
/*
* show complement features on top (if configured to show them)
*/
- if (av.isShowComplementFeatures())
+ if (av.isShowComplementFeatures() && av.isShowComplementFeaturesOnTop())
{
- AlignViewportI complement = av.getCodingComplement();
- AlignFrame af = Desktop.getAlignFrameFor(complement);
- FeatureRendererModel fr2 = af.getFeatureRenderer();
- List<SequenceFeature> features = fr2.findComplementFeaturesAtResidue(
- seq, seq.findPosition(column - 1));
-
- ReverseListIterator<SequenceFeature> it = new ReverseListIterator<>(
- features);
- while (it.hasNext())
+ Color col = findComplementFeatureColour(seq, column);
+ if (col != null)
{
- SequenceFeature sf = it.next();
- if (!fr2.featureGroupNotShown(sf))
- {
- Color col = fr2.getColour(sf);
- if (col != null)
- {
- return col;
- }
- }
+ return col;
}
}
}
/*
- * no displayed feature found at position
+ * show complement features underneath (if configured to show them)
*/
+ Color col = null;
+ if (av.isShowComplementFeatures()
+ && !av.isShowComplementFeaturesOnTop())
+ {
+ col = findComplementFeatureColour(seq, column);
+ }
+
+ return col;
+ }
+
+ Color findComplementFeatureColour(SequenceI seq, int column)
+ {
+ AlignViewportI complement = av.getCodingComplement();
+ AlignFrame af = Desktop.getAlignFrameFor(complement);
+ FeatureRendererModel fr2 = af.getFeatureRenderer();
+ List<SequenceFeature> features = fr2.findComplementFeaturesAtResidue(
+ seq, seq.findPosition(column - 1));
+
+ ReverseListIterator<SequenceFeature> it = new ReverseListIterator<>(
+ features);
+ while (it.hasNext())
+ {
+ SequenceFeature sf = it.next();
+ if (!fr2.featureGroupNotShown(sf))
+ {
+ Color col = fr2.getColour(sf);
+ if (col != null)
+ {
+ return col;
+ }
+ }
+ }
return null;
}
}