diff --git a/src/com/ixab/GUI/ErrorMessageGate.java b/src/com/ixab/GUI/ErrorMessageGate.java
index 90c86e7..243991c 100644
--- a/src/com/ixab/GUI/ErrorMessageGate.java
+++ b/src/com/ixab/GUI/ErrorMessageGate.java
@@ -2,6 +2,7 @@ package com.ixab.GUI;
public class ErrorMessageGate {
public static void setErrorText(String s) {
- // TODO: na was wohl?
+ MainWindow mw = MainWindowGate.getMainWindow();
+ mw.getErrorLabel().setText(s);
}
}
diff --git a/src/com/ixab/GUI/MainWindow.form b/src/com/ixab/GUI/MainWindow.form
index 7370746..81ef617 100644
--- a/src/com/ixab/GUI/MainWindow.form
+++ b/src/com/ixab/GUI/MainWindow.form
@@ -3,11 +3,11 @@
-
+
-
-
+
+
@@ -39,7 +39,7 @@
-
+
@@ -47,7 +47,7 @@
-
+
@@ -71,52 +71,97 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -125,37 +170,23 @@
-
+
-
+
+
+
+
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -173,7 +204,7 @@
-
+
@@ -181,7 +212,7 @@
-
+
@@ -189,7 +220,7 @@
-
+
@@ -197,7 +228,7 @@
-
+
diff --git a/src/com/ixab/GUI/MainWindow.java b/src/com/ixab/GUI/MainWindow.java
index 7353b8e..da1ec8f 100644
--- a/src/com/ixab/GUI/MainWindow.java
+++ b/src/com/ixab/GUI/MainWindow.java
@@ -12,17 +12,17 @@ public class MainWindow {
private JPanel panel;
private JComboBox comboBoxStreams;
private JComboBox comboBoxQuality;
- private JTextField textField1;
- private JButton hinzufügenButton;
- private JButton streamAbspielenButton;
- private JButton entfernenButton;
- private JLabel labelStreamStatus;
- private JLabel labelStreamViewers;
- private JLabel labelStreamTitle;
- private JLabel labelStreamGame;
- private JButton neuLadenButton;
- private JPanel previewImagePanel;
- private JButton einstellungenButton;
+ private JButton buttonAddStream;
+ private JButton buttonPlayStream;
+ private JButton buttonRemoveStream;
+ private JTextField textFieldStreamStatus;
+ private JTextField textFieldStreamViewers;
+ private JTextField textFieldStreamTitle;
+ private JTextField textFieldStreamGame;
+ private JButton buttonReloadStreamData;
+ private JPanel panelPreviewImage;
+ private JButton buttonSettings;
+ private Thread updateThread;
protected JLabel getErrorLabel() {
return errorLabel;
@@ -34,20 +34,20 @@ public class MainWindow {
public MainWindow() {
MainWindowGate.setMainWindow(this);
this.initComboBoxes();
- streamAbspielenButton.addActionListener(new ActionListener() {
+ buttonPlayStream.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
StreamOpener so = new StreamOpener(ConfigFileInstanceHandler.getConfig(), ConfigFileInstanceHandler.getConfig().getStreams().indexOf(comboBoxStreams.getSelectedItem()), comboBoxQuality.getSelectedItem().toString());
so.start();
}
});
- hinzufügenButton.addActionListener(new ActionListener() {
+ buttonAddStream.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addNewStream();
}
});
- entfernenButton.addActionListener(new ActionListener() {
+ buttonRemoveStream.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ConfigFileInstanceHandler.getConfig().removeStream(comboBoxStreams.getSelectedItem());
@@ -65,13 +65,13 @@ public class MainWindow {
}
}
});
- neuLadenButton.addActionListener(new ActionListener() {
+ buttonReloadStreamData.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateStreamDetails();
}
});
- einstellungenButton.addActionListener(new ActionListener() {
+ buttonSettings.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SettingsWindow sw = new SettingsWindow();
@@ -80,11 +80,26 @@ public class MainWindow {
});
}
private void updateStreamDetails() {
- StreamInfo.initStreamData(comboBoxStreams.getSelectedItem().toString());
- labelStreamStatus.setText(StreamInfo.getStatus());
- labelStreamGame.setText(StreamInfo.getGame());
- labelStreamViewers.setText(StreamInfo.getViewers());
- labelStreamTitle.setText(StreamInfo.getTitle());
+ if (updateThread != null) {
+ if (updateThread.isAlive()) {
+ updateThread.interrupt();
+ }
+ }
+ Runnable r = new Runnable() {
+ @Override
+ public void run() {
+ StreamInfo.initStreamData(comboBoxStreams.getSelectedItem().toString());
+ textFieldStreamStatus.setText(StreamInfo.getStatus());
+ textFieldStreamGame.setText(StreamInfo.getGame());
+ textFieldStreamViewers.setText(StreamInfo.getViewers());
+ textFieldStreamTitle.setText(StreamInfo.getTitle());
+ panelPreviewImage.getGraphics().drawImage(StreamInfo.getPreviewImage(),0,0,null);
+ }
+ };
+ Thread t = new Thread(r);
+ this.updateThread = t;
+ t.start();
+ ErrorMessageGate.setErrorText("Lade Stream-Daten von " + comboBoxStreams.getSelectedItem().toString() + "...");
}
private void addNewStream() {
AddStreamDialog as = new AddStreamDialog();
diff --git a/src/com/ixab/GUI/SettingsWindow.form b/src/com/ixab/GUI/SettingsWindow.form
index f01ea28..7d5b4e8 100644
--- a/src/com/ixab/GUI/SettingsWindow.form
+++ b/src/com/ixab/GUI/SettingsWindow.form
@@ -49,7 +49,7 @@
-
+
@@ -102,6 +102,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/com/ixab/GUI/SettingsWindow.java b/src/com/ixab/GUI/SettingsWindow.java
index f1d912b..1e11e17 100644
--- a/src/com/ixab/GUI/SettingsWindow.java
+++ b/src/com/ixab/GUI/SettingsWindow.java
@@ -1,6 +1,8 @@
package com.ixab.GUI;
+import com.ixab.ConfigHandling.ConfigFileIOHandler;
import com.ixab.ConfigHandling.ConfigFileInstanceHandler;
+import com.ixab.UserInfoHandling.UserInfo;
import javax.swing.*;
import java.awt.event.*;
@@ -12,6 +14,8 @@ public class SettingsWindow extends JDialog {
private JCheckBox debugmodusCheckBox;
private JTextField textField1;
private JButton suchenButton;
+ private JTextField twitchBenutzernameTextField;
+ private JButton buttonImportUserData;
public SettingsWindow() {
textField1.setText(ConfigFileInstanceHandler.getConfig().getLSPath());
@@ -54,10 +58,25 @@ public class SettingsWindow extends JDialog {
if (jfc.getSelectedFile() != null) textField1.setText(jfc.getSelectedFile().getAbsolutePath());
}
});
+ buttonImportUserData.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent actionEvent) {
+ UserInfo.initUserFollowData(twitchBenutzernameTextField.getText());
+ UserInfo.getFollowedChannelNames();
+ }
+ });
+ twitchBenutzernameTextField.addFocusListener(new FocusAdapter() {
+ @Override
+ public void focusGained(FocusEvent e) {
+ super.focusGained(e);
+ twitchBenutzernameTextField.setText("");
+ }
+ });
}
private void onOK() {
-// add your code here
+ ConfigFileInstanceHandler.getConfig().setLSPath(textField1.getText());
+ ConfigFileIOHandler.save(ConfigFileInstanceHandler.getConfig());
dispose();
}
diff --git a/src/com/ixab/Main.java b/src/com/ixab/Main.java
index e678258..6732f4a 100644
--- a/src/com/ixab/Main.java
+++ b/src/com/ixab/Main.java
@@ -8,7 +8,7 @@ import com.ixab.GUI.MainWindow;
import javax.swing.*;
public class Main {
- private final static String version = "0.3 Alpha";
+ private final static String version = "0.4 Alpha";
private static Config c = null;
public static void main(String[] args) {
try {
@@ -28,8 +28,6 @@ public class Main {
catch (IllegalAccessException e) {
// handle exception
}
-
- //ConfigLoadMenu.create(null);
c = ConfigFileIOHandler.load();
if (c == null) {
initNewConfig();
diff --git a/src/com/ixab/StreamHandling/StreamInfo.java b/src/com/ixab/StreamHandling/StreamInfo.java
index 88568aa..88ca7c6 100644
--- a/src/com/ixab/StreamHandling/StreamInfo.java
+++ b/src/com/ixab/StreamHandling/StreamInfo.java
@@ -1,7 +1,10 @@
package com.ixab.StreamHandling;
+import com.ixab.GUI.ErrorMessageGate;
import org.json.JSONObject;
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@@ -14,7 +17,7 @@ public class StreamInfo {
private static JSONObject streamPreviewData = null;
public static String getGame() {
if (streamData == null && streamPreviewData == null) {
- return "0";
+ return "-";
} else {
JSONObject channelData = new JSONObject(streamData.get("channel").toString());
return channelData.get("game").toString();
@@ -22,7 +25,7 @@ public class StreamInfo {
}
public static String getTitle() {
if (streamData == null && streamPreviewData == null) {
- return "0";
+ return "-";
} else {
JSONObject channelData = new JSONObject(streamData.get("channel").toString());
return channelData.get("status").toString();
@@ -42,7 +45,27 @@ public class StreamInfo {
return "online";
}
}
- public static void initStreamData(String streamName) {
+ public static BufferedImage getPreviewImage() {
+ if (streamPreviewData == null) {
+ BufferedImage c = new BufferedImage(1,1,0);
+ return c;
+ } else {
+ URL url = null;
+ BufferedImage c = null;
+ try {
+ url = new URL(streamPreviewData.get("medium").toString());
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ try {
+ c = ImageIO.read(url);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return c;
+ }
+ }
+ public static boolean initStreamData(String streamName) {
if (streamName != null) {
InputStream is = null;
URL url = null;
@@ -62,7 +85,9 @@ public class StreamInfo {
try {
is = url.openStream();
} catch (IOException e) {
+ ErrorMessageGate.setErrorText("Fehler bei Verbindungsaufbau zu Twitch.");
e.printStackTrace();
+ return false;
}
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
@@ -89,5 +114,6 @@ public class StreamInfo {
streamPreviewData = new JSONObject(streamData.get("preview").toString());
}
}
+ return true;
}
}
diff --git a/src/com/ixab/UserInfoHandling/UserInfo.java b/src/com/ixab/UserInfoHandling/UserInfo.java
new file mode 100644
index 0000000..0ec5338
--- /dev/null
+++ b/src/com/ixab/UserInfoHandling/UserInfo.java
@@ -0,0 +1,82 @@
+package com.ixab.UserInfoHandling;
+
+import com.ixab.GUI.ErrorMessageGate;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+
+public class UserInfo {
+ private static JSONArray userFollowData;
+ private static String userFollowCount;
+
+ private static int getFollowCount() {
+ return Integer.getInteger(userFollowCount);
+ }
+ public static ArrayList getFollowedChannelNames() {
+ ArrayList names = new ArrayList();
+ System.out.println(userFollowData.toString()); // TODO: implement something to work with
+ return names;
+ }
+
+ public static boolean initUserFollowData(String userName) {
+ if (userName != null) {
+ InputStream is = null;
+ URL url = null;
+ JSONObject object = null;
+ StringBuilder urlBuilder = new StringBuilder();
+ urlBuilder.append("https://api.twitch.tv/kraken/users/");
+
+ urlBuilder.append(userName);
+
+ urlBuilder.append("/follows/channels");
+
+ String URLString = urlBuilder.toString();
+
+ try {
+ url = new URL(URLString);
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+ try {
+ is = url.openStream();
+ } catch (FileNotFoundException e) {
+ ErrorMessageGate.setErrorText("Benutzer "+userName+" existiert nicht.");
+ e.printStackTrace();
+ return false;
+ } catch (IOException e) {
+ ErrorMessageGate.setErrorText("Fehler bei Verbindungsaufbau zu Twitch.");
+ e.printStackTrace();
+ return false;
+ }
+ InputStreamReader isr = new InputStreamReader(is);
+ BufferedReader br = new BufferedReader(isr);
+
+ try {
+ String line;
+ StringBuilder sb = new StringBuilder();
+ while ((line = br.readLine()) != null) {
+ sb.append(line);
+ }
+ object = new JSONObject(sb.toString());
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ String result = object.get("_total").toString();
+
+ if (result == "null") {
+ userFollowData = null;
+ userFollowCount = null;
+ } else {
+ userFollowData = new JSONArray(object.getJSONArray("follows").toString());
+ userFollowCount = result;
+ }
+ }
+ return true;
+ }
+}