/*\r
* Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
*\r
* This program is free software; you can redistribute it and/or\r
* modify it under the terms of the GNU General Public License\r
*/\r
package jalview.gui;\r
\r
-import jalview.bin.*;\r
-\r
-import jalview.jbgui.*;\r
-\r
import java.awt.*;\r
import java.awt.event.*;\r
-\r
import javax.swing.*;\r
\r
+import jalview.bin.*;\r
+import jalview.jbgui.*;\r
\r
/**\r
* DOCUMENT ME!\r
* @author $author$\r
* @version $Revision$\r
*/\r
-public class FontChooser extends GFontChooser\r
+public class FontChooser\r
+ extends GFontChooser\r
{\r
- AlignmentPanel ap;\r
- TreePanel tp;\r
- Font oldFont;\r
- boolean init = true;\r
- JInternalFrame frame;\r
-\r
- /**\r
- * Creates a new FontChooser object.\r
- *\r
- * @param ap DOCUMENT ME!\r
- */\r
- public FontChooser(TreePanel tp)\r
- {\r
- this.tp = tp;\r
- oldFont = tp.getTreeFont();\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
- 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
- frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
-\r
- String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()\r
- .getAvailableFontFamilyNames();\r
-\r
- for (int i = 0; i < fonts.length; i++)\r
- {\r
- fontName.addItem(fonts[i]);\r
- }\r
-\r
- for (int i = 1; i < 31; i++)\r
- {\r
- fontSize.addItem(i + "");\r
- }\r
-\r
- fontStyle.addItem("plain");\r
- fontStyle.addItem("bold");\r
- fontStyle.addItem("italic");\r
-\r
- fontName.setSelectedItem(oldFont.getName());\r
- fontSize.setSelectedItem(oldFont.getSize() + "");\r
- fontStyle.setSelectedIndex(oldFont.getStyle());\r
-\r
- init = false;\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void ok_actionPerformed(ActionEvent e)\r
- {\r
- try\r
- {\r
- frame.setClosed(true);\r
- }\r
- catch (Exception ex)\r
- {\r
- }\r
-\r
- if(ap!=null)\r
- {\r
- if (ap.getOverviewPanel() != null)\r
- {\r
- ap.getOverviewPanel().updateOverviewImage();\r
- }\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void cancel_actionPerformed(ActionEvent e)\r
- {\r
- if(ap!=null)\r
- {\r
- ap.av.setFont(oldFont);\r
- ap.repaint();\r
- }\r
- else if(tp!=null)\r
- {\r
- tp.setTreeFont(oldFont);\r
- }\r
- fontName.setSelectedItem(oldFont.getName());\r
- fontSize.setSelectedItem(oldFont.getSize() + "");\r
- fontStyle.setSelectedIndex(oldFont.getStyle());\r
-\r
- try\r
- {\r
- frame.setClosed(true);\r
- }\r
- catch (Exception ex)\r
- {\r
- }\r
- }\r
-\r
- /**\r
- * DOCUMENT ME!\r
- */\r
- void changeFont()\r
- {\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
+ AlignmentPanel ap;\r
+ TreePanel tp;\r
+ Font oldFont;\r
+ boolean init = true;\r
+ JInternalFrame frame;\r
+\r
+ /**\r
+ * Creates a new FontChooser object.\r
+ *\r
+ * @param ap DOCUMENT ME!\r
+ */\r
+ public FontChooser(TreePanel tp)\r
+ {\r
+ this.tp = tp;\r
+ ap = tp.treeCanvas.ap;\r
+ oldFont = tp.getTreeFont();\r
+ defaultButton.setVisible(false);\r
+ smoothFont.setEnabled(false);\r
+ init();\r
+ }\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
+\r
+ smoothFont.setSelected(ap.av.antiAlias);\r
+\r
+ if (tp != null)\r
+ {\r
+ Desktop.addInternalFrame(frame, "Change Font (Tree Panel)", 340, 170, false);\r
+ }\r
+ else\r
+ {\r
+ Desktop.addInternalFrame(frame, "Change Font", 340, 170, false);\r
+ }\r
+\r
+ frame.setLayer(JLayeredPane.PALETTE_LAYER);\r
+\r
+ String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()\r
+ .getAvailableFontFamilyNames();\r
+\r
+ for (int i = 0; i < fonts.length; i++)\r
+ {\r
+ fontName.addItem(fonts[i]);\r
+ }\r
+\r
+ for (int i = 1; i < 51; i++)\r
+ {\r
+ fontSize.addItem(i + "");\r
+ }\r
+\r
+ fontStyle.addItem("plain");\r
+ fontStyle.addItem("bold");\r
+ fontStyle.addItem("italic");\r
+\r
+ fontName.setSelectedItem(oldFont.getName());\r
+ fontSize.setSelectedItem(oldFont.getSize() + "");\r
+ fontStyle.setSelectedIndex(oldFont.getStyle());\r
+\r
+ FontMetrics fm = getGraphics().getFontMetrics(oldFont);\r
+ monospaced.setSelected(fm.getStringBounds("M", getGraphics()).getWidth()\r
+ == fm.getStringBounds("|", getGraphics()).getWidth());\r
+\r
+ init = false;\r
+ }\r
+\r
+ public void smoothFont_actionPerformed(ActionEvent e)\r
+ {\r
+ ap.av.antiAlias = smoothFont.isSelected();\r
+ ap.annotationPanel.image = null;\r
+ ap.paintAlignment(true);\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void ok_actionPerformed(ActionEvent e)\r
+ {\r
+ try\r
+ {\r
+ frame.setClosed(true);\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ }\r
+\r
+ if (ap != null)\r
+ {\r
+ if (ap.getOverviewPanel() != null)\r
{\r
- tp.setTreeFont(newFont);\r
+ ap.getOverviewPanel().updateOverviewImage();\r
}\r
}\r
+ }\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void fontName_actionPerformed(ActionEvent e)\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void cancel_actionPerformed(ActionEvent e)\r
+ {\r
+ if (ap != null)\r
{\r
- if (init)\r
- {\r
- return;\r
- }\r
-\r
- changeFont();\r
+ ap.av.setFont(oldFont);\r
+ ap.paintAlignment(true);\r
}\r
+ else if (tp != null)\r
+ {\r
+ tp.setTreeFont(oldFont);\r
+ }\r
+ fontName.setSelectedItem(oldFont.getName());\r
+ fontSize.setSelectedItem(oldFont.getSize() + "");\r
+ fontStyle.setSelectedIndex(oldFont.getStyle());\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void fontSize_actionPerformed(ActionEvent e)\r
+ try\r
+ {\r
+ frame.setClosed(true);\r
+ }\r
+ catch (Exception ex)\r
{\r
- if (init)\r
- {\r
- return;\r
- }\r
+ }\r
+ }\r
\r
- changeFont();\r
+ /**\r
+ * DOCUMENT ME!\r
+ */\r
+ void changeFont()\r
+ {\r
+ Font newFont = new Font(fontName.getSelectedItem().toString(),\r
+ fontStyle.getSelectedIndex(),\r
+ Integer.parseInt(fontSize.getSelectedItem().\r
+ toString()));\r
+ if (tp != null)\r
+ {\r
+ tp.setTreeFont(newFont);\r
}\r
+ else if (ap != null)\r
+ {\r
+ ap.av.setFont(newFont);\r
+ ap.fontChanged();\r
+ }\r
+\r
+ FontMetrics fm = getGraphics().getFontMetrics(newFont);\r
+\r
+ monospaced.setSelected(fm.getStringBounds("M", getGraphics()).getWidth()\r
+ == fm.getStringBounds("|", getGraphics()).getWidth());\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- protected void fontStyle_actionPerformed(ActionEvent e)\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void fontName_actionPerformed(ActionEvent e)\r
+ {\r
+ if (init)\r
{\r
- if (init)\r
- {\r
- return;\r
- }\r
+ return;\r
+ }\r
\r
- changeFont();\r
+ changeFont();\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void fontSize_actionPerformed(ActionEvent e)\r
+ {\r
+ if (init)\r
+ {\r
+ return;\r
}\r
\r
- /**\r
- * DOCUMENT ME!\r
- *\r
- * @param e DOCUMENT ME!\r
- */\r
- public void defaultButton_actionPerformed(ActionEvent e)\r
+ changeFont();\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ protected void fontStyle_actionPerformed(ActionEvent e)\r
+ {\r
+ if (init)\r
{\r
- Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString());\r
- Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + "");\r
- Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());\r
+ return;\r
}\r
+\r
+ changeFont();\r
+ }\r
+\r
+ /**\r
+ * DOCUMENT ME!\r
+ *\r
+ * @param e DOCUMENT ME!\r
+ */\r
+ public void defaultButton_actionPerformed(ActionEvent e)\r
+ {\r
+ Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString());\r
+ Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + "");\r
+ Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());\r
+ Cache.setProperty("ANTI_ALIAS", Boolean.toString(smoothFont.isSelected()));\r
+ }\r
}\r