📄 rangemenu.java
字号:
"Ogham", "Runic", "Tagalog", "Hanunoo", "Buhid", "Tagbanwa", "Khmer", "Mongolian", "Limbu", "Tai Le", "Khmer Symbols", "Phonetic Extensions", "Latin Extended Additional", "Greek Extended", "General Punctuation", "Superscripts and Subscripts", "Currency Symbols", "Combining Marks for Symbols", "Letterlike Symbols", "Number Forms", "Arrows", "Mathematical Operators", "Miscellaneous Technical", "Control Pictures", "Optical Character Recognition", "Enclosed Alphanumerics", "Box Drawing", "Block Elements", "Geometric Shapes", "Miscellaneous Symbols", "Dingbats", "Miscellaneous Mathematical Symbols-A", "Supplemental Arrows-A", "Braille Patterns", "Supplemental Arrows-B", "Miscellaneous Mathematical Symbols-B", "Supplemental Mathematical Operators", "Miscellaneous Symbols and Arrows", "CJK Radicals Supplement", "Kangxi Radicals", "Ideographic Description Characters", "CJK Symbols and Punctuation", "Hiragana", "Katakana", "Bopomofo", "Hangul Compatibility Jamo", "Kanbun", "Bopomofo Extended", "Katakana Phonetic Extensions", "Enclosed CJK Letters and Months", "CJK Compatibility", "CJK Unified Ideographs Extension A", "Yijing Hexagram Symbols", "CJK Unified Ideographs", "Yi Syllables", "Yi Radicals", "Hangul Syllables", "Surrogates Area", // High Surrogates, High Private Use Surrogates, Low Surrogates "Private Use Area", "CJK Compatibility Ideographs", "Alphabetic Presentation Forms", "Arabic Presentation Forms-A", "Variation Selectors", "Combining Half Marks", "CJK Compatibility Forms", "Small Form Variants", "Arabic Presentation Forms-B", "Halfwidth and Fullwidth Forms", "Specials", "Linear B Syllabary", "Linear B Ideograms", "Aegean Numbers", "Old Italic", "Gothic", "Ugaritic", "Deseret", "Shavian", "Osmanya", "Cypriot Syllabary", "Byzantine Musical Symbols", "Musical Symbols", "Tai Xuan Jing Symbols", "Mathematical Alphanumeric Symbols", "CJK Unified Ideographs Extension B", "CJK Compatibility Ideographs Supplement", "Tags", "Variation Selectors Supplement", "Supplementary Private Use Area-A", "Supplementary Private Use Area-B", "Custom...", }; private boolean useCustomRange = false; private int[] customRange = { 0x0000, 0x007f }; /// Custom range dialog variables private final JDialog customRangeDialog; private final JTextField customRangeStart = new JTextField( "0000", 4 ); private final JTextField customRangeEnd = new JTextField( "007F", 4 ); private final int CUSTOM_RANGE_INDEX = UNICODE_RANGE_NAMES.length - 1; /// Parent Font2DTest Object holder private final Font2DTest parent; public static final int SURROGATES_AREA_INDEX = 91; public RangeMenu( Font2DTest demo, JFrame f ) { super(); parent = demo; for ( int i = 0; i < UNICODE_RANGE_NAMES.length; i++ ) addItem( UNICODE_RANGE_NAMES[i] ); setSelectedIndex( 0 ); addActionListener( this ); /// Set up custom range dialog... customRangeDialog = new JDialog( f, "Custom Unicode Range", true ); customRangeDialog.setResizable( false ); JPanel dialogTop = new JPanel(); JPanel dialogBottom = new JPanel(); JButton okButton = new JButton("OK"); JLabel from = new JLabel( "From:" ); JLabel to = new JLabel("To:"); Font labelFont = new Font( "dialog", Font.BOLD, 12 ); from.setFont( labelFont ); to.setFont( labelFont ); okButton.setFont( labelFont ); dialogTop.add( from ); dialogTop.add( customRangeStart ); dialogTop.add( to ); dialogTop.add( customRangeEnd ); dialogBottom.add( okButton ); okButton.addActionListener( this ); customRangeDialog.getContentPane().setLayout( new BorderLayout() ); customRangeDialog.getContentPane().add( "North", dialogTop ); customRangeDialog.getContentPane().add( "South", dialogBottom ); customRangeDialog.pack(); } /// Return the range that is currently selected public int[] getSelectedRange() { if ( useCustomRange ) { int startIndex, endIndex; String startText, endText; String empty = ""; try { startText = customRangeStart.getText().trim(); endText = customRangeEnd.getText().trim(); if ( startText.equals(empty) && !endText.equals(empty) ) { endIndex = Integer.parseInt( endText, 16 ); startIndex = endIndex - 7*25; } else if ( !startText.equals(empty) && endText.equals(empty) ) { startIndex = Integer.parseInt( startText, 16 ); endIndex = startIndex + 7*25; } else { startIndex = Integer.parseInt( customRangeStart.getText(), 16 ); endIndex = Integer.parseInt( customRangeEnd.getText(), 16 ); } } catch ( Exception e ) { /// Error in parsing the hex number --- /// Reset the range to what it was before and return that customRangeStart.setText( Integer.toString( customRange[0], 16 )); customRangeEnd.setText( Integer.toString( customRange[1], 16 )); return customRange; } if ( startIndex < 0 ) startIndex = 0; if ( endIndex > 0xffff ) endIndex = 0xffff; if ( startIndex > endIndex ) startIndex = endIndex; customRange[0] = startIndex; customRange[1] = endIndex; return customRange; } else return UNICODE_RANGES[ getSelectedIndex() ]; } /// Function used by loadOptions in Font2DTest main panel /// to reset setting and range selection public void setSelectedRange( String name, int start, int end ) { setSelectedItem( name ); customRange[0] = start; customRange[1] = end; parent.fireRangeChanged(); } /// ActionListener interface function /// ABP /// moved JComboBox event code into this fcn from /// itemStateChanged() method. Part of change to Swing. public void actionPerformed( ActionEvent e ) { Object source = e.getSource(); if ( source instanceof JComboBox ) { String rangeName = (String)((JComboBox)source).getSelectedItem(); if ( rangeName.equals("Custom...") ) { useCustomRange = true; customRangeDialog.setLocationRelativeTo(parent); customRangeDialog.show(); } else { useCustomRange = false; } parent.fireRangeChanged(); } else if ( source instanceof JButton ) { /// Since it is only "OK" button that sends any action here... customRangeDialog.hide(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -