📄 operatorresultmenubarhandler.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
*
* $Author$
* $Date$
* $Revision$
*
* This is the handler of the Menu bar of ALL operator results dialogs.
*/
package eti.bi.alphaminer.operation.result;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
//import eti.bi.alphaminer.core.handler.CaseHandler;
import eti.bi.alphaminer.core.handler.ICaseHandler;
import eti.bi.alphaminer.core.observer.ObserveMessage;
import eti.bi.alphaminer.core.observer.Observer;
import eti.bi.alphaminer.ui.IMessageDialog;
import eti.bi.alphaminer.ui.ISystemMessageHandler;
import eti.bi.exception.AppException;
import eti.bi.exception.SysException;
import eti.bi.common.Locale.Resource;
/**
* MenuBarHandler is responsible for creating and managing the menu bar of the
* KBBI-client Applciation.
*
* Modified to add the export "txt" file. Bug Fixed.
* By TWang on Jan 21, 2005
*/
public class OperatorResultMenuBarHandler
extends MouseAdapter
implements Observer, ActionListener, ItemListener {
// The opeartor result panel associating with this menu bar handler
private OperatorResult m_OperatorResult;
/* Tool bar handled by this handler */
private JMenuBar m_MenuBar;
/* Level 1 menu item for File
* [File]
* - Export
* - Text
* - Excel
* - PMML
* - JPG
* - CLose
* */
private JMenu m_MenuFile;
/* Menu item for export txt */
private JMenuItem m_MenuFileExportText;
// TWang. Jan 21, 2005.
/* Menu item for export excel */
private JMenuItem m_MenuFileExportExcel;
/* Menu item for export pmml */
private JMenuItem m_MenuExportPmml;
/* Menu item for export jpg image */
private JMenuItem m_MenuExportJpg;
private JMenuItem m_MenuAdvance;
private ICaseHandler m_CaseHandler;
private ISystemMessageHandler m_SystemMessageHandler;
private IMessageDialog m_MessageDialog;
/* Case id of the case instance that created this menu bar handler */
private String m_CaseID = "Can Not Get The CaseID";
/* Command message send out by item menu and catch by this menu bar handler */
private final String ACTION_EXPORT_TEXT = "export2text";
private final String ACTION_EXPORT_EXCEL = "export2excel";
private final String ACTION_EXPORT_PMML = "export2pmml";
private final String ACTION_EXPORT_JPG = "export2jpg";
private final String ACTION_CLOSE = "close";
private final String ACTION_ADVANCE = "advance";
/**
* Constructs a MenuBarHandler.
*
* Bug Description: m_OperatorResult.getCaseID() might return NULL, since
* the OperatorResult may not initiate the caseID before this function
* is called.
*
* Bug Fiexed: give the CaseID a default value, and call the function in the
* actionPerformed() function.
*
* By TWang, Jan 24, 2005.
*/
public OperatorResultMenuBarHandler(OperatorResult a_OperatorResult, ICaseHandler aCaseHandler) {
m_OperatorResult = a_OperatorResult;
m_CaseID = m_OperatorResult.getCaseID();
//m_CaseHandler = ICaseHandler.getInstance();
m_CaseHandler = aCaseHandler;
m_SystemMessageHandler = m_CaseHandler.getSystemMessageHandler(m_CaseID);
m_MessageDialog = m_CaseHandler.getMessageDialog();
// Bug .
// m_CaseID = m_OperatorResult.getCaseID();
// register to observe the action of the operator result panel
m_OperatorResult.registerInterest(this);
// Construct the menu bar
createMenuBar();
}
/**
* @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
* Catch the action message sent by the menu items
*/
public void actionPerformed(ActionEvent e) {
// Object source = e.getSource();
String action = e.getActionCommand();
// Get the CaseID.
m_CaseID = m_OperatorResult.getCaseID();
try
{
if (action.equals(ACTION_EXPORT_TEXT))
{
processActionExportText();
} else if (action.equals(ACTION_EXPORT_EXCEL))
{
processActionExportExcel();
} else if (action.equals(ACTION_CLOSE))
{
processActionClose();
} else if (action.equals(ACTION_EXPORT_PMML))
{
processActionExportPMML();
} else if (action.equals(ACTION_EXPORT_JPG))
{
processActionExportJPG();
} else if (action.equals(ACTION_ADVANCE))
{
JCheckBoxMenuItem menu = (JCheckBoxMenuItem)e.getSource();
processActionAdvance(menu.isSelected());
}
}catch(AppException appException)
{
m_MessageDialog.showWarning(appException.getMessage(),"File Export");
m_SystemMessageHandler.appendMessage(appException.getMessage());
}catch(SysException sysException)
{
m_MessageDialog.showError(sysException.getMessage(),"File Export");
m_SystemMessageHandler.appendMessage(sysException.getMessage());
}
}
/**
* @see eti.bi.alphaminer.core.observer.Observer#sendNotify(String)
*
* Invoked by the observed objects to send the notification message in string format.
*/
public void sendNotify(String a_Message) {
// No message would be received in String format
}
/**
* Creates the Menu Bar.
*/
private void createMenuBar() {
m_MenuBar = new JMenuBar();
createFileMenu();
}
public JMenuBar getMenuBar()
{
return m_MenuBar;
}
/**
* Creates File Menu.
*/
private void createFileMenu()
{
m_MenuFile = new JMenu(Resource.srcStr("m_MenuFile"));
m_MenuFile.setMnemonic('F');
JMenu menuFileExport;
menuFileExport = new JMenu(Resource.srcStr("menuFileExport"));
menuFileExport.setMnemonic(KeyEvent.VK_S);
m_MenuFileExportText = new JMenuItem("Text...");
m_MenuFileExportText.setActionCommand(ACTION_EXPORT_TEXT);
m_MenuFileExportText.addActionListener(this);
m_MenuFileExportExcel = new JMenuItem("Excel...");
m_MenuFileExportExcel.setActionCommand(ACTION_EXPORT_EXCEL);
m_MenuFileExportExcel.addActionListener(this);
m_MenuExportPmml = new JMenuItem("PMML...");
m_MenuExportPmml.setActionCommand(ACTION_EXPORT_PMML);
m_MenuExportPmml.addActionListener(this);
m_MenuExportJpg = new JMenuItem("JPG...");
m_MenuExportJpg.setActionCommand(ACTION_EXPORT_JPG);
m_MenuExportJpg.addActionListener(this);
/* menuExportExcel.setAccelerator(KeyStroke.getKeyStroke(
KeyEvent.VK_2, ActionEvent.ALT_MASK));*/
menuFileExport.add(m_MenuFileExportText);
menuFileExport.add(m_MenuFileExportExcel);
menuFileExport.add(m_MenuExportPmml);
menuFileExport.add(m_MenuExportJpg);
JMenuItem m_MenuClose = new JMenuItem(Resource.srcStr("m_MenuClose"));
m_MenuClose.setActionCommand(ACTION_CLOSE);
m_MenuClose.addActionListener(this);
/* m_MenuFileConnect.setAccelerator(
KeyStroke.getKeyStroke('C', KeyEvent.ALT_MASK, false));*/
m_MenuAdvance = new JCheckBoxMenuItem(Resource.srcStr("m_MenuAdvance"));
m_MenuAdvance.setEnabled(false); // default is disabled
m_MenuAdvance.setActionCommand(ACTION_ADVANCE);
m_MenuAdvance.addActionListener(this);
m_MenuFile.add(menuFileExport);
m_MenuFile.addSeparator();
m_MenuFile.add(m_MenuAdvance);
m_MenuFile.addSeparator();
m_MenuFile.add(m_MenuClose);
m_MenuBar.add(m_MenuFile);
resetMenu();
}
/* (non-Javadoc)
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
*/
public void itemStateChanged(ItemEvent arg0) {
// TODO Auto-generated method stub
}
/* Invoke the export() method of the operator result panel */
private void processActionExportJPG() throws SysException, AppException
{
m_OperatorResult.export();
}
/* Invoke the export() method of the operator result panel */
private void processActionExportText() throws SysException, AppException
{
m_OperatorResult.export();
}
/* Invoke the export() method of the operator result panel */
private void processActionExportExcel() throws SysException, AppException
{
m_OperatorResult.export();
}
/* Invoke the export() method of the operator result panel */
private void processActionExportPMML() throws SysException, AppException
{
m_OperatorResult.export();
}
/* Invoke the export() method of the operator result panel */
private void processActionClose()
{
m_OperatorResult.close();
}
private void processActionAdvance(boolean enableAdvanceResults) throws SysException, AppException
{
if (enableAdvanceResults)
{
m_OperatorResult.enableAdvanceResults();
}else
{
m_OperatorResult.disableAdvanceResults();
}
}
/* (non-Javadoc)
* @see eti.bi.alphaminer.core.observer.Observer#sendNotify(int)
* Invoked by the observed objects to send the notification message in int format.
*/
public void sendNotify(int a_Message) {
switch(a_Message)
{
case ObserveMessage.MESSAGE_CHANGE_VIEW:
// If the view of the result panel is slected, invoke processChangeView()
ResultView aView = m_OperatorResult.getSelectedView();
processChangeView(aView.getViewType());
break;
default:
break;
}
}
/* Initalie the menu
* It disable all menu items that have dependency on other controls
*
*/
private void resetMenu()
{
m_MenuFileExportText.setEnabled(false);
m_MenuFileExportExcel.setEnabled(false);
m_MenuExportPmml.setEnabled(false);
m_MenuExportJpg.setEnabled(false);
}
/* Called when the view of the operator result has changed
* It configure the menu items according to the changed view type
*/
private void processChangeView(int a_ViewType)
{
resetMenu();
switch(a_ViewType)
{
case ResultView.TYPE_DATA:
m_MenuFileExportExcel.setEnabled(true);
break;
case ResultView.TYPE_PMML:
m_MenuExportPmml.setEnabled(true);
break;
case ResultView.TYPE_GRAPH:
m_MenuExportJpg.setEnabled(true);
break;
case ResultView.TYPE_TABLE:
m_MenuFileExportExcel.setEnabled(true);
break;
case ResultView.TYPE_TEXT:
m_MenuFileExportText.setEnabled(true);
break;
default:
break;
}
}
/* (non-Javadoc)
* @see eti.bi.alphaminer.core.observer.Observer#sendNotify(int, java.lang.Object)
*/
public void sendNotify(int a_Message, Object a_Object) {
// TODO Auto-generated method stub
}
public void enableAdvanceMenu()
{
m_MenuAdvance.setEnabled(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -