Java 类org.eclipse.swt.graphics.Device 实例源码

项目:convertigo-eclipse    文件:ViewLabelProvider.java   
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);
}
项目:codelens-eclipse    文件:StyledTextPatcher.java   
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 });
}
项目:parabuild-ci    文件:SWTUtils.java   
/**
 * 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());
}
项目:BiglyBT    文件:ColorCache2.java   
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 ));
    }
}
项目:BiglyBT    文件:ColorCache.java   
/**
 *
 * @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);
}
项目:ccu-historian    文件:SWTUtils.java   
/**
 * 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());
}
项目:DarwinSPL    文件:DwContextInformationDialog.java   
@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);
    }
}
项目:aya-lang    文件:SWTUtils.java   
/**
 * 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());
}
项目:triquetrum    文件:ShapeUtils.java   
/**
 * 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);
}
项目:mytourbook    文件:DialogLayerViewerToolTip.java   
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);
    }
项目:OpenSPIFe    文件:FontUtils.java   
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;
}
项目:nabs    文件:SWTUtils.java   
/**
 * 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());
}
项目:read-open-source-code    文件:SWTGC.java   
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();

}
项目:AcademicTorrents-Downloader    文件:ColorCache2.java   
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 ));
    }
}
项目:AcademicTorrents-Downloader    文件:ColorCache.java   
/**
 * @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);
}
项目:astor    文件:SWTUtils.java   
/**
 * 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());
}
项目:gef-gwt    文件:FileImageDescriptor.java   
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);
}
项目:gef-gwt    文件:ImageDescriptor.java   
/**
 * 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;
}
项目:group-five    文件:SWTUtils.java   
/**
 * 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());
}
项目:birt    文件:DesignerRepresentation.java   
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( );
    }
}
项目:neoscada    文件:PrintProcessor.java   
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 );
    }
}
项目:neoscada    文件:PrintProcessor.java   
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;
        }
    }
}
项目:avoCADo    文件:GLView.java   
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;
}
项目:BiglyBT    文件:ColorCache.java   
/**
 *
 * @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]);
}
项目:BiglyBT    文件:Colors.java   
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);
}
项目:ccu-historian    文件:SWTUtils.java   
/**
 * 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);
}
项目:libraries    文件:GuiIconDescription.java   
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;
}
项目:libraries    文件:UpdateRunner.java   
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;
}
项目:aya-lang    文件:SWTUtils.java   
/**
 * 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);
}
项目:TranskribusSwtGui    文件:Fonts.java   
/**
 * 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);
}
项目:yamcs-studio    文件:ThemeColorBlock.java   
public ThemeColorBlock(StyleDefinition def, Device device, ResourceManager resourceManager) {
    this.def = def;
    for (ThemeColor color : def.getColors()) {
        RGB rgb = color.getRGB();
        if (!colorMap.containsKey(rgb)) {
            colorMap.put(rgb, resourceManager.createColor(rgb));
        }
    }

    upImage = resourceManager.createImage(RCPUtils.getImageDescriptor(ThemeColorBlock.class, "icons/up.gif"));
    downImage = resourceManager.createImage(RCPUtils.getImageDescriptor(ThemeColorBlock.class, "icons/down.gif"));
}
项目:yamcs-studio    文件:StyleEditor.java   
private StyleDefinition loadData(Device device) {
    try {
        return StyleDefinition.from(input.getFile().getContents());
    } catch (IOException | CoreException e) {
        log.log(Level.SEVERE, "Could not read style definition", e);
        return null;
    }
}
项目:triquetrum    文件:RGBAColorDescriptor.java   
@Override
public Color createColor(Device device) {
  // If this descriptor is wrapping an existing color, then we can return the original color
  // if this is the same device.
  if (originalColor != null) {
    // If we're allocating on the same device as the original color, return the original.
    if (originalColor.getDevice() == device) {
      return originalColor;
    }
  }

  return new Color(device, color);
}
项目:raptor-chess-interface    文件:RaptorImageRegistry.java   
@Override
public Object createResource(Device device)
        throws DeviceResourceException {
    if (device == originalDisplay) {
        refCount++;
        return original;
    }
    return super.createResource(device);
}
项目:raptor-chess-interface    文件:RaptorImageRegistry.java   
/**
 * Creates an empty image registry using the given resource manager to
 * allocate images.
 * 
 * @param manager
 *            the resource manager used to allocate images
 * 
 * @since 3.1
 */
public RaptorImageRegistry(ResourceManager manager) {
    Assert.isNotNull(manager);
    Device dev = manager.getDevice();
    if (dev instanceof Display) {
        display = (Display) dev;
    }
    this.manager = manager;
    manager.disposeExec(disposeRunnable);
}
项目:PDFReporter-Studio    文件:CommunityAPIUtils.java   
private static String tryCreateMozilla() {
    if (EnvironmentUtils.IS_LINUX) {
        boolean oldDebug = Device.DEBUG;
        Device.DEBUG = true;
        PrintStream oldOut = System.out;
        Shell shell = null;
        PrintStream newOut = null;
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            newOut = new PrintStream(baos);
            // replace the out since the Mozilla output debug results into
            // stdout.
            System.setOut(newOut);
            shell = new Shell();
            try {
                new Browser(shell, SWT.NONE);
            } catch (Throwable e) {
                UIUtils.showError(e);
            }
            return baos.toString();
        } catch (Throwable e1) {
            // ignore
        } finally {
            if (shell != null) {
                shell.dispose();
            }
            System.setOut(oldOut);
            IOUtils.closeQuietly(newOut);
            Device.DEBUG = oldDebug;
        }
    }
    return ""; //$NON-NLS-1$
}
项目:gama    文件:GraphicsHelper.java   
/**
 * 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(final Device device, final 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 (final 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());
}
项目:durian-swt    文件:SwtMisc.java   
/** Returns the Display instance, asserting that the method was called from the UI thread. */
public static Display assertUI() {
    // returns the system display, creating it if necessary
    synchronized (Device.class) {
        // Display.getDefault() and display.getThread() both synchronize on
        // Device.class.  By synchronizing ourselves, we minimize contention
        Display display = Display.getDefault();
        Preconditions.checkArgument(display.getThread() == Thread.currentThread(), "Must be called only from UI thread");
        return display;
    }
}
项目:mytourbook    文件:ChartLayerPhoto.java   
@Override
public void drawOverlay(final GC gcOverlay, final GraphDrawingData graphDrawingData) {

    if (_hoveredPaintGroup == null) {
        return;
    }

    final Device display = gcOverlay.getDevice();

    gcOverlay.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
    gcOverlay.setBackground(getPhotoGroupBackgroundColor(_hoveredPhotoCategory.photoType, true));

    drawPhotoAndGroup(gcOverlay, _hoveredPaintGroup, _hoveredPhotoCategory);
}
项目:mytourbook    文件:ColorUtil.java   
public static org.eclipse.swt.graphics.Color getContrastColor(final Device device, final int rgbValue) {

        final byte blue = (byte) ((rgbValue & 0xFF0000) >> 16);
        final byte green = (byte) ((rgbValue & 0xFF00) >> 8);
        final byte red = (byte) ((rgbValue & 0xFF) >> 0);

        return getContrastColor(device, red & 0xFF, green & 0xFF, blue & 0xFF);
    }