Java Code Examples for org.eclipse.swt.graphics.FontData#getName()

The following examples show how to use org.eclipse.swt.graphics.FontData#getName() . 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: PreviewLabel.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void initFields( )
{
	try
	{
		FontData fd = getFont( ).getFontData( )[0];

		fontFamily = fd.getName( );
		fontSize = fd.getHeight( );
		isBold = ( fd.getStyle( ) & SWT.BOLD ) != 0;
		isItalic = ( fd.getStyle( ) & SWT.ITALIC ) != 0;
	}
	catch ( Exception e )
	{
		/**
		 * Does nothing.
		 */
	}
}
 
Example 2
Source File: RemovedNodeElementEditPart.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
protected Font changeFont(IFigure figure) {
	this.disposeFont();

	RemovedNodeElement removedNodeElement = (RemovedNodeElement) this
			.getModel();

	String fontName = removedNodeElement.getFontName();
	int fontSize = removedNodeElement.getFontSize();

	if (fontName == null) {
		FontData fontData = Display.getCurrent().getSystemFont()
				.getFontData()[0];
		fontName = fontData.getName();
	}
	if (fontSize <= 0) {
		fontSize = ViewableModel.DEFAULT_FONT_SIZE;
	}

	this.font = new Font(Display.getCurrent(), fontName, fontSize,
			SWT.NORMAL);

	figure.setFont(this.font);

	return font;
}
 
Example 3
Source File: NodeElementEditPart.java    From ermasterr with Apache License 2.0 6 votes vote down vote up
protected Font changeFont(final IFigure figure) {
    final NodeElement nodeElement = (NodeElement) getModel();

    String fontName = nodeElement.getFontName();
    int fontSize = nodeElement.getFontSize();

    if (Check.isEmpty(fontName)) {
        final FontData fontData = Display.getCurrent().getSystemFont().getFontData()[0];
        fontName = fontData.getName();
        nodeElement.setFontName(fontName);
    }
    if (fontSize <= 0) {
        fontSize = ViewableModel.DEFAULT_FONT_SIZE;
        nodeElement.setFontSize(fontSize);
    }

    font = Resources.getFont(fontName, fontSize);

    figure.setFont(font);

    return font;
}
 
Example 4
Source File: SeparatorPanel.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void initComponents(String label) {
       GridLayout gridLayout = new GridLayout(2, false);
	setLayout(gridLayout);
	
	GridData layoutData = new GridData();
	layoutData.grabExcessHorizontalSpace = true;
	layoutData.horizontalAlignment = GridData.FILL;
	setLayoutData(layoutData);

	// Text label
	StyledText gridLinesLabel = new StyledText(this, SWT.NONE);
	gridLinesLabel.setEditable(false);
	Display display = Display.getDefault();
	FontData data = display .getSystemFont().getFontData()[0];
	Font font = new Font(display, data.getName(), data.getHeight(), SWT.BOLD);
	gridLinesLabel.setFont(font);
	gridLinesLabel.setBackground(Display.getCurrent().getSystemColor (SWT.COLOR_WIDGET_BACKGROUND));
	gridLinesLabel.setText(label);

	// Separator line
	Label separator = new Label (this, SWT.SEPARATOR | SWT.HORIZONTAL);
	GridData separatorData = new GridData();
	separatorData.grabExcessHorizontalSpace = true;
	separatorData.horizontalAlignment = GridData.FILL;
	separatorData.horizontalIndent = 5;
	separator.setLayoutData(separatorData);
}
 
Example 5
Source File: SWTUtils.java    From SIMVA-SoS with Apache License 2.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 6
Source File: CustomCellEditor.java    From ermaster-b with Apache License 2.0 5 votes vote down vote up
private TextFieldPopupMenu() {
	FontData fontData = Display.getCurrent().getSystemFont()
			.getFontData()[0];

	Font font = new Font(fontData.getName(), Font.PLAIN, 12);

	JMenuItem cutMenuItem = this.add(new CutAction());
	cutMenuItem.setFont(font);

	JMenuItem copyMenuItem = this.add(new CopyAction());
	copyMenuItem.setFont(font);

	JMenuItem pasteMenuItem = this.add(new PasteAction());
	pasteMenuItem.setFont(font);
}
 
