in modules/jdktools/src/main/java/org/apache/harmony/tools/appletviewer/AppletFrame.java [167:426]
private void showSetPropDialog(final JFrame frame){
final JDialog dialog = new JDialog(frame, "Harmony AppletViewer Properties");
// Sheet part of Dialog
JLabel httpHost = new JLabel(Main.httpProxyHost);
httpHost.setFont(httpHost.getFont().deriveFont(Font.PLAIN));
JLabel httpPort = new JLabel(Main.httpProxyPort);
httpPort.setFont(httpPort.getFont().deriveFont(Font.PLAIN));
JLabel httpsHost = new JLabel(Main.httpsProxyHost);
httpsHost.setFont(httpsHost.getFont().deriveFont(Font.PLAIN));
JLabel httpsPort = new JLabel(Main.httpsProxyPort);
httpsPort.setFont(httpsPort.getFont().deriveFont(Font.PLAIN));
JLabel ftpHost = new JLabel(Main.ftpProxyHost);
ftpHost.setFont(ftpHost.getFont().deriveFont(Font.PLAIN));
JLabel ftpPort = new JLabel(Main.ftpProxyPort);
ftpPort.setFont(ftpPort.getFont().deriveFont(Font.PLAIN));
final JTextField tfHttpHost = new JTextField(Main.properties.getProperty(Main.httpProxyHost));
Dimension d = tfHttpHost.getPreferredSize();
tfHttpHost.setPreferredSize(new Dimension(50, d.height));
final JTextField tfHttpPort = new JTextField(Main.properties.getProperty(Main.httpProxyPort));
tfHttpPort.setPreferredSize(new Dimension(50, d.height));
final JTextField tfHttpsHost = new JTextField(Main.properties.getProperty(Main.httpsProxyHost));
tfHttpsHost.setPreferredSize(new Dimension(50, d.height));
final JTextField tfHttpsPort = new JTextField(Main.properties.getProperty(Main.httpsProxyPort));
tfHttpsPort.setPreferredSize(new Dimension(50, d.height));
final JTextField tfFtpHost = new JTextField(Main.properties.getProperty(Main.ftpProxyHost));
tfFtpHost.setPreferredSize(new Dimension(50, d.height));
final JTextField tfFtpPort = new JTextField(Main.properties.getProperty(Main.ftpProxyPort));
tfFtpPort.setPreferredSize(new Dimension(50, d.height));
JPanel sheetPanel = new JPanel();
sheetPanel.setLayout(new GridLayout(6,2));
sheetPanel.add(httpHost);
sheetPanel.add(tfHttpHost);
sheetPanel.add(httpPort);
sheetPanel.add(tfHttpPort);
sheetPanel.add(httpsHost);
sheetPanel.add(tfHttpsHost);
sheetPanel.add(httpsPort);
sheetPanel.add(tfHttpsPort);
sheetPanel.add(ftpHost);
sheetPanel.add(tfFtpHost);
sheetPanel.add(ftpPort);
sheetPanel.add(tfFtpPort);
sheetPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
final boolean useSameServer;
final JCheckBox sameServer = new JCheckBox("Use same proxy server for all protocols");
if(Main.properties.getProperty(Main.httpProxyHost).equals(
Main.properties.getProperty(Main.httpsProxyHost)) &&
Main.properties.getProperty(Main.httpProxyHost).equals(
Main.properties.getProperty(Main.ftpProxyHost)) &&
Main.properties.getProperty(Main.httpProxyPort).equals(
Main.properties.getProperty(Main.httpsProxyPort)) &&
Main.properties.getProperty(Main.httpProxyPort).equals(
Main.properties.getProperty(Main.ftpProxyPort))) {
sameServer.setSelected(true);
tfHttpsHost.setText("");
tfHttpsHost.setEditable(false);
tfHttpsPort.setText("");
tfHttpsPort.setEditable(false);
tfFtpHost.setText("");
tfFtpHost.setEditable(false);
tfFtpPort.setText("");
tfFtpPort.setEditable(false);
useSameServer = true;
} else {
sameServer.setSelected(false);
useSameServer = false;
}
sameServer.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
if(e.getStateChange() == ItemEvent.SELECTED){
tfHttpsHost.setText("");
tfHttpsHost.setEditable(false);
tfHttpsPort.setText("");
tfHttpsPort.setEditable(false);
tfFtpHost.setText("");
tfFtpHost.setEditable(false);
tfFtpPort.setText("");
tfFtpPort.setEditable(false);
} else {
tfHttpsHost.setEditable(true);
tfHttpsPort.setEditable(true);
tfFtpHost.setEditable(true);
tfFtpPort.setEditable(true);
}
tfHttpHost.setCaretPosition(0);
}
});
JPanel checkBoxPanel = new JPanel();
checkBoxPanel.add(sameServer);
checkBoxPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
// Button part of Dialog
JButton apply = new JButton("Apply");
apply.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(!checkPort(Main.httpProxyPort, tfHttpPort.getText().trim())){
return;
}
if(sameServer.isSelected()){
Main.properties.setProperty(Main.httpProxyHost, tfHttpHost.getText().trim());
Main.properties.setProperty(Main.httpProxyPort, tfHttpPort.getText().trim());
Main.properties.setProperty(Main.httpsProxyHost, tfHttpHost.getText().trim());
Main.properties.setProperty(Main.httpsProxyPort, tfHttpPort.getText().trim());
Main.properties.setProperty(Main.ftpProxyHost, tfHttpHost.getText().trim());
Main.properties.setProperty(Main.ftpProxyPort, tfHttpPort.getText().trim());
} else {
if(!checkPort(Main.httpsProxyPort, tfHttpsPort.getText().trim())){
return;
}
if(!checkPort(Main.ftpProxyPort, tfFtpPort.getText().trim())){
return;
}
Main.properties.setProperty(Main.httpProxyHost, tfHttpHost.getText().trim());
Main.properties.setProperty(Main.httpProxyPort, tfHttpPort.getText().trim());
Main.properties.setProperty(Main.httpsProxyHost, tfHttpsHost.getText().trim());
Main.properties.setProperty(Main.httpsProxyPort, tfHttpsPort.getText().trim());
Main.properties.setProperty(Main.ftpProxyHost, tfFtpHost.getText().trim());
Main.properties.setProperty(Main.ftpProxyPort, tfFtpPort.getText().trim());
}
Enumeration<?> en = Main.properties.propertyNames();
while(en.hasMoreElements()){
String key = (String)en.nextElement();
String val = Main.properties.getProperty(key);
if(val != null && val != ""){
System.setProperty(key, val);
}
}
Main.storeProxyProperties();
dialog.setVisible(false);
dialog.dispose();
}
private boolean checkPort(String portName, String value){
boolean passed = true;
try{
if(Integer.parseInt(value) < 0){
passed = false;
showErrorMessage(portName);
}
} catch(NumberFormatException e){
passed = false;
showErrorMessage(portName);
}
return passed;
}
private void showErrorMessage(String portName){
JOptionPane.showMessageDialog(frame,
portName + " must be a positive integer value", "Invalid entry",
JOptionPane.ERROR_MESSAGE);
}
});
JButton reset = new JButton("Reset");
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
tfHttpHost.setText(Main.properties.getProperty(Main.httpProxyHost));
tfHttpPort.setText(Main.properties.getProperty(Main.httpProxyPort));
if(useSameServer){
sameServer.setSelected(true);
tfHttpsHost.setText("");
tfHttpsHost.setEditable(false);
tfHttpsPort.setText("");
tfHttpsPort.setEditable(false);
tfFtpHost.setText("");
tfFtpHost.setEditable(false);
tfFtpPort.setText("");
tfFtpPort.setEditable(false);
} else {
tfHttpsHost.setText(Main.properties.getProperty(Main.httpsProxyHost));
tfHttpsPort.setText(Main.properties.getProperty(Main.httpsProxyPort));
tfFtpHost.setText(Main.properties.getProperty(Main.ftpProxyHost));
tfFtpPort.setText(Main.properties.getProperty(Main.ftpProxyPort));
sameServer.setSelected(false);
}
}
});
JButton cancel = new JButton("Cancel");
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.setVisible(false);
dialog.dispose();
}
});
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
buttonPanel.add(apply);
buttonPanel.add(reset);
buttonPanel.add(cancel);
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
contentPane.add(sheetPanel, BorderLayout.NORTH);
contentPane.add(checkBoxPanel, BorderLayout.CENTER);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
dialog.setContentPane(contentPane);
dialog.setLocationRelativeTo(frame);
dialog.pack();
dialog.setVisible(true);
tfHttpHost.setCaretPosition(0);
}