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 / 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 {
@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 / 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:explosivegnome@yahoo.com">explosivegnome@yahoo.com</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 / NativePythonTest.java
Last active February 18, 2016 19:29
Run scientific python scripts in java app via process spawning
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
@DrPlantabyte
DrPlantabyte / TreasureChests.java
Created April 18, 2016 00:03
Example of the Steam Advantage mod generating loot tables that will be loaded by the Additional Loot Tables to add new mod items to dungeon treasure chests
package cyano.steamadvantage.init;
import cyano.steamadvantage.SteamAdvantage;
import net.minecraftforge.fml.common.FMLLog;
import org.apache.logging.log4j.Level;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
@DrPlantabyte
DrPlantabyte / CCH-java-app_build.gradle
Last active July 20, 2017 11:54
This is my default build.gradle file, which has a createProject task that makes all of the folders so you don't have to guess the convention and even intializes it with a blank JavaFX app
// buildscript blocks MUST go before plugins
buildscript {
dependencies {
classpath group: 'de.dynamicfiles.projects.gradle.plugins', name: 'javafx-gradle-plugin', version: '8.8.2'
}
repositories {
mavenLocal()
mavenCentral()
}
@DrPlantabyte
DrPlantabyte / netbeans-project-gradle.build
Created July 20, 2017 11:23
A simple gradle build file that you can drop into your typical Netbeans java project to build the jar using gradle from the command-line.
apply plugin: 'java'
libsDirName = '../dist'
docsDirName = '../dist'
sourceSets {
main {
java {
srcDirs = ['src']
}
}
}
@DrPlantabyte
DrPlantabyte / FXMLControllerCreator.java
Last active March 21, 2018 02:41
Generate a JavaFX controller class from a given FXML file.
import org.w3c.dom.*;
import org.xml.sax.SAXException;
import javax.swing.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
@DrPlantabyte
DrPlantabyte / jpms-new-project.py
Last active December 14, 2021 02:41
Python script to create a JPMS project without fancy build tools
#!/usr/bin/python3
import os, sys
from os import path
def main():
print("\tCreating new Java JPMS module project...")
project_name = input("Project name: ").strip()
if path.exists(project_name):
print("Abort: '%s' already exists. ")
exit(1)