< prev index next >

src/demo/share/jfc/Font2DTest/RangeMenu.java

Print this page




  45 import java.awt.Font;
  46 import java.awt.event.ActionEvent;
  47 import java.awt.event.ActionListener;
  48 import java.awt.event.ItemEvent;
  49 import java.awt.event.ItemListener;
  50 
  51 import javax.swing.*;
  52 
  53 import java.util.*;
  54 import java.util.regex.*;
  55 
  56 /**
  57  * RangeMenu.java
  58  *
  59  * @author Shinsuke Fukuda
  60  * @author Ankit Patel [Conversion to Swing - 01/07/30]
  61  */
  62 
  63 /// Custom made choice menu that holds data for unicode range
  64 
  65 public final class RangeMenu extends JComboBox implements ActionListener {
  66 
  67     private static final int[][] UNICODE_RANGES = getUnicodeRanges();
  68     private static final String[] UNICODE_RANGE_NAMES = getUnicodeRangeNames();
  69 
  70     private boolean useCustomRange = false;
  71     private int[] customRange = { 0x0000, 0x007f };
  72 
  73     /// Custom range dialog variables
  74     private final JDialog customRangeDialog;
  75     private final JTextField customRangeStart = new JTextField( "0000", 4 );
  76     private final JTextField customRangeEnd   = new JTextField( "007F", 4 );
  77     private final int CUSTOM_RANGE_INDEX = UNICODE_RANGE_NAMES.length - 1;
  78 
  79     /// Parent Font2DTest Object holder
  80     private final Font2DTest parent;
  81 
  82     public static final int SURROGATES_AREA_INDEX = 91;
  83 
  84     public RangeMenu( Font2DTest demo, JFrame f ) {
  85         super();


 164           return UNICODE_RANGES[ getSelectedIndex() ];
 165     }
 166 
 167     /// Function used by loadOptions in Font2DTest main panel
 168     /// to reset setting and range selection
 169     public void setSelectedRange( String name, int start, int end ) {
 170         setSelectedItem( name );
 171         customRange[0] = start;
 172         customRange[1] = end;
 173         parent.fireRangeChanged();
 174     }
 175 
 176     /// ActionListener interface function
 177     /// ABP
 178     /// moved JComboBox event code into this fcn from
 179     /// itemStateChanged() method. Part of change to Swing.
 180     public void actionPerformed( ActionEvent e ) {
 181         Object source = e.getSource();
 182 
 183         if ( source instanceof JComboBox ) {
 184                 String rangeName = (String)((JComboBox)source).getSelectedItem();
 185 
 186                 if ( rangeName.equals("Custom...") ) {
 187                     useCustomRange = true;
 188                     customRangeDialog.setLocationRelativeTo(parent);
 189                     customRangeDialog.show();
 190                 }
 191                 else {
 192                   useCustomRange = false;
 193                 }
 194                 parent.fireRangeChanged();
 195         }
 196         else if ( source instanceof JButton ) {
 197                 /// Since it is only "OK" button that sends any action here...
 198                 customRangeDialog.hide();
 199         }
 200     }
 201 
 202     private static int[][] getUnicodeRanges() {
 203         List<Integer> ranges = new ArrayList<>();
 204         ranges.add(0);
 205         Character.UnicodeBlock currentBlock = Character.UnicodeBlock.of(0);
 206         for (int cp = 0x000001; cp < 0x110000; cp++ ) {
 207             Character.UnicodeBlock ub = Character.UnicodeBlock.of(cp);
 208             if (currentBlock == null) {
 209                 if (ub != null) {
 210                     ranges.add(cp);
 211                     currentBlock = ub;
 212                 }
 213             } else {  // being in some unicode range
 214                 if (ub == null) {
 215                     ranges.add(cp - 1);
 216                     currentBlock = null;
 217                 } else if (cp == 0x10ffff) {  // end of last block
 218                     ranges.add(cp);




  45 import java.awt.Font;
  46 import java.awt.event.ActionEvent;
  47 import java.awt.event.ActionListener;
  48 import java.awt.event.ItemEvent;
  49 import java.awt.event.ItemListener;
  50 
  51 import javax.swing.*;
  52 
  53 import java.util.*;
  54 import java.util.regex.*;
  55 
  56 /**
  57  * RangeMenu.java
  58  *
  59  * @author Shinsuke Fukuda
  60  * @author Ankit Patel [Conversion to Swing - 01/07/30]
  61  */
  62 
  63 /// Custom made choice menu that holds data for unicode range
  64 
  65 public final class RangeMenu extends JComboBox<String> implements ActionListener {
  66 
  67     private static final int[][] UNICODE_RANGES = getUnicodeRanges();
  68     private static final String[] UNICODE_RANGE_NAMES = getUnicodeRangeNames();
  69 
  70     private boolean useCustomRange = false;
  71     private int[] customRange = { 0x0000, 0x007f };
  72 
  73     /// Custom range dialog variables
  74     private final JDialog customRangeDialog;
  75     private final JTextField customRangeStart = new JTextField( "0000", 4 );
  76     private final JTextField customRangeEnd   = new JTextField( "007F", 4 );
  77     private final int CUSTOM_RANGE_INDEX = UNICODE_RANGE_NAMES.length - 1;
  78 
  79     /// Parent Font2DTest Object holder
  80     private final Font2DTest parent;
  81 
  82     public static final int SURROGATES_AREA_INDEX = 91;
  83 
  84     public RangeMenu( Font2DTest demo, JFrame f ) {
  85         super();


 164           return UNICODE_RANGES[ getSelectedIndex() ];
 165     }
 166 
 167     /// Function used by loadOptions in Font2DTest main panel
 168     /// to reset setting and range selection
 169     public void setSelectedRange( String name, int start, int end ) {
 170         setSelectedItem( name );
 171         customRange[0] = start;
 172         customRange[1] = end;
 173         parent.fireRangeChanged();
 174     }
 175 
 176     /// ActionListener interface function
 177     /// ABP
 178     /// moved JComboBox event code into this fcn from
 179     /// itemStateChanged() method. Part of change to Swing.
 180     public void actionPerformed( ActionEvent e ) {
 181         Object source = e.getSource();
 182 
 183         if ( source instanceof JComboBox ) {
 184                 String rangeName = (String)((JComboBox<?>)source).getSelectedItem();
 185 
 186                 if ( rangeName.equals("Custom...") ) {
 187                     useCustomRange = true;
 188                     customRangeDialog.setLocationRelativeTo(parent);
 189                     customRangeDialog.setVisible(true);
 190                 }
 191                 else {
 192                   useCustomRange = false;
 193                 }
 194                 parent.fireRangeChanged();
 195         }
 196         else if ( source instanceof JButton ) {
 197                 /// Since it is only "OK" button that sends any action here...
 198                 customRangeDialog.setVisible(false);
 199         }
 200     }
 201 
 202     private static int[][] getUnicodeRanges() {
 203         List<Integer> ranges = new ArrayList<>();
 204         ranges.add(0);
 205         Character.UnicodeBlock currentBlock = Character.UnicodeBlock.of(0);
 206         for (int cp = 0x000001; cp < 0x110000; cp++ ) {
 207             Character.UnicodeBlock ub = Character.UnicodeBlock.of(cp);
 208             if (currentBlock == null) {
 209                 if (ub != null) {
 210                     ranges.add(cp);
 211                     currentBlock = ub;
 212                 }
 213             } else {  // being in some unicode range
 214                 if (ub == null) {
 215                     ranges.add(cp - 1);
 216                     currentBlock = null;
 217                 } else if (cp == 0x10ffff) {  // end of last block
 218                     ranges.add(cp);


< prev index next >