Search in sources :

Example 1 with ViewNotifier

use of org.sirix.gui.view.ViewNotifier in project sirix by sirixdb.

the class SunburstControl method mousePressed.

/**
 * Implements processing mousePressed.
 *
 * @param pEvent
 *          The {@link MouseEvent}.
 *
 * @see processing.core.PApplet#mousePressed
 */
@Override
public void mousePressed(final MouseEvent pEvent) {
    mSunburstGUI.getControlP5().controlWindow.mouseEvent(pEvent);
    mSunburstGUI.zoomMouseEvent(pEvent);
    mSunburstGUI.setShowGUI(mSunburstGUI.getControlP5().getGroup("menu").isOpen());
    if (!mSunburstGUI.isShowGUI() && mSunburstGUI.mDone) {
        boolean doMouseOver = true;
        if (mSunburstGUI.mRevisions != null && mSunburstGUI.mRevisions.isOpen()) {
            doMouseOver = false;
        }
        if (doMouseOver) {
            // Mouse rollover.
            if (!mSunburstGUI.mParent.keyPressed) {
                if (mSunburstGUI.mHitTestIndex != -1) {
                    synchronized (mSunburstGUI) {
                        mHitTestIndex = mSunburstGUI.mHitTestIndex;
                    }
                    mSunburstGUI.pushImg();
                    // Bug in processing's mousbotton, thus used SwingUtilities.
                    if (SwingUtilities.isLeftMouseButton(pEvent) && !mSunburstGUI.mCtrl.isOpen()) {
                        final SunburstContainer container = new SunburstContainer(mSunburstGUI, mModel);
                        if (mSunburstGUI.mUsePruning) {
                            if (mSunburstGUI.mUseDiffView == ViewType.DIFF && mSunburstGUI.mUseDiffView.getValue()) {
                                container.setPruning(Pruning.DIFF);
                            } else {
                                container.setPruning(Pruning.DEPTH);
                            }
                        } else {
                            container.setPruning(Pruning.NO);
                        }
                        container.setMoveDetection(mSunburstGUI.mUseMoveDetection);
                        final SunburstView view = (SunburstView) ((Embedded) mSunburstGUI.mParent).getView();
                        final ViewNotifier notifier = view.getNotifier();
                        final SunburstItem item = mModel.getItem(mHitTestIndex);
                        notifier.getGUI().getReadDB().setKey(item.getKey());
                        if (mSunburstGUI.mUseDiffView == ViewType.DIFF) {
                            LOGWRAPPER.debug("old rev: " + container.getOldRevision());
                            mModel.update(container.setAll(mSunburstGUI.mSelectedRev, item.getDepth(), mSunburstGUI.getModificationWeight()).setNewStartKey(item.getKey()).setDiff(item.getDiff()));
                        } else {
                            mModel.update(container.setNewStartKey(item.getKey()));
                        }
                        refreshed(container, mHitTestIndex);
                    } else if (SwingUtilities.isRightMouseButton(pEvent)) {
                        if (mSunburstGUI.mUseDiffView == ViewType.NODIFF) {
                            try {
                                ((SunburstModel) mModel).popupMenu(pEvent, mSunburstGUI.mCtrl, mHitTestIndex);
                            } catch (final SirixException e) {
                                LOGWRAPPER.error(e.getMessage(), e);
                                JOptionPane.showMessageDialog(mSunburstGUI.mParent, this, "Failed to commit change: " + e.getMessage(), JOptionPane.ERROR_MESSAGE);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ViewNotifier(org.sirix.gui.view.ViewNotifier) SirixException(org.sirix.exception.SirixException)

Example 2 with ViewNotifier

use of org.sirix.gui.view.ViewNotifier in project sirix by sirixdb.

the class SunburstControl method keyReleased.

/**
 * Is getting called from processings keyRealeased-method and implements it.
 *
 * @see processing.core.PApplet#keyReleased()
 */
@Override
public void keyReleased() {
    if (!mSunburstGUI.mXPathField.isActive() && !mSunburstGUI.mCtrl.isOpen()) {
        switch(mSunburstGUI.mParent.key) {
            case 'r':
            case 'R':
                mSunburstGUI.mParent.frameRate(35);
                mSunburstGUI.mRad = 0;
                mSunburstGUI.resetZoom();
                mSunburstGUI.mZoomPanReset = true;
                break;
            case 's':
            case 'S':
                // Save PNG.
                mSunburstGUI.mParent.saveFrame(ViewUtilities.SAVEPATH + ViewUtilities.timestamp() + "_##.png");
                break;
            case 'p':
            case 'P':
                // Save PDF.
                mSunburstGUI.mParent.frameRate(60);
                mSunburstGUI.setSavePDF(true);
                PApplet.println("\n" + "saving to pdf – starting");
                mSunburstGUI.mParent.beginRecord(PConstants.PDF, ViewUtilities.SAVEPATH + ViewUtilities.timestamp() + ".pdf");
                mSunburstGUI.mParent.textMode(PConstants.SHAPE);
                break;
            case 'q':
                // mSunburstGUI.setViewKind(EView.NODIFF);
                ((Embedded) mSunburstGUI.mParent).refreshUpdate();
                break;
            case '\b':
                // Backspace.
                mModel.undo();
                mSunburstGUI.undo();
                final SunburstView view = (SunburstView) ((Embedded) mSunburstGUI.mParent).getView();
                final ViewNotifier notifier = view.getNotifier();
                notifier.getGUI().getReadDB().setKey(mModel.getItem(0).getKey());
                notifyChanges(mModel.subList(0, mModel.getItemsSize()));
                break;
            case '1':
                mSunburstGUI.setMappingMode(1);
                break;
            case '2':
                mSunburstGUI.setMappingMode(2);
                break;
            case '3':
                mSunburstGUI.setMappingMode(3);
                break;
            case 'o':
            case 'O':
                if (mSunburstGUI.mUseDiffView == ViewType.NODIFF) {
                    mSunburstGUI.mUseDiffView.setValue(true);
                    mSunburstGUI.mRevisions = mSunburstGUI.getControlP5().addDropdownList("Compare revision", mSunburstGUI.mParent.width - 250, 100, 100, 120);
                    assert mSunburstGUI.mDb != null;
                    try {
                        for (long i = mSunburstGUI.mDb.getRevisionNumber() + 1, newestRev = mSunburstGUI.mDb.getSession().beginNodeReadTrx().getRevisionNumber(); i <= newestRev; i++) {
                            mSunburstGUI.mRevisions.addItem("Revision " + i, (int) i);
                        }
                    } catch (final SirixException e) {
                        LOGWRAPPER.error(e.getMessage(), e);
                        JOptionPane.showMessageDialog(mSunburstGUI.mParent, this, "Failed to open read transaction: " + e.getMessage(), JOptionPane.ERROR_MESSAGE);
                    }
                }
                break;
            default:
        }
        switch(mSunburstGUI.mParent.key) {
            case '1':
            case '2':
            case '3':
                mSunburstGUI.update(EResetZoomer.YES);
                break;
            case 'm':
            case 'M':
                mSunburstGUI.setShowGUI(mSunburstGUI.getControlP5().getGroup("menu").isOpen());
                mSunburstGUI.setShowGUI(!mSunburstGUI.isShowGUI());
                break;
            default:
        }
        final ControllerGroup<?> menu = mSunburstGUI.getControlP5().getGroup("menu");
        if (mSunburstGUI.isShowGUI()) {
            menu.open();
            mSunburstGUI.getApplet().frameRate(5);
        } else {
            menu.close();
            mSunburstGUI.getApplet().frameRate(40);
        }
        if (mSunburstGUI.mParent.keyCode == PConstants.RIGHT) {
            mSunburstGUI.mRad += 5;
            mSunburstGUI.mRadChanged = true;
        } else if (mSunburstGUI.mParent.keyCode == PConstants.LEFT) {
            mSunburstGUI.mRad -= 5;
            mSunburstGUI.mRadChanged = true;
        }
    }
}
Also used : ViewNotifier(org.sirix.gui.view.ViewNotifier) SirixException(org.sirix.exception.SirixException) Embedded(org.sirix.gui.view.sunburst.SunburstView.Embedded)

Example 3 with ViewNotifier

use of org.sirix.gui.view.ViewNotifier in project sirix by sirixdb.

the class SunburstControl method notifyChanges.

/**
 * Notify other views of changes.
 *
 * @param pItems
 *          the new item list
 */
private void notifyChanges(final List<SunburstItem> pItems) {
    assert pItems != null;
    final SunburstView view = (SunburstView) ((Embedded) mSunburstGUI.mParent).getView();
    final ViewNotifier notifier = view.getNotifier();
    if (mModel instanceof SunburstModel) {
        notifier.update(view, Optional.<VisualItemAxis>absent());
    } else if (mModel instanceof SunburstCompareModel) {
        notifier.update(view, Optional.of(new VisualItemAxis(pItems)));
    }
}
Also used : VisualItemAxis(org.sirix.gui.view.VisualItemAxis) SunburstCompareModel(org.sirix.gui.view.sunburst.model.SunburstCompareModel) ViewNotifier(org.sirix.gui.view.ViewNotifier) SunburstModel(org.sirix.gui.view.sunburst.model.SunburstModel)

Example 4 with ViewNotifier

use of org.sirix.gui.view.ViewNotifier in project sirix by sirixdb.

the class SunburstControl method controlEvent.

@Override
public void controlEvent(final ControlEvent pControlEvent) {
    super.controlEvent(pControlEvent);
    if (pControlEvent.isGroup()) {
        if (pControlEvent.getGroup().getName().equals("Compare revision")) {
            mSunburstGUI.mParent.noLoop();
            mSunburstGUI.mSelectedRev = (int) pControlEvent.getGroup().getValue();
            final int selectedRev = mSunburstGUI.mSelectedRev;
            mModel = new SunburstCompareModel(mSunburstGUI.mParent, mSunburstGUI.mDb);
            mModel.addPropertyChangeListener(mSunburstGUI);
            final SunburstContainer container = new SunburstContainer(mSunburstGUI, mModel);
            if (mSunburstGUI.mUsePruning) {
                container.setPruning(Pruning.DIFF);
            } else {
                container.setPruning(Pruning.NO);
            }
            container.setMoveDetection(mSunburstGUI.mUseMoveDetection);
            mModel.traverseTree(container.setRevision(selectedRev).setModWeight(mSunburstGUI.getModificationWeight()));
            mSunburstGUI.mUseDiffView = ViewType.DIFF;
            mSunburstGUI.mUseDiffView.setValue(true);
            final SunburstView view = (SunburstView) ((Embedded) mSunburstGUI.mParent).getView();
            final ViewNotifier notifier = view.getNotifier();
            mDb.setCompareRevisionNumber(selectedRev);
            notifier.init(view);
        }
    } else if (pControlEvent.isController()) {
        if (pControlEvent.getController() instanceof Toggle) {
            final Toggle toggle = (Toggle) pControlEvent.getController();
            final boolean state = toggle.getState();
            switch(toggle.getId()) {
                case 3:
                    mSunburstGUI.setUseArc(state);
                    break;
                case 4:
                    mSunburstGUI.setFisheye(state);
                    break;
                case 5:
                    if (state) {
                        mRefresh = true;
                    }
                    mSunburstGUI.setUsePruning(state);
                    break;
                case 6:
                    mSunburstGUI.setUseAttribute(state);
                    break;
                case 7:
                    mSunburstGUI.setUseMoveDetection(state);
                    break;
            }
        }
    }
}
Also used : SunburstCompareModel(org.sirix.gui.view.sunburst.model.SunburstCompareModel) ViewNotifier(org.sirix.gui.view.ViewNotifier) Toggle(controlP5.Toggle)

Aggregations

ViewNotifier (org.sirix.gui.view.ViewNotifier)4 SirixException (org.sirix.exception.SirixException)2 SunburstCompareModel (org.sirix.gui.view.sunburst.model.SunburstCompareModel)2 Toggle (controlP5.Toggle)1 VisualItemAxis (org.sirix.gui.view.VisualItemAxis)1 Embedded (org.sirix.gui.view.sunburst.SunburstView.Embedded)1 SunburstModel (org.sirix.gui.view.sunburst.model.SunburstModel)1