1 36 37 40 41 import java.awt.BorderLayout ; 42 import java.awt.Font ; 43 import java.awt.event.ActionEvent ; 44 import java.awt.event.ActionListener ; 45 import java.awt.event.ItemEvent ; 46 import java.awt.event.ItemListener ; 47 48 import javax.swing.*; 49 50 57 58 60 public final class RangeMenu extends JComboBox implements ActionListener { 61 62 65 private final int[][] UNICODE_RANGES = { 66 { 0x000000, 0x00007f }, { 0x000080, 0x0000ff }, { 0x000100, 0x00017f }, { 0x000180, 0x00024f }, { 0x000250, 0x0002af }, { 0x0002b0, 0x0002ff }, { 0x000300, 0x00036f }, { 0x000370, 0x0003ff }, { 0x000400, 0x0004ff }, { 0x000500, 0x00052f }, { 0x000530, 0x00058f }, { 0x000590, 0x0005ff }, { 0x000600, 0x0006ff }, { 0x000700, 0x00074f }, { 0x000780, 0x0007bf }, { 0x000900, 0x00097f }, { 0x000980, 0x0009ff }, { 0x000a00, 0x000a7f }, { 0x000a80, 0x000aff }, { 0x000b00, 0x000b7f }, { 0x000b80, 0x000bff }, { 0x000c00, 0x000c7f }, { 0x000c80, 0x000cff }, { 0x000d00, 0x000d7f }, { 0x000d80, 0x000dff }, { 0x000e00, 0x000e7f }, { 0x000e80, 0x000eff }, { 0x000f00, 0x000fff }, { 0x001000, 0x00109f }, { 0x0010a0, 0x0010ff }, { 0x001100, 0x0011ff }, { 0x001200, 0x00137f }, { 0x0013a0, 0x0013ff }, { 0x001400, 0x00167f }, { 0x001680, 0x00169f }, { 0x0016a0, 0x0016ff }, { 0x001700, 0x00171f }, { 0x001720, 0x00173f }, { 0x001740, 0x00175f }, { 0x001760, 0x00177f }, { 0x001780, 0x0017ff }, { 0x001800, 0x0018af }, { 0x001900, 0x00194f }, { 0x001950, 0x00197f }, { 0x0019e0, 0x0019ff }, { 0x001d00, 0x001d7f }, { 0x001e00, 0x001eff }, { 0x001f00, 0x001fff }, { 0x002000, 0x00206f }, { 0x002070, 0x00209f }, { 0x0020a0, 0x0020cf }, { 0x0020d0, 0x0020ff }, { 0x002100, 0x00214f }, { 0x002150, 0x00218f }, { 0x002190, 0x0021ff }, { 0x002200, 0x0022ff }, { 0x002300, 0x0023ff }, { 0x002400, 0x00243f }, { 0x002440, 0x00245f }, { 0x002460, 0x0024ff }, { 0x002500, 0x00257f }, { 0x002580, 0x00259f }, { 0x0025a0, 0x0025ff }, { 0x002600, 0x0026ff }, { 0x002700, 0x0027bf }, { 0x0027c0, 0x0027ef }, { 0x0027f0, 0x0027ff }, { 0x002800, 0x0028ff }, { 0x002900, 0x00297f }, { 0x002980, 0x0029ff }, { 0x002a00, 0x002aff }, { 0x002b00, 0x002bff }, { 0x002e80, 0x002eff }, { 0x002f00, 0x002fdf }, { 0x002ff0, 0x002fff }, { 0x003000, 0x00303f }, { 0x003040, 0x00309f }, { 0x0030a0, 0x0030ff }, { 0x003100, 0x00312f }, { 0x003130, 0x00318f }, { 0x003190, 0x00319f }, { 0x0031a0, 0x0031bf }, { 0x0031f0, 0x0031ff }, { 0x003200, 0x0032ff }, { 0x003300, 0x0033ff }, { 0x003400, 0x004dbf }, { 0x004dc0, 0x004dff }, { 0x004e00, 0x009fff }, { 0x00a000, 0x00a48f }, { 0x00a490, 0x00a4cf }, { 0x00ac00, 0x00d7af }, { 0x00d800, 0x00dfff }, { 0x00e000, 0x00f8ff }, { 0x00f900, 0x00faff }, { 0x00fb00, 0x00fb4f }, { 0x00fb50, 0x00fdff }, { 0x00fe00, 0x00fe0f }, { 0x00fe20, 0x00fe2f }, { 0x00fe30, 0x00fe4f }, { 0x00fe50, 0x00fe6f }, { 0x00fe70, 0x00feff }, { 0x00ff00, 0x00ffef }, { 0x00fff0, 0x00ffff }, { 0x010000, 0x01007f }, { 0x010080, 0x0100ff }, { 0x010100, 0x01013f }, { 0x010300, 0x01032f }, { 0x010330, 0x01034f }, { 0x010380, 0x01039f }, { 0x010400, 0x01044f }, { 0x010450, 0x01047f }, { 0x010480, 0x0104af }, { 0x010800, 0x01083f }, { 0x01d000, 0x01d0ff }, { 0x01d100, 0x01d1ff }, { 0x01d300, 0x01d35f }, { 0x01d400, 0x01d7ff }, { 0x020000, 0x02a6df }, { 0x02f800, 0x02fa1f }, { 0x0e0000, 0x0e007f }, { 0x0e0100, 0x0e01ef }, { 0x0f0000, 0x0fffff }, { 0x100000, 0x10ffff }, { 0x000000, 0x00007f }, }; 191 192 private final String [] UNICODE_RANGE_NAMES = { 193 "Basic Latin", 194 "Latin-1 Supplement", 195 "Latin Extended-A", 196 "Latin Extended-B", 197 "IPA Extensions", 198 "Spacing Modifier Letters", 199 "Combining Diacritical Marks", 200 "Greek", 201 "Cyrillic", 202 "Cyrillic Supplement", 203 "Armenian", 204 "Hebrew", 205 "Arabic", 206 "Syriac", 207 "Thaana", 208 "Devanagari", 209 "Bengali", 210 "Gurmukhi", 211 "Gujarati", 212 "Oriya", 213 "Tamil", 214 "Telugu", 215 "Kannada", 216 "Malayalam", 217 "Sinhala", 218 "Thai", 219 "Lao", 220 "Tibetan", 221 "Myanmar", 222 "Georgian", 223 "Hangul Jamo", 224 "Ethiopic", 225 "Cherokee", 226 "Unified Canadian Aboriginal Syllabics", 227 "Ogham", 228 "Runic", 229 "Tagalog", 230 "Hanunoo", 231 "Buhid", 232 "Tagbanwa", 233 "Khmer", 234 "Mongolian", 235 "Limbu", 236 "Tai Le", 237 "Khmer Symbols", 238 "Phonetic Extensions", 239 "Latin Extended Additional", 240 "Greek Extended", 241 "General Punctuation", 242 "Superscripts and Subscripts", 243 "Currency Symbols", 244 "Combining Marks for Symbols", 245 "Letterlike Symbols", 246 "Number Forms", 247 "Arrows", 248 "Mathematical Operators", 249 "Miscellaneous Technical", 250 "Control Pictures", 251 "Optical Character Recognition", 252 "Enclosed Alphanumerics", 253 "Box Drawing", 254 "Block Elements", 255 "Geometric Shapes", 256 "Miscellaneous Symbols", 257 "Dingbats", 258 "Miscellaneous Mathematical Symbols-A", 259 "Supplemental Arrows-A", 260 "Braille Patterns", 261 "Supplemental Arrows-B", 262 "Miscellaneous Mathematical Symbols-B", 263 "Supplemental Mathematical Operators", 264 "Miscellaneous Symbols and Arrows", 265 "CJK Radicals Supplement", 266 "Kangxi Radicals", 267 "Ideographic Description Characters", 268 "CJK Symbols and Punctuation", 269 "Hiragana", 270 "Katakana", 271 "Bopomofo", 272 "Hangul Compatibility Jamo", 273 "Kanbun", 274 "Bopomofo Extended", 275 "Katakana Phonetic Extensions", 276 "Enclosed CJK Letters and Months", 277 "CJK Compatibility", 278 "CJK Unified Ideographs Extension A", 279 "Yijing Hexagram Symbols", 280 "CJK Unified Ideographs", 281 "Yi Syllables", 282 "Yi Radicals", 283 "Hangul Syllables", 284 "Surrogates Area", "Private Use Area", 286 "CJK Compatibility Ideographs", 287 "Alphabetic Presentation Forms", 288 "Arabic Presentation Forms-A", 289 "Variation Selectors", 290 "Combining Half Marks", 291 "CJK Compatibility Forms", 292 "Small Form Variants", 293 "Arabic Presentation Forms-B", 294 "Halfwidth and Fullwidth Forms", 295 "Specials", 296 "Linear B Syllabary", 297 "Linear B Ideograms", 298 "Aegean Numbers", 299 "Old Italic", 300 "Gothic", 301 "Ugaritic", 302 "Deseret", 303 "Shavian", 304 "Osmanya", 305 "Cypriot Syllabary", 306 "Byzantine Musical Symbols", 307 "Musical Symbols", 308 "Tai Xuan Jing Symbols", 309 "Mathematical Alphanumeric Symbols", 310 "CJK Unified Ideographs Extension B", 311 "CJK Compatibility Ideographs Supplement", 312 "Tags", 313 "Variation Selectors Supplement", 314 "Supplementary Private Use Area-A", 315 "Supplementary Private Use Area-B", 316 "Custom...", 317 }; 318 319 private boolean useCustomRange = false; 320 private int[] customRange = { 0x0000, 0x007f }; 321 322 private final JDialog customRangeDialog; 324 private final JTextField customRangeStart = new JTextField( "0000", 4 ); 325 private final JTextField customRangeEnd = new JTextField( "007F", 4 ); 326 private final int CUSTOM_RANGE_INDEX = UNICODE_RANGE_NAMES.length - 1; 327 328 private final Font2DTest parent; 330 331 public static final int SURROGATES_AREA_INDEX = 91; 332 333 public RangeMenu( Font2DTest demo, JFrame f ) { 334 super(); 335 parent = demo; 336 337 for ( int i = 0; i < UNICODE_RANGE_NAMES.length; i++ ) 338 addItem( UNICODE_RANGE_NAMES[i] ); 339 340 setSelectedIndex( 0 ); 341 addActionListener( this ); 342 343 customRangeDialog = new JDialog( f, "Custom Unicode Range", true ); 345 customRangeDialog.setResizable( false ); 346 347 JPanel dialogTop = new JPanel(); 348 JPanel dialogBottom = new JPanel(); 349 JButton okButton = new JButton("OK"); 350 JLabel from = new JLabel( "From:" ); 351 JLabel to = new JLabel("To:"); 352 Font labelFont = new Font ( "dialog", Font.BOLD, 12 ); 353 from.setFont( labelFont ); 354 to.setFont( labelFont ); 355 okButton.setFont( labelFont ); 356 357 dialogTop.add( from ); 358 dialogTop.add( customRangeStart ); 359 dialogTop.add( to ); 360 dialogTop.add( customRangeEnd ); 361 dialogBottom.add( okButton ); 362 okButton.addActionListener( this ); 363 364 customRangeDialog.getContentPane().setLayout( new BorderLayout () ); 365 customRangeDialog.getContentPane().add( "North", dialogTop ); 366 customRangeDialog.getContentPane().add( "South", dialogBottom ); 367 customRangeDialog.pack(); 368 } 369 370 372 public int[] getSelectedRange() { 373 if ( useCustomRange ) { 374 int startIndex, endIndex; 375 String startText, endText; 376 String empty = ""; 377 try { 378 startText = customRangeStart.getText().trim(); 379 endText = customRangeEnd.getText().trim(); 380 if ( startText.equals(empty) && !endText.equals(empty) ) { 381 endIndex = Integer.parseInt( endText, 16 ); 382 startIndex = endIndex - 7*25; 383 } 384 else if ( !startText.equals(empty) && endText.equals(empty) ) { 385 startIndex = Integer.parseInt( startText, 16 ); 386 endIndex = startIndex + 7*25; 387 } 388 else { 389 startIndex = Integer.parseInt( customRangeStart.getText(), 16 ); 390 endIndex = Integer.parseInt( customRangeEnd.getText(), 16 ); 391 } 392 } 393 catch ( Exception e ) { 394 customRangeStart.setText( Integer.toString( customRange[0], 16 )); 397 customRangeEnd.setText( Integer.toString( customRange[1], 16 )); 398 return customRange; 399 } 400 401 if ( startIndex < 0 ) 402 startIndex = 0; 403 if ( endIndex > 0xffff ) 404 endIndex = 0xffff; 405 if ( startIndex > endIndex ) 406 startIndex = endIndex; 407 408 customRange[0] = startIndex; 409 customRange[1] = endIndex; 410 return customRange; 411 } 412 else 413 return UNICODE_RANGES[ getSelectedIndex() ]; 414 } 415 416 public void setSelectedRange( String name, int start, int end ) { 419 setSelectedItem( name ); 420 customRange[0] = start; 421 customRange[1] = end; 422 parent.fireRangeChanged(); 423 } 424 425 public void actionPerformed( ActionEvent e ) { 430 Object source = e.getSource(); 431 432 if ( source instanceof JComboBox ) { 433 String rangeName = (String )((JComboBox)source).getSelectedItem(); 434 435 if ( rangeName.equals("Custom...") ) { 436 useCustomRange = true; 437 customRangeDialog.setLocationRelativeTo(parent); 438 customRangeDialog.show(); 439 } 440 else { 441 useCustomRange = false; 442 } 443 parent.fireRangeChanged(); 444 } 445 else if ( source instanceof JButton ) { 446 customRangeDialog.hide(); 448 } 449 } 450 } 451
| Popular Tags
|