Example 7
Source File: FontScalingUtil.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public static FontData scaleFont(FontData fontData, int style) {
	if (OPERATING_SYSTEM.indexOf("win") == -1 || DiagramActivator.getDefault().getPreferenceStore()
			.getBoolean(StatechartPreferenceConstants.PREF_FONT_SCALING)) {
		return new FontData(fontData.getName(), fontData.getHeight(), fontData.getStyle() | style);
	}
	int DPI = Display.getCurrent().getDPI().y;
	if (DPI != WINDOWS_DEFAULT_DPI) {
		double factor = (double) WINDOWS_DEFAULT_DPI / DPI;
		return new FontData(fontData.getName(), (int) (fontData.getHeight() * factor), fontData.getStyle() | style);
	}
	return new FontData(fontData.getName(), fontData.getHeight(), fontData.getStyle() | style);

}
 
Example 8
Source File: SWTUtils.java    From ccu-historian with GNU General Public License v3.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 9
Source File: SWTUtils.java    From astor 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 10
Source File: XtextDirectEditManager.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This method obtains the fonts that are being used by the figure at its
 * zoom level.
 * 
 * @param gep
 *            the associated <code>GraphicalEditPart</code> of the figure
 * @param actualFont
 *            font being used by the figure
 * @param display
 * @return <code>actualFont</code> if zoom level is 1.0 (or when there's an
 *         error), new Font otherwise.
 */
private Font getZoomLevelFont(Font actualFont, Display display) {
	Object zoom = getEditPart().getViewer().getProperty(ZoomManager.class.toString());

	if (zoom != null) {
		double zoomLevel = ((ZoomManager) zoom).getZoom();

		if (zoomLevel == 1.0f)
			return actualFont;

		FontData[] fd = new FontData[actualFont.getFontData().length];
		FontData tempFD = null;

		for (int i = 0; i < fd.length; i++) {
			tempFD = actualFont.getFontData()[i];

			fd[i] = new FontData(tempFD.getName(), (int) (zoomLevel * tempFD.getHeight()), tempFD.getStyle());
		}

		try {
			FontDescriptor fontDescriptor = FontDescriptor.createFrom(fd);
			cachedFontDescriptors.add(fontDescriptor);
			return getResourceManager().createFont(fontDescriptor);
		} catch (DeviceResourceException e) {
			Trace.catching(DiagramUIPlugin.getInstance(), DiagramUIDebugOptions.EXCEPTIONS_CATCHING, getClass(),
					"getZoomLevelFonts", e); //$NON-NLS-1$
			Log.error(DiagramUIPlugin.getInstance(), DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING,
					"getZoomLevelFonts", e); //$NON-NLS-1$

			return actualFont;
		}
	} else
		return actualFont;
}
 
Example 11
Source File: ProgressCircle.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private Font createDefaultFont() {
	final FontData fontData = getFont().getFontData()[0];
	final Font newFont = new Font(getDisplay(), fontData.getName(), Math.max(fontData.getHeight(), 20), fontData.getStyle());
	addDisposeListener(e -> {
		if (!newFont.isDisposed()) {
			newFont.dispose();
		}
	});
	return newFont;
}
 
Example 12
Source File: N4IDEXpectView.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void createPartControl(Composite parent) {

	FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
	fillLayout.marginHeight = 5;
	fillLayout.marginWidth = 5;
	parent.setLayout(fillLayout);

	// main container
	container = new Composite(parent, SWT.BORDER);
	container.setLayout(new FillLayout());

	// create container for stack trace data
	Composite stacktraceDataContainer = new Composite(parent, SWT.BORDER);

	FormLayout formLayout = new FormLayout();
	formLayout.marginHeight = 5;
	formLayout.marginWidth = 5;
	formLayout.spacing = 5;
	stacktraceDataContainer.setLayout(formLayout);

	Composite stackLabelContainer = new Composite(stacktraceDataContainer, SWT.NO_SCROLL | SWT.SHADOW_NONE);
	stackLabelContainer.setLayout(new GridLayout());

	FormData stackLabelFormData = new FormData();
	stackLabelFormData.top = new FormAttachment(0);
	stackLabelFormData.left = new FormAttachment(0);
	stackLabelFormData.right = new FormAttachment(100);
	stackLabelFormData.bottom = new FormAttachment(20);
	stackLabelContainer.setLayoutData(stackLabelFormData);

	Composite stackTraceContainer = new Composite(stacktraceDataContainer, SWT.NO_SCROLL | SWT.SHADOW_NONE);
	stackTraceContainer.setLayout(new FillLayout());

	FormData stackTraceFormData = new FormData();
	stackTraceFormData.top = new FormAttachment(stackLabelContainer);
	stackTraceFormData.left = new FormAttachment(0);
	stackTraceFormData.right = new FormAttachment(100);
	stackTraceFormData.bottom = new FormAttachment(100);
	stackTraceContainer.setLayoutData(stackTraceFormData);

	// Create viewer for test tree in main container
	testTreeViewer = new TreeViewer(container);
	testTreeViewer.setContentProvider(new XpectContentProvider());
	testTreeViewer.setLabelProvider(new XpectLabelProvider(this.testsExecutionStatus));
	testTreeViewer.setInput(null);

	// create stack trace label
	stacktraceLabel = new Label(stackLabelContainer, SWT.SHADOW_OUT);
	FontData fontData = stacktraceLabel.getFont().getFontData()[0];
	Display display = Display.getCurrent();
	// may be null if outside the UI thread
	if (display == null)
		display = Display.getDefault();
	Font font = new Font(display, new FontData(fontData.getName(), fontData
			.getHeight(), SWT.BOLD));
	// Make stack trace label bold
	stacktraceLabel.setFont(font);

	stacktraceLabel.setText(NO_TRACE_MSG);

	// create stack trace console
	MessageConsole messageConsole = new MessageConsole("trace", null);
	stacktraceConsole = new TraceConsole(messageConsole);
	stacktraceConsoleViewer = new TextConsoleViewer(stackTraceContainer, messageConsole);

	// context menu
	getSite().setSelectionProvider(testTreeViewer);
	MenuManager contextMenu = new MenuManager();
	contextMenu.setRemoveAllWhenShown(true);
	getSite().registerContextMenu(contextMenu, testTreeViewer);
	Control control = testTreeViewer.getControl();
	Menu menu = contextMenu.createContextMenu(control);
	control.setMenu(menu);
	activateContext();

	createSelectionActions();

}
 
Example 13
Source File: DualListSnippet.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private static List<DLItem> createItems(final Shell shell) {
	final List<DLItem> list = new ArrayList<>();

	String defaultFontName = null;
	int defaultHeight = -1;
	for (final FontData fontData : shell.getFont().getFontData()) {
		if (defaultFontName == null) {
			defaultFontName = fontData.getName();
		}
		if (defaultHeight == -1) {
			defaultHeight = fontData.getHeight();
		}
	}

	final Font font = new Font(shell.getDisplay(), defaultFontName, defaultHeight, SWT.BOLD);

	list.add(new DLItem("Austria", createImage(shell, "austria")));
	list.add(new DLItem("Belgium", createImage(shell, "belgium")));
	list.add(new DLItem("Bulgaria", createImage(shell, "bulgaria")));
	list.add(new DLItem("Cyprus", createImage(shell, "cyprus")));
	list.add(new DLItem("Czech Republic", createImage(shell, "czech")));
	list.add(new DLItem("Denmark", createImage(shell, "denmark")));
	list.add(new DLItem("Estonia", createImage(shell, "estonia")));
	list.add(new DLItem("Finland", createImage(shell, "finland")));
	list.add(new DLItem("France", createImage(shell, "france"), font));
	list.add(new DLItem("Germany", createImage(shell, "germany")));
	list.add(new DLItem("Greece", createImage(shell, "greece")));
	list.add(new DLItem("Hungary", createImage(shell, "hungary")));
	list.add(new DLItem("Ireland", createImage(shell, "ireland")));
	list.add(new DLItem("Italy", createImage(shell, "italy")));
	list.add(new DLItem("Latvia", createImage(shell, "latvia")));
	list.add(new DLItem("Lithuania", createImage(shell, "lithuania")));
	list.add(new DLItem("Luxembourg", createImage(shell, "luxembourg")));
	list.add(new DLItem("Malta", createImage(shell, "malta")));
	list.add(new DLItem("Netherlands", createImage(shell, "netherlands")));
	list.add(new DLItem("Poland", createImage(shell, "poland"), shell.getDisplay().getSystemColor(SWT.COLOR_WHITE), shell.getDisplay().getSystemColor(SWT.COLOR_RED)));
	list.add(new DLItem("Portugal", createImage(shell, "portugal")));
	list.add(new DLItem("Romania", createImage(shell, "romania")));
	list.add(new DLItem("Slovakia", createImage(shell, "slovakia")));
	list.add(new DLItem("Slovenia", createImage(shell, "slovenia")));
	list.add(new DLItem("Spain", createImage(shell, "spain")));
	list.add(new DLItem("Sweden", createImage(shell, "sweden")));
	list.add(new DLItem("United Kingdom", createImage(shell, "unitedkingdom")));

	shell.addDisposeListener(e -> {
		font.dispose();
	});

	return list;
}
 
Example 14
Source File: UpdaterDialog.java    From developer-studio with Apache License 2.0 4 votes vote down vote up
private void listFeatures(Group group, ActiveTab tab) {
	IPreferenceStore prefPage = PlatformUI.getPreferenceStore();
	boolean showHiddenFeatures = prefPage.getBoolean(DeveloperPreferencePage.SHOW_HIDDEN_FEATURES);

	Iterator<Entry<String, EnhancedFeature>> featureList;
	if (tab == ActiveTab.ALL_FEATURES) {
		featureList = updateManager.getAvailableFeaturesMap().entrySet().iterator();
	} else {
		featureList = updateManager.getPossibleUpdatesMap().entrySet().iterator();
	}
	while (featureList.hasNext()) {
		EnhancedFeature feature = featureList.next().getValue();
		// set isKernelFeature=true or isHidden=true in update.properties
		// file in features to
		// ignore them in available Features tab
		if (tab == ActiveTab.ALL_FEATURES && !showHiddenFeatures) {
			if (feature.isKernelFeature() || feature.isHidden()) {
				continue;
			}
		}
		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
		final Group featureGroup = createFeatureRepresentationGroup(group, gridData);
		createCheckBoxInFeatureGroup(feature, featureGroup, tab);

		Label featureImageLabel = new Label(featureGroup, SWT.NONE);
		try {
			Image image = new Image(Display.getDefault(), feature.getIconURL().replace(FILE_PROTOCOL, "")); //$NON-NLS-1$
			featureImageLabel.setImage(image);
		} catch (Exception ex) {
			log.warn(Messages.UpdaterDialog_8 + feature.getId(), ex);
		}
		final Group featureInfoGroup = createFeatureInfoRepresentationGroup(featureGroup);
		StyledText featureName = createFeatureNameText(feature, featureInfoGroup);
		FontData fontData = featureName.getFont().getFontData()[0];
		Font font = new Font(featureInfoGroup.getDisplay(),
				new FontData(fontData.getName(), fontData.getHeight() + 1, SWT.BOLD));
		featureName.setFont(font);
		createFeatureNewVersionText(feature, featureInfoGroup);
		if (feature.isUpdateFeature() && feature.getWhatIsNew() != null && !feature.getWhatIsNew().isEmpty()) {
			createFeatureDescr(feature.getWhatIsNew(), feature.getBugFixes(), featureInfoGroup);
		}
	}
}
 
Example 15
Source File: DualListTextSnippet.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private static List<DLItem> createItems(final Shell shell) {
	final List<DLItem> list = new ArrayList<DLItem>();

	String defaultFontName = null;
	int defaultHeight = -1;
	for (final FontData fontData : shell.getFont().getFontData()) {
		if (defaultFontName == null) {
			defaultFontName = fontData.getName();
		}
		if (defaultHeight == -1) {
			defaultHeight = fontData.getHeight();
		}
	}

	final Font font = new Font(shell.getDisplay(), defaultFontName, defaultHeight, SWT.BOLD);

	list.add(new DLItem("Austria"));
	list.add(new DLItem("Belgium"));
	list.add(new DLItem("Bulgaria"));
	list.add(new DLItem("Cyprus"));
	list.add(new DLItem("Czech Republic"));
	list.add(new DLItem("Denmark"));
	list.add(new DLItem("Estonia"));
	list.add(new DLItem("Finland"));
	list.add(new DLItem("France"));
	list.add(new DLItem("Germany"));
	list.add(new DLItem("Greece"));
	list.add(new DLItem("Hungary"));
	list.add(new DLItem("Ireland"));
	list.add(new DLItem("Italy"));
	list.add(new DLItem("Latvia"));
	list.add(new DLItem("Lithuania"));
	list.add(new DLItem("Luxembourg"));
	list.add(new DLItem("Malta"));
	list.add(new DLItem("Netherlands"));
	list.add(new DLItem("Poland"));
	list.add(new DLItem("Portugal"));
	list.add(new DLItem("Romania"));
	list.add(new DLItem("Slovakia"));
	list.add(new DLItem("Slovenia"));
	list.add(new DLItem("Spain"));
	list.add(new DLItem("Sweden"));
	list.add(new DLItem("United Kingdom"));

	shell.addDisposeListener(e -> {
		font.dispose();
	});

	return list;
}
 
Example 16
Source File: Snippet163old.java    From http4e with Apache License 2.0 4 votes vote down vote up
public static void main(String [] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setLayout(new FillLayout());
   StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
   styledText.setText(text);
   FontData data = styledText.getFont().getFontData()[0];
   Font font1 = new Font(display, data.getName(), data.getHeight() * 2, data.getStyle());
   Font font2 = new Font(display, data.getName(), data.getHeight() * 4 / 5, data.getStyle());
   StyleRange[] styles = new StyleRange[8];
   styles[0] = new StyleRange();
   styles[0].font = font1; 
   styles[1] = new StyleRange();
   styles[1].rise = data.getHeight() / 3; 
   styles[2] = new StyleRange();
   styles[2].background = display.getSystemColor(SWT.COLOR_GREEN); 
   styles[3] = new StyleRange();
   styles[3].foreground = display.getSystemColor(SWT.COLOR_MAGENTA); 
   styles[4] = new StyleRange();
   styles[4].font = font2; 
   styles[4].foreground = display.getSystemColor(SWT.COLOR_BLUE);;
   styles[4].underline = true;
   styles[5] = new StyleRange();
   styles[5].rise = -data.getHeight() / 3; 
   styles[5].strikeout = true;
   styles[5].underline = true;
   styles[6] = new StyleRange();
   styles[6].font = font1; 
   styles[6].foreground = display.getSystemColor(SWT.COLOR_YELLOW);
   styles[6].background = display.getSystemColor(SWT.COLOR_BLUE);
   styles[7] = new StyleRange();
   styles[7].rise =  data.getHeight() / 3;
   styles[7].underline = true;
   styles[7].fontStyle = SWT.BOLD;
   styles[7].foreground = display.getSystemColor(SWT.COLOR_RED);
   styles[7].background = display.getSystemColor(SWT.COLOR_BLACK);
   
   int[] ranges = new int[] {16, 4, 61, 13, 107, 10, 122, 10, 134, 3, 143, 6, 160, 7, 168, 7};
   styledText.setStyleRanges(ranges, styles);
   
   shell.setSize(300, 300);
   shell.open();
   while (!shell.isDisposed()) {
      if (!display.readAndDispatch())
         display.sleep();
   }
   font1.dispose();
   font2.dispose();     
   display.dispose();
}
 
Example 17
Source File: TmfAbstractToolTipHandler.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
@SuppressWarnings("nls")
        private String toHtml() {
            GC gc = new GC(Display.getDefault());
            FontData fontData = gc.getFont().getFontData()[0];
            String fontName = fontData.getName();
            String fontHeight = fontData.getHeight() + "pt";
            gc.dispose();
            Table<ToolTipString, ToolTipString, ToolTipString> model = getModel();
            StringBuilder toolTipContent = new StringBuilder();
            toolTipContent.append("<head>\n" +
                    "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" +
                    "<style>\n" +
                    ".collapsible {\n" +
                    "  background-color: #777;\n" +
                    "  color: white;\n" +
//                    "  cursor: pointer;\n" + // Add when enabling JavaScript
                    "  padding: 0px;\n" +
                    "  width: 100%;\n" +
                    "  border: none;\n" +
                    "  text-align: left;\n" +
                    "  outline: none;\n" +
                    "  font-family: " + fontName +";\n" +
                    "  font-size: " + fontHeight + ";\n" +
                    "}\n" +
                    "\n" +
                    ".active, .collapsible:hover {\n" +
                    "  background-color: #555;\n" +
                    "}\n" +
                    "\n" +
                    ".content {\n" +
                    "  padding: 0px 0px;\n" +
                    "  display: block;\n" +
                    "  overflow: hidden;\n" +
                    "  background-color: #f1f1f1;\n" +
                    "}\n" +
                    ".tab {\n" +
                    "  padding:0px;\n" +
                    "  font-family: " + fontName + ";\n" +
                    "  font-size: " + fontHeight + ";\n" +
                    "}\n" +
                    ".leftPadding {\n" +
                    "  padding:0px 0px 0px " + CELL_PADDING + "px;\n" +
                    "}\n" +
                    ".bodystyle {\n" +
                    "  margin:" + BODY_MARGIN + "px;\n" +
                    "  padding:0px 0px;\n" +
                    "}\n" +
                    "</style>\n" +
                    "</head>");
            toolTipContent.append("<body class=\"bodystyle\">"); //$NON-NLS-1$

            toolTipContent.append("<div class=\"content\">");
            toolTipContent.append("<table class=\"tab\">");
            Set<ToolTipString> rowKeySet = model.rowKeySet();
            for (ToolTipString row : rowKeySet) {
                if (!row.equals(UNCATEGORIZED)) {
                    toolTipContent.append("<tr><th colspan=\"2\"><button class=\"collapsible\">").append(row.toHtmlString()).append("</button></th></tr>");
                }
                Set<Entry<ToolTipString, ToolTipString>> entrySet = model.row(row).entrySet();
                for (Entry<ToolTipString, ToolTipString> entry : entrySet) {
                    toolTipContent.append("<tr>");
                    toolTipContent.append("<td>");
                    toolTipContent.append(entry.getKey().toHtmlString());
                    toolTipContent.append("</td>");
                    toolTipContent.append("<td class=\"leftPadding\">");
                    toolTipContent.append(entry.getValue().toHtmlString());
                    toolTipContent.append("</td>");
                    toolTipContent.append("</tr>");
                }
            }
            toolTipContent.append("</table></div>");
            /* Add when enabling JavaScript
            toolTipContent.append("\n" +
                    "<script>\n" +
                    "var coll = document.getElementsByClassName(\"collapsible\");\n" +
                    "var i;\n" +
                    "\n" +
                    "for (i = 0; i < coll.length; i++) {\n" +
                    "  coll[i].addEventListener(\"click\", function() {\n" +
                    "    this.classList.toggle(\"active\");\n" +
                    "    var content = this.nextElementSibling;\n" +
                    "    if (content.style.display === \"block\") {\n" +
                    "      content.style.display = \"none\";\n" +
                    "    } else {\n" +
                    "      content.style.display = \"block\";\n" +
                    "    }\n" +
                    "  });\n" +
                    "}\n" +
                    "</script>");
            */
            toolTipContent.append("</body>"); //$NON-NLS-1$
            return toolTipContent.toString();
        }
 
Example 18
Source File: CaptureDialog.java    From logbook with MIT License 4 votes vote down vote up
/**
 * Create contents of the dialog.
 */
private void createContents() {
    // シェル
    this.shell = new Shell(this.getParent(), this.getStyle());
    this.shell.setText(this.getText());
    // レイアウト
    GridLayout glShell = new GridLayout(1, false);
    glShell.horizontalSpacing = 1;
    glShell.marginHeight = 1;
    glShell.marginWidth = 1;
    glShell.verticalSpacing = 1;
    this.shell.setLayout(glShell);

    // 太字にするためのフォントデータを作成する
    FontData defaultfd = this.shell.getFont().getFontData()[0];
    FontData fd = new FontData(defaultfd.getName(), defaultfd.getHeight(), SWT.BOLD);
    this.font = new Font(Display.getDefault(), fd);

    // コンポジット
    Composite rangeComposite = new Composite(this.shell, SWT.NONE);
    rangeComposite.setLayout(new GridLayout(2, false));

    // 範囲設定
    this.text = new Text(rangeComposite, SWT.BORDER | SWT.READ_ONLY);
    GridData gdText = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
    gdText.widthHint = 120;
    this.text.setLayoutData(gdText);
    this.text.setText("範囲が未設定です");

    Button button = new Button(rangeComposite, SWT.NONE);
    button.setText("範囲を選択");
    button.addSelectionListener(new SelectRectangleAdapter());

    // コンポジット
    this.composite = new Composite(this.shell, SWT.NONE);
    GridLayout loglayout = new GridLayout(3, false);
    this.composite.setLayout(loglayout);
    this.composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));

    // 周期設定
    this.interval = new Button(this.composite, SWT.CHECK);
    this.interval.addSelectionListener((SelectedListener) e -> {
        this.capture.setText(getCaptureButtonText(false, this.interval.getSelection()));
    });
    this.interval.setText("周期");

    this.intervalms = new Spinner(this.composite, SWT.BORDER);
    this.intervalms.setMaximum(60000);
    this.intervalms.setMinimum(100);
    this.intervalms.setSelection(1000);
    this.intervalms.setIncrement(100);

    Label label = new Label(this.composite, SWT.NONE);
    label.setText("ミリ秒");

    this.capture = new Button(this.shell, SWT.NONE);
    this.capture.setFont(this.font);
    GridData gdCapture = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    gdCapture.horizontalSpan = 3;
    gdCapture.heightHint = 64;
    this.capture.setLayoutData(gdCapture);
    this.capture.setEnabled(false);
    this.capture.setText(getCaptureButtonText(false, this.interval.getSelection()));
    this.capture.addSelectionListener(new CaptureStartAdapter());

    this.shell.pack();
}
 
Example 19
Source File: TableViewEditPart.java    From ermaster-b with Apache License 2.0 3 votes vote down vote up
protected Font changeFont(TableFigure tableFigure) {
	Font font = super.changeFont(tableFigure);

	FontData fonData = font.getFontData()[0];

	this.titleFont = new Font(Display.getCurrent(), fonData.getName(),
			fonData.getHeight(), SWT.BOLD);

	tableFigure.setFont(font, this.titleFont);

	return font;
}
 
Example 20
Source File: PanelCellEditor.java    From ermaster-b with Apache License 2.0 3 votes vote down vote up
protected static Font getAwtFont() {
	FontData fontData = Display.getCurrent().getSystemFont().getFontData()[0];

	Font font = new Font(fontData.getName(), Font.PLAIN, 12);

	return font;
}