org.eclipse.swt.graphics.Font Java Examples

The following examples show how to use org.eclipse.swt.graphics.Font. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyntaxColorerPreviewer.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
public SyntaxColorerPreviewer(Composite parent, final IPreferenceStore preferenceStore) {
     super(parent, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
     this.preferenceStore = preferenceStore;
     this.setLayoutData(new GridData(GridData.FILL_BOTH));
     
     Font font= JFaceResources.getTextFont();
     this.setFont(font);
     
     defBackgroundColor = getEditorBackgroundColor(preferenceStore);
     this.setBackground(defBackgroundColor);
     
     prefListener = new IPropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent event) {
	try { // Widget may be disposed here
	    defBackgroundColor = getEditorBackgroundColor(preferenceStore);
              setBackground(defBackgroundColor);
              updateColors();
       } catch (Exception e) {} 
}
     };
     
     preferenceStore.addPropertyChangeListener(prefListener);
     
     tokenManager = new TokenManager();
 }
 
Example #2
Source File: ThemeUIComposite.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private void setDefaultFont(Font newFont) {
	String[] fontIds = { "org.eclipse.jface.textfont",
			"org.eclipse.ui.workbench.texteditor.blockSelectionModeFont" };
	FontData[] newData = newFont.getFontData();
	for (String fontId : fontIds) {
		setFont(fontId, newData);
	}

	newData = newFont.getFontData();
	FontData[] smaller = new FontData[newData.length];
	int j = 0;
	for (FontData fd : newData) {
		int height = fd.getHeight();
		if (height >= 12) {
			fd.setHeight(height - 2);
		} else if (height >= 10) {
			fd.setHeight(height - 1);
		}
		smaller[(j++)] = fd;
	}
	setFont("com.aptana.explorer.font", smaller);
}
 
Example #3
Source File: EnterOptionsDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void getData() {
  fixedFontData = props.getFixedFont();
  fixedFont = new Font( display, fixedFontData );

  graphFontData = props.getGraphFont();
  graphFont = new Font( display, graphFontData );

  noteFontData = props.getNoteFont();
  noteFont = new Font( display, noteFontData );

  backgroundRGB = props.getBackgroundRGB();
  if ( backgroundRGB == null ) {
    backgroundRGB = display.getSystemColor( SWT.COLOR_WIDGET_BACKGROUND ).getRGB();
  }
  background = new Color( display, backgroundRGB );

  graphColorRGB = props.getGraphColorRGB();
  graphColor = new Color( display, graphColorRGB );

  tabColorRGB = props.getTabColorRGB();
  tabColor = new Color( display, tabColorRGB );
}
 
Example #4
Source File: Sleak.java    From swt-bling with MIT License 6 votes vote down vote up
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 = "";
  if (colors != 0) string += colors + " Color(s)\n";
  if (cursors != 0) string += cursors + " Cursor(s)\n";
  if (fonts != 0) string += fonts + " Font(s)\n";
  if (gcs != 0) string += gcs + " GC(s)\n";
  if (images != 0) string += images + " Image(s)\n";
  /* Currently regions are not counted. */
  //  if (regions != 0) string += regions + " Region(s)\n";
  if (string.length () != 0) {
    string = string.substring (0, string.length () - 1);
  }
  label.setText (string);
}
 
Example #5
Source File: TypeScriptTemplatePreferencePage.java    From typescript.java with MIT License 6 votes vote down vote up
protected SourceViewer createViewer(Composite parent) {
	IDocument document= new Document();
	JavaScriptTextTools tools= JSDTTypeScriptUIPlugin.getDefault().getJavaTextTools();
	tools.setupJavaDocumentPartitioner(document, IJavaScriptPartitions.JAVA_PARTITIONING);
	IPreferenceStore store= JSDTTypeScriptUIPlugin.getDefault().getCombinedPreferenceStore();
	SourceViewer viewer= new JavaSourceViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, store);
	SimpleJavaSourceViewerConfiguration configuration= new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaScriptPartitions.JAVA_PARTITIONING, false);
	viewer.configure(configuration);
	viewer.setEditable(false);
	viewer.setDocument(document);

	Font font= JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT);
	viewer.getTextWidget().setFont(font);
	new TypeScriptSourcePreviewerUpdater(viewer, configuration, store);
	
	Control control= viewer.getControl();
	GridData data= new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_VERTICAL);
	control.setLayoutData(data);
	
	return viewer;
}
 
