The plugin requires four methods/functions to be implemented:
- name, used in the plugin list
- config, returning a JComponent object that shows any configuration options onscreen. This is being called when the plugin list button is pressed.
- shutdown, in case you need to clean up something, e.g. file or network handlers
- getChild, returning a VirtualFolder item
The only specific item is the getChild function. For this function, you need to create a DLNAResource item. Typical DLNAResource are virtual folders (VirtualFolders) or playback items.
Following text is a short version of the code I created for the Shutdown plugin. It instantiates the VirtualVideoAction. When the user selects this item, PMS will issue the shutdown command to Windows (I had to make this short!). Instead of creating the folder structure whenever getChild() is called, I decided to create the folder when PMS starts and an instance of this class is created.
- Code: Select all
package net.pms.external;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.io.IOException;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import com.sun.jna.Platform;
import net.pms.PMS;
import net.pms.dlna.DLNAResource;
import net.pms.dlna.virtual.VirtualFolder;
import net.pms.dlna.virtual.VirtualVideoAction;
/**Implements the Shutdown command for PS3MediaServer
* @author chacaman
* @version 0.1
*
*/
public class ShutdownPlugin implements AdditionalFolderAtRoot{
private VirtualFolder shutdownfolder;
public ShutdownPlugin(){
PMS.minimal("Shutdown Plugin - Creating ROOT");
shutdownfolder = new VirtualFolder("Shutdown..., null); //$NON-NLS-1$
if (Platform.isWindows()){
PMS.minimal("Shutdown Plugin - Found Windows machine");
shutdownfolder.addChild(new VirtualVideoAction("Power off", true) { //$NON-NLS-1$
public boolean enable() {
Runtime runtime = Runtime.getRuntime();
try {
Process process = runtime.exec("ShutDown /s /f");
} catch (IOException e) {}
return true;
}
});
PMS.minimal("Shutdown Plugin - Created POWEROFF node");
}
@Override
public DLNAResource getChild() {
return shutdownfolder;
}
@Override
public JComponent config() {
JPanel SDPanel = new JPanel(new GridBagLayout()); // Use GridBagLayout because it is flexible
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.LINE_START;
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 2;
SDPanel.add(new JLabel("This plugin creates a Shutdown node at root level. Nothing to see here."),c);
return SDPanel;
}
@Override
public String name() {
return "Shutdown plugin";
}
@Override
public void shutdown() {
// Nothing to do here
}
}
The complete code can be found under this topic.
