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

The following are top voted examples for showing how to use org.eclipse.swt.graphics.Rectangle. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: n4js   File: TypeInformationPopup.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the initial location to use for the shell based upon the current selection in the viewer. Bottom is
 * preferred to top, and right is preferred to left, therefore if possible the popup will be located below and to
 * the right of the selection.
 *
 * @param initialSize
 *            the initial size of the shell, as returned by {@code getInitialSize}.
 * @return the initial location of the shell
 */
@Override
protected Point getInitialLocation(final Point initialSize) {
	if (null == anchor) {
		return super.getInitialLocation(initialSize);
	}

	final Point point = anchor;
	final Rectangle monitor = getShell().getMonitor().getClientArea();
	if (monitor.width < point.x + initialSize.x) {
		point.x = max(0, point.x - initialSize.x);
	}
	if (monitor.height < point.y + initialSize.y) {
		point.y = max(0, point.y - initialSize.y);
	}

	return point;
}
 
Example 2
Project: n4js   File: UIUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Given the desired position of the shell, this method returns an adjusted position such that the window is no
 * larger than its monitor, and does not extend beyond the edge of the monitor. This is used for computing the
 * initial window position via the parent shell, clients can use this as a utility method if they want to limit the
 * region in which the window may be moved.
 *
 * @param shell
 *            the shell which shell bounds is being calculated.
 * @param preferredSize
 *            the preferred position of the window.
 * @return a rectangle as close as possible to preferredSize that does not extend outside the monitor.
 */
public static Rectangle getConstrainedShellBounds(final Shell shell, final Point preferredSize) {

	final Point location = getInitialLocation(shell, preferredSize);
	final Rectangle result = new Rectangle(location.x, location.y, preferredSize.x, preferredSize.y);

	final Monitor monitor = getClosestMonitor(shell.getDisplay(), Geometry.centerPoint(result));

	final Rectangle bounds = monitor.getClientArea();

	if (result.height > bounds.height) {
		result.height = bounds.height;
	}

	if (result.width > bounds.width) {
		result.width = bounds.width;
	}

	result.x = Math.max(bounds.x, Math.min(result.x, bounds.x
			+ bounds.width - result.width));
	result.y = Math.max(bounds.y, Math.min(result.y, bounds.y
			+ bounds.height - result.height));

	return result;
}
 
Example 3
Project: n4js   File: UIUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the monitor whose client area contains the given point. If no monitor contains the point, returns the
 * monitor that is closest to the point.
 *
 * @param toSearch
 *            point to find (display coordinates).
 * @param toFind
 *            point to find (display coordinates).
 * @return the monitor closest to the given point.
 */
private static Monitor getClosestMonitor(final Display toSearch, final Point toFind) {
	int closest = Integer.MAX_VALUE;

	final Monitor[] monitors = toSearch.getMonitors();
	Monitor result = monitors[0];

	for (int index = 0; index < monitors.length; index++) {
		final Monitor current = monitors[index];

		final Rectangle clientArea = current.getClientArea();

		if (clientArea.contains(toFind)) {
			return current;
		}

		final int distance = Geometry.distanceSquared(Geometry.centerPoint(clientArea), toFind);
		if (distance < closest) {
			closest = distance;
			result = current;
		}
	}

	return result;
}
 
Example 4
Project: parabuild-ci   File: ChartComposite.java   Source Code and License 6 votes vote down vote up
/**
 * Returns the data area (the area inside the axes) for the plot or subplot,
 * with the current scaling applied.
 *
 * @param x  the x-coordinate (for subplot selection).
 * @param y  the y-coordinate (for subplot selection).
 * 
 * @return The scaled data area.
 */
public Rectangle getScreenDataArea(int x, int y) {
    PlotRenderingInfo plotInfo = this.info.getPlotInfo();
    Rectangle result;
    if (plotInfo.getSubplotCount() == 0)
        result = getScreenDataArea();
    else {
        // get the origin of the zoom selection in the Java2D space used for
        // drawing the chart (that is, before any scaling to fit the panel)
        Point2D selectOrigin = translateScreenToJava2D(new Point(x, y));
        int subplotIndex = plotInfo.getSubplotIndex(selectOrigin);
        if (subplotIndex == -1) {
            return null;
        }
        result = scale(plotInfo.getSubplotInfo(subplotIndex).getDataArea());
    }
    return result;
}
 
Example 5
Project: BiglyBT   File: ViewUtils.java   Source Code and License 6 votes vote down vote up
public static void setViewRequiresOneDownload(Composite genComposite) {
	if (genComposite == null || genComposite.isDisposed()) {
		return;
	}
	Utils.disposeComposite(genComposite, false);

	Label lab = new Label(genComposite, SWT.NULL);
	GridData gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true);
	gridData.verticalIndent = 10;
	lab.setLayoutData(gridData);
	Messages.setLanguageText(lab, "view.one.download.only");

	genComposite.layout(true);

	Composite parent = genComposite.getParent();
	if (parent instanceof ScrolledComposite) {
		ScrolledComposite scrolled_comp = (ScrolledComposite) parent;

		Rectangle r = scrolled_comp.getClientArea();
		scrolled_comp.setMinSize(genComposite.computeSize(r.width, SWT.DEFAULT ));
	}

}
 
Example 6
Project: BiglyBT   File: ColumnThumbAndName.java   Source Code and License 6 votes vote down vote up
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
	if (event.eventType == TableCellMouseEvent.EVENT_MOUSEMOVE
			|| event.eventType == TableRowMouseEvent.EVENT_MOUSEDOWN) {
		TableRow row = event.cell.getTableRow();
		if (row == null) {
			return;
		}
		Object data = row.getData(ID_EXPANDOHITAREA);
		if (data instanceof Rectangle) {
			Rectangle hitArea = (Rectangle) data;
			boolean inExpando = hitArea.contains(event.x, event.y);

			if (event.eventType == TableCellMouseEvent.EVENT_MOUSEMOVE) {
				((TableCellCore) event.cell).setCursorID(inExpando ? SWT.CURSOR_HAND
						: SWT.CURSOR_ARROW);
			} else if (inExpando) { // mousedown
				if (row instanceof TableRowCore) {
					TableRowCore rowCore = (TableRowCore) row;
					rowCore.setExpanded(!rowCore.isExpanded());
				}
			}
		}
	}
}
 
Example 7
Project: gw4e.project   File: TableHelper.java   Source Code and License 6 votes vote down vote up
public static void handleEvent(Event event) {

		Table table = (Table) event.widget;
		int columnCount = table.getColumnCount();
		if (columnCount == 0)
			return;
		Rectangle area = table.getClientArea();
		int totalAreaWdith = area.width;
		int lineWidth = table.getGridLineWidth();
		int totalGridLineWidth = (columnCount - 1) * lineWidth;
		int totalColumnWidth = 0;
		for (TableColumn column : table.getColumns()) {
			totalColumnWidth = totalColumnWidth + column.getWidth();
		}
		int diff = totalAreaWdith - (totalColumnWidth + totalGridLineWidth);

		TableColumn lastCol = table.getColumns()[columnCount - 1];

		lastCol.setWidth(diff + lastCol.getWidth());

	}
 
Example 8
Project: neoscada   File: AbstractDataSeriesRenderer.java   Source Code and License 6 votes vote down vote up
protected static boolean translateToPoint ( final Rectangle clientRect, final XAxis x, final YAxis y, final DataPoint point, final DataEntry entry )
{
    // we always need X
    point.x = clientRect.x + x.translateToClient ( clientRect.width, entry.getTimestamp () );

    final Double value = entry.getValue ();
    if ( value == null || Double.isNaN ( value ) || Double.isInfinite ( value ) )
    {
        return false;
    }

    // we only provide Y if we really have a value

    point.y = clientRect.y + y.translateToClient ( clientRect.height, value );

    return true;
}
 
Example 9
Project: avoCADo   File: MainAvoCADoShell.java   Source Code and License 6 votes vote down vote up
/**
 * create the main avoCADo shell and display it
 * @param display
 */
public MainAvoCADoShell(Display display){
	shell = new Shell(display);
	
	setupShell(); 				// place components in the main avoCADo shell
	
	shell.setText("avoCADo");
	shell.setSize(800, 600);	//TODO: set intial size to last known size
	shell.setMinimumSize(640, 480);
	Rectangle b = display.getBounds();
	int xPos = Math.max(0, (b.width-800)/2);
	int yPos = Math.max(0, (b.height-600)/2);
	shell.setLocation(xPos, yPos);
	shell.setImage(ImageUtils.getIcon("./avoCADo.png", 32, 32));
	shell.open();
	
	AvoGlobal.intializeNewAvoCADoProject(); // initialize app to starting model/view.
	
	StartupSplashShell.closeSplash();
			
	// handle events while the shell is not disposed
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
}
 
Example 10
Project: parabuild-ci   File: SWTStrokeCanvas.java   Source Code and License 6 votes vote down vote up
/**
 * Creates a new instance.
 * 
 * @param parent  the parent.
 * @param style  the style.
 */
public SWTStrokeCanvas(Composite parent, int style) {
    super(parent, style);
    addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            BasicStroke stroke = (BasicStroke) getStroke();
            if (stroke != null) {
                int x, y;
                Rectangle rect = getClientArea();
                x = (rect.width - 100) / 2;
                y = (rect.height - 16) / 2;
                Transform swtTransform = new Transform(e.gc.getDevice()); 
                e.gc.getTransform(swtTransform);
                swtTransform.translate(x, y);
                e.gc.setTransform(swtTransform);
                swtTransform.dispose();
                e.gc.setBackground(getDisplay().getSystemColor(
                        SWT.COLOR_BLACK));
                e.gc.setLineWidth((int) stroke.getLineWidth());
                e.gc.drawLine(10, 8, 90, 8);
            }
        }
    });
}
 
Example 11
Project: neoscada   File: TitleRenderer.java   Source Code and License 6 votes vote down vote up
@Override
public void render ( final Graphics g, final Rectangle clientRectangle )
{
    if ( this.title == null || this.title.isEmpty () )
    {
        return;
    }

    g.setClipping ( this.rect );

    g.setFont ( createFont ( g.getResourceManager () ) );

    final Point size = g.textExtent ( this.title );

    final int x = this.rect.width / 2 - size.x / 2;
    final int y = this.padding;
    g.drawText ( this.title, this.rect.x + x, this.rect.y + y, null );

    g.setClipping ( clientRectangle );
}
 
Example 12
Project: neoscada   File: TitleRenderer.java   Source Code and License 6 votes vote down vote up
@Override
public Rectangle resize ( final ResourceManager resourceManager, final Rectangle clientRectangle )
{
    if ( this.title == null || this.title.isEmpty () )
    {
        return null;
    }

    final GC gc = new GC ( resourceManager.getDevice () );
    gc.setFont ( createFont ( resourceManager ) );

    try
    {
        final Point size = gc.textExtent ( this.title );
        this.rect = new Rectangle ( clientRectangle.x, clientRectangle.y, clientRectangle.width, size.y + this.padding * 2 );
        return new Rectangle ( clientRectangle.x, this.rect.y + this.rect.height, clientRectangle.width, clientRectangle.height - this.rect.height );
    }
    finally
    {
        gc.dispose ();
    }
}
 
Example 13
Project: BiglyBT   File: ColumnSubscriptionName.java   Source Code and License 6 votes vote down vote up
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
	Rectangle bounds = cell.getBounds();

	ImageLoader imageLoader = ImageLoader.getInstance();
	Image viewImage = imageLoader.getImage("ic_view");
	if(imageWidth == -1 || imageHeight == -1) {
		imageWidth = viewImage.getBounds().width;
		imageHeight = viewImage.getBounds().height;
	}

	bounds.width -= (imageWidth + 5);

	GCStringPrinter.printString(gc, cell.getSortValue().toString(), bounds,true,false,SWT.LEFT);

	Subscription sub = (Subscription) cell.getDataSource();

	if ( sub != null && !sub.isSearchTemplate()){

		gc.drawImage(viewImage, bounds.x + bounds.width, bounds.y + bounds.height / 2 - imageHeight / 2);
	}

	imageLoader.releaseImage("ic_view");

		//gc.drawText(cell.getText(), bounds.x,bounds.y);
}
 
Example 14
Project: applecommander   File: SwtUtil.java   Source Code and License 6 votes vote down vote up
/**
 * Setup some sensible paging information.
 */
public static void setupPagingInformation(ScrolledComposite composite) {
	GC gc = new GC(composite);
	FontMetrics fontMetrics = gc.getFontMetrics();
	gc.dispose();
	int fontHeight = fontMetrics.getHeight();
	int fontWidth = fontMetrics.getAverageCharWidth();
	Rectangle clientArea = composite.getClientArea();
	int lines = clientArea.height / fontHeight;
	int pageHeight = lines * fontHeight;
	int pageWidth = clientArea.width - fontWidth; 
	composite.getVerticalBar().setIncrement(fontHeight);
	composite.getVerticalBar().setPageIncrement(pageHeight);
	composite.getHorizontalBar().setIncrement(fontWidth);
	composite.getHorizontalBar().setPageIncrement(pageWidth);
}
 
Example 15
Project: OCCI-Studio   File: ImageCanvas.java   Source Code and License 6 votes vote down vote up
void paint(GC gc) {
	if (fImage != null) {
		Rectangle bounds = fImage.getBounds();
		Rectangle clientArea = getClientArea();
		int x;
		if (bounds.width < clientArea.width)
			x = (clientArea.width - bounds.width) / 2;
		else
			x = -getHorizontalBar().getSelection();
		int y;
		if (bounds.height < clientArea.height)
			y = (clientArea.height - bounds.height) / 2;
		else
			y = -getVerticalBar().getSelection();
		gc.drawImage(fImage, x, y);
	}
}
 
Example 16
Project: neoscada   File: VisualInterfaceViewer.java   Source Code and License 6 votes vote down vote up
protected void handleResize ( final Rectangle bounds )
{
    if ( !isZooming () )
    {
        final org.eclipse.draw2d.geometry.Rectangle r = new org.eclipse.draw2d.geometry.Rectangle ( bounds.x, bounds.y, bounds.width, bounds.height );
        this.connectionLayer.setPreferredSize ( r.getSize () );

        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 );
}
 
Example 17
Project: convertigo-eclipse   File: KTableCellEditor.java   Source Code and License 6 votes vote down vote up
/**
 * Activates the editor at the given position.
 * 
 * @param row
 * @param col
 * @param rect
 */
public void open(KTable table, int col, int row, Rectangle rect) {
  m_Table = table;
  m_Model = table.getModel();
  m_Rect = rect;
  m_Row = row;
  m_Col = col;
  if (m_Control == null) {
    m_Control = createControl();
    m_Control.setToolTipText(toolTip);
    m_Control.addFocusListener(new FocusAdapter() {
      public void focusLost(FocusEvent arg0) {
        close(true);
      }
    });
  }
  setBounds(m_Rect);
  GC gc = new GC(m_Table);
  m_Table.drawCell(gc, m_Col, m_Row);
  gc.dispose();
}
 
Example 18
Project: avoCADo   File: AboutAvoCADoGPLShell.java   Source Code and License 6 votes vote down vote up
/**
 * create the startup splash shell and display it
 * @param display
 */
public AboutAvoCADoGPLShell(Display display){
	shell = new Shell(display, SWT.PRIMARY_MODAL);
	
	setupShell(); 				// place components in the avoCADo license shell
	
	shell.setText("avoCADo GPLv2");
	shell.setSize(583, 350);	//TODO: set initial size to last known size
	Rectangle b = display.getBounds();
	int xPos = Math.max(0, (b.width-583)/2);
	int yPos = Math.max(0, (b.height-350)/2);
	shell.setLocation(xPos, yPos);
	shell.open();
	
	// handle events while the shell is not disposed
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
}
 
Example 19
Project: AppleCommander   File: DiskMapTab.java   Source Code and License 6 votes vote down vote up
/**
 * Handle paint requests for vertical ruler.
 */
protected void paintVerticalRuler(PaintEvent event) {
	// FIXME - not i18n safe!!
	String label = (disk.getBitmapLabels()[0] + "s").toUpperCase(); //$NON-NLS-1$
	if (disk.getBitmapLabels().length == 2) {
		label = (disk.getBitmapLabels()[1] + "s").toUpperCase(); //$NON-NLS-1$
	}
	StringBuffer buf = new StringBuffer();
	for (int i=0; i<label.length(); i++) {
		if (i>0) buf.append("\n"); //$NON-NLS-1$
		buf.append(label.charAt(i));
	}
	label = buf.toString();
	Canvas canvas = (Canvas) event.widget;
	Rectangle area = canvas.getClientArea();
	event.gc.drawLine(area.x + area.width/2, area.y, area.x + area.width/2, area.y + area.height);
	Point size = event.gc.textExtent(label);
	event.gc.drawText(label, area.x + area.width/2 - size.x/2, area.y + area.height/2 - size.y/2);
}
 
Example 20
Project: SWET   File: BreadcrumbItem.java   Source Code and License 6 votes vote down vote up
void drawButtonAtPosition(final int x) {

		if (this.selection) {
			drawBackgroundAtPosition(x);
		}
		if (!this.isLastItemOfTheBreadCrumb) {
			drawTrianglesAtPosition(x);
		}

		int xPosition = computeGap();
		final Image drawnedImage = drawImageAtPosition(x + xPosition);
		if (drawnedImage != null) {
			xPosition += drawnedImage.getBounds().width + 2 * MARGIN;
		}
		drawTextAtPosition(x + xPosition);

		this.bounds = new Rectangle(x, 0, getWidth(), this.toolbarHeight);
	}
 
Example 21
Project: iTrace-Archive   File: TokenHighlighter.java   Source Code and License 6 votes vote down vote up
@Override
public void handleEvent(Event event) {
	String[] propertyNames = event.getPropertyNames();
	//System.out.println(event.getProperty(propertyNames[0]));
	IStyledTextGazeResponse response = (IStyledTextGazeResponse)event.getProperty(propertyNames[0]);
	Rectangle mBounds = ITrace.getDefault().getRootShell().getBounds();
       int screenX = (int) (response.getGaze().getX() * mBounds.width);
       int screenY = (int) (response.getGaze().getY() * mBounds.height);
       //Rectangle monitorBounds = ITrace.getDefault().monitorBounds;
       if(styledText.isDisposed()) return;
       Rectangle editorBounds = styledText.getBounds();
       Point screenPos = styledText.toDisplay(0, 0);
       editorBounds.x = screenPos.x - mBounds.x;
       editorBounds.y = screenPos.y - mBounds.y;
       if(editorBounds.contains(screenX, screenY)){
       	int relativeX = screenX-editorBounds.x;
       	int relativeY = screenY-editorBounds.y;
       	update(response.getLine()-1,response.getCol(), relativeX, relativeY);
       }
	
}
 
Example 22
Project: tap17-muggl-javaee   File: StaticGuiSupport.java   Source Code and License 5 votes vote down vote up
/**
 * Get the centered position for a window on the primary monitor according
 * to its' width and height.
 * @param myWidth The windows' width.
 * @param myHeight The windows' height.
 * @param display The Display.
 * @return An array containing the X and the Y position.
 */
public static int[] getCenteredPosition(int myWidth, int myHeight, Display display) {
	// Calculate the current position.
	Rectangle displayBounds = display.getPrimaryMonitor().getBounds();
	int[] myPos = new int[2];
	myPos[0] = displayBounds.width / 2 - (myWidth / 2);
	myPos[1] = displayBounds.height / 2 - (myHeight / 2);

	// Finished.
	return myPos;
}
 
Example 23
Project: n4js   File: TestProgressBar.java   Source Code and License 5 votes vote down vote up
/**
 * Paint.
 */
