Skip to content

Commit

Permalink
Worksheet: ResultBlock.init refactored.
Browse files Browse the repository at this point in the history
  • Loading branch information
asheb authored and andreyvit committed Dec 29, 2008
1 parent 5cd5540 commit 1568a65
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 22 deletions.
@@ -1,12 +1,19 @@
package com.yoursway.ide.worksheet;

import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;

public interface WorksheetStyle {

Font worksheetFont();

Font resultFont();

Color resultBlockColor();

Color outputColor();

StyleRange errorStyle(int offset, int length);

}
@@ -1,5 +1,6 @@
package com.yoursway.ide.worksheet.internal.demo;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
Expand All @@ -10,17 +11,38 @@
public class StyleMock implements WorksheetStyle {

private final Font font;
private final Font resultFont;

private final Color resultBackColor;
private final Color outputColor;
private final Color errorColor;

public StyleMock(Display display) {
font = new Font(display, "Monaco", 12, 0);
resultFont = new Font(display, "Monaco", 12, SWT.BOLD);

resultBackColor = new Color(display, 100, 100, 100);
outputColor = new Color(display, 255, 255, 255);
errorColor = new Color(display, 255, 192, 192);

}

public Font worksheetFont() {
return font;
}

public Font resultFont() {
return resultFont;
}

public Color resultBlockColor() {
return resultBackColor;
}

public Color outputColor() {
return outputColor;
}

public StyleRange errorStyle(int start, int length) {
StyleRange style = new StyleRange();
style.start = start;
Expand Down
Expand Up @@ -5,12 +5,8 @@
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;

import com.yoursway.ide.worksheet.WorksheetStyle;
import com.yoursway.swt.animations.SizeAndAlphaAnimation;
Expand Down Expand Up @@ -46,18 +42,31 @@ public ResultBlock(WorksheetStyle style) {
}

@UseFromUIThread
public void init(final Composite composite, final EmbeddedBlockSite site) {
public void init(Composite composite, EmbeddedBlockSite site) {
initSite(site);
initComposite(composite);
initEmbeddedText(composite);
initAnimation(composite);
}

private void initSite(final EmbeddedBlockSite site) {
if (site == null)
throw new NullPointerException("site is null");

this.site = site;

Display display = composite.getDisplay();
final Color color = new Color(display, 100, 100, 100); //! magic

site.addResizeListener(new ResizeListener() {
@UseFromUIThread
public void resized(Point size) {
updateSize(true);
}
});
}

private void initComposite(final Composite composite) {
composite.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.setBackground(color);
e.gc.setBackground(style.resultBlockColor());
Point size = composite.getSize();
int radius = 10, left = 10; //! magic
e.gc.fillRoundRectangle(left, 0, size.x - left, size.y, radius, radius);
Expand All @@ -67,11 +76,13 @@ public void paintControl(PaintEvent e) {
e.gc.fillRectangle(0, 0, size.x, size.y);
}
});

}

private void initEmbeddedText(Composite composite) {
embeddedText = new StyledText(composite, SWT.MULTI | SWT.WRAP);
embeddedText.setBackground(color);
embeddedText.setForeground(new Color(display, 255, 255, 255)); //! magic
embeddedText.setFont(new Font(display, "Monaco", 12, SWT.BOLD)); //! magic
embeddedText.setFont(style.resultFont());
embeddedText.setBackground(style.resultBlockColor());
embeddedText.setForeground(style.outputColor());
embeddedText.setEditable(false);
embeddedText.setLocation(18, 5); //! magic

Expand All @@ -81,18 +92,13 @@ public void paintControl(PaintEvent e) {
public void paintControl(PaintEvent e) {
e.gc.setBackground(site.getBackground());
e.gc.setAlpha(255 - alpha);
Point size = ((Control) e.widget).getSize();
Point size = embeddedText.getSize();
e.gc.fillRectangle(0, 0, size.x, size.y);
}
});

site.addResizeListener(new ResizeListener() {
@UseFromUIThread
public void resized(Point size) {
updateSize(true);
}
});

}

private void initAnimation(final Composite composite) {
alpha = 0;
animation.targetAlpha(255);

Expand Down

0 comments on commit 1568a65

Please sign in to comment.