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

📄 limitprintpanel.java

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

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.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
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.Util;
import jp.co.ntl.ServerException;
import jp.co.ntl.TimeOutException;
import jp.co.ntl.swing.BasePanel;
import jp.co.ntl.swing.TableSorter;
import jp.co.ntl.swing.ext.DialogManager;
import jp.co.ntl.swing.ext.MsgUtil;
import jp.co.ntl.limitprint.LimitPrintInfo;

public class LimitPrintPanel extends BasePanel implements ActionListener, ListSelectionListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JTable					tblLimitPrint;
	private LimitPrintTableModel	mdlLimitPrint;
	private ListSelectionModel		mdlLimitPrintSelect;
	private JScrollPane			scrLimitPrint;
	private TableSorter			sorter;
	private JButton				btnModify;
	private JButton				btnRefresh;
	
	private JMenuItem				menuModify;
	
	private Vector					vcLpInfo;
	private LimitPrintInfoInvoker	invoker;
	
	public LimitPrintPanel(JFrame parent, Net net) {
		super(parent, net);
	}
	
	public LimitPrintPanel(JApplet appl, Net net) {
		super(appl, net);
	}
	
	protected void buildComponents() {
		Resource.load(loc);
		
	    Page.initialize(net);
	    invoker = LimitPrintInfoInvoker.getInstance(net);
	    
	    createPopupMenu();
	    
	    vcLpInfo = new Vector();
	    mdlLimitPrint = new LimitPrintTableModel(vcLpInfo);
	    sorter = new TableSorter(mdlLimitPrint);
	    tblLimitPrint = new JTable(sorter);
	    sorter.setTableHeader(tblLimitPrint.getTableHeader());
	    scrLimitPrint = new JScrollPane(tblLimitPrint);
	    add(scrLimitPrint, BorderLayout.CENTER);
	    tblLimitPrint.getTableHeader().setReorderingAllowed(false);
	    
	    btnModify = new JButton(Resource.getString(Resource.MODIFY));
	    btnRefresh = new JButton(Resource.getString(Resource.REFRESH));
	    addButtonPanel(new JButton[] { btnModify, btnRefresh },
	    		new String[] {
	    			Resource.getString(Resource.TIP_MODIFY),
	    			Resource.getString(Resource.TIP_REFRESH),
	    		});
	    
	    btnModify.addActionListener(this);
	    btnRefresh.addActionListener(this);
	    
	    mdlLimitPrintSelect = tblLimitPrint.getSelectionModel();
	    mdlLimitPrintSelect.addListSelectionListener(this);
	    mdlLimitPrintSelect.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
	    
	    setButtonState(false, null);
	    tblLimitPrint.setColumnSelectionAllowed(false);
	    tblLimitPrint.addMouseListener(this);
	}
	
	private void createPopupMenu() {
		popupMenu = new JPopupMenu();
		menuModify = new JMenuItem(Resource.getString(Resource.MODIFY));
		menuModify.addActionListener(this);
		popupMenu.add(menuModify);
	}
	
	public void beginPanel() throws NetworkException, ServerException, TimeOutException {
		doRefresh();
	}
	
	private void setButtonState(boolean b, int[] selViewRows) {
		if (selViewRows != null && selViewRows.length <= 1) {
			btnModify.setEnabled(b);
		} else {
			btnModify.setEnabled(false);
		}
	}
	
	protected void setPopupMenuState() {
		int[]	selViewRows = tblLimitPrint.getSelectedRows();
		
		if (selViewRows.length > 1) {
			menuModify.setEnabled(false);
		} else {
			menuModify.setEnabled(true);
		}
	}
	
	private boolean getLimitPrintInfo() throws NetworkException, ServerException, TimeOutException {
		Vector	vcLpInfo = null;
		
		vcLpInfo = invoker.getLimitPrintInfo();
		mdlLimitPrint.addInfos(vcLpInfo);
		
		return true;
	}

	protected boolean doRegister() throws NetworkException, ServerException, TimeOutException {
		return true;
	}
	
	protected boolean doDelete() throws NetworkException, ServerException, TimeOutException {
		return true;
	}

	protected boolean doModify() throws NetworkException, ServerException, TimeOutException {
		int		selRow = sorter.modelIndex(tblLimitPrint.getSelectedRow());
		
		if (selRow >= 0) {
			LimitPrintInfo	lpInfo = (LimitPrintInfo)mdlLimitPrint.getSelectedInfo(selRow);
			
			LimitPrintInfoPanel	lpPanel = new LimitPrintInfoPanel(true, lpInfo);
			
			if (DialogManager.showCustomDialog(
					this, 
					Resource.getString(Resource.LIMITPRINTINFO_TITLE),
					lpPanel) == LimitPrintInfoPanel.OK_BUTTON) {
				invoker.setLimitPrintInfo(lpInfo);
				mdlLimitPrint.setInfo(selRow, lpInfo);
				sendActionEvent(ActionEventConstants.ACTCMD_REFRESH_USER);
				sendActionEvent(ActionEventConstants.ACTCMD_REFRESH_GROUP);
			}
		}
		
		return true;
	}

	public int getInfosFromServer() {
		Util.debugPrint("UserPanel.getInfosFromServer");
		int		result = GET_INFO_RESULT_NORMAL;
		
		mdlLimitPrint.deleteAllInfos();
		
		try {
			getLimitPrintInfo();
		} 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 == btnModify || obj == menuModify) {
				sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
				doModify();
			} 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 == mdlLimitPrintSelect) {
			sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
			int[]	rows = tblLimitPrint.getSelectedRows();
			if (rows == null || rows.length == 0) {
				setButtonState(false, null);
			} else {
				setButtonState(true, rows);
			}
		}
	}
}

⌨️ 快捷键说明

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