[ADDED/MODIFIED] Mehr Stream Daten. Threading.

This commit is contained in:
toksikk
2015-11-12 15:48:37 +01:00
parent 19b2195dc3
commit 6a05f5f447
8 changed files with 299 additions and 101 deletions
+2 -1
View File
@@ -2,6 +2,7 @@ package com.ixab.GUI;
public class ErrorMessageGate { public class ErrorMessageGate {
public static void setErrorText(String s) { public static void setErrorText(String s) {
// TODO: na was wohl? MainWindow mw = MainWindowGate.getMainWindow();
mw.getErrorLabel().setText(s);
} }
} }
+87 -56
View File
@@ -3,11 +3,11 @@
<grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="27dc6" binding="panel" layout-manager="GridLayoutManager" row-count="4" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<xy x="20" y="20" width="650" height="400"/> <xy x="20" y="20" width="650" height="500"/>
</constraints> </constraints>
<properties> <properties>
<minimumSize width="650" height="200"/> <minimumSize width="650" height="400"/>
<preferredSize width="650" height="200"/> <preferredSize width="650" height="400"/>
</properties> </properties>
<border type="none"/> <border type="none"/>
<children> <children>
@@ -39,7 +39,7 @@
<text value="Qualität:"/> <text value="Qualität:"/>
</properties> </properties>
</component> </component>
<component id="7c5a1" class="javax.swing.JButton" binding="entfernenButton" default-binding="true"> <component id="7c5a1" class="javax.swing.JButton" binding="buttonRemoveStream" default-binding="true">
<constraints> <constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
@@ -47,7 +47,7 @@
<text value="Ausgw. Stream entfernen"/> <text value="Ausgw. Stream entfernen"/>
</properties> </properties>
</component> </component>
<grid id="7567d" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="7567d" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="1" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="1" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -71,52 +71,97 @@
<text value="Kategorie:"/> <text value="Kategorie:"/>
</properties> </properties>
</component> </component>
<component id="2a9d4" class="javax.swing.JLabel" binding="labelStreamTitle"> <grid id="31cd7" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="3" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties/>
<text value=""/> <border type="none"/>
</properties> <children>
</component>
<component id="dcbec" class="javax.swing.JLabel" binding="labelStreamGame">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<hspacer id="7a444">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="658e2" class="javax.swing.JLabel"> <component id="658e2" class="javax.swing.JLabel">
<constraints> <constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<text value="Vorschau:"/> <text value="Vorschau:"/>
</properties> </properties>
</component> </component>
<grid id="8ebda" binding="previewImagePanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="8ebda" binding="panelPreviewImage" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="3" column="1" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="1" row-span="2" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<minimum-size width="320" height="180"/>
<preferred-size width="320" height="180"/>
<maximum-size width="320" height="180"/>
</grid>
</constraints> </constraints>
<properties/> <properties>
<background color="-1"/>
</properties>
<border type="none"/> <border type="none"/>
<children/> <children/>
</grid> </grid>
<grid id="136f3" layout-manager="GridLayoutManager" row-count="1" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <hspacer id="8b583">
<constraints>
<grid row="0" column="2" row-span="2" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<vspacer id="edf84">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
</children>
</grid>
<component id="7fec7" class="javax.swing.JTextField" binding="textFieldStreamTitle">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
</properties>
</component>
<component id="544c8" class="javax.swing.JTextField" binding="textFieldStreamGame">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
</properties>
</component>
<grid id="75d86" layout-manager="GridLayoutManager" row-count="1" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="2" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="bbe9d" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Status:"/>
</properties>
</component>
<component id="7f132" class="javax.swing.JTextField" binding="textFieldStreamStatus">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="50" height="-1"/>
<preferred-size width="50" height="-1"/>
<maximum-size width="50" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
</properties>
</component>
<component id="c34b7" class="javax.swing.JLabel"> <component id="c34b7" class="javax.swing.JLabel">
<constraints> <constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
@@ -125,37 +170,23 @@
<text value="Zuschauer:"/> <text value="Zuschauer:"/>
</properties> </properties>
</component> </component>
<component id="65a1f" class="javax.swing.JLabel" binding="labelStreamViewers"> <component id="97d89" class="javax.swing.JTextField" binding="textFieldStreamViewers">
<constraints> <constraints>
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="0" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false">
<minimum-size width="70" height="-1"/>
<preferred-size width="70" height="-1"/>
<maximum-size width="70" height="-1"/>
</grid>
</constraints> </constraints>
<properties> <properties>
<text value=""/> <editable value="false"/>
</properties> </properties>
</component> </component>
<hspacer id="b1486"> <hspacer id="903e4">
<constraints> <constraints>
<grid row="0" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="0" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
</hspacer> </hspacer>
<component id="e40fa" class="javax.swing.JLabel" binding="labelStreamStatus">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<component id="bbe9d" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="39" height="14"/>
</grid>
</constraints>
<properties>
<text value="Status:"/>
</properties>
</component>
</children> </children>
</grid> </grid>
</children> </children>
@@ -173,7 +204,7 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="48958" class="javax.swing.JButton" binding="neuLadenButton" default-binding="true"> <component id="48958" class="javax.swing.JButton" binding="buttonReloadStreamData" default-binding="true">
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
@@ -181,7 +212,7 @@
<text value="Stream Infos neu laden"/> <text value="Stream Infos neu laden"/>
</properties> </properties>
</component> </component>
<component id="be49e" class="javax.swing.JButton" binding="streamAbspielenButton" default-binding="true"> <component id="be49e" class="javax.swing.JButton" binding="buttonPlayStream" default-binding="true">
<constraints> <constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
@@ -189,7 +220,7 @@
<text value="Stream abspielen"/> <text value="Stream abspielen"/>
</properties> </properties>
</component> </component>
<component id="95ee2" class="javax.swing.JButton" binding="einstellungenButton" default-binding="true"> <component id="95ee2" class="javax.swing.JButton" binding="buttonSettings" default-binding="true">
<constraints> <constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
@@ -197,7 +228,7 @@
<text value="Einstellungen"/> <text value="Einstellungen"/>
</properties> </properties>
</component> </component>
<component id="a3649" class="javax.swing.JButton" binding="hinzufügenButton" default-binding="true"> <component id="a3649" class="javax.swing.JButton" binding="buttonAddStream" default-binding="true">
<constraints> <constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
+35 -20
View File
@@ -12,17 +12,17 @@ public class MainWindow {
private JPanel panel; private JPanel panel;
private JComboBox comboBoxStreams; private JComboBox comboBoxStreams;
private JComboBox comboBoxQuality; private JComboBox comboBoxQuality;
private JTextField textField1; private JButton buttonAddStream;
private JButton hinzufügenButton; private JButton buttonPlayStream;
private JButton streamAbspielenButton; private JButton buttonRemoveStream;
private JButton entfernenButton; private JTextField textFieldStreamStatus;
private JLabel labelStreamStatus; private JTextField textFieldStreamViewers;
private JLabel labelStreamViewers; private JTextField textFieldStreamTitle;
private JLabel labelStreamTitle; private JTextField textFieldStreamGame;
private JLabel labelStreamGame; private JButton buttonReloadStreamData;
private JButton neuLadenButton; private JPanel panelPreviewImage;
private JPanel previewImagePanel; private JButton buttonSettings;
private JButton einstellungenButton; private Thread updateThread;
protected JLabel getErrorLabel() { protected JLabel getErrorLabel() {
return errorLabel; return errorLabel;
@@ -34,20 +34,20 @@ public class MainWindow {
public MainWindow() { public MainWindow() {
MainWindowGate.setMainWindow(this); MainWindowGate.setMainWindow(this);
this.initComboBoxes(); this.initComboBoxes();
streamAbspielenButton.addActionListener(new ActionListener() { buttonPlayStream.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
StreamOpener so = new StreamOpener(ConfigFileInstanceHandler.getConfig(), ConfigFileInstanceHandler.getConfig().getStreams().indexOf(comboBoxStreams.getSelectedItem()), comboBoxQuality.getSelectedItem().toString()); StreamOpener so = new StreamOpener(ConfigFileInstanceHandler.getConfig(), ConfigFileInstanceHandler.getConfig().getStreams().indexOf(comboBoxStreams.getSelectedItem()), comboBoxQuality.getSelectedItem().toString());
so.start(); so.start();
} }
}); });
hinzufügenButton.addActionListener(new ActionListener() { buttonAddStream.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
addNewStream(); addNewStream();
} }
}); });
entfernenButton.addActionListener(new ActionListener() { buttonRemoveStream.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ConfigFileInstanceHandler.getConfig().removeStream(comboBoxStreams.getSelectedItem()); ConfigFileInstanceHandler.getConfig().removeStream(comboBoxStreams.getSelectedItem());
@@ -65,13 +65,13 @@ public class MainWindow {
} }
} }
}); });
neuLadenButton.addActionListener(new ActionListener() { buttonReloadStreamData.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
updateStreamDetails(); updateStreamDetails();
} }
}); });
einstellungenButton.addActionListener(new ActionListener() { buttonSettings.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
SettingsWindow sw = new SettingsWindow(); SettingsWindow sw = new SettingsWindow();
@@ -80,11 +80,26 @@ public class MainWindow {
}); });
} }
private void updateStreamDetails() { private void updateStreamDetails() {
if (updateThread != null) {
if (updateThread.isAlive()) {
updateThread.interrupt();
}
}
Runnable r = new Runnable() {
@Override
public void run() {
StreamInfo.initStreamData(comboBoxStreams.getSelectedItem().toString()); StreamInfo.initStreamData(comboBoxStreams.getSelectedItem().toString());
labelStreamStatus.setText(StreamInfo.getStatus()); textFieldStreamStatus.setText(StreamInfo.getStatus());
labelStreamGame.setText(StreamInfo.getGame()); textFieldStreamGame.setText(StreamInfo.getGame());
labelStreamViewers.setText(StreamInfo.getViewers()); textFieldStreamViewers.setText(StreamInfo.getViewers());
labelStreamTitle.setText(StreamInfo.getTitle()); 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() { private void addNewStream() {
AddStreamDialog as = new AddStreamDialog(); AddStreamDialog as = new AddStreamDialog();
+27 -1
View File
@@ -49,7 +49,7 @@
</grid> </grid>
</children> </children>
</grid> </grid>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="e3588" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -102,6 +102,32 @@
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
</hspacer> </hspacer>
<component id="c3f1e" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Benutzer Import:"/>
</properties>
</component>
<component id="3e70" class="javax.swing.JTextField" binding="twitchBenutzernameTextField" default-binding="true">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<text value="Twitch-Benutzername"/>
</properties>
</component>
<component id="9749e" class="javax.swing.JButton" binding="buttonImportUserData">
<constraints>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Importieren"/>
</properties>
</component>
</children> </children>
</grid> </grid>
</children> </children>
+20 -1
View File
@@ -1,6 +1,8 @@
package com.ixab.GUI; package com.ixab.GUI;
import com.ixab.ConfigHandling.ConfigFileIOHandler;
import com.ixab.ConfigHandling.ConfigFileInstanceHandler; import com.ixab.ConfigHandling.ConfigFileInstanceHandler;
import com.ixab.UserInfoHandling.UserInfo;
import javax.swing.*; import javax.swing.*;
import java.awt.event.*; import java.awt.event.*;
@@ -12,6 +14,8 @@ public class SettingsWindow extends JDialog {
private JCheckBox debugmodusCheckBox; private JCheckBox debugmodusCheckBox;
private JTextField textField1; private JTextField textField1;
private JButton suchenButton; private JButton suchenButton;
private JTextField twitchBenutzernameTextField;
private JButton buttonImportUserData;
public SettingsWindow() { public SettingsWindow() {
textField1.setText(ConfigFileInstanceHandler.getConfig().getLSPath()); textField1.setText(ConfigFileInstanceHandler.getConfig().getLSPath());
@@ -54,10 +58,25 @@ public class SettingsWindow extends JDialog {
if (jfc.getSelectedFile() != null) textField1.setText(jfc.getSelectedFile().getAbsolutePath()); 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() { private void onOK() {
// add your code here ConfigFileInstanceHandler.getConfig().setLSPath(textField1.getText());
ConfigFileIOHandler.save(ConfigFileInstanceHandler.getConfig());
dispose(); dispose();
} }
+1 -3
View File
@@ -8,7 +8,7 @@ import com.ixab.GUI.MainWindow;
import javax.swing.*; import javax.swing.*;
public class Main { public class Main {
private final static String version = "0.3 Alpha"; private final static String version = "0.4 Alpha";
private static Config c = null; private static Config c = null;
public static void main(String[] args) { public static void main(String[] args) {
try { try {
@@ -28,8 +28,6 @@ public class Main {
catch (IllegalAccessException e) { catch (IllegalAccessException e) {
// handle exception // handle exception
} }
//ConfigLoadMenu.create(null);
c = ConfigFileIOHandler.load(); c = ConfigFileIOHandler.load();
if (c == null) { if (c == null) {
initNewConfig(); initNewConfig();
+29 -3
View File
@@ -1,7 +1,10 @@
package com.ixab.StreamHandling; package com.ixab.StreamHandling;
import com.ixab.GUI.ErrorMessageGate;
import org.json.JSONObject; import org.json.JSONObject;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -14,7 +17,7 @@ public class StreamInfo {
private static JSONObject streamPreviewData = null; private static JSONObject streamPreviewData = null;
public static String getGame() { public static String getGame() {
if (streamData == null && streamPreviewData == null) { if (streamData == null && streamPreviewData == null) {
return "0"; return "-";
} else { } else {
JSONObject channelData = new JSONObject(streamData.get("channel").toString()); JSONObject channelData = new JSONObject(streamData.get("channel").toString());
return channelData.get("game").toString(); return channelData.get("game").toString();
@@ -22,7 +25,7 @@ public class StreamInfo {
} }
public static String getTitle() { public static String getTitle() {
if (streamData == null && streamPreviewData == null) { if (streamData == null && streamPreviewData == null) {
return "0"; return "-";
} else { } else {
JSONObject channelData = new JSONObject(streamData.get("channel").toString()); JSONObject channelData = new JSONObject(streamData.get("channel").toString());
return channelData.get("status").toString(); return channelData.get("status").toString();
@@ -42,7 +45,27 @@ public class StreamInfo {
return "online"; 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) { if (streamName != null) {
InputStream is = null; InputStream is = null;
URL url = null; URL url = null;
@@ -62,7 +85,9 @@ public class StreamInfo {
try { try {
is = url.openStream(); is = url.openStream();
} catch (IOException e) { } catch (IOException e) {
ErrorMessageGate.setErrorText("Fehler bei Verbindungsaufbau zu Twitch.");
e.printStackTrace(); e.printStackTrace();
return false;
} }
InputStreamReader isr = new InputStreamReader(is); InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr); BufferedReader br = new BufferedReader(isr);
@@ -89,5 +114,6 @@ public class StreamInfo {
streamPreviewData = new JSONObject(streamData.get("preview").toString()); streamPreviewData = new JSONObject(streamData.get("preview").toString());
} }
} }
return true;
} }
} }
@@ -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<String> getFollowedChannelNames() {
ArrayList<String> names = new ArrayList<String>();
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;
}
}