Java Code Examples for org.eclipse.swt.graphics.Rectangle

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project aws-toolkit-for-eclipse, under directory /com.amazonaws.eclipse.ec2/src/com/amazonaws/eclipse/ec2/ui/securitygroups/.

Source file: EditSecurityGroupPermissionEntryDialog.java

  22 
vote

@Override public void create(){
  super.create();
  Point p=portRangeComposite.computeSize(SWT.DEFAULT,SWT.DEFAULT);
  Rectangle r=userGroupComposite.getParent().getClientArea();
  if (r.width > p.x)   p.x=r.width;
  swappableComposite.setSize(p);
  portRangePermissionButton.setSelection(true);
  swappableComposite.setActiveComposite(portRangeComposite);
  getShell().layout();
  getShell().setSize(getShell().computeSize(SWT.DEFAULT,SWT.DEFAULT));
}
 

Example 2

From project bpelunit, under directory /tycho/net.bpelunit.framework.client.eclipse/src/net/bpelunit/framework/client/eclipse/views/.

Source file: BPELUnitProgressBar.java

  22 
vote

private void paintStep(int startX,int endX){
  GC gc=new GC(this);
  setStatusColor(gc);
  Rectangle rect=getClientArea();
  startX=Math.max(1,startX);
  gc.fillRectangle(startX,1,endX - startX,rect.height - 2);
  gc.dispose();
}
 

Example 3

From project bundlemaker, under directory /main/org.bundlemaker.core.ui/src/org/bundlemaker/core/ui/.

Source file: CenterImageLabelProvider.java

  22 
vote

@Override protected void paint(Event event,Object element){
  Image img=getImage(element);
  if (img != null) {
    Rectangle bounds=((TreeItem)event.item).getBounds(event.index);
    Rectangle imgBounds=img.getBounds();
    bounds.width/=2;
    bounds.width-=imgBounds.width / 2;
    bounds.height/=2;
    bounds.height-=imgBounds.height / 2;
    int x=bounds.width > 0 ? bounds.x + bounds.width : bounds.x;
    int y=bounds.height > 0 ? bounds.y + bounds.height : bounds.y;
    event.gc.drawImage(img,x,y);
  }
}
 

Example 4

From project ceylon-ide-eclipse, under directory /plugins/com.redhat.ceylon.eclipse.ui/src/com/redhat/ceylon/eclipse/code/hover/.

Source file: BrowserInformationControl.java

  22 
vote

public Rectangle computeTrim(){
  Rectangle trim=super.computeTrim();
  if (isResizable() && fgScrollBarSize != null) {
    boolean RTL=(getShell().getStyle() & SWT.RIGHT_TO_LEFT) != 0;
    if (RTL) {
      trim.x-=fgScrollBarSize.x;
    }
    trim.width+=fgScrollBarSize.x;
    trim.height+=fgScrollBarSize.y;
  }
  return trim;
}
 

Example 5

From project CIShell, under directory /clients/gui/org.cishell.reference.gui.guibuilder.swt/src/org/cishell/reference/gui/guibuilder/swt/builder/components/.

Source file: LabelingComponent.java

  22 
vote

/** 
 * Sets the location for a hovering shell.
 * @param descriptionShell the object that is to hover
 * @param position the position of a widget to hover over
 */
private void setHoverLocation(Shell descriptionShell,Point position){
  Rectangle displayBounds=descriptionShell.getDisplay().getBounds();
  Rectangle shellBounds=descriptionShell.getBounds();
  shellBounds.x=Math.max(Math.min(position.x + DESCRIPTION_SHELL_LEFT_MARGIN,displayBounds.width - shellBounds.width),0);
  shellBounds.y=Math.max(Math.min(position.y,displayBounds.height - shellBounds.height),0);
  descriptionShell.setBounds(shellBounds);
}
 

Example 6

From project dawn-isenciaui, under directory /com.isencia.passerelle.workbench.model.editor.ui/src/main/java/com/isencia/passerelle/workbench/model/editor/ui/cell/.

Source file: DialogBrowserEditor.java

  22 
vote

public void layout(Composite editor,boolean force){
  Rectangle bounds=editor.getClientArea();
  Point size=button.computeSize(SWT.DEFAULT,SWT.DEFAULT,force);
  if (text != null) {
    text.setBounds(0,0,bounds.width - size.x,bounds.height);
  }
  button.setBounds(bounds.width - size.x,0,size.x,bounds.height);
}
 

Example 7

From project dawn-ui, under directory /org.dawb.workbench.plotting/src/org/dawb/workbench/plotting/printing/.

Source file: PrintMargin.java

  22 
vote

/** 
 * Returns a PrintMargin object containing the true border margins for the specified printer with the given margin width (in inches) for each side.
 */
static PrintMargin getPrintMargin(Printer printer,double marginLeft,double marginRight,double marginTop,double marginBottom){
  Rectangle clientArea=printer.getClientArea();
  Rectangle trim=printer.computeTrim(0,0,0,0);
  Point dpi=printer.getDPI();
  int leftMargin=(int)(marginLeft * dpi.x) - trim.x;
  int rightMargin=clientArea.width + trim.width - (int)(marginRight * dpi.x) - trim.x;
  int topMargin=(int)(marginTop * dpi.y) - trim.y;
  int bottomMargin=clientArea.height + trim.height - (int)(marginBottom * dpi.y) - trim.y;
  return new PrintMargin(leftMargin,rightMargin,topMargin,bottomMargin);
}
 

Example 8

From project Diver, under directory /ca.uvic.chisel.widgets/src/ca/uvic/chisel/widgets/.

Source file: RangeSlider.java

  22 
vote

/** 
 */
protected void resetScale(){
  Rectangle bounds=getCanvas().getClientArea();
  int visualRangeSize=bounds.width - HANDLE_SIZE * 2;
  if (visualRangeSize < HANDLE_SIZE * 2) {
    scale=0;
  }
  scale=((double)visualRangeSize) / (getMaximum() - getMinimum());
  setVisualLow(toVisualValue(getSelectedMinimum()));
  setVisualHigh(toVisualValue(getSelectedMaximum()));
}
 

Example 9

From project dozer, under directory /eclipse-plugin/net.sf.dozer.eclipse.plugin/src/org/dozer/eclipse/plugin/editorpage/imagecombo/.

Source file: ImageCombo.java

  22 
vote

void internalLayout(boolean changed){
  if (isDropped())   dropDown(false);
  Rectangle rect=getClientArea();
  int width=rect.width;
  int height=rect.height;
  Point arrowSize=arrow.computeSize(SWT.DEFAULT,height,changed);
  text.setBounds(0,0,width - arrowSize.x,height);
  arrow.setBounds(width - arrowSize.x,0,arrowSize.x,arrowSize.y);
}
 

Example 10

From project Eclipse, under directory /com.mobilesorcery.sdk.testing/src/org/eclipse/jdt/internal/junit/ui/.

Source file: JUnitProgressBar.java

  22 
vote

private void paintStep(int startX,int endX){
  GC gc=new GC(this);
  setStatusColor(gc);
  Rectangle rect=getClientArea();
  startX=Math.max(1,startX);
  gc.fillRectangle(startX,1,endX - startX,rect.height - 2);
  gc.dispose();
}
 

Example 11

From project eclipse-instasearch, under directory /instasearch/src/it/unibz/instasearch/ui/.

Source file: DropdownMenuProvider.java

  22 
vote

/** 
 * Called when either the button itself or the dropdown arrow is clicked
 * @param event the event that trigged this call
 */
@Override public void widgetSelected(SelectionEvent event){
  ToolItem item=(ToolItem)event.widget;
  if (item != toolItem)   return;
  Rectangle rect=item.getBounds();
  Point pt=item.getParent().toDisplay(new Point(rect.x,rect.y));
  Menu menu=menuManager.createContextMenu(item.getParent());
  menu.setLocation(pt.x,pt.y + rect.height);
  menu.setVisible(true);
  if (event.detail != SWT.ARROW) {
  }
}
 

Example 12

From project eclipse-integration-cloudfoundry, under directory /org.cloudfoundry.ide.eclipse.server.ui/src/org/cloudfoundry/ide/eclipse/internal/server/ui/editor/.

Source file: ApplicationActionMenuControl.java

  22 
vote

protected void showViewMenu(MenuManager manager,ToolBar toolBar){
  if (!isVisible()) {
    return;
  }
  Menu menu=manager.createContextMenu(applicationActionButton);
  applicationActionButton.setMenu(menu);
  Rectangle bounds=toolBar.getBounds();
  Point topRight=new Point(bounds.x + bounds.x / 10,bounds.height);
  topRight=applicationActionButton.toDisplay(topRight);
  menu.setLocation(topRight.x,topRight.y);
  menu.setVisible(true);
}
 

Example 13

From project Eclipse-Terminal, under directory /com.randomwalking.swt.terminal.linux.gtk.x86/src/com/randomwalking/swt/terminal/.

Source file: Terminal.java

  22 
vote

protected void controlResized(ControlEvent e){
  checkWidget();
  final Rectangle rect=getClientArea();
  setBounds(rect.x,rect.y,rect.width,rect.height);
  OS.gtk_widget_set_size_request(terminalHandle,rect.width,rect.height);
}
 

Example 14

From project EMF-IncQuery, under directory /plugins/org.eclipse.viatra2.emf.incquery.tooling.gui/src/org/eclipse/viatra2/emf/incquery/queryexplorer/content/detail/.

Source file: ModelElementCellEditor.java

  22 
vote

public void layout(Composite editor,boolean force){
  Rectangle bounds=editor.getClientArea();
  Point dialogButtonSize=dialogButton.computeSize(SWT.DEFAULT,SWT.DEFAULT,force);
  Point clearButtonSize=clearButton.computeSize(SWT.DEFAULT,SWT.DEFAULT,force);
  if (contents != null) {
    contents.setBounds(0,0,bounds.width - dialogButtonSize.x - clearButtonSize.x,bounds.height);
  }
  clearButton.setBounds(bounds.width - dialogButtonSize.x - clearButtonSize.x,0,clearButtonSize.x,bounds.height);
  dialogButton.setBounds(bounds.width - dialogButtonSize.x,0,dialogButtonSize.x,bounds.height);
}
 

Example 15

From project flyingsaucer, under directory /flying-saucer-swt/src/main/java/org/xhtmlrenderer/swt/.

Source file: SWTFSImage.java

  22 
vote

public SWTFSImage(Image image,UserAgentCallback uac,String uri){
  _uac=uac;
  _uri=uri;
  _image=image;
  if (image != null) {
    Rectangle bounds=image.getBounds();
    _width=bounds.width;
    _height=bounds.height;
  }
 else {
    _width=10;
    _height=10;
  }
}
 

Example 16

From project Foglyn, under directory /com.foglyn.ui/src/com/foglyn/ui/.

Source file: FoglynFillWidthLayout.java

  22 
vote

