jdk/src/share/demo/jfc/Font2DTest/FontPanel.java
author goetz
Thu, 21 Nov 2013 18:29:34 -0800
changeset 22852 1063026e8cee
parent 21278 ef8a3a2a72f2
child 23010 6dadb192ad81
permissions -rw-r--r--
8028471: PPC64 (part 215): opto: Extend ImplicitNullCheck optimization. Summary: Fixed Implicit NULL check optimization for AIX, where the page at address '0' is only write-protected. Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 10292
diff changeset
     2
 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * Redistribution and use in source and binary forms, with or without
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * modification, are permitted provided that the following conditions
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * are met:
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *   - Redistributions of source code must retain the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 *     notice, this list of conditions and the following disclaimer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *   - Redistributions in binary form must reproduce the above copyright
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 *     notice, this list of conditions and the following disclaimer in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 *     documentation and/or other materials provided with the distribution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    15
 *   - Neither the name of Oracle nor the names of its
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *     contributors may be used to endorse or promote products derived
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *     from this software without specific prior written permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
10292
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    32
/*
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    33
 * This source code is provided to illustrate the usage of a given feature
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    34
 * or technique and has been deliberately simplified. Additional steps
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    35
 * required for a production-quality application, such as security checks,
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    36
 * input validation and proper error handling, might not be present in
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    37
 * this sample code.
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    38
 */
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    39
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 5506
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.BorderLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.Cursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.FontMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.Graphics2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.awt.RenderingHints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.awt.Toolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.awt.event.AdjustmentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.awt.event.AdjustmentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.awt.event.ComponentAdapter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.awt.event.ComponentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import java.awt.event.MouseEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import java.awt.event.MouseListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import java.awt.event.MouseMotionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import java.awt.font.FontRenderContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import java.awt.font.GlyphVector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import java.awt.font.LineBreakMeasurer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import java.awt.font.TextLayout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import java.awt.geom.AffineTransform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import java.awt.geom.NoninvertibleTransformException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import java.awt.geom.Rectangle2D;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import java.awt.print.PageFormat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import java.awt.print.Printable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import java.awt.print.PrinterJob;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import java.io.BufferedOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
import java.io.FileOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
import java.text.AttributedString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
import java.util.EnumSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
import javax.imageio.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
import static java.awt.RenderingHints.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * FontPanel.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * @author Shinsuke Fukuda
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * @author Ankit Patel [Conversion to Swing - 01/07/30]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
/// This panel is combination of the text drawing area of Font2DTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
/// and the custom controlled scroll bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
public final class FontPanel extends JPanel implements AdjustmentListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /// Drawing Option Constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private final String STYLES[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
      { "plain", "bold", "italic", "bold italic" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private final int NONE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private final int SCALE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private final int SHEAR = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private final int ROTATE = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private final String TRANSFORMS[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
      { "with no transforms", "with scaling", "with Shearing", "with rotation" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private final int DRAW_STRING = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    private final int DRAW_CHARS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private final int DRAW_BYTES = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private final int DRAW_GLYPHV = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private final int TL_DRAW = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private final int GV_OUTLINE = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private final int TL_OUTLINE = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private final String METHODS[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        "drawString", "drawChars", "drawBytes", "drawGlyphVector",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        "TextLayout.draw", "GlyphVector.getOutline", "TextLayout.getOutline" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public final int RANGE_TEXT = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public final int ALL_GLYPHS = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public final int USER_TEXT = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public final int FILE_TEXT = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private final String MS_OPENING[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
      { " Unicode ", " Glyph Code ", " lines ", " lines " };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private final String MS_CLOSING[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
      { "", "", " of User Text ", " of LineBreakMeasurer-reformatted Text " };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /// General Graphics Variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private final JScrollBar verticalBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private final FontCanvas fc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private boolean updateBackBuffer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private boolean updateFontMetrics = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private boolean updateFont = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private boolean force16Cols = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public boolean showingError = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private int g2Transform = NONE; /// ABP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /// Printing constants and variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public final int ONE_PAGE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public final int CUR_RANGE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public final int ALL_TEXT = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private int printMode = ONE_PAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private PageFormat page = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private PrinterJob printer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /// Text drawing variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private String fontName = "Dialog";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private float fontSize = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    private int fontStyle = Font.PLAIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private int fontTransform = NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private Font testFont = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    private Object antiAliasType = VALUE_TEXT_ANTIALIAS_DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private Object fractionalMetricsType = VALUE_FRACTIONALMETRICS_DEFAULT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    private Object lcdContrast = getDefaultLCDContrast();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private int drawMethod = DRAW_STRING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private int textToUse = RANGE_TEXT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private String userText[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private String fileText[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private int drawRange[] = { 0x0000, 0x007f };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    private String fontInfos[] = new String[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private boolean showGrid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /// Parent Font2DTest panel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    private final Font2DTest f2dt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    private final JFrame parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public FontPanel( Font2DTest demo, JFrame f ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        f2dt = demo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        parent = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        verticalBar = new JScrollBar ( JScrollBar.VERTICAL );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        fc = new FontCanvas();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        this.setLayout( new BorderLayout() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        this.add( "Center", fc );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        this.add( "East", verticalBar );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        verticalBar.addAdjustmentListener( this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        this.addComponentListener( new ComponentAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            public void componentResized( ComponentEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                updateBackBuffer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                updateFontMetrics = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        /// Initialize font and its infos
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        testFont = new Font(fontName, fontStyle, (int)fontSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if ((float)((int)fontSize) != fontSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            testFont = testFont.deriveFont(fontSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        updateFontInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return new Dimension(600, 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /// Functions called by the main programs to set the various parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public void setTransformG2( int transform ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        g2Transform = transform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        updateBackBuffer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        updateFontMetrics = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        fc.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /// convenience fcn to create AffineTransform of appropriate type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    private AffineTransform getAffineTransform( int transform ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            /// ABP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            AffineTransform at = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            switch ( transform )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            case SCALE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
              at.setToScale( 1.5f, 1.5f ); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            case ROTATE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
              at.setToRotation( Math.PI / 6 ); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            case SHEAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
              at.setToShear( 0.4f, 0 ); break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            case NONE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
              //System.err.println( "Illegal G2 Transform Arg: " + transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return at;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public void setFontParams(Object obj, float size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                              int style, int transform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        setFontParams( (String)obj, size, style, transform );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public void setFontParams(String name, float size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                              int style, int transform) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        boolean fontModified = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        if ( !name.equals( fontName ) || style != fontStyle )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
          fontModified = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        fontName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        fontSize = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        fontStyle = style;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        fontTransform = transform;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        /// Recreate the font as specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        testFont = new Font(fontName, fontStyle, (int)fontSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if ((float)((int)fontSize) != fontSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            testFont = testFont.deriveFont(fontSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if ( fontTransform != NONE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            AffineTransform at = getAffineTransform( fontTransform );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            testFont = testFont.deriveFont( at );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        updateBackBuffer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        updateFontMetrics = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        fc.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if ( fontModified ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            /// Tell main panel to update the font info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            updateFontInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            f2dt.fireUpdateFontInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public void setRenderingHints( Object aa, Object fm, Object contrast) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        antiAliasType = ((AAValues)aa).getHint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        fractionalMetricsType = ((FMValues)fm).getHint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        lcdContrast = contrast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        updateBackBuffer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        updateFontMetrics = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        fc.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public void setDrawMethod( int i ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        drawMethod = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        updateBackBuffer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        fc.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public void setTextToDraw( int i, int range[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                               String textSet[], String fileData[] ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        textToUse = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if ( textToUse == RANGE_TEXT )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
          drawRange = range;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        else if ( textToUse == ALL_GLYPHS )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
          drawMethod = DRAW_GLYPHV;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        else if ( textToUse == USER_TEXT )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
          userText = textSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        else if ( textToUse == FILE_TEXT ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            fileText = fileData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            drawMethod = TL_DRAW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        updateBackBuffer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        updateFontMetrics = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        fc.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        updateFontInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public void setGridDisplay( boolean b ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        showGrid = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        updateBackBuffer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        fc.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public void setForce16Columns( boolean b ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        force16Cols = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        updateBackBuffer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        updateFontMetrics = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        fc.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /// Prints out the text display area
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public void doPrint( int i ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        if ( printer == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            printer = PrinterJob.getPrinterJob();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            page = printer.defaultPage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        printMode = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        printer.setPrintable( fc, page );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if ( printer.printDialog() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                printer.print();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            catch ( Exception e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                f2dt.fireChangeStatus( "ERROR: Printing Failed; See Stack Trace", true );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /// Displays the page setup dialog and updates PageFormat info
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    public void doPageSetup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if ( printer == null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            printer = PrinterJob.getPrinterJob();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            page = printer.defaultPage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        page = printer.pageDialog( page );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /// Obtains the information about selected font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    private void updateFontInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        int numGlyphs = 0, numCharsInRange = drawRange[1] - drawRange[0] + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        fontInfos[0] = "Font Face Name: " + testFont.getFontName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        fontInfos[1] = "Glyphs in This Range: ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if ( textToUse == RANGE_TEXT ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            for ( int i = drawRange[0]; i < drawRange[1]; i++ )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
              if ( testFont.canDisplay( i ))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                numGlyphs++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            fontInfos[1] = fontInfos[1] + numGlyphs + " / " + numCharsInRange;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
          fontInfos[1] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /// Accessor for the font information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public String[] getFontInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return fontInfos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /// Collects the currectly set options and returns them as string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public String getCurrentOptions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        /// Create a new String to store the options
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        /// The array will contain all 8 setting (font name, size...) and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        /// character range or user text data used (no file text data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        int userTextSize = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        String options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        options = ( fontName + "\n" + fontSize  + "\n" + fontStyle + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    fontTransform + "\n"  + g2Transform + "\n"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    textToUse + "\n" + drawMethod + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    AAValues.getHintVal(antiAliasType) + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                    FMValues.getHintVal(fractionalMetricsType) + "\n" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    lcdContrast + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if ( textToUse == USER_TEXT )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
          for ( int i = 0; i < userText.length; i++ )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            options += ( userText[i] + "\n" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        return options;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /// Reload all options and refreshes the canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public void loadOptions( boolean grid, boolean force16, int start, int end,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                             String name, float size, int style,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                             int transform, int g2transform,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                             int text, int method, int aa, int fm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                             int contrast, String user[] ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        int range[] = { start, end };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        /// Since repaint call has a low priority, these functions will finish
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        /// before the actual repainting is done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        setGridDisplay( grid );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        setForce16Columns( force16 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        // previous call to readTextFile has already set the text to draw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        if (textToUse != FILE_TEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
          setTextToDraw( text, range, user, null );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        setFontParams( name, size, style, transform );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        setTransformG2( g2transform ); // ABP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        setDrawMethod( method );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        setRenderingHints(AAValues.getValue(aa), FMValues.getValue(fm),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                          new Integer(contrast));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /// Writes the current screen to PNG file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public void doSavePNG( String fileName ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        fc.writePNG( fileName );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /// When scrolled using the scroll bar, update the backbuffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public void adjustmentValueChanged( AdjustmentEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        updateBackBuffer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        fc.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    public void paintComponent( Graphics g ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        // Windows does not repaint correctly, after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        // a zoom. Thus, we need to force the canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        // to repaint, but only once. After the first repaint,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        // everything stabilizes. [ABP]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        fc.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    /// Inner class definition...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    /// Inner panel that holds the actual drawing area and its routines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    private class FontCanvas extends JPanel implements MouseListener, MouseMotionListener, Printable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        /// Number of characters that will fit across and down this canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        private int numCharAcross, numCharDown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        /// First and last character/line that will be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        /// Limit is the end of range/text where no more draw will be done
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        private int drawStart, drawEnd, drawLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        /// FontMetrics variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        /// Here, gridWidth is equivalent to maxAdvance (slightly bigger though)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        /// and gridHeight is equivalent to lineHeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        private int maxAscent, maxDescent, gridWidth = 0, gridHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        /// Offset from the top left edge of the canvas where the draw will start
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        private int canvasInset_X = 5, canvasInset_Y = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        /// Offscreen buffer of this canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        private BufferedImage backBuffer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        /// LineBreak'ed TextLayout vector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        private Vector lineBreakTLs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        /// Whether the current draw command requested is for printing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        private boolean isPrinting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        /// Other printing infos
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        private int lastPage, printPageNumber, currentlyShownChar = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        private final int PR_OFFSET = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        private final int PR_TITLE_LINEHEIGHT = 30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        /// Information about zooming (used with range text draw)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        private final JWindow zoomWindow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        private BufferedImage zoomImage = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        private int mouseOverCharX = -1, mouseOverCharY = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        private int currMouseOverChar = -1, prevZoomChar = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        private float ZOOM = 2.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        private boolean nowZooming = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        private boolean firstTime = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
// ABP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        /// Status bar message backup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        private String backupStatusString = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        /// Error constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        private final String ERRORS[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            "ERROR: drawBytes cannot handle characters beyond 0x00FF. Select different range or draw methods.",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            "ERROR: Cannot fit text with the current font size. Resize the window or use smaller font size.",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            "ERROR: Cannot print with the current font size. Use smaller font size.",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        private final int DRAW_BYTES_ERROR = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        private final int CANT_FIT_DRAW = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        private final int CANT_FIT_PRINT = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        /// Other variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        private final Cursor blankCursor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        public FontCanvas() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            this.addMouseListener( this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            this.addMouseMotionListener( this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            this.setForeground( Color.black );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            this.setBackground( Color.white );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            /// Creates an invisble pointer by giving it bogus image
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            /// Possibly find a workaround for this...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            Toolkit tk = Toolkit.getDefaultToolkit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            byte bogus[] = { (byte) 0 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            blankCursor =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
              tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            zoomWindow = new JWindow( parent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                public void paint( Graphics g ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    g.drawImage( zoomImage, 0, 0, zoomWindow );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            zoomWindow.setCursor( blankCursor );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            zoomWindow.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        public boolean firstTime() { return firstTime; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        public void refresh() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            firstTime = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            updateBackBuffer = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        /// Sets the font, hints, according to the set parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        private void setParams( Graphics2D g2 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            g2.setFont( testFont );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            g2.setRenderingHint(KEY_TEXT_ANTIALIASING, antiAliasType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            g2.setRenderingHint(KEY_FRACTIONALMETRICS, fractionalMetricsType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            g2.setRenderingHint(KEY_TEXT_LCD_CONTRAST, lcdContrast);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            /* I am preserving a somewhat dubious behaviour of this program.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
             * Outline text would be drawn anti-aliased by setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
             * graphics anti-aliasing hint if the text anti-aliasing hint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
             * was set. The dubious element here is that people simply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
             * using this program may think this is built-in behaviour
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 14342
diff changeset
   527
             * but its not - at least not when the app explicitly draws
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
             * outline text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
             * This becomes more dubious in cases such as "GASP" where the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
             * size at which text is AA'ed is not something you can easily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
             * calculate, so mimicing that behaviour isn't going to be easy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
             * So I precisely preserve the behaviour : this is done only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
             * if the AA value is "ON". Its not applied in the other cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            if (antiAliasType == VALUE_TEXT_ANTIALIAS_ON &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                (drawMethod == TL_OUTLINE || drawMethod == GV_OUTLINE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_OFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        /// Draws the grid (Used for unicode/glyph range drawing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        private void drawGrid( Graphics2D g2 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            int totalGridWidth = numCharAcross * gridWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            int totalGridHeight = numCharDown * gridHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            g2.setColor( Color.black );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            for ( int i = 0; i < numCharDown + 1; i++ )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
              g2.drawLine( canvasInset_X, i * gridHeight + canvasInset_Y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                           canvasInset_X + totalGridWidth, i * gridHeight + canvasInset_Y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            for ( int i = 0; i < numCharAcross + 1; i++ )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
              g2.drawLine( i * gridWidth + canvasInset_X, canvasInset_Y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                           i * gridWidth + canvasInset_X, canvasInset_Y + totalGridHeight );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        /// Draws one character at time onto the canvas according to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        /// the method requested (Used for RANGE_TEXT and ALL_GLYPHS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        public void modeSpecificDrawChar( Graphics2D g2, int charCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                                          int baseX, int baseY ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            GlyphVector gv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            int oneGlyph[] = { charCode };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            char charArray[] = Character.toChars( charCode );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            FontRenderContext frc = g2.getFontRenderContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            AffineTransform oldTX = g2.getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            /// Create GlyphVector to measure the exact visual advance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            /// Using that number, adjust the position of the character drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            if ( textToUse == ALL_GLYPHS )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
              gv = testFont.createGlyphVector( frc, oneGlyph );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
              gv = testFont.createGlyphVector( frc, charArray );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            Rectangle2D r2d2 = gv.getPixelBounds(frc, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            int shiftedX = baseX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            // getPixelBounds returns a result in device space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            // we need to convert back to user space to be able to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            // calculate the shift as baseX is in user space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                 double pt[] = new double[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                 pt[0] = r2d2.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                 pt[1] = r2d2.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                 pt[2] = r2d2.getX()+r2d2.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                 pt[3] = r2d2.getY()+r2d2.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                 oldTX.inverseTransform(pt,0,pt,0,2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                 shiftedX = baseX - (int) ( pt[2] / 2 + pt[0] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            } catch (NoninvertibleTransformException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            /// ABP - keep track of old tform, restore it later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            g2.translate( shiftedX, baseY );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            g2.transform( getAffineTransform( g2Transform ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            if ( textToUse == ALL_GLYPHS )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
              g2.drawGlyphVector( gv, 0f, 0f );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                if ( testFont.canDisplay( charCode ))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                  g2.setColor( Color.black );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                  g2.setColor( Color.lightGray );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                switch ( drawMethod ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                  case DRAW_STRING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                    g2.drawString( new String( charArray ), 0, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                  case DRAW_CHARS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                    g2.drawChars( charArray, 0, 1, 0, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                  case DRAW_BYTES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    if ( charCode > 0xff )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                      throw new CannotDrawException( DRAW_BYTES_ERROR );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    byte oneByte[] = { (byte) charCode };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                    g2.drawBytes( oneByte, 0, 1, 0, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                  case DRAW_GLYPHV:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    g2.drawGlyphVector( gv, 0f, 0f );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                  case TL_DRAW:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                    TextLayout tl = new TextLayout( new String( charArray ), testFont, frc );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                    tl.draw( g2, 0f, 0f );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                  case GV_OUTLINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                    r2d2 = gv.getVisualBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    shiftedX = baseX - (int) ( r2d2.getWidth() / 2 + r2d2.getX() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                    g2.draw( gv.getOutline( 0f, 0f ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                  case TL_OUTLINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                    r2d2 = gv.getVisualBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    shiftedX = baseX - (int) ( r2d2.getWidth() / 2 + r2d2.getX() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                    TextLayout tlo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                      new TextLayout( new String( charArray ), testFont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                                      g2.getFontRenderContext() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                    g2.draw( tlo.getOutline( null ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            /// ABP - restore old tform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            g2.setTransform ( oldTX );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        /// Draws one line of text at given position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        private void modeSpecificDrawLine( Graphics2D g2, String line,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                                           int baseX, int baseY ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            /// ABP - keep track of old tform, restore it later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            AffineTransform oldTx = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            oldTx = g2.getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            g2.translate( baseX, baseY );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            g2.transform( getAffineTransform( g2Transform ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            switch ( drawMethod ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
              case DRAW_STRING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                g2.drawString( line, 0, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
              case DRAW_CHARS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                g2.drawChars( line.toCharArray(), 0, line.length(), 0, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
              case DRAW_BYTES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                    byte lineBytes[] = line.getBytes( "ISO-8859-1" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                    g2.drawBytes( lineBytes, 0, lineBytes.length, 0, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                catch ( Exception e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                    e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
              case DRAW_GLYPHV:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                GlyphVector gv =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                  testFont.createGlyphVector( g2.getFontRenderContext(), line );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                g2.drawGlyphVector( gv, (float) 0, (float) 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
              case TL_DRAW:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                TextLayout tl = new TextLayout( line, testFont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                                                g2.getFontRenderContext() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                tl.draw( g2, (float) 0, (float) 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
              case GV_OUTLINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                GlyphVector gvo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                  testFont.createGlyphVector( g2.getFontRenderContext(), line );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                g2.draw( gvo.getOutline( (float) 0, (float) 0 ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
              case TL_OUTLINE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                TextLayout tlo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                  new TextLayout( line, testFont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                                  g2.getFontRenderContext() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                AffineTransform at = new AffineTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                g2.draw( tlo.getOutline( at ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            /// ABP - restore old tform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            g2.setTransform ( oldTx );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        /// Draws one line of text at given position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        private void tlDrawLine( Graphics2D g2, TextLayout tl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                                           float baseX, float baseY ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            /// ABP - keep track of old tform, restore it later
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            AffineTransform oldTx = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            oldTx = g2.getTransform();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            g2.translate( baseX, baseY );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            g2.transform( getAffineTransform( g2Transform ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            tl.draw( g2, (float) 0, (float) 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            /// ABP - restore old tform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            g2.setTransform ( oldTx );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        /// If textToUse is set to range drawing, then convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        /// int to hex string and prepends 0s to make it length 4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        /// Otherwise line number was fed; simply return number + 1 converted to String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        /// (This is because first line is 1, not 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        private String modeSpecificNumStr( int i ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            if ( textToUse == USER_TEXT || textToUse == FILE_TEXT )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
              return String.valueOf( i + 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            StringBuffer s = new StringBuffer( Integer.toHexString( i ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            while ( s.length() < 4 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
              s.insert( 0, "0" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            return s.toString().toUpperCase();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        /// Resets the scrollbar to display correct range of text currently on screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        /// (This scrollbar is not part of a "ScrollPane". It merely simulates its effect by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        ///  indicating the necessary area to be drawn within the panel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        ///  By doing this, it prevents creating gigantic panel when large text range,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        ///  i.e. CJK Ideographs, is requested)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        private void resetScrollbar( int oldValue ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            int totalNumRows = 1, numCharToDisplay;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                if ( textToUse == RANGE_TEXT )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                  numCharToDisplay = drawRange[1] - drawRange[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                else /// textToUse == ALL_GLYPHS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                  numCharToDisplay = testFont.getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                totalNumRows = numCharToDisplay / numCharAcross;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                if ( numCharToDisplay % numCharAcross != 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
                  totalNumRows++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                if ( oldValue / numCharAcross > totalNumRows )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                  oldValue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                verticalBar.setValues( oldValue / numCharAcross,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                                       numCharDown, 0, totalNumRows );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                if ( textToUse == USER_TEXT )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                  totalNumRows = userText.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                else /// textToUse == FILE_TEXT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                  totalNumRows = lineBreakTLs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                verticalBar.setValues( oldValue, numCharDown, 0, totalNumRows );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            if ( totalNumRows <= numCharDown && drawStart == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
              verticalBar.setEnabled( false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
              verticalBar.setEnabled( true );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        /// Calculates the font's metrics that will be used for draw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        private void calcFontMetrics( Graphics2D g2d, int w, int h ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            FontMetrics fm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            Graphics2D g2 = (Graphics2D)g2d.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            /// ABP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            if ( g2Transform != NONE && textToUse != FILE_TEXT ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                g2.setFont( g2.getFont().deriveFont( getAffineTransform( g2Transform )) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                fm = g2.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                fm = g2.getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            maxAscent = fm.getMaxAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            maxDescent = fm.getMaxDescent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            if (maxAscent == 0) maxAscent = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            if (maxDescent == 0) maxDescent = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                /// Give slight extra room for each character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                maxAscent += 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                maxDescent += 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                gridWidth = fm.getMaxAdvance() + 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                gridHeight = maxAscent + maxDescent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                if ( force16Cols )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                  numCharAcross = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                  numCharAcross = ( w - 10 ) / gridWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                numCharDown = ( h - 10 ) / gridHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                canvasInset_X = ( w - numCharAcross * gridWidth ) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                canvasInset_Y = ( h - numCharDown * gridHeight ) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                if ( numCharDown == 0 || numCharAcross == 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                  throw new CannotDrawException( isPrinting ? CANT_FIT_PRINT : CANT_FIT_DRAW );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                if ( !isPrinting )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                  resetScrollbar( verticalBar.getValue() * numCharAcross );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                maxDescent += fm.getLeading();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                canvasInset_X = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                canvasInset_Y = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                /// gridWidth and numCharAcross will not be used in this mode...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                gridHeight = maxAscent + maxDescent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                numCharDown = ( h - canvasInset_Y * 2 ) / gridHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                if ( numCharDown == 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                  throw new CannotDrawException( isPrinting ? CANT_FIT_PRINT : CANT_FIT_DRAW );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                /// If this is text loaded from file, prepares the LineBreak'ed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                /// text layout at this point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                if ( textToUse == FILE_TEXT ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                    if ( !isPrinting )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                      f2dt.fireChangeStatus( "LineBreaking Text... Please Wait", false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                    lineBreakTLs = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                    for ( int i = 0; i < fileText.length; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                        AttributedString as =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                          new AttributedString( fileText[i], g2.getFont().getAttributes() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                        LineBreakMeasurer lbm =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                          new LineBreakMeasurer( as.getIterator(), g2.getFontRenderContext() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                        while ( lbm.getPosition() < fileText[i].length() )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                          lineBreakTLs.add( lbm.nextLayout( (float) w ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                if ( !isPrinting )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                  resetScrollbar( verticalBar.getValue() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        /// Calculates the amount of text that will be displayed on screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        private void calcTextRange() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            String displaying = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                if ( isPrinting )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                  if ( printMode == ONE_PAGE )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                    drawStart = currentlyShownChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                  else /// printMode == CUR_RANGE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                    drawStart = numCharAcross * numCharDown * printPageNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                  drawStart = verticalBar.getValue() * numCharAcross;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                if ( textToUse == RANGE_TEXT ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                    drawStart += drawRange[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                    drawLimit = drawRange[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                  drawLimit = testFont.getNumGlyphs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                drawEnd = drawStart + numCharAcross * numCharDown - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                if ( drawEnd >= drawLimit )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                  drawEnd = drawLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                if ( isPrinting )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                  if ( printMode == ONE_PAGE )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                    drawStart = currentlyShownChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                  else /// printMode == ALL_TEXT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                    drawStart = numCharDown * printPageNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                    drawStart = verticalBar.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                drawEnd = drawStart + numCharDown - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                if ( textToUse == USER_TEXT )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                  drawLimit = userText.length - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                  drawLimit = lineBreakTLs.size() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                if ( drawEnd >= drawLimit )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                  drawEnd = drawLimit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            // ABP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            if ( drawStart > drawEnd ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
              drawStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
              verticalBar.setValue(drawStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            /// Change the status bar if not printing...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            if ( !isPrinting ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                backupStatusString = ( "Displaying" + MS_OPENING[textToUse] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                                       modeSpecificNumStr( drawStart ) + " to " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                                       modeSpecificNumStr( drawEnd ) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                                       MS_CLOSING[textToUse] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                f2dt.fireChangeStatus( backupStatusString, false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        /// Draws text according to the parameters set by Font2DTest GUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        private void drawText( Graphics g, int w, int h ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            Graphics2D g2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            /// Create back buffer when not printing, and its Graphics2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            /// Then set drawing parameters for that Graphics2D object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            if ( isPrinting )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
              g2 = (Graphics2D) g;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            else  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                backBuffer = (BufferedImage) this.createImage( w, h );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                g2 = backBuffer.createGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                g2.setColor(Color.white);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                g2.fillRect(0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                g2.setColor(Color.black);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            /// sets font, RenderingHints.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            setParams( g2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            /// If flag is set, recalculate fontMetrics and reset the scrollbar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            if ( updateFontMetrics || isPrinting ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                /// NOTE: re-calculates in case G2 transform
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                /// is something other than NONE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                calcFontMetrics( g2, w, h );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                updateFontMetrics = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            /// Calculate the amount of text that can be drawn...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            calcTextRange();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            /// Draw according to the set "Text to Use" mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                int charToDraw = drawStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                if ( showGrid )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                  drawGrid( g2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                if ( !isPrinting )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                  g.drawImage( backBuffer, 0, 0, this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                for ( int i = 0; i < numCharDown && charToDraw <= drawEnd; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                  for ( int j = 0; j < numCharAcross && charToDraw <= drawEnd; j++, charToDraw++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                      int gridLocX = j * gridWidth + canvasInset_X;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                      int gridLocY = i * gridHeight + canvasInset_Y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                      modeSpecificDrawChar( g2, charToDraw,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                                            gridLocX + gridWidth / 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                                            gridLocY + maxAscent );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                      //if ( !isPrinting ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                      //    g.setClip( gridLocX, gridLocY, gridWidth + 1, gridHeight + 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                      //    g.drawImage( backBuffer, 0, 0, this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                            //}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            else if ( textToUse == USER_TEXT ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                g2.drawRect( 0, 0, w - 1, h - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                if ( !isPrinting )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                  g.drawImage( backBuffer, 0, 0, this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                for ( int i = drawStart; i <= drawEnd; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                    int lineStartX = canvasInset_Y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                    int lineStartY = ( i - drawStart ) * gridHeight + maxAscent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                    modeSpecificDrawLine( g2, userText[i], lineStartX, lineStartY );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                float xPos, yPos = (float) canvasInset_Y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                g2.drawRect( 0, 0, w - 1, h - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                if ( !isPrinting )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                  g.drawImage( backBuffer, 0, 0, this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                for ( int i = drawStart; i <= drawEnd; i++ ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    TextLayout oneLine = (TextLayout) lineBreakTLs.elementAt( i );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                    xPos =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                      oneLine.isLeftToRight() ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                      canvasInset_X : ( (float) w - oneLine.getAdvance() - canvasInset_X );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                    float fmData[] = {0, oneLine.getAscent(), 0, oneLine.getDescent(), 0, oneLine.getLeading()};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                    if (g2Transform != NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                        AffineTransform at = getAffineTransform(g2Transform);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                        at.transform( fmData, 0, fmData, 0, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                    //yPos += oneLine.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                    yPos += fmData[1]; // ascent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                    //oneLine.draw( g2, xPos, yPos );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                    tlDrawLine( g2, oneLine, xPos, yPos );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                    //yPos += oneLine.getDescent() + oneLine.getLeading();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                    yPos += fmData[3] + fmData[5]; // descent + leading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                if ( !isPrinting )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
                g.drawImage( backBuffer, 0, 0, this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            g2.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
        /// Component paintComponent function...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        /// Draws/Refreshes canvas according to flag(s) set by other functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        public void paintComponent( Graphics g ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            if ( updateBackBuffer ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                Dimension d = this.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
                isPrinting = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                    drawText( g, d.width, d.height );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                catch ( CannotDrawException e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
                    f2dt.fireChangeStatus( ERRORS[ e.id ], true );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                    super.paintComponent(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
              /// Screen refresh
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
              g.drawImage( backBuffer, 0, 0, this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            showingError = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            updateBackBuffer = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        /// Printable interface function
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        /// Component print function...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        public int print( Graphics g, PageFormat pf, int pageIndex ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            if ( pageIndex == 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                /// Reset the last page index to max...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                lastPage = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                currentlyShownChar = verticalBar.getValue() * numCharAcross;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            if ( printMode == ONE_PAGE ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                if ( pageIndex > 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                  return NO_SUCH_PAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                if ( pageIndex > lastPage )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                  return NO_SUCH_PAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
            int pageWidth = (int) pf.getImageableWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            int pageHeight = (int) pf.getImageableHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            /// Back up metrics and other drawing info before printing modifies it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            int backupDrawStart = drawStart, backupDrawEnd = drawEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            int backupNumCharAcross = numCharAcross, backupNumCharDown = numCharDown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            Vector backupLineBreakTLs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            if ( textToUse == FILE_TEXT )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
              backupLineBreakTLs = (Vector) lineBreakTLs.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            printPageNumber = pageIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            isPrinting = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            /// Push the actual draw area 60 down to allow info to be printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            g.translate( (int) pf.getImageableX(), (int) pf.getImageableY() + 60 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                drawText( g, pageWidth, pageHeight - 60 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            catch ( CannotDrawException e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                f2dt.fireChangeStatus( ERRORS[ e.id ], true );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                return NO_SUCH_PAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            /// Draw information about what is being printed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            String hints = ( " with antialias " + antiAliasType + "and" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                             " fractional metrics " + fractionalMetricsType +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                             " and lcd contrast = " + lcdContrast);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            String infoLine1 = ( "Printing" + MS_OPENING[textToUse] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                                 modeSpecificNumStr( drawStart ) + " to " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                                 modeSpecificNumStr( drawEnd ) + MS_CLOSING[textToUse] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            String infoLine2 = ( "With " + fontName + " " + STYLES[fontStyle] + " at " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                                 fontSize + " point size " + TRANSFORMS[fontTransform] );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            String infoLine3 = "Using " + METHODS[drawMethod] + hints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            String infoLine4 = "Page: " + ( pageIndex + 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            g.setFont( new Font( "dialog", Font.PLAIN, 12 ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            g.setColor( Color.black );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            g.translate( 0, -60 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            g.drawString( infoLine1, 15, 10 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            g.drawString( infoLine2, 15, 22 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            g.drawString( infoLine3, 15, 34 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            g.drawString( infoLine4, 15, 46 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            if ( drawEnd == drawLimit )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
              /// This indicates that the draw will be completed with this page
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
              lastPage = pageIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            /// Restore the changed values back...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            /// This is important for JScrollBar settings and LineBreak'ed TLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            drawStart = backupDrawStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            drawEnd = backupDrawEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            numCharAcross = backupNumCharAcross;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            numCharDown = backupNumCharDown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            if ( textToUse == FILE_TEXT )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
              lineBreakTLs = backupLineBreakTLs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            return PAGE_EXISTS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        /// Ouputs the current canvas into a given PNG file
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        public void writePNG( String fileName ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                ImageIO.write(backBuffer, "png", new java.io.File(fileName));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            catch ( Exception e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                f2dt.fireChangeStatus( "ERROR: Failed to Save PNG image; See stack trace", true );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        /// Figures out whether a character at the pointer location is valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        /// And if so, updates mouse location informations, as well as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        /// the information on the status bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        private boolean checkMouseLoc( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            if ( gridWidth != 0 && gridHeight != 0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
              if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                  int charLocX = ( e.getX() - canvasInset_X ) / gridWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                  int charLocY = ( e.getY() - canvasInset_Y ) / gridHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                  /// Check to make sure the mouse click location is within drawn area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                  if ( charLocX >= 0 && charLocY >= 0 &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                       charLocX < numCharAcross && charLocY < numCharDown ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                      int mouseOverChar =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                        charLocX + ( verticalBar.getValue() + charLocY ) * numCharAcross;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                      if ( textToUse == RANGE_TEXT )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                        mouseOverChar += drawRange[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                      if ( mouseOverChar > drawEnd )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                      mouseOverCharX = charLocX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                      mouseOverCharY = charLocY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                      currMouseOverChar = mouseOverChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                      /// Update status bar
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                      f2dt.fireChangeStatus( "Pointing to" + MS_OPENING[textToUse] +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                                             modeSpecificNumStr( mouseOverChar ), false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                      return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        /// Shows (updates) the character zoom window
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        public void showZoomed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            GlyphVector gv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
            Font backup = testFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            Point canvasLoc = this.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            /// Calculate the zoom area's location and size...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            int dialogOffsetX = (int) ( gridWidth * ( ZOOM - 1 ) / 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            int dialogOffsetY = (int) ( gridHeight * ( ZOOM - 1 ) / 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            int zoomAreaX =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
              mouseOverCharX * gridWidth + canvasInset_X - dialogOffsetX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            int zoomAreaY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
              mouseOverCharY * gridHeight + canvasInset_Y - dialogOffsetY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            int zoomAreaWidth = (int) ( gridWidth * ZOOM );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            int zoomAreaHeight = (int) ( gridHeight * ZOOM );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            /// Position and set size of zoom window as needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            zoomWindow.setLocation( canvasLoc.x + zoomAreaX, canvasLoc.y + zoomAreaY );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            if ( !nowZooming ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                if ( zoomWindow.getWarningString() != null )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                  /// If this is not opened as a "secure" window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                  /// it has a banner below the zoom dialog which makes it look really BAD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                  /// So enlarge it by a bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                  zoomWindow.setSize( zoomAreaWidth + 1, zoomAreaHeight + 20 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                  zoomWindow.setSize( zoomAreaWidth + 1, zoomAreaHeight + 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            /// Prepare zoomed image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            zoomImage =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
              (BufferedImage) zoomWindow.createImage( zoomAreaWidth + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                                                      zoomAreaHeight + 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            Graphics2D g2 = (Graphics2D) zoomImage.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            testFont = testFont.deriveFont( fontSize * ZOOM );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            setParams( g2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            g2.setColor( Color.white );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            g2.fillRect( 0, 0, zoomAreaWidth, zoomAreaHeight );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            g2.setColor( Color.black );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            g2.drawRect( 0, 0, zoomAreaWidth, zoomAreaHeight );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            modeSpecificDrawChar( g2, currMouseOverChar,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                                  zoomAreaWidth / 2, (int) ( maxAscent * ZOOM ));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            g2.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            if ( !nowZooming )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
              zoomWindow.show();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            /// This is sort of redundant... since there is a paint function
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            /// inside zoomWindow definition that does the drawImage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            /// (I should be able to call just repaint() here)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            /// However, for some reason, that paint function fails to respond
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            /// from second time and on; So I have to force the paint here...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            zoomWindow.getGraphics().drawImage( zoomImage, 0, 0, this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
            nowZooming = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            prevZoomChar = currMouseOverChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            testFont = backup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            // Windows does not repaint correctly, after
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            // a zoom. Thus, we need to force the canvas
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            // to repaint, but only once. After the first repaint,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            // everything stabilizes. [ABP]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            if ( firstTime() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                refresh();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        /// Listener Functions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        /// MouseListener interface function
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        /// Zooms a character when mouse is pressed above it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        public void mousePressed( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            if ( !showingError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                if ( checkMouseLoc( e )) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                    showZoomed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                    this.setCursor( blankCursor );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        /// MouseListener interface function
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        /// Redraws the area that was drawn over by zoomed character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        public void mouseReleased( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            if ( textToUse == RANGE_TEXT || textToUse == ALL_GLYPHS ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                if ( nowZooming )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                  zoomWindow.hide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                nowZooming = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            this.setCursor( Cursor.getDefaultCursor() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        /// MouseListener interface function
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        /// Resets the status bar to display range instead of a specific character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        public void mouseExited( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            if ( !showingError && !nowZooming )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
              f2dt.fireChangeStatus( backupStatusString, false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        /// MouseMotionListener interface function
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        /// Adjusts the status bar message when mouse moves over a character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        public void mouseMoved( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            if ( !showingError ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                if ( !checkMouseLoc( e ))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                  f2dt.fireChangeStatus( backupStatusString, false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        /// MouseMotionListener interface function
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        /// Scrolls the zoomed character when mouse is dragged
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        public void mouseDragged( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            if ( !showingError )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
              if ( nowZooming ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                  if ( checkMouseLoc( e ) && currMouseOverChar != prevZoomChar )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                    showZoomed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        /// Empty function to comply with interface requirement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        public void mouseClicked( MouseEvent e ) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        public void mouseEntered( MouseEvent e ) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    private final class CannotDrawException extends RuntimeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        /// Error ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        public final int id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        public CannotDrawException( int i ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            id = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    enum FMValues {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
       FMDEFAULT ("DEFAULT",  VALUE_FRACTIONALMETRICS_DEFAULT),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
       FMOFF     ("OFF",      VALUE_FRACTIONALMETRICS_OFF),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
       FMON      ("ON",       VALUE_FRACTIONALMETRICS_ON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        private Object hint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        private static FMValues[] valArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        FMValues(String s, Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            name = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            hint = o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
       public Object getHint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
           return hint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
       public static Object getValue(int ordinal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
           if (valArray == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
               valArray = (FMValues[])EnumSet.allOf(FMValues.class).toArray(new FMValues[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
           for (int i=0;i<valArray.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
               if (valArray[i].ordinal() == ordinal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                   return valArray[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
           return valArray[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
       private static FMValues[] getArray() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
           if (valArray == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
               valArray = (FMValues[])EnumSet.allOf(FMValues.class).toArray(new FMValues[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
           return valArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
       public static int getHintVal(Object hint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
           getArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
           for (int i=0;i<valArray.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
               if (valArray[i].getHint() == hint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                   return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
           return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
   enum AAValues {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
       AADEFAULT ("DEFAULT",  VALUE_TEXT_ANTIALIAS_DEFAULT),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
       AAOFF     ("OFF",      VALUE_TEXT_ANTIALIAS_OFF),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
       AAON      ("ON",       VALUE_TEXT_ANTIALIAS_ON),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
       AAGASP    ("GASP",     VALUE_TEXT_ANTIALIAS_GASP),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
       AALCDHRGB ("LCD_HRGB", VALUE_TEXT_ANTIALIAS_LCD_HRGB),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
       AALCDHBGR ("LCD_HBGR", VALUE_TEXT_ANTIALIAS_LCD_HBGR),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
       AALCDVRGB ("LCD_VRGB", VALUE_TEXT_ANTIALIAS_LCD_VRGB),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
       AALCDVBGR ("LCD_VBGR", VALUE_TEXT_ANTIALIAS_LCD_VBGR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        private Object hint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        private static AAValues[] valArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        AAValues(String s, Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            name = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            hint = o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
       public Object getHint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
           return hint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
       public static boolean isLCDMode(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
           return (o instanceof AAValues &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                   ((AAValues)o).ordinal() >= AALCDHRGB.ordinal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
       public static Object getValue(int ordinal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
           if (valArray == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
               valArray = (AAValues[])EnumSet.allOf(AAValues.class).toArray(new AAValues[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
           for (int i=0;i<valArray.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
               if (valArray[i].ordinal() == ordinal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
                   return valArray[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
           return valArray[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
       private static AAValues[] getArray() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
           if (valArray == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
               Object [] oa = EnumSet.allOf(AAValues.class).toArray(new AAValues[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
               valArray = (AAValues[])(EnumSet.allOf(AAValues.class).toArray(new AAValues[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
           return valArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
       public static int getHintVal(Object hint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
           getArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
           for (int i=0;i<valArray.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
               if (valArray[i].getHint() == hint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                   return i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
               }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
           return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
    private static Integer defaultContrast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    static Integer getDefaultLCDContrast() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        if (defaultContrast == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
            GraphicsConfiguration gc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
            GraphicsEnvironment.getLocalGraphicsEnvironment().
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                getDefaultScreenDevice().getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        Graphics2D g2d =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            (Graphics2D)(gc.createCompatibleImage(1,1).getGraphics());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        defaultContrast = (Integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            g2d.getRenderingHint(RenderingHints.KEY_TEXT_LCD_CONTRAST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        return defaultContrast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
}