?? printerinfopanel.java
字號:
package jp.co.ntl.swing.ext.printer.printer;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.SpringLayout;
import jp.co.ntl.ext.CheckUtil;
import jp.co.ntl.place.PlaceInfo;
import jp.co.ntl.printer.PrinterInfo2;
import jp.co.ntl.printergroup.PrinterGroupInfo;
import jp.co.ntl.group.GroupInfo;
import jp.co.ntl.preference.PreferenceInfo;
import jp.co.ntl.swing.SpringUtilities;
import jp.co.ntl.swing.NumberField;
import jp.co.ntl.swing.ext.GroupPanel;
import jp.co.ntl.swing.ext.AbstractDetailInfoPanel;
import jp.co.ntl.swing.ext.DialogManager;
public class PrinterInfoPanel extends AbstractDetailInfoPanel implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private JLabel lblPrinter;
private JComboBox cmbPrinter;
private JLabel lblPlace;
private JComboBox cmbPlace;
private JLabel lblDevice;
private JTextField txtDevice;
private JLabel lblOutput;
private JComboBox cmbOutput;
private GroupPanel groupSrv;
private JLabel lblSrvHost;
private JTextField txtSrvHost;
private JLabel lblSrvPort;
private NumberField txtSrvPort;
private JLabel lblMethod;
private JComboBox cmbMethod;
private JLabel lblColor;
private JComboBox cmbColor;
private JLabel lblPrinterGroup;
private JComboBox cmbPrinterGroup;
private JLabel lblGroup;
private JComboBox cmbGroup;
private PrinterInfo2 prnInfo;
private Vector vcPrinterInfo;
private Vector vcPrinterGroupInfo;
private Vector vcGroupInfo;
private Vector vcPlaceInfo;
private Vector vcInstalledPrinter;
public PrinterInfoPanel(boolean modify, PrinterInfo2 prnInfo, Vector vcPrinterInfo, Vector vcPrinterGroupInfo, Vector vcGroupInfo, Vector vcPlaceInfo, Vector vcInstalledPrinter) {
super(modify, new Object[] { prnInfo, vcPrinterInfo, vcPrinterGroupInfo, vcGroupInfo, vcPlaceInfo, vcInstalledPrinter });
}
protected void setParams(Object[] params) {
this.prnInfo = (PrinterInfo2)params[0];
this.vcPrinterInfo = (Vector)params[1];
this.vcPrinterGroupInfo = (Vector)params[2];
this.vcGroupInfo = (Vector)params[3];
this.vcPlaceInfo = (Vector)params[4];
this.vcInstalledPrinter = (Vector)params[5];
}
protected void buildComponents() {
setLayout(new SpringLayout());
Dimension size = new Dimension(250, 24);
lblPrinter = new JLabel(Resource.getString(Resource.PRINTERINFO_PRINTER));
add(lblPrinter);
String[] txt = (String[])vcInstalledPrinter.toArray(new String[0]);
cmbPrinter = new JComboBox(txt);
add(cmbPrinter);
lblPlace = new JLabel(Resource.getString(Resource.PRINTERINFO_PLACE));
add(lblPlace);
txt = new String[vcPlaceInfo.size()];
for (int i = 0; i < vcPlaceInfo.size(); i++) {
PlaceInfo placeInfo = (PlaceInfo)vcPlaceInfo.elementAt(i);
txt[i] = placeInfo.getPlace();
}
cmbPlace = new JComboBox(txt);
add(cmbPlace);
lblDevice = new JLabel(Resource.getString(Resource.PRINTERINFO_DEVICE));
add(lblDevice);
txtDevice = new JTextField();
txtDevice.setPreferredSize(size);
add(txtDevice);
lblOutput = new JLabel(Resource.getString(Resource.PRINTERINFO_OUTPUT));
add(lblOutput);
lblOutput.setEnabled(false); // 枹懳墳偺偨傔
txt = new String[] {
Resource.getString(Resource.OUTPUT_STANDARD),
Resource.getString(Resource.OUTPUT_LPR),
Resource.getString(Resource.OUTPUT_FTP),
};
cmbOutput = new JComboBox(txt);
add(cmbOutput);
cmbOutput.setEnabled(false); // 枹懳墳偺偨傔
JLabel lblDummy = new JLabel(" ");
add(lblDummy);
groupSrv = new GroupPanel(Resource.getString(Resource.PRINTERINFO_GROUP_SRV));
groupSrv.setLayout(new SpringLayout());
lblSrvHost = new JLabel(Resource.getString(Resource.PRINTERINFO_SRVHOST));
groupSrv.add(lblSrvHost);
txtSrvHost = new JTextField();
txtSrvHost.setPreferredSize(new Dimension(75, 24));
groupSrv.add(txtSrvHost);
lblSrvPort = new JLabel(Resource.getString(Resource.PRINTERINFO_SRVPORT));
groupSrv.add(lblSrvPort);
txtSrvPort = new NumberField(5, NumberField.UINT);
txtSrvPort.setPreferredSize(new Dimension(75, 24));
groupSrv.add(txtSrvPort);
SpringUtilities.makeCompactGrid(groupSrv, groupSrv.getComponentCount() / 2, 2, 20, 20, 20, 20);
add(groupSrv);
lblMethod = new JLabel(Resource.getString(Resource.PRINTERINFO_METHOD));
add(lblMethod);
lblMethod.setEnabled(false); // 枹懳墳偺偨傔
txt = new String[] {
Resource.getString(Resource.METHOD_ONDEMAND),
Resource.getString(Resource.METHOD_DIRECT)
};
cmbMethod = new JComboBox(txt);
add(cmbMethod);
cmbMethod.setEnabled(false); // 枹懳墳偺偨傔
lblColor = new JLabel(Resource.getString(Resource.PRINTERINFO_COLOR));
add(lblColor);
txt = new String[] {
Resource.getString(Resource.COLOR_MONO),
Resource.getString(Resource.COLOR_COLOR),
/// Resource.getString(Resource.COLOR_FULLCOLOR)
};
cmbColor = new JComboBox(txt);
add(cmbColor);
lblPrinterGroup = new JLabel(Resource.getString(Resource.PRINTERINFO_PRINTERGROUP));
add(lblPrinterGroup);
txt = new String[vcPrinterGroupInfo.size()];
for (int i = 0; i < vcPrinterGroupInfo.size(); i++) {
txt[i] = ((PrinterGroupInfo)vcPrinterGroupInfo.elementAt(i)).getPrinterGName();
}
cmbPrinterGroup = new JComboBox(txt);
add(cmbPrinterGroup);
lblGroup = new JLabel(Resource.getString(Resource.PRINTERINFO_GROUP));
add(lblGroup);
txt = new String[vcGroupInfo.size()];
for (int i = 0; i < vcGroupInfo.size(); i++) {
txt[i] = ((GroupInfo)vcGroupInfo.elementAt(i)).getName();
}
cmbGroup = new JComboBox(txt);
add(cmbGroup);
SpringUtilities.makeCompactGrid(this, getComponentCount() / 2, 2, 10, 10, 10, 10);
setItemState();
cmbOutput.addActionListener(this);
}
protected void setValuesToComponent() {
for (int i = 0; i < vcInstalledPrinter.size(); i++) {
if (prnInfo.getName().equals((String)vcInstalledPrinter.elementAt(i))) {
cmbPrinter.setSelectedIndex(i);
break;
}
}
cmbPlace.setSelectedItem(prnInfo.getPlaceInfo().getPlace());
txtDevice.setText(prnInfo.getDeviceName());
cmbOutput.setSelectedIndex(prnInfo.getOutputKind());
txtSrvHost.setText(prnInfo.getSrvHost());
txtSrvPort.setText(Integer.toString(prnInfo.getSrvPort()));
cmbMethod.setSelectedIndex(prnInfo.getMethod());
cmbColor.setSelectedIndex(prnInfo.getColorModel());
for (int i = 0; i < vcPrinterGroupInfo.size(); i++) {
PrinterGroupInfo pg = (PrinterGroupInfo)vcPrinterGroupInfo.elementAt(i);
if (pg.getPrinterGName().equals(prnInfo.getPrinterGInfo().getPrinterGName())) {
cmbPrinterGroup.setSelectedIndex(i);
break;
}
}
for (int i = 0; i < vcGroupInfo.size(); i++) {
GroupInfo g = (GroupInfo)vcGroupInfo.elementAt(i);
if (g.getName().equals(prnInfo.getGroupInfo().getName())) {
cmbGroup.setSelectedIndex(i);
break;
}
}
setItemState();
}
protected void setValuesFromComponent() {
prnInfo.setName((String)cmbPrinter.getSelectedItem());
String place = (String)cmbPlace.getSelectedItem();
for (int i = 0; i < vcPlaceInfo.size(); i++) {
PlaceInfo placeInfo = (PlaceInfo)vcPlaceInfo.elementAt(i);
if (place.equals(placeInfo.getPlace())) {
prnInfo.setPlaceInfo(placeInfo);
break;
}
}
prnInfo.setDeviceName(txtDevice.getText());
prnInfo.setOutputKind(cmbOutput.getSelectedIndex());
prnInfo.setSrvHost(txtSrvHost.getText());
prnInfo.setSrvPort(Integer.parseInt(txtSrvPort.getText()));
prnInfo.setMethod(cmbMethod.getSelectedIndex());
prnInfo.setColorModel(cmbColor.getSelectedIndex());
for (int i = 0; i < vcPrinterGroupInfo.size(); i++) {
PrinterGroupInfo pgInfo = (PrinterGroupInfo)vcPrinterGroupInfo.elementAt(i);
if (pgInfo.getPrinterGName().equals(cmbPrinterGroup.getSelectedItem())) {
prnInfo.setPrinterGInfo(pgInfo);
break;
}
}
for (int i = 0; i < vcGroupInfo.size(); i++) {
GroupInfo grInfo = (GroupInfo)vcGroupInfo.elementAt(i);
if (grInfo.getName().equals(cmbGroup.getSelectedItem())) {
prnInfo.setGroupInfo(grInfo);
break;
}
}
}
protected void setItemState() {
boolean b = false;
if (cmbOutput.getSelectedIndex() != PrinterInfo2.OUTPUT_KIND_OS) {
b = true;
}
groupSrv.setEnabled(b);
lblSrvHost.setEnabled(b);
txtSrvHost.setEnabled(b);
lblSrvPort.setEnabled(b);
txtSrvPort.setEnabled(b);
}
protected boolean checkValues() {
CheckUtil chk;
// 僾儕儞僞柤僠僃僢僋
for (int i = 0; i < vcPrinterInfo.size(); i++) {
PrinterInfo2 printerInfo = (PrinterInfo2)vcPrinterInfo.elementAt(i);
if (printerInfo.getName().equals(prnInfo.getName())) {
continue;
}
if (printerInfo.getName().equals((String)cmbPrinter.getSelectedItem())) {
String[] params = new String[] {
Resource.getString(Resource.PRINTERINFO_PRINTER)
};
DialogManager.showMessage(this, DialogManager.ERROR_ALREADY_REGISTERED, params);
return false;
}
}
// 僨僶僀僗柤偺挿偝僠僃僢僋
chk = new CheckUtil(Resource.getString(Resource.PRINTERINFO_DEVICE), this);
if (chk.isLengthOver(txtDevice.getText(), PrinterInfo2.MAX_DEVICE_NAME_LEN)) {
return false;
}
// 僨僶僀僗柤偵巇條偱偒側偄暥帤偑擖椡偝傟偰偄傞偲偒
if (chk.isValidateChar(txtDevice.getText())) {
return false;
}
// LPR/FTP僾儕儞僞儂僗僩柤僠僃僢僋
if (cmbOutput.getSelectedIndex() != PrinterInfo2.OUTPUT_KIND_OS) {
chk = new CheckUtil(Resource.getString(Resource.PRINTERINFO_SRVHOST), this);
String srvHost = txtSrvHost.getText();
// LPR/FTP僾儕儞僞儂僗僩柤偑枹擖椡偺偲偒
if (chk.isNull(srvHost)) {
return false;
}
// LPR/FTP僾儕儞僞儂僗僩柤偺挿偝僠僃僢僋
if (chk.isLengthOver(srvHost, PrinterInfo2.MAX_SRVHOST_LEN)) {
return false;
}
if (srvHost.indexOf(".") >= 0) {
// IP傾僪儗僗偺応崌
if (chk.isValidIPAddress(srvHost)) {
return false;
}
} else {
// 儂僗僩柤偺応崌
if (chk.isValidateChar(srvHost)) {
return false;
}
}
// LPR/FTP僾儕儞僞億乕僩斣崋偑枹擖椡偺偲偒
chk = new CheckUtil(Resource.getString(Resource.PRINTERINFO_SRVPORT), this);
String srvPort = txtSrvPort.getText();
if (chk.isNull(srvPort)) {
return false;
}
// LPR/FTP僾儕儞僞億乕僩斣崋偑斖埻奜偺偲偒
if (chk.isRangeOver(Integer.parseInt(srvPort), PrinterInfo2.MIN_SRVPORT, PrinterInfo2.MAX_SRVPORT)) {
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))
};
}
}
public void actionPerformed(ActionEvent ae) {
Object obj = ae.getSource();
if (obj == cmbOutput) {
setItemState();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -