org.eclipse.draw2d.Viewport Java Examples

The following examples show how to use org.eclipse.draw2d.Viewport. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ERDiagramOutlinePage.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
private void showThumbnail() {
	if (quickMode) {
		return;
	}
	// RootEditPart�̃r���[���\�[�X�Ƃ��ăT���l�C�����쐬
	ScalableFreeformRootEditPart editPart = (ScalableFreeformRootEditPart) this.graphicalViewer
			.getRootEditPart();

	if (this.thumbnail != null) {
		this.thumbnail.deactivate();
	}

	this.thumbnail = new ScrollableThumbnail((Viewport) editPart
			.getFigure());
	this.thumbnail.setSource(editPart
			.getLayer(LayerConstants.PRINTABLE_LAYERS));

	this.lws.setContents(this.thumbnail);

}
 
Example #2
Source File: EditorRulerComposite.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void disposeRulerViewer( GraphicalViewer viewer )
{
	if ( viewer == null )
		return;
	/*
	 * There's a tie from the editor's range model to the RulerViewport (via
	 * a listener) to the RulerRootEditPart to the RulerViewer. Break this
	 * tie so that the viewer doesn't leak and can be garbage collected.
	 */

	RangeModel rModel = new DefaultRangeModel( );
	Viewport port = ( (FigureCanvas) viewer.getControl( ) ).getViewport( );
	port.setHorizontalRangeModel( new RulerDefaultRangeModel( rModel ) );
	port.setVerticalRangeModel( new RulerDefaultRangeModel( rModel ) );
	rulerEditDomain.removeViewer( viewer );
	viewer.getControl( ).dispose( );
}
 
Example #3
Source File: ProcessDiagramEditor.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * initialize the overview
 */
protected void initializeOverview() {
	LightweightSystem lws = new LightweightSystem(overview);
	RootEditPart rep = getGraphicalViewer().getRootEditPart();
	DiagramRootEditPart root = (DiagramRootEditPart) rep;
	thumbnail = new ScrollableThumbnailEx((Viewport) root.getFigure());
	// thumbnail.setSource(root.getLayer(org.eclipse.gef.LayerConstants.PRINTABLE_LAYERS));
	thumbnail.setSource(root.getLayer(LayerConstants.SCALABLE_LAYERS));

	lws.setContents(thumbnail);
	disposeListener = new DisposeListener() {

		public void widgetDisposed(DisposeEvent e) {
			if (thumbnail != null) {
				thumbnail.deactivate();
				thumbnail = null;
			}
		}
	};
	getEditor().addDisposeListener(disposeListener);
	this.overviewInitialized = true;
}
 
Example #4
Source File: FiguresHelper.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convenient method to translate bounds to Absolute coordinate
 *
 * @param owner
 * @param b
 */
public static void translateToAbsolute(final IFigure owner, final Rectangle b) {
    owner.translateToAbsolute(b);
    IFigure parentFigure = owner.getParent();
    while (parentFigure != null) {
        if (parentFigure instanceof Viewport) {
            final Viewport viewport = (Viewport) parentFigure;
            b.translate(
                    viewport.getHorizontalRangeModel().getValue(),
                    viewport.getVerticalRangeModel().getValue());
            parentFigure = parentFigure.getParent();
        }
        else {
            parentFigure = parentFigure.getParent();
        }
    }
}
 
Example #5
Source File: RailroadView.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public void reveal(IFigure figure) {
	Viewport viewport = canvas.getViewport();
	Rectangle viewportBounds = viewport.getBounds().getCopy();
	viewportBounds.translate(viewport.getViewLocation());
	Rectangle figureBounds = figure.getBounds().getCopy();
	figure.translateToAbsolute(figureBounds);
	figureBounds.translate(viewport.getViewLocation());
	if (!viewportBounds.contains(figureBounds)) {
		int newX = viewportBounds.x;
		int newY = viewportBounds.y;
		if(viewportBounds.x > figureBounds.x) {
			newX = figureBounds.x; 
		} else if(viewportBounds.x + viewportBounds.getRight().x < figureBounds.getRight().x) {
			newX = figureBounds.getRight().x - viewportBounds.width;
		}
		if(viewportBounds.y > figureBounds.y) {
			newY = figureBounds.y; 
		} else if(viewportBounds.getBottom().y < figureBounds.getBottom().y) {
			newY = figureBounds.getBottom().y - viewportBounds.height;
		}
		canvas.scrollSmoothTo(newX, newY);
	}
}
 
Example #6
Source File: AbstractSwitchLaneSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param zoom 
 * 
 */
private void showSelectionForAddBottom(double zoom) {
	if (!isOnBottom()) {

		IFigure f = new ImageFigure(Pics.getImage(PicsConstants.arrowDown));
		f.setSize(20, 20);

		sourceFigure = getHostFigure() ;

		Rectangle bounds = sourceFigure.getBounds().getCopy();
		//get the absolute coordinate of bounds
		sourceFigure.translateToAbsolute(bounds);
		IFigure parentFigure = sourceFigure.getParent();
		while( parentFigure != null  ) {
			if(parentFigure instanceof Viewport) {
				Viewport viewport = (Viewport)parentFigure;
				bounds.translate(
						viewport.getHorizontalRangeModel().getValue(),
						viewport.getVerticalRangeModel().getValue());
				parentFigure = parentFigure.getParent();
			}
			else {
				parentFigure = parentFigure.getParent();
			}
		}

		Point location =new Point(bounds.getBottomLeft().x+20,bounds.getBottomLeft().y) ; 

		f.setLocation(location);

		f.addMouseListener(new MouseListenerForSpan(AbstractSwitchLaneSelectionEditPolicy.ADD_BOTTOM));
		getLayer(LayerConstants.HANDLE_LAYER).add(f);
		figures.add(f);
	}
}
 
Example #7
Source File: SankeyMiniViewAction.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private ScrollableThumbnail createThumbnail() {
	Viewport port = (Viewport) part.getFigure();
	IFigure figure = part.getLayer(LayerConstants.PRINTABLE_LAYERS);
	ScrollableThumbnail thumbnail = new ScrollableThumbnail(port);
	thumbnail.setSource(figure);
	return thumbnail;
}
 
Example #8
Source File: Animation.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
public static boolean captureLayout(IFigure root) {

		RECORDING = true;

		while (!(root instanceof Viewport)) {
			root = root.getParent();
		}
		viewport = (Viewport) root;
		while (root.getParent() != null) {
			root = root.getParent();
		}

		initialStates = new HashMap<>();
		finalStates = new HashMap<>();

		// This part records all layout results.
		root.validate();
		Iterator<IFigure> iter = initialStates.keySet().iterator();
		if (!iter.hasNext()) {
			// Nothing layed out, so abort the animation
			RECORDING = false;
			return false;
		}
		while (iter.hasNext()) {
			recordFinalState(iter.next());
		}

		start = System.currentTimeMillis();
		finish = start + DURATION;
		current = start + 20;

		RECORDING = false;
		PLAYBACK = true;
		return true;
	}
 
Example #9
Source File: OpenMiniatureViewAction.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private void update(Viewport port, IFigure figure, Control control, ZoomManager zoomManager) {
	this.port = port;
	this.figure = figure;
	this.control = control;
	this.zoomManager = zoomManager;
	if (window != null)
		window.refresh();
}
 
Example #10
Source File: CustomPasteCommand.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 */
protected Point getPartAbsoluteCursorLocation() {
	org.eclipse.draw2d.geometry.Point toolLocation = null;
	try {
		Tool tool = selectedTargetEditPart.getViewer().getEditDomain().getActiveTool();
		AbstractTool aTool = (AbstractTool) tool;
		Method m = AbstractTool.class.getDeclaredMethod("getLocation"); //$NON-NLS-1$
		m.setAccessible(true);
		toolLocation = ((org.eclipse.draw2d.geometry.Point) m.invoke(aTool)).getCopy();

		IFigure parentFigure = selectedTargetEditPart.getFigure().getParent();
		while( parentFigure != null  ) {
			if(parentFigure instanceof Viewport) {
				Viewport viewport = (Viewport)parentFigure;
				toolLocation.translate(viewport.getHorizontalRangeModel().getValue(),
						viewport.getVerticalRangeModel().getValue());
				parentFigure = parentFigure.getParent();
			} else {
				parentFigure = parentFigure.getParent();
			}
		}

		return toolLocation;
	} catch (Exception e) {
		BonitaStudioLog.log("can't find exact location for pasting"); //$NON-NLS-1$
		return null;
	}
}
 
Example #11
Source File: UpdateSizePoolSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void mousePressed(MouseEvent me) {
    try {

        IFigure  f = ((CustomMainProcessEditPart) poolEditPart.getParent()).getFigure() ;
        IFigure p = f ;
        while(!(p instanceof Viewport)){
            p = p.getParent();
        }

        int y = ((Viewport)p).getVerticalRangeModel().getValue() ;
        int x = ((Viewport)p).getHorizontalRangeModel().getValue() ;


        IUndoableOperation c = new UpdatePoolSizeCommand(poolEditPart, type);
        OperationHistoryFactory.getOperationHistory().execute(c,null,null);
        me.consume();


        poolEditPart.getViewer().setSelection(new StructuredSelection(poolEditPart));
        refresh();
        poolEditPart.getViewer().setSelection(new StructuredSelection(getHost()));

        if(type.equals(ADD_RIGHT)){
            ((Viewport)p).setHorizontalLocation(x+150);
        }

        ((Viewport)p).setVerticalLocation(y);


    } catch (ExecutionException e) {
        e.printStackTrace();
    }
}
 
Example #12
Source File: SwitchPoolSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 */
private void showSelectionForAddTop() {
	if (!isOnTop()) {

		IFigure f = new ImageFigure(Pics.getImage(PicsConstants.arrowUp));
		f.setParent(getHostFigure());
		f.setSize(20, 20);



		sourceFigure = getHostFigure() ;

		Rectangle bounds = sourceFigure.getBounds().getCopy();
		//get the absolute coordinate of bounds
		sourceFigure.translateToAbsolute(bounds);
		IFigure parentFigure = sourceFigure.getParent();
		while( parentFigure != null  ) {
			if(parentFigure instanceof Viewport) {
				Viewport viewport = (Viewport)parentFigure;
				bounds.translate(
						viewport.getHorizontalRangeModel().getValue(),
						viewport.getVerticalRangeModel().getValue());
				parentFigure = parentFigure.getParent();
			}
			else {
				parentFigure = parentFigure.getParent();
			}
		}

		f.setLocation(new Point(bounds.getTopLeft().x,bounds.getTop().y-20));
		f.addMouseListener(new MouseListenerForSpan(AbstractSwitchLaneSelectionEditPolicy.ADD_TOP));
		layer.add(f);
		figures.add(f);
	}
}
 
Example #13
Source File: SwitchPoolSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 */
private void showSelectionForAddBottom() {
	if (!isOnBottom()) {

		IFigure f = new ImageFigure(Pics.getImage(PicsConstants.arrowDown));
		f.setSize(20, 20);

		sourceFigure = getHostFigure() ;

		Rectangle bounds = sourceFigure.getBounds().getCopy();
		//get the absolute coordinate of bounds
		sourceFigure.translateToAbsolute(bounds);
		IFigure parentFigure = sourceFigure.getParent();
		while( parentFigure != null  ) {
			if(parentFigure instanceof Viewport) {
				Viewport viewport = (Viewport)parentFigure;
				bounds.translate(
						viewport.getHorizontalRangeModel().getValue(),
						viewport.getVerticalRangeModel().getValue());
				parentFigure = parentFigure.getParent();
			}
			else {
				parentFigure = parentFigure.getParent();
			}
		}

		f.setLocation(new Point(bounds.getBottomLeft().x,bounds.getBottom().y));

		f.addMouseListener(new MouseListenerForSpan(AbstractSwitchLaneSelectionEditPolicy.ADD_BOTTOM));
		layer.add(f);
		figures.add(f);
	}
}
 
Example #14
Source File: AbstractSwitchLaneSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param zoom 
 * 
 */
private void showSelectionForAddTop(double zoom) {
	if (!isOnTop()) {

		IFigure f = new ImageFigure(Pics.getImage(PicsConstants.arrowUp));
		f.setParent(getHostFigure());
		f.setSize(20, 20);



		sourceFigure = getHostFigure() ;

		Rectangle bounds = sourceFigure.getBounds().getCopy();
		//get the absolute coordinate of bounds
		sourceFigure.translateToAbsolute(bounds);
		IFigure parentFigure = sourceFigure.getParent();
		while( parentFigure != null  ) {
			if(parentFigure instanceof Viewport) {
				Viewport viewport = (Viewport)parentFigure;
				bounds.translate(
						viewport.getHorizontalRangeModel().getValue(),
						viewport.getVerticalRangeModel().getValue());
				parentFigure = parentFigure.getParent();
			}
			else {
				parentFigure = parentFigure.getParent();
			}
		}


		Point location = new Point(bounds.getTopLeft().x+20,bounds.getTopLeft().y-20) ;

		f.setLocation(location);
		f.addMouseListener(new MouseListenerForSpan(AbstractSwitchLaneSelectionEditPolicy.ADD_TOP));
		getLayer(LayerConstants.HANDLE_LAYER).add(f);
		figures.add(f);
	}
}
 
Example #15
Source File: UpdateSizeLaneSelectionEditPolicy.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void mousePressed(final MouseEvent me) {
    try {

        final IFigure  f = ((CustomMainProcessEditPart) laneEditPart.getParent().getParent().getParent()).getFigure() ;
        IFigure p = f ;
        while(!(p instanceof Viewport)){
            p = p.getParent();
        }

        final int y = ((Viewport)p).getVerticalRangeModel().getValue() ;

        IGraphicalEditPart targetEp = laneEditPart;
        if(type.equals(UpdateSizePoolSelectionEditPolicy.ADD_RIGHT)||type.equals(UpdateSizePoolSelectionEditPolicy.REMOVE_RIGHT)){
            targetEp = getPoolEditPart();
        }

        final IUndoableOperation c = new UpdatePoolSizeCommand(targetEp, type);
        OperationHistoryFactory.getOperationHistory().execute(c,null,null);
        me.consume();
        laneEditPart.getViewer().setSelection(new StructuredSelection(targetEp));
        refresh();
        laneEditPart.getViewer().setSelection(new StructuredSelection(getHost()));
        ((Viewport)p).setVerticalLocation(y);


    } catch (final ExecutionException e) {
        e.printStackTrace();
    }
}
 
Example #16
Source File: FiguresHelper.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Convenient method to translate bounds to Absolute coordinate
 *
 * @param owner
 * @param p
 */
public static void translateToAbsolute(IFigure owner, final Point p) {
    while (owner != null) {
        if (owner instanceof Viewport) {
            final Viewport viewport = (Viewport) owner;
            p.translate(
                    viewport.getHorizontalRangeModel().getValue(),
                    viewport.getVerticalRangeModel().getValue());
            owner = owner.getParent();
        }
        else {
            owner = owner.getParent();
        }
    }
}
 
Example #17
Source File: ReportRootEditPart.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns <code>true</code> if the given point is inside the
 * viewport, but near its edge.
 * 
 * @see org.eclipse.gef.AutoexposeHelper#detect(org.eclipse.draw2d.geometry.Point)
 */
public boolean detect( Point where )
{
	lastStepTime = 0;
	Viewport port = findViewport( owner );
	Rectangle rect = Rectangle.SINGLETON;
	port.getClientArea( rect );
	port.translateToParent( rect );
	port.translateToAbsolute( rect );
	return rect.contains( where )
			&& !rect.crop( threshold ).contains( where );
}
 
Example #18
Source File: DeferredGraphicalViewer.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 */
public void initStepDat( )
{
	Viewport port = ( (FigureCanvas) getControl( ) ).getViewport( );
	stepData.minX = port.getHorizontalRangeModel( ).getMinimum( );
	stepData.maxX = port.getHorizontalRangeModel( ).getMaximum( );
	stepData.valueX = port.getHorizontalRangeModel( ).getValue( );
	stepData.extendX = port.getHorizontalRangeModel( ).getExtent( );

	stepData.minY = port.getVerticalRangeModel( ).getMinimum( );
	stepData.maxY = port.getVerticalRangeModel( ).getMaximum( );
	stepData.valueY = port.getVerticalRangeModel( ).getValue( );
	stepData.extendY = port.getVerticalRangeModel( ).getExtent( );
}
 
Example #19
Source File: ERDiagramOutlinePage.java    From erflute with Apache License 2.0 5 votes vote down vote up
private void showThumbnail() {
    if (quickMode) {
        return;
    }
    final ScalableFreeformRootEditPart editPart = (ScalableFreeformRootEditPart) graphicalViewer.getRootEditPart();
    if (thumbnail != null) {
        thumbnail.deactivate();
    }
    this.thumbnail = new ScrollableThumbnail((Viewport) editPart.getFigure());
    thumbnail.setSource(editPart.getLayer(LayerConstants.PRINTABLE_LAYERS));
    lws.setContents(thumbnail);
}
 
Example #20
Source File: ReportRootEditPart.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns <code>true</code> if the given point is outside the
 * viewport or near its edge. Scrolls the viewport by a calculated (time
 * based) amount in the current direction.
 * 
 * todo: investigate if we should allow auto expose when the pointer is
 * outside the viewport
 * 
 * @see org.eclipse.gef.AutoexposeHelper#step(org.eclipse.draw2d.geometry.Point)
 */
public boolean step( Point where )
{
	Viewport port = findViewport( owner );

	Rectangle rect = Rectangle.SINGLETON;
	port.getClientArea( rect );
	port.translateToParent( rect );
	port.translateToAbsolute( rect );
	if ( !rect.contains( where )
			|| rect.crop( threshold ).contains( where ) )
		return false;

	// set scroll offset (speed factor)
	int scrollOffset = 0;

	// calculate time based scroll offset
	if ( lastStepTime == 0 )
		lastStepTime = System.currentTimeMillis( );

	DeferredGraphicalViewer.OriginStepData stepData = ( (DeferredGraphicalViewer) owner.getViewer( ) ).getOriginStepData( );
	long difference = System.currentTimeMillis( ) - lastStepTime;

	if ( difference > 0 )
	{
		scrollOffset = ( (int) difference / 3 );
		lastStepTime = System.currentTimeMillis( );
	}

	if ( scrollOffset == 0 )
		return true;

	rect.crop( threshold );

	int region = rect.getPosition( where );
	Point loc = port.getViewLocation( );

	if ( ( region & PositionConstants.SOUTH ) != 0 )
		loc.y += scrollOffset;
	else if ( ( region & PositionConstants.NORTH ) != 0 )
		loc.y -= scrollOffset;

	if ( ( region & PositionConstants.EAST ) != 0 )
		loc.x += scrollOffset;
	else if ( ( region & PositionConstants.WEST ) != 0 )
		loc.x -= scrollOffset;

	if ( stepData.minX > loc.x )
		loc.x = port.getHorizontalRangeModel( ).getValue( );
	if ( stepData.maxX - stepData.extendX < loc.x )
		loc.x = port.getHorizontalRangeModel( ).getValue( );
	if ( stepData.minY > loc.y )
		loc.y = port.getVerticalRangeModel( ).getValue( );
	if ( stepData.maxY - stepData.extendY < loc.y )
		loc.y = port.getVerticalRangeModel( ).getValue( );
	port.setViewLocation( loc );

	return true;
}
 
Example #21
Source File: OpenMiniatureViewAction.java    From olca-app with Mozilla Public License 2.0 4 votes vote down vote up
private Viewport getViewport() {
	return (Viewport) getRootEditPart().getFigure();
}
 
Example #22
Source File: DeferredGraphicalViewer.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void reveal( EditPart part )
{
	// In some case, the editor control is not created, but get the sync selection event.
	// Fix this problem temporary.
	if(getFigureCanvas( )==null || getFigureCanvas( ).isDisposed( ))
	{
		return;
	}
	
	Viewport port = getFigureCanvas( ).getViewport( );
	IFigure target = ( (GraphicalEditPart) part ).getFigure( );

	Rectangle exposeRegion = target.getBounds( ).getCopy( );

	// Get the primary editpolicy
	EditPolicy policy = part.getEditPolicy( EditPolicy.PRIMARY_DRAG_ROLE );

	// If the policy let us access the handles, proceed, otherwise
	// default to original behaviour
	if ( !( policy instanceof ISelectionHandlesEditPolicy ) )
	{
		super.reveal( part );
		return;
	}

	// First translate exposeRegion to the root level
	target = target.getParent( );
	while ( target != null && target != port )
	{
		target.translateToParent( exposeRegion );
		target = target.getParent( );
	}

	// Merge selection handles if any to the exposeRegion
	List handles = ( (ISelectionHandlesEditPolicy) policy ).getHandles( );
	for ( Iterator iter = handles.iterator( ); iter.hasNext( ); )
	{
		AbstractHandle handle = (AbstractHandle) iter.next( );

		Locator locator = handle.getLocator( );
		locator.relocate( handle );
		exposeRegion.union( handle.getBounds( ).getCopy( ) );
	}

	exposeRegion.getExpanded( 5, 5 );

	Dimension viewportSize = port.getClientArea( ).getSize( );

	Point topLeft = exposeRegion.getTopLeft( );
	Point bottomRight = exposeRegion.getBottomRight( )
			.translate( viewportSize.getNegated( ) );
	Point finalLocation = new Point( );
	if ( viewportSize.width < exposeRegion.width )
		finalLocation.x = Math.min( bottomRight.x, Math.max( topLeft.x,
				port.getViewLocation( ).x ) );
	else
		finalLocation.x = Math.min( topLeft.x, Math.max( bottomRight.x,
				port.getViewLocation( ).x ) );

	if ( viewportSize.height < exposeRegion.height )
		finalLocation.y = Math.min( bottomRight.y, Math.max( topLeft.y,
				port.getViewLocation( ).y ) );
	else
		finalLocation.y = Math.min( topLeft.y, Math.max( bottomRight.y,
				port.getViewLocation( ).y ) );

	getFigureCanvas( ).scrollSmoothTo( finalLocation.x, finalLocation.y );
}
 
Example #23
Source File: EditorRulerRootEditPart.java    From birt with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Convenience method to get to the viewport
 * 
 * @return the figure cast as a viewport
 */
protected Viewport getViewport( )
{
	return (Viewport) getFigure( );
}