⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printingoptionpanel.java

📁 具有不同语法高亮的编辑器实例
💻 JAVA
字号:
/*
 * 02/27/2004
 *
 * PrintingOptionPanel.java - Options panel for options dialog
 *                            giving printing options.
 * Copyright (C) 2004 Robert Futrell
 * email@address.com
 * www.website.com
 *
 * This file is a part of RText.
 *
 * RText is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * RText 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 for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package org.fife.rtext;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ResourceBundle;
import javax.swing.*;

import org.fife.ui.FontDialog;
import org.fife.ui.OptionsDialogPanel;
import org.fife.ui.RButton;
import org.fife.ui.UIUtilities;


/**
 * Options panel for options dialog giving the printing options available.
 *
 * @author Robert Futrell
 * @version 1.0
 */
class PrintingOptionPanel extends OptionsDialogPanel implements ActionListener {

	private Font printFont;			// The "other font" if they don't select "Use current font."
	private JButton fontBrowseButton;	// The button used to set the print font.

	private JCheckBox headerCheckBox;	// If checked, the user wants a header on printed documents.
	private JCheckBox footerCheckBox;	// If checked, the user wants a footer on printed documents.
	private boolean useHeader;		// Internal variable used to remember what the user clicked.
	private boolean useFooter;		// Internal variable used to remember what the user clicked.

	private static final String FONT_PROPERTY	= "PrintingOptionPanel.font";


/*****************************************************************************/


	/**
	 * Constructor.
	 *
	 * @param rtext The owner of the options dialog in which this panel
	 *              appears.
	 * @param msg The resource bundle to use.
	 */
	public PrintingOptionPanel(final RText rtext, final ResourceBundle msg) {

		super(msg.getString("OptPrName"));
		setLayout(new BorderLayout());
		setBorder(UIUtilities.getEmpty5Border());

		JPanel printFontPanel = new JPanel();
		printFontPanel.setBorder(new OptionPanelBorder(msg.getString("OptPrFTitle")));
		printFontPanel.setLayout(new BoxLayout(printFontPanel, BoxLayout.X_AXIS));
		printFontPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
		
		JPanel temp = new JPanel();
		temp.setLayout(new BoxLayout(temp, BoxLayout.Y_AXIS));
		JLabel fontLabel = new JLabel(msg.getString("OptPrFont"));
		printFont = new Font("monospaced", Font.PLAIN, 9);
		fontBrowseButton = new RButton(displayFontNicely(printFont));
		Dimension dim = new Dimension(200, 40);
		fontBrowseButton.setMinimumSize(dim);
		fontBrowseButton.setPreferredSize(dim);
		fontBrowseButton.setMaximumSize(dim);
		fontBrowseButton.setFont(printFont);
		fontBrowseButton.setActionCommand("BrowseFonts");
		fontBrowseButton.addActionListener(this);
		temp.add(fontBrowseButton);
		JPanel otherFontPanel = new JPanel();
		otherFontPanel.setLayout(new BoxLayout(otherFontPanel, BoxLayout.X_AXIS));
		otherFontPanel.add(fontLabel);
		otherFontPanel.add(fontBrowseButton);
		otherFontPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
		temp.add(otherFontPanel);

		printFontPanel.add(temp);
		printFontPanel.add(Box.createHorizontalGlue());

		temp = new JPanel();
		temp.setLayout(new BoxLayout(temp, BoxLayout.Y_AXIS));
		headerCheckBox = new JCheckBox(msg.getString("OptPrPH"));
		footerCheckBox = new JCheckBox(msg.getString("OptPrPF"));
		headerCheckBox.setEnabled(false);
		footerCheckBox.setEnabled(false);
		temp.add(headerCheckBox);
		temp.add(footerCheckBox);
		JPanel printHeaderFooterPanel = new JPanel();
		printHeaderFooterPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
		printHeaderFooterPanel.setBorder(new OptionPanelBorder(msg.getString("OptPrHFL")));
		printHeaderFooterPanel.setLayout(new BoxLayout(printHeaderFooterPanel, BoxLayout.X_AXIS));
		printHeaderFooterPanel.add(temp);
		printHeaderFooterPanel.add(Box.createHorizontalGlue());

		temp = new JPanel();
		temp.setLayout(new BoxLayout(temp, BoxLayout.Y_AXIS));
		temp.add(printFontPanel);
		temp.add(printHeaderFooterPanel);

		add(temp, BorderLayout.NORTH);
		
	}


/*****************************************************************************/