@Override protected void layout(Composite composite,boolean flushCache){
  Rectangle area=composite.getClientArea();
  if (area.width == 0) {
    area.width=calculateWidthHint(composite);
  }
  area.x+=marginLeft;
  area.y+=marginTop;
  area.width-=(marginRight + marginLeft);
  area.height-=(marginBottom + marginTop);
  Control[] children=composite.getChildren();
  for (  Control control : children) {
    control.setBounds(area);
  }
}
 

Example 17

From project gda-common-rcp, under directory /uk.ac.gda.common.rcp/src/swing2swt/layout/.

Source file: FlowLayout.java

  22 
vote

private void alignCurrentLine(Rectangle clientArea,int lineWidth,int lineHeight){
  for (int j=0; j < currentLine.size(); j++) {
    Control c=currentLine.get(j);
    Rectangle bounds=c.getBounds();
    int x=bounds.x;
    if (align == CENTER)     x+=(clientArea.width - lineWidth) / 2;
 else     if (align == RIGHT)     x+=clientArea.width - lineWidth;
    int y=bounds.y + (lineHeight - bounds.height) / 2;
    c.setLocation(x,y);
  }
}
 

Example 18

From project gmc, under directory /src/org.gluster.storage.management.console/src/org/gluster/storage/management/console/utils/.

Source file: GUIHelper.java

  22 
vote

public void centerShellInScreen(Shell shell){
  Rectangle monitorBounds=shell.getMonitor().getBounds();
  Rectangle myBounds=shell.getBounds();
  int x=monitorBounds.x + (monitorBounds.width - myBounds.width) / 2;
  int y=monitorBounds.y + (monitorBounds.height - myBounds.height) / 2;
  shell.setLocation(x,y);
}
 

Example 19

From project grails-ide, under directory /org.grails.ide.eclipse.ui/src/org/grails/ide/eclipse/ui/internal/inplace/.

Source file: GrailsInplaceDialog.java

  22 
vote

private Point getDefaultLocation(Point initialSize){
  Rectangle monitorBounds=getMonitorBounds();
  Point centerPoint;
  if (parentShell != null) {
    centerPoint=Geometry.centerPoint(parentShell.getBounds());
  }
 else {
    centerPoint=Geometry.centerPoint(monitorBounds);
  }
  return new Point(centerPoint.x - (initialSize.x / 2),Math.max(monitorBounds.y,Math.min(centerPoint.y - (initialSize.y * 2 / 3),monitorBounds.y + monitorBounds.height - initialSize.y)));
}
 

Example 20

From project iee, under directory /org.eclipse.iee.sample.graph/src/org/jfree/experimental/chart/swt/.

Source file: ChartComposite.java

  22 
vote

/** 
 * Applies any scaling that is in effect for the chart drawing to the given rectangle.
 * @param rect  the rectangle.
 * @return A new scaled rectangle.
 */
public Rectangle scale(Rectangle2D rect){
  Rectangle insets=this.getClientArea();
  int x=(int)Math.round(rect.getX() * getScaleX()) + insets.x;
  int y=(int)Math.round(rect.getY() * this.getScaleY()) + insets.y;
  int w=(int)Math.round(rect.getWidth() * this.getScaleX());
  int h=(int)Math.round(rect.getHeight() * this.getScaleY());
  return new Rectangle(x,y,w,h);
}
 

Example 21

From project incubator, under directory /net.karlmartens.ui/src/net/karlmartens/ui/viewer/.

Source file: TimeSeriesTableViewer.java

  22 
vote

private void handleKeyPressed(Event e){
  if (!_navigationStrategy.isNavigationEvent(e) && !_navigationStrategy.isExpandEvent(e) && !_navigationStrategy.isSelectAllEvent(e))   return;
  final Rectangle rect=_table.getVisibleScrollableCells();
  _scroll.setSelection(rect.x - _table.getFixedColumnCount());
  final TableColumn column=_table.getColumn(rect.x);
  _scroll.setLabel(column.getText());
  updateHighlights();
}
 

Example 22

From project interactive-self-assessment, under directory /editbox/src/pm/eclipse/editbox/impl/.

Source file: BoxDecoratorImpl.java

  22 
vote

protected Collection<Box> visibleBoxes(){
  Rectangle r0=boxText.getClientArea();
  int start=boxText.getHorizontalIndex() + boxText.getOffsetAtLine(boxText.getTopIndex());
  int end=boxText.getCharCount() - 1;
  int lineIndex=boxText.getLineIndex(r0.height);
  if (lineIndex < boxText.getLineCount() - 1)   end=boxText.getOffsetAtLine(lineIndex);
  List<Box> result=new ArrayList<Box>();
  for (  Box b : boxes)   if (b.intersects(start,end))   result.add(b);
  calcBounds(result);
  return result;
}
 

Example 23

From project JGit, under directory /org.spearce.egit.ui/src/org/spearce/egit/ui/internal/components/.

Source file: CenteredImageLabelProvider.java

  22 
vote

@Override protected void paint(final Event event,final Object element){
  final Image image=getImage(element);
  final Rectangle bounds=((TableItem)event.item).getBounds(event.index);
  final Rectangle imgBounds=image.getBounds();
  bounds.width/=2;
  bounds.width-=imgBounds.width / 2;
  bounds.height/=2;
  bounds.height-=imgBounds.height / 2;
  final int x=bounds.width > 0 ? bounds.x + bounds.width : bounds.x;
  final int y=bounds.height > 0 ? bounds.y + bounds.height : bounds.y;
  event.gc.drawImage(image,x,y);
}
 

Example 24

From project JsTestDriver, under directory /eclipse-plugin/plugins/com.google.eclipse.javascript.jstestdriver.ui/src/com/google/eclipse/javascript/jstestdriver/ui/view/.

Source file: TestResultProgressBar.java

  22 
vote

private void paint(PaintEvent e){
  GC gc=e.gc;
  Display display=getDisplay();
  Rectangle rectangle=getClientArea();
  gc.fillRectangle(rectangle);
  drawBorder(gc,rectangle.x,rectangle.y,rectangle.width - 1,rectangle.height - 1,display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
  gc.setBackground(currentColor);
  barWidth=Math.min(rectangle.width - 2,barWidth);
  gc.fillRectangle(1,1,barWidth,rectangle.height - 2);
}
 

Example 25

From project mylyn.context, under directory /org.eclipse.mylyn.context.ui/src/org/eclipse/mylyn/internal/context/ui/.

Source file: FilteredChildrenDecorationDrawer.java

  22 
vote

private void redrawTree(TreeItem item){
  if (viewer.getTree() != null && !viewer.getTree().isDisposed()) {
    if (item != null && !item.isDisposed()) {
      Rectangle bounds=item.getBounds();
      Rectangle treeBounds=viewer.getTree().getBounds();
      viewer.getTree().redraw(0,bounds.y,treeBounds.width,bounds.height,true);
    }
 else {
      viewer.getTree().redraw();
    }
  }
}
 

Example 26

From project mylyn.docs, under directory /org.eclipse.mylyn.wikitext.ui/src/org/eclipse/mylyn/internal/wikitext/ui/viewer/.

Source file: ImageManager.java

  22 
vote

/** 
 * get the widget-relative region of the given annotation
 * @return the region, or null if it is unknown
 */
private Rectangle getRegion(ImageAnnotation annotation){
  if (annotation.getImage() == null) {
    return null;
  }
  Position position=viewer.getAnnotationModel().getPosition(annotation);
  Point locationAtOffset=viewer.getTextWidget().getLocationAtOffset(position.offset);
  Rectangle bounds=annotation.getImage().getBounds();
  Rectangle rectange=new Rectangle(locationAtOffset.x,locationAtOffset.y,bounds.width,bounds.height);
  return rectange;
}
 

Example 27

From project mylyn.incubator, under directory /org.eclipse.mylyn.sandbox.ui/src/org/eclipse/mylyn/internal/sandbox/ui/views/.

Source file: ActiveSearchQuickView.java

  22 
vote

private void showViewMenu(){
  isDeactivateListenerActive=false;
  Menu aMenu=getViewMenuManager().createContextMenu(dialogShell);
  Rectangle toolbarBounds=toolBar.getBounds();
  Point topLeft=new Point(toolbarBounds.x,toolbarBounds.y + toolbarBounds.height);
  topLeft=dialogShell.toDisplay(topLeft);
  aMenu.setLocation(topLeft.x,topLeft.y);
  aMenu.setVisible(true);
}
 

Example 28

From project netifera, under directory /platform/com.netifera.platform.ui/com.netifera.platform.ui/src/com/netifera/platform/ui/forms/.

Source file: NetiferaExpand.java

  22 
vote

/** 
 * Computes the size of the expandable composite.
 * @see org.eclipse.swt.widgets.Composite#computeSize
 */
public Point computeSize(int wHint,int hHint,boolean changed){
  checkWidget();
  Point size;
  ExpandableLayout layout=(ExpandableLayout)getLayout();
  if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
    size=layout.computeSize(this,wHint,hHint,changed);
  }
 else {
    size=new Point(wHint,hHint);
  }
  Rectangle trim=computeTrim(0,0,size.x,size.y);
  return new Point(trim.width,trim.height);
}
 

Example 29

From project Archimedes, under directory /br.org.archimedes.core/src/br/org/archimedes/gui/model/.

Source file: MouseMoveHandler.java

  21 
vote

/** 
 * This method receives the mouse move event from the current Canvas, and sends to the observers the normalized point.
 * @param event The mouse event received
 */
public void receiveMouseMove(MouseEvent event){
  Point point;
  Canvas canvas=(Canvas)event.getSource();
  Rectangle rect=canvas.getClientArea();
  double x=(double)event.x;
  double y=(double)event.y;
  point=new Point(x - rect.width / 2,(rect.height - y) - rect.height / 2);
  Workspace workspace=br.org.archimedes.Utils.getWorkspace();
  try {
    point=workspace.screenToModel(point);
  }
 catch (  NullArgumentException e) {
    e.printStackTrace();
  }
  workspace.setMousePosition(point);
  setChanged();
  notifyObservers(point);
}
 

Example 30

From project Bio-PEPA, under directory /uk.ac.ed.inf.common.ui.plotting/src/uk/ac/ed/inf/common/ui/plotting/dialogs/.

Source file: ChartCanvas.java

  21 
vote

/** 
 * Constructs one canvas containing chart.
 * @param parent a composite control which will be the parent of the new instance (cannot be null)
 * @param style the style of control to construct
 */
public ChartCanvas(IChart chart,Composite parent,int style){
  super(parent,style);
  try {
    PluginSettings ps=PluginSettings.instance();
    render=ps.getDevice("dv.SWT");
  }
 catch (  ChartException ex) {
    ex.printStackTrace();
  }
  addPaintListener(new PaintListener(){
    public void paintControl(    PaintEvent e){
      Composite co=(Composite)e.getSource();
      final Rectangle rect=co.getClientArea();
      if (cachedImage == null) {
        buildChart(rect);
        drawToCachedImage(rect);
      }
      e.gc.drawImage(cachedImage,0,0,cachedImage.getBounds().width,cachedImage.getBounds().height,0,0,rect.width,rect.height);
    }
  }
);
  addControlListener(new ControlAdapter(){
    public void controlResized(    ControlEvent e){
      Composite co=(Composite)e.getSource();
      final Rectangle rect=co.getClientArea();
      buildChart(rect);
      cachedImage=null;
    }
  }
);
  setChart(((CommonChart)chart).getBirtChart());
}
 

