public void prefferedSizeByContents(final int maximumLines) { if (getEditor1() == null && getEditor2() == null) return; if (getEditor1() != null) { getEditor1().getSettings().setAdditionalLinesCount(0); getEditor1().getSettings().setAdditionalPageAtBottom(false); } if (getEditor2() != null) { getEditor2().getSettings().setAdditionalLinesCount(0); getEditor2().getSettings().setAdditionalPageAtBottom(false); } myPanel.setPrefferedWidth(20); myPanel.setPreferredHeightGetter( new Getter<Integer>() { @Override public Integer get() { final int size1 = getEditor1() == null ? 10 : getEditor1().getComponent().getPreferredSize().height; final int size2 = getEditor2() == null ? 10 : getEditor2().getComponent().getPreferredSize().height; final int lineHeight = getEditor1() == null ? getEditor2().getLineHeight() : getEditor1().getLineHeight(); final int size = Math.max(size1, size2); if (maximumLines > 0) { return Math.min(size, maximumLines * lineHeight); } return size; } }); }
public void dispose() { myDisposed = true; myDiffUpdater.dispose(); Disposer.dispose(myScrollSupport); Disposer.dispose(myData); myPanel.cancelScrollEditors(); JComponent component = myPanel.getBottomComponent(); if (component instanceof Disposable) { Disposer.dispose((Disposable) component); } myPanel.setBottomComponent(null); myPanel.setDataProvider(null); myPanel.setScrollingPanel(null); }
public void setFileContentsAreIdentical() { if (myTopMessageDiffPanel == null || myTopMessageDiffPanel instanceof FileContentsAreIdenticalDiffPanel) { LineSeparator sep1 = myData.getContent1() == null ? null : myData.getContent1().getLineSeparator(); LineSeparator sep2 = myData.getContent2() == null ? null : myData.getContent2().getLineSeparator(); if (LineSeparator.knownAndDifferent(sep1, sep2)) { myTopMessageDiffPanel = new LineSeparatorsOnlyDiffPanel(); } else { myTopMessageDiffPanel = new FileContentsAreIdenticalDiffPanel(); } myPanel.insertTopComponent(myTopMessageDiffPanel); } }
void rediff() { try { if (myTopMessageDiffPanel != null) { myPanel.removeTopComponent(myTopMessageDiffPanel); } LineBlocks blocks = myData.updateEditors(); setLineBlocks(blocks != null ? blocks : LineBlocks.EMPTY); if (blocks != null && blocks.getCount() == 0) { if (myData.isContentsEqual()) { setFileContentsAreIdentical(); } } } catch (FilesTooBigForDiffException e) { setTooBigFileErrorContents(); } }
public void setContents(DiffContent content1, DiffContent content2) { LOG.assertTrue(content1 != null && content2 != null); LOG.assertTrue(!myDisposed); myData.setContents(content1, content2); Project project = myData.getProject(); FileType[] types = DiffUtil.chooseContentTypes(new DiffContent[] {content1, content2}); VirtualFile beforeFile = content1.getFile(); VirtualFile afterFile = content2.getFile(); String path = myDiffRequest == null ? null : myDiffRequest.getWindowTitle(); myLeftSide.setHighlighterFactory( createHighlighter(types[0], beforeFile, afterFile, path, project)); myRightSide.setHighlighterFactory( createHighlighter(types[1], afterFile, beforeFile, path, project)); setSplitterProportion(content1, content2); rediff(); if (myIsRequestFocus) { myPanel.requestScrollEditors(); } }
public void setDiffRequest(DiffRequest data) { myDiffRequest = data; if (data.getHints().contains(DiffTool.HINT_DO_NOT_IGNORE_WHITESPACES)) { setComparisonPolicy(ComparisonPolicy.DEFAULT, false); } myDataProvider.putData(myDiffRequest.getGenericData()); DiffContent content1 = data.getContents()[0]; DiffContent content2 = data.getContents()[1]; setContents(content1, content2); setTitles(data); setWindowTitle(myOwnerWindow, data.getWindowTitle()); myPanel.setToolbarActions(createToolbar()); data.customizeToolbar(myPanel.resetToolbar()); myPanel.registerToolbarActions(); initEditorSettings(getEditor1()); initEditorSettings(getEditor2()); final JComponent oldBottomComponent = myPanel.getBottomComponent(); if (oldBottomComponent instanceof Disposable) { Disposer.dispose((Disposable) oldBottomComponent); } final JComponent newBottomComponent = data.getBottomComponent(); myPanel.setBottomComponent(newBottomComponent); if (myIsRequestFocus) { IdeFocusManager fm = IdeFocusManager.getInstance(myProject); boolean isEditor1Focused = getEditor1() != null && fm.getFocusedDescendantFor(getEditor1().getComponent()) != null; boolean isEditor2Focused = myData.getContent2() != null && getEditor2() != null && fm.getFocusedDescendantFor(getEditor2().getComponent()) != null; if (isEditor1Focused || isEditor2Focused) { Editor e = isEditor2Focused ? getEditor2() : getEditor1(); if (e != null) { fm.requestFocus(e.getContentComponent(), true); } } myPanel.requestScrollEditors(); } }
private void updateStatusBar() { myPanel.setStatusBarText(getNumDifferencesText()); }
public void setPatchAppliedApproximately() { if (!(myTopMessageDiffPanel instanceof CanNotCalculateDiffPanel)) { myTopMessageDiffPanel = new DiffIsApproximate(); myPanel.insertTopComponent(myTopMessageDiffPanel); } }
public void setTooBigFileErrorContents() { setLineBlocks(LineBlocks.EMPTY); myTopMessageDiffPanel = new CanNotCalculateDiffPanel(); myPanel.insertTopComponent(myTopMessageDiffPanel); }
public void enableToolbar(final boolean value) { myPanel.disableToolbar(!value); }
public void removeStatusBar() { myPanel.removeStatusBar(); }
public void reset() { // myUi.getContentManager().removeAllContents(false); myPanel.setPreferredHeightGetter(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(); ComparisonPolicy defaultComparisonPolicy = DiffManagerImpl.getInstanceEx().getComparisonPolicy(); if (comparisonPolicy != defaultComparisonPolicy) { setComparisonPolicy(defaultComparisonPolicy, false); } HighlightMode highlightMode = getHighlightMode(); HighlightMode defaultHighlightMode = DiffManagerImpl.getInstanceEx().getHighlightMode(); if (highlightMode != defaultHighlightMode) { setHighlightMode(defaultHighlightMode, false); } 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(); }