de·caff Commons

The de·caff Commons provide a wild mix of open source Java classes used in various projects on this site.

Various blog posts here will also refer to these classes.

License

The de·caff Commons (CC for the rest of this page) are licensed under the ISC License with a few exceptions (see below). The ISC license reads

 Copyright © YEAR-YEAR  Andreas M. Rammelt <rammi@caff.de>

 Permission to use, copy, modify, and/or distribute this software for any
 purpose with or without fee is hereby granted, provided that the above
 copyright notice and this permission notice appear in all copies.

 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Exceptions

The module support-wmf is an excerpt of the Apache Batik project, which is provided under the Apache 2.0 License.

The module generics contains ports of the TimSort algorithm from the Python Programming Language. The ports make up the following classes:

It comes under the Python Software Foundation License Agreement, and reads

PSF LICENSE AGREEMENT
1. This LICENSE AGREEMENT is between the Python Software Foundation ("PSF"), and
   the Individual or Organization ("Licensee") accessing and otherwise using Python
   3.11.1 software in source or binary form and its associated documentation.

2. Subject to the terms and conditions of this License Agreement, PSF hereby
   grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
   analyze, test, perform and/or display publicly, prepare derivative works,
   distribute, and otherwise use Python 3.11.1 alone or in any derivative
   version, provided, however, that PSF's License Agreement and PSF's notice of
   copyright, i.e., "Copyright © 2001-2023 Python Software Foundation; All Rights
   Reserved" are retained in Python 3.11.1 alone or in any derivative version
   prepared by Licensee.

3. In the event Licensee prepares a derivative work that is based on or
   incorporates Python 3.11.1 or any part thereof, and wants to make the
   derivative work available to others as provided herein, then Licensee hereby
   agrees to include in any such work a brief summary of the changes made to Python
   3.11.1.

4. PSF is making Python 3.11.1 available to Licensee on an "AS IS" basis.
   PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  BY WAY OF
   EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR
   WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE
   USE OF PYTHON 3.11.1 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.

5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 3.11.1
   FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF
   MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 3.11.1, OR ANY DERIVATIVE
   THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.

6. This License Agreement will automatically terminate upon a material breach of
   its terms and conditions.

7. Nothing in this License Agreement shall be deemed to create any relationship
   of agency, partnership, or joint venture between PSF and Licensee.  This License
   Agreement does not grant permission to use PSF trademarks or trade name in a
   trademark sense to endorse or promote products or services of Licensee, or any
   third party.

8. By copying, installing or otherwise using Python 3.11.1, Licensee agrees
   to be bound by the terms and conditions of this License Agreement.

The module generics also uses an adapted form of the class java.util.DualPivotQuickSort from the OpenJDK project which comes under the GNU General Public License version 2. In this lib the class appears as de.caff.generics.algorithm.DualPivotQuicksort .

TL;DR

All of the above licenses allow free usage of the code and the resulting programs. Some licenses require to be kept when you create own versions of the libs, and to be published with your version.

Requirements

The CC are pure Java, the minimal necessary Java version is now 1.8.

Download

The CC come in 5 modules.

Module Jar Src Ant JDoc Purpose
caff-generics jar src ant zip / online Helper classes for functional programming in Java 7
caff-common jar src ant zip / online
(incl. the above)
Various tools, requires caff-generics above
caff-common-swing jar src ant zip / online
(incl. both above)
GUI related classes, requires both above modules.
support-wmf jar src ant zip / online Excerpt from Apache Batik to draw WMF, independent of other modules. Not a part of the CC, but included here to allow to download possible changes as the license requires.
vector-icons Not yet finished support for hi-res icons. included in git access.

Git Access

You can also clone the complete CC git repository (including 3rd party code) from javu.de:

git clone https://javu.de/caff-commons.git

Modules

Module caff-generics

The caff-generics module (see online javadoc) provides various helper classes for functional programming. With Java 1.8 it is no longer as useful as before, so it’s mostly included because it is still in use (at least by de·caff software).

Module caff-common

Especially this module (online javadoc) contains a wide variety of different functionality.

A bit of this functionality already has made it into blog postings here on de·caff:

Module caff-common-swing

This module (online javadoc) mainly provides helpers for automatic settings management. This allows to define a few simple constants, and manage preferences and user editing automatically. If you happen do know my de·caff Viewer have a look at its settings dialog. The complete dialog is automatically constructed from some simple constants which define the available settings and their grouping. E.g. here is all what is behind the quite complex View tab.

  /** Internal preference property for the background color in the views. */
  private static final SwingColorPreferenceProperty   PP_BG_COLOR =
          new SwingColorPreferenceProperty(ViewSettingsProvider.PROPERTY_BACKGROUND_COLOR,
                                           "ppBgColor",
                                           Utility.getColorParameter("dxfviewer.bgcolor",
                                                                     DEFAULT_BACKGROUND_COLOR));
  /** Internal preference group for view color settings. */
  private static final EditablePreferenceGroup PG_VIEW_COLORS =
          new EditablePreferenceGroup("pgViewColors",
                                      false,
                                      PP_BG_COLOR);
  /** Internal preference property for the coordinate system on/off state.  */
  private static final SwingBooleanPreferenceProperty PP_CS_ON  =
          new SwingBooleanPreferenceProperty(ViewSettingsProvider.PROPERTY_DISPLAYING_COORDINATES_SYSTEM,
                                             "ppCsOn",
                                             true);
  /** Internal constant for south west placement of coordinates system. */
  private static final IntegerEnumValue ENUM_CS_SOUTH_WEST =
          new IntegerEnumValue("enCsSW", ViewConstants.COORDS_SW);
  /** Internal constant for south east placement of coordinates system. */
  private static final IntegerEnumValue ENUM_CS_SOUTH_EAST =
          new IntegerEnumValue("enCsSE", ViewConstants.COORDS_SE);
  /** Internal constant for north east placement of coordinates system. */
  private static final IntegerEnumValue ENUM_CS_NORTH_EAST =
          new IntegerEnumValue("enCsNE", ViewConstants.COORDS_NE);
  /** Internal constant for north west placement of coordinates system. */
  private static final IntegerEnumValue ENUM_CS_NORTH_WEST =
          new IntegerEnumValue("enCsNW", ViewConstants.COORDS_NW);
  /** Internal preference property for coordinates system placement. */
  private static final SwingEnumPreferenceProperty<Integer> PP_CS_POS =
          new SwingEnumPreferenceProperty<>(ENUM_CS_SOUTH_WEST,
                                                   ViewSettingsProvider.PROPERTY_COORDINATES_SYSTEM_POSITION,
                                                   "ppCsPos",
                                                   ENUM_CS_SOUTH_WEST,
                                                   ENUM_CS_SOUTH_EAST,
                                                   ENUM_CS_NORTH_EAST,
                                                   ENUM_CS_NORTH_WEST);
  /** Internal preference group for coordinates system settings. */
  private static final EditablePreferenceGroup PG_VIEW_CS =
          new EditablePreferenceGroup("pgViewCS",
                                      false,
                                      PP_CS_ON,
                                      PP_CS_POS);
  /** Create 3D VIEWs? */
  private static final SwingBooleanPreferenceProperty PP_3D_VIEWS =
          new SwingBooleanPreferenceProperty("USE_3D_VIEWS",
                                             "ppView3D",
                                             BasicConversionSettings.CREATE_3D_VIEWS);

  /** Create 3D VPORTs? */
  private static final SwingBooleanPreferenceProperty PP_3D_VPORTS =
          new SwingBooleanPreferenceProperty("USE_3D_VPORTS",
                                             "ppVPort3D",
                                             BasicConversionSettings.CREATE_3D_VPORTS);
  /** Internal preference property for using linestyles (needs more memory and is slower!). */
  private static final SwingBooleanPreferenceProperty PP_USING_LINESTYLES =
          new SwingBooleanPreferenceProperty(ViewSettingsProvider.PROPERTY_USING_LINESTYLES,
                                             "ppUsingLinestyles",
                                             true);
  /** Internal preference property for using point shapes (usually is slower!). */
  private static final SwingBooleanPreferenceProperty PP_USING_POINT_SHAPES =
          new SwingBooleanPreferenceProperty(ViewSettingsProvider.PROPERTY_USING_POINT_SHAPES,
                                             "ppUsingPointShapes",
                                             true);
  /** Internal preference property for enabling picking (needs more memory!). */
  private static final SwingBooleanPreferenceProperty PP_ENABLE_PICKING =
          new SwingBooleanPreferenceProperty(ViewSettingsProvider.PROPERTY_PICKING_ENABLED,
                                             "ppEnablePicking",
                                             true);
  /** Internal preference for wheel direction. */
  private static final SwingBooleanPreferenceProperty PP_INVERT_WHEEL_DIRECTION =
          new SwingBooleanPreferenceProperty(ViewSettingsProvider.PROPERTY_INVERT_WHEEL,
                                             "ppInvertWheel", Utility.areWeOnDOS());    // Default on Windows is inverted
  /** Internal preference group for miscellaneous view settings. */
  private static final EditablePreferenceGroup PG_VIEW_MISC =
          new EditablePreferenceGroup("pgViewMisc",
                                      false,
                                      PP_3D_VIEWS,
                                      PP_3D_VPORTS,
                                      PP_USING_LINESTYLES,
                                      PP_USING_POINT_SHAPES,
                                      PP_ENABLE_PICKING,
                                      PP_INVERT_WHEEL_DIRECTION);

  /** Internal preference group for view settings. */
  private static final EditablePreferenceGroup PREFERENCES_VIEW =
          new EditablePreferenceGroup("pgView",
                                      false,
                                      PG_VIEW_COLORS,
                                      PG_VIEW_CS,
                                      PG_VIEW_MISC);

Above I use the convention that PG_ is used for groups of preferences, and PP_ is used for preference properties.

Starting from the end you see the constant PREFERENCES_VIEW which groups the three settings for color, coordinate system and miscellaneous settings (which is exactly what you find in the tab as bordered panels). So if you look for the last preference group PG_VIEW_MISC you’ll just find another constant grouping 6 preference settings. E.g. the last one of these (PP_INVERT_WHEEL_DIRECTION) is a boolean property which is either true or false. The strings starting with pp and pg are i18n tags.

From the above constants the tab in the dialog is automatically created, indeed all tabs are again in another group from which the whole dialog is made in a single call. Loading the preferences and storing them is just one call to this root group each, and listeners can connect to the constants or just read their value when required. Adding another preference setting now just means adding an appropriate constant, its i18n resources and adding this constant to the group where it belongs.

Here’s the view tab as created from the above code:

Screenshot of Options View Tab

Module wmf-support

This module is not part of the CC. It is the WMF related code extracted from Apache Batik, and included here to fulfill the license.

Module vector-icons

Caveat: currently not in a state which others can easily use.

Support for vector icons allowing easier adaption to different screen resolutions.

Running under the name of VIC this is used in the de·caff Viewer to allow changing the resolution of the GUI. Basically a kind of stripped-down SVG it provides a way to define vector graphic icons. I dropped SVG because nowadays decent SVG libraries are larger than my viewer (which is already a really complex program). VIC basically uses a simple file representation of Java Shapes and Paints. Runtime representation of VIC comes with a footprint of some 80kB for some 20 classes.

Some useful classes (like conversion from SVG to VIC) are not included. If you are really interested drop me a note and I’ll see what I can do.