protected void onPaint(GC gc) {
	final Rectangle b = getBounds();

	final TestStatus status = counter != null ? counter.getAggregatedStatus() : null;
	if (status != null) {

		final int total = Math.max(expectedTotal, counter.getTotal()); // this is our 100% value
		final int value = counter.getTotal(); // current value
		final int totalPx = b.width;
		final int valuePx = Math.round(totalPx * (((float) value) / ((float) total)));

		gc.setBackground(getColorForStatus(status));
		gc.fillRectangle(0, 0, valuePx, b.height);

		gc.setBackground(getBackground());
		gc.fillRectangle(0 + valuePx, 0, b.width - valuePx, b.height);
	} else {
		// clear
		gc.setBackground(getBackground());
		gc.fillRectangle(b);
	}

	if (counter != null) {
		final FontMetrics fm = gc.getFontMetrics();
		gc.setForeground(getForeground());
		final int pending = expectedTotal > 0 ? expectedTotal - counter.getTotal() : -1;
		gc.drawString(counter.toString(true, pending, SWT.RIGHT),
				4, b.height / 2 - fm.getHeight() / 2 - fm.getDescent(), true);
	}
}
 
Example 24
Project: n4js   File: ShowHistoryAction.java   Source Code and License 5 votes vote down vote up
@Override
public void runWithEvent(Event event) {
	if (event.widget instanceof ToolItem) {
		final ToolItem toolItem = (ToolItem) event.widget;
		final Control control = toolItem.getParent();
		final Menu menu = getMenuCreator().getMenu(control);

		final Rectangle bounds = toolItem.getBounds();
		final Point topLeft = new Point(bounds.x, bounds.y + bounds.height);
		menu.setLocation(control.toDisplay(topLeft));
		menu.setVisible(true);
	}
}
 
Example 25
Project: ide-plugins   File: PluginDialog.java   Source Code and License 5 votes vote down vote up
@Override
protected Point getInitialLocation(Point initialSize) {
    Monitor activeMonitor = Stream.of(display.getMonitors())
            .filter(m -> m.getBounds().intersects(getShell().getBounds()))
            .findFirst()
            .orElse(display.getPrimaryMonitor());

    Rectangle visualBounds = activeMonitor.getClientArea();
    int x = visualBounds.x + (visualBounds.width - initialSize.x) / 2;
    int y = visualBounds.y + (visualBounds.height - initialSize.y) / 2;
    return new Point(x, y);
}
 
Example 26
Project: SWET   File: BreadcrumbItem.java   Source Code and License 5 votes vote down vote up
private Point computeMaxWidthAndHeightForImages(final Image... images) {
	final Point imageSize = new Point(-1, -1);
	for (final Image image : images) {
		if (image == null) {
			continue;
		}
		final Rectangle imageBounds = image.getBounds();
		imageSize.x = Math.max(imageBounds.width, imageSize.x);
		imageSize.y = Math.max(imageBounds.height, imageSize.y);
	}
	return imageSize;
}
 
Example 27
Project: avoCADo   File: SWTUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Get the width of the shell's right edge
 * @param s
 * @return
 */
public static int getShellRightEdgeWidth(Shell s){
	Rectangle b = s.getBounds();
	Rectangle t = s.computeTrim(b.x, b.y, b.width, b.height);
	int rightEW = ((t.width-b.width)-(b.x-t.x));
	if(s.getMaximized()){
		return 0;
	}else{
		return rightEW;
	}
}
 
Example 28
Project: BiglyBT   File: VivaldiPanel.java   Source Code and License 5 votes vote down vote up
private void draw(GC gc,float x,float y,float h,DHTControlContact contact,int distance,float error) {
  if(x == 0 && y == 0) return;
  if(error > 1) error = 1;
  int errDisplay = (int) (100 * error);
  int x0 = scale.getX(x,y);
  int y0 = scale.getY(x,y);

  Image img = ImageRepository.getCountryFlag( contact.getTransportContact().getTransportAddress().getAddress(), true );

  if ( img != null ){
  	Rectangle bounds = img.getBounds();
  	int old = gc.getAlpha();
  	gc.setAlpha( 150 );
  	gc.drawImage( img, x0-bounds.width/2, y0-bounds.height);
  	gc.setAlpha( old );
  }

  gc.fillRectangle(x0-1,y0-1,3,3);
  //int elevation =(int) ( 200*h/(scale.maxY-scale.minY));
  //gc.drawLine(x0,y0,x0,y0-elevation);

  //String text = /*contact.getTransportContact().getAddress().getAddress().getHostAddress() + " (" + */distance + " ms \nerr:"+errDisplay+"%";
  String text = /*contact.getTransportContact().getAddress().getAddress().getHostAddress() + " (" + */distance + " ms "+errDisplay+"%";

  int lineReturn = text.indexOf("\n");
  int xOffset = gc.getFontMetrics().getAverageCharWidth() * (lineReturn != -1 ? lineReturn:text.length()) / 2;
  gc.drawText(text,x0-xOffset,y0,true);

  currentPositions.add( new Object[]{ x0, y0, h, contact, x, y, distance });
}
 
Example 29
Project: neoscada   File: MouseDragZoomer.java   Source Code and License 5 votes vote down vote up
@Override
public void render ( final Graphics g, final Rectangle clientRectangle )
{
    if ( this.selection != null )
    {
        final Rectangle chartRect = this.chart.getClientAreaProxy ().getClientRectangle ();

        g.setLineAttributes ( new LineAttributes ( 1.0f ) );
        g.setForeground ( null );

        g.drawRectangle ( this.selection.x + chartRect.x, this.selection.y + chartRect.y, this.selection.width, this.selection.height );
    }
}
 
Example 30
Project: BiglyBT   File: ColumnActivityNew.java   Source Code and License 5 votes vote down vote up
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
	ActivitiesEntry entry = (ActivitiesEntry) cell.getDataSource();

	Rectangle cellBounds = cell.getBounds();
	Image img = entry.getReadOn() <= 0 ? imgNew : imgOld;

	if (img != null && !img.isDisposed()) {
		Rectangle imgBounds = img.getBounds();
		gc.drawImage(img, cellBounds.x
				+ ((cellBounds.width - imgBounds.width) / 2), cellBounds.y
				+ ((cellBounds.height - imgBounds.height) / 2));
	}
}
 
Example 31
Project: neoscada   File: MouseHover.java   Source Code and License 5 votes vote down vote up
@Override
protected void doRender ( final Graphics g, final Rectangle clientRectangle )
{
    if ( this.position == null )
    {
        return;
    }

    final int x = this.position;
    g.setForeground ( this.color );
    g.drawLine ( x, clientRectangle.y, x, clientRectangle.y + clientRectangle.height );
}
 
