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, which 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.

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

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: * Enum Bit Masks: a type-safe bitflag implementation. * Give Java Applications More Memory: give your application more memory without user interaction.

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.