Search in sources :

Example 1 with PERTChartOperatorBar

use of edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar in project cogtool by cogtool.

the class PERTPanel method resizeVisualization.

/**
     * Resets the position and size of the PERTChartOperatorBar objects
     * when the panel is resized.
     *
     * @param e resize Event to respond to.
     */
public void resizeVisualization(Event e) {
    int totalWidth = getVisualizationWidth();
    int totalHeight = getVisualizationHeight();
    int regionHeight = PrecisionUtilities.round((totalHeight - 10) / Math.max(numRows, 1));
    Iterator<PERTChartOperatorBar> barIterator = bars.iterator();
    PERTChartOperatorBar bar;
    int barW;
    int barH;
    int barX;
    int barY;
    // rescale the width of each bar based on the ratio of it's duration to
    // the total time, and set its new position
    double displayedDuration = displayEndTime - displayStartTime;
    if ((totalTime > 0) && (displayedDuration > 0)) {
        while (barIterator.hasNext()) {
            bar = barIterator.next();
            // Calculate position based on the position of the right of the
            // bar to avoid oscillating widths
            int barRightPos = marginLeft + PrecisionUtilities.round(((bar.getStartTime() + bar.getDuration() - displayStartTime) / displayedDuration) * (totalWidth - 10));
            //
            //                barW = PrecisionUtilities.round((bar.getDuration() * (totalWidth - 10))
            //                                                / displayedDuration) + 1;
            barX = marginLeft + PrecisionUtilities.round(((bar.getStartTime() - displayStartTime) / displayedDuration) * (totalWidth - 10));
            barW = barRightPos - barX + 1;
            if (bar.isCascade()) {
                int y1 = Math.min(bar.getRow(), bar.getEndRow());
                int y2 = Math.max(bar.getRow(), bar.getEndRow());
                barY = marginTop + (y1 * regionHeight) + PrecisionUtilities.round(0.5 * barHeight);
                barH = (y2 - y1) * regionHeight;
                if (barW < 1) {
                    barW = 1;
                }
            } else {
                barY = marginTop + (bar.getRow() * regionHeight);
                barH = barHeight;
                if (barW < 3) {
                    barX -= 1;
                    barW = 3;
                }
            }
            bar.setBounds(new Rectangle(barX, barY, barW, barH));
        }
    }
    lws.getUpdateManager().performUpdate();
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) PERTChartOperatorBar(edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar)

Example 2 with PERTChartOperatorBar

use of edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar in project cogtool by cogtool.

the class PERTChartMouseState method dealWithMouseDown.

/*
     * Generates selection events based on mouse clicks.
     *
     * @see org.eclipse.swt.events.MouseListener#mouseDown
     */
@Override
protected void dealWithMouseDown(MouseEvent e) {
    super.dealWithMouseDown(e);
    PERTChartOperatorBar bar = panel.findBarAt(e.x, e.y);
    if (bar != null) {
        // TODO: allow for shift click to support multiple selection
        selection.setSelectedStep(bar.getStep());
    } else {
        selection.deselectAll();
    }
}
Also used : PERTChartOperatorBar(edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar)

Example 3 with PERTChartOperatorBar

use of edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar in project cogtool by cogtool.

the class PERTPanel method observeSelectionState.

/**
     * Associates this panel with a PERTChartSelectionState so that when a new
     * operator is selected, this panel will redraw itself accordingly.
     *
     * @param selectionState
     */
public void observeSelectionState(PERTChartSelectionState selectionState) {
    chartSelectionState = selectionState;
    AlertHandler handler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            // TODO: Change this to map or set
            List<ResultStep> selectedSteps = ((PERTChartSelectionState.SelectionChange) alert).selectedSteps;
            // clear selection boxes
            Iterator<SelectionHalo> haloIterator = selectionBoxes.iterator();
            SelectionHalo deadHalo = null;
            while (haloIterator.hasNext()) {
                deadHalo = haloIterator.next();
                contents.remove(deadHalo);
                deadHalo.dispose();
            }
            selectionBoxes.clear();
            Iterator<PERTChartOperatorBar> barIterator = bars.iterator();
            PERTChartOperatorBar bar;
            while (barIterator.hasNext()) {
                bar = barIterator.next();
                if (selectedSteps.contains(bar.getStep())) {
                    bar.setSelected(true);
                    SelectionHalo halo = new SelectionHalo();
                    halo.setTarget(bar);
                    contents.add(halo);
                    selectionBoxes.add(halo);
                } else {
                    bar.setSelected(false);
                }
            }
            //redraw();
            contents.repaint();
        }
    };
    chartSelectionState.addHandler(this, PERTChartSelectionState.SelectionChange.class, handler);
}
Also used : ResultStep(edu.cmu.cs.hcii.cogtool.model.ResultStep) PERTChartSelectionState(edu.cmu.cs.hcii.cogtool.ui.PERTChartSelectionState) PERTChartOperatorBar(edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) EventObject(java.util.EventObject)

Example 4 with PERTChartOperatorBar

use of edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar in project cogtool by cogtool.

the class PERTPanel method setResultSteps.

public void setResultSteps(List<ResultStep> steps, List<String> resourceLabels) {
    // First remove seleciton halos
    Iterator<SelectionHalo> haloIterator = selectionBoxes.iterator();
    SelectionHalo deadHalo = null;
    while (haloIterator.hasNext()) {
        deadHalo = haloIterator.next();
        contents.remove(deadHalo);
        deadHalo.dispose();
    }
    selectionBoxes.clear();
    // Then remove existing operator bars
    Iterator<PERTChartOperatorBar> barIt = bars.iterator();
    PERTChartOperatorBar deadBar = null;
    while (barIt.hasNext()) {
        deadBar = barIt.next();
        Iterator<PERTStepDependency> depIt = deadBar.getDependencies().iterator();
        while (depIt.hasNext()) {
            PERTStepDependency deadDependency = depIt.next();
            contents.remove(deadDependency);
        }
        contents.remove(deadBar);
    //deadBar.dispose();
    }
    bars.clear();
    Iterator<ResultStep> stepIterator = steps.iterator();
    ResultStep step;
    PERTChartOperatorBar bar;
    // create a map so that we can copy the dependency structure from the
    // ResultSteps to the PERTChartOperatorBars
    // TODO: save this state, and use this instead of bars
    Map<ResultStep, PERTChartOperatorBar> barMap = new HashMap<ResultStep, PERTChartOperatorBar>();
    List<PERTChartOperatorBar> operators = new ArrayList<PERTChartOperatorBar>();
    // iterate through once and create operator bars
    while (stepIterator.hasNext()) {
        step = stepIterator.next();
        bar = new PERTChartOperatorBar(step, resourceLabels, barHeight);
        bar.setColorWithMap(colorMap);
        barMap.put(step, bar);
        bars.add(bar);
        if (bar.isCascade()) {
            contents.add(bar);
        } else {
            operators.add(bar);
        }
        // coompare to find the total time
        totalTime = Math.max(totalTime, step.startTime + step.duration);
    }
    // iterator through operators, and add them now:
    Iterator<PERTChartOperatorBar> opIter = operators.iterator();
    while (opIter.hasNext()) {
        contents.add(opIter.next());
    }
    // iterate through again setting dependencies on each bar object
    //   based on the dependencies in each ResultStep object
    ResultStep.ResultStepDependency rStepDep;
    Iterator<ResultStep.ResultStepDependency> depStepIter;
    stepIterator = steps.iterator();
    double ntvTotalTime = 0.0d;
    while (stepIterator.hasNext()) {
        step = stepIterator.next();
        bar = barMap.get(step);
        depStepIter = step.getDependencies().iterator();
        ntvTotalTime = Math.max(ntvTotalTime, step.startTime + step.duration);
        while (depStepIter.hasNext()) {
            rStepDep = depStepIter.next();
            PERTChartOperatorBar otherBar = barMap.get(rStepDep.dependency);
            PERTStepDependency dep = bar.addDependency(otherBar, rStepDep);
            contents.add(dep);
            connections.add(dep);
        }
    }
    nativeTotalTime = ntvTotalTime;
    totalTime = nativeTotalTime;
    numRows = resourceLabels.size();
    resizeVisualization(null);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PERTChartOperatorBar(edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar) PERTStepDependency(edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar.PERTStepDependency) ResultStep(edu.cmu.cs.hcii.cogtool.model.ResultStep)

Example 5 with PERTChartOperatorBar

use of edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar in project cogtool by cogtool.

the class PERTChartMouseState method dealWithMouseMove.

@Override
protected void dealWithMouseMove(MouseEvent e) {
    super.dealWithMouseMove(e);
    Iterator<PERTChartOperatorBar> bIter = panel.getOperatorBarList().iterator();
    boolean found = false;
    while ((!found) && bIter.hasNext()) {
        PERTChartOperatorBar bar = bIter.next();
        if (bar.containsPoint(e.x, e.y)) {
            found = true;
            if (currentCursor != handCursor) {
                currentCursor = handCursor;
                panel.setCursor(currentCursor);
            }
        }
    }
    if (!found) {
        if (currentCursor != arrowCursor) {
            currentCursor = arrowCursor;
            panel.setCursor(currentCursor);
        }
    }
}
Also used : PERTChartOperatorBar(edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar)

Aggregations

PERTChartOperatorBar (edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar)5 ResultStep (edu.cmu.cs.hcii.cogtool.model.ResultStep)2 PERTChartSelectionState (edu.cmu.cs.hcii.cogtool.ui.PERTChartSelectionState)1 PERTStepDependency (edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar.PERTStepDependency)1 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)1 ArrayList (java.util.ArrayList)1 EventObject (java.util.EventObject)1 HashMap (java.util.HashMap)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1