package org.openslx.dozmod.gui.window; import java.awt.Frame; import java.awt.GridBagConstraints; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.net.URISyntaxException; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import org.apache.log4j.Logger; import org.openslx.dozmod.Branding; import org.openslx.dozmod.authentication.ShibbolethEcp; import org.openslx.dozmod.gui.Gui; import org.openslx.dozmod.gui.helper.GridManager; import org.openslx.dozmod.gui.helper.UiFeedback; import org.openslx.dozmod.util.DesktopEnvironment; /** * Class for showing window with button to open registration page in browser. */ @SuppressWarnings("serial") public class BwIdmLinkWindow extends JDialog implements UiFeedback { private static final String title = "Registrierung erforderlich"; private static final String infoText = "" + "Sie sind nicht bei " + Branding.getServiceName() + " registriert. " + "Bitte rufen Sie die angegebene Seite auf um sich zu registrieren und versuchen Sie es erneut." + ""; protected JButton btnLink; protected JButton OkButton; private static final Logger LOGGER = Logger.getLogger(BwIdmLinkWindow.class); /** * Don't use this, use static function open instead! */ public BwIdmLinkWindow(Frame modalParent) { super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS); final BwIdmLinkWindow me = this; setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // panel for the border. JPanel contentPanel = new JPanel(); contentPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(contentPanel); GridManager grid = new GridManager(contentPanel, 1); // infotext JLabel infoLabel = new JLabel(infoText); infoLabel.setBorder(BorderFactory.createTitledBorder("Hinweis")); grid.add(infoLabel).fill(true, true).expand(true, true).anchor(GridBagConstraints.CENTER); grid.nextRow(); // button for opening the link btnLink = new JButton("Seite im Browser öffnen"); btnLink.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { DesktopEnvironment.openWebpageUri(ShibbolethEcp.getRegistrationUrl().toURI()); } catch (URISyntaxException e1) { LOGGER.error("Could not convert from url to uri: ", e1); } } }); grid.add(btnLink).anchor(GridBagConstraints.CENTER).fill(false, false).expand(false, false); grid.nextRow(); // text area for copying the link if needed. JTextArea linkText = new JTextArea(ShibbolethEcp.getRegistrationUrl().toString()); linkText.setEditable(false); linkText.setMaximumSize(linkText.getPreferredSize()); linkText.setMinimumSize(linkText.getPreferredSize()); grid.add(linkText).anchor(GridBagConstraints.CENTER).fill(false, false).expand(false, false); grid.nextRow(); // Ok button on the bottom JPanel bottomPane = new JPanel(); bottomPane.setLayout(new BoxLayout(bottomPane, BoxLayout.LINE_AXIS)); bottomPane.add(Box.createHorizontalGlue()); // close/ok button OkButton = new JButton("Schließen"); OkButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { me.dispose(); } }); bottomPane.add(OkButton); grid.add(bottomPane).fill(true, false).expand(true, false); grid.nextRow(); grid.finish(false); // Scale window with font setMinimumSize(Gui.getScaledDimension(500, 200)); setPreferredSize(getMinimumSize()); setLocationRelativeTo(modalParent); } /** * Open a new window for showing the registration page in browser. * * @param modalParent the parent of the window. */ public static void open(Frame modalParent) { new BwIdmLinkWindow(modalParent).setVisible(true); } @Override public boolean wantConfirmQuit() { return false; } @Override public void escapePressed() { dispose(); } }