src/demo/share/jfc/Font2DTest/RangeMenu.java
author jcbeyler
Wed, 14 Nov 2018 12:25:15 -0800
changeset 52561 40098289d580
parent 47216 71c04702a3d5
permissions -rw-r--r--
8213622: Windows VS2013 build failure - "'snprintf': identifier not found" Summary: Replace snprintf with strlen and memcpy Reviewed-by: dholmes, mvala, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
8893
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
     2
 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3108
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/*
10292
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8893
diff changeset
    33
 * This source code is provided to illustrate the usage of a given feature
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8893
diff changeset
    34
 * or technique and has been deliberately simplified. Additional steps
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8893
diff changeset
    35
 * required for a production-quality application, such as security checks,
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8893
diff changeset
    36
 * input validation and proper error handling, might not be present in
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8893
diff changeset
    37
 * this sample code.
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8893
diff changeset
    38
 */
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8893
diff changeset
    39
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8893
diff changeset
    40
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 8893
diff changeset
    41
/*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.BorderLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.event.ActionEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.event.ActionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.event.ItemEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.event.ItemListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
8893
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
    53
import java.util.*;
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
    54
import java.util.regex.*;
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
    55
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * RangeMenu.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @author Shinsuke Fukuda
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @author Ankit Patel [Conversion to Swing - 01/07/30]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
/// Custom made choice menu that holds data for unicode range
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
public final class RangeMenu extends JComboBox implements ActionListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
8893
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
    67
    private static final int[][] UNICODE_RANGES = getUnicodeRanges();
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
    68
    private static final String[] UNICODE_RANGE_NAMES = getUnicodeRangeNames();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private boolean useCustomRange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private int[] customRange = { 0x0000, 0x007f };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /// Custom range dialog variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private final JDialog customRangeDialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private final JTextField customRangeStart = new JTextField( "0000", 4 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private final JTextField customRangeEnd   = new JTextField( "007F", 4 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private final int CUSTOM_RANGE_INDEX = UNICODE_RANGE_NAMES.length - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /// Parent Font2DTest Object holder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private final Font2DTest parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static final int SURROGATES_AREA_INDEX = 91;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public RangeMenu( Font2DTest demo, JFrame f ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        parent = demo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        for ( int i = 0; i < UNICODE_RANGE_NAMES.length; i++ )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
          addItem( UNICODE_RANGE_NAMES[i] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        setSelectedIndex( 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        addActionListener( this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        /// Set up custom range dialog...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        customRangeDialog = new JDialog( f, "Custom Unicode Range", true );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        customRangeDialog.setResizable( false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        JPanel dialogTop = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        JPanel dialogBottom = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        JButton okButton = new JButton("OK");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        JLabel from = new JLabel( "From:" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        JLabel to = new JLabel("To:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        Font labelFont = new Font( "dialog", Font.BOLD, 12 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        from.setFont( labelFont );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        to.setFont( labelFont );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        okButton.setFont( labelFont );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        dialogTop.add( from );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        dialogTop.add( customRangeStart );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        dialogTop.add( to );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        dialogTop.add( customRangeEnd );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        dialogBottom.add( okButton );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        okButton.addActionListener( this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        customRangeDialog.getContentPane().setLayout( new BorderLayout() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        customRangeDialog.getContentPane().add( "North", dialogTop );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        customRangeDialog.getContentPane().add( "South", dialogBottom );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        customRangeDialog.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /// Return the range that is currently selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public int[] getSelectedRange() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if ( useCustomRange ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            int startIndex, endIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            String startText, endText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            String empty = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                startText = customRangeStart.getText().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                endText = customRangeEnd.getText().trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                if ( startText.equals(empty) && !endText.equals(empty) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    endIndex = Integer.parseInt( endText, 16 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    startIndex = endIndex - 7*25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                else if ( !startText.equals(empty) && endText.equals(empty) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    startIndex = Integer.parseInt( startText, 16 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    endIndex = startIndex + 7*25;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    startIndex = Integer.parseInt( customRangeStart.getText(), 16 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    endIndex = Integer.parseInt( customRangeEnd.getText(), 16 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            catch ( Exception e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                /// Error in parsing the hex number ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                /// Reset the range to what it was before and return that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                customRangeStart.setText( Integer.toString( customRange[0], 16 ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                customRangeEnd.setText( Integer.toString( customRange[1], 16 ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                return customRange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            if ( startIndex < 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
              startIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            if ( endIndex > 0xffff )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
              endIndex = 0xffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            if ( startIndex > endIndex )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
              startIndex = endIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            customRange[0] = startIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            customRange[1] = endIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return customRange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
          return UNICODE_RANGES[ getSelectedIndex() ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /// Function used by loadOptions in Font2DTest main panel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /// to reset setting and range selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public void setSelectedRange( String name, int start, int end ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        setSelectedItem( name );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        customRange[0] = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        customRange[1] = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        parent.fireRangeChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /// ActionListener interface function
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /// ABP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /// moved JComboBox event code into this fcn from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /// itemStateChanged() method. Part of change to Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public void actionPerformed( ActionEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        Object source = e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        if ( source instanceof JComboBox ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                String rangeName = (String)((JComboBox)source).getSelectedItem();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                if ( rangeName.equals("Custom...") ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    useCustomRange = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    customRangeDialog.setLocationRelativeTo(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    customRangeDialog.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                  useCustomRange = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                parent.fireRangeChanged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        else if ( source instanceof JButton ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                /// Since it is only "OK" button that sends any action here...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                customRangeDialog.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
8893
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   201
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   202
    private static int[][] getUnicodeRanges() {
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   203
        List<Integer> ranges = new ArrayList<>();
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   204
        ranges.add(0);
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   205
        Character.UnicodeBlock currentBlock = Character.UnicodeBlock.of(0);
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   206
        for (int cp = 0x000001; cp < 0x110000; cp++ ) {
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   207
            Character.UnicodeBlock ub = Character.UnicodeBlock.of(cp);
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   208
            if (currentBlock == null) {
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   209
                if (ub != null) {
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   210
                    ranges.add(cp);
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   211
                    currentBlock = ub;
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   212
                }
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   213
            } else {  // being in some unicode range
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   214
                if (ub == null) {
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   215
                    ranges.add(cp - 1);
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   216
                    currentBlock = null;
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   217
                } else if (cp == 0x10ffff) {  // end of last block
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   218
                    ranges.add(cp);
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   219
                } else if (! ub.equals(currentBlock)) {
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   220
                    ranges.add(cp - 1);
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   221
                    ranges.add(cp);
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   222
                    currentBlock = ub;
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   223
                }
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   224
            }
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   225
        }
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   226
        ranges.add(0x00);  // for user defined range.
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   227
        ranges.add(0x7f);  // for user defined range.
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   228
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   229
        int[][] returnval = new int[ranges.size() / 2][2];
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   230
        for (int i = 0 ; i < ranges.size() / 2 ; i++ ) {
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   231
            returnval[i][0] = ranges.get(2*i);
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   232
            returnval[i][1] = ranges.get(2*i + 1);
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   233
        }
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   234
        return returnval;
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   235
    }
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   236
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   237
    private static String[] getUnicodeRangeNames() {
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   238
        String[] names = new String[UNICODE_RANGES.length];
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   239
        for (int i = 0 ; i < names.length ; i++ ) {
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   240
            names[i] = titleCase(
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   241
                Character.UnicodeBlock.of(UNICODE_RANGES[i][0]).toString());
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   242
        }
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   243
        names[names.length - 1] = "Custom...";
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   244
        return names;
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   245
    }
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   246
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   247
    private static String titleCase(String str) {
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   248
        str = str.replaceAll("_", " ");
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   249
        Pattern p = Pattern.compile("(^|\\W)([a-z])");
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   250
        Matcher m = p.matcher(str.toLowerCase(Locale.ROOT));
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   251
        StringBuffer sb = new StringBuffer();
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   252
        while (m.find()) {
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   253
            m.appendReplacement(sb, m.group(1) + m.group(2).toUpperCase(Locale.ROOT));
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   254
        }
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   255
        m.appendTail(sb);
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   256
        return sb.toString().replace("Cjk", "CJK").replace("Nko", "NKo");
e5c356836282 7032334: Update Font2DTest demo to support Unicode 6
ogino
parents: 5506
diff changeset
   257
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
}