]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/jface/FontCellEditor.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / jface / FontCellEditor.java
diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/jface/FontCellEditor.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/jface/FontCellEditor.java
new file mode 100644 (file)
index 0000000..c69f15a
--- /dev/null
@@ -0,0 +1,83 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+/*\r
+ *\r
+ * @author Toni Kalajainen\r
+ */\r
+package org.simantics.utils.ui.jface;\r
+\r
+import org.eclipse.jface.viewers.DialogCellEditor;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.graphics.Color;\r
+import org.eclipse.swt.graphics.FontData;\r
+import org.eclipse.swt.widgets.Composite;\r
+import org.eclipse.swt.widgets.Control;\r
+import org.eclipse.swt.widgets.FontDialog;\r
+import org.eclipse.swt.widgets.Label;\r
+\r
+public class FontCellEditor extends DialogCellEditor {\r
+\r
+    private Label fontLabel;\r
+        \r
+    public FontCellEditor() {\r
+        super();\r
+    }\r
+\r
+    public FontCellEditor(Composite parent, int style) {\r
+        super(parent, style);\r
+    }\r
+\r
+\r
+\r
+    public FontCellEditor(Composite parent) {\r
+        super(parent);\r
+    }\r
+\r
+    @Override\r
+    protected Control createContents(Composite cell) {\r
+        fontLabel = new Label(cell, SWT.LEFT);\r
+        Color bg = cell.getBackground();\r
+        fontLabel.setBackground(bg);\r
+        return fontLabel;\r
+    }\r
+    \r
+\r
+    @Override\r
+    protected Object openDialogBox(Control cellEditorWindow) {\r
+        \r
+        FontDialog fontDialog = new FontDialog(cellEditorWindow.getShell());\r
+        FontData fontData = (FontData) getValue();\r
+        if (fontData!=null)\r
+            fontDialog.setFontList(new FontData[] {fontData});\r
+        return fontDialog.open();\r
+    }\r
+\r
+    @Override\r
+    protected void updateContents(Object value) {\r
+        FontData fontData = (FontData) value;\r
+        if (fontData==null) {\r
+            fontLabel.setText("select font...");\r
+            return;\r
+        }\r
+        \r
+        StringBuilder sb = new StringBuilder();\r
+        sb.append( fontData.getName() );\r
+        sb.append( ", "+fontData.getHeight() );\r
+        if ( (fontData.getStyle() & SWT.BOLD)>0 )\r
+            sb.append(", Bold");\r
+        if ( (fontData.getStyle() & SWT.ITALIC)>0 )\r
+            sb.append(", Italic");\r
+        fontLabel.setText(sb.toString());\r
+    }\r
+    \r
+    \r
+}\r