2362N/A * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * A class which implements a cross-platform print dialog. 0N/A * @author Chris Campbell 0N/A * Waiting print status (user response pending). 0N/A * Approve print status (user activated "Print" or "OK"). 0N/A * Cancel print status (user activated "Cancel"); 0N/A * Constructor for the "standard" print dialog (containing all relevant 0N/A * Constructor for the "standard" print dialog (containing all relevant 0N/A * Initialize print dialog. 0N/A * Constructor for the solitary "page setup" dialog 0N/A * Constructor for the solitary "page setup" dialog 0N/A * Initialize "page setup" dialog 0N/A * Performs Cancel when Esc key is pressed. 0N/A * Returns the current status of the dialog (whether the user has selected 0N/A * the "Print" or "Cancel" button) 0N/A * Returns an AttributeSet based on whether or not the user cancelled the 0N/A * dialog. If the user selected "Print" we return their new selections, 0N/A * otherwise we return the attributes that were passed in initially. 0N/A * Returns a PrintService based on whether or not the user cancelled the 0N/A * dialog. If the user selected "Print" we return the user's selection 0N/A * for the PrintService, otherwise we return null. 0N/A * Sets the current status flag for the dialog and disposes it (thus 0N/A * returning control of the parent frame back to the user) 0N/A * Displays a JFileChooser that allows the user to select the destination 0N/A * for "Print To File" 0N/A // "dst" should not be null. The following code 0N/A // is only added to safeguard against a possible 0N/A // buggy implementation of a PrintService having a 0N/A // null default Destination. 0N/A // all manner of runtime exceptions possible 0N/A * Updates each of the top level panels 0N/A * Initialize ResourceBundle 0N/A throw new Error(
"Fatal: Resource for ServiceUI " +
0N/A * Returns message string from resource 0N/A throw new Error(
"Fatal: Resource for ServiceUI is broken; " +
0N/A "there is no " +
key +
" key in resource");
4986N/A // ok first & not double && 0N/A * Returns mnemonic character from resource 0N/A * Returns the mnemonic as a KeyEvent.VK constant from the resource. 0N/A * Returns URL for image resource 0N/A throw new Error(
"Fatal: Resource for ServiceUI is broken; " +
0N/A "there is no " +
key +
" key in resource");
0N/A * Creates a new JButton and sets its text, mnemonic, and ActionListener 0N/A * Creates a new JButton and sets its text, and ActionListener 0N/A * Creates a new JCheckBox and sets its text, mnemonic, and ActionListener 0N/A * Creates a new JRadioButton and sets its text, mnemonic, 0N/A * and ActionListener 0N/A * Creates a pop-up dialog for "no print service" 0N/A * Sets the constraints for the GridBagLayout and adds the Component 0N/A * to the given Container 0N/A * Adds the AbstractButton to both the given ButtonGroup and Container 0N/A * The "General" tab. Includes the controls for PrintService, 0N/A // REMIND: may want to notify the user why we're 0N/A // disabling the button 0N/A // to preserve the state of Print To File 0N/A // "dest" should not be null. The following code 0N/A // is only added to safeguard against a possible 0N/A // buggy implementation of a PrintService having a 0N/A // null default Destination. 0N/A * We disable the "Print To File" checkbox if this returns false 0N/A * Break this out as it may be useful when we allow API to 0N/A * specify printing to a file. In that case its probably right 0N/A * to throw a SecurityException if the permission is not granted. 0N/A // setup Destination (print-to-file) widgets 0N/A // setup PrintService information widgets 0N/A // Selection never seemed to work so I'm commenting this part. 0N/A new JPanel(new FlowLayout(FlowLayout.LEADING)); 0N/A createRadioButton("radiobutton.selection", this); 0N/A pnlMiddle.add(rbSelect); 0N/A addToGB(pnlMiddle, this, gridbag, c); 0N/A // Comment this for now - rbSelect is not initialized 0N/A // because Selection button is not added. 0N/A // See PrintRangePanel above. 0N/A //rbSelect.setSelected(true); 0N/A // setup Copies spinner 0N/A // setup Collate checkbox 0N/A * OrientationRequested, and Sides. 0N/A // storage for the last margin values calculated, -ve is uninitialised 0N/A // storage for margins as objects mapped into orientation for display 0N/A // add an invisible spacing component. 0N/A /* Get the numbers, use to create a MPA. 0N/A * If its valid, accept it and update the attribute set. 0N/A * If its not valid, then reject it and call updateInfo() 0N/A * to re-establish the previous entries. 0N/A /* adjust for orientation */ 0N/A * This method either accepts the values and creates a new 0N/A * MediaPrintableArea, or does nothing. 0N/A * It should not attempt to create a printable area from anything 0N/A * other than the exact values passed in. 0N/A * But REMIND/TBD: it would be user friendly to replace margins the 0N/A * user entered but are out of bounds with the minimum. 0N/A * At that point this method will need to take responsibility for 0N/A * updating the "stored" values and the UI. 0N/A /* This is complex as a MediaPrintableArea is valid only within 0N/A * a particular context of media size. 0N/A * So we need a MediaSize as well as a MediaPrintableArea. 0N/A * MediaSize can be obtained from MediaSizeName. 0N/A * If the application specifies a MediaPrintableArea, we accept it 0N/A * to the extent its valid for the Media they specify. If they 0N/A * don't specify a Media, then the default is assumed. 0N/A * If an application doesn't define a MediaPrintableArea, we need to 0N/A * create a suitable one, this is created using the specified (or 0N/A * default) Media and default 1 inch margins. This is validated 0N/A * against the paper in case this is too large for tiny media. 0N/A * At this point we now know as best we can :- 0N/A * - the maximum corresponding printable area 0N/A * - the media printable area specified by the client, if any. 0N/A * The next step is to create a default MPA if none was specified. 0N/A * 1" margins are used unless they are disproportionately 0N/A * large compared to the size of the media. 0N/A // If the paper is set to something which is too small to 0N/A // accommodate a specified printable area, perhaps carried 0N/A // over from a larger paper, the adjustment that needs to be 0N/A // performed should seem the most natural from a user's viewpoint. 0N/A // Since the user is specifying margins, then we are biased 0N/A // towards keeping the margins as close to what is specified as 0N/A // possible, shrinking or growing the printable area. 0N/A // But the API uses printable area, so you need to know the 0N/A // media size in which the margins were previously interpreted, 0N/A // or at least have a record of the margins. 0N/A // In the case that this is the creation of this UI we do not 0N/A // have this record, so we are somewhat reliant on the client 0N/A // to supply a reasonable default 0N/A // margins impossible, but maintain P.A if can 0N/A // try to centre the printable area. 0N/A /* We now have a valid printable area. 0N/A * Turn it into margins, using the mediaSize 0N/A /* Now we know the values to use, we need to assign them 0N/A * to the fields appropriate for the orientation. 0N/A * Note: if orientation changes this method must be called. 0N/A // replace characters that would be invalid in 0N/A // a resource key with valid characters 0N/A /* Non-default paper size, so need to store tray 0N/A * as SunAlternateMedia 0N/A // orientation affects display of margins. 0N/A /* this is ad hoc to keep things simple */ 0N/A // initialize size selection to default 0N/A "orientPortrait.png",
true,
0N/A "orientLandscape.png",
false,
0N/A "orientRevPortrait.png",
false,
0N/A "orientRevLandscape.png",
false,
0N/A // orientation affects display of margins. 0N/A /* This is ad hoc to keep things simple */ 997N/A // need to validate if default is not supported 997N/A // get the first in the list 997N/A }
else {
// if (or == OrientationRequested.REVERSE_LANDSCAPE) 0N/A * The "Appearance" tab. Includes the controls for Chromaticity, 0N/A * PrintQuality, JobPriority, JobName, and other related job attributes. 0N/A // REMIND: use isSameAs if we move to a IconRB in the future 0N/A }
else {
// if (ch == Chromaticity.COLOR) 0N/A }
else {
// if (pq == PrintQuality.HIGH) 0N/A "oneside.png",
true,
0N/A "tumble.png",
false,
0N/A "duplex.png",
false,
0N/A }
else {
// if (sd == Sides.DUPLEX) 0N/A // setup JobSheets checkbox 0N/A // setup JobPriority spinner 0N/A // setup JobName text field 0N/A // setup RequestingUserName text field 0N/A * A special widget that groups a JRadioButton with an associated icon, 0N/A * placed to the left of the radio button. 0N/A * Similar in functionality to the default JFileChooser, except this 0N/A * chooser will pop up a "Do you want to overwrite..." dialog if the 0N/A * user selects a file that already exists. 0N/A // only delete access is denied. Just ignore it because in 0N/A // most cases the file created in createNewFile gets 0N/A // overwritten anyway.