⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 saveabxlogaction.java

📁 Java version of ABC/HR comparator v0.5. by schnofler. Runs on Sun JRE 1.5 or later
💻 JAVA
字号:
package abchr.gui;

import jlfgr.GraphicsRepository;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Locale;
import java.util.Date;

import guiutils.SimpleFileChooser;
import guiutils.SimpleFileFilter;
import abchr.DetailedABXTestFormatter;
import abchr.ABXTest;

class SaveABXLogAction extends AbstractAction implements ABXPanel.Listener {
	private static class Formatter extends DetailedABXTestFormatter {
		public Formatter(ABXTest test) {
			super(test);
			final String nl=System.getProperty("line.separator");
			this.setFormattingString("Sample A: $A_SAMPLE$"+nl+"Sample B: $B_SAMPLE$"+nl+nl+"$RESULT_LIST$");
			this.setTrialFormattingString("$RANGE_COND$    $TIME$ $PASSFAIL_S$ $CORRECT$/$TOTAL$ pval $PVAL_EXT$");
			this.setRangeFormatter(new DetailedABXTestFormatter.SimpleRangeFormatter() {
				public String format(int rangeBegin,int rangeEnd) {
					return "Playback Range: "+formatTime(rangeBegin)+" to "+formatTime(rangeEnd)+nl;
				}
			});
		}
	}

	private ABXPanel panel;

	public SaveABXLogAction(ABXPanel panel) {
		super("Save Log...",GraphicsRepository.getToolbarIcon("general/Properties16.gif"));
		this.panel=panel;
		panel.addListener(this);
		changed(panel);
	}

	public void actionPerformed(ActionEvent e) {
		File f=SimpleFileChooser.saveFile(panel,new SimpleFileFilter(".txt","Text files"));
		if(f==null){return;}
		BufferedOutputStream output=null;
		try {
			output=new BufferedOutputStream(new FileOutputStream(f));
			final String nl=System.getProperty("line.separator");
			DetailedABXTestFormatter formatter=new Formatter(panel.getTest());
			output.write(("ABX log"+nl
				+System.getProperty("abchr-java-versionstring")+nl
				+DateFormat.getDateTimeInstance(DateFormat.LONG,DateFormat.MEDIUM,Locale.US).format(new Date())+nl+nl).getBytes());
			output.write(formatter.format().getBytes());
			formatter.setFormattingString(nl+" ---------"+nl+"Total: $FINAL_RESULT$");
			formatter.setTrialFormattingString("$CORRECT$ out of $TOTAL$, p $PVAL_EXT$");
			output.write(formatter.format().getBytes());
		} catch(IOException e1) {
			JOptionPane.showMessageDialog(panel,"Could not save log file.","I/O error",JOptionPane.ERROR_MESSAGE);
		} finally {
			if(output!=null){
				try{output.close();}catch(IOException e1){}
			}
		}
	}

	public void changed(ABXPanel sender) {
		this.setEnabled(sender.getTest()!=null);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -