X-Git-Url: http://secure.phpeclipse.com
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/CustomSourceInformationControl.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/CustomSourceInformationControl.java
index 06e67f9..3f3c40a 100644
--- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/CustomSourceInformationControl.java
+++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/CustomSourceInformationControl.java
@@ -31,48 +31,64 @@ import org.eclipse.swt.widgets.Shell;
*
* @since 3.0
*/
-public class CustomSourceInformationControl extends SourceViewerInformationControl {
+public class CustomSourceInformationControl extends
+ SourceViewerInformationControl {
/** The font name for the viewer font - the same as the java editor's. */
- private static final String SYMBOLIC_FONT_NAME= "org.eclipse.jdt.ui.editors.textfont"; //$NON-NLS-1$
-
- /** The maximum width of the control, set in setSizeConstraints(int, int)
. */
- int fMaxWidth= Integer.MAX_VALUE;
- /** The maximum height of the control, set in setSizeConstraints(int, int)
. */
- int fMaxHeight= Integer.MAX_VALUE;
-
- /** The partition type to be used as the starting partition type by the paritition scanner. */
+ private static final String SYMBOLIC_FONT_NAME = "net.sourceforge.phpdt.ui.editors.textfont"; //$NON-NLS-1$
+
+ /**
+ * The maximum width of the control, set in
+ * setSizeConstraints(int, int)
.
+ */
+ int fMaxWidth = Integer.MAX_VALUE;
+
+ /**
+ * The maximum height of the control, set in
+ * setSizeConstraints(int, int)
.
+ */
+ int fMaxHeight = Integer.MAX_VALUE;
+
+ /**
+ * The partition type to be used as the starting partition type by the
+ * paritition scanner.
+ */
private String fPartition;
+
/** The horizontal scroll index. */
private int fHorizontalScrollPixel;
-
+
/*
- * @see org.eclipse.jface.text.IInformationControl#setSizeConstraints(int, int)
+ * @see org.eclipse.jface.text.IInformationControl#setSizeConstraints(int,
+ * int)
*/
public void setSizeConstraints(int maxWidth, int maxHeight) {
- fMaxWidth= maxWidth;
- fMaxHeight= maxHeight;
+ fMaxWidth = maxWidth;
+ fMaxHeight = maxHeight;
}
/**
* Creates a new information control.
*
- * @param parent the shell that is the parent of this hover / control
- * @param partition the initial partition type to be used for the underlying viewer
+ * @param parent
+ * the shell that is the parent of this hover / control
+ * @param partition
+ * the initial partition type to be used for the underlying
+ * viewer
*/
public CustomSourceInformationControl(Shell parent, String partition) {
super(parent);
setViewerFont();
setStartingPartitionType(partition);
}
-
+
/*
* @see org.eclipse.jface.text.IInformationControl#computeSizeHint()
*/
public Point computeSizeHint() {
- Point size= super.computeSizeHint();
- size.x= Math.min(size.x, fMaxWidth);
- size.y= Math.min(size.y, fMaxHeight);
+ Point size = super.computeSizeHint();
+ size.x = Math.min(size.x, fMaxWidth);
+ size.y = Math.min(size.y, fMaxHeight);
return size;
}
@@ -80,81 +96,83 @@ public class CustomSourceInformationControl extends SourceViewerInformationContr
* Sets the font for this viewer sustaining selection and scroll position.
*/
private void setViewerFont() {
- Font font= JFaceResources.getFont(SYMBOLIC_FONT_NAME);
+ Font font = JFaceResources.getFont(SYMBOLIC_FONT_NAME);
if (getViewer().getDocument() != null) {
- Point selection= getViewer().getSelectedRange();
- int topIndex= getViewer().getTopIndex();
-
- StyledText styledText= getViewer().getTextWidget();
- Control parent= styledText;
+ Point selection = getViewer().getSelectedRange();
+ int topIndex = getViewer().getTopIndex();
+
+ StyledText styledText = getViewer().getTextWidget();
+ Control parent = styledText;
if (getViewer() instanceof ITextViewerExtension) {
- ITextViewerExtension extension= (ITextViewerExtension) getViewer();
- parent= extension.getControl();
+ ITextViewerExtension extension = (ITextViewerExtension) getViewer();
+ parent = extension.getControl();
}
-
+
parent.setRedraw(false);
-
+
styledText.setFont(font);
-
- getViewer().setSelectedRange(selection.x , selection.y);
+
+ getViewer().setSelectedRange(selection.x, selection.y);
getViewer().setTopIndex(topIndex);
-
+
if (parent instanceof Composite) {
- Composite composite= (Composite) parent;
+ Composite composite = (Composite) parent;
composite.layout(true);
}
-
+
parent.setRedraw(true);
-
+
} else {
- StyledText styledText= getViewer().getTextWidget();
+ StyledText styledText = getViewer().getTextWidget();
styledText.setFont(font);
- }
+ }
}
/**
* Sets the initial partition for the underlying source viewer.
*
- * @param partition the partition type
+ * @param partition
+ * the partition type
*/
public void setStartingPartitionType(String partition) {
if (partition == null)
- fPartition= IDocument.DEFAULT_CONTENT_TYPE;
+ fPartition = IDocument.DEFAULT_CONTENT_TYPE;
else
- fPartition= partition;
+ fPartition = partition;
}
-
+
/*
* @see org.eclipse.jface.text.IInformationControl#setInformation(java.lang.String)
*/
public void setInformation(String content) {
super.setInformation(content);
- IDocument doc= getViewer().getDocument();
+ IDocument doc = getViewer().getDocument();
if (doc == null)
return;
-
+
// ensure that we can scroll enough
ensureScrollable();
-
- String start= null;
+
+ String start = null;
if (IPHPPartitions.PHP_PHPDOC_COMMENT.equals(fPartition)) {
- start= "/**" + doc.getLegalLineDelimiters()[0]; //$NON-NLS-1$
+ start = "/**" + doc.getLegalLineDelimiters()[0]; //$NON-NLS-1$
} else if (IPHPPartitions.PHP_MULTILINE_COMMENT.equals(fPartition)) {
- start= "/*" + doc.getLegalLineDelimiters()[0]; //$NON-NLS-1$
+ start = "/*" + doc.getLegalLineDelimiters()[0]; //$NON-NLS-1$
}
if (start != null) {
try {
doc.replace(0, 0, start);
- int startLen= start.length();
- getViewer().setDocument(doc, startLen, doc.getLength() - startLen);
+ int startLen = start.length();
+ getViewer().setDocument(doc, startLen,
+ doc.getLength() - startLen);
} catch (BadLocationException e) {
// impossible
Assert.isTrue(false);
}
}
-
+
getViewer().getTextWidget().setHorizontalPixel(fHorizontalScrollPixel);
}
@@ -164,28 +182,28 @@ public class CustomSourceInformationControl extends SourceViewerInformationContr
* accordingly.
*/
private void ensureScrollable() {
- IDocument doc= getViewer().getDocument();
+ IDocument doc = getViewer().getDocument();
if (doc == null)
return;
-
- StyledText widget= getViewer().getTextWidget();
+
+ StyledText widget = getViewer().getTextWidget();
if (widget == null || widget.isDisposed())
return;
-
- int last= doc.getNumberOfLines() - 1;
- GC gc= new GC(widget);
+
+ int last = doc.getNumberOfLines() - 1;
+ GC gc = new GC(widget);
gc.setFont(widget.getFont());
- int maxWidth= 0;
- String content= new String();
+ int maxWidth = 0;
+ String content = new String();
try {
- for (int i= 0; i <= last; i++) {
+ for (int i = 0; i <= last; i++) {
IRegion line;
- line= doc.getLineInformation(i);
- content= doc.get(line.getOffset(), line.getLength());
- int width= gc.textExtent(content).x;
+ line = doc.getLineInformation(i);
+ content = doc.get(line.getOffset(), line.getLength());
+ int width = gc.textExtent(content).x;
if (width > maxWidth) {
- maxWidth= width;
+ maxWidth = width;
}
}
} catch (BadLocationException e) {
@@ -193,26 +211,28 @@ public class CustomSourceInformationControl extends SourceViewerInformationContr
} finally {
gc.dispose();
}
-
+
// limit the size of the window to the maximum width minus scrolling,
// but never more than the configured max size (viewport size).
- fMaxWidth= Math.max(0, Math.min(fMaxWidth, maxWidth - fHorizontalScrollPixel + 8));
+ fMaxWidth = Math.max(0, Math.min(fMaxWidth, maxWidth
+ - fHorizontalScrollPixel + 8));
}
-
+
/*
- * @see org.eclipse.jdt.internal.ui.text.java.hover.SourceViewerInformationControl#hasContents()
+ * @see net.sourceforge.phpdt.internal.ui.text.java.hover.SourceViewerInformationControl#hasContents()
*/
public boolean hasContents() {
return super.hasContents() && fMaxWidth > 0;
}
-
+
/**
* Sets the horizontal scroll index in pixels.
- *
- * @param scrollIndex the new horizontal scroll index
+ *
+ * @param scrollIndex
+ * the new horizontal scroll index
*/
public void setHorizontalScrollPixel(int scrollIndex) {
- scrollIndex= Math.max(0, scrollIndex);
- fHorizontalScrollPixel= scrollIndex;
+ scrollIndex = Math.max(0, scrollIndex);
+ fHorizontalScrollPixel = scrollIndex;
}
}