Example 31

From project bioclipse.seneca, under directory /plugins/net.bioclipse.seneca/src/net/bioclipse/seneca/structgen/.

Source file: AnnealingLogPane.java

  21 
vote

public Image paintToImage(){
  Display display=getDisplay();
  Rectangle r=getBounds();
  Image image=new Image(display,r);
  GC gc=new GC(image);
  gc.setBackground(this.backgroundColor);
  gc.fillRectangle(r);
  gc.setForeground(this.gridColor);
  gc.drawRectangle(BORDER_WIDTH,BORDER_WIDTH,r.width - 2 * BORDER_WIDTH,r.height - 2 * BORDER_WIDTH);
  int lowerline=PREF_HEIGHT - BORDER_WIDTH + TICK_LENGTH;
  for (int w=BORDER_WIDTH; w < PREF_WIDTH; w+=xScale) {
    gc.drawLine(w,BORDER_WIDTH,w,lowerline);
  }
  int leftline=BORDER_WIDTH - TICK_LENGTH;
  for (int h=BORDER_WIDTH; h < PREF_WIDTH; h+=yScale) {
    gc.drawLine(leftline,h,PREF_WIDTH - BORDER_WIDTH,h);
  }
  AnnealingGraph.Point last=graph.createPoint(0,0);
  for (  AnnealingGraph.Point p : graph) {
    int h=PREF_HEIGHT * (PREF_WIDTH / PREF_HEIGHT);
    Color currentColor=colorRamp(display,h - p.x,0,h);
    gc.setForeground(currentColor);
    gc.drawLine(last.x + BORDER_WIDTH,last.y + BORDER_WIDTH,p.x + BORDER_WIDTH,p.y + BORDER_WIDTH);
    last=p;
    currentColor.dispose();
  }
  gc.dispose();
  return image;
}
 

Example 32

From project dawn-product, under directory /org.dawb.workbench.application/src/com/swtdesigner/.

Source file: SWTResourceManager.java

  21 
vote

/** 
 * Returns an  {@link Image} composed of a base image decorated by another image.
 * @param baseImage the base  {@link Image} that should be decorated
 * @param decorator the  {@link Image} to decorate the base image
 * @param corner the corner to place decorator image
 * @return the resulting decorated {@link Image}
 */
public static Image decorateImage(final Image baseImage,final Image decorator,final int corner){
  if (corner <= 0 || corner >= LAST_CORNER_KEY) {
    throw new IllegalArgumentException("Wrong decorate corner");
  }
  Map<Image,Map<Image,Image>> cornerDecoratedImageMap=m_decoratedImageMap[corner];
  if (cornerDecoratedImageMap == null) {
    cornerDecoratedImageMap=new HashMap<Image,Map<Image,Image>>();
    m_decoratedImageMap[corner]=cornerDecoratedImageMap;
  }
  Map<Image,Image> decoratedMap=cornerDecoratedImageMap.get(baseImage);
  if (decoratedMap == null) {
    decoratedMap=new HashMap<Image,Image>();
    cornerDecoratedImageMap.put(baseImage,decoratedMap);
  }
  Image result=decoratedMap.get(decorator);
  if (result == null) {
    Rectangle bib=baseImage.getBounds();
    Rectangle dib=decorator.getBounds();
    result=new Image(Display.getCurrent(),bib.width,bib.height);
    GC gc=new GC(result);
    gc.drawImage(baseImage,0,0);
    if (corner == TOP_LEFT) {
      gc.drawImage(decorator,0,0);
    }
 else     if (corner == TOP_RIGHT) {
      gc.drawImage(decorator,bib.width - dib.width,0);
    }
 else     if (corner == BOTTOM_LEFT) {
      gc.drawImage(decorator,0,bib.height - dib.height);
    }
 else     if (corner == BOTTOM_RIGHT) {
      gc.drawImage(decorator,bib.width - dib.width,bib.height - dib.height);
    }
    gc.dispose();
    decoratedMap.put(decorator,result);
  }
  return result;
}
 

Example 33

From project dawn-third, under directory /org.dawb.org.csstudio.swt.xygraph/src/org/csstudio/swt/xygraph/toolbar/.

Source file: XYGraphToolbar.java

  21 
vote

protected void addSnapshotButton(){
  Button snapShotButton=new Button(createImage("icons/camera.gif"));
  snapShotButton.setToolTip(new Label("Print scaled image to printer"));
  addButton(snapShotButton);
  snapShotButton.addActionListener(new ActionListener(){
    public void actionPerformed(    ActionEvent event){
      PrintDialog dialog=new PrintDialog(Display.getCurrent().getActiveShell(),SWT.NULL);
      PrinterData printerData=dialog.open();
      printerData.orientation=PrinterData.LANDSCAPE;
      if (printerData != null) {
        Printer printer=new Printer(printerData);
        Point screenDPI=Display.getCurrent().getDPI();
        Point printerDPI=printer.getDPI();
        int scaleFactorX=printerDPI.x / screenDPI.x;
        Rectangle size=printer.getClientArea();
        Rectangle trim=printer.computeTrim(0,0,0,0);
        Rectangle imageSize=new Rectangle(size.x / scaleFactorX,size.y / scaleFactorX,size.width / scaleFactorX,size.height / scaleFactorX);
        if (printer.startJob("Print Plot")) {
          if (printer.startPage()) {
            GC gc=new GC(printer);
            Image xyImage=xyGraph.getImage(imageSize);
            Image printerImage=new Image(printer,xyImage.getImageData());
            xyImage.dispose();
            gc.drawImage(printerImage,imageSize.x,imageSize.y,imageSize.width,imageSize.height,-trim.x,-trim.y,size.width - trim.width,size.height - trim.height);
            printerImage.dispose();
            gc.dispose();
            printer.endPage();
          }
        }
        printer.endJob();
        printer.dispose();
      }
    }
  }
);
}
 

