Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Stange behaviour on resolution change
Stange behaviour on resolution change [message #632753] Thu, 14 October 2010 07:30 Go to next message
Anubhav Manak is currently offline Anubhav Manak
Messages: 17
Registered: July 2009
Junior Member
Hi,

If I change resolution (control panel -> Display properties-> settings) of my system while my application is running, the layout of components get changed.

Initial screen:
http://i56.tinypic.com/1o6sus.jpg

After changing the resolution of my system:
http://i51.tinypic.com/bjbypw.jpg

I have written following code to demostrate my problem. The border selection in new thread is for showing the problem. In real app border is set by mouse click.

Following code is used to create the contents of my view
public void createPartControl (Composite parent)
	{
		FigureCanvas main = new FigureCanvas(parent);
		main.setBackground(ColorConstants.lightBlue);
		main.setLayout(new FormLayout());
		Composite compositeModules = new Composite(main, SWT.NONE);
		compositeModules.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY));

		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		layout.makeColumnsEqualWidth = true;
		layout.horizontalSpacing = 1;
		layout.verticalSpacing = 1;
		layout.marginWidth = 1;
		layout.marginHeight = 1;

		compositeModules.setLayout(layout);

		for (int i = 0; i < 2; i++)
		{
			for (int j = 0; j < 2; j++)
			{

				final ModuleCanvas moduleCanvas = new ModuleCanvas(compositeModules);
				GridData gridData = new GridData(SWT.CENTER);
				gridData.heightHint = 90;
				gridData.widthHint = 160;
				gridData.grabExcessHorizontalSpace = false;
				gridData.grabExcessVerticalSpace = false;
				moduleCanvas.setLayoutData(gridData);
				if (i == 0 && j == 0)
				{
					new Thread()
					{
						@Override
						public void run ()
						{
							try
							{
								sleep(10000);
							}
							catch (InterruptedException e)
							{
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							Display.getDefault().asyncExec(new Runnable()
							{

								@Override
								public void run ()
								{
									moduleCanvas.setBorder();

								}

							});
						}

					}.start();

				}
			}
		}

		compositeModules.pack();
	}



public class ModuleCanvas
	extends FigureCanvas
{
	private LineBorder mLineBorder = new LineBorder();


	public ModuleCanvas(Composite parent)
	{
		super(parent);
		mLineBorder.setWidth(10);
		mLineBorder.setColor(ColorConstants.blue);

		Figure f = new Figure()
		{
			@Override
			public void paint (Graphics graphics)
			{
				super.paint(graphics);

				int width = this.getSize().width;
				int height = this.getSize().height;


				graphics.setBackgroundColor(ColorConstants.black);
				graphics.setForegroundColor(ColorConstants.gray);

				graphics.fillRectangle(0, 0, width, height);
				graphics.drawString("A01", 5, 5); // position
			}
		};

		f.setOpaque(true);
		f.setBackgroundColor(ColorConstants.white);
		this.setContents(f);
	}


	public void setBorder ()
	{
		this.setBorder(mLineBorder);
	}
}


Can you please tell me what is wrong with the code? or how can i fix this?

Thanks in advance
Anubhav
Re: Stange behaviour on resolution change [message #632772 is a reply to message #632753] Thu, 14 October 2010 08:57 Go to previous messageGo to next message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
why do u need a thread with 10sec delay for setting the border???

that said if i remove it the problem comes even in normal scanario...

So i think the problem is not with resolution change...


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: Stange behaviour on resolution change [message #632784 is a reply to message #632772] Thu, 14 October 2010 09:18 Go to previous messageGo to next message
Anubhav Manak is currently offline Anubhav Manak
Messages: 17
Registered: July 2009
Junior Member
Thread with delay was to just reproduce the problem. With resolution change I can easily reproduce the problem. there may be some other cases also
Re: Stange behaviour on resolution change [message #632787 is a reply to message #632784] Thu, 14 October 2010 09:23 Go to previous message
Vijay Raj
Messages: 608
Registered: July 2009
Senior Member
try this...

/**
     * This is a callback that will allow us to create the viewer and initialize it.
     */
    @Override
    public void createPartControl(Composite parent)
    {
        FigureCanvas main = new FigureCanvas(parent);
        main.setBackground(ColorConstants.lightBlue);
        main.setLayout(new FormLayout());
        Composite compositeModules = new Composite(main, SWT.NONE);
        compositeModules.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY));

        org.eclipse.swt.layout.GridLayout layout = new org.eclipse.swt.layout.GridLayout();
        layout.numColumns = 2;
        layout.makeColumnsEqualWidth = true;
        layout.horizontalSpacing = 1;
        layout.verticalSpacing = 1;
        layout.marginWidth = 1;
        layout.marginHeight = 1;

        compositeModules.setLayout(layout);

        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 2; j++)
            {

                final ModuleCanvas moduleCanvas = new ModuleCanvas(compositeModules);
                org.eclipse.swt.layout.GridData gridData = new org.eclipse.swt.layout.GridData(
                        SWT.CENTER);
                gridData.heightHint = 90;
                gridData.widthHint = 160;
                gridData.grabExcessHorizontalSpace = false;
                gridData.grabExcessVerticalSpace = false;
                moduleCanvas.setLayoutData(gridData);
                if (i == 0 && j == 0)
                {
                    // new Thread()
                    // {
                    // @Override
                    // public void run()
                    // {
                    // try
                    // {
                    // sleep(10000);
                    // }
                    // catch (InterruptedException e)
                    // {
                    // // TODO Auto-generated catch block
                    // e.printStackTrace();
                    // }
                    // Display.getDefault().asyncExec(new Runnable()
                    // {
                    //
                    // @Override
                    // public void run()
                    // {

                    // }
                    //
                    // });
                    // }

                    // }.start();
                    // moduleCanvas.setBorder();
                }
            }
        }

        // compositeModules.pack();

    }

    public class ModuleCanvas extends FigureCanvas
    {

        public ModuleCanvas(Composite parent)
        {
            super(parent);
            LineBorder mLineBorder = new LineBorder();
            mLineBorder.setWidth(10);
            mLineBorder.setColor(ColorConstants.blue);
            this.setBorder(mLineBorder);
            Figure f = new RectangleFigure()
            {

                @Override
                public void paint(Graphics graphics)
                {
                    super.paint(graphics);
                    graphics.drawString("A01", 5, 5); // position
                }
            };
            f.setBackgroundColor(ColorConstants.black);
            f.setOpaque(true);
            // f.setBackgroundColor(ColorConstants.white);
            this.setContents(f);

        }
    }




since it is happenen any way without thread,it will happen with thread for resolution change... Smile


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay

[Updated on: Thu, 14 October 2010 09:27]

Report message to a moderator

Previous Topic:Different Routing for different type of connections
Next Topic:add new tab to the palette tool
Goto Forum:
  


Current Time: Thu Oct 23 22:09:36 GMT 2014

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

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