/**********************************************************************
- * Copyright (c) 2005, 2008 IBM Corporation and others.
- * Copyright (c) 2011, 2012 Ericsson.
- *
+ * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM - Initial API and implementation
- * Bernd Hufmann - Updated for TMF
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ * Bernd Hufmann - Updated for TMF
**********************************************************************/
+
package org.eclipse.linuxtools.tmf.ui.views.uml2sd;
import java.util.Timer;
import org.eclipse.swt.widgets.Shell;
/**
- * ScrollView widget provides a scrolling area with on-demand scroll bars.
+ * ScrollView widget provides a scrolling area with on-demand scroll bars.
* Overview scrollable panel can be used (@see setOverviewEnabled()).
- *
+ *
* @author Eric Miravete
* @version 1.0
*/
public class ScrollView extends Composite {
-
+
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
- // Value for scroll bar mode, default is AUTO
+ // Value for scroll bar mode, default is AUTO
/**
* Scroll bar mode AUTO
*/
*/
public static final int ALWAYS_OFF = 2;
/**
- * Bit mask for visible vertical scroll bar
+ * Bit mask for visible vertical scroll bar
*/
public static final int VBAR = 0x01;
/**
- * Bit mask for visible horizontal scroll bar
+ * Bit mask for visible horizontal scroll bar
*/
public static final int HBAR = 0x02;
/**
*/
protected int fContentsWidth = 0;
/**
- * Value of the contents x coordinate property
+ * Value of the contents x coordinate property
*/
protected int fContentsX = 0;
/**
- * Value of the contents y coordinate property
+ * Value of the contents y coordinate property
*/
protected int fContentsY = 0;
/**
- * Scroll bar mode of horizontal scroll bar.
- */
+ * Scroll bar mode of horizontal scroll bar.
+ */
protected int fHorScrollbarMode = AUTO;
/**
- * Scroll bar mode of vertical scroll bar.
- */
+ * Scroll bar mode of vertical scroll bar.
+ */
protected int fVertScrollbarMode = AUTO;
/**
* Increment for the horizontal scroll bar.
*/
protected Canvas fViewControl;
/**
- * Control used in the bottom right corner @see setCornerControl() and @see setOverviewEnabled(true)
+ * Control used in the bottom right corner @see setCornerControl() and @see setOverviewEnabled(true)
*/
protected Control fCornerControl;
/**
*/
protected int fOverviewSize = 100; // default size for overview
/**
- * Timer for auto_scroll feature
+ * Timer for auto_scroll feature
*/
protected AutoScroll fAutoScroll = null;
- /**
- * TimerTask for auto_scroll feature !=null when auto scroll is running
+ /**
+ * TimerTask for auto_scroll feature !=null when auto scroll is running
*/
protected Timer fAutoScrollTimer = null;
- /**
- * where mouse down appear on contents area (x coordinate)
+ /**
+ * where mouse down appear on contents area (x coordinate)
*/
protected int fMouseDownX = -1;
- /**
- * where mouse down appear on contents area (y coordinate)
+ /**
+ * where mouse down appear on contents area (y coordinate)
*/
protected int fMousDownY = -1;
-
+
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
/**
* Create a ScrollView, child of composite c. Both scroll bar have the mode AUTO. Auto scroll feature is enabled
* using a delay of 250ms. Overview feature is not enabled by default (use setOverviewEnabled()).
- *
+ *
* @param c The parent composite
* @param style The SWT style bits @see SWT
*/
/**
* Create a ScrollView, child of composite c. Both scroll bar have the mode AUTO. Auto scroll feature is enabled
* using a delay of 250ms. Overview feature is not enabled by default (use setOverviewEnabled()).
- *
+ *
* @param c The parent composite.
* @param style The SWT style bits @see SWT
* @param mouseWheel Flag to force scrollView to handles mouse wheel
}
});
- if (fViewControl.getVerticalBar() != null)
+ if (fViewControl.getVerticalBar() != null) {
// add fViewControl hidden scrollbar listener to get mouse wheel ...
fViewControl.getVerticalBar().addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
+ }
getHorizontalBar().addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
public void widgetDefaultSelected(SelectionEvent e) {
}
});
- if (fViewControl.getHorizontalBar() != null)
+ if (fViewControl.getHorizontalBar() != null) {
fViewControl.getHorizontalBar().addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
public void widgetDefaultSelected(SelectionEvent e) {
}
});
+ }
}
// ------------------------------------------------------------------------
// Methods
// ------------------------------------------------------------------------
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.widgets.Composite#setFocus()
- */
@Override
public boolean setFocus() {
return fViewControl.forceFocus();
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.widgets.Control#setCursor(org.eclipse.swt.graphics.Cursor)
- */
@Override
public void setCursor(Cursor cursor) {
fViewControl.setCursor(cursor);
}
- /*
- * Dispose controls used in scroll view
- *
- * (non-Javadoc)
- * @see org.eclipse.swt.widgets.Widget#dispose()
- */
@Override
public void dispose() {
if (fAutoScroll != null) {
super.dispose();
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.widgets.Composite#getClientArea()
- */
@Override
public Rectangle getClientArea() {
return fViewControl.getClientArea();
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.widgets.Control#setBackground(org.eclipse.swt.graphics.Color)
- */
@Override
public void setBackground(Color c) {
super.setBackground(c);
fViewControl.setBackground(c);
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.widgets.Control#setToolTipText(java.lang.String)
- */
@Override
public void setToolTipText(String text) {
fViewControl.setToolTipText(text);
* Draw overview area, @see setOverviewEnabled. By default draw a rectangle corresponding to the visible area of
* scroll view. You can redefine this method to draw the contents as drawContents does... ...in an other magnify
* factor.
- *
+ *
* @param gc GC to used to draw.
* @param r Rectangle corresponding to the client area of overview.
*/
/**
* Remove the local Listener and add the new listener.
- *
+ *
* @param nlistener the new listener
*/
public void replaceControlListener(ControlListener nlistener) {
/**
* Remove the local Listener and add the new listener.
- *
+ *
* @param nlistener the new listener
*/
public void replaceKeyListener(KeyListener nlistener) {
/**
* Remove the local Listener and add the new listener.
- *
+ *
* @param nlistener the new listener
*/
public void replaceMouseListener(MouseListener nlistener) {
/**
* Remove the local Listener and add the new listener.
- *
+ *
* @param nlistener the new listener
*/
public void replaceMouseMoveListener(MouseMoveListener nlistener) {
/**
* Remove the local Listener and add the new listener.
- *
+ *
* @param nlistener the new listener
*/
public void replacePaintListener(PaintListener nlistener) {
/**
* Access method for the contentsHeight property.
- *
+ *
* @return the current value of the contentsHeight property
*/
public int getContentsHeight() {
/**
* Access method for the contentsWidth property.
- *
+ *
* @return the current value of the contentsWidth property
*/
public int getContentsWidth() {
/**
* Access method for the contentsX property.
- *
+ *
* @return the current value of the contentsX property
*/
public int getContentsX() {
/**
* Access method for the contentsY property.
- *
+ *
* @return the current value of the contentsY property
*/
public int getContentsY() {
/**
* Determines if the dragAutoScroll property is true.
- *
+ *
* @return <code>true<code> if the dragAutoScroll property is true
*/
- public boolean getDragAutoScroll() {
+ public boolean isDragAutoScroll() {
return fAutoScrollEnabled;
}
/**
* Sets the value of the dragAutoScroll property.
- *
+ *
* @param aDragAutoScroll the new value of the dragAutoScroll property
*/
public void setDragAutoScroll(boolean aDragAutoScroll) {
/**
* Change delay (in millisec) used for auto scroll feature.
- *
+ *
* @param period new period between to auto scroll
*/
public void setDragAutoScrollPeriod(int period) {
/**
* Return auto scroll period.
+ *
+ * @return The period
*/
public int getDragAutoScrollPeriod() {
return fAutoScrollPeriod;
/**
* Access method for the hScrollBarMode property.
- *
+ *
* @return the current value of the hScrollBarMode property
*/
public int getHScrollBarMode() {
/**
* Sets the value of the hScrollBarMode property.
- *
+ *
* @param aHScrollBarMode the new value of the hScrollBarMode property
*/
public void setHScrollBarMode(int aHScrollBarMode) {
/**
* Access method for the vScrollBarMode property.
- *
+ *
* @return the current value of the vScrollBarMode property
*/
public int getVScrollBarMode() {
/**
* Sets the value of the vScrollBarMode property.
- *
+ *
* @param aVScrollBarMode the new value of the vScrollBarMode property
*/
public void setVScrollBarMode(int aVScrollBarMode) {
/**
* Return horizontal scroll bar increment, default:1
+ *
+ * @return The increment
*/
public int getHScrollBarIncrement() {
return fHorScrollbarIncrement;
/**
* Return vertical scroll bar increment, default:1
+ *
+ * @return The increment
*/
public int getVScrollBarIncrement() {
return fVertScrollbarIncrement;
}
/**
- * Change horizontal scroll bar increment, minimum:1. Page increment is always set to visible width.
+ * Change horizontal scroll bar increment, minimum:1. Page increment is
+ * always set to visible width.
+ *
+ * @param inc
+ * Increment value to set
*/
public void setHScrollBarIncrement(int inc) {
fHorScrollbarIncrement = Math.max(1, inc);
}
/**
- * Change vertical scroll bar increment, minimum:1. Page increment is always set to visible height.
+ * Change vertical scroll bar increment, minimum:1. Page increment is always
+ * set to visible height.
+ *
+ * @param inc
+ * Increment value to set
*/
public void setVScrollBarIncrement(int inc) {
fVertScrollbarIncrement = Math.max(1, inc);
* Enable or disable overview feature. Enabling overview, dispose and replace existing corner control by a button.
* Clicking in it open overview, move mouse cursor holding button to move scroll view and release button to hide
* overview. Tip: hold control and/or shift key while moving mouse when overview is open made fine scroll.
- *
+ *
* @param value true to engage overview feature
*/
public void setOverviewEnabled(boolean value) {
- if (getOverviewEnabled() == value) {
+ if (isOverviewEnabled() == value) {
return;
}
/**
* Change overview size (at ratio 1:1), default is 100
+ *
+ * @param size
+ * The new size
*/
public void setOverviewSize(int size) {
fOverviewSize = Math.abs(size);
/**
* Returns whether the overview is enabled or not.
- *
+ *
* @return true is overview feature is enabled
*/
- public boolean getOverviewEnabled() {
+ public boolean isOverviewEnabled() {
if (fCornerControl instanceof Button) {
Object data = ((Button) fCornerControl).getData();
// overview alreay
/**
* Returns the overview size at ratio 1:1.
- *
+ *
* @return current overview size at ratio 1:1
*/
public int getOverviewSize() {
/**
* Returns control used to display view (might not be this object). Use this control to add/remove listener on the
* draw area.
- *
- * @return control used to display view (might not be this object).
+ *
+ * @return control used to display view (might not be this object).
*/
public Control getViewControl() {
return fViewControl;
/**
* Called when the mouse enter the ScrollView area
- *
+ *
* @param e
+ * Mouse event
*/
protected void contentsMouseExit(MouseEvent e) {
}
/**
- * Called when the mouse enter the ScrollView area after and system defined time
- *
+ * Called when the mouse enter the ScrollView area after and system defined
+ * time
+ *
* @param e
+ * Mouse event
*/
protected void contentsMouseHover(MouseEvent e) {
}
/**
* Called when the mouse enter the ScrollView area
- *
+ *
* @param e
+ * Mouse event
*/
protected void contentsMouseEnter(MouseEvent e) {
}
/**
* Called when user double on contents area.
- *
+ *
* @param e
+ * Mouse event
*/
protected void contentsMouseDoubleClickEvent(MouseEvent e) {
}
/**
* Called when mouse is on contents area and button is pressed.
- *
+ *
* @param e
+ * Mouse event
*/
protected void contentsMouseDownEvent(MouseEvent e) {
fMouseDownX = e.x;
fMousDownY = e.y;
}
- /**
- * TimerTask for auto scroll feature.
+ /**
+ * TimerTask for auto scroll feature.
*/
protected static class AutoScroll extends TimerTask {
+
+ /** X delta */
public int deltaX;
+
+ /** Y delta */
public int deltaY;
+
+ /** ScrollView object */
public ScrollView scrollView;
+ /**
+ * Constructor.
+ *
+ * @param sv
+ * ScrollView object to use
+ * @param dx
+ * X delta
+ * @param dy
+ * Y delta
+ */
public AutoScroll(ScrollView sv, int dx, int dy) {
scrollView = sv;
deltaX = dx;
/**
* Called when mouse is on contents area and mode.
- *
+ *
* @param event
+ * Mouse event
*/
protected void contentsMouseMoveEvent(MouseEvent event) {
if ((event.stateMask & SWT.BUTTON_MASK) != 0) {
/**
* Called when mouse is on contents area and button is released
- *
+ *
* @param event
+ * Mouse event
*/
protected void contentsMouseUpEvent(MouseEvent event) {
// reset auto scroll if it's engaged
}
/**
- * Responsible to draw contents area. At least rectangle clipX must be redrawn. This rectangle is given in contents
- * coordinates. By default, no paint is produced.
- *
+ * Responsible to draw contents area. At least rectangle clipX must be
+ * redrawn. This rectangle is given in contents coordinates. By default, no
+ * paint is produced.
+ *
* @param gc
+ * Graphics context
* @param clipx
+ * X clip
* @param clipy
+ * Y clip
* @param clipw
+ * W clip
* @param cliph
+ * H clip
*/
protected void drawContents(GC gc, int clipx, int clipy, int clipw, int cliph) {
}
/**
* Change the size of the contents area.
- *
+ *
* @param width new width of the area.
* @param height new height of the area.
*/
public void resizeContents(int width, int height) {
- // System.out.println("SV--resizeContents("+_w+","+_h+" ) {");
int localWidth = width;
int localHeight = height;
-
+
if (localWidth < 0) {
localWidth = 0;
}
return;
}
- // System.out.println("RESIZE-CONTENTS("+_w+","+_h+")");
fContentsWidth = localWidth;
fContentsHeight = localHeight;
} else {
updateScrollBarsValues();
}
- // System.out.println("SV--resizeContents() }");
}
// redefined for internal use ..
}
/**
- * @param delataX The delta in X
+ * @param delataX The delta in X
* @param deltaY the delta in Y
*/
public void scrollBy(int delataX, int deltaY) {
/**
* Scroll to ensure point(in contents coordinates) is visible.
- *
+ *
* @param px Point's x position
* @param py Point's y position
*/
/**
* Make rectangle (x,y,w,h, in contents coordinates) visible. if rectangle cannot be completely visible, use
* align flags.
- *
+ *
* @param xValue x contents coordinates of rectangle.
* @param yValue y contents coordinates of rectangle.
* @param width width of rectangle.
/**
* Make rectangle (xValue,yValue,width,height, in contents coordinates) visible. if rectangle cannot be completely visible, use
* align flags.
- *
+ *
* @param xValue x contents coordinates of rectangle.
* @param yValue y contents coordinates of rectangle.
* @param width width of rectangle.
* @param forceAlign force alignment for rectangle smaller than the visible area
*/
protected void ensureVisible(int xValue, int yValue, int width, int height, int align, boolean forceAlign) {
-
+
+ int localX = xValue;
+ int localY = yValue;
int localWidth = width;
int localHeight = height;
if (localWidth < 0) {
- xValue = xValue + localWidth;
+ localX = localX + localWidth;
localWidth = -localWidth;
}
if (localHeight < 0) {
- yValue = yValue + localHeight;
+ localY = localY + localHeight;
localHeight = -localHeight;
}
int hbar = getHorizontalBarHeight();
int vbar = getVerticalBarWidth();
- int cx = getContentsX(), cy = getContentsY();
+ int cx = getContentsX();
+ int cy = getContentsY();
int right = getContentsX() + getVisibleWidth() - vbar;
int bottom = getContentsY() + getVisibleHeight() - hbar;
boolean align_h = false, align_v = false;
- if (xValue < getContentsX()) {
- cx = xValue;
- } else if (xValue + localWidth > right) {
- cx = xValue - localWidth;
+ if (localX < getContentsX()) {
+ cx = localX;
+ } else if (localX + localWidth > right) {
+ cx = localX - localWidth;
}
- if (yValue < getContentsY()) {
- cy = yValue;
- } else if (yValue + localHeight > bottom) {
- cy = yValue - localHeight;
+ if (localY < getContentsY()) {
+ cy = localY;
+ } else if (localY + localHeight > bottom) {
+ cy = localY - localHeight;
}
if (localWidth > getVisibleWidth()) {
align_v = true;
}
// compute alignment on visible area horizontally
- if (align_h || (forceAlign && xValue + localWidth > right)) {
+ if (align_h || (forceAlign && localX + localWidth > right)) {
// use align flags
if ((align & SWT.LEFT) != 0) {
- cx = xValue;
+ cx = localX;
} else if ((align & SWT.RIGHT) != 0) {
cx = right - localWidth;
} else { // center
- cx = xValue + (localWidth - getVisibleWidth()) / 2;
+ cx = localX + (localWidth - getVisibleWidth()) / 2;
}
}
// compute alignment on visible area vertically
- if (align_v || (forceAlign && yValue + localHeight > bottom)) {
+ if (align_v || (forceAlign && localY + localHeight > bottom)) {
// use align flags
if ((align & SWT.TOP) != 0) {
- cy = yValue;
+ cy = localY;
} else if ((align & SWT.BOTTOM) != 0) {
cy = bottom - localHeight;
} else { // center
- cy = yValue + (localHeight - getVisibleHeight()) / 2;
+ cy = localY + (localHeight - getVisibleHeight()) / 2;
}
}
setContentsPos(cx, cy);
/**
* Returns true if point is visible (expressed in contents coordinates).
- *
+ *
* @param px Point's x position
* @param py Point's y position
* @return true if point is visible (expressed in contents coordinates)
/**
* Returns true if rectangle if partially visible.
- *
+ *
* @param xValue x contents coordinates of rectangle.
* @param yValue y contents coordinates of rectangle.
* @param width width of rectangle.
}
/**
- * Returns visible part of rectangle, or null if rectangle is not visible. Rectangle is expressed in contents
- * coordinates.
+ * Returns visible part of rectangle, or null if rectangle is not visible.
+ * Rectangle is expressed in contents coordinates.
*
- * @param xValue x contents coordinates of rectangle.
- * @param yValue y contents coordinates of rectangle.
- * @param width width of rectangle.
- * @param height height of rectangle.
- * @return visible part of rectangle, or null if rectangle is not visible.
- */
- public Rectangle getVisiblePart(int xValue, int yYalue, int width, int height) {
+ * @param xValue
+ * x contents coordinates of rectangle.
+ * @param yValue
+ * y contents coordinates of rectangle.
+ * @param width
+ * width of rectangle.
+ * @param height
+ * height of rectangle.
+ * @return visible part of rectangle, or null if rectangle is not visible.
+ */
+ public Rectangle getVisiblePart(int xValue, int yValue, int width, int height) {
if (xValue + width < getContentsX()) {
return null;
}
- if (yYalue + height < getContentsY()) {
+ if (yValue + height < getContentsY()) {
return null;
}
int vr = getContentsX() + getVisibleWidth();
if (xValue > vr) {
return null;
}
- if (yYalue > vb) {
+ if (yValue > vb) {
return null;
}
- int rr = xValue + width, rb = yYalue + height;
- int nl = Math.max(xValue, getContentsX()), nt = Math.max(yYalue, getContentsY()), nr = Math.min(rr, vr), nb = Math.min(rb, vb);
+ int rr = xValue + width, rb = yValue + height;
+ int nl = Math.max(xValue, getContentsX()), nt = Math.max(yValue, getContentsY()), nr = Math.min(rr, vr), nb = Math.min(rb, vb);
return new Rectangle(nl, nt, nr - nl, nb - nt);
}
/**
- * Returns the visible part for given rectangle.
- *
+ * Returns the visible part for given rectangle.
+ *
* @param rect A rectangle
- *
+ *
* @return gets visible part of rectangle (or <code>null</code>)
*/
public final Rectangle getVisiblePart(Rectangle rect) {
/**
* Change top left position of visible area. Check if the given point is inside contents area.
- *
+ *
* @param xValue x contents coordinates of visible area.
* @param yValue y contents coordinates of visible area.
* @return true if view really moves
return true;
}
- // redefined to return our vertical bar
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.widgets.Scrollable#getVerticalBar()
- */
@Override
public ScrollBar getVerticalBar() {
return fVertScrollBar.getVerticalBar();
}
- // redefined to return out horizontal bar
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.widgets.Scrollable#getHorizontalBar()
- */
@Override
public ScrollBar getHorizontalBar() {
return fHorScrollBar.getHorizontalBar();
* @param forHeight height of foreground
* @param currHorVis The current visibility state of horizontal scroll bar
* @param currVertvis The current visibility state of vertical scroll bar
- * @return <code>true</code> if visibility changed else <code>false</code>
+ * @return <code>true</code> if visibility changed else <code>false</code>
*/
public int computeBarVisibility(int forWidth, int forHeight, boolean currHorVis, boolean currVertvis) {
-
+
int localForWidth = forWidth;
int vis = 0x00;
switch (fVertScrollbarMode) {
}
}
break;
+ default:
+ break;
}
switch (fHorScrollbarMode) {
}
}
break;
+ default:
+ break;
}
return vis;
}
/**
- * setup scroll bars visibility, return true if one of visibility changed.
+ * Setup scroll bars visibility.
+ *
+ * @return True if one of visibility changed.
*/
protected boolean updateScrollBarVisiblity() {
boolean change = false;
int barNewVis = computeBarVisibility(getVisibleWidth(), getVisibleHeight(), currHorVis, currVertVis);
boolean newVertVis = (barNewVis & VBAR) != 0;
boolean newHorVis = (barNewVis & HBAR) != 0;
- // System.out.println("SV--updateScrollBarVis old, h:"+curr_h_vis+" v:"+curr_v_vis+" new="+bar_new_vis);
if (currVertVis ^ newVertVis) { // vertsb_.getVisible() )
fVertScrollBar.setVisible(newVertVis);
change = true;
* Setup scroll bar using contents, visible and scroll bar mode properties.
*/
protected void updateScrollBarsValues() {
- // System.out.println("UPDATE-SCROLL-BAR-VALUES");
/* update vertical scrollbar */
ScrollBar b = getVerticalBar();
if (b != null) {
* corner control. This control is visible only if at least one scrollbar is visible. Given control will be disposed
* by ScrollView, at dispose() time, at next setCornetControl() call or when calling setOverviewEnabled(). Pay
* attention calling this reset overview feature until setOverviewEnabled(true) if called.
- * @param control The control for the overview
+ * @param control The control for the overview
*/
public void setCornerControl(Control control) {
if (fCornerControl != null) {
/**
* Transform (x,y) point in widget coordinates to contents coordinates.
- *
+ *
* @param x The x widget coordinate.
* @param y The y widget coordinate.
* @return org.eclipse.swt.graphics.Point with content coordinates.
return new Point(viewToContentsX(x), viewToContentsY(y));
}
- /**
+ /**
* Transform x in widget coordinates to contents coordinates
- *
+ *
* @param x The y widget coordinate.
- * @return the x content coordinate.
+ * @return the x content coordinate.
*/
public int viewToContentsX(int x) {
return fContentsX + x;
}
- /**
+ /**
* Transform y in widget coordinates to contents coordinates
- *
+ *
* @param y The y widget coordinate.
- * @return the y content coordinate.
+ * @return the y content coordinate.
*/
public int viewToContentsY(int y) {
return fContentsY + y;
/**
* Transform (x,y) point from contents coordinates, to widget coordinates.
- *
+ *
* @param x The x content coordinate.
* @param y The y content coordinate.
* @return coordinates widget area as.
/**
* Transform X axis coordinates from contents to widgets.
- *
+ *
* @param x contents coordinate to transform.
* @return x coordinate in widget area
*/
/**
* Transform Y axis coordinates from contents to widgets.
- *
+ *
* @param y contents coordinate to transform
* @return y coordinate in widget area
*/
/**
* Return the visible height of scroll view, might be > contentsHeight
- *
+ *
* @return the visible height of scroll view, might be > contentsHeight()
*/
public int getVisibleHeight() {
- Rectangle r = fViewControl.getClientArea();
- return r.height;
+ return fViewControl.getClientArea().height;
}
/**
* Return int the visible width of scroll view, might be > contentsWidth().
- *
+ *
* @return int the visible width of scroll view, might be > contentsWidth()
*/
public int getVisibleWidth() {
- Rectangle r = fViewControl.getClientArea();
- return r.width;
+ return fViewControl.getClientArea().width;
}
/**
- * Add support for arrow key, scroll the ... scroll view. But you can redefine this method for your convenience.
+ * Add support for arrow key, scroll the ... scroll view. But you can
+ * redefine this method for your convenience.
+ *
+ * @param event
+ * Keyboard event
*/
protected void keyPressedEvent(KeyEvent event) {
switch (event.keyCode) {
case SWT.ARROW_RIGHT:
scrollBy(+getVisibleWidth(), 0);
break;
+ default:
+ break;
}
}
- /**
+ /**
* Redefine this method at your convenience
+ *
* @param event The key event.
*/
protected void keyReleasedEvent(KeyEvent event) {
}
- /**
- * Called when ScrollView view is resized.
- */
- protected void viewResized() {
- // System.out.println("SV--viewResizeEvent()");
- // scroll contents x,y if visible area bigger than contents...
- if (!setContentsPos(getContentsX(), getContentsY())) {
- // if no scroll done, scroll bar must be updated.
- /*
- * if( ocx==getContentsX() && ocy==getContentsY() ) { updateScrollBars(); }
- */
- }
- }
-
/**
* Returns vertical bar width, even if bar isn't visible.
- *
- * @return vertical bar width, even if bar isn't visible
+ *
+ * @return vertical bar width, even if bar isn't visible
*/
public int getVerticalBarWidth() {
// include vertical bar width and trimming of scrollable used
/**
* Returns horizontal bar height even if bar isn't visible.
- *
- * @return horizontal bar height even if bar isn't visible
+ *
+ * @return horizontal bar height even if bar isn't visible
*/
public int getHorizontalBarHeight() {
// include horiz. bar height and trimming of scrollable used
return bh + 1;
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.widgets.Scrollable#computeTrim(int, int, int, int)
- */
@Override
public Rectangle computeTrim(int x, int y, int w, int h) {
Rectangle r = new Rectangle(x, y, w, h);
}
/**
- * Internal layout for ScrollView, handle scrollbars, drawzone and corner control
+ * Internal layout for ScrollView, handle scrollbars, drawzone and corner control
*/
protected class SVLayout extends Layout {
/**
* The do-it-not flag
*/
boolean dontLayout = false;
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.widgets.Layout#computeSize(org.eclipse.swt.widgets.Composite, int, int, boolean)
- */
+
@Override
protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
Point p = new Point(250, 250);
return p;
}
- /*
- * (non-Javadoc)
- * @see org.eclipse.swt.widgets.Layout#layout(org.eclipse.swt.widgets.Composite, boolean)
- */
@Override
protected void layout(Composite composite, boolean flushCache) {
if (dontLayout) {
dontLayout = true;
}
- // System.out.println(">>> SV.layout() {");
Point cs = composite.getSize();
int bar_vis = computeBarVisibility(cs.x, cs.y, false, false);
boolean vb_vis = (bar_vis & VBAR) != 0;
int wb = vb_vis ? vbw : 0;
int hb = hb_vis ? hbh : 0;
int cww = 0, cwh = 0;
- // System.out.println("SV-LAYOUT H.vis="+hb_vis+" V.vis="+vb_vis);
if (fCornerControl != null && (vb_vis || hb_vis)) { // corner_control_.getVisible())
fCornerControl.setVisible(true);
cww = vbw;
cwh = hbh;
- if (wb == 0)
+ if (wb == 0) {
wb = vbw;
- if (hb == 0)
+ }
+ if (hb == 0) {
hb = hbh;
+ }
} else if (vb_vis && hb_vis) {
if (fCornerControl != null) {
fCornerControl.setVisible(false);
int vh = cs.y - (hb_vis ? hbh : 0);
int vbx = cs.x - wb;
int hby = cs.y - hb;
- Rectangle rc = fViewControl.getClientArea();
- int old_width = rc.width;
- int old_height = rc.height;
- // provoque pas un viewResize ???
+
fViewControl.setBounds(0, 0, vw, vh);
- boolean do_view_resize = false;
- rc = fViewControl.getClientArea();
- if (old_width != rc.width || old_height != rc.height) {
- // area size change, so visibleWidth()/Height() change too
- // so scrollbars visibility ma change too..
- // so need an other layout !
- /*
- * if( updateScrollBarVisiblity() ) { layout( composite, flushCache);
- * System.out.println("<<< SV.layout() } (recursive)"); return ; }
- */
- do_view_resize = true;
- }
+
if (vb_vis) {
fVertScrollBar.setBounds(vbx, 0, wb, cs.y - cwh);
}
fCornerControl.setBounds(vbx, hby, vbw, hbh);
}
updateScrollBarsValues();
- if (do_view_resize) {
- // System.out.println(" -layout do_view_resize old="+old_width+"x"+old_height+" new="+viewcontrol_.getClientArea());
- viewResized();
- }
- // System.out.println("<<< SV.layout() }");
+
seek--;
if (seek == 0) {
dontLayout = false;
}
// static must take place here... cursor is created once.
- static Cursor fOverviewCursor;
+ volatile static Cursor fOverviewCursor;
/** Support for click-and-see overview shell on this ScrollView */
protected class Overview {
-
+
/**
* factor for X from real and overview sizes, for mouse move speed.
*/
protected int fSaveCursorY;
/**
- * apply overview support on a control. Replace existing corner_widget
+ * Apply overview support on a control. Replace existing corner_widget
+ *
+ * @param control
+ * The control to use
*/
public void useControl(Control control) {
final Point pos = control.getLocation();
@Override
public void focusLost(FocusEvent e) {
- if (overviewing())
+ if (overviewing()) {
overviewDisappear(false);
+ }
}
});
});
}
- /**
- * Dispose controls of overview
+ /**
+ * Dispose controls of overview
*/
public void dispose() {
if (fOverview != null) {
}
}
- /**
+ /**
* @return true if overview is currently on screen
*/
protected boolean overviewing() {
return (fOverview != null && fOverview.isVisible());
}
- /**
+ /**
* Process overview appear
+ *
+ * @param mx
+ * X coordinate
+ * @param my
+ * Y coordinate
*/
protected void overviewAppear(int mx, int my) {
if (fOverview == null) {
int s = 1;
byte src[] = new byte[s * s];
byte msk[] = new byte[s * s];
- for (int i = 0; i < s * s; ++i)
+ for (int i = 0; i < s * s; ++i) {
src[i] = (byte) 0xFF;
+ }
ImageData i_src = new ImageData(s, s, 1, palette, 1, src);
ImageData i_msk = new ImageData(s, s, 1, palette, 1, msk);
fOverviewCursor = new Cursor(null, i_src, i_msk, 0, 0);
// cx,cy to display's global coordinates
p = toGlobalCoordinates(fOverview.getParent(), cx, cy);
- cx = p.x;
- cy = p.y;
-
}
- /**
- * Process disappear of overview
+ /**
+ * Process disappear of overview
*/
protected void overviewDisappear() {
overviewDisappear(true);
}
- /**
+ /**
* Process disappear of overview
- * @param restoreCursorLoc A flag to restore cursor location
+ * @param restoreCursorLoc A flag to restore cursor location
*/
protected void overviewDisappear(boolean restoreCursorLoc) {
- if (fOverview == null)
+ if (fOverview == null) {
return;
+ }
fOverview.setVisible(false);
fCornerControl.setCursor(null);
if (restoreCursorLoc) {
overviewMove(dx, dy, event);
}
- /**
+ /**
* Process mouse move event when overviewing
- *
+ *
* @param dx The x coordinates delta
* @param dy The y coordinates delta
* @param event The typed event
/**
* Convert overview coordinates to global coordinates.
- *
- * @param loc the control reference
- * @param x The x coordinate to convert
- * @param y The y coordinate to convert
- * @return
+ *
+ * @param loc
+ * the control reference
+ * @param x
+ * The x coordinate to convert
+ * @param y
+ * The y coordinate to convert
+ * @return The new converted Point
*/
protected Point toGlobalCoordinates(Control loc, int x, int y) {
Point p = new Point(x, y);