Skip to content

Commit

Permalink
Working UI, switch to hide/display SoftStreamDecks
Browse files Browse the repository at this point in the history
  • Loading branch information
WElRD authored and WElRD committed Sep 16, 2018
1 parent f6f6873 commit b774327
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,12 @@ public void run() {
}
}

public static SDImage FOLDER_ICON = IconHelper.loadImageSafe("icons" + File.separator + "folder.png");
public static SDImage AUDIO_ICON = IconHelper.loadImageSafe("icons" + File.separator + "audio.png");
public static SDImage BACK_ICON = IconHelper.loadImageSafe("icons" + File.separator + "back.png");

public final static StopItem STOP_ITEM = new StopItem();

public final static StatusAmbienceItem AMBIENCE_STATUS_ITEM = new StatusAmbienceItem();

public static void playAmbience(Sound sound) {
sound.resetCurrentFile();
AudioPlayer player = new AudioPlayer(sound, configuration.getMixerInfo());
STOP_ITEM.setRollingText(sound.getName());
try {
Expand Down Expand Up @@ -347,7 +344,7 @@ public static void saveSoundBoard(SoundBoard sb) throws IOException {
Files.createDirectories(backupPath.getParent());
if(!Files.isDirectory(t))
Files.copy(t, backupPath, StandardCopyOption.REPLACE_EXISTING);
System.out.println(t);
//System.out.println(t);
if(!t.equals(ambiencePath))
Files.delete(t);
} catch (IOException e) {
Expand All @@ -367,7 +364,7 @@ public static void saveSoundBoard(SoundBoard sb) throws IOException {
Files.createDirectories(backupPath.getParent());
if(!Files.isDirectory(t))
Files.copy(t, backupPath, StandardCopyOption.REPLACE_EXISTING);
System.out.println(t);
//System.out.println(t);
if(!t.equals(effectsPath))
Files.delete(t);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class AppConfiguration {

public String soundLib = "soundlib";

public String soundBoardLib = "soundboards";
public String soundBoardLib = "soundboards";

public String audioInterface = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import de.rcblum.stream.deck.device.SoftStreamDeck;

import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

Expand Down Expand Up @@ -47,11 +50,12 @@ public class JSoundboardFrame extends JFrame {
private JLabel lblSoundBoards;
private JSelectablePanel pnSounds;
private JLabel lblSounds;
private JSelectablePanel pn;
private JSelectablePanel pnOptions;
private JLabel lblOptions;
private JScrollPane scrollPane;
private PageViewer pnContent;
private JPanel pnStatus;
private JLabel lblShowSoftdecks;

/**
* Launch the application.
Expand Down Expand Up @@ -130,55 +134,54 @@ public JSoundboardFrame() {
lblSounds.setBounds(10, 0, 180, 40);
pnSounds.add(lblSounds);

pn = new JSelectablePanel();
pn.setLayout(null);
pn.setBackground(new Color(0, 81, 108));
pn.setBounds(0, 80, 200, 40);
pnSideBar.add(pn);
pnOptions = new JSelectablePanel();
pnOptions.setLayout(null);
pnOptions.setBackground(new Color(0, 81, 108));
pnOptions.setBounds(0, 80, 200, 40);
JSelectablePanel.JSelectablePanelGroup pnGroup = new JSelectablePanel.JSelectablePanelGroup();
pnGroup.add(pnSoundBoards);
pnGroup.add(pnSounds);
pnSideBar.add(pnOptions);

JSelectablePanel pnDecks = new JSelectablePanel();
pnDecks.setSelected(true);
pnDecks.addSelectionListener(new JSelectablePanel.SelectionListener() {

@Override
public void selectionChanged(JSelectablePanel source, boolean newValue) {
if(newValue)
SoftStreamDeck.showDecks();
else
SoftStreamDeck.hideDecks();
}
});
pnDecks.setLayout(null);
pnDecks.setBounds(0, 410, 200, 40);
pnSideBar.add(pnDecks);

lblShowSoftdecks = new JLabel("Show SoftDecks");
lblShowSoftdecks.setOpaque(false);
lblShowSoftdecks.setHorizontalAlignment(SwingConstants.CENTER);
lblShowSoftdecks.setForeground(Color.LIGHT_GRAY);
lblShowSoftdecks.setBounds(10, 0, 180, 40);
pnDecks.add(lblShowSoftdecks);

lblOptions = new JLabel("Options");
lblOptions.setOpaque(false);
lblOptions.setHorizontalAlignment(SwingConstants.CENTER);
lblOptions.setBounds(10, 0, 180, 40);
MouseListener ml = new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
mouseClicked(e);
}

@Override
public void mousePressed(MouseEvent e) {}

JSelectablePanel.SelectionListener sl = new JSelectablePanel.SelectionListener() {
@Override
public void mouseExited(MouseEvent e) {}

@Override
public void mouseEntered(MouseEvent e) {}

@Override
public void mouseClicked(MouseEvent e) {
if (e.getSource() == JSoundboardFrame.this.pnSoundBoards) {
JSoundboardFrame.this.pnSounds.setSelected(false);
JSoundboardFrame.this.pn.setSelected(false);
JSoundboardFrame.this.pnSoundBoards.setSelected(true);
}
else if (e.getSource() == JSoundboardFrame.this.pn) {
JSoundboardFrame.this.pnSounds.setSelected(false);
JSoundboardFrame.this.pnSoundBoards.setSelected(false);
JSoundboardFrame.this.pn.setSelected(true);
public void selectionChanged(JSelectablePanel source, boolean newValue) {
if(newValue) {
switchContent();
}
else if (e.getSource() == JSoundboardFrame.this.pnSounds) {
JSoundboardFrame.this.pn.setSelected(false);
JSoundboardFrame.this.pnSoundBoards.setSelected(false);
JSoundboardFrame.this.pnSounds.setSelected(true);
}
switchContent();
}
};
pn.add(lblOptions);
this.pnSounds.addMouseListener(ml);
this.pnSoundBoards.addMouseListener(ml);
this.pn.addMouseListener(ml);
pnOptions.add(lblOptions);
this.pnSounds.addSelectionListener(sl);
this.pnSoundBoards.addSelectionListener(sl);
// this.pnOptions.addSelectionListener(sl);
JSoundboardFrame.this.pnSoundBoards.setSelected(true);
lblSoundBoards.setForeground(ColorScheme.SIDE_BAR_FOREGROUND_COLOR);
lblSounds.setForeground(ColorScheme.SIDE_BAR_FOREGROUND_COLOR);
Expand All @@ -193,14 +196,19 @@ private void switchContent() {
}

private void displaySoundBoards() {
if(pnSoundBoards.isSelected()) {
Page p = new JSoundboardPage();
pnContent.viewPage(p);
}
else if(pnSounds.isSelected()) {
Page p = new JSoundPage();
pnContent.viewPage(p);
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (pnSoundBoards.isSelected()) {
Page p = new JSoundboardPage();
pnContent.viewPage(p);
} else if (pnSounds.isSelected()) {
Page p = new JSoundPage();
pnContent.viewPage(p);
}
}

});
}

private void setSize(Component comp, int width, int height) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,116 @@
package vv3ird.ESDSoundboardApp.ngui.components;

import java.awt.Component;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import javax.swing.JPanel;

import vv3ird.ESDSoundboardApp.ngui.ColorScheme;

public class JSelectablePanel extends JPanel {

private static final long serialVersionUID = -5709653658285821316L;

private List<SelectionListener> selectTionListener = new ArrayList<>(1);

MouseList ml = new MouseList();

private List<JSelectablePanel> group = new LinkedList<>();

boolean selected = false;

public JSelectablePanel() {

}


public boolean isSelected() {
return selected;
}

public void setSelected(boolean selected) {
this.selected = selected;
setBackground(this.selected ? ColorScheme.MAIN_BACKGROUND_COLOR : ColorScheme.SIDE_BAR_BACKGROUND_COLOR);
for (SelectionListener selectionListener : selectTionListener) {
selectionListener.selectionChanged(this, this.selected);
}
}

@Override
public Component add(Component comp) {
comp.addMouseListener(ml);
return super.add(comp);
}

@Override
public void remove(Component comp) {
comp.removeMouseListener(ml);
super.remove(comp);
}

public boolean addSelectionListener(SelectionListener list) {
return this.selectTionListener.add(list);
}

public boolean removeSelectionListener(SelectionListener list) {
return this.selectTionListener.remove(list);
}

class MouseList implements MouseListener {

@Override
public void mouseClicked(MouseEvent e) {}
@Override
public void mousePressed(MouseEvent e) {}
@Override
public void mouseReleased(MouseEvent e) {
setSelected(!selected);
}
@Override
public void mouseEntered(MouseEvent e) {}
@Override
public void mouseExited(MouseEvent e) {}

}

public static interface SelectionListener {
public void selectionChanged(JSelectablePanel source, boolean newValue);
}

public static class JSelectablePanelGroup implements SelectionListener {

List<JSelectablePanel> panels = new ArrayList<>(3);

private boolean updateingPeers = false;

public void add(JSelectablePanel panel) {
if(!panels.contains(panel)) {
panels.add(panel);
panel.addSelectionListener(this);
}
}

public void remove(JSelectablePanel panel) {
if(panels.contains(panel)) {
panels.remove(panel);
panel.removeSelectionListener(this);
}
}

@Override
public void selectionChanged(JSelectablePanel source, boolean newValue) {
if(!updateingPeers && panels.contains(source) && newValue) {
updateingPeers = true;
for (JSelectablePanel panel : panels) {
if(panel != source)
panel.setSelected(false);
}
updateingPeers = false;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package vv3ird.ESDSoundboardApp.ngui.components;

import javax.swing.JPanel;
import javax.swing.JLabel;

import de.rcblum.stream.deck.device.StreamDeck;
import de.rcblum.stream.deck.util.IconHelper;
Expand All @@ -16,53 +16,48 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;

public class JSoundPanel extends ImagePanel {

private static final long serialVersionUID = 7112434291220556525L;

Sound s = null;

private JLabel btnX;

public JSoundPanel(Sound s, Color background) {
setLayout(null);
setSize(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE);
setPreferredSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
setMinimumSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
setMaximumSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
setSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
setBackground(Color.RED);
this.s = s;
Color oldC = IconHelper.FRAME_COLOR;
SDImage bImg = null;
try {
IconHelper.FRAME_COLOR = background;
SDImage bImg = IconHelper.loadImage(this.s.getCoverPath(), new FileInputStream(new File(this.s.getCoverPath())), true);
bImg = IconHelper.addText(bImg, s.getName(), IconHelper.TEXT_BOTTOM);
setImage(bImg.image);
bImg = IconHelper.loadImage(this.s.getCoverPath(), new FileInputStream(new File(this.s.getCoverPath())), true);
}
catch (IOException e) {
}
IconHelper.FRAME_COLOR = oldC;
btnX = new JLabel("X");
btnX.setFont(new Font("Segoe UI", Font.PLAIN, 12));
btnX.setForeground(ColorScheme.FOREGROUND_COLOR);
btnX.setBounds(59, 0, 23, 23);
btnX.setOpaque(false);
add(btnX);
init(bImg.image, s.getName(), background);
}

public JSoundPanel(BufferedImage img, Color background) {
public JSoundPanel(BufferedImage img, String text, Color background) {
init(img, text, background);
}

private void init(BufferedImage img, String text, Color background) {
setLayout(null);
int alpha = IconHelper.TEXT_BOX_ALPHA_VALUE;
Color oldC = IconHelper.FRAME_COLOR;
IconHelper.FRAME_COLOR = background;
IconHelper.TEXT_BOX_ALPHA_VALUE = 150;
SDImage bImg = IconHelper.addText(img, text, IconHelper.TEXT_BOTTOM);
IconHelper.FRAME_COLOR = oldC;
IconHelper.TEXT_BOX_ALPHA_VALUE = alpha;
setSize(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE);
setPreferredSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
setMinimumSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
setMaximumSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
setSize(new Dimension(StreamDeck.ICON_SIZE, StreamDeck.ICON_SIZE));
setImage(img);
setImage(bImg.image);
btnX = new JLabel("X");
btnX.setFont(new Font("Segoe UI", Font.PLAIN, 12));
btnX.setForeground(ColorScheme.FOREGROUND_COLOR);
Expand Down
Loading

0 comments on commit b774327

Please sign in to comment.