Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » itemMenu bis
itemMenu bis [message #467257] Fri, 27 January 2006 08:33
Eclipse UserFriend
Originally posted by: remy.fctpas.fr

bonjour
est t'il correct d'ecrire
ci joint une touche bis pour menu


hello
and you it correct to make ?
Ci joint key bis redo for menu

m[i].addSelectionListener(new Action0());
m[i].addSelectionListener(new Action1());


merci

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;


public class BisActionInstaller {

public static void install(Menu menuBar)
{
int lMenuCount=menuBar.getItemCount();
System.out.println(lMenuCount);
for (int i=0;i<lMenuCount;i++)
{
installBisActionUpdater(menuBar.getItem(i));
}

}
private static void installBisActionUpdater(MenuItem menu)
{
new MenuItem(menu.getMenu(),SWT.SEPARATOR);
MenuItem bis =new MenuItem(menu.getMenu(),SWT.PUSH);
bis.setText("&Bis");
bis.setEnabled(false);

System.out.println(menu);
BisAction bisAction=new BisAction(bis);
MenuItem []m=menu.getMenu().getItems();
for(int i=0;i<m.length;i++)
{
System.out.println(m[i]);
m[i].addSelectionListener(bisAction);
//m[i].addSelectionListener(new Action2());

}
}
}
//******************************
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;

public class BisAction implements SelectionListener
{
MenuItem bis,item;


public BisAction(MenuItem bis)
{
this.bis=bis;
}
public void widgetSelected(SelectionEvent event)
{
if(!bis.equals((MenuItem)event.getSource()))
{
setItem( (MenuItem)event.getSource() );
initBis();
}
else
{
Event event1 = new Event();
event1.item=getItem();
getItem().notifyListeners(SWT.Selection,event1);
}
}
public void widgetDefaultSelected(SelectionEvent event)
{

}
private void setItem(MenuItem i)
{
item=i;
}
private MenuItem getItem()
{
return item;
}
private MenuItem getItemBis()
{
return bis;
}
private void initBis()
{
if(!bis.equals(getItem()))
{
bis.setText("bis "+getItem().getText());
bis.setEnabled(true);
}

}

}
//********************************
import org.eclipse.swt.events.*;
import org.eclipse.swt.widgets.*;

public class Action implements SelectionListener{

public void widgetSelected(SelectionEvent event)
{
System.out.println("Action
"+((MenuItem)event.getSource()).getText());
}
public void widgetDefaultSelected(SelectionEvent event)
{
System.out.println("Action
"+((MenuItem)event.getSource()).getText());
}

}

//**********************************

import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;


public class fenetre {

Display display;
Shell shell;
Menu menuBar,fileMenu,helpmenu;
MenuItem fileMenuH,helpMenuH;
MenuItem fileExitItem,fileSaveItem,helpGetHelpItem;
Label label;
public fenetre()
{
display = new Display();
shell = new Shell();
shell.setText("Menu");
shell.setSize(300,300);

label= new Label(shell,SWT.CENTER);
label.setBounds(shell.getClientArea());

menuBar =new Menu(shell,SWT.BAR);

fileMenuH =new MenuItem(menuBar,SWT.CASCADE);
fileMenuH.setText("&Fichier");
fileMenuH.addSelectionListener(new Action());

helpMenuH =new MenuItem(menuBar,SWT.CASCADE);
helpMenuH.setText("&Aide");
helpMenuH.addSelectionListener(new Action());

fileMenu =new Menu(shell,SWT.DROP_DOWN);
fileMenuH.setMenu(fileMenu);

helpmenu =new Menu(shell,SWT.DROP_DOWN);
helpMenuH.setMenu(helpmenu);


fileSaveItem =new MenuItem(fileMenu,SWT.PUSH);
fileSaveItem.setText("&Enregistrer");
fileSaveItem.addSelectionListener(new Action());

fileExitItem =new MenuItem(fileMenu,SWT.PUSH);
fileExitItem.setText("&Quitter");
fileExitItem.addSelectionListener(new Action());

helpGetHelpItem=new MenuItem(helpmenu,SWT.PUSH);
helpGetHelpItem.setText("AU &Secours");
helpGetHelpItem.addSelectionListener(new Action());

BisActionInstaller.install(menuBar);
shell.setMenuBar(menuBar);
shell.open();
shell.redraw();
while (!shell.isDisposed())
{
if(!display.readAndDispatch())display.sleep();
}
display.dispose();

}
}
//*********************
public class Main
{
public static void main(String[] args)
{
fenetre f=new fenetre();
f.notify();
}
}


--
des conneries j'en ai dites oui oui je vous assure...
mais elles n'engagent que votre perception
remy
Previous Topic:"Rounded" buttons with SWT?
Next Topic:Using OverlayLayout with SWT_AWT bridge
Goto Forum:
  


Current Time: Fri Aug 23 22:43:10 GMT 2019

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

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

Back to the top