From 493dcdac079c13decfe14c8b0b3ffdfe257b00fd Mon Sep 17 00:00:00 2001 From: Oren Bissick Date: Thu, 25 May 2017 14:32:27 -0400 Subject: [PATCH] Add edit config functionality. --- src/jmaxscale/EditConfGUI.java | 17 ++++++++--------- src/jmaxscale/TransferFile.java | 5 +++-- src/jmaxscale/ui.form | 2 +- src/jmaxscale/ui.java | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/jmaxscale/EditConfGUI.java b/src/jmaxscale/EditConfGUI.java index 3b797fe..d439f3a 100644 --- a/src/jmaxscale/EditConfGUI.java +++ b/src/jmaxscale/EditConfGUI.java @@ -23,11 +23,11 @@ public EditConfGUI(){ fileRead(); panels(); } - + private TransferFile ssh = new TransferFile(); private String storeAllString=""; private JButton saveCloseBtn = new JButton("Save Changes and Close"); private JButton closeButton = new JButton("Exit Without Saving"); - private JFrame frame=new JFrame("Viewing All Program Details"); + private JFrame frame=new JFrame("Edit MaxScale Config"); // private JTextArea textArea = new JTextArea(storeAllString,0,70); private JTextArea textArea = new JTextArea(); @@ -37,10 +37,9 @@ private JButton getCloseButton(){ } private void fileRead(){ - TransferFile ssh = new TransferFile(); - ssh.download("MaxScale.cnf", ui.getHost(), ui.getUser(), ui.getPass()); + ssh.download("maxscale.cnf", ui.getHost(), ui.getUser(), ui.getPass()); try{ - FileReader read = new FileReader("MaxScale.cnf"); + FileReader read = new FileReader("maxscale.cnf"); Scanner scan = new Scanner(read); while(scan.hasNextLine()){ String temp=scan.nextLine()+"\n"; @@ -83,10 +82,9 @@ public void actionPerformed(ActionEvent e) { } }); - frame.setSize(1000, 700); + frame.setSize(700, 500); frame.setVisible(true); - frame.setLocationRelativeTo(null); - + } private void saveBtn(){ @@ -95,10 +93,11 @@ private void saveBtn(){ try { - file = new File("MaxScale.cnf"); + file = new File("maxscale.cnf"); out = new FileWriter(file); out.write(textArea.getText()); out.close(); + ssh.upload("maxscale.cnf", ui.getHost(), ui.getUser(), ui.getPass()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { diff --git a/src/jmaxscale/TransferFile.java b/src/jmaxscale/TransferFile.java index 5a22593..f979392 100644 --- a/src/jmaxscale/TransferFile.java +++ b/src/jmaxscale/TransferFile.java @@ -68,8 +68,8 @@ public void download(String file, String host,String user, String password){ channelSftp = (ChannelSftp) channel; channelSftp.cd(SFTPWORKINGDIR); byte[] buffer = new byte[1024]; - BufferedInputStream bis = new BufferedInputStream(channelSftp.get("MaxScale.cnf")); - File newFile = new File("MaxScale.cnf"); + BufferedInputStream bis = new BufferedInputStream(channelSftp.get("maxscale.cnf")); + File newFile = new File("maxscale.cnf"); OutputStream os = new FileOutputStream(newFile); BufferedOutputStream bos = new BufferedOutputStream(os); int readCount; @@ -80,6 +80,7 @@ public void download(String file, String host,String user, String password){ bis.close(); bos.close(); } catch (JSchException | SftpException | IOException ex) { + System.out.println(ex.toString()); } } } diff --git a/src/jmaxscale/ui.form b/src/jmaxscale/ui.form index 7bb0b94..99b8120 100644 --- a/src/jmaxscale/ui.form +++ b/src/jmaxscale/ui.form @@ -95,7 +95,7 @@ - + diff --git a/src/jmaxscale/ui.java b/src/jmaxscale/ui.java index 0179b01..31a77a3 100644 --- a/src/jmaxscale/ui.java +++ b/src/jmaxscale/ui.java @@ -225,7 +225,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { .addComponent(userName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(passwordLabel) .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE) + .addGap(26, 26, 26) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(runButton) .addComponent(comLabel) @@ -321,7 +321,7 @@ private void configButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN- thread.start();*/ EditConfGUI editWin = new EditConfGUI(); - + editWin.setLocation(this.getLocation()); }//GEN-LAST:event_configButtonActionPerformed private void maxUserFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_maxUserFocusLost