Example 32
Project: Hydrograph   File: ExecutionTrackingConsoleUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Open execution tracking console window.
 *
 * @param localJobId the local job id
 */
private void openExecutionTrackingConsoleWindow(String localJobId) {
	boolean newConsole=false;
	ExecutionTrackingConsole console = JobManager.INSTANCE.getExecutionTrackingConsoles().get(localJobId);
	if(console==null){
		console = new ExecutionTrackingConsole(getConsoleName(),localJobId);
		JobManager.INSTANCE.getExecutionTrackingConsoles().put(localJobId, console);
		newConsole = true;
	}
	if(console.getShell()==null){
		console.clearConsole();
		console.open();
		if(!JobManager.INSTANCE.isJobRunning(console.consoleName)){
			console.statusLineManager.setMessage("");
		}
	}else{
		Rectangle originalBounds = console.getShell().getBounds();
		console.getShell().setMaximized(true);
		Rectangle originalBoundsClone = new Rectangle(originalBounds.x, originalBounds.y, originalBounds.width, originalBounds.height);
		console.getShell().setBounds(originalBoundsClone);		
		console.getShell().setActive();	
	}
	if(StringUtils.isNotEmpty(getUniqueJobId()) && newConsole && isJobUpdated){
		ExecutionStatus[] executionStatus = readFile(null, getUniqueJobId(), JobManager.INSTANCE.isLocalMode());
		console.setStatus(getHeader(getUniqueJobId()));
		for(int i =0; i<executionStatus.length; i++){
			console.setStatus(getExecutionStatusInString(executionStatus[i]));
		}
	}
}
 
Example 33
Project: neoscada   File: LegendRenderer.java   Source Code and License 5 votes vote down vote up
@Override
public void render ( final Graphics g, final Rectangle clientRectangle )
{
    final Rectangle chartRect = this.renderer.getClientAreaProxy ().getClientRectangle ();

    final DataSet data = makeAllData ( g );

    renderData ( g, chartRect, data );
}
 
Example 34
Project: BiglyBT   File: TabbedEntry.java   Source Code and License 5 votes vote down vote up
@Override
public Image obfuscatedImage(Image image) {
	Rectangle bounds = swtItem == null ? null : swtItem.getBounds();
	if ( bounds != null ){

		boolean isActive = swtItem.getParent().getSelection() == swtItem;
		boolean isHeaderVisible = swtItem.isShowing();

		Point location = Utils.getLocationRelativeToShell(swtItem.getParent());

		bounds.x += location.x;
		bounds.y += location.y;

		Map<String, Object> map = new HashMap<>();
		map.put("image", image);
		map.put("obfuscateTitle", false);
		if (isActive) {
			triggerEvent(UISWTViewEvent.TYPE_OBFUSCATE, map);

			if (viewTitleInfo instanceof ObfuscateImage) {
				((ObfuscateImage) viewTitleInfo).obfuscatedImage(image);
			}
		}

		if (isHeaderVisible) {
 			if (viewTitleInfo instanceof ObfuscateTab) {
 				String header = ((ObfuscateTab) viewTitleInfo).getObfuscatedHeader();
 				if (header != null) {
 					UIDebugGenerator.obfuscateArea(image, bounds, header);
 				}
 			}

 			if (MapUtils.getMapBoolean(map, "obfuscateTitle", false)) {
 				UIDebugGenerator.obfuscateArea(image, bounds);
 			}
		}
	}

	return image;
}
 
Example 35
Project: neoscada   File: AbstractDataSeriesRenderer.java   Source Code and License 5 votes vote down vote up
@Override
public void render ( final Graphics g, final Rectangle clientRectangle )
{
    if ( !this.visible )
    {
        return;
    }
    else
    {
        performRender ( g, clientRectangle );
    }
}
 
Example 36
Project: neoscada   File: AbstractPositionYRuler.java   Source Code and License 5 votes vote down vote up
@Override
protected void doRender ( final Graphics g, final Rectangle clientRectangle )
{
    if ( this.axis == null )
    {
        return;
    }

    final Double position = getPosition ();
    if ( position == null )
    {
        return;
    }

    final int y = (int)this.axis.translateToClient ( clientRectangle.height, getPosition () );

    if ( ( this.style & SWT.TOP ) > 0 )
    {
        g.fillRectangle ( clientRectangle.x, clientRectangle.y, clientRectangle.width, y );
    }
    else if ( ( this.style & SWT.BOTTOM ) > 0 )
    {
        g.fillRectangle ( clientRectangle.x, y, clientRectangle.width, clientRectangle.height - y );
    }
    else
    {
        if ( y < 0 || y > clientRectangle.width )
        {
            return;
        }
        g.drawLine ( clientRectangle.x, clientRectangle.y + y, clientRectangle.width, clientRectangle.y + y );
    }
}
 
Example 37
Project: parabuild-ci   File: ChartComposite.java   Source Code and License 5 votes vote down vote up
/**
 * Zooms in on a selected region.
 *
 * @param selection  the selected region.
 */
public void zoom(Rectangle selection) {

    // get the origin of the zoom selection in the Java2D space used for
    // drawing the chart (that is, before any scaling to fit the panel)
    Point2D selectOrigin = translateScreenToJava2D(
            new Point(selection.x, selection.y));
    PlotRenderingInfo plotInfo = this.info.getPlotInfo();
    Rectangle scaledDataArea = getScreenDataArea(
            (int) (selection.x + selection.width)/2, 
            (int) (selection.y + selection.height)/2);
    if ((selection.height > 0) && (selection.width > 0)) {

        double hLower = (selection.x - scaledDataArea.x) 
            / (double) scaledDataArea.width;
        double hUpper = (selection.x + selection.width - scaledDataArea.x) 
            / (double) scaledDataArea.width;
        double vLower = (scaledDataArea.y + scaledDataArea.height - selection.y - selection.height) 
            / (double) scaledDataArea.height;
        double vUpper = (scaledDataArea.y + scaledDataArea.height - selection.y) 
            / (double) scaledDataArea.height;
        Plot p = this.chart.getPlot();
        if (p instanceof Zoomable) {
            Zoomable z = (Zoomable) p;
            if (z.getOrientation() == PlotOrientation.HORIZONTAL) {
                z.zoomDomainAxes(vLower, vUpper, plotInfo, selectOrigin);
                z.zoomRangeAxes(hLower, hUpper, plotInfo, selectOrigin);
            }
            else {
                z.zoomDomainAxes(hLower, hUpper, plotInfo, selectOrigin);
                z.zoomRangeAxes(vLower, vUpper, plotInfo, selectOrigin);
            }
        }

    }

}
 
