java类org.eclipse.swt.graphics.GC的实例源码

XCalendarIncrWidget.java 文件源码 项目:xcalendar 阅读 24 收藏 0 点赞 0 评论 0
/**
 * 
 */
@Override
public void render(XCalendarFrame frame) {
    // Background
    final GC gc = frame.getGc();
    final XCalendarModel model = popup.getModel();
    final XCalendarTheme theme = model.getTheme();
    final boolean hovered = this.mouse.isEntered();
    int x = bounds.x, y = bounds.y, w = bounds.width, h = bounds.height;
    gc.setBackground(theme.getBackground(true, false, false, hovered));
    gc.fillRoundRectangle(x, y, w, h, theme.getArc(), theme.getArc());

    // Foreground
    String text = chevron_up;
    gc.setForeground(theme.getToolBarBackground(hovered));
    gc.setFont(Fonts.getAwesomeFont()); final Point size = extent(gc, text);
    gc.drawText(text, x + 1 + ((w - size.x) >> 1), y + 1 + ((h - size.y) >> 1));
}
GraphUtils.java 文件源码 项目:n4js 阅读 34 收藏 0 点赞 0 评论 0
public static void drawString(GC gc, String str, float x, float y, float width, float height, int bgAlpha) {
    if (str == null)
        return;

    org.eclipse.swt.graphics.Point size = gc.stringExtent(str);
    int posX = Math.round(x + width / 2 - size.x / 2);
    int posY = Math.round(y + height / 2 - size.y / 2);

    if (bgAlpha >= 255) {
        gc.drawString(str, posX, posY);
    } else {
        gc.drawString(str, posX, posY, true);
        if (bgAlpha > 0) {
            gc.setAlpha(bgAlpha);
            gc.fillRectangle(posX, posY, size.x, size.y);
            gc.setAlpha(255);
        }
    }
}
GraphUtils.java 文件源码 项目:n4js 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Paints an looping arc from scr to tgt.
 * <p/>
 * <b>Assumption:</b> The tgt is located right/below of the src.
 */
public static float[] arcSelf(GC gc, Point src, Point tgt) {
    Path path = new Path(gc.getDevice());
    int diffH = 10;
    int diff = diffH * 3;
    path.moveTo((int) src.x, (int) src.y);
    path.cubicTo(
            (int) src.x + diff, (int) src.y - diffH,
            (int) tgt.x, (int) tgt.y - diff,
            (int) tgt.x, (int) tgt.y);

    gc.drawPath(path);

    float[] pp = path.getPathData().points;
    return pp;
}
XCalendarPrevWidget.java 文件源码 项目:xcalendar 阅读 23 收藏 0 点赞 0 评论 0
/**
 * 
 */
@Override
public void render(XCalendarFrame frame) {
    // Background
    final GC gc = frame.getGc();
    final XCalendarModel model = popup.getModel();
    final XCalendarTheme theme = model.getTheme();
    final boolean hovered = this.mouse.isEntered();
    int x = bounds.x, y = bounds.y, w = bounds.width, h = bounds.height;
    gc.setBackground(theme.getBackground(true, false, false, hovered));
    gc.fillRoundRectangle(x, y, w, h, theme.getArc(), theme.getArc());

    // Foreground
    String text = chevron_left;
    gc.setForeground(theme.getForeground(true, false, true));
    gc.setFont(Fonts.getAwesomeFont()); final Point size = extent(gc, text);
    gc.drawText(text, x + 1 + ((w - size.x) >> 1), y + 1 + ((h - size.y) >> 1));
}
DiskExplorerTab.java 文件源码 项目:applecommander 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Pre-compute column widths for the file tab.
 * These can and are over-ridden by user sizing.
 */
protected void computeColumnWidths(int format) {
    List headers = disks[0].getFileColumnHeaders(format);
    int[] headerWidths = new int[headers.size()];
    GC gc = new GC(shell);
    for (int i=0; i<headers.size(); i++) {
        FileColumnHeader header = (FileColumnHeader) headers.get(i);
        if (header.getTitle().length() >= header.getMaximumWidth()) {
            headerWidths[i] = gc.stringExtent(header.getTitle()).x + 
                2 * gc.stringExtent(textBundle.get("WidestCharacter")).x;  //$NON-NLS-1$
        } else {
            headerWidths[i] = gc.stringExtent(
                    textBundle.get("WidestCharacter")).x  //$NON-NLS-1$
                    * header.getMaximumWidth();
        }
    }
    gc.dispose();
    gc = null;
    columnWidths.put(new Integer(format), headerWidths);
}
Edge.java 文件源码 项目:n4js 阅读 27 收藏 0 点赞 0 评论 0
/**
 * draw temporary labels for external nodes (and save their bounds for later)
 */
private List<Rectangle> drawTemporaryLabels(GC gc) {
    final List<Rectangle> nodesExternalBounds = new ArrayList<>();
    final Rectangle clip = GraphUtils.getClip(gc);
    float px = clip.x + clip.width;
    float py = clip.y + clip.height;
    for (String currNE : endNodesExternal) {
        final org.eclipse.swt.graphics.Point size = gc.stringExtent(currNE);
        py -= size.y + 4;
        final float rx = px - (size.x + 4);
        final Rectangle b = new Rectangle(rx, py, size.x, size.y);
        nodesExternalBounds.add(b);
        // TODO string extent will be computed twice :(
        GraphUtils.drawString(gc, currNE, b.x + b.width / 2, b.y + b.height / 2);
    }
    return nodesExternalBounds;
}
CFEdge.java 文件源码 项目:n4js 阅读 32 收藏 0 点赞 0 评论 0
/** Paints an edge */
void paintEdge(GC gc, Node srcN, Node tgtN) {
    setColor(gc);

    Point src = srcN.getCenter();
    Point tgt = tgtN.getCenter();
    Point tgtB;

    if (srcN == tgtN) {
        tgtB = paintSelfArc(gc, tgtN, tgt);
    } else if (isReverseArc(src, tgt)) {
        tgtB = paintReverseArc(gc, srcN, tgtN, src, tgt);
    } else {
        tgtB = paintArc(gc, srcN, tgtN, src, tgt);
    }

    drawArrowHead(gc, tgt, tgtB);
}
XCalendarDecrWidget.java 文件源码 项目:xcalendar 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 
 */
@Override
public void render(XCalendarFrame frame) {
    // Background
    final GC gc = frame.getGc();
    final XCalendarModel model = popup.getModel();
    final XCalendarTheme theme = model.getTheme();
    final boolean hovered = this.mouse.isEntered();
    int x = bounds.x, y = bounds.y, w = bounds.width, h = bounds.height;
    gc.setBackground(theme.getBackground(true, false, false, hovered));
    gc.fillRoundRectangle(x, y, w, h, theme.getArc(), theme.getArc());

    // Foreground
    String text = chevron_down;
    gc.setForeground(theme.getToolBarBackground(hovered));
    gc.setFont(Fonts.getAwesomeFont()); final Point size = extent(gc, text);
    gc.drawText(text, x + 1 + ((w - size.x) >> 1), y + 1 + ((h - size.y) >> 1));
}
CFEdge.java 文件源码 项目:n4js 阅读 34 收藏 0 点赞 0 评论 0
/** Draws the label between jumping control flow elements. */
void drawLabel(GC gc, Point p) {
    label = "";
    for (ControlFlowType cfType : cfTypes) {
        switch (cfType) {
        case Break:
        case Continue:
        case Return:
        case Throw:
        case LoopEnter:
        case LoopReenter:
        case LoopInfinite:
            if (!label.isEmpty())
                label += "|";
            label += cfType.name();
            break;
        default:
        }
    }

    org.eclipse.swt.graphics.Point size = gc.stringExtent(label);
    float x = p.x - size.x / 2;
    float y = p.y - size.y / 2;
    GraphUtils.drawString(gc, label, x, y);
}
Node.java 文件源码 项目:n4js 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Paints the Node
 */
public void paint(GC gc) {
    gc.setBackground(getBackgroundColor());
    gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_BLACK));

    gc.fillRoundRectangle(Math.round(x), Math.round(y), Math.round(width), Math.round(height), 5, 5);
    GraphUtils.drawString(gc, title, x, y, width, height, 0);

    if (hasOutgoingCrossLinksInternal || hasOutgoingCrossLinksExternal) {
        Color colorRed = gc.getDevice().getSystemColor(SWT.COLOR_RED);
        gc.setBackground(colorRed);
        gc.setForeground(colorRed);

        int ovalX = Math.round(x + width - SIZE_CROSS_LINKS_MARKER - 2);
        int ovalY = Math.round(y + 2);
        int ovalSize = Math.round(SIZE_CROSS_LINKS_MARKER);
        if (hasOutgoingCrossLinksInternal) {
            gc.fillOval(ovalX, ovalY, ovalSize, ovalSize);
        } else {
            gc.drawOval(ovalX, ovalY, ovalSize, ovalSize);
        }
    }

    gc.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
}
TitleRenderer.java 文件源码 项目:neoscada 阅读 29 收藏 0 点赞 0 评论 0
@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 ();
    }
}
Sleak.java 文件源码 项目:applecommander 阅读 30 收藏 0 点赞 0 评论 0
void refreshLabel () {
    int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0, regions = 0;
    for (int i=0; i<objects.length; i++) {
        Object object = objects [i];
        if (object instanceof Color) colors++;
        if (object instanceof Cursor) cursors++;
        if (object instanceof Font) fonts++;
        if (object instanceof GC) gcs++;
        if (object instanceof Image) images++;
        if (object instanceof Region) regions++;
    }
    String string = ""; //$NON-NLS-1$
    if (colors != 0) string += colors + " Color(s)\n"; //$NON-NLS-1$
    if (cursors != 0) string += cursors + " Cursor(s)\n"; //$NON-NLS-1$
    if (fonts != 0) string += fonts + " Font(s)\n"; //$NON-NLS-1$
    if (gcs != 0) string += gcs + " GC(s)\n"; //$NON-NLS-1$
    if (images != 0) string += images + " Image(s)\n"; //$NON-NLS-1$
    if (regions != 0) string += regions + " Region(s)\n"; //$NON-NLS-1$
    if (string.length () != 0) {
        string = string.substring (0, string.length () - 1);
    }
    label.setText (string);
}
CComboContentAdapter.java 文件源码 项目:Hydrograph 阅读 26 收藏 0 点赞 0 评论 0
public Rectangle getInsertionBounds(Control control) {
    // This doesn't take horizontal scrolling into affect. 
    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=204599
    CCombo combo = (CCombo) control;
    int position = combo.getSelection().y;
    String contents = combo.getText();
    GC gc = new GC(combo);
    gc.setFont(combo.getFont());
    Point extent = gc.textExtent(contents.substring(0, Math.min(position,
            contents.length())));
    gc.dispose();
    if (COMPUTE_TEXT_USING_CLIENTAREA) {
        return new Rectangle(combo.getClientArea().x + extent.x, combo
            .getClientArea().y, 1, combo.getClientArea().height);
    }
    return new Rectangle(extent.x, 0, 1, combo.getSize().y);
}
XCalendarSecondWidget.java 文件源码 项目:xcalendar 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 
 */
@Override
public void render(XCalendarFrame frame) {
    // Background
    final GC gc = frame.getGc();
    final XCalendarModel model = popup.getModel();
    final XCalendarTheme theme = model.getTheme();
    final boolean hovered = this.mouse.isEntered();
    int x = bounds.x, y = bounds.y, w = bounds.width, h = bounds.height;
    gc.setBackground(theme.getBackground(true, false, false, hovered));
    gc.fillRoundRectangle(x, y, w, h, theme.getArc(), theme.getArc());

    // Foreground
    String text = theme.getSecondTheme()[row][col];
    gc.setForeground(theme.getForeground(true, false, true));
    gc.setFont(theme.getFont()); final Point size = extent(gc, text);
    gc.drawText(text, x + 1 + ((w - size.x) >> 1), y + 1 + ((h - size.y) >> 1));
}
SWTX.java 文件源码 项目:convertigo-eclipse 阅读 31 收藏 0 点赞 0 评论 0
public static void drawButtonDeepDown(GC gc, String text, int textAlign,
      Image image, int imageAlign, int x, int y, int w, int h) {
    Display display = Display.getCurrent();
    gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
    gc.drawLine(x, y, x + w - 2, y);
    gc.drawLine(x, y, x, y + h - 2);
    gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
    gc.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
    gc.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
    gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    gc.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
    gc.drawLine(x + w - 2, y + h - 2, x + w - 2, y + 1);
    //
gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
gc.fillRectangle(x + 2, y + 2, w - 4, 1);
gc.fillRectangle(x + 1, y + 2, 2, h - 4);
//
    gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    drawTextImage(gc, text, textAlign, image, imageAlign, x + 2 + 1,
        y + 2 + 1, w - 4, h - 3 - 1);
  }
