@@ -106,6 +106,39 @@ private void initSettingsPanel() {
106106 });
107107 panelSettings .add (UserInterfaceUtil .createSettingBgr (lblDeviceId , fieldDeviceId , btnAddDeviceId ));
108108
109+ if (instance .getOpenRGB ().isConnected ()) {
110+ // show info label, remove all and add all button
111+ int deviceCount = instance .getOpenRGB ().getControllerCount ();
112+
113+ JLabel lblCountInfo = new JLabel ("There are " + deviceCount + " devices available." );
114+ lblCountInfo .setForeground (Style .textColor );
115+
116+ JButton btnAddAll = new JButton ("Add all" );
117+ UiUtils .configureButton (btnAddAll );
118+ btnAddAll .addActionListener (e -> {
119+ for (int i = 0 ; i < deviceCount ; i ++) {
120+ if (!listDevices .contains (i ))
121+ listDevices .add (i );
122+ }
123+ updateDeviceListPanel ();
124+ });
125+
126+ JButton btnRemoveAll = new JButton ("Remove all" );
127+ UiUtils .configureButton (btnRemoveAll );
128+ btnRemoveAll .addActionListener (e -> {
129+ listDevices .clear ();
130+ updateDeviceListPanel ();
131+ });
132+
133+ // add components to panel
134+ panelSettings .add (UserInterfaceUtil .createSettingBgr (lblCountInfo , btnAddAll , btnRemoveAll ));
135+ } else {
136+ // show hint message
137+ JLabel lblHint = new JLabel ("(i) Go back and connect the client to receive live data from the SDK server." );
138+ lblHint .setForeground (Style .textColorDarker );
139+ panelSettings .add (UserInterfaceUtil .createSettingBgr (lblHint ));
140+ }
141+
109142 panelDeviceList = new JPanel ();
110143 panelDeviceList .setBackground (Style .panelDarkBackground );
111144 panelDeviceList .setLayout (new BoxLayout (panelDeviceList , BoxLayout .Y_AXIS ));
@@ -191,9 +224,11 @@ private void updateDeviceListPanel() {
191224 boolean isConnected = instance .getOpenRGB ().isConnected ();
192225 int controllerCount = isConnected ? instance .getOpenRGB ().getControllerCount () : -1 ;
193226
194- for (int deviceId : listDevices ) {
227+ for (int i = 0 ; i < listDevices .size (); i ++) {
228+ final int deviceId = listDevices .get (i );
195229 ListElement el = new ListElement (40 );
196230 panelDeviceList .add (el );
231+ panelDeviceList .add (Box .createVerticalStrut (5 ));
197232
198233 JLabel lblDeviceId = new JLabel ("Device #" + deviceId );
199234 lblDeviceId .setForeground (Style .textColor );
@@ -219,20 +254,67 @@ private void updateDeviceListPanel() {
219254 }
220255 }
221256
257+ el .add (Box .createHorizontalGlue ());
258+
259+ // move device up
260+ JButton btnUp = new JButton ("\u25B2 " );
261+ configurePanelButton (btnUp );
262+ btnUp .setToolTipText ("Move up" );
263+ btnUp .addActionListener (e -> {
264+ int index = listDevices .indexOf (deviceId );
265+ if (index > 0 ) {
266+ // move element up in list
267+ listDevices .remove (index );
268+ listDevices .add (index - 1 , deviceId );
269+ }
270+ updateDeviceListPanel ();
271+ });
272+ el .add (btnUp );
273+ el .add (Box .createHorizontalStrut (5 ));
274+
275+ // move device down
276+ JButton btnDown = new JButton ("\u25BC " );
277+ configurePanelButton (btnDown );
278+ btnDown .setToolTipText ("Move down" );
279+ btnDown .addActionListener (e -> {
280+ int index = listDevices .indexOf (deviceId );
281+ if (index < listDevices .size () - 1 ) {
282+ // move element down in list
283+ listDevices .remove (index );
284+ listDevices .add (index + 1 , deviceId );
285+ }
286+ updateDeviceListPanel ();
287+ });
288+ el .add (btnDown );
289+ el .add (Box .createHorizontalStrut (5 ));
290+
291+ // check to disable move up/down buttons
292+ if (i == 0 )
293+ btnUp .setEnabled (false );
294+ if (i == listDevices .size () - 1 )
295+ btnDown .setEnabled (false );
296+
222297 // remove device button
223- JButton btnRemove = new JButton ("X " );
224- UiUtils . configureButton (btnRemove );
298+ JButton btnRemove = new JButton ("\u2715 " );
299+ configurePanelButton (btnRemove );
225300 btnRemove .setToolTipText ("Remove device from list" );
226301 btnRemove .addActionListener (e -> {
227302 listDevices .remove ((Integer ) deviceId );
228303 updateDeviceListPanel ();
229304 });
230- el .add (Box .createHorizontalGlue ());
231305 el .add (btnRemove );
232306 }
233307 panelDeviceList .updateUI ();
234308 }
235309
310+ private void configurePanelButton (JButton btn ) {
311+ UiUtils .configureButton (btn );
312+ btn .setContentAreaFilled (false );
313+ btn .setBorder (null );
314+ btn .setCursor (new Cursor (Cursor .HAND_CURSOR ));
315+ btn .setFont (new Font (Font .DIALOG , Font .PLAIN , 13 ));
316+ }
317+
236318 @ Override
237319 public void onBack () {
238320 // update devices panel
0 commit comments