Example 38
Project: SWET   File: SimpleToolBarEx.java   Source Code and License 5 votes vote down vote up
private void paginateBreadCrumb() {
	Rectangle rect = bc.getBounds();
	if (rect.width > shell.getBounds().width - 5
			|| rect.width > java.awt.Toolkit.getDefaultToolkit()
					.getScreenSize().width - 100) {
		Breadcrumb bc2 = new Breadcrumb(bc.getParent(), SWT.BORDER);
		// NOTE: operates global
		bc = bc2;
	}
}
 
Example 39
Project: BiglyBT   File: ColumnTC_Sample.java   Source Code and License 5 votes vote down vote up
public Cell(TableCell parentCell, TableColumnCore column, Composite c, TableRowCore sampleRow) {
	this.column = column;
	if (sampleRow == null) {
		return;
	}
	Object ds = sampleRow.getDataSource(true);
	Object pds = sampleRow.getDataSource(false);
	if (column.handlesDataSourceType(pds.getClass())) {
			sampleCell = new FakeTableCell(column, ds);

			Rectangle bounds = ((TableCellSWT)parentCell).getBounds();
			sampleCell.setControl(c, bounds, false);
	}
}
 
Example 40
Project: BiglyBT   File: SideBarToolTips.java   Source Code and License 5 votes vote down vote up
/**
 * @return
 *
 * @since 3.1.1.1
 */
private String getToolTip(Point mousePos_RelativeToItem) {
	MdiEntryVitalityImage[] vitalityImages = mdiEntry.getVitalityImages();
	for (int i = 0; i < vitalityImages.length; i++) {
		SideBarVitalityImageSWT vitalityImage = (SideBarVitalityImageSWT) vitalityImages[i];
		if (vitalityImage == null) {
			continue;
		}
		String indicatorToolTip = vitalityImage.getToolTip();
		if (indicatorToolTip == null || !vitalityImage.isVisible()) {
			continue;
		}
		Rectangle hitArea = vitalityImage.getHitArea();
		if (hitArea == null) {
			continue;
		}
		if (hitArea.contains(mousePos_RelativeToItem)) {
			return indicatorToolTip;
		}
	}

	if (mdiEntry.getViewTitleInfo() != null) {
		String tt = (String) mdiEntry.getViewTitleInfo().getTitleInfoProperty(ViewTitleInfo.TITLE_INDICATOR_TEXT_TOOLTIP);
		return tt;
	}

	return null;
}
 
Example 41
Project: BiglyBT   File: ColumnSubResultNew.java   Source Code and License 5 votes vote down vote up
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
	SBC_SubscriptionResult entry = (SBC_SubscriptionResult) cell.getDataSource();

	Rectangle cellBounds = cell.getBounds();
	Image img = entry== null || entry.getRead() ? imgOld: imgNew;

	if (img != null && !img.isDisposed()) {
		Rectangle imgBounds = img.getBounds();
		gc.drawImage(img, cellBounds.x
				+ ((cellBounds.width - imgBounds.width) / 2), cellBounds.y
				+ ((cellBounds.height - imgBounds.height) / 2));
	}
}
 
Example 42
Project: avoCADo   File: SWTUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Get height of the shell's titlebar
 * @param s
 * @return
 */
public static int getShellTitlebarHeight(Shell s){
	Rectangle b = s.getBounds();
	Rectangle t = s.computeTrim(b.x, b.y, b.width, b.height);
	int tbarHeight = (b.y-t.y);
	return tbarHeight;
}
 
Example 43
Project: neoscada   File: PrintProcessor.java   Source Code and License 5 votes vote down vote up
private void drawRow ( final Device device, final GC gc, final String label, final List<Double> data, final Rectangle bounds, final double minX, final double maxX )
{
    final Rectangle deviceBounds = device.getBounds ();

    gc.setLineWidth ( 1 );

    final int size = data.size ();

    final double diff = maxX - minX;

    Point lastPoint = null;
    for ( int i = 0; i < size; i++ )
    {
        // final Value v = data[i];
        final ValueInformation info = this.valueInformation.get ( i );

        if ( info.getQuality () > 0.75 )
        {
            final double posX = (double)bounds.width / (double)size * i;
            final double posY = data.get ( i ) / diff * bounds.height;

            final Point point = new Point ( (int)posX + bounds.x, (int)posY + bounds.y );

            if ( lastPoint != null )
            {
                gc.drawLine ( lastPoint.x, deviceBounds.height - lastPoint.y, point.x, deviceBounds.height - lastPoint.y );
                gc.drawLine ( point.x, deviceBounds.height - lastPoint.y, point.x, deviceBounds.height - point.y );
            }

            lastPoint = point;
        }
        else
        {
            lastPoint = null;
        }
    }
}
 
Example 44
Project: convertigo-eclipse   File: LimitCharsLogsPreferenceDialog.java   Source Code and License 5 votes vote down vote up
@Override
public void configureShell(Shell newShell) {
	super.configureShell(newShell);
	newShell.setText("Limit chars logs");
	newShell.setSize(nWidth, nHeight);

	int nLeft = 0;
	int nTop = 0;

	Display display = newShell.getDisplay();

	Point pt = display.getCursorLocation();
	Monitor[] monitors = display.getMonitors();

	for (int i = 0; i < monitors.length; i++) {
		if (monitors[i].getBounds().contains(pt)) {
			Rectangle rect = monitors[i].getClientArea();

			if (rect.x < 0)
				nLeft = ((rect.width - nWidth) / 2) + rect.x;
			else
				nLeft = (rect.width - nWidth) / 2;

			if (rect.y < 0)
				nTop = ((rect.height - nHeight) / 2) + rect.y;
			else
				nTop = (rect.height - nHeight) / 2;

			break;
		}
	}

	newShell.setBounds(nLeft, nTop, nWidth, nHeight);
	
}
 
Example 45
Project: Hydrograph   File: PaletteToolTip.java   Source Code and License 5 votes vote down vote up
/**
 * 
 * Returns tooltip bounds
 * 
 * @return org.eclipse.swt.graphics.Rectangle
 */
public Rectangle getToolTipBounds(){
	Point tooltipSize = getToolTipWidthHeight();
	Rectangle bounds = new Rectangle(0, 0, tooltipSize.x, tooltipSize.y);
	logger.debug("tooltip bounds=" + bounds);
	return bounds;
}
 
