/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A class which implements a cross-platform print dialog.
*
* @author Chris Campbell
*/
/**
* Waiting print status (user response pending).
*/
/**
* Approve print status (user activated "Print" or "OK").
*/
/**
* Cancel print status (user activated "Cancel");
*/
private int defaultServiceIndex;
private int status;
private boolean isAWT = false;
static {
initResource();
}
/**
* Constructor for the "standard" print dialog (containing all relevant
* tabs)
*/
int x, int y,
int defaultServiceIndex,
{
flavor, attributes);
}
/**
* Constructor for the "standard" print dialog (containing all relevant
* tabs)
*/
int x, int y,
int defaultServiceIndex,
{
flavor, attributes);
}
/**
* Initialize print dialog.
*/
void initPrintDialog(int x, int y,
int defaultServiceIndex,
{
this.asOriginal = attributes;
isAWT = true;
}
Container c = getContentPane();
c.setLayout(new BorderLayout());
tpTabs = new JTabbedPane();
pnlGeneral = new GeneralPanel();
pnlPageSetup = new PageSetupPanel();
pnlAppearance = new AppearancePanel();
updatePanels();
addWindowListener(new WindowAdapter() {
}
});
setResizable(false);
setLocation(x, y);
pack();
}
/**
* Constructor for the solitary "page setup" dialog
*/
int x, int y,
{
}
/**
* Constructor for the solitary "page setup" dialog
*/
int x, int y,
{
}
/**
* Initialize "page setup" dialog
*/
void initPageDialog(int x, int y,
{
this.asOriginal = attributes;
Container c = getContentPane();
c.setLayout(new BorderLayout());
pnlPageSetup = new PageSetupPanel();
addWindowListener(new WindowAdapter() {
}
});
setResizable(false);
setLocation(x, y);
pack();
}
/**
* Performs Cancel when Esc key is pressed.
*/
public void actionPerformed(ActionEvent e) {
}
};
}
}
/**
* Returns the current status of the dialog (whether the user has selected
* the "Print" or "Cancel" button)
*/
public int getStatus() {
return status;
}
/**
* Returns an AttributeSet based on whether or not the user cancelled the
* dialog. If the user selected "Print" we return their new selections,
* otherwise we return the attributes that were passed in initially.
*/
return asCurrent;
} else {
return asOriginal;
}
}
/**
* Returns a PrintService based on whether or not the user cancelled the
* dialog. If the user selected "Print" we return the user's selection
* for the PrintService, otherwise we return null.
*/
return psCurrent;
} else {
return null;
}
}
/**
* Sets the current status flag for the dialog and disposes it (thus
* returning control of the parent frame back to the user)
*/
super.dispose();
}
boolean approved = false;
if (source == btnApprove) {
approved = true;
if (pnlGeneral != null) {
if (pnlGeneral.isPrintToFileRequested()) {
approved = showFileChooser();
} else {
}
}
}
}
/**
* Displays a JFileChooser that allows the user to select the destination
* for "Print To File"
*/
private boolean showFileChooser() {
// "dst" should not be null. The following code
// is only added to safeguard against a possible
// buggy implementation of a PrintService having a
// null default Destination.
try {
} catch (URISyntaxException e) {
}
}
}
}
try {
} catch (Exception e) {
// all manner of runtime exceptions possible
}
} else {
}
try {
} catch (Exception e) {
}
} else {
}
}
/**
* Updates each of the top level panels
*/
private void updatePanels() {
}
/**
* Initialize ResourceBundle
*/
public static void initResource() {
try {
return null;
throw new Error("Fatal: Resource for ServiceUI " +
"is missing");
}
}
}
);
}
/**
* Returns message string from resource
*/
try {
throw new Error("Fatal: Resource for ServiceUI is broken; " +
}
}
int i = s.indexOf('&');
return s;
}
if (j == i+1) {
if (j+1 == len) {
} else {
}
}
// ok first & not double &&
if (i == 0) {
} else {
}
}
/**
* Returns mnemonic character from resource
*/
return Character.toUpperCase(c);
} else {
return (char)0;
}
}
/**
* Returns the mnemonic as a KeyEvent.VK constant from the resource.
*/
return 0;
}
try {
if (_keyEventClazz == null) {
true, (ServiceDialog.class).getClassLoader());
}
return value;
} catch (Exception e) {
}
return 0;
}
/**
* Returns URL for image resource
*/
"resources/" + key);
return url;
}
});
throw new Error("Fatal: Resource for ServiceUI is broken; " +
}
return url;
}
/**
* Creates a new JButton and sets its text, mnemonic, and ActionListener
*/
return btn;
}
/**
* Creates a new JButton and sets its text, and ActionListener
*/
return btn;
}
/**
* Creates a new JCheckBox and sets its text, mnemonic, and ActionListener
*/
return cb;
}
/**
* Creates a new JRadioButton and sets its text, mnemonic,
* and ActionListener
*/
{
return rb;
}
/**
* Creates a pop-up dialog for "no print service"
*/
{
getMsg("dialog.noprintermsg"));
}
/**
* Sets the constraints for the GridBagLayout and adds the Component
* to the given Container
*/
{
}
/**
* Adds the AbstractButton to both the given ButtonGroup and Container
*/
{
}
/**
* The "General" tab. Includes the controls for PrintService,
*/
public GeneralPanel() {
super();
GridBagConstraints c = new GridBagConstraints();
c.insets = panelInsets;
c.weightx = 1.0;
c.weighty = 1.0;
pnlPrintService = new PrintServicePanel();
pnlPrintRange = new PrintRangePanel();
pnlCopies = new CopiesPanel();
}
public boolean isPrintToFileRequested() {
return (pnlPrintService.isPrintToFileSelected());
}
public void updateInfo() {
}
}
{
private boolean changedService = false;
private boolean filePermission;
public PrintServicePanel() {
super();
GridBagConstraints c = new GridBagConstraints();
}
cbName.addItemListener(this);
cbName.addPopupMenuListener(this);
c.insets = compInsets;
c.weightx = 0.0;
c.weightx = 1.0;
c.weightx = 0.0;
c.weighty = 1.0;
c.gridwidth = 1;
this, gridbag, c);
}
public boolean isPrintToFileSelected() {
return cbPrintToFile.isSelected();
}
{
c.gridwidth = 1;
return label;
}
if (source == btnProperties) {
} else {
// REMIND: may want to notify the user why we're
// disabling the button
btnProperties.setEnabled(false);
}
}
}
}
changedService = true;
// to preserve the state of Print To File
Destination.class)) {
} else {
getDefaultAttributeValue(Destination.class);
// "dest" should not be null. The following code
// is only added to safeguard against a possible
// buggy implementation of a PrintService having a
// null default Destination.
try {
dest =
} catch (URISyntaxException ue) {
}
}
}
}
} else {
}
}
}
}
}
changedService = false;
}
if (changedService) {
changedService = false;
updatePanels();
}
}
}
/**
* We disable the "Print To File" checkbox if this returns false
*/
private boolean allowedToPrintToFile() {
try {
return true;
} catch (SecurityException e) {
return false;
}
}
/**
* Break this out as it may be useful when we allow API to
* specify printing to a file. In that case its probably right
* to throw a SecurityException if the permission is not granted.
*/
private void throwPrintToFile() {
if (printToFilePermission == null) {
}
}
}
public void updateInfo() {
boolean dstSupported = false;
boolean dstSelected = false;
boolean dstAllowed = filePermission ?
allowedToPrintToFile() : false;
// setup Destination (print-to-file) widgets
dstSupported = true;
}
dstSelected = true;
}
&& dstSupported);
// setup PrintService information widgets
}
}
}
}
}
implements ActionListener, FocusListener
{
private boolean prSupported;
public PrintRangePanel() {
super();
GridBagConstraints c = new GridBagConstraints();
c.insets = compInsets;
rbAll.setSelected(true);
// Selection never seemed to work so I'm commenting this part.
/*
if (isAWT) {
JPanel pnlMiddle =
new JPanel(new FlowLayout(FlowLayout.LEADING));
rbSelect =
createRadioButton("radiobutton.selection", this);
bg.add(rbSelect);
pnlMiddle.add(rbSelect);
addToGB(pnlMiddle, this, gridbag, c);
}
*/
format.setParseIntegerOnly(true);
format.setDecimalSeparatorAlwaysShown(false);
nf.setAllowsInvalid(true);
nf.setCommitsOnValidEdit(true);
tfRangeFrom.setEnabled(false);
tfRangeFrom.addActionListener(this);
tfRangeFrom.addFocusListener(this);
getMsg("radiobutton.rangepages"));
lblRangeTo.setEnabled(false);
try {
} catch (CloneNotSupportedException e) {
nfto = new NumberFormatter();
}
tfRangeTo.setEnabled(false);
tfRangeTo.addFocusListener(this);
getMsg("label.rangeto"));
}
source == tfRangeFrom ||
}
if (isAWT) {
}
}
}
}
private void setupRangeWidgets() {
}
private void updateRangeAttribute() {
int min;
int max;
try {
} catch (NumberFormatException e) {
min = 1;
}
try {
} catch (NumberFormatException e) {
}
if (min < 1) {
min = 1;
}
}
}
public void updateInfo() {
prSupported = false;
isAWT) {
prSupported = true;
}
int min = 1;
int max = 1;
}
}
}
if (isAWT) {
SunPageSelection.class);
}
rbAll.setSelected(true);
// Comment this for now - rbSelect is not initialized
// because Selection button is not added.
// See PrintRangePanel above.
//rbSelect.setSelected(true);
} else { // RANGE
rbPages.setSelected(true);
}
}
}
implements ActionListener, ChangeListener
{
private boolean scSupported;
public CopiesPanel() {
super();
GridBagConstraints c = new GridBagConstraints();
c.insets = compInsets;
getMsg("label.numcopies"));
// REMIND
spinCopies.addChangeListener(this);
cbCollate.setEnabled(false);
}
if (cbCollate.isSelected()) {
} else {
}
}
}
private void updateCollateCB() {
if (isAWT) {
cbCollate.setEnabled(true);
} else {
}
}
public void updateInfo() {
boolean cpSupported = false;
scSupported = false;
// setup Copies spinner
cpSupported = true;
}
}
}
}
} else {
min = 1;
}
}
// setup Collate checkbox
scSupported = true;
}
}
}
}
}
/**
* The "Page Setup" tab. Includes the controls for MediaSource/MediaTray,
* OrientationRequested, and Sides.
*/
public PageSetupPanel() {
super();
GridBagConstraints c = new GridBagConstraints();
c.insets = panelInsets;
c.weightx = 1.0;
c.weighty = 1.0;
pnlMedia = new MediaPanel();
pnlOrientation = new OrientationPanel();
pnlMargins = new MarginsPanel();
}
public void updateInfo() {
}
}
implements ActionListener, FocusListener {
// storage for the last margin values calculated, -ve is uninitialised
// storage for margins as objects mapped into orientation for display
public MarginsPanel() {
super();
GridBagConstraints c = new GridBagConstraints();
c.weightx = 1.0;
c.weighty = 0.0;
c.insets = compInsets;
if (defaultCountry != null &&
unitsKey = "label.inches";
}
} else {
}
format.setParseIntegerOnly(false);
nf.setAllowsInvalid(true);
nf.setCommitsOnValidEdit(true);
leftMargin.addFocusListener(this);
leftMargin.addActionListener(this);
getMsg("label.leftmargin"));
rightMargin.addFocusListener(this);
rightMargin.addActionListener(this);
getMsg("label.rightmargin"));
topMargin.addFocusListener(this);
topMargin.addActionListener(this);
getMsg("label.topmargin"));
bottomMargin.addFocusListener(this);
bottomMargin.addActionListener(this);
getMsg("label.bottommargin"));
// add an invisible spacing component.
}
}
}
/* Get the numbers, use to create a MPA.
* If its valid, accept it and update the attribute set.
* If its not valid, then reject it and call updateInfo()
* to re-establish the previous entries.
*/
if (!(source instanceof JFormattedTextField)) {
return;
} else {
return;
}
return;
}
return;
}
return;
}
return;
}
}
/* adjust for orientation */
}
float tmp;
}
} else {
return;
} else {
}
}
}
/*
* This method either accepts the values and creates a new
* MediaPrintableArea, or does nothing.
* It should not attempt to create a printable area from anything
* other than the exact values passed in.
* user entered but are out of bounds with the minimum.
* At that point this method will need to take responsibility for
* updating the "stored" values and the UI.
*/
}
}
}
tmpASet);
if (values instanceof MediaPrintableArea[] &&
}
}
units);
}
return null;
} else {
}
}
/* This is complex as a MediaPrintableArea is valid only within
* a particular context of media size.
* So we need a MediaSize as well as a MediaPrintableArea.
* MediaSize can be obtained from MediaSizeName.
* If the application specifies a MediaPrintableArea, we accept it
* to the extent its valid for the Media they specify. If they
* don't specify a Media, then the default is assumed.
*
* If an application doesn't define a MediaPrintableArea, we need to
* create a suitable one, this is created using the specified (or
* default) Media and default 1 inch margins. This is validated
* against the paper in case this is too large for tiny media.
*/
public void updateInfo() {
if (isAWT) {
leftMargin.setEnabled(false);
rightMargin.setEnabled(false);
topMargin.setEnabled(false);
bottomMargin.setEnabled(false);
lblLeft.setEnabled(false);
lblRight.setEnabled(false);
lblTop.setEnabled(false);
lblBottom.setEnabled(false);
return;
}
}
}
}
tmpASet);
if (values instanceof MediaPrintableArea[] &&
} else if (values instanceof MediaPrintableArea) {
}
}
units);
}
/*
* At this point we now know as best we can :-
* - the media size
* - the maximum corresponding printable area
* - the media printable area specified by the client, if any.
* The next step is to create a default MPA if none was specified.
* 1" margins are used unless they are disproportionately
* large compared to the size of the media.
*/
float maxMarginRatio = 5f;
if (wid > maxMarginRatio) {
xMgn = 1f;
} else {
}
if (hgt > maxMarginRatio) {
yMgn = 1f;
} else {
}
}
boolean invalid = false;
// If the paper is set to something which is too small to
// accommodate a specified printable area, perhaps carried
// over from a larger paper, the adjustment that needs to be
// performed should seem the most natural from a user's viewpoint.
// Since the user is specifying margins, then we are biased
// towards keeping the margins as close to what is specified as
// possible, shrinking or growing the printable area.
// But the API uses printable area, so you need to know the
// media size in which the margins were previously interpreted,
// or at least have a record of the margins.
// In the case that this is the creation of this UI we do not
// have this record, so we are somewhat reliant on the client
// to supply a reasonable default
if (lmVal >= 0f) {
invalid = true;
// margins impossible, but maintain P.A if can
}
// try to centre the printable area.
} else {
}
}
} else {
}
}
invalid = true;
}
invalid = true;
}
invalid = true;
}
invalid = true;
}
invalid = true;
}
invalid = true;
}
if (invalid) {
}
/* We now have a valid printable area.
* Turn it into margins, using the mediaSize
*/
/* Now we know the values to use, we need to assign them
* to the fields appropriate for the orientation.
* Note: if orientation changes this method must be called.
*/
}
}
}
}
public MediaPanel() {
super();
GridBagConstraints c = new GridBagConstraints();
c.insets = compInsets;
c.weighty = 1.0;
c.weightx = 0.0;
c.weightx = 1.0;
c.weightx = 0.0;
c.gridwidth = 1;
}
try {
// replace characters that would be invalid in
// a resource key with valid characters
return key;
}
}
{
}
}
} else if (m instanceof MediaSizeName) {
} else {
/* Non-default paper size, so need to store tray
* as SunAlternateMedia
*/
}
}
} else if (index == 0) {
}
}
}
// orientation affects display of margins.
if (pnlMargins != null) {
}
}
}
/* this is ad hoc to keep things simple */
pnlMargins = pnl;
}
public void updateInfo() {
boolean mediaSupported = false;
cbSize.removeItemListener(this);
cbSource.removeItemListener(this);
mediaSupported = true;
if (medium instanceof MediaSizeName) {
}
}
}
}
if (isAWT) {
cbSource.setEnabled(false);
lblSource.setEnabled(false);
} else {
}
if (mediaSupported) {
// initialize size selection to default
if (defMedia instanceof MediaSizeName) {
}
}
}
}
}
if (medium instanceof MediaSizeName) {
}
} else {
}
}
}
}
} else {
}
}
}
cbSize.addItemListener(this);
cbSource.addItemListener(this);
}
}
implements ActionListener
{
public OrientationPanel() {
super();
GridBagConstraints c = new GridBagConstraints();
c.insets = compInsets;
c.weighty = 1.0;
"orientPortrait.png", true,
bg, this);
rbPortrait.addActionListener(this);
"orientLandscape.png", false,
bg, this);
rbLandscape.addActionListener(this);
"orientRevPortrait.png", false,
bg, this);
rbRevPortrait.addActionListener(this);
"orientRevLandscape.png", false,
bg, this);
rbRevLandscape.addActionListener(this);
}
}
// orientation affects display of margins.
if (pnlMargins != null) {
}
}
/* This is ad hoc to keep things simple */
pnlMargins = pnl;
}
public void updateInfo() {
boolean pSupported = false;
boolean lSupported = false;
boolean rpSupported = false;
boolean rlSupported = false;
if (isAWT) {
pSupported = true;
lSupported = true;
} else
if (values instanceof OrientationRequested[]) {
pSupported = true;
lSupported = true;
rpSupported = true;
rlSupported = true;
}
}
}
}
// need to validate if default is not supported
if (values instanceof OrientationRequested[]) {
// get the first in the list
}
}
}
}
}
rbPortrait.setSelected(true);
rbLandscape.setSelected(true);
rbRevPortrait.setSelected(true);
} else { // if (or == OrientationRequested.REVERSE_LANDSCAPE)
rbRevLandscape.setSelected(true);
}
}
}
/**
* The "Appearance" tab. Includes the controls for Chromaticity,
* PrintQuality, JobPriority, JobName, and other related job attributes.
*/
public AppearancePanel() {
super();
GridBagConstraints c = new GridBagConstraints();
c.insets = panelInsets;
c.weightx = 1.0;
c.weighty = 1.0;
pnlChromaticity = new ChromaticityPanel();
pnlQuality = new QualityPanel();
c.gridwidth = 1;
pnlSides = new SidesPanel();
pnlJobAttributes = new JobAttributesPanel();
}
public void updateInfo() {
}
}
implements ActionListener
{
public ChromaticityPanel() {
super();
GridBagConstraints c = new GridBagConstraints();
c.weighty = 1.0;
rbMonochrome.setSelected(true);
}
// REMIND: use isSameAs if we move to a IconRB in the future
if (source == rbMonochrome) {
}
}
public void updateInfo() {
boolean monoSupported = false;
boolean colorSupported = false;
if (isAWT) {
monoSupported = true;
colorSupported = true;
} else
if (values instanceof Chromaticity[]) {
monoSupported = true;
colorSupported = true;
}
}
}
}
}
}
rbMonochrome.setSelected(true);
} else { // if (ch == Chromaticity.COLOR)
rbColor.setSelected(true);
}
}
}
implements ActionListener
{
public QualityPanel() {
super();
GridBagConstraints c = new GridBagConstraints();
c.weighty = 1.0;
rbNormal.setSelected(true);
}
}
}
public void updateInfo() {
boolean draftSupported = false;
boolean normalSupported = false;
boolean highSupported = false;
if (isAWT) {
draftSupported = true;
normalSupported = true;
highSupported = true;
} else
if (values instanceof PrintQuality[]) {
draftSupported = true;
normalSupported = true;
highSupported = true;
}
}
}
}
}
}
rbDraft.setSelected(true);
rbNormal.setSelected(true);
} else { // if (pq == PrintQuality.HIGH)
rbHigh.setSelected(true);
}
}
}
implements ActionListener
{
public SidesPanel() {
super();
GridBagConstraints c = new GridBagConstraints();
c.insets = compInsets;
c.weighty = 1.0;
"oneside.png", true,
bg, this);
rbOneSide.addActionListener(this);
"tumble.png", false,
bg, this);
rbTumble.addActionListener(this);
"duplex.png", false,
bg, this);
rbDuplex.addActionListener(this);
}
}
}
public void updateInfo() {
boolean osSupported = false;
boolean tSupported = false;
boolean dSupported = false;
osSupported = true;
tSupported = true;
dSupported = true;
}
}
}
}
}
}
rbOneSide.setSelected(true);
rbTumble.setSelected(true);
} else { // if (sd == Sides.DUPLEX)
rbDuplex.setSelected(true);
}
}
}
{
public JobAttributesPanel() {
super();
GridBagConstraints c = new GridBagConstraints();
c.insets = compInsets;
c.weighty = 1.0;
// REMIND
spinPriority.addChangeListener(this);
getMsg("label.priority"));
c.weightx = 0.0;
c.gridwidth = 1;
c.weightx = 1.0;
tfJobName = new JTextField();
tfJobName.addFocusListener(this);
getMsg("label.jobname"));
c.weightx = 0.0;
c.gridwidth = 1;
tfUserName = new JTextField();
tfUserName.addFocusListener(this);
getMsg("label.username"));
}
if (cbJobSheets.isSelected()) {
} else {
}
}
}
Locale.getDefault()));
} else if (source == tfUserName) {
Locale.getDefault()));
}
}
public void updateInfo() {
boolean jsSupported = false;
boolean jpSupported = false;
boolean jnSupported = false;
boolean unSupported = false;
// setup JobSheets checkbox
jsSupported = true;
}
}
}
// setup JobPriority spinner
jpSupported = true;
}
}
}
value = 1;
}
// setup JobName text field
jnSupported = true;
}
}
}
// setup RequestingUserName text field
unSupported = true;
}
}
}
}
}
/**
* A special widget that groups a JRadioButton with an associated icon,
* placed to the left of the radio button.
*/
{
return icon;
}
});
}
}
}
}
public boolean isSelected() {
return rb.isSelected();
}
}
}
/**
* Similar in functionality to the default JFileChooser, except this
* chooser will pop up a "Do you want to overwrite..." dialog if the
* user selects a file that already exists.
*/
public void approveSelection() {
boolean exists;
try {
} catch (SecurityException e) {
exists = false;
}
if (exists) {
int val;
getMsg("dialog.overwrite"),
getMsg("dialog.owtitle"),
return;
}
}
try {
if (selected.createNewFile()) {
}
} catch (IOException ioe) {
JOptionPane.showMessageDialog(this,
getMsg("dialog.owtitle"),
return;
} catch (SecurityException se) {
// only delete access is denied. Just ignore it because in
// most cases the file created in createNewFile gets
// overwritten anyway.
}
JOptionPane.showMessageDialog(this,
getMsg("dialog.owtitle"),
return;
}
super.approveSelection();
}
}
}