Skip to content

Commit b774327

Browse files
WElRDWElRD
WElRD
authored and
WElRD
committed
Working UI, switch to hide/display SoftStreamDecks
1 parent f6f6873 commit b774327

File tree

8 files changed

+191
-154
lines changed

8 files changed

+191
-154
lines changed

ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/AudioApp.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,12 @@ public void run() {
9696
}
9797
}
9898

99-
public static SDImage FOLDER_ICON = IconHelper.loadImageSafe("icons" + File.separator + "folder.png");
100-
public static SDImage AUDIO_ICON = IconHelper.loadImageSafe("icons" + File.separator + "audio.png");
101-
public static SDImage BACK_ICON = IconHelper.loadImageSafe("icons" + File.separator + "back.png");
102-
10399
public final static StopItem STOP_ITEM = new StopItem();
104100

105101
public final static StatusAmbienceItem AMBIENCE_STATUS_ITEM = new StatusAmbienceItem();
106102

107103
public static void playAmbience(Sound sound) {
104+
sound.resetCurrentFile();
108105
AudioPlayer player = new AudioPlayer(sound, configuration.getMixerInfo());
109106
STOP_ITEM.setRollingText(sound.getName());
110107
try {
@@ -347,7 +344,7 @@ public static void saveSoundBoard(SoundBoard sb) throws IOException {
347344
Files.createDirectories(backupPath.getParent());
348345
if(!Files.isDirectory(t))
349346
Files.copy(t, backupPath, StandardCopyOption.REPLACE_EXISTING);
350-
System.out.println(t);
347+
//System.out.println(t);
351348
if(!t.equals(ambiencePath))
352349
Files.delete(t);
353350
} catch (IOException e) {
@@ -367,7 +364,7 @@ public static void saveSoundBoard(SoundBoard sb) throws IOException {
367364
Files.createDirectories(backupPath.getParent());
368365
if(!Files.isDirectory(t))
369366
Files.copy(t, backupPath, StandardCopyOption.REPLACE_EXISTING);
370-
System.out.println(t);
367+
//System.out.println(t);
371368
if(!t.equals(effectsPath))
372369
Files.delete(t);
373370
} catch (IOException e) {

ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/config/AppConfiguration.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class AppConfiguration {
2727

2828
public String soundLib = "soundlib";
2929

30-
public String soundBoardLib = "soundboards";
30+
public String soundBoardLib = "soundboards";
3131

3232
public String audioInterface = null;
3333

ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/ngui/JSoundboardFrame.java

+57-49
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import javax.swing.JFrame;
99
import javax.swing.JPanel;
1010
import javax.swing.border.EmptyBorder;
11+
12+
import de.rcblum.stream.deck.device.SoftStreamDeck;
13+
1114
import javax.swing.UIManager;
1215
import javax.swing.UnsupportedLookAndFeelException;
1316

@@ -47,11 +50,12 @@ public class JSoundboardFrame extends JFrame {
4750
private JLabel lblSoundBoards;
4851
private JSelectablePanel pnSounds;
4952
private JLabel lblSounds;
50-
private JSelectablePanel pn;
53+
private JSelectablePanel pnOptions;
5154
private JLabel lblOptions;
5255
private JScrollPane scrollPane;
5356
private PageViewer pnContent;
5457
private JPanel pnStatus;
58+
private JLabel lblShowSoftdecks;
5559

5660
/**
5761
* Launch the application.
@@ -130,55 +134,54 @@ public JSoundboardFrame() {
130134
lblSounds.setBounds(10, 0, 180, 40);
131135
pnSounds.add(lblSounds);
132136

133-
pn = new JSelectablePanel();
134-
pn.setLayout(null);
135-
pn.setBackground(new Color(0, 81, 108));
136-
pn.setBounds(0, 80, 200, 40);
137-
pnSideBar.add(pn);
137+
pnOptions = new JSelectablePanel();
138+
pnOptions.setLayout(null);
139+
pnOptions.setBackground(new Color(0, 81, 108));
140+
pnOptions.setBounds(0, 80, 200, 40);
141+
JSelectablePanel.JSelectablePanelGroup pnGroup = new JSelectablePanel.JSelectablePanelGroup();
142+
pnGroup.add(pnSoundBoards);
143+
pnGroup.add(pnSounds);
144+
pnSideBar.add(pnOptions);
145+
146+
JSelectablePanel pnDecks = new JSelectablePanel();
147+
pnDecks.setSelected(true);
148+
pnDecks.addSelectionListener(new JSelectablePanel.SelectionListener() {
149+
150+
@Override
151+
public void selectionChanged(JSelectablePanel source, boolean newValue) {
152+
if(newValue)
153+
SoftStreamDeck.showDecks();
154+
else
155+
SoftStreamDeck.hideDecks();
156+
}
157+
});
158+
pnDecks.setLayout(null);
159+
pnDecks.setBounds(0, 410, 200, 40);
160+
pnSideBar.add(pnDecks);
161+
162+
lblShowSoftdecks = new JLabel("Show SoftDecks");
163+
lblShowSoftdecks.setOpaque(false);
164+
lblShowSoftdecks.setHorizontalAlignment(SwingConstants.CENTER);
165+
lblShowSoftdecks.setForeground(Color.LIGHT_GRAY);
166+
lblShowSoftdecks.setBounds(10, 0, 180, 40);
167+
pnDecks.add(lblShowSoftdecks);
138168

139169
lblOptions = new JLabel("Options");
140170
lblOptions.setOpaque(false);
141171
lblOptions.setHorizontalAlignment(SwingConstants.CENTER);
142172
lblOptions.setBounds(10, 0, 180, 40);
143-
MouseListener ml = new MouseListener() {
144-
@Override
145-
public void mouseReleased(MouseEvent e) {
146-
mouseClicked(e);
147-
}
148-
149-
@Override
150-
public void mousePressed(MouseEvent e) {}
151-
173+
JSelectablePanel.SelectionListener sl = new JSelectablePanel.SelectionListener() {
152174
@Override
153-
public void mouseExited(MouseEvent e) {}
154-
155-
@Override
156-
public void mouseEntered(MouseEvent e) {}
157-
158-
@Override
159-
public void mouseClicked(MouseEvent e) {
160-
if (e.getSource() == JSoundboardFrame.this.pnSoundBoards) {
161-
JSoundboardFrame.this.pnSounds.setSelected(false);
162-
JSoundboardFrame.this.pn.setSelected(false);
163-
JSoundboardFrame.this.pnSoundBoards.setSelected(true);
164-
}
165-
else if (e.getSource() == JSoundboardFrame.this.pn) {
166-
JSoundboardFrame.this.pnSounds.setSelected(false);
167-
JSoundboardFrame.this.pnSoundBoards.setSelected(false);
168-
JSoundboardFrame.this.pn.setSelected(true);
175+
public void selectionChanged(JSelectablePanel source, boolean newValue) {
176+
if(newValue) {
177+
switchContent();
169178
}
170-
else if (e.getSource() == JSoundboardFrame.this.pnSounds) {
171-
JSoundboardFrame.this.pn.setSelected(false);
172-
JSoundboardFrame.this.pnSoundBoards.setSelected(false);
173-
JSoundboardFrame.this.pnSounds.setSelected(true);
174-
}
175-
switchContent();
176179
}
177180
};
178-
pn.add(lblOptions);
179-
this.pnSounds.addMouseListener(ml);
180-
this.pnSoundBoards.addMouseListener(ml);
181-
this.pn.addMouseListener(ml);
181+
pnOptions.add(lblOptions);
182+
this.pnSounds.addSelectionListener(sl);
183+
this.pnSoundBoards.addSelectionListener(sl);
184+
// this.pnOptions.addSelectionListener(sl);
182185
JSoundboardFrame.this.pnSoundBoards.setSelected(true);
183186
lblSoundBoards.setForeground(ColorScheme.SIDE_BAR_FOREGROUND_COLOR);
184187
lblSounds.setForeground(ColorScheme.SIDE_BAR_FOREGROUND_COLOR);
@@ -193,14 +196,19 @@ private void switchContent() {
193196
}
194197

195198
private void displaySoundBoards() {
196-
if(pnSoundBoards.isSelected()) {
197-
Page p = new JSoundboardPage();
198-
pnContent.viewPage(p);
199-
}
200-
else if(pnSounds.isSelected()) {
201-
Page p = new JSoundPage();
202-
pnContent.viewPage(p);
203-
}
199+
SwingUtilities.invokeLater(new Runnable() {
200+
@Override
201+
public void run() {
202+
if (pnSoundBoards.isSelected()) {
203+
Page p = new JSoundboardPage();
204+
pnContent.viewPage(p);
205+
} else if (pnSounds.isSelected()) {
206+
Page p = new JSoundPage();
207+
pnContent.viewPage(p);
208+
}
209+
}
210+
211+
});
204212
}
205213

206214
private void setSize(Component comp, int width, int height) {
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,116 @@
11
package vv3ird.ESDSoundboardApp.ngui.components;
22

3+
import java.awt.Component;
4+
import java.awt.event.ComponentEvent;
5+
import java.awt.event.ComponentListener;
6+
import java.awt.event.MouseEvent;
7+
import java.awt.event.MouseListener;
8+
import java.util.ArrayList;
9+
import java.util.LinkedList;
10+
import java.util.List;
11+
312
import javax.swing.JPanel;
413

514
import vv3ird.ESDSoundboardApp.ngui.ColorScheme;
615

716
public class JSelectablePanel extends JPanel {
817

918
private static final long serialVersionUID = -5709653658285821316L;
19+
20+
private List<SelectionListener> selectTionListener = new ArrayList<>(1);
21+
22+
MouseList ml = new MouseList();
23+
24+
private List<JSelectablePanel> group = new LinkedList<>();
25+
1026
boolean selected = false;
1127

1228
public JSelectablePanel() {
13-
1429
}
1530

16-
1731
public boolean isSelected() {
1832
return selected;
1933
}
2034

2135
public void setSelected(boolean selected) {
2236
this.selected = selected;
2337
setBackground(this.selected ? ColorScheme.MAIN_BACKGROUND_COLOR : ColorScheme.SIDE_BAR_BACKGROUND_COLOR);
38+
for (SelectionListener selectionListener : selectTionListener) {
39+
selectionListener.selectionChanged(this, this.selected);
40+
}
41+
}
42+
43+
@Override
44+
public Component add(Component comp) {
45+
comp.addMouseListener(ml);
46+
return super.add(comp);
47+
}
48+
49+
@Override
50+
public void remove(Component comp) {
51+
comp.removeMouseListener(ml);
52+
super.remove(comp);
53+
}
54+
55+
public boolean addSelectionListener(SelectionListener list) {
56+
return this.selectTionListener.add(list);
57+
}
58+
59+
public boolean removeSelectionListener(SelectionListener list) {
60+
return this.selectTionListener.remove(list);
61+
}
62+
63+
class MouseList implements MouseListener {
64+
65+
@Override
66+
public void mouseClicked(MouseEvent e) {}
67+
@Override
68+
public void mousePressed(MouseEvent e) {}
69+
@Override
70+
public void mouseReleased(MouseEvent e) {
71+
setSelected(!selected);
72+
}
73+
@Override
74+
public void mouseEntered(MouseEvent e) {}
75+
@Override
76+
public void mouseExited(MouseEvent e) {}
77+
78+
}
79+
80+
public static interface SelectionListener {
81+
public void selectionChanged(JSelectablePanel source, boolean newValue);
82+
}
83+
84+
public static class JSelectablePanelGroup implements SelectionListener {
85+
86+
List<JSelectablePanel> panels = new ArrayList<>(3);
87+
88+
private boolean updateingPeers = false;
89+
90+
public void add(JSelectablePanel panel) {
91+
if(!panels.contains(panel)) {
92+
panels.add(panel);
93+
panel.addSelectionListener(this);
94+
}
95+
}
96+
97+
public void remove(JSelectablePanel panel) {
98+
if(panels.contains(panel)) {
99+
panels.remove(panel);
100+
panel.removeSelectionListener(this);
101+
}
102+
}
103+
104+
@Override
105+
public void selectionChanged(JSelectablePanel source, boolean newValue) {
106+
if(!updateingPeers && panels.contains(source) && newValue) {
107+
updateingPeers = true;
108+
for (JSelectablePanel panel : panels) {
109+
if(panel != source)
110+
panel.setSelected(false);
111+
}
112+
updateingPeers = false;
113+
}
114+
}
24115
}
25116
}

ESDSoundboardApp/src/main/java/vv3ird/ESDSoundboardApp/ngui/components/JSoundPanel.java

+20-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package vv3ird.ESDSoundboardApp.ngui.components;
22

3-
import javax.swing.JPanel;
3+
import javax.swing.JLabel;
44

55
import de.rcblum.stream.deck.device.StreamDeck;
66
import de.rcblum.stream.deck.util.IconHelper;
@@ -16,53 +16,48 @@
1616
import java.io.File;
1717
import java.io.FileInputStream;
1818
import java.io.IOException;
19-
import java.io.InputStream;
20-
21-
import javax.swing.BorderFactory;
22-
import javax.swing.ImageIcon;
23-
import javax.swing.JButton;
24-
import javax.swing.JLabel;
2519

2620
public class JSoundPanel extends ImagePanel {
2721

22+
private static final long serialVersionUID = 7112434291220556525L;
23+
2824
Sound s = null;
25+
2926
private JLabel btnX;
3027

3128
public JSoundPanel(Sound s, Color background) {
32-
setLayout(null);
33-
setSize(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE);
34-
setPreferredSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
35-
setMinimumSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
36-
setMaximumSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
37-
setSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
38-
setBackground(Color.RED);
3929
this.s = s;
4030
Color oldC = IconHelper.FRAME_COLOR;
31+
SDImage bImg = null;
4132
try {
4233
IconHelper.FRAME_COLOR = background;
43-
SDImage bImg = IconHelper.loadImage(this.s.getCoverPath(), new FileInputStream(new File(this.s.getCoverPath())), true);
44-
bImg = IconHelper.addText(bImg, s.getName(), IconHelper.TEXT_BOTTOM);
45-
setImage(bImg.image);
34+
bImg = IconHelper.loadImage(this.s.getCoverPath(), new FileInputStream(new File(this.s.getCoverPath())), true);
4635
}
4736
catch (IOException e) {
4837
}
4938
IconHelper.FRAME_COLOR = oldC;
50-
btnX = new JLabel("X");
51-
btnX.setFont(new Font("Segoe UI", Font.PLAIN, 12));
52-
btnX.setForeground(ColorScheme.FOREGROUND_COLOR);
53-
btnX.setBounds(59, 0, 23, 23);
54-
btnX.setOpaque(false);
55-
add(btnX);
39+
init(bImg.image, s.getName(), background);
5640
}
5741

58-
public JSoundPanel(BufferedImage img, Color background) {
42+
public JSoundPanel(BufferedImage img, String text, Color background) {
43+
init(img, text, background);
44+
}
45+
46+
private void init(BufferedImage img, String text, Color background) {
5947
setLayout(null);
48+
int alpha = IconHelper.TEXT_BOX_ALPHA_VALUE;
49+
Color oldC = IconHelper.FRAME_COLOR;
50+
IconHelper.FRAME_COLOR = background;
51+
IconHelper.TEXT_BOX_ALPHA_VALUE = 150;
52+
SDImage bImg = IconHelper.addText(img, text, IconHelper.TEXT_BOTTOM);
53+
IconHelper.FRAME_COLOR = oldC;
54+
IconHelper.TEXT_BOX_ALPHA_VALUE = alpha;
6055
setSize(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE);
6156
setPreferredSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
6257
setMinimumSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
6358
setMaximumSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
6459
setSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
65-
setImage(img);
60+
setImage(bImg.image);
6661
btnX = new JLabel("X");
6762
btnX.setFont(new Font("Segoe UI", Font.PLAIN, 12));
6863
btnX.setForeground(ColorScheme.FOREGROUND_COLOR);

0 commit comments

Comments
 (0)