XCalendarSelectTimeWidget.java 文件源码 项目:xcalendar 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 
 */
@Override
public void render(XCalendarFrame frame) {
    // Background
    final GC gc = frame.getGc();
    final XCalendarModel model = popup.getModel();
    final XCalendarTheme theme = model.getTheme();
    final boolean hovered = this.mouse.isEntered();
    final boolean time = model.getStateMachine().isTime();
    int x = bounds.x, y = bounds.y, w = bounds.width, h = bounds.height;
    gc.setBackground(theme.getBackground(true, false, false, hovered));
    gc.fillRoundRectangle(x, y, w, h, theme.getArc(), theme.getArc());

    // Foreground
    String text = time ? calendar : clock_o;
    gc.setForeground(theme.getToolBarBackground(false));
    gc.setFont(Fonts.getAwesomeFont()); final Point size = extent(gc, text);
    gc.drawText(text, x + 1 + ((w - size.x) >> 1), y + 1 + ((h - size.y) >> 1));
}
KTableCellEditor.java 文件源码 项目:convertigo-eclipse 阅读 32 收藏 0 点赞 0 评论 0
/**
 * 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();
}
ColumnSubscriptionName.java 文件源码 项目:BiglyBT 阅读 26 收藏 0 点赞 0 评论 0
@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);
}
CodeLensViewZone.java 文件源码 项目:codelens-eclipse 阅读 30 收藏 0 点赞 0 评论 0
@Override
public void draw(int paintX, int paintSpaceLeadingX, int paintY, GC gc) {
    StyledText styledText = getTextViewer().getTextWidget();
    Rectangle client = styledText.getClientArea();
    gc.setBackground(styledText.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    styledText.drawBackground(gc, paintX, paintY, client.width, this.getHeightInPx());

    gc.setForeground(styledText.getDisplay().getSystemColor(SWT.COLOR_GRAY));

    Font font = new Font(styledText.getDisplay(), "Arial", 9, SWT.ITALIC);
    gc.setFont(font);
    String text = getText(gc, paintSpaceLeadingX);
    if (text != null) {
        int y = paintY + 4;
        gc.drawText(text, paintSpaceLeadingX, y);

        if (hoveredCodeLensEndX != null) {
            Point extent = gc.textExtent(text);
            gc.drawLine(hoveredCodeLensStartX, y + extent.y - 1, hoveredCodeLensEndX, y + extent.y - 1);
        }
    }
}
LineNumberChangeRulerColumnPatch.java 文件源码 项目:codelens-eclipse 阅读 38 收藏 0 点赞 0 评论 0
@Override
public Object invoke(Object obj, Method thisMethod, Method proceed, Object[] args) throws Throwable {
    if ("createControl".equals(thisMethod.getName())) {
        CompositeRuler parentRuler = (CompositeRuler) args[0];
        this.fCachedTextViewer = parentRuler.getTextViewer();
        this.fCachedTextWidget = fCachedTextViewer.getTextWidget();
    } else if ("setDisplayMode".equals(thisMethod.getName())) {
        this.fCharacterDisplay = (boolean) args[0];
    } else if ("doPaint".equals(thisMethod.getName()) && args.length > 1) {
        GC gc = (GC) args[0];
        ILineRange visibleLines = (ILineRange) args[1];

        if (fRevisionPainter == null) {
            fRevisionPainter = getValue("fRevisionPainter", obj);
            fDiffPainter = getValue("fDiffPainter", obj);
        }

        LineNumberChangeRulerColumn l = ((LineNumberChangeRulerColumn) obj);
        doPaint(gc, visibleLines, l);
        return null;
    }
    return proceed.invoke(obj, args);
}
LineNumberChangeRulerColumnPatch.java 文件源码 项目:codelens-eclipse 阅读 28 收藏 0 点赞 0 评论 0
void doPaint(GC gc, ILineRange visibleLines, LineNumberChangeRulerColumn l) {
    Color foreground = gc.getForeground();
    if (visibleLines != null) {
        if (fRevisionPainter.hasInformation())
            fRevisionPainter.paint(gc, visibleLines);
        else if (fDiffPainter.hasInformation()) // don't paint quick
                                                // diff
                                                // colors if revisions
                                                // are
                                                // painted
            fDiffPainter.paint(gc, visibleLines);
    }
    gc.setForeground(foreground);
    if (l.isShowingLineNumbers() || fCharacterDisplay)
        doPaintPatch(gc, visibleLines, l);
}
ImageCanvasAdapter.java 文件源码 项目:applecommander 阅读 29 收藏 0 点赞 0 评论 0
public void print() {
    final Printer printer = SwtUtil.showPrintDialog(imageCanvas);
    if (printer == null) return;    // Print was cancelled
    new Thread(new Runnable() {
        public void run() {
            printer.startJob(getPrintJobName());
            printer.startPage();
            Point dpi = printer.getDPI();
            Image image = getImageCanvas().getImage();
            int imageWidth = image.getImageData().width;
            int imageHeight = image.getImageData().height;
            int printedWidth = imageWidth * (dpi.x / 96);
            int printedHeight = imageHeight * (dpi.y / 96);
            GC gc = new GC(printer);
            gc.drawImage(image,
                0, 0, imageWidth, imageHeight,
                0, 0, printedWidth, printedHeight);
            printer.endPage();
            printer.endJob();
            gc.dispose();
            printer.dispose();
        }
    }).start();
}
BreadcrumbItem.java 文件源码 项目:SWET 阅读 35 收藏 0 点赞 0 评论 0
private Point computeSizeOfTextAndImages() {
    int width = 0, height = 0;
    final boolean textISNotEmpty = getText() != null && !getText().equals("");

    if (textISNotEmpty) {
        final GC gc = new GC(this.parentBreadcrumb);
        gc.setFont(this.parentBreadcrumb.getFont());
        final Point extent = gc.stringExtent(getText());
        gc.dispose();
        width += extent.x;
        height = extent.y;
    }

    final Point imageSize = computeMaxWidthAndHeightForImages(getImage(),
            this.selectionImage, this.disabledImage);

    if (imageSize.x != -1) {
        width += imageSize.x;
        height = Math.max(imageSize.y, height);
        if (textISNotEmpty) {
            width += MARGIN * 2;
        }
    }
    width += MARGIN;
    return new Point(width, height);
}
DiskExplorerTab.java 文件源码 项目:AppleCommander 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Pre-compute column widths for the file tab.
 * These can and are over-ridden by user sizing.
 */
