yet another attempt to preserve the resized lookup size

This commit is contained in:
peter
2011-09-20 17:27:55 +02:00
parent 90744ff1b1
commit 8096a204c6
3 changed files with 52 additions and 30 deletions
@@ -134,6 +134,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
private final LookupLayeredPane myLayeredPane = new LookupLayeredPane();
private JButton myScrollBarIncreaseButton;
private boolean myStartCompletionWhenNothingMatches;
private boolean myResizePending;
public LookupImpl(Project project, Editor editor, @NotNull LookupArranger arranger){
super(new JPanel(new BorderLayout()));
@@ -285,7 +286,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
myLookupTextWidth = Math.max(maxWidth, myLookupTextWidth);
myModel.setItemPresentation(item, presentation);
myResizePending = true;
}
public Collection<LookupElementAction> getActionsFor(LookupElement element) {
@@ -335,6 +336,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
myAdditionalPrefix += c;
myInitialPrefix = null;
myFrozenItems.clear();
myResizePending = true;
refreshUi(false);
ensureSelectionVisible();
}
@@ -365,6 +367,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
myAdditionalPrefix = myAdditionalPrefix.substring(0, len - 1);
myInitialPrefix = null;
myFrozenItems.clear();
myResizePending = true;
if (!myReused) {
refreshUi(false);
ensureSelectionVisible();
@@ -801,7 +804,7 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
LOG.assertTrue(marker.isValid(), "invalid marker");
marker.dispose();
if (isVisible()) {
updateLookupBounds();
updateLookupLocation();
}
checkValid();
}
@@ -1271,8 +1274,13 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
LOG.error("Null root pane");
}
if (myResizePending) {
myResizePending = false;
pack();
}
updateScrollbarVisibility();
updateLookupBounds();
updateLookupLocation();
if (reused || selectionVisible) {
ensureSelectionVisible();
@@ -1280,8 +1288,8 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
}
}
private void updateLookupBounds() {
HintManagerImpl.adjustEditorHintPosition(this, myEditor, calculatePosition());
private void updateLookupLocation() {
HintManagerImpl.updateLocation(this, myEditor, calculatePosition());
}
private void updateScrollbarVisibility() {
@@ -1360,10 +1368,14 @@ public class LookupImpl extends LightweightHint implements LookupEx, Disposable
mainPanel.setSize(size);
mainPanel.validate();
UISettings.getInstance().MAX_LOOKUP_LIST_WIDTH = Math.max(300, myScrollPane.getViewport().getWidth());
int visibleRowCount = myList.getLastVisibleIndex() - myList.getFirstVisibleIndex() + 1;
if (visibleRowCount != myList.getModel().getSize()) {
UISettings.getInstance().MAX_LOOKUP_ITEM_COUNT = Math.max(5, visibleRowCount);
Dimension preferredSize = mainPanel.getPreferredSize();
if (preferredSize.width != size.width) {
UISettings.getInstance().MAX_LOOKUP_LIST_WIDTH = Math.max(300, myScrollPane.getViewport().getWidth());
}
int listHeight = myList.getLastVisibleIndex() - myList.getFirstVisibleIndex() + 1;
if (listHeight != myList.getModel().getSize() && listHeight != myList.getVisibleRowCount() && preferredSize.height != size.height) {
UISettings.getInstance().MAX_LOOKUP_ITEM_COUNT = Math.max(5, listHeight);
}
layoutStatusIcons();
@@ -290,7 +290,7 @@ public class HintManagerImpl extends HintManager implements Disposable {
Component component = hint.getComponent();
doShowInGivenLocation(hint, editor, p, hintInfo);
doShowInGivenLocation(hint, editor, p, hintInfo, true);
ListenerUtil.addMouseListener(component, new MouseAdapter() {
public void mousePressed(MouseEvent e) {
@@ -364,10 +364,10 @@ public class HintManagerImpl extends HintManager implements Disposable {
}
}
private static void doShowInGivenLocation(final LightweightHint hint, final Editor editor, Point p, HintHint hintInfo) {
private static void doShowInGivenLocation(final LightweightHint hint, final Editor editor, Point p, HintHint hintInfo, boolean updateSize) {
if (ApplicationManager.getApplication().isUnitTestMode()) return;
JLayeredPane layeredPane = editor.getComponent().getRootPane().getLayeredPane();
Dimension size = hint.getComponent().getPreferredSize();
Dimension size = updateSize ? hint.getComponent().getPreferredSize() : hint.getComponent().getSize();
if (hint.isRealPopup()) {
final Point editorCorner = editor.getComponent().getLocation();
@@ -382,24 +382,28 @@ public class HintManagerImpl extends HintManager implements Disposable {
p = rectangle.getLocation();
SwingUtilities.convertPointFromScreen(p, layeredPane);
}
else if ((layeredPane.getWidth() < p.x + size.width) && !hintInfo.isAwtTooltip() && !hint.isRealPopup()) {
else if ((layeredPane.getWidth() < p.x + size.width) && !hintInfo.isAwtTooltip()) {
p.x = Math.max(0, layeredPane.getWidth() - size.width);
}
if (hint.isVisible()) {
hint.updateBounds(p.x, p.y);
if (updateSize) {
hint.updateBounds(p.x, p.y);
} else {
hint.updateLocation(p.x, p.y);
}
}
else {
hint.show(layeredPane, p.x, p.y, editor.getContentComponent(), hintInfo);
}
}
public static void adjustEditorHintPosition(final LightweightHint hint, final Editor editor, final Point p) {
adjustEditorHintPosition(hint, editor, p, UNDER);
public static void updateLocation(final LightweightHint hint, final Editor editor, Point p) {
doShowInGivenLocation(hint, editor, p, createHintHint(editor, p, hint, UNDER), false);
}
public static void adjustEditorHintPosition(final LightweightHint hint, final Editor editor, final Point p, short constraint) {
doShowInGivenLocation(hint, editor, p, createHintHint(editor, p, hint, constraint));
doShowInGivenLocation(hint, editor, p, createHintHint(editor, p, hint, constraint), true);
}
public void hideAllHints() {
@@ -767,6 +771,10 @@ public class HintManagerImpl extends HintManager implements Disposable {
hintInfo.setPreferredPosition(Balloon.Position.atLeft);
}
if (hint.isAwtTooltip()) {
hintInfo.setAwtTooltip(true);
}
hintInfo.setPositionChangeShift(0, editor.getLineHeight());
return hintInfo;
@@ -184,7 +184,7 @@ public class LightweightHint extends UserDataHolderBase implements Hint {
Point actualPoint = new Point(x, y);
JComponent actualComponent = new OpaquePanel(new BorderLayout());
actualComponent.add(myComponent, BorderLayout.CENTER);
if (myHintHint.isAwtTooltip()) {
if (isAwtTooltip()) {
fixActualPoint(actualPoint);
@@ -223,7 +223,7 @@ public class LightweightHint extends UserDataHolderBase implements Hint {
protected void onPopupCancel() {}
private void fixActualPoint(Point actualPoint) {
if (!myHintHint.isAwtTooltip()) return;
if (!isAwtTooltip()) return;
if (!myIsRealPopup) return;
Dimension size = myComponent.getPreferredSize();
@@ -357,21 +357,19 @@ public class LightweightHint extends UserDataHolderBase implements Hint {
@Override
public void pack() {
updateBounds(-1, -1, false);
setSize(myComponent.getPreferredSize());
}
@Override
public void updateBounds(int x, int y) {
updateBounds(x, y, true);
setSize(myComponent.getPreferredSize());
updateLocation(x, y);
}
private void updateBounds(int x, int y, boolean updateLocation) {
setSize(myComponent.getPreferredSize());
if (updateLocation) {
Point point = new Point(x, y);
fixActualPoint(point);
setLocation(new RelativePoint(myParentComponent, point));
}
public void updateLocation(int x, int y) {
Point point = new Point(x, y);
fixActualPoint(point);
setLocation(new RelativePoint(myParentComponent, point));
}
public final JComponent getComponent() {
@@ -436,7 +434,7 @@ public class LightweightHint extends UserDataHolderBase implements Hint {
myPopup.setSize(size);
} else {
//todo kirillk
if (myHintHint.isAwtTooltip()) {
if (isAwtTooltip()) {
return;
} else {
myComponent.setSize(size);
@@ -447,6 +445,10 @@ public class LightweightHint extends UserDataHolderBase implements Hint {
}
}
public boolean isAwtTooltip() {
return myHintHint != null && myHintHint.isAwtTooltip();
}
public Dimension getSize() {
return myComponent.getSize();
}