Search in sources :

Example 1 with PERTChartSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.PERTChartSelectionState 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 2 with PERTChartSelectionState

use of edu.cmu.cs.hcii.cogtool.ui.PERTChartSelectionState in project cogtool by cogtool.

the class PERTChartPanel method observeSelectionState.

/**
     * Associate this view with a PERTChartSelectionState so that, when a new
     * operator is selected, this view adds the operator info to the
     * operatorInfoPanel.
     *
     * @param selection
     */
public void observeSelectionState(PERTChartSelectionState selection) {
    chartSelectionState = selection;
    visPanel.observeSelectionState(chartSelectionState);
    scrollBar.observeSelectionState(chartSelectionState);
    AlertHandler handler = new AlertHandler() {

        public void handleAlert(EventObject alert) {
            List<ResultStep> selectedStepList = ((PERTChartSelectionState.SelectionChange) alert).selectedSteps;
            String trace = traceText.getText();
            int startPos = -1;
            int endPos = -1;
            operatorInfoText.setText("");
            Iterator<ResultStep> stepIt = selectedStepList.iterator();
            while (stepIt.hasNext()) {
                ResultStep step = stepIt.next();
                operatorInfoText.append(step.toString() + "\n\n\n\n");
                if (startPos < 0) {
                    startPos = Math.max(0, StringUtil.getCharPosFromLineNum(trace, step.traceStart));
                } else {
                    startPos = Math.min(startPos, StringUtil.getCharPosFromLineNum(trace, step.traceStart));
                }
                endPos = Math.max(endPos, StringUtil.getCharPosFromLineNum(trace, step.traceEnd));
            }
            if (selectedStepList.size() == 0) {
                operatorInfoText.setText(NO_OPERATOR_SELECTED);
            }
            if ((startPos > -1) && (endPos > -1)) {
                traceText.setSelection(startPos, endPos);
                traceText.showSelection();
            }
        }
    };
    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) AlertHandler(edu.cmu.cs.hcii.cogtool.util.AlertHandler) EventObject(java.util.EventObject)

Aggregations

ResultStep (edu.cmu.cs.hcii.cogtool.model.ResultStep)2 PERTChartSelectionState (edu.cmu.cs.hcii.cogtool.ui.PERTChartSelectionState)2 AlertHandler (edu.cmu.cs.hcii.cogtool.util.AlertHandler)2 EventObject (java.util.EventObject)2 PERTChartOperatorBar (edu.cmu.cs.hcii.cogtool.uimodel.PERTChartOperatorBar)1