| 5 |
5 |
import java.util.ArrayList;
|
| 6 |
6 |
|
| 7 |
7 |
import org.apache.commons.lang.StringUtils;
|
| 8 |
|
import org.eclipse.jface.resource.StringConverter;
|
| 9 |
8 |
import org.eclipse.swt.SWT;
|
| 10 |
9 |
import org.eclipse.swt.events.SelectionEvent;
|
| 11 |
10 |
import org.eclipse.swt.events.SelectionListener;
|
| 12 |
|
import org.eclipse.swt.graphics.FontData;
|
| 13 |
11 |
import org.eclipse.swt.widgets.Combo;
|
| 14 |
12 |
import org.eclipse.swt.widgets.Composite;
|
| 15 |
13 |
import org.eclipse.swt.widgets.ToolItem;
|
| ... | ... | |
| 38 |
36 |
public class AdvancedChartEditorToolBar extends ChartEditorToolBar {
|
| 39 |
37 |
|
| 40 |
38 |
public final static String ID = "AdvancedChartEditorToolBar";
|
| 41 |
|
private ToolItem showTitleButton;
|
| 42 |
|
private ToolItem showLegendButton;
|
| 43 |
|
private ToolItem showGridButton;
|
| 44 |
|
private Combo renderingModeCombo;
|
| 45 |
|
private Combo fontCombo;
|
| 46 |
|
private Combo fontSizeCombo;
|
| 47 |
|
private Combo chartTypeCombo;
|
| 48 |
|
private Font currentFont;
|
| 49 |
|
private Combo fontStyleCombo;
|
|
39 |
|
| 50 |
40 |
|
|
41 |
|
| 51 |
42 |
/**
|
| 52 |
43 |
* Creates a new chart editor tool bar dedicated to advanced parameters.
|
| 53 |
44 |
* @param parent
|
| ... | ... | |
| 55 |
46 |
*/
|
| 56 |
47 |
public AdvancedChartEditorToolBar(ChartEditor<? extends ChartResult> chartEditor, Composite parent, GLComposite subWidgetsComposite, int style) {
|
| 57 |
48 |
super(chartEditor, parent, subWidgetsComposite, style, AdvancedChartEditorToolBar.ID);
|
|
49 |
|
| 58 |
50 |
|
|
51 |
// Show/hide chart title button
|
|
52 |
final ToolItem showTitleButton = new ToolItem(this, SWT.CHECK);
|
|
53 |
// showTitleButton.setText(SWTComponentsProviderMessages.showhideTitle);
|
|
54 |
showTitleButton.setImage(IImageKeys.getImage(getClass(), "icons/show_title.png")); //$NON-NLS-1$
|
|
55 |
showTitleButton.setDisabledImage(IImageKeys.getImage(getClass(), "icons/show_title_disabled.png")); //$NON-NLS-1$
|
|
56 |
showTitleButton.setToolTipText(ChartsUIMessages.showhideTitle);
|
|
57 |
|
| 59 |
58 |
if (!chartEditor.getResult().isEmptyPreference(ChartsEnginePreferences.SHOW_TITLE)) {
|
| 60 |
|
showTitleButton = new ToolItem(this, SWT.CHECK);
|
| 61 |
|
// showTitleButton.setText(SWTComponentsProviderMessages.showhideTitle);
|
| 62 |
|
showTitleButton.setImage(IImageKeys.getImage(getClass(), "icons/show_title.png")); //$NON-NLS-1$
|
| 63 |
|
showTitleButton.setDisabledImage(IImageKeys.getImage(getClass(), "icons/show_title_disabled.png")); //$NON-NLS-1$
|
| 64 |
|
showTitleButton.setToolTipText(ChartsUIMessages.showhideTitle);
|
| 65 |
|
|
| 66 |
59 |
showTitleButton.setSelection(chartEditor.getResult().isTitleVisible());
|
| 67 |
60 |
}
|
| 68 |
|
// // disable if not managed by the command
|
| 69 |
|
// else {
|
| 70 |
|
// showTitleButton.setEnabled(false);
|
| 71 |
|
// }
|
|
61 |
// disable if not managed by the command
|
|
62 |
else {
|
|
63 |
showTitleButton.setEnabled(false);
|
|
64 |
}
|
| 72 |
65 |
|
|
66 |
|
|
67 |
// Show/hide chart legend button
|
|
68 |
final ToolItem showLegendButton = new ToolItem(this, SWT.CHECK);
|
|
69 |
// showLegendButton.setText(SWTComponentsProviderMessages.showhideLegend);
|
|
70 |
showLegendButton.setImage(IImageKeys.getImage(getClass(), "icons/show_legend.png")); //$NON-NLS-1$
|
|
71 |
showLegendButton.setDisabledImage(IImageKeys.getImage(getClass(), "icons/show_legend_disabled.png")); //$NON-NLS-1$
|
|
72 |
showLegendButton.setToolTipText(ChartsUIMessages.showhideLegend);
|
|
73 |
|
| 73 |
74 |
if (!chartEditor.getResult().isEmptyPreference(ChartsEnginePreferences.SHOW_LEGEND)) {
|
| 74 |
|
showLegendButton = new ToolItem(this, SWT.CHECK);
|
| 75 |
|
// showLegendButton.setText(SWTComponentsProviderMessages.showhideLegend);
|
| 76 |
|
showLegendButton.setImage(IImageKeys.getImage(getClass(), "icons/show_legend.png")); //$NON-NLS-1$
|
| 77 |
|
showLegendButton.setDisabledImage(IImageKeys.getImage(getClass(), "icons/show_legend_disabled.png")); //$NON-NLS-1$
|
| 78 |
|
showLegendButton.setToolTipText(ChartsUIMessages.showhideLegend);
|
| 79 |
|
|
| 80 |
75 |
showLegendButton.setSelection(chartEditor.getResult().isLegendVisible());
|
| 81 |
76 |
}
|
| 82 |
|
// // disable if not managed by the command
|
| 83 |
|
// else {
|
| 84 |
|
// showLegendButton.setEnabled(false);
|
| 85 |
|
// }
|
|
77 |
// disable if not managed by the command
|
|
78 |
else {
|
|
79 |
showLegendButton.setEnabled(false);
|
|
80 |
}
|
| 86 |
81 |
|
|
82 |
|
|
83 |
// Show/hide chart background grid button
|
|
84 |
final ToolItem showGridButton = new ToolItem(this, SWT.CHECK);
|
|
85 |
// showGridButton.setText(SWTComponentsProviderMessages.showhideGrid);
|
|
86 |
showGridButton.setImage(IImageKeys.getImage(getClass(), "icons/show_grid.png")); //$NON-NLS-1$
|
|
87 |
showGridButton.setDisabledImage(IImageKeys.getImage(getClass(), "icons/show_grid_disabled.png")); //$NON-NLS-1$
|
|
88 |
showGridButton.setToolTipText(ChartsUIMessages.showhideGrid);
|
|
89 |
|
| 87 |
90 |
if (!chartEditor.getResult().isEmptyPreference(ChartsEnginePreferences.SHOW_GRID)) {
|
| 88 |
|
showGridButton = new ToolItem(this, SWT.CHECK);
|
| 89 |
|
// showGridButton.setText(SWTComponentsProviderMessages.showhideGrid);
|
| 90 |
|
showGridButton.setImage(IImageKeys.getImage(getClass(), "icons/show_grid.png")); //$NON-NLS-1$
|
| 91 |
|
showGridButton.setDisabledImage(IImageKeys.getImage(getClass(), "icons/show_grid_disabled.png")); //$NON-NLS-1$
|
| 92 |
|
showGridButton.setToolTipText(ChartsUIMessages.showhideGrid);
|
| 93 |
|
|
| 94 |
91 |
showGridButton.setSelection(chartEditor.getResult().isGridVisible());
|
| 95 |
92 |
}
|
| 96 |
|
// // disable if not managed by the command
|
| 97 |
|
// else {
|
| 98 |
|
// showGridButton.setEnabled(false);
|
| 99 |
|
// }
|
|
93 |
// disable if not managed by the command
|
|
94 |
else {
|
|
95 |
showGridButton.setEnabled(false);
|
|
96 |
}
|
|
97 |
|
|
98 |
|
|
99 |
// Rendering colors mode selection
|
|
100 |
new ToolItem(this, SWT.SEPARATOR);
|
|
101 |
final Combo renderingModeCombo = new Combo(this, SWT.READ_ONLY);
|
|
102 |
String colorsModes[] = new String[] { ChartsUIMessages.colors,
|
|
103 |
ChartsUIMessages.grayscale,
|
|
104 |
ChartsUIMessages.blackAndWhite,
|
|
105 |
ChartsUIMessages.monochrome
|
|
106 |
};
|
|
107 |
renderingModeCombo.setItems(colorsModes);
|
| 100 |
108 |
|
|
109 |
this.addCombo(renderingModeCombo);
|
| 101 |
110 |
|
| 102 |
111 |
if (!chartEditor.getResult().isEmptyPreference(ChartsEnginePreferences.RENDERING_COLORS_MODE)) {
|
| 103 |
|
// Rendering colors mode selection
|
| 104 |
|
new ToolItem(this, SWT.SEPARATOR);
|
| 105 |
|
renderingModeCombo = new Combo(this, SWT.READ_ONLY);
|
| 106 |
|
String colorsModes[] = new String[] { ChartsUIMessages.colors,
|
| 107 |
|
ChartsUIMessages.grayscale,
|
| 108 |
|
ChartsUIMessages.blackAndWhite,
|
| 109 |
|
ChartsUIMessages.monochrome
|
| 110 |
|
};
|
| 111 |
|
renderingModeCombo.setItems(colorsModes);
|
| 112 |
|
|
| 113 |
|
// ToolItem renderingComboItem = new ToolItem(this, SWT.SEPARATOR);
|
| 114 |
|
// renderingComboItem.setControl(renderingModeCombo);
|
| 115 |
|
// renderingModeCombo.pack();
|
| 116 |
|
// renderingComboItem.setWidth(renderingModeCombo.getBounds().width);
|
| 117 |
|
|
| 118 |
|
this.addControl(renderingModeCombo);
|
| 119 |
|
|
| 120 |
112 |
renderingModeCombo.select(chartEditor.getResult().getRenderingColorsMode());
|
| 121 |
113 |
}
|
| 122 |
|
// // disable if not managed
|
| 123 |
|
// else {
|
| 124 |
|
// renderingModeCombo.setEnabled(false);
|
| 125 |
|
// }
|
|
114 |
// disable if not managed
|
|
115 |
else {
|
|
116 |
renderingModeCombo.setEnabled(false);
|
|
117 |
}
|
|
118 |
|
| 126 |
119 |
|
| 127 |
|
|
| 128 |
120 |
// Font selection
|
| 129 |
|
currentFont = ChartsEngine.createFont(chartEditor.getResult().getFont());
|
|
121 |
final Font currentFont = ChartsEngine.createFont(chartEditor.getResult().getFont());
|
| 130 |
122 |
|
| 131 |
123 |
// FIXME: SJ: may be better here to get the fonts from SWT rather than from Java, see java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
|
| 132 |
|
fontCombo = new Combo(this, SWT.READ_ONLY);
|
|
124 |
final Combo fontCombo = new Combo(this, SWT.READ_ONLY);
|
| 133 |
125 |
String fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
|
| 134 |
126 |
fontCombo.setItems(fonts);
|
| 135 |
127 |
|
| 136 |
|
// ToolItem fontsComboItem = new ToolItem(this, SWT.SEPARATOR);
|
| 137 |
|
// fontsComboItem.setControl(fontCombo);
|
| 138 |
|
// fontCombo.pack();
|
| 139 |
|
// fontsComboItem.setWidth(fontCombo.getBounds().width);
|
|
128 |
this.addCombo(fontCombo);
|
| 140 |
129 |
|
| 141 |
|
this.addControl(fontCombo);
|
| 142 |
|
|
| 143 |
130 |
int currentFontIndex = 0;
|
| 144 |
131 |
for (int i = 0; i < fonts.length; i++) {
|
| 145 |
132 |
if (fonts[i].equals(currentFont.getName())) {
|
| ... | ... | |
| 148 |
135 |
}
|
| 149 |
136 |
}
|
| 150 |
137 |
fontCombo.select(currentFontIndex);
|
| 151 |
|
|
|
138 |
|
|
139 |
|
| 152 |
140 |
// Font size
|
| 153 |
|
fontSizeCombo = new Combo(this, SWT.READ_ONLY);
|
|
141 |
final Combo fontSizeCombo = new Combo(this, SWT.READ_ONLY);
|
| 154 |
142 |
String fontSizes[] = new String[30];
|
| 155 |
143 |
int currentFontSizeIndex = 0;
|
| 156 |
144 |
for (int i = 0; i < fontSizes.length; i++) {
|
| ... | ... | |
| 162 |
150 |
}
|
| 163 |
151 |
fontSizeCombo.setItems(fontSizes);
|
| 164 |
152 |
|
| 165 |
|
// ToolItem fontSizeComboItem = new ToolItem(this, SWT.SEPARATOR);
|
| 166 |
|
// fontSizeComboItem.setControl(fontSizeCombo);
|
| 167 |
|
// fontSizeCombo.pack();
|
| 168 |
|
// fontSizeComboItem.setWidth(fontSizeCombo.getBounds().width);
|
|
153 |
this.addCombo(fontSizeCombo);
|
| 169 |
154 |
|
| 170 |
|
this.addControl(fontSizeCombo);
|
| 171 |
|
|
| 172 |
155 |
fontSizeCombo.select(currentFontSizeIndex);
|
| 173 |
156 |
|
| 174 |
|
|
|
157 |
|
| 175 |
158 |
// Font style
|
| 176 |
|
fontStyleCombo = new Combo(this, SWT.READ_ONLY);
|
|
159 |
final Combo fontStyleCombo = new Combo(this, SWT.READ_ONLY);
|
| 177 |
160 |
|
| 178 |
|
|
| 179 |
161 |
//FIXME: SJ: the styles list should be builded from the available styles of the current selected font.
|
| 180 |
162 |
// Here are some tests to try to get the available styles
|
| 181 |
163 |
|
| ... | ... | |
| 204 |
186 |
int currentFontStyleIndex = currentFont.getStyle();
|
| 205 |
187 |
fontStyleCombo.setItems(fontStyles);
|
| 206 |
188 |
|
| 207 |
|
// ToolItem fontStyleComboItem = new ToolItem(this, SWT.SEPARATOR);
|
| 208 |
|
// fontStyleComboItem.setControl(fontStyleCombo);
|
| 209 |
|
// fontStyleCombo.pack();
|
| 210 |
|
// fontStyleComboItem.setWidth(fontStyleCombo.getBounds().width);
|
|
189 |
this.addCombo(fontStyleCombo);
|
| 211 |
190 |
|
| 212 |
|
this.addControl(fontStyleCombo);
|
| 213 |
|
|
| 214 |
191 |
fontStyleCombo.select(currentFontStyleIndex);
|
| 215 |
192 |
|
| 216 |
193 |
|
| 217 |
|
|
|
194 |
// FIXME: SJ: this Combo may not be created if is not in expert mode. At this moment, it's created and hidden
|
| 218 |
195 |
// Chart types from installed chart creators in all installed charts engines
|
| 219 |
|
chartTypeCombo = new Combo(this, SWT.READ_ONLY);
|
|
196 |
final Combo chartTypeCombo = new Combo(this, SWT.READ_ONLY);
|
| 220 |
197 |
if (TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER)) {
|
| 221 |
198 |
|
| 222 |
199 |
ArrayList<String> chartsEngineNames = new ArrayList<>();
|
| ... | ... | |
| 251 |
228 |
}
|
| 252 |
229 |
chartTypeCombo.setItems(chartTypes);
|
| 253 |
230 |
|
| 254 |
|
// ToolItem chartTypeComboItem = new ToolItem(this, SWT.SEPARATOR);
|
| 255 |
|
// chartTypeComboItem.setControl(chartTypeCombo);
|
| 256 |
|
// chartTypeCombo.pack();
|
| 257 |
|
// chartTypeComboItem.setWidth(chartTypeCombo.getBounds().width);
|
|
231 |
this.addCombo(chartTypeCombo);
|
| 258 |
232 |
|
| 259 |
|
|
| 260 |
|
this.addControl(chartTypeCombo);
|
| 261 |
233 |
|
| 262 |
|
|
| 263 |
234 |
chartTypeCombo.select(currentChartCreatorIndex);
|
| 264 |
235 |
|
| 265 |
236 |
|
| ... | ... | |
| 267 |
238 |
chartTypeCombo.setVisible(false);
|
| 268 |
239 |
}
|
| 269 |
240 |
}
|
|
241 |
else {
|
|
242 |
chartTypeCombo.setVisible(false);
|
|
243 |
}
|
| 270 |
244 |
|
| 271 |
245 |
|
| 272 |
246 |
// Listeners
|
| ... | ... | |
| 332 |
306 |
|
| 333 |
307 |
}
|
| 334 |
308 |
};
|
| 335 |
|
if (showTitleButton != null) showTitleButton.addSelectionListener(listener);
|
| 336 |
|
if (showLegendButton != null) showLegendButton.addSelectionListener(listener);
|
| 337 |
|
if (showGridButton != null) showGridButton.addSelectionListener(listener);
|
| 338 |
|
if (renderingModeCombo != null) renderingModeCombo.addSelectionListener(listener);
|
| 339 |
|
if (fontCombo != null) fontCombo.addSelectionListener(listener);
|
| 340 |
|
if (fontSizeCombo != null) fontSizeCombo.addSelectionListener(listener);
|
| 341 |
|
if (fontStyleCombo != null) fontStyleCombo.addSelectionListener(listener);
|
| 342 |
|
if (chartTypeCombo != null) chartTypeCombo.addSelectionListener(listener);
|
|
309 |
|
|
310 |
|
|
311 |
// Add listener
|
|
312 |
if (showTitleButton.isEnabled()) {
|
|
313 |
showTitleButton.addSelectionListener(listener);
|
|
314 |
}
|
|
315 |
if (showLegendButton != null) {
|
|
316 |
showLegendButton.addSelectionListener(listener);
|
|
317 |
}
|
|
318 |
if (showGridButton != null) {
|
|
319 |
showGridButton.addSelectionListener(listener);
|
|
320 |
}
|
|
321 |
if (renderingModeCombo != null) {
|
|
322 |
renderingModeCombo.addSelectionListener(listener);
|
|
323 |
}
|
|
324 |
fontCombo.addSelectionListener(listener);
|
|
325 |
fontSizeCombo.addSelectionListener(listener);
|
|
326 |
fontStyleCombo.addSelectionListener(listener);
|
|
327 |
if (chartTypeCombo.isVisible()) {
|
|
328 |
chartTypeCombo.addSelectionListener(listener);
|
|
329 |
}
|
| 343 |
330 |
}
|
| 344 |
331 |
|
| 345 |
332 |
|