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

ViewLabelProvider.java 文件源码 项目:convertigo-eclipse 阅读 29 收藏 0 点赞 0 评论 0
public ViewLabelProvider() {
    Device device = Display.getCurrent();

    fontSystem = device.getSystemFont();

    FontData fontData = fontSystem.getFontData()[0];

    fontDetectedDatabaseObject = new Font(device, fontData);

    FontData fontDataModified = fontSystem.getFontData()[0];
    fontDataModified.setStyle(SWT.BOLD);
    fontModifiedDatabaseObject = new Font(device, fontDataModified);

    colorUnloadedProject = new Color(device, 12, 116, 176);
    colorDisabledDatabaseObject = new Color(device, 255, 0, 0);
    colorInheritedDatabaseObject = new Color(device, 150, 150, 150);
    colorUnreachableDatabaseObject = new Color(device, 255, 140, 0);
    colorDetectedDatabaseObject = new Color(device, 192, 219, 207);
}
StyledTextPatcher.java 文件源码 项目:codelens-eclipse 阅读 24 收藏 0 点赞 0 评论 0
private static /* org.eclipse.swt.custom.StyledTextRenderer */ Object createStyledTextRenderer(
        StyledText styledText, ILineSpacingProvider lineSpacingProvider) throws Exception {
    // get the org.eclipse.swt.custom.StyledTextRenderer instance of
    // StyledText
    /* org.eclipse.swt.custom.StyledTextRenderer */ Object originalRenderer = getRendererField(styledText)
            .get(styledText);

    // Create a Javassist proxy
    ProxyFactory factory = new ProxyFactory();
    factory.setSuperclass(originalRenderer.getClass());
    StyledTextRenderer renderer = new StyledTextRenderer(styledText, originalRenderer.getClass());
    renderer.setLineSpacingProvider(lineSpacingProvider);
    factory.setHandler(renderer);
    return factory.create(new Class[] { Device.class, StyledText.class },
            new Object[] { styledText.getDisplay(), styledText });
}
SWTUtils.java 文件源码 项目:parabuild-ci 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Creates a swt color instance to match the rgb values 
 * of the specified awt paint. For now, this method test 
 * if the paint is a color and then return the adequate 
 * swt color. Otherwise plain black is assumed.
 * 
 * @param device The swt device to draw on (display or gc device).
 * @param paint The awt color to match.
 * @return a swt color object.
 */
public static Color toSwtColor(Device device, java.awt.Paint paint) {
    java.awt.Color color;
    if (paint instanceof java.awt.Color) {
        color = (java.awt.Color) paint;
    }
    else {
        try {
            throw new Exception("only color is supported at present... " 
                    + "setting paint to uniform black color" );
        } 
        catch (Exception e) {
            e.printStackTrace();
            color = new java.awt.Color(0, 0, 0);
        }
    }
    return new org.eclipse.swt.graphics.Color(device,
            color.getRed(), color.getGreen(), color.getBlue());
}
ColorCache2.java 文件源码 项目:BiglyBT 阅读 24 收藏 0 点赞 0 评论 0
public static CachedColor
getColor(
    Device      device,
    RGB         rgb )
{
    synchronized( color_map ){

        CachedColorManaged entry = color_map.get( rgb );

        if ( entry == null ){

            entry = new CachedColorManaged( new Color( device, rgb ));

            color_map.put( rgb, entry );

        }else{

            entry.addRef();
        }

        return( new CachedColorManagedFacade( entry ));
    }
}
ColorCache.java 文件源码 项目:BiglyBT 阅读 27 收藏 0 点赞 0 评论 0
/**
 *
 * @since 3.1.1.1
 */
public static Color getColor(Device device, float[] hsb) {
    if (hsb[0] < 0) {
        hsb[0] = 0;
    } else if (hsb[0] > 360) {
        hsb[0] = 360;
    }
    if (hsb[1] < 0) {
        hsb[1] = 0;
    } else if (hsb[1] > 1) {
        hsb[1] = 1;
    }
    if (hsb[2] < 0) {
        hsb[2] = 0;
    } else if (hsb[2] > 1) {
        hsb[2] = 1;
    }
    RGB rgb = new RGB(hsb[0], hsb[1], hsb[2]);
    return getColor(device, rgb.red, rgb.green, rgb.blue);
}
SWTUtils.java 文件源码 项目:ccu-historian 阅读 34 收藏 0 点赞 0 评论 0
/**
 * Creates a swt color instance to match the rgb values
 * of the specified awt paint. For now, this method test
 * if the paint is a color and then return the adequate
 * swt color. Otherwise plain black is assumed.
 *
 * @param device The swt device to draw on (display or gc device).
 * @param paint The awt color to match.
 * @return a swt color object.
 */
public static Color toSwtColor(Device device, java.awt.Paint paint) {
    java.awt.Color color;
    if (paint instanceof java.awt.Color) {
        color = (java.awt.Color) paint;
    }
    else {
        try {
            throw new Exception("only color is supported at present... "
                    + "setting paint to uniform black color");
        }
        catch (Exception e) {
            e.printStackTrace();
            color = new java.awt.Color(0, 0, 0);
        }
    }
    return new org.eclipse.swt.graphics.Color(device,
            color.getRed(), color.getGreen(), color.getBlue());
}
DwContextInformationDialog.java 文件源码 项目:DarwinSPL 阅读 23 收藏 0 点赞 0 评论 0
@Override
public void modifyText(ModifyEvent e) {
    if(onlyNumericTexts.contains(e.getSource())) {
        Text text = (Text) e.getSource();
        String tooltip = "";
        Color background = null;
        if(isNumberic(text.getText())) {
            tooltip = "Only integer values allowed";
            Device device = Display.getCurrent();
            background = new Color(device, 255,0,0);
        }
        else {
            tooltip = "";
        }
        text.setBackground(background);
        text.setToolTipText(tooltip);
    }
}
SWTUtils.java 文件源码 项目:aya-lang 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Creates a swt color instance to match the rgb values
 * of the specified awt paint. For now, this method test
 * if the paint is a color and then return the adequate
 * swt color. Otherwise plain black is assumed.
 *
 * @param device The swt device to draw on (display or gc device).
 * @param paint The awt color to match.
 * @return a swt color object.
 */
public static Color toSwtColor(Device device, java.awt.Paint paint) {
    java.awt.Color color;
    if (paint instanceof java.awt.Color) {
        color = (java.awt.Color) paint;
    }
    else {
        try {
            throw new Exception("only color is supported at present... "
                    + "setting paint to uniform black color");
        }
        catch (Exception e) {
            e.printStackTrace();
            color = new java.awt.Color(0, 0, 0);
        }
    }
    return new org.eclipse.swt.graphics.Color(device,
            color.getRed(), color.getGreen(), color.getBlue());
}
ShapeUtils.java 文件源码 项目:triquetrum 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Converts an AWT based buffered image into an SWT <code>Image</code>. This will always return an <code>Image</code> that has 24 bit depth regardless of the
 * type of AWT buffered image that is passed into the method.
 *
 * @param device
 * @param awtImage
 *          the {@link java.awt.image.BufferedImage} to be converted to an <code>Image</code>
 *          
 * @return an <code>Image</code> that represents the same image data as the AWT <code>BufferedImage</code> type.
 */
