📄 programcanvas.java
字号:
rem = getW (currImg.begT, FrameBegTime + maxT) - widthCan; // if (extra > rem) extra = rem; // panePosX = _xPix + extra; if ( extra > rem ) panePosX = _xPix + rem; else panePosX = _xPix + extra; } else panePosX = _xPix; debug.println( "adjustZoomImg(" + pos + ") : currImg.begT = " + currImg.begT + ", currImg.endT = " + currImg.endT + ", maxT = " + maxT ); debug.println( "adjustZoomImg(" + pos + ") : extra = " + extra + ", " + "rem = " + rem + ", panePosX = " + panePosX ); debug.println( "adjustZoomImg(" + pos + ") : A) begTime = " + begTime + ", currImg.begT = " + currImg.begT ); begTime = FrameBegTime + getTime (tbegH); // begTime = getTime (tbegH); // begTime = currImg.begT + getTime (tbegH); debug.println( "adjustZoomImg(" + pos + ") : B) tbegH = " + tbegH + ", " + "begTime = " + begTime ); adjustStartEndTimes (); } void changeZoomFactor (double z) { if (z <= 0) {new ErrorDialog (null, "Value must be > 0"); return;} zF = z; } //--------------------------------------------------------------------------------- /** * This function renders in viewport view corresponding to given start and end times */ void changeExTime (double start, double end) { double diff = end - start; if (diff <= 0.0) return; // int pos = getW (0, start); int pos = getW( FrameBegTime, start ); parent.hbar.setValue (pos); //Position the scrollbar at the start time parent.setPosition (pos); //render the view with this start time //Now zoom in/out so that the end time corresponds with the given one. zoomH ((endTime - begTime) / diff); parent.zoomH (); } /** * This function renders in viewport view corresponding to current start and * given end times */ void changeToTime (double end) { if (end <= begTime) { new ErrorDialog (null, "value must be > " + Double.toString (begTime)); return; } double diff = end - begTime; // int pos = getW (0, begTime); int pos = getW( FrameBegTime, begTime ); parent.hbar.setValue (pos); //Position the scrollbar at the start time parent.setPosition (pos); //render the view with this start time //Now zoom in/out so that the end time corresponds with the given one. zoomH ((endTime - begTime) / diff); parent.zoomH (); } /** * This function renders in viewport view corresponding to given start and * current end times */ void changeFromTime (double start) { if (start >= endTime || start < 0) { new ErrorDialog (null, "value must be >= 0 and < " + Double.toString (endTime)); return; } double diff = endTime - start; // int pos = getW (0, start); int pos = getW( FrameBegTime, start ); parent.hbar.setValue (pos); //Position the scrollbar at the start time parent.setPosition (pos); //render the view with this start time //Now zoom in/out so that the end time corresponds with the given one. zoomH ((endTime - begTime) / diff); parent.zoomH (); } /** * Method called whenver the canvas has to be resized */ void Resize() { waitCursor (); Dimension dimVP = parent.vport.getExtentSize (); widthCan = dimVP.width; heightCan = dimVP.height; _xPix = 3 * widthCan; _yPix = heightCan; if (_yPix < 1) _yPix = 1; if (_xPix < 1) _xPix = 1; // Calling both methods may not be needed // setPreferredSize( getPreferredSize() ); setSize( getPreferredSize() ); maxT = tMaxT; xDensity = (widthCan / maxT) * zoomH; maxT += (endGap / xDensity); xDensity = (widthCan / maxT) * zoomH; // setupImg() HAS to be called in every call of Resize(), // So window redraws can be done correctly. Resize() is called // by componentResized() which is called when window is resized updateH (); setupImg (); if ( setupComplete ) { // sbPos = getEvtXCord (begTime); // sbPos = getW(currImg.begT, begTime); sbPos = getEvtXCord( begTime - FrameBegTime ); currImg = img [0]; adjustZoomImg (sbPos); } else drawInitImg(); panePosX = _xPix + getW (currImg.begT, begTime); parent.zoomH (); normalCursor (); } /** * Redraw all the images so that changes in options can take effect * CAUTION: setupNestedStates will hog up some of CPU's time but, it * has to be performed to keep nesting upto date */ void Refresh () { waitCursor (); blink = false; blFlag = true; if (timer.isRunning ()) timer.stop (); int prevH = getPrev (currImg.imgIdH); int nextH = getNext (currImg.imgIdH); waitCursor(); all_states.visible.SetupNestedStates(); normalCursor(); img [prevH].drawStuff (); img [nextH].drawStuff (); currImg.drawStuff (); if (blink) timer.start (); repaint (); parent.vcanvas1.repaint (); parent.vcanvas2.repaint (); parent.vport.setViewPosition (new Point (panePosX, 0)); debug.println( "Refresh() : .parent.vport.setViewPosition(" + panePosX + ", 0)" ); normalCursor (); } //--------------------------------------------------------------------------- // private void pushArrows (StateGroup p, double time) { public void pushArrows( StateGroup p, double time ) { StateGroupLabel groupID = p.groupID; RecDef arrowdef; Enumeration arrows; ArrowInfo arrow; Enumeration arrowdefs = parent.arrowDefs.elements(); while ( arrowdefs.hasMoreElements() ) { arrowdef = ( RecDef ) arrowdefs.nextElement(); if ( arrowdef.stateVector.size() > 0 && arrowdef.checkbox.isSelected() ) { arrows = arrowdef.stateVector.elements(); while ( arrows.hasMoreElements() ) { arrow = ( ArrowInfo ) arrows.nextElement(); if ( arrow.begGroupID.IsEqualTo( groupID ) ) arrow.begT += time; if ( arrow.endGroupID.IsEqualTo( groupID ) ) arrow.endT += time; } } } } /** * This method adjusts the scroll position of scrollPane container when * the time line is being moved */ // private void adjustPosition() public void adjustPosition() { StateGroup group; StateInterval state; double duration; double max_duration = 0; Enumeration groups = all_states.visible.elements(); while ( groups.hasMoreElements() ) { group = (StateGroup) groups.nextElement (); if ( group.size() > 0 ) { state = (StateInterval) group.lastElement(); duration = state.info.endT - FrameBegTime; if ( duration > max_duration ) max_duration = duration; } } boolean end = false; if (max_duration < tMaxT || max_duration > tMaxT) { if (max_duration < tMaxT) end = true; double diff = tMaxT - max_duration; tMaxT = max_duration; maxT -= diff; updateH (); parent.setHoriz(); centralizeH(); } if (end) { if ( ( parent.hbar.getValue() + parent.hbar.getVisibleAmount() ) >= parent.hbar.getMaximum() ) { parent.hbar.setValue (maxH - widthCan); adjustImgH (parent.hbar.getValue ()); parent.vport.setViewPosition (new Point (panePosX, 0)); debug.println( "adjustPosition() : " ); debug.println( "\t" + "parent.hbar.setValue(" + (maxH - widthCan) + ")" ); debug.println( "\t" + "parent.vport.setViewPosition(" + panePosX + ", 0)" ); } } } /** * This method returns the maximum value in pixels that the time line * can be moved to the left before reaching the (begTime) time position * p = the process whose time line is to be moved */ int getMaxDiff ( StateGroup group ) { if ( group.size() > 0 ) { StateInterval state = (StateInterval) group.firstElement(); // return getEvtXCord (state.info.begT - 0.0); return getEvtXCord ( state.info.begT - FrameBegTime ); } return 0; } //end of methods dealing with process position manipulation------------------ /** * change nest factor to given value and update the display */ void changeNestFactor (double n) { if ( all_states.visible.GetMaxNestingLevel() < 1) return; double uBound = 1 / (double) all_states.visible.GetMaxNestingLevel(); if (n < 0 || n >= uBound) { new ErrorDialog (null, "Value must be > 0 and < " + ( new Double(uBound) ).toString() ); return; } nestFactor = n; Refresh (); } /** * Calculates most appropriate nest factor by dividing total thickness * equally among all nested levels */ double doAppropNesting () { changeNestFactor (1 / ((double) all_states.visible.GetMaxNestingLevel() + 1)); return nestFactor; } /** * returns the desired scroll position in the scrollpane */ int getPanePosX() { return panePosX; } /** * Method required by the scrollpane container to adjust values */ public Dimension getPreferredSize () {return new Dimension (_xPix * 3, _yPix);} /** * Adjust field values */ void adjustTimeField (int x) { cursorPos = (x - _xPix); parent.adjustTimeField (currTime = currImg.begT + getTime (cursorPos)); } void adjustElTimeField () { parent.adjustElTimeField (currTime - elapsedPoint); } void adjustStartEndTimes () { debug.println( "Before adjustStartEndTimes() : " + "begTime = " + begTime + ", endTime = " + endTime + ", widthCan = " + widthCan ); endTime = begTime + getTime (widthCan); parent.optionsDlg.adjustTimes (begTime, endTime); debug.println( "After adjustStartEndTimes() : " + "begTime = " + begTime + ", endTime = " + endTime + ", widthCan = " + widthCan ); } void addDisplay (int dtype) { waitCursor (); dtypeV.addElement (new Integer (dtype)); setupImg (); // sbPos = getEvtXCord (begTime); // sbPos = getW( currImg.begT, begTime ); sbPos = getEvtXCord( begTime - FrameBegTime ); currImg = img [0]; adjustZoomImg (sbPos); panePosX = _xPix + getW (currImg.begT, begTime); parent.zoomH (); normalCursor (); } void removeDisplay (int index) { waitCursor (); dtypeV.removeElementAt (index); setupImg (); // sbPos = getEvtXCord (begTime); // sbPos = getW( currImg.begT, begTime ); sbPos = getEvtXCord( begTime - FrameBegTime ); currImg = img [0]; adjustZoomImg (sbPos); panePosX = _xPix + getW (currImg.begT, begTime); parent.zoomH (); normalCursor (); } /** * sets the current cursor to 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));} /** * Handle the event when JViewport is resized */ public void componentResized (ComponentEvent e) { debug.println( "*******" + "___componentResized()___ : start!" ); parent.waitCursor (); if (parent.setupComplete) Resize (); parent.normalCursor (); } /** * Unused methods of ComponentListener interface */ public void componentHidden (ComponentEvent e) {;} public void componentMoved (ComponentEvent e) {;} public void componentShown (ComponentEvent e) {;} public void kill () { // resetProcTimes (); all_states.ResetTimeLines(); all_states = null; killImgs (); } protected void finalize() throws Throwable {super.finalize();} class TimerListener implements ActionListener { public void actionPerformed(ActionEvent evt) { blFlag = !blFlag; repaint (); } } boolean getZLkLineDStat () {return zoomLkLineDispStatus;} boolean getElTLineDStat () {return elTLineDispStatus;} void updateZLkLineDStat (boolean b) {zoomLkLineDispStatus = b; repaint ();} void updateElTLineDStat (boolean b) {elTLineDispStatus = b; repaint ();}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -