我要做一个界面设计的作业,要求实现 小窗口的拖放功能。大概要求是:
首先用sashform把窗口分成左右两部分,左边的窗口里面有一下小窗口,但是可以拖拉到右边的窗口,可以任意停靠,就像photoshop 里面的工具栏一样,请问各位高手该咋做,有没有例子让我参考一下,邮箱:[email protected]
首先用sashform把窗口分成左右两部分,左边的窗口里面有一下小窗口,但是可以拖拉到右边的窗口,可以任意停靠,就像photoshop 里面的工具栏一样,请问各位高手该咋做,有没有例子让我参考一下,邮箱:[email protected]
楼主截止到2008-06-18 14:16:33的汇总数据:
发帖数:1
结贴数:0
结贴率: 0.00%
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
public void mouseDown(MouseEvent e) {
// TODO Auto-generated method stub
//get shell original location
_originalPoint = new Point(e.x,e.y);
System.out.println(" x :"+e.x+" y:"+e.y);
}
public void mouseUp(MouseEvent e) {
// TODO Auto-generated method stub
_originalPoint = null;
}
});
_shell.addMouseMoveListener(new MouseMoveListener(){
public void mouseMove(MouseEvent e) {
// TODO Auto-generated method stub
if( _originalPoint != null){
Point point =Display.getCurrent().map(_shell, null, e.x, e.y);
//reset play list pane`s location
if( _playListComposite != null){
Shell childShell = ((PlayListPane)_playListComposite)._childShell;
if( childShell!= null){
//如果界面有衔接,或者重叠,则一起移动
int child_X = _shell.getLocation().x;
int child_Y = _shell.getLocation().y + _shell.getSize().y ;
if( childShell.getLocation().x >= (child_X -10) &&
childShell.getLocation().x <= ( child_X + 10) &&
childShell.getLocation().y >=(child_Y - 5)&&
childShell.getLocation().y <=( child_Y + 5)){
childShell.setLocation(point.x-_originalPoint.x, point.y-_originalPoint.y+_shell.getSize().y);
}
}
}
_shell.setLocation(point.x-_originalPoint.x, point.y-_originalPoint.y);
}
}
});
-------------------------------------------------------------
Quietly through .....
Quietly through .....
// implement mouse drag
canvas.addMouseMoveListener( this );
canvas.addMouseListener( this );即可直接拖拽是整个窗口移动
按住Ctrl是在窗口内部拖拽该组件package com.dextrys.trilogy.toolkit.jzoomer.base;import org.eclipse.jface.window.ApplicationWindow;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import com.dextrys.trilogy.toolkit.jzoomer.common.JZoomerConstant;
import com.dextrys.trilogy.util.SourceBundlesReader;
import com.dextrys.trilogy.util.swt.DisplayUtil;/**
*
* @author marquis Modified Date:Jun 16, 2008
*/
public class BasicWindow extends ApplicationWindow implements MouseMoveListener, MouseListener
{
//private int locationX = 0;
//private int locationY = 0;
private Point location; //Mouse Relative Location
private Cursor currentCursor; public static final Cursor CURSOR_HAND = new Cursor( Display.getCurrent(), SWT.CURSOR_HAND );
public static final Cursor CURSOR_CROSS = new Cursor( Display.getCurrent(), SWT.CURSOR_CROSS );
public static final Cursor CURSOR_ARROW = new Cursor( Display.getCurrent(), SWT.CURSOR_ARROW ); public BasicWindow()
{
} // ====================Mouse Listener========================
public void mouseMove( MouseEvent e )
{ // when mouse move with left button pressed, implement move-following-mouse moving
Control c = ( Control ) e.getSource();
if( e.stateMask == SWT.BUTTON1 )
{// move with mouse left button pressed
//System.out.println( "Mouse move: Left button pressed" );
if( e.getSource() instanceof Composite && c.getParent() instanceof Shell )
{// top composite
c.setCursor( CURSOR_HAND );
moveShell(); } else
{// other widgets
c.setCursor( CURSOR_HAND );
moveShell();
}
} else if( e.stateMask == ( SWT.CTRL | SWT.BUTTON1 ) )
{// move ctrl + mouse left button pressed
c.setCursor( CURSOR_HAND );
if( e.getSource() instanceof Composite && c.getParent() instanceof Shell )
{// top composite
} else
{// other widgets
moveInParent( e );
}
}
} public void mouseDown( MouseEvent e )
{
Control c = ( Control ) e.getSource();
currentCursor = c.getCursor();
if( e.button == 1 && e.stateMask == SWT.None )
{// press down mouse left button
if( e.getSource() instanceof Composite && c.getParent() instanceof Shell )
{// top composite
c.setCursor( CURSOR_HAND );
location = getMouseRelativeLocation();
} else
{// other widgets
c.setCursor( CURSOR_HAND );
location = getMouseRelativeLocation();
}
} else if( e.button == 1 && e.stateMask == SWT.CTRL )
{// press down ctrl + mouse left button
if( e.getSource() instanceof Composite && c.getParent() instanceof Shell )
{// top composite
} else
{// other widgets
c.setCursor( CURSOR_HAND );
location = new Point( e.x, e.y );
}
}
} public void mouseUp( MouseEvent e )
{
//Restore cursor
Control c = ( Control ) e.getSource();
c.setCursor( currentCursor );
// c.setCursor( CURSOR_ARROW );
} public void mouseDoubleClick( MouseEvent e )
{ }}