KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Font2DTest


1 /*
2  * @(#)Font2DTest.java 1.28 05/11/17
3  *
4  * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * -Redistribution of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  *
12  * -Redistribution in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * Neither the name of Sun Microsystems, Inc. or the names of contributors may
17  * be used to endorse or promote products derived from this software without
18  * specific prior written permission.
19  *
20  * This software is provided "AS IS," without a warranty of any kind. ALL
21  * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
22  * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
23  * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN")
24  * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
25  * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
26  * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
27  * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
28  * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
29  * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
30  * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31  *
32  * You acknowledge that this software is not designed, licensed or intended
33  * for use in the design, construction, operation or maintenance of any
34  * nuclear facility.
35  */

36
37 /*
38  * @(#)Font2DTest.java 1.28 05/11/17
39  */

40
41 import java.awt.Component JavaDoc;
42 import java.awt.BorderLayout JavaDoc;
43 import java.awt.CheckboxGroup JavaDoc;
44 import java.awt.Container JavaDoc;
45 import java.awt.Dimension JavaDoc;
46 import java.awt.Font JavaDoc;
47 import java.awt.Graphics JavaDoc;
48 import java.awt.GraphicsEnvironment JavaDoc;
49 import java.awt.GridBagConstraints JavaDoc;
50 import java.awt.GridBagLayout JavaDoc;
51 import java.awt.GridLayout JavaDoc;
52 import java.awt.Insets JavaDoc;
53 import java.awt.Toolkit JavaDoc;
54 import java.awt.event.ActionEvent JavaDoc;
55 import java.awt.event.ActionListener JavaDoc;
56 import java.awt.event.ItemEvent JavaDoc;
57 import java.awt.event.ItemListener JavaDoc;
58 import java.awt.event.WindowAdapter JavaDoc;
59 import java.awt.event.WindowEvent JavaDoc;
60 import java.awt.image.BufferedImage JavaDoc;
61 import java.io.BufferedInputStream JavaDoc;
62 import java.io.BufferedOutputStream JavaDoc;
63 import java.io.File JavaDoc;
64 import java.io.FileInputStream JavaDoc;
65 import java.io.FileOutputStream JavaDoc;
66 import java.util.EnumSet JavaDoc;
67 import java.util.StringTokenizer JavaDoc;
68 import java.util.BitSet JavaDoc;
69 import javax.swing.*;
70 import javax.swing.event.*;
71
72 /**
73  * Font2DTest.java
74  *
75  * @version @(#)Font2DTest.java 1.2 00/08/22
76  * @author Shinsuke Fukuda
77  * @author Ankit Patel [Conversion to Swing - 01/07/30]
78  */

79
80 /// Main Font2DTest Class
81

