?? accountpanel.java
字號(hào):
package jp.co.ntl.swing.ext.history.account;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Vector;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JFileChooser;
import javax.swing.JTable;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.filechooser.FileFilter;
import javax.swing.table.TableColumn;
import jp.co.ntl.Net;
import jp.co.ntl.Page;
import jp.co.ntl.NetworkException;
import jp.co.ntl.ServerException;
import jp.co.ntl.TimeOutException;
import jp.co.ntl.SpoolerException;
import jp.co.ntl.ActionEventConstants;
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 AccountPanel extends BasePanel implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
private JTable tblAccount;
private AccountTableModel mdlAccount;
private JScrollPane scrAccount;
private JButton btnDownload;
private JButton btnDelete;
private JButton btnRefresh;
private Vector vcAccountInfo;
private AccountInvoker invoker;
private TableSorter sorter;
public AccountPanel(JFrame parent, Net net) {
super(parent, net);
}
public AccountPanel(JApplet appl, Net net) {
super(appl, net);
}
protected void buildComponents() {
Resource.load(loc);
Page.initialize(net);
invoker = AccountInvoker.getInstance(net);
vcAccountInfo = new Vector();
mdlAccount = new AccountTableModel(vcAccountInfo, loc.getLanguage());
sorter = new TableSorter(mdlAccount);
tblAccount = new JTable(sorter);
sorter.setTableHeader(tblAccount.getTableHeader());
scrAccount = new JScrollPane(tblAccount);
tblAccount.getTableHeader().setReorderingAllowed(false);
tblAccount.setColumnSelectionAllowed(false);
tblAccount.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
TableColumn column;
column = tblAccount.getColumn(AccountTableModel.columnCOPIES);
column.setPreferredWidth(40);
add(scrAccount, BorderLayout.CENTER);
btnDownload = new JButton(Resource.getString(Resource.DOWNLOAD));
btnDelete = new JButton(Resource.getString(Resource.DELETE));
btnRefresh = new JButton(Resource.getString(Resource.REFRESH));
addButtonPanel(
new JButton[] {btnDownload, btnDelete, btnRefresh},
new String[] {
Resource.getString(Resource.TIP_DOWNLOAD),
Resource.getString(Resource.TIP_DELETE),
Resource.getString(Resource.TIP_REFRESH)
});
btnDownload.addActionListener(this);
btnDelete.addActionListener(this);
btnRefresh.addActionListener(this);
}
public void beginPanel() throws NetworkException, ServerException, TimeOutException {
doRefresh();
}
public boolean getAccountInfo() throws NetworkException, ServerException, TimeOutException {
Vector vcAccountInfo = new Vector();
try {
vcAccountInfo = invoker.getAccountList();
mdlAccount.addInfos(vcAccountInfo);
} catch (SpoolerException e) {
throw new NetworkException(e.getMessage());
}
return true;
}
private boolean doDownload() throws NetworkException, ServerException, TimeOutException {
if (!isApplet()) {
CSVFileFilter filter = new CSVFileFilter();
if (DialogManager.showSaveDialog(this, filter) == JFileChooser.APPROVE_OPTION) {
try {
JFileChooser fc = DialogManager.getFileDialogObject();
File selectedFile = fc.getSelectedFile();
File downloadFile = selectedFile;
FileFilter ff = fc.getFileFilter();
if (ff.getClass() == CSVFileFilter.class) {
if (!((CSVFileFilter)ff).accept(selectedFile)) {
downloadFile = new File(selectedFile.getPath() + "." +
((CSVFileFilter)ff).getExtensionString());
}
}
if (!invoker.downloadAccount(downloadFile)) {
DialogManager.showMessage(this, DialogManager.ERROR_FAILED_DOWNLOAD);
return false;
} else {
DialogManager.showMessage(this, DialogManager.DOWNLOAD_SUCCESS);
}
} catch (SpoolerException e) {
throw new NetworkException(e.getMessage());
}
}
} else {
}
return true;
}
protected boolean doRegister() throws NetworkException, ServerException, TimeOutException {
return true;
}
protected boolean doModify() throws NetworkException, ServerException, TimeOutException {
return true;
}
protected boolean doDelete() throws NetworkException, ServerException, TimeOutException {
if (DialogManager.showConfirmMessage(
this,
DialogManager.CONFIRM_DELETE,
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
/* int[] selViewRows = tblAccount.getSelectedRows();
int i;
Vector vcAccountInfo = new Vector();
for (i = 0; i < selViewRows.length; i++) {
int selRow = sorter.modelIndex(selViewRows[i]);
vcAccountInfo.addElement(mdlAccount.getSelectedInfo(selRow));
}*/
try {
if (!invoker.deleteAccounts()) {
DialogManager.showMessage(this, DialogManager.ERROR_NETWORK);
return false;
}
mdlAccount.deleteAllInfos();
} catch (SpoolerException e) {
throw new NetworkException(e.getMessage());
}
}
return true;
}
protected void setPopupMenuState() {
}
public void actionPerformed(ActionEvent ae) {
Object obj = ae.getSource();
try {
if (obj == btnDownload) {
sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
doDownload();
} else if (obj == btnDelete) {
sendActionEvent(ActionEventConstants.ACTCMD_RESET_SESSION_TIMER);
doDelete();
} 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 int getInfosFromServer() {
int result = GET_INFO_RESULT_NORMAL;
mdlAccount.deleteAllInfos();
try {
getAccountInfo();
} 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;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -