-
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.
Caution
This is not an official API and some constants may change.
Setting preferences to unsupported values may result in unknown behaviour.
For a list of preference constants please refer to the IPreferenceConstants class.
To access the Archi Preference Store we need to call
const archiPrefs = Java.type('com.archimatetool.editor.ArchiPlugin').PREFERENCES;
// Get current ArchiMate figure fill color for a Business Actor
console.log('Current Fill Color for Business Actor: ' + archiPrefs.getString('defaultFillColour_BusinessActor'));
// Set it
archiPrefs.setValue('defaultFillColour_BusinessActor', '#ff0000');
// Set back to default value
archiPrefs.setToDefault('defaultFillColour_BusinessActor');
// 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);
// Set back to default values
archiPrefs.setToDefault('defaultArchiMateFigureWidth');
archiPrefs.setToDefault('defaultArchiMateFigureHeight');
// 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);
// Set back to default value
archiPrefs.setToDefault('gridSize');
// Get Archi's Preference Store
const archiPrefs = Java.type('com.archimatetool.editor.ArchiPlugin').PREFERENCES;
// 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');
// 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');
var fontData = new FontDataClass(defaultViewFont);
// It's a long string so we need to load it into an Eclipse FontData object to get its parts
if(defaultViewFont) {
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 it's the empty string then we can't parse it
else {
console.log("Font is internal default");
}
// 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);
// Set back to default value
archiPrefs.setToDefault('defaultViewFont');
If you value and use Archi please consider making a donation. Thanks!