Example #6
Source File: JavaCamelJobScriptsExportWSWizardPage.java    From tesb-studio-se with Apache License 2.0 6 votes vote down vote up
@Override
public void createOptions(final Composite optionsGroup, Font font) {
    optionsGroupComposite = optionsGroup;
    optionsGroupFont = font;

    createOptionsForKar(optionsGroup, font);
    // createOptionForDockerImage(optionsGroup, font);

    if ("ROUTE_MICROSERVICE".equals(
            getProcessItem().getProperty().getAdditionalProperties().get(TalendProcessArgumentConstant.ARG_BUILD_TYPE))) {
        createDockerOptions(optionsGroup);
        restoreWidgetValuesForImage();
    }

    restoreWidgetValuesForKar();
}
 
Example #7
Source File: CalendarComposite.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void drawChartOntoGC(GC gc) {
	Rectangle bounds = super.getBounds();
	gc.setBackground(mColorManager.getCalendarBackgroundColor());
	gc.fillRectangle(bounds);

	Font used = null;
	if (CalendarCombo.OS_CARBON) {
		used = mSettings.getCarbonDrawFont();
		if (used != null)
			gc.setFont(used);
	}

	// header
	drawHeader(gc);
	// day titles
	drawTitleDays(gc);
	// days
	drawDays(gc);
	// 1 pixel border
	drawBorder(gc);

	gc.dispose();
	if (used != null)
		used.dispose();
}
 
Example #8
Source File: MenuDataDialog.java    From EasyShell with Eclipse Public License 2.0 5 votes vote down vote up
private void createRemoveButton(Composite parent) {
    Font font = parent.getFont();
    removeButton = new Button(parent, SWT.PUSH);
    removeButton.setText(Activator.getResourceString("easyshell.menu.editor.dialog.button.text.remove"));
    removeButton.setToolTipText(Activator.getResourceString("easyshell.menu.editor.dialog.button.tooltip.remove"));
    removeButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            removeDialog();
        }
    });
    removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    removeButton.setFont(font);
    setButtonLayoutData(removeButton);
}
 
Example #9
Source File: SnippetGalleryViewerTester.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public Font getFont(Object element) {
	String label = (String) element;
	if (Integer.parseInt(label.substring(label.indexOf(' ') + 1)) % 2 > 0) {
		return null;
	} else {
		FontData sysFontData = Display.getCurrent().getSystemFont().getFontData()[0];
		sysFontData.setStyle(SWT.BOLD | SWT.ITALIC);
		return new Font(Display.getCurrent(), sysFontData);
	}
}
 
Example #10
Source File: ReportDocumentEditor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private Composite createComposite( Composite parent, Font font,
		int columns, int hspan, int fill, int marginwidth, int marginheight )
{
	Composite g = new Composite( parent, SWT.NONE );
	GridLayout layout = new GridLayout( columns, false );
	layout.marginWidth = marginwidth;
	layout.marginHeight = marginheight;
	g.setLayout( layout );
	g.setFont( font );
	GridData gd = new GridData( fill );
	gd.horizontalSpan = hspan;
	g.setLayoutData( gd );
	return g;
}
 
Example #11
Source File: TextAttributeProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected TextAttribute createTextAttribute(String id, TextStyle defaultTextStyle) {
	TextStyle textStyle = new TextStyle();
	preferencesAccessor.populateTextStyle(id, textStyle, defaultTextStyle);
	int style = textStyle.getStyle();
	Font fontFromFontData = EditorUtils.fontFromFontData(textStyle.getFontData());
	return new TextAttribute(EditorUtils.colorFromRGB(textStyle.getColor()), EditorUtils.colorFromRGB(textStyle
			.getBackgroundColor()), style, fontFromFontData);
}
 
Example #12
Source File: DataItemCombo.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void setFont( Font font )
{
	super.setFont( font );
	this.font = font;
	text.setFont( font );
	list.setFont( font );
	internalLayout( true );
}
 
Example #13
Source File: ScriptMainTab.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void buildTempFolder( Composite parentG )
{
	Font font = parentG.getFont( );
	Group tempFolderGroup = ScriptSWTFactory.createGroup( parentG,
			Messages.getString( "ScriptMainTab.msg.temp.folder" ), //$NON-NLS-1$
			2,
			1,
			GridData.FILL_HORIZONTAL );
	Composite folder = ScriptSWTFactory.createComposite( tempFolderGroup,
			font,
			3,
			2,
			GridData.FILL_BOTH,
			0,
			0 );
	fTempFolder = ScriptSWTFactory.createSingleText( folder, 1 );
	fTempFolder.addModifyListener( modifyListener );

	Button forderSearchButton = createPushButton( folder,
			Messages.getString( "ScriptMainTab.button.text.search" ), //$NON-NLS-1$
			null );

	forderSearchButton.addSelectionListener( new SelectionAdapter( ) {

		public void widgetSelected( SelectionEvent e )
		{
			IPath chosen = chooseDropLocation( Messages.getString( "ScriptMainTab.title.temp.folder" ), //$NON-NLS-1$
					Messages.getString( "ScriptMainTab.msg.select.temp.folder" ), //$NON-NLS-1$
					fTempFolder.getText( ) );
			if ( chosen != null )
				fTempFolder.setText( chosen.toOSString( ) );
		}
	} );

	createVariableButton( folder,
			Messages.getString( "ScriptMainTab.button.text.variables" ), //$NON-NLS-1$ 
			fTempFolder );
}
 
Example #14
Source File: AdaptedDataVisualizer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @see org.eclipse.nebula.widgets.grid.DataVisualizer#setDefaultFont(org.eclipse.swt.graphics.Font)
 */
@Override
public void setDefaultFont(Font defaultFont) {
	/**
	 * Is empty
	 */
}
 
Example #15
Source File: ExcelExporter.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
private String getFontInCSSFormat(Font font) {
	FontData fontData = font.getFontData()[0];
	String fontName = fontData.getName();
	int fontStyle = fontData.getStyle();
	String HTML_STYLES[] = new String[] { "NORMAL", "BOLD", "ITALIC" };

	return String.format("font: %s; font-family: %s",
	                     fontStyle <= 2 ? HTML_STYLES[fontStyle] : HTML_STYLES[0],
	                     fontName);
}
 
Example #16
Source File: LaunchConfigurationMainTab.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
 **/
@Override
public void createControl(Composite parent) {
	Font font = parent.getFont();
	Composite comp = createComposite(parent, font, 1, 1, GridData.FILL_BOTH);
	createFileGroup(comp);
	setControl(comp);

}
 
Example #17
Source File: ConcordanceSearchDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
private TextStyle createResultsStyle() {
	background = new Color(Display.getCurrent(), 0x19, 0x19, 0x70);
	foreground = new Color(Display.getCurrent(), 0xff, 0xff, 0xff);
	FontData fontData = JFaceResources.getDefaultFont().getFontData()[0];
	fontData.setStyle(fontData.getStyle());
	rsFont = new Font(Display.getDefault(), fontData);
	TextStyle style = new TextStyle(rsFont, foreground, background);
	return style;
}
 
Example #18
Source File: TableComboViewerSnippet1.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
public Font getFont(Object element, int index) {
	Model item = (Model)element;
	
	if (item.getId() == 1 || item.getId() == 15 || 
		item.getId() == 5 || item.getId() == 20 ||
		item.getId() == 10) {
		return boldFont;
	}
	else {
		return null;
	}			
}
 
Example #19
Source File: SWTUtils.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #20
Source File: AppEngineTemplatePage.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets the font and the grid data for some control.
 */
private void setFillHorizontalLayoutDataAndFont(Control control, Font font) {
    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    control.setLayoutData(data);
    control.setFont(font);
}
 
Example #21
Source File: GridItem_Test.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testClear() {
  GridItem item = new GridItem( grid, SWT.NONE );
  Font font = new Font( display, "Arial", 20, SWT.BOLD );
  Color background = new Color( display, 0, 255, 0 );
  Color foreground = new Color( display, 0, 0, 255 );
  item.setFont( font );
  item.setBackground( background );
  item.setForeground( foreground );
  grid.clear( 0, false );
  assertSame( grid.getFont(), item.getFont() );
  assertSame( grid.getBackground(), item.getBackground() );
  assertSame( grid.getForeground(), item.getForeground() );
}
 
Example #22
Source File: Axis.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setFont(Font font) {
	if (font == null)
		return;
	super.setFont(font);
	this.scaleFontData = getFont().getFontData()[0];
}
 
Example #23
Source File: WizardFileSystemResourceExportPage2.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the export destination specification widgets
 * @param parent
 *            org.eclipse.swt.widgets.Composite
 */
protected void createDestinationGroup(Composite parent) {

	Font font = parent.getFont();
	// destination specification group
	Composite destinationSelectionGroup = new Composite(parent, SWT.NONE);
	GridLayout layout = new GridLayout();
	layout.numColumns = 3;
	destinationSelectionGroup.setLayout(layout);
	destinationSelectionGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL
			| GridData.VERTICAL_ALIGN_FILL));
	destinationSelectionGroup.setFont(font);

	Label destinationLabel = new Label(destinationSelectionGroup, SWT.NONE);
	destinationLabel.setText(getDestinationLabel());
	destinationLabel.setFont(font);

	// destination name entry field
	destinationNameField = new Text(destinationSelectionGroup, SWT.BORDER);
	destinationNameField.addListener(SWT.Modify, this);
	destinationNameField.addListener(SWT.Selection, this);
	GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
	data.widthHint = SIZING_TEXT_FIELD_WIDTH;
	destinationNameField.setLayoutData(data);
	destinationNameField.setFont(font);

	// destination browse button
	destinationBrowseButton = new Button(destinationSelectionGroup, SWT.PUSH);
	destinationBrowseButton.setText(DataTransferMessages.DataTransfer_browse);
	destinationBrowseButton.addListener(SWT.Selection, this);
	destinationBrowseButton.setFont(font);
	setButtonLayoutData(destinationBrowseButton);

	new Label(parent, SWT.NONE); // vertical spacer
}
 
Example #24
Source File: ModelLabelProvider.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Font getFont(Object element) {
  if (element instanceof IModelNode) {
    IModelNode modelNode = (IModelNode) element;
    if (modelNode.isTerminated()) {
      return JFaceResources.getFontRegistry().getItalic(
          JFaceResources.DEFAULT_FONT);
    }
  }
  return null;
}
 
Example #25
Source File: ColorStyler.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private Font getFont() {
	if (font != null)
		return font;
	FontDescriptor desc = FontDescriptor.createFrom(
			Display.getCurrent().getSystemFont()).setStyle(SWT.ITALIC);
	font = desc.createFont(Display.getCurrent());
	return font;
}
 
Example #26
Source File: TextPainterWithPadding.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
private Font getFont(int style) {
	Device device = Display.getDefault();
	switch (style) {
	case SWT.BOLD:
		return new Font(device, getFontData(style));
	case SWT.ITALIC:
		return new Font(device, getFontData(style));
	case SWT.BOLD | SWT.ITALIC:
		return new Font(device, getFontData(style));
	default:
		return font;
	}

}
 
Example #27
Source File: CommandPage.java    From EasyShell with Eclipse Public License 2.0 5 votes vote down vote up
private void createCopyButton(Font font, GridData gridData, Composite groupComponent) {
    addCopyButton = new Button(groupComponent, SWT.PUSH);
    addCopyButton.setText(Activator.getResourceString("easyshell.command.page.button.text.copy"));
    addCopyButton.setToolTipText(Activator.getResourceString("easyshell.command.page.button.tooltip.copy"));
    addCopyButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            addCopyDialog();
        }
    });
    addCopyButton.setLayoutData(gridData);
    addCopyButton.setFont(font);
    setButtonLayoutData(addCopyButton);
}
 
Example #28
Source File: SWTUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the default small font from the JFace font registry.
 * 
 * @return default small font
 */
public static Font getDefaultSmallFont()
{
	Font small = JFaceResources.getFontRegistry().get(SMALL_FONT);
	if (small != null)
	{
		return small;
	}

	Font f = JFaceResources.getDefaultFont();
	FontData[] smaller = resizeFont(f, -2);
	JFaceResources.getFontRegistry().put(SMALL_FONT, smaller);
	return JFaceResources.getFontRegistry().get(SMALL_FONT);
}
 
Example #29
Source File: DefaultGalleryGroupRenderer.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Set the font for drawing the group title or <tt>null</tt> to use system
 * font.
 * 
 * @param font
 *            the font to set
 */
public void setFont(Font font) {
	if (this.font != font) {
		this.font = font;
		if (getGallery() != null)
			getGallery().redraw();
	}
}
 
Example #30
Source File: SWTFactory.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a Composite widget
 * @param parent the parent composite to add this composite to
 * @param font the font to set on the control
 * @param columns the number of columns within the composite
 * @param hspan the horizontal span the composite should take up on the parent
 * @param fill the style for how this composite should fill into its parent
 * @param marginwidth the width of the margin to place on the sides of the composite (default is 5, specified by GridLayout)
 * @param marginheight the height of the margin to place o the top and bottom of the composite
 * @return the new composite
 * @since 3.3
 */
public static Composite createComposite(Composite parent, Font font, int columns, int hspan, int fill, int marginwidth, int marginheight) {
	Composite g = new Composite(parent, SWT.NONE);
	GridLayout layout = new GridLayout(columns, false);
	layout.marginWidth = marginwidth;
	layout.marginHeight = marginheight;
   	g.setLayout(layout);
   	g.setFont(font);
   	GridData gd = new GridData(fill);
	gd.horizontalSpan = hspan;
   	g.setLayoutData(gd);
   	return g;
}