Archived
[ADDED] Erste Implementierung einer Logger Klasse
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.ixab.ConfigHandling;
|
||||
|
||||
import com.ixab.Logging.Logger;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class ConfigFileIOHandler {
|
||||
@@ -18,7 +20,7 @@ public class ConfigFileIOHandler {
|
||||
return null;
|
||||
}catch(ClassNotFoundException e)
|
||||
{
|
||||
System.out.println("Config class not found");
|
||||
Logger.print("Config class not found");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
@@ -33,7 +35,7 @@ public class ConfigFileIOHandler {
|
||||
out.writeObject(c);
|
||||
out.close();
|
||||
fileOut.close();
|
||||
System.out.println("Config data is saved in config.dat");
|
||||
Logger.print("Config data is saved in config.dat");
|
||||
}catch(IOException i)
|
||||
{
|
||||
i.printStackTrace();
|
||||
@@ -45,4 +47,7 @@ public class ConfigFileIOHandler {
|
||||
public static void save(Config c) {
|
||||
save(c, "config.dat");
|
||||
}
|
||||
public static void save() {
|
||||
save(ConfigFileInstanceHandler.getConfig(), "config.dat");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +48,7 @@ public class AddStreamDialog extends JDialog {
|
||||
private void onOK() {
|
||||
ConfigFileInstanceHandler.getConfig().addStream(textField1.getText());
|
||||
ConfigFileIOHandler.save(ConfigFileInstanceHandler.getConfig());
|
||||
MainWindowGate.getMainWindow().lockStreamInfoGetter = true;
|
||||
MainWindowGate.getMainWindow().refreshStreamsComboBox();
|
||||
MainWindowGate.getMainWindow().lockStreamInfoGetter = false;
|
||||
ErrorMessageGate.setErrorText("Stream \""+textField1.getText()+"\" hinzugefügt.");
|
||||
textField1.setText("");
|
||||
dispose();
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.ixab.ConfigHandling.ConfigFileIOHandler;
|
||||
import com.ixab.ConfigHandling.ConfigFileInstanceHandler;
|
||||
import com.ixab.ConfigHandling.StreamConfigItem;
|
||||
import com.ixab.ConfigHandling.StreamConfigSorter;
|
||||
import com.ixab.Logging.Logger;
|
||||
import com.ixab.StreamHandling.StreamOpener;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -31,7 +32,7 @@ public class MainWindow {
|
||||
|
||||
private JLabel errorLabel;
|
||||
private JButton buttonReloadStreamData;
|
||||
protected boolean lockStreamInfoGetter = false;
|
||||
private boolean lockStreamInfoGetter = false;
|
||||
|
||||
public MainWindow() {
|
||||
|
||||
@@ -93,6 +94,12 @@ public class MainWindow {
|
||||
});
|
||||
}
|
||||
private void startUpdaterThread() {
|
||||
if (updateThread != null) {
|
||||
if (updateThread.isAlive()) {
|
||||
updateThread.interrupt();
|
||||
Logger.print("Thread interrupted", this);
|
||||
}
|
||||
}
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -117,7 +124,7 @@ public class MainWindow {
|
||||
}
|
||||
private void makeAPause(long time) {
|
||||
try {
|
||||
System.out.println("schläft "+time/1000.0+" sek");
|
||||
Logger.print("schläft "+time/1000.0+" sek", this);
|
||||
Thread.sleep(time);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
@@ -125,12 +132,14 @@ public class MainWindow {
|
||||
}
|
||||
};
|
||||
Thread t = new Thread(r);
|
||||
this.updateThread = t;
|
||||
t.start();
|
||||
}
|
||||
private void updateStreamDetails() {
|
||||
if (updateThread != null) {
|
||||
if (updateThread.isAlive()) {
|
||||
updateThread.interrupt();
|
||||
Logger.print("Thread interrupted" , this);
|
||||
}
|
||||
}
|
||||
Runnable r = new Runnable() {
|
||||
|
||||
@@ -74,9 +74,7 @@ public class SettingsWindow extends JDialog {
|
||||
ConfigFileInstanceHandler.getConfig().addStream(name);
|
||||
}
|
||||
ConfigFileIOHandler.save(ConfigFileInstanceHandler.getConfig());
|
||||
MainWindowGate.getMainWindow().lockStreamInfoGetter = true;
|
||||
MainWindowGate.getMainWindow().refreshStreamsComboBox();
|
||||
MainWindowGate.getMainWindow().lockStreamInfoGetter = false;
|
||||
}
|
||||
buttonImportUserData.setText(old);
|
||||
ErrorMessageGate.setErrorText("Streams von "+twitchBenutzernameTextField.getText()+" hinzugefügt.");
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.ixab.Logging;
|
||||
|
||||
import com.sun.org.apache.xpath.internal.SourceTree;
|
||||
|
||||
public class Logger {
|
||||
private static String bracketOpen = "[";
|
||||
private static String bracketClosed = "]";
|
||||
private static String spacer = " ";
|
||||
public static void print(String s, Class c) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
long time = System.currentTimeMillis();
|
||||
sb.append(bracketOpen);
|
||||
sb.append(c.getCanonicalName());
|
||||
sb.append(bracketClosed);
|
||||
sb.append(spacer);
|
||||
sb.append(bracketOpen);
|
||||
sb.append(time);
|
||||
sb.append(bracketClosed);
|
||||
sb.append(spacer);
|
||||
sb.append(s);
|
||||
System.out.println(sb.toString());
|
||||
}
|
||||
public static void print(String s) {
|
||||
print(s, Logger.class);
|
||||
}
|
||||
public static void print(String s, Object o) {
|
||||
print(s, o.getClass());
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.ixab.StreamHandling;
|
||||
|
||||
import com.ixab.ConfigHandling.Config;
|
||||
import com.ixab.GUI.MainWindow;
|
||||
import com.ixab.Logging.Logger;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -25,15 +26,15 @@ public class StreamOpener extends Thread {
|
||||
String line=null;
|
||||
|
||||
while((line=input.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
Logger.print(line, this);
|
||||
// TODO: analyze livestreamer output and inform gui on errors
|
||||
}
|
||||
|
||||
int exitVal = pr.waitFor();
|
||||
System.out.println("Exited with error code " + exitVal);
|
||||
Logger.print("Exited with error code " + exitVal, this);
|
||||
|
||||
} catch(Exception e) {
|
||||
System.out.println(e.toString());
|
||||
Logger.print(e.toString(), this);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ixab.UserInfoHandling;
|
||||
|
||||
import com.ixab.GUI.ErrorMessageGate;
|
||||
import com.ixab.Logging.Logger;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
@@ -23,7 +24,7 @@ public class UserInfo {
|
||||
try {
|
||||
JSONObject followed = new JSONObject(userFollowData.get(i).toString());
|
||||
JSONObject channel = new JSONObject(followed.get("channel").toString());
|
||||
System.out.println(i+" "+channel.get("name").toString()); //remove this line if not needed anymore
|
||||
Logger.print(i + " " + channel.get("name").toString()); //remove this line if not needed anymore
|
||||
names.add(channel.get("name").toString());
|
||||
// TODO: bisher nur maximal 100 importieren wegen twitch api.
|
||||
} catch (JSONException e) {
|
||||
|
||||
Reference in New Issue
Block a user