/** * Constructor */ public RulerViewport() { super(true); setLayoutManager(null); // The range model that's not shared is initialized such that it can't scroll // anymore (otherwise, CTRL + SHIFT + ARROW scrolls it). RangeModel bogusRangeModel; if (horizontal) bogusRangeModel = getVerticalRangeModel(); else bogusRangeModel = getHorizontalRangeModel(); bogusRangeModel.setMinimum(0); bogusRangeModel.setMaximum(100); bogusRangeModel.setValue(0); bogusRangeModel.setExtent(100); }
/** * This method can be used to determine the center location (x) of the timeline relative to the user on the screen. Results of this operation can be passed to the timeline.centerOnTime(..) method * to re-center the timeline after a destabilizing operation. Of course first the location would first have to be converted to a Date object, in which case you could just call the * getCurrentScreenCenterDate() method. * * @return the x location of the center of the screen */ public int getCurrentScreenCenterLocation() { int screenPosition = -1; int viewportWidth = this.getTimelineViewers().get(1).getTimelineEditPart().getDataScrollPane().getViewport().getBounds().width; RangeModel horzRangeModel = this.getHorizontalRangeModel(); int currentScrollPosition = horzRangeModel.getValue(); int vLeft = currentScrollPosition; int vCenter = vLeft + (viewportWidth / 2); screenPosition = vCenter; if (screenPosition == -1) { LogUtil.warn("couldn't get center screen position"); } return screenPosition; }
/** * This method can be used to retrieve the right most visible location of the timeline visible to the user through the current viewport. * * @return the x location of the right most part of the timeline visible to the user. */ public int getCurrentScreenRightLocation() { int screenPosition = -1; int viewportWidth = this.getTimelineViewers().get(1).getTimelineEditPart().getDataScrollPane().getViewport().getBounds().width; RangeModel horzRangeModel = this.getHorizontalRangeModel(); int currentScrollPosition = horzRangeModel.getValue(); int vLeft = currentScrollPosition; int vRight = vLeft + viewportWidth; screenPosition = vRight; if (screenPosition == -1) { LogUtil.warn("couldn't get right screen position"); } return screenPosition; }
/** * Finds the viewport of the given EditPart and scrolls it as requested. If * it can't be scrolled then leaves doit to be true so that the given * EditPart's ancestors might have a chance to scroll. * * @see org.eclipse.gef.MouseWheelHelper#handleMouseWheelScrolled(org.eclipse.swt.widgets.Event) */ public void handleMouseWheelScrolled(Event event) { Viewport viewport = findViewport(owner); if (viewport == null || !viewport.isShowing()) return; RangeModel rModel = viewport.getVerticalRangeModel(); if (rModel.getExtent() < (rModel.getMaximum() - rModel.getMinimum())) { int currentPos = rModel.getValue(); int scrollHeight = lineHeight; if (event.detail == SWT.SCROLL_PAGE) scrollHeight = pageHeight > lineHeight ? pageHeight : Math.max( lineHeight, viewport.getClientArea(Rectangle.SINGLETON).height - 26); scrollHeight *= event.count; viewport.setVerticalLocation(currentPos - scrollHeight); if (rModel.getValue() != currentPos) event.doit = false; } }
/** * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#restoreState(org.eclipse.ui.IMemento) */ public void restoreState(IMemento memento) { setExpanded(new Boolean(memento.getString(PROPERTY_EXPANSION_STATE)) .booleanValue()); setPinnedOpen(new Boolean(memento.getString(PROPERTY_PINNED_STATE)) .booleanValue()); RangeModel rModel = getDrawerFigure().getScrollpane().getViewport() .getVerticalRangeModel(); rModel.setMinimum(memento.getInteger(RangeModel.PROPERTY_MINIMUM) .intValue()); rModel.setMaximum(memento.getInteger(RangeModel.PROPERTY_MAXIMUM) .intValue()); rModel.setExtent(memento.getInteger(RangeModel.PROPERTY_EXTENT) .intValue()); rModel.setValue(memento.getInteger(RangeModel.PROPERTY_VALUE) .intValue()); super.restoreState(memento); }
/** * Constructor */ public RulerViewport() { super(true); setLayoutManager(null); // The range model that's not shared is initialized such that it // can't scroll // anymore (otherwise, CTRL + SHIFT + ARROW scrolls it). RangeModel bogusRangeModel; if (horizontal) bogusRangeModel = getVerticalRangeModel(); else bogusRangeModel = getHorizontalRangeModel(); bogusRangeModel.setMinimum(0); bogusRangeModel.setMaximum(100); bogusRangeModel.setValue(0); bogusRangeModel.setExtent(100); }
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. */ dockLayoutPanel.remove(northPanel); dockLayoutPanel.remove(westPanel); dockLayoutPanel.forceLayout(); RangeModel rModel = new DefaultRangeModel(); Viewport port = ((FigureCanvas) viewer.getControl()).getViewport(); port.setHorizontalRangeModel(rModel); port.setVerticalRangeModel(rModel); rulerEditDomain.removeViewer(viewer); viewer.getRootEditPart().deactivate(); // viewer.getControl().dispose(); }
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( ); }
/** * Constructor */ public RulerViewport( ) { super( true ); setLayoutManager( null ); // The range model that's not shared is initialized such that it // can't scroll // anymore (otherwise, CTRL + SHIFT + ARROW scrolls it). RangeModel bogusRangeModel; if ( horizontal ) bogusRangeModel = getVerticalRangeModel( ); else bogusRangeModel = getHorizontalRangeModel( ); bogusRangeModel.setMinimum( 0 ); bogusRangeModel.setMaximum( 100 ); bogusRangeModel.setValue( 0 ); bogusRangeModel.setExtent( 100 ); }
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(rModel); port.setVerticalRangeModel(rModel); rulerEditDomain.removeViewer(viewer); viewer.getControl().dispose(); }
/** * This is the method that does the actual layout. We don't want a layout to occur when layout() is invoked, rather * when something changes in the shared RangeModel. * * @param force * if <code>true</code>, the contents will be resized and revalidated; otherwise, just a repaint will * occur. */ protected void doLayout(boolean force) { repaint(); /* * @TODO:Pratik It seems you don't really need this force argument. Those that invoke doLayout(false) can invoke * repaint() themselves. doLayout() should just layout. */ if (force) { RangeModel rModel; if (horizontal) rModel = getHorizontalRangeModel(); else rModel = getVerticalRangeModel(); Rectangle contentBounds = Rectangle.SINGLETON; if (horizontal) { contentBounds.y = 0; contentBounds.x = rModel.getMinimum(); contentBounds.height = this.getContents().getPreferredSize().height; contentBounds.width = rModel.getMaximum() - rModel.getMinimum(); } else { contentBounds.y = rModel.getMinimum(); contentBounds.x = 0; contentBounds.height = rModel.getMaximum() - rModel.getMinimum(); contentBounds.width = this.getContents().getPreferredSize().width; } if (!this.getContents().getBounds().equals(contentBounds)) { this.getContents().setBounds(contentBounds); this.getContents().revalidate(); } } }
/** * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent event) { if (this.getContents() != null && event.getSource() instanceof RangeModel) { String property = event.getPropertyName(); doLayout(RangeModel.PROPERTY_MAXIMUM.equals(property) || RangeModel.PROPERTY_MINIMUM.equals(property) || RangeModel.PROPERTY_VALUE.equals(property)); } }
/** * Replace the range model for this viewer * * @param rangeModel */ public void setHorizontalRangeModel(RangeModel rangeModel) { AbstractTimelineEditPart timelineEditPart = getTimelineEditPart(); ScrollPane dataScrollPane = timelineEditPart.getDataScrollPane(); Viewport viewport = dataScrollPane.getViewport(); viewport.setHorizontalRangeModel(rangeModel); }
private Control createTimelineRegion(Composite parent) { Composite timelineRegion = new EnsembleComposite(parent, SWT.NONE); timelineRegion.setData("debug", Timeline.class.getSimpleName() + ".timelineRegion"); timelineRegion.setLayout(new BorderLayout()); // create the range model first final RangeModel rangeModel = new DefaultRangeModel(); setHorizontalRangeModel(rangeModel); // frozen top timeline contents // date/time ruler (scale) Composite timelineTopComposite = buildTopTimeline(timelineRegion); timelineTopComposite.setLayoutData(SWT.TOP); // timeline contents ScrolledComposite scroller = buildTimelineContents(timelineRegion); scroller.setLayoutData(SWT.CENTER); // scroller TimelineViewer timelineHScroller = buildTimeline(timelineRegion, getTimelineModel(), new SplitScrollEditPartFactory<T>()); timelineHScroller.getControl().setLayoutData(SWT.BOTTOM); scroller.getContent().addListener(SWT.MouseHorizontalWheel, new Listener() { @Override public void handleEvent(Event event) { int value = rangeModel.getValue(); value -= 5 * event.count; rangeModel.setValue(value); } }); return timelineRegion; }
private void setHorizontalRangeModel(RangeModel rm) { if (horzRangeModel != null) { horzRangeModel.removePropertyChangeListener(horizontalRangeModelListener); } if (rm != null) { rm.addPropertyChangeListener(horizontalRangeModelListener); } this.horzRangeModel = rm; }
@Override public void propertyChange(PropertyChangeEvent evt) { final int newPosition = ((Integer) evt.getNewValue()).intValue(); if (RangeModel.PROPERTY_VALUE.equals(evt.getPropertyName())) { if (newPosition == x) { // success x = -1; } horzintalPosition = newPosition; } else { if (x >= 0 && x <= newPosition) { // try and set the value horzRangeModel.setValue(x); } } boolean optimizeScrolling = true; if (optimizeScrolling) { setScrolling(true); if (scrollingThread != null) { scrollingThread.interrupt(); scrollingThread = null; } scrollingThread = new Thread("Scrolling Thread") { @Override public void run() { try { sleep(SCROLL_REFRESH_DELAY); setScrolling(false); } catch (InterruptedException e) { // usually will be interrupted } } }; scrollingThread.start(); } }
/** * This method can be used to retrieve the left most visible location of the timeline visible to the user through the current viewport. * * @return the x location of the left most part of the timeline visible to the user. */ public int getCurrentScreenLeftLocation() { int screenPosition = -1; RangeModel horzRangeModel = this.getHorizontalRangeModel(); int currentScrollPosition = horzRangeModel.getValue(); int vLeft = currentScrollPosition; screenPosition = vLeft; if (screenPosition == -1) { LogUtil.warn("couldn't get left screen position"); } return screenPosition; }
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(rModel); port.setVerticalRangeModel(rModel); rulerEditDomain.removeViewer(viewer); viewer.getControl().dispose(); }
/** * @see org.eclipse.gef.ui.palette.editparts.PaletteEditPart#saveState(org.eclipse.ui.IMemento) */ public void saveState(IMemento memento) { memento.putString(PROPERTY_EXPANSION_STATE, new Boolean(isExpanded()).toString()); memento.putString(PROPERTY_PINNED_STATE, new Boolean(isPinnedOpen()).toString()); RangeModel rModel = getDrawerFigure().getScrollpane().getViewport() .getVerticalRangeModel(); memento.putInteger(RangeModel.PROPERTY_MINIMUM, rModel.getMinimum()); memento.putInteger(RangeModel.PROPERTY_MAXIMUM, rModel.getMaximum()); memento.putInteger(RangeModel.PROPERTY_EXTENT, rModel.getExtent()); memento.putInteger(RangeModel.PROPERTY_VALUE, rModel.getValue()); super.saveState(memento); }
protected void initialize() { super.initialize(); setLayoutManager(new ScrollBarLayout(transposer) { protected Rectangle layoutButtons(ScrollBar scrollBar) { Rectangle bounds = transposer.t(scrollBar.getClientArea()); Dimension buttonSize = new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT); getButtonUp().setBounds( transposer.t(new Rectangle(bounds.getTop() .getTranslated(-(buttonSize.width / 2), 0), buttonSize))); Rectangle r = new Rectangle(bounds.getBottom().getTranslated( -(buttonSize.width / 2), -buttonSize.height), buttonSize); getButtonDown().setBounds(transposer.t(r)); Rectangle trackBounds = bounds.getCropped(new Insets( buttonSize.height, 0, buttonSize.height, 0)); RangeModel model = scrollBar.getRangeModel(); getButtonUp() .setVisible(model.getValue() != model.getMinimum()); getButtonDown().setVisible( model.getValue() != model.getMaximum() - model.getExtent()); return trackBounds; } }); setPageUp(null); setPageDown(null); setThumb(null); setOpaque(false); }
/** * This is the method that does the actual layout. We don't want a * layout to occur when layout() is invoked, rather when something * changes in the shared RangeModel. * * @param force * if <code>true</code>, the contents will be resized and * revalidated; otherwise, just a repaint will occur. */ protected void doLayout(boolean force) { repaint(); /* * @TODO:Pratik It seems you don't really need this force argument. * Those that invoke doLayout(false) can invoke repaint() * themselves. doLayout() should just layout. */ if (force) { RangeModel rModel; if (horizontal) rModel = getHorizontalRangeModel(); else rModel = getVerticalRangeModel(); Rectangle contentBounds = Rectangle.SINGLETON; if (horizontal) { contentBounds.y = 0; contentBounds.x = rModel.getMinimum(); contentBounds.height = this.getContents() .getPreferredSize().height; contentBounds.width = rModel.getMaximum() - rModel.getMinimum(); } else { contentBounds.y = rModel.getMinimum(); contentBounds.x = 0; contentBounds.height = rModel.getMaximum() - rModel.getMinimum(); contentBounds.width = this.getContents().getPreferredSize().width; } if (!this.getContents().getBounds().equals(contentBounds)) { this.getContents().setBounds(contentBounds); this.getContents().revalidate(); } } }
/** * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */ public void propertyChange( PropertyChangeEvent event ) { if ( this.getContents( ) != null && event.getSource( ) instanceof RangeModel ) { String property = event.getPropertyName( ); doLayout( RangeModel.PROPERTY_MAXIMUM.equals( property ) || RangeModel.PROPERTY_MINIMUM.equals( property ) || RangeModel.PROPERTY_VALUE.equals( property ) ); } }
/** * @param model */ public RulerDefaultRangeModel( RangeModel model ) { assert model != null; this.delegate = model; delegate.addPropertyChangeListener( this ); }
public SecondaryRangeModel(RangeModel primaryRangeModel) { this.primaryRangeModel = primaryRangeModel; }
private RangeModel getHorizontalRangeModel() { return horzRangeModel; }
/** * This is the method that does the actual layout. We don't want a * layout to occur when layout() is invoked, rather when something * changes in the shared RangeModel. * * @param force * if <code>true</code>, the contents will be resized and * revalidated; otherwise, just a repaint will occur. */ protected void doLayout( boolean force ) { repaint( ); /* * @TODO:Pratik It seems you don't really need this force argument. * Those that invoke doLayout(false) can invoke repaint() * themselves. doLayout() should just layout. */ if ( force ) { RangeModel rModel; if ( horizontal ) rModel = getHorizontalRangeModel( ); else rModel = getVerticalRangeModel( ); Rectangle contentBounds = Rectangle.SINGLETON; if ( horizontal ) { contentBounds.y = 0; contentBounds.x = rModel.getMinimum( ); contentBounds.height = this.getContents( ) .getPreferredSize( ).height; contentBounds.width = rModel.getMaximum( ) - rModel.getMinimum( ); } else { contentBounds.y = rModel.getMinimum( ); contentBounds.x = 0; contentBounds.height = rModel.getMaximum( ) - rModel.getMinimum( ); contentBounds.width = this.getContents( ) .getPreferredSize( ).width; } if ( !this.getContents( ).getBounds( ).equals( contentBounds ) ) { this.getContents( ).setBounds( contentBounds ); this.getContents( ).revalidate( ); } } }