X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFontChooser.java;h=6eab36b69fad10ace1c83ae8ff5ebd95a4ffcb3c;hb=3bdd4947c87108581abe34d05c878ee110b60f72;hp=b911d7d632afec839d3b8928a323749a682e4e95;hpb=588042b69abf8e60bcc950b24c283933c7dd422f;p=jalview.git diff --git a/src/jalview/gui/FontChooser.java b/src/jalview/gui/FontChooser.java index b911d7d..6eab36b 100755 --- a/src/jalview/gui/FontChooser.java +++ b/src/jalview/gui/FontChooser.java @@ -18,132 +18,226 @@ */ 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; + + /** + * Creates a new FontChooser object. + * + * @param ap DOCUMENT ME! + */ + public FontChooser(TreePanel tp) + { + this.tp = tp; + oldFont = tp.getTreeFont(); + defaultButton.setVisible(false); + init(); + } + /** + * Creates a new FontChooser object. + * + * @param ap DOCUMENT ME! + */ + public FontChooser(AlignmentPanel ap) + { + oldFont = ap.av.getFont(); + this.ap = ap; + init(); + } - public FontChooser(AlignmentPanel ap) - { - frame = new JInternalFrame(); - frame.setContentPane(this); - Desktop.addInternalFrame(frame, "Change Font", 480, 100, false); - frame.setLayer(JLayeredPane.PALETTE_LAYER); + void init() + { + frame = new JInternalFrame(); + frame.setContentPane(this); + if(tp!=null) + Desktop.addInternalFrame(frame, "Change Font (Tree Panel)", 540, 100, false); + else + Desktop.addInternalFrame(frame, "Change Font", 540, 100, false); - this.ap = ap; + frame.setLayer(JLayeredPane.PALETTE_LAYER); - String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment() - .getAvailableFontFamilyNames(); + String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment() + .getAvailableFontFamilyNames(); - for (int i = 0; i < fonts.length; i++) - { - fontName.addItem(fonts[i]); - } + for (int i = 0; i < fonts.length; i++) + { + fontName.addItem(fonts[i]); + } - for (int i = 1; i < 31; i++) - { - fontSize.addItem(i + ""); - } + for (int i = 1; i < 51; i++) + { + fontSize.addItem(i + ""); + } - fontStyle.addItem("plain"); - fontStyle.addItem("bold"); - fontStyle.addItem("italic"); + 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()); + fontName.setSelectedItem(oldFont.getName()); + fontSize.setSelectedItem(oldFont.getSize() + ""); + fontStyle.setSelectedIndex(oldFont.getStyle()); - init = false; - } + FontMetrics fm = getGraphics().getFontMetrics(oldFont); + monospaced.setSelected( fm.getStringBounds("M",getGraphics()).getWidth() + ==fm.getStringBounds("|",getGraphics()).getWidth()); - protected void ok_actionPerformed(ActionEvent e) - { - try - { - frame.setClosed(true); + + init = false; } - catch (Exception ex) + + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void ok_actionPerformed(ActionEvent e) { + try + { + frame.setClosed(true); + } + catch (Exception ex) + { + } + + if(ap!=null) + { + if (ap.getOverviewPanel() != null) + { + ap.getOverviewPanel().updateOverviewImage(); + } + } } - if (ap.getOverviewPanel() != null) + /** + * DOCUMENT ME! + * + * @param e DOCUMENT ME! + */ + protected void cancel_actionPerformed(ActionEvent e) { - ap.getOverviewPanel().updateOverviewImage(); + 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) + { + } } - } - - 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 + /** + * DOCUMENT ME! + */ + void changeFont() { - frame.setClosed(true); + Font newFont = new Font(fontName.getSelectedItem().toString(), + fontStyle.getSelectedIndex(), + Integer.parseInt(fontSize.getSelectedItem().toString())); + if (ap != null) + { + ap.av.setFont(newFont); + ap.fontChanged(); + } + else if(tp != null) + { + tp.setTreeFont(newFont); + } + + 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()); } - - 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()); - } }