Example usage for org.eclipse.swt.widgets Display getDefault

List of usage examples for org.eclipse.swt.widgets Display getDefault

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Display getDefault.

Prototype

public static Display getDefault() 

Source Link

Document

Returns the default display.

Usage

From source file:org.ewhoxford.swt.bloodpressure.ui.MeasurePageTab.java

/**
 * Determination of BP and pulse algorithm
 *//*from   w  w w .jav  a2 s.  c o m*/
private void startSignalProcessing() {

    // myProgressDialog = ProgressDialog.show(MeasureActivity.this,
    // getResources().getText(R.string.alert_dialog_processing_data),
    // getResources().getText(R.string.alert_dialog_determine_bp),
    // true);

    // Runnable runnable = new Runnable() {
    // @Override
    // public void run() {
    // // Imagine something useful here
    // try {
    // Thread.sleep(10000);
    // } catch (InterruptedException e) {
    // e.printStackTrace();
    // }
    //            
    // }
    // };
    //      
    // BusyIndicator.showWhile(controlGroup.getShell().getDisplay(),
    // runnable);

    new Thread() {
        public void run() {

            int l = data.getBpMeasureHistory().size();
            arrayTime = new float[l];
            arrayPressure = new double[l];
            int i = 0;
            int fs = 100;
            while (i < l) {
                arrayPressure[i] = data.getBpMeasureHistory().get(i).doubleValue();
                arrayTime[i] = ((float) i / (float) fs);
                i++;
            }

            TimeSeriesMod signal = new TimeSeriesMod();
            signal.setPressure(arrayPressure);
            signal.setTime(arrayTime);
            bloodPressureValue = new BloodPressureValue();
            SignalProcessing r = new SignalProcessing();

            try {
                bloodPressureValue = r.signalProcessing(signal, fs);
            } catch (BadMeasureException e) {
                // myProgressDialog.dismiss();
                Display.getDefault().syncExec(discardMeasure);

            } catch (TempBadMeasureException e) {
                // myProgressDialog.dismiss();
                Display.getDefault().syncExec(discardTemBadMeasure);
            }

            // Dismiss the Dialog
            // myProgressDialog.dismiss();
            Display.getDefault().syncExec(updataBPResultView);
        }
    }.start();

}

From source file:org.mwc.debrief.track_shift.views.BaseStackedDotsView.java

/**
 * the track has been moved, update the dots
 *//*w w  w.  ja  v  a 2  s . co  m*/
void clearPlots() {
    if (Thread.currentThread() == Display.getDefault().getThread()) {
        // it's ok we're already in a display thread
        _dotPlot.setDataset(null);
        _linePlot.setDataset(null);
    } else {
        // we're not in the display thread - make it so!
        Display.getDefault().syncExec(new Runnable() {
            public void run() {
                _dotPlot.setDataset(null);
                _linePlot.setDataset(null);
            }
        });
    }
}

From source file:org.mwc.debrief.track_shift.views.BaseStackedDotsView.java

/**
 * the track has been moved, update the dots
 *//* w w  w.j  a  v  a2  s .  c o  m*/
void updateStackedDots(final boolean updateDoublets) {
    if (Thread.currentThread() == Display.getDefault().getThread()) {
        // it's ok we're already in a display thread
        wrappedUpdateStackedDots(updateDoublets);
    } else {
        // we're not in the display thread - make it so!
        Display.getDefault().syncExec(new Runnable() {
            public void run() {
                // update the current datasets
                wrappedUpdateStackedDots(updateDoublets);
            }
        });
    }
}

From source file:org.gumtree.vis.swt.PlotComposite.java

private void addListeners() {
    if (plot != null) {
        //         mouseWheelListener = new MouseWheelListener() {
        ////from   w w w  . j ava  2s .  c o  m
        //            @Override
        //            public void mouseScrolled(MouseEvent event) {
        //               JPanel panel = null;
        //               if (plot instanceof JPanel) {
        //                  panel = (JPanel) plot;
        //               }
        //               MouseWheelEvent awtEvent = org.gumtree.vis.listener.SWT_AWT.toMouseWheelEvent(
        //                     event, panel);
        //               plot.processMouseWheelEvent(awtEvent);
        //            }
        //         };
        //         addMouseWheelListener(mouseWheelListener);

        keyListener = new KeyListener() {

            boolean keyPressed = false;

            @Override
            public void keyReleased(KeyEvent event) {
                switch (event.keyCode) {
                case SWT.DEL:
                    plot.removeSelectedMask();
                    plot.removeSelectedText();
                    break;
                default:
                    break;
                }
                switch (event.character) {
                default:
                    break;
                }
                keyPressed = false;
            }

            @Override
            public void keyPressed(KeyEvent event) {
                switch (event.stateMask) {
                case SWT.CTRL:
                    if (event.keyCode == 'c' || event.keyCode == 'C') {
                        if (!keyPressed) {
                            plot.doCopy();
                        }
                    } else if (event.keyCode == 'z' || event.keyCode == 'Z' || event.keyCode == 'r'
                            || event.keyCode == 'R') {
                        if (!keyPressed) {
                            plot.restoreAutoBounds();
                        }
                    } else if (event.keyCode == 'p' || event.keyCode == 'P') {
                        if (!keyPressed) {
                            Thread newThread = new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    plot.createChartPrintJob();
                                }
                            });
                            newThread.start();
                        }
                    } else if (event.keyCode == 'e' || event.keyCode == 'E') {
                        if (!keyPressed) {
                            Thread newThread = new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    try {
                                        plot.doSaveAs();
                                    } catch (IOException e) {
                                        handleException(e);
                                    }
                                }
                            });
                            newThread.start();
                        }
                    }
                    keyPressed = true;
                    break;
                case SWT.ALT:
                    break;
                default:
                    switch (event.keyCode) {
                    case SWT.ARROW_UP:
                        plot.moveSelectedMask(event.keyCode);
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() > 0) {
                                    String text = plot.getTextInputContent();
                                    int cursorIndex = plot.getTextInputCursorIndex();
                                    String[] lines = text.split("\n", 100);
                                    int cursorX = 0;
                                    int charCount = 0;
                                    int newCursorIndex = cursorIndex;
                                    for (int i = 0; i < lines.length; i++) {
                                        if (cursorIndex > charCount
                                                && cursorIndex < charCount + lines[i].length() + 1) {
                                            cursorX = cursorIndex - charCount;
                                            if (i > 0) {
                                                if (cursorX <= lines[i - 1].length()) {
                                                    newCursorIndex = charCount - lines[i - 1].length() - 1
                                                            + cursorX;
                                                } else {
                                                    newCursorIndex = charCount - 1;
                                                }
                                                plot.setTextInputCursorIndex(newCursorIndex);
                                            }
                                            break;
                                        } else if (cursorIndex == charCount + lines[i].length() + 1) {
                                            newCursorIndex = charCount;
                                            plot.setTextInputCursorIndex(newCursorIndex);
                                            break;
                                        }
                                        charCount += lines[i].length() + 1;
                                    }
                                }
                            }
                        }
                        break;
                    case SWT.ARROW_LEFT:
                        plot.moveSelectedMask(event.keyCode);
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() > 0) {
                                    plot.setTextInputCursorIndex(plot.getTextInputCursorIndex() - 1);
                                }
                            }
                        }
                        break;
                    case SWT.ARROW_RIGHT:
                        plot.moveSelectedMask(event.keyCode);
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() < plot.getTextInputContent().length()) {
                                    plot.setTextInputCursorIndex(plot.getTextInputCursorIndex() + 1);
                                }
                            }
                        }
                        break;
                    case SWT.ARROW_DOWN:
                        plot.moveSelectedMask(event.keyCode);
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() >= 0) {
                                    String text = plot.getTextInputContent();
                                    int cursorIndex = plot.getTextInputCursorIndex();
                                    String[] lines = text.split("\n", 100);
                                    int cursorX = 0;
                                    int charCount = 0;
                                    int newCursorIndex = cursorIndex;
                                    for (int i = 0; i < lines.length; i++) {
                                        if (cursorIndex >= charCount
                                                && cursorIndex < charCount + lines[i].length() + 1) {
                                            cursorX = cursorIndex - charCount;
                                            if (i < lines.length - 1) {
                                                if (cursorX <= lines[i + 1].length()) {
                                                    newCursorIndex = charCount + lines[i].length() + 1
                                                            + cursorX;
                                                } else {
                                                    newCursorIndex = charCount + lines[i].length() + 1
                                                            + lines[i + 1].length();
                                                }
                                                plot.setTextInputCursorIndex(newCursorIndex);
                                            }
                                            break;
                                        }
                                        charCount += lines[i].length() + 1;
                                    }
                                }
                            }
                        }
                        break;
                    case SWT.ESC:
                        plot.cancelTextInput();
                    case SWT.SHIFT:
                        break;
                    case SWT.CTRL:
                        break;
                    case SWT.ALT:
                        break;
                    case SWT.F1:
                        break;
                    case SWT.F2:
                        break;
                    case SWT.F3:
                        break;
                    case SWT.F4:
                        break;
                    case SWT.F5:
                        break;
                    case SWT.F6:
                        break;
                    case SWT.F7:
                        break;
                    case SWT.F8:
                        break;
                    case SWT.F9:
                        break;
                    case SWT.F10:
                        break;
                    case SWT.F11:
                        break;
                    case SWT.F12:
                        break;
                    case SWT.PAGE_UP:
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() >= 0) {
                                    String text = plot.getTextInputContent();
                                    int cursorIndex = plot.getTextInputCursorIndex();
                                    String[] lines = text.split("\n", 100);
                                    int cursorX = 0;
                                    int charCount = 0;
                                    int newLine = 0;
                                    for (int i = 0; i < lines.length; i++) {
                                        if (cursorIndex >= charCount
                                                && cursorIndex < charCount + lines[i].length() + 1) {
                                            cursorX = cursorIndex - charCount;
                                            if (i > 0) {
                                                newLine = i - 5;
                                                if (newLine < 0) {
                                                    newLine = 0;
                                                }
                                                jumpToPosition(newLine, cursorX);
                                            }
                                            break;
                                        }
                                        charCount += lines[i].length() + 1;
                                    }
                                }
                            }
                        }
                        break;
                    case SWT.PAGE_DOWN:
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() >= 0) {
                                    String text = plot.getTextInputContent();
                                    int cursorIndex = plot.getTextInputCursorIndex();
                                    String[] lines = text.split("\n", 100);
                                    int cursorX = 0;
                                    int charCount = 0;
                                    int newLine = 0;
                                    for (int i = 0; i < lines.length; i++) {
                                        if (cursorIndex >= charCount
                                                && cursorIndex < charCount + lines[i].length() + 1) {
                                            cursorX = cursorIndex - charCount;
                                            if (i < lines.length - 1) {
                                                newLine = i + 5;
                                                if (newLine >= lines.length) {
                                                    newLine = lines.length - 1;
                                                }
                                                jumpToPosition(newLine, cursorX);
                                            }
                                            break;
                                        }
                                        charCount += lines[i].length() + 1;
                                    }
                                }
                            }
                        }
                        break;
                    case SWT.HOME:
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() >= 0) {
                                    String text = plot.getTextInputContent();
                                    int cursorIndex = plot.getTextInputCursorIndex();
                                    String[] lines = text.split("\n", 100);
                                    int charCount = 0;
                                    for (int i = 0; i < lines.length; i++) {
                                        if (cursorIndex >= charCount
                                                && cursorIndex <= charCount + lines[i].length()) {
                                            plot.setTextInputCursorIndex(charCount);
                                            break;
                                        }
                                        charCount += lines[i].length() + 1;
                                    }
                                }
                            }
                        }
                        break;
                    case SWT.END:
                        if (plot.isCurrentlyInputtingText()) {
                            if (plot.getTextInputContent() != null) {
                                if (plot.getTextInputCursorIndex() >= 0) {
                                    String text = plot.getTextInputContent();
                                    int cursorIndex = plot.getTextInputCursorIndex();
                                    String[] lines = text.split("\n", 100);
                                    int charCount = 0;
                                    for (int i = 0; i < lines.length; i++) {
                                        if (cursorIndex >= charCount
                                                && cursorIndex <= charCount + lines[i].length()) {
                                            plot.setTextInputCursorIndex(charCount + lines[i].length());
                                            break;
                                        }
                                        charCount += lines[i].length() + 1;
                                    }
                                }
                            }
                        }
                        break;
                    case SWT.BS:
                        if (plot.isCurrentlyInputtingText()) {
                            String inputText;
                            String textInputContent = plot.getTextInputContent();
                            int cursorIndex = plot.getTextInputCursorIndex();
                            int newIndex;
                            if (textInputContent == null || cursorIndex <= 0
                                    || textInputContent.length() == 0) {
                                return;
                            } else if (cursorIndex == 1) {
                                inputText = textInputContent.substring(1);
                                newIndex = 0;
                            } else if (cursorIndex < textInputContent.length()) {
                                newIndex = cursorIndex - 1;
                                inputText = textInputContent.substring(0, newIndex)
                                        + textInputContent.substring(cursorIndex);
                            } else {
                                inputText = textInputContent.substring(0, textInputContent.length() - 1);
                                newIndex = inputText.length();
                            }
                            plot.setTextInputContent(inputText);
                            plot.setTextInputCursorIndex(newIndex);
                        }
                        break;
                    case SWT.DEL:
                        if (plot.isCurrentlyInputtingText()) {
                            String inputText;
                            String textInputContent = plot.getTextInputContent();
                            int cursorIndex = plot.getTextInputCursorIndex();
                            int newIndex = cursorIndex;
                            if (textInputContent == null || textInputContent.length() == 0
                                    || cursorIndex >= textInputContent.length()) {
                                return;
                            } else if (cursorIndex == 0) {
                                inputText = textInputContent.substring(1);
                            } else {
                                inputText = textInputContent.substring(0, cursorIndex)
                                        + textInputContent.substring(cursorIndex + 1);
                            }
                            plot.setTextInputContent(inputText);
                            plot.setTextInputCursorIndex(newIndex);
                        }
                        break;
                    case SWT.CAPS_LOCK:
                        break;
                    case SWT.INSERT:
                        break;
                    case SWT.NUM_LOCK:
                        break;
                    case SWT.PRINT_SCREEN:
                        break;
                    case SWT.SCROLL_LOCK:
                        break;
                    case SWT.PAUSE:
                        break;
                    default:
                        if (plot.isCurrentlyInputtingText()) {
                            if (Character.isWhitespace(event.character) && event.keyCode != SWT.SPACE) {
                                if (event.keyCode == SWT.CR || event.keyCode == SWT.LF
                                        || event.keyCode == 16777296) {
                                    addStringToTextInput("\n", plot.getTextInputCursorIndex());
                                }
                            } else {
                                addStringToTextInput(String.valueOf(event.character),
                                        plot.getTextInputCursorIndex());
                            }
                        }
                        break;
                    }
                    plot.repaint();
                }
            }

        };
        addKeyListener(keyListener);

        final Composite composite = this;

        chartMouseListener = new ChartMouseListener() {

            @Override
            public void chartMouseMoved(ChartMouseEvent event) {

            }

            @Override
            public void chartMouseClicked(ChartMouseEvent event) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (!composite.isDisposed() && !composite.isFocusControl()) {
                            composite.setFocus();
                        }
                    }
                });
            }
        };
        plot.addChartMouseListener(chartMouseListener);
    }
}

