📄 formrun.java
字号:
package com.prcomps.cahitarf.gui;
import com.sohlman.easylayout.EasyLayout;
import com.sohlman.easylayout.Constraint;
import com.prcomps.cahitarf.Db2Arff;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JFileChooser;
import java.util.ResourceBundle;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.FlowLayout;
import java.io.FileNotFoundException;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.io.File;
import java.io.FileOutputStream;
/**
*/
public class FormRun
extends JPanel
implements IWizardPanel
{
ResourceBundle bundle = WizardFrame.getBundle();
JTextArea txtOut = new JTextArea();
public FormRun()
{
setName( WizardFrame.FORM_RUN );
createForm();
}
private void createForm()
{
setLayout( new EasyLayout( new int[] { 100 }, new int[] { 0, 100 }, 5, 5 ) );
JButton btnSample = new JButton( bundle.getString( "wizard.run.btnsample" ) );
JButton btnToScreen = new JButton( bundle.getString( "wizard.run.btnscreen" ) );
JButton btnToFile = new JButton( bundle.getString( "wizard.run.btnfile" ) );
btnSample.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
toScreen( 50 );
}
});
btnToScreen.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
toScreen( 0 );
}
});
btnToFile.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent e )
{
toFile();
}
});
JPanel buttonPanel = new JPanel( new FlowLayout() );
buttonPanel.add( btnSample );
buttonPanel.add( btnToScreen );
buttonPanel.add( btnToFile );
add( buttonPanel, new Constraint( 0, 0, Constraint.RIGHT, Constraint.CENTER, 5, 5 ) );
add( new JScrollPane( txtOut ), new Constraint( 0, 1 ) );
}
private void toScreen( int maxRows )
{
Db2Arff db2Arff = new Db2Arff();
db2Arff.setProperties( WizardFrame.properties );
db2Arff.setMaxRows( maxRows );
try
{
db2Arff.loadDrivers();
ByteArrayOutputStream bout = new ByteArrayOutputStream( 2 * 1024 * 1024 );
PrintStream out = new PrintStream( bout );
db2Arff.toArff( out );
txtOut.setText( bout.toString() );
}
catch ( FileNotFoundException e )
{
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
}
private void toFile()
{
JFileChooser fc = new JFileChooser( System.getProperty( "user.dir" ) );
int result = fc.showSaveDialog( this );
if ( result == JFileChooser.APPROVE_OPTION )
toFile( fc.getSelectedFile() );
}
private void toFile( File fout )
{
try
{
PrintStream out = new PrintStream( new FileOutputStream( fout ) );
Db2Arff db2Arff = new Db2Arff();
db2Arff.setProperties( WizardFrame.properties );
db2Arff.loadDrivers();
db2Arff.toArff( out );
}
catch ( FileNotFoundException e )
{
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
}
public String getNext()
throws NotReadyException
{
throw new NotReadyException( bundle.getString("wizard.btnNext.no") );
}
public String getPrev()
throws NotReadyException
{
return WizardFrame.FORM_ATTRS;
}
public void checkStatus()
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -