PrintUtil.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 1999-2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
public class PrintUtil {
// For I18N
private static ResourceBundle rb =
private static ResourceBundle hrb =
/**
* Prints an object to either file or printer. Uses the toString()
* method of the object to obtain a string representation for it.
* @param obj the Object that is to be printed
*/
boolean usePrinter;
printFrame.setVisible(true);
}
/**
* Call rb.getString(), but catch exception and return English
* key so that small spelling errors don't cripple the GUI
*
*/
}
try {
return res;
} catch (MissingResourceException e) {
return key;
}
}
/**
* Forgets the command and filename that was last entered.
*/
public static final void reinitialize() {
}
/*
************************************************************
* I N N E R C L A S S E S F O L L O W
************************************************************
*/
/**
* This class will show a Frame to determine whether the user wants
* to print to a file and which file, if so, or to the printer
* directly. Finally it will print to the appropriate destinaition.
*/
private static class PrintFrame extends Frame {
private CheckboxGroup options;
private static String defaultFileName =
"/tmp/.SEAM_temp.txt" /* NO18N */;
/**
* Constructor for PrintFrame.
*/
setLayout(new GridBagLayout());
addButtons();
setResizable(false);
command.setEditable(true);
fileName.setEditable(false);
}
private void addLabelsAndFields() {
}
private void addCheckboxGroup() {
options = new CheckboxGroup();
}
private void addButtons() {
// gbc.gridy = 2;
// gbc.insets = new Insets(0, 10, 0, 10);
// gbc.weighty = .1;
// add(new LineSeparator(), gbc);
// gbc.weighty = 1;
p.setLayout(new GridBagLayout());
gbc = new GridBagConstraints();
addWindowListener(new WindowCloseListener());
}
/**
* Called when the print frame has to be closed. IT may be closed
* as a result of the user choosing any one of "print", "cancel" or
* just the window close (which also cancels the printing).
* @param doIt true if the printing should be carried out, false
* if it is to be cancelled.
*/
if (doIt) {
try {
return;
else
} else {
return;
else
}
} catch (IOException e) {
// System.out.println(e); XXX
}
} // end of doIt
dispose();
}// end of close
/**
* Prints the string to a file and then send the file's contents
* to the printer. It then deletes the file.
* @param command the print comman to be used
*/
printThread.start();
}
/**
* Saves the string onto the file.
* @param fileName the file to which the string must be written
*/
FileWriter(fileName)));
}
// Listeners for the gui components:
// javac in current makefile will not compile if these are anonymous.
private class PrintSelectedListener implements ItemListener {
public void itemStateChanged(ItemEvent e) {
command.setEditable(true);
fileName.setEditable(false);
}
}
private class FileSelectedListener implements ItemListener {
public void itemStateChanged(ItemEvent e) {
command.setEditable(false);
fileName.setEditable(true);
}
}
private class StartPrintingListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
close(true);
}
}
private class CancelButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
close(false);
}
}
private class HelpButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
hd.setVisible(true);
}
}
private class FileMoreButtonListener implements
public void actionPerformed(ActionEvent e) {
// Turn off print "command" and enable output "file name"
command.setEditable(false);
fileName.setEditable(true);
getString("SEAM File Helper"),
// Use what's in the fileName field already to initialize the
// FileDialog
if (fileNameText != null) {
if (file.isDirectory())
else {
}
}
fd.setVisible(true);
}
}
/**
* This class prints out to a temporary file defaultFileName, send
* that to the printer, and then deletes the file after TIME_OUT
* milliseconds.
*/
private class PrintThread extends Thread {
}
public void run() {
try {
try {
} catch (InterruptedException e) {}
} catch (IOException e) {
// System.err.println(e); XXX
}
}
}
private class WindowCloseListener extends WindowAdapter {
public void windowClosing(WindowEvent e) {
close(false);
}
}
} // class PrintFrame
}