Skip to content

Accessing Archi's Preferences

Phil Beauvoir edited this page Jan 15, 2024 · 12 revisions

Introduction

This page shows how to access Archi's internal Preference Store in order to query and set various preferences.

Please note that this is not an official API and some constants may change.

For a list of preference constants please refer to the IPreferenceConstants class.

jArchi examples

Accessing the Archi Preference Store

To access the Archi Preference Store we need to call

const archiPrefs = Java.type('com.archimatetool.editor.ArchiPlugin').PREFERENCES;

Getting and setting the default ArchiMate figure width and height

// Get Archi's Preference Store
const archiPrefs = Java.type('com.archimatetool.editor.ArchiPlugin').PREFERENCES;

// Get default ArchiMate figure width and height
console.log('Default Width: ' + archiPrefs.getDefaultInt('defaultArchiMateFigureWidth'));
console.log('Default Height: ' + archiPrefs.getDefaultInt('defaultArchiMateFigureHeight'));

// Get current ArchiMate figure width and height
console.log('Current Width: ' + archiPrefs.getInt('defaultArchiMateFigureWidth'));
console.log('Current Height: ' + archiPrefs.getInt('defaultArchiMateFigureHeight'));

// Set ArchiMate figure width and height
archiPrefs.setValue('defaultArchiMateFigureWidth', 140);
archiPrefs.setValue('defaultArchiMateFigureHeight', 60);

Getting and setting the default grid size

// Get Archi's Preference Store
const archiPrefs = Java.type('com.archimatetool.editor.ArchiPlugin').PREFERENCES;

// Get default value of gridSize
console.log('Default gridSize: ' + archiPrefs.getDefaultInt('gridSize'));

// Get current value of gridSize
console.log('Current gridSize: ' + archiPrefs.getInt('gridSize'));

// Set value of gridSize
archiPrefs.setValue('gridSize', 16);

Getting and setting the default font name, height, and style for diagram objects

// Get Archi's Preference Store
const archiPrefs = Java.type('com.archimatetool.editor.ArchiPlugin').PREFERENCES;

// Default font for diagram objects
// It's a long string so we need to load it into an Eclipse FontData object to get its parts
var defaultViewFont = archiPrefs.getString('defaultViewFont');

// Load the string into a FontData object
// See https://github.com/eclipse-platform/eclipse.platform.swt/blob/master/bundles/org.eclipse.swt/Eclipse%20SWT/gtk/org/eclipse/swt/graphics/FontData.java
const FontDataClass = Java.type('org.eclipse.swt.graphics.FontData');
var fontData = new FontDataClass(defaultViewFont);

// Then we can get name, height, and style
console.log('Font name: ' + fontData.getName());
console.log('Font height: ' + fontData.getHeight());
console.log('Font style: ' + fontData.getStyle());

/ Create a new FontData of font name, height, and style
var newFontData = new FontDataClass('Arial', 12, 0);

// Get the FontData string
var fdString = newFontData.toString();

// Set it to the default font in preferences
// If Archi is running you need to restart
archiPrefs.setValue('defaultViewFont', fdString);