Archi Forum

Archi Plug-ins => jArchi => Topic started by: rchevallier on October 12, 2022, 16:12:48 PM

Title: Possible to get the Custom colors of a model ?
Post by: rchevallier on October 12, 2022, 16:12:48 PM
Hi all,

Is there a way to access from jarchi (thru Java objects) the custom colors defined in the application. The idea is when using the SWT ColorDialog in a jArchi script, to display it with the same custom color palette.

Thanks
Title: Re: Possible to get the Custom colors of a model ?
Post by: Phil Beauvoir on October 12, 2022, 16:25:05 PM
Sorry, not really. jArchi doesn't access Archi's preferences store. There may be a way to do it through loading the Java Eclipse classes of Archi's main bundle, but I haven't checked whether that's possible.
Title: Re: Possible to get the Custom colors of a model ?
Post by: Phil Beauvoir on October 12, 2022, 18:05:51 PM
I figured out how to get the user defined colors of elements in Archi's preferences. If a user color is not set, the value is an empty string:

// Get the Archi bundle
const ArchiPlugin = Java.type("com.archimatetool.editor.ArchiPlugin");

// Get Archi's Preferences
const Preferences = ArchiPlugin.PREFERENCES;

// Get ArchimateModelUtils
const ArchimateModelUtils = Java.type("com.archimatetool.model.util.ArchimateModelUtils");

// For each element class get the user defined color (empty string if not set)
for(const element of ArchimateModelUtils.getAllArchimateClasses()) {
    const elementName = element.getName();
    const hexColorValue = Preferences.getString("defaultFillColour_" + elementName);
    console.log(elementName + ": " + hexColorValue);
}
Title: Re: Possible to get the Custom colors of a model ?
Post by: rchevallier on October 15, 2022, 14:42:00 PM
Thanks

It seems I was not clear enough for my demand: I was looking at the user custom color of the standard color chooser. Sorry about that

Ex: in Windows as attachment

My understanding they are saved by archi
Title: Re: Possible to get the Custom colors of a model ?
Post by: Phil Beauvoir on October 15, 2022, 20:25:22 PM
// Get the Archi bundle
const ArchiPlugin = Java.type("com.archimatetool.editor.ArchiPlugin");

// Get Archi's Preferences
const Preferences = ArchiPlugin.PREFERENCES;

const colorPaletteSize = 16; // 16 on Windows

for (let index = 0; index < colorPaletteSize; index++) {
    const hexColorValue = Preferences.getString("colorChooser_" + index);
    console.log(hexColorValue);
}

Title: Re: Possible to get the Custom colors of a model ?
Post by: rchevallier on October 16, 2022, 10:51:45 AM
Thanks. Have a nice weekend
Title: Re: Possible to get the Custom colors of a model ?
Post by: rchevallier on October 17, 2022, 10:44:16 AM
Just thinking, it seems the code I need to write already exists in Java in archimateTool.

const CustomColorDialog = Java.type("com.archimatetool.editor.ui.components.CustomColorDialog");
const dlg = new CustomColorDialog(shell);
const color = dlg.open();

I understand the class is not part of the public interface of Archi, and so may change without notice, but it will avoid reimplementing the exact same code in JavaScript