?? ecgapplet.java
字號:
/************************************************************************/
/* */
/* ecgApplet.java */
/* */
/* Copyright (C) 2003 Mauricio Villarroel */
/* (mauricio.vllarroel@estudiantes.ucb.edu.bo) */
/* */
/* ecgApplet.java and all its components are free software; you can */
/* redistribute them 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 file 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. */
/* */
/************************************************************************/
/* */
/* This file was created for the ECGSYN Application. */
/* */
/* ECGSYN: A program for generating a realistic synthetic */
/* Electrocardiogram Signals. */
/* Copyright (c) 2003 by Patrick McSharry & Gari Clifford. */
/* All rights reserved. */
/* */
/* See IEEE Transactions On Biomedical Engineering, */
/* 50(3), 289-294, March 2003. */
/* Contact: */
/* P. McSharry (patrick@mcsharry.net) */
/* G. Clifford (gari@mit.edu) */
/* */
/************************************************************************/
/* */
/* Further updates to this software will be published on: */
/* http://www.physionet.org/ */
/* */
/************************************************************************/
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.text.*;
import java.util.Vector;
import java.io.File;
import java.io.IOException;
import java.awt.event.*;
import java.lang.Math.*;
import java.util.Timer;
import java.util.TimerTask;
/*
* This class formats a number in decimal notation or in
* scientific notation.
*/
class FormatNumber{
final static DecimalFormat dec1 = new DecimalFormat("0.0");
final static DecimalFormat dec2 = new DecimalFormat("0.00");
final static DecimalFormat sci1 = new DecimalFormat("0.0E0");
final static DecimalFormat sci2 = new DecimalFormat("0.00E0");
/*
* Formats the 'number' parameter and returns it as a String.
* precision = number of decimal places in the output.
*/
public static String toString( double number,
double upLimit,
double loLimit,
int precision)
{
// If number less than decimalLimit, or equal to zero, use decimal style
if( number == 0.0 ||
(Math.abs(number) <= upLimit && Math.abs(number) > loLimit) )
{
switch (precision){
case 1 : return dec1.format(number);
case 2 : return dec2.format(number);
default: return dec1.format(number);
}
} else{
// Create the format for Scientific Notation with E
switch (precision){
case 1 : return sci1.format(number);
case 2 : return sci2.format(number);
default: return sci1.format(number);
}
}
}
}
/*
*
* Public main class
*/
public class ecgApplet extends javax.swing.JApplet implements AdjustmentListener{
/**************************************
* Colors for the Plotting Components *
**************************************/
protected Color ecgPlotColor = Color.BLUE;
protected Color frameLineColor = Color.BLACK;
protected Color frameInsideLineColor = Color.LIGHT_GRAY;
protected Color frameFillColor = Color.WHITE;
protected Color axesNumColor = Color.GRAY;
protected Color titleColor = Color.BLACK;
protected Color bgColor = Color.WHITE;
/*********************************************
* These constants used in drawText() method
* for placement of the text within a given
* rectangular area.
*********************************************/
final int CENTER = 0;
final int LEFT = 1;
final int RIGHT = 2;
/*******************
* Frame Dimensions.
*******************/
final int posFrameX =0;
final int posFrameY =1;
final int frameHeight =290;
final int frameAmplitude = frameHeight/2;
//Coordinates Origin
final int posOriginY = posFrameY + (frameHeight/2);
//X coordinates
final int horzScaleY = posFrameY + frameHeight;
final int horzScaleWidth = 100;
final int horzScaleHeight = 20;
final int fScaleNumSize = 9;
/****************************************************
* Limit below which scale values use decimal format,
* above which they use scientific format.
****************************************************/
double upLimit = 100.0;
double loLimit = 0.01;
/******************************
* Ploting variables
******************************/
boolean readyToPlot;
int plotScrollBarValue;
double plotZoom = 0.008;
double plotZoomInc = 2;
/* Flag Variable, show if data has been generated. */
private boolean ecgGenerated = false;
/****************************************************************
* GLOBAL ECG PARAMETERS:
****************************************************************/
private int N; /* Number of heart beats */
private double hrstd; /* Heart rate std */
private double hrmean; /* Heart rate mean */
private double lfhfratio; /* LF/HF ratio */
private int sfecg; /* ECG sampling frequency */
private int sf; /* Internal sampling frequency */
private double amplitude; /* Amplitude for the plot area */
private int seed; /* Seed */
private double Anoise; /* Amplitude of additive uniform noise*/
private int period;
/* Define frequency parameters for rr process
* flo and fhi correspond to the Mayer waves and respiratory rate respectively
*/
private double flo; /* Low frequency */
private double fhi; /* High frequency */
private double flostd; /* Low frequency std */
private double fhistd; /* High frequency std */
/* Order of extrema: [P Q R S T] */
private double[] theta = new double[6]; /* ti not in radians*/
private double[] a = new double[6];
private double[] b = new double[6];
/*******************************
* Variable for the Data table
*******************************/
private String[] peakStr = {"", "P", "Q", "R", "S", "T"};
/******************************************
* Variables to Animate ECG
******************************************/
//Animating in process?
private boolean ecgAnimateFlg =false;
Timer ecgAnimateTimer;
private long ecgAnimateInterval;
/* Total plotting Data Table Row */
private int ecgAnimateNumRows;
/* Current plotting Data Table Row */
private int ecgAnimateCurRow;
/* Plot Area Panel width */
private int ecgAnimatePanelWidth;
/* Starting X axis value to plot*/
private int ecgAnimateInitialZero;
/* For plotting */
Point ecgAnimateLastPoint = new java.awt.Point(0, 0);
/** Initializes the applet ecgApplet */
public void init() {
initComponents();
initWindow();
}
private void initWindow(){
/*********************
*Init the main Window
*Set maximize
*********************/
try{
ecgWindow.setMaximum(true);
} catch(java.beans.PropertyVetoException e){
txtStatus.append("Exception Error : " + e + "\n");
}
/*********************
*Init the data Table
*********************/
tableValuesModel = new DefaultTableModel( new Object [][] {},
new String [] {"Time", "Voltage", "Peak"}){
Class[] types = new Class [] {
java.lang.String.class, java.lang.String.class, java.lang.String.class
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
};
tableValues.setModel(tableValuesModel);
/* Init the ecgFrame */
ecgFrame = new ecgPanel();
ecgFrame.setBackground(new java.awt.Color(255, 255, 255));
ecgPlotArea.setViewportView(ecgFrame);
/* Set the ScrollBar */
plotScrollBar.addAdjustmentListener(this);
/* Set the size of the Dialogs */
paramDialog.setBounds(80, 80, 570,500);
alert.setBounds(80, 80, 540,200);
helpDialog.setBounds(80, 80, 600,500);
/*************************
* Reset all Application
* to a init state.
*************************/
resetECG();
}
private void initComponents() {//GEN-BEGIN:initComponents
paramDialog = new javax.swing.JDialog();
paramDesktopPane = new javax.swing.JDesktopPane();
closeParamDialogButton = new javax.swing.JButton();
resetParamDialogButton = new javax.swing.JButton();
saveParamDialogButton = new javax.swing.JButton();
paramTabbedPane = new javax.swing.JTabbedPane();
generalInterfacePanel = new javax.swing.JPanel();
txtSf = new javax.swing.JTextField();
lblSf = new javax.swing.JLabel();
lblN = new javax.swing.JLabel();
txtN = new javax.swing.JTextField();
lblHrmean = new javax.swing.JLabel();
txtHrmean = new javax.swing.JTextField();
lblHrstd = new javax.swing.JLabel();
txtHrstd = new javax.swing.JTextField();
lblAmplitude = new javax.swing.JLabel();
txtAmplitude = new javax.swing.JTextField();
lblGeneralTitle = new javax.swing.JLabel();
lblAnoise = new javax.swing.JLabel();
txtAnoise = new javax.swing.JTextField();
lblSfecg = new javax.swing.JLabel();
txtSfecg = new javax.swing.JTextField();
lblSeed = new javax.swing.JLabel();
txtSeed = new javax.swing.JTextField();
spectralCharacteristicsPanel = new javax.swing.JPanel();
lblSpectralTitle = new javax.swing.JLabel();
lblLfhfratio = new javax.swing.JLabel();
txtLfhfratio = new javax.swing.JTextField();
lblFlo = new javax.swing.JLabel();
txtFlo = new javax.swing.JTextField();
lblFhi = new javax.swing.JLabel();
txtFhi = new javax.swing.JTextField();
lblFlostd = new javax.swing.JLabel();
lblFhistd = new javax.swing.JLabel();
txtFhistd = new javax.swing.JTextField();
txtFlostd = new javax.swing.JTextField();
extremaPanel = new javax.swing.JPanel();
lblMorphologyTitle = new javax.swing.JLabel();
tiScrollPane = new javax.swing.JScrollPane();
tiTable = new javax.swing.JTable();
aiScrollPane = new javax.swing.JScrollPane();
aiTable = new javax.swing.JTable();
biScrollPane = new javax.swing.JScrollPane();
biTable = new javax.swing.JTable();
ExtremaLabelScrollPane = new javax.swing.JScrollPane();
ExtremaLabelTable = new javax.swing.JTable();
paramHelpButton = new javax.swing.JButton();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -