📄 histcanvas.java
字号:
private void obtainArea (int a, boolean top) { double zscore; switch (a) { case 1: zscore = 2.3268; break; case 5: zscore = 1.6452; break; case 10: zscore = 1.2817; break; case 20: zscore = 0.8; break; case 30: zscore = 0.524; break; case 50: zscore = 0; break; default: new ErrorDiag (null, "Region has not been implemented"); return; } if (!top) zscore = zscore * -1; double m = getMeanOfStateLens (); double st = getStDevOfStateLens (m); //Using the st. normal dist. transformation z = (X - m) / st double X = zscore * st + m; if (X >= maxT && top) { new ErrorDiag (null, "No states with duration > mu(" + (new Float (m)).toString () + ") + " + zscore + "sigma(" + (new Float (st)).toString () + ")"); return; } else if (X <= leastT && !top) { new ErrorDiag (null, "No states with duration < mu(" + (new Float (m)).toString () + ") + " + zscore + "sigma(" + (new Float (st)).toString () + ")"); return; } endT = maxT; begT = leastT; if (top) { if (stateVector.size () > 1 && X >= leastT) begT = X; } else if (stateVector.size () > 1 && X <= maxT) endT = X; xDensity = _xPix / (endT - begT); view.drawRegion (begT, endT); repaint (); calcHPixMax (); calcHbarMax (); calcHbarVal (); setHbarValues (); //set Field values parent.startLenField.setText ((new Float (begT)).toString ()); parent.endLenField.setText ((new Float (endT)).toString ()); parent.statesInViewField.setText (Integer.toString (view.statesDrawn)); parent.pcInViewField.setText ((new Float (view.statesDrawn * 100 / stateVector.size ())).toString ()); } private double getMeanOfStateLens () { Enumeration enum = stateVector.elements (); double sum = 0; while (enum.hasMoreElements ()) { Info currState = (Info)enum.nextElement (); sum += currState.lenT; } return (sum / stateVector.size ()); } private double getStDevOfStateLens (double m) { Enumeration enum = stateVector.elements (); double sum = 0; while (enum.hasMoreElements ()) { Info currState = (Info)enum.nextElement (); sum += ((currState.lenT - m) * (currState.lenT - m)); } return Math.sqrt (sum / stateVector.size ()); } public void componentResized (ComponentEvent e) {ResizeCanvas ();} public void adjustmentValueChanged (AdjustmentEvent e) { int x = parent.hbar.getValue (); int v = parent.hbar.getVisibleAmount (); begT = leastT + (maxT - leastT) * (double)x / hbarMax; endT = leastT + (maxT - leastT) * (double)(x + v) / hbarMax; view.drawRegion (begT, endT); repaint (); parent.startLenField.setText ((new Float (begT)).toString ()); parent.endLenField.setText ((new Float (endT)).toString ()); parent.statesInViewField.setText (Integer.toString (view.statesDrawn)); parent.pcInViewField.setText ((new Float (view.statesDrawn * 100 / stateVector.size ())).toString ()); parent.zFacField.setText ((new Float (zoomFac)).toString ()); } public void stateChanged (ChangeEvent e) { JSlider source = (JSlider)e.getSource (); if (source == parent.binSlider) { int numBins = parent.binSlider.getValue (); parent.numBinsField.setText (Integer.toString (numBins)); parent.maxNumBinsField.setText (Integer.toString (maxNumBins)); changeNumBins (numBins); } } public void ResizeCanvas () { waitCursor (); Dimension dim = getSize (); widthCan = dim.width; topGap = parent.getInsets ().top; heightCan = dim.height; _xPix = widthCan; _yPix = heightCan; if (_yPix < 1) _yPix = 1; if (_xPix < 1) _xPix = 1; //will be moved from here if (!setupComplete) { setupComplete = true; eff_yPix = _yPix; } xDensity = widthCan / (endT - begT); yDensity = (_yPix - 3.0 * lineSize) / (double)stateVector.size (); setupImg (); view.drawRegion (begT, endT); repaint (); //Modify hbar values calcHPixMax (); calcHbarMax (); calcHbarVal (); setHbarValues (); normalCursor (); } private void calcHPixMax () {hPixMax = getW (leastT, maxT);} private void calcHbarMax () {hbarMax = hPixMax;} private void calcHbarVal () { double d = (begT - leastT) * xDensity; hbarVal = (int)Math.rint (d); } private void setHbarValues () { parent.hbar.setValues (hbarVal, _xPix, 0, hbarMax); } private void resetView () { waitCursor (); begT = leastT; endT = maxT; xDensity = _xPix / (endT - begT); view.drawRegion (begT, endT); repaint (); calcHPixMax (); calcHbarMax (); calcHbarVal (); setHbarValues (); //set Field values parent.startLenField.setText ((new Float (begT)).toString ()); parent.endLenField.setText ((new Float (endT)).toString ()); parent.statesInViewField.setText (Integer.toString (view.statesDrawn)); parent.pcInViewField.setText ((new Float (view.statesDrawn * 100 / stateVector.size ())).toString ()); normalCursor (); } private void zoomInH () { waitCursor (); double centerT = begT + (endT - begT) / 2; begT = centerT - (centerT - begT) / zoomFac; endT = centerT + (endT - centerT) / zoomFac; xDensity = _xPix / (endT - begT); view.drawRegion (begT, endT); repaint (); calcHPixMax (); calcHbarMax (); calcHbarVal (); setHbarValues (); //set Field values parent.startLenField.setText ((new Float (begT)).toString ()); parent.endLenField.setText ((new Float (endT)).toString ()); parent.statesInViewField.setText (Integer.toString (view.statesDrawn)); parent.pcInViewField.setText ((new Float (view.statesDrawn * 100 / stateVector.size ())).toString ()); normalCursor (); } private void zoomOutH () { waitCursor (); double centerT = begT + (endT - begT) / 2; begT = centerT - (centerT - begT) * zoomFac; if (begT < leastT) begT = leastT; endT = centerT + (endT - centerT) * zoomFac; if (endT > maxT) endT = maxT; xDensity = _xPix / (endT - begT); view.drawRegion (begT, endT); repaint (); //set Hbar values calcHPixMax (); calcHbarMax (); calcHbarVal (); setHbarValues (); //set Field values parent.startLenField.setText ((new Float (begT)).toString ()); parent.endLenField.setText ((new Float (endT)).toString ()); parent.statesInViewField.setText (Integer.toString (view.statesDrawn)); parent.pcInViewField.setText ((new Float (view.statesDrawn * 100 / stateVector.size ())).toString ()); normalCursor (); } /** * handles events when the mouse is moved or dragged */ public void processMouseMotionEvent (MouseEvent e) { if (e.getID () == MouseEvent.MOUSE_MOVED) adjustTimeField (e.getX ()); if (e.getID () == MouseEvent.MOUSE_DRAGGED) { int y = e.getY (); int dy = ty - y; eff_yPix += dy; yDensity = (eff_yPix - 3.0 * lineSize) * 1.0/ (double)stateVector.size (); view.drawRegion (begT, endT); repaint (); ty = y; } else super.processMouseMotionEvent (e); } /** * handles events when the mouse is pressed */ public void processMouseEvent (MouseEvent e) { if (e.getID () == MouseEvent.MOUSE_PRESSED) ty = e.getY (); else if (e.getID () == MouseEvent.MOUSE_RELEASED) ty = e.getY (); else super.processMouseMotionEvent (e); } int print (Graphics g, int x, int y, int width, int height) { FontMetrics tfm = g.getFontMetrics (); g.drawString ("State '" + stateDef.description.desc + "' length distribution", x, y + tfm.getHeight () - tfm.getDescent ()); g.drawString (Integer.toString (view.statesDrawn) + " drawn out of " + Integer.toString (stateVector.size ()) + " (" + (new Float (view.statesDrawn * 100.0 / (double)stateVector.size ())).toString () + "%)", x, y + 2 * tfm.getHeight () - tfm.getDescent ()); return 3 * tfm.getHeight (); } //end of event handler methods--------------------------------------------------- private void adjustTimeField (int x) { parent.cursorField.setText ((new Float (view.begT + getTime (x))).toString ()); } /** * sets the current cursor to the WAIT_CURSOR type */ void waitCursor () {setCursor (new Cursor (Cursor.WAIT_CURSOR));} /** * sets the WAIT_CURSOR to cursor associated with this canvas */ void normalCursor () {setCursor (new Cursor (Cursor.CROSSHAIR_CURSOR));} /** Unused methods of the ComponentListener interface. */ public void componentHidden (ComponentEvent e) {;} public void componentMoved (ComponentEvent e) {;} public void componentShown (ComponentEvent e) {;} void kill () { if (view != null) {view.kill (); view = null;} } protected void finalize () throws Throwable {super.finalize ();} ActionListener tAL = new ActionListener () { public void actionPerformed (ActionEvent e) { String command = e.getActionCommand (); if (command.endsWith ("%")) { int val = Integer.parseInt (command.substring (0, command.length () - 1)); parent.areaField.setText (command); obtainArea (val, true); } } }; ActionListener bAL = new ActionListener () { public void actionPerformed (ActionEvent e) { String command = e.getActionCommand (); if (command.endsWith ("%")) { int val = Integer.parseInt (command.substring (0, command.length () - 1)); parent.bAreaField.setText (command); obtainArea (val, false); } } };}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -