1 40 41 package org.jfree.experimental.chart.swt.editor; 42 43 import java.util.ResourceBundle ; 44 45 import org.eclipse.swt.SWT; 46 import org.eclipse.swt.events.SelectionAdapter; 47 import org.eclipse.swt.events.SelectionEvent; 48 import org.eclipse.swt.graphics.Color; 49 import org.eclipse.swt.graphics.Font; 50 import org.eclipse.swt.graphics.FontData; 51 import org.eclipse.swt.graphics.RGB; 52 import org.eclipse.swt.layout.FillLayout; 53 import org.eclipse.swt.layout.GridData; 54 import org.eclipse.swt.layout.GridLayout; 55 import org.eclipse.swt.widgets.Button; 56 import org.eclipse.swt.widgets.ColorDialog; 57 import org.eclipse.swt.widgets.Composite; 58 import org.eclipse.swt.widgets.FontDialog; 59 import org.eclipse.swt.widgets.Group; 60 import org.eclipse.swt.widgets.Label; 61 import org.eclipse.swt.widgets.Text; 62 import org.jfree.chart.JFreeChart; 63 import org.jfree.chart.title.TextTitle; 64 import org.jfree.chart.title.Title; 65 import org.jfree.experimental.swt.SWTPaintCanvas; 66 import org.jfree.experimental.swt.SWTUtils; 67 68 71 class SWTTitleEditor extends Composite { 72 73 74 private boolean showTitle; 75 76 77 private Button showTitleCheckBox; 78 79 80 private Text titleField; 81 82 83 private FontData titleFont; 84 85 86 private Text fontField; 87 88 89 private Button selectFontButton; 90 91 92 private Color titleColor; 93 94 95 private Button selectColorButton; 96 97 98 protected static ResourceBundle localizationResources 99 = ResourceBundle.getBundle("org.jfree.chart.editor.LocalizationBundle"); 100 101 102 private Font font; 103 104 110 SWTTitleEditor(Composite parent, int style, Title title) { 111 super(parent, style); 112 FillLayout layout = new FillLayout(); 113 layout.marginHeight = layout.marginWidth = 4; 114 setLayout( layout ); 115 116 TextTitle t = (title != null ? (TextTitle) title 117 : new TextTitle(localizationResources.getString("Title"))); 118 this.showTitle = (title != null); 119 this.titleFont = SWTUtils.toSwtFontData(getDisplay(), t.getFont(), 120 true); 121 this.titleColor = SWTUtils.toSwtColor(getDisplay(), t.getPaint()); 122 123 Group general = new Group(this, SWT.NONE); 124 general.setLayout(new GridLayout(3, false)); 125 general.setText(localizationResources.getString("General")); 126 Label label = new Label(general, SWT.NONE); 128 label.setText(localizationResources.getString("Show_Title")); 129 GridData gridData = new GridData(); 130 gridData.horizontalSpan = 2; 131 label.setLayoutData(gridData); 132 showTitleCheckBox = new Button(general, SWT.CHECK); 133 showTitleCheckBox.setSelection(this.showTitle); 134 showTitleCheckBox.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, 135 false, false)); 136 showTitleCheckBox.addSelectionListener( 137 new SelectionAdapter() { 138 public void widgetSelected(SelectionEvent event) { 139 showTitle = showTitleCheckBox.getSelection(); 140 } 141 }); 142 new Label(general, SWT.NONE).setText(localizationResources.getString( 144 "Text")); 145 titleField = new Text(general, SWT.BORDER); 146 titleField.setText(t.getText()); 147 titleField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, 148 false)); 149 new Label(general, SWT.NONE).setText(""); 150 new Label(general, SWT.NONE).setText(localizationResources.getString( 152 "Font")); 153 fontField = new Text(general, SWT.BORDER); 154 fontField.setText(titleFont.toString()); 155 fontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, 156 false)); 157 selectFontButton = new Button(general, SWT.PUSH); 158 selectFontButton.setText(localizationResources.getString("Select...")); 159 selectFontButton.addSelectionListener( 160 new SelectionAdapter() { 161 public void widgetSelected(SelectionEvent event) { 162 FontDialog dlg = new FontDialog(getShell()); 164 dlg.setText(localizationResources.getString( 165 "Font_Selection")); 166 dlg.setFontList(new FontData[] { titleFont }); 167 if (dlg.open() != null) { 168 if (font != null) font.dispose(); 170 font = new Font(getShell().getDisplay(), 173 dlg.getFontList()); 174 fontField.setText(font.getFontData()[0].toString()); 176 titleFont = font.getFontData()[0]; 177 } 178 } 179 } 180 ); 181 new Label(general, SWT.NONE).setText(localizationResources.getString( 183 "Color")); 184 final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general, 187 SWT.NONE, this.titleColor); 188 GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER, true, 189 false); 190 canvasGridData.heightHint = 20; 191 colorCanvas.setLayoutData(canvasGridData); 192 selectColorButton = new Button(general, SWT.PUSH); 193 selectColorButton.setText(localizationResources.getString("Select...")); 194 selectColorButton.addSelectionListener( 195 new SelectionAdapter() { 196 public void widgetSelected(SelectionEvent event) { 197 ColorDialog dlg = new ColorDialog(getShell()); 199 dlg.setText(localizationResources.getString( 200 "Title_Color")); 201 dlg.setRGB(titleColor.getRGB()); 202 RGB rgb = dlg.open(); 203 if (rgb != null) { 204 titleColor = new Color(getDisplay(), rgb); 207 colorCanvas.setColor( titleColor ); 208 } 209 } 210 } 211 ); 212 } 213 214 219 public String getTitleText() { 220 return this.titleField.getText(); 221 } 222 223 228 public FontData getTitleFont() { 229 return this.titleFont; 230 } 231 232 237 public Color getTitleColor() { 238 return this.titleColor; 239 } 240 241 247 public void setTitleProperties(JFreeChart chart) { 248 if (this.showTitle) { 249 TextTitle title = chart.getTitle(); 250 if (title == null) { 251 title = new TextTitle(); 252 chart.setTitle(title); 253 } 254 title.setText(getTitleText()); 255 title.setFont(SWTUtils.toAwtFont(getDisplay(), getTitleFont(), 256 true)); 257 title.setPaint(SWTUtils.toAwtColor(getTitleColor())); 258 } 259 else { 260 chart.setTitle((TextTitle) null); 261 } 262 } 263 } 264 | Popular Tags |