This repository has been archived on 2018-03-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
jLSLauncher/src/com/ixab/GUI/StreamChooserMenu.java
T

114 lines
4.3 KiB
Java
Raw Normal View History

2015-11-06 18:15:26 +01:00
package com.ixab.GUI;
import com.ixab.ConfigHandling.ConfigFileIOHandler;
import com.ixab.ConfigHandling.ConfigFileInstanceHandler;
2015-11-07 00:19:11 +01:00
import com.ixab.StreamHandling.StreamInfo;
import com.ixab.StreamHandling.StreamOpener;
import javax.swing.*;
2015-11-07 00:56:35 +01:00
import java.awt.event.*;
2015-11-06 18:15:26 +01:00
public class StreamChooserMenu {
private JPanel panel;
2015-11-07 00:19:11 +01:00
private JComboBox comboBoxStreams;
2015-11-07 00:56:35 +01:00
private JComboBox comboBoxQuality;
private JTextField textField1;
private JButton hinzufügenButton;
private JButton streamAbspielenButton;
private JButton entfernenButton;
2015-11-07 00:19:11 +01:00
private JLabel labelStreamStatus;
private JLabel labelStreamViewers;
private JLabel labelStreamTitle;
private JLabel labelStreamGame;
2015-11-07 00:56:35 +01:00
private JButton neuLadenButton;
private boolean lockStreamInfoGetter = false;
public StreamChooserMenu() {
this.initComboBoxes();
streamAbspielenButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
2015-11-07 00:56:35 +01:00
StreamOpener so = new StreamOpener(ConfigFileInstanceHandler.getConfig(), ConfigFileInstanceHandler.getConfig().getStreams().indexOf(comboBoxStreams.getSelectedItem()), comboBoxQuality.getSelectedItem().toString());
so.start();
}
});
hinzufügenButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addNewStream();
}
});
entfernenButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
2015-11-07 00:19:11 +01:00
ConfigFileInstanceHandler.getConfig().removeStream(comboBoxStreams.getSelectedItem());
ConfigFileIOHandler.save(ConfigFileInstanceHandler.getConfig());
2015-11-07 00:56:35 +01:00
lockStreamInfoGetter = true;
initStreamsComboBox();
2015-11-07 00:56:35 +01:00
lockStreamInfoGetter = false;
}
});
2015-11-07 00:19:11 +01:00
comboBoxStreams.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
2015-11-07 00:56:35 +01:00
if (!lockStreamInfoGetter) {
updateStreamDetails();
}
}
});
textField1.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
super.keyPressed(e);
if (textField1.isFocusOwner() && e.getKeyCode() == 10) {
addNewStream();
}
}
});
2015-11-07 00:56:35 +01:00
neuLadenButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateStreamDetails();
}
});
}
private void updateStreamDetails() {
StreamInfo.getStreamInfo(comboBoxStreams.getSelectedItem().toString());
labelStreamStatus.setText(StreamInfo.getStatus());
labelStreamGame.setText(StreamInfo.getGame());
labelStreamViewers.setText(StreamInfo.getViewers());
labelStreamTitle.setText(StreamInfo.getTitle());
}
private void addNewStream() {
ConfigFileInstanceHandler.getConfig().addStream(textField1.getText());
ConfigFileIOHandler.save(ConfigFileInstanceHandler.getConfig());
2015-11-07 00:56:35 +01:00
lockStreamInfoGetter = true;
initStreamsComboBox();
2015-11-07 00:56:35 +01:00
lockStreamInfoGetter = false;
textField1.setText("");
}
private void initComboBoxes() {
initQualityComboBox();
initStreamsComboBox();
}
private void initStreamsComboBox() {
2015-11-07 00:19:11 +01:00
comboBoxStreams.removeAllItems();
for (String streamName :
ConfigFileInstanceHandler.getConfig().getStreams()) {
2015-11-07 00:19:11 +01:00
comboBoxStreams.addItem(streamName);
}
}
private void initQualityComboBox() {
2015-11-07 00:56:35 +01:00
comboBoxQuality.removeAllItems();
comboBoxQuality.addItem("best"); comboBoxQuality.addItem("high"); comboBoxQuality.addItem("medium"); comboBoxQuality.addItem("low"); comboBoxQuality.addItem("mobile");
}
public static void main(String[] args) {
JFrame frame = new JFrame("jLSLauncher v"+ com.ixab.Main.getVersion());
frame.setContentPane(new StreamChooserMenu().panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
2015-11-06 18:15:26 +01:00
}