	/**
	 * Listens for actions in this panel.
	 */
	public void actionPerformed(ActionEvent e) {

		String actionCommand = e.getActionCommand();

		// If the user wants to pick a new font to print in...
		if (actionCommand.equals("BrowseFonts")) {
			FontDialog printFontDialog = new FontDialog(null,
										"Printing Font", printFont,
										null, false, false);
			printFontDialog.setVisible(true);
			Font newPrintFont = printFontDialog.getSelectedFont();
			if (newPrintFont != null) {
				hasUnsavedChanges = true;
				Font old = printFont;
				printFont = newPrintFont;
				fontBrowseButton.setText(displayFontNicely(printFont));
				fontBrowseButton.setFont(printFont);
				firePropertyChange(FONT_PROPERTY, old, printFont);
			}
		}

	}


/*****************************************************************************/


	/**
	 * Returns a <code>String</code> that displays a <code>Font</code>'s name
	 * and properties nicely.
	 *
	 * @param font The font to get a nice display string for.
	 * @return The display string for <code>font</code>.
	 */
	private String displayFontNicely(Font font) {
		String returnVal = font.getFontName() + " " + font.getSize();
		switch (font.getStyle()) {
			case Font.PLAIN:
				returnVal += " PLAIN";
				break;
			case Font.BOLD:
				returnVal += " BOLD";
				break;
			case Font.ITALIC:
				returnVal += " ITALIC";
				break;
			case Font.BOLD + Font.ITALIC:
				returnVal += " BOLD,ITALIC";
				break;
		}
		return returnVal;
	}


/*****************************************************************************/


	/**
	 * Checks whether or not all input the user specified on this panel is
	 * valid.  This should be overridden to check, for example, whether
	 * text fields have valid values, etc.  This method will be called
	 * whenever the user clicks "OK" or "Apply" on the options dialog to
	 * ensure all input is valid.  If it isn't, the component with invalid
	 * data will be given focus and the user will be prompted to fix it.<br>
	 * 
	 *
	 * @return <code>null</code> if the panel has all valid inputs, or an
	 *         <code>OptionsPanelCheckResult</code> if an input was invalid.
	 *         This component is the one that had the error and will be
	 *         given focus, and the string is an error message that will be
	 *         displayed.
	 */
	public OptionsPanelCheckResult ensureValidInputs() {
		// They can't input invalid stuff on this options panel.
		return null;
	}


/*****************************************************************************/


	/**
	 * Returns the font the user selected for printing.
	 *
	 * @return A font to use for printing.
	 * @see #setPrintFont
	 */
	public Font getPrintFont() {
		return printFont;
	}


/*****************************************************************************/


	/**
	 * Returns the <code>JComponent</code> at the "top" of this Options
	 * panel.  This is the component that will receive focus if the user
	 * switches to this Options panel in the Options dialog.  As an added
	 * bonus, if this component is a <code>JTextComponent</code>, its
	 * text is selected for easy changing.
	 */
	public JComponent getTopJComponent() {
		return fontBrowseButton;
	}


/*****************************************************************************/


	/**
	 * Sets the font currently being displayed as the font used for printing.
	 *
	 * @param printFont The font to display as the current font used for
	 *                  printing.  If <code>null</code>, then a default is
	 *                  used.
	 * @see #getPrintFont
	 */
	public void setPrintFont(Font printFont) {
		if (printFont==null) {
			this.printFont = new Font("monospaced", Font.PLAIN, 9);
		}
		else {
			this.printFont = printFont;
		}
		fontBrowseButton.setFont(this.printFont);
		fontBrowseButton.setText(displayFontNicely(this.printFont));
	}


/*****************************************************************************/

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -