X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fappletgui%2FFontChooser.java;h=59f6957948d255635e61c1372c73b62c43c70192;hb=d82ec00f14199ef0ce21bd5bc70a59142b7c4b07;hp=42b18507b4002a3433d6695e1f25bf3b64ab6e5f;hpb=d423f22792e47dbc800ae220a58677f988971d06;p=jalview.git
diff --git a/src/jalview/appletgui/FontChooser.java b/src/jalview/appletgui/FontChooser.java
old mode 100755
new mode 100644
index 42b1850..59f6957
--- a/src/jalview/appletgui/FontChooser.java
+++ b/src/jalview/appletgui/FontChooser.java
@@ -1,38 +1,93 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
* Jalview is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- *
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
* Jalview is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.appletgui;
-import java.awt.*;
-import java.awt.event.*;
-
-public class FontChooser extends Panel implements ActionListener,
- ItemListener
+import jalview.api.ViewStyleI;
+import jalview.util.MessageManager;
+
+import java.awt.BorderLayout;
+import java.awt.Button;
+import java.awt.Checkbox;
+import java.awt.Choice;
+import java.awt.Color;
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Frame;
+import java.awt.Label;
+import java.awt.Panel;
+import java.awt.Toolkit;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+/**
+ * This dialog allows the user to try different font settings and related
+ * options. Changes are immediately visible on the alignment or tree. The user
+ * can dismiss the dialog by confirming changes with 'OK', or reverting to
+ * previous settings with 'Cancel'.
+ */
+@SuppressWarnings("serial")
+public class FontChooser extends Panel implements ItemListener
{
- AlignmentPanel ap;
+ private static final Font VERDANA_11PT = new Font("Verdana", 0, 11);
+
+ private Choice fontSize = new Choice();
+
+ private Choice fontStyle = new Choice();
+
+ private Choice fontName = new Choice();
+
+ private Checkbox scaleAsCdna = new Checkbox();
+
+ private Button ok = new Button();
+
+ private Button cancel = new Button();
+
+ private AlignmentPanel ap;
- TreePanel tp;
+ private TreePanel tp;
- Font oldFont;
+ private Font oldFont;
- boolean init = true;
+ private int oldCharWidth = 0;
- Frame frame;
+ private boolean oldScaleProtein = false;
+ private Font lastSelected = null;
+
+ private int lastSelStyle = 0;
+
+ private int lastSelSize = 0;
+
+ private boolean init = true;
+
+ private Frame frame;
+
+ /**
+ * Constructor for a TreePanel font chooser
+ *
+ * @param tp
+ */
public FontChooser(TreePanel tp)
{
try
@@ -48,8 +103,18 @@ public class FontChooser extends Panel implements ActionListener,
init();
}
+ /**
+ * Constructor for an AlignmentPanel font chooser
+ *
+ * @param ap
+ */
public FontChooser(AlignmentPanel ap)
{
+ this.ap = ap;
+ oldFont = ap.av.getFont();
+ oldCharWidth = ap.av.getViewStyle().getCharWidth();
+ oldScaleProtein = ap.av.getViewStyle().isScaleProteinAsCdna();
+
try
{
jbInit();
@@ -57,12 +122,12 @@ public class FontChooser extends Panel implements ActionListener,
{
e.printStackTrace();
}
-
- this.ap = ap;
- oldFont = ap.av.getFont();
init();
}
+ /**
+ * Populate choice lists and open this dialog
+ */
void init()
{
String fonts[] = Toolkit.getDefaultToolkit().getFontList();
@@ -84,42 +149,42 @@ public class FontChooser extends Panel implements ActionListener,
fontSize.select(oldFont.getSize() + "");
fontStyle.select(oldFont.getStyle());
- Frame frame = new Frame();
- this.frame = frame;
+ this.frame = new Frame();
frame.add(this);
- jalview.bin.JalviewLite.addFrame(frame, "Change Font", 440, 115);
+ jalview.bin.JalviewLite.addFrame(frame,
+ MessageManager.getString("action.change_font"), 440, 115);
init = false;
}
- public void actionPerformed(ActionEvent evt)
- {
- if (evt.getSource() == ok)
- {
- ok_actionPerformed();
- }
- else if (evt.getSource() == cancel)
- {
- cancel_actionPerformed();
- }
- }
-
+ /**
+ * Actions on change of font name, size or style.
+ */
public void itemStateChanged(ItemEvent evt)
{
- if (evt.getSource() == fontName)
+ final Object source = evt.getSource();
+ if (source == fontName)
{
fontName_actionPerformed();
}
- else if (evt.getSource() == fontSize)
+ else if (source == fontSize)
{
fontSize_actionPerformed();
}
- else if (evt.getSource() == fontStyle)
+ else if (source == fontStyle)
{
fontStyle_actionPerformed();
}
+ else if (source == scaleAsCdna)
+ {
+ scaleAsCdna_actionPerformed();
+ }
}
+ /**
+ * Close this dialog on OK to confirm any changes. Also updates the overview
+ * window if displayed.
+ */
protected void ok_actionPerformed()
{
frame.setVisible(false);
@@ -130,14 +195,29 @@ public class FontChooser extends Panel implements ActionListener,
ap.getOverviewPanel().updateOverviewImage();
}
}
-
}
+ /**
+ * Close this dialog on Cancel, reverting to previous font settings.
+ */
protected void cancel_actionPerformed()
{
if (ap != null)
{
+ ap.av.setScaleProteinAsCdna(oldScaleProtein);
+ if (ap.av.getCodingComplement() != null)
+ {
+ ap.av.getCodingComplement().setScaleProteinAsCdna(oldScaleProtein);
+ ap.alignFrame.getSplitFrame().repaint();
+ }
+
ap.av.setFont(oldFont);
+ ViewStyleI style = ap.av.getViewStyle();
+ if (style.getCharWidth() != oldCharWidth)
+ {
+ style.setCharWidth(oldCharWidth);
+ ap.av.setViewStyle(style);
+ }
ap.paintAlignment(true);
}
else if (tp != null)
@@ -153,20 +233,54 @@ public class FontChooser extends Panel implements ActionListener,
frame.setVisible(false);
}
+ /**
+ * DOCUMENT ME!
+ */
void changeFont()
{
+ if (lastSelected == null)
+ {
+ // initialise with original font
+ lastSelected = oldFont;
+ lastSelSize = oldFont.getSize();
+ lastSelStyle = oldFont.getStyle();
+ }
+
Font newFont = new Font(fontName.getSelectedItem().toString(),
fontStyle.getSelectedIndex(), Integer.parseInt(fontSize
.getSelectedItem().toString()));
- if (ap != null)
+ FontMetrics fm = getGraphics().getFontMetrics(newFont);
+ double mw = fm.getStringBounds("M", getGraphics()).getWidth(), iw = fm
+ .getStringBounds("I", getGraphics()).getWidth();
+ if (mw < 1 || iw < 1)
{
- ap.av.setFont(newFont);
- ap.fontChanged();
+ // TODO: JAL-1100
+ fontName.select(lastSelected.getName());
+ fontStyle.select(lastSelStyle);
+ fontSize.select("" + lastSelSize);
+ JVDialog d = new JVDialog(this.frame,
+ MessageManager.getString("label.invalid_font"), true, 350,
+ 200);
+ Panel mp = new Panel();
+ d.cancel.setVisible(false);
+ mp.setLayout(new FlowLayout());
+ mp.add(new Label(
+ "Font doesn't have letters defined\nso cannot be used\nwith alignment data."));
+ d.setMainPanel(mp);
+ d.setVisible(true);
+ return;
}
- else if (tp != null)
+ if (tp != null)
{
tp.setTreeFont(newFont);
}
+ else if (ap != null)
+ {
+ ap.av.setFont(newFont);
+ ap.fontChanged();
+ }
+ // remember last selected
+ lastSelected = newFont;
}
protected void fontName_actionPerformed()
@@ -196,86 +310,115 @@ public class FontChooser extends Panel implements ActionListener,
changeFont();
}
- Label label1 = new Label();
-
- protected Choice fontSize = new Choice();
-
- protected Choice fontStyle = new Choice();
-
- Label label2 = new Label();
-
- Label label3 = new Label();
-
- protected Choice fontName = new Choice();
-
- Button ok = new Button();
-
- Button cancel = new Button();
-
- Panel panel1 = new Panel();
-
- Panel panel2 = new Panel();
-
- Panel panel3 = new Panel();
+ /**
+ * Construct this panel's contents
+ *
+ * @throws Exception
+ */
+ private void jbInit() throws Exception
+ {
+ this.setLayout(new BorderLayout());
+ this.setBackground(Color.white);
- BorderLayout borderLayout1 = new BorderLayout();
+ Label fontLabel = new Label(MessageManager.getString("label.font"));
+ fontLabel.setFont(VERDANA_11PT);
+ fontLabel.setAlignment(Label.RIGHT);
+ fontSize.setFont(VERDANA_11PT);
+ fontSize.addItemListener(this);
+ fontStyle.setFont(VERDANA_11PT);
+ fontStyle.addItemListener(this);
- BorderLayout borderLayout2 = new BorderLayout();
+ Label sizeLabel = new Label(MessageManager.getString("label.size"));
+ sizeLabel.setAlignment(Label.RIGHT);
+ sizeLabel.setFont(VERDANA_11PT);
- BorderLayout borderLayout3 = new BorderLayout();
+ Label styleLabel = new Label(MessageManager.getString("label.style"));
+ styleLabel.setAlignment(Label.RIGHT);
+ styleLabel.setFont(VERDANA_11PT);
- Panel panel4 = new Panel();
+ fontName.setFont(VERDANA_11PT);
+ fontName.addItemListener(this);
- Panel panel5 = new Panel();
+ scaleAsCdna.setLabel(MessageManager.getString("label.scale_as_cdna"));
+ scaleAsCdna.setFont(VERDANA_11PT);
+ scaleAsCdna.addItemListener(this);
+ scaleAsCdna.setState(ap.av.isScaleProteinAsCdna());
- BorderLayout borderLayout4 = new BorderLayout();
+ ok.setFont(VERDANA_11PT);
+ ok.setLabel(MessageManager.getString("action.ok"));
+ ok.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ ok_actionPerformed();
+ }
+ });
+ cancel.setFont(VERDANA_11PT);
+ cancel.setLabel(MessageManager.getString("action.cancel"));
+ cancel.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ cancel_actionPerformed();
+ }
+ });
+
+ Panel fontPanel = new Panel();
+ fontPanel.setLayout(new BorderLayout());
+ Panel stylePanel = new Panel();
+ stylePanel.setLayout(new BorderLayout());
+ Panel sizePanel = new Panel();
+ sizePanel.setLayout(new BorderLayout());
+ Panel scalePanel = new Panel();
+ scalePanel.setLayout(new BorderLayout());
+ Panel okCancelPanel = new Panel();
+ Panel optionsPanel = new Panel();
+
+ fontPanel.setBackground(Color.white);
+ stylePanel.setBackground(Color.white);
+ sizePanel.setBackground(Color.white);
+ okCancelPanel.setBackground(Color.white);
+ optionsPanel.setBackground(Color.white);
+
+ fontPanel.add(fontLabel, BorderLayout.WEST);
+ fontPanel.add(fontName, BorderLayout.CENTER);
+ stylePanel.add(styleLabel, BorderLayout.WEST);
+ stylePanel.add(fontStyle, BorderLayout.CENTER);
+ sizePanel.add(sizeLabel, BorderLayout.WEST);
+ sizePanel.add(fontSize, BorderLayout.CENTER);
+ scalePanel.add(scaleAsCdna, BorderLayout.CENTER);
+ okCancelPanel.add(ok, null);
+ okCancelPanel.add(cancel, null);
+
+ optionsPanel.add(fontPanel, null);
+ optionsPanel.add(sizePanel, null);
+ optionsPanel.add(stylePanel, null);
+
+ /*
+ * Only show 'scale protein as cDNA' in a SplitFrame
+ */
+ this.add(optionsPanel, BorderLayout.NORTH);
+ if (ap.alignFrame.getSplitFrame() != null)
+ {
+ this.add(scalePanel, BorderLayout.CENTER);
+ }
+ this.add(okCancelPanel, BorderLayout.SOUTH);
+ }
- private void jbInit() throws Exception
+ /**
+ * Turn on/off scaling of protein characters to 3 times the width of cDNA
+ * characters
+ */
+ protected void scaleAsCdna_actionPerformed()
{
- label1.setFont(new java.awt.Font("Verdana", 0, 11));
- label1.setAlignment(Label.RIGHT);
- label1.setText("Font: ");
- this.setLayout(borderLayout4);
- fontSize.setFont(new java.awt.Font("Verdana", 0, 11));
- fontSize.addItemListener(this);
- fontStyle.setFont(new java.awt.Font("Verdana", 0, 11));
- fontStyle.addItemListener(this);
- label2.setAlignment(Label.RIGHT);
- label2.setFont(new java.awt.Font("Verdana", 0, 11));
- label2.setText("Size: ");
- label3.setAlignment(Label.RIGHT);
- label3.setFont(new java.awt.Font("Verdana", 0, 11));
- label3.setText("Style: ");
- fontName.setFont(new java.awt.Font("Verdana", 0, 11));
- fontName.addItemListener(this);
- ok.setFont(new java.awt.Font("Verdana", 0, 11));
- ok.setLabel("OK");
- ok.addActionListener(this);
- cancel.setFont(new java.awt.Font("Verdana", 0, 11));
- cancel.setLabel("Cancel");
- cancel.addActionListener(this);
- this.setBackground(Color.white);
- panel1.setLayout(borderLayout1);
- panel2.setLayout(borderLayout3);
- panel3.setLayout(borderLayout2);
- panel5.setBackground(Color.white);
- panel4.setBackground(Color.white);
- panel1.setBackground(Color.white);
- panel2.setBackground(Color.white);
- panel3.setBackground(Color.white);
- panel1.add(label1, BorderLayout.WEST);
- panel1.add(fontName, BorderLayout.CENTER);
- panel5.add(panel1, null);
- panel5.add(panel3, null);
- panel5.add(panel2, null);
- panel2.add(label3, BorderLayout.WEST);
- panel2.add(fontStyle, BorderLayout.CENTER);
- panel3.add(label2, BorderLayout.WEST);
- panel3.add(fontSize, BorderLayout.CENTER);
- this.add(panel4, BorderLayout.SOUTH);
- panel4.add(ok, null);
- panel4.add(cancel, null);
- this.add(panel5, BorderLayout.CENTER);
+ ap.av.setScaleProteinAsCdna(scaleAsCdna.getState());
+ ap.av.getCodingComplement().setScaleProteinAsCdna(
+ scaleAsCdna.getState());
+ ap.alignFrame.getSplitFrame().adjustLayout();
+ ap.paintAlignment(true);
+ ap.alignFrame.getSplitFrame().repaint();
}
}