public ServerSettingsPanel() { super(); OAuthPropertyBean.getInstance().addChangeListener(this); SpringLayout layout = new SpringLayout(); setLayout(layout); setPreferredSize(new Dimension(400, 400)); // Setup text fields tf_host = new JTextField(16); tf_host.getDocument().addDocumentListener(this); tf_port = new JTextField(4); tf_port.getDocument().addDocumentListener(this); tf_port.setText("8443"); // Add components add(l_hostname); add(tf_host); add(l_port); add(tf_port); // Set Layout // hostname layout.putConstraint(SpringLayout.WEST, l_hostname, 5, SpringLayout.WEST, this); layout.putConstraint(SpringLayout.NORTH, l_hostname, 5, SpringLayout.NORTH, this); layout.putConstraint(SpringLayout.WEST, tf_host, 5, SpringLayout.WEST, this); layout.putConstraint(SpringLayout.NORTH, tf_host, 3, SpringLayout.SOUTH, l_hostname); // port layout.putConstraint(SpringLayout.WEST, tf_port, 10, SpringLayout.EAST, tf_host); layout.putConstraint(SpringLayout.NORTH, tf_port, 0, SpringLayout.NORTH, tf_host); layout.putConstraint(SpringLayout.WEST, l_port, 0, SpringLayout.WEST, tf_port); layout.putConstraint(SpringLayout.SOUTH, l_port, -3, SpringLayout.NORTH, tf_port); }
public static void saveProperties(File file) { Properties props = new Properties(); OAuthPropertyBean pBean = OAuthPropertyBean.getInstance(); props.put(OAuthPropertyBean.AZ_HOST, pBean.getAzHost()); props.put(OAuthPropertyBean.AZ_PORT, pBean.getAzPort()); props.put(OAuthPropertyBean.AZ_URI, pBean.getAzUri()); props.put(OAuthPropertyBean.CLIENT_ID, pBean.getClientId()); props.put(OAuthPropertyBean.CLIENT_SECRET, pBean.getClientSecret()); props.put(OAuthPropertyBean.SCOPE, pBean.getScope()); props.put(OAuthPropertyBean.STATE, pBean.getState()); props.put(OAuthPropertyBean.ACCESS_URI, pBean.getAccessUri()); try { props.store(new FileOutputStream(file), "OAuthTestClient Configuration File"); } catch (FileNotFoundException e) { MessageLog.getInstance().addMessage("Unable to save properties: " + e.getMessage()); } catch (IOException e) { e.printStackTrace(); MessageLog.getInstance().addMessage("Unable to save properties: " + e.getMessage()); } }
public static void loadProperties(File file) { Properties props = new Properties(); try { props.load(new FileInputStream(file)); } catch (FileNotFoundException e) { e.printStackTrace(); MessageLog.getInstance().addMessage("Unable to load properties: " + e.getMessage()); } catch (IOException e) { e.printStackTrace(); MessageLog.getInstance().addMessage("Unable to load properties: " + e.getMessage()); } OAuthPropertyBean pBean = OAuthPropertyBean.getInstance(); pBean.setAzHost(props.getProperty(OAuthPropertyBean.AZ_HOST, "")); pBean.setAzPort(props.getProperty(OAuthPropertyBean.AZ_PORT, "")); pBean.setAzUri(props.getProperty(OAuthPropertyBean.AZ_URI, "")); pBean.setClientId(props.getProperty(OAuthPropertyBean.CLIENT_ID, "")); pBean.setClientSecret(props.getProperty(OAuthPropertyBean.CLIENT_SECRET, "")); pBean.setScope(props.getProperty(OAuthPropertyBean.SCOPE, "")); pBean.setState(props.getProperty(OAuthPropertyBean.STATE, "")); pBean.setAccessUri(props.getProperty(OAuthPropertyBean.ACCESS_URI, "")); }
private void updateProperties() { // Doing this the lazy way until I figure out exactly which field has changed. OAuthPropertyBean prop = OAuthPropertyBean.getInstance(); prop.setAzHost(tf_host.getText()); prop.setAzPort(tf_port.getText()); }