Example 34

From project dawn-workflow, under directory /org.dawb.passerelle.actors/src/org/dawb/passerelle/editors/.

Source file: VariablePainter.java

  21 
vote

/** 
 * Highlights the given widget				deactivate(true); return; region.
 * @param gc the GC to draw into
 * @param offset the offset of the widget region
 * @param length the length of the widget region
 */
private void draw(GC gc,int offset,int length,final Color fore){
  if (gc != null) {
    Rectangle bounds;
    if (length > 0)     bounds=fTextWidget.getTextBounds(offset,offset + length - 1);
 else {
      Point loc=fTextWidget.getLocationAtOffset(offset);
      bounds=new Rectangle(loc.x,loc.y,1,fTextWidget.getLineHeight(offset));
    }
    gc.setBackground(backColor);
    gc.fillRectangle(bounds.x,bounds.y,bounds.width - 1,bounds.height - 1);
    gc.setForeground(fore);
    gc.drawText(fTextWidget.getText(offset,offset + length - 1),bounds.x,bounds.y);
  }
 else {
    fTextWidget.redrawRange(offset,length,true);
  }
}
 

Example 35

From project droolsjbpm-tools, under directory /drools-eclipse/org.drools.eclipse/src/main/java/org/drools/eclipse/flow/ruleflow/view/property/metadata/.

Source file: MetaDataDialog.java

  21 
vote

private int getSelectedColumn(int x,int y){
  int columnToEdit=-1;
  int columns=table.getColumnCount();
  if (table.getSelection().length == 0) {
    return -1;
  }
  for (int i=0; i < columns; i++) {
    Rectangle bounds=table.getSelection()[0].getBounds(i);
    if (bounds.contains(x,y)) {
      columnToEdit=i;
      break;
    }
  }
  return columnToEdit;
}
 

Example 36

From project e4-rendering, under directory /com.toedter.e4.ui.workbench.swt/src/com/toedter/e4/ui/workbench/swt/layouts/.

Source file: SimpleTrimLayout.java

  21 
vote

@Override protected void layout(Composite composite,boolean flushCache){
  Rectangle clientArea=composite.getClientArea();
  Control[] children=composite.getChildren();
  for (  Control child : children) {
    try {
switch ((Position)child.getLayoutData()) {
case TOP:
        child.setBounds(clientArea.x,clientArea.y,clientArea.width,getHeight(TOP));
      break;
case LEFT:
    child.setBounds(clientArea.x,clientArea.y + getHeight(TOP),getWidth(LEFT),clientArea.height - getHeight(TOP) - getHeight(BOTTOM));
  break;
case RIGHT:
child.setBounds(clientArea.width - getWidth(RIGHT),clientArea.y + getHeight(TOP),getWidth(RIGHT),clientArea.height - getHeight(TOP) - getHeight(BOTTOM));
break;
case BOTTOM:
child.setBounds(clientArea.x,clientArea.y + clientArea.height - getHeight(BOTTOM),clientArea.width,getHeight(BOTTOM));
break;
case CENTER:
child.setBounds(clientArea.x + getWidth(LEFT),clientArea.y + getHeight(TOP),clientArea.width - getWidth(LEFT) - getWidth(RIGHT),clientArea.height - getHeight(TOP) - getHeight(BOTTOM));
break;
default :
break;
}
}
 catch (Exception e) {
System.err.println("Children of a composite with SimpleTrimLayout need layout data like SimpleTrimLayout.TOP, .LEFT, .CENTER, .RIGHT, or .BOTTOM");
}
}
}
 

Example 37

From project eclim, under directory /org.eclim.vimplugin/java/org/vimplugin/editors/.

Source file: VimEditor.java

  21 
vote

/** 
 * Sets focus (brings to top in Vim) to the buffer.. this function will be called when user activates this editor window
 */
@Override public void setFocus(){
  if (alreadyClosed) {
    getSite().getPage().closeEditor(this,false);
    return;
  }
  if (embedded) {
    parent.setFocus();
  }
  VimPlugin plugin=VimPlugin.getDefault();
  VimConnection conn=plugin.getVimserver(serverID).getVc();
  try {
    String cursor=conn.function(bufferID,"getCursor","");
    if (cursor == null) {
      return;
    }
  }
 catch (  IOException ioe) {
    logger.error("Unable to get cursor position.",ioe);
  }
  conn.command(bufferID,"raise","");
  if (embedded && parent.getDisplay().getActiveShell() != null) {
    boolean autoClickFocus=plugin.getPreferenceStore().getBoolean(PreferenceConstants.P_FOCUS_AUTO_CLICK);
    if (autoClickFocus) {
      Rectangle bounds=parent.getBounds();
      final Point point=parent.toDisplay(bounds.x + 5,bounds.y + bounds.height - 25);
      new Thread(){
        public void run(){
          DisplayUtils.doClick(parent.getDisplay(),point.x,point.y,true);
        }
      }
.start();
    }
  }
}
 

Example 38

From project eclipse-integration-commons, under directory /org.springsource.ide.eclipse.commons.frameworks.ui/src/org/springsource/ide/eclipse/commons/frameworks/ui/internal/contentassist/.

