diff options
| author | geronimo <geronimo013@gmx.de> | 2012-07-26 16:32:37 +0200 |
|---|---|---|
| committer | geronimo <geronimo013@gmx.de> | 2012-07-26 16:32:37 +0200 |
| commit | 55a02203e1d5fcdf8cbc0093af5c14d41d6d8dd7 (patch) | |
| tree | 564507b5f40bcd65d7b6cb2d5041202c8250927f /cmpcj/src/de/schwarzrot/cmpc/util | |
| parent | 2d0b837e6c885383ae807ca793cbe91aa32de995 (diff) | |
| download | cmp-55a02203e1d5fcdf8cbc0093af5c14d41d6d8dd7.tar.gz cmp-55a02203e1d5fcdf8cbc0093af5c14d41d6d8dd7.tar.bz2 | |
worked out little java client that serves to start other mediaplayers
Diffstat (limited to 'cmpcj/src/de/schwarzrot/cmpc/util')
9 files changed, 618 insertions, 0 deletions
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" }; + } +} |
