Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 25686 Details for
Bug 106065
moving the caret with the arrow keys doesn't move the viewport accordingly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
patch for GraphicalTextViewer
moving_caret.patch (text/plain), 5.17 KB, created by
Takahiro Kato
on 2005-08-04 12:23:11 EDT
(
hide
)
Description:
patch for GraphicalTextViewer
Filename:
MIME Type:
Creator:
Takahiro Kato
Created:
2005-08-04 12:23:11 EDT
Size:
5.17 KB
patch
obsolete
>--- /usr/tkato/eclipse_cvs/org.eclipse.gef.examples.text/src/org/eclipse/gef/examples/text/GraphicalTextViewer.java 2005-05-17 14:24:20.000000000 -0700 >+++ /usr/tkato/IdeaProjects/gef_cvs/text_example/src/org/eclipse/gef/examples/text/GraphicalTextViewer2.java 2005-08-02 16:18:39.000000000 -0700 >@@ -11,27 +11,25 @@ > > package org.eclipse.gef.examples.text; > >-import java.util.List; >-import java.util.Map; >- >-import org.eclipse.swt.widgets.Canvas; >-import org.eclipse.swt.widgets.Caret; >- >-import org.eclipse.jface.util.Assert; >- >+import org.eclipse.draw2d.FigureCanvas; > import org.eclipse.draw2d.UpdateListener; > import org.eclipse.draw2d.UpdateManager; >+import org.eclipse.draw2d.Viewport; > import org.eclipse.draw2d.geometry.Rectangle; > import org.eclipse.draw2d.text.CaretInfo; >- >+import org.eclipse.gef.examples.text.edit.TextualEditPart; > import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer; >+import org.eclipse.jface.util.Assert; >+import org.eclipse.swt.widgets.Canvas; >+import org.eclipse.swt.widgets.Caret; > >-import org.eclipse.gef.examples.text.edit.TextualEditPart; >+import java.util.List; >+import java.util.Map; > > /** > * @since 3.1 > */ >-public class GraphicalTextViewer extends ScrollingGraphicalViewer { >+public class GraphicalTextViewer2 extends ScrollingGraphicalViewer { > > class CaretRefresh implements Runnable { > public void run() { >@@ -40,10 +38,20 @@ > } > } > >+private class ViewportRefresh implements Runnable { >+ public void run() { >+ refreshViewport(); >+ viewportRefresh = null; >+ } >+} >+ > private Caret caret; > private Runnable caretRefresh; > private SelectionRange selectionRange; > >+/** The thread to refresh the viewport */ >+private Runnable viewportRefresh; >+ > private Caret getCaret() { > if (caret == null && getControl() != null) > caret = new Caret((Canvas)getControl(), 0); >@@ -90,6 +98,13 @@ > queueCaretRefresh(); > } > }); >+ >+ getUpdateManager().addUpdateListener(new UpdateListener() { >+ public void notifyPainting(Rectangle damage, Map dirtyRegions) { } >+ public void notifyValidating() { >+ queueViewportRefresh(); >+ } >+ }); > } > > /** >@@ -103,15 +118,15 @@ > } > >@@ -121,6 +136,102 @@ > } > > /** >+ * Queues the viewport to refresh. >+ */ >+void queueViewportRefresh() { >+ if (viewportRefresh == null) { >+ viewportRefresh = new ViewportRefresh(); >+ getUpdateManager().runWithUpdate(viewportRefresh); >+ } >+} >+ >+/** >+ * Refreshes the viewport. >+ */ >+void refreshViewport() { >+ if (getCaretOwner() == null) >+ return; >+ CaretInfo newCaretInfo; >+ TextLocation location = getCaretLocation (); >+ if (getSelectionRange().isForward && location.offset > 0) >+ { >+ newCaretInfo = getCaretOwner().getCaretPlacement(location.offset - 1, true); >+ } >+ else >+ { >+ newCaretInfo = getCaretOwner().getCaretPlacement(location.offset, false); >+ } >+ refreshViewport(newCaretInfo); >+} >+ >+/** >+ * Scrolls the view if necessary to show the new caret location. >+ * >+ * @param newCaretInfo new caret info to show. >+ */ >+public void refreshViewport(CaretInfo newCaretInfo) >+{ >+ // update the viewport >+ boolean forward = getSelectionRange().isForward; >+ FigureCanvas figureCanvas = (FigureCanvas) getControl(); >+ Viewport viewport = figureCanvas.getViewport(); >+ int viewPortHeight = viewport.getBounds().height; >+ >+ int caretNewYEnd = newCaretInfo.getLineY() + newCaretInfo.getLineHeight(); >+ int currentViewportY = viewport.getViewLocation().y; >+ int dy = 0; >+ >+ if (forward) { >+ dy = caretNewYEnd - viewPortHeight; >+ } else { >+ int newCaretY = newCaretInfo.getLineY(); >+ if (newCaretY < 0) >+ dy = newCaretY; >+ } >+ >+ refreshViewportX(newCaretInfo); >+ >+ if (dy != 0) >+ figureCanvas.scrollToY(currentViewportY + dy); >+} >+ >+public void refreshViewportX(CaretInfo newCaretInfo) { >+ FigureCanvas figureCanvas = getFigureCanvas(); >+ Viewport viewport = figureCanvas.getViewport(); >+ boolean forward = getSelectionRange().isForward; >+ int newX = newCaretInfo.getX(); >+ int currentViewportX = viewport.getViewLocation().x; >+ int viewportLength = viewport.getClientArea().width; >+ // this value is to display the caret in the 2/3 from right in the viewport. >+ int viewportOffsetLength = viewport.getClientArea().width / 3 * 2; >+ int locationX = currentViewportX; >+ if (forward) { >+ if (newX < 0) { >+ // this means the caret is going to the next line. >+ locationX = 0; >+ } >+ >+ if (newX > viewportLength) { >+ // caret went out of the viewport (to right) >+ locationX += newX - viewportOffsetLength; >+ } >+ } else { >+ >+ if (newX < 0) { >+ // caret went out of the view port (to left) >+ locationX += newX - viewportOffsetLength; >+ } >+ >+ if (newX > viewportLength) { >+ // this means it's wrapping back to the previous line. >+ locationX = newX; >+ } >+ } >+ >+ figureCanvas.scrollToX(locationX); >+} >+ >+/** > * Sets the selection range to the given value. Updates any editparts which had or will > * have textual selection. Fires selection changed. Place the caret in the appropriate > * location.
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 106065
: 25686