From: <doc...@us...> - 2007-09-14 04:34:17
|
Revision: 171 http://openpcl.svn.sourceforge.net/openpcl/?rev=171&view=rev Author: documentsystems Date: 2007-09-13 21:34:18 -0700 (Thu, 13 Sep 2007) Log Message: ----------- Howard Hoagland. Made changes to 4 classes (PclRenderImage, PriDrawText, OpenPCLViewer, IPluginHooksOpenPCL) to implement this new feature: If the user Control-Clicks the toolbar "Options" button, then toggle show/hide to see white text hidden tag strings on the screen by redrawing the white text in dark green. Also draw a dark green box around the now visible txt. Modified Paths: -------------- openpcl/src/com/openpcl/pclrenderimage/PclRenderImage.java openpcl/src/com/openpcl/pclrenderimage/render/PriDrawText.java openpcl/src/com/openpcl/viewer/OpenPCLViewer.java openpcl/src/com/openpcl/viewer/api/IPluginHooksOpenPCL.java Modified: openpcl/src/com/openpcl/pclrenderimage/PclRenderImage.java =================================================================== --- openpcl/src/com/openpcl/pclrenderimage/PclRenderImage.java 2007-09-14 00:17:27 UTC (rev 170) +++ openpcl/src/com/openpcl/pclrenderimage/PclRenderImage.java 2007-09-14 04:34:18 UTC (rev 171) @@ -96,6 +96,9 @@ protected boolean mIsStateBuildingPclPages = true; protected boolean mWantToCenterCharInCharCellBox = true; + // For showing/hiding hidden tags + protected String mShowHideTagBaseString = null; + /** Constructor. There are no callback methods, only call into methods that can return an object value */ public PclRenderImage() { mBufferedImageToDrawOn = createNewBufferedImageToDrawOn(); @@ -143,6 +146,7 @@ public boolean getIsDrawingForPrinting() { return mIsDrawingForPrinting; } public boolean getIsStateBuildingPclPages() { return mIsStateBuildingPclPages; } public boolean getWantToCenterCharInCharCellBox() { return mWantToCenterCharInCharCellBox; } + public String getShowHideTagBaseString() { return mShowHideTagBaseString; } public String getFileNameNoPath() { return mFileNameNoPath; } public String getFullFilePathAndName() { return mFullFilePathAndName; } @@ -153,6 +157,8 @@ mIsDrawingForPrinting = pIsDrawingForPrinting; } public void setWantToCenterCharInCharCellBox(boolean pWantToCenterCharInCharCellBox) { mWantToCenterCharInCharCellBox = pWantToCenterCharInCharCellBox; } + public void setShowHideTagBaseString(String pShowHideTagBaseString) { + mShowHideTagBaseString = pShowHideTagBaseString; } public void setCurrentZoomFactor(double pCurrentZoomFactor) { mCurrentZoomFactor = pCurrentZoomFactor; } protected void handleFormFeedFound(int pBufferPos) { Modified: openpcl/src/com/openpcl/pclrenderimage/render/PriDrawText.java =================================================================== --- openpcl/src/com/openpcl/pclrenderimage/render/PriDrawText.java 2007-09-14 00:17:27 UTC (rev 170) +++ openpcl/src/com/openpcl/pclrenderimage/render/PriDrawText.java 2007-09-14 04:34:18 UTC (rev 171) @@ -1,6 +1,7 @@ package com.openpcl.pclrenderimage.render; import java.awt.Color; +import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.font.TextLayout; import java.awt.geom.Rectangle2D; @@ -34,7 +35,13 @@ protected PriFontBase mPriFontBase = null; protected PriBitmapFont mPriBitmapFont = null; protected PriBitmapCharacter mPriBitmapCharacter = null; - + private char[] mBufferUpChars = null; + private static final int mBufferedUpMax = 1000; + private int mBufferUpIndex = -1; + private int mBufferUpXpos = 0; + private int mBufferUpYpos = 0; + private Color mDarkGreenColor = new Color(0,120,0); + /**Constructor * @param pPclRenderImage * @param pGraphics2D @@ -43,7 +50,9 @@ super(); mPclRenderImage = pPclRenderImage; mGraphics2D = pGraphics2D; - + // Non auto expanding byte array for execution speed. 1000 chars is way enough for all the chars that can fit on one line. + mBufferUpChars = new char[mBufferedUpMax]; + // if (mPclRenderImage == null) { // PriDebug.error("Missing reference to PclRenderImage in PriDrawText constructor.", // new InvalidParameterException()); @@ -354,6 +363,25 @@ mPclRenderImage.getPriCursorPos().getYpos()); } + // Buffer up the chars to draw hidden tag text in black instead of white + if (mBufferUpIndex < 0) { + // Upon the first char of the buffered up string, save the current X,Y point + mBufferUpXpos = mPclRenderImage.getPriCursorPos().getXpos(); + mBufferUpYpos = mPclRenderImage.getPriCursorPos().getYpos(); + // First char of String of chars starts at index 0 + mBufferUpIndex = 0; + } else { + // This isn't the very first char in the string, so just bump the index into the byte array here + mBufferUpIndex++; + } + + // If already reached the max size of the non growing char array, then stop drawing any more chars. + // This shouldn't happen because there's no way to get more than "mBufferedUpMax" chars on a print line anyways. + if (mBufferUpIndex < mBufferedUpMax) { + // Buffer up the chars into a char array + mBufferUpChars[mBufferUpIndex] = afterSubstitutionsCharToDraw; + } + // Alternate way to draw the character through TextLayout reference, // but the Graphics2D.drawString() works Ok too. // The below is if a visual comparison is wanted to see if one or the other is visually better @@ -373,12 +401,41 @@ } /** Draw buffered up chars as one String. + * Overridden methods in a subclass of this class will have code to buffer up viewable text, and write out the text + * as one write operation to save space in it's output stream. For example, a subclass plugin that has this method + * can "save to a PDF file" by using the itext.jar classes. The output .PDF file will be much bigger if chars are written + * to the PDF file one at a time compared to one write operation for the string of chars.<br> + * <br> + * PclRenderImage uses the internal printer font character width tables, so for printing, chars drawn one at a time + * outside of this method. However, code in this method here is for viewing only, and not printing.<br> + * <br> + * If the user Control-Clicks the toolbar "Options" button, then toggle show/hide to see white text hidden tag strings + * on the screen by redrawing the white text in dark green. Also draw a dark green box around the now visible txt. + * <br> * Subclass plugins override this method so do not delete or rename this method. */ public void drawBufferedUpCharsAs1String() { - // Just return here with no code to execute because overridden methods in a subclass of this class will have code in the - // overridden method. Subclass plugins override this method so do not delete or rename this method. - // Since PclRenderImage uses the internal printer font character width tables, then no code is needed here. - return; + // If there are no characters buffered up to draw, then return here + if (mBufferUpIndex < 0) { return; } + + // Get the String of several chars to draw + String tDrawCharsAsString = String.valueOf(mBufferUpChars, 0, mBufferUpIndex + 1); + + // Re-draw string only if the string starts with the currently set hidden tag base string + if ( (mPclRenderImage.getShowHideTagBaseString() != null) && + (tDrawCharsAsString.toLowerCase().startsWith(mPclRenderImage.getShowHideTagBaseString().toLowerCase())) ) { + // Send the buffered up chars to be drawn as one String, not using the internal printer font character width tables + mGraphics2D.setPaint(mDarkGreenColor); + mGraphics2D.drawString(tDrawCharsAsString, mBufferUpXpos, mBufferUpYpos); + FontMetrics tFontMetrics = mGraphics2D.getFontMetrics(); + + mGraphics2D.drawRect(mBufferUpXpos, mBufferUpYpos - tFontMetrics.getAscent(), + tFontMetrics.stringWidth(tDrawCharsAsString), tFontMetrics.getHeight()); + + mGraphics2D.setPaint(Color.BLACK); + } + + // Reset the index into the char array to be no chars are in there now + mBufferUpIndex = -1; } } Modified: openpcl/src/com/openpcl/viewer/OpenPCLViewer.java =================================================================== --- openpcl/src/com/openpcl/viewer/OpenPCLViewer.java 2007-09-14 00:17:27 UTC (rev 170) +++ openpcl/src/com/openpcl/viewer/OpenPCLViewer.java 2007-09-14 04:34:18 UTC (rev 171) @@ -217,7 +217,10 @@ " Views is already open so can't open another one right now.\n" + "Close one or more views then try again."; - public static final String sNotSupportedAtThisTime = "Not supported at this time"; + public static final String sNotSupportedAtThisTime = "Not supported at this time"; + + // For showing/hiding hidden tags + private String[] mHiddenTagBaseArray = { "HIDDENTAG:"} ; // os.name property public static String sOsNameString = null; @@ -1077,7 +1080,7 @@ } } - /** Apply the selected LookAndFeel to the screen + /** Apply the selected LookAndFeel to the screen. * Subclass plugins override this method so do not delete or rename this method. */ public void applySelectedLookAndFeel() { SwingUtilities.updateComponentTreeUI(mParentFrame); @@ -1310,7 +1313,7 @@ return determineFileTypeByFileExtension(tExtensionOfFileName); } - /** Determine the file type by the file extension + /** Determine the file type by the file extension. * Subclass plugins override this method so do not delete or rename this method. */ public int determineFileTypeByFileExtension(String pExtensionOfFileName) { if (pExtensionOfFileName.equalsIgnoreCase(".PCL") || @@ -1435,7 +1438,7 @@ return false; } - /** Create a new view panel + /** Create a new view panel. * Subclass plugins override this method so do not delete or rename this method. */ public PosView createNewViewPanel(String pShortName) { return new PosView(this, pShortName); @@ -1549,13 +1552,13 @@ return tErrorString; } - /** Allow subclases to set their own icon + /** Allow subclases to set their own icon. * Subclass plugins override this method so do not delete or rename this method. */ public Icon getJInternalFrameIcon() { return (PosReadImageIcon.read("V221MultiDoc.png")); } - /** Allow subclases to set their own title + /** Allow subclases to set their own title. * Subclass plugins override this method so do not delete or rename this method. */ public String getJInternalFrameTitleBar(String defaultTitle) { return (defaultTitle); @@ -1993,7 +1996,7 @@ parseFileBytesIntoTreeNodes(tFileNameOnly, pFilePathAndFileName); } - /** Open the file on disk. Read and parse all bytes in the file into tree nodes + /** Open the file on disk. Read and parse all bytes in the file into tree nodes. * Subclass plugins override this method so do not delete or rename this method. */ public void parseFileBytesIntoTreeNodes(String pFileNameOnly, String pFilePathAndFileName) { if (mPosViewSelected.getFileType() == sFileTypePCL) { @@ -2448,8 +2451,18 @@ mPosUserOptionsDialog.setLocationRelativeTo(getAppFrame()); mPosUserOptionsDialog.setVisible(true); } else { - // Hidden feature. If the Control key is pressed when clicking this button, then toggle show/hide to see white text - // by redrawing the text in black, only if the text starts with the specified text. Also draw a box around the now visible txt. + // If the user Control-Clicks the toolbar "Options" button, then toggle show/hide to see white text hidden tag strings + // on the screen by redrawing the white text in dark green. Also draw a dark green box around the now visible txt. + if (mPosViewSelected == null) { return; } + + if (mPosViewSelected.getPclRenderImage().getShowHideTagBaseString() == null) { + // Toggle to show + mPosViewSelected.getPclRenderImage().setShowHideTagBaseString(getHiddenTagBaseString(1)); + } else { + mPosViewSelected.getPclRenderImage().setShowHideTagBaseString(null); + } + // Redraw the current page with the toggle show/hide tag base string + renderImageCurrentPageAndZoom(); } } @@ -2507,34 +2520,44 @@ return mParentFrame; } - /** Get the app name + /** Get the app name. * Subclass plugins override this method so do not delete or rename this method. */ public String getAppName() { return mAppName; } - /** Get the app description + /** Get the app description. * Subclass plugins override this method so do not delete or rename this method. */ public String getAppDescription() { return mAppDescription; } - /** Get the app version + /** Get the app version. * Subclass plugins override this method so do not delete or rename this method. */ public String getAppVersion() { return mAppVersion; } - /** Get the package path to the license info .html file + /** Get the package path to the license info .html file. * Subclass plugins override this method so do not delete or rename this method. */ public String getPackagePathLicenseInfo() { return mPackagePathLicenseInfo; } - /** Get the package path to the help about .html file + /** Get the package path to the help about .html file. * Subclass plugins override this method so do not delete or rename this method. */ public String getPackageHelpAboutInfo() { return mPackagePathHelpAbout; } + + /** Get the hidden tag base String. + * Subclass plugins override this method so do not delete or rename this method. */ + public String getHiddenTagBaseString(int pTagIndex) { + if (mHiddenTagBaseArray == null || mHiddenTagBaseArray.length < pTagIndex) { + return null; + } else { + return mHiddenTagBaseArray[pTagIndex - 1]; + } + } } Modified: openpcl/src/com/openpcl/viewer/api/IPluginHooksOpenPCL.java =================================================================== --- openpcl/src/com/openpcl/viewer/api/IPluginHooksOpenPCL.java 2007-09-14 00:17:27 UTC (rev 170) +++ openpcl/src/com/openpcl/viewer/api/IPluginHooksOpenPCL.java 2007-09-14 04:34:18 UTC (rev 171) @@ -90,5 +90,7 @@ /** Allow subclases to set their own title */ public String getJInternalFrameTitleBar(String defaultTitle); - + + /** Get the hidden tag base String */ + public String getHiddenTagBaseString(int pTagIndex); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |