public ScrollingModelImpl(EditorImpl editor) { myEditor = editor; myEditor.getScrollPane().getViewport().addChangeListener(new ChangeListener() { private Rectangle myLastViewRect; @Override public void stateChanged(ChangeEvent event) { Rectangle viewRect = getVisibleArea(); VisibleAreaEvent visibleAreaEvent = new VisibleAreaEvent(myEditor, myLastViewRect, viewRect); if (!myViewportPositioned && viewRect.height > 0) { myViewportPositioned = true; if (adjustVerticalOffsetIfNecessary()) { return; } } myLastViewRect = viewRect; for (VisibleAreaListener listener : myVisibleAreaListeners) { listener.visibleAreaChanged(visibleAreaEvent); } } }); myDocumentListener = new DocumentAdapter() { @Override public void beforeDocumentChange(DocumentEvent e) { cancelAnimatedScrolling(true); } }; myEditor.getDocument().addDocumentListener(myDocumentListener); }
private void initListenerIfNecessary() { // We can't attach the listener during this object initialization because there is a big chance that the editor is in incomplete // state there (e.g. it's scrolling model is not initialized yet). if (myVisualAreaListenerAttached) { return; } myVisualAreaListenerAttached = true; myEditor.getScrollingModel().addVisibleAreaListener(new VisibleAreaListener() { @Override public void visibleAreaChanged(VisibleAreaEvent e) { updateLastTopLeftCornerOffset(); } }); updateLastTopLeftCornerOffset(); }
private static void reflectivelyCheckCurrentListeners(String logLabel, Editor editor) { // Works in developement. Not in prod. try { if (editor.getScrollingModel().getClass().equals(ScrollingModelImpl.class)) { List<VisibleAreaListener> listeners = ReflectionUtil.getField(ScrollingModelImpl.class, editor.getScrollingModel(), List.class, "myVisibleAreaListeners"); logger.info(logLabel + ": editor=" + shortObjectString(editor) + " currentListeners=" + listShortObjects(listeners)); } } catch (Exception e) { logger.error("reflectivelyCheckCurrentListeners: error trying.", e); } }
@Override public void stateChanged(ChangeEvent event) { Rectangle viewRect = getVisibleArea(); VisibleAreaEvent visibleAreaEvent = new VisibleAreaEvent(myEditor, myLastViewRect, viewRect); if (!myViewportPositioned && viewRect.height > 0) { myViewportPositioned = true; if (adjustVerticalOffsetIfNecessary()) { return; } } myLastViewRect = viewRect; for (VisibleAreaListener listener : myVisibleAreaListeners) { listener.visibleAreaChanged(visibleAreaEvent); } }
@Override public VisibleAreaListener getVisibleAreaListener() { return myVisibleAreaListener; }
@Override public VisibleAreaListener getVisibleAreaListener() { return null; }
public DiffPanelImpl(final Window owner, @NotNull Project project, boolean enableToolbar, boolean horizontal, int diffDividerPolygonsOffset, DiffTool parentTool) { myProject = project; myIsHorizontal = horizontal; myParentTool = parentTool; myOptions = new DiffPanelOptions(this); myPanel = new DiffPanelOuterComponent(TextDiffType.DIFF_TYPES, null); myPanel.disableToolbar(!enableToolbar); if (enableToolbar) myPanel.resetToolbar(); myOwnerWindow = owner; myIsSyncScroll = true; final boolean v = !horizontal; myLeftSide = new DiffSideView(this, new CustomLineBorder(1, 0, v ? 0 : 1, v ? 0 : 1)); myRightSide = new DiffSideView(this, new CustomLineBorder(v ? 0 : 1, v ? 0 : 1, 1, 0)); myLeftSide.becomeMaster(); myDiffUpdater = new Rediffers(this); myDiffDividerPolygonsOffset = diffDividerPolygonsOffset; myData = createDiffPanelState(this); if (horizontal) { mySplitter = new DiffSplitter(myLeftSide.getComponent(), myRightSide.getComponent(), new DiffDividerPaint(this, FragmentSide.SIDE1, diffDividerPolygonsOffset), myData); } else { mySplitter = new HorizontalDiffSplitter(myLeftSide.getComponent(), myRightSide.getComponent()); } myPanel.insertDiffComponent(mySplitter.getComponent(), new MyScrollingPanel()); myDataProvider = new MyGenericDataProvider(this); myPanel.setDataProvider(myDataProvider); ComparisonPolicy comparisonPolicy = getComparisonPolicy(); if (comparisonPolicy != DiffManagerImpl.getInstanceEx().getComparisonPolicy()) { setComparisonPolicy(comparisonPolicy); } HighlightMode highlightMode = getHighlightMode(); if (highlightMode != DiffManagerImpl.getInstanceEx().getHighlightMode()) { setHighlightMode(highlightMode); } myVisibleAreaListener = new VisibleAreaListener() { @Override public void visibleAreaChanged(VisibleAreaEvent e) { Editor editor1 = getEditor1(); if (editor1 != null) { editor1.getComponent().repaint(); } Editor editor2 = getEditor2(); if (editor2 != null) { editor2.getComponent().repaint(); } } }; registerActions(); }
public void onContentChangedIn(EditorSource source) { myDiffUpdater.contentRemoved(source); final EditorEx editor = source.getEditor(); if (myIsHorizontal && source.getSide() == FragmentSide.SIDE1 && editor != null) { editor.setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT); } DiffSideView viewSide = getSideView(source.getSide()); viewSide.setEditorSource(getProject(), source); Disposer.dispose(myScrollSupport); if (editor == null) { if (!myDisposed) { rediff(); } return; } final MouseListener mouseListener = PopupHandler .installUnknownPopupHandler(editor.getContentComponent(), new MergeActionGroup(this, source.getSide()), ActionManager.getInstance()); myDiffUpdater.contentAdded(source); editor.getSettings().setLineNumbersShown(true); editor.getSettings().setFoldingOutlineShown(false); editor.getFoldingModel().setFoldingEnabled(false); ((EditorMarkupModel)editor.getMarkupModel()).setErrorStripeVisible(true); Editor editor1 = getEditor(FragmentSide.SIDE1); Editor editor2 = getEditor(FragmentSide.SIDE2); if (editor1 != null && editor2 != null && myIsSyncScroll) { myScrollSupport.install(new EditingSides[]{this}); } final VisibleAreaListener visibleAreaListener = mySplitter.getVisibleAreaListener(); final ScrollingModel scrollingModel = editor.getScrollingModel(); if (visibleAreaListener != null) { scrollingModel.addVisibleAreaListener(visibleAreaListener); scrollingModel.addVisibleAreaListener(myVisibleAreaListener); } myFontSizeSynchronizer.synchronize(editor); source.addDisposable(new Disposable() { public void dispose() { myFontSizeSynchronizer.stopSynchronize(editor); } }); source.addDisposable(new Disposable() { public void dispose() { if (visibleAreaListener != null) { scrollingModel.removeVisibleAreaListener(visibleAreaListener); scrollingModel.removeVisibleAreaListener(myVisibleAreaListener); } editor.getContentComponent().removeMouseListener(mouseListener); } }); }
@Override public void addVisibleAreaListener(@NotNull final VisibleAreaListener listener) { throw new UnsupportedOperationException("Not implemented"); }
@Override public void removeVisibleAreaListener(@NotNull final VisibleAreaListener listener) { throw new UnsupportedOperationException("Not implemented"); }
@Override public void addVisibleAreaListener(@NotNull VisibleAreaListener listener) { myVisibleAreaListeners.add(listener); }
@Override public void removeVisibleAreaListener(@NotNull VisibleAreaListener listener) { boolean success = myVisibleAreaListeners.remove(listener); LOG.assertTrue(success); }
public DiffPanelImpl(final Window owner, Project project, boolean enableToolbar, boolean horizontal, int diffDividerPolygonsOffset, DiffTool parentTool) { myProject = project; myIsHorizontal = horizontal; myParentTool = parentTool; myOptions = new DiffPanelOptions(this); myPanel = new DiffPanelOuterComponent(TextDiffType.DIFF_TYPES, null); myPanel.disableToolbar(!enableToolbar); if (enableToolbar) myPanel.resetToolbar(); myOwnerWindow = owner; myIsSyncScroll = true; final boolean v = !horizontal; myLeftSide = new DiffSideView(this, new CustomLineBorder(UIUtil.getBorderColor(), 1, 0, v ? 0 : 1, v ? 0 : 1)); myRightSide = new DiffSideView(this, new CustomLineBorder(UIUtil.getBorderColor(), v ? 0 : 1, v ? 0 : 1, 1, 0)); myLeftSide.becomeMaster(); myDiffUpdater = new Rediffers(this); myData = createDiffPanelState(this); if (horizontal) { mySplitter = new DiffSplitter(myLeftSide.getComponent(), myRightSide.getComponent(), new DiffDividerPaint(this, FragmentSide.SIDE1, diffDividerPolygonsOffset), myData); } else { mySplitter = new HorizontalDiffSplitter(myLeftSide.getComponent(), myRightSide.getComponent()); } myPanel.insertDiffComponent(mySplitter.getComponent(), new MyScrollingPanel()); myDataProvider = new MyGenericDataProvider(this); myPanel.setDataProvider(myDataProvider); final ComparisonPolicy comparisonPolicy = getComparisonPolicy(); final ComparisonPolicy defaultComparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy(); if (defaultComparisonPolicy != null && comparisonPolicy != defaultComparisonPolicy) { setComparisonPolicy(defaultComparisonPolicy); } myVisibleAreaListener = new VisibleAreaListener() { @Override public void visibleAreaChanged(VisibleAreaEvent e) { Editor editor1 = getEditor1(); if (editor1 != null) { editor1.getComponent().repaint(); } Editor editor2 = getEditor2(); if (editor2 != null) { editor2.getComponent().repaint(); } } }; registerActions(); }
@Override public void addVisibleAreaListener(final VisibleAreaListener listener) { throw new UnsupportedOperationException("Not implemented"); }
@Override public void removeVisibleAreaListener(final VisibleAreaListener listener) { throw new UnsupportedOperationException("Not implemented"); }
@Override public void addVisibleAreaListener(VisibleAreaListener listener) { myVisibleAreaListeners.add(listener); }
@Override public void removeVisibleAreaListener(VisibleAreaListener listener) { boolean success = myVisibleAreaListeners.remove(listener); LOG.assertTrue(success); }
public DiffPanelImpl(final Window owner, @Nonnull Project project, boolean enableToolbar, boolean horizontal, int diffDividerPolygonsOffset, DiffTool parentTool) { myProject = project; myIsHorizontal = horizontal; myParentTool = parentTool; myOptions = new DiffPanelOptions(this); myPanel = new DiffPanelOuterComponent(TextDiffType.DIFF_TYPES, null); myPanel.disableToolbar(!enableToolbar); if (enableToolbar) myPanel.resetToolbar(); myOwnerWindow = owner; myIsSyncScroll = true; final boolean v = !horizontal; myLeftSide = new DiffSideView(this, new CustomLineBorder(1, 0, v ? 0 : 1, v ? 0 : 1)); myRightSide = new DiffSideView(this, new CustomLineBorder(v ? 0 : 1, v ? 0 : 1, 1, 0)); myLeftSide.becomeMaster(); myDiffUpdater = new Rediffers(this); myDiffDividerPolygonsOffset = diffDividerPolygonsOffset; myData = createDiffPanelState(this); if (horizontal) { mySplitter = new DiffSplitter(myLeftSide.getComponent(), myRightSide.getComponent(), new DiffDividerPaint(this, FragmentSide.SIDE1, diffDividerPolygonsOffset), myData); } else { mySplitter = new HorizontalDiffSplitter(myLeftSide.getComponent(), myRightSide.getComponent()); } myPanel.insertDiffComponent(mySplitter.getComponent(), new MyScrollingPanel()); myDataProvider = new MyGenericDataProvider(this); myPanel.setDataProvider(myDataProvider); final ComparisonPolicy comparisonPolicy = getComparisonPolicy(); final ComparisonPolicy defaultComparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy(); final HighlightMode highlightMode = getHighlightMode(); final HighlightMode defaultHighlightMode = DiffManagerImpl.getInstanceEx().getHighlightMode(); if (defaultComparisonPolicy != null && comparisonPolicy != defaultComparisonPolicy) { setComparisonPolicy(defaultComparisonPolicy); } if (defaultHighlightMode != null && highlightMode != defaultHighlightMode) { setHighlightMode(defaultHighlightMode); } myVisibleAreaListener = new VisibleAreaListener() { @Override public void visibleAreaChanged(VisibleAreaEvent e) { Editor editor1 = getEditor1(); if (editor1 != null) { editor1.getComponent().repaint(); } Editor editor2 = getEditor2(); if (editor2 != null) { editor2.getComponent().repaint(); } } }; registerActions(); }
public void onContentChangedIn(EditorSource source) { myDiffUpdater.contentRemoved(source); final EditorEx editor = source.getEditor(); if (myIsHorizontal && source.getSide() == FragmentSide.SIDE1 && editor != null) { editor.setVerticalScrollbarOrientation(EditorEx.VERTICAL_SCROLLBAR_LEFT); } DiffSideView viewSide = getSideView(source.getSide()); viewSide.setEditorSource(getProject(), source); Disposer.dispose(myScrollSupport); if (editor == null) { if (!myDisposed) { rediff(); } return; } final MouseListener mouseListener = PopupHandler.installUnknownPopupHandler(editor.getContentComponent(), new MergeActionGroup(this, source.getSide()), ActionManager.getInstance()); myDiffUpdater.contentAdded(source); editor.getSettings().setLineNumbersShown(true); editor.getSettings().setFoldingOutlineShown(false); editor.getFoldingModel().setFoldingEnabled(false); ((EditorMarkupModel)editor.getMarkupModel()).setErrorStripeVisible(true); Editor editor1 = getEditor(FragmentSide.SIDE1); Editor editor2 = getEditor(FragmentSide.SIDE2); if (editor1 != null && editor2 != null && myIsSyncScroll) { myScrollSupport.install(new EditingSides[]{this}); } final VisibleAreaListener visibleAreaListener = mySplitter.getVisibleAreaListener(); final ScrollingModel scrollingModel = editor.getScrollingModel(); if (visibleAreaListener != null) { scrollingModel.addVisibleAreaListener(visibleAreaListener); scrollingModel.addVisibleAreaListener(myVisibleAreaListener); } myFontSizeSynchronizer.synchronize(editor); source.addDisposable(new Disposable() { public void dispose() { myFontSizeSynchronizer.stopSynchronize(editor); } }); source.addDisposable(new Disposable() { public void dispose() { if (visibleAreaListener != null) { scrollingModel.removeVisibleAreaListener(visibleAreaListener); scrollingModel.removeVisibleAreaListener(myVisibleAreaListener); } editor.getContentComponent().removeMouseListener(mouseListener); } }); }
@Override public void addVisibleAreaListener(@Nonnull final VisibleAreaListener listener) { throw new UnsupportedOperationException("Not implemented"); }
@Override public void removeVisibleAreaListener(@Nonnull final VisibleAreaListener listener) { throw new UnsupportedOperationException("Not implemented"); }
@Override public void addVisibleAreaListener(@Nonnull VisibleAreaListener listener) { myVisibleAreaListeners.add(listener); }
@Override public void removeVisibleAreaListener(@Nonnull VisibleAreaListener listener) { boolean success = myVisibleAreaListeners.remove(listener); LOG.assertTrue(success); }
void addVisibleAreaListener(@NotNull VisibleAreaListener listener);
void removeVisibleAreaListener(@NotNull VisibleAreaListener listener);
VisibleAreaListener getVisibleAreaListener();
void addVisibleAreaListener(VisibleAreaListener listener);
void removeVisibleAreaListener(VisibleAreaListener listener);
void addVisibleAreaListener(@Nonnull VisibleAreaListener listener);
void removeVisibleAreaListener(@Nonnull VisibleAreaListener listener);