From source file:org.mwc.cmap.xyplot.views.XYPlotView.java

private void rtfToClipboard(final String fName, final Dimension dim) {
    // Issue #520 - Copy WMF embedded in RTF
    ByteArrayOutputStream os = null;
    DataInputStream dis = null;/* w  ww . ja v  a 2  s .  co  m*/
    try {
        os = new ByteArrayOutputStream();
        RTFWriter writer = new RTFWriter(os);
        File file = new File(fName);
        byte[] data = new byte[(int) file.length()];
        dis = new DataInputStream(new FileInputStream(file));
        dis.readFully(data);
        writer.writeHeader();
        writer.writeEmfPicture(data, dim.getWidth(), dim.getHeight());
        writer.writeTail();

        RTFTransfer rtfTransfer = RTFTransfer.getInstance();
        Clipboard clipboard = new Clipboard(Display.getDefault());
        Object[] rtfData = new Object[] { os.toString() };
        clipboard.setContents(rtfData, new Transfer[] { rtfTransfer });
    } catch (final Exception e1) {
        IStatus status = new Status(IStatus.ERROR, PlotViewerPlugin.PLUGIN_ID, e1.getLocalizedMessage(), e1);
        XYPlotPlugin.getDefault().getLog().log(status);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e1) {
                // ignore
            }
        }
        if (dis != null) {
            try {
                dis.close();
            } catch (IOException e1) {
                // ignore
            }
        }
    }

}

