From: <doc...@us...> - 2007-07-04 01:45:14
|
Revision: 101 http://openpcl.svn.sourceforge.net/openpcl/?rev=101&view=rev Author: documentsystems Date: 2007-07-03 18:45:14 -0700 (Tue, 03 Jul 2007) Log Message: ----------- Howard Hoagland. Implemented "Additional Copies" with user input validation checking dialogs for must be numeric, and must be between 0 and 3, and made Additional Copies work with "Print All Documents on Legal Size" for both Windows Print and "Print PCL Direct", and tested many different combination print scenarios. Modified Paths: -------------- openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java openpcl/src/com/openpcl/viewer/printing/PosPrintSetupDialog.java Modified: openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java =================================================================== --- openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-07-03 21:44:07 UTC (rev 100) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintPages.java 2007-07-04 01:45:14 UTC (rev 101) @@ -65,12 +65,14 @@ public static final int sProcessPrintChanged = 2; public static final int sProcessPrintRemaining = 3; private int mProcessPrintType = 0; + private int mNumberOfPagesThatWillPrint = 0; private static final String[] mTitleBarTextForPrintDialog = { "Print All", "Print Selected", "Print Changed", "Print Remaining"}; public static byte sbESC = 0x1B; // Escape char public static byte sbFF = 0xC; // Form Feed ( char(12) ) private PriModifyPclBytes mPriModifyPclBytes = null; private PclParser mPclParser = null; + private StringBuffer mIndexNumbersStringBuffer = null; private int mNumberOfPrintPasses = 1; private int mCurrentPrintPassNumber = 1; @@ -131,25 +133,25 @@ // Save the parameter print type (all, selected, changed, or remaining) mProcessPrintType = pProcessPrintType; - StringBuffer tStringBuffer = new StringBuffer(); + mIndexNumbersStringBuffer = new StringBuffer(); mPagesToPrintArrayList = null; // Depending on if print all, print selected, print changed, print remaining, get which pages to print switch (mProcessPrintType) { case sProcessPrintAll: mPagesToPrintArrayList = mPosView.getPosBuildListOfPagesToPrint().makeArrayListofAllPages(); - tStringBuffer.append("\"Print all\""); + mIndexNumbersStringBuffer.append("\"Print all\""); break; case sProcessPrintSelected: mPagesToPrintArrayList = mPosView.getPosBuildListOfPagesToPrint().makeArrayListofSelectedPages(); - tStringBuffer.append("\"Print selected\""); + mIndexNumbersStringBuffer.append("\"Print selected\""); break; case sProcessPrintChanged: mPagesToPrintArrayList = mPosView.getPosBuildListOfPagesToPrint().makeArrayListofChangedPages(); - tStringBuffer.append("\"Print changed\""); + mIndexNumbersStringBuffer.append("\"Print changed\""); break; case sProcessPrintRemaining: mPagesToPrintArrayList = mPosView.getPosBuildListOfPagesToPrint().makeArrayListofRemainingPages(); - tStringBuffer.append("\"Print remaining\""); + mIndexNumbersStringBuffer.append("\"Print remaining\""); break; } @@ -184,21 +186,21 @@ return false; } - int tNumberOfPagesThatWillPrint = mPagesToPrintArrayList.size(); + mNumberOfPagesThatWillPrint = mPagesToPrintArrayList.size(); // Append all the selected page numbers to the StringBuffer - tStringBuffer.append(" " + tNumberOfPagesThatWillPrint + " page"); - if (tNumberOfPagesThatWillPrint == 1) { - tStringBuffer.append(". Index number: "); + mIndexNumbersStringBuffer.append(" " + mNumberOfPagesThatWillPrint + " page"); + if (mNumberOfPagesThatWillPrint == 1) { + mIndexNumbersStringBuffer.append(". Index number: "); } else { - tStringBuffer.append("s. Index numbers are: "); + mIndexNumbersStringBuffer.append("s. Index numbers are: "); } - for (int i = 0; i < tNumberOfPagesThatWillPrint; i++) { + for (int i = 0; i < mNumberOfPagesThatWillPrint; i++) { PosTreeNode eachNode = (PosTreeNode) mPagesToPrintArrayList.get(i); - tStringBuffer.append(eachNode.getNodeNumber()); - if (i < tNumberOfPagesThatWillPrint -1) { - tStringBuffer.append(", "); + mIndexNumbersStringBuffer.append(eachNode.getNodeNumber()); + if (i < mNumberOfPagesThatWillPrint -1) { + mIndexNumbersStringBuffer.append(", "); } } @@ -212,7 +214,7 @@ String tDialogTitleBarString = "Print"; mPosPrintSetupDialog = new PosPrintSetupDialog(mPosView, tDialogTitleBarString, - mPosPrintSetupDialogChoices, mAttributes, mPrinterJob, tStringBuffer.toString()); + mPosPrintSetupDialogChoices, mAttributes, mPrinterJob, mIndexNumbersStringBuffer.toString()); mPosPrintSetupDialog.setLocationRelativeTo(mParentFrame); mPosPrintSetupDialog.setVisible(true); @@ -234,7 +236,7 @@ return false; } - mPrintingProgressBar.setMaximum(tNumberOfPagesThatWillPrint); + mPrintingProgressBar.setMaximum(mNumberOfPagesThatWillPrint); mPrintingProgressBar.setString("Initializing..."); mPrintingProgressBar.setValue(0); mPrintingProgressJDialog.setLocationRelativeTo(mParentFrame); @@ -250,16 +252,40 @@ // Show the JDialog that has the JProgressBar threadShowProgressBar.start(); - // Depending on the choice in our custom printer setup dialog of PCL Direct or Image Print + StringBuffer tMsgStringBuffer = new StringBuffer(); + tMsgStringBuffer.append(" to printer selected: "); + tMsgStringBuffer.append(mPrintService.getName()); + tMsgStringBuffer.append("\n Additional Copies is " + mPosPrintSetupDialogChoices.getNumAdditionalCopies()); + tMsgStringBuffer.append("\n Print all Documents on Legal Size is "); + if (mPosPrintSetupDialogChoices.shouldPrintAllOnLegalSize()) { + tMsgStringBuffer.append("\"True\""); + } else { + tMsgStringBuffer.append("\"False\""); + } + tMsgStringBuffer.append("\n " + mIndexNumbersStringBuffer); + + // Console output print type "Use Windows Print" or "Print PCL Direct" if (mPosPrintSetupDialogChoices.isPrintFormatPclDirect()) { - PriDebug.releaseln("Printing Pcl Direct using printer selected: " + mPrintService.getName()); - mPrintedOkReturn = printPclDirect(mPagesToPrintArrayList, mPosPrintSetupDialogChoices, - mPrintingProgressBar, mAttributes); + PriDebug.releaseln("\"Print PCL Direct\"" + tMsgStringBuffer.toString()); } else { - PriDebug.releaseln("Image Print using printer selected: " + mPrintService.getName()); - mPrintedOkReturn = imagePrint(mPagesToPrintArrayList, mPosPrintSetupDialogChoices, - mPrintingProgressBar, mAttributes); + PriDebug.releaseln("\"Windows Print\"" + tMsgStringBuffer.toString()); } + + // The number of additional copies has already been validated and is guaranteed to be 0 to 3 at this point + mNumberOfPrintPasses = 1 + mPosPrintSetupDialogChoices.getNumAdditionalCopies(); + + // Call the print of the all/selected/remaining/changed pages "N" times depending on Additional Copies field + for (int i = 1; i <= mNumberOfPrintPasses; i++) { + // Call "Use Windows Print" or "Print PCL Direct" + if (mPosPrintSetupDialogChoices.isPrintFormatPclDirect()) { + mPrintedOkReturn = printPclDirect(mPagesToPrintArrayList, mPosPrintSetupDialogChoices, + mPrintingProgressBar, mAttributes); + } else { + mPrintedOkReturn = imagePrint(mPagesToPrintArrayList, mPosPrintSetupDialogChoices, + mPrintingProgressBar, mAttributes); + } + } + return null; } Modified: openpcl/src/com/openpcl/viewer/printing/PosPrintSetupDialog.java =================================================================== --- openpcl/src/com/openpcl/viewer/printing/PosPrintSetupDialog.java 2007-07-03 21:44:07 UTC (rev 100) +++ openpcl/src/com/openpcl/viewer/printing/PosPrintSetupDialog.java 2007-07-04 01:45:14 UTC (rev 101) @@ -5,6 +5,7 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Font; +import java.awt.Frame; import java.awt.GridLayout; import java.awt.HeadlessException; import java.awt.event.ActionEvent; @@ -58,6 +59,7 @@ private static final long serialVersionUID = 1L; private PosView mPosView = null; private PosStartupOptions mPosStartupOptions = null; + private Frame mParentFrame = null; private PosPrintSetupDialogChoices mPrintChoices = null; private PrintRequestAttributeSet mAttributes = null; private PrinterJob mPrinterJob = null; @@ -167,6 +169,7 @@ super(pPosView.getOpenPCLViewer().getAppFrame(), pTitleBarText, true); mPosView = pPosView; mPosStartupOptions = mPosView.getOpenPCLViewer().getPosStartupOptions(); + mParentFrame = mPosView.getOpenPCLViewer().getAppFrame(); // Set to false the show DSML buttons even if the user said true on the command line mPosStartupOptions.setShowDSMLPrintDialogButtons(false); @@ -208,7 +211,7 @@ mTab1.add(mListOfPrintersJPanel, "0, 0, 2, 0"); mTab1.add(mWindowsPrintOrPclPrintJPanel, "0, 1, 2, 1"); mTab1.add(mPrintAllOnLegalSizeJCheckBox, "0, 2, 2, 2"); -// mTab1.add(mAddlCopiesJPanel, "0, 3, 2, 3"); + mTab1.add(mAddlCopiesJPanel, "0, 3, 2, 3"); // mTab1.add(mPrintBarCodesJPanel, "0, 6"); // mTab1.add(mPrintOrderJPanel, "2, 6"); @@ -231,7 +234,7 @@ mPageNumbersThatWillPrintJScrollPane = new JScrollPane(mPageNumbersThatWillPrintJTextArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); // mTab2.add(mPageNumbersThatWillPrintJScrollPane, "0, 2, 1, 2"); - mAdvancedOptionsJDialog = new JDialog(mPosView.getOpenPCLViewer().getAppFrame(), "Advanced Options", true); + mAdvancedOptionsJDialog = new JDialog(mParentFrame, "Advanced Options", true); double tloAdvancedOptionsJDialog[][] = new double[][] { { 10, mTloFill, mTloPref, 10}, // columns { 10, mTloFill, 10, mTloPref, 10} // rows @@ -276,7 +279,7 @@ // ActionListeners mPrintModeMoreInfoJButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - JOptionPane.showMessageDialog(mPosView.getOpenPCLViewer().getAppFrame(), sPrinterModeHoverOverString, + JOptionPane.showMessageDialog(mParentFrame, sPrinterModeHoverOverString, "Info for \"Use Windows Print\"", JOptionPane.INFORMATION_MESSAGE); } }); @@ -331,7 +334,7 @@ mAdvancedOptionsJButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - mAdvancedOptionsJDialog.setLocationRelativeTo(mPosView.getOpenPCLViewer().getAppFrame()); + mAdvancedOptionsJDialog.setLocationRelativeTo(mParentFrame); mAdvancedOptionsJDialog.setVisible(true); } }); @@ -344,9 +347,11 @@ mOKJButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - getPrintChoicesFromScreen(); - mPrintChoices.setUserHitOk(true); - setVisible(false); + if (!hasUserInputErrors()) { + getPrintChoicesFromScreen(); + mPrintChoices.setUserHitOk(true); + setVisible(false); + } } }); @@ -534,9 +539,11 @@ // Additional copies try { - int addlCopies = Integer.parseInt(mAddlCopiesJTextField.getText()); + int addlCopies = Integer.parseInt(mAddlCopiesJTextField.getText().trim()); mPrintChoices.setNumAdditionalCopies(addlCopies); } catch (NumberFormatException e) { + // A blank field will get a NumberFormatException and below it will be set to 0. + // Previous validation in hasUserInputErrors() doesn't allow OK to continue if non numeric or not 0 to 3 is entered mPrintChoices.setNumAdditionalCopies(0); } @@ -745,6 +752,39 @@ } } + private boolean hasUserInputErrors() { + final String tUserInputNumberRequiredString = "A number is required for Additional Copies."; + final String tUserInputValidRange0to3String = "The valid range for Additional Copies is 0 to 3."; + final String tUserInputTitleString = "Problem with Additional Copies field"; + + String tAddlCopiesString = mAddlCopiesJTextField.getText(); + if (tAddlCopiesString.trim().equalsIgnoreCase("")) { + // returning false means the screen passed user input validation (blank is treated as 0) + return false; + } + + int tAddlCopiesInt = 0; + try { + tAddlCopiesInt = Integer.parseInt(tAddlCopiesString); + } catch (NumberFormatException nfe) { + JOptionPane.showMessageDialog(mParentFrame, tUserInputNumberRequiredString, + tUserInputTitleString, JOptionPane.INFORMATION_MESSAGE); + // returning true means the screen didn't pass user input validation + return true; + } + + if (tAddlCopiesInt < 0 || tAddlCopiesInt > 3) { + JOptionPane.showMessageDialog(mParentFrame, tUserInputValidRange0to3String, + tUserInputTitleString, JOptionPane.INFORMATION_MESSAGE); + // returning true means the screen didn't pass user input validation + return true; + + } else { + // returning false means the screen passed user input validation + return false; + } + } + private class ListOfPrintersSelectionListener implements ListSelectionListener { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |