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

📄 paperinfopanel.java

📁 打印管理程序,测试完全通过.windows开发环境.
💻 JAVA
字号:
package jp.co.ntl.swing.ext.printer.paper;

import java.awt.Dimension;
import java.util.Vector;

import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JPanel;
///import javax.swing.JSpinner;
import javax.swing.SpringLayout;
///import javax.swing.SpinnerNumberModel;
import javax.swing.BoxLayout;
import javax.swing.Box;

import jp.co.ntl.ext.CheckUtil;
import jp.co.ntl.swing.NumberField;
import jp.co.ntl.swing.SpringUtilities;
import jp.co.ntl.swing.ext.AbstractDetailInfoPanel;
import jp.co.ntl.swing.ext.DialogManager;
import jp.co.ntl.paper.PaperInfo;
import jp.co.ntl.printer.PrinterInfo2;
import jp.co.ntl.preference.PreferenceInfo;

public class PaperInfoPanel extends AbstractDetailInfoPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JLabel			lblPaperName;
	private JTextField		txtPaperName;
	private JLabel			lblPrice;
	private NumberField	numPrice;
///	private JSpinner		spinPrice;
	private JLabel			lblPriceUnit;
	private JLabel			lblPrinter;
	private JComboBox		cmbPrinter;
	
	private PaperInfo		paperInfo;
	private Vector			vcPaperInfo;
	private Vector			vcPrinterInfo;
	private String			prePrinter;

	public PaperInfoPanel(boolean modify, PaperInfo paperInfo, Vector vcPaperInfo, Vector vcPrinterInfo) {
		super(modify, new Object[] { paperInfo, vcPaperInfo, vcPrinterInfo });
	}
	
	protected void setParams(Object[] params) {
		paperInfo = (PaperInfo)params[0];
		vcPaperInfo = (Vector)params[1];
		vcPrinterInfo = (Vector)params[2];
	}
	
	protected void buildComponents() {
		setLayout(new SpringLayout());
		
		Dimension	size = new Dimension(250, 24);
		Dimension	sizeNumField = new Dimension(120, 24);
		
		lblPaperName = new JLabel(Resource.getString(Resource.PAPER_INFO_PAPER));
		add(lblPaperName);
		
		txtPaperName = new JTextField();
		txtPaperName.setPreferredSize(size);
		add(txtPaperName);
		
		lblPrice = new JLabel(Resource.getString(Resource.PAPER_INFO_PRICE));
		add(lblPrice);
		
		JPanel	panelPrice = new JPanel();
		panelPrice.setLayout(new BoxLayout(panelPrice, BoxLayout.X_AXIS));
		
		numPrice = new NumberField(10, NumberField.UINT);
		numPrice.setPreferredSize(sizeNumField);
		panelPrice.add(numPrice);
/*		spinPrice = new JSpinner(new SpinnerNumberModel(PaperInfo.MIN_PRICE, PaperInfo.MIN_PRICE, PaperInfo.MAX_PRICE, 1));
		spinPrice.setPreferredSize(sizeNumField);
		panelPrice.add(spinPrice);*/
		
		panelPrice.add(Box.createRigidArea(new Dimension(10, 0)));
		
		lblPriceUnit = new JLabel(Resource.getString(Resource.PRICE_UNIT));
		panelPrice.add(lblPriceUnit);
		
		add(panelPrice);
		
		lblPrinter = new JLabel(Resource.getString(Resource.PAPER_INFO_PRINTER));
		add(lblPrinter);

		String[]	txt = new String[vcPrinterInfo.size()];
		for (int i = 0; i < vcPrinterInfo.size(); i++) {
			txt[i] = ((PrinterInfo2)vcPrinterInfo.elementAt(i)).getName();
		}
		cmbPrinter = new JComboBox(txt);
		add(cmbPrinter);
		
		SpringUtilities.makeCompactGrid(this, getComponentCount() / 2, 2, 10, 10, 10, 10);
	}
	
	protected void setValuesFromComponent() {
		paperInfo.setPaperName(txtPaperName.getText());
		paperInfo.setPrice(numPrice.getIntValue());
///		paperInfo.setPrice(((Integer)spinPrice.getValue()).intValue());
		for (int i = 0; i < vcPrinterInfo.size(); i++) {
			PrinterInfo2	printerInfo = (PrinterInfo2)vcPrinterInfo.elementAt(i);
			if (printerInfo.getName().equals(cmbPrinter.getSelectedItem())) {
				paperInfo.setPrinterInfo(printerInfo);
				break;
			}
		}
	}

	protected void setValuesToComponent() {
		preValue = paperInfo.getPaperName();
		prePrinter = paperInfo.getPrinterInfo().getName();
		txtPaperName.setText(paperInfo.getPaperName());
		numPrice.setValue(paperInfo.getPrice());
///		spinPrice.setValue(new Integer(paperInfo.getPrice()));
		cmbPrinter.setSelectedItem(paperInfo.getPrinterInfo().getName());

		// 梡巻僒僀僘柤偑"Unknown"偺偲偒丄僌儗乕傾僂僩偡傞
		if (txtPaperName.getText().equals("Unknown")) {
			txtPaperName.setEnabled(false);
		} else {
			txtPaperName.setEnabled(true);
		}
	}

	protected boolean checkValues() {
		CheckUtil	chk = new CheckUtil(Resource.getString(Resource.PAPER_INFO_PAPER), this);
		String		paperName = txtPaperName.getText();
		String		printer = (String)cmbPrinter.getSelectedItem();
		
		// 梡巻柤偑枹擖椡偺偲偒
		if (chk.isNull(paperName)) {
			return false;
		}
		
		// 梡巻柤偺挿偝僠僃僢僋
		if (chk.isLengthOver(paperName, PaperInfo.MAX_PAPER_NAME_LEN)) {
			return false;
		}
		
		// 梡巻柤偵巊梡偱偒側偄暥帤偑巊傢傟偰偄傞偲偒
		if (chk.isValidateChar(paperName)) {
			return false;
		}
		
		// 梡巻柤偑偡偱偵巊傢傟偰偄傞偲偒
		if (!modify || (modify && !preValue.equals(paperName))) {
			for (int i = 0; i < vcPaperInfo.size(); i++) {
				PaperInfo	paperInfo = (PaperInfo)vcPaperInfo.elementAt(i);
				if (paperInfo.getPrinterInfo().getName().equals(printer)) {
					if (chk.isAlreadyRegitered(paperName, paperInfo.getPaperName())) {
						return false;
					}
				}
			}
		} else if (modify && preValue.equals(paperName) && !prePrinter.equals(printer)) {
			for (int i = 0; i < vcPaperInfo.size(); i++) {
				PaperInfo	paperInfo = (PaperInfo)vcPaperInfo.elementAt(i);
				if (paperInfo.getPrinterInfo().getName().equals(printer)) {
					String[]	params = new String[] {
						Resource.getString(Resource.PAPER_INFO_PAPER),
					};
					DialogManager.showMessage(this, DialogManager.ERROR_ALREADY_REGISTERED, params);
					return false;
				}
			}
		}
		
		// 扨壙偑枹擖椡偺偲偒
		chk = new CheckUtil(Resource.getString(Resource.PAPER_INFO_PRICE), this);
		String	price = numPrice.getText();
		if (chk.isNull(price)) {
			return false;
		}
		
		// 扨壙傪敾掕
		int	priceVal = numPrice.getIntValue();
///		int	priceVal = ((Integer)spinPrice.getValue()).intValue();
		if (chk.isRangeOver(priceVal, PaperInfo.MIN_PRICE, PaperInfo.MAX_PRICE)) {
			return false;
		}

		return true;
	}

	public JButton[] getButtons() {
		if (clientKind == PreferenceInfo.CLIENT_MAC) {
			return new JButton[] {
					new JButton(Resource.getString(Resource.PRINTERINFO_CANCEL)),
					new JButton(Resource.getString(Resource.PRINTERINFO_OK))
			};
		} else {
			return new JButton[] {
					new JButton(Resource.getString(Resource.PRINTERINFO_OK)),
					new JButton(Resource.getString(Resource.PRINTERINFO_CANCEL))
			};
		}
	}
}

⌨️ 快捷键说明

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