public static org.eclipse.swt.graphics.Image toSWT(Device device, BufferedImage awtImage) {
  device = (device!=null) ? device : Display.getCurrent();
  // We can force bitdepth to be 24 bit because BufferedImage getRGB
  // allows us to always retrieve 24 bit data regardless of source color depth.
  PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
  ImageData swtImageData = new ImageData(awtImage.getWidth(), awtImage.getHeight(), 24, palette);
  // Ensure scansize is aligned on 32 bit.
  int scansize = (((awtImage.getWidth() * 3) + 3) * 4) / 4;
  WritableRaster alphaRaster = awtImage.getAlphaRaster();
  byte[] alphaBytes = new byte[awtImage.getWidth()];
  for (int y = 0; y < awtImage.getHeight(); y++) {
    int[] buff = awtImage.getRGB(0, y, awtImage.getWidth(), 1, null, 0, scansize);
    swtImageData.setPixels(0, y, awtImage.getWidth(), buff, 0);
    if (alphaRaster != null) {
      int[] alpha = alphaRaster.getPixels(0, y, awtImage.getWidth(), 1, (int[]) null);
      for (int i = 0; i < awtImage.getWidth(); i++) {
        alphaBytes[i] = (byte) alpha[i];
      }
      swtImageData.setAlphas(0, y, awtImage.getWidth(), alphaBytes, 0);
    }
  }
  return new org.eclipse.swt.graphics.Image(device, swtImageData);
}
DialogLayerViewerToolTip.java 文件源码 项目:mytourbook 阅读 26 收藏 0 点赞 0 评论 0
public DialogLayerViewerToolTip(final ContainerCheckedTreeViewer propViewer) {

        super(propViewer.getTree());

        _propViewer = propViewer;

        _tree = propViewer.getTree();
        _tree.addDisposeListener(new DisposeListener() {
            @Override
            public void widgetDisposed(final DisposeEvent e) {
                onDispose();
            }
        });

        final Device display = _tree.getDisplay();

        _bgColor = display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
        _fgColor = display.getSystemColor(SWT.COLOR_INFO_FOREGROUND);
    }
FontUtils.java 文件源码 项目:OpenSPIFe 阅读 28 收藏 0 点赞 0 评论 0
public FontKey(Device device, String name, int height, int style, FontData[] fontDatas) {
    this.device = device;
    this.name = name;
    this.height = height;
    this.style = style;
    this.fontDatas = fontDatas;

    int fontDataHash = 0;
    if(fontDatas != null) {
        for(FontData fontData : fontDatas) {
            fontDataHash += fontData.hashCode();
        }
    }

    int deviceHashCode = 0;
    if(device != null) {
        deviceHashCode = 0;
    }

    int nameHashCode = 0;
    if(name != null) {
        nameHashCode = name.hashCode();
    }

    this.hashCode = deviceHashCode + nameHashCode + height + style + fontDataHash;
}
SWTUtils.java 文件源码 项目:nabs 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Creates a swt color instance to match the rgb values 
 * of the specified awt paint. For now, this method test 
 * if the paint is a color and then return the adequate 
 * swt color. Otherwise plain black is assumed.
 * 
 * @param device The swt device to draw on (display or gc device).
 * @param paint The awt color to match.
 * @return a swt color object.
 */
public static Color toSwtColor(Device device, java.awt.Paint paint) {
    java.awt.Color color;
    if (paint instanceof java.awt.Color) {
        color = (java.awt.Color) paint;
    }
    else {
        try {
            throw new Exception("only color is supported at present... " 
                    + "setting paint to uniform black color" );
        } 
        catch (Exception e) {
            e.printStackTrace();
            color = new java.awt.Color(0, 0, 0);
        }
    }
    return new org.eclipse.swt.graphics.Color(device,
            color.getRed(), color.getGreen(), color.getBlue());
}
SWTGC.java 文件源码 项目:read-open-source-code 阅读 36 收藏 0 点赞 0 评论 0
public SWTGC(Device device, Point area, int iconsize) {
    this.image = new Image(device, area.x, area.y);
    this.gc = new GC(image);
    this.images = GUIResource.getInstance().getImagesSteps();
    this.iconsize = iconsize;
    this.area = area;

    this.colors = new ArrayList<Color>();
    this.fonts = new ArrayList<Font>();

       this.background     = GUIResource.getInstance().getColorGraph();
       this.black          = GUIResource.getInstance().getColorBlack();
       this.red            = GUIResource.getInstance().getColorRed();
       this.yellow         = GUIResource.getInstance().getColorYellow();
       this.orange         = GUIResource.getInstance().getColorOrange();
       this.green          = GUIResource.getInstance().getColorGreen();
       this.blue           = GUIResource.getInstance().getColorBlue();
       this.magenta        = GUIResource.getInstance().getColorMagenta();
       this.gray           = GUIResource.getInstance().getColorGray();
       this.lightGray      = GUIResource.getInstance().getColorLightGray();
       this.darkGray       = GUIResource.getInstance().getColorDarkGray();

}
ColorCache2.java 文件源码 项目:AcademicTorrents-Downloader 阅读 22 收藏 0 点赞 0 评论 0
public static CachedColor
getColor(
    Device      device,
    RGB         rgb )
{
    synchronized( color_map ){

        CachedColorManaged entry = color_map.get( rgb );

        if ( entry == null ){

            entry = new CachedColorManaged( new Color( device, rgb ));

            color_map.put( rgb, entry );

        }else{

            entry.addRef();
        }

        return( new CachedColorManagedFacade( entry ));
    }
}
ColorCache.java 文件源码 项目:AcademicTorrents-Downloader 阅读 30 收藏 0 点赞 0 评论 0
/**
 * @param display
 * @param hsb
 * @return 
 *
 * @since 3.1.1.1
 */
