X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FFontChooser.java;h=853d4aaf73ac1cb023cc1fd3df73f73537fe3564;hb=e63fbac40aee31b0563c07a349f46d9dad37f46a;hp=06f29e9dd18f435dae628fb2b2ee7d042a12de33;hpb=136c0793b90b72b928c4d77dc109dd5c644e00d3;p=jalview.git diff --git a/src/jalview/gui/FontChooser.java b/src/jalview/gui/FontChooser.java index 06f29e9..853d4aa 100755 --- a/src/jalview/gui/FontChooser.java +++ b/src/jalview/gui/FontChooser.java @@ -20,10 +20,6 @@ */ package jalview.gui; -import jalview.bin.Cache; -import jalview.jbgui.GFontChooser; -import jalview.util.MessageManager; - import java.awt.Font; import java.awt.FontMetrics; import java.awt.geom.Rectangle2D; @@ -31,6 +27,10 @@ import java.awt.geom.Rectangle2D; import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; +import jalview.bin.Cache; +import jalview.jbgui.GFontChooser; +import jalview.util.MessageManager; + /** * DOCUMENT ME! * @@ -43,6 +43,8 @@ public class FontChooser extends GFontChooser TreePanel tp; + CutAndPasteTransfer cap; + /* * The font on opening the dialog (to be restored on Cancel) */ @@ -87,7 +89,7 @@ public class FontChooser extends GFontChooser public FontChooser(TreePanel treePanel) { this.tp = treePanel; - ap = treePanel.treeCanvas.ap; + ap = treePanel.getTreeCanvas().getAssociatedPanel(); oldFont = treePanel.getTreeFont(); defaultButton.setVisible(false); smoothFont.setEnabled(false); @@ -109,31 +111,47 @@ public class FontChooser extends GFontChooser init(); } + /** + * Creates a new FontChooser for a CutAndPasteTransfer + * @param cap + */ + public FontChooser(CutAndPasteTransfer cap) + { + oldFont = new Font("Monospaced", Font.PLAIN, 12); + this.cap = cap; + init(); + } + void init() { frame = new JInternalFrame(); + frame.setFrameIcon(null); frame.setContentPane(this); - smoothFont.setSelected(ap.av.antiAlias); - - /* - * Enable 'scale protein as cDNA' in a SplitFrame view. The selection is - * stored in the ViewStyle of both dna and protein Viewport. Also enable - * checkbox for copy font changes to other half of split frame. - */ - boolean inSplitFrame = ap.av.getCodingComplement() != null; - if (inSplitFrame) + if (!isCapFont()) { - oldComplementFont = ((AlignViewport) ap.av.getCodingComplement()) - .getFont(); - oldComplementSmooth = ((AlignViewport) ap.av.getCodingComplement()).antiAlias; - scaleAsCdna.setVisible(true); - scaleAsCdna.setSelected(ap.av.isScaleProteinAsCdna()); - fontAsCdna.setVisible(true); - fontAsCdna.setSelected(ap.av.isProteinFontAsCdna()); + smoothFont.setSelected(ap.av.antiAlias); + + /* + * Enable 'scale protein as cDNA' in a SplitFrame view. The selection is + * stored in the ViewStyle of both dna and protein Viewport. Also enable + * checkbox for copy font changes to other half of split frame. + */ + boolean inSplitFrame = ap.av.getCodingComplement() != null; + if (inSplitFrame) + { + oldComplementFont = ((AlignViewport) ap.av.getCodingComplement()) + .getFont(); + oldComplementSmooth = ((AlignViewport) ap.av + .getCodingComplement()).antiAlias; + scaleAsCdna.setVisible(true); + scaleAsCdna.setSelected(ap.av.isScaleProteinAsCdna()); + fontAsCdna.setVisible(true); + fontAsCdna.setSelected(ap.av.isProteinFontAsCdna()); + } } - if (tp != null) + if (isTreeFont()) { Desktop.addInternalFrame(frame, MessageManager.getString("action.change_font_tree_panel"), @@ -170,9 +188,9 @@ public class FontChooser extends GFontChooser fontStyle.setSelectedIndex(oldFont.getStyle()); FontMetrics fm = getGraphics().getFontMetrics(oldFont); - monospaced.setSelected(fm.getStringBounds("M", getGraphics()) - .getWidth() == fm.getStringBounds("|", getGraphics()) - .getWidth()); + monospaced.setSelected( + fm.getStringBounds("M", getGraphics()).getWidth() == fm + .getStringBounds("|", getGraphics()).getWidth()); init = false; } @@ -182,10 +200,11 @@ public class FontChooser extends GFontChooser { ap.av.antiAlias = smoothFont.isSelected(); ap.getAnnotationPanel().image = null; - ap.paintAlignment(true); + ap.paintAlignment(true, false); if (ap.av.getCodingComplement() != null && ap.av.isProteinFontAsCdna()) { - ((AlignViewport) ap.av.getCodingComplement()).antiAlias = ap.av.antiAlias; + ((AlignViewport) ap.av + .getCodingComplement()).antiAlias = ap.av.antiAlias; SplitFrame sv = (SplitFrame) ap.alignFrame.getSplitViewContainer(); sv.adjustLayout(); sv.repaint(); @@ -227,19 +246,24 @@ public class FontChooser extends GFontChooser @Override protected void cancel_actionPerformed() { - if (ap != null) + if (isTreeFont()) + { + tp.setTreeFont(oldFont); + } + else if (ap != null) { ap.av.setFont(oldFont, true); ap.av.setScaleProteinAsCdna(oldProteinScale); ap.av.setProteinFontAsCdna(oldMirrorFont); ap.av.antiAlias = oldSmoothFont; - ap.paintAlignment(true); + ap.fontChanged(); if (scaleAsCdna.isVisible() && scaleAsCdna.isEnabled()) { ap.av.getCodingComplement().setScaleProteinAsCdna(oldProteinScale); ap.av.getCodingComplement().setProteinFontAsCdna(oldMirrorFont); - ((AlignViewport) ap.av.getCodingComplement()).antiAlias = oldComplementSmooth; + ((AlignViewport) ap.av + .getCodingComplement()).antiAlias = oldComplementSmooth; ap.av.getCodingComplement().setFont(oldComplementFont, true); SplitFrame splitFrame = (SplitFrame) ap.alignFrame .getSplitViewContainer(); @@ -247,10 +271,6 @@ public class FontChooser extends GFontChooser splitFrame.repaint(); } } - else if (tp != null) - { - tp.setTreeFont(oldFont); - } try { @@ -260,6 +280,15 @@ public class FontChooser extends GFontChooser } } + private boolean isTreeFont() + { + return tp != null; + } + + private boolean isCapFont() + { + return cap != null; + } /** * DOCUMENT ME! */ @@ -284,8 +313,9 @@ public class FontChooser extends GFontChooser double iw = iBounds.getWidth(); if (mw < 1 || iw < 1) { - String message = iBounds.getHeight() < 1 ? MessageManager - .getString("label.font_doesnt_have_letters_defined") + String message = iBounds.getHeight() < 1 + ? MessageManager + .getString("label.font_doesnt_have_letters_defined") : MessageManager.getString("label.font_too_small"); JvOptionPane.showInternalMessageDialog(this, message, MessageManager.getString("label.invalid_font"), @@ -298,8 +328,8 @@ public class FontChooser extends GFontChooser { fontSize.setSelectedItem(lastSelected.getSize()); } - if (!lastSelected.getName().equals( - fontName.getSelectedItem().toString())) + if (!lastSelected.getName() + .equals(fontName.getSelectedItem().toString())) { fontName.setSelectedItem(lastSelected.getName()); } @@ -313,7 +343,7 @@ public class FontChooser extends GFontChooser } return; } - if (tp != null) + if (isTreeFont()) { tp.setTreeFont(newFont); } @@ -323,28 +353,27 @@ public class FontChooser extends GFontChooser ap.fontChanged(); /* - * adjust other half of split frame if any, if either same - * font, or proportionate scaling, is selected + * adjust other half of split frame if present, whether or not same font or + * scale to cDNA is selected, because a font change may affect character + * width, and this is kept the same in both panels */ - if (fontAsCdna.isEnabled()) + if (fontAsCdna.isVisible()) { if (fontAsCdna.isSelected()) { - /* - * copy the font - */ ap.av.getCodingComplement().setFont(newFont, true); } - /* - * adjust layout for font change / reset / sizing - */ SplitFrame splitFrame = (SplitFrame) ap.alignFrame .getSplitViewContainer(); splitFrame.adjustLayout(); splitFrame.repaint(); } } + else if (isCapFont()) + { + cap.setFont(newFont); + } monospaced.setSelected(mw == iw); @@ -421,8 +450,8 @@ public class FontChooser extends GFontChooser protected void scaleAsCdna_actionPerformed() { ap.av.setScaleProteinAsCdna(scaleAsCdna.isSelected()); - ap.av.getCodingComplement().setScaleProteinAsCdna( - scaleAsCdna.isSelected()); + ap.av.getCodingComplement() + .setScaleProteinAsCdna(scaleAsCdna.isSelected()); final SplitFrame splitFrame = (SplitFrame) ap.alignFrame .getSplitViewContainer(); splitFrame.adjustLayout();