Giter Club home page Giter Club logo

property-editor's Introduction

Hierarchical Property List Editor

Actions Status codecov Maven Central

Demo

An editor for hierarchical properties as Java Swing component. Shamelessly inspired by Apple's Property List Editor in Xcode. It allows building data structures based on Maps and Lists and primitive types such as Long, Double, and Boolean. It is originally created for the KNIME Selenium Nodes but it could probably be of general interest.

The editor is built on top of SwingX from SwingLabs.

Download

Via Maven:

<dependency>
  <groupId>de.philippkatz.swing.property</groupId>
  <artifactId>property-editor</artifactId>
  <version>2.0.1</version>
</dependency>

Usage

// create a new component and pass the data
Object input = …
PropertiesTreeTableModel model = new PropertiesTreeTableModel(input);
PropertiesEditor editor = new PropertiesEditor(model);

// access to the data; this is either a Map<String, Object> or a List<Object>
Object result = model.getData();

Full Working Example

Have a look at PropertiesEditorDemo for a more detailed version.

public class PropertiesEditorDemo {

  private static Object createSampleData() {
    Map<String, Object> root = new LinkedHashMap<>();
    root.put("string", "The quick brown fox");
    root.put("boolean", true);
    root.put("numbers", 42);
    root.put("fruits", Arrays.asList("apple", "orange", "grapefruit"));
    return root;
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setTitle("Properties Editor Demo");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setMinimumSize(new Dimension(600, 400));
    frame.add(new PropertiesEditor(new PropertiesTreeTableModel(createSampleData())));
    frame.setVisible(true);
  }

}

Advanced

The types to use in the editor can be customized using the PropertiesEditorConfig. It also allows to change the type names in the user interface. Example:

PropertiesEditorConfigBuilder configBuilder = PropertiesEditorConfig.builder();

// use "Object" and "Array" instead of "Map" and "List"
configBuilder.addType(new PropertyTypes.MapType("Object"));
configBuilder.addType(new PropertyTypes.ListType("Array"));

// only allow String and Boolean
configBuilder.addDefaultType(new PropertyTypes.StringType("String", ""));
configBuilder.addType(new PropertyTypes.BooleanType("Boolean", true));

PropertiesEditorConfig config = configBuilder.build();
PropertiesTreeTableModel model = new PropertiesTreeTableModel(config, data);

Contributing

Pull requests are very welcome. Feel free to discuss bugs or new features by opening a new issue.

License

GNU Lesser General Public License


Copyright (c) 2017 – 2020, Philipp Katz

property-editor's People

Contributors

dependabot[bot] avatar qqilihq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

property-editor's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.