22 |
22 |
import org.txm.core.preferences.TBXPreferences;
|
23 |
23 |
import org.txm.core.preferences.TXMPreferences;
|
24 |
24 |
import org.txm.rcp.IImageKeys;
|
|
25 |
import org.txm.rcp.preferences.RCPPreferences;
|
25 |
26 |
import org.txm.rcp.swt.GLComposite;
|
26 |
27 |
|
27 |
28 |
/**
|
... | ... | |
32 |
33 |
*
|
33 |
34 |
*/
|
34 |
35 |
public class AdvancedChartEditorToolBar extends ChartEditorToolBar {
|
35 |
|
|
36 |
|
public final static String ID = "AdvancedChartEditorToolBar" ;
|
37 |
36 |
|
|
37 |
public final static String ID = "AdvancedChartEditorToolBar";
|
|
38 |
|
38 |
39 |
/**
|
39 |
40 |
*
|
40 |
41 |
* @param parent
|
... | ... | |
45 |
46 |
|
46 |
47 |
|
47 |
48 |
final ToolItem showTitleButton = new ToolItem(this, SWT.CHECK);
|
48 |
|
//showTitle.setText(SWTComponentsProviderMessages.showhideTitle);
|
|
49 |
// showTitle.setText(SWTComponentsProviderMessages.showhideTitle);
|
49 |
50 |
showTitleButton.setImage(IImageKeys.getImage(getClass(), "icons/show_title.png"));
|
50 |
51 |
showTitleButton.setDisabledImage(IImageKeys.getImage(getClass(), "icons/show_title_disabled.png"));
|
51 |
52 |
showTitleButton.setToolTipText(ChartsUIMessages.showhideTitle);
|
52 |
|
|
53 |
|
if(!chartEditor.getResult().isEmptyPreference(ChartsEnginePreferences.SHOW_TITLE)) {
|
|
53 |
|
|
54 |
if (!chartEditor.getResult().isEmptyPreference(ChartsEnginePreferences.SHOW_TITLE)) {
|
54 |
55 |
showTitleButton.setSelection(chartEditor.getResult().isTitleVisible());
|
55 |
56 |
}
|
56 |
57 |
// disable if not managed by the command
|
57 |
|
else {
|
|
58 |
else {
|
58 |
59 |
showTitleButton.setEnabled(false);
|
59 |
60 |
}
|
60 |
61 |
|
61 |
|
|
|
62 |
|
62 |
63 |
final ToolItem showLegendButton = new ToolItem(this, SWT.CHECK);
|
63 |
|
//showLegend.setText(SWTComponentsProviderMessages.showhideLegend);
|
|
64 |
// showLegend.setText(SWTComponentsProviderMessages.showhideLegend);
|
64 |
65 |
showLegendButton.setImage(IImageKeys.getImage(getClass(), "icons/show_legend.png"));
|
65 |
66 |
showLegendButton.setDisabledImage(IImageKeys.getImage(getClass(), "icons/show_legend_disabled.png"));
|
66 |
67 |
showLegendButton.setToolTipText(ChartsUIMessages.showhideLegend);
|
67 |
|
|
68 |
|
if(!chartEditor.getResult().isEmptyPreference(ChartsEnginePreferences.SHOW_LEGEND)) {
|
|
68 |
|
|
69 |
if (!chartEditor.getResult().isEmptyPreference(ChartsEnginePreferences.SHOW_LEGEND)) {
|
69 |
70 |
showLegendButton.setSelection(chartEditor.getResult().isLegendVisible());
|
70 |
71 |
}
|
71 |
72 |
// disable if not managed by the command
|
72 |
|
else {
|
|
73 |
else {
|
73 |
74 |
showLegendButton.setEnabled(false);
|
74 |
75 |
}
|
75 |
|
|
76 |
76 |
|
|
77 |
|
77 |
78 |
final ToolItem showGridButton = new ToolItem(this, SWT.CHECK);
|
78 |
|
//showGrid.setText(SWTComponentsProviderMessages.showhideGrid);
|
|
79 |
// showGrid.setText(SWTComponentsProviderMessages.showhideGrid);
|
79 |
80 |
showGridButton.setImage(IImageKeys.getImage(getClass(), "icons/show_grid.png"));
|
80 |
81 |
showGridButton.setDisabledImage(IImageKeys.getImage(getClass(), "icons/show_grid_disabled.png"));
|
81 |
82 |
showGridButton.setToolTipText(ChartsUIMessages.showhideGrid);
|
82 |
83 |
|
83 |
|
if(!chartEditor.getResult().isEmptyPreference(ChartsEnginePreferences.SHOW_GRID)) {
|
|
84 |
if (!chartEditor.getResult().isEmptyPreference(ChartsEnginePreferences.SHOW_GRID)) {
|
84 |
85 |
showGridButton.setSelection(chartEditor.getResult().isGridVisible());
|
85 |
86 |
}
|
86 |
87 |
// disable if not managed by the command
|
87 |
|
else {
|
|
88 |
else {
|
88 |
89 |
showGridButton.setEnabled(false);
|
89 |
90 |
}
|
90 |
|
|
91 |
91 |
|
92 |
92 |
|
|
93 |
|
93 |
94 |
// Rendering colors mode selection
|
94 |
95 |
new ToolItem(this, SWT.SEPARATOR);
|
95 |
96 |
final Combo renderingModeCombo = new Combo(this, SWT.READ_ONLY);
|
96 |
|
String colorsModes[] = new String[]{ChartsUIMessages.colors,
|
97 |
|
ChartsUIMessages.grayscale,
|
98 |
|
ChartsUIMessages.blackAndWhite,
|
99 |
|
ChartsUIMessages.monochrome
|
100 |
|
};
|
|
97 |
String colorsModes[] = new String[] { ChartsUIMessages.colors,
|
|
98 |
ChartsUIMessages.grayscale,
|
|
99 |
ChartsUIMessages.blackAndWhite,
|
|
100 |
ChartsUIMessages.monochrome
|
|
101 |
};
|
101 |
102 |
renderingModeCombo.setItems(colorsModes);
|
102 |
103 |
|
103 |
104 |
ToolItem renderingComboItem = new ToolItem(this, SWT.SEPARATOR);
|
... | ... | |
105 |
106 |
renderingModeCombo.pack();
|
106 |
107 |
renderingComboItem.setWidth(renderingModeCombo.getBounds().width);
|
107 |
108 |
|
108 |
|
if(!chartEditor.getResult().isEmptyPreference(ChartsEnginePreferences.RENDERING_COLORS_MODE)) {
|
|
109 |
if (!chartEditor.getResult().isEmptyPreference(ChartsEnginePreferences.RENDERING_COLORS_MODE)) {
|
109 |
110 |
renderingModeCombo.select(chartEditor.getResult().getRenderingColorsMode());
|
110 |
111 |
}
|
111 |
112 |
// disable if not managed
|
112 |
|
else {
|
|
113 |
else {
|
113 |
114 |
renderingModeCombo.setEnabled(false);
|
114 |
115 |
}
|
115 |
116 |
|
... | ... | |
118 |
119 |
final Font currentFont = ChartsEngine.createFont(chartEditor.getResult().getFont());
|
119 |
120 |
|
120 |
121 |
final Combo fontCombo = new Combo(this, SWT.READ_ONLY);
|
121 |
|
String fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); //FIXME: SJ: maybe better here to get the fonts from SWT rather than from Java
|
|
122 |
String fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); // FIXME: SJ: may be better here to get the fonts from SWT rather than from Java
|
122 |
123 |
fontCombo.setItems(fonts);
|
123 |
|
|
|
124 |
|
124 |
125 |
ToolItem fontsComboItem = new ToolItem(this, SWT.SEPARATOR);
|
125 |
126 |
fontsComboItem.setControl(fontCombo);
|
126 |
127 |
fontCombo.pack();
|
127 |
128 |
fontsComboItem.setWidth(fontCombo.getBounds().width);
|
128 |
129 |
|
129 |
130 |
int currentFontIndex = 0;
|
130 |
|
for(int i = 0; i < fonts.length; i++) {
|
131 |
|
if(fonts[i].equals(currentFont.getName())) {
|
|
131 |
for (int i = 0; i < fonts.length; i++) {
|
|
132 |
if (fonts[i].equals(currentFont.getName())) {
|
132 |
133 |
currentFontIndex = i;
|
133 |
134 |
break;
|
134 |
135 |
}
|
135 |
136 |
}
|
136 |
137 |
fontCombo.select(currentFontIndex);
|
137 |
138 |
|
138 |
|
|
|
139 |
|
139 |
140 |
// Font size
|
140 |
141 |
final Combo fontSizeCombo = new Combo(this, SWT.READ_ONLY);
|
141 |
142 |
String fontSizes[] = new String[30];
|
142 |
143 |
int currentFontSizeIndex = 0;
|
143 |
|
for(int i = 0; i < fontSizes.length; i++) {
|
|
144 |
for (int i = 0; i < fontSizes.length; i++) {
|
144 |
145 |
fontSizes[i] = String.valueOf(i + 1);
|
145 |
|
if(currentFont.getSize() == (i + 1)) {
|
|
146 |
if (currentFont.getSize() == (i + 1)) {
|
146 |
147 |
currentFontSizeIndex = i;
|
147 |
148 |
}
|
148 |
149 |
|
... | ... | |
155 |
156 |
fontSizeComboItem.setWidth(fontSizeCombo.getBounds().width);
|
156 |
157 |
|
157 |
158 |
fontSizeCombo.select(currentFontSizeIndex);
|
158 |
|
|
159 |
159 |
|
|
160 |
|
160 |
161 |
// Chart types from installed chart creators in all installed charts engines
|
161 |
162 |
final Combo chartTypeCombo = new Combo(this, SWT.READ_ONLY);
|
162 |
|
if(TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER)) {
|
163 |
|
|
164 |
|
ArrayList<String> chartsEngineNames = new ArrayList<String>();
|
165 |
|
ArrayList<ChartCreator> allChartCreators = new ArrayList<ChartCreator>();
|
|
163 |
if (TBXPreferences.getInstance().getBoolean(TBXPreferences.EXPERT_USER)) {
|
166 |
164 |
|
|
165 |
ArrayList<String> chartsEngineNames = new ArrayList<>();
|
|
166 |
ArrayList<ChartCreator> allChartCreators = new ArrayList<>();
|
|
167 |
|
167 |
168 |
for (int i = 0; i < ChartsEngine.getChartsEngines().size(); i++) {
|
168 |
169 |
ArrayList<ChartCreator> chartCreators = ChartsEngine.getChartsEngines().get(i).getChartCreators(this.getEditorPart().getResult());
|
169 |
170 |
for (int j = 0; j < chartCreators.size(); j++) {
|
... | ... | |
176 |
177 |
String chartTypes[] = new String[allChartCreators.size()];
|
177 |
178 |
int currentChartCreatorIndex = 0;
|
178 |
179 |
|
179 |
|
for(int i = 0; i < allChartCreators.size(); i++) {
|
|
180 |
for (int i = 0; i < allChartCreators.size(); i++) {
|
180 |
181 |
|
181 |
182 |
chartTypes[i] = allChartCreators.get(i).getChartType();
|
182 |
|
if(chartTypes[i] == null) {
|
|
183 |
if (chartTypes[i] == null) {
|
183 |
184 |
chartTypes[i] = ChartsEnginePreferences.DEFAULT_CHART_TYPE;
|
184 |
185 |
}
|
185 |
186 |
|
186 |
187 |
// preselected combo index
|
187 |
|
if(this.getEditorPart().getChartType() != null && this.getEditorPart().getChartType().equals(chartTypes[i])
|
|
188 |
if (this.getEditorPart().getChartType() != null && this.getEditorPart().getChartType().equals(chartTypes[i])
|
188 |
189 |
&& this.getEditorPart().getResult().getChartsEngine().getName().equals(chartsEngineNames.get(i))) {
|
189 |
190 |
currentChartCreatorIndex = i;
|
190 |
191 |
}
|
... | ... | |
202 |
203 |
chartTypeCombo.select(currentChartCreatorIndex);
|
203 |
204 |
|
204 |
205 |
|
205 |
|
if(allChartCreators.size() < 2) {
|
|
206 |
if (allChartCreators.size() < 2) {
|
206 |
207 |
chartTypeCombo.setVisible(false);
|
207 |
208 |
}
|
208 |
209 |
}
|
... | ... | |
218 |
219 |
|
219 |
220 |
|
220 |
221 |
// FIXME: SJ: title, legend, grid visibility etc. should use the autoUpdateEditor annotation parameters copy functions
|
221 |
|
if(e.getSource() == showTitleButton) {
|
|
222 |
if (e.getSource() == showTitleButton) {
|
222 |
223 |
getEditorPart().getResult().setTitleVisible(showTitleButton.getSelection());
|
223 |
224 |
}
|
224 |
|
else if(e.getSource() == showLegendButton) {
|
|
225 |
else if (e.getSource() == showLegendButton) {
|
225 |
226 |
getEditorPart().getResult().setLegendVisible(showLegendButton.getSelection());
|
226 |
227 |
}
|
227 |
|
else if(e.getSource() == showGridButton) {
|
|
228 |
else if (e.getSource() == showGridButton) {
|
228 |
229 |
getEditorPart().getResult().setGridVisible(showGridButton.getSelection());
|
229 |
230 |
}
|
230 |
|
else if(e.getSource() == renderingModeCombo) {
|
|
231 |
else if (e.getSource() == renderingModeCombo) {
|
231 |
232 |
getEditorPart().getResult().setRenderingColorsMode(renderingModeCombo.getSelectionIndex());
|
232 |
233 |
}
|
233 |
234 |
// end of FIXME
|
234 |
235 |
|
235 |
|
|
236 |
|
else if(e.getSource() == fontCombo || e.getSource() == fontSizeCombo) {
|
|
236 |
// Font
|
|
237 |
else if (e.getSource() == fontCombo || e.getSource() == fontSizeCombo) {
|
237 |
238 |
getEditorPart().getResult().setFont("1|" + fontCombo.getItem(fontCombo.getSelectionIndex()) + "|" + fontSizeCombo.getItem(fontSizeCombo.getSelectionIndex()) + "|0"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
238 |
239 |
}
|
239 |
|
else if(e.getSource() == chartTypeCombo) {
|
|
240 |
// Chart type / chart creators
|
|
241 |
else if (e.getSource() == chartTypeCombo) {
|
240 |
242 |
|
241 |
243 |
String[] data = StringUtils.split(chartTypeCombo.getItem(chartTypeCombo.getSelectionIndex()), '/');
|
242 |
244 |
data[0] = StringUtils.trim(data[0]);
|
... | ... | |
245 |
247 |
getEditorPart().getResult().setChartsEngine((ChartsEngine) Toolbox.getEngineManager(EngineType.CHARTS).getEngine(data[0]));
|
246 |
248 |
update = false;
|
247 |
249 |
}
|
248 |
|
|
|
250 |
|
249 |
251 |
getEditorPart().getResult().setChartDirty();
|
|
252 |
getEditorPart().setDirty(true);
|
250 |
253 |
|
251 |
|
// updates or creates chart
|
252 |
|
getEditorPart().compute(update);
|
253 |
|
getEditorPart().setFocus();
|
|
254 |
if (RCPPreferences.getInstance().getBoolean(RCPPreferences.AUTO_UPDATE_EDITOR)) {
|
|
255 |
// updates or creates chart
|
|
256 |
getEditorPart().compute(update);
|
|
257 |
getEditorPart().setFocus();
|
|
258 |
}
|
254 |
259 |
}
|
255 |
260 |
|
256 |
261 |
@Override
|
... | ... | |
267 |
272 |
fontSizeCombo.addSelectionListener(listener);
|
268 |
273 |
chartTypeCombo.addSelectionListener(listener);
|
269 |
274 |
}
|
270 |
|
|
271 |
|
|
272 |
275 |
|
|
276 |
|
|
277 |
|
273 |
278 |
@Override
|
274 |
|
protected void checkSubclass() { } // if this method is not defined then the ToolBar cannot be subclassed
|
|
279 |
protected void checkSubclass() {} // if this method is not defined then the ToolBar cannot be subclassed
|
275 |
280 |
|
276 |
|
|
277 |
|
}
|
|
281 |
|
|
282 |
}
|