1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
14 * @author Toni Kalajainen
\r
16 package org.simantics.utils.ui.jface;
\r
18 import org.eclipse.jface.viewers.DialogCellEditor;
\r
19 import org.eclipse.swt.SWT;
\r
20 import org.eclipse.swt.graphics.Color;
\r
21 import org.eclipse.swt.graphics.FontData;
\r
22 import org.eclipse.swt.widgets.Composite;
\r
23 import org.eclipse.swt.widgets.Control;
\r
24 import org.eclipse.swt.widgets.FontDialog;
\r
25 import org.eclipse.swt.widgets.Label;
\r
27 public class FontCellEditor extends DialogCellEditor {
\r
29 private Label fontLabel;
\r
31 public FontCellEditor() {
\r
35 public FontCellEditor(Composite parent, int style) {
\r
36 super(parent, style);
\r
41 public FontCellEditor(Composite parent) {
\r
46 protected Control createContents(Composite cell) {
\r
47 fontLabel = new Label(cell, SWT.LEFT);
\r
48 Color bg = cell.getBackground();
\r
49 fontLabel.setBackground(bg);
\r
55 protected Object openDialogBox(Control cellEditorWindow) {
\r
57 FontDialog fontDialog = new FontDialog(cellEditorWindow.getShell());
\r
58 FontData fontData = (FontData) getValue();
\r
60 fontDialog.setFontList(new FontData[] {fontData});
\r
61 return fontDialog.open();
\r
65 protected void updateContents(Object value) {
\r
66 FontData fontData = (FontData) value;
\r
67 if (fontData==null) {
\r
68 fontLabel.setText("select font...");
\r
72 StringBuilder sb = new StringBuilder();
\r
73 sb.append( fontData.getName() );
\r
74 sb.append( ", "+fontData.getHeight() );
\r
75 if ( (fontData.getStyle() & SWT.BOLD)>0 )
\r
76 sb.append(", Bold");
\r
77 if ( (fontData.getStyle() & SWT.ITALIC)>0 )
\r
78 sb.append(", Italic");
\r
79 fontLabel.setText(sb.toString());
\r