?? printergrouppanel.java
字號:
package jp.co.ntl.swing.ext.printer.printergroup;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.JApplet;
import javax.swing.JButton;
///import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import jp.co.ntl.ActionEventConstants;
import jp.co.ntl.Net;
import jp.co.ntl.NetworkException;
import jp.co.ntl.Page;
import jp.co.ntl.ServerException;
import jp.co.ntl.TimeOutException;
import jp.co.ntl.printergroup.PrinterGroupInfo;
import jp.co.ntl.swing.BasePanel;
import jp.co.ntl.swing.TableSorter;
///import jp.co.ntl.swing.ext.CSVFileFilter;
import jp.co.ntl.swing.ext.DialogManager;
import jp.co.ntl.swing.ext.MsgUtil;
public class PrinterGroupPanel extends BasePanel implements ActionListener, ListSelectionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private JTable tblPrinterGroup;
private PrinterGroupTableModel mdlPrinterGroup;
private ListSelectionModel mdlPrinterGroupSelect;
private JScrollPane scrPrinterGroup;
private JButton btnRegister;
private JButton btnModify;
private JButton btnDelete;
/// private JButton btnMultiRegister;
private JButton btnRefresh;
private JMenuItem menuModify;
private JMenuItem menuDelete;
private Vector vcPrinterGroupInfo;
private PrinterGroupInfoInvoker invoker;
private TableSorter sorter;
public PrinterGroupPanel(JFrame parent, Net net) {
super(parent, net);
}
public PrinterGroupPanel(JApplet appl, Net net) {
super(appl, net);
}
protected void buildComponents() {
Resource.load(loc);
Page.initialize(net);
invoker = PrinterGroupInfoInvoker.getInstance(net);
createPopupMenu();
vcPrinterGroupInfo = new Vector();
mdlPrinterGroup = new PrinterGroupTableModel(vcPrinterGroupInfo);
sorter = new TableSorter(mdlPrinterGroup);
tblPrinterGroup = new JTable(sorter);
sorter.setTableHeader(tblPrinterGroup.getTableHeader());
scrPrinterGroup = new JScrollPane(tblPrinterGroup);
add(scrPrinterGroup, BorderLayout.CENTER);
tblPrinterGroup.getTableHeader().setReorderingAllowed(false);
btnRegister = new JButton(Resource.getString(Resource.REGISTER));
btnModify = new JButton(Resource.getString(Resource.MODIFY));
btnDelete = new JButton(Resource.getString(Resource.DELETE));
/// btnMultiRegister = new JButton(Resource.getString(Resource.MULTI_REGISTER));
btnRefresh = new JButton(Resource.getString(Resource.REFRESH));
addButtonPanel(
new JButton[] {btnRegister, btnModify, btnDelete/*, btnMultiRegister*/, btnRefresh},
new String[] {
Resource.getString(Resource.TIP_REGISTER),
Resource.getString(Resource.TIP_MODIFY),
Resource.getString(Resource.TIP_DELETE),
/// Resource.getString(Resource.TIP_MULTI_REGISTER),
Resource.getString(Resource.TIP_REFRESH)
});
btnRegister.addActionListener(this);
btnModify.addActionListener(this);
btnDelete.addActionListener(this);
/// btnMultiRegister.addActionListener(this);
btnRefresh.addActionListener(this);
mdlPrinterGroupSelect = tblPrinterGroup.getSelectionModel();
mdlPrinterGroupSelect.addListSelectionListener(this);
mdlPrinterGroupSelect.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
setButtonState(false, 0);
tblPrinterGroup.setColumnSelectionAllowed(false);
tblPrinterGroup.addMouseListener(this);
}
private void createPopupMenu() {
popupMenu = new JPopupMenu();
menuModify = new JMenuItem(Resource.getString(Resource.MODIFY));
menuModify.addActionListener(this);
popupMenu.add(menuModify);
menuDelete = new JMenuItem(Resource.getString(Resource.DELETE));
menuDelete.addActionListener(this);
popupMenu.add(menuDelete);
}
public void beginPanel() throws NetworkException, ServerException, TimeOutException {
doRefresh();
}
private void setButtonState(boolean b, int selectRows) {
if (selectRows <= 1) {
btnModify.setEnabled(b);
} else {
btnModify.setEnabled(false);
}
btnDelete.setEnabled(b);
}
protected void setPopupMenuState() {
if (tblPrinterGroup.getSelectedRowCount() > 1) {
menuModify.setEnabled(false);
} else {
menuModify.setEnabled(true);
}
}
public boolean getPrinterGroupInfo() throws NetworkException, ServerException, TimeOutException {
Vector vcPrinterGroupInfo = new Vector();
vcPrinterGroupInfo = invoker.getPrinterGroupInfo();
mdlPrinterGroup.addInfos(vcPrinterGroupInfo);
return true;
}
protected boolean doRegister() throws NetworkException, ServerException, TimeOutException {
PrinterGroupInfo printerGroupInfo = new PrinterGroupInfo();
PrinterGroupInfoPanel p = new PrinterGroupInfoPanel(false, printerGroupInfo, vcPrinterGroupInfo);
if (DialogManager.showCustomDialog(
this, Resource.getString(Resource.PRINTERGROUPINFO_TITLE), p) == PrinterGroupInfoPanel.OK_BUTTON) {
int id = invoker.addPrinterGroup(printerGroupInfo);
printerGroupInfo.setPrinterGID(id);
mdlPrinterGroup.addInfo(printerGroupInfo);
sendActionEvent(ActionEventConstants.ACTCMD_REFRESH_PRINTER);
}
return true;
}
protected boolean doModify() throws NetworkException, ServerException, TimeOutException {
int selRow = sorter.modelIndex(tblPrinterGroup.getSelectedRow());
if (selRow >= 0) {
PrinterGroupInfo printerGroupInfo = (PrinterGroupInfo)mdlPrinterGroup.getSelectedInfo(selRow);
PrinterGroupInfoPanel p = new PrinterGroupInfoPanel(true, printerGroupInfo, vcPrinterGroupInfo);
if (DialogManager.showCustomDialog(
this, Resource.getString(Resource.PRINTERGROUPINFO_TITLE), p) == PrinterGroupInfoPanel.OK_BUTTON) {
invoker.setPrinterGroupInfo(printerGroupInfo);
mdlPrinterGroup.setInfo(selRow, printerGroupInfo);
sendActionEvent(ActionEventConstants.ACTCMD_REFRESH_PRINTER);
}
}
return true;
}
protected boolean doDelete() throws NetworkException, ServerException, TimeOutException {
int[] selViewRows = tblPrinterGroup.getSelectedRows();
Vector vcPgInfo = new Vector();
for (int i = 0; i < selViewRows.length; i++) {
int selRow = sorter.modelIndex(selViewRows[i]);
if (selRow >= 0) {
vcPgInfo.addElement(mdlPrinterGroup.getSelectedInfo(selRow));
}
}
if (invoker.isRelatedPrinterGroup(vcPgInfo)) {
DialogManager.showMessage(this, DialogManager.ERROR_DELETE_PRINTERGROUP_RELATED_PRINTER);
return false;
}
if (DialogManager.showConfirmMessage(
this,
DialogManager.CONFIRM_DELETE,
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
invoker.delPrinterGroup(vcPgInfo);
for (int i = selViewRows.length - 1; i >= 0; i--) {
int selRow = sorter.modelIndex(selViewRows[i]);
if (selRow >= 0) {
mdlPrinterGroup.deleteInfo(selRow);
}
}
sendActionEvent(ActionEventConstants.ACTCMD_REFRESH_PRINTER);
}
return true;
}
/*
private void doMultiRegister() throws NetworkException, ServerException, TimeOutException {
if (!isApplet()) {
CSVFileFilter filter = new CSVFileFilter();
JFileChooser fc = new JFileChooser();
fc.setFileFilter(filter);
int ret = fc.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
}
}
}*/
public int getInfosFromServer() {
int result = GET_INFO_RESULT_NORMAL;
mdlPrinterGroup.deleteAllInfos();
try {
getPrinterGroupInfo();
} catch (NetworkException e) {
result = GET_INFO_RESULT_ERROR;
sendActionEvent(MsgUtil.getMessage(MsgUtil.ERROR_NETWORK, null));
} catch (ServerException e) {
result = GET_INFO_RESULT_ERROR;
sendActionEvent(MsgUtil.getMessage(MsgUtil.ERROR_SERVER, null));
} catch (TimeOutException e) {
}
if (result == GET_INFO_RESULT_NORMAL) {
sendActionEvent(MsgUtil.getMessage(MsgUtil.MSG_IDLE, null));
}
return result;
}
public void actionPerformed(ActionEvent ae) {
Object obj = ae.getSource();
try {
if (obj == btnRegister) {
sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
doRegister();
} else if (obj == btnModify || obj == menuModify) {
sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
doModify();
} else if (obj == btnDelete || obj == menuDelete) {
sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
doDelete();
/* } else if (obj == btnMultiRegister) {
doMultiRegister();*/
} else if (obj == btnRefresh) {
sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
doRefresh();
}
} catch (NetworkException e) {
DialogManager.showMessage(this, DialogManager.ERROR_NETWORK);
} catch (ServerException e) {
DialogManager.showMessage(this, DialogManager.ERROR_SERVER);
} catch (TimeOutException e) {
}
}
public void valueChanged(ListSelectionEvent e) {
Object obj = e.getSource();
if (obj == mdlPrinterGroupSelect) {
sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
int[] rows = tblPrinterGroup.getSelectedRows();
if (rows == null || rows.length == 0) {
setButtonState(false, 0);
} else {
setButtonState(true, rows.length);
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -