summaryrefslogtreecommitdiff
path: root/cmpcj/src/de
diff options
context:
space:
mode:
authorgeronimo <geronimo013@gmx.de>2012-08-04 11:10:44 +0200
committergeronimo <geronimo013@gmx.de>2012-08-04 11:10:44 +0200
commite8175c7b23047fefd52f85afe05e2864b2a9bba8 (patch)
tree8dab4e287545805d173a6c8e297c1798a1a01599 /cmpcj/src/de
parentc7d67f443bdfe842c2e356d4edbe345338e3e08d (diff)
downloadcmp-e8175c7b23047fefd52f85afe05e2864b2a9bba8.tar.gz
cmp-e8175c7b23047fefd52f85afe05e2864b2a9bba8.tar.bz2
created new icons to enable visual feedback on mediatype selection, changed json-parser and enabled virtual mediatype usage
Diffstat (limited to 'cmpcj/src/de')
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java37
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java34
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java36
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java39
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java173
5 files changed, 261 insertions, 58 deletions
diff --git a/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java b/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java
index 73f6204..0448549 100644
--- a/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java
+++ b/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java
@@ -1,25 +1,25 @@
/**
* ======================== legal notice ======================
*
- * File: SRMediaPlayer.java
- * Created:
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: cmpc - a java frontend (client) part of compound media player
- * uses external players to play the media
+ * File: SRMediaPlayer.java Created: Author: <a
+ * href="mailto:geronimo013@gmx.de">Geronimo</a> Project: cmpc - a java frontend
+ * (client) part of compound media player uses external players to play the
+ * media
*
* CMP - compound media player
*
- * is a client/server mediaplayer intended to play any media from any workstation
- * without the need to export or mount shares. cmps is an easy to use backend
- * with a (ready to use) HTML-interface. Additionally the backend supports
- * authentication via HTTP-digest authorization.
- * cmpc is a client with vdr-like osd-menues.
+ * is a client/server mediaplayer intended to play any media from any
+ * workstation without the need to export or mount shares. cmps is an easy to
+ * use backend with a (ready to use) HTML-interface. Additionally the backend
+ * supports authentication via HTTP-digest authorization. cmpc is a client with
+ * vdr-like osd-menues.
*
- * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
- * published under Creative Commons by-sa
- * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under
+ * Creative Commons by-sa For details see
+ * http://creativecommons.org/licenses/by-sa/3.0/
*
- * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ * The cmp project's homepage is at
+ * http://projects.vdr-developer.org/projects/cmp
*
* --------------------------------------------------------------
*/
@@ -159,6 +159,7 @@ public class SRMediaPlayer implements IMediaPlayer {
public static void main(final String[] args) {
+ appInfo();
javax.swing.SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
@@ -169,6 +170,14 @@ public class SRMediaPlayer implements IMediaPlayer {
});
}
+
+ protected static void appInfo() {
+ System.err.println("cmpcj - the java frontend of CMP (compound media player)");
+ System.err.println(" serves to browse a medialist from remote systems and to start a player");
+ System.err.println(" for selected media.");
+ System.err.println(" (c) 2012 - Reinhard Mantey - some rights reserved.");
+ System.err.println(" CMP is published as open source under Creative Commons by-sa");
+ }
private boolean debug = false;
private JFrame mainFrame;
private Config config;
diff --git a/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java b/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java
index c336329..57f320f 100644
--- a/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java
+++ b/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java
@@ -1,25 +1,25 @@
/**
* ======================== legal notice ======================
*
- * File: MediaType.java
- * Created:
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: cmpc - a java frontend (client) part of compound media player
- * uses external players to play the media
+ * File: MediaType.java Created: Author: <a
+ * href="mailto:geronimo013@gmx.de">Geronimo</a> Project: cmpc - a java frontend
+ * (client) part of compound media player uses external players to play the
+ * media
*
* CMP - compound media player
*
- * is a client/server mediaplayer intended to play any media from any workstation
- * without the need to export or mount shares. cmps is an easy to use backend
- * with a (ready to use) HTML-interface. Additionally the backend supports
- * authentication via HTTP-digest authorization.
- * cmpc is a client with vdr-like osd-menues.
+ * is a client/server mediaplayer intended to play any media from any
+ * workstation without the need to export or mount shares. cmps is an easy to
+ * use backend with a (ready to use) HTML-interface. Additionally the backend
+ * supports authentication via HTTP-digest authorization. cmpc is a client with
+ * vdr-like osd-menues.
*
- * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
- * published under Creative Commons by-sa
- * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under
+ * Creative Commons by-sa For details see
+ * http://creativecommons.org/licenses/by-sa/3.0/
*
- * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ * The cmp project's homepage is at
+ * http://projects.vdr-developer.org/projects/cmp
*
* --------------------------------------------------------------
*/
@@ -32,7 +32,7 @@ public class MediaType {
}
- public int getStart() {
+ public long getStart() {
return start;
}
@@ -42,10 +42,10 @@ public class MediaType {
}
- public void setStart(int start) {
+ public void setStart(long start) {
this.start = start;
}
private String name;
- private int start;
+ private long start;
}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java
index b37834c..983fdd3 100644
--- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java
+++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java
@@ -1,25 +1,25 @@
/**
* ======================== legal notice ======================
*
- * File: MediaListLoader.java
- * Created:
- * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a>
- * Project: cmpc - a java frontend (client) part of compound media player
- * uses external players to play the media
+ * File: MediaListLoader.java Created: Author: <a
+ * href="mailto:geronimo013@gmx.de">Geronimo</a> Project: cmpc - a java frontend
+ * (client) part of compound media player uses external players to play the
+ * media
*
* CMP - compound media player
*
- * is a client/server mediaplayer intended to play any media from any workstation
- * without the need to export or mount shares. cmps is an easy to use backend
- * with a (ready to use) HTML-interface. Additionally the backend supports
- * authentication via HTTP-digest authorization.
- * cmpc is a client with vdr-like osd-menues.
+ * is a client/server mediaplayer intended to play any media from any
+ * workstation without the need to export or mount shares. cmps is an easy to
+ * use backend with a (ready to use) HTML-interface. Additionally the backend
+ * supports authentication via HTTP-digest authorization. cmpc is a client with
+ * vdr-like osd-menues.
*
- * Copyright (c) 2012 Reinhard Mantey, some rights reserved!
- * published under Creative Commons by-sa
- * For details see http://creativecommons.org/licenses/by-sa/3.0/
+ * Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under
+ * Creative Commons by-sa For details see
+ * http://creativecommons.org/licenses/by-sa/3.0/
*
- * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp
+ * The cmp project's homepage is at
+ * http://projects.vdr-developer.org/projects/cmp
*
* --------------------------------------------------------------
*/
@@ -30,7 +30,6 @@ import java.net.ConnectException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
-import org.codehaus.jackson.map.ObjectMapper;
import ca.odell.glazedlists.BasicEventList;
import ca.odell.glazedlists.EventList;
import de.schwarzrot.cmpc.domain.Media;
@@ -64,7 +63,7 @@ public class MediaListLoader implements Runnable {
start = new Date();
request = new URL("http", hostName, port, "/?format=json");
URLConnection conn = request.openConnection();
- final PlayList firstPlaylist = jsonOM.readValue(conn.getInputStream(), PlayList.class);
+ final PlayList firstPlaylist = jsonParser.parseListChunk(conn.getInputStream());
mediaPool.getReadWriteLock().writeLock().lock();
for (Media m : firstPlaylist.getResults()) {
@@ -85,7 +84,7 @@ public class MediaListLoader implements Runnable {
uri = String.format("/?start=%d&limit=%d&format=json", n, 100);
request = new URL("http", hostName, port, uri);
conn = request.openConnection();
- next = jsonOM.readValue(conn.getInputStream(), PlayList.class);
+ next = jsonParser.parseListChunk(conn.getInputStream());
mediaPool.getReadWriteLock().writeLock().lock();
for (Media m : next.getResults()) {
mediaPool.add(m);
@@ -96,6 +95,7 @@ public class MediaListLoader implements Runnable {
}
} catch (Throwable t) {
System.out.println("Oups, media list contains now #" + mediaPool.size() + " entries.");
+ System.err.println("Error on chunk #" + n);
t.printStackTrace();
} finally {
try {
@@ -119,6 +119,6 @@ public class MediaListLoader implements Runnable {
private String hostName;
private int port;
- private ObjectMapper jsonOM = new ObjectMapper();
+ private MedialistParser jsonParser = new MedialistParser();
private EventList<Media> mediaPool = new BasicEventList<Media>();
}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java
index 24cd506..bde865a 100644
--- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java
+++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java
@@ -60,14 +60,17 @@ public class MediaTypeSelect extends AbstractMatcherEditor<Media> implements Lis
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
+ ImageIcon icon = null;
+
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
+ icon = selImages[((Media.SupportedMediaType) value).ordinal()];
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
+ icon = stdImages[((Media.SupportedMediaType) value).ordinal()];
}
- ImageIcon icon = images[((Media.SupportedMediaType) value).ordinal()];
setSize(110, 110);
setHorizontalAlignment(JLabel.CENTER);
@@ -86,21 +89,35 @@ public class MediaTypeSelect extends AbstractMatcherEditor<Media> implements Lis
ClassLoader cl = getClass().getClassLoader();
URL url;
- images = new ImageIcon[iconFiles.length];
+ stdImages = new ImageIcon[iconFiles.length];
for (int i = 0; i < iconFiles.length; ++i) {
try {
url = cl.getResource(iconFiles[i]);
img = ImageIO.read(url);
- images[i] = new ImageIcon(img.getScaledInstance(110, 110, Image.SCALE_SMOOTH));
+ stdImages[i] = new ImageIcon(img.getScaledInstance(110, 110, Image.SCALE_SMOOTH));
} catch (Throwable t) {
System.err.println("failed to read image from " + iconFiles[i]);
t.printStackTrace();
}
}
+
+ selImages = new ImageIcon[activeIconFiles.length];
+ for (int i = 0; i < activeIconFiles.length; ++i) {
+ try {
+ url = cl.getResource(activeIconFiles[i]);
+
+ img = ImageIO.read(url);
+ selImages[i] = new ImageIcon(img.getScaledInstance(110, 110, Image.SCALE_SMOOTH));
+ } catch (Throwable t) {
+ System.err.println("failed to read image from " + activeIconFiles[i]);
+ t.printStackTrace();
+ }
+ }
}
- ImageIcon[] images;
+ ImageIcon[] stdImages;
+ ImageIcon[] selImages;
}
@@ -139,11 +156,15 @@ public class MediaTypeSelect extends AbstractMatcherEditor<Media> implements Lis
private EventList<Media.SupportedMediaType> selectedTypes;
private JList mediaTypeJList;
private static final String[] iconFiles;
+ private static final String[] activeIconFiles;
static {
- iconFiles = new String[] { "images/folder_black.png", "images/folder_black_music.png",
- "images/folder_black_movies.png", "images/folder_black_i_movies.png", "images/folder_black_dvd.png",
- "images/folder_black_i_dvd.png", "images/folder_black_vdr_old.png",
- "images/folder_black_i_vdr_old.png", "images/folder_black_vdr.png", "images/folder_black_i_vdr.png",
- "images/folder_black_photos.png", "images/folder_black.png" };
+ iconFiles = new String[] { "images/sr_default.png", "images/sr_music.png", "images/sr_movies.png",
+ "images/sr_movies_i.png", "images/sr_dvd.png", "images/sr_dvd_i.png", "images/sr_lvdr.png",
+ "images/sr_lvdr_i.png", "images/sr_vdr.png", "images/sr_vdr_i.png", "images/sr_photos.png",
+ "images/sr_default.png" };
+ activeIconFiles = new String[] { "images/sradefault.png", "images/sramusic.png", "images/sramovies.png",
+ "images/sramovies_i.png", "images/sradvd.png", "images/sradvd_i.png", "images/sralvdr.png",
+ "images/sralvdr_i.png", "images/sravdr.png", "images/sravdr_i.png", "images/sraphotos.png",
+ "images/sradefault.png" };
}
}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java b/cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java
new file mode 100644
index 0000000..8f69af0
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java
@@ -0,0 +1,173 @@
+package de.schwarzrot.cmpc.util;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Test;
+import com.google.gson.stream.JsonReader;
+import de.schwarzrot.cmpc.domain.Media;
+import de.schwarzrot.cmpc.domain.MediaType;
+import de.schwarzrot.cmpc.domain.PlayList;
+
+
+public class MedialistParser {
+ public PlayList parseListChunk(InputStream is) {
+ JsonReader reader = null;
+ PlayList rv = null;
+
+ try {
+ reader = new JsonReader(new InputStreamReader(is, "UTF-8"));
+
+ rv = readPlayList(reader);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ } finally {
+ try {
+ reader.close();
+ } catch (Throwable t) {
+ }
+ }
+ return rv;
+ }
+
+
+ @Test
+ public void testJSonParsing() {
+ FileInputStream fis = null;
+
+ try {
+ fis = new FileInputStream(new File("test.json"));
+ parseListChunk(fis);
+ fis.close();
+ fis = null;
+ } catch (Throwable t) {
+ t.printStackTrace();
+ } finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (Throwable t) {
+ }
+ }
+ }
+ }
+
+
+ protected Media readMedia(JsonReader reader) {
+ Media rv = new Media();
+
+ try {
+ reader.beginObject();
+ while (reader.hasNext()) {
+ String name = reader.nextName();
+
+ if ("name".equals(name)) {
+ rv.setName(reader.nextString());
+ } else if ("type".equals(name)) {
+ rv.setType(reader.nextInt());
+ } else if ("format".equals(name)) {
+ rv.setFormat(reader.nextString());
+ } else if ("width".equals(name)) {
+ rv.setWidth(reader.nextInt());
+ } else if ("height".equals(name)) {
+ rv.setHeight(reader.nextInt());
+ } else if ("path".equals(name)) {
+ rv.setPath(reader.nextString());
+ } else {
+ reader.skipValue();
+ }
+ }
+ reader.endObject();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ return rv;
+ }
+
+
+ protected List<Media> readMediaArray(JsonReader reader) {
+ List<Media> rv = new ArrayList<Media>();
+
+ try {
+ reader.beginArray();
+ while (reader.hasNext()) {
+ rv.add(readMedia(reader));
+ }
+ reader.endArray();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ return rv;
+ }
+
+
+ protected MediaType readMediaType(JsonReader reader) {
+ MediaType rv = new MediaType();
+
+ try {
+ reader.beginObject();
+ while (reader.hasNext()) {
+ String name = reader.nextName();
+
+ if ("name".equals(name)) {
+ rv.setName(reader.nextString());
+ } else if ("start".equals(name)) {
+ rv.setStart(reader.nextLong());
+ } else {
+ reader.skipValue();
+ }
+ }
+ reader.endObject();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ return rv;
+ }
+
+
+ protected PlayList readPlayList(JsonReader reader) {
+ PlayList rv = new PlayList();
+
+ try {
+ reader.beginObject();
+ while (reader.hasNext()) {
+ String name = reader.nextName();
+
+ if ("total".equals(name)) {
+ rv.setTotal(reader.nextLong());
+ } else if ("types".equals(name)) {
+ rv.setTypes(readTypeArray(reader));
+ } else if ("results".equals(name)) {
+ rv.setResults(readMediaArray(reader));
+ } else {
+ reader.skipValue();
+ }
+ }
+ reader.endObject();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ rv = null;
+ }
+ return rv;
+ }
+
+
+ protected List<MediaType> readTypeArray(JsonReader reader) {
+ List<MediaType> rv = new ArrayList<MediaType>();
+
+ try {
+ reader.beginArray();
+ while (reader.hasNext()) {
+ rv.add(readMediaType(reader));
+ }
+ reader.endArray();
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ return rv;
+ }
+}