From source file:edu.harvard.i2b2.analysis.ui.AnalysisComposite.java

public void setupEventTree(ArrayList<ObservationType> oset, EventSet eventSet) {
    tree1.removeAll();//from www .java2  s.  c  om

    for (int k = 0; k < eventSet.getEvent().size(); k++) {
        EventType event = eventSet.getEvent().get(k);

        TreeItem eventItem = new TreeItem(tree1, SWT.NONE);
        eventItem.setText(event.getEventId().getValue());
        eventItem.setImage(new Image(Display.getDefault(), this.getClass().getClassLoader()
                .getResourceAsStream("edu/harvard/i2b2/imageExplorer/ui/core-cell.gif")));

        // for(int i=0; i<oset.size(); i++) {
        // ObservationSet set = oset.get(i);
        for (int j = 0; j < oset.size(); j++) {
            ObservationType obs = oset.get(j);
            if (obs.getEventId().getValue().equalsIgnoreCase(event.getEventId().getValue())) {
                TreeItem item = new TreeItem(eventItem, SWT.NONE);
                item.setText(obs.getConceptCd().getValue());
                // obs.getTvalChar().substring(obs.getTvalChar().lastIndexOf(
                // "/")+1));
                item.setImage(new Image(Display.getDefault(), this.getClass().getClassLoader()
                        .getResourceAsStream("edu/harvard/i2b2/imageExplorer/ui/core-cell.gif")));
                item.setData(new Integer(j + 1).toString());
                item.setData("Observation", obs);

                tree1.showItem(item);
            }
        }
        // }
    }
}