Example 46
Project: SWET   File: ChoicesDialog.java   Source Code and License 5 votes vote down vote up
private void center(Shell shell) {

		Shell parent = (Shell) shell.getParent();
		Rectangle bounds = parent.getBounds();
		Point size = shell.getSize();

		int x = bounds.x + bounds.width / 2 - size.x / 2;
		int y = bounds.y + bounds.height / 2 - size.y / 2;
		// System.err.println("ChoiceDialog: center: x=" + x + " y=" + y);
		shell.setLocation(x, (y < 0) ? 0 : y);
	}
 
Example 47
Project: convertigo-eclipse   File: EnginePreferenceDialog.java   Source Code and License 5 votes vote down vote up
@Override
public void configureShell(Shell newShell) {
	super.configureShell(newShell);
	newShell.setText("Engine Log settings");
	newShell.setSize(nWidth, nHeight);

	int nLeft = 0;
	int nTop = 0;

	Display display = newShell.getDisplay();

	Point pt = display.getCursorLocation();
	Monitor[] monitors = display.getMonitors();

	for (int i = 0; i < monitors.length; i++) {
		if (monitors[i].getBounds().contains(pt)) {
			Rectangle rect = monitors[i].getClientArea();

			if (rect.x < 0)
				nLeft = ((rect.width - nWidth) / 2) + rect.x;
			else
				nLeft = (rect.width - nWidth) / 2;

			if (rect.y < 0)
				nTop = ((rect.height - nHeight) / 2) + rect.y;
			else
				nTop = (rect.height - nHeight) / 2;

			break;
		}
	}

	newShell.setBounds(nLeft, nTop, nWidth, nHeight);
	
}
 
Example 48
Project: applecommander   File: DiskMapTab.java   Source Code and License 5 votes vote down vote up
/**
 * Draw a box on the screen.  The shadowed box is only drawn if there is
 * enough space within the box; otherwise, the box is just filled in with
 * the fill color.  Additionally, drawBox ensures that a square is drawn.
 */
protected void drawBox(Rectangle box, GC gc, Color fill, Color outline, Color shadow) {
	if (box.width >= 10 && box.height >= 10) {
		// square the rectangle shape:
		int size = Math.min(box.height, box.width);
		box.height = size + ((box.height - size) / 2);
		box.width = size + ((box.width - size) / 2);
		// offset internal box:
		box.x+= 2;
		box.y+= 2;
		box.width-= 5;
		box.height-= 5;
		// draw!
		gc.setBackground(shadow);
		gc.fillRectangle(box);
		box.x-= 2;
		box.y-= 2;
		gc.setBackground(fill);
		gc.fillRectangle(box);
		gc.setForeground(outline);
		gc.drawRectangle(box);
	} else {
		// just fill:
		gc.setBackground(fill);
		gc.fillRectangle(box);
	}
}
 
Example 49
Project: BiglyBT   File: ColumnFileCount.java   Source Code and License 5 votes vote down vote up
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
	DownloadManager dm = (DownloadManager) cell.getDataSource();
	if (dm == null) {
		return;
	}

	int sortVal = dm.getNumFileInfos();
	Rectangle bounds = cell.getBounds();
	Rectangle printArea = new Rectangle(bounds.x, bounds.y, bounds.width - 6,
			bounds.height);
	GCStringPrinter.printString(gc, "" + sortVal, printArea, true, true,
			SWT.RIGHT);
}
 
Example 50
Project: xcalendar   File: XCalendarFrame.java   Source Code and License 5 votes vote down vote up
/**
 * 
 */
@Override
public void close() {
	if(this.gc.isDisposed()) return;
	gc.setClipping((Rectangle)null);
	if(transform != null && !transform.isDisposed()) transform.dispose();
}
 
Example 51
Project: SWET   File: ScrolledTextEx.java   Source Code and License 5 votes vote down vote up
private static Point center(Display display, Shell shell) {
	Monitor primary = display.getPrimaryMonitor();
	Rectangle bounds = primary.getBounds();
	Rectangle rect = shell.getBounds();

	int x = bounds.x + (bounds.width - rect.width) / 2;
	int y = bounds.y + (bounds.height - rect.height) / 2;

	Point location = new Point(x, y);
	return location;
}
 
Example 52
Project: parabuild-ci   File: SWTUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Transform an awt Rectangle2d instance into a swt one.
 * The coordinates are rounded to integer for the swt object.
 * @param rect2d The awt rectangle to map.
 * @return an swt <code>Rectangle</code> object.
 */
public static Rectangle toSwtRectangle(Rectangle2D rect2d) {
    return new Rectangle(
            (int) Math.round(rect2d.getMinX()),
            (int) Math.round(rect2d.getMinY()),
            (int) Math.round(rect2d.getWidth()),
            (int) Math.round(rect2d.getHeight())
            );
}
 
Example 53
Project: convertigo-eclipse   File: SWTX.java   Source Code and License 5 votes vote down vote up
public static void drawButtonUp(GC gc, String text, int textAlign,
    Image image, int imageAlign, Rectangle r, int leftMargin,
    int topMargin) {
  Display display = Display.getCurrent();
  drawButtonUp(gc, text, textAlign, image, imageAlign, r.x, r.y, r.width,
      r.height, display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND),
      display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW),
      display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW), display
          .getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW),
      leftMargin, topMargin);
}
 
Example 54
Project: convertigo-eclipse   File: KTable.java   Source Code and License 5 votes vote down vote up
/**
 * This method activated the cell editor on the current focus cell, if the
 * table model allows cell editing for this cell.
 */
public void openEditorInFocus() {
  m_CellEditor = m_Model.getCellEditor(m_FocusCol, m_FocusRow);
  if (m_CellEditor != null) {
    Rectangle r = getCellRect(m_FocusCol, m_FocusRow);
    m_CellEditor.open(this, m_FocusCol, m_FocusRow, r);
  }
}
 
Example 55
Project: parabuild-ci   File: ChartComposite.java   Source Code and License 5 votes vote down vote up
/**
 * Returns the data area for the chart (the area inside the axes) with the
 * current scaling applied (that is, the area as it appears on screen).
 *
 * @return The scaled data area.
 */
public Rectangle getScreenDataArea() {
    Rectangle2D dataArea = this.info.getPlotInfo().getDataArea();
    Rectangle clientArea = this.getClientArea();
    int x = (int) (dataArea.getX() * this.scaleX + clientArea.x);
    int y = (int) (dataArea.getY() * this.scaleY + clientArea.y);
    int w = (int) (dataArea.getWidth() * this.scaleX);
    int h = (int) (dataArea.getHeight() * this.scaleY);
    return new Rectangle(x, y, w, h);
}
 
Example 56
Project: AppleCommander   File: DiskMapTab.java   Source Code and License 5 votes vote down vote up
/**
 * Paint a map with the given dimensions.
 */
