?? basepanel.java
字號(hào):
package jp.co.ntl.swing;
import java.awt.Container;
import java.awt.AWTEventMulticaster;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JPanel;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.BorderFactory;
import javax.swing.JPopupMenu;
import jp.co.ntl.Net;
import jp.co.ntl.NetworkException;
import jp.co.ntl.ServerException;
import jp.co.ntl.TimeOutException;
import jp.co.ntl.Util;
public abstract class BasePanel extends JPanel implements MouseListener {
/**
*
*/
private static final long serialVersionUID = 1L;
///chin
public static final String ACTCMD_BACK = "back";
public static final String ACTCMD_REFRESH_SPOOLER = "Refresh.Spooler";
public static final String ACTCMD_REFRESH_USER = "Refresh.User";
public static final String ACTCMD_REFRESH_GROUP = "Refresh.Group";
public static final String ACTCMD_REFRESH_SPKEY = "Refresh.SPKey";
public static final String ACTCMD_REFRESH_LIMITPRINT = "Refresh.LimitPrint";
public static final String ACTCMD_REFRESH_TERMINAL = "Refresh.Terminal";
public static final String ACTCMD_REFRESH_PRINTER = "Refresh.Printer";
public static final String ACTCMD_REFRESH_PRINTER_GROUP = "Refresh.PrinterGroup";
public static final String ACTCMD_REFRESH_PRINTER_PAPER = "Refresh.PrinterPaper";
public static final String ACTCMD_REFRESH_PLACE = "Refresh.Place";
public static final String ACTCMD_REFRESH_ACCOUNT = "Refresh.Account";
public static final String ACTCMD_REFRESH_USER_HISTORY = "Refresh.UserHistory";
public static final String ACTCMD_REFRESH_SCREEN = "Refresh.Screen";
///chin
public static final int ADMIN_PANEL = 0;
public static final int USER_PANEL = 1;
public static final int GET_INFO_RESULT_NORMAL = 0;
public static final int GET_INFO_RESULT_WAIT = 1;
public static final int GET_INFO_RESULT_ERROR = -1;
protected Locale loc;
protected Net net;
protected JApplet app = null;
protected JFrame parent = null;
protected JPanel btnPanel;
protected Container cont = null;
protected int kind = ADMIN_PANEL;
protected JPopupMenu popupMenu = null;
transient ActionListener actionListener;
protected String actionCommand = "";
public BasePanel() {
this.loc = Util.getCurrentLocale();
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
}
public BasePanel(JFrame parent, Net net) {
this(parent, net, ADMIN_PANEL);
}
public BasePanel(Container parent, Net net) {
this((JApplet)null, net);
this.cont = parent;
}
public BasePanel(JApplet app, Net net) {
this(app, net, ADMIN_PANEL);
}
public BasePanel(JFrame parent, Net net, int kind) {
this.parent = parent;
commonConstractor(net, kind);
buildComponents();
}
public BasePanel(JApplet app, Net net, int kind) {
this.app = app;
commonConstractor(net, kind);
// 2007.11.14 add start
buildComponents();
// 2007.11.14 add end
}
public void commonConstractor(Net net, int kind) {
this.net = net;
this.loc = Util.getCurrentLocale();
this.kind = kind;
setLayout(new BorderLayout());
setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
}
protected abstract void buildComponents();
public abstract void beginPanel() throws NetworkException, ServerException, TimeOutException;
protected abstract boolean doRegister() throws NetworkException, ServerException, TimeOutException;
protected abstract boolean doModify() throws NetworkException, ServerException, TimeOutException;
protected abstract boolean doDelete() throws NetworkException, ServerException, TimeOutException;
/// protected abstract boolean doMultiRegister() throws NetworkException, ServerException, TimeOutException;
public abstract int getInfosFromServer();
protected abstract void setPopupMenuState();
public boolean doRefresh() {
Timer timer = new Timer(true);
GetInfosTimerTask timerTask = new GetInfosTimerTask();
timer.schedule(timerTask, 0, 100);
return true;
}
public void addButtonPanel(JButton[] buttons, String[] tipStrings) {
btnPanel = new JPanel(new FlowLayout());
for (int i = 0; i < buttons.length; i++) {
if (tipStrings[i] != null) {
buttons[i].setToolTipText(tipStrings[i]);
}
btnPanel.add(buttons[i]);
}
add(btnPanel, BorderLayout.SOUTH);
}
protected boolean isApplet() {
if (app != null) {
return true;
}
return false;
}
public void setActionCommand(String command) {
actionCommand = command;
}
public String getActionCommand() {
return actionCommand;
}
public synchronized void addActionListener(ActionListener al) {
actionListener = AWTEventMulticaster.add(actionListener, al);
}
public synchronized void removeActionListener(ActionListener al) {
actionListener = AWTEventMulticaster.remove(actionListener, al);
}
public void sendActionEvent(String command) {
if (actionListener != null) {
actionCommand = command;
actionListener.actionPerformed(
new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionCommand));
}
}
private class GetInfosTimerTask extends TimerTask {
public void run() {
int result = GET_INFO_RESULT_WAIT;
result = getInfosFromServer();
if (result != GET_INFO_RESULT_WAIT) {
cancel();
}
}
}
public void mouseClicked(MouseEvent me) {
}
public void mouseEntered(MouseEvent me) {
}
public void mouseExited(MouseEvent me) {
}
public void mousePressed(MouseEvent me) {
showPopup(me);
}
public void mouseReleased(MouseEvent me) {
showPopup(me);
}
private void showPopup(MouseEvent me) {
if (me.isPopupTrigger()) {
if (popupMenu != null) {
setPopupMenuState();
popupMenu.show(me.getComponent(), me.getX(), me.getY());
}
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -