/*
* PS3 Media Server, for streaming any medias to your PS3.
* Copyright (C) 2008 A.Brochard
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2
* of the License only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package net.pms.encoders;
import com.jgoodies.forms.builder.PanelBuilder;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import net.pms.Messages;
import net.pms.PMS;
import net.pms.configuration.PmsConfiguration;
import net.pms.dlna.DLNAResource;
import net.pms.formats.Format;
import net.pms.util.PlayerUtil;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.StringTokenizer;
public class MEncoderAviSynth extends MEncoderVideo {
public MEncoderAviSynth(PmsConfiguration configuration) {
super(configuration);
}
private JTextArea textArea;
private JCheckBox convertfps;
@Override
public JComponent config() {
FormLayout layout = new FormLayout(
"left:pref, 0:grow",
"p, 3dlu, p, 3dlu, p, 3dlu, 0:grow");
PanelBuilder builder = new PanelBuilder(layout);
CellConstraints cc = new CellConstraints();
JComponent cmp = builder.addSeparator(Messages.getString("MEncoderAviSynth.2"), cc.xyw(2, 1, 1));
cmp = (JComponent) cmp.getComponent(0);
cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
convertfps = new JCheckBox(Messages.getString("MEncoderAviSynth.3"));
convertfps.setContentAreaFilled(false);
if (PMS.getConfiguration().getAvisynthConvertFps()) {
convertfps.setSelected(true);
}
convertfps.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
PMS.getConfiguration().setAvisynthConvertFps((e.getStateChange() == ItemEvent.SELECTED));
}
});
builder.add(convertfps, cc.xy(2, 3));
String clip = PMS.getConfiguration().getAvisynthScript();
if (clip == null) {
clip = "";
}
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(clip, PMS.AVS_SEPARATOR);
int i = 0;
while (st.hasMoreTokens()) {
if (i > 0) {
sb.append("\n");
}
sb.append(st.nextToken());
i++;
}
textArea = new JTextArea(sb.toString());
textArea.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
StringBuilder sb = new StringBuilder();
StringTokenizer st = new StringTokenizer(textArea.getText(), "\n");
int i = 0;
while (st.hasMoreTokens()) {
if (i > 0) {
sb.append(PMS.AVS_SEPARATOR);
}
sb.append(st.nextToken());
i++;
}
PMS.getConfiguration().setAvisynthScript(sb.toString());
}
});
JScrollPane pane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
pane.setPreferredSize(new Dimension(500, 350));
builder.add(pane, cc.xy(2, 5));
return builder.getPanel();
}
@Override
public PlayerPurpose getPurpose() {
return PlayerPurpose.VIDEO_FILE_PLAYER;
}
public static final String ID = "avsmencoder";
@Override
public String id() {
return ID;
}
@Override
public boolean avisynth() {
return true;
}
@Override
public String name() {
return "AviSynth/MEncoder";
}
/**
* {@inheritDoc}
*/
@Override
public boolean isCompatible(DLNAResource resource) {
return PlayerUtil.isVideo(resource, Format.Identifier.MKV)
|| PlayerUtil.isVideo(resource, Format.Identifier.MPG);
}
}