📄 abstractlistui.java
字号:
package com.cownew.PIS.ui.commonUI;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import com.cownew.PIS.ui.base.ExceptionHandler;
import com.cownew.PIS.ui.base.UIPanel;
import com.cownew.PIS.ui.utils.PISAbstractAction;
public abstract class AbstractListUI extends UIPanel
{
protected JMenuBar mainMenuBar;
protected JToolBar toolBar;
private JScrollPane scrollPaneTable;
private JTable tableMain;
protected ActionAddNew actionAddNew;
protected ActionView actionView;
protected ActionEdit actionEdit;
protected ActionDelete actionDelete;
protected ActionRefresh actionRefresh;
protected ActionFilter actionFilter;
protected ActionExportToExcel actionExportToExcel;
private JToolBar toolBarPaging;
private JLabel labelFirstPage;
private JLabel labelNextPage;
private JLabel labelPriorPage;
protected JLabel labelPageInfo;
public AbstractListUI() throws Exception
{
super();
}
protected void initialize()
{
super.initialize();
setLayout(new BorderLayout());
add(getScrollPaneTable(),BorderLayout.CENTER);
this.add(getToolBarPaging(), BorderLayout.SOUTH);
}
protected void initAction()
{
super.initAction();
actionAddNew = new ActionAddNew("新增");
actionView = new ActionView("查看");
actionEdit = new ActionEdit("编辑");
actionDelete = new ActionDelete("删除");
actionRefresh = new ActionRefresh("刷新");
actionFilter = new ActionFilter("过滤");
actionExportToExcel = new ActionExportToExcel("导出到excel");
}
public JToolBar getToolBar()
{
if (toolBar == null)
{
toolBar = new JToolBar();
toolBar.setFloatable(false);
initToolBar(toolBar);
}
return toolBar;
}
public JMenuBar getMainMenuBar()
{
if (mainMenuBar == null)
{
mainMenuBar = new JMenuBar();
initMainMenu(mainMenuBar);
}
return mainMenuBar;
}
protected void initMainMenu(JMenuBar menuBar)
{
JMenu menuFile = new JMenu("文件");
JMenuItem miAddNew = new JMenuItem();
menuFile.add(miAddNew);
miAddNew.setAction(actionAddNew);
JMenuItem miView = new JMenuItem();
menuFile.add(miView);
miView.setAction(actionView);
JMenuItem miEdit = new JMenuItem();
menuFile.add(miEdit);
miEdit.setAction(actionEdit);
JMenuItem miDelete = new JMenuItem();
menuFile.add(miDelete);
miDelete.setAction(actionDelete);
JMenuItem miRefresh = new JMenuItem();
menuFile.add(miRefresh);
miRefresh.setAction(actionRefresh);
JMenuItem miFilter = new JMenuItem();
menuFile.add(miFilter);
miFilter.setAction(actionFilter);
JMenuItem miExportToExcel = new JMenuItem();
menuFile.add(miExportToExcel);
miExportToExcel.setAction(actionExportToExcel);
menuBar.add(menuFile);
}
protected void initToolBar(JToolBar tBar)
{
JButton btnAddNew = new JButton(actionAddNew);
tBar.add(btnAddNew);
JButton btnView = new JButton(actionView);
tBar.add(btnView);
JButton btnEdit = new JButton(actionEdit);
tBar.add(btnEdit);
JButton btnDelete = new JButton(actionDelete);
tBar.add(btnDelete);
JButton btnRefresh = new JButton(actionRefresh);
tBar.add(btnRefresh);
JButton btnFilter = new JButton(actionFilter);
tBar.add(btnFilter);
}
private JScrollPane getScrollPaneTable()
{
if (scrollPaneTable == null)
{
scrollPaneTable = new JScrollPane();
scrollPaneTable.setPreferredSize(new Dimension(100,100));
scrollPaneTable.setViewportView(getTableMain());
scrollPaneTable.setVisible(true);
}
return scrollPaneTable;
}
protected JTable getTableMain()
{
if (tableMain == null)
{
tableMain = new JTable();
tableMain.setVisible(true);
}
return tableMain;
}
protected class ActionAddNew extends PISAbstractAction
{
public ActionAddNew(String name)
{
super(name);
}
public void onActionPerformed(ActionEvent e) throws Exception
{
actionAddNew_actionPerformed(e);
}
}
protected class ActionView extends PISAbstractAction
{
public ActionView(String name)
{
super(name);
}
public void onActionPerformed(ActionEvent e) throws Exception
{
actionView_actionPerformed(e);
}
}
protected class ActionEdit extends PISAbstractAction
{
public ActionEdit(String name)
{
super(name);
}
public void onActionPerformed(ActionEvent e) throws Exception
{
actionEdit_actionPerformed(e);
}
}
protected class ActionDelete extends PISAbstractAction
{
public ActionDelete(String name)
{
super(name);
}
public void onActionPerformed(ActionEvent e) throws Exception
{
actionDelete_actionPerformed(e);
}
}
protected class ActionRefresh extends PISAbstractAction
{
public ActionRefresh(String name)
{
super(name);
}
public void onActionPerformed(ActionEvent e) throws Exception
{
actionRefresh_actionPerformed(e);
}
}
protected class ActionFilter extends PISAbstractAction
{
public ActionFilter(String name, Icon icon)
{
super(name, icon);
}
public ActionFilter(String name)
{
super(name);
}
public void onActionPerformed(ActionEvent e) throws Exception
{
actionFilter_actionPerformed(e);
}
}
protected class ActionExportToExcel extends PISAbstractAction
{
public ActionExportToExcel(String name, Icon icon)
{
super(name, icon);
}
public ActionExportToExcel(String name)
{
super(name);
}
public void onActionPerformed(ActionEvent e) throws Exception
{
actionExportToExcel_actionPerformed(e);
}
}
protected void actionEdit_actionPerformed(ActionEvent e) throws Exception
{
}
protected void actionRefresh_actionPerformed(ActionEvent e) throws Exception
{
}
protected void actionAddNew_actionPerformed(ActionEvent e) throws Exception
{
}
protected void actionView_actionPerformed(ActionEvent e) throws Exception
{
}
protected void actionDelete_actionPerformed(ActionEvent e) throws Exception
{
}
protected void actionFilter_actionPerformed(ActionEvent e) throws Exception
{
}
protected void actionExportToExcel_actionPerformed(ActionEvent e) throws Exception
{
}
private JToolBar getToolBarPaging()
{
if (toolBarPaging == null)
{
labelFirstPage = new JLabel();
labelFirstPage.setText("第一页");
labelFirstPage.setForeground(Color.BLUE);
labelFirstPage.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
labelFirstPage.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e)
{
try
{
firstPage_actionPerformed();
} catch (Exception ex)
{
ExceptionHandler.handle(ex);
}
}
});
labelPriorPage = new JLabel();
labelPriorPage.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
labelPriorPage.setText("上一页");
labelPriorPage.setForeground(Color.BLUE);
labelPriorPage.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e)
{
try
{
priorPage_actionPerformed();
} catch (Exception ex)
{
ExceptionHandler.handle(ex);
}
}
});
labelNextPage = new JLabel();
labelNextPage.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
labelNextPage.setText("下一页");
labelNextPage.setDisplayedMnemonic(KeyEvent.VK_UNDEFINED);
labelNextPage.setForeground(Color.BLUE);
labelNextPage.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e)
{
try
{
nextPage_actionPerformed();
} catch (Exception ex)
{
ExceptionHandler.handle(ex);
}
}
});
labelPageInfo = new JLabel();
toolBarPaging = new JToolBar();
toolBarPaging.setFloatable(false);
toolBarPaging.add(labelFirstPage);
toolBarPaging.add(labelPriorPage);
toolBarPaging.add(labelNextPage);
toolBarPaging.add(labelPageInfo);
}
return toolBarPaging;
}
/**
* 下一页
*/
protected void nextPage_actionPerformed() throws Exception
{
}
/**
* 上一页
*/
protected void priorPage_actionPerformed() throws Exception
{
}
/**
* 首页
*/
protected void firstPage_actionPerformed() throws Exception
{
}
} // @jve:decl-index=0:visual-constraint="10,10"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -