/*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* This source code is provided to illustrate the usage of a given feature
* or technique and has been deliberately simplified. Additional steps
* required for a production-quality application, such as security checks,
* input validation and proper error handling, might not be present in
* this sample code.
*/
/**
*
* @author Shinsuke Fukuda
* @author Ankit Patel [Conversion to Swing - 01/07/30]
*/
/// Main Font2DTest Class
/// JFrame that will contain Font2DTest
/// FontPanel class that will contain all graphical output
/// RangeMenu class that contains info about the unicode ranges
/// Other menus to set parameters for text drawing
/// CheckboxMenuItems
/// JDialog boxes
/// Status bar
/// Text filename
// Enabled or disabled status of canDisplay check
private static boolean canDisplayCheck = true;
/// Initialize GUI variables and its layouts
parent = f;
sizeField.addActionListener( this );
transformMenu = new ChoiceV2( this );
transformMenuG2 = new ChoiceV2( this );
methodsMenu = new ChoiceV2( this );
antiAliasMenu.addActionListener(this);
fracMetricsMenu.addActionListener(this);
contrastSlider.setEnabled(false);
contrastSlider.setPaintTicks(true);
contrastSlider.setPaintLabels(true);
contrastSlider.addChangeListener(this);
setupPanel();
setupDialog( isApplet );
if(canDisplayCheck) {
}
}
/// Set up the main interface panel
private void setupPanel() {
addLabeledComponentToGBL( "Font Transform:",
addLabeledComponentToGBL( "Graphics Transform: ",
addLabeledComponentToGBL("LCD contrast: ",
addLabeledComponentToGBL("Antialiasing: ",
addLabeledComponentToGBL("Fractional metrics: ",
}
/// Adds a component to a container with a label to its left in GridBagLayout
JComponent c,
if ( c == null )
c = new JLabel( "" );
}
/// Sets up menu entries
if ( !isApplet )
else
}
/// Sets up the all dialogs used in Font2DTest...
if (!isApplet)
filePromptDialog = new JFileChooser( );
else
/// Prepare user text dialog...
//ABP
public void windowClosing( WindowEvent e ) {
}
});
/// Prepare printing dialog...
printCBGroup = new ButtonGroup();
new JRadioButton( "Print one page from currently displayed character/line",
true );
new JRadioButton( "Print all characters in currently selected range",
false );
new JRadioButton( "Print all lines of text",
false );
LabelV2 l =
new LabelV2( "Note: Page range in native \"Print\" dialog will not affect the result" );
printDialog.setResizable( false );
public void windowClosing( WindowEvent e ) {
printDialog.hide();
}
});
}
printDialog.pack();
/// Prepare font information dialog...
fontInfoDialog.setResizable( false );
public void windowClosing( WindowEvent e ) {
showFontInfoCBMI.setState( false );
}
});
}
/// Move the location of the dialog...
}
/// RangeMenu object signals using this function
/// when Unicode range has been changed and text needs to be redrawn
public void fireRangeChanged() {
if(canDisplayCheck) {
}
if ( showFontInfoCBMI.getState() )
}
/// Changes the message on the status bar
/// If this is not ran as an applet, use own status bar,
/// Otherwise, use the appletviewer/browser's status bar
if ( error )
fp.showingError = true;
else
fp.showingError = false;
}
/// Updates the information about the selected font
public void fireUpdateFontInfo() {
if ( showFontInfoCBMI.getState() ) {
}
}
int size = 16;
try {
}
catch ( Exception e ) {
}
Font f;
for (int i = 0; i < listCount; i++) {
}
else {
}
}
}
for (int i = rangeStart; i < rangeEnd; i++) {
if (font.canDisplay(i)) {
return true;
}
}
return false;
}
int retVal;
/// ABP
if ( filePromptDialog == null)
return null;
if ( isSave ) {
str = "Save";
}
else {
str = "Load";
}
if (initFileName != null)
return fileName;
}
}
return null;
}
/// Converts user text into arrays of String, delimited at newline character
/// Also replaces any valid escape sequence with appropriate unicode character
/// Support \\UXXXXXX notation for surrogates
int lineNumber = 0;
while ( perLine.hasMoreElements() ) {
int prevEscapeEnd = 0;
int nextEscape = -1;
do {
? ((nextSupEscape < 0)
? -1
: ((nextSupEscape < 0)
if ( nextEscape != -1 ) {
if ( prevEscapeEnd < nextEscape )
try {
if (nextEscape == nextBMPEscape) {
} else {
}
}
catch ( Exception e ) {
}
}
} while (nextEscape != -1);
if ( prevEscapeEnd < lineLength )
}
return textLines;
}
/// Reads the text from specified file, detecting UTF-16 encoding
/// Then breaks the text into String array, delimited at every line break
try {
if (numBytes == 0) {
}
/// If byte mark is found, then use UTF-16 encoding to convert bytes...
if (numBytes >= 2 &&
/// Otherwise, use system default encoding
else
/// 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++ ) {
if ( iTh == '\r' ) {
else
break;
}
else if ( iTh == '\n' )
/// Use the one already created
break;
}
while ( perLine.hasMoreElements() ) {
/// To make LineBreakMeasurer to return a valid TextLayout
/// on an empty line, simply feed it a space char...
oneLine = " ";
}
rm.setEnabled( false );
methodsMenu.setEnabled( false );
}
fireChangeStatus( "ERROR: Failed to Read Text File; See Stack Trace", true );
}
}
/// Returns a String storing current configuration
try {
/// Prepend title and the option that is only obtainable here
( "Font2DTest Option File\n" +
}
fireChangeStatus( "ERROR: Failed to Save Options File; See Stack Trace", true );
}
}
/// Updates GUI visibility/status after some parameters have changed
private void updateGUI() {
/// Set the visibility of User Text dialog
else
/// Change the visibility/status/availability of Print JDialog buttons
/// ABP
/// update methodsMenu to show that TextLayout.draw is being used
/// when we are in FILE_TEXT mode
}
else {
/// ABP
/// update methodsMenu to show that drawGlyph is being used
/// when we are in ALL_GLYPHS mode
}
/// Modify RangeMenu and fontInfo label availabilty
rm.setEnabled( true );
}
else {
rm.setEnabled( false );
}
}
/// Loads saved options and applies them
try {
if ( numBytes < 2 ||
throw new Exception( "Not a Font2DTest options file" );
throw new Exception( "Not a Font2DTest options file" );
/// Parse all options
if ( numLines != 0 ) {
dialogEntry = "";
}
}
}
/// Reset GUIs
updateGUI();
}
/// Reset option variables and repaint
if ( showFontInfoOpt ) {
}
else
}
fireChangeStatus( "ERROR: Failed to Load Options File; See Stack Trace", true );
}
}
/// Loads a previously saved image
try {
f.setResizable( false );
f.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
}
});
f.pack();
f.show();
}
fireChangeStatus( "ERROR: Failed to Load PNG File; See Stack Trace", true );
}
}
/// Interface functions...
/// ActionListener interface function
/// Responds to JMenuItem, JTextField and JButton actions
}
loadOptions( fileName );
}
}
}
fp.doPageSetup();
printDialog.show();
}
else if ( source instanceof JTextField ) {
float sz = 12f;
try {
sz = 12f;
}
}
sz,
}
/// Print dialog buttons...
if ( printModeCBs[i].isSelected() ) {
printDialog.hide();
}
}
printDialog.hide();
/// Update button from Usert Text JDialog...
}
/// RangeMenu handles actions by itself and then calls fireRangeChanged,
/// so it is not listed or handled here
float sz = 12f;
try {
sz = 12f;
}
}
sz,
} else if ( c == methodsMenu )
else if ( c == textMenu ) {
if(canDisplayCheck) {
}
readTextFile( fileName );
} else {
/// User cancelled selection; reset to previous choice
return;
}
}
updateGUI();
}
else if ( c == transformMenuG2 ) {
}
else if (c == antiAliasMenu || c == fracMetricsMenu) {
if (c == antiAliasMenu) {
}
}
}
}
}
}
/// ItemListener interface function
/// Responds to JCheckBoxMenuItem, JComboBox and JCheckBox actions
if ( source instanceof JCheckBoxMenuItem ) {
if ( cbmi == displayGridCBMI )
else if ( cbmi == force16ColsCBMI )
else if ( cbmi == showFontInfoCBMI ) {
if ( showFontInfoCBMI.getState() ) {
}
else
}
}
}
private static void printUsage() {
"\nwhere options include:\n" +
" -dcdc | -disablecandisplaycheck disable canDisplay check for font\n" +
" -? | -help print this help message\n" +
"\nExample :\n" +
" To disable canDisplay check on font for ranges\n" +
" java -jar Font2DTest.jar -dcdc";
}
/// Main function
canDisplayCheck = false;
}
else {
printUsage();
}
}
f.addWindowListener( new WindowAdapter() {
});
f.pack();
f.show();
}
/// Inner class definitions...
/// Class to display just an image file
/// Used to show the comparison PNG image
}
}
}
}
/// Classes made to avoid repetitive calls... (being lazy)
super( name );
this.addActionListener( al );
}
}
public ChoiceV2() {;}
super();
this.addActionListener( al );
}
this(al);
if(fontChoice) {
//Register this component in ToolTipManager
setToolTipText("");
setRenderer(new ChoiceV2Renderer(this));
}
}
int index = this.getSelectedIndex();
}
else {
}
}
return super.getToolTipText();
}
}
}
}
g.dispose();
}
int index,
boolean isSelected,
boolean cellHasFocus) {
//For JComboBox if index is -1, its rendering the selected index.
if(index == -1) {
}
}
else {
}
} else {
}
return this;
}
}
super( name );
}
}
super( name );
this.addActionListener( al );
}
}
super( name, b );
this.addItemListener( il );
}
}
}