X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2FFontChooser.java;h=966a461f9fa46891dc3adc9bc81fc4c95db77511;hb=eb22dac14771c467104f57362e3a624d0140f897;hp=d319fa14af1ef868885422a244c3ae04bf9f5645;hpb=ccf4c584032d16ed0ed8d0678f01305887724f96;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/FontChooser.java b/forester/java/src/org/forester/archaeopteryx/FontChooser.java index d319fa1..966a461 100644 --- a/forester/java/src/org/forester/archaeopteryx/FontChooser.java +++ b/forester/java/src/org/forester/archaeopteryx/FontChooser.java @@ -9,7 +9,7 @@ // by: James Bardsley (torasin@torasin.com) // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.archaeopteryx; @@ -49,9 +49,9 @@ public class FontChooser extends JDialog implements ActionListener, ListSelectio private String _type; private int _style; private int _size; - private final JList _font_list = new JList( Util.getAvailableFontFamiliesSorted() ); - private final JList _style_list = new JList( STYLE ); - private final JList _size_list = new JList( SIZE ); + private final JList _font_list = new JList( AptxUtil.getAvailableFontFamiliesSorted() ); + private final JList _style_list = new JList( STYLE ); + private final JList _size_list = new JList( SIZE ); private final JTextField _fonts_tf = new JTextField(); private final JTextField _style_tf = new JTextField(); private final JTextField _size_tf = new JTextField(); @@ -126,12 +126,13 @@ public class FontChooser extends JDialog implements ActionListener, ListSelectio this( new Font( font_name, font_style, size ) ); } + @Override public void actionPerformed( final ActionEvent e ) { if ( e.getSource() == _fonts_tf ) { boolean found = false; _type = _fonts_tf.getText(); for( int i = 0; i < _font_list.getModel().getSize(); i++ ) { - if ( ( ( String ) _font_list.getModel().getElementAt( i ) ).startsWith( _fonts_tf.getText().trim() ) ) { + if ( _font_list.getModel().getElementAt( i ).startsWith( _fonts_tf.getText().trim() ) ) { _font_list.setSelectedIndex( i ); setScrollPos( _font_jsp, _font_list, i ); found = true; @@ -206,28 +207,11 @@ public class FontChooser extends JDialog implements ActionListener, ListSelectio return _font.getStyle(); } - private void parseSize() { - try { - _size = ( Integer.parseInt( _size_tf.getText().trim() ) ); - } - catch ( final Exception ex ) { - // Ignore. - } - if ( _size < 1 ) { - _size = 1; - } - } - @Override public void setFont( final Font font ) { _font = font; } - private void setScrollPos( final JScrollPane sp, final JList list, final int index ) { - final int unit_size = sp.getVerticalScrollBar().getMaximum() / list.getModel().getSize(); - sp.getVerticalScrollBar().setValue( ( index - 2 ) * unit_size ); - } - public int showDialog( final Component parent, final String title ) { boolean found = false; _option = CANCEL_OPTION; @@ -248,7 +232,7 @@ public class FontChooser extends JDialog implements ActionListener, ListSelectio found = false; for( int i = 0; i < _size_list.getModel().getSize(); i++ ) { _size_list.setSelectedIndex( i ); - if ( _font.getSize() <= Integer.parseInt( ( String ) _size_list.getSelectedValue() ) ) { + if ( _font.getSize() <= Integer.parseInt( _size_list.getSelectedValue() ) ) { found = true; setScrollPos( _size_jsp, _size_list, i ); break; @@ -262,16 +246,17 @@ public class FontChooser extends JDialog implements ActionListener, ListSelectio return _option; } + @Override public void valueChanged( final ListSelectionEvent e ) { if ( e.getSource() == _font_list ) { if ( _font_list.getSelectedValue() != null ) { - _fonts_tf.setText( ( ( String ) ( _font_list.getSelectedValue() ) ) ); + _fonts_tf.setText( ( ( _font_list.getSelectedValue() ) ) ); } _type = _fonts_tf.getText(); _test_tf.setFont( new Font( _type, _style, _size ) ); } else if ( e.getSource() == _style_list ) { - _style_tf.setText( ( ( String ) ( _style_list.getSelectedValue() ) ) ); + _style_tf.setText( ( ( _style_list.getSelectedValue() ) ) ); if ( _style_tf.getText().equals( REGULAR ) ) { _style = 0; } @@ -288,10 +273,27 @@ public class FontChooser extends JDialog implements ActionListener, ListSelectio } else if ( e.getSource() == _size_list ) { if ( _size_list.getSelectedValue() != null ) { - _size_tf.setText( ( ( String ) ( _size_list.getSelectedValue() ) ) ); + _size_tf.setText( ( ( _size_list.getSelectedValue() ) ) ); } _size = ( Integer.parseInt( _size_tf.getText().trim() ) ); _test_tf.setFont( new Font( _type, _style, _size ) ); } } + + private void parseSize() { + try { + _size = ( Integer.parseInt( _size_tf.getText().trim() ) ); + } + catch ( final Exception ex ) { + // Ignore. + } + if ( _size < 1 ) { + _size = 1; + } + } + + private void setScrollPos( final JScrollPane sp, final JList list, final int index ) { + final int unit_size = sp.getVerticalScrollBar().getMaximum() / list.getModel().getSize(); + sp.getVerticalScrollBar().setValue( ( index - 2 ) * unit_size ); + } }