📄 programcanvas.java
字号:
int rem = getW (currImg.begT, maxT) - widthCan; if (extra > rem) extra = rem; panePosX = _xPix + extra; } else panePosX = _xPix; begTime = getTime (tbegH); adjustStartEndTimes (); } void changeZoomFactor (double z) { if (z <= 0) {new ErrorDiag (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); 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 ErrorDiag (null, "value must be > " + Double.toString (begTime)); return; } double diff = end - begTime; int pos = getW (0, 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 ErrorDiag (null, "value must be >= 0 and < " + Double.toString (endTime)); return; } double diff = endTime - start; int pos = getW (0, 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; updateH (); setupImg (); if (!setupComplete) drawInitImg (); else { sbPos = getEvtXCord (begTime); currImg = img [0]; adjustZoomImg (sbPos); } 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); setupNestedStates (); 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)); normalCursor (); } //-------------------------------------------------------------------------------------- /** * Methods to handle deleting, swapping and horizontally translating process display * Delete the process at the given index of procVector */ void DeleteProc (int index) { JProcess p = (JProcess)(procVector.elementAt (index)); procVector.removeElementAt (index); dprocVector.addElement (p); proct --; dproct ++; calcYDensity (); } /** * Delete process at the given index from dprocVector and insert it on top * of the process with the given pid * dindex = index into dProcVector which specifies the JProcess object to be removed * pid = pid of the process before which the removed process is to be inserted */ void InsertProc (int dindex, int pid) { JProcess dp = (JProcess)(dprocVector.elementAt (dindex)); dprocVector.removeElementAt (dindex); procVector.insertElementAt (dp, getIndex (procVector, pid)); proct++; dproct--; calcYDensity (); } /** * push the timeLine and all states of the given process. * p = process whose time line is to be moved * time = this specifies the time in seconds the time line is to be moved * (time > 0) => right, (time < 0) => left */ private void pushTimeLine (JProcess p, double time) { Enumeration enum = p.procStateVector.elements (); ProcessState currEvt = (ProcessState)(p.procStateVector.firstElement ()); if (currEvt != null) { currEvt.info.begT += time; if (currEvt.info.begT < 0) { time -= currEvt.info.begT; currEvt.info.begT = 0; } currEvt.info.endT += time; enum.nextElement (); } while (enum.hasMoreElements ()) { currEvt = (ProcessState)(enum.nextElement ()); currEvt.info.begT += time; currEvt.info.endT += time; } //Push the arrows pushArrows (p, time); //position the image appropriately adjustPosition (); } /** * push the time line and all states of the given states * p = process whose time line is to be moved * amount = displacement in pixels to move * dir = direction. true => right, false => left */ void pushTimeLine (JProcess p, int amount, boolean dir) { double time = getTime (amount); if (!dir) time *= (- 1); pushTimeLine (p, time); } private void pushArrows (JProcess p, double time) { Enumeration enum = parent.quiver.arrowVector.elements (); while (enum.hasMoreElements ()) { ArrowInfo arrow = (ArrowInfo)enum.nextElement (); if (arrow.begProcId == p.procId) arrow.begT += time; if (arrow.endProcId == p.procId) arrow.endT += time; } } /** * This method adjusts the scroll position of scrollPane container when * the time line is being moved */ private void adjustPosition () { double max = 0; Enumeration enum = procVector.elements (); while (enum.hasMoreElements ()) { JProcess p = (JProcess)enum.nextElement (); ProcessState ps = (ProcessState)p.procStateVector.lastElement (); if (ps.info.endT > max) max = ps.info.endT; } boolean end = false; if (max < tMaxT || max > tMaxT) { if (max < tMaxT) end = true; double diff = tMaxT - max; tMaxT = max; 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)); } } } /** * This method returns the maximum value in pixels that the time line can be moved * to the left before reaching the 0 time position * p = the process whose time line is to be moved */ int getMaxDiff (JProcess p) { if (p.procStateVector.size () > 0) { ProcessState ps = (ProcessState)(p.procStateVector.firstElement ()); return getEvtXCord (ps.info.begT - 0.0); } return 0; } /** * Repostions the time line to its original position * p = the process whose time line is to be repositioned */ void resetTimeLine (JProcess p) { ProcessState ps = (ProcessState)p.procStateVector.firstElement (); pushTimeLine (p, p.begT - ps.info.begT); } //end of methods dealing with process position manipulation------------------------------ /** * change nest factor to given value and cause change to take effect on display */ void changeNestFactor (double n) { if (maxLevel < 1) return; double uBound = 1 / (double)maxLevel; if (n < 0 || n >= uBound) { new ErrorDiag (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)maxLevel + 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 () { endTime = begTime + getTime (widthCan); parent.optionsDlg.adjustTimes (begTime, endTime); } void addDisplay (int dtype) { waitCursor (); dtypeV.addElement (new Integer (dtype)); setupImg (); sbPos = getEvtXCord (begTime); 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); 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) { 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 (); procVector = null; dprocVector = null; killImgs (); } private void resetProcTimes () { for (int i = 0; i < procVector.size (); i++) resetTimeLine ((JProcess)procVector.elementAt (i)); for (int i = 0; i < dprocVector.size (); i++) resetTimeLine ((JProcess)dprocVector.elementAt (i)); } 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 + -