Skip to content
/ JavaTemplate Public template

JavaTemplate - files for a new project setup (AppProperties, CLI arguments, Logging, Usage, Version, Message, Util, Parser, GUI, XML)

License

Apache-2.0, Unknown licenses found

Licenses found

Apache-2.0
LICENSE
Unknown
LICENSE.integrated
Notifications You must be signed in to change notification settings

openworld42/JavaTemplate

Repository files navigation

JavaUtil




JavaTemplate

JavaTemplate supports a fast startup of a new project, providing several classes and utilities to start with.

Maintenance Status dependencies License PRs Welcome

✈️   Click here if you just want the latest release jar file.

🚴   To use it, download a release or simply copy over the files you want to use and delete the parts or files you don't need. Take less files from the stable 1.0.x branch if you dont need the full JavaTemplate.

🏛️   Since it is a template for repeated needs during project setup, it does almost nothing by itself, but runs a simple GUI (Graphical User Interface, may be deleted) for the early stages of design and programming.

To run it: download the template_vx.x.x.jar file and call it from the command line using

java -jar template_vx.x.x.jar

where x.x.x is the current version. You need a Java runtime/JDK installed (at least version 17 - check on command line using java -version).
To get it: Linux: simply use your package manager, Windows/macOS/others: download and install JDK from here.

🤔   I have been using/growing this for fast setups of my own projects over years, starting with 500-1000 (or even 2500) lines of code from the beginning, concentrating on the project needs - and not repeat the somewhat boring tasks. I tried to keep it simple but functional, thus reducing unnecessary complexity.

:electron:   And yes, it's all source under your hood/needs, not a framework to live with, and has no dependencies. It's a template, you modify it, delete the unnecessary parts, and start with some infrastructure from the very beginning. Use the saved time for other things you like.

Javadocs / API

The API contains:

  • Main: an application entry class catching all unexpected Exceptions, starting a GUI (can be deleted), with logging and command line option parsing. Properties (like last window positions) are included.
  • AppProperties: application specific property object (e.g. for window sizes and small items to persist). Default properties are automatically stored as XML or key/value files and can be read back easily at the next application start.
  • CommandLineArgs: a specimen for command line options and the parsing.
  • Usage: the usual -h --help output and other options specimen (documentation is very often underestimated ;-).
  • Logger: a simple logging class, may be upgraded later for another or more complex logging. One needs rarely the full complexity (if so, it is easy to start with Logger and use it as a wrapper when something is going to get big).
  • Version: a simple version (release) class for version management.
  • Msg and Message: a good start for a possible distribution of other languages/labels/tags, with fair cost at the beginning of a new project. Add files for other languages later - with almost no changes to the code.
  • Util: an utility class with several static methods, needed in most projects (e.g. wanted to write something (array, list) to the output, but break the lines if too long? Always searching the javadocs for date or decimal formats? Find files in a directory with a prefix (log rotation, versioning, etc.)? Rename backup files to save the history? Prompt and read on stdin for debugging reasons? Convert a stacktrace into a String? Read/write a full content string to/from a file/URL? Various string manipulations, easy sleeping, and more). If you want to contribute your 2 cents (and use the code style of the project) or if you have any suggestions on often needed items: provide useful methods/ideas - welcome on board (Apache license!).
  • Parser: a text file parser specimen with line numbers (helps debugging a lot), tokenize items to lists, and more.
  • your 2 cents may go here: ...

XML of course, nowadays:

  • XmlWriter: a simple way to serialize things/objects to a XML file (quick method).
  • XmlWritable: an interface an object may implement to make it writable to XML using XmlWriter.
  • XML parser: a specimen
  • XmlExample: a specimen for a XML turnaround, writing out some objects and reading them back.
` Last, but not least, don't forget the GUI (Graphical User Interface):
  • Look&Feel: is configurable, or can be set to a fixed one
  • MainView (swing based): a main window specimen with almost everything to delete out if not needed. Contains code snippets for ToolBar, Menu, status line, some widgets, listeners, action handling/dispatching, focus, window closing actions, simple dialog examples (file chooser, question input, etc.), and yes, layout (e.g. an easy way to use GridBagLayout!).
  • Gbc: ride the GridBagConstraints horse for GridBagLayout in a kingsman way - short/fast learning curve, index placed (grid x/y placement), automated insets for a good look/feel of the widgets, anchoring (e.g. "NW t" for north-west anchor with automated (wider) inset at the top), filler() to drag/push widgets and more: take a look for its use in MainView. No drawing tools needed anymore.
  • Gui: the utility class for the graphical user interface (always wanted to center the main window at startup? Error/Warning/Info dialog not braking down to 3 lines of code? Use Gui)
  • Dialog: a specimen for a JDialog to start with, if needed in your application.

Note: all files are Apache 2.0 licensed, therefore could be used as a starter for any other GPL/Apache/FOSS project, as well as the use of individual classes.

(If you need just the source for a project setup, there is no need to refer to me as an author, but it would be a handsome gesture. I will NOT use my right of legal action for that, it's just my 2 cents for the mankind.)

Author: Heinz Silberbauer (You like it? Spend a Github Star to motivate me 🐜)