use of org.eclipse.swt.events.PaintEvent in project BiglyBT by BiglySoftware.
the class MultiPlotGraphic method initialize.
public void initialize(Canvas canvas, boolean is_active) {
super.initialize(canvas);
drawCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
if (bufferImage != null && !bufferImage.isDisposed()) {
Rectangle bounds = bufferImage.getBounds();
if (bounds.width >= (e.width + e.x) && bounds.height >= (e.height + e.y)) {
e.gc.drawImage(bufferImage, e.x, e.y, e.width, e.height, e.x, e.y, e.width, e.height);
}
}
}
});
drawCanvas.addListener(SWT.Resize, new Listener() {
@Override
public void handleEvent(Event event) {
drawChart(true);
}
});
setActive(is_active);
}
use of org.eclipse.swt.events.PaintEvent in project BiglyBT by BiglySoftware.
the class ProgressWindow method showDialog.
protected void showDialog(Shell _shell, CoreOperation _core_op) {
shell = _shell;
if (shell == null || shell.isDisposed()) {
return;
}
boolean closeable = (shell.getStyle() & SWT.CLOSE) != 0;
shell.setText(MessageText.getString("progress.window.title"));
CoreOperationTask task = _core_op == null ? null : _core_op.getTask();
ProgressCallback progress = task == null ? null : task.getProgressCallback();
boolean alreadyPositioned = Utils.linkShellMetricsToConfig(shell, "com.biglybt.ui.swt.progress.ProgressWindow" + "." + _core_op.getOperationType());
Utils.setShellIcon(shell);
if (!closeable) {
shell.addListener(SWT.Close, (ev) -> {
ev.doit = false;
});
}
GridLayout layout = new GridLayout();
layout.numColumns = 2;
shell.setLayout(layout);
Color bg = (Utils.isDarkAppearanceNative() || Utils.isDarkAppearancePartial()) ? null : Colors.white;
shell.setBackground(bg);
if (task != null) {
String name = task.getName();
if (name != null) {
Label lName = new Label(shell, SWT.NONE);
FontData fontData = lName.getFont().getFontData()[0];
Font bold_font = new Font(shell.getDisplay(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
lName.setText(name);
GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
lName.setLayoutData(gridData);
lName.setBackground(bg);
lName.setFont(bold_font);
lName.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent arg0) {
bold_font.dispose();
}
});
if (progress != null && (progress.getSupportedTaskStates() & ProgressCallback.ST_SUBTASKS) != 0) {
subtask_label = new Label(shell, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
gridData.horizontalIndent = 25;
subtask_label.setLayoutData(gridData);
subtask_label.setBackground(bg);
}
}
}
spinImages = ImageLoader.getInstance().getImages("working");
if (spinImages == null || spinImages.length == 0) {
new Label(shell, SWT.NULL);
} else {
final Rectangle spinBounds = spinImages[0].getBounds();
final Canvas canvas = new Canvas(shell, SWT.DOUBLE_BUFFERED) {
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return (new Point(spinBounds.width, spinBounds.height));
}
};
canvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
e.gc.drawImage(spinImages[curSpinIndex], 0, 0);
}
});
Utils.execSWTThreadLater(100, new AERunnable() {
@Override
public void runSupport() {
if (canvas == null || canvas.isDisposed()) {
return;
}
canvas.redraw();
if (curSpinIndex == spinImages.length - 1) {
curSpinIndex = 0;
} else {
curSpinIndex++;
}
if (progress != null && progress_bar != null) {
if (progress_bar.isDisposed()) {
return;
}
int p = progress.getProgress();
progress_bar.setSelection(p);
if (subtask_label != null) {
String st = progress.getSubTaskName();
if (st == null) {
st = "";
}
subtask_label.setText(st);
}
}
Utils.execSWTThreadLater(100, this);
}
});
canvas.setBackground(bg);
}
Label label = new Label(shell, SWT.NONE);
label.setText(MessageText.getString(resource));
GridData gridData = new GridData();
label.setLayoutData(gridData);
label.setBackground(bg);
if (progress != null) {
Composite compProg = new Composite(shell, SWT.BORDER);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalSpan = 2;
compProg.setLayoutData(gridData);
GridLayout layoutProgress = new GridLayout();
layoutProgress.numColumns = 1;
layoutProgress.marginWidth = layoutProgress.marginHeight = 0;
compProg.setLayout(layoutProgress);
compProg.setBackground(bg);
progress_bar = new ProgressBar(compProg, SWT.HORIZONTAL);
progress_bar.setMinimum(0);
progress_bar.setMaximum(1000);
progress_bar.setBackground(bg);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.widthHint = 400;
progress_bar.setLayoutData(gridData);
int states = progress.getSupportedTaskStates();
if ((states & ProgressCallback.ST_BUTTONS) != 0) {
Label labelSeparator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
labelSeparator.setLayoutData(gridData);
// buttons
boolean has_pause_resume = (states & (ProgressCallback.ST_PAUSE | ProgressCallback.ST_RESUME)) != 0;
boolean has_cancel = (states & ProgressCallback.ST_CANCEL) != 0;
if (!has_pause_resume) {
has_cancel = true;
}
int num_buttons = 0;
if (has_pause_resume)
num_buttons += 2;
if (has_cancel)
num_buttons++;
Composite comp = new Composite(shell, SWT.NULL);
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END | GridData.HORIZONTAL_ALIGN_FILL);
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalSpan = 2;
comp.setLayoutData(gridData);
GridLayout layoutButtons = new GridLayout();
layoutButtons.numColumns = num_buttons;
comp.setLayout(layoutButtons);
comp.setBackground(bg);
List<Button> buttons = new ArrayList<>();
Button bPause;
Button bResume;
Button bCancel;
if (has_pause_resume) {
bPause = new Button(comp, SWT.PUSH);
bPause.setText(MessageText.getString("v3.MainWindow.button.pause"));
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END | GridData.HORIZONTAL_ALIGN_FILL);
gridData.grabExcessHorizontalSpace = true;
// gridData.widthHint = 70;
bPause.setLayoutData(gridData);
buttons.add(bPause);
bResume = new Button(comp, SWT.PUSH);
bResume.setText(MessageText.getString("v3.MainWindow.button.resume"));
gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END | GridData.HORIZONTAL_ALIGN_FILL);
gridData.grabExcessHorizontalSpace = false;
// gridData.widthHint = 70;
bResume.setLayoutData(gridData);
buttons.add(bResume);
} else {
bPause = null;
bResume = null;
}
if (has_cancel) {
bCancel = new Button(comp, SWT.PUSH);
bCancel.setText(MessageText.getString("UpdateWindow.cancel"));
gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
gridData.grabExcessHorizontalSpace = false;
// gridData.widthHint = 70;
bCancel.setLayoutData(gridData);
buttons.add(bCancel);
} else {
bCancel = null;
}
Utils.makeButtonsEqualWidth(buttons);
if (has_pause_resume) {
// if we have resume then we have pause
bResume.setEnabled(false);
bPause.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
task_paused = true;
bPause.setEnabled(false);
bResume.setEnabled(true);
shell.setDefaultButton(bResume);
progress.setTaskState(ProgressCallback.ST_PAUSE);
}
});
bResume.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
task_paused = false;
bPause.setEnabled(true);
bResume.setEnabled(false);
shell.setDefaultButton(bPause);
progress.setTaskState(ProgressCallback.ST_RESUME);
}
});
}
if (bCancel != null) {
bCancel.addListener(SWT.Selection, new Listener() {
@Override
public void handleEvent(Event e) {
if (has_pause_resume) {
bPause.setEnabled(false);
bResume.setEnabled(false);
}
bCancel.setEnabled(false);
progress.setTaskState(ProgressCallback.ST_CANCEL);
}
});
}
Utils.execSWTThreadLater(250, new Runnable() {
@Override
public void run() {
if (comp.isDisposed()) {
return;
}
int state = progress.getTaskState();
if (state == ProgressCallback.ST_CANCEL) {
shell.dispose();
} else {
if (has_pause_resume) {
if (state == ProgressCallback.ST_PAUSE) {
bPause.setEnabled(false);
bResume.setEnabled(true);
} else {
bPause.setEnabled(true);
bResume.setEnabled(false);
}
}
Utils.execSWTThreadLater(250, this);
}
}
});
shell.setDefaultButton(has_pause_resume ? bPause : bCancel);
shell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent arg0) {
if (task_paused) {
progress.setTaskState(ProgressCallback.ST_RESUME);
}
}
});
}
}
shell.pack();
if (!alreadyPositioned) {
Composite parent = shell.getParent();
if (parent != null) {
Utils.centerWindowRelativeTo(shell, parent);
} else {
Utils.centreWindow(shell);
}
}
shell.open();
}
use of org.eclipse.swt.events.PaintEvent in project BiglyBT by BiglySoftware.
the class ViewQuickNotifications method initialize.
private void initialize(Composite parent) {
parent.setLayout(new GridLayout());
composite = new Composite(parent, SWT.BORDER);
GridData gridData = new GridData(GridData.FILL_BOTH);
composite.setLayoutData(gridData);
GridLayout layout = new GridLayout(2, false);
layout.marginLeft = layout.marginRight = layout.marginTop = layout.marginBottom = 0;
composite.setLayout(layout);
// icon
notification_icon = new Label(composite, SWT.NONE);
gridData = new GridData();
gridData.widthHint = 20;
notification_icon.setLayoutData(gridData);
// text
notification_text = new Label(composite, SWT.DOUBLE_BUFFERED);
gridData = new GridData(GridData.FILL_HORIZONTAL);
notification_text.setLayoutData(gridData);
MouseAdapter listener = new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
UIFunctions uif = UIFunctionsManager.getUIFunctions();
if (uif != null) {
uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_ACTIVITIES);
}
}
};
// text
more_text = new BufferedLabel(composite, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalSpan = 2;
more_text.setLayoutData(gridData);
notification_text.setData("");
Control[] controls = { composite, notification_icon, notification_text, more_text.getControl() };
for (Control c : controls) {
c.addMouseListener(listener);
Messages.setLanguageTooltip(c, "label.click.to.view.tooltip");
}
notification_text.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
String text = (String) notification_text.getData();
int style = SWT.LEFT;
Rectangle bounds = notification_text.getBounds();
bounds.x = 4;
bounds.y = 0;
bounds.width -= 8;
GCStringPrinter sp = new GCStringPrinter(e.gc, text, bounds, true, true, style);
sp.calculateMetrics();
sp.printString();
}
});
}
use of org.eclipse.swt.events.PaintEvent in project translationstudio8 by heartsome.
the class Grid method initListeners.
/**
* Initialize all listeners.
*/
private void initListeners() {
disposeListener = new Listener() {
public void handleEvent(Event e) {
onDispose(e);
}
};
addListener(SWT.Dispose, disposeListener);
addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
onPaint(e);
}
});
addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
onResize();
}
});
if (getVerticalBar() != null) {
getVerticalBar().addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
onScrollSelection();
}
});
}
if (getHorizontalBar() != null) {
getHorizontalBar().addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
onScrollSelection();
}
});
}
addListener(SWT.KeyDown, new Listener() {
public void handleEvent(Event e) {
onKeyDown(e);
}
});
addTraverseListener(new TraverseListener() {
public void keyTraversed(TraverseEvent e) {
e.doit = true;
}
});
addMouseListener(new MouseListener() {
public void mouseDoubleClick(MouseEvent e) {
onMouseDoubleClick(e);
}
public void mouseDown(MouseEvent e) {
onMouseDown(e);
}
public void mouseUp(MouseEvent e) {
onMouseUp(e);
}
});
addMouseMoveListener(new MouseMoveListener() {
public void mouseMove(MouseEvent e) {
onMouseMove(e);
}
});
addMouseTrackListener(new MouseTrackListener() {
public void mouseEnter(MouseEvent e) {
}
public void mouseExit(MouseEvent e) {
onMouseExit(e);
}
public void mouseHover(MouseEvent e) {
}
});
addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
onFocusIn();
redraw();
}
public void focusLost(FocusEvent e) {
redraw();
}
});
// Special code to reflect mouse wheel events if using an external
// scroller
addListener(SWT.MouseWheel, new Listener() {
public void handleEvent(Event e) {
onMouseWheel(e);
}
});
}
use of org.eclipse.swt.events.PaintEvent in project translationstudio8 by heartsome.
the class InnerTag method init.
// 初始化组件。
private void init() {
addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
tagRender.draw(e.gc, innerTagBean, 0, 0);
}
});
addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
Control parent = getParent();
if (parent instanceof StyledText) {
StyledText text = (StyledText) parent;
Point size = getSize();
Point p = getLocation();
int offset = text.getOffsetAtLocation(p);
int mouseX = e.x;
if (mouseX > size.x / 2) {
text.setCaretOffset(offset + 1);
} else {
text.setCaretOffset(offset);
}
}
}
});
}
Aggregations