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