Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] mulitple listeners/sash

I have multiple listeners on the same object.  The object is a sash 
that divides a tree and a browser.  The slash should be able to be drug 
anywhere within the view of the Eclipse plugin.  When the slash has 
been double clicked on, the sash should collapse back to a 0 (I'm using 
FormLayout with means 0 would be a percentage) and when the sash is at 
0 and double-clicked on again, it should return to the x coordinate 
that it had been drug to (or collapsed from).  I can drag the sash and 
collpase the sash to 0 fine, but I cannot get a working coordinate to 
return the sash back too.  Do you have any ideas?

Here is a sample of the code(all of the system prints are there to help 
me identify the numbers being passed)...

public void handleEvent(Event event) {
		if (event.widget == sash) {
			if (event.type == SWT.Selection) {
				widgetSelected(new SelectionEvent
(event));
			}
			if (event.type == SWT.MouseDoubleClick) {
				mouseDoubleClick(new MouseEvent(event));
			}		
		}
    }
	
	
	void installListeners () {
	    listener = new Listener () {
	        public void handleEvent (Event event) {
	            OutputView.this.handleEvent (event);
	        }
	    };
	    sash.addListener(SWT.Selection, listener);
		sash.addListener(SWT.MouseDoubleClick, listener);
	}
	
	public void widgetSelected(SelectionEvent event) {
		if(((FormData) sash.getLayoutData()).left.numerator != -
1)
		{
        	htOffsetValue.put(new Integer(htWidthCount),new Integer
(((FormData) sash.getLayoutData()).left.numerator));
		}
		((FormData) sash.getLayoutData()).left = new 
FormAttachment(-1, event.x);
        sash.getParent().layout(); 
        
        htWidthValue.put(new Integer(htWidthCount),new Integer
(((FormData) sash.getLayoutData()).left.offset));
        htWidthCount++;
        System.out.println(((FormData) sash.getLayoutData
()).left.offset);
        width = ((FormData) sash.getLayoutData()).left.offset;
        
	}

	//Mouse Double Click listener
	public void mouseDoubleClick(MouseEvent event) {
		FormAttachment faSwt = null;
		System.out.println(width);
		System.out.println(((FormData) sash.getLayoutData
()).left.offset + "  > " +((Integer)htWidthValue.get(new Integer
(0))).intValue());
		
    	if (width > 5) {
    		// go back to edge
    		System.out.print(" you are dum 1 ");
    		faSwt = new FormAttachment(0);	
    		System.out.println((((FormData) sash.getLayoutData
()).left.numerator));
    	}
    	if (width <= 5) {
    		int percent = ((Integer)htWidthValue.get(new Integer
(0))).intValue();
    		System.out.println(" you are dum ");
    		faSwt = new FormAttachment(percent);
    		System.out.println((((FormData) sash.getLayoutData
()).left.numerator));
    		//htWidthCount = 0;
    		htWidthValue.clear();
    		htOffsetValue.clear();
    	}
	
    	((FormData) sash.getLayoutData()).left = faSwt;//new 
FormAttachment(0, e.x);
    	//put sash in location above
    	sash.getParent().layout();

	}

Thanks in advance.


Back to the top