private void paintDiskMap(int xdim, int ydim, PaintEvent event) {
	Canvas canvas = (Canvas) event.widget;
	Rectangle area = canvas.getClientArea();
	area.width-= 2;
	area.height-= 2;

	int[] ypos = new int[ydim + 1];
	for (int i=0; i<ydim; i++) {
		ypos[i] = (i * area.height) / ydim + 1;
	}
	ypos[ydim] = area.height;
	int[] xpos = new int[xdim + 1];
	for (int i=0; i<xdim; i++) {
		xpos[i] = (i * area.width) / xdim + 1;
	}
	xpos[xdim] = area.width;
	
	Image image = new Image(canvas.getDisplay(), area);
	GC gc = new GC(image);
	int x = 0;
	int y = 0;
	DiskUsage usage = disk.getDiskUsage();
	for (x=0; x<xdim && usage.hasNext(); x++) {
		for (y=0; y<ydim && usage.hasNext(); y++) {
			usage.next();
			boolean free = usage.isFree();
			Rectangle box = new Rectangle(xpos[x], ypos[y], 
					xpos[x+1]-xpos[x], ypos[y+1]-ypos[y]);
			drawBox(box, gc, free ? freeFill : usedFill, black, gray);
		}
	}
	event.gc.drawImage(image, 0, 0);
	gc.dispose();
	image.dispose();
}
 
Example 57
Project: convertigo-eclipse   File: KTable.java   Source Code and License 5 votes vote down vote up
protected void drawCells(GC gc, Rectangle clipRect, int fromCol, int toCol,
	      int fromRow, int toRow) {
//	    int cnt = 0;
	    Rectangle r;

	    if (m_CellEditor != null) {
	      if (!isCellVisible(m_CellEditor.m_Col, m_CellEditor.m_Row)) {
	        Rectangle hide = new Rectangle(-101, -101, 100, 100);
	        m_CellEditor.setBounds(hide);
	      } else {
	        m_CellEditor.setBounds(getCellRect(m_CellEditor.m_Col,
	            m_CellEditor.m_Row));
	      }
	    }

	    for (int row = fromRow; row < toRow; row++) {
	      r = getCellRect(0, row);
	      if (r.y + r.height < clipRect.y) {
	        continue;
	      }
	      if (r.y > clipRect.y + clipRect.height) {
	        break;
	      }

	      for (int col = fromCol; col < toCol; col++) {
	        r = getCellRect(col, row);
	        if (r.x > clipRect.x + clipRect.width) {
	          break;
	        }
	        if (canDrawCell(col, row, clipRect)) {
	          drawCell(gc, col, row);
//	          cnt++;
	        }
	      }
	    }
	  }
 
Example 58
Project: xcalendar   File: SwtUtils.java   Source Code and License 4 votes vote down vote up
/**
 * Shell
 */
public static void center(final Shell shell) {
    final Rectangle r1 = shell.getMonitor().getBounds(), r2 = shell.getBounds();
    shell.setLocation(r1.x + (r1.width - r2.width) / 2, r1.y + (r1.height - r2.height) / 2);
}
 
Example 59
Project: Hydrograph   File: FTPOperationConfigDialog.java   Source Code and License 4 votes vote down vote up
@Override
protected Control createDialogArea(Composite parent) {
	Composite container = (Composite) super.createDialogArea(parent);
	container.setLayout(new GridLayout(1, false));
	container.getShell().setText(windowLabel);
	
	if(StringUtils.equalsIgnoreCase(protocol, Constants.AWS_S3)){
		COMPOSITE_CONST_HEIGHT = 330;
	}else {
		COMPOSITE_CONST_HEIGHT = 276;
	}
	
	Shell shell = container.getShell();
	shell.addControlListener(new ControlAdapter() {
           @Override
           public void controlResized(ControlEvent e) {
               Rectangle rect = shell.getBounds();
               if(rect.width != COMPOSITE_CONST_HEIGHT) {
                   shell.setBounds(rect.x, rect.y, rect.width, COMPOSITE_CONST_HEIGHT);
               }
           }
       });
	
	Composite composite = new Composite(container, SWT.BORDER);
	composite.setLayout(new GridLayout(2, false));
	composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
	
	FTPWidgetUtility ftpWidgetUtility = new FTPWidgetUtility();
	Label operationLabel = (Label) ftpWidgetUtility.createLabel(composite, Messages.OPERATION);
	setPropertyHelpText(operationLabel, "Used to select the Operation");
	authenticationModeCombo = (Combo) ftpWidgetUtility.CreateCombo(composite, optionList);
	
	
	Composite composite2 = new Composite(container, SWT.NONE);
	composite2.setLayout(new GridLayout(1, false));
	composite2.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
	
	Composite stackComposite = new Composite(composite2, SWT.NONE);
	StackLayout layout = new StackLayout();
	stackComposite.setLayout(layout);
	stackComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
	
	stackComposite.getShell().setText(Messages.OPERATION_CONFIG);
	createOperationConfigArea(stackComposite, layout);
	
	addModifyListener(text1);
	addModifyListener(text2);
	addModifyListener(text3);
	addModifyListener(text4);
	
	populateWidget();
	
	return container;
}
 
Example 60
Project: BiglyBT   File: ShellSlider.java   Source Code and License 4 votes vote down vote up
/**
 * Slide In
 *
 * @param shell
 * @param direction
 * @param endBounds
 */
public ShellSlider(final Shell shell, int direction, final Rectangle endBounds) {
	this.shell = shell;
	this.endBounds = endBounds;
	this.slideIn = true;
	this.direction = direction;

	if (shell == null || shell.isDisposed())
		return;

	Display display = shell.getDisplay();
	display.syncExec(new Runnable() {
		@Override
		public void run() {
			if (shell.isDisposed())
				return;

			switch (ShellSlider.this.direction) {
				case SWT.UP:
				default:
					shell.setLocation(endBounds.x, endBounds.y);
					Rectangle displayBounds = null;
					try {
						boolean ok = false;
						Monitor[] monitors = shell.getDisplay().getMonitors();
						for (int i = 0; i < monitors.length; i++) {
							Monitor monitor = monitors[i];
							displayBounds = monitor.getBounds();
							if (displayBounds.contains(endBounds.x, endBounds.y)) {
								ok = true;
								break;
							}
						}
						if (!ok) {
							displayBounds = shell.getMonitor().getBounds();
						}
					} catch (Throwable t) {
						displayBounds = shell.getDisplay().getBounds();
					}

					shellBounds = new Rectangle(endBounds.x, displayBounds.y
							+ displayBounds.height, endBounds.width, 0);
					break;
			}
			shell.setBounds(shellBounds);
			shell.setVisible(true);

			if (DEBUG)
				System.out.println("Slide In: " + shell.getText());
		}
	});
}