JAR Libraries

Using JAR libraries

Logisim has two types of circuit components: those that are designed within Logisim as combinations of components, and those primitive components that are written in Java. Logisim circuits are easier to design, but they cannot support sophisticated user interaction, and they are relatively inefficient.

Logisim contains a fairly thorough collection of built-in libraries of Java components, but it can also load additional libraries written by you or others. Once you have downloaded a library, you can import it into your project by right-clicking the project in the explorer pane (the top line) and choosing Load Library > JAR Library…. Then, Logisim will prompt you to select the JAR file. (In some circumstances, you may have to type the starting class name when prompted, which would be provided by the library developer. However, a developer typically configures the JAR library to avoid this (by including a manifest file in the JAR with a Library-Class attribute specifying the main class name).)

If you only want to reuse circuits designed in Logisim, you do not need to write a JAR library. Save the circuits in a .circ file and load that file with | Project |→| Load Library |→| Logisim-evolution Library… |. This is described in the Logisim libraries section.

Creating JAR libraries

The remainder of this section is dedicated to a series of thoroughly commented examples illustrating how to develop Logisim libraries yourself. You should only attempt this if you're an experienced Java programmer. You will find the documentation beyond these examples fairly meager.

The example source code is maintained in the Logisim-evolution source tree under src/main/java/com/cburch/gray. The pages in this section explain the important pieces of that example, but the source tree is the best reference if the printed snippets and the current code diverge.

Building a JAR library

A JAR library must be compiled against the same Logisim-evolution API that it is intended to run with. When building outside the Logisim-evolution source tree, put the Logisim-evolution JAR on your Java compiler's class path, compile the library classes, and package those classes and any resources into a JAR file.

To avoid asking users for a class name when they load the JAR, include a manifest entry named Library-Class. Its value must be the fully qualified name of the class extending com.cburch.logisim.tools.Library. For the gray-code example, that entry would be Library-Class: com.cburch.gray.Components.

The gray-code example is also compiled as part of Logisim-evolution itself, so contributors can verify that the example still builds by running ./gradlew compileJava from the Logisim-evolution source tree.

Gray Code Incrementer

Illustrates the essential components of any component type using a simple example of a component that takes a multibit input and computes the next Gray code value following it.

Library Class

Illustrates how to define a library. This is the entry point for any JAR file - the class whose name the user enters when loading the JAR library.

Simple Gray Code Counter

Illustrates how to make a component that has internal state, in particular an 8-bit counter that iterates through Gray codes.

Gray Code Counter

Demonstrates a complete, fairly sophisticated component with which the user can interact. It implements a Gray code counter where the number of bits remembered is customizable, and where the user can edit the current value by clicking on it with the Poke Tool and typing a value.

Guidelines
General information for those developing third-party libraries.

License

The code in this example JAR library is released under the MIT license, a more permissive license than the GPL, under which the rest of Logisim is released.

Copyright (c) 2009, Carl Burch.

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 furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Next: Gray Code Incrementer.