/*
* Multiconvert
* Multiconvert is a lightweight and plattform independent Video conversion tool
* based on ffmpeg and written in Java.
*
* Copyright (C) 2010 Sebastian Weidenbach
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* 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, see <http://www.gnu.org/licenses/>.
*
* ----------------------------------------------------------------------------------
* Historie:
* 2010−03−13 Erste Fassung <sebastianwe@users.sourceforge.net>
*/
package gui;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTextField;
import util.Constants;
import util.SwingUtils;
import language.Language;
/**
* InternetVideo objects represent a JFrame where the user can choose
* an internet video file
*
* @author sebastianwe
*/
public class InternetVideo extends JDialog
{
private static final long serialVersionUID = -4332482661191128777L;
/*
* InternetVideo objects save the uri and the type of an internet video
*/
private String uri;
private int type = 0;
/**
* creates a new InternetVideo object
*
* @param caller
* caller of the method
* @param lang
* Language
*/
public InternetVideo(final FFMpegGui caller, final Language lang)
{
super(caller, lang.inet, true);
final InternetVideo self = this;
JLabel webType = new JLabel(lang.webtype);
webType.setSize(125, 20);
webType.setLocation(5, 5);
webType.setFont(webType.getFont().deriveFont(Font.BOLD));
JLabel uri = new JLabel(lang.uri);
uri.setSize(125, 20);
uri.setLocation(5, 30);
uri.setFont(uri.getFont().deriveFont(Font.BOLD));
JButton ok = new JButton(lang.ok);
ok.setSize(125, 20);
ok.setLocation(5, 55);
final JComboBox webTypes = new JComboBox(new String[] { "YouTube" });
webTypes.setSize(275, 20);
webTypes.setLocation(140, 5);
final JTextField urifield = new JTextField("http://");
urifield.setSize(275, 20);
urifield.setLocation(140, 30);
final JPopupMenu context = new JPopupMenu();
JMenuItem paste = new JMenuItem(lang.insert);
context.add(paste);
paste.addMouseListener(new MouseListener()
{
@Override
public void mouseClicked(MouseEvent e)
{
}
@Override
public void mousePressed(MouseEvent e)
{
}
@Override
public void mouseExited(MouseEvent e)
{
}
@Override
public void mouseEntered(MouseEvent e)
{
}
@Override
public void mouseReleased(MouseEvent e)
{
Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferData = systemClipboard.getContents(null);
DataFlavor[] dataFlavor = transferData.getTransferDataFlavors();
String s = null;
for(int i = 0; i < dataFlavor.length; i++)
{
try
{
s = (String) transferData.getTransferData(dataFlavor[i]);
if(s != null)
break;
}
catch (Exception exc)
{
if(Constants.debug)
exc.printStackTrace();
}
}
if(s != null)
urifield.setText(s);
}
});
urifield.addMouseListener(new MouseListener()
{
@Override
public void mouseReleased(MouseEvent e)
{
if (e.isPopupTrigger())
context.show(urifield, e.getX(), e.getY());
}
@Override
public void mousePressed(MouseEvent e)
{
if (e.isPopupTrigger())
context.show(urifield, e.getX(), e.getY());
}
@Override
public void mouseExited(MouseEvent e)
{
}
@Override
public void mouseEntered(MouseEvent e)
{
}
@Override
public void mouseClicked(MouseEvent e)
{
}
});
JButton cancel = new JButton(lang.cancel);
cancel.setSize(125, 20);
cancel.setLocation(140, 55);
cancel.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
dispose();
}
});
ok.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
self.uri = urifield.getText();
self.type = webTypes.getSelectedIndex();
dispose();
}
});
add(webType);
add(uri);
add(webTypes);
add(urifield);
add(ok);
add(cancel);
setLayout(null);
setResizable(false);
setSize(440,110);
setLocation(SwingUtils.getCenterPositon(getSize()));
setVisible(true);
}
/**
* Returns the video URI
*
* @return
* website uri
*/
public String getURI()
{
return uri;
}
/**
* Returns the website type
*
* @return
* uri website type
*/
public int getType()
{
return type;
}
}