diff options
author | geronimo <geronimo013@gmx.de> | 2012-08-15 07:55:07 +0200 |
---|---|---|
committer | geronimo <geronimo013@gmx.de> | 2012-08-15 07:55:07 +0200 |
commit | af80bd2426282b7491d9ba0ebfb201abb42e3ca4 (patch) | |
tree | 8aeac09a815f3133773cb927597738d4150030f1 /cmpcj/src/de/schwarzrot/base | |
parent | 7eb41fd1431019f44227af6f5d707e7c98e0416e (diff) | |
download | cmp-af80bd2426282b7491d9ba0ebfb201abb42e3ca4.tar.gz cmp-af80bd2426282b7491d9ba0ebfb201abb42e3ca4.tar.bz2 |
next variant of java client
Diffstat (limited to 'cmpcj/src/de/schwarzrot/base')
9 files changed, 648 insertions, 0 deletions
diff --git a/cmpcj/src/de/schwarzrot/base/dock/BasicDockable.java b/cmpcj/src/de/schwarzrot/base/dock/BasicDockable.java new file mode 100644 index 0000000..534ca2b --- /dev/null +++ b/cmpcj/src/de/schwarzrot/base/dock/BasicDockable.java @@ -0,0 +1,75 @@ +/** + * ======================== legal notice ====================== + * + * File: BasicDockable.java + * Created: 13. June 2012, 04:57 + * 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.base.dock; + + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JComponent; +import javax.swing.JMenuItem; +import bibliothek.gui.dock.common.DefaultSingleCDockable; + + +public class BasicDockable extends DefaultSingleCDockable { + public BasicDockable(String id, String title, JComponent content) { + super(id, title, content); + } + + + public JMenuItem createMenuItem() { + final JCheckBoxMenuItem item = new JCheckBoxMenuItem(getTitleText(), getTitleIcon()); + + item.setSelected(isVisible()); + item.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (item.isSelected()) + doShow(); + else + doClose(); + } + }); + return item; + } + + + public void doClose() { + setVisible(false); + } + + + public void doShow() { + setVisible(true); + } + + + public JComponent getContent() { + return content; + } + + private JComponent content; +} diff --git a/cmpcj/src/de/schwarzrot/base/table/PropertyTableFormat.java b/cmpcj/src/de/schwarzrot/base/table/PropertyTableFormat.java new file mode 100644 index 0000000..fd62769 --- /dev/null +++ b/cmpcj/src/de/schwarzrot/base/table/PropertyTableFormat.java @@ -0,0 +1,86 @@ +/** + * ======================== legal notice ====================== + * + * File: PropertyTableFormat.java + * Created: 13. June 2012, 04:57 + * 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.base.table; + + +import java.util.Map; +import java.util.Map.Entry; +import ca.odell.glazedlists.gui.TableFormat; +import de.schwarzrot.base.util.ApplicationServiceProvider; +import de.schwarzrot.base.util.MessageBundle; +import de.schwarzrot.control.app.CMPMessageBundle; + + +public class PropertyTableFormat implements TableFormat<Map.Entry<String, Object>> { + private static MessageBundle bundle; + + + @Override + public int getColumnCount() { + return 2; + } + + + @Override + public String getColumnName(int column) { + if (bundle == null) + bundle = ApplicationServiceProvider.getService(MessageBundle.class); + + switch (column) { + case 0: + return bundle.getMessage(CMPMessageBundle.PTF_0); + case 1: + return bundle.getMessage(CMPMessageBundle.PTF_1); + default: + throw new IndexOutOfBoundsException(); + } + } + + + @Override + public Object getColumnValue(Entry<String, Object> e, int column) { + switch (column) { + case 0: + return e.getKey(); + case 1: + return e.getValue(); + default: + throw new IndexOutOfBoundsException(); + } + } + + + public int getColumnWidth(int column) { + switch (column) { + case 0: + return 100; + case 1: + return -1; + default: + throw new IndexOutOfBoundsException(); + } + } +} diff --git a/cmpcj/src/de/schwarzrot/base/util/AbstractDialog.java b/cmpcj/src/de/schwarzrot/base/util/AbstractDialog.java new file mode 100644 index 0000000..80fed51 --- /dev/null +++ b/cmpcj/src/de/schwarzrot/base/util/AbstractDialog.java @@ -0,0 +1,174 @@ +/** + * ======================== legal notice ====================== + * + * File: AbstractDialog.java + * Created: 13. June 2012, 04:57 + * 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.base.util; + + +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JDialog; +import javax.swing.JPanel; + + +public abstract class AbstractDialog extends JDialog { + public static final int RESET_OPTION = -1; + public static final int CLOSE_OPTION = 0; + public static final int CANCEL_OPTION = 1; + public static final int APPROVE_OPTION = 2; + private static final long serialVersionUID = 713L; + public enum DialogMode { + CLOSE, CANCEL, CANCEL_APPROVE, RESET_CANCEL_APPROVE + } + public enum Orientation { + Left, Center, Right + }; + + + protected AbstractDialog(Window parent, boolean modal, DialogMode dialogMode, Orientation buttonOrientation) { + super(parent, "dummy", modal ? JDialog.ModalityType.APPLICATION_MODAL : JDialog.ModalityType.MODELESS); + msgBundle = ApplicationServiceProvider.getService(MessageBundle.class); + setTitle(msgBundle.getMessage(getClass().getSimpleName() + ".title")); + this.dialogMode = dialogMode; + this.buttonOrientation = buttonOrientation; + msgBundle = ApplicationServiceProvider.getService(MessageBundle.class); + } + + + public JComponent createButtons() { + JPanel rv = new JPanel(); + JButton button = null; + + switch (buttonOrientation) { + case Left: + rv.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 5)); + break; + + case Right: + rv.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 5)); + break; + + default: + rv.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 5)); + break; + } + + switch (dialogMode) { + case RESET_CANCEL_APPROVE: + button = createButton(".Reset"); + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + result = RESET_OPTION; + performReset(); + setVisible(false); + } + }); + rv.add(button); + case CANCEL_APPROVE: + button = createButton(".Approve"); + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + result = APPROVE_OPTION; + performApprove(); + setVisible(false); + } + }); + rv.add(button); + case CANCEL: + button = createButton(".Cancel"); + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + result = CANCEL_OPTION; + performCancel(); + setVisible(false); + } + }); + rv.add(button); + break; + default: + button = createButton(".Close"); + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent ae) { + result = CLOSE_OPTION; + performClose(); + setVisible(false); + } + }); + rv.add(button); + } + return rv; + } + + + public abstract JComponent createContentPane(); + + + public int showDialog(Window parent) { + getContentPane().add(createContentPane(), BorderLayout.CENTER); + getContentPane().add(createButtons(), BorderLayout.SOUTH); + pack(); + setLocationRelativeTo(parent); + setVisible(true); + dispose(); + + return result; + } + + + protected JButton createButton(String buttonID) { + JButton button = new JButton(msgBundle.getMessage(getClass().getSimpleName() + buttonID)); + + return button; + } + + + protected void performApprove() { + } + + + protected void performCancel() { + } + + + protected void performClose() { + } + + + protected void performReset() { + } + + protected MessageBundle msgBundle; + private int result = CLOSE_OPTION; + private DialogMode dialogMode; + private Orientation buttonOrientation; +} diff --git a/cmpcj/src/de/schwarzrot/base/util/ActionManager.java b/cmpcj/src/de/schwarzrot/base/util/ActionManager.java new file mode 100644 index 0000000..35ea31d --- /dev/null +++ b/cmpcj/src/de/schwarzrot/base/util/ActionManager.java @@ -0,0 +1,61 @@ +/** + * ======================== legal notice ====================== + * + * File: ActionManager.java + * Created: 13. June 2012, 04:57 + * 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.base.util; + + +import java.util.HashMap; +import java.util.Map; +import javax.swing.Action; +import javax.swing.JMenuItem; + + +public class ActionManager<E extends Enum<E>> { + public ActionManager() { + knownCallbacks = new HashMap<Enum<E>, CallbackDefinition<E>>(); + } + + + public void addCallbackDefinition(CallbackDefinition<E> callbackDefinition) { + knownCallbacks.put(callbackDefinition.getCallbackKey(), callbackDefinition); + } + + + public JMenuItem createMenuItem(Enum<E> cmd) { + return null; + } + + + public Action getAction(Enum<E> cmd) { + Action rv = null; + + if (knownCallbacks.containsKey(cmd)) + rv = knownCallbacks.get(cmd); + + return rv; + } + + private Map<Enum<E>, CallbackDefinition<E>> knownCallbacks; +} diff --git a/cmpcj/src/de/schwarzrot/base/util/ApplicationServiceProvider.java b/cmpcj/src/de/schwarzrot/base/util/ApplicationServiceProvider.java new file mode 100644 index 0000000..04aee17 --- /dev/null +++ b/cmpcj/src/de/schwarzrot/base/util/ApplicationServiceProvider.java @@ -0,0 +1,51 @@ +/** + * ======================== legal notice ====================== + * + * File: ApplicationServiceProvider.java + * Created: 13. June 2012, 04:57 + * 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.base.util; + + +import java.util.HashMap; +import java.util.Map; + + +public class ApplicationServiceProvider { + private static Map<Class<?>, Object> knownServices = new HashMap<Class<?>, Object>(); + + + @SuppressWarnings("unchecked") + public static <S extends Object> S getService(Class<S> clazz) { + return (S) knownServices.get(clazz); + } + + + public static <S extends Object> boolean hasService(Class<S> clazz) { + return knownServices.containsKey(clazz); + } + + + public static <S extends Object> void registerService(Class<S> clazz, S service) { + knownServices.put(clazz, service); + } +} diff --git a/cmpcj/src/de/schwarzrot/base/util/CallbackDefinition.java b/cmpcj/src/de/schwarzrot/base/util/CallbackDefinition.java new file mode 100644 index 0000000..92aa930 --- /dev/null +++ b/cmpcj/src/de/schwarzrot/base/util/CallbackDefinition.java @@ -0,0 +1,62 @@ +/** + * ======================== legal notice ====================== + * + * File: CallbackDefinition.java + * Created: 13. June 2012, 04:57 + * 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.base.util; + + +import javax.swing.AbstractAction; + + +public abstract class CallbackDefinition<E extends Enum<E>> extends AbstractAction { + private static final long serialVersionUID = 713L; + private static final String IDENTIFIER = "CBIdentifier"; + + + public CallbackDefinition(E key) { + this(key, true); + } + + + public CallbackDefinition(E key, boolean enabled) { + MessageBundle mb = ApplicationServiceProvider.getService(MessageBundle.class); + String actionKey = key.getClass().getSimpleName() + "." + key.name(); + + putValue(IDENTIFIER, key); + putValue(ACTION_COMMAND_KEY, actionKey); + putValue(NAME, mb.getMessage(actionKey)); + putValue(LARGE_ICON_KEY, null); + putValue(SMALL_ICON, null); + putValue(SHORT_DESCRIPTION, mb.getMessage(actionKey + ".short.desc")); + putValue(LONG_DESCRIPTION, mb.getMessage(actionKey + ".long.desc")); + putValue(ACCELERATOR_KEY, null); + setEnabled(enabled); + } + + + @SuppressWarnings("unchecked") + public E getCallbackKey() { + return (E) getValue(IDENTIFIER); + } +} diff --git a/cmpcj/src/de/schwarzrot/base/util/ImageFactory.java b/cmpcj/src/de/schwarzrot/base/util/ImageFactory.java new file mode 100644 index 0000000..612f4cb --- /dev/null +++ b/cmpcj/src/de/schwarzrot/base/util/ImageFactory.java @@ -0,0 +1,74 @@ +/** + * ======================== legal notice ====================== + * + * File: ImageFactory.java + * Created: 13. June 2012, 04:57 + * 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.base.util; + + +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.ResourceBundle; +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; + + +public class ImageFactory { + public ImageIcon getIcon(String key) { + return getIcon(key, 16, 16); + } + + + public ImageIcon getIcon(String key, int width, int height) { + if (!iconPool.containsKey(key)) + iconPool.put(key, new ImageIcon(getImage(key, width, height))); + + return iconPool.get(key); + } + + + public Image getImage(String key, int width, int height) { + ClassLoader cl = getClass().getClassLoader(); + BufferedImage img = null; + URL url; + + try { + String imgPath = RESOURCE_BUNDLE.getString(key); + url = cl.getResource(imgPath); + img = ImageIO.read(url); + + return img.getScaledInstance(width, height, Image.SCALE_SMOOTH); + } catch (Throwable t) { + System.err.println("failed to read key: " + key); + t.printStackTrace(); + } + return null; + } + + private Map<String, ImageIcon> iconPool = new HashMap<String, ImageIcon>(); + private final String BUNDLE_NAME = "de.schwarzrot.control.app.lang.images"; + private final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); +} diff --git a/cmpcj/src/de/schwarzrot/base/util/MessageBundle.java b/cmpcj/src/de/schwarzrot/base/util/MessageBundle.java new file mode 100644 index 0000000..4442efa --- /dev/null +++ b/cmpcj/src/de/schwarzrot/base/util/MessageBundle.java @@ -0,0 +1,31 @@ +/** + * ======================== legal notice ====================== + * + * File: MessageBundle.java + * Created: 13. June 2012, 04:57 + * 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.base.util; + + +public interface MessageBundle { + public String getMessage(String key); +} diff --git a/cmpcj/src/de/schwarzrot/base/util/SuccessHandler.java b/cmpcj/src/de/schwarzrot/base/util/SuccessHandler.java new file mode 100644 index 0000000..9f0af4b --- /dev/null +++ b/cmpcj/src/de/schwarzrot/base/util/SuccessHandler.java @@ -0,0 +1,34 @@ +/** + * ======================== legal notice ====================== + * + * File: SuccessHandler.java + * Created: 13. June 2012, 04:57 + * 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.base.util; + + +public interface SuccessHandler { + public void handleFailure(Throwable t); + + + public void handleSuccess(); +} |