1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
/**
* Orthanc - A Lightweight, RESTful DICOM Store
* Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
* Department, University Hospital of Liege, Belgium
* Copyright (C) 2017-2018 Osimis S.A., Belgium
*
* 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/>.
**/
package com.orthancserver;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.SwingWorker;
import javax.swing.border.EmptyBorder;
import org.json.simple.JSONObject;
public class OrthancConfigurationDialog extends JDialog
{
private JTextField name_ = new JTextField("Orthanc");
private JTextField url_ = new JTextField("http://localhost:8042/");
private JTextField username_ = new JTextField("");
private JTextField password_ = new JPasswordField("");
private boolean isSuccess_;
private OrthancConnection CreateConnection()
{
OrthancConnection orthanc = new OrthancConnection();
orthanc.SetInsecure(true); // Fix issue 9 (cannot connect to self-signed certificates)
orthanc.SetName(name_.getText());
orthanc.SetBaseUrl(url_.getText());
if (username_.getText().length() != 0)
{
orthanc.SetCredentials(username_.getText(), password_.getText());
}
return orthanc;
}
public OrthancConfigurationDialog()
{
final JPanel contentPanel = new JPanel();
contentPanel.setBorder(new EmptyBorder(20, 5, 5, 5));
contentPanel.setLayout(new GridLayout2(0, 2, 20, 5));
JLabel label = new JLabel("Name:");
label.setHorizontalAlignment(JLabel.RIGHT);
contentPanel.add(label);
contentPanel.add(name_);
label = new JLabel("URL:");
label.setHorizontalAlignment(JLabel.RIGHT);
contentPanel.add(label);
contentPanel.add(url_);
label = new JLabel("Username:");
label.setHorizontalAlignment(JLabel.RIGHT);
contentPanel.add(label);
contentPanel.add(username_);
label = new JLabel("Password:");
label.setHorizontalAlignment(JLabel.RIGHT);
contentPanel.add(label);
contentPanel.add(password_);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(contentPanel, BorderLayout.NORTH);
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
{
JButton test = new JButton("Test connection");
test.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg) {
OrthancConnection orthanc = CreateConnection();
try
{
JSONObject system = (JSONObject) orthanc.ReadJson("system");
JOptionPane.showMessageDialog(null, "Successfully connected to this Orthanc server " +
"(version: " + (String) system.get("Version") + ")!",
"Success", JOptionPane.INFORMATION_MESSAGE);
}
catch (IOException e)
{
JOptionPane.showMessageDialog(null, "Cannot connect to this Orthanc server!",
"Error", JOptionPane.ERROR_MESSAGE);
}
}
});
buttonPane.add(test);
}
{
JButton okButton = new JButton("Add");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg) {
isSuccess_ = true;
setVisible(false);
}
});
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg) {
setVisible(false);
}
});
buttonPane.add(cancelButton);
}
}
setUndecorated(false);
setSize(500,500);
setTitle("Add new server");
setModal(true);
}
public OrthancConnection ShowModal()
{
isSuccess_ = false;
setVisible(true);
if (isSuccess_)
{
return CreateConnection();
}
else
{
return null;
}
}
}
|