-
Notifications
You must be signed in to change notification settings - Fork 35
Accessing Archi's Preferences
Phil Beauvoir edited this page Jan 15, 2024
·
12 revisions
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.
// Get Archi's Preference Store
const archiPrefs = Java.type('com.archimatetool.editor.ArchiPlugin').INSTANCE.preferenceStore;
// Get default value of gridSize
var defaultGridSize = archiPrefs.getDefaultInt('gridSize');
console.log('default gridSize: ' + defaultGridSize);
// Get current value of gridSize
var gridSize = archiPrefs.getInt('gridSize');
console.log('gridSize: ' + gridSize);
// Set value of gridSize
archiPrefs.setValue('gridSize', 16);
console.log('gridSize: ' + archiPrefs.getInt('gridSize'));
// Get Archi's Preference Store
const archiPrefs = Java.type('com.archimatetool.editor.ArchiPlugin').INSTANCE.preferenceStore;
// 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());
If you value and use Archi please consider making a donation. Thanks!