This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[gui][PATCH] fyi: dragging + painting fixes.
- From: Kim Ho <kho at redhat dot com>
- To: java-patches <java-patches at gcc dot gnu dot org>
- Date: 09 Mar 2004 11:33:39 -0500
- Subject: [gui][PATCH] fyi: dragging + painting fixes.
- Organization:
Hi,
- Add dragging to ScrollBar + Slider.
- Forward drag events to the proper component (last pressed component).
- Fix JScrollBar (the thumb is now at the top for value = 0).
- Fix visitChild in Container to move the clip to intersect properly.
- Change the string setting condition in JProgressBar
- Remove some println statements.
Cheers,
Kim
2004-03-09 Kim Ho <kho@redhat.com>
* java/awt/Container.java: (visitChild): Move
the x and y coordinate of the component rectangle
to correct position.
(handleEvent): Forward drag events to the pressed
component.
* javax/swing/plaf/basic/BasicScrollBarUI.java:
Fix comments.
(ArrowButtonListener::mousePressed): Stop the
existing timer.
(mouseDragged): Implement.
(TrackListener::mousePressed): Only react if
the press doesn't occur on the thumb, otherwise
just set the offset.
(TrackListener::mouseReleased): Unset the isAdjusting
value.
(createIncreaseIcon): Switch icon.
(createDecreaseIcon): Switch icon.
(calculatePreferredSize): Use width.
(getThumbBounds): Use the top as the lower value.
(layoutVScrollBar): Switch the button locations.
(paintIncreaseHighlight): Paint correct side of thumb.
(paintDecreaseHighlight): ditto.
(valueForYPosition): Use top as the lower value.
* javax/swing/plaf/basic/BasicSliderUI.java:
Fix comments.
(mouseDragged): Implement.
(mousePressed): Only react when the thumb isn't
pressed, otherwise just set offset.
(mouseReleased): Handle a release of the thumb.
(scrollDueToClickInTrack): Stop the timer first.
* javax/swing/JProgressBar.java:
(setString): Fix change condition.
* javax/swing/JSeparator.java:
Remove println's.
Cheers,
Kim
Index: java/awt/Container.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/Container.java,v
retrieving revision 1.34.2.3
diff -u -r1.34.2.3 Container.java
--- java/awt/Container.java 5 Mar 2004 22:24:50 -0000 1.34.2.3
+++ java/awt/Container.java 9 Mar 2004 16:32:54 -0000
@@ -1248,10 +1248,17 @@
Component comp)
{
Rectangle bounds = comp.getBounds();
+ Rectangle candidate = comp.getBounds();
Rectangle oldClip = gfx.getClipBounds();
if (oldClip == null)
oldClip = bounds;
- Rectangle clip = oldClip.intersection(bounds);
+ else
+ {
+ candidate.x += oldClip.x;
+ candidate.y += oldClip.y;
+ }
+
+ Rectangle clip = oldClip.intersection(candidate);
if (clip.isEmpty()) return;
@@ -1668,6 +1675,21 @@
MouseEvent me = (MouseEvent) e;
acquireComponentForMouseEvent(me);
+
+ // If the event is a drag, then we have to dispatch
+ // to the component who was last pressed. We can't
+ // use mouseEventTarget since the target should
+ // still be able to move. (For mouse move events).
+ if (e.getID() == MouseEvent.MOUSE_DRAGGED &&
+ pressedComponent != null &&
+ pressedComponent.isShowing())
+ {
+ MouseEvent newEvt =
+ SwingUtilities.convertMouseEvent(nativeContainer, me,
+ pressedComponent);
+ pressedComponent.dispatchEvent(newEvt);
+ return e.isConsumed();
+ }
// Avoid dispatching ENTERED and EXITED events twice.
if (mouseEventTarget != null
Index: javax/swing/plaf/basic/BasicScrollBarUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/Attic/BasicScrollBarUI.java,v
retrieving revision 1.1.2.1
diff -u -r1.1.2.1 BasicScrollBarUI.java
--- javax/swing/plaf/basic/BasicScrollBarUI.java 26 Feb 2004 14:24:09 -0000 1.1.2.1
+++ javax/swing/plaf/basic/BasicScrollBarUI.java 9 Mar 2004 16:32:54 -0000
@@ -93,6 +93,7 @@
*/
public void mousePressed(MouseEvent e)
{
+ scrollTimer.stop();
scrollListener.setScrollByBlock(false);
if (e.getSource() == incrButton)
scrollListener.setDirection(POSITIVE_SCROLL);
@@ -257,7 +258,8 @@
/** The current Y coordinate of the mouse. */
protected int currentMouseY;
- /** FIXME: use for something */
+ /** The offset between the current mouse cursor and the
+ current value of the scrollbar. */
protected int offset;
/**
@@ -268,8 +270,18 @@
*/
public void mouseDragged(MouseEvent e)
{
- // FIXME: implement.
- System.out.println("DRAGGING");
+ currentMouseX = e.getX();
+ currentMouseY = e.getY();
+ if (scrollbar.getValueIsAdjusting())
+ {
+ int value;
+ if (scrollbar.getOrientation() == SwingConstants.HORIZONTAL)
+ value = valueForXPosition(currentMouseX) - offset;
+ else
+ value = valueForYPosition(currentMouseY) - offset;
+
+ scrollbar.setValue(value);
+ }
}
/**
@@ -279,8 +291,8 @@
*/
public void mouseMoved(MouseEvent e)
{
- // FIXME: implement.
- System.out.println("MOVING");
+ // Not interested in where the mouse
+ // is unless it is being dragged.
}
/**
@@ -304,10 +316,9 @@
if (value == scrollbar.getValue())
return;
- if (thumbRect.contains(e.getPoint()))
- scrollbar.setValue(value);
- else
+ if (!thumbRect.contains(e.getPoint()))
{
+ scrollTimer.stop();
scrollListener.setScrollByBlock(true);
if (value > scrollbar.getValue())
{
@@ -321,6 +332,17 @@
}
scrollTimer.start();
}
+ else
+ {
+ // We'd like to keep track of where the cursor
+ // is inside the thumb.
+ // This works because the scrollbar's value represents
+ // "lower" edge of the thumb. The value at which
+ // the cursor is at must be greater or equal
+ // to that value.
+ scrollbar.setValueIsAdjusting(true);
+ offset = value - scrollbar.getValue();
+ }
scrollbar.repaint();
}
@@ -334,6 +356,9 @@
{
trackHighlight = NO_HIGHLIGHT;
scrollTimer.stop();
+
+ if (scrollbar.getValueIsAdjusting())
+ scrollbar.setValueIsAdjusting(false);
scrollbar.repaint();
}
@@ -583,7 +608,7 @@
if (orientation == SwingConstants.HORIZONTAL)
incrButton.setIcon(rightIcon);
else
- incrButton.setIcon(upIcon);
+ incrButton.setIcon(downIcon);
return incrButton;
}
@@ -603,7 +628,7 @@
if (orientation == SwingConstants.HORIZONTAL)
decrButton.setIcon(leftIcon);
else
- decrButton.setIcon(downIcon);
+ decrButton.setIcon(upIcon);
return decrButton;
}
@@ -738,7 +763,7 @@
decrButton.getPreferredSize().width);
width = Math.max(getMinimumThumbSize().width, width);
width = Math.max(20, width);
- width = Math.min(getMaximumThumbSize().height, height);
+ width = Math.min(getMaximumThumbSize().width, width);
}
Insets insets = scrollbar.getInsets();
@@ -811,7 +836,7 @@
{
thumbRect.x = trackRect.x;
thumbRect.y = trackRect.y
- + (max - value - extent) * trackRect.height / (max - min);
+ + value * trackRect.height / (max - min);
thumbRect.width = trackRect.width;
thumbRect.height = extent * trackRect.height / (max - min);
@@ -996,9 +1021,9 @@
Dimension incrDims = incrButton.getPreferredSize();
Dimension decrDims = decrButton.getPreferredSize();
- incrButton.setBounds(vr.x, vr.y, trackRect.width, incrDims.height);
- decrButton.setBounds(vr.x, trackRect.y + trackRect.height,
- trackRect.width, decrDims.height);
+ decrButton.setBounds(vr.x, vr.y, trackRect.width, decrDims.height);
+ incrButton.setBounds(vr.x, trackRect.y + trackRect.height,
+ trackRect.width, incrDims.height);
}
/**
@@ -1055,10 +1080,8 @@
g.fillRect(trackRect.x, trackRect.y, thumbRect.x - trackRect.x,
trackRect.height);
else
- g.fillRect(trackRect.x, thumbRect.y + thumbRect.height,
- trackRect.width,
- trackRect.y + trackRect.height - thumbRect.y -
- thumbRect.height);
+ g.fillRect(trackRect.x, trackRect.y, trackRect.width,
+ thumbRect.y - trackRect.y);
g.setColor(saved);
}
@@ -1078,9 +1101,11 @@
g.fillRect(thumbRect.x + thumbRect.width, trackRect.y,
trackRect.x + trackRect.width - thumbRect.x - thumbRect.width,
trackRect.height);
- else
- g.fillRect(trackRect.x, trackRect.y, trackRect.width,
- thumbRect.y - trackRect.y);
+ else
+ g.fillRect(trackRect.x, thumbRect.y + thumbRect.height,
+ trackRect.width,
+ trackRect.y + trackRect.height - thumbRect.y -
+ thumbRect.height);
g.setColor(saved);
}
@@ -1328,7 +1353,7 @@
if (len == 0)
return ((max - min) / 2);
- value = ((len - (yPos - trackRect.y)) * (max - min) / len + min);
+ value = ((yPos - trackRect.y) * (max - min) / len + min);
// If this isn't a legal value, then we'll have to move to one now.
if (value > max)
Index: javax/swing/plaf/basic/BasicSliderUI.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/plaf/basic/Attic/BasicSliderUI.java,v
retrieving revision 1.1.2.5
diff -u -r1.1.2.5 BasicSliderUI.java
--- javax/swing/plaf/basic/BasicSliderUI.java 26 Feb 2004 14:24:09 -0000 1.1.2.5
+++ javax/swing/plaf/basic/BasicSliderUI.java 9 Mar 2004 16:32:55 -0000
@@ -333,7 +333,8 @@
/** The current Y position of the mouse. */
protected int currentMouseY;
- /** FIXME: Figure out what this is used for. */
+ /** The offset between the current slider value
+ and the cursor's position. */
protected int offset;
/**
@@ -345,8 +346,18 @@
*/
public void mouseDragged(MouseEvent e)
{
- // FIXME: When we receive dragging events, fix this.
- // System.out.println("JSLIDER - Mouse Dragged");
+ currentMouseX = e.getX();
+ currentMouseY = e.getY();
+ if (slider.getValueIsAdjusting())
+ {
+ int value;
+ if (slider.getOrientation() == JSlider.HORIZONTAL)
+ value = valueForXPosition(currentMouseX) - offset;
+ else
+ value = valueForYPosition(currentMouseY) - offset;
+
+ slider.setValue(value);
+ }
}
/**
@@ -357,8 +368,7 @@
*/
public void mouseMoved(MouseEvent e)
{
- // FIXME: When we receive mouve events, fix this.
- // System.out.println("JSLIDER - Mouse Moved");
+ // Don't care that we're moved unless we're dragging.
}
/**
@@ -387,9 +397,7 @@
return;
// If the thumb is hit, then we don't need to set the timers to move it.
- if (thumbRect.contains(e.getPoint()))
- slider.setValue(value);
- else
+ if (!thumbRect.contains(e.getPoint()))
{
// The mouse has hit some other part of the slider.
// The value moves no matter where in the slider you hit.
@@ -398,6 +406,11 @@
else
scrollDueToClickInTrack(NEGATIVE_SCROLL);
}
+ else
+ {
+ slider.setValueIsAdjusting(true);
+ offset = value - slider.getValue();
+ }
}
/**
@@ -411,6 +424,12 @@
currentMouseX = e.getX();
currentMouseY = e.getY();
+ if (slider.getValueIsAdjusting())
+ {
+ slider.setValueIsAdjusting(false);
+ if (slider.getSnapToTicks())
+ slider.setValue(findClosestTick(slider.getValue()));
+ }
if (scrollTimer != null)
scrollTimer.stop();
}
@@ -2000,6 +2019,8 @@
*/
protected void scrollDueToClickInTrack(int dir)
{
+ scrollTimer.stop();
+
scrollListener.setDirection(dir);
scrollListener.setScrollByBlock(true);
Index: javax/swing/JProgressBar.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JProgressBar.java,v
retrieving revision 1.3.8.2
diff -u -r1.3.8.2 JProgressBar.java
--- javax/swing/JProgressBar.java 26 Feb 2004 14:24:08 -0000 1.3.8.2
+++ javax/swing/JProgressBar.java 9 Mar 2004 16:32:55 -0000
@@ -392,8 +392,9 @@
*/
public void setString(String string)
{
- if ((string == null || progressString == null &&
- string != progressString) || ! string.equals(progressString))
+ if (((string == null || progressString == null) &&
+ string != progressString) || (string != null &&
+ ! string.equals(progressString)))
{
String oldString = progressString;
progressString = string;
Index: javax/swing/JSeparator.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/javax/swing/JSeparator.java,v
retrieving revision 1.3.8.1
diff -u -r1.3.8.1 JSeparator.java
--- javax/swing/JSeparator.java 26 Feb 2004 14:24:08 -0000 1.3.8.1
+++ javax/swing/JSeparator.java 9 Mar 2004 16:32:55 -0000
@@ -96,7 +96,6 @@
*/
public JSeparator(int orientation)
{
- System.out.println("MAKING IT");
if (orientation != HORIZONTAL && orientation != VERTICAL)
throw new IllegalArgumentException(orientation
+ " is not a valid orientation.");
@@ -134,8 +133,6 @@
{
setUI((SeparatorUI) UIManager.getUI(this));
invalidate();
- if (ui == null)
- System.out.println("CRAP");
}
/**