Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Button selection event
Button selection event [message #509472] Fri, 22 January 2010 14:38 Go to next message
Dharmit Shah is currently offline Dharmit ShahFriend
Messages: 1
Registered: January 2010
Junior Member
Hello,

I'm developing a GUI for Network Simulator. In the GUI, I've created a button that has the image of a PC and other button which has image of a Router. What I'm planning to make is- Suppose if a user clicks on the button of PC and then clicks somewhere on the shell, image of a PC should be placed there. In this way, he should be able to design a topology. Can someone please tell me how can I do this? Do I need to use DND? Or can it be done with the help of events?

Thanks.
Re: Button selection event [message #510638 is a reply to message #509472] Thu, 28 January 2010 07:35 Go to previous messageGo to next message
Praveen  is currently offline Praveen Friend
Messages: 86
Registered: July 2009
Member
Dharmit Shah wrote:
> topology. Can someone please tell me how can I do this? Do I need to use
> DND? Or can it be done with the help of events?

Handling events should be sufficient. Please check whether the below
posted snippet might be helpful for implementing your scenario -

public class ButtonShiftImage {

static boolean transferStarted = true;
public void createShell () {
final Display display = new Display ();
final Shell shell = new Shell (display);
shell.setLayout(new GridLayout());

final Image image = new Image(display, "swt.png");
final Button imageButton = new Button (shell, SWT.PUSH);
imageButton.setText ("Normal");
imageButton.setImage(image);

imageButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
transferStarted = true;
}
});

shell.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
if (transferStarted) {
transferStarted = false;
GC gc = new GC(display);
gc.drawImage(image, e.x, e.y);
}
}
});

shell.setSize (200, 200);
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}

public static void main (String [] args) {
ButtonShiftImage db = new ButtonShiftImage();
db.createShell();
}
}
Re: Button selection event [message #512519 is a reply to message #509472] Fri, 05 February 2010 11:06 Go to previous message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
You can build this from ground up....

or you can easyly build the whole solution using GEF/GMF...

http://lh6.ggpht.com/_3SpBG8kdCvs/S2v6mUTlZEI/AAAAAAAADHI/QMxLJILfr4M/s800/shapes.GIF

The circle the square can be anything...

The right side has a pellete which would contain u r pc or router or any thing.....

u can click an drop them on the main window...


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Previous Topic:Awkward thing happens when I call shell.open() on a certain computer
Next Topic:Has StyledText a maximum input for data?
Goto Forum:
  


Current Time: Fri Apr 19 22:04:44 GMT 2024

Powered by FUDForum. Page generated in 0.02702 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top