List of usage examples for org.json.prettyprint JsonWriter formatJson
public static String formatJson(String json) throws IOException
From source file:org.planetcrypto.bitcoin.PlanetCryptoBitcoinUI.java
private void CustomCommandSubmitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CustomCommandSubmitButtonActionPerformed String command = CustomCommandEntryTextField.getText(); String miner = MinerSelectionBox.getSelectedItem().toString(); Boolean json = CustomCommandJsonCheckBox.isSelected(); if (command.equals("")) { JOptionPane.showMessageDialog(null, "Please enter a command.", "ERROR: NO COMMAND", JOptionPane.WARNING_MESSAGE); } else {/*ww w . j ava2s .c o m*/ for (int i = 0; i < existing_miners.size(); i++) { if (existing_miners.get(i).get("name").equals(miner)) { //System.out.println("Found compatible miner"); String response = api_Commands.parseArgs(existing_miners.get(i).get("ip"), existing_miners.get(i).get("port"), command, json); if (!json) { try { response = api_Commands.prettyPrint(response); CustomCommandOutputTextArea.setText(response); return; } catch (IOException ex) { Logger.getLogger(PlanetCryptoBitcoinUI.class.getName()).log(Level.SEVERE, null, ex); CustomCommandOutputTextArea.setText("Error"); return; } } else { try { String niceJSON = JsonWriter.formatJson(response); CustomCommandOutputTextArea.setLineWrap(true); CustomCommandOutputTextArea .setText("Command: " + command + "\n" + "Response: \n" + niceJSON); CustomCommandEntryTextField.setText(""); CustomCommandJsonCheckBox.setSelected(false); } catch (IOException ex) { Logger.getLogger(PlanetCryptoBitcoinUI.class.getName()).log(Level.SEVERE, null, ex); CustomCommandOutputTextArea.setText("Command: " + command + "\nResponse: Error \n"); CustomCommandEntryTextField.setText(""); CustomCommandJsonCheckBox.setSelected(false); } } } } } }