From: amwaterhouse Date: Wed, 28 Sep 2005 14:54:03 +0000 (+0000) Subject: Wrap alignment with annotations X-Git-Tag: Release_2_06~9 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ee53965807b83bf93a21cbc341cee9a9e005b2cb;p=jalview.git Wrap alignment with annotations --- diff --git a/src/jalview/appletgui/AlignFrame.java b/src/jalview/appletgui/AlignFrame.java index 988aadd..bda314d 100755 --- a/src/jalview/appletgui/AlignFrame.java +++ b/src/jalview/appletgui/AlignFrame.java @@ -35,8 +35,8 @@ public class AlignFrame { final AlignmentPanel alignPanel; final AlignViewport viewport; - public static final int NEW_WINDOW_WIDTH = 700; - public static final int NEW_WINDOW_HEIGHT = 500; + public static int NEW_WINDOW_WIDTH = 700; + public static int NEW_WINDOW_HEIGHT = 500; jalview.bin.JalviewLite applet; @@ -83,6 +83,16 @@ public class AlignFrame else if (param.equalsIgnoreCase("Pairwise Identity")) sortPairwiseMenuItem_actionPerformed(null); } + + param = applet.getParameter("wrap"); + if (param != null) + { + if (param.equalsIgnoreCase("true")) + { + wrapMenuItem.setState(true); + wrapMenuItem_actionPerformed(null); + } + } } this.addWindowListener(new WindowAdapter() @@ -740,11 +750,7 @@ public class AlignFrame public void font_actionPerformed(ActionEvent e) { - Frame frame = new Frame(); - FontChooser fc = new FontChooser(alignPanel, frame); - frame.add(fc); - jalview.bin.JalviewLite.addFrame(frame, "Change Font", 440, 100); - + new FontChooser(alignPanel); } protected void fullSeqId_actionPerformed(ActionEvent e) @@ -808,11 +814,6 @@ public class AlignFrame public void annotationPanelMenuItem_actionPerformed(ActionEvent e) { - if (annotationPanelMenuItem.getState() && viewport.getWrapAlignment()) - { - annotationPanelMenuItem.setState(false); - return; - } viewport.setShowAnnotation(annotationPanelMenuItem.getState()); alignPanel.setAnnotationVisible(annotationPanelMenuItem.getState()); } @@ -1154,11 +1155,7 @@ public class AlignFrame try { - PCAPanel pcaPanel = new PCAPanel(viewport); - Frame frame = new Frame(); - frame.add(pcaPanel); - jalview.bin.JalviewLite.addFrame(frame, "Principal component analysis", - 400, 400); + new PCAPanel(viewport); } catch (java.lang.OutOfMemoryError ex) { diff --git a/src/jalview/appletgui/AlignViewport.java b/src/jalview/appletgui/AlignViewport.java index 30724a4..209f939 100755 --- a/src/jalview/appletgui/AlignViewport.java +++ b/src/jalview/appletgui/AlignViewport.java @@ -57,8 +57,7 @@ public class AlignViewport int charHeight; int charWidth; - int chunkWidth; - int chunkHeight; + int wrappedWidth; Font font = new Font("SansSerif", Font.PLAIN, 10); AlignmentI alignment; @@ -443,24 +442,14 @@ public class AlignViewport return charHeight; } - public void setChunkWidth(int w) + public void setWrappedWidth(int w) { - this.chunkWidth = w; + this.wrappedWidth = w; } - public int getChunkWidth() + public int getwrappedWidth() { - return chunkWidth; - } - - public void setChunkHeight(int h) - { - this.chunkHeight = h; - } - - public int getChunkHeight() - { - return chunkHeight; + return wrappedWidth; } public AlignmentI getAlignment() diff --git a/src/jalview/appletgui/AlignmentPanel.java b/src/jalview/appletgui/AlignmentPanel.java index cf383ac..7332a1a 100755 --- a/src/jalview/appletgui/AlignmentPanel.java +++ b/src/jalview/appletgui/AlignmentPanel.java @@ -22,10 +22,8 @@ package jalview.appletgui; import java.awt.*; import java.awt.event.*; -import jalview.analysis.*; import jalview.datamodel.*; import jalview.jbappletgui.*; -import jalview.schemes.*; public class AlignmentPanel extends GAlignmentPanel implements AdjustmentListener @@ -274,8 +272,11 @@ public class AlignmentPanel public void setAnnotationVisible(boolean b) { - annotationSpaceFillerHolder.setVisible(b); - annotationScroller.setVisible(b); + if (!av.wrapAlignment) + { + annotationSpaceFillerHolder.setVisible(b); + annotationScroller.setVisible(b); + } validate(); repaint(); } @@ -287,9 +288,17 @@ public class AlignmentPanel hscroll.setVisible(!wrap); idwidthAdjuster.setVisible(!wrap); - av.setShowAnnotation(!wrap); - annotationScroller.setVisible(!wrap); - annotationSpaceFillerHolder.setVisible(!wrap); + if (wrap) + { + annotationScroller.setVisible(false); + annotationSpaceFillerHolder.setVisible(false); + } + else if (av.showAnnotation) + { + annotationScroller.setVisible(true); + annotationSpaceFillerHolder.setVisible(true); + } + idSpaceFillerPanel1.setVisible(!wrap); validate(); diff --git a/src/jalview/appletgui/AnnotationLabels.java b/src/jalview/appletgui/AnnotationLabels.java index 82b97a5..1df7455 100755 --- a/src/jalview/appletgui/AnnotationLabels.java +++ b/src/jalview/appletgui/AnnotationLabels.java @@ -29,6 +29,7 @@ public class AnnotationLabels { boolean active = false; AlignmentPanel ap; + AlignViewport av; boolean resizing = false; int oldY, mouseX; static String ADDNEW = "Add new row"; @@ -42,6 +43,7 @@ public class AnnotationLabels public AnnotationLabels(AlignmentPanel ap) { this.ap = ap; + this.av = ap.av; setLayout(null); addMouseListener(new MouseAdapter() { @@ -52,6 +54,12 @@ public class AnnotationLabels }); } + public AnnotationLabels(AlignViewport av) +{ + this.av = av; +} + + public void setScrollOffset(int y) { scrollOffset = y; @@ -60,7 +68,7 @@ public class AnnotationLabels public void actionPerformed(ActionEvent evt) { - AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation(); + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); if (evt.getActionCommand().equals(HIDE)) { @@ -146,10 +154,10 @@ public class AnnotationLabels public void paint(Graphics g) { - drawComponent(g); + drawComponent(g, getSize().width); } - public void drawComponent(Graphics g) + public void drawComponent(Graphics g, int width) { FontMetrics fm = g.getFontMetrics(g.getFont()); g.setColor(Color.white); @@ -158,7 +166,7 @@ public class AnnotationLabels g.translate(0, scrollOffset); g.setColor(Color.black); - AlignmentAnnotation[] aa = ap.av.alignment.getAlignmentAnnotation(); + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); int y = g.getFont().getSize(); int x = 0; @@ -171,7 +179,7 @@ public class AnnotationLabels continue; } - x = getSize().width - fm.stringWidth(aa[i].label) - 3; + x = width - fm.stringWidth(aa[i].label) - 3; if (aa[i].isGraph) { diff --git a/src/jalview/appletgui/AnnotationPanel.java b/src/jalview/appletgui/AnnotationPanel.java index f7ba2fe..a1597f8 100755 --- a/src/jalview/appletgui/AnnotationPanel.java +++ b/src/jalview/appletgui/AnnotationPanel.java @@ -69,15 +69,24 @@ public class AnnotationPanel // ap.annotationScroller.getVAdjustable().addAdjustmentListener( this ); } + + public AnnotationPanel(AlignViewport av) + { + this.av = av; + } + + public void adjustmentValueChanged(AdjustmentEvent evt) { ap.alabels.setScrollOffset( -evt.getValue()); } - public void adjustPanelHeight() + public int adjustPanelHeight() { // setHeight of panels AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + + int height = 0; if (aa != null) { @@ -117,12 +126,14 @@ public class AnnotationPanel } this.setSize(getSize().width, height); - ap.annotationScroller.setSize(getSize().width, height); + if(ap!=null) + ap.annotationScroller.setSize(getSize().width, height); -// ap.annotationSpaceFillerHolder.setSize(d.width,annotationPanel.getSize().height); repaint(); + return height; + } public void addEditableColumn(int i) @@ -217,7 +228,6 @@ public class AnnotationPanel drawComponent(gg, av.startRes, av.endRes + 1); g.drawImage(image, 0, 0, this); - } public void fastPaint(int horizontal) @@ -256,229 +266,233 @@ public class AnnotationPanel public void drawComponent(Graphics g, int startRes, int endRes) { - g.setColor(Color.white); - g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height); - if (av.alignment.getAlignmentAnnotation() == null || - av.alignment.getAlignmentAnnotation().length < 1) - { - g.setColor(Color.white); - g.fillRect(0, 0, getSize().width, getSize().height); - g.setColor(Color.black); - g.drawString("Alignment has no annotations", 20, 15); - return; - } + g.setFont(av.getFont()); - AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); + if (fm == null) + fm = g.getFontMetrics(); - int j, x = 0, y = 0; - char[] lastSS = new char[aa.length]; - int[] lastSSX = new int[aa.length]; - int iconOffset = av.charHeight / 2; - boolean validRes = false; - //\u03B2 \u03B1 - for (int i = 0; i < aa.length; i++) - { - AlignmentAnnotation row = aa[i]; - if (!row.visible) - { - continue; - } + g.setColor(Color.white); + g.fillRect(0, 0, (endRes - startRes) * av.charWidth, getSize().height); - if (row.isGraph) - { - // this is so that we draw the characters below the graph - y += row.height; - if (row.hasText) - { - y -= av.charHeight; - } - } - if (row.hasText) - { - iconOffset = av.charHeight / 2; - } - else + if ((av.alignment.getAlignmentAnnotation() == null) || + (av.alignment.getAlignmentAnnotation().length < 1)) { - iconOffset = 0; + g.setColor(Color.white); + g.fillRect(0, 0, getSize().width, getSize().height); + g.setColor(Color.black); + g.drawString("Alignment has no annotations", 20, 15); + + return; } - for (j = startRes; j < endRes; j++) - { - if (row.annotations.length <= j || row.annotations[j] == null) - { - validRes = false; - } - else - { - validRes = true; - } + AlignmentAnnotation[] aa = av.alignment.getAlignmentAnnotation(); - x = (j - startRes) * av.charWidth; + int j; + int x = 0; + int y = 0; + char[] lastSS = new char[aa.length]; + int[] lastSSX = new int[aa.length]; + int iconOffset = av.charHeight / 2; + boolean validRes = false; - if (activeRow == i) - { + //\u03B2 \u03B1 + for (int i = 0; i < aa.length; i++) + { + AlignmentAnnotation row = aa[i]; - g.setColor(Color.red); + if (!row.visible) + { + continue; + } - if (activeRes != null) + + if (row.isGraph) { - for (int n = 0; n < activeRes.size(); n++) - { - int v = Integer.parseInt(activeRes.elementAt(n).toString()); - if (v == j) + // this is so that we draw the characters below the graph + y += row.height; + + if (row.hasText) { - g.fillRect( (j - startRes) * av.charWidth, y, av.charWidth, - row.height); + y -= av.charHeight; } - } } - } - if (validRes && row.annotations[j].displayCharacter.length() > 0) - { - int charOffset = (av.charWidth - - fm.charWidth(row.annotations[j].displayCharacter. - charAt(0))) / 2; - g.setColor(row.annotations[j].colour); - if (j == 0 || row.isGraph) + if (row.hasText) { - if (row.annotations[0].secondaryStructure == 'H' - || row.annotations[0].secondaryStructure == 'E') - { - g.drawString(row.annotations[j].displayCharacter, x, - y + iconOffset + 3); - } + iconOffset = av.charHeight / 2; } - else if ( (row.annotations[j].secondaryStructure == 'H' - || row.annotations[j].secondaryStructure == 'E') && - (row.annotations[j - 1] == null || - row.annotations[j].secondaryStructure != - row.annotations[j - 1].secondaryStructure)) + else { - - g.drawString(row.annotations[j].displayCharacter, x + charOffset, - y + iconOffset + 3); + iconOffset = 0; } - if (!row.hasIcons) + for (j = startRes; j < endRes; j++) { - g.drawString(row.annotations[j].displayCharacter, x + charOffset, - y + iconOffset + 3); - } - } + if ((row.annotations.length <= j) || + (row.annotations[j] == null)) + { + validRes = false; + } + else + { + validRes = true; + } - if (row.hasIcons) - { - if (!validRes || row.annotations[j].secondaryStructure != lastSS[i]) - { - switch (lastSS[i]) - { - case 'H': - g.setColor(HELIX_COLOUR); - g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i], - 7, 8, 8); - break; - case 'E': - g.setColor(SHEET_COLOUR); - g.fillRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i] - 4, - 7); - g.fillPolygon(new int[] - {x - 4, x - 4, x} - , new int[] - {y + iconOffset, y + 14 + iconOffset, - y + 8 + iconOffset}, 3); - break; - case 'C': - break; - default: - g.setColor(Color.gray); - g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2); - break; - } - - if (validRes) - { - lastSS[i] = row.annotations[j].secondaryStructure; - } - else - { - lastSS[i] = ' '; - } - lastSSX[i] = x; - } - } + x = (j - startRes) * av.charWidth; - if (validRes && row.isGraph) - { - g.setColor(new Color(0, 0, 180)); - int height = (int) ( (row.annotations[j].value / row.graphMax) * - GRAPH_HEIGHT); - if (row.windowLength > 1) - { - int total = 0; - for (int i2 = j - (row.windowLength / 2); - i2 < j + (row.windowLength / 2); i2++) - { - if (i2 < 0 || i2 >= av.alignment.getWidth()) + if (validRes && + (row.annotations[j].displayCharacter.length() > 0)) { - continue; + + int charOffset = (av.charWidth - + fm.charWidth(row.annotations[j].displayCharacter.charAt( + 0))) / 2; + g.setColor(row.annotations[j].colour); + + if (j == 0 || row.isGraph) + { + g.drawString(row.annotations[j].displayCharacter, x+charOffset, + y + iconOffset + 3); + } + else if (((row.annotations[j - 1] == null) || + (row.annotations[j].displayCharacter != row.annotations[j - + 1].displayCharacter))) + { + g.drawString(row.annotations[j].displayCharacter, x+charOffset, + y + iconOffset + 3); + } } - total += row.annotations[i2].value; - } + if (row.hasIcons) + { + if (!validRes || + (row.annotations[j].secondaryStructure != lastSS[i])) + { + switch (lastSS[i]) + { + case 'H': + g.setColor(HELIX_COLOUR); + g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i], 7, 8, 8); + + break; + + case 'E': + g.setColor(SHEET_COLOUR); + g.fillRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i] - 4, 7); + g.fillPolygon(new int[] { x - 4, x - 4, x }, + new int[] + { + y + iconOffset, y + 14 + iconOffset, + y + 8 + iconOffset + }, 3); + + break; + + case 'C': + break; + + default: + g.setColor(Color.gray); + g.fillRect(lastSSX[i], y + 6 + iconOffset, + x - lastSSX[i], 2); + + break; + } + + if (validRes) + { + lastSS[i] = row.annotations[j].secondaryStructure; + } + else + { + lastSS[i] = ' '; + } + + lastSSX[i] = x; + } + } - total /= row.windowLength; - height = (int) ( (total / row.graphMax) * GRAPH_HEIGHT); + if (validRes && row.isGraph) + { + g.setColor(new Color(0, 0, 180)); + + int height = (int) ((row.annotations[j].value / row.graphMax) * GRAPH_HEIGHT); + + if (row.windowLength > 1) + { + int total = 0; + + for (int i2 = j - (row.windowLength / 2); + i2 < (j + (row.windowLength / 2)); i2++) + { + if ((i2 < 0) || (i2 >= av.alignment.getWidth())) + { + continue; + } + + total += row.annotations[i2].value; + } + + total /= row.windowLength; + height = (int) ((total / row.graphMax) * GRAPH_HEIGHT); + } + g.setColor(row.annotations[j].colour); + g.fillRect(x, y - height, av.charWidth, height); + } } - g.setColor(row.annotations[j].colour); - g.fillRect(x, y - height, av.charWidth, height); - } - } + x += av.charWidth; + + if (row.hasIcons) + { + switch (lastSS[i]) + { + case 'H': + g.setColor(HELIX_COLOUR); + g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i], 7, 8, 8); - x += av.charWidth; + break; - if (row.hasIcons) - { - switch (lastSS[i]) - { - case 'H': - g.setColor(HELIX_COLOUR); - g.fillRoundRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i], 7, - 8, 8); - break; - case 'E': - g.setColor(SHEET_COLOUR); - g.fillRect(lastSSX[i], y + 4 + iconOffset, x - lastSSX[i] - 4, 7); - g.fillPolygon(new int[] - {x - 4, x - 4, x} - , new int[] - {y + iconOffset, y + 14 + iconOffset, - y + 7 + iconOffset} - , 3); - break; - case 'C': - break; - default: - g.setColor(Color.gray); - g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2); - break; + case 'E': + g.setColor(SHEET_COLOUR); + g.fillRect(lastSSX[i], y + 4 + iconOffset, + x - lastSSX[i] - 4, 7); + g.fillPolygon(new int[] { x - 4, x - 4, x }, + new int[] + { + y + iconOffset, y + 14 + iconOffset, + y + 7 + iconOffset + }, 3); + + break; - } - } + case 'C': + break; - if (row.isGraph && row.hasText) - { - y += av.charHeight; - } - if (!row.isGraph) - { - y += aa[i].height; - } - } + default: + g.setColor(Color.gray); + g.fillRect(lastSSX[i], y + 6 + iconOffset, x - lastSSX[i], 2); + + break; + } + } + + if (row.isGraph && row.hasText) + { + y += av.charHeight; + } + + if (!row.isGraph) + { + y += aa[i].height; + } + } } // used by overview window diff --git a/src/jalview/appletgui/FontChooser.java b/src/jalview/appletgui/FontChooser.java index 02a7471..e424a42 100755 --- a/src/jalview/appletgui/FontChooser.java +++ b/src/jalview/appletgui/FontChooser.java @@ -27,16 +27,27 @@ public class FontChooser extends GFontChooser { AlignmentPanel ap; + TreePanel tp; Font oldFont; boolean init = true; Frame frame; - public FontChooser(AlignmentPanel ap, Frame frame) + public FontChooser(TreePanel tp) { - super(); + this.tp = tp; + oldFont = tp.getTreeFont(); + init(); + } - this.frame = frame; + public FontChooser(AlignmentPanel ap) + { + this.ap = ap; + oldFont = ap.av.getFont(); + init(); + } + void init() + { this.ap = ap; String fonts[] = Toolkit.getDefaultToolkit().getFontList(); for (int i = 0; i < fonts.length; i++) @@ -53,27 +64,44 @@ public class FontChooser fontStyle.addItem("bold"); fontStyle.addItem("italic"); - oldFont = ap.av.getFont(); fontName.select(oldFont.getName()); fontSize.select(oldFont.getSize() + ""); fontStyle.select(oldFont.getStyle()); + Frame frame = new Frame(); + this.frame = frame; + frame.add(this); + jalview.bin.JalviewLite.addFrame(frame, "Change Font", 440, 100); + init = false; } protected void ok_actionPerformed() { frame.setVisible(false); - if (ap.getOverviewPanel() != null) + if (ap != null) { - ap.getOverviewPanel().updateOverviewImage(); + if (ap.getOverviewPanel() != null) + { + ap.getOverviewPanel().updateOverviewImage(); + } } + } protected void cancel_actionPerformed() { - ap.av.setFont(oldFont); - ap.repaint(); + if(ap!=null) + { + ap.av.setFont(oldFont); + ap.repaint(); + } + else if(tp!=null) + { + tp.setTreeFont(oldFont); + tp.treeCanvas.repaint(); + } + fontName.select(oldFont.getName()); fontSize.select(oldFont.getSize() + ""); fontStyle.select(oldFont.getStyle()); @@ -88,8 +116,15 @@ public class FontChooser Integer.parseInt(fontSize.getSelectedItem(). toString()) ); - ap.av.setFont(newFont); - ap.fontChanged(); + if (ap != null) + { + ap.av.setFont(newFont); + ap.fontChanged(); + } + else if(tp != null) + { + tp.setTreeFont(newFont); + } } protected void fontName_actionPerformed() diff --git a/src/jalview/appletgui/IdCanvas.java b/src/jalview/appletgui/IdCanvas.java index 399506e..30560d7 100755 --- a/src/jalview/appletgui/IdCanvas.java +++ b/src/jalview/appletgui/IdCanvas.java @@ -177,23 +177,51 @@ public class IdCanvas { Color currentColor = Color.white; Color currentTextColor = Color.black; + Font italic = new Font(av.getFont().getName(), Font.ITALIC, + av.getFont().getSize()); if (av.getWrapAlignment()) { + int annotationHeight = 0; + AnnotationLabels labels = null; - int rowSize = av.getEndRes() - av.getStartRes(); - // Draw the rest of the panels - - for (int ypos = 2 * av.charHeight, row = av.startRes; - ypos <= getSize().height && row < av.alignment.getWidth(); - ypos += av.chunkHeight, row += rowSize) + if(av.showAnnotation) { - for (int i = starty; i < av.alignment.getHeight(); i++) + AnnotationPanel ap = new AnnotationPanel(av); + annotationHeight = ap.adjustPanelHeight(); + labels = new AnnotationLabels(av); + } + + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; + + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + + annotationHeight; + + int rowSize = av.getEndRes() - av.getStartRes(); + + // Draw the rest of the panels + for (int ypos = hgap, row = av.startRes; + (ypos <= getSize().height) && (row < av.alignment.getWidth()); + ypos += cHeight, row += rowSize) { - SequenceI s = av.alignment.getSequenceAt(i); - drawIdString(gg, s, i, 0, ypos); + for (int i = starty; i < av.alignment.getHeight(); i++) + { + SequenceI s = av.alignment.getSequenceAt(i); + drawIdString(gg, s, i, 0, ypos); + } + + if(labels!=null) + { + gg.setFont(av.getFont()); + gg.translate(0, ypos+(av.getAlignment().getHeight() * av.charHeight)); + labels.drawComponent(gg, getSize().width); + gg.translate(0, -ypos-(av.getAlignment().getHeight() * av.charHeight)); + gg.setFont(italic); + } } - } } else diff --git a/src/jalview/appletgui/PCAPanel.java b/src/jalview/appletgui/PCAPanel.java index 399fce8..026ca09 100755 --- a/src/jalview/appletgui/PCAPanel.java +++ b/src/jalview/appletgui/PCAPanel.java @@ -40,7 +40,6 @@ public class PCAPanel public PCAPanel(AlignViewport av) { - this.av = av; if (av.getSelectionGroup()!=null && av.getSelectionGroup().getSize() > 3) { @@ -58,8 +57,14 @@ public class PCAPanel seqs[i] = av.getAlignment().getSequenceAt(i); } } + rc = new RotatableCanvas(av); add(rc, BorderLayout.CENTER); + + jalview.bin.JalviewLite.addFrame(this, "Principal component analysis", + 400, 400); + + Thread worker = new Thread(this); worker.start(); } @@ -109,6 +114,7 @@ public class PCAPanel rc.setPoints(points, pca.getM().rows); rc.repaint(); seqs = null; + this.repaint(); } void doDimensionChange() @@ -149,4 +155,20 @@ public class PCAPanel doDimensionChange(); } + public void values_actionPerformed(ActionEvent actionEvent) + { + + CutAndPasteTransfer cap = new CutAndPasteTransfer(false, null); + Frame frame = new Frame(); + frame.add(cap); + jalview.bin.JalviewLite.addFrame(frame, "PCA details", 500, 500); + + cap.setText(pca.getDetails()); + } + + public void labels_itemStateChanged(ItemEvent itemEvent) + { + rc.showLabels( labels.getState() ); + } + } diff --git a/src/jalview/appletgui/RotatableCanvas.java b/src/jalview/appletgui/RotatableCanvas.java index 9fa7491..82207a2 100755 --- a/src/jalview/appletgui/RotatableCanvas.java +++ b/src/jalview/appletgui/RotatableCanvas.java @@ -80,12 +80,19 @@ public class RotatableCanvas float scalefactor = 1; AlignViewport av; + boolean showLabels = false; public RotatableCanvas(AlignViewport av) { this.av = av; } + public void showLabels(boolean b) + { + showLabels = b; + repaint(); + } + public void setPoints(Vector points, int npoint) { this.points = points; @@ -376,7 +383,14 @@ public class RotatableCanvas } g.fillRect(x - 3, y - 3, 6, 6); - g.setColor(Color.red); + if (showLabels) + { + g.setColor(Color.red); + g.drawString( ( (SequencePoint) points.elementAt(i)).sequence. + getName(), + x - 3, y - 4); + } + } // //Now the rectangle // if (rectx2 != -1 && recty2 != -1) { diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index 853a327..46ddf37 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -241,11 +241,6 @@ public class SeqCanvas gg.setColor(Color.white); gg.fillRect(0, 0, imgWidth, imgHeight); - chunkWidth = getWrappedCanvasWidth(getSize().width); - chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; - - av.setChunkHeight(chunkHeight); - av.setChunkWidth(chunkWidth); if (av.getWrapAlignment()) { @@ -304,6 +299,8 @@ public class SeqCanvas FontMetrics fm = getFontMetrics(av.getFont()); + int LABEL_EAST = 0; + if (av.scaleRightWrapped) { LABEL_EAST = fm.stringWidth(getMask()+"0"); @@ -316,60 +313,91 @@ public class SeqCanvas LABEL_WEST = fm.stringWidth(getMask()); } + int hgap = av.charHeight; + if(av.scaleAboveWrapped) + hgap += av.charHeight; + int cWidth = (canvasWidth - LABEL_EAST - LABEL_WEST) / av.charWidth; - int cHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; + int cHeight = av.getAlignment().getHeight() * av.charHeight; + + av.setWrappedWidth(cWidth); av.endRes = av.startRes + cWidth; - int endx = startRes + cWidth - 1; - int ypos = 2 * av.charHeight; - while (ypos <= canvasHeight && startRes < av.alignment.getWidth()) + int endx = (startRes + cWidth) - 1; + int ypos = hgap; + + + while ((ypos <= canvasHeight) && (startRes < av.alignment.getWidth())) { - g.setColor(Color.black); + g.setColor(Color.black); - if (av.scaleLeftWrapped) - { - drawWestScale(g, startRes, endx, ypos); - } + if (av.scaleLeftWrapped) + { + drawWestScale(g, startRes, endx, ypos); + } - if (av.scaleRightWrapped) - { - g.translate(canvasWidth - LABEL_EAST, 0); - drawEastScale(g, startRes, endx, ypos); - g.translate( - (canvasWidth - LABEL_EAST), 0); - } + if (av.scaleRightWrapped) + { + g.translate(canvasWidth - LABEL_EAST, 0); + drawEastScale(g, startRes, endx, ypos); + g.translate(-(canvasWidth - LABEL_EAST), 0); + } - g.translate(LABEL_WEST, 0); - if (av.scaleAboveWrapped) - { - drawNorthScale(g, startRes, endx, ypos); - } + g.translate(LABEL_WEST, 0); + if (av.scaleAboveWrapped) + { + drawNorthScale(g, startRes, endx, ypos); + } - if(g.getClip()==null) - g.setClip(0, 0, cWidth * av.charWidth, canvasHeight); - if (av.alignment.getWidth() >= av.vconsensus.size()) - { - endx = av.vconsensus.size() - 2; - } - drawPanel(g, startRes, endx, 0, al.getHeight(), startRes, 0, ypos); - g.setClip(null); - g.translate( -LABEL_WEST, 0); + if (av.vconsensus!=null && av.alignment.getWidth() >= av.vconsensus.size()) + { + endx = av.vconsensus.size() - 2; + } - ypos += cHeight; - startRes += cWidth; - endx = startRes + cWidth - 1; - if (endx > al.getWidth()) - { - endx = al.getWidth(); - } - } + drawPanel(g, startRes, endx, 0, al.getHeight(), startRes, 0, ypos); + + if(av.showAnnotation) + { + g.translate(0, cHeight + ypos); + if(annotations==null) + annotations = new AnnotationPanel(av); + + annotations.drawComponent( g, startRes, endx + 1); + g.translate(0, -cHeight - ypos); + } + g.translate(-LABEL_WEST, 0); + + ypos += cHeight+getAnnotationHeight()+hgap; + + + startRes += cWidth; + endx = (startRes + cWidth) - 1; + + if (endx > al.getWidth()) + { + endx = al.getWidth(); + } + } } + AnnotationPanel annotations; + int getAnnotationHeight() + { + if(!av.showAnnotation) + return 0; + + if(annotations==null) + annotations = new AnnotationPanel(av); + + return annotations.adjustPanelHeight(); + } + synchronized public void drawPanel(Graphics g, int x1, int x2, int y1, int y2, int startx, int starty, int offset) { @@ -378,29 +406,28 @@ public class SeqCanvas sr.renderGaps(av.renderGaps); SequenceI nextSeq; - /// First draw the sequences - ///////////////////////////// - for (int i = y1; i < y2; i++) - { - nextSeq = av.alignment.getSequenceAt(i); + ///////////////////////////// + for (int i = y1; i < y2; i++) + { + nextSeq = av.alignment.getSequenceAt(i); - sr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq), x1, x2, + sr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq), x1, x2, + (x1 - startx) * av.charWidth, + offset + + (i - starty) * av.charHeight, + av.charWidth, av.charHeight); + + if (av.showSequenceFeatures) + { + fr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq), x1, x2, (x1 - startx) * av.charWidth, offset + - (i-starty)*av.charHeight, + (i - starty) * av.charHeight, av.charWidth, av.charHeight); - - if (av.showSequenceFeatures) - { - fr.drawSequence(g, nextSeq, av.alignment.findAllGroups(nextSeq), x1, x2, - (x1 - startx) * av.charWidth, - offset + - (i-starty)*av.charHeight, - av.charWidth, av.charHeight); - } } - // + } + ///////////////////////////////////// // Now outline any areas if necessary @@ -415,146 +442,146 @@ public class SeqCanvas group = (SequenceGroup) groups.elementAt(0); groupIndex = 0; } - if (group != null && !isOverview) { - do - { - int oldY = -1; - int i = 0; - boolean inGroup = false; - int top = -1; - int bottom = -1; - - for (i = y1; i < y2; i++) - { - sx = (group.getStartRes() - startx) * av.charWidth; - sy = offset + ((i - starty) * av.charHeight); - ex = (((group.getEndRes() + 1) - group.getStartRes()) * av.charWidth) - - 1; - - if(sx+ex<0 || sx>imgWidth) - { - continue; - } + do + { + int oldY = -1; + int i = 0; + boolean inGroup = false; + int top = -1; + int bottom = -1; - if ( (sx <= (x2-x1)*av.charWidth) && - group.sequences.contains(av.alignment.getSequenceAt( - i))) - { - if ((bottom == -1) && - !group.sequences.contains( - av.alignment.getSequenceAt(i + 1))) - { - bottom = sy + av.charHeight; - } + for (i = y1; i < y2; i++) + { + sx = (group.getStartRes() - startx) * av.charWidth; + sy = offset + ((i - starty) * av.charHeight); + ex = (((group.getEndRes() + 1) - group.getStartRes()) * av.charWidth) - + 1; - if (!inGroup) - { - if (((top == -1) && (i == 0)) || - !group.sequences.contains( - av.alignment.getSequenceAt(i - 1))) - { - top = sy; - } - - oldY = sy; - inGroup = true; - - if (group == av.getSelectionGroup()) - { - g.setColor(Color.red); - } - else - { - g.setColor(group.getOutlineColour()); - } - } - } - else - { - if (inGroup) + if(sx+ex<0 || sx>imgWidth) { - if (sx >= 0 && sx < imgWidth) - g.drawLine(sx, oldY, sx, sy); - - if (sx + ex < imgWidth) - g.drawLine(sx + ex, oldY, sx + ex, sy); + continue; + } - if (sx < 0) + if ( (sx <= (x2-x1)*av.charWidth) && + group.sequences.contains(av.alignment.getSequenceAt( + i))) + { + if ((bottom == -1) && + !group.sequences.contains( + av.alignment.getSequenceAt(i + 1))) + { + bottom = sy + av.charHeight; + } + + if (!inGroup) + { + if (((top == -1) && (i == 0)) || + !group.sequences.contains( + av.alignment.getSequenceAt(i - 1))) + { + top = sy; + } + + oldY = sy; + inGroup = true; + + if (group == av.getSelectionGroup()) + { + + g.setColor(Color.red); + } + else + { + g.setColor(group.getOutlineColour()); + } + } + } + else + { + if (inGroup) { - ex += sx; - sx = 0; - } + if (sx >= 0 && sx < imgWidth) + g.drawLine(sx, oldY, sx, sy); + + if (sx + ex < imgWidth) + g.drawLine(sx + ex, oldY, sx + ex, sy); + + if (sx < 0) + { + ex += sx; + sx = 0; + } + + if (sx + ex > imgWidth) + ex = imgWidth; + + else if (sx + ex >= (x2 - x1 + 1) * av.charWidth) + ex = (x2 - x1 + 1) * av.charWidth; + + if (top != -1) + { + g.drawLine(sx, top, sx + ex, top); + top = -1; + } + + if (bottom != -1) + { + g.drawLine(sx, bottom, sx + ex, bottom); + bottom = -1; + } + + inGroup = false; + } + } + } - if (sx + ex > imgWidth) - ex = imgWidth; + if (inGroup) + { + sy = offset + ( (i - starty) * av.charHeight); + if (sx >= 0 && sx < imgWidth) + g.drawLine(sx, oldY, sx, sy); - else if (sx + ex >= (x2 - x1 + 1) * av.charWidth) - ex = (x2 - x1 + 1) * av.charWidth; + if (sx + ex < imgWidth) + g.drawLine(sx + ex, oldY, sx + ex, sy); - if (top != -1) - { - g.drawLine(sx, top, sx + ex, top); - top = -1; - } + if (sx < 0) + { + ex += sx; + sx = 0; + } - if (bottom != -1) - { - g.drawLine(sx, bottom, sx + ex, bottom); - bottom = -1; - } + if (sx + ex > imgWidth) + ex = imgWidth; + else if (sx + ex >= (x2 - x1 + 1) * av.charWidth) + ex = (x2 - x1 + 1) * av.charWidth; - inGroup = false; - } + if (top != -1) + { + g.drawLine(sx, top, sx + ex, top); + top = -1; } - } - - if (inGroup) - { - sy = offset + ( (i - starty) * av.charHeight); - if (sx >= 0 && sx < imgWidth) - g.drawLine(sx, oldY, sx, sy); - if (sx + ex < imgWidth) - g.drawLine(sx + ex, oldY, sx + ex, sy); + if (bottom != -1) + { + g.drawLine(sx, bottom - 1, sx + ex, bottom - 1); + bottom = -1; + } - if (sx < 0) - { - ex += sx; - sx = 0; + inGroup = false; } - if (sx + ex > imgWidth) - ex = imgWidth; - else if (sx + ex >= (x2 - x1 + 1) * av.charWidth) - ex = (x2 - x1 + 1) * av.charWidth; + groupIndex++; - if (top != -1) + if (groupIndex >= groups.size()) { - g.drawLine(sx, top, sx + ex, top); - top = -1; + break; } - if (bottom != -1) - { - g.drawLine(sx, bottom - 1, sx + ex, bottom - 1); - bottom = -1; - } - - inGroup = false; - } - - groupIndex++; - - if (groupIndex >= groups.size()) - { - break; - } - - group = (SequenceGroup) groups.elementAt(groupIndex); - } - while (groupIndex < groups.size()); + group = (SequenceGroup) groups.elementAt(groupIndex); + } + while (groupIndex < groups.size()); } /// Highlight search Results once all sequences have been drawn diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 9c3a1e8..9ed48b2 100755 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -161,16 +161,26 @@ public class SeqPanel if (av.wrapAlignment) { + + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; + + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + seqCanvas.getAnnotationHeight(); + int y = evt.getY(); - y -= (2 * av.charHeight); + y -= hgap; x -= seqCanvas.LABEL_WEST; - int chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; - int cwidth = seqCanvas.getWrappedCanvasWidth(this.getSize().width); - wrappedBlock = y/chunkHeight; - wrappedBlock += av.getStartRes()/cwidth; - res = wrappedBlock*cwidth + x / av.getCharWidth(); + int cwidth = seqCanvas.getWrappedCanvasWidth(getSize().width); + + wrappedBlock = y / cHeight; + wrappedBlock += av.getStartRes() / cwidth; + + res = wrappedBlock * cwidth + x / av.getCharWidth(); + } else { @@ -183,14 +193,22 @@ public class SeqPanel int findSeq(MouseEvent evt) { + int seq = 0; int y = evt.getY(); if (av.wrapAlignment) { - y -= (2 * av.charHeight); - int chunkHeight = (av.getAlignment().getHeight() + 2) * av.charHeight; - seq = ( (y % chunkHeight) / av.getCharHeight()); + int hgap = av.charHeight; + if (av.scaleAboveWrapped) + hgap += av.charHeight; + + int cHeight = av.getAlignment().getHeight() * av.charHeight + + hgap + seqCanvas.getAnnotationHeight(); + + y -= hgap; + + seq = ( (y % cHeight) / av.getCharHeight()); } else { diff --git a/src/jalview/appletgui/TreeCanvas.java b/src/jalview/appletgui/TreeCanvas.java index 38d23db..76569dd 100755 --- a/src/jalview/appletgui/TreeCanvas.java +++ b/src/jalview/appletgui/TreeCanvas.java @@ -37,15 +37,13 @@ public class TreeCanvas AlignViewport av; public static final String PLACEHOLDER = " * "; Font font; - int fontSize = 12; - boolean fitToWindow = true; boolean showDistances = false; boolean showBootstrap = false; boolean markPlaceholders = false; int offx = 20; - int offy = 20; + int offy; float threshold; @@ -62,6 +60,7 @@ public class TreeCanvas public TreeCanvas(AlignViewport av, ScrollPane scroller) { this.av = av; + font = av.getFont(); scrollPane = scroller; addMouseListener(this); setLayout(null); @@ -172,7 +171,7 @@ public class TreeCanvas } if (!nodeLabel.equals("")) { - g.drawString(nodeLabel, xstart, ypos - 10); + g.drawString(nodeLabel, xstart+2, ypos - 2); } String name = (markPlaceholders && node.isPlaceholder()) ? @@ -181,7 +180,7 @@ public class TreeCanvas int charWidth = fm.stringWidth(name) + 3; int charHeight = fm.getHeight(); - Rectangle rect = new Rectangle(xend + 20, ypos - charHeight, + Rectangle rect = new Rectangle(xend + 10, ypos - charHeight, charWidth, charHeight); nameHash.put( (SequenceI) node.element(), rect); @@ -228,7 +227,7 @@ public class TreeCanvas if (showDistances && node.dist > 0) { - g.drawString(new Format("%-.2f").form(node.dist), xstart, ypos - 5); + g.drawString(new Format("%-.2f").form(node.dist), xstart+2, ypos - 2); } } @@ -280,7 +279,7 @@ public class TreeCanvas top.count = ( (SequenceNode) top.left()).count + ( (SequenceNode) top.right()).count; } - float chunk = (float) (height - offy * 2) / top.count; + float chunk = (float) (height - offy) / top.count; pickNode(pickBox, top, chunk, wscale, width, offx, offy); } @@ -352,7 +351,9 @@ public class TreeCanvas public void paint(Graphics g) { - font = new Font("Verdana", Font.PLAIN, fontSize); + if(tree==null) + return; + g.setFont(font); FontMetrics fm = g.getFontMetrics(font); @@ -378,19 +379,10 @@ public class TreeCanvas scrollPane.validate(); } - public int getFontSize() - { - return fontSize; - } - - public void setFontSize(int fontSize) - { - this.fontSize = fontSize; - repaint(); - } public void draw(Graphics g, int width, int height) { + offy = font.getSize()+10; g.setColor(Color.white); g.fillRect(0, 0, width, height); @@ -406,7 +398,7 @@ public class TreeCanvas top.count = ( (SequenceNode) top.left()).count + ( (SequenceNode) top.right()).count; } - float chunk = (float) (height - offy * 2) / top.count; + float chunk = (float) (height - offy) / top.count; drawNode(g, tree.getTopNode(), chunk, wscale, width, offx, offy); diff --git a/src/jalview/appletgui/TreePanel.java b/src/jalview/appletgui/TreePanel.java index 42be37b..3e26a4b 100755 --- a/src/jalview/appletgui/TreePanel.java +++ b/src/jalview/appletgui/TreePanel.java @@ -60,9 +60,6 @@ public class TreePanel { super(); initTreePanel(av, seqVector, type, pwtype, s, e, null); - - // We know this tree has distances. JBPNote TODO: prolly should add this as a userdefined default - treeCanvas.setShowDistances(true); } /** @@ -127,6 +124,8 @@ public class TreePanel treeCanvas.setTree(tree); if(newtree!=null) { + distanceMenu.setState(newtree.HasDistances()); + bootstrapMenu.setState(newtree.HasBootstrap()); treeCanvas.setShowBootstrap(newtree.HasBootstrap()); treeCanvas.setShowDistances(newtree.HasDistances()); } @@ -145,7 +144,7 @@ public class TreePanel protected void fitToWindow_actionPerformed(ActionEvent e) { treeCanvas.fitToWindow = fitToWindow.getState(); - repaint(); + treeCanvas.repaint(); } public void newickOutput_actionPerformed(ActionEvent actionEvent) @@ -159,28 +158,23 @@ public class TreePanel jalview.bin.JalviewLite.addFrame(frame, type + " " + pwtype, 500, 100); } - protected void fontSize_actionPerformed(ActionEvent e) + public java.awt.Font getTreeFont() { - /* if( treeCanvas==null ) - return; + return treeCanvas.font; + } - String size = fontSize.getLabel().substring( fontSize.getLabel().indexOf("-")+1); + public void setTreeFont(java.awt.Font font) + { + treeCanvas.font = font; + treeCanvas.repaint(); + } - Object selection = JOptionPane.showInternalInputDialog(Desktop.desktop, - "Select font size", - "Font size", - JOptionPane.QUESTION_MESSAGE, - null, new String[]{"1","2","4","6","8","10","12","14","16","18","20"} - ,"Font Size - "+size); - if(selection!=null) - { - fontSize.setText("Font Size - " + selection); + protected void fontSize_actionPerformed(ActionEvent e) + { + if( treeCanvas==null ) + return; - int i = Integer.parseInt(selection.toString()); - treeCanvas.setFontSize(i); - } - scrollPane.setViewportView(treeCanvas); - */ + new FontChooser(this); } protected void distanceMenu_actionPerformed(ActionEvent e)