Skip to content

Commit 30e4fc2

Browse files
committed
Unified GUI
1 parent af58f82 commit 30e4fc2

5 files changed

Lines changed: 119 additions & 94 deletions

File tree

JavaGUI/src/martin/tempest/gui/Main.java

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.awt.Rectangle;
66
import java.awt.Toolkit;
77

8-
import javax.swing.JDialog;
98
import javax.swing.JFrame;
109
import javax.swing.JComboBox;
1110
import javax.swing.JButton;
@@ -19,6 +18,7 @@
1918

2019
import martin.tempest.core.TSDRLibrary;
2120
import martin.tempest.core.TSDRLibrary.SYNC_DIRECTION;
21+
import martin.tempest.core.exceptions.TSDRAlreadyRunningException;
2222
import martin.tempest.core.exceptions.TSDRException;
2323
import martin.tempest.core.exceptions.TSDRLoadPluginException;
2424
import martin.tempest.gui.HoldButton.HoldListener;
@@ -34,6 +34,7 @@
3434
import javax.swing.SwingConstants;
3535
import javax.swing.event.ChangeListener;
3636
import javax.swing.event.ChangeEvent;
37+
import javax.swing.text.html.HTMLDocument.HTMLReader.IsindexAction;
3738
import javax.swing.JCheckBox;
3839

3940
import java.awt.event.KeyAdapter;
@@ -44,6 +45,10 @@
4445
import java.awt.event.MouseEvent;
4546
import java.util.prefs.Preferences;
4647

48+
import javax.swing.JPanel;
49+
import javax.swing.border.TitledBorder;
50+
import javax.swing.UIManager;
51+
4752
public class Main implements TSDRLibrary.FrameReadyCallback, TSDRSourceParamChangedListener {
4853

4954
private final static int OSD_TIME = 2000;
@@ -97,7 +102,7 @@ public class Main implements TSDRLibrary.FrameReadyCallback, TSDRSourceParamChan
97102
private JTextField txtFramerate;
98103
private HoldButton btnLowerFramerate, btnHigherFramerate, btnUp, btnDown, btnLeft, btnRight;
99104
private String current_plugin_name = "";
100-
private JDialog plugindialog = null;
105+
private JPanel pnInputDeviceSettings;
101106

102107
private final TSDRSource[] souces = TSDRSource.getAvailableSources();
103108
private final VideoMode[] videomodes = VideoMode.getVideoModes();
@@ -153,7 +158,7 @@ private void initialize() {
153158
frmTempestSdr.addKeyListener(keyhook);
154159
frmTempestSdr.setResizable(false);
155160
frmTempestSdr.setTitle("TempestSDR");
156-
frmTempestSdr.setBounds(100, 100, 734, 561);
161+
frmTempestSdr.setBounds(100, 100, 749, 654);
157162
frmTempestSdr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
158163
frmTempestSdr.getContentPane().setLayout(null);
159164
frmTempestSdr.addMouseListener(new MouseAdapter() {
@@ -188,7 +193,7 @@ public void mouseClicked(MouseEvent e) {
188193

189194
}
190195
});
191-
visualizer.setBounds(0, 32, 563, 433);
196+
visualizer.setBounds(12, 13, 551, 422);
192197
frmTempestSdr.getContentPane().add(visualizer);
193198

194199
cbDevice = new JComboBox();
@@ -201,12 +206,12 @@ public void actionPerformed(ActionEvent arg0) {
201206
onPluginSelected();
202207
}
203208
});
204-
cbDevice.setBounds(0, 3, 218, 22);
209+
cbDevice.setBounds(12, 448, 218, 22);
205210
frmTempestSdr.getContentPane().add(cbDevice);
206211

207212
btnStartStop = new JButton("Start");
208213
btnStartStop.setEnabled(false);
209-
btnStartStop.setBounds(568, 2, 159, 25);
214+
btnStartStop.setBounds(575, 13, 159, 25);
210215
btnStartStop.addActionListener(new ActionListener() {
211216
public void actionPerformed(ActionEvent e) {
212217
performStartStop();
@@ -215,7 +220,7 @@ public void actionPerformed(ActionEvent e) {
215220
frmTempestSdr.getContentPane().add(btnStartStop);
216221

217222
cbVideoModes = new JComboBox();
218-
cbVideoModes.setBounds(568, 32, 159, 22);
223+
cbVideoModes.setBounds(575, 43, 159, 22);
219224
cbVideoModes.setModel(new DefaultComboBoxModel(videomodes));
220225
if (closest_videomode_id != -1) cbVideoModes.setSelectedIndex(closest_videomode_id);
221226
cbVideoModes.addActionListener(new ActionListener() {
@@ -227,7 +232,7 @@ public void actionPerformed(ActionEvent arg0) {
227232

228233
JLabel lblWidth = new JLabel("Width:");
229234
lblWidth.setHorizontalAlignment(SwingConstants.RIGHT);
230-
lblWidth.setBounds(568, 62, 65, 16);
235+
lblWidth.setBounds(575, 73, 65, 16);
231236
frmTempestSdr.getContentPane().add(lblWidth);
232237

233238
spWidth = new JSpinner();
@@ -236,13 +241,13 @@ public void stateChanged(ChangeEvent arg0) {
236241
onResolutionChange();
237242
}
238243
});
239-
spWidth.setBounds(638, 59, 89, 22);
244+
spWidth.setBounds(645, 70, 89, 22);
240245
spWidth.setModel(new SpinnerNumberModel(width_initial, 1, 10000, 1));
241246
frmTempestSdr.getContentPane().add(spWidth);
242247

243248
JLabel lblHeight = new JLabel("Height:");
244249
lblHeight.setHorizontalAlignment(SwingConstants.RIGHT);
245-
lblHeight.setBounds(568, 89, 65, 16);
250+
lblHeight.setBounds(575, 100, 65, 16);
246251
frmTempestSdr.getContentPane().add(lblHeight);
247252

248253
spHeight = new JSpinner();
@@ -251,18 +256,18 @@ public void stateChanged(ChangeEvent arg0) {
251256
onResolutionChange();
252257
}
253258
});
254-
spHeight.setBounds(638, 86, 89, 22);
259+
spHeight.setBounds(645, 97, 89, 22);
255260
spHeight.setModel(new SpinnerNumberModel(height_initial, 1, 10000, 1));
256261
frmTempestSdr.getContentPane().add(spHeight);
257262

258263
JLabel lblFramerate = new JLabel("Framerate:");
259264
lblFramerate.setHorizontalAlignment(SwingConstants.RIGHT);
260-
lblFramerate.setBounds(568, 116, 65, 16);
265+
lblFramerate.setBounds(575, 127, 65, 16);
261266
frmTempestSdr.getContentPane().add(lblFramerate);
262267

263268
lblGain = new JLabel("Gain:");
264-
lblGain.setHorizontalAlignment(SwingConstants.RIGHT);
265-
lblGain.setBounds(0, 502, 218, 16);
269+
lblGain.setHorizontalAlignment(SwingConstants.LEFT);
270+
lblGain.setBounds(575, 419, 65, 16);
266271
frmTempestSdr.getContentPane().add(lblGain);
267272

268273
slGain = new JSlider();
@@ -272,12 +277,12 @@ public void stateChanged(ChangeEvent e) {
272277
onGainLevelChanged();
273278
}
274279
});
275-
slGain.setBounds(223, 497, 340, 26);
280+
slGain.setBounds(575, 444, 159, 26);
276281
frmTempestSdr.getContentPane().add(slGain);
277282

278283
lblFrequency = new JLabel("Frequency:");
279284
lblFrequency.setHorizontalAlignment(SwingConstants.RIGHT);
280-
lblFrequency.setBounds(0, 473, 218, 16);
285+
lblFrequency.setBounds(242, 448, 65, 16);
281286
frmTempestSdr.getContentPane().add(lblFrequency);
282287

283288
spFrequency = new JSpinner();
@@ -286,7 +291,7 @@ public void stateChanged(ChangeEvent arg0) {
286291
onCenterFreqChange();
287292
}
288293
});
289-
spFrequency.setBounds(223, 470, 340, 22);
294+
spFrequency.setBounds(319, 448, 244, 22);
290295
spFrequency.setModel(frequency_spinner_model);
291296
frmTempestSdr.getContentPane().add(spFrequency);
292297

@@ -297,7 +302,7 @@ public void actionPerformed(ActionEvent arg0) {
297302
}
298303
});
299304
chckbxInvertedColours.setHorizontalAlignment(SwingConstants.LEFT);
300-
chckbxInvertedColours.setBounds(568, 169, 159, 25);
305+
chckbxInvertedColours.setBounds(575, 180, 159, 25);
301306
frmTempestSdr.getContentPane().add(chckbxInvertedColours);
302307

303308
btnUp = new HoldButton("Up");
@@ -306,7 +311,7 @@ public void onHold(final int clickssofar) {
306311
onSync(SYNC_DIRECTION.UP, clickssofar);
307312
}
308313
});
309-
btnUp.setBounds(608, 244, 78, 25);
314+
btnUp.setBounds(615, 255, 78, 25);
310315
frmTempestSdr.getContentPane().add(btnUp);
311316

312317
btnLeft = new HoldButton("Left");
@@ -315,7 +320,7 @@ public void onHold(final int clickssofar) {
315320
onSync(SYNC_DIRECTION.LEFT, clickssofar);
316321
}
317322
});
318-
btnLeft.setBounds(568, 269, 65, 25);
323+
btnLeft.setBounds(575, 280, 65, 25);
319324
frmTempestSdr.getContentPane().add(btnLeft);
320325

321326
btnRight = new HoldButton("Right");
@@ -324,7 +329,7 @@ public void onHold(final int clickssofar) {
324329
onSync(SYNC_DIRECTION.RIGHT, clickssofar);
325330
}
326331
});
327-
btnRight.setBounds(662, 269, 65, 25);
332+
btnRight.setBounds(669, 280, 65, 25);
328333
frmTempestSdr.getContentPane().add(btnRight);
329334

330335
btnDown = new HoldButton("Down");
@@ -333,7 +338,7 @@ public void onHold(final int clickssofar) {
333338
onSync(SYNC_DIRECTION.DOWN, clickssofar);
334339
}
335340
});
336-
btnDown.setBounds(608, 295, 78, 25);
341+
btnDown.setBounds(615, 306, 78, 25);
337342
frmTempestSdr.getContentPane().add(btnDown);
338343

339344
txtFramerate = new JTextField();
@@ -352,7 +357,7 @@ public void keyReleased(KeyEvent evt) {
352357
onFrameRateTextChanged();
353358
}
354359
});
355-
txtFramerate.setBounds(638, 113, 89, 22);
360+
txtFramerate.setBounds(645, 124, 89, 22);
356361
frmTempestSdr.getContentPane().add(txtFramerate);
357362
txtFramerate.setColumns(10);
358363

@@ -362,7 +367,7 @@ public void onHold(final int clickssofar) {
362367
onFrameRateChanged(true, clickssofar);
363368
}
364369
});
365-
btnLowerFramerate.setBounds(638, 135, 41, 25);
370+
btnLowerFramerate.setBounds(645, 146, 41, 25);
366371
frmTempestSdr.getContentPane().add(btnLowerFramerate);
367372

368373
btnHigherFramerate = new HoldButton(">");
@@ -371,12 +376,12 @@ public void onHold(final int clickssofar) {
371376
onFrameRateChanged(false, clickssofar);
372377
}
373378
});
374-
btnHigherFramerate.setBounds(686, 135, 41, 25);
379+
btnHigherFramerate.setBounds(693, 146, 41, 25);
375380
frmTempestSdr.getContentPane().add(btnHigherFramerate);
376381

377382
slMotionBlur = new JSlider();
378383
slMotionBlur.setValue((int) (prefs.getFloat(PREF_MOTIONBLUR, 0.0f) * (slMotionBlur.getMaximum() - slMotionBlur.getMinimum()) + slMotionBlur.getMinimum()));
379-
slMotionBlur.setBounds(638, 201, 89, 22);
384+
slMotionBlur.setBounds(645, 212, 89, 22);
380385
slMotionBlur.addChangeListener(new ChangeListener() {
381386
public void stateChanged(ChangeEvent e) {
382387
onMotionBlurLevelChanged();
@@ -386,9 +391,15 @@ public void stateChanged(ChangeEvent e) {
386391

387392
JLabel lblMotionBlur = new JLabel("Lowpass:");
388393
lblMotionBlur.setHorizontalAlignment(SwingConstants.RIGHT);
389-
lblMotionBlur.setBounds(568, 201, 65, 16);
394+
lblMotionBlur.setBounds(575, 212, 65, 16);
390395
frmTempestSdr.getContentPane().add(lblMotionBlur);
391396

397+
pnInputDeviceSettings = new JPanel();
398+
pnInputDeviceSettings.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Input device settings", TitledBorder.LEADING, TitledBorder.TOP, null, null));
399+
pnInputDeviceSettings.setBounds(12, 483, 704, 123);
400+
frmTempestSdr.getContentPane().add(pnInputDeviceSettings);
401+
pnInputDeviceSettings.setLayout(null);
402+
392403
frmTempestSdr.setFocusableWindowState(true);
393404
frmTempestSdr.requestFocus();
394405

@@ -656,7 +667,15 @@ else if (!left)
656667
}
657668

658669
private void onPluginSelected() {
659-
if (plugindialog != null) plugindialog.setVisible(false);
670+
671+
btnStartStop.setEnabled(false);
672+
try {
673+
mSdrlib.unloadPlugin();
674+
} catch (TSDRException e) {};
675+
676+
pnInputDeviceSettings.removeAll();
677+
pnInputDeviceSettings.revalidate();
678+
pnInputDeviceSettings.repaint();
660679

661680
final int id = cbDevice.getSelectedIndex();
662681
prefs.putInt(PREF_SOURCE_ID, id);
@@ -666,8 +685,11 @@ private void onPluginSelected() {
666685
final TSDRSource current = (TSDRSource) cbDevice.getSelectedItem();
667686
current.setOnParameterChangedCallback(this);
668687

669-
plugindialog = ((TSDRSource) cbDevice.getSelectedItem()).invokeGUIDialog(frmTempestSdr, preferences);
670-
if (plugindialog != null) plugindialog.setVisible(true);
688+
if (current.populateGUI(pnInputDeviceSettings, preferences)) {
689+
pnInputDeviceSettings.revalidate();
690+
pnInputDeviceSettings.repaint();
691+
} else
692+
current.setParams(preferences);
671693
}
672694

673695
@Override
@@ -705,6 +727,8 @@ public void keyReleased(KeyEvent e) {
705727

706728
@Override
707729
public void onParametersChanged(TSDRSource source) {
730+
cbDevice.setEnabled(false);
731+
btnStartStop.setEnabled(false);
708732

709733
try {
710734
try {
@@ -713,7 +737,8 @@ public void onParametersChanged(TSDRSource source) {
713737

714738
mSdrlib.loadPlugin(source);
715739
} catch (Throwable t) {
716-
btnStartStop.setEnabled(false);
740+
if (!(t instanceof TSDRAlreadyRunningException))
741+
btnStartStop.setEnabled(false);
717742
displayException(frmTempestSdr, t);
718743
return;
719744
}

0 commit comments

Comments
 (0)