protection against negative offsets

This commit is contained in:
Alexey Kudravtsev
2014-08-26 13:16:40 +04:00
parent 89dcbaf12d
commit a4f32e08f4
3 changed files with 9 additions and 9 deletions
@@ -223,10 +223,10 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI {
}
public int getDecrementButtonHeight() {
return decrButton.getHeight();
return Math.max(0, decrButton.getHeight());
}
public int getIncrementButtonHeight() {
return incrButton.getHeight();
return Math.max(0, incrButton.getHeight());
}
private void resetRegularThumbAnimator() {
@@ -4822,22 +4822,21 @@ public final class EditorImpl extends UserDataHolderBase implements EditorEx, Hi
int getDecScrollButtonHeight() {
ScrollBarUI barUI = getUI();
Insets insets = getInsets();
int top = Math.max(0, insets.top);
if (barUI instanceof ButtonlessScrollBarUI) {
return insets.top + ((ButtonlessScrollBarUI)barUI).getDecrementButtonHeight();
return top + ((ButtonlessScrollBarUI)barUI).getDecrementButtonHeight();
}
else if (barUI instanceof BasicScrollBarUI) {
if (barUI instanceof BasicScrollBarUI) {
try {
JButton decrButtonValue = (JButton)decrButtonField.get(barUI);
LOG.assertTrue(decrButtonValue != null);
return insets.top + decrButtonValue.getHeight();
return top + decrButtonValue.getHeight();
}
catch (Exception exc) {
throw new IllegalStateException(exc);
}
}
else {
return insets.top + 15;
}
return top + 15;
}
/**
@@ -127,9 +127,10 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
void recalcEditorDimensions() {
EditorImpl.MyScrollBar scrollBar = myEditor.getVerticalScrollBar();
int scrollBarHeight = scrollBar.getSize().height;
int scrollBarHeight = Math.max(0, scrollBar.getSize().height);
myEditorScrollbarTop = scrollBar.getDecScrollButtonHeight()/* + 1*/;
assert myEditorScrollbarTop>=0;
int editorScrollbarBottom = scrollBar.getIncScrollButtonHeight();
myEditorTargetHeight = scrollBarHeight - myEditorScrollbarTop - editorScrollbarBottom;
myEditorSourceHeight = myEditor.getPreferredHeight();