Source file: ContentProposalAdapter.java

  21 
vote

protected void adjustBounds(){
  Rectangle parentBounds=getParentShell().getBounds();
  Rectangle proposedBounds;
  Rectangle rightProposedBounds=new Rectangle(parentBounds.x + parentBounds.width + PopupDialog.POPUP_HORIZONTALSPACING,parentBounds.y + PopupDialog.POPUP_VERTICALSPACING,parentBounds.width,parentBounds.height);
  rightProposedBounds=getConstrainedShellBounds(rightProposedBounds);
  if (rightProposedBounds.intersects(parentBounds)) {
    Rectangle leftProposedBounds=new Rectangle(parentBounds.x - parentBounds.width - POPUP_HORIZONTALSPACING- 1,parentBounds.y,parentBounds.width,parentBounds.height);
    leftProposedBounds=getConstrainedShellBounds(leftProposedBounds);
    if (leftProposedBounds.intersects(parentBounds)) {
      if (rightProposedBounds.x - parentBounds.x >= parentBounds.x - leftProposedBounds.x) {
        rightProposedBounds.x=parentBounds.x + parentBounds.width + PopupDialog.POPUP_HORIZONTALSPACING;
        proposedBounds=rightProposedBounds;
      }
 else {
        leftProposedBounds.width=parentBounds.x - POPUP_HORIZONTALSPACING - leftProposedBounds.x;
        proposedBounds=leftProposedBounds;
      }
    }
 else {
      proposedBounds=leftProposedBounds;
    }
  }
 else {
    proposedBounds=rightProposedBounds;
  }
  getShell().setBounds(proposedBounds);
}
 

Example 39

From project egit-github, under directory /org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/.

Source file: AvatarStore.java

  21 
vote

/** 
 * Get scaled image
 * @param size
 * @param data
 * @return image data scaled to specified size
 */
public Image getScaledImage(int size,ImageData data){
  Display display=PlatformUI.getWorkbench().getDisplay();
  Image image=new Image(display,data);
  Rectangle sourceBounds=image.getBounds();
  if (sourceBounds.width == size)   return image;
  Image scaled=new Image(display,size,size);
  GC gc=new GC(scaled);
  try {
    gc.setAntialias(SWT.ON);
    gc.setInterpolation(SWT.HIGH);
    Rectangle targetBounds=scaled.getBounds();
    gc.drawImage(image,0,0,sourceBounds.width,sourceBounds.height,0,0,targetBounds.width,targetBounds.height);
  }
  finally {
    gc.dispose();
    image.dispose();
  }
  return scaled;
}
 

Example 40

From project koneki.ldt, under directory /plugins/org.eclipse.koneki.ldt.branding/src/org/eclipse/koneki/ldt/branding/splash/internal/.

Source file: SplashHandler.java

  21 
vote

public void init(Shell splash){
  super.init(splash);
  String progressRectString=null;
  String messageRectString=null;
  String foregroundColorString=null;
  IProduct product=Platform.getProduct();
  if (product != null) {
    progressRectString=product.getProperty(IProductConstants.STARTUP_PROGRESS_RECT);
    messageRectString=product.getProperty(IProductConstants.STARTUP_MESSAGE_RECT);
    foregroundColorString=product.getProperty(IProductConstants.STARTUP_FOREGROUND_COLOR);
  }
  Rectangle messageRect=StringConverter.asRectangle(messageRectString,DEFAULT_MESSAGE_RECT);
  setMessageRect(messageRect);
  Rectangle progressRect=StringConverter.asRectangle(progressRectString,DEFAULT_PROGRESS_RECT);
  setProgressRect(progressRect);
  int foregroundColorInteger;
  try {
    foregroundColorInteger=Integer.parseInt(foregroundColorString,16);
  }
 catch (  NumberFormatException ex) {
    foregroundColorInteger=DEFAULT_FOREGROUND_COLOR;
  }
  setForeground(new RGB((foregroundColorInteger & 0xFF0000) >> 16,(foregroundColorInteger & 0xFF00) >> 8,foregroundColorInteger & 0xFF));
  String version=System.getProperty(Activator.PRODUCT_VERSION_PROPERTY);
  int lastIndexOf=version.lastIndexOf('.');
  if (lastIndexOf != -1)   version=version.substring(0,lastIndexOf);
  final String buildId="Version: " + version;
  final Point position=new Point(280,150);
  font=new Font(Display.getDefault(),new FontData("Helvetica",(Platform.getOS().equals(Platform.OS_MACOSX) ? 9 : 7),SWT.BOLD));
  getContent().addPaintListener(new PaintListener(){
    public void paintControl(    PaintEvent e){
      e.gc.setForeground(getForeground());
      e.gc.setFont(font);
      e.gc.drawText(buildId,position.x,position.y,true);
    }
  }
);
}
 

Example 41

From project Krypsis, under directory /Symbian/src/org/krypsis/symbian/command/photo/.

Source file: PhotoApplication.java

  21 
vote

/** 
 * Initializes the camera application.
 */