protected void computeColumnWidths(int format) {
    List headers = disks[0].getFileColumnHeaders(format);
    int[] headerWidths = new int[headers.size()];
    GC gc = new GC(shell);
    for (int i=0; i<headers.size(); i++) {
        FileColumnHeader header = (FileColumnHeader) headers.get(i);
        if (header.getTitle().length() >= header.getMaximumWidth()) {
            headerWidths[i] = gc.stringExtent(header.getTitle()).x + 
                2 * gc.stringExtent(textBundle.get("WidestCharacter")).x;  //$NON-NLS-1$
        } else {
            headerWidths[i] = gc.stringExtent(
                    textBundle.get("WidestCharacter")).x  //$NON-NLS-1$
                    * header.getMaximumWidth();
        }
    }
    gc.dispose();
    gc = null;
    columnWidths.put(new Integer(format), headerWidths);
}
XCalendarClearWidget.java 文件源码 项目:xcalendar 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Render
 */
@Override
public void render(XCalendarFrame frame) {
    // Background
    final GC gc = frame.getGc();
    final XCalendarModel model = popup.getModel();
    final XCalendarTheme theme = model.getTheme();
    final boolean hovered = this.mouse.isEntered();
    int x = bounds.x, y = bounds.y, w = bounds.width, h = bounds.height;
    gc.setBackground(theme.getBackground(true, false, false, hovered));
    gc.fillRoundRectangle(x, y, w, h, theme.getArc(), theme.getArc());

    // Foreground
    String text = trash_o;
    gc.setForeground(theme.getToolBarBackground(false));
    gc.setFont(Fonts.getAwesomeFont()); final Point size = extent(gc, text);
    gc.drawText(text, x + 1 + ((w - size.x) >> 1), y + 1 + ((h - size.y) >> 1));
}
Sleak.java 文件源码 项目:AppleCommander 阅读 32 收藏 0 点赞 0 评论 0
void refreshLabel () {
    int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0, regions = 0;
    for (int i=0; i<objects.length; i++) {
        Object object = objects [i];
        if (object instanceof Color) colors++;
        if (object instanceof Cursor) cursors++;
        if (object instanceof Font) fonts++;
        if (object instanceof GC) gcs++;
        if (object instanceof Image) images++;
        if (object instanceof Region) regions++;
    }
    String string = ""; //$NON-NLS-1$
    if (colors != 0) string += colors + " Color(s)\n"; //$NON-NLS-1$
    if (cursors != 0) string += cursors + " Cursor(s)\n"; //$NON-NLS-1$
    if (fonts != 0) string += fonts + " Font(s)\n"; //$NON-NLS-1$
    if (gcs != 0) string += gcs + " GC(s)\n"; //$NON-NLS-1$
    if (images != 0) string += images + " Image(s)\n"; //$NON-NLS-1$
    if (regions != 0) string += regions + " Region(s)\n"; //$NON-NLS-1$
    if (string.length () != 0) {
        string = string.substring (0, string.length () - 1);
    }
    label.setText (string);
}
TestProgressBar.java 文件源码 项目:n4js 阅读 33 收藏 0 点赞 0 评论 0
/**
 * 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);
    }
}
GraphUtils.java 文件源码 项目:n4js 阅读 32 收藏 0 点赞 0 评论 0
/** Paints an arc from src to tgt using the given control point ctr. */
public static float[] arc(GC gc, Point ctr, Point src, Point tgt) {
    Path path = new Path(gc.getDevice());
    path.moveTo((int) src.x, (int) src.y);
    path.quadTo((int) ctr.x, (int) ctr.y, (int) tgt.x, (int) tgt.y);
    gc.drawPath(path);

    float[] pp = path.getPathData().points;
    return pp;
}
GraphUtils.java 文件源码 项目:n4js 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Paints an arc from src to tgt.
 * <p/>
 * <b>Assumption:</b> The tgt is located below of the src.
 */
