X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFontChooser.java;h=9803822ecd1759c9d406af5d052569e90985d006;hb=0a1d49ccc421184b23bcb45cee901f5313913aa1;hp=b911d7d632afec839d3b8928a323749a682e4e95;hpb=588042b69abf8e60bcc950b24c283933c7dd422f;p=jalview.git diff --git a/src/jalview/gui/FontChooser.java b/src/jalview/gui/FontChooser.java index b911d7d..9803822 100755 --- a/src/jalview/gui/FontChooser.java +++ b/src/jalview/gui/FontChooser.java @@ -1,6 +1,6 @@ /* * Jalview - A Sequence Alignment Editor and Viewer - * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle + * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -18,132 +18,242 @@ */ package jalview.gui; +import jalview.bin.*; + +import jalview.jbgui.*; + import java.awt.*; import java.awt.event.*; + import javax.swing.*; -import jalview.bin.*; -import jalview.jbgui.*; -public class FontChooser - extends GFontChooser +/** + * DOCUMENT ME! + * + * @author $author$ + * @version $Revision$ + */ +public class FontChooser extends GFontChooser { - AlignmentPanel ap; - Font oldFont; - boolean init = true; - JInternalFrame frame; + AlignmentPanel ap; + TreePanel tp; + Font oldFont; + boolean init = true; + JInternalFrame frame; - public FontChooser(AlignmentPanel ap) - { - frame = new JInternalFrame(); - frame.setContentPane(this); - Desktop.addInternalFrame(frame, "Change Font", 480, 100, false); - frame.setLayer(JLayeredPane.PALETTE_LAYER); + /** + * Creates a new FontChooser object. + * + * @param ap DOCUMENT ME! + */ + public FontChooser(TreePanel tp) + { + this.tp = tp; + ap = tp.treeCanvas.ap; + oldFont = tp.getTreeFont(); + defaultButton.setVisible(false); + smoothFont.setEnabled(false); + init(); + } + /** + * Creates a new FontChooser object. + * + * @param ap DOCUMENT ME! + */ + public FontChooser(AlignmentPanel ap) + { + oldFont = ap.av.getFont(); + this.ap = ap; + init(); + } - this.ap = ap; + void init() + { + frame = new JInternalFrame(); + frame.setContentPane(this); - String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment() - .getAvailableFontFamilyNames(); + smoothFont.setSelected(ap.av.antiAlias); - for (int i = 0; i < fonts.length; i++) - { - fontName.addItem(fonts[i]); + if(tp!=null) + Desktop.addInternalFrame(frame, "Change Font (Tree Panel)", 340, 170, false); + else + Desktop.addInternalFrame(frame, "Change Font", 340, 170, false); + + frame.setLayer(JLayeredPane.PALETTE_LAYER); + + String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment() + .getAvailableFontFamilyNames(); + + for (int i = 0; i < fonts.length; i++) + { + fontName.addItem(fonts[i]); + } + + for (int i = 1; i < 51; i++) + { + fontSize.addItem(i + ""); + } + + fontStyle.addItem("plain"); + fontStyle.addItem("bold"); + fontStyle.addItem("italic"); + + fontName.setSelectedItem(oldFont.getName()); + fontSize.setSelectedItem(oldFont.getSize() + ""); + fontStyle.setSelectedIndex(oldFont.getStyle()); + + FontMetrics fm = getGraphics().getFontMetrics(oldFont); + monospaced.setSelected( fm.getStringBounds("M",getGraphics()).getWidth() + ==fm.getStringBounds("|",getGraphics()).getWidth()); + + + init = false; } - for (int i = 1; i < 31; i++) + public void smoothFont_actionPerformed(ActionEvent e) { - fontSize.addItem(i + ""); + ap.av.antiAlias = smoothFont.isSelected(); + ap.annotationPanel.image = null; + ap.repaint(); } - fontStyle.addItem("plain"); - fontStyle.addItem("bold"); - fontStyle.addItem("italic"); - oldFont = ap.av.getFont(); - fontName.setSelectedItem(oldFont.getName()); - fontSize.setSelectedItem(oldFont.getSize() + ""); - fontStyle.setSelectedIndex(oldFont.getStyle()); - init = false; - } - - protected void ok_actionPerformed(ActionEvent e) - { - try + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void ok_actionPerformed(ActionEvent e) { - frame.setClosed(true); + try + { + frame.setClosed(true); + } + catch (Exception ex) + { + } + + if(ap!=null) + { + if (ap.getOverviewPanel() != null) + { + ap.getOverviewPanel().updateOverviewImage(); + } + } } - catch (Exception ex) + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void cancel_actionPerformed(ActionEvent e) { + if(ap!=null) + { + ap.av.setFont(oldFont); + ap.repaint(); + } + else if(tp!=null) + { + tp.setTreeFont(oldFont); + } + fontName.setSelectedItem(oldFont.getName()); + fontSize.setSelectedItem(oldFont.getSize() + ""); + fontStyle.setSelectedIndex(oldFont.getStyle()); + + try + { + frame.setClosed(true); + } + catch (Exception ex) + { + } } - if (ap.getOverviewPanel() != null) + /** + * DOCUMENT ME! + */ + void changeFont() { - ap.getOverviewPanel().updateOverviewImage(); - } - } + Font newFont = new Font(fontName.getSelectedItem().toString(), + fontStyle.getSelectedIndex(), + Integer.parseInt(fontSize.getSelectedItem().toString())); + if(tp != null) + { + tp.setTreeFont(newFont); + } + else if(ap != null) + { + ap.av.setFont(newFont); + ap.fontChanged(); + } - protected void cancel_actionPerformed(ActionEvent e) - { - ap.av.setFont(oldFont); - ap.repaint(); - fontName.setSelectedItem(oldFont.getName()); - fontSize.setSelectedItem(oldFont.getSize() + ""); - fontStyle.setSelectedIndex(oldFont.getStyle()); - try - { - frame.setClosed(true); + FontMetrics fm = getGraphics().getFontMetrics(newFont); + + monospaced.setSelected( fm.getStringBounds("M",getGraphics()).getWidth() + ==fm.getStringBounds("|",getGraphics()).getWidth()); + } - catch (Exception ex) + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void fontName_actionPerformed(ActionEvent e) { + if (init) + { + return; + } + + changeFont(); } - } - - void changeFont() - { - Font newFont = new Font(fontName.getSelectedItem().toString(), - fontStyle.getSelectedIndex(), - Integer.parseInt(fontSize.getSelectedItem(). - toString())); - ap.av.setFont(newFont); - ap.fontChanged(); - } - - protected void fontName_actionPerformed(ActionEvent e) - { - if (init) + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void fontSize_actionPerformed(ActionEvent e) { - return; - } + if (init) + { + return; + } - changeFont(); - } + changeFont(); + } - protected void fontSize_actionPerformed(ActionEvent e) - { - if (init) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void fontStyle_actionPerformed(ActionEvent e) { - return; - } + if (init) + { + return; + } - changeFont(); - } + changeFont(); + } - protected void fontStyle_actionPerformed(ActionEvent e) - { - if (init) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + public void defaultButton_actionPerformed(ActionEvent e) { - return; + Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString()); + Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + ""); + Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString()); + Cache.setProperty("ANTI_ALIAS", Boolean.toString(smoothFont.isSelected())); } - - changeFont(); - } - - public void defaultButton_actionPerformed(ActionEvent e) - { - Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString()); - Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + ""); - Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString()); - } }