use of org.eclipse.swt.widgets.Canvas in project netxms by netxms.
the class ScreenshotView method createPartControl.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
parent.setLayout(new FillLayout());
scroller = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
canvas = new Canvas(scroller, SWT.NONE);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
GC gc = e.gc;
if (image != null) {
gc.drawImage(image, 0, 0);
gc.drawText(imageInfo, 10, image.getImageData().height + 10);
} else if (errorMessage != null) {
gc.setForeground(canvas.getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
gc.setFont(JFaceResources.getBannerFont());
gc.drawText(errorMessage, 10, 10, true);
}
}
});
scroller.setContent(canvas);
scroller.setExpandVertical(true);
scroller.setExpandHorizontal(true);
scroller.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
updateScrollerSize();
}
});
activateContext();
createActions();
contributeToActionBars();
refresh();
}
use of org.eclipse.swt.widgets.Canvas in project netxms by netxms.
the class AvailabilityChart method createClientArea.
/* (non-Javadoc)
* @see org.netxms.ui.eclipse.widgets.DashboardElement#createClientArea(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createClientArea(Composite parent) {
Composite clientArea = new Composite(parent, SWT.NONE);
colors = new ColorCache(clientArea);
GridLayout layout = new GridLayout();
layout.numColumns = 4;
clientArea.setLayout(layout);
dayChart = createChart(clientArea, Messages.get().AvailabilityChart_Today);
weekChart = createChart(clientArea, Messages.get().AvailabilityChart_ThisWeek);
monthChart = createChart(clientArea, Messages.get().AvailabilityChart_ThisMonth);
Canvas legend = new Canvas(clientArea, SWT.NONE);
legend.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent e) {
paintLegend(e.gc);
}
});
GridData gd = new GridData();
gd.horizontalAlignment = SWT.FILL;
gd.grabExcessHorizontalSpace = true;
gd.verticalAlignment = SWT.FILL;
gd.grabExcessVerticalSpace = true;
legend.setLayoutData(gd);
return clientArea;
}
use of org.eclipse.swt.widgets.Canvas in project core by jcryptool.
the class AlgorithmView method createSearchArea.
/**
* Creates the search field. On Mac the text does contain a clear (reset) icon which resets
* the view filter. Since Windows does not support this an additional clear (reset) icon
* is shown next to the text.
*
* @param parent The parent composite
*/
private void createSearchArea(Composite parent) {
// search field
final Text search = new Text(parent, SWT.SEARCH | SWT.ICON_CANCEL | SWT.ICON_SEARCH);
if ((search.getStyle() & SWT.CANCEL) == 0) {
// reset search button for systems that do not support the cancel icon
Canvas canvas = new Canvas(parent, SWT.NONE);
GridData gridData = new GridData();
gridData.heightHint = 18;
gridData.widthHint = 18;
canvas.setLayoutData(gridData);
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
// $NON-NLS-1$
e.gc.drawImage(ViewsPlugin.getImageDescriptor("icons/clear.gif").createImage(), 1, 1);
}
});
canvas.addMouseListener(new MouseAdapter() {
public void mouseUp(MouseEvent e) {
search.setText(Messages.AlgorithmView_search_message);
search.setForeground(COLOR_FILTER_INITIAL);
initialSearchState = true;
// $NON-NLS-1$
treeView.setFilter("");
// $NON-NLS-1$
paletteView.setFilter("");
}
});
}
search.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
search.setText(Messages.AlgorithmView_search_message);
search.setForeground(COLOR_FILTER_INITIAL);
search.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
if (initialSearchState) {
// $NON-NLS-1$
search.setText("");
search.setForeground(COLOR_FILTER_USER);
initialSearchState = false;
}
}
});
search.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
treeView.setFilter(search.getText());
paletteView.setFilter(search.getText());
}
});
search.addSelectionListener(new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
if (e.detail == SWT.CANCEL) {
search.setText(Messages.AlgorithmView_search_message);
search.setForeground(COLOR_FILTER_INITIAL);
initialSearchState = true;
// $NON-NLS-1$
treeView.setFilter("");
// $NON-NLS-1$
paletteView.setFilter("");
}
}
});
}
use of org.eclipse.swt.widgets.Canvas in project janrufmonitor by tbrandt77.
the class BalloonWindow method prepareForOpen.
public void prepareForOpen() {
Point contentsSize = contents.getSize();
Point titleSize = new Point(0, 0);
boolean showTitle = ((style & (SWT.CLOSE | SWT.TITLE)) != 0);
if (showTitle) {
if (titleLabel == null) {
titleLabel = new Label(shell, SWT.NONE);
titleLabel.setBackground(shell.getBackground());
titleLabel.setForeground(shell.getForeground());
FontData[] fds = shell.getFont().getFontData();
for (int i = 0; i < fds.length; i++) {
fds[i].setStyle(fds[i].getStyle() | SWT.BOLD);
}
final Font font = new Font(shell.getDisplay(), fds);
titleLabel.addListener(SWT.Dispose, new Listener() {
public void handleEvent(Event event) {
font.dispose();
}
});
titleLabel.setFont(font);
selectionControls.add(titleLabel);
}
String titleText = shell.getText();
titleLabel.setText(titleText == null ? "" : titleText);
titleLabel.pack();
titleSize = titleLabel.getSize();
final Image titleImage = shell.getImage();
if (titleImageLabel == null && shell.getImage() != null) {
titleImageLabel = new Canvas(shell, SWT.NONE);
titleImageLabel.setBackground(shell.getBackground());
titleImageLabel.setBounds(titleImage.getBounds());
titleImageLabel.addListener(SWT.Paint, new Listener() {
public void handleEvent(Event event) {
event.gc.drawImage(titleImage, 0, 0);
}
});
Point tilSize = titleImageLabel.getSize();
titleSize.x += tilSize.x + titleWidgetSpacing;
if (tilSize.y > titleSize.y)
titleSize.y = tilSize.y;
selectionControls.add(titleImageLabel);
}
if (systemControlsBar == null && (style & SWT.CLOSE) != 0) {
// Color closeFG = shell.getForeground(), closeBG = shell.getBackground();
// Color closeFG = shell.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY), closeBG = shell.getBackground();
Color closeFG = shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND), closeBG = shell.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
final Image closeImage = createCloseImage(shell.getDisplay(), closeBG, closeFG);
shell.addListener(SWT.Dispose, new Listener() {
public void handleEvent(Event event) {
closeImage.dispose();
}
});
systemControlsBar = new ToolBar(shell, SWT.FLAT);
systemControlsBar.setBackground(closeBG);
systemControlsBar.setForeground(closeFG);
ToolItem closeItem = new ToolItem(systemControlsBar, SWT.PUSH);
closeItem.setImage(closeImage);
closeItem.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
shell.close();
}
});
systemControlsBar.pack();
Point closeSize = systemControlsBar.getSize();
titleSize.x += closeSize.x + titleWidgetSpacing;
if (closeSize.y > titleSize.y)
titleSize.y = closeSize.y;
}
titleSize.y += titleSpacing;
if (titleSize.x > contentsSize.x) {
contentsSize.x = titleSize.x;
contents.setSize(contentsSize.x, contentsSize.y);
}
contentsSize.y += titleSize.y;
}
Rectangle screen = shell.getDisplay().getClientArea();
int anchor = preferredAnchor;
if (anchor != SWT.NONE && autoAnchor && locX != Integer.MIN_VALUE) {
if ((anchor & SWT.LEFT) != 0) {
if (locX + contentsSize.x + marginLeft + marginRight - 16 >= screen.x + screen.width)
anchor = anchor - SWT.LEFT + SWT.RIGHT;
} else // RIGHT
{
if (locX - contentsSize.x - marginLeft - marginRight + 16 < screen.x)
anchor = anchor - SWT.RIGHT + SWT.LEFT;
}
if ((anchor & SWT.TOP) != 0) {
if (locY + contentsSize.y + 20 + marginTop + marginBottom >= screen.y + screen.height)
anchor = anchor - SWT.TOP + SWT.BOTTOM;
} else // BOTTOM
{
if (locY - contentsSize.y - 20 - marginTop - marginBottom < screen.y)
anchor = anchor - SWT.BOTTOM + SWT.TOP;
}
}
final Point shellSize = (anchor == SWT.NONE) ? new Point(contentsSize.x + marginLeft + marginRight, contentsSize.y + marginTop + marginBottom) : new Point(contentsSize.x + marginLeft + marginRight, contentsSize.y + marginTop + marginBottom + 20);
if (shellSize.x < 54 + marginLeft + marginRight)
shellSize.x = 54 + marginLeft + marginRight;
if (anchor == SWT.NONE) {
if (shellSize.y < 10 + marginTop + marginBottom)
shellSize.y = 10 + marginTop + marginBottom;
} else {
if (shellSize.y < 30 + marginTop + marginBottom)
shellSize.y = 30 + marginTop + marginBottom;
}
shell.setSize(shellSize);
int titleLocY = marginTop + (((anchor & SWT.TOP) != 0) ? 20 : 0);
contents.setLocation(marginLeft, titleSize.y + titleLocY);
if (showTitle) {
int realTitleHeight = titleSize.y - titleSpacing;
if (titleImageLabel != null) {
titleImageLabel.setLocation(marginLeft, titleLocY + (realTitleHeight - titleImageLabel.getSize().y) / 2);
titleLabel.setLocation(marginLeft + titleImageLabel.getSize().x + titleWidgetSpacing, titleLocY + (realTitleHeight - titleLabel.getSize().y) / 2);
} else
titleLabel.setLocation(marginLeft, titleLocY + (realTitleHeight - titleLabel.getSize().y) / 2);
if (systemControlsBar != null)
systemControlsBar.setLocation(shellSize.x - marginRight - systemControlsBar.getSize().x, titleLocY + (realTitleHeight - systemControlsBar.getSize().y) / 2);
}
final Region region = new Region();
region.add(createOutline(shellSize, anchor, true));
shell.setRegion(region);
shell.addListener(SWT.Dispose, new Listener() {
public void handleEvent(Event event) {
region.dispose();
}
});
final int[] outline = createOutline(shellSize, anchor, false);
shell.addListener(SWT.Paint, new Listener() {
public void handleEvent(Event event) {
event.gc.drawPolygon(outline);
}
});
if (locX != Integer.MIN_VALUE) {
Point shellLoc = new Point(locX, locY);
if ((anchor & SWT.BOTTOM) != 0)
shellLoc.y = shellLoc.y - shellSize.y + 1;
if ((anchor & SWT.LEFT) != 0)
shellLoc.x -= 15;
else if ((anchor & SWT.RIGHT) != 0)
shellLoc.x = shellLoc.x - shellSize.x + 16;
if (autoAnchor) {
if (shellLoc.x < screen.x)
shellLoc.x = screen.x;
else if (shellLoc.x > screen.x + screen.width - shellSize.x)
shellLoc.x = screen.x + screen.width - shellSize.x;
if (anchor == SWT.NONE) {
if (shellLoc.y < screen.y)
shellLoc.y = screen.y;
else if (shellLoc.y > screen.y + screen.height - shellSize.y)
shellLoc.y = screen.y + screen.height - shellSize.y;
}
}
shell.setLocation(shellLoc);
}
}
use of org.eclipse.swt.widgets.Canvas in project balzac by balzac-lang.
the class TrustedNodesPreferences method createNetworkContents.
private void createNetworkContents(Composite parent, boolean testnet) {
Group group = new Group(parent, SWT.NONE);
group.setText(testnet ? " Testnet node " : " Mainnet node ");
GridLayout gl_grpTestnet = new GridLayout(2, false);
gl_grpTestnet.marginTop = 5;
gl_grpTestnet.marginRight = 5;
gl_grpTestnet.marginLeft = 5;
gl_grpTestnet.marginBottom = 5;
group.setLayout(gl_grpTestnet);
Label hostLabel = new Label(group, SWT.NONE);
hostLabel.setText("Host");
Text hostText = new Text(group, SWT.BORDER);
hostText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label lblPort = new Label(group, SWT.NONE);
lblPort.setText("Port");
Spinner portSpinner = new Spinner(group, SWT.BORDER);
portSpinner.setMaximum(65535);
portSpinner.setMinimum(1);
GridData gd_portSpinner = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_portSpinner.heightHint = 19;
gd_portSpinner.widthHint = 163;
portSpinner.setLayoutData(gd_portSpinner);
Label lblHttpsButton = new Label(group, SWT.NONE);
lblHttpsButton.setText("Https");
Button httpsCheckbox = new Button(group, SWT.CHECK);
httpsCheckbox.setToolTipText("Recommended if the server accepts SSL connections");
Label usernameLabel = new Label(group, SWT.NONE);
usernameLabel.setText("Username");
Text usernameText = new Text(group, SWT.BORDER);
usernameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
Label urlLabel = new Label(group, SWT.NONE);
urlLabel.setText("URL");
Text urlText = new Text(group, SWT.BORDER);
urlText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
urlText.addFocusListener(new FocusListener() {
@Override
public void focusLost(FocusEvent e) {
String text = urlText.getText();
if (!text.startsWith("/"))
urlText.setText("/" + text);
}
@Override
public void focusGained(FocusEvent e) {
}
});
Label testnetPasswordLabel = new Label(group, SWT.NONE);
testnetPasswordLabel.setText("Password");
Text passwordText = new Text(group, SWT.BORDER | SWT.PASSWORD);
passwordText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
Label timeoutLabel = new Label(group, SWT.NONE);
timeoutLabel.setText("Timeout");
Spinner timeoutSpinner = new Spinner(group, SWT.BORDER);
timeoutSpinner.setMaximum(Integer.MAX_VALUE);
timeoutSpinner.setMinimum(-1);
timeoutSpinner.setToolTipText("Set -1 for undefined waiting time (not recommended)");
GridData gd_timeoutSpinner = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_timeoutSpinner.heightHint = 19;
gd_timeoutSpinner.widthHint = 163;
timeoutSpinner.setLayoutData(gd_timeoutSpinner);
// test button with feedbacks
Composite compositeBtnTest = new Composite(group, SWT.NONE);
compositeBtnTest.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
GridLayout gl_composite = new GridLayout(2, false);
gl_composite.horizontalSpacing = 10;
gl_composite.marginWidth = 0;
compositeBtnTest.setLayout(gl_composite);
Button btnTestConnection = new Button(compositeBtnTest, SWT.NONE);
btnTestConnection.setText("Test");
Composite compositeFeedbacks = new Composite(compositeBtnTest, SWT.NONE);
Canvas networkFeedbackOK = new Canvas(compositeFeedbacks, SWT.NONE);
networkFeedbackOK.setBounds(0, 0, 16, 16);
networkFeedbackOK.setBackgroundImage(imageSuccess);
networkFeedbackOK.setVisible(false);
Canvas networkFeedbackERR = new Canvas(compositeFeedbacks, SWT.NONE);
networkFeedbackERR.setBounds(0, 0, 16, 16);
networkFeedbackERR.setBackgroundImage(imageError);
networkFeedbackERR.setVisible(false);
// error details
Composite errorDetailsComposite = new Composite(group, SWT.BORDER);
StyledText errorDetailsTextArea = new StyledText(errorDetailsComposite, SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL);
GridData gd_errorDetailsTextArea = new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1);
gd_errorDetailsTextArea.grabExcessVerticalSpace = true;
errorDetailsComposite.setLayoutData(gd_errorDetailsTextArea);
errorDetailsComposite.setBackground(errorDetailsTextArea.getBackground());
errorDetailsTextArea.setAlwaysShowScrollBars(false);
errorDetailsComposite.addControlListener(new ControlListener() {
private int TOP_MARGIN = 4;
private int LEFT_MARGIN = 8;
@Override
public void controlResized(ControlEvent e) {
Composite parent = errorDetailsTextArea.getParent();
errorDetailsTextArea.setBounds(LEFT_MARGIN, TOP_MARGIN, parent.getSize().x - 2 * parent.getBorderWidth() - LEFT_MARGIN, parent.getSize().y - 2 * parent.getBorderWidth() - TOP_MARGIN);
}
@Override
public void controlMoved(ControlEvent e) {
}
});
btnTestConnection.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
errorDetailsTextArea.setText("");
networkFeedbackOK.setVisible(false);
networkFeedbackERR.setVisible(false);
}
@Override
public void mouseUp(MouseEvent e) {
String address = hostText.getText();
Integer port = portSpinner.getSelection();
String protocol = httpsCheckbox.getSelection() ? "https" : "http";
String url = urlText.getText();
String user = usernameText.getText();
String password = passwordText.getText();
Integer timeout = timeoutSpinner.getSelection();
if (password.isEmpty()) {
try {
if (testnet)
password = secureStorage.node(SecureStorageUtils.SECURE_STORAGE__NODE__BITCOIN__TESTNET_NODE).get(SecureStorageUtils.SECURE_STORAGE__PROPERTY__TESTNET_PASSWORD, "");
else
password = secureStorage.node(SecureStorageUtils.SECURE_STORAGE__NODE__BITCOIN__MAINNET_NODE).get(SecureStorageUtils.SECURE_STORAGE__PROPERTY__MAINNET_PASSWORD, "");
} catch (StorageException e1) {
e1.printStackTrace();
errorDetailsTextArea.append("Error fetching the password from the secure store.\n\n");
errorDetailsTextArea.append(Throwables.getStackTraceAsString(e1));
networkFeedbackERR.setVisible(true);
return;
}
}
RPCBitcoinClient bitcoinClient = new RPCBitcoinClient(address, port, protocol, url, user, password, timeout, TimeUnit.MILLISECONDS);
try {
BitcoindApi api = bitcoinClient.getApi();
boolean isTestnet = api.getblockchaininfo().getChain().equals("test");
if (isTestnet != testnet) {
String expected = testnet ? "testnet" : "mainnet";
String actual = isTestnet ? "testnet" : "mainnet";
errorDetailsTextArea.append("Wrong network type: expected " + expected + ", found " + actual + ".");
networkFeedbackERR.setVisible(true);
return;
}
} catch (Exception e1) {
e1.printStackTrace();
errorDetailsTextArea.append("Cannot connect to the node.\n\n");
errorDetailsTextArea.append(Throwables.getStackTraceAsString(e1));
networkFeedbackERR.setVisible(true);
return;
}
errorDetailsTextArea.append("ok");
networkFeedbackOK.setVisible(true);
}
});
if (testnet)
testnetHostText = hostText;
else
mainnetHostText = hostText;
if (testnet)
testnetPortSpinner = portSpinner;
else
mainnetPortSpinner = portSpinner;
if (testnet)
testnetHttpsCheckbox = httpsCheckbox;
else
mainnetHttpsCheckbox = httpsCheckbox;
if (testnet)
testnetUrlText = urlText;
else
mainnetUrlText = urlText;
if (testnet)
testnetUsernameText = usernameText;
else
mainnetUsernameText = usernameText;
if (testnet)
testnetPasswordText = passwordText;
else
mainnetPasswordText = passwordText;
if (testnet)
testnetTimeoutSpinner = timeoutSpinner;
else
mainnetTimeoutSpinner = timeoutSpinner;
}
Aggregations