I am creating a custom tooltip where i have a textbox.I am able to do that but i could not get balloon like icon as in the attached picture .Can anyone help me regarding this.
Mytooltip class:
public class MyToolTip extends ToolTip {
private Shell parentShell;
public MyToolTip(Control control) {
super(control,SWT.BALLOON,false);
this.parentShell = control.getShell();
}
#Override
protected Composite createToolTipContentArea(Event event, Composite parent) {
// TODO Auto-generated method stub
Composite comp = new Composite(parent,SWT.NONE);
comp.setLayout(new FillLayout());
Text text = new Text(comp,SWT.BORDER);
text.setText("");
return comp;
}
}
Class using tooltip:
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new RowLayout(SWT.VERTICAL));
Text text = new Text(shell, SWT.BORDER);
text.setText("sample text field");
MyToolTip myTooltipLabel = new MyToolTip(text);
myTooltipLabel.setShift(new Point(-5, -5));
myTooltipLabel.setHideOnMouseDown(false);
myTooltipLabel.activate();
myTooltipLabel.setRespectDisplayBounds(false);
myTooltipLabel.setRespectMonitorBounds(false);
The problem is, that you are using org.eclipse.jface.window.ToolTip whereas the code that was used to create that screenshot uses org.eclipse.swt.widgets.ToolTip.
The SWT tooltip can have the balloon look by passing SWT.BALLOON as the style bit.
The JFace tooltip does not support SWT.BALLOON, only ToolTip.NO_RECREATE and ToolTip.RECREATE.
So here is the conclusion: You can't subclass the swt tooltip to make it editable. You can't make the JFace tooltip look the way you want it to look. The only solution that is left is creating your own Widget based on Composite or Canvas that does what you want.
Related
I am supposed to create a scroll bar in my Eclipse RCP view and I referred to the ScrolledComposite javadoc and taking help from this.
private void createComposite2(final Composite parent,final String text, int compositeNumber)
{
final ScrolledComposite rightScrolled = new ScrolledComposite(parent, SWT.V_SCROLL|SWT.H_SCROLL|SWT.BORDER);
group=GUIToolkit.newGroup(rightScrolled, SWT.NONE, text, null);
rightScrolled.setContent(group);
group.setLayout(new FillLayout());
rightScrolled.setExpandHorizontal(true);
rightScrolled.setExpandVertical(true);
group.setSize(group.computeSize(SWT.DEFAULT, SWT.DEFAULT));
group.setBackground(white);
createPartControl(group,compositeNumber);
}
But instead the scroll is absent. Can anybody tell me what exactly is the problem? In one of the online resources I saw addControlListner. Will that help? If yes, how can I use it?
After some research and hit and trial, i came up with this code,
private void createComposite2(final Composite parent,final String text, int compositeNumber)
{
final ScrolledComposite rightScrolled = new ScrolledComposite(parent, SWT.V_SCROLL|SWT.H_SCROLL);
group=GUIToolkit.newGroup(rightScrolled, SWT.NONE, text, null);
rightScrolled.setContent(group);
rightScrolled.setExpandHorizontal(true);
rightScrolled.setExpandVertical(true);
rightScrolled.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) {
org.eclipse.swt.graphics.Rectangle r = rightScrolled.getClientArea();
rightScrolled.setMinSize(group.computeSize(r.width, SWT.DEFAULT));
}
});
group.setLayout(new FillLayout());
group.setBackground(white);
createPartControl(group,compositeNumber);
}
which resulted in scroll coming but it would not readjust to show the window.
Have a look at the first composite with name SOAD. It's the normal size.
and now this is when i push it on left side, the scroll should have been activated, and it is not... It is cropping the content.
How do i fix this
I have a class "View" which extends a ViewPart.
After sth in my class I want to show a dialog, which contains of two labels.
First I used "InputDialog" like this:
Composite composite = new Composite(top, SWT.NONE);
Label label= new Label(tmpComposite, SWT.NONE);
label.setText("");
InputDialog dlg;
dlg = new InputDialog(Display.getCurrent().getActiveShell(),
"Title", "Some Text", label.getText(), insertValidator());
if (dlg.open() == Window.OK) {
//Do sth.
}
This works. But now I have two labels. How can I realize it?
I found a few solutions, but none of them is working in a ViewPart or with Eclipse RCP.
Thanks for your help!
By the way if your solution is to call a java class from my "View", how can I come back to "View" and how can I see my new dialog? Tried it, not working.
You need to create a custom dialog by extending org.eclipse.jface.dialogs.Dialog:
public class MyDialog extends Dialog
{
public MyDialog(Shell parentShell)
{
super(parentShell);
}
#Override
protected Control createDialogArea(Composite parent)
{
Composite container = (Composite)super.createDialogArea(parent);
// Add your controls here
return container;
}
}
You use this in a similar way to InputDialog
MyDialog dialog = new MyDialog(shell);
dialog.open();
Have a look at http://www.vogella.com/articles/EclipseDialogs/article.html for some more details.
I want to add a button to a RCP client. The window needs to display my barChart as well as 3 buttons.
When i add the line:
panel.add(button);
it returns an error:
The method add(Component) in the type Container is not applicable for the arguments (Button)
Please help :)
#Override
protected void createWindows(final Shell shell) throws Exception {
shell.setLayout(new FillLayout());
final Composite composite = new Composite(shell, SWT.EMBEDDED);
final Frame frame = SWT_AWT.new_Frame(composite);
final StaticBarSketch barGraph = new StaticBarSketch();
final Button button = new Button(composite, SWT.PUSH);
button.setText("Press");
Panel panel = new Panel();
panel.add(barGraph);
frame.add(panel);
barGraph.init();
composite.addListener(SWT.Resize, new Listener() {
#Override
public void handleEvent(Event event) {
barGraph.resized(composite.getSize().x, composite.getSize().y);
}
});
Instead of using a Panel, use Composite. Panel is from Swing and you are mixing Swing with RCP/SWT, which is not wise.
The Button that you are using is from SWT and you are adding that to Panel which is a Swing component and you can only a Swing component to Panel. You can either change the Button to AWT's Button or Swings JButton. Otherwise as stated earlier, change the Panel to Composite.
I'm working on a Java/Eclipse SWT application that displays and edits map data captured by a special device in a stacked fashion, i.e. there are different layers of "geospatial features" that can be shown/hidden or modified. It was found to be helpful to have an aerial imagery layer which could be easily retrieved e.g. from google maps.
I thought of using the SWT Browser Widget to retrieve and render this satellite view, which actually works like a charm. The Problem is that I need to have a hidden Browser Widget which would work in the background and return me a swt.graphics.Image etc. of the rendered content or even better directly use a given GC for drawing.
I also thought about simpler solutions but there are two restrictions:
I can't just use static maps from Google because the map tile I need would have to be larger than they allow and the partial reloading that they provide (e.g. when moving the map view port) would also be very handy.
I can't simply feed my data into Google Maps for several reasons.
So in general: How do I have a (hidden) instance of a Browser Widget render its output to an Image/GC instead of the screen. Is there something else except from the Browser Widget which could do the job?
I think you can use the org.eclipse.swt.widgets.Control.print(GC) method to print a control to an image. I have not tried it for Browser though.
Here is sample to start with using SWT Browser control
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Browser Test");
shell.setSize(500, 500);
shell.setLayout(new GridLayout(1,false));
final Browser browser = new Browser(shell, SWT.NONE);
browser.setUrl("https://maps.google.com/maps?hl=en&tab=wl");
//browser.setVisible(false);
browser.setLayoutData(new GridData(GridData.FILL_BOTH));
Button b = new Button(shell, SWT.NONE);
b.setText("Show");
b.addListener(SWT.Selection, new Listener() {
#Override
public void handleEvent(Event event) {
Image img = new Image(display, 500, 500);
GC gc = new GC(img);
browser.print(gc);
gc.dispose();
showImage(img);
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private static class ImageDialog extends Dialog
{
private Image img;
protected ImageDialog(Shell parentShell,Image img) {
super(parentShell);
this.img = img;
}
#Override
protected Control createDialogArea(Composite parent) {
Composite comp = (Composite) super.createDialogArea(parent);
Label lbl = new Label(comp,SWT.NONE);
lbl.setImage(img);
return comp;
}
#Override
protected void okPressed() {
img.dispose();
super.okPressed();
}
}
protected static void showImage(Image img) {
ImageDialog dialog = new ImageDialog(Display.getDefault().getActiveShell(), img);
dialog.open();
}
another approach that we can think of
user capture div as image and save to computer
execute java script into SWT Browser Browser.execute(java script) to capture div into an image.
I have four composites aligned in order.
Each composite has a check box, Label, and 2 Buttons. Now these composites are aligned one after another.
I want to enable focus on these items, i.e. when I use tab to go from one composite to other, the current composite should look highlighted. Ideally I want it to behave like a list, when you choose an item then that gets highlighted. Is this possible?
I understand that composite acts as a container for others widgets, control. My requirement is that I have a list of 5 entries, and that each item in the list has a check box, label, and two Buttons. I would also want it to be focused on when they are selected.
Also please let me know alternative solutions for the same UI that I have described above.
To make tab go from composite to composite, set the tab list for each composite to be one control that you want to have focus after a tab. For example, the check box:
composite.setTabList(new Control[]{checkButton});
To make the highlight, your imagination is the limit. You can change background, add some border, you name it. You just have to update it whenever one of the controls from the composite get focus.
Here is a full example:
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout(SWT.VERTICAL));
createElement(shell);
createElement(shell);
createElement(shell);
createElement(shell);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
private static void createElement(final Composite parent) {
final Composite composite = new Composite(parent, SWT.BORDER);
composite.setLayout(new GridLayout(4, false));
final Button checkButton = new Button(composite, SWT.CHECK);
new Label(composite, SWT.NONE);
final Button button1 = new Button(composite, SWT.PUSH);
final Button button2 = new Button(composite, SWT.PUSH);
Listener listener = new Listener() {
#Override
public void handleEvent(Event event) {
for (Control control : parent.getChildren()) {
control.setBackground(null);
}
composite.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_RED));
if (event.widget == button1 || event.widget == button2) {
checkButton.setFocus();
}
}
};
checkButton.addListener(SWT.FocusIn, listener);
button1.addListener(SWT.FocusIn, listener);
button2.addListener(SWT.FocusIn, listener);
composite.setTabList(new Control[]{checkButton});
}