2362N/A * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved. 0N/A * Redistribution and use in source and binary forms, with or without 0N/A * modification, are permitted provided that the following conditions 0N/A * - Redistributions of source code must retain the above copyright 0N/A * notice, this list of conditions and the following disclaimer. 0N/A * - Redistributions in binary form must reproduce the above copyright 0N/A * notice, this list of conditions and the following disclaimer in the 0N/A * documentation and/or other materials provided with the distribution. 2362N/A * - Neither the name of Oracle nor the names of its 0N/A * contributors may be used to endorse or promote products derived 0N/A * from this software without specific prior written permission. 0N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 0N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 0N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 0N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 0N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 0N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 0N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 0N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 0N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 0N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 0N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4378N/A * This source code is provided to illustrate the usage of a given feature 4378N/A * or technique and has been deliberately simplified. Additional steps 4378N/A * required for a production-quality application, such as security checks, 4378N/A * input validation and proper error handling, might not be present in 0N/A * @author Shinsuke Fukuda 0N/A * @author Ankit Patel [Conversion to Swing - 01/07/30] 0N/A/// This panel is combination of the text drawing area of Font2DTest 0N/A/// and the custom controlled scroll bar 0N/A /// Drawing Option Constants 0N/A {
"plain",
"bold",
"italic",
"bold italic" };
0N/A {
"with no transforms",
"with scaling",
"with Shearing",
"with rotation" };
0N/A "drawString",
"drawChars",
"drawBytes",
"drawGlyphVector",
0N/A "TextLayout.draw",
"GlyphVector.getOutline",
"TextLayout.getOutline" };
0N/A {
" Unicode ",
" Glyph Code ",
" lines ",
" lines " };
0N/A {
"",
"",
" of User Text ",
" of LineBreakMeasurer-reformatted Text " };
0N/A /// General Graphics Variable 0N/A /// Printing constants and variables 0N/A /// Text drawing variables 0N/A /// Parent Font2DTest panel 0N/A /// Initialize font and its infos 0N/A /// Functions called by the main programs to set the various parameters 0N/A /// convenience fcn to create AffineTransform of appropriate type 0N/A //System.err.println( "Illegal G2 Transform Arg: " + transform); 0N/A /// Recreate the font as specified 0N/A /// Tell main panel to update the font info 0N/A /// Prints out the text display area 0N/A /// Displays the page setup dialog and updates PageFormat info 0N/A /// Obtains the information about selected font 0N/A /// Accessor for the font information 0N/A /// Collects the currectly set options and returns them as string 0N/A /// Create a new String to store the options 0N/A /// The array will contain all 8 setting (font name, size...) and 0N/A /// character range or user text data used (no file text data) 0N/A /// Reload all options and refreshes the canvas 0N/A /// Since repaint call has a low priority, these functions will finish 0N/A /// before the actual repainting is done 0N/A // previous call to readTextFile has already set the text to draw 0N/A /// Writes the current screen to PNG file 0N/A /// When scrolled using the scroll bar, update the backbuffer 0N/A // Windows does not repaint correctly, after 0N/A // a zoom. Thus, we need to force the canvas 0N/A // to repaint, but only once. After the first repaint, 0N/A // everything stabilizes. [ABP] 0N/A /// Inner class definition... 0N/A /// Inner panel that holds the actual drawing area and its routines 0N/A /// Number of characters that will fit across and down this canvas 0N/A /// Limit is the end of range/text where no more draw will be done 0N/A /// FontMetrics variables 0N/A /// Here, gridWidth is equivalent to maxAdvance (slightly bigger though) 0N/A /// and gridHeight is equivalent to lineHeight 0N/A /// Offset from the top left edge of the canvas where the draw will start 0N/A /// Offscreen buffer of this canvas 0N/A /// LineBreak'ed TextLayout vector 0N/A /// Whether the current draw command requested is for printing 0N/A /// Other printing infos 0N/A /// Information about zooming (used with range text draw) 0N/A /// Status bar message backup 0N/A "ERROR: drawBytes cannot handle characters beyond 0x00FF. Select different range or draw methods.",
0N/A "ERROR: Cannot fit text with the current font size. Resize the window or use smaller font size.",
0N/A "ERROR: Cannot print with the current font size. Use smaller font size.",
0N/A /// Creates an invisble pointer by giving it bogus image 0N/A /// Possibly find a workaround for this... 0N/A /// Sets the font, hints, according to the set parameters 0N/A /* I am preserving a somewhat dubious behaviour of this program. 0N/A * Outline text would be drawn anti-aliased by setting the 0N/A * graphics anti-aliasing hint if the text anti-aliasing hint 0N/A * was set. The dubious element here is that people simply 0N/A * using this program may think this is built-in behaviour 0N/A * but its not - at least not when the app explictly draws 0N/A * This becomes more dubious in cases such as "GASP" where the 0N/A * size at which text is AA'ed is not something you can easily 0N/A * calculate, so mimicing that behaviour isn't going to be easy. 0N/A * So I precisely preserve the behaviour : this is done only 0N/A * if the AA value is "ON". Its not applied in the other cases. 0N/A /// Draws one character at time onto the canvas according to 0N/A /// the method requested (Used for RANGE_TEXT and ALL_GLYPHS) 0N/A /// Create GlyphVector to measure the exact visual advance 0N/A /// Using that number, adjust the position of the character drawn 0N/A // getPixelBounds returns a result in device space. 0N/A // we need to convert back to user space to be able to 0N/A // calculate the shift as baseX is in user space. 0N/A double pt[] =
new double[
4];
0N/A /// ABP - keep track of old tform, restore it later 0N/A /// ABP - restore old tform 0N/A /// Draws one line of text at given position 0N/A /// ABP - keep track of old tform, restore it later 0N/A /// ABP - restore old tform 0N/A /// Draws one line of text at given position 0N/A /// ABP - keep track of old tform, restore it later 0N/A /// ABP - restore old tform 0N/A /// If textToUse is set to range drawing, then convert 0N/A /// int to hex string and prepends 0s to make it length 4 0N/A /// Otherwise line number was fed; simply return number + 1 converted to String 0N/A /// (This is because first line is 1, not 0) 0N/A /// Resets the scrollbar to display correct range of text currently on screen 0N/A /// (This scrollbar is not part of a "ScrollPane". It merely simulates its effect by 0N/A /// indicating the necessary area to be drawn within the panel. 0N/A /// By doing this, it prevents creating gigantic panel when large text range, 0N/A /// i.e. CJK Ideographs, is requested) 0N/A else /// textToUse == ALL_GLYPHS 0N/A else /// textToUse == FILE_TEXT; 0N/A /// Calculates the font's metrics that will be used for draw 0N/A /// Give slight extra room for each character 0N/A /// gridWidth and numCharAcross will not be used in this mode... 0N/A /// If this is text loaded from file, prepares the LineBreak'ed 0N/A /// text layout at this point 0N/A /// Calculates the amount of text that will be displayed on screen 0N/A else /// printMode == CUR_RANGE 0N/A else /// printMode == ALL_TEXT 0N/A /// Change the status bar if not printing... 0N/A /// Draws text according to the parameters set by Font2DTest GUI 0N/A /// Create back buffer when not printing, and its Graphics2D 0N/A /// Then set drawing parameters for that Graphics2D object 0N/A /// sets font, RenderingHints. 0N/A /// If flag is set, recalculate fontMetrics and reset the scrollbar 0N/A /// NOTE: re-calculates in case G2 transform 0N/A /// is something other than NONE 0N/A /// Calculate the amount of text that can be drawn... 0N/A /// Draw according to the set "Text to Use" mode 0N/A //if ( !isPrinting ) { 0N/A // g.setClip( gridLocX, gridLocY, gridWidth + 1, gridHeight + 1 ); 0N/A // g.drawImage( backBuffer, 0, 0, this ); 0N/A //yPos += oneLine.getAscent(); 0N/A //oneLine.draw( g2, xPos, yPos ); 0N/A //yPos += oneLine.getDescent() + oneLine.getLeading(); 0N/A /// Component paintComponent function... 0N/A /// Printable interface function 0N/A /// Component print function... 0N/A /// Reset the last page index to max... 0N/A /// Back up metrics and other drawing info before printing modifies it 0N/A /// Push the actual draw area 60 down to allow info to be printed 0N/A /// Draw information about what is being printed 0N/A /// This indicates that the draw will be completed with this page 0N/A /// Restore the changed values back... 0N/A /// This is important for JScrollBar settings and LineBreak'ed TLs 0N/A /// Ouputs the current canvas into a given PNG file 0N/A /// Figures out whether a character at the pointer location is valid 0N/A /// And if so, updates mouse location informations, as well as 0N/A /// the information on the status bar 0N/A /// Check to make sure the mouse click location is within drawn area 0N/A /// Update status bar 0N/A /// Shows (updates) the character zoom window 0N/A /// Calculate the zoom area's location and size... 0N/A /// Position and set size of zoom window as needed 0N/A /// If this is not opened as a "secure" window, 0N/A /// it has a banner below the zoom dialog which makes it look really BAD 0N/A /// So enlarge it by a bit 0N/A /// Prepare zoomed image 0N/A /// This is sort of redundant... since there is a paint function 0N/A /// inside zoomWindow definition that does the drawImage. 0N/A /// (I should be able to call just repaint() here) 0N/A /// However, for some reason, that paint function fails to respond 0N/A /// from second time and on; So I have to force the paint here... 0N/A // Windows does not repaint correctly, after 0N/A // a zoom. Thus, we need to force the canvas 0N/A // to repaint, but only once. After the first repaint, 0N/A // everything stabilizes. [ABP] 0N/A /// Listener Functions 0N/A /// MouseListener interface function 0N/A /// Zooms a character when mouse is pressed above it 0N/A /// MouseListener interface function 0N/A /// Redraws the area that was drawn over by zoomed character 0N/A /// MouseListener interface function 0N/A /// Resets the status bar to display range instead of a specific character 0N/A /// MouseMotionListener interface function 0N/A /// Adjusts the status bar message when mouse moves over a character 0N/A /// MouseMotionListener interface function 0N/A /// Scrolls the zoomed character when mouse is dragged 0N/A /// Empty function to comply with interface requirement