[autocomplete] 48/143: Fixed positioning of completion popup windows and parameter assistance windows in multi-monitor environments.
Benjamin Mesing
ben at alioth.debian.org
Sat Oct 19 12:53:15 UTC 2013
This is an automated email from the git hooks/post-receive script.
ben pushed a commit to branch master
in repository autocomplete.
commit 2b5c396b961e9c9a7cb3e3ab7d9d4f533033fc27
Author: bobbylight <robert at fifesoft.com>
Date: Fri Jul 30 02:07:29 2010 +0000
Fixed positioning of completion popup windows and parameter assistance windows in multi-monitor environments.
---
.../ui/autocomplete/AutoCompletePopupWindow.java | 31 ++++--
.../ParameterizedCompletionDescriptionToolTip.java | 44 +++++----
src/org/fife/ui/autocomplete/Util.java | 103 +++++++++++++-------
3 files changed, 114 insertions(+), 64 deletions(-)
diff --git a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
index c777891..daa2a7c 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
@@ -26,6 +26,7 @@ package org.fife.ui.autocomplete;
import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
+import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
@@ -395,20 +396,25 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener,
return;
}
- Dimension screenSize = getToolkit().getScreenSize();
+ // Don't use getLocationOnScreen() as this throws an exception if
+ // window isn't visible yet, but getLocation() doesn't, and is in
+ // screen coordinates!
+ Point p = getLocation();
+ Rectangle screenBounds = Util.getScreenBoundsForPoint(p.x, p.y);
+ //Dimension screenSize = getToolkit().getScreenSize();
//int totalH = Math.max(getHeight(), descWindow.getHeight());
// Try to position to the right first (LTR)
int x;
if (ac.getTextComponentOrientation().isLeftToRight()) {
x = getX() + getWidth() + 5;
- if (x+descWindow.getWidth()>screenSize.width) { // doesn't fit
+ if (x+descWindow.getWidth()>screenBounds.x+screenBounds.width) { // doesn't fit
x = getX() - 5 - descWindow.getWidth();
}
}
else { // RTL
x = getX() - 5 - descWindow.getWidth();
- if (x<0) { // Doesn't fit
+ if (x<screenBounds.x) { // Doesn't fit
x = getX() + getWidth() + 5;
}
}
@@ -612,8 +618,15 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener,
*/
public void setLocationRelativeTo(Rectangle r) {
+ // Multi-monitor support - make sure the completion window (and
+ // description window, if applicable) both fit in the same window in
+ // a multi-monitor environment. To do this, we decide which monitor
+ // the rectangle "r" is in, and use that one (just pick top-left corner
+ // as the defining point).
+ Rectangle screenBounds = Util.getScreenBoundsForPoint(r.x, r.y);
+ //Dimension screenSize = getToolkit().getScreenSize();
+
boolean showDescWindow = descWindow!=null && ac.getShowDescWindow();
- Dimension screenSize = getToolkit().getScreenSize();
int totalH = getHeight();
if (showDescWindow) {
totalH = Math.max(totalH, descWindow.getHeight());
@@ -623,7 +636,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener,
// entire height of our stuff fits on the screen one way or the other.
aboveCaret = false;
int y = r.y + r.height + VERTICAL_SPACE;
- if (y+totalH>screenSize.height) {
+ if (y+totalH>screenBounds.height) {
y = r.y - VERTICAL_SPACE - getHeight();
aboveCaret = true;
}
@@ -634,11 +647,11 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener,
if (!ac.getTextComponentOrientation().isLeftToRight()) {
x -= getWidth(); // RTL => align right edge
}
- if (x<0) {
- x = 0;
+ if (x<screenBounds.x) {
+ x = screenBounds.x;
}
- else if (x+getWidth()>screenSize.width) { // completions don't fit
- x = screenSize.width - getWidth();
+ else if (x+getWidth()>screenBounds.x+screenBounds.width) { // completions don't fit
+ x = screenBounds.x + screenBounds.width - getWidth();
}
setLocation(x, y);
diff --git a/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java b/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java
index c824181..d49f8ab 100644
--- a/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java
+++ b/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java
@@ -24,7 +24,6 @@
package org.fife.ui.autocomplete;
import java.awt.Color;
-import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Window;
@@ -56,7 +55,7 @@ import javax.swing.text.Highlighter.Highlight;
/**
- * A "tooltip" that displays information on the function or method currently
+ * A "tool tip" that displays information on the function or method currently
* being entered.
*
* @author Robert Futrell
@@ -65,7 +64,7 @@ import javax.swing.text.Highlighter.Highlight;
class ParameterizedCompletionDescriptionToolTip {
/**
- * The actual tooltip.
+ * The actual tool tip.
*/
private JWindow tooltip;
@@ -95,19 +94,19 @@ class ParameterizedCompletionDescriptionToolTip {
private ParameterizedCompletion pc;
/**
- * Listens for events in the text component while this window is vislble.
+ * Listens for events in the text component while this window is visible.
*/
private Listener listener;
/**
* The minimum offset into the document that the caret can move to
- * before this tooltip disappears.
+ * before this tool tip disappears.
*/
private int minPos;
/**
* The maximum offset into the document that the caret can move to
- * before this tooltip disappears.
+ * before this tool tip disappears.
*/
private Position maxPos; // Moves with text inserted.
@@ -138,7 +137,7 @@ class ParameterizedCompletionDescriptionToolTip {
* Constructor.
*
* @param owner The parent window.
- * @param ac The parent autocompletion.
+ * @param ac The parent auto-completion.
* @param pc The completion being described.
*/
public ParameterizedCompletionDescriptionToolTip(Window owner,
@@ -335,13 +334,20 @@ class ParameterizedCompletionDescriptionToolTip {
/**
- * Sets the location of this tooltip relative to the given rectangle.
+ * Sets the location of this tool tip relative to the given rectangle.
*
* @param r The visual position of the caret (in screen coordinates).
*/
public void setLocationRelativeTo(Rectangle r) {
- Dimension screenSize = tooltip.getToolkit().getScreenSize();
+ // Multi-monitor support - make sure the completion window (and
+ // description window, if applicable) both fit in the same window in
+ // a multi-monitor environment. To do this, we decide which monitor
+ // the rectangle "r" is in, and use that one (just pick top-left corner
+ // as the defining point).
+ Rectangle screenBounds = Util.getScreenBoundsForPoint(r.x, r.y);
+System.out.println(screenBounds);
+ //Dimension screenSize = tooltip.getToolkit().getScreenSize();
// Try putting our stuff "above" the caret first.
int y = r.y - 5 - tooltip.getHeight();
@@ -352,11 +358,11 @@ class ParameterizedCompletionDescriptionToolTip {
// Get x-coordinate of completions. Try to align left edge with the
// caret first.
int x = r.x;
- if (x<0) {
- x = 0;
+ if (x<screenBounds.x) {
+ x = screenBounds.x;
}
- else if (x+tooltip.getWidth()>screenSize.width) { // completions don't fit
- x = screenSize.width - tooltip.getWidth();
+ else if (x+tooltip.getWidth()>screenBounds.x+screenBounds.width) { // completions don't fit
+ x = screenBounds.x + screenBounds.width - tooltip.getWidth();
}
tooltip.setLocation(x, y);
@@ -365,9 +371,9 @@ class ParameterizedCompletionDescriptionToolTip {
/**
- * Toggles the visibility of this tooltip.
+ * Toggles the visibility of this tool tip.
*
- * @param visible Whether the tooltip should be visible.
+ * @param visible Whether the tool tip should be visible.
* @param addParamListStart Whether or not
* {@link CompletionProvider#getParameterListStart()} should be
* added to the text component. If <code>visible</code> is
@@ -428,8 +434,8 @@ class ParameterizedCompletionDescriptionToolTip {
/**
- * Updates the text in the tooltip to have the current parameter
- * disiplayed in bold. The "current parameter" is determined from the
+ * Updates the text in the tool tip to have the current parameter
+ * displayed in bold. The "current parameter" is determined from the
* current caret position.
*/
private void updateText() {
@@ -456,7 +462,7 @@ class ParameterizedCompletionDescriptionToolTip {
/**
- * Updates the text in the tooltip to have the current parameter
+ * Updates the text in the tool tip to have the current parameter
* displayed in bold.
*
* @param selectedParam The index of the selected parameter.
@@ -631,7 +637,7 @@ class ParameterizedCompletionDescriptionToolTip {
/**
- * Listens for various events in the text component while this tooltip
+ * Listens for various events in the text component while this tool tip
* is visible.
*
* @author Robert Futrell
diff --git a/src/org/fife/ui/autocomplete/Util.java b/src/org/fife/ui/autocomplete/Util.java
index 41c3506..92e2f3e 100644
--- a/src/org/fife/ui/autocomplete/Util.java
+++ b/src/org/fife/ui/autocomplete/Util.java
@@ -23,12 +23,16 @@
package org.fife.ui.autocomplete;
import java.awt.Color;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.Rectangle;
import java.lang.reflect.Method;
import java.net.URI;
/**
- * Utility methods for the autocomplete framework.
+ * Utility methods for the auto-complete framework.
*
* @author Robert Futrell
* @version 1.0
@@ -41,41 +45,6 @@ class Util {
/**
- * Returns a hex string for the specified color, suitable for HTML.
- *
- * @param c The color.
- * @return The string representation, in the form "<code>#rrggbb</code>",
- * or <code>null</code> if <code>c</code> is <code>null</code>.
- */
- public static String getHexString(Color c) {
-
- if (c==null) {
- return null;
- }
-
- StringBuffer sb = new StringBuffer("#");
- int r = c.getRed();
- if (r<16) {
- sb.append('0');
- }
- sb.append(Integer.toHexString(r));
- int g = c.getGreen();
- if (g<16) {
- sb.append('0');
- }
- sb.append(Integer.toHexString(g));
- int b = c.getBlue();
- if (b<16) {
- sb.append('0');
- }
- sb.append(Integer.toHexString(b));
-
- return sb.toString();
-
- }
-
-
- /**
* Attempts to open a web browser to the specified URI.
*
* @param uri The URI to open. If this is <code>null</code>, nothing
@@ -150,4 +119,66 @@ class Util {
}
+ /**
+ * Returns a hex string for the specified color, suitable for HTML.
+ *
+ * @param c The color.
+ * @return The string representation, in the form "<code>#rrggbb</code>",
+ * or <code>null</code> if <code>c</code> is <code>null</code>.
+ */
+ public static String getHexString(Color c) {
+
+ if (c==null) {
+ return null;
+ }
+
+ StringBuffer sb = new StringBuffer("#");
+ int r = c.getRed();
+ if (r<16) {
+ sb.append('0');
+ }
+ sb.append(Integer.toHexString(r));
+ int g = c.getGreen();
+ if (g<16) {
+ sb.append('0');
+ }
+ sb.append(Integer.toHexString(g));
+ int b = c.getBlue();
+ if (b<16) {
+ sb.append('0');
+ }
+ sb.append(Integer.toHexString(b));
+
+ return sb.toString();
+
+ }
+
+
+ /**
+ * Returns the screen coordinates for the monitor that contains the
+ * specified point. This is useful for setups with multiple monitors,
+ * to ensure that popup windows are positioned properly.
+ *
+ * @param x The x-coordinate.
+ * @param y The y-coordinate.
+ * @return The bounds of the monitor that contains the specified point.
+ */
+ public static Rectangle getScreenBoundsForPoint(int x, int y) {
+ GraphicsEnvironment env = GraphicsEnvironment.
+ getLocalGraphicsEnvironment();
+ GraphicsDevice[] devices = env.getScreenDevices();
+ for (int i=0; i<devices.length; i++) {
+ GraphicsConfiguration[] configs = devices[i].getConfigurations();
+ for (int j=0; j<configs.length; j++) {
+ Rectangle gcBounds = configs[j].getBounds();
+ if (gcBounds.contains(x, y)) {
+ return gcBounds;
+ }
+ }
+ }
+ // If point is outside all monitors, default to default monitor (?)
+ return env.getMaximumWindowBounds();
+ }
+
+
}
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/autocomplete.git
More information about the pkg-java-commits
mailing list