public static float[] arcReversed(GC gc, Point src, Point tgt) {
    Path path = new Path(gc.getDevice());
    int ydiff = (int) ((tgt.y - src.y) / 3);
    path.moveTo((int) src.x, (int) src.y);
    path.cubicTo((int) src.x, (int) src.y + ydiff, (int) tgt.x, (int) tgt.y - ydiff * 2, (int) tgt.x, (int) tgt.y);
    gc.drawPath(path);

    float[] pp = path.getPathData().points;
    return pp;
}
GraphUtils.java 文件源码 项目:n4js 阅读 35 收藏 0 点赞 0 评论 0
public static void drawArrowHead(GC gc, Point referencePoint, Point p) {
    final double angle = Math.atan2(p.y - referencePoint.y, p.x - referencePoint.x) * 180.0 / Math.PI;
    final Transform tf = new Transform(gc.getDevice());
    tf.rotate(new Double(angle).floatValue());
    tf.scale(7, 3);
    final float[] pnts = new float[] { -1, 1, -1, -1 };
    tf.transform(pnts);
    gc.drawLine(Math.round(p.x), Math.round(p.y), Math.round(p.x + pnts[0]), Math.round(p.y + pnts[1]));
    gc.drawLine(Math.round(p.x), Math.round(p.y), Math.round(p.x + pnts[2]), Math.round(p.y + pnts[3]));
    tf.dispose();
}


问题


面经


文章

微信
公众号

扫码关注公众号