Skip to content

Commit

Permalink
Worksheet: insertions (or embedded blocks) renamed to insets.
Browse files Browse the repository at this point in the history
  • Loading branch information
asheb authored and andreyvit committed Dec 29, 2008
1 parent 6deed4b commit 7b15fce
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public interface WorksheetShortcuts {

boolean isExecHotkey(KeyEvent e);

boolean isRemoveInsertionsHotkey(KeyEvent e);
boolean isRemoveInsetsHotkey(KeyEvent e);

boolean isShowTextHotkey(KeyEvent e);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface WorksheetStyle {

Font resultFont();

Color resultBlockColor();
Color resultInsetColor();

Color outputColor();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package com.yoursway.ide.worksheet.internal.controller;

import com.yoursway.ide.worksheet.internal.view.ResultBlock;
import com.yoursway.ide.worksheet.internal.view.ResultInset;
import com.yoursway.utils.annotations.UseFromUIThread;

public class Command {

private final String commandText;
private final ResultBlockProvider blockProvider;
private final ResultInsetProvider insetProvider;

public Command(String commandText, ResultBlockProvider blockProvider) {
public Command(String commandText, ResultInsetProvider insetProvider) {
if (commandText.trim().length() == 0)
throw new AssertionError("A command must not be empty.");
if (blockProvider == null)
throw new NullPointerException("blockProvider is null");
if (insetProvider == null)
throw new NullPointerException("insetProvider is null");

this.commandText = commandText;
this.blockProvider = blockProvider;
this.insetProvider = insetProvider;
}

public String commandText() {
return commandText;
}

@UseFromUIThread
public ResultBlock block() {
return blockProvider.get();
public ResultInset inset() {
return insetProvider.get();
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.yoursway.ide.worksheet.internal.controller;

import com.yoursway.ide.worksheet.executors.WorksheetCommandExecutor;
import com.yoursway.ide.worksheet.internal.view.ResultBlock;
import com.yoursway.ide.worksheet.internal.view.ResultInset;
import com.yoursway.utils.annotations.UseFromAnyThread;
import com.yoursway.utils.annotations.UseFromUIThread;

public class Execution {

private final String command;
private final ResultBlock output;
private final ResultInset output;
private final WorksheetCommandExecutor executor;

@UseFromUIThread
Expand All @@ -17,14 +17,14 @@ public Execution(Command command, WorksheetCommandExecutor executor) {
throw new NullPointerException("executor is null");

this.command = command.commandText();
output = command.block();
output = command.inset();
this.executor = executor;

output.becomeWaiting();
}

@UseFromAnyThread
public ResultBlock start() {
public ResultInset start() {
output.reset();
executor.executeCommand(command);
return output;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.yoursway.ide.worksheet.internal.controller;

import com.yoursway.ide.worksheet.internal.view.ResultBlock;
import com.yoursway.ide.worksheet.internal.view.ResultInset;
import com.yoursway.utils.annotations.UseFromUIThread;

public interface ResultBlockProvider {
public interface ResultInsetProvider {

@UseFromUIThread
ResultBlock get();
ResultInset get();

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.yoursway.ide.worksheet.WorksheetShortcuts;
import com.yoursway.ide.worksheet.executors.OutputListener;
import com.yoursway.ide.worksheet.executors.WorksheetCommandExecutor;
import com.yoursway.ide.worksheet.internal.view.ResultBlock;
import com.yoursway.ide.worksheet.internal.view.ResultInset;
import com.yoursway.ide.worksheet.internal.view.WorksheetView;
import com.yoursway.ide.worksheet.internal.view.WorksheetViewCallback;
import com.yoursway.ide.worksheet.internal.view.WorksheetViewFactory;
Expand All @@ -23,7 +23,7 @@ public class WorksheetController implements OutputListener, WorksheetViewCallbac
private final WorksheetCommandExecutor executor;

private final Queue<Execution> executions = new LinkedList<Execution>(); //? sync
private ResultBlock outputBlock = null;
private ResultInset outputInset = null;
private final WorksheetShortcuts shortcuts;

public WorksheetController(WorksheetViewFactory viewFactory, WorksheetCommandExecutor executor,
Expand All @@ -50,8 +50,8 @@ public void verifyKey(VerifyEvent e) {
boolean handled = true;
if (shortcuts.isExecHotkey(e))
executeSelectedCommands();
else if (shortcuts.isRemoveInsertionsHotkey(e))
removeAllInsertion();
else if (shortcuts.isRemoveInsetsHotkey(e))
removeAllInsets();
else if (shortcuts.isShowTextHotkey(e))
showSelectedText();
else
Expand All @@ -64,8 +64,8 @@ private void showSelectedText() {
view.showSelectedText();
}

private void removeAllInsertion() {
view.removeAllInsertions();
private void removeAllInsets() {
view.removeAllInsets();
}

private void executeSelectedCommands() {
Expand All @@ -87,31 +87,31 @@ public void modifyText(ExtendedModifyEvent e) {
if (e.length == 1 && view.isNewLineChar(e.start)) //> check line breaking
return;

view.makeInsertionsObsolete(start, end);
view.makeInsetsObsolete(start, end);
}

@UseFromUIThread
private void executeCommand(Command command) {
executions.add(new Execution(command, executor));
if (executions.size() == 1)
outputBlock = executions.peek().start();
outputInset = executions.peek().start();
}

@UseFromAnyThread
@SynchronizedWithMonitorOfThis
public synchronized void outputted(String text, boolean error) {
outputBlock.append(text, error);
outputInset.append(text, error);
}

@UseFromAnyThread
@SynchronizedWithMonitorOfThis
public synchronized void completed() {
executions.poll();
outputBlock = null;
outputInset = null;

Execution execution = executions.peek();
if (execution != null)
outputBlock = execution.start();
outputInset = execution.start();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public boolean isExecHotkey(KeyEvent e) {
return e.stateMask == SWT.COMMAND && (e.character == '\n' || e.character == '\r');
}

public boolean isRemoveInsertionsHotkey(KeyEvent e) {
public boolean isRemoveInsetsHotkey(KeyEvent e) {
return e.stateMask == SWT.COMMAND && e.character == 'r';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Font resultFont() {
return resultFont;
}

public Color resultBlockColor() {
public Color resultInsetColor() {
return resultBackColor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
import com.yoursway.ide.worksheet.WorksheetStyle;
import com.yoursway.swt.animations.SizeAndAlphaAnimation;
import com.yoursway.swt.animations.SizeAndAlphaAnimationApplier;
import com.yoursway.swt.styledtext.extended.EmbeddedBlock;
import com.yoursway.swt.styledtext.extended.EmbeddedBlockSite;
import com.yoursway.swt.styledtext.extended.Inset;
import com.yoursway.swt.styledtext.extended.InsetSite;
import com.yoursway.swt.styledtext.extended.ResizeListener;
import com.yoursway.utils.annotations.DeadlockWarningBlocksOnUIThread;
import com.yoursway.utils.annotations.UseFromAnyThread;
import com.yoursway.utils.annotations.UseFromUIThread;

public class ResultBlock implements EmbeddedBlock {
public class ResultInset implements Inset {

private final WorksheetStyle style;
private StyledText embeddedText;
private CoolScrollBar scrollBar;
private EmbeddedBlockSite site;
private InsetSite site;

private final SizeAndAlphaAnimation animation;
private int alpha;
Expand All @@ -36,7 +36,7 @@ public class ResultBlock implements EmbeddedBlock {
private int newLines = 0;

@UseFromAnyThread
public ResultBlock(WorksheetStyle style) {
public ResultInset(WorksheetStyle style) {
if (style == null)
throw new NullPointerException("settings is null");

Expand All @@ -46,14 +46,14 @@ public ResultBlock(WorksheetStyle style) {
}

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

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

Expand All @@ -70,7 +70,7 @@ public void resized(Point size) {
private void initComposite(final Composite composite) {
composite.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
e.gc.setBackground(style.resultBlockColor());
e.gc.setBackground(style.resultInsetColor());
Point size = composite.getSize();
int radius = 10, left = 10; //! magic
e.gc.fillRoundRectangle(left, 0, size.x - left, size.y, radius, radius);
Expand All @@ -85,7 +85,7 @@ public void paintControl(PaintEvent e) {
private void initEmbeddedText(Composite composite) {
embeddedText = new StyledText(composite, SWT.MULTI | SWT.WRAP);
embeddedText.setFont(style.resultFont());
embeddedText.setBackground(style.resultBlockColor());
embeddedText.setBackground(style.resultInsetColor());
embeddedText.setForeground(style.outputColor());
embeddedText.setEditable(false);
embeddedText.setLocation(18, 5); //! magic
Expand Down Expand Up @@ -136,7 +136,7 @@ public void run() {
@UseFromAnyThread
@DeadlockWarningBlocksOnUIThread
public void updateAlpha(final int alpha) {
ResultBlock.this.alpha = alpha;
ResultInset.this.alpha = alpha;

if (composite.isDisposed())
return;
Expand Down Expand Up @@ -245,7 +245,7 @@ public void run() {
int start = embeddedText.getCharCount();
embeddedText.append(t);
if (error) {
StyleRange style = ResultBlock.this.style.errorStyle(start, t.length());
StyleRange style = ResultInset.this.style.errorStyle(start, t.length());
embeddedText.setStyleRange(style);
}
updateSize(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import com.yoursway.ide.worksheet.WorksheetStyle;
import com.yoursway.ide.worksheet.internal.controller.Command;
import com.yoursway.ide.worksheet.internal.controller.ResultBlockProvider;
import com.yoursway.ide.worksheet.internal.controller.ResultInsetProvider;
import com.yoursway.swt.styledtext.extended.ExtendedStyledText;
import com.yoursway.utils.annotations.UseFromUIThread;

Expand Down Expand Up @@ -48,10 +48,10 @@ public Iterable<Command> selectedCommands() {
continue;

final int j = i;
commands.add(new Command(commandText, new ResultBlockProvider() {
commands.add(new Command(commandText, new ResultInsetProvider() {
@UseFromUIThread
public ResultBlock get() {
return block(j);
public ResultInset get() {
return inset(j);
}
}));
}
Expand All @@ -63,22 +63,22 @@ private String commandText(int lineIndex) {
}

@UseFromUIThread
private ResultBlock block(int lineIndex) {
if (extendedText.lineHasInsertion(lineIndex))
return (ResultBlock) extendedText.existingInsertion(lineIndex);
private ResultInset inset(int lineIndex) {
if (extendedText.lineHasInset(lineIndex))
return (ResultInset) extendedText.existingInset(lineIndex);
else
return addBlock(lineIndex);
return addInset(lineIndex);
}

private ResultBlock addBlock(int lineIndex) {
ResultBlock block = new ResultBlock(style);
extendedText.addEmbeddedBlock(lineIndex, block);
return block;
private ResultInset addInset(int lineIndex) {
ResultInset inset = new ResultInset(style);
extendedText.addInset(lineIndex, inset);
return inset;
}

public void removeAllInsertions() {
public void removeAllInsets() {
for (int i = 0; i < extendedText.getLineCount(); i++) {
extendedText.removeInsertion(i);
extendedText.removeInset(i);
}
}

Expand All @@ -91,13 +91,13 @@ public void makeNewLineAtEnd() {
extendedText.setSelection(extendedText.getCharCount());
}

public void makeInsertionsObsolete(int start, int end) {
public void makeInsetsObsolete(int start, int end) {
int firstLine = extendedText.getLineAtOffset(start);
int lastLine = extendedText.getLineAtOffset(end);
for (int i = firstLine; i <= lastLine; i++) {
if (extendedText.lineHasInsertion(i)) {
ResultBlock block = (ResultBlock) extendedText.existingInsertion(i);
block.becomeObsolete();
if (extendedText.lineHasInset(i)) {
ResultInset inset = (ResultInset) extendedText.existingInset(i);
inset.becomeObsolete();
}
}
}
Expand Down

0 comments on commit 7b15fce

Please sign in to comment.