/* License see bottom*/
package jpianotrain.util;
import static jpianotrain.util.ResourceKeys.BUTTON_OK;
import static jpianotrain.util.ResourceKeys.MESSAGE_OPEN_URL;
import static jpianotrain.util.ResourceKeys.TITLE_URL_DIALOG;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import jpianotrain.ApplicationContext;
/**
* Handles external URLs. Some HTML-displaying
* components may come accross external links
* and should not open'em themselves.
*
* @author methke01
* @since 0.0.2
*/
public class ExternalURLHandler {
public static void handle(URL u) {
ApplicationContext ctx=ApplicationContext.getInstance();
if (urlDialog==null) {
urlDialog=new URLDialog(ctx.getDefaultDialogOwner());
}
urlDialog.setUrl(u);
urlDialog.setVisible(true);
}
private static class URLDialog extends JDialog
implements ActionListener {
public URLDialog(JFrame owner) {
super(owner, ResourceFactory.getString(TITLE_URL_DIALOG), true);
setPreferredSize(new Dimension(400, 110));
createUI();
}
private void createUI() {
setLayout(new GridBagLayout());
GridBagConstraints gbc=new GridBagConstraints();
gbc.gridx=0;
gbc.gridy=0;
gbc.fill=GridBagConstraints.HORIZONTAL;
gbc.insets=new Insets(2,2,2,2);
gbc.anchor=GridBagConstraints.WEST;
add(new JLabel(ResourceFactory.getString(MESSAGE_OPEN_URL)), gbc);
gbc.gridy++;
gbc.fill=GridBagConstraints.HORIZONTAL;
urlField=new JTextField();
urlField.setEditable(false);
add(urlField, gbc);
okButton=new JButton(ResourceFactory.getString(BUTTON_OK));
okButton.addActionListener(this);
gbc.fill=GridBagConstraints.NONE;
gbc.gridy++;
gbc.anchor=GridBagConstraints.CENTER;
add(okButton,gbc);
pack();
}
public void setUrl(URL u) {
urlField.setText(u.toString());
}
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
private JButton okButton;
private JTextField urlField;
}
private static URLDialog urlDialog;
}
/*
Copyright (C) 2008 Alexander Methke
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 (gplv3.txt).
*/