private void init(){
  final Display display=Display.getDefault();
  this.shell=new Shell(display.getActiveShell());
  shell.open();
  Command exitCommand=new Command(shell,Command.EXIT,0);
  exitCommand.setText("Exit");
  exitCommand.addSelectionListener(this);
  this.takePictureCommand=new Command(shell,Command.GENERAL,10);
  takePictureCommand.setText("Snap!");
  takePictureCommand.addSelectionListener(this);
  takePictureCommand.setDefaultCommand();
  Player player=null;
  try {
    player=Manager.createPlayer("capture://video");
    player.realize();
    this.videoControl=(VideoControl)player.getControl("VideoControl");
    Control vControl=(Control)videoControl.initDisplayMode(VideoControl.USE_GUI_PRIMITIVE,Control.class.getName());
    vControl.setParent(shell);
    Rectangle r=vControl.getBounds();
    videoControl.setDisplaySize(r.width,r.height);
    videoControl.setVisible(true);
    player.start();
  }
 catch (  Exception e) {
    logger.error("Could not start capturing picture: " + e);
    getPhotoListener().onError(ErrorResponse.CAPABILITY_NOT_SUPPORTED);
    shell.dispose();
  }
  while (!shell.isDisposed()) {
    if (!display.readAndDispatch()) {
      display.sleep();
    }
  }
  if (player != null) {
    player.deallocate();
    player.close();
  }
}
 

Example 42

From project m2eclipse-hudson, under directory /org.sonatype.m2e.hudson.ui/src/main/java/com/sonatype/buildserver/eclipse/ui/.

Source file: JobPopup.java

  21 
vote

/** 
 * (non-Javadoc)
 * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point)
 */
protected Point getInitialLocation(Point initialSize){
  Shell parent=getParentShell();
  Point parentSize, parentLocation;
  if (parent != null) {
    parentSize=parent.getSize();
    parentLocation=parent.getLocation();
  }
 else {
    Rectangle bounds=getShell().getDisplay().getBounds();
    parentSize=new Point(bounds.width,bounds.height);
    parentLocation=new Point(0,0);
  }
  Point point=label.getLabel().toDisplay(new Point(0,0));
  int x=parentSize.x - initialSize.x + parentLocation.x - POPUP_OFFSET;
  int y=parentSize.y - initialSize.y + parentLocation.y - POPUP_OFFSET;
  if (x > point.x) {
    x=point.x;
  }
  if (y > point.y - initialSize.y) {
    y=point.y - initialSize.y;
  }
  return new Point(x,y);
}
 

Example 43

From project mylyn.builds, under directory /org.eclipse.mylyn.builds.ui/src/org/eclipse/mylyn/internal/builds/ui/editor/.

Source file: BuildEditorPage.java

  21 
vote

/** 
 * Force a re-layout of entire form.
 */
public void reflow(){
  if (reflow) {
    ScrolledForm form=getManagedForm().getForm();
    try {
      form.setRedraw(false);
      Rectangle parentClientArea=form.getParent().getClientArea();
      Point formSize=form.getSize();
      if (formSize.x != parentClientArea.width) {
        ScrollBar verticalBar=form.getVerticalBar();
        int verticalBarWidth=verticalBar != null ? verticalBar.getSize().x : 15;
        form.setSize(parentClientArea.width - verticalBarWidth,formSize.y);
      }
      form.layout(true,false);
      form.reflow(true);
    }
  finally {
      form.setRedraw(true);
    }
  }
}
 

Example 44

From project Newsreader, under directory /bundles/org.eclipse.ecf.salvo.ui/src/org/eclipse/ecf/salvo/ui/internal/editor/.

Source file: ArticlePanel.java

  21 
vote

public void paintControl(PaintEvent e){
  if (tree.getTopItem() == null)   return;
  try {
    sideTable.setVisible(false);
    int itemHeight=tree.getItemHeight();
    Rectangle clientArea=tree.getClientArea();
    int offset=tree.getTopItem().getBounds().y;
    int counter=0;
    while (true) {
      Point point=new Point(0,counter++ * itemHeight);
      TreeItem itemd=null;
      if (clientArea.height > point.y)       itemd=tree.getItem(new Point(0,point.y + offset));
      if (itemd == null || itemd.getData() == null)       return;
      IArticle article=(IArticle)((ISalvoResource)itemd.getData()).getObject();
      sideTable.setItemCount(counter);
      sideTable.getItem(counter - 1).setImage(1,getImage(article,1));
      sideTable.getItem(counter - 1).setImage(2,getImage(article,2));
    }
  }
  finally {
    sideTable.pack();
    sideTable.setVisible(true);
  }
}
 

Example 45

From project dawn-common, under directory /org.dawb.common.ui/src/org/dawb/common/ui/image/.

Source file: IconUtils.java

  20 
vote

public static ImageDescriptor createIconDescriptor(String iconText){
  final ImageData data=new ImageData(16,16,8,PaletteFactory.makeGrayScalePalette());
  final Image image=new Image(Display.getCurrent(),data);
  final GC gc=new GC(image);
  gc.setForeground(ColorConstants.white);
  gc.fillRectangle(new Rectangle(0,0,16,16));
  gc.setForeground(ColorConstants.darkGray);
  gc.setFont(new Font(Display.getCurrent(),new FontData("Dialog",6,SWT.BOLD)));
  gc.drawText(iconText,4,2);
  gc.dispose();
  return new ImageDescriptor(){
    @Override public ImageData getImageData(){
      return image.getImageData();
    }
  }
;
}
 

Example 46

From project org.openscada.dakara, under directory /org.openscada.vi.ui.draw2d/src/org/openscada/vi/ui/draw2d/.

Source file: VisualInterfaceViewer.java

  19 
vote

protected void handleResize(final Rectangle bounds){
  if (!isZooming()) {
    setZoom(1.0);
    return;
  }
  final Dimension prefSize=getPreferredSize(bounds);
  final double ar=prefSize.preciseWidth() / prefSize.preciseHeight();
  double newHeight=bounds.width / ar;
  final double zoom;
  if (newHeight > bounds.height) {
    newHeight=bounds.height;
  }
  zoom=newHeight / prefSize.preciseHeight();
  setZoom(zoom);
}