Font2DTestpublic final class Font2DTest extends JPanel implements ActionListener, ItemListener
Fields Summary |
---|
private final JFrame | parent | private final FontPanel | fp | private final RangeMenu | rm | private final ChoiceV2 | fontMenu | private final JTextField | sizeField | private final ChoiceV2 | styleMenu | private final ChoiceV2 | textMenu | private int | currentTextChoice | private final ChoiceV2 | transformMenu | private final ChoiceV2 | transformMenuG2 | private final ChoiceV2 | methodsMenu | private final JCheckBox | useAntialiasCB | private final JCheckBox | useFractionalCB | private CheckboxMenuItemV2 | displayGridCBMI | private CheckboxMenuItemV2 | force16ColsCBMI | private CheckboxMenuItemV2 | showFontInfoCBMI | private JDialog | userTextDialog | private JTextArea | userTextArea | private JDialog | printDialog | private JDialog | fontInfoDialog | private LabelV2[] | fontInfos | private JFileChooser | filePromptDialog | private ButtonGroup | printCBGroup | private JRadioButton[] | printModeCBs | private final LabelV2 | statusBar | private final Font | labelFont | private String | tFileName |
Constructors Summary |
---|
public Font2DTest(JFrame f, boolean isApplet)
/// Initialize GUI variables and its layouts
parent = f;
rm = new RangeMenu( this, parent );
fp = new FontPanel( this, parent );
statusBar = new LabelV2("");
fontMenu = new ChoiceV2( this );
sizeField = new JTextField( "12", 3 );
styleMenu = new ChoiceV2( this );
textMenu = new ChoiceV2( ); // listener added later
transformMenu = new ChoiceV2( this );
transformMenuG2 = new ChoiceV2( this );
methodsMenu = new ChoiceV2( this );
useAntialiasCB = new JCheckBox( "Antialiasing", false );
useFractionalCB = new JCheckBox(" Fractional Metrics", false );
useAntialiasCB.setFont( labelFont );
useFractionalCB.setFont( labelFont );
sizeField.addActionListener( this );
useAntialiasCB.addItemListener( this );
useFractionalCB.addItemListener( this );
setupPanel();
setupMenu( isApplet );
setupDialog( isApplet );
|
Methods Summary |
---|
public void | actionPerformed(java.awt.event.ActionEvent e)
Object source = e.getSource();
if ( source instanceof JMenuItem ) {
JMenuItem mi = (JMenuItem) source;
String itemName = mi.getLabel();
if ( itemName.equals( "Save Selected Options..." )) {
String fileName = promptFile( true, "options.txt" );
if ( fileName != null )
writeCurrentOptions( fileName );
}
else if ( itemName.equals( "Load Options..." )) {
String fileName = promptFile( false, "options.txt" );
if ( fileName != null )
loadOptions( fileName );
}
else if ( itemName.equals( "Save as JPEG..." )) {
String fileName = promptFile( true, fontMenu.getSelectedItem() + ".jpeg" );
if ( fileName != null )
fp.doSaveJPEG( fileName );
}
else if ( itemName.equals( "Load JPEG File to Compare..." )) {
String fileName = promptFile( false, null );
if ( fileName != null )
loadComparisonJPEG( fileName );
}
else if ( itemName.equals( "Page Setup..." ))
fp.doPageSetup();
else if ( itemName.equals( "Print..." ))
printDialog.show();
else if ( itemName.equals( "Close" ))
parent.dispose();
else if ( itemName.equals( "Exit" ))
System.exit(0);
}
else if ( source instanceof JTextField ) {
JTextField tf = (JTextField) source;
int sz = 12;
try {
sz = Integer.parseInt(sizeField.getText());
if (sz < 1 || sz > 120) {
sz = 12;
sizeField.setText("12");
}
} catch (Exception se) {
sizeField.setText("12");
}
if ( tf == sizeField )
fp.setFontParams( fontMenu.getSelectedItem(),
sz,
styleMenu.getSelectedIndex(),
transformMenu.getSelectedIndex() );
}
else if ( source instanceof JButton ) {
String itemName = ( (JButton) source ).getLabel();
/// Print dialog buttons...
if ( itemName.equals( "Print" )) {
for ( int i = 0; i < printModeCBs.length; i++ )
if ( printModeCBs[i].isSelected() ) {
printDialog.hide();
fp.doPrint( i );
}
}
else if ( itemName.equals( "Cancel" ))
printDialog.hide();
/// Update button from Usert Text JDialog...
else if ( itemName.equals( "Update" ))
fp.setTextToDraw( fp.USER_TEXT, null,
parseUserText( userTextArea.getText() ), null );
}
else if ( source instanceof JComboBox ) {
JComboBox c = (JComboBox) source;
/// RangeMenu handles actions by itself and then calls fireRangeChanged,
/// so it is not listed or handled here
if ( c == fontMenu || c == styleMenu || c == transformMenu )
fp.setFontParams( fontMenu.getSelectedItem(),
Integer.parseInt(sizeField.getText()),
styleMenu.getSelectedIndex(),
transformMenu.getSelectedIndex() );
else if ( c == methodsMenu )
fp.setDrawMethod( methodsMenu.getSelectedIndex() );
else if ( c == textMenu ) {
int selected = textMenu.getSelectedIndex();
if ( selected == fp.RANGE_TEXT )
fp.setTextToDraw( fp.RANGE_TEXT, rm.getSelectedRange(),
null, null );
else if ( selected == fp.USER_TEXT )
fp.setTextToDraw( fp.USER_TEXT, null,
parseUserText( userTextArea.getText() ), null );
else if ( selected == fp.FILE_TEXT ) {
String fileName = promptFile( false, null );
if ( fileName != null ) {
tFileName = fileName;
readTextFile( fileName );
} else {
/// User cancelled selection; reset to previous choice
c.setSelectedIndex( currentTextChoice );
return;
}
}
else if ( selected == fp.ALL_GLYPHS )
fp.setTextToDraw( fp.ALL_GLYPHS, null, null, null );
updateGUI();
currentTextChoice = selected;
}
else if ( c == transformMenuG2 ) {
fp.setTransformG2( transformMenuG2.getSelectedIndex() );
}
}
| private void | addLabeledComponentToGBL(java.lang.String name, javax.swing.JComponent c, java.awt.GridBagLayout gbl, java.awt.GridBagConstraints gbc, java.awt.Container target)
LabelV2 l = new LabelV2( name );
GridBagConstraints gbcLabel = (GridBagConstraints) gbc.clone();
gbcLabel.insets = new Insets( 2, 2, 2, 0 );
gbcLabel.gridwidth = 1;
gbcLabel.weightx = 0;
if ( c == null )
c = new JLabel( "" );
gbl.setConstraints( l, gbcLabel );
target.add( l );
gbl.setConstraints( c, gbc );
target.add( c );
| public void | fireChangeStatus(java.lang.String message, boolean error)
/// If this is not ran as an applet, use own status bar,
/// Otherwise, use the appletviewer/browser's status bar
statusBar.setText( message );
if ( error )
fp.showingError = true;
else
fp.showingError = false;
| public void | fireRangeChanged()
int range[] = rm.getSelectedRange();
fp.setTextToDraw( fp.RANGE_TEXT, range, null, null );
if ( showFontInfoCBMI.getState() )
fireUpdateFontInfo();
| public void | fireUpdateFontInfo()
if ( showFontInfoCBMI.getState() ) {
String infos[] = fp.getFontInfo();
for ( int i = 0; i < fontInfos.length; i++ )
fontInfos[i].setText( infos[i] );
fontInfoDialog.pack();
}
| public void | itemStateChanged(java.awt.event.ItemEvent e)
Object source = e.getSource();
if ( source instanceof JCheckBoxMenuItem ) {
JCheckBoxMenuItem cbmi = (JCheckBoxMenuItem) source;
if ( cbmi == displayGridCBMI )
fp.setGridDisplay( displayGridCBMI.getState() );
else if ( cbmi == force16ColsCBMI )
fp.setForce16Columns( force16ColsCBMI.getState() );
else if ( cbmi == showFontInfoCBMI ) {
if ( showFontInfoCBMI.getState() ) {
fireUpdateFontInfo();
fontInfoDialog.show();
}
else
fontInfoDialog.hide();
}
}
else if ( source instanceof JCheckBox ) {
fp.setRenderingHints( useAntialiasCB.isSelected(),
useFractionalCB.isSelected() );
}
| private void | loadComparisonJPEG(java.lang.String fileName)
try {
BufferedInputStream bis =
new BufferedInputStream( new FileInputStream( fileName ));
JPEGImageDecoder jid = JPEGCodec.createJPEGDecoder( bis );
BufferedImage image = jid.decodeAsBufferedImage();
bis.close();
JFrame f = new JFrame( "Comparison JPEG" );
ImagePanel ip = new ImagePanel( image );
f.setResizable( false );
f.getContentPane().add( ip );
f.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
( (JFrame) e.getSource() ).dispose();
}
});
f.pack();
f.show();
}
catch ( Exception ex ) {
fireChangeStatus( "ERROR: Failed to Load JPEG File; See Stack Trace", true );
ex.printStackTrace();
}
| private void | loadOptions(java.lang.String fileName)
try {
BufferedInputStream bis =
new BufferedInputStream( new FileInputStream( fileName ));
int numBytes = bis.available();
byte byteData[] = new byte[ numBytes ];
bis.read( byteData, 0, numBytes );
bis.close();
if ( numBytes < 2 ||
(byteData[0] != (byte) 0xFE || byteData[1] != (byte) 0xFF) )
throw new Exception( "Not a Font2DTest options file" );
String options = new String( byteData, "UTF-16" );
StringTokenizer perLine = new StringTokenizer( options, "\n" );
String title = perLine.nextToken();
if ( !title.equals( "Font2DTest Option File" ))
throw new Exception( "Not a Font2DTest options file" );
/// Parse all options
boolean displayGridOpt = new Boolean( perLine.nextToken() ).booleanValue();
boolean force16ColsOpt = new Boolean( perLine.nextToken() ).booleanValue();
boolean showFontInfoOpt = new Boolean( perLine.nextToken() ).booleanValue();
String rangeNameOpt = perLine.nextToken();
int rangeStartOpt = Integer.parseInt( perLine.nextToken() );
int rangeEndOpt = Integer.parseInt( perLine.nextToken() );
String fontNameOpt = perLine.nextToken();
int fontSizeOpt = Integer.parseInt( perLine.nextToken() );
int fontStyleOpt = Integer.parseInt( perLine.nextToken() );
int fontTransformOpt = Integer.parseInt( perLine.nextToken() );
int g2TransformOpt = Integer.parseInt( perLine.nextToken() );
int textToUseOpt = Integer.parseInt( perLine.nextToken() );
int drawMethodOpt = Integer.parseInt( perLine.nextToken() );
boolean useAntialiasOpt = new Boolean( perLine.nextToken() ).booleanValue();
boolean useFractionalOpt = new Boolean( perLine.nextToken() ).booleanValue();
String userTextOpt[] = { "Java2D!" }, dialogEntry = "Java2D!";
if (textToUseOpt == fp.USER_TEXT ) {
int numLines = perLine.countTokens(), lineNumber = 0;
if ( numLines != 0 ) {
userTextOpt = new String[ numLines ];
dialogEntry = "";
for ( ; perLine.hasMoreElements(); lineNumber++ ) {
userTextOpt[ lineNumber ] = perLine.nextToken();
dialogEntry += userTextOpt[ lineNumber ] + "\n";
}
}
}
/// Reset GUIs
displayGridCBMI.setState( displayGridOpt );
force16ColsCBMI.setState( force16ColsOpt );
showFontInfoCBMI.setState( showFontInfoOpt );
rm.setSelectedRange( rangeNameOpt, rangeStartOpt, rangeEndOpt );
fontMenu.setSelectedItem( fontNameOpt );
sizeField.setText( String.valueOf( fontSizeOpt ));
styleMenu.setSelectedIndex( fontStyleOpt );
transformMenu.setSelectedIndex( fontTransformOpt );
transformMenuG2.setSelectedIndex( g2TransformOpt );
textMenu.setSelectedIndex( textToUseOpt );
methodsMenu.setSelectedIndex( drawMethodOpt );
useAntialiasCB.setSelected( useAntialiasOpt );
useFractionalCB.setSelected( useFractionalOpt );
userTextArea.setText( dialogEntry );
updateGUI();
if ( textToUseOpt == fp.FILE_TEXT ) {
tFileName = perLine.nextToken();
readTextFile(tFileName );
}
/// Reset option variables and repaint
fp.loadOptions( displayGridOpt, force16ColsOpt, rangeStartOpt, rangeEndOpt,
fontNameOpt, fontSizeOpt, fontStyleOpt, fontTransformOpt, g2TransformOpt,
textToUseOpt, drawMethodOpt, useAntialiasOpt,
useFractionalOpt, userTextOpt );
if ( showFontInfoOpt ) {
fireUpdateFontInfo();
fontInfoDialog.show();
}
else
fontInfoDialog.hide();
}
catch ( Exception ex ) {
fireChangeStatus( "ERROR: Failed to Load Options File; See Stack Trace", true );
ex.printStackTrace();
}
| public static void | main(java.lang.String[] argv)
final JFrame f = new JFrame( "Font2DTest" );
final Font2DTest f2dt = new Font2DTest( f, false );
f.addWindowListener( new WindowAdapter() {
public void windowOpening( WindowEvent e ) { f2dt.repaint(); }
public void windowClosing( WindowEvent e ) { System.exit(0); }
});
f.getContentPane().add( f2dt );
f.pack();
f.show();
| private java.lang.String[] | parseUserText(java.lang.String orig)
int length = orig.length();
StringTokenizer perLine = new StringTokenizer( orig, "\n" );
String textLines[] = new String[ perLine.countTokens() ];
int lineNumber = 0;
while ( perLine.hasMoreElements() ) {
String oneLine = perLine.nextToken();
int lineLength = oneLine.length();
int prevEscapeEnd = 0;
int nextEscape = oneLine.indexOf( "\\u" );
StringBuffer converted = new StringBuffer();
while ( nextEscape != -1 ) {
if ( prevEscapeEnd < nextEscape )
converted.append( oneLine.substring( prevEscapeEnd, nextEscape ));
prevEscapeEnd = nextEscape + 6;
try {
String hex = oneLine.substring( nextEscape + 2, nextEscape + 6 );
converted.append( (char) Integer.parseInt( hex, 16 ));
}
catch ( Exception e ) {
int copyLimit =
( nextEscape + 6 < lineLength ) ? ( nextEscape + 6 ) : lineLength;
converted.append( oneLine.substring( nextEscape, copyLimit ));
}
nextEscape = oneLine.indexOf( "\\u", prevEscapeEnd );
}
if ( prevEscapeEnd < lineLength )
converted.append( oneLine.substring( prevEscapeEnd, lineLength ));
textLines[ lineNumber++ ] = converted.toString();
}
return textLines;
| private java.lang.String | promptFile(boolean isSave, java.lang.String initFileName)
int retVal;
String str;
/// ABP
if ( filePromptDialog == null)
return null;
if ( isSave ) {
filePromptDialog.setDialogType( JFileChooser.SAVE_DIALOG );
filePromptDialog.setDialogTitle( "Save..." );
str = "Save";
}
else {
filePromptDialog.setDialogType( JFileChooser.OPEN_DIALOG );
filePromptDialog.setDialogTitle( "Load..." );
str = "Load";
}
if (initFileName != null)
filePromptDialog.setSelectedFile( new File( initFileName ) );
retVal = filePromptDialog.showDialog( this, str );
if ( retVal == JFileChooser.APPROVE_OPTION ) {
File file = filePromptDialog.getSelectedFile();
String fileName = file.getAbsolutePath();
if ( fileName != null ) {
return fileName;
}
}
return null;
| private void | readTextFile(java.lang.String fileName)
try {
String fileText, textLines[];
BufferedInputStream bis =
new BufferedInputStream( new FileInputStream( fileName ));
int numBytes = bis.available();
if (numBytes == 0) {
throw new Exception("Text file " + fileName + " is empty");
}
byte byteData[] = new byte[ numBytes ];
bis.read( byteData, 0, numBytes );
bis.close();
/// If byte mark is found, then use UTF-16 encoding to convert bytes...
if (numBytes >= 2 &&
(( byteData[0] == (byte) 0xFF && byteData[1] == (byte) 0xFE ) ||
( byteData[0] == (byte) 0xFE && byteData[1] == (byte) 0xFF )))
fileText = new String( byteData, "UTF-16" );
/// Otherwise, use system default encoding
else
fileText = new String( byteData );
int length = fileText.length();
StringTokenizer perLine = new StringTokenizer( fileText, "\n" );
/// Determine "Return Char" used in this file
/// This simply finds first occurrence of CR, CR+LF or LF...
for ( int i = 0; i < length; i++ ) {
char iTh = fileText.charAt( i );
if ( iTh == '\r" ) {
if ( i < length - 1 && fileText.charAt( i + 1 ) == '\n" )
perLine = new StringTokenizer( fileText, "\r\n" );
else
perLine = new StringTokenizer( fileText, "\r" );
break;
}
else if ( iTh == '\n" )
/// Use the one already created
break;
}
int lineNumber = 0, numLines = perLine.countTokens();
textLines = new String[ numLines ];
while ( perLine.hasMoreElements() ) {
String oneLine = perLine.nextToken();
if ( oneLine == null )
/// To make LineBreakMeasurer to return a valid TextLayout
/// on an empty line, simply feed it a space char...
oneLine = " ";
textLines[ lineNumber++ ] = oneLine;
}
fp.setTextToDraw( fp.FILE_TEXT, null, null, textLines );
rm.setEnabled( false );
methodsMenu.setEnabled( false );
}
catch ( Exception ex ) {
fireChangeStatus( "ERROR: Failed to Read Text File; See Stack Trace", true );
ex.printStackTrace();
}
| private void | setupDialog(boolean isApplet)
if (!isApplet)
filePromptDialog = new JFileChooser( );
else
filePromptDialog = null;
/// Prepare user text dialog...
userTextDialog = new JDialog( parent, "User Text", false );
JPanel dialogTopPanel = new JPanel();
JPanel dialogBottomPanel = new JPanel();
LabelV2 message1 = new LabelV2( "Enter text below and then press update" );
LabelV2 message2 = new LabelV2( "(Unicode char can be denoted by \\uXXXX)" );
userTextArea = new JTextArea( "Java2D!" );
ButtonV2 bUpdate = new ButtonV2( "Update", this );
userTextArea.setFont( new Font( "dialog", Font.PLAIN, 12 ));
dialogTopPanel.setLayout( new GridLayout( 2, 1 ));
dialogTopPanel.add( "North", message1 );
dialogTopPanel.add( "South", message2 );
dialogBottomPanel.add( bUpdate );
//ABP
JScrollPane userTextAreaSP = new JScrollPane(userTextArea);
userTextAreaSP.setPreferredSize(new Dimension(300, 100));
userTextDialog.getContentPane().setLayout( new BorderLayout() );
userTextDialog.getContentPane().add( "North", dialogTopPanel );
userTextDialog.getContentPane().add( "Center", userTextAreaSP );
userTextDialog.getContentPane().add( "South", dialogBottomPanel );
userTextDialog.pack();
userTextDialog.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
userTextDialog.hide();
}
});
/// Prepare printing dialog...
printCBGroup = new ButtonGroup();
printModeCBs[ fp.ONE_PAGE ] =
new JRadioButton( "Print one page from currently displayed character/line",
true );
printModeCBs[ fp.CUR_RANGE ] =
new JRadioButton( "Print all characters in currently selected range",
false );
printModeCBs[ fp.ALL_TEXT ] =
new JRadioButton( "Print all lines of text",
false );
LabelV2 l =
new LabelV2( "Note: Page range in native \"Print\" dialog will not affect the result" );
JPanel buttonPanel = new JPanel();
printModeCBs[ fp.ALL_TEXT ].setEnabled( false );
buttonPanel.add( new ButtonV2( "Print", this ));
buttonPanel.add( new ButtonV2( "Cancel", this ));
printDialog = new JDialog( parent, "Print...", true );
printDialog.setResizable( false );
printDialog.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
printDialog.hide();
}
});
printDialog.getContentPane().setLayout( new GridLayout( printModeCBs.length + 2, 1 ));
printDialog.getContentPane().add( l );
for ( int i = 0; i < printModeCBs.length; i++ ) {
printModeCBs[i].setFont( labelFont );
printCBGroup.add( printModeCBs[i] );
printDialog.getContentPane().add( printModeCBs[i] );
}
printDialog.getContentPane().add( buttonPanel );
printDialog.pack();
/// Prepare font information dialog...
fontInfoDialog = new JDialog( parent, "Font info", false );
fontInfoDialog.setResizable( false );
fontInfoDialog.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
fontInfoDialog.hide();
showFontInfoCBMI.setState( false );
}
});
JPanel fontInfoPanel = new JPanel();
fontInfoPanel.setLayout( new GridLayout( fontInfos.length, 1 ));
for ( int i = 0; i < fontInfos.length; i++ ) {
fontInfos[i] = new LabelV2("");
fontInfoPanel.add( fontInfos[i] );
}
fontInfoDialog.getContentPane().add( fontInfoPanel );
/// Move the location of the dialog...
userTextDialog.setLocation( 200, 300 );
fontInfoDialog.setLocation( 0, 400 );
| private void | setupMenu(boolean isApplet)
JMenu fileMenu = new JMenu( "File" );
JMenu optionMenu = new JMenu( "Option" );
fileMenu.add( new MenuItemV2( "Save Selected Options...", this ));
fileMenu.add( new MenuItemV2( "Load Options...", this ));
fileMenu.addSeparator();
fileMenu.add( new MenuItemV2( "Save as JPEG...", this ));
fileMenu.add( new MenuItemV2( "Load JPEG File to Compare...", this ));
fileMenu.add( new MenuItemV2( "Page Setup...", this ));
fileMenu.add( new MenuItemV2( "Print...", this ));
fileMenu.addSeparator();
if ( !isApplet )
fileMenu.add( new MenuItemV2( "Exit", this ));
else
fileMenu.add( new MenuItemV2( "Close", this ));
displayGridCBMI = new CheckboxMenuItemV2( "Display Grid", true, this );
force16ColsCBMI = new CheckboxMenuItemV2( "Force 16 Columns", false, this );
showFontInfoCBMI = new CheckboxMenuItemV2( "Display Font Info", false, this );
optionMenu.add( displayGridCBMI );
optionMenu.add( force16ColsCBMI );
optionMenu.add( showFontInfoCBMI );
JMenuBar mb = parent.getJMenuBar();
if ( mb == null )
mb = new JMenuBar();
mb.add( fileMenu );
mb.add( optionMenu );
parent.setJMenuBar( mb );
String fontList[] =
GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
for ( int i = 0; i < fontList.length; i++ )
fontMenu.addItem( fontList[i] );
fontMenu.setSelectedItem( "Dialog" );
styleMenu.addItem( "Plain" );
styleMenu.addItem( "Bold" );
styleMenu.addItem( "Italic" );
styleMenu.addItem( "Bold Italic" );
transformMenu.addItem( "None" );
transformMenu.addItem( "Scale" );
transformMenu.addItem( "Shear" );
transformMenu.addItem( "Rotate" );
transformMenuG2.addItem( "None" );
transformMenuG2.addItem( "Scale" );
transformMenuG2.addItem( "Shear" );
transformMenuG2.addItem( "Rotate" );
methodsMenu.addItem( "drawString" );
methodsMenu.addItem( "drawChars" );
methodsMenu.addItem( "drawBytes" );
methodsMenu.addItem( "drawGlyphVector" );
methodsMenu.addItem( "TextLayout.draw" );
methodsMenu.addItem( "GlyphVector.getOutline + draw" );
methodsMenu.addItem( "TextLayout.getOutline + draw" );
textMenu.addItem( "Unicode Range" );
textMenu.addItem( "All Glyphs" );
textMenu.addItem( "User Text" );
textMenu.addItem( "Text File" );
textMenu.addActionListener ( this ); // listener added later so unneeded events not thrown
| private void | setupPanel()
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 1;
gbc.insets = new Insets( 2, 0, 2, 2 );
this.setLayout( gbl );
addLabeledComponentToGBL( "Font:", fontMenu, gbl, gbc, this );
addLabeledComponentToGBL( "Size:", sizeField, gbl, gbc, this );
gbc.gridwidth = GridBagConstraints.REMAINDER;
addLabeledComponentToGBL( "Transform:", transformMenu, gbl, gbc, this );
gbc.gridwidth = 1;
addLabeledComponentToGBL( "Range:", rm, gbl, gbc, this );
addLabeledComponentToGBL( "Style:", styleMenu, gbl, gbc, this );
gbc.gridwidth = GridBagConstraints.REMAINDER;
addLabeledComponentToGBL( "Text to use:", textMenu, gbl, gbc, this );
gbc.gridwidth = 1;
/// ABP
addLabeledComponentToGBL( "Method:", methodsMenu, gbl, gbc, this );
gbc.anchor = GridBagConstraints.EAST;
gbc.gridwidth = GridBagConstraints.REMAINDER;
addLabeledComponentToGBL( "Graphics2D Transform:", transformMenuG2, gbl, gbc, this );
gbc.gridwidth = 1;
gbc.gridwidth = 2;
gbc.fill = GridBagConstraints.NONE;
gbc.anchor = GridBagConstraints.CENTER;
gbl.setConstraints( useAntialiasCB, gbc );
this.add( useAntialiasCB );
gbc.gridwidth = GridBagConstraints.REMAINDER;
gbl.setConstraints( useFractionalCB, gbc );
this.add( useFractionalCB );
gbc.weightx = 1;
gbc.weighty = 1;
gbc.insets = new Insets( 2, 0, 0, 2 );
gbc.fill = GridBagConstraints.BOTH;
gbl.setConstraints( fp, gbc );
this.add( fp );
gbc.weighty = 0;
gbc.insets = new Insets( 0, 2, 0, 0 );
gbl.setConstraints( statusBar, gbc );
this.add( statusBar );
| private void | updateGUI()
int selectedText = textMenu.getSelectedIndex();
/// Set the visibility of User Text dialog
if ( selectedText == fp.USER_TEXT )
userTextDialog.show();
else
userTextDialog.hide();
/// Change the visibility/status/availability of Print JDialog buttons
printModeCBs[ fp.ONE_PAGE ].setSelected( true );
if ( selectedText == fp.FILE_TEXT || selectedText == fp.USER_TEXT ) {
/// ABP
/// update methodsMenu to show that TextLayout.draw is being used
/// when we are in FILE_TEXT mode
if ( selectedText == fp.FILE_TEXT )
methodsMenu.setSelectedItem("TextLayout.draw");
methodsMenu.setEnabled( selectedText == fp.USER_TEXT );
printModeCBs[ fp.CUR_RANGE ].setEnabled( false );
printModeCBs[ fp.ALL_TEXT ].setEnabled( true );
}
else {
/// ABP
/// update methodsMenu to show that drawGlyph is being used
/// when we are in ALL_GLYPHS mode
if ( selectedText == fp.ALL_GLYPHS )
methodsMenu.setSelectedItem("drawGlyphVector");
methodsMenu.setEnabled( selectedText == fp.RANGE_TEXT );
printModeCBs[ fp.CUR_RANGE ].setEnabled( true );
printModeCBs[ fp.ALL_TEXT ].setEnabled( false );
}
/// Modify RangeMenu and fontInfo label availabilty
if ( selectedText == fp.RANGE_TEXT ) {
fontInfos[1].setVisible( true );
rm.setEnabled( true );
}
else {
fontInfos[1].setVisible( false );
rm.setEnabled( false );
}
| private void | writeCurrentOptions(java.lang.String fileName)
try {
String curOptions = fp.getCurrentOptions();
BufferedOutputStream bos =
new BufferedOutputStream( new FileOutputStream( fileName ));
/// Prepend title and the option that is only obtainable here
int range[] = rm.getSelectedRange();
String completeOptions =
( "Font2DTest Option File\n" +
displayGridCBMI.getState() + "\n" +
force16ColsCBMI.getState() + "\n" +
showFontInfoCBMI.getState() + "\n" +
rm.getSelectedItem() + "\n" +
range[0] + "\n" + range[1] + "\n" + curOptions + tFileName);
byte toBeWritten[] = completeOptions.getBytes( "UTF-16" );
bos.write( toBeWritten, 0, toBeWritten.length );
bos.close();
}
catch ( Exception ex ) {
fireChangeStatus( "ERROR: Failed to Save Options File; See Stack Trace", true );
ex.printStackTrace();
}
|
|