Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » probleme avec les scrolls
probleme avec les scrolls [message #138142] Tue, 15 June 2004 07:54
Eclipse UserFriend
Originally posted by: misterfunkyman.hotmail.com

voila j'ai un probleme, j'ai une application graphique ou je cree des
elements je les connecte...
le probleme c'est que mon shell empeche le contenu de ma fenetre de
s'agrandir : quand je cree un element il se bloque sur le bord de ma
fenetre :
je vous met mon code en esperant que vous pourrez m'aider (j'ai essaye
plein de truc mais ca n'a pas marche).
J'essaie en fait que mon conteneur s'agrandissent en fonction des elements
qu'on lui ajoute.

public class Test {
public static void main(String args[]){
Display d = new Display();
Shell shell = new Shell(d);
shell.setSize(700, 600);
shell.setText("Test");
LightweightSystem lws = new LightweightSystem(shell);
final XYLayout contentsLayout = new XYLayout();
final FigureTest contents = new FigureTest();
contents.setLayoutManager(contentsLayout);
ScrollPane scroll= new ScrollPane();
//contents.setPreferredSize(700,600);
scroll.setContents(contents);
scroll.setScrollBarVisibility(ScrollPane.ALWAYS);
//scroll.setPreferredSize(scroll.MAX_DIMENSION);

Panel panneau=new Panel();
final ToggleButton boutonLiaison = new ToggleButton("liaison");
final ToggleButton boutonMigrate = new ToggleButton("fonction migrate");
final ToggleButton boutonPar = new ToggleButton("fonction par");
final ToggleButton boutonProprietes = new ToggleButton("proprietes");
final ToggleButton boutonBouge = new ToggleButton("bouge");
final ToggleButton boutonYML = new ToggleButton("YML");
final ToggleButton boutonAjouter = new ToggleButton("ajouter");
panneau.setLayoutManager(new FlowLayout());
panneau.add(boutonLiaison);
panneau.add(boutonPar);
panneau.add(boutonProprietes);
panneau.add(boutonBouge);
panneau.add(boutonYML);
panneau.add(boutonAjouter);
contentsLayout.setConstraint(panneau, new Rectangle(10,10,-1,-1));
contents.add(panneau);

final ActionListener listenerToggleButton = new ActionListener() {
public void actionPerformed(ActionEvent event) {
if(((ToggleButton)event.getSource()).isSelected()==true) {
boutonLiaison.setSelected(false);
boutonPar.setSelected(false);
boutonProprietes.setSelected(false);
boutonBouge.setSelected(false);
boutonBouge.setSelected(false);
boutonYML.setSelected(false);
boutonAjouter.setSelected(false);
((ToggleButton)event.getSource()).setSelected(true);
}
else {
((ToggleButton)event.getSource()).setSelected(false);
}
}
};

boutonLiaison.addActionListener(listenerToggleButton);
boutonPar.addActionListener(listenerToggleButton);
boutonProprietes.addActionListener(listenerToggleButton);
boutonBouge.addActionListener(listenerToggleButton);
boutonYML.addActionListener(listenerToggleButton);
boutonAjouter.addActionListener(listenerToggleButton);

final MouseListener listenerConnection = new MouseListener() {
public void mousePressed(MouseEvent me) {
contents.setPressedTargetConnection((PolylineConnection)me.g etSource(),(Figure)((PolylineConnection)me.getSource()).getS ourceAnchor().getOwner());
if(((PolylineConnection)me.getSource()).getSourceAnchor().ge tOwner().toString().startsWith( "FonctionMigrate"))
((FonctionMigrate)((PolylineConnection)me.getSource()).getSo urceAnchor().getOwner()).retirerSuivant((Figure)((((Polyline Connection)me.getSource()).getTargetAnchor().getOwner())));
else
if(((PolylineConnection)me.getSource()).getSourceAnchor().ge tOwner().toString().startsWith( "FonctionPar1"))
((FonctionPar1)((PolylineConnection)me.getSource()).getSourc eAnchor().getOwner()).retirerSuivant((Figure)((((PolylineCon nection)me.getSource()).getTargetAnchor().getOwner())));
}
public void mouseReleased(MouseEvent me) {}
public void mouseDoubleClicked(MouseEvent me) {}
};

final MouseListener listenerFigure= new MouseListener() {
public void mousePressed(MouseEvent me) {
if(boutonLiaison.isSelected()==true) {
PolylineConnection c= new PolylineConnection();
c.addMouseListener(listenerConnection);
contents.setConnection(c, ((Figure)me.getSource()));
}
else if(boutonBouge.isSelected()==true){
contents.setFigurePressed((Figure)me.getSource());
((Figure)me.getSource()).setVisible(false);
}
else if(boutonYML.isSelected()==true) {
System.out.println("\nVoici le code :");
if((me.getSource()).toString().startsWith("FonctionMigrate")==true)
((FonctionMigrate)me.getSource()).afficherYML();
else if((me.getSource()).toString().startsWith("FonctionPar1")==true)
((FonctionPar1)me.getSource()).afficherYML();
}
else if(boutonAjouter.isSelected()==true) {
//FonctionMigrate figure = new FonctionMigrate(new Label("migrate"),
new Label("GenInputVector"),new Label("VInput[i]"),new Label("i"), new
Label("blockSize"));
if(me.getSource().toString().startsWith("FonctionPar1")) {
FonctionMigrate figure = new FonctionMigrate(new Label("migrate"),
new Label("GenInputVector"),new Label("VInput[i]"),new Label("i"), new
Label("blockSize"));
//FonctionMigrate figure = new FonctionMigrate(new Label("migrate"));
((FonctionPar1)me.getSource()).ajouterContenu(figure);
}
}
}
public void mouseReleased(MouseEvent me) {
if(boutonLiaison.isSelected()==true &
contents.isChangingConnection()==false) {
PolylineConnection c;
c=contents.getConnection(((Figure)me.getSource()));
if(c.getSourceAnchor().getOwner().toString().startsWith("FonctionMigrate ")
&&
((FonctionMigrate)c.getSourceAnchor().getOwner()).isFigurePr esent(((Figure)me.getSource()))==false)
{
contents.add(c);
((FonctionMigrate)((c.getSourceAnchor()).getOwner())).ajoute rSuivant((Figure)(me.getSource()));
System.out.println("la fonction");
((FonctionMigrate)((c.getSourceAnchor()).getOwner())).printF onction();
System.out.println("puis ses suivants");
((FonctionMigrate)((c.getSourceAnchor()).getOwner())).affich erSuivant();
}
else
if(c.getSourceAnchor().getOwner().toString().startsWith("FonctionPar1 ") &&
((FonctionPar1)c.getSourceAnchor().getOwner()).isFigurePrese nt(((Figure)me.getSource()))==false)
{
contents.add(c);
((FonctionPar1)((c.getSourceAnchor()).getOwner())).ajouterSu ivant((Figure)(me.getSource()));
System.out.println("la fonction");
((FonctionPar1)((c.getSourceAnchor()).getOwner())).printFonc tion();
System.out.println("puis ses suivants");
((FonctionPar1)((c.getSourceAnchor()).getOwner())).afficherS uivant();
}
}
else if(contents.isChangingConnection()==true) {
PolylineConnection c= new PolylineConnection();
c=contents.getReleasedTargetConnection(((Figure)me.getSource ()));
c.addMouseListener(listenerConnection);
contents.add(c);
if(c.getSourceAnchor().getOwner().toString().startsWith("FonctionMigrate "))
{
((FonctionMigrate)((c.getSourceAnchor()).getOwner())).ajoute rSuivant((Figure)(me.getSource()));
System.out.println("la fonction");
((FonctionMigrate)((c.getSourceAnchor()).getOwner())).printF onction();
System.out.println("puis ses suivants");
((FonctionMigrate)((c.getSourceAnchor()).getOwner())).affich erSuivant();
}
else
if(c.getSourceAnchor().getOwner().toString().startsWith("FonctionPar1 ")) {
((FonctionPar1)((c.getSourceAnchor()).getOwner())).ajouterSu ivant((Figure)(me.getSource()));
System.out.println("la fonction");
((FonctionPar1)((c.getSourceAnchor()).getOwner())).printFonc tion();
System.out.println("puis ses suivants");
((FonctionPar1)((c.getSourceAnchor()).getOwner())).afficherS uivant();
}
}
}
public void mouseDoubleClicked(MouseEvent me) {
if(boutonProprietes.isSelected() == true &&
me.getSource().toString().startsWith("FonctionMigrate"))
((FonctionMigrate)me.getSource()).setAttributes();
else if(boutonProprietes.isSelected() == true &&
me.getSource().toString().startsWith("FonctionPar1")) {
((FonctionPar1)me.getSource()).setAttributes();
}
}
};

MouseListener listenerContents= new MouseListener() {

public void mousePressed(MouseEvent me) {
//System.out.println(me.x+" "+me.y);
}
public void mouseReleased(MouseEvent me) {
if(contents.getFigurePressed()!=null) {
contents.remove(contents.getFigurePressed());
contentsLayout.setConstraint(contents.getFigurePressed(), new
Rectangle(me.x,me.y,-1,-1));
contents.add(contents.getFigurePressed());
contents.getFigurePressed().setVisible(true);
contents.setFigurePressed(null);
}
}
public void mouseDoubleClicked(MouseEvent me) {
if(boutonLiaison.isSelected()==false) {
if(boutonPar.isSelected()==false) {
FonctionMigrate figure = new FonctionMigrate(new Label("migrate"),
new Label("GenInputVector"),new Label("VInput[i]"),new Label("i"), new
Label("blockSize"));
//FonctionMigrate figure = new FonctionMigrate(new Label("migrate"));
figure.setSaContrainteX(me.x);
figure.setSaContrainteY(me.y);
contentsLayout.setConstraint(figure, new Rectangle(me.x, me.y, -1,
-1));
contents.add(figure);
figure.addMouseListener(listenerFigure);
}
else {
FonctionPar1 figure = new FonctionPar1(new Label("par"), new
Label("1"),new Label("block"));
//FonctionPar1 figure = new FonctionPar1(new Label("autre"));
figure.setSaContrainteX(me.x);
figure.setSaContrainteY(me.y);
contentsLayout.setConstraint(figure, new Rectangle(me.x, me.y, -1,
-1));
contents.add(figure);
figure.addMouseListener(listenerFigure);
}
}
}
};

contents.addMouseListener(listenerContents);

lws.setContents(scroll);
shell.open();
while (!shell.isDisposed())
while (!d.readAndDispatch())
d.sleep();
shell.dispose();
}
}
Previous Topic:ruler marks < 0
Next Topic:toolBar
Goto Forum:
  


Current Time: Wed Apr 24 18:22:16 GMT 2024

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

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

Back to the top