]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/jface/FontCellEditor.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / jface / FontCellEditor.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 /*
13  *
14  * @author Toni Kalajainen
15  */
16 package org.simantics.utils.ui.jface;
17
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;
26
27 public class FontCellEditor extends DialogCellEditor {
28
29     private Label fontLabel;
30         
31     public FontCellEditor() {
32         super();
33     }
34
35     public FontCellEditor(Composite parent, int style) {
36         super(parent, style);
37     }
38
39
40
41     public FontCellEditor(Composite parent) {
42         super(parent);
43     }
44
45     @Override
46     protected Control createContents(Composite cell) {
47         fontLabel = new Label(cell, SWT.LEFT);
48         Color bg = cell.getBackground();
49         fontLabel.setBackground(bg);
50         return fontLabel;
51     }
52     
53
54     @Override
55     protected Object openDialogBox(Control cellEditorWindow) {
56         
57         FontDialog fontDialog = new FontDialog(cellEditorWindow.getShell());
58         FontData fontData = (FontData) getValue();
59         if (fontData!=null)
60             fontDialog.setFontList(new FontData[] {fontData});
61         return fontDialog.open();
62     }
63
64     @Override
65     protected void updateContents(Object value) {
66         FontData fontData = (FontData) value;
67         if (fontData==null) {
68             fontLabel.setText("select font...");
69             return;
70         }
71         
72         StringBuilder sb = new StringBuilder();
73         sb.append( fontData.getName() );
74         sb.append( ", "+fontData.getHeight() );
75         if ( (fontData.getStyle() & SWT.BOLD)>0 )
76             sb.append(", Bold");
77         if ( (fontData.getStyle() & SWT.ITALIC)>0 )
78             sb.append(", Italic");
79         fontLabel.setText(sb.toString());
80     }
81     
82     
83 }