82 public final class Font2DTest extends JPanel
83     implements ActionListener JavaDoc, ItemListener JavaDoc, ChangeListener {
84
85     /// JFrame that will contain Font2DTest
86
private final JFrame parent;
87     /// FontPanel class that will contain all graphical output
88
private final FontPanel fp;
89     /// RangeMenu class that contains info about the unicode ranges
90
private final RangeMenu rm;
91
92     /// Other menus to set parameters for text drawing
93
private final ChoiceV2 fontMenu;
94     private final JTextField sizeField;
95     private final ChoiceV2 styleMenu;
96     private final ChoiceV2 textMenu;
97     private int currentTextChoice = 0;
98     private final ChoiceV2 transformMenu;
99     private final ChoiceV2 transformMenuG2;
100     private final ChoiceV2 methodsMenu;
101     private final JComboBox antiAliasMenu;
102     private final JComboBox fracMetricsMenu;
103     
104     private final JSlider contrastSlider;
105
106     /// CheckboxMenuItems
107
private CheckboxMenuItemV2 displayGridCBMI;
108     private CheckboxMenuItemV2 force16ColsCBMI;
109     private CheckboxMenuItemV2 showFontInfoCBMI;
110
111     /// JDialog boxes
112
private JDialog userTextDialog;
113     private JTextArea userTextArea;
114     private JDialog printDialog;
115     private JDialog fontInfoDialog;
116     private LabelV2 fontInfos[] = new LabelV2[2];
117     private JFileChooser filePromptDialog = null;
118
119     private ButtonGroup printCBGroup;
120     private JRadioButton printModeCBs[] = new JRadioButton[3];
121
122     /// Status bar
123
private final LabelV2 statusBar;
124
125     private int fontStyles [] = {Font.PLAIN, Font.BOLD, Font.ITALIC, Font.BOLD | Font.ITALIC};
126
127     /// Text filename
128
private String JavaDoc tFileName;
129
130     // Enabled or disabled status of canDisplay check
131
private static boolean canDisplayCheck = true;
132
133     /// Initialize GUI variables and its layouts
134
public Font2DTest( JFrame f, boolean isApplet ) {
135         parent = f;
136         
137         rm = new RangeMenu( this, parent );
138         fp = new FontPanel( this, parent );
139         statusBar = new LabelV2("");
140
141         fontMenu = new ChoiceV2( this, canDisplayCheck );
142         sizeField = new JTextField( "12", 3 );
143         sizeField.addActionListener( this );
144         styleMenu = new ChoiceV2( this );
145         textMenu = new ChoiceV2( ); // listener added later
146
transformMenu = new ChoiceV2( this );
147         transformMenuG2 = new ChoiceV2( this );
148         methodsMenu = new ChoiceV2( this );
149
150         antiAliasMenu =
151         new JComboBox(EnumSet.allOf(FontPanel.AAValues.class).toArray());
152     antiAliasMenu.addActionListener(this);
153         fracMetricsMenu =
154         new JComboBox(EnumSet.allOf(FontPanel.FMValues.class).toArray());
155     fracMetricsMenu.addActionListener(this);
156
157     contrastSlider = new JSlider(JSlider.HORIZONTAL, 100, 250,
158                  FontPanel.getDefaultLCDContrast().intValue());
159     contrastSlider.setEnabled(false);
160     contrastSlider.setMajorTickSpacing(20);
161     contrastSlider.setMinorTickSpacing(10);
162     contrastSlider.setPaintTicks(true);
163     contrastSlider.setPaintLabels(true);
164     contrastSlider.addChangeListener(this);
165         setupPanel();
166         setupMenu( isApplet );
167         setupDialog( isApplet );
168
169         if(canDisplayCheck) {
170             fireRangeChanged();
171         }
172     }
173
174     /// Set up the main interface panel
175
private void setupPanel() {
176         GridBagLayout JavaDoc gbl = new GridBagLayout JavaDoc();
177         GridBagConstraints JavaDoc gbc = new GridBagConstraints JavaDoc();
178         gbc.fill = GridBagConstraints.HORIZONTAL;
179         gbc.weightx = 1;
180         gbc.insets = new Insets JavaDoc( 2, 0, 2, 2 );
181         this.setLayout( gbl );
182
183         addLabeledComponentToGBL( "Font: ", fontMenu, gbl, gbc, this );
184         addLabeledComponentToGBL( "Size: ", sizeField, gbl, gbc, this );
185         gbc.gridwidth = GridBagConstraints.REMAINDER;
186         addLabeledComponentToGBL( "Font Transform:",
187                   transformMenu, gbl, gbc, this );
188         gbc.gridwidth = 1;
189
190         addLabeledComponentToGBL( "Range: ", rm, gbl, gbc, this );
191         addLabeledComponentToGBL( "Style: ", styleMenu, gbl, gbc, this );
192         gbc.gridwidth = GridBagConstraints.REMAINDER;
193         addLabeledComponentToGBL( "Graphics Transform: ",
194                   transformMenuG2, gbl, gbc, this );
195         gbc.gridwidth = 1;
196
197         gbc.anchor = GridBagConstraints.WEST;
198         addLabeledComponentToGBL( "Method: ", methodsMenu, gbl, gbc, this );
199     addLabeledComponentToGBL("", null, gbl, gbc, this);
200         gbc.anchor = GridBagConstraints.EAST;
201         gbc.gridwidth = GridBagConstraints.REMAINDER;
202         addLabeledComponentToGBL( "Text to use:", textMenu, gbl, gbc, this );
203
204     gbc.weightx=1;
205         gbc.gridwidth = 1;
206         gbc.fill = GridBagConstraints.HORIZONTAL;
207         gbc.anchor = GridBagConstraints.WEST;
208     addLabeledComponentToGBL("LCD contrast: ",
209                   contrastSlider, gbl, gbc, this);
210
211         gbc.gridwidth = 1;
212         gbc.fill = GridBagConstraints.NONE;
213     addLabeledComponentToGBL("Antialiasing: ",
214                   antiAliasMenu, gbl, gbc, this);
215
216         gbc.anchor = GridBagConstraints.EAST;
217         gbc.gridwidth = GridBagConstraints.REMAINDER;
218     addLabeledComponentToGBL("Fractional metrics: ",
219                   fracMetricsMenu, gbl, gbc, this);
220
221         gbc.weightx = 1;
222         gbc.weighty = 1;
223         gbc.anchor = GridBagConstraints.WEST;
224         gbc.insets = new Insets JavaDoc( 2, 0, 0, 2 );
225         gbc.fill = GridBagConstraints.BOTH;
226         gbl.setConstraints( fp, gbc );
227         this.add( fp );
228
229         gbc.weighty = 0;
230         gbc.insets = new Insets JavaDoc( 0, 2, 0, 0 );
231         gbl.setConstraints( statusBar, gbc );
232         this.add( statusBar );
233     }
234
235     /// Adds a component to a container with a label to its left in GridBagLayout
236
private void addLabeledComponentToGBL( String JavaDoc name,
237                                            JComponent c,
238                                            GridBagLayout JavaDoc gbl,
239                                            GridBagConstraints JavaDoc gbc,
240                                            Container JavaDoc target ) {
241         LabelV2 l = new LabelV2( name );
242         GridBagConstraints JavaDoc gbcLabel = (GridBagConstraints JavaDoc) gbc.clone();
243         gbcLabel.insets = new Insets JavaDoc( 2, 2, 2, 0 );
244         gbcLabel.gridwidth = 1;
245         gbcLabel.weightx = 0;
246
247         if ( c == null )
248           c = new JLabel( "" );
249
250         gbl.setConstraints( l, gbcLabel );
251         target.add( l );
252         gbl.setConstraints( c, gbc );
253         target.add( c );
254     }
255
256     /// Sets up menu entries
257
private void setupMenu( boolean isApplet ) {
258         JMenu fileMenu = new JMenu( "File" );
259         JMenu optionMenu = new JMenu( "Option" );
260
261         fileMenu.add( new MenuItemV2( "Save Selected Options...", this ));
262         fileMenu.add( new MenuItemV2( "Load Options...", this ));
263         fileMenu.addSeparator();
264         fileMenu.add( new MenuItemV2( "Save as PNG...", this ));
265         fileMenu.add( new MenuItemV2( "Load PNG File to Compare...", this ));
266         fileMenu.add( new MenuItemV2( "Page Setup...", this ));
267         fileMenu.add( new MenuItemV2( "Print...", this ));
268         fileMenu.addSeparator();
269         if ( !isApplet )
270           fileMenu.add( new MenuItemV2( "Exit", this ));
271         else
272           fileMenu.add( new MenuItemV2( "Close", this ));
273
274         displayGridCBMI = new CheckboxMenuItemV2( "Display Grid", true, this );
275         force16ColsCBMI = new CheckboxMenuItemV2( "Force 16 Columns", false, this );
276         showFontInfoCBMI = new CheckboxMenuItemV2( "Display Font Info", false, this );
277         optionMenu.add( displayGridCBMI );
278         optionMenu.add( force16ColsCBMI );
279         optionMenu.add( showFontInfoCBMI );
280
281         JMenuBar mb = parent.getJMenuBar();
282         if ( mb == null )
283           mb = new JMenuBar();
284         mb.add( fileMenu );
285         mb.add( optionMenu );
286
287         parent.setJMenuBar( mb );
288
289         String JavaDoc fontList[] =
290           GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
291
292         for ( int i = 0; i < fontList.length; i++ )
293           fontMenu.addItem( fontList[i] );
294         fontMenu.setSelectedItem( "Dialog" );
295
296         styleMenu.addItem( "Plain" );
297         styleMenu.addItem( "Bold" );
298         styleMenu.addItem( "Italic" );
299         styleMenu.addItem( "Bold Italic" );
300
301         transformMenu.addItem( "None" );
302         transformMenu.addItem( "Scale" );
303         transformMenu.addItem( "Shear" );
304         transformMenu.addItem( "Rotate" );
305
306         transformMenuG2.addItem( "None" );
307         transformMenuG2.addItem( "Scale" );
308         transformMenuG2.addItem( "Shear" );
309         transformMenuG2.addItem( "Rotate" );
310
311         methodsMenu.addItem( "drawString" );
312         methodsMenu.addItem( "drawChars" );
313         methodsMenu.addItem( "drawBytes" );
314         methodsMenu.addItem( "drawGlyphVector" );
315         methodsMenu.addItem( "TextLayout.draw" );
316         methodsMenu.addItem( "GlyphVector.getOutline + draw" );
317         methodsMenu.addItem( "TextLayout.getOutline + draw" );
318
319         textMenu.addItem( "Unicode Range" );
320         textMenu.addItem( "All Glyphs" );
321         textMenu.addItem( "User Text" );
322         textMenu.addItem( "Text File" );
323         textMenu.addActionListener ( this ); // listener added later so unneeded events not thrown
324
}
325
326     /// Sets up the all dialogs used in Font2DTest...
327
private void setupDialog( boolean isApplet ) {
328         if (!isApplet)
329             filePromptDialog = new JFileChooser( );
330         else
331             filePromptDialog = null;
332
333         /// Prepare user text dialog...
334
userTextDialog = new JDialog( parent, "User Text", false );
335         JPanel dialogTopPanel = new JPanel();
336         JPanel dialogBottomPanel = new JPanel();
337         LabelV2 message1 = new LabelV2( "Enter text below and then press update" );
338         LabelV2 message2 = new LabelV2( "(Unicode char can be denoted by \\uXXXX)" );
339         LabelV2 message3 = new LabelV2( "(Supplementary chars can be denoted by \\UXXXXXX)" );
340         userTextArea = new JTextArea( "Java2D!" );
341         ButtonV2 bUpdate = new ButtonV2( "Update", this );
342         userTextArea.setFont( new Font JavaDoc( "dialog", Font.PLAIN, 12 ));
343         dialogTopPanel.setLayout( new GridLayout JavaDoc( 3, 1 ));
344         dialogTopPanel.add( message1 );
345         dialogTopPanel.add( message2 );
346         dialogTopPanel.add( message3 );
347         dialogBottomPanel.add( bUpdate );
348         //ABP
349
JScrollPane userTextAreaSP = new JScrollPane(userTextArea);
350         userTextAreaSP.setPreferredSize(new Dimension JavaDoc(300, 100));
351
352         userTextDialog.getContentPane().setLayout( new BorderLayout JavaDoc() );
353         userTextDialog.getContentPane().add( "North", dialogTopPanel );
354         userTextDialog.getContentPane().add( "Center", userTextAreaSP );
355         userTextDialog.getContentPane().add( "South", dialogBottomPanel );
356         userTextDialog.pack();
357     userTextDialog.addWindowListener( new WindowAdapter JavaDoc() {
358             public void windowClosing( WindowEvent JavaDoc e ) {
359                 userTextDialog.hide();
360             }
361         });
362
363         /// Prepare printing dialog...
364
printCBGroup = new ButtonGroup();
365         printModeCBs[ fp.ONE_PAGE ] =
366           new JRadioButton( "Print one page from currently displayed character/line",
367                          true );
368         printModeCBs[ fp.CUR_RANGE ] =
369           new JRadioButton( "Print all characters in currently selected range",
370                          false );
371         printModeCBs[ fp.ALL_TEXT ] =
372           new JRadioButton( "Print all lines of text",
373                          false );
374         LabelV2 l =
375           new LabelV2( "Note: Page range in native \"Print\" dialog will not affect the result" );
376         JPanel buttonPanel = new JPanel();
377         printModeCBs[ fp.ALL_TEXT ].setEnabled( false );
378         buttonPanel.add( new ButtonV2( "Print", this ));
379         buttonPanel.add( new ButtonV2( "Cancel", this ));
380
381         printDialog = new JDialog( parent, "Print...", true );
382         printDialog.setResizable( false );
383     printDialog.addWindowListener( new WindowAdapter JavaDoc() {
384             public void windowClosing( WindowEvent JavaDoc e ) {
385                 printDialog.hide();
386             }
387         });
388         printDialog.getContentPane().setLayout( new GridLayout JavaDoc( printModeCBs.length + 2, 1 ));
389         printDialog.getContentPane().add( l );
390         for ( int i = 0; i < printModeCBs.length; i++ ) {
391             printCBGroup.add( printModeCBs[i] );
392             printDialog.getContentPane().add( printModeCBs[i] );
393         }
394         printDialog.getContentPane().add( buttonPanel );
395         printDialog.pack();
396
397         /// Prepare font information dialog...
398
fontInfoDialog = new JDialog( parent, "Font info", false );
399         fontInfoDialog.setResizable( false );
400         fontInfoDialog.addWindowListener( new WindowAdapter JavaDoc() {
401             public void windowClosing( WindowEvent JavaDoc e ) {
402                 fontInfoDialog.hide();
403                 showFontInfoCBMI.setState( false );
404             }
405         });
406         JPanel fontInfoPanel = new JPanel();
407         fontInfoPanel.setLayout( new GridLayout JavaDoc( fontInfos.length, 1 ));
408         for ( int i = 0; i < fontInfos.length; i++ ) {
409             fontInfos[i] = new LabelV2("");
410             fontInfoPanel.add( fontInfos[i] );
411         }
412         fontInfoDialog.getContentPane().add( fontInfoPanel );
413
414         /// Move the location of the dialog...
415
userTextDialog.setLocation( 200, 300 );
416         fontInfoDialog.setLocation( 0, 400 );
417     }
418
419     /// RangeMenu object signals using this function
420
/// when Unicode range has been changed and text needs to be redrawn
421
public void fireRangeChanged() {
422         int range[] = rm.getSelectedRange();
423         fp.setTextToDraw( fp.RANGE_TEXT, range, null, null );
424         if(canDisplayCheck) {
425             setupFontList(range[0], range[1]);
426         }
427         if ( showFontInfoCBMI.getState() )
428           fireUpdateFontInfo();
429     }
430
431     /// Changes the message on the status bar
432
public void fireChangeStatus( String JavaDoc message, boolean error ) {
433         /// If this is not ran as an applet, use own status bar,
434
/// Otherwise, use the appletviewer/browser's status bar
435
statusBar.setText( message );
436         if ( error )
437           fp.showingError = true;
438         else
439           fp.showingError = false;
440     }
441
442     /// Updates the information about the selected font
443
public void fireUpdateFontInfo() {
444         if ( showFontInfoCBMI.getState() ) {
445             String JavaDoc infos[] = fp.getFontInfo();
446             for ( int i = 0; i < fontInfos.length; i++ )
447               fontInfos[i].setText( infos[i] );
448             fontInfoDialog.pack();
449         }
450     }
451
452     private void setupFontList(int rangeStart, int rangeEnd) {
453         
454         int listCount = fontMenu.getItemCount();
455         int size = 16;
456
457         try {
458             size = Float.valueOf(sizeField.getText()).intValue();
459         }
460         catch ( Exception JavaDoc e ) {
461             System.out.println("Invalid font size in the size textField. Using default value of 16");
462         }
463
464         int style = fontStyles[styleMenu.getSelectedIndex()];
465         Font JavaDoc f;
466         for (int i = 0; i < listCount; i++) {
467             String JavaDoc fontName = (String JavaDoc)fontMenu.getItemAt(i);
468             f = new Font JavaDoc(fontName, style, size);
469             if ((rm.getSelectedIndex() != RangeMenu.SURROGATES_AREA_INDEX) &&
470                 canDisplayRange(f, rangeStart, rangeEnd)) {
471                 fontMenu.setBit(i, true);
472             }
473             else {
474                 fontMenu.setBit(i, false);
475             }
476         }
477
478         fontMenu.repaint();
479     }
480
481     protected boolean canDisplayRange(Font JavaDoc font, int rangeStart, int rangeEnd) {
482         for (int i = rangeStart; i < rangeEnd; i++) {
483             if (font.canDisplay(i)) {
484                 return true;
485             }
486         }
487         return false;
488     }
489
490     /// Displays a file load/save dialog and returns the specified file
491
private String JavaDoc promptFile( boolean isSave, String JavaDoc initFileName ) {
492     int retVal;
493     String JavaDoc str;
494     
495     /// ABP
496
if ( filePromptDialog == null)
497         return null;
498     
499         if ( isSave ) {
500             filePromptDialog.setDialogType( JFileChooser.SAVE_DIALOG );
501             filePromptDialog.setDialogTitle( "Save..." );
502             str = "Save";
503
504
505         }
506         else {
507             filePromptDialog.setDialogType( JFileChooser.OPEN_DIALOG );
508             filePromptDialog.setDialogTitle( "Load..." );
509             str = "Load";
510         }
511         
512     if (initFileName != null)
513         filePromptDialog.setSelectedFile( new File JavaDoc( initFileName ) );
514     retVal = filePromptDialog.showDialog( this, str );
515
516         if ( retVal == JFileChooser.APPROVE_OPTION ) {
517             File JavaDoc file = filePromptDialog.getSelectedFile();
518             String JavaDoc fileName = file.getAbsolutePath();
519             if ( fileName != null ) {
520                 return fileName;
521         }
522     }
523     
524         return null;
525     }
526
527     /// Converts user text into arrays of String, delimited at newline character
528
/// Also replaces any valid escape sequence with appropriate unicode character
529
/// Support \\UXXXXXX notation for surrogates
530
private String JavaDoc[] parseUserText( String JavaDoc orig ) {
531         int length = orig.length();
532         StringTokenizer JavaDoc perLine = new StringTokenizer JavaDoc( orig, "\n" );
533         String JavaDoc textLines[] = new String JavaDoc[ perLine.countTokens() ];
534         int lineNumber = 0;
535
536         while ( perLine.hasMoreElements() ) {
537             StringBuffer JavaDoc converted = new StringBuffer JavaDoc();
538             String JavaDoc oneLine = perLine.nextToken();
539             int lineLength = oneLine.length();
540             int prevEscapeEnd = 0;
541             int nextEscape = -1;
542             do {
543                 int nextBMPEscape = oneLine.indexOf( "\\u", prevEscapeEnd );
544                 int nextSupEscape = oneLine.indexOf( "\\U", prevEscapeEnd );
545                 nextEscape = (nextBMPEscape < 0)
546                     ? ((nextSupEscape < 0)
547                        ? -1
548                        : nextSupEscape)
549                     : ((nextSupEscape < 0)
550                        ? nextBMPEscape
551                        : Math.min(nextBMPEscape, nextSupEscape));
552
553                 if ( nextEscape != -1 ) {
554                     if ( prevEscapeEnd < nextEscape )
555                         converted.append( oneLine.substring( prevEscapeEnd, nextEscape ));
556                     
557                     prevEscapeEnd = nextEscape + (nextEscape == nextBMPEscape ? 6 : 8);
558                     try {
559                         String JavaDoc hex = oneLine.substring( nextEscape + 2, prevEscapeEnd );
560                         if (nextEscape == nextBMPEscape) {
561                             converted.append( (char) Integer.parseInt( hex, 16 ));
562                         } else {
563                             converted.append( new String JavaDoc( Character.toChars( Integer.parseInt( hex, 16 ))));
564                         }
565                     }
566                     catch ( Exception JavaDoc e ) {
567                         int copyLimit = Math.min(lineLength, prevEscapeEnd);
568                         converted.append( oneLine.substring( nextEscape, copyLimit ));
569                     }
570                 }
571             } while (nextEscape != -1);
572             if ( prevEscapeEnd < lineLength )
573               converted.append( oneLine.substring( prevEscapeEnd, lineLength ));
574             textLines[ lineNumber++ ] = converted.toString();
575         }
576         return textLines;
577     }
578
579     /// Reads the text from specified file, detecting UTF-16 encoding
580
/// Then breaks the text into String array, delimited at every line break
581
private void readTextFile( String JavaDoc fileName ) {
582         try {
583             String JavaDoc fileText, textLines[];
584             BufferedInputStream JavaDoc bis =
585               new BufferedInputStream JavaDoc( new FileInputStream JavaDoc( fileName ));
586             int numBytes = bis.available();
587             if (numBytes == 0) {
588                 throw new Exception JavaDoc("Text file " + fileName + " is empty");
589             }
590             byte byteData[] = new byte[ numBytes ];
591             bis.read( byteData, 0, numBytes );
592             bis.close();
593
594             /// If byte mark is found, then use UTF-16 encoding to convert bytes...
595
if (numBytes >= 2 &&
596                 (( byteData[0] == (byte) 0xFF && byteData[1] == (byte) 0xFE ) ||
597                  ( byteData[0] == (byte) 0xFE && byteData[1] == (byte) 0xFF )))
598               fileText = new String JavaDoc( byteData, "UTF-16" );
599             /// Otherwise, use system default encoding
600
else
601               fileText = new String JavaDoc( byteData );
602
603             int length = fileText.length();
604             StringTokenizer JavaDoc perLine = new StringTokenizer JavaDoc( fileText, "\n" );
605             /// Determine "Return Char" used in this file
606
/// This simply finds first occurrence of CR, CR+LF or LF...
607
for ( int i = 0; i < length; i++ ) {
608                 char iTh = fileText.charAt( i );
609                 if ( iTh == '\r' ) {
610                     if ( i < length - 1 && fileText.charAt( i + 1 ) == '\n' )
611                       perLine = new StringTokenizer JavaDoc( fileText, "\r\n" );
612                     else
613                       perLine = new StringTokenizer JavaDoc( fileText, "\r" );
614                     break;
615                 }
616                 else if ( iTh == '\n' )
617                   /// Use the one already created
618
break;
619             }
620             int lineNumber = 0, numLines = perLine.countTokens();
621             textLines = new String JavaDoc[ numLines ];
622
623             while ( perLine.hasMoreElements() ) {
624                 String JavaDoc oneLine = perLine.nextToken();
625                 if ( oneLine == null )
626                   /// To make LineBreakMeasurer to return a valid TextLayout
627
/// on an empty line, simply feed it a space char...
628
oneLine = " ";
629                 textLines[ lineNumber++ ] = oneLine;
630             }
631             fp.setTextToDraw( fp.FILE_TEXT, null, null, textLines );
632             rm.setEnabled( false );
633             methodsMenu.setEnabled( false );
634         }
635         catch ( Exception JavaDoc ex ) {
636             fireChangeStatus( "ERROR: Failed to Read Text File; See Stack Trace", true );
637             ex.printStackTrace();
638         }
639     }
640
641     /// Returns a String storing current configuration
642
private void writeCurrentOptions( String JavaDoc fileName ) {
643         try {
644             String JavaDoc curOptions = fp.getCurrentOptions();
645             BufferedOutputStream JavaDoc bos =
646               new BufferedOutputStream JavaDoc( new FileOutputStream JavaDoc( fileName ));
647             /// Prepend title and the option that is only obtainable here
648
int range[] = rm.getSelectedRange();
649             String JavaDoc completeOptions =
650               ( "Font2DTest Option File\n" +
651                 displayGridCBMI.getState() + "\n" +
652                 force16ColsCBMI.getState() + "\n" +
653                 showFontInfoCBMI.getState() + "\n" +
654                 rm.getSelectedItem() + "\n" +
655                 range[0] + "\n" + range[1] + "\n" + curOptions + tFileName);
656             byte toBeWritten[] = completeOptions.getBytes( "UTF-16" );
657             bos.write( toBeWritten, 0, toBeWritten.length );
658             bos.close();
659         }
660         catch ( Exception JavaDoc ex ) {
661             fireChangeStatus( "ERROR: Failed to Save Options File; See Stack Trace", true );
662             ex.printStackTrace();
663         }
664     }
665
666     /// Updates GUI visibility/status after some parameters have changed
667
private void updateGUI() {
668         int selectedText = textMenu.getSelectedIndex();
669
670         /// Set the visibility of User Text dialog
671
if ( selectedText == fp.USER_TEXT )
672           userTextDialog.show();
673         else
674           userTextDialog.hide();
675         /// Change the visibility/status/availability of Print JDialog buttons
676
printModeCBs[ fp.ONE_PAGE ].setSelected( true );
677         if ( selectedText == fp.FILE_TEXT || selectedText == fp.USER_TEXT ) {
678         /// ABP
679
/// update methodsMenu to show that TextLayout.draw is being used
680
/// when we are in FILE_TEXT mode
681
if ( selectedText == fp.FILE_TEXT )
682             methodsMenu.setSelectedItem("TextLayout.draw");
683             methodsMenu.setEnabled( selectedText == fp.USER_TEXT );
684             printModeCBs[ fp.CUR_RANGE ].setEnabled( false );
685             printModeCBs[ fp.ALL_TEXT ].setEnabled( true );
686         }
687         else {
688         /// ABP
689
/// update methodsMenu to show that drawGlyph is being used
690
/// when we are in ALL_GLYPHS mode
691
if ( selectedText == fp.ALL_GLYPHS )
692             methodsMenu.setSelectedItem("drawGlyphVector");
693             methodsMenu.setEnabled( selectedText == fp.RANGE_TEXT );
694             printModeCBs[ fp.CUR_RANGE ].setEnabled( true );
695             printModeCBs[ fp.ALL_TEXT ].setEnabled( false );
696         }
697         /// Modify RangeMenu and fontInfo label availabilty
698
if ( selectedText == fp.RANGE_TEXT ) {
699             fontInfos[1].setVisible( true );
700             rm.setEnabled( true );
701         }
702         else {
703             fontInfos[1].setVisible( false );
704             rm.setEnabled( false );
705         }
706     }
707
708     /// Loads saved options and applies them
709
private void loadOptions( String JavaDoc fileName ) {
710         try {
711             BufferedInputStream JavaDoc bis =
712               new BufferedInputStream JavaDoc( new FileInputStream JavaDoc( fileName ));
713             int numBytes = bis.available();
714             byte byteData[] = new byte[ numBytes ];
715             bis.read( byteData, 0, numBytes );
716             bis.close();
717             if ( numBytes < 2 ||
718         (byteData[0] != (byte) 0xFE || byteData[1] != (byte) 0xFF) )
719               throw new Exception JavaDoc( "Not a Font2DTest options file" );
720             
721             String JavaDoc options = new String JavaDoc( byteData, "UTF-16" );
722             StringTokenizer JavaDoc perLine = new StringTokenizer JavaDoc( options, "\n" );
723             String JavaDoc title = perLine.nextToken();
724             if ( !title.equals( "Font2DTest Option File" ))
725               throw new Exception JavaDoc( "Not a Font2DTest options file" );
726
727             /// Parse all options
728
boolean displayGridOpt = Boolean.parseBoolean( perLine.nextToken() );
729             boolean force16ColsOpt = Boolean.parseBoolean( perLine.nextToken() );
730             boolean showFontInfoOpt = Boolean.parseBoolean( perLine.nextToken() );
731             String JavaDoc rangeNameOpt = perLine.nextToken();
732             int rangeStartOpt = Integer.parseInt( perLine.nextToken() );
733             int rangeEndOpt = Integer.parseInt( perLine.nextToken() );
734             String JavaDoc fontNameOpt = perLine.nextToken();
735             float fontSizeOpt = Float.parseFloat( perLine.nextToken() );
736             int fontStyleOpt = Integer.parseInt( perLine.nextToken() );
737             int fontTransformOpt = Integer.parseInt( perLine.nextToken() );
738             int g2TransformOpt = Integer.parseInt( perLine.nextToken() );
739             int textToUseOpt = Integer.parseInt( perLine.nextToken() );
740             int drawMethodOpt = Integer.parseInt( perLine.nextToken() );
741             int antialiasOpt = Integer.parseInt(perLine.nextToken());
742             int fractionalOpt = Integer.parseInt(perLine.nextToken());
743             int lcdContrast = Integer.parseInt(perLine.nextToken());
744             String JavaDoc userTextOpt[] = { "Java2D!" }, dialogEntry = "Java2D!";
745             if (textToUseOpt == fp.USER_TEXT ) {
746                 int numLines = perLine.countTokens(), lineNumber = 0;
747                 if ( numLines != 0 ) {
748                     userTextOpt = new String JavaDoc[ numLines ];
749                     dialogEntry = "";
750                     for ( ; perLine.hasMoreElements(); lineNumber++ ) {
751                         userTextOpt[ lineNumber ] = perLine.nextToken();
752                         dialogEntry += userTextOpt[ lineNumber ] + "\n";
753                     }
754                 }
755         }
756
757             /// Reset GUIs
758
displayGridCBMI.setState( displayGridOpt );
759             force16ColsCBMI.setState( force16ColsOpt );
760             showFontInfoCBMI.setState( showFontInfoOpt );
761             rm.setSelectedRange( rangeNameOpt, rangeStartOpt, rangeEndOpt );
762             fontMenu.setSelectedItem( fontNameOpt );
763             sizeField.setText( String.valueOf( fontSizeOpt ));
764             styleMenu.setSelectedIndex( fontStyleOpt );
765             transformMenu.setSelectedIndex( fontTransformOpt );
766             transformMenuG2.setSelectedIndex( g2TransformOpt );
767             textMenu.setSelectedIndex( textToUseOpt );
768             methodsMenu.setSelectedIndex( drawMethodOpt );
769             antiAliasMenu.setSelectedIndex( antialiasOpt );
770             fracMetricsMenu.setSelectedIndex( fractionalOpt );
771         contrastSlider.setValue(lcdContrast);
772
773             userTextArea.setText( dialogEntry );
774             updateGUI();
775
776         if ( textToUseOpt == fp.FILE_TEXT ) {
777           tFileName = perLine.nextToken();
778           readTextFile(tFileName );
779             }
780
781             /// Reset option variables and repaint
782
fp.loadOptions( displayGridOpt, force16ColsOpt,
783                 rangeStartOpt, rangeEndOpt,
784                             fontNameOpt, fontSizeOpt,
785                 fontStyleOpt, fontTransformOpt, g2TransformOpt,
786                             textToUseOpt, drawMethodOpt,
787                 antialiasOpt, fractionalOpt,
788                 lcdContrast, userTextOpt );
789             if ( showFontInfoOpt ) {
790                 fireUpdateFontInfo();
791                 fontInfoDialog.show();
792             }
793             else
794               fontInfoDialog.hide();
795         }
796         catch ( Exception JavaDoc ex ) {
797             fireChangeStatus( "ERROR: Failed to Load Options File; See Stack Trace", true );
798             ex.printStackTrace();
799         }
800     }
801
802     /// Loads a previously saved image
803
private void loadComparisonPNG( String JavaDoc fileName ) {
804         try {
805         BufferedImage JavaDoc image =
806         javax.imageio.ImageIO.read(new File JavaDoc(fileName));
807             JFrame f = new JFrame( "Comparison PNG" );
808             ImagePanel ip = new ImagePanel( image );
809             f.setResizable( false );
810             f.getContentPane().add( ip );
811             f.addWindowListener( new WindowAdapter JavaDoc() {
812                 public void windowClosing( WindowEvent JavaDoc e ) {
813                     ( (JFrame) e.getSource() ).dispose();
814                 }
815             });
816             f.pack();
817             f.show();
818         }
819         catch ( Exception JavaDoc ex ) {
820             fireChangeStatus( "ERROR: Failed to Load PNG File; See Stack Trace", true );
821             ex.printStackTrace();
822         }
823     }
824
825     /// Interface functions...
826

827     /// ActionListener interface function
828
/// Responds to JMenuItem, JTextField and JButton actions
829
public void actionPerformed( ActionEvent JavaDoc e ) {
830         Object JavaDoc source = e.getSource();
831
832         if ( source instanceof JMenuItem ) {
833             JMenuItem mi = (JMenuItem) source;
834             String JavaDoc itemName = mi.getText();
835
836             if ( itemName.equals( "Save Selected Options..." )) {
837                 String JavaDoc fileName = promptFile( true, "options.txt" );
838                 if ( fileName != null )
839                   writeCurrentOptions( fileName );
840             }
841             else if ( itemName.equals( "Load Options..." )) {
842                 String JavaDoc fileName = promptFile( false, "options.txt" );
843                 if ( fileName != null )
844                   loadOptions( fileName );
845             }
846             else if ( itemName.equals( "Save as PNG..." )) {
847                 String JavaDoc fileName = promptFile( true, fontMenu.getSelectedItem() + ".png" );
848                 if ( fileName != null )
849                   fp.doSavePNG( fileName );
850             }
851             else if ( itemName.equals( "Load PNG File to Compare..." )) {
852                 String JavaDoc fileName = promptFile( false, null );
853                 if ( fileName != null )
854                   loadComparisonPNG( fileName );
855             }
856             else if ( itemName.equals( "Page Setup..." ))
857               fp.doPageSetup();
858             else if ( itemName.equals( "Print..." ))
859               printDialog.show();
860             else if ( itemName.equals( "Close" ))
861               parent.dispose();
862             else if ( itemName.equals( "Exit" ))
863               System.exit(0);
864         }
865
866         else if ( source instanceof JTextField ) {
867             JTextField tf = (JTextField) source;
868             float sz = 12f;
869             try {
870                  sz = Float.parseFloat(sizeField.getText());
871                  if (sz < 1f || sz > 120f) {
872                       sz = 12f;
873                       sizeField.setText("12");
874                  }
875             } catch (Exception JavaDoc se) {
876                  sizeField.setText("12");
877             }
878             if ( tf == sizeField )
879               fp.setFontParams( fontMenu.getSelectedItem(),
880                                 sz,
881                                 styleMenu.getSelectedIndex(),
882                                 transformMenu.getSelectedIndex() );
883         }
884
885         else if ( source instanceof JButton ) {
886             String JavaDoc itemName = ( (JButton) source ).getText();
887             /// Print dialog buttons...
888
if ( itemName.equals( "Print" )) {
889                 for ( int i = 0; i < printModeCBs.length; i++ )
890                   if ( printModeCBs[i].isSelected() ) {
891                       printDialog.hide();
892                       fp.doPrint( i );
893                   }
894             }
895             else if ( itemName.equals( "Cancel" ))
896               printDialog.hide();
897             /// Update button from Usert Text JDialog...
898
else if ( itemName.equals( "Update" ))
899               fp.setTextToDraw( fp.USER_TEXT, null,
900                                 parseUserText( userTextArea.getText() ), null );
901         }
902         else if ( source instanceof JComboBox ) {
903             JComboBox c = (JComboBox) source;
904             
905             /// RangeMenu handles actions by itself and then calls fireRangeChanged,
906
/// so it is not listed or handled here
907
if ( c == fontMenu || c == styleMenu || c == transformMenu ) {
908         float sz = 12f;
909         try {
910             sz = Float.parseFloat(sizeField.getText());
911             if (sz < 1f || sz > 120f) {
912             sz = 12f;
913             sizeField.setText("12");
914             }
915         } catch (Exception JavaDoc se) {
916             sizeField.setText("12");
917         }
918         fp.setFontParams(fontMenu.getSelectedItem(),
919                  sz,
920                  styleMenu.getSelectedIndex(),
921                  transformMenu.getSelectedIndex());
922         } else if ( c == methodsMenu )
923               fp.setDrawMethod( methodsMenu.getSelectedIndex() );
924             else if ( c == textMenu ) {
925
926                 if(canDisplayCheck) {
927                     fireRangeChanged();
928                 }
929
930                 int selected = textMenu.getSelectedIndex();
931
932                 if ( selected == fp.RANGE_TEXT )
933                   fp.setTextToDraw( fp.RANGE_TEXT, rm.getSelectedRange(),
934                                     null, null );
935                 else if ( selected == fp.USER_TEXT )
936                   fp.setTextToDraw( fp.USER_TEXT, null,
937                                     parseUserText( userTextArea.getText() ), null );
938                 else if ( selected == fp.FILE_TEXT ) {
939                     String JavaDoc fileName = promptFile( false, null );
940                     if ( fileName != null ) {
941               tFileName = fileName;
942               readTextFile( fileName );
943             } else {
944                         /// User cancelled selection; reset to previous choice
945
c.setSelectedIndex( currentTextChoice );
946                         return;
947                     }
948                 }
949                 else if ( selected == fp.ALL_GLYPHS )
950                   fp.setTextToDraw( fp.ALL_GLYPHS, null, null, null );
951
952                 updateGUI();
953                 currentTextChoice = selected;
954             }
955             else if ( c == transformMenuG2 ) {
956                 fp.setTransformG2( transformMenuG2.getSelectedIndex() );
957             }
958         else if (c == antiAliasMenu || c == fracMetricsMenu) {
959         if (c == antiAliasMenu) {
960             boolean enabled = FontPanel.AAValues.
961             isLCDMode(antiAliasMenu.getSelectedItem());
962             contrastSlider.setEnabled(enabled);
963         }
964         fp.setRenderingHints(antiAliasMenu.getSelectedItem(),
965                      fracMetricsMenu.getSelectedItem(),
966                      contrastSlider.getValue());
967         }
968         }
969     }
970
971     public void stateChanged(ChangeEvent e) {
972      Object JavaDoc source = e.getSource();
973      if (source instanceof JSlider) {
974          fp.setRenderingHints(antiAliasMenu.getSelectedItem(),
975                   fracMetricsMenu.getSelectedItem(),
976                   contrastSlider.getValue());
977      }
978     }
979
980     /// ItemListener interface function
981
/// Responds to JCheckBoxMenuItem, JComboBox and JCheckBox actions
982
public void itemStateChanged( ItemEvent JavaDoc e ) {
983         Object JavaDoc source = e.getSource();
984
985         if ( source instanceof JCheckBoxMenuItem ) {
986             JCheckBoxMenuItem cbmi = (JCheckBoxMenuItem) source;
987             if ( cbmi == displayGridCBMI )
988               fp.setGridDisplay( displayGridCBMI.getState() );
989             else if ( cbmi == force16ColsCBMI )
990               fp.setForce16Columns( force16ColsCBMI.getState() );
991             else if ( cbmi == showFontInfoCBMI ) {
992                 if ( showFontInfoCBMI.getState() ) {
993                     fireUpdateFontInfo();
994                     fontInfoDialog.show();
995                 }
996                 else
997                   fontInfoDialog.hide();
998             }
999         }
1000    }
1001
1002    private static void printUsage() {
1003        String JavaDoc usage = "Usage: java -jar Font2DTest.jar [options]\n" +
1004            "\nwhere options include:\n" +
1005            " -dcdc | -disablecandisplaycheck disable canDisplay check for font\n" +
1006            " -? | -help print this help message\n" +
1007            "\nExample :\n" +
1008            " To disable canDisplay check on font for ranges\n" +
1009            " java -jar Font2DTest.jar -dcdc";
1010        System.out.println(usage);
1011        System.exit(0);
1012    }
1013
1014    /// Main function
1015
public static void main(String JavaDoc argv[]) {
1016        
1017        if(argv.length > 0) {
1018            if(argv[0].equalsIgnoreCase("-disablecandisplaycheck") ||
1019               argv[0].equalsIgnoreCase("-dcdc")) {
1020                canDisplayCheck = false;
1021            }
1022            else {
1023                printUsage();
1024            }
1025        }
1026
1027    UIManager.put("swing.boldMetal", Boolean.FALSE);
1028        final JFrame f = new JFrame( "Font2DTest" );
1029        final Font2DTest f2dt = new Font2DTest( f, false );
1030        f.addWindowListener( new WindowAdapter JavaDoc() {
1031            public void windowOpening( WindowEvent JavaDoc e ) { f2dt.repaint(); }
1032            public void windowClosing( WindowEvent JavaDoc e ) { System.exit(0); }
1033        });
1034
1035        f.getContentPane().add( f2dt );
1036        f.pack();
1037        f.show();
1038    }
1039
1040    /// Inner class definitions...
1041

1042    /// Class to display just an image file
1043
/// Used to show the comparison PNG image
1044
private final class ImagePanel extends JPanel {
1045        private final BufferedImage JavaDoc bi;
1046        
1047        public ImagePanel( BufferedImage JavaDoc image ) {
1048            bi = image;
1049        }
1050
1051        public Dimension JavaDoc getPreferredSize() {
1052            return new Dimension JavaDoc( bi.getWidth(), bi.getHeight() );
1053        }
1054
1055        public void paintComponent( Graphics JavaDoc g ) {
1056            g.drawImage( bi, 0, 0, this );
1057        }
1058    }
1059
1060    /// Classes made to avoid repetitive calls... (being lazy)
1061
private final class ButtonV2 extends JButton {
1062        public ButtonV2( String JavaDoc name, ActionListener JavaDoc al ) {
1063            super( name );
1064            this.addActionListener( al );
1065        }
1066    }
1067
1068    private final class ChoiceV2 extends JComboBox {
1069        
1070        private BitSet JavaDoc bitSet = null;
1071
1072    public ChoiceV2() {;}
1073
1074        public ChoiceV2( ActionListener JavaDoc al ) {
1075            super();
1076            this.addActionListener( al );
1077        }
1078
1079        public ChoiceV2( ActionListener JavaDoc al, boolean fontChoice) {
1080            this(al);
1081            if(fontChoice) {
1082                //Register this component in ToolTipManager
1083
setToolTipText("");
1084                bitSet = new BitSet JavaDoc();
1085                setRenderer(new ChoiceV2Renderer(this));
1086            }
1087        }
1088        
1089        public String JavaDoc getToolTipText() {
1090            int index = this.getSelectedIndex();
1091            String JavaDoc fontName = (String JavaDoc) this.getSelectedItem();
1092            if(fontName != null &&
1093               (textMenu.getSelectedIndex() == fp.RANGE_TEXT)) {
1094                if (getBit(index)) {
1095                    return "Font \"" + fontName + "\" can display some characters in \"" +
1096                        rm.getSelectedItem() + "\" range";
1097                }
1098                else {
1099                    return "Font \"" + fontName + "\" cannot display any characters in \"" +
1100                        rm.getSelectedItem() + "\" range";
1101                }
1102            }
1103            return super.getToolTipText();
1104        }
1105
1106        public void setBit(int bitIndex, boolean value) {
1107            bitSet.set(bitIndex, value);
1108        }
1109
1110        public boolean getBit(int bitIndex) {
1111            return bitSet.get(bitIndex);
1112        }
1113    }
1114 
1115    private final class ChoiceV2Renderer extends DefaultListCellRenderer {
1116 
1117        private ImageIcon yesImage, blankImage;
1118        private ChoiceV2 choice = null;
1119
1120        public ChoiceV2Renderer(ChoiceV2 choice) {
1121            try {
1122                yesImage = new ImageIcon(getClass().getResource("yes.gif"));
1123                blankImage = new ImageIcon(getClass().getResource("blank.gif"));
1124            }
1125            catch(Exception JavaDoc exception) {
1126                System.out.println("Exception : " + exception);
1127            }
1128            this.choice = choice;
1129        }
1130 
1131        public Component JavaDoc getListCellRendererComponent(JList list,
1132                                                      Object JavaDoc value,
1133                                                      int index,
1134                                                      boolean isSelected,
1135                                                      boolean cellHasFocus) {
1136
1137            if(textMenu.getSelectedIndex() == fp.RANGE_TEXT) {
1138
1139                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
1140
1141                //For JComboBox if index is -1, its rendering the selected index.
1142
if(index == -1) {
1143                    index = choice.getSelectedIndex();
1144                }
1145                
1146                if(choice.getBit(index)) {
1147                    setIcon(yesImage);
1148                }
1149                else {
1150                    setIcon(blankImage);
1151                }
1152
1153            } else {
1154                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
1155                setIcon(blankImage);
1156            }
1157
1158            return this;
1159        }
1160    }
1161
1162    private final class LabelV2 extends JLabel {
1163        public LabelV2( String JavaDoc name ) {
1164            super( name );
1165        }
1166    }
1167
1168    private final class MenuItemV2 extends JMenuItem {
1169        public MenuItemV2( String JavaDoc name, ActionListener JavaDoc al ) {
1170            super( name );
1171            this.addActionListener( al );
1172        }
1173    }
1174
1175    private final class CheckboxMenuItemV2 extends JCheckBoxMenuItem {
1176        public CheckboxMenuItemV2( String JavaDoc name, boolean b, ItemListener JavaDoc il ) {
1177            super( name, b );
1178            this.addItemListener( il );
1179        }
1180    }
1181}
1182
Popular Tags