View Javadoc
1   /*
2    WSMO Studio - a Semantic Web Service Editor
3    Copyright (c) 2004-2006, OntoText Lab. / SIRMA Group
4    
5    This library is free software; you can redistribute it and/or modify it under
6    the terms of the GNU Lesser General Public License as published by the Free
7    Software Foundation; either version 2.1 of the License, or (at your option)
8    any later version.
9    This library is distributed in the hope that it will be useful, but WITHOUT
10   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   details.
13   You should have received a copy of the GNU Lesser General Public License along
14   with this library; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16   */
17  
18  /***
19   * <p>Title: WSMO Studio</p>
20   * <p>Description: Semantic Web Service Editor</p>
21   * <p>Copyright:  Copyright (c) 2004-2006</p>
22   * <p>Company: OntoText Lab. / SIRMA </p>
23   */
24  
25  package org.wsmostudio.preferences;
26  
27  import org.eclipse.jface.preference.ColorFieldEditor;
28  import org.eclipse.swt.SWT;
29  import org.eclipse.swt.widgets.*;
30  
31  public class TextStyleFieldEditor extends ColorFieldEditor {
32  
33      private Button boldCheck, italicsCheck;
34      
35      public TextStyleFieldEditor(String name, String labelText, Composite parent) {
36          super(name, labelText, parent);
37      }
38  
39      protected Button getChangeControl(Composite parent) {
40          Button result = super.getChangeControl(parent);
41          
42          new Label(parent, SWT.NONE).setText("   ");
43          
44          boldCheck = new Button(parent, SWT.CHECK);
45          boldCheck.setText("Bold");
46          
47          italicsCheck = new Button(parent, SWT.CHECK);
48          italicsCheck.setText("Italics");
49          
50          return result;
51      }
52  
53      public void dispose() {
54          boldCheck.dispose();
55          italicsCheck.dispose();
56          super.dispose();
57      }
58      
59      public int getNumberOfControls() {
60          return 5;
61      }
62      protected void doFillIntoGrid(Composite parent, int numColumns) { 
63          super.doFillIntoGrid(parent, numColumns - 3);
64      }
65      
66      protected void adjustForNumColumns(int numColumns) {
67          super.adjustForNumColumns(numColumns - 3);
68      }
69  
70      protected void doLoad() {
71          super.doLoad();
72          int style = getPreferenceStore().getInt(getPreferenceName() + TextEditorColorsPage.STYLE_SUFFIX);
73          boldCheck.setSelection((style & SWT.BOLD) == SWT.BOLD);
74          italicsCheck.setSelection((style & SWT.ITALIC) == SWT.ITALIC);
75      }
76      protected void doLoadDefault() {
77          super.doLoadDefault();
78          int style = getPreferenceStore().getDefaultInt(getPreferenceName() + TextEditorColorsPage.STYLE_SUFFIX);
79          boldCheck.setSelection((style & SWT.BOLD) == SWT.BOLD);
80          italicsCheck.setSelection((style & SWT.ITALIC) == SWT.ITALIC);
81      }
82      protected void doStore() {
83          int newStyle = SWT.NONE;
84          if (boldCheck.getSelection() == true) {
85              newStyle = SWT.BOLD;
86          }
87          if (italicsCheck.getSelection() == true) {
88              newStyle |= SWT.ITALIC;
89          }
90          int oldStyle = getPreferenceStore().getInt(getPreferenceName() + TextEditorColorsPage.STYLE_SUFFIX);
91          // update only if necessary
92          if (oldStyle != newStyle) {
93              getPreferenceStore().setValue(getPreferenceName() + TextEditorColorsPage.STYLE_SUFFIX, newStyle);
94          }
95          super.doStore();
96      }
97  }
98  
99  /*
100  * $Log$
101  * Revision 1.1  2006/01/26 11:57:14  alex_simov
102  * text style is now fully user adjustable for all elements via preference page
103  * /default style added/
104  *
105  */