X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.ui%2Fsrc%2Forg%2Fsimantics%2Fui%2Ffonts%2FFonts.java;h=db5c85f90dec23a7e89a67b443e73062869568f3;hb=2444a7d3ebc4aea7f9899dbf8aa84c8f94e75fd9;hp=c0276f5747ad967c98847a543bf98682cc7b8527;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/fonts/Fonts.java b/bundles/org.simantics.ui/src/org/simantics/ui/fonts/Fonts.java index c0276f574..db5c85f90 100644 --- a/bundles/org.simantics.ui/src/org/simantics/ui/fonts/Fonts.java +++ b/bundles/org.simantics.ui/src/org/simantics/ui/fonts/Fonts.java @@ -1,104 +1,104 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.ui.fonts; - -import java.awt.Font; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Device; -import org.eclipse.swt.graphics.FontData; - -/** - * @author Antti Villberg - */ -public class Fonts { - - public static java.awt.Font awt(FontDescriptor descriptor) { - return new Font(descriptor.getFamily(), descriptor.getStyle(), descriptor.getSize()); - } - - public static org.simantics.datatypes.literal.Font fromAWT(Font f) { - return new org.simantics.datatypes.literal.Font(f.getFamily(), f.getSize(), fromAwtStyle(f.getStyle())); - } - - private static boolean hasMask(int test, int mask) { - return (test & mask) == mask; - } - - public static String fromSwtStyle(int swtStyle) { - if(hasMask(swtStyle, SWT.BOLD|SWT.ITALIC)) return "BoldItalic"; - else if (hasMask(swtStyle, SWT.BOLD)) return "Bold"; - else if (hasMask(swtStyle, SWT.ITALIC)) return "Italic"; - return "Normal"; - } - - public static String fromAwtStyle(int awtStyle) { - if(hasMask(awtStyle, Font.BOLD|Font.ITALIC)) return "BoldItalic"; - else if (hasMask(awtStyle, Font.BOLD)) return "Bold"; - else if (hasMask(awtStyle, Font.ITALIC)) return "Italic"; - return "Normal"; - } - - public static int swtStyle(String text) { - if("Normal".equals(text)) return SWT.NORMAL; - else if ("Bold".equals(text)) return SWT.BOLD; - else if ("Italic".equals(text)) return SWT.ITALIC; - else if ("BoldItalic".equals(text)) return SWT.BOLD|SWT.ITALIC; - else throw new RuntimeException("Illegal style '" + text + "'"); - } - - public static int awtStyle(String text) { - if("Normal".equals(text)) return 0; - else if ("Bold".equals(text)) return Font.BOLD; - else if ("Italic".equals(text)) return Font.ITALIC; - else if ("BoldItalic".equals(text)) return Font.BOLD|Font.ITALIC; - else throw new RuntimeException("Illegal style '" + text + "'"); - } - - /** - * Returns SWT Font instance. Be aware that this is a native resource and - * must be disposed of properly. - * - * @param device - * @param font - * @return - * @see #swt(org.simantics.datatypes.literal.Font) - */ - public static org.eclipse.swt.graphics.Font swt(Device device, org.simantics.datatypes.literal.Font font) { - return new org.eclipse.swt.graphics.Font(device, font.family, font.height, swtStyle(font.style)); - } - - /** - * Returns JFace FontDescriptor instance. - * - * @param font - * @return FontDescriptor for specified font - */ - public static org.eclipse.jface.resource.FontDescriptor swt(org.simantics.datatypes.literal.Font font) { - return org.eclipse.jface.resource.FontDescriptor.createFrom(font.family, font.height, swtStyle(font.style)); - } - - /** - * Returns SWT FontData instance. - * - * @param font - * @return FontData for specified font - */ - public static FontData swtFontData(org.simantics.datatypes.literal.Font font) { - return new FontData(font.family, font.height, swtStyle(font.style)); - } - - public static java.awt.Font awt(org.simantics.datatypes.literal.Font font) { - return new java.awt.Font(font.family, awtStyle(font.style), font.height); - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.ui.fonts; + +import java.awt.Font; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Device; +import org.eclipse.swt.graphics.FontData; + +/** + * @author Antti Villberg + */ +public class Fonts { + + public static java.awt.Font awt(FontDescriptor descriptor) { + return new Font(descriptor.getFamily(), descriptor.getStyle(), descriptor.getSize()); + } + + public static org.simantics.datatypes.literal.Font fromAWT(Font f) { + return new org.simantics.datatypes.literal.Font(f.getFamily(), f.getSize(), fromAwtStyle(f.getStyle())); + } + + private static boolean hasMask(int test, int mask) { + return (test & mask) == mask; + } + + public static String fromSwtStyle(int swtStyle) { + if(hasMask(swtStyle, SWT.BOLD|SWT.ITALIC)) return "BoldItalic"; + else if (hasMask(swtStyle, SWT.BOLD)) return "Bold"; + else if (hasMask(swtStyle, SWT.ITALIC)) return "Italic"; + return "Normal"; + } + + public static String fromAwtStyle(int awtStyle) { + if(hasMask(awtStyle, Font.BOLD|Font.ITALIC)) return "BoldItalic"; + else if (hasMask(awtStyle, Font.BOLD)) return "Bold"; + else if (hasMask(awtStyle, Font.ITALIC)) return "Italic"; + return "Normal"; + } + + public static int swtStyle(String text) { + if("Normal".equals(text)) return SWT.NORMAL; + else if ("Bold".equals(text)) return SWT.BOLD; + else if ("Italic".equals(text)) return SWT.ITALIC; + else if ("BoldItalic".equals(text)) return SWT.BOLD|SWT.ITALIC; + else throw new RuntimeException("Illegal style '" + text + "'"); + } + + public static int awtStyle(String text) { + if("Normal".equals(text)) return 0; + else if ("Bold".equals(text)) return Font.BOLD; + else if ("Italic".equals(text)) return Font.ITALIC; + else if ("BoldItalic".equals(text)) return Font.BOLD|Font.ITALIC; + else throw new RuntimeException("Illegal style '" + text + "'"); + } + + /** + * Returns SWT Font instance. Be aware that this is a native resource and + * must be disposed of properly. + * + * @param device + * @param font + * @return + * @see #swt(org.simantics.datatypes.literal.Font) + */ + public static org.eclipse.swt.graphics.Font swt(Device device, org.simantics.datatypes.literal.Font font) { + return new org.eclipse.swt.graphics.Font(device, font.family, font.height, swtStyle(font.style)); + } + + /** + * Returns JFace FontDescriptor instance. + * + * @param font + * @return FontDescriptor for specified font + */ + public static org.eclipse.jface.resource.FontDescriptor swt(org.simantics.datatypes.literal.Font font) { + return org.eclipse.jface.resource.FontDescriptor.createFrom(font.family, font.height, swtStyle(font.style)); + } + + /** + * Returns SWT FontData instance. + * + * @param font + * @return FontData for specified font + */ + public static FontData swtFontData(org.simantics.datatypes.literal.Font font) { + return new FontData(font.family, font.height, swtStyle(font.style)); + } + + public static java.awt.Font awt(org.simantics.datatypes.literal.Font font) { + return new java.awt.Font(font.family, awtStyle(font.style), font.height); + } + +}