From source file:com.planetmayo.debrief.satc_rcp.views.MaintainContributionsView.java

private Color colorFor(BaseContribution contribution) {

    if (assignedColors == null) {
        assignedColors = new HashMap<BaseContribution, Color>();
    }/* w  w  w .ja v  a  2  s.  co  m*/

    // have we already assigned this one?
    Color res = assignedColors.get(contribution);

    if (res == null) {
        int index = assignedColors.size() % defaultColors.length;
        java.awt.Color newCol = defaultColors[index];
        res = new Color(Display.getDefault(), newCol.getRed(), newCol.getGreen(), newCol.getBlue());
        assignedColors.put(contribution, res);
    }

    return res;

}

From source file:org.gumtree.vis.swt.PlotComposite.java

public void handleException(final Exception e) {
    Display display = Display.getCurrent();
    if (display == null) {
        display = Display.getDefault();
    }/*from ww  w. ja va2  s .com*/
    display.asyncExec(new Runnable() {
        @Override
        public void run() {
            if (getShell() != null) {
                MessageBox messageBox = new MessageBox(getShell(), SWT.ICON_WARNING | SWT.OK);
                messageBox.setText("Failed to Save");
                messageBox.setMessage("failed : " + e.getMessage());
                messageBox.open();
                //               MessageDialog.openError(getShell(), "Failed to Save", "failed to save " +
                //                     "the image: " + e.getMessage());

            }
        }
    });
}

