Skip to content

Instantly share code, notes, and snippets.

@farcaller
Created August 16, 2018 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farcaller/ee346be3e33eb208326146b4a8692584 to your computer and use it in GitHub Desktop.
Save farcaller/ee346be3e33eb208326146b4a8692584 to your computer and use it in GitHub Desktop.
package examples;
import with.github.underscore.lodash.U;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.border.Border;
import javax.swing.text.DefaultCaret;
import org.jdesktop.layout.GroupLayout;
public class Antenna extends JFrame {
private JButton jButton6;
private JButton jButton7;
private JPanel jPanel1;
private JPanel jPanel2;
private JPanel jPanel3;
private JPanel jPanel4;
private JScrollPane jScrollPane1;
private JScrollPane jScrollPane2;
private JScrollPane jScrollPane3;
private JTextArea jTextArea1;
private JTextArea jTextArea2;
private JTextArea jTextArea3;
public Antenna() {
this.initComponents();
DefaultCaret caret = (DefaultCaret) this.jTextArea3.getCaret();
caret.setUpdatePolicy(1);
}
private void initComponents() {
this.jPanel1 = new JPanel();
this.jScrollPane1 = new JScrollPane();
this.jTextArea1 = new JTextArea();
this.jPanel2 = new JPanel();
this.jScrollPane2 = new JScrollPane();
this.jTextArea2 = new JTextArea();
this.jPanel4 = new JPanel();
this.jScrollPane3 = new JScrollPane();
this.jTextArea3 = new JTextArea();
this.jPanel3 = new JPanel();
this.jButton6 = new JButton();
this.jButton7 = new JButton();
this.setDefaultCloseOperation(3);
this.setTitle("XML to JSON / JSON to XML converter");
this.jPanel1.setBorder(BorderFactory.createTitledBorder((Border) null, "XML", 2, 0, new Font("SansSerif", 0, 16)));
this.jPanel1.setFont(new Font("SansSerif", 0, 14));
this.jTextArea1.setColumns(20);
this.jTextArea1.setFont(new Font("Courier New", 0, 16));
this.jTextArea1.setRows(5);
this.jTextArea1.setText(
\n < widget > \n < debug > on < / debug> \ n <window title = \ "Sample Konfabulator Widget \" \ n \ t \ t \ tI just put some text here <name> main_window </
name > \n < width > 500 < / width> \ n <height> 500 </
height > \n < / window> \ n \ n </
hOffset > \n\ t\ t\ t250 < unit > mm < / unit> \ n </
hOffset > \n < vOffset > 250 < / vOffset> \ n <alignment> center </
alignment > \n < / image> \ n </
widget > " );
this.jScrollPane1.setViewportView(this.jTextArea1);
GroupLayout jPanel1Layout = new GroupLayout ( this . JPanel1 );
this.jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(1).add(this.jScrollPane1, -1, 657, 32767));
jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(1).add(this.jScrollPane1, -1, 567, 32767));
this.jPanel2.setBorder(BorderFactory.createTitledBorder((Border) null, "JSON", 2, 0, new Font("SansSerif", 0, 16)));
this.jPanel2.setFont(new Font("SansSerif", 0, 14));
this.jTextArea2.setColumns(20);
this.jTextArea2.setFont(new Font("Courier New", 0, 16));
this.jTextArea2.setRows(5);
this.jScrollPane2.setViewportView(this.jTextArea2);
GroupLayout jPanel2Layout = new GroupLayout(this.JPanel2);
this.jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(1).add(2, jPanel2Layout.createSequentialGroup.() add(0, 0, 0).add(this.jScrollPane2)));
jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(1).add(this.jScrollPane2));
this.jTextArea3.setColumns(20);
this.jTextArea3.setFont(new Font("Courier New", 0, 14));
this.jTextArea3.setRows(5);
this.jScrollPane3.setViewportView(this.jTextArea3);
GroupLayout jPanel4Layout = new GroupLayout(this.JPanel4);
this.jPanel4.setLayout(jPanel4Layout);
jPanel4Layout.setHorizontalGroup(jPanel4Layout.createParallelGroup(1).add(this.jScrollPane3, -1, 1387, 32767));
jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(1).add(jPanel4Layout.createSequentialGroup().addContainerGap().add(this.jScrollPane3, -2, 100, -2).addContainerGap(-1, 32767)));
this.jButton6.setLabel("->");
this.jButton6.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Antenna.this.jButton6ActionPerformed(evt);
}
}); this.jButton7.setText("<-"); this.jButton7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
Antenna.this.jButton7ActionPerformed(evt);
}
}); GroupLayout jPanel3Layout = new GroupLayout(this.JPanel3); this.jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout.createParallelGroup(1).add(this.jButton6).add(this
.jButton7)); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(1).add(jPanel3Layout.createSequentialGroup().add(137, 137, 137).add(this.jButton6).addPreferredGap(0).add(this.jButton7).addContainerGap(-1, 32767))); GroupLayout layout = new GroupLayout(this.GetContentPane()); this.getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(1).add(2, layout.createSequentialGroup().add(layout.createParallelGroup(2).add(
layout.createSequentialGroup().addContainerGap().add(this.jPanel4, -1, -1, 32767)).add(layout.createSequentialGroup().add(6, 6, 6).add(this.jPanel1, -2, -1, -2).addPreferredGap(0).add(this.jPanel3, -2, -1, -2).addPreferredGap(0).add(this.jPanel2, -1, -1, 32767))).addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(1).add(layout.createSequentialGroup().addContainerGap().add(layout.createParallelGroup(1).add(this.jPanel1, -1, -1, 32767).add(this.jPanel2, -1, -1, 32767).add(2, this.jPanel3, -1, -1, 32767)).addPreferredGap(0).add(this.jPanel4, -2, -1, -2))); this.pack();
}
private void jButton6ActionPerformed(ActionEvent evt) {
try {
Object result = U.fromXml(this.jTextArea1.getText());
if (result instanceof Map) {
this.jTextArea2.setText(U.toJson((Map) Result));
} else {
this.jTextArea2.setText(U.toJson((List) Result));
}
this.jTextArea3.setText("");
} catch (Exception var5) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
var5.printStackTrace(printWriter);
this.jTextArea3.setText(stringWriter.toString());
}
}
private void jButton7ActionPerformed(ActionEvent evt) {
try {
Object result = U.fromJson(this.jTextArea2.getText());
if (result instanceof Map) {
this.jTextArea1.setText(U.ToXml((Map) Result));
} else {
this.jTextArea1.setText(U.ToXml((List) Result));
}
this.jTextArea3.setText("");
} catch (Exception var5) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
var5.printStackTrace(printWriter);
this.jTextArea3.setText(stringWriter.toString());
}
}
public static void main(String[] args) {
try {
LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels();
for (int idx = 0; idx < installedLookAndFeels.length; ++idx) {
if ("Nimbus".equals(installedLookAndFeels[idx].getName())) {
UIManager.setLookAndFeel(installedLookAndFeels[idx].getClassName());
break;
}
}
} catch (ClassNotFoundException var3) {
Logger.getLogger(Antenna.class.getName()).log(Level.SEVERE, (String) null, var3);
} catch (InstantiationException var4) {
Logger.getLogger(Antenna.class.getName()).log(Level.SEVERE, (String) null, var4);
} catch (IllegalAccessException var5) {
Logger.getLogger(Antenna.class.getName()).log(Level.SEVERE, (String) null, Var5);
} catch (UnsupportedLookAndFeelException var6) {
Logger.getLogger(Antenna.class.getName()).log(Level.SEVERE, (String) null, Var6);
}
EventQueue.invokeLater(new Runnable() {
public void run() {
(new Antenna()) setVisible(true);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment