📄 ecgplotwindow.java
字号:
private void resetButtons(){ animateStopButton.setEnabled(false); animateStartButton.setEnabled(false); exportButton.setEnabled(false); clearButton.setEnabled(false); zoomInButton.setEnabled(false); zoomOutButton.setEnabled(false); } /* Enable the buttons after generating the ecg Data. */ private void enableButtons(){ animateStartButton.setEnabled(true); exportButton.setEnabled(true); clearButton.setEnabled(true); zoomInButton.setEnabled(true); zoomOutButton.setEnabled(true); } private void resetPlotArea(){ lblMaxAmplitude.setText("1.4"); lblMinAmplitude.setText("-1.4"); readyToPlot = false; plotScrollBarValue = 0; } /* * Set the appropiate state of the controls for start the ECG Animation */ private void startECGAnimationSetControls(){ animateStopButton.setEnabled(true); //exportButton.setEnabled(true); clearButton.setEnabled(false); generateButton.setEnabled(false); zoomInButton.setEnabled(false); zoomOutButton.setEnabled(false); animateStartButton.setEnabled(false); } /* * Set the appropiate state of the controls for stop the ECG Animation */ private void stopECGAnimationSetControls(){ animateStartButton.setEnabled(true); clearButton.setEnabled(true); generateButton.setEnabled(true); zoomInButton.setEnabled(true); zoomOutButton.setEnabled(true); animateStopButton.setEnabled(false); } private void fillDataTable(){ // Delete the DataTable for(int i=0;i<calcOb.getEcgResultNumRows();i++){ Vector nuevoRow = new Vector(3); nuevoRow.addElement(new String(Double.toString(calcOb.getEcgResultTime(i)))); nuevoRow.addElement(new String(Double.toString(calcOb.getEcgResultVoltage(i)))); nuevoRow.addElement(new String(Integer.toString(calcOb.getEcgResultPeak(i)))); tableValuesModel.addRow(nuevoRow); } } /** * Draw a string in the center of a given box. * Reduce the font size if necessary to fit. Can * fix the type size to a value passed as an argument. * The position of the string within the box passed * as LEFT, CENTER or RIGHT constant value. * Don't draw the strings if they do not fit. */ private int drawText( Graphics g, String msg, int xBox, int yBox, int boxWidth, int boxHeight, int fixedTypeSizeValue, int position){ boolean fixedTypeSize = false; int typeSize = 24; // Fixed to a particular type size. if(fixedTypeSizeValue > 0) { fixedTypeSize = true; typeSize = fixedTypeSizeValue; } int typeSizeMin = 8; int x=xBox,y=yBox; do { // Create the font and pass it to the Graphics context g.setFont(new Font("Monospaced",Font.PLAIN,typeSize)); // Get measures needed to center the message FontMetrics fm = g.getFontMetrics(); // How many pixels wide is the string int msgWidth = fm.stringWidth(msg); // How tall is the text? int msgHeight = fm.getHeight(); // See if the text will fit in the allotted // vertical limits if( msgHeight < boxHeight && msgWidth < boxWidth) { y = yBox + boxHeight/2 +(msgHeight/2); if( position == CENTER) x = xBox + boxWidth/2 - (msgWidth/2); else if(position == RIGHT) x = xBox + boxWidth - msgWidth; else x = xBox; break; } // If fixedTypeSize and wouldn't fit, don't draw. if( fixedTypeSize) return -1; // Try smaller type typeSize -= 2; } while (typeSize >= typeSizeMin); // Don't display the numbers if they did not fit if( typeSize < typeSizeMin) return -1; // Otherwise, draw and return positive signal. g.drawString(msg,x,y);// ecgFrame.revalidate();// ecgFrame.repaint(); return typeSize; } /* * This class is the AdjustmentListener for the * scroll bar. So the events come here when the * scroll bar is moved. */ public void adjustmentValueChanged(AdjustmentEvent evt){ plotScrollBarValue = plotScrollBar.getValue(); ecgFrame.repaint(); } class ecgPanel extends javax.swing.JPanel{ public void paintComponent(Graphics g){ // First call the paintComponent of the // superclass, in this case JPanel. super.paintComponent(g); /* Draw the plot frame. */ g.setColor(frameLineColor); g.drawLine(0, posFrameY, ecgFrame.getBounds().width, posFrameY); g.drawLine(0, posOriginY, this.getBounds().width, posOriginY); g.drawLine(0, horzScaleY, this.getBounds().width, horzScaleY); if(readyToPlot){ //JOptionPane.showMessageDialog(EcgPlotWindow.this, "Entro en la funcion paint"); int rows = tableValuesModel.getRowCount(); int x, y, i; int plotLimit; int initialZero; int curSecond, lastSecond; String strValue; /* * Set the first point to the current Table row */ initialZero = (int)(Double.valueOf(tableValues.getValueAt(plotScrollBarValue, 0).toString()).doubleValue() / plotZoom); lastSecond = (int)(Double.valueOf(tableValues.getValueAt(plotScrollBarValue, 0).toString()).doubleValue()); x = 0; y = posOriginY - (int)(Double.valueOf(tableValues.getValueAt(plotScrollBarValue, 1).toString()).doubleValue() * frameAmplitude / paramOb.getAmplitude()); Point lastPoint = new java.awt.Point(x, y); i= plotScrollBarValue; while((x <= this.getBounds().width)&& (i <=rows)){ //JOptionPane.showMessageDialog(EcgPlotWindow.this, "Entro al while de paint"); curSecond = (int)(Double.valueOf(tableValues.getValueAt(i, 0).toString()).doubleValue()); if(curSecond > lastSecond){ lastSecond = curSecond; // Convert the x value to a string strValue = EcgFormatNumber.toString(Double.valueOf(tableValues.getValueAt(i, 0).toString()).doubleValue(), upLimit, loLimit, 2); /* * Plot the X axes number values (the Time). */ g.setColor(axesNumColor); drawText(g, strValue, x, horzScaleY, horzScaleWidth, horzScaleHeight, fScaleNumSize,LEFT); g.setColor(frameInsideLineColor); g.drawLine(x, posFrameY, x, horzScaleY + 5); } /* * Plot a line between the las point and the current point. * This to create a illusion to connect the two points. */ g.setColor(ecgPlotColor); g.drawLine(lastPoint.x, lastPoint.y, x, y); /* * Set the current point to be the last, and * get a new point to plot in the following loop. */ lastPoint.setLocation(x, y); i+= 1; x = (int)(Double.valueOf(tableValues.getValueAt(i, 0).toString()).doubleValue() / plotZoom) - initialZero; y = posOriginY - (int)(Double.valueOf(tableValues.getValueAt(i, 1).toString()).doubleValue() * frameAmplitude / paramOb.getAmplitude()); } } } } /* * Class to plot the ECG animation */ class ECGAnimate extends TimerTask{ int x = 0; int y = posOriginY - (int)(Double.valueOf(tableValues.getValueAt(ecgAnimateCurRow, 1).toString()).doubleValue() * frameAmplitude / paramOb.getAmplitude()); int curSecond = 0; int lastSecond = 0; Graphics ga = ecgFrame.getGraphics(); public void run(){ curSecond = (int)(Double.valueOf(tableValues.getValueAt(ecgAnimateCurRow, 0).toString()).doubleValue()); if(curSecond > lastSecond){ lastSecond = curSecond; /* * Plot the X axes number values (the Time). */ ga.setColor(axesNumColor); drawText(ga, EcgFormatNumber.toString(Double.valueOf(tableValues.getValueAt(ecgAnimateCurRow, 0).toString()).doubleValue(), upLimit, loLimit, 2), x, horzScaleY, horzScaleWidth, horzScaleHeight, fScaleNumSize,LEFT); ga.setColor(frameInsideLineColor); ga.drawLine(x, posFrameY, x, horzScaleY + 5); } ga.setColor(ecgPlotColor); ga.drawLine(ecgAnimateLastPoint.x, ecgAnimateLastPoint.y, x, y); ecgAnimateCurRow += 1; if(ecgAnimateCurRow >= ecgAnimateNumRows){ /* * If we reach the end of the Data Table, loop again entire table. */ ecgFrame.repaint(); ecgAnimateCurRow = 0; ecgAnimateInitialZero = 0; x = 0; y = posOriginY - (int)(Double.valueOf(tableValues.getValueAt(ecgAnimateCurRow, 1).toString()).doubleValue() * frameAmplitude / paramOb.getAmplitude()); ecgAnimateLastPoint.setLocation(x, y); curSecond = 0; lastSecond = 0; } else if(x > ecgAnimatePanelWidth){ /* * If we not reached the end of the Data Table, but we reach to the limit of * the Plot Area. so reset the X coordinate to begin again. */ ecgFrame.repaint(); x = 0; y = posOriginY - (int)(Double.valueOf(tableValues.getValueAt(ecgAnimateCurRow, 1).toString()).doubleValue() * frameAmplitude / paramOb.getAmplitude()); ecgAnimateInitialZero = (int)(Double.valueOf(tableValues.getValueAt(ecgAnimateCurRow, 0).toString()).doubleValue() / plotZoom); ecgAnimateLastPoint.setLocation(x, y); //curSecond = 0; //lastSecond = 0; } else{ ecgAnimateLastPoint.setLocation(x, y); x = (int)(Double.valueOf(tableValues.getValueAt(ecgAnimateCurRow, 0).toString()).doubleValue() / plotZoom) - ecgAnimateInitialZero; y = posOriginY - (int)(Double.valueOf(tableValues.getValueAt(ecgAnimateCurRow, 1).toString()).doubleValue() * frameAmplitude / paramOb.getAmplitude()); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -