📄 pmmlview.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.
*/
/*
* Created on 2005/1/12
*
* $Author$
* $Date$
* $Revision$
*
* This class extends ResultView to work as a common pane to visualize and export PMML
*/
package eti.bi.alphaminer.operation.result.view;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import eti.bi.alphaminer.operation.result.OperatorResult;
import eti.bi.alphaminer.operation.result.ResultView;
import eti.bi.alphaminer.operation.result.export.PmmlExporter;
import eti.bi.common.Locale.Resource;
import eti.bi.exception.AppException;
import eti.bi.exception.SysException;
/**
* @author kelvinj
*
*/
public class PmmlView extends ResultView{
/**
*
*/
private static final long serialVersionUID = 4995039935856901446L;
// File path of the pmml file to be parsed
private String m_PmmlFilePath;
// The pmml in String format
private String m_PmmlString;
// Text area for showing the pmml text
private JTextArea m_TextArea;
// Scroll Pane to hold the text area
private JScrollPane m_ScrollPane;
public final static String TILTLE_EXPORT = Resource.srcStr("PMMLEXPORT");
public final static String VIEW_NAME = "PMML";
public PmmlView(String a_PmmlFilePath, OperatorResult a_OperatorResult)
{
super(VIEW_NAME, a_OperatorResult);
m_ViewType = TYPE_PMML;
m_PmmlFilePath = a_PmmlFilePath;
m_PmmlString = new String("No Pmml");
m_TextArea = new JTextArea();
m_TextArea.setFont(new Font("Dialog", Font.PLAIN, 11));
m_ScrollPane = new JScrollPane(m_TextArea);
this.setLayout(new BorderLayout());
this.add(m_ScrollPane,"Center");
}
/*
* Call to set the pmml file path
*/
public void setPmmlFilePath(String a_PmmlFilePath)
{
m_PmmlFilePath = a_PmmlFilePath;
}
/*
* This method would read the file in m_PmmlFilePath and write to the
* pmml string m_PmmlString
* Before calling this method, make sure the file path is set using setPmmlFilePath()
*
*/
public void preparePmml() throws SysException
{
if (m_PmmlFilePath == null)
{
throw new SysException("[PmmlView].[preparePmml].m_PmmlFilePath is null");
}
File pmmlFile = new File(m_PmmlFilePath);
if (!pmmlFile.exists())
{
throw new SysException("[PmmlView].[preparePmml]." + m_PmmlFilePath + " does not exists");
}
try
{
StringBuffer tempPmml = new StringBuffer();
FileReader fileReader = new FileReader(m_PmmlFilePath);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String line = bufferedReader.readLine();
while (line != null)
{
tempPmml.append(line);
// Have to append end line, otherwise the pmml string would be in single line
// when showing on the text area
tempPmml.append("\n");
line = bufferedReader.readLine();
}
m_PmmlString = tempPmml.toString();
m_TextArea.setCaretPosition(0);
}catch(Exception e)
{
throw new SysException("Fail in preparing PMML from file " + m_PmmlFilePath + ".");
}
}
/* display the pmml string to the text area */
public void showPmml()
{
if (m_PmmlString != null)
{
m_TextArea.setText(m_PmmlString);
m_TextArea.setEditable(false);
}
}
public void export() throws SysException, AppException
{
// Use user home directory
File directory = new File(System.getProperty("user.dir"));
// Create and initialize file chooser for pmml
JFileChooser chooser = new JFileChooser(directory);
chooser.setDialogTitle(TILTLE_EXPORT);
chooser.setFileFilter(PmmlExporter.FILTER);
chooser.setSelectedFile(PmmlExporter.DEFAULT_FILE);
// pop up the file chooser dialog and return the file value
int returnVal = chooser.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
File exportFile = chooser.getSelectedFile();
// Create the excel exporter with the excel file extension enforced to be .xls
//BIData aBIData = getOutputBIData();
if (exportFile.exists()) {
int option = JOptionPane
.showConfirmDialog(
(Component) this,
"The file \""
+ exportFile.getName()
+ "\""
+ " already exists. Do you want to replace the existing file?",//
"AlphaMiner", JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (option != JOptionPane.CANCEL_OPTION) {
if (option == JOptionPane.YES_OPTION) {
if (m_PmmlString!=null)
{
PmmlExporter aExporter = new PmmlExporter(m_PmmlString, exportFile, true);
aExporter.export();
}
}else{
returnVal = chooser.showSaveDialog(this);
}
}
}
else {
//<<tyleung 20/4/2005
if (m_PmmlString!=null)
{
PmmlExporter aExporter = new PmmlExporter(m_PmmlString, exportFile, true);
aExporter.export();
}
}
//tyleung 20/4/2005>>
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -