summaryrefslogtreecommitdiff
path: root/cmpcj/src
diff options
context:
space:
mode:
Diffstat (limited to 'cmpcj/src')
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/app/ConfigFactory.java132
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/app/IMediaPlayer.java46
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java181
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/domain/Config.java73
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/domain/Media.java82
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/domain/MediaServer.java51
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java51
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/domain/PlayList.java65
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/domain/PlayerDefinition.java65
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/ui/AppSelector.java90
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/ui/MediaClient.java264
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/util/MediaClientExecutor.java34
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/util/MediaComparator.java40
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/util/MediaExecutor.java57
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/util/MediaForTypeMatcher.java54
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java124
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/util/MediaPool2TypeList.java59
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/util/MediaTableFormat.java64
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/util/MediaTextFilterator.java40
-rw-r--r--cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java146
20 files changed, 1718 insertions, 0 deletions
diff --git a/cmpcj/src/de/schwarzrot/cmpc/app/ConfigFactory.java b/cmpcj/src/de/schwarzrot/cmpc/app/ConfigFactory.java
new file mode 100644
index 0000000..f1c4685
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/app/ConfigFactory.java
@@ -0,0 +1,132 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: ConfigFactory.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.app;
+
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import de.schwarzrot.cmpc.domain.Config;
+import de.schwarzrot.cmpc.domain.Media;
+import de.schwarzrot.cmpc.domain.MediaServer;
+import de.schwarzrot.cmpc.domain.PlayerDefinition;
+
+
+public class ConfigFactory {
+ protected static final Pattern SETUP_MASK = Pattern.compile("^\\s*(\\S+)\\s*=\\s*(.+)$");
+
+
+ public ConfigFactory(File configDirectory) {
+ baseDir = configDirectory;
+ }
+
+
+ public Config getConfig() {
+ if (config == null) {
+ config = readConfig();
+ }
+ return config;
+ }
+
+
+ protected Config readConfig() {
+ File setupFile = new File(baseDir, "srclient.conf");
+ BufferedReader br = null;
+ Config rv = new Config();
+
+ if (setupFile.exists()) {
+ try {
+ br = new BufferedReader(new FileReader(setupFile));
+ String line, trimmedLine;
+
+ while ((line = br.readLine()) != null) {
+ trimmedLine = line.trim();
+
+ if (trimmedLine.isEmpty() || trimmedLine.startsWith("#"))
+ continue;
+ Matcher m = SETUP_MASK.matcher(trimmedLine);
+
+ if (m.matches()) {
+ String key = m.group(1);
+ String value = m.group(2);
+
+ if (key.compareToIgnoreCase("server") == 0) {
+ String[] parts = value.split("\\s*\\:\\s*");
+ MediaServer ms = null;
+
+ if (parts.length > 1) {
+ ms = new MediaServer();
+ ms.setHostName(parts[0]);
+ ms.setPort(Integer.decode(parts[1]));
+
+ rv.addServer(ms);
+ }
+ } else if (key.compareToIgnoreCase("player") == 0) {
+ String[] parts = value.split("\\s*\\:\\s*");
+ PlayerDefinition pd = null;
+
+ if (parts.length > 1) {
+ pd = new PlayerDefinition();
+ String[] cmdline = parts[1].split("\\s+");
+
+ pd.setExecutable(cmdline[0]);
+
+ for (int i = 1; i < cmdline.length; ++i) {
+ pd.addParameter(cmdline[i]);
+ }
+ if (parts[0].compareTo("*") == 0) {
+ // default player
+ for (Media.SupportedMediaType cmt : Media.SupportedMediaType.values())
+ rv.putPlayer(cmt, pd);
+ } else {
+ for (Media.SupportedMediaType cmt : Media.SupportedMediaType.values()) {
+ if (parts[0].compareTo(cmt.name()) == 0)
+ rv.putPlayer(cmt, pd);
+ }
+ }
+ }
+ }
+ }
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ } finally {
+ if (br != null) {
+ try {
+ br.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+ }
+ return rv;
+ }
+ private Config config;
+ private File baseDir;
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/app/IMediaPlayer.java b/cmpcj/src/de/schwarzrot/cmpc/app/IMediaPlayer.java
new file mode 100644
index 0000000..d68adbc
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/app/IMediaPlayer.java
@@ -0,0 +1,46 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: IMediaPlayer.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.app;
+
+
+import de.schwarzrot.cmpc.domain.Config;
+
+
+public interface IMediaPlayer {
+ public Config getConfig();
+
+
+ public String getCurrentMediaCenter();
+
+
+ public boolean isDebug();
+
+
+ public void selectApp();
+
+
+ public void startApp(String name, int port);
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java b/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java
new file mode 100644
index 0000000..73f6204
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java
@@ -0,0 +1,181 @@
+/**
+ * ======================== 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
+ *
+ * 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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.app;
+
+
+import java.awt.CardLayout;
+import java.awt.Container;
+import java.io.File;
+import javax.swing.JFrame;
+import javax.swing.JPanel;
+import javax.swing.UIManager;
+import javax.swing.UIManager.LookAndFeelInfo;
+import de.schwarzrot.cmpc.domain.Config;
+import de.schwarzrot.cmpc.ui.AppSelector;
+import de.schwarzrot.cmpc.ui.MediaClient;
+
+
+public class SRMediaPlayer implements IMediaPlayer {
+ private static final String DEFAULT_TITLE = "client";
+ private static final String USER_HOME = "user.home";
+ private static final String TITLE_MASK = "Compound Media Player (%s)";
+ private static final String MAIN = "MediaServerSelector";
+ private static final String CLIENT = "MediaClient";
+
+
+ public SRMediaPlayer(String[] args, ConfigFactory cf) {
+ for (String a : args) {
+ if (a.compareTo("-d") == 0 || a.compareTo("--debug") == 0)
+ debug = true;
+ }
+ configFactory = cf;
+ }
+
+
+ public void createAndShowGUI() {
+ JFrame.setDefaultLookAndFeelDecorated(false);
+
+ config = configFactory.getConfig();
+ try {
+ for (LookAndFeelInfo lfi : UIManager.getInstalledLookAndFeels()) {
+ if ("Nimbus".equals(lfi.getName())) {
+ UIManager.setLookAndFeel(lfi.getClassName());
+ JFrame.setDefaultLookAndFeelDecorated(true);
+ }
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ System.exit(-1);
+ }
+ mainFrame = new JFrame("JMediaPlayer");
+
+ //Add components to it.
+ Container contentPane = mainFrame.getContentPane();
+ setupMainView(contentPane);
+
+ mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ setTitle(DEFAULT_TITLE);
+ mainFrame.setSize(1000, 700);
+ mainFrame.setLocationRelativeTo(null); //center it
+ mainFrame.setVisible(true);
+ }
+
+
+ @Override
+ public Config getConfig() {
+ return config;
+ }
+
+
+ public ConfigFactory getConfigFactory() {
+ return configFactory;
+ }
+
+
+ @Override
+ public String getCurrentMediaCenter() {
+ return currentMediaCenter;
+ }
+
+
+ @Override
+ public boolean isDebug() {
+ return debug;
+ }
+
+
+ @Override
+ public void selectApp() {
+ setTitle(DEFAULT_TITLE);
+ switchView(MAIN);
+ }
+
+
+ public void setConfigFactory(ConfigFactory configFactory) {
+ this.configFactory = configFactory;
+ }
+
+
+ @Override
+ public void startApp(String name, int port) {
+ currentMediaCenter = name;
+ setTitle(name);
+ switchView(CLIENT);
+ try {
+ mediaClientPane.startConnection(name, port);
+ } catch (Throwable t) {
+ mediaClientPane.setActive(false);
+ switchView(MAIN);
+ }
+ }
+
+
+ protected void setTitle(String title) {
+ mainFrame.setTitle(String.format(TITLE_MASK, title));
+ }
+
+
+ protected void setupMainView(Container clientArea) {
+ stakker = new CardLayout();
+ switchingPane = new JPanel(stakker);
+ mediaClientPane = new MediaClient(CLIENT, this);
+ appSelectorPane = new AppSelector(MAIN, config.getKnownServers());
+
+ mediaClientPane.setup(this);
+ appSelectorPane.setup(this);
+
+ switchingPane.add(appSelectorPane, MAIN);
+ switchingPane.add(mediaClientPane, CLIENT);
+ clientArea.add(switchingPane);
+ }
+
+
+ protected void switchView(String name) {
+ stakker.show(switchingPane, name);
+ }
+
+
+ public static void main(final String[] args) {
+ javax.swing.SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ File configDir = new File(System.getProperty(USER_HOME), ".cmp");
+ SRMediaPlayer app = new SRMediaPlayer(args, new ConfigFactory(configDir));
+ app.createAndShowGUI();
+ }
+ });
+ }
+
+ private boolean debug = false;
+ private JFrame mainFrame;
+ private Config config;
+ private CardLayout stakker;
+ private JPanel switchingPane;
+ private MediaClient mediaClientPane;
+ private AppSelector appSelectorPane;
+ private ConfigFactory configFactory;
+ private String currentMediaCenter;
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/domain/Config.java b/cmpcj/src/de/schwarzrot/cmpc/domain/Config.java
new file mode 100644
index 0000000..f803811
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/domain/Config.java
@@ -0,0 +1,73 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Config.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.domain;
+
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+
+public class Config {
+ public Config() {
+ knownServers = new ArrayList<MediaServer>();
+ playerMap = new HashMap<Media.SupportedMediaType, PlayerDefinition>();
+ }
+
+
+ public void addServer(MediaServer ms) {
+ knownServers.add(ms);
+ }
+
+
+ public List<MediaServer> getKnownServers() {
+ return knownServers;
+ }
+
+
+ public Map<Media.SupportedMediaType, PlayerDefinition> getPlayerMap() {
+ return playerMap;
+ }
+
+
+ public void putPlayer(Media.SupportedMediaType type, PlayerDefinition pd) {
+ playerMap.put(type, pd);
+ }
+
+
+ public void setKnownServers(List<MediaServer> knownServers) {
+ this.knownServers = knownServers;
+ }
+
+
+ public void setPlayerMap(Map<Media.SupportedMediaType, PlayerDefinition> playerMap) {
+ this.playerMap = playerMap;
+ }
+
+ private List<MediaServer> knownServers;
+ private Map<Media.SupportedMediaType, PlayerDefinition> playerMap;
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/domain/Media.java b/cmpcj/src/de/schwarzrot/cmpc/domain/Media.java
new file mode 100644
index 0000000..e784924
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/domain/Media.java
@@ -0,0 +1,82 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: Media.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.domain;
+
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+
+
+public class Media {
+ public enum SupportedMediaType {
+ Invalid, Audio, Movie, DVDImage, LegacyVdrRecording, VdrRecording, Picture, Unknown
+ };
+
+
+ public String getName() {
+ return name;
+ }
+
+
+ public String getPath() {
+ return path;
+ }
+
+
+ public String getSearch() {
+ return search;
+ }
+
+
+ public int getType() {
+ return type;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ public void setPath(String path) {
+ this.path = path;
+ try {
+ search = URLDecoder.decode(path, "utf8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ public void setType(int type) {
+ this.type = type;
+ }
+
+ private String name;
+ private int type;
+ private String path;
+ private String search;
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/domain/MediaServer.java b/cmpcj/src/de/schwarzrot/cmpc/domain/MediaServer.java
new file mode 100644
index 0000000..e6f2683
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/domain/MediaServer.java
@@ -0,0 +1,51 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaServer.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.domain;
+
+
+public class MediaServer {
+ public String getHostName() {
+ return hostName;
+ }
+
+
+ public int getPort() {
+ return port;
+ }
+
+
+ public void setHostName(String hostName) {
+ this.hostName = hostName;
+ }
+
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ private String hostName;
+ private int port;
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java b/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java
new file mode 100644
index 0000000..c336329
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java
@@ -0,0 +1,51 @@
+/**
+ * ======================== 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
+ *
+ * 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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.domain;
+
+
+public class MediaType {
+ public String getName() {
+ return name;
+ }
+
+
+ public int getStart() {
+ return start;
+ }
+
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+ public void setStart(int start) {
+ this.start = start;
+ }
+
+ private String name;
+ private int start;
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/domain/PlayList.java b/cmpcj/src/de/schwarzrot/cmpc/domain/PlayList.java
new file mode 100644
index 0000000..e1aa7d2
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/domain/PlayList.java
@@ -0,0 +1,65 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: PlayList.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.domain;
+
+
+import java.util.List;
+
+
+public class PlayList {
+ public List<Media> getResults() {
+ return results;
+ }
+
+
+ public long getTotal() {
+ return total;
+ }
+
+
+ public List<MediaType> getTypes() {
+ return types;
+ }
+
+
+ public void setResults(List<Media> results) {
+ this.results = results;
+ }
+
+
+ public void setTotal(long total) {
+ this.total = total;
+ }
+
+
+ public void setTypes(List<MediaType> types) {
+ this.types = types;
+ }
+
+ private long total;
+ private List<Media> results;
+ private List<MediaType> types;
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/domain/PlayerDefinition.java b/cmpcj/src/de/schwarzrot/cmpc/domain/PlayerDefinition.java
new file mode 100644
index 0000000..5bc4df0
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/domain/PlayerDefinition.java
@@ -0,0 +1,65 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: PlayerDefinition.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.domain;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class PlayerDefinition {
+ public PlayerDefinition() {
+ parameters = new ArrayList<String>();
+ }
+
+
+ public void addParameter(String parameter) {
+ parameters.add(parameter);
+ }
+
+
+ public String getExecutable() {
+ return executable;
+ }
+
+
+ public List<String> getParameters() {
+ return parameters;
+ }
+
+
+ public void setExecutable(String executable) {
+ this.executable = executable;
+ }
+
+
+ public void setParameters(List<String> parameters) {
+ this.parameters = parameters;
+ }
+
+ private String executable;
+ private List<String> parameters;
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/ui/AppSelector.java b/cmpcj/src/de/schwarzrot/cmpc/ui/AppSelector.java
new file mode 100644
index 0000000..75d3e3c
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/ui/AppSelector.java
@@ -0,0 +1,90 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: AppSelector.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.ui;
+
+
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.util.List;
+import javax.swing.AbstractAction;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
+import de.schwarzrot.cmpc.app.IMediaPlayer;
+import de.schwarzrot.cmpc.domain.MediaServer;
+
+
+public class AppSelector extends JComponent {
+ private static final long serialVersionUID = 713L;
+
+
+ public AppSelector(String id, List<MediaServer> mediaServerHosts) {
+ this.myPanelName = id;
+ this.knownMediaCenters = mediaServerHosts;
+ }
+
+
+ @Override
+ public String getName() {
+ return myPanelName;
+ }
+
+
+ public void setup(final IMediaPlayer mp) {
+ setLayout(new GridLayout(1, 2));
+ JPanel knownHosts = new JPanel();
+
+ knownHosts.setLayout(new GridLayout(knownMediaCenters.size(), 1));
+ for (MediaServer ms : knownMediaCenters) {
+ JButton bt = new JButton(ms.getHostName());
+ AbstractAction a = new AbstractAction() {
+ private static final long serialVersionUID = 713L;
+
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ String host = (String) this.getValue("mediaCenterHost");
+ Integer port = (Integer) this.getValue("mediaCenterPort");
+
+ System.out.println("shall connect " + host + ":" + port);
+ mp.startApp(host, port);
+ }
+ };
+ a.putValue("mediaCenterHost", ms.getHostName());
+ a.putValue("mediaCenterPort", ms.getPort());
+ bt.addActionListener(a);
+ knownHosts.add(bt);
+ }
+ add(knownHosts);
+ JButton setup = new JButton("Setup");
+
+ add(setup);
+ doLayout();
+ }
+
+ private String myPanelName;
+ private List<MediaServer> knownMediaCenters;
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/ui/MediaClient.java b/cmpcj/src/de/schwarzrot/cmpc/ui/MediaClient.java
new file mode 100644
index 0000000..f51e635
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/ui/MediaClient.java
@@ -0,0 +1,264 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaClient.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.ui;
+
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Image;
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.image.BufferedImage;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import javax.imageio.ImageIO;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.JTextField;
+import javax.swing.table.DefaultTableCellRenderer;
+import ca.odell.glazedlists.EventList;
+import ca.odell.glazedlists.FilterList;
+import ca.odell.glazedlists.SortedList;
+import ca.odell.glazedlists.swing.DefaultEventTableModel;
+import ca.odell.glazedlists.swing.GlazedListsSwing;
+import ca.odell.glazedlists.swing.TableComparatorChooser;
+import ca.odell.glazedlists.swing.TextComponentMatcherEditor;
+import de.schwarzrot.cmpc.app.IMediaPlayer;
+import de.schwarzrot.cmpc.domain.Media;
+import de.schwarzrot.cmpc.domain.PlayerDefinition;
+import de.schwarzrot.cmpc.util.MediaClientExecutor;
+import de.schwarzrot.cmpc.util.MediaComparator;
+import de.schwarzrot.cmpc.util.MediaExecutor;
+import de.schwarzrot.cmpc.util.MediaListLoader;
+import de.schwarzrot.cmpc.util.MediaTableFormat;
+import de.schwarzrot.cmpc.util.MediaTextFilterator;
+import de.schwarzrot.cmpc.util.MediaTypeSelect;
+
+
+public class MediaClient extends JComponent implements MediaClientExecutor {
+ private static final long serialVersionUID = 713L;
+
+
+ public MediaClient(String id, IMediaPlayer player) {
+ this.myPanelName = id;
+ this.player = player;
+ setLayout(new BorderLayout());
+ listLoader = new MediaListLoader();
+ mediaPool = listLoader.getMediaPool();
+ }
+
+
+ @Override
+ public String getName() {
+ return myPanelName;
+ }
+
+
+ public boolean isActive() {
+ return active;
+ }
+
+
+ @Override
+ public void playMedia(Media m) {
+ List<String> command = new ArrayList<String>();
+ PlayerDefinition pd = player.getConfig().getPlayerMap().get(m.getType());
+ StringBuilder sb = new StringBuilder("http://");
+
+ sb.append(curHostName);
+ sb.append(":");
+ sb.append(curPort);
+ sb.append(m.getPath());
+
+ command.add(pd.getExecutable());
+ for (String param : pd.getParameters()) {
+ command.add(param);
+ }
+ command.add(sb.toString());
+ ProcessBuilder pb = new ProcessBuilder(command);
+
+ pb.redirectErrorStream(true);
+ try {
+ Process proc = pb.start();
+ BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
+ String line;
+
+ if (player.isDebug()) {
+ while ((line = br.readLine()) != null) {
+ System.err.println(line);
+ }
+ } else {
+ while ((line = br.readLine()) != null)
+ ;
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ }
+ }
+
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+
+ public void setup(final IMediaPlayer mp) {
+ add(createClientPane(), BorderLayout.CENTER);
+ }
+
+
+ public void startConnection(String hostname, int port) {
+ setHost(hostname);
+ setPort(port);
+ mediaPool.getReadWriteLock().writeLock().lock();
+ mediaPool.clear();
+ mediaPool.getReadWriteLock().writeLock().unlock();
+ listLoader.loadMedia(curHostName, curPort);
+ }
+
+
+ protected JComponent createClientPane() {
+ JPanel clientPane = new JPanel();
+
+ loadImages();
+ mediaPool.getReadWriteLock().readLock().lock();
+ try {
+ SortedList<Media> sortedMedias = new SortedList<Media>(GlazedListsSwing.swingThreadProxyList(mediaPool),
+ new MediaComparator());
+ MediaTypeSelect mtSelect = new MediaTypeSelect(sortedMedias);
+ FilterList<Media> filteredMedias = new FilterList<Media>(sortedMedias, mtSelect);
+ JTextField filterEdit = new JTextField(30);
+ FilterList<Media> textFilteredMedia = new FilterList<Media>(filteredMedias,
+ new TextComponentMatcherEditor<Media>(filterEdit, new MediaTextFilterator()));
+ DefaultEventTableModel<Media> mediaTableModel = new DefaultEventTableModel<Media>(textFilteredMedia,
+ new MediaTableFormat());
+ JTable mediaJTable = new JTable(mediaTableModel);
+ @SuppressWarnings({ "unused", "rawtypes" })
+ TableComparatorChooser tableSorter = TableComparatorChooser.install(mediaJTable, sortedMedias,
+ TableComparatorChooser.MULTIPLE_COLUMN_MOUSE_WITH_UNDO);
+ JScrollPane mediaTableScrollPane = new JScrollPane(mediaJTable);
+ JScrollPane mediaTypesScrollPane = new JScrollPane(mtSelect.getJList());
+ JLabel filter = new JLabel(" Filter: ");
+ JButton exitButton = new JButton(images[0]);
+ JButton preferences = new JButton(images[1]);
+
+ filter.setForeground(Color.GRAY);
+ filterEdit.setBackground(Color.LIGHT_GRAY);
+ exitButton.setBackground(Color.BLACK);
+ preferences.setBackground(Color.BLACK);
+ exitButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ player.selectApp();
+ }
+ });
+ mediaTypesScrollPane.setPreferredSize(new Dimension(100, 100));
+ mediaTypesScrollPane.setBackground(Color.BLACK);
+ mediaJTable.getColumnModel().getColumn(0).setMaxWidth(40);
+ mediaJTable.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer());
+ mediaJTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer());
+ mediaJTable.addMouseListener(new MediaExecutor(mediaJTable, textFilteredMedia, this));
+ clientPane.setLayout(new GridBagLayout());
+
+ clientPane.add(exitButton, new GridBagConstraints(0, 0, 1, 2, 0.0, 0.0, GridBagConstraints.CENTER,
+ GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
+ clientPane.add(preferences, new GridBagConstraints(1, 0, 1, 2, 0.0, 0.0, GridBagConstraints.CENTER,
+ GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
+
+ clientPane.add(mediaTypesScrollPane, new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0,
+ GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
+
+ clientPane.add(filter, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
+ GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 10, 0));
+
+ clientPane.add(filterEdit, new GridBagConstraints(3, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER,
+ GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
+
+ clientPane.add(mediaTableScrollPane, new GridBagConstraints(2, 1, 2, 2, 1.0, 1.0,
+ GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
+ clientPane.setOpaque(true);
+ clientPane.setBackground(Color.BLACK);
+ } finally {
+ mediaPool.getReadWriteLock().readLock().unlock();
+ }
+ return clientPane;
+ }
+
+
+ protected void loadImages() {
+ BufferedImage img = null;
+ ClassLoader cl = getClass().getClassLoader();
+ URL url;
+
+ images = 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(64, 64, Image.SCALE_SMOOTH));
+ } catch (Throwable t) {
+ System.err.println("failed to read image from " + iconFiles[i]);
+ t.printStackTrace();
+ }
+ }
+ }
+
+
+ protected void setHost(String hostname) {
+ curHostName = hostname;
+ }
+
+
+ protected void setPort(Integer port) {
+ curPort = port;
+ }
+
+ private IMediaPlayer player;
+ private MediaListLoader listLoader;
+ private EventList<Media> mediaPool;
+ private String myPanelName;
+ private int curPort;
+ private String curHostName;
+ private boolean active;
+ private ImageIcon[] images;
+ private static final String[] iconFiles;
+ static {
+ iconFiles = new String[] { "images/black_exit.png", "images/black_preferences.png" };
+ }
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaClientExecutor.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaClientExecutor.java
new file mode 100644
index 0000000..620c373
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaClientExecutor.java
@@ -0,0 +1,34 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaClientExecutor.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.util;
+
+
+import de.schwarzrot.cmpc.domain.Media;
+
+
+public interface MediaClientExecutor {
+ public void playMedia(Media m);
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaComparator.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaComparator.java
new file mode 100644
index 0000000..8e9ce48
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaComparator.java
@@ -0,0 +1,40 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaComparator.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.util;
+
+
+import java.util.Comparator;
+import de.schwarzrot.cmpc.domain.Media;
+
+
+public class MediaComparator implements Comparator<Media> {
+ @Override
+ public int compare(Media a, Media b) {
+ if (a.getType() == b.getType())
+ return a.getName().compareToIgnoreCase(b.getName());
+ return a.getType() - b.getType();
+ }
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaExecutor.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaExecutor.java
new file mode 100644
index 0000000..8cdea21
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaExecutor.java
@@ -0,0 +1,57 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaExecutor.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.util;
+
+
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import javax.swing.JTable;
+import ca.odell.glazedlists.EventList;
+import de.schwarzrot.cmpc.domain.Media;
+
+
+public class MediaExecutor extends MouseAdapter {
+ public MediaExecutor(JTable table, EventList<Media> list, MediaClientExecutor mce) {
+ this.table = table;
+ this.list = list;
+ executor = mce;
+ }
+
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() > 1) {
+ int i = table.rowAtPoint(e.getPoint());
+ Media m = list.get(i);
+
+ executor.playMedia(m);
+ }
+ }
+
+ private JTable table;
+ private EventList<Media> list;
+ private MediaClientExecutor executor;
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaForTypeMatcher.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaForTypeMatcher.java
new file mode 100644
index 0000000..c3a3469
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaForTypeMatcher.java
@@ -0,0 +1,54 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaForTypeMatcher.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.util;
+
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import ca.odell.glazedlists.matchers.Matcher;
+import de.schwarzrot.cmpc.domain.Media;
+
+
+public class MediaForTypeMatcher implements Matcher<Media> {
+ public MediaForTypeMatcher(Collection<Integer> mediaTypes) {
+ this.mediaTypes.addAll(mediaTypes);
+ }
+
+
+ @Override
+ public boolean matches(Media m) {
+ if (m == null)
+ return false;
+ if (mediaTypes.isEmpty())
+ return true;
+ Integer mt = m.getType();
+
+ return mediaTypes.contains(mt);
+ }
+
+ private Set<Integer> mediaTypes = new HashSet<Integer>();
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java
new file mode 100644
index 0000000..b37834c
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java
@@ -0,0 +1,124 @@
+/**
+ * ======================== 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
+ *
+ * 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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.util;
+
+
+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;
+import de.schwarzrot.cmpc.domain.PlayList;
+
+
+public class MediaListLoader implements Runnable {
+ public EventList<Media> getMediaPool() {
+ return mediaPool;
+ }
+
+
+ public void loadMedia(String hostname, int port) {
+ this.hostName = hostname;
+ this.port = port;
+
+ Thread backgroundThread = new Thread(this);
+
+ backgroundThread.setName("load media list from " + hostName);
+ backgroundThread.setDaemon(true);
+ backgroundThread.start();
+ }
+
+
+ @Override
+ public void run() {
+ URL request = null;
+ Date start, end;
+
+ try {
+ start = new Date();
+ request = new URL("http", hostName, port, "/?format=json");
+ URLConnection conn = request.openConnection();
+ final PlayList firstPlaylist = jsonOM.readValue(conn.getInputStream(), PlayList.class);
+
+ mediaPool.getReadWriteLock().writeLock().lock();
+ for (Media m : firstPlaylist.getResults()) {
+ mediaPool.add(m);
+ }
+ mediaPool.getReadWriteLock().writeLock().unlock();
+
+ end = new Date();
+ System.out.println("processing of first playlist-part took " + (end.getTime() - start.getTime()) + " ms.");
+ PlayList next;
+ long total = firstPlaylist.getTotal();
+ long n = firstPlaylist.getResults().size();
+ String uri;
+
+ start = new Date();
+ try {
+ while (n < total) {
+ 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);
+ mediaPool.getReadWriteLock().writeLock().lock();
+ for (Media m : next.getResults()) {
+ mediaPool.add(m);
+ }
+ mediaPool.getReadWriteLock().writeLock().unlock();
+ n += next.getResults().size();
+ Thread.sleep(10);
+ }
+ } catch (Throwable t) {
+ System.out.println("Oups, media list contains now #" + mediaPool.size() + " entries.");
+ t.printStackTrace();
+ } finally {
+ try {
+ mediaPool.getReadWriteLock().writeLock().unlock();
+ } catch (Throwable t) {
+ }
+ }
+ end = new Date();
+ System.out.println("processing of rest of playlist took " + (end.getTime() - start.getTime()) + " ms.");
+ } catch (ConnectException ce) {
+ System.out.println("media server " + hostName + " is not available ...");
+ } catch (Throwable t) {
+ t.printStackTrace();
+ } finally {
+ try {
+ mediaPool.getReadWriteLock().writeLock().unlock();
+ } catch (Throwable t) {
+ }
+ }
+ }
+
+ private String hostName;
+ private int port;
+ private ObjectMapper jsonOM = new ObjectMapper();
+ private EventList<Media> mediaPool = new BasicEventList<Media>();
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaPool2TypeList.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaPool2TypeList.java
new file mode 100644
index 0000000..ce541ac
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaPool2TypeList.java
@@ -0,0 +1,59 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaPool2TypeList.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.util;
+
+
+import ca.odell.glazedlists.EventList;
+import ca.odell.glazedlists.TransformedList;
+import ca.odell.glazedlists.event.ListEvent;
+import de.schwarzrot.cmpc.domain.Media;
+
+
+public class MediaPool2TypeList extends TransformedList<Media, Integer> {
+ public MediaPool2TypeList(EventList<Media> source) {
+ super(source);
+ source.addListEventListener(this);
+ }
+
+
+ @Override
+ public Integer get(int index) {
+ Media m = source.get(index);
+
+ return m.getType();
+ }
+
+
+ public void listChanged(ListEvent<Media> listChanges) {
+ updates.forwardEvent(listChanges);
+ }
+
+
+ @Override
+ protected boolean isWritable() {
+ return false;
+ }
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTableFormat.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTableFormat.java
new file mode 100644
index 0000000..7fa5452
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTableFormat.java
@@ -0,0 +1,64 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaTableFormat.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.util;
+
+
+import ca.odell.glazedlists.gui.TableFormat;
+import de.schwarzrot.cmpc.domain.Media;
+
+
+public class MediaTableFormat implements TableFormat<Media> {
+ @Override
+ public int getColumnCount() {
+ return 2;
+ }
+
+
+ @Override
+ public String getColumnName(int column) {
+ switch (column) {
+ case 0:
+ return "Type";
+ case 1:
+ return "Name";
+ default:
+ throw new IllegalStateException();
+ }
+ }
+
+
+ @Override
+ public Object getColumnValue(Media m, int column) {
+ switch (column) {
+ case 0:
+ return m.getType();
+ case 1:
+ return m.getName();
+ default:
+ throw new IllegalStateException();
+ }
+ }
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTextFilterator.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTextFilterator.java
new file mode 100644
index 0000000..e41c81f
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTextFilterator.java
@@ -0,0 +1,40 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaTextFilterator.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.util;
+
+
+import java.util.List;
+import ca.odell.glazedlists.TextFilterator;
+import de.schwarzrot.cmpc.domain.Media;
+
+
+public class MediaTextFilterator implements TextFilterator<Media> {
+ @Override
+ public void getFilterStrings(List<String> baseList, Media m) {
+ baseList.add(m.getName());
+ baseList.add(m.getSearch());
+ }
+}
diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java
new file mode 100644
index 0000000..9ba948e
--- /dev/null
+++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java
@@ -0,0 +1,146 @@
+/**
+ * ======================== legal notice ======================
+ *
+ * File: MediaTypeSelect.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.
+ *
+ * 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
+ *
+ * --------------------------------------------------------------
+ */
+package de.schwarzrot.cmpc.util;
+
+
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import java.net.URL;
+import javax.imageio.ImageIO;
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.ListCellRenderer;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+import ca.odell.glazedlists.EventList;
+import ca.odell.glazedlists.UniqueList;
+import ca.odell.glazedlists.matchers.AbstractMatcherEditor;
+import ca.odell.glazedlists.matchers.Matcher;
+import ca.odell.glazedlists.swing.DefaultEventListModel;
+import ca.odell.glazedlists.swing.DefaultEventSelectionModel;
+import de.schwarzrot.cmpc.domain.Media;
+
+
+public class MediaTypeSelect extends AbstractMatcherEditor<Media> implements ListSelectionListener {
+ public class MediaTypeCellRenderer extends JLabel implements ListCellRenderer {
+ private static final long serialVersionUID = 713L;
+
+
+ public MediaTypeCellRenderer() {
+ loadImages();
+ }
+
+
+ @Override
+ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
+ boolean cellHasFocus) {
+ if (isSelected) {
+ setBackground(list.getSelectionBackground());
+ setForeground(list.getSelectionForeground());
+ } else {
+ setBackground(list.getBackground());
+ setForeground(list.getForeground());
+ }
+ ImageIcon icon = images[(Integer) value];
+ setSize(110, 110);
+ setHorizontalAlignment(JLabel.CENTER);
+
+ if (icon != null) {
+ setIcon(icon);
+ setText("");
+ } else {
+ setText(value.toString());
+ }
+ return this;
+ }
+
+
+ protected void loadImages() {
+ BufferedImage img = null;
+ ClassLoader cl = getClass().getClassLoader();
+ URL url;
+
+ images = 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));
+ } catch (Throwable t) {
+ System.err.println("failed to read image from " + iconFiles[i]);
+ t.printStackTrace();
+ }
+ }
+ }
+
+ ImageIcon[] images;
+ }
+
+
+ public MediaTypeSelect(EventList<Media> source) {
+ EventList<Integer> mediaTypeNonUnique = new MediaPool2TypeList(source);
+
+ mediaTypeList = new UniqueList<Integer>(mediaTypeNonUnique);
+ DefaultEventListModel<Integer> mediaTypeListModel = new DefaultEventListModel<Integer>(mediaTypeList);
+
+ mediaTypeJList = new JList(mediaTypeListModel);
+ DefaultEventSelectionModel<Integer> mediaTypeSelectionModel = new DefaultEventSelectionModel<Integer>(
+ mediaTypeList);
+
+ mediaTypeJList.setSelectionModel(mediaTypeSelectionModel);
+ selectedTypes = mediaTypeSelectionModel.getSelected();
+ mediaTypeJList.addListSelectionListener(this);
+ mediaTypeJList.setCellRenderer(new MediaTypeCellRenderer());
+ mediaTypeJList.setBackground(Color.BLACK);
+ }
+
+
+ public JList getJList() {
+ return mediaTypeJList;
+ }
+
+
+ @Override
+ public void valueChanged(ListSelectionEvent e) {
+ Matcher<Media> newMatcher = new MediaForTypeMatcher(selectedTypes);
+
+ fireChanged(newMatcher);
+ }
+
+ private EventList<Integer> mediaTypeList;
+ private EventList<Integer> selectedTypes;
+ private JList mediaTypeJList;
+ private static final String[] iconFiles;
+ static {
+ iconFiles = new String[] { "images/folder_black.png", "images/folder_black_music.png",
+ "images/folder_black_movies.png", "images/folder_black_dvd.png", "images/folder_black_vdr_old.png",
+ "images/folder_black_vdr.png", "images/folder_black_photos.png", "images/folder_black.png" };
+ }
+}