From source file:org.gumtree.vis.swt.PlotComposite.java

public void clear() {
    if (this.plot != null) {
        if (plot instanceof JPanel) {
            Display.getDefault().asyncExec(new Runnable() {

                @Override// w w w . j  av  a2 s.c o  m
                public void run() {
                    frame.remove((JPanel) plot);
                    if (emptyPanel != null) {
                        frame.add(emptyPanel);
                    }
                    removeListeners(plot);
                    plot = null;
                    if (!isDisposed()) {
                        pack();
                        getParent().layout(true, true);
                    }
                    frame.repaint();
                }
            });
        } else {
            throw new IllegalArgumentException("must be a chart plot panel");
        }
    }
}

From source file:fr.inria.soctrace.framesoc.ui.histogram.view.HistogramView.java

/**
 * Display the chart in the UI thread, using the loaded interval.
 * //  www.  j av a2s  .c  o m
 * @param chart
 *            jfreechart chart
 * @param histogramInterval
 *            displayed interval
 * @param first
 *            flag indicating if it is the first refresh for a given load
 */
private void displayChart(final JFreeChart chart, final TimeInterval displayed, final boolean first) {
    // prepare the new histogram UI
    Display.getDefault().syncExec(new Runnable() {
        @Override
        public void run() {
            // Clean parent
            for (Control c : compositeChart.getChildren()) {
                c.dispose();
            }
            // histogram chart
            chartFrame = new ChartComposite(compositeChart, SWT.NONE, chart, USE_BUFFER) {

                @Override
                public void mouseMove(MouseEvent e) {
                    super.mouseMove(e);

                    // update cursor
                    if (!isInDataArea(e.x, e.y)) {
                        getShell().setCursor(ARROW_CURSOR);
                    } else {
                        if (dragInProgress || (activeSelection && (isNear(e.x, selectedTs0))
                                || isNear(e.x, selectedTs1))) {
                            getShell().setCursor(IBEAM_CURSOR);
                        } else {
                            getShell().setCursor(ARROW_CURSOR);
                        }
                    }

                    // update marker
                    long v = getTimestampAt(e.x);
                    if (dragInProgress) {
                        // when drag is in progress, the moving side is always Ts1
                        selectedTs1 = v;
                        long min = Math.min(selectedTs0, selectedTs1);
                        long max = Math.max(selectedTs0, selectedTs1);
                        marker.setStartValue(min);
                        marker.setEndValue(max);
                        timeChanged = true;
                        timeBar.setSelection(min, max);
                    }

                    // update status line
                    updateStatusLine(v);
                }

                @Override
                public void mouseUp(MouseEvent e) {
                    super.mouseUp(e);

                    dragInProgress = false;
                    selectedTs1 = getTimestampAt(e.x);
                    if (selectedTs0 > selectedTs1) {
                        // reorder Ts0 and Ts1
                        long tmp = selectedTs1;
                        selectedTs1 = selectedTs0;
                        selectedTs0 = tmp;
                    } else if (selectedTs0 == selectedTs1) {
                        marker.setStartValue(selectedTs0);
                        marker.setEndValue(selectedTs0);
                        activeSelection = false;
                        timeBar.setSelection(loadedInterval);
                        updateStatusLine(selectedTs0);
                    }
                }

                @Override
                public void mouseDown(MouseEvent e) {
                    super.mouseDown(e);

                    if (activeSelection) {
                        if (isNear(e.x, selectedTs0)) {
                            // swap in order to have Ts1 as moving side
                            long tmp = selectedTs0;
                            selectedTs0 = selectedTs1;
                            selectedTs1 = tmp;
                        } else if (isNear(e.x, selectedTs1)) {
                            // nothing to do if the moving side is already Ts1
                        } else {
                            // near to no one: remove marker and add a new one
                            removeMarker();
                            selectedTs0 = getTimestampAt(e.x);
                            addNewMarker(selectedTs0, selectedTs0);
                        }
                    } else {
                        removeMarker();
                        selectedTs0 = getTimestampAt(e.x);
                        addNewMarker(selectedTs0, selectedTs0);
                    }
                    activeSelection = true;
                    dragInProgress = true;
                }

                private boolean isNear(int pos, long value) {
                    final int RANGE = 3;
                    int vPos = getPosAt(value);
                    if (Math.abs(vPos - pos) <= RANGE) {
                        return true;
                    }
                    return false;
                }

                boolean isInDataArea(int x, int y) {
                    if (chartFrame != null) {
                        org.eclipse.swt.graphics.Rectangle swtRect = chartFrame.getScreenDataArea();
                        Rectangle2D screenDataArea = new Rectangle();
                        screenDataArea.setRect(swtRect.x, swtRect.y, swtRect.width, swtRect.height);
                        return swtRect.contains(x, y);
                    }
                    return false;
                }
            };

            chartFrame.addMouseWheelListener(new MouseWheelListener() {

                @Override
                public void mouseScrolled(MouseEvent e) {
                    if ((e.stateMask & SWT.CTRL) == SWT.CTRL) {
                        if (e.count > 0) {
                            // zoom in
                            zoomChartAxis(true, e.x, e.y);
                        } else {
                            // zoom out
                            zoomChartAxis(false, e.x, e.y);
                        }
                    }
                }

                private void zoomChartAxis(boolean increase, int x, int y) {
                    double min = plot.getDomainAxis().getRange().getLowerBound();
                    double max = plot.getDomainAxis().getRange().getUpperBound();
                    X_FORMAT.setContext((long) min, (long) max, true);
                    Point2D p = chartFrame.translateScreenToJava2D(new Point(x, y));
                    PlotRenderingInfo plotInfo = chartFrame.getChartRenderingInfo().getPlotInfo();

                    if (increase) {
                        double dmin = min;
                        double dmax = max;
                        if (dmin <= 0) {
                            double inc = -2 * dmin + 1;
                            dmin += inc;
                            dmax += inc;
                        }
                        double diff = (dmax - dmin) / dmin;
                        if (diff >= 0.01) {
                            // zoom only if the (max - min) is at least 1% of the min
                            plot.zoomDomainAxes(0.5, plotInfo, p, true);
                        }
                    } else {
                        // XXX On Fedora 17 this always dezoom all
                        plot.zoomDomainAxes(-0.5, plotInfo, p, true);
                    }

                    // adjust
                    min = plot.getDomainAxis().getRange().getLowerBound();
                    max = plot.getDomainAxis().getRange().getUpperBound();
                    Range maxRange = new Range(Math.max(loadedInterval.startTimestamp, min),
                            Math.min(loadedInterval.endTimestamp, max));
                    plot.getDomainAxis().setRange(maxRange);

                }
            });

            // - size
            chartFrame.setSize(compositeChart.getSize());
            // - prevent y zooming
            chartFrame.setRangeZoomable(false);
            // - prevent x zooming (we do it manually with wheel)
            chartFrame.setDomainZoomable(false);
            // - workaround for last xaxis tick not shown (jfreechart bug)
            RectangleInsets insets = plot.getInsets();
            plot.setInsets(new RectangleInsets(insets.getTop(), insets.getLeft(), insets.getBottom(), 25));
            // - time bounds
            plot.getDomainAxis().setLowerBound(displayed.startTimestamp);
            plot.getDomainAxis().setUpperBound(displayed.endTimestamp);
            // producers and types
            if (first) {
                for (ConfigurationData data : configurationMap.values()) {
                    data.tree.getViewer().setInput(data.roots);
                    data.tree.setCheckedElements(data.checked);
                    data.tree.getViewer().refresh();
                    data.tree.getViewer().expandAll();
                }
            }
            // timebar
            timeBar.setSelection(loadedInterval);
        }
    });

}