Skip to content

Instantly share code, notes, and snippets.

View DrPlantabyte's full-sized avatar

Chris Hall DrPlantabyte

  • Sydney, Australia
View GitHub Profile
@DrPlantabyte
DrPlantabyte / JSONConverter.java
Created July 23, 2015 17:52
Upcoming Java feature JSR-353 (JSON support) only provides immutable JSON classes and is not useful as a data structure (it was intended for input/output only). This Gist implements a converter between JSON and HashMaps, so you can use nested HashMaps (parallel to JSON objects) and write/read it to/from JSON files.
/*
* The MIT License
*
* Copyright 2015 CCHall <a href="mailto:[email protected]">[email protected]</a>.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@DrPlantabyte
DrPlantabyte / RSyntaxTextArea-example
Created September 5, 2014 17:40
How to display JavaScript syntax highlighting in Java with RSyntaxTextArea
JPanel scriptPane = new javax.swing.JPanel();
// ...
void addSyntaxTextArea() {
RSyntaxTextArea scriptArea = new RSyntaxTextArea(10, 20);
scriptArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
scriptArea.setCodeFoldingEnabled(true);
scriptArea.setAntiAliasingEnabled(true);
RTextScrollPane sp = new RTextScrollPane(scriptArea);
sp.setFoldIndicatorEnabled(true);
scriptPane.setLayout(new BorderLayout());
@DrPlantabyte
DrPlantabyte / JFileChooser that remembers
Last active August 29, 2015 14:06
Example of how to save program config in an OS appropriate config file. Specifically, this example shows how to remember the location of a JFileChooser after the program exits.
import java.util.*;
import javax.swing.*;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class SavedConfigExample {