|
7 | 7 | ******************************************************************************/ |
8 | 8 | package org.csstudio.trends.databrowser3.ui.properties; |
9 | 9 |
|
10 | | -import java.time.Duration; |
| 10 | +import java.io.IOException; |
| 11 | +import java.util.ResourceBundle; |
11 | 12 |
|
| 13 | +import javafx.fxml.FXMLLoader; |
12 | 14 | import org.csstudio.trends.databrowser3.Messages; |
13 | 15 | import org.csstudio.trends.databrowser3.model.Model; |
14 | | -import org.csstudio.trends.databrowser3.model.ModelListener; |
| 16 | +import org.phoebus.framework.nls.NLS; |
15 | 17 | import org.phoebus.ui.undo.UndoableActionManager; |
16 | 18 |
|
17 | | -import javafx.geometry.Insets; |
18 | | -import javafx.scene.control.CheckBox; |
19 | | -import javafx.scene.control.ColorPicker; |
20 | | -import javafx.scene.control.Label; |
21 | 19 | import javafx.scene.control.Tab; |
22 | | -import javafx.scene.control.TextField; |
23 | | -import javafx.scene.control.Tooltip; |
24 | | -import javafx.scene.layout.GridPane; |
25 | 20 |
|
26 | 21 | /** Property tab for misc. items |
27 | 22 | * @author Kay Kasemir |
28 | 23 | */ |
29 | 24 | @SuppressWarnings("nls") |
30 | 25 | public class MiscTab extends Tab |
31 | 26 | { |
32 | | - private final Model model; |
33 | | - |
34 | | - /** Flag to prevent recursion when this tab updates the model and thus triggers the model_listener */ |
35 | | - private boolean updating = false; |
36 | | - |
37 | | - private final TextField title = new TextField(), update_period = new TextField(), scroll_step = new TextField(); |
38 | | - private CheckBox save_changes = new CheckBox(), show_legend = new CheckBox(); |
39 | | - private ColorPicker foreground = new ColorPicker(), background = new ColorPicker(); |
40 | | - private FontButton title_font, label_font, scale_font, legend_font; |
41 | | - |
42 | | - /** Update Tab when model changes (undo, ...) */ |
43 | | - private ModelListener model_listener = new ModelListener() |
44 | | - { |
45 | | - @Override |
46 | | - public void changedSaveChangesBehavior(boolean do_save_changes) |
47 | | - { |
48 | | - if (updating) |
49 | | - return; |
50 | | - save_changes.setSelected(do_save_changes); |
51 | | - } |
52 | | - |
53 | | - @Override |
54 | | - public void changedLayout() |
55 | | - { |
56 | | - if (updating) |
57 | | - return; |
58 | | - show_legend.setSelected(model.isLegendVisible()); |
59 | | - } |
60 | | - |
61 | | - @Override |
62 | | - public void changedTitle() |
63 | | - { |
64 | | - if (updating) |
65 | | - return; |
66 | | - title.setText(model.getTitle().orElse("")); |
67 | | - } |
68 | | - |
69 | | - @Override |
70 | | - public void changedColorsOrFonts() |
71 | | - { |
72 | | - if (updating) |
73 | | - return; |
74 | | - foreground.setValue(model.getPlotForeground()); |
75 | | - background.setValue(model.getPlotBackground()); |
76 | | - title_font.selectFont(model.getTitleFont()); |
77 | | - label_font.selectFont(model.getLabelFont()); |
78 | | - scale_font.selectFont(model.getScaleFont()); |
79 | | - legend_font.selectFont(model.getLegendFont()); |
80 | | - } |
81 | | - |
82 | | - @Override |
83 | | - public void changedTiming() |
84 | | - { |
85 | | - if (updating) |
86 | | - return; |
87 | | - update_period.setText(Double.toString(model.getUpdatePeriod())); |
88 | | - scroll_step.setText(Double.toString(model.getScrollStep().toMillis() / 1000.0)); |
89 | | - } |
90 | | - }; |
91 | | - |
92 | | - |
93 | 27 | MiscTab(final Model model, final UndoableActionManager undo) |
94 | 28 | { |
95 | | - super(Messages.Miscellaneous); |
96 | | - this.model = model; |
97 | | - |
98 | | - final GridPane layout = new GridPane(); |
99 | | - layout.setHgap(5); |
100 | | - layout.setVgap(5); |
101 | | - layout.setPadding(new Insets(5)); |
102 | | - // layout.setGridLinesVisible(true); // Debug layout |
103 | | - |
104 | | - |
105 | | - layout.add(new Label(Messages.TitleLbl), 0, 0); |
106 | | - title.setTooltip(new Tooltip(Messages.TitleTT)); |
107 | | - title.setOnAction(event -> |
108 | | - { |
109 | | - updating = true; |
110 | | - new ChangeTitleCommand(model, undo, title.getText()); |
111 | | - updating = false; |
112 | | - }); |
113 | | - layout.add(title, 1, 0); |
114 | 29 |
|
115 | | - layout.add(new Label(Messages.UpdatePeriodLbl), 0, 1); |
116 | | - layout.add(update_period, 1, 1); |
117 | | - update_period.setOnAction(event -> |
118 | | - { |
119 | | - updating = true; |
120 | | - final double period = Double.parseDouble(update_period.getText().trim()); |
121 | | - new ChangeUpdatePeriodCommand(model, undo, period); |
122 | | - updating = false; |
123 | | - }); |
124 | | - |
125 | | - layout.add(new Label(Messages.ScrollStepLbl), 0, 2); |
126 | | - layout.add(scroll_step, 1, 2); |
127 | | - scroll_step.setOnAction(event -> |
128 | | - { |
129 | | - updating = true; |
130 | | - try |
131 | | - { |
132 | | - final Duration step = Duration.ofMillis( |
133 | | - Math.round( Double.parseDouble(scroll_step.getText().trim()) * 1000.0 ) ); |
134 | | - new ChangeScrollStepCommand(model, undo, step); |
135 | | - } |
136 | | - catch (Exception ex) |
137 | | - { |
138 | | - scroll_step.setText(Double.toString(model.getScrollStep().toMillis() / 1000.0)); |
| 30 | + super(Messages.Miscellaneous); |
| 31 | + ResourceBundle resourceBundle = NLS.getMessages(Messages.class); |
| 32 | + FXMLLoader loader = new FXMLLoader(); |
| 33 | + loader.setResources(resourceBundle); |
| 34 | + loader.setLocation(this.getClass().getResource("MiscTab.fxml")); |
| 35 | + |
| 36 | + loader.setControllerFactory(clazz -> { |
| 37 | + if(clazz.isAssignableFrom(MiscTabController.class)){ |
| 38 | + try { |
| 39 | + return clazz.getConstructor(Model.class, UndoableActionManager.class).newInstance(model, undo); |
| 40 | + } catch (Exception e) { |
| 41 | + throw new RuntimeException(e); |
| 42 | + } |
139 | 43 | } |
140 | | - updating = false; |
141 | | - }); |
142 | | - |
143 | | - layout.add(new Label(Messages.ForegroundColorLbl), 0, 3); |
144 | | - foreground.setStyle("-fx-color-label-visible: false ;"); |
145 | | - layout.add(foreground, 1, 3); |
146 | | - foreground.setValue(model.getPlotForeground()); |
147 | | - foreground.setOnAction(event -> |
148 | | - { |
149 | | - updating = true; |
150 | | - new ChangePlotForegroundCommand(model, undo, foreground.getValue()); |
151 | | - updating = false; |
152 | | - }); |
153 | | - |
154 | | - layout.add(new Label(Messages.BackgroundColorLbl), 0, 4); |
155 | | - background.setStyle("-fx-color-label-visible: false ;"); |
156 | | - layout.add(background, 1, 4); |
157 | | - background.setValue(model.getPlotBackground()); |
158 | | - background.setOnAction(event -> |
159 | | - { |
160 | | - updating = true; |
161 | | - new ChangePlotBackgroundCommand(model, undo, background.getValue()); |
162 | | - updating = false; |
163 | | - }); |
164 | | - |
165 | | - layout.add(new Label(Messages.SaveChangesLbl), 0, 5); |
166 | | - save_changes.setTooltip(new Tooltip(Messages.SaveChangesTT)); |
167 | | - save_changes.setOnAction(event -> |
168 | | - { |
169 | | - updating = true; |
170 | | - new ChangeSaveChangesCommand(model, undo, save_changes.isSelected()); |
171 | | - updating = false; |
| 44 | + return null; |
172 | 45 | }); |
173 | | - layout.add(save_changes, 1, 5); |
174 | 46 |
|
175 | | - layout.add(new Label(Messages.TitleFontLbl), 2, 0); |
176 | | - title_font = new FontButton(model.getTitleFont(), |
177 | | - font -> new ChangeFontCommand(model, undo, model.getTitleFont(), font, (m, f) -> m.setTitleFont(f))); |
178 | | - title_font.setMaxWidth(Double.MAX_VALUE); |
179 | | - layout.add(title_font, 3, 0); |
180 | | - |
181 | | - layout.add(new Label(Messages.LabelFontLbl), 2, 1); |
182 | | - label_font = new FontButton(model.getLabelFont(), |
183 | | - font -> new ChangeFontCommand(model, undo, model.getLabelFont(), font, (m, f) -> m.setLabelFont(f))); |
184 | | - label_font.setMaxWidth(Double.MAX_VALUE); |
185 | | - layout.add(label_font, 3, 1); |
186 | | - |
187 | | - layout.add(new Label(Messages.ScaleFontLbl), 2, 2); |
188 | | - scale_font = new FontButton(model.getScaleFont(), |
189 | | - font -> new ChangeFontCommand(model, undo, model.getScaleFont(), font, (m, f) -> m.setScaleFont(f))); |
190 | | - scale_font.setMaxWidth(Double.MAX_VALUE); |
191 | | - layout.add(scale_font, 3, 2); |
192 | | - |
193 | | - layout.add(new Label(Messages.LegendFontLbl), 2, 3); |
194 | | - legend_font = new FontButton(model.getLegendFont(), |
195 | | - font -> new ChangeFontCommand(model, undo, model.getLegendFont(), font, (m, f) -> m.setLegendFont(f))); |
196 | | - legend_font.setMaxWidth(Double.MAX_VALUE); |
197 | | - layout.add(legend_font, 3, 3); |
198 | | - |
199 | | - layout.add(new Label(Messages.LegendLbl), 2, 4); |
200 | | - show_legend.setOnAction(event -> |
201 | | - { |
202 | | - updating = true; |
203 | | - new ChangeShowLegendCommand(model, undo, show_legend.isSelected()); |
204 | | - updating = false; |
205 | | - }); |
206 | | - layout.add(show_legend, 3, 4); |
207 | | - |
208 | | - setContent(layout); |
209 | | - |
210 | | - model.addListener(model_listener); |
211 | | - |
212 | | - // Initial values |
213 | | - model_listener.changedTitle(); |
214 | | - model_listener.changedColorsOrFonts(); |
215 | | - model_listener.changedSaveChangesBehavior(model.shouldSaveChanges()); |
216 | | - model_listener.changedTiming(); |
217 | | - model_listener.changedLayout(); |
| 47 | + try { |
| 48 | + setContent(loader.load()); |
| 49 | + } catch (IOException e) { |
| 50 | + throw new RuntimeException(e); |
| 51 | + } |
218 | 52 | } |
219 | 53 | } |
0 commit comments