Change fonts in Treepanel
authoramwaterhouse <Andrew Waterhouse>
Wed, 14 Sep 2005 11:22:13 +0000 (11:22 +0000)
committeramwaterhouse <Andrew Waterhouse>
Wed, 14 Sep 2005 11:22:13 +0000 (11:22 +0000)
src/jalview/gui/FontChooser.java

index 527bf5d..98d3ecb 100755 (executable)
@@ -37,6 +37,7 @@ import javax.swing.*;
 public class FontChooser extends GFontChooser\r
 {\r
     AlignmentPanel ap;\r
+    TreePanel tp;\r
     Font oldFont;\r
     boolean init = true;\r
     JInternalFrame frame;\r
@@ -46,14 +47,35 @@ public class FontChooser extends GFontChooser
      *\r
      * @param ap DOCUMENT ME!\r
      */\r
+    public FontChooser(TreePanel tp)\r
+    {\r
+      this.tp = tp;\r
+      oldFont = tp.getFont();\r
+      defaultButton.setVisible(false);\r
+      init();\r
+    }\r
+    /**\r
+     * Creates a new FontChooser object.\r
+     *\r
+     * @param ap DOCUMENT ME!\r
+     */\r
     public FontChooser(AlignmentPanel ap)\r
     {\r
+      oldFont = ap.av.getFont();\r
+      this.ap = ap;\r
+      init();\r
+    }\r
+\r
+    void init()\r
+    {\r
         frame = new JInternalFrame();\r
         frame.setContentPane(this);\r
-        Desktop.addInternalFrame(frame, "Change Font", 480, 100, false);\r
-        frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
+        if(tp!=null)\r
+           Desktop.addInternalFrame(frame, "Change Font (Tree Panel)", 480, 100, false);\r
+        else\r
+           Desktop.addInternalFrame(frame, "Change Font", 480, 100, false);\r
 \r
-        this.ap = ap;\r
+        frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
 \r
         String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()\r
                                                      .getAvailableFontFamilyNames();\r
@@ -72,7 +94,6 @@ public class FontChooser extends GFontChooser
         fontStyle.addItem("bold");\r
         fontStyle.addItem("italic");\r
 \r
-        oldFont = ap.av.getFont();\r
         fontName.setSelectedItem(oldFont.getName());\r
         fontSize.setSelectedItem(oldFont.getSize() + "");\r
         fontStyle.setSelectedIndex(oldFont.getStyle());\r
@@ -95,9 +116,12 @@ public class FontChooser extends GFontChooser
         {\r
         }\r
 \r
-        if (ap.getOverviewPanel() != null)\r
+        if(ap!=null)\r
         {\r
+          if (ap.getOverviewPanel() != null)\r
+          {\r
             ap.getOverviewPanel().updateOverviewImage();\r
+          }\r
         }\r
     }\r
 \r
@@ -108,8 +132,15 @@ public class FontChooser extends GFontChooser
      */\r
     protected void cancel_actionPerformed(ActionEvent e)\r
     {\r
-        ap.av.setFont(oldFont);\r
-        ap.repaint();\r
+        if(ap!=null)\r
+        {\r
+          ap.av.setFont(oldFont);\r
+          ap.repaint();\r
+        }\r
+        else if(tp!=null)\r
+        {\r
+          tp.setFont(oldFont);\r
+        }\r
         fontName.setSelectedItem(oldFont.getName());\r
         fontSize.setSelectedItem(oldFont.getSize() + "");\r
         fontStyle.setSelectedIndex(oldFont.getStyle());\r
@@ -128,11 +159,18 @@ public class FontChooser extends GFontChooser
      */\r
     void changeFont()\r
     {\r
-        Font newFont = new Font(fontName.getSelectedItem().toString(),\r
-                fontStyle.getSelectedIndex(),\r
-                Integer.parseInt(fontSize.getSelectedItem().toString()));\r
+      Font newFont = new Font(fontName.getSelectedItem().toString(),\r
+                              fontStyle.getSelectedIndex(),\r
+                              Integer.parseInt(fontSize.getSelectedItem().toString()));\r
+      if (ap != null)\r
+      {\r
         ap.av.setFont(newFont);\r
         ap.fontChanged();\r
+      }\r
+      else if(tp != null)\r
+      {\r
+        tp.setFont(newFont);\r
+      }\r
     }\r
 \r
     /**\r