### Eclipse Workspace Patch 1.0 #P org.eclipse.jface Index: src/org/eclipse/jface/dialogs/TitleAreaDialog.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jface/src/org/eclipse/jface/dialogs/TitleAreaDialog.java,v retrieving revision 1.47 diff -u -r1.47 TitleAreaDialog.java --- src/org/eclipse/jface/dialogs/TitleAreaDialog.java 3 Mar 2010 22:39:32 -0000 1.47 +++ src/org/eclipse/jface/dialogs/TitleAreaDialog.java 23 Apr 2010 21:55:52 -0000 @@ -17,9 +17,13 @@ import org.eclipse.jface.resource.JFaceColors; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.RGB; @@ -31,9 +35,10 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; /** * A dialog that has a title area for displaying a title and an image as well as @@ -94,7 +99,7 @@ private String errorMessage; - private Text messageLabel; + private StyledText messageLabel; private Composite workArea; @@ -111,6 +116,24 @@ private Image titleAreaImage; /** + * A control for representing an arrow pointing upwards. This is used for + * scrolling the dialog's message area at the top in the event that the + * message is too long and cannot fit in the allocated space. + * + * @see #downArrow + */ + private Label upArrow; + + /** + * A control for representing an arrow pointing downwards. This is used for + * scrolling the dialog's message area at the top in the event that the + * message is too long and cannot fit in the allocated space. + * + * @see #upArrow + */ + private Label downArrow; + + /** * Instantiate a new title area dialog. * * @param parentShell @@ -146,6 +169,13 @@ // create the dialog area and button bar dialogArea = createDialogArea(workArea); buttonBar = createButtonBar(workArea); + + // need to know whether to draw the up & down arrows + getShell().addListener(SWT.Resize, new Listener() { + public void handleEvent(Event event) { + layoutForNewMessage(); + } + }); return contents; } @@ -245,11 +275,63 @@ messageImageLabel = new Label(parent, SWT.CENTER); messageImageLabel.setBackground(background); // Message label @ bottom, center - messageLabel = new Text(parent, SWT.WRAP | SWT.READ_ONLY); + messageLabel = new StyledText(parent, SWT.WRAP | SWT.READ_ONLY); JFaceColors.setColors(messageLabel, foreground, background); messageLabel.setText(" \n "); // two lines//$NON-NLS-1$ messageLabel.setFont(JFaceResources.getDialogFont()); messageLabelHeight = messageLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; + + // arrows + upArrow = new Label(parent, SWT.NONE); + upArrow.setForeground(titleAreaColor); + upArrow.setBackground(titleAreaColor); + FormData upArrowData = new FormData(); + upArrowData.top = new FormAttachment(titleLabel, verticalSpacing); + upArrowData.right = new FormAttachment(titleImageLabel); + upArrowData.width = 10; + upArrow.setLayoutData(upArrowData); + upArrow.setCursor(Display.getDefault().getSystemCursor(SWT.CURSOR_HAND)); + JFaceColors.setColors(upArrow, foreground, background); + upArrow.addListener(SWT.MouseDown, new Listener() { + public void handleEvent(Event event) { + messageLabel.setTopPixel(messageLabel.getTopPixel() + - messageLabel.getLineHeight()); + } + + }); + upArrow.addPaintListener(new PaintListener() { + public void paintControl(PaintEvent e) { + paintArrow(e, upArrow); + } + }); + + downArrow = new Label(parent, SWT.NONE); + FormData downArrowData = new FormData(); + Control bottomControl = titleImageLabel; + downArrowData.bottom = new FormAttachment(bottomControl, 0, SWT.BOTTOM); + downArrowData.right = new FormAttachment(titleImageLabel); + downArrowData.width = 10; + downArrow.setLayoutData(downArrowData); + downArrow.setCursor(Display.getDefault().getSystemCursor( + SWT.CURSOR_HAND)); + downArrow.setCursor(Display.getDefault().getSystemCursor( + SWT.CURSOR_HAND)); + JFaceColors.setColors(downArrow, foreground, background); + downArrow.addListener(SWT.MouseDown, new Listener() { + + public void handleEvent(Event event) { + messageLabel.setTopPixel(messageLabel.getTopPixel() + + messageLabel.getLineHeight()); + } + + }); + downArrow.addPaintListener(new PaintListener() { + + public void paintControl(PaintEvent e) { + paintArrow(e, downArrow); + } + }); + // Filler labels leftFillerLabel = new Label(parent, SWT.CENTER); leftFillerLabel.setBackground(background); @@ -262,6 +344,49 @@ return messageLabel; } + private void paintArrow(PaintEvent e, Label arrow) { + int[] downPoints = { 0, 2, 8, 2, 4, 6 }; + + Point size = arrow.getSize(); + int x = (size.x - 9) / 2; + int y = (size.y - 9) / 2; + + int[] data = translate(downPoints, x, y); + + Color bg = arrow.getDisplay().getSystemColor( + SWT.COLOR_WIDGET_FOREGROUND); + GC gc = e.gc; + gc.setBackground(bg); + + if (arrow == upArrow) { + // invert the arrow's y data + for (int i = 1; i < data.length; i += 2) { + if (data[i] == 5) { + // this is the middle, ignore + continue; + } + // capping is size 9 + data[i] = data[i] - 9; + if (data[i] < 0) { + // correct negative values + data[i] = data[i] * -1; + } + } + } + gc.fillPolygon(data); + } + + private int[] translate(int[] data, int x, int y) { + int[] target = new int[data.length]; + for (int i = 0; i < data.length; i += 2) { + target[i] = data[i] + x; + } + for (int i = 1; i < data.length; i += 2) { + target[i] = data[i] + y; + } + return target; + } + /** * Determine if the title image is larger than the title message and message * area. This is used for layout decisions. @@ -293,7 +418,11 @@ messageImageLabel.setLayoutData(messageImageData); FormData messageLabelData = new FormData(); messageLabelData.top = new FormAttachment(titleLabel, verticalSpacing); - messageLabelData.right = new FormAttachment(titleImageLabel); + // if scrolling needed, then attach it with the arrow + if (arrowsVisible()) + messageLabelData.right = new FormAttachment(upArrow); + else + messageLabelData.right = new FormAttachment(titleImageLabel); messageLabelData.left = new FormAttachment(messageImageLabel, horizontalSpacing); messageLabelData.height = messageLabelHeight; @@ -437,7 +566,11 @@ FormData messageLabelData = new FormData(); messageLabelData.top = new FormAttachment(titleLabel, verticalSpacing); - messageLabelData.right = new FormAttachment(titleImageLabel); + // if scrolling needed, then attach it with the arrow + if (arrowsVisible()) + messageLabelData.right = new FormAttachment(upArrow); + else + messageLabelData.right = new FormAttachment(titleImageLabel); messageLabelData.left = new FormAttachment(messageImageLabel, 0); messageLabelData.height = messageLabelHeight; if (titleImageLargest) @@ -451,6 +584,15 @@ workArea.getParent().layout(true); } + private boolean arrowsVisible() { + if (dialogArea == null) + return false; + Point newSize = messageLabel.computeSize(messageLabel.getSize().x, + SWT.DEFAULT, true); + return newSize.y > messageLabelHeight; + + } + /** * Set the message text. If the message line currently displays an error, * the message is saved and will be redisplayed when the error message is