public static Color getColor(Device device, float[] hsb) {
    if (hsb[0] < 0) {
        hsb[0] = 0;
    } else if (hsb[0] > 360) {
        hsb[0] = 360;
    }
    if (hsb[1] < 0) {
        hsb[1] = 0;
    } else if (hsb[1] > 1) {
        hsb[1] = 1;
    }
    if (hsb[2] < 0) {
        hsb[2] = 0;
    } else if (hsb[2] > 1) {
        hsb[2] = 1;
    }
    RGB rgb = new RGB(hsb[0], hsb[1], hsb[2]);
    return getColor(device, rgb.red, rgb.green, rgb.blue);
}
SWTUtils.java 文件源码 项目:astor 阅读 29 收藏 0 点赞 0 评论 0
/**
 * Creates a swt color instance to match the rgb values
 * of the specified awt paint. For now, this method test
 * if the paint is a color and then return the adequate
 * swt color. Otherwise plain black is assumed.
 *
 * @param device The swt device to draw on (display or gc device).
 * @param paint The awt color to match.
 * @return a swt color object.
 */
public static Color toSwtColor(Device device, java.awt.Paint paint) {
    java.awt.Color color;
    if (paint instanceof java.awt.Color) {
        color = (java.awt.Color) paint;
    }
    else {
        try {
            throw new Exception("only color is supported at present... "
                    + "setting paint to uniform black color");
        }
        catch (Exception e) {
            e.printStackTrace();
            color = new java.awt.Color(0, 0, 0);
        }
    }
    return new org.eclipse.swt.graphics.Color(device,
            color.getRed(), color.getGreen(), color.getBlue());
}
FileImageDescriptor.java 文件源码 项目:gef-gwt 阅读 25 收藏 0 点赞 0 评论 0
public Image createImage(boolean returnMissingImageOnError, Device device) {
    Image img = ImageDescriptorHelper.getInstance()
            .getImage(location, name);
    if (img != null) {
        return img;
    }
    String path = getFilePath();
    if (path == null)
        return createDefaultImage(returnMissingImageOnError, device);
    try {
        return new Image(device, path);
    } catch (SWTException exception) {
        // if we fail try the default way using a stream
    }
    return super.createImage(returnMissingImageOnError, device);
}
ImageDescriptor.java 文件源码 项目:gef-gwt 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Creates and returns a new image descriptor from a URL.
 * 
 * @param url
 *            The URL of the image file.
 * @return a new image descriptor
 */
// public static ImageDescriptor createFromURL(URL url) {
// if (url == null) {
// return getMissingImageDescriptor();
// }
// return new URLImageDescriptor(url);
// }

/*
 * (non-Javadoc)
 * 
 * @see
 * org.eclipse.jface.resource.DeviceResourceDescriptor#createResource(org
 * .eclipse.swt.graphics.Device)
 */
public Object createResource(Device device) throws DeviceResourceException {
    Image result = createImage(false, device);
    if (result == null) {
        throw new DeviceResourceException(this);
    }
    return result;
}
SWTUtils.java 文件源码 项目:group-five 阅读 35 收藏 0 点赞 0 评论 0
/**
 * Creates a swt color instance to match the rgb values
 * of the specified awt paint. For now, this method test
 * if the paint is a color and then return the adequate
 * swt color. Otherwise plain black is assumed.
 *
 * @param device The swt device to draw on (display or gc device).
 * @param paint The awt color to match.
 * @return a swt color object.
 */
public static Color toSwtColor(Device device, java.awt.Paint paint) {
    java.awt.Color color;
    if (paint instanceof java.awt.Color) {
        color = (java.awt.Color) paint;
    }
    else {
        try {
            throw new Exception("only color is supported at present... "
                    + "setting paint to uniform black color");
        }
        catch (Exception e) {
            e.printStackTrace();
            color = new java.awt.Color(0, 0, 0);
        }
    }
    return new org.eclipse.swt.graphics.Color(device,
            color.getRed(), color.getGreen(), color.getBlue());
}
DesignerRepresentation.java 文件源码 项目:birt 阅读 31 收藏 0 点赞 0 评论 0
private void showNullChart( Dimension dSize )
{
    // Display error message for null chart. This behavior is consistent
    // with invalid table.
    String MSG = Messages.getString( "DesignerRepresentation.msg.InvalidChart" ); //$NON-NLS-1$
    logger.log( ILogger.ERROR,
            Messages.getString( "DesignerRepresentation.log.UnableToFind" ) ); //$NON-NLS-1$

    Device dv = Display.getCurrent( );
    Font font = FontManager.getFont( "Dialog", 10, SWT.ITALIC ); //$NON-NLS-1$
    gc.setFont( font );
    FontMetrics fm = gc.getFontMetrics( );
    gc.setForeground( dv.getSystemColor( SWT.COLOR_RED ) );
    gc.setBackground( dv.getSystemColor( SWT.COLOR_WHITE ) );
    gc.fillRectangle( 0, 0, dSize.width - 1, dSize.height - 1 );
    gc.drawRectangle( 0, 0, dSize.width - 1, dSize.height - 1 );
    String[] texts = splitOnBreaks( MSG, font, dSize.width - 10 );
    int y = 5;
    for ( String text : texts )
    {
        gc.drawText( text, 5, y );
        y += fm.getHeight( );
    }
}
PrintProcessor.java 文件源码 项目:neoscada 阅读 33 收藏 0 点赞 0 评论 0
private void drawChart ( final Device device, final GC gc, final double minX, final double maxX, final Calendar startTimestamp, final Calendar endTimestamp )
{
    final Rectangle bounds = device.getBounds ();

    final Color color = new Color ( device, new RGB ( 0, 0, 0 ) );

    final Rectangle drawBounds = new Rectangle ( bounds.x + 10, bounds.y + 10, bounds.width - 20, bounds.height - 20 );
    gc.setForeground ( color );
    gc.drawRectangle ( drawBounds );

    for ( final Map.Entry<String, List<Double>> row : this.values.entrySet () )
    {
        drawRow ( device, gc, row.getKey (), row.getValue (), drawBounds, minX, maxX );
    }
}
PrintProcessor.java 文件源码 项目:neoscada 阅读 25 收藏 0 点赞 0 评论 0
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;
        }
    }
}
GLView.java 文件源码 项目:avoCADo 阅读 28 收藏 0 点赞 0 评论 0
private void glInit(){
    glContext.makeCurrent();
    gl = glContext.getGL ();
    glu = new GLU();

    gl.glClearColor(AvoColors.GL_COLOR4_BACKGND[0],AvoColors.GL_COLOR4_BACKGND[1],
            AvoColors.GL_COLOR4_BACKGND[2],AvoColors.GL_COLOR4_BACKGND[3]);
    gl.glColor3f(1.0f, 0.0f, 0.0f);
    gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
    gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);     
    gl.glEnable(GL.GL_BLEND);
    gl.glEnable(GL.GL_AUTO_NORMAL);
    gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE);
    gl.glEnable(GL.GL_COLOR_MATERIAL);  // override material properties, makes coloring easier & faster
    gl.glEnable(GL.GL_LINE_SMOOTH); // smooth rendering of lines
    gl.glClearDepth(1.0);
    gl.glClearStencil(0);
    gl.glLineWidth(2.0f);
    gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glEnable(GL.GL_SHADE_MODEL);
    gl.glShadeModel(GL.GL_SMOOTH);
    gl.glDepthFunc(GL.GL_LEQUAL);

    doProceduralShading(gl);

    configureGLLighting(gl);            

    glContext.release();

    Device.DEBUG = true;
}
ColorCache.java 文件源码 项目:BiglyBT 阅读 24 收藏 0 点赞 0 评论 0
/**
 *
 * @since 3.0.4.3
 */
public static Color getColor(Device device, int[] rgb) {
    if (rgb == null || rgb.length < 3) {
        return null;
    }
    return getColor(device, rgb[0], rgb[1], rgb[2]);
}
Colors.java 文件源码 项目:BiglyBT 阅读 28 收藏 0 点赞 0 评论 0
public static Color getSystemColor (Device d, int id) {
    if (Utils.isGTK3) {
        if (id == SWT.COLOR_INFO_BACKGROUND) {
            return ColorCache.getColor(d, 0, 0,0 );
        }
        if (id == SWT.COLOR_INFO_FOREGROUND) {
            return ColorCache.getColor(d, 255, 255,255 );
        }
    }
    return d.getSystemColor(id);
}
SWTUtils.java 文件源码 项目:ccu-historian 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Create an awt font by converting as much information
 * as possible from the provided swt <code>FontData</code>.
 * <p>Generally speaking, given a font size, an swt font will
 * display differently on the screen than the corresponding awt
 * one. Because the SWT toolkit use native graphical ressources whenever
 * it is possible, this fact is platform dependent. To address
 * this issue, it is possible to enforce the method to return
 * an awt font with the same height as the swt one.
 *
 * @param device The swt device being drawn on (display or gc device).
 * @param fontData The swt font to convert.
 * @param ensureSameSize A boolean used to enforce the same size
 * (in pixels) between the swt font and the newly created awt font.
 * @return An awt font converted from the provided swt font.
 */
public static java.awt.Font toAwtFont(Device device, FontData fontData,
        boolean ensureSameSize) {
    int height = (int) Math.round(fontData.getHeight() * device.getDPI().y
            / 72.0);
    // hack to ensure the newly created awt fonts will be rendered with the
    // same height as the swt one
    if (ensureSameSize) {
        GC tmpGC = new GC(device);
        Font tmpFont = new Font(device, fontData);
        tmpGC.setFont(tmpFont);
        JPanel DUMMY_PANEL = new JPanel();
        java.awt.Font tmpAwtFont = new java.awt.Font(fontData.getName(),
                fontData.getStyle(), height);
        if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                > tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    > tmpGC.textExtent(Az).x) {
                height--;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        else if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                < tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    < tmpGC.textExtent(Az).x) {
                height++;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        tmpFont.dispose();
        tmpGC.dispose();
    }
    return new java.awt.Font(fontData.getName(), fontData.getStyle(),
            height);
}
GuiIconDescription.java 文件源码 项目:libraries 阅读 21 收藏 0 点赞 0 评论 0
public GuiIconDescription(
  final Device device,
  final IConstant constant,
  final File smallIcon,
  final File mediumIcon,
  final File largeIcon,
  final String source) {
  this.device = device;
  this.constant = constant;
  this.smallIcon = smallIcon;
  this.mediumIcon = mediumIcon;
  this.largeIcon = largeIcon;
  this.source = source;
}
UpdateRunner.java 文件源码 项目:libraries 阅读 21 收藏 0 点赞 0 评论 0
public UpdateRunner(
  final ICanceler canceler,
  final Device device,
  final WritableList<IGuiIconDescription> descriptions,
  final IJavaProject... projects) {
  this.device = device;
  this.descriptions = descriptions;
  this.projects = projects;
  this.canceler = canceler;
}
SWTUtils.java 文件源码 项目:aya-lang 阅读 34 收藏 0 点赞 0 评论 0
/**
 * Create an awt font by converting as much information
 * as possible from the provided swt <code>FontData</code>.
 * <p>Generally speaking, given a font size, an swt font will
 * display differently on the screen than the corresponding awt
 * one. Because the SWT toolkit use native graphical ressources whenever
 * it is possible, this fact is platform dependent. To address
 * this issue, it is possible to enforce the method to return
 * an awt font with the same height as the swt one.
 *
 * @param device The swt device being drawn on (display or gc device).
 * @param fontData The swt font to convert.
 * @param ensureSameSize A boolean used to enforce the same size
 * (in pixels) between the swt font and the newly created awt font.
 * @return An awt font converted from the provided swt font.
 */
public static java.awt.Font toAwtFont(Device device, FontData fontData,
        boolean ensureSameSize) {
    int height = (int) Math.round(fontData.getHeight() * device.getDPI().y
            / 72.0);
    // hack to ensure the newly created awt fonts will be rendered with the
    // same height as the swt one
    if (ensureSameSize) {
        GC tmpGC = new GC(device);
        Font tmpFont = new Font(device, fontData);
        tmpGC.setFont(tmpFont);
        JPanel DUMMY_PANEL = new JPanel();
        java.awt.Font tmpAwtFont = new java.awt.Font(fontData.getName(),
                fontData.getStyle(), height);
        if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                > tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    > tmpGC.textExtent(Az).x) {
                height--;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        else if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                < tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    < tmpGC.textExtent(Az).x) {
                height++;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        tmpFont.dispose();
        tmpGC.dispose();
    }
    return new java.awt.Font(fontData.getName(), fontData.getStyle(),
            height);
}
Fonts.java 文件源码 项目:TranskribusSwtGui 阅读 31 收藏 0 点赞 0 评论 0
/**
 * Create an awt font by converting as much information
 * as possible from the provided swt <code>FontData</code>.
 * <p>Generally speaking, given a font size, an swt font will
 * display differently on the screen than the corresponding awt
 * one. Because the SWT toolkit use native graphical ressources whenever
 * it is possible, this fact is platform dependent. To address
 * this issue, it is possible to enforce the method to return
 * an awt font with the same height as the swt one.
 *
 * @param device The swt device being drawn on (display or gc device).
 * @param fontData The swt font to convert.
 * @param ensureSameSize A boolean used to enforce the same size
 * (in pixels) between the swt font and the newly created awt font.
 * @return An awt font converted from the provided swt font.
 */
public static java.awt.Font toAwtFont(Device device, FontData fontData,
        boolean ensureSameSize) {
    int height = (int) Math.round(fontData.getHeight() * device.getDPI().y
            / 72.0);
    // hack to ensure the newly created awt fonts will be rendered with the
    // same height as the swt one
    if (ensureSameSize) {
        GC tmpGC = new GC(device);
        Font tmpFont = new Font(device, fontData);
        tmpGC.setFont(tmpFont);
        JPanel DUMMY_PANEL = new JPanel();
        java.awt.Font tmpAwtFont = new java.awt.Font(fontData.getName(),
                fontData.getStyle(), height);
        if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                > tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    > tmpGC.textExtent(Az).x) {
                height--;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        else if (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                < tmpGC.textExtent(Az).x) {
            while (DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(Az)
                    < tmpGC.textExtent(Az).x) {
                height++;
                tmpAwtFont = new java.awt.Font(fontData.getName(),
                        fontData.getStyle(), height);
            }
        }
        tmpFont.dispose();
        tmpGC.dispose();
    }
    return new java.awt.Font(fontData.getName(), fontData.getStyle(),
            height);
}


问题


面经


文章

微信
公众号

扫码关注公众号