From: <doc...@us...> - 2007-08-06 17:51:15
|
Revision: 143 http://openpcl.svn.sourceforge.net/openpcl/?rev=143&view=rev Author: documentsystems Date: 2007-08-06 10:51:17 -0700 (Mon, 06 Aug 2007) Log Message: ----------- Howard Hoagland. In OpenPCLViewer, at program startup time, and at program exit time, using the new class PosPersistPrintOptionsValues, read and write all the print setup dialog options the user clicked on (Use Windows Print or print PCL Direct, Print as displayed, Legal first then Letter, Letter first then Legal, All on Legal, All on Letter (shrinks Legal), Print Form Names, Duplex), to the local persisted storage using the java.util.prefs.Preferences in a platform independent way. For Windows, it will write to the Registry at "HKEY_CURRENT_USER\Software\JavaSoft\Prefs\com\openpcl\viewer". For Macintosh, the Preferences object in the local running JVM writes the settings in a Macintosh specific way. Modified Paths: -------------- openpcl/src/com/openpcl/viewer/OpenPCLViewer.java Modified: openpcl/src/com/openpcl/viewer/OpenPCLViewer.java =================================================================== --- openpcl/src/com/openpcl/viewer/OpenPCLViewer.java 2007-08-06 17:43:28 UTC (rev 142) +++ openpcl/src/com/openpcl/viewer/OpenPCLViewer.java 2007-08-06 17:51:17 UTC (rev 143) @@ -76,6 +76,7 @@ import com.openpcl.viewer.panels.PosView; import com.openpcl.viewer.panels.PosWindowControlList; import com.openpcl.viewer.panels.PosZoomSlider; +import com.openpcl.viewer.printing.PosPersistPrintOptionsValues; import com.openpcl.viewer.printing.PosPrintPages; import com.openpcl.viewer.printing.PosPrintSetupDialogChoices; import com.openpcl.viewer.statusbar.PosStatusBar; @@ -187,6 +188,7 @@ private String mFilePathAndFileName = "C:\\"; private Preferences mPackagePreferences = null; private PosPersistViewValues mPosPersistViewValues = null; + private PosPersistPrintOptionsValues mPosPersistPrintOptionsValues = null; private PosStartupOptions mPosStartupOptions = null; private PosPrintSetupDialogChoices mPosPrintSetupDialogChoices = null; private PrintRequestAttributeSet mPrintRequestAttributeSet = null; @@ -198,7 +200,6 @@ public static final int sMinIndexImages = 1; public static final int sMaxNumImages = 9; public static final double sDefaultZoomFactor = 0.3d; - private int mCurrentViewIndex = sMinIndexImages; private PosView mPosViewSelected = null; private PosView[] mPosViewArray = new PosView[sMaxNumImages + 1]; private String mPackagePathLicenseInfo = "com/openpcl/viewer/htmlfiles/LicenseInfo.html"; @@ -568,17 +569,28 @@ showStatusBar(); // Show the status bar now so the user doesn't have to wait longer while the rest of the items are built validate(); + // Build popup dialogs but don't show them at startup time. They get shown only when the user clicks later + buildPopupDialogs(); - // Read the last one closed before exited last time JInternalFrame (x,y) and (width,height) and last opened file directory - if (mCanWriteToLocalClient) { readPersistedViewValues(); } + // Get a Preferences object that is platform independent. The running JVM will store these values to the user's + // PC or Macintish in a platform specific way. For Windows, the values are written to the Windows registry at: + // "HKEY_CURRENT_USER\Software\JavaSoft\Prefs\com\openpcl\viewer" + // For Macintosh, the JVM on the Macintosh will write the Preferences object's values in a Macintosh platform specific way. + mPackagePreferences = Preferences.userNodeForPackage(OpenPCLViewer.class); + + // Read the (x,y) and (width,height) and last opened file directory, of the last JInternalFrame closed before exiting last time + // from local persisted storage + readPersistedViewValues(mPackagePreferences); + // Read all the print setup dialog options from local persisted storage into the PosPrintSetupDialogChoices object + // that the print setup dialog has a reference to + readPrintOptionsValues(mPackagePreferences, mPosPrintSetupDialogChoices); + // Build the MDI Desktop Pane mPosMdiDesktopPane = buildPosMdiDesktopPane(); add(mPosMdiDesktopPane, BorderLayout.CENTER); // Need to force screen update to show the tree and image panel revalidate(); - // Build popup dialogs but don't show them at startup time. They get shown only when the user clicks later - buildPopupDialogs(); mPosManageToolBar.setNoViewsOpen(); } @@ -739,21 +751,21 @@ } /** - * Read the persisted view frame's (x,y) location and (width,height), and window state (maximized/iconified) + * Read the locally persisted view frame's (x,y) location and (width,height), and window state (maximized/iconified) * and full path and filename of last file opened * @author howard 10/9/06 */ - protected void readPersistedViewValues() { + protected void readPersistedViewValues(Preferences pPrefs) { // If the JAR files are not signed, don't try to read from the client platform if ( !mCanWriteToLocalClient ) { return; } + // Must have a reference to the Preferences object + if (pPrefs == null) { return; } - // Read the persistent view settings from the platform independent Perferences class but the JVM will store - // these values to the user's PC registry for Windows at "HKEY_CURRENT_USER\Software\JavaSoft\Prefs" - mPackagePreferences = Preferences.userNodeForPackage(OpenPCLViewer.class); + // Read the persisted view settings from the platform independent Perferences class mPosPersistViewValues = new PosPersistViewValues(); - mPosPersistViewValues.readViewValues(mPackagePreferences); + mPosPersistViewValues.readViewValues(pPrefs); - // Get the persistent app settings for window (x,y) location and (width, height) and window state + // Get the persisted app settings for window (x,y) location and (width, height) and window state // to be able to show the app's JFrame in the same locating and width and window state as last time // the app was run mViewframeX = mPosPersistViewValues.getViewframeX(); @@ -765,20 +777,84 @@ } /** - * Save the persisted view frame's (x,y) location and (width,height), and window state (maximized/iconified) + * Read the locally persisted print setup dialog options + * @param pPrefs + * @param pPosPrintSetupDialogChoices + * @author DocMagic, Document Systems Inc, Howard H 8/3/07 + */ + protected void readPrintOptionsValues(Preferences pPrefs, PosPrintSetupDialogChoices pPosPrintSetupDialogChoices) { + // If the JAR files are not signed, don't try to read from the client platform + if ( !mCanWriteToLocalClient ) { return; } + // Must have a reference to the Preferences object and PosPrintSetupDialogChoices + if ( (pPrefs == null) || (pPosPrintSetupDialogChoices == null) ) { return; } + + // Read the persisted print options settings from the platform independent Perferences class + mPosPersistPrintOptionsValues = new PosPersistPrintOptionsValues(); + mPosPersistPrintOptionsValues.readPrintOptionsValues(pPrefs); + + // Windows Print or Pcl Direct + if (mPosPersistPrintOptionsValues.getPrintOptionsUseWindowsPrint().equalsIgnoreCase("Y")) { + pPosPrintSetupDialogChoices.setPrintFormatIsWindowsPrint(); + } else if (mPosPersistPrintOptionsValues.getPrintOptionsPclDirect().equalsIgnoreCase("Y")) { + pPosPrintSetupDialogChoices.setPrintFormatIsPclDirect(); + } + + // Paper size and print order + if (mPosPersistPrintOptionsValues.getPrintOptionsAsDisplayed().equalsIgnoreCase("Y")) { + pPosPrintSetupDialogChoices.setPaperSizeAsDisplayedSelected(); + } else if (mPosPersistPrintOptionsValues.getPrintOptionsLegalThenLetter().equalsIgnoreCase("Y")) { + pPosPrintSetupDialogChoices.setPaperSizeLegalFirstThenLetter(); + } else if (mPosPersistPrintOptionsValues.getPrintOptionsLetterThenLegal().equalsIgnoreCase("Y")) { + pPosPrintSetupDialogChoices.setPaperSizeLetterFirstThenLegal(); + } else if (mPosPersistPrintOptionsValues.getPrintOptionsAllOnLegal().equalsIgnoreCase("Y")) { + pPosPrintSetupDialogChoices.setPaperSizePrintAllOnLegal(); + } else if (mPosPersistPrintOptionsValues.getPrintOptionsAllOnLetter().equalsIgnoreCase("Y")) { + pPosPrintSetupDialogChoices.setPaperSizePrintAllOnLetterShrinksLegal(); + } + + // Additional copies + int tNumAdditionalCopies = 0; + try { + tNumAdditionalCopies = Integer.parseInt(mPosPersistPrintOptionsValues.getPrintOptionsAdditionalCopies()); + } catch (NumberFormatException npe) { + } + + pPosPrintSetupDialogChoices.setNumAdditionalCopies(tNumAdditionalCopies); + + // Print Form Names + if (mPosPersistPrintOptionsValues.getPrintOptionsPrintFormNames().equalsIgnoreCase("Y")) { + pPosPrintSetupDialogChoices.setShouldPrintFormNames(true); + } else { + pPosPrintSetupDialogChoices.setShouldPrintFormNames(false); + } + + // Duplex + if (mPosPersistPrintOptionsValues.getPrintOptionsDuplex().equalsIgnoreCase("Y")) { + pPosPrintSetupDialogChoices.setShouldDuplex(true); + } else { + pPosPrintSetupDialogChoices.setShouldDuplex(false); + } + } + + /** + * Save to local persisted storage the view frame's (x,y) location and (width,height), and window state (maximized/iconified) * and full path and filename of last file opened * @author howard 10/9/06 */ - protected void savePersistedViewValues(JInternalFrame pJInternalFrame) { + protected void savePersistedViewValues( + JInternalFrame pJInternalFrame, Preferences pPrefs, PosPersistViewValues pPosPersistViewValues) { + // If the JAR files are not signed, don't try to write to the client platform if ( !mCanWriteToLocalClient ) { return; } + // Must have a reference to the Preferences object and PosPersistViewValues + if ( (pPrefs == null) || (pPosPersistViewValues == null) ) { return; } Rectangle tRect = null; if ( !(pJInternalFrame.isMaximum()) ) { // At the moment the user closes the app, the JFrame is not maximized and is not iconified/minimized, so // save the current JFrame location (x,y) and (width,height) as current window on screen now tRect = pJInternalFrame.getBounds(); - mPosPersistViewValues.saveViewValues(mPackagePreferences, tRect.x, tRect.y, + pPosPersistViewValues.saveViewValues(pPrefs, tRect.x, tRect.y, tRect.width, tRect.height, JFrame.NORMAL, mFilePathAndFileName); } else { @@ -787,7 +863,7 @@ // the user un maximizes it (aka hits the "Restore" button), it will go to the last (x,y) and (width,height) // instead of staying at the (0,0) location and maximized (width,height) size tRect = pJInternalFrame.getNormalBounds(); - mPosPersistViewValues.saveViewValues(mPackagePreferences, tRect.x, tRect.y, + pPosPersistViewValues.saveViewValues(pPrefs, tRect.x, tRect.y, tRect.width, tRect.height, JFrame.MAXIMIZED_BOTH, mFilePathAndFileName); } @@ -802,6 +878,34 @@ mViewframeState = JFrame.NORMAL; } } + + /** + * Save to local persisted storate the print setup dialog options + * @param pPrefs + * @param pPosPersistPrintOptionsValues + * @param pPosPrintSetupDialogChoices + * @author DocMagic, Document Systems Inc, Howard H 8/3/07 + */ + protected void savePersistedPrintOptionsValues(Preferences pPrefs, + PosPersistPrintOptionsValues pPosPersistPrintOptionsValues, PosPrintSetupDialogChoices pPosPrintSetupDialogChoices) { + + // If the JAR files are not signed, don't try to write to the client platform + if ( !mCanWriteToLocalClient ) { return; } + // Must have a reference to the Preferences object and PosPersistPrintOptionsValues and PosPrintSetupDialogChoices + if ( (pPrefs == null) || (pPosPersistPrintOptionsValues == null) || (pPosPrintSetupDialogChoices == null)) { return; } + + pPosPersistPrintOptionsValues.savePrintOptionsValues(pPrefs, + (pPosPrintSetupDialogChoices.isPrintFormatWindowsPrint() ? "Y" : "N"), + (pPosPrintSetupDialogChoices.isPrintFormatPclDirect() ? "Y" : "N"), + (pPosPrintSetupDialogChoices.isPaperSizeAsDisplayedOrSelected() ? "Y" : "N"), + (pPosPrintSetupDialogChoices.isPaperSizeLegalFirstThenLetter() ? "Y" : "N"), + (pPosPrintSetupDialogChoices.isPaperSizeLetterFirstThenLegal() ? "Y" : "N"), + (pPosPrintSetupDialogChoices.isPaperSizePrintAllOnLegal() ? "Y" : "N"), + (pPosPrintSetupDialogChoices.isPaperSizePrintAllOnLetterShrinksLegal() ? "Y" : "N"), + String.valueOf(pPosPrintSetupDialogChoices.getNumAdditionalCopies()), + (pPosPrintSetupDialogChoices.shouldPrintFormNames() ? "Y" : "N"), + (pPosPrintSetupDialogChoices.shouldDuplex() ? "Y" : "N") ); + } // One line getters public PosManageToolBar getPosManageToolBar() {return mPosManageToolBar;} @@ -1132,7 +1236,7 @@ if (tAllFrames.length <= 1) { // There is only one JInternalFrame showing now and when this one closes, then none will be showing // so write the JInternalFrame's (x,y) and (width, height) and last opened file to the local client platform - if (mCanWriteToLocalClient) { savePersistedViewValues(pPosView.getJInternalFrame()); } + savePersistedViewValues(pPosView.getJInternalFrame(), mPackagePreferences, mPosPersistViewValues); mPosManageToolBar.setNoViewsOpen(); } } @@ -1375,7 +1479,7 @@ mPosMdiDesktopPane.add(tJInternalFrame); // After adding the JInternalFrame in the MDI JDesktopPane, position the just added JInternalFrame - // depending on if the first view showing, then use the persistent store (x,y) and (width,height) + // depending on if the first view showing, then use the persisted store (x,y) and (width,height) if (tIsFirstJInternalFrame) { // Make the below "true" to see the problem of the last (x,y) and (width,height) was placed OK last time but now @@ -2332,7 +2436,6 @@ public void actionShowOptionsDialog() { mPosUserOptionsDialog.setLocationRelativeTo(getAppFrame()); mPosUserOptionsDialog.setVisible(true); - // TODO read the values that were set in the user options dialog and handle the different settings } /** Toggle show/hide the help choices popup */ @@ -2375,12 +2478,13 @@ /** Action "App is Exiting". This will call the CloseAllFiles operation and remove the JFrame listeners */ public void actionAppIsExiting() { - PriDebug.infoln("App is exiting"); // Remove the component listener that was put on the parent JFrame, which is used to close any showing // popup dialog mParentFrame.removeComponentListener(mFrameComponentListener); // Call the CloseAllFiles actionCloseAllFiles(); + // Save the print setup dialog options to persisted local storage so that next time the app is run, those will be read + savePersistedPrintOptionsValues(mPackagePreferences, mPosPersistPrintOptionsValues, mPosPrintSetupDialogChoices); } /** Get the app's Frame */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |