Question about custom editor

I'm trying to create to some special concepts and editors for them, could you suggest what should I do?

1st concept: a set of 8 bits. The editor should allow to set/clear bits individually. Is there any way to specify that the number of 'bits' is not just N but exactly 8?

2st concept: a set of exactly 16 bytes. Ideally, an editor should allow editing all 16 bytes as a ASCII string, or as an array of decimal or hexadecimal numbers. Perhaps having such an aditor will require custom swing component - what about a concept? fixed-size arrays are quite common in many fields including mine.

0
3 comments
Avatar
Permanently deleted user

Igor Karpov wrote:

I'm trying to create to some special concepts and editors for them, could you suggest what should I do?

1st concept: a set of 8 bits. The editor should allow to set/clear bits individually. Is there any way to specify that the number of 'bits' is not just N but exactly 8?

2st concept: a set of exactly 16 bytes. Ideally, an editor should allow editing all 16 bytes as a ASCII string, or as an array of decimal or hexadecimal numbers. Perhaps having such an aditor will require custom swing component - what about a concept? fixed-size arrays are quite common in many fields including mine.

You can look at model access concept in editor language. It is available

in  layout in completion menu.

0
Avatar
Permanently deleted user

I suppose without at least a few lines of documentation it is not clear what to do.. First, I'm trying to start with defining a '16 bytes' concept and even this is not clear... Is there a way to do it?

0
Avatar
Permanently deleted user

Igor Karpov wrote:

I suppose without at least a few lines of documentation it is not clear what to do.. First, I'm trying to start with defining a '16 bytes' concept and even this is not clear... Is there a way to do it?

Now the best way to learn MPS is to read existing code.

For ideas of implementing your language you can look for structure,

editor, baseLanguage sturcture editor and generators. I recommend you

first looking at rather simple language such as structure or editor

language and move to more complex usch as baseLanguage,

collectionLanguage, modelQueryLanguage.

With your problem you can deal such a way. Create concept with string

property that we will use to store all 16 bytes. One character per byte.

When you will create editor select in cell layout cell_horizontal in it

select model acessor cell. choose create new query method. Type name in

IDEA something like this will appear :

   public static ModelAccessor createModelAccessor_Acess(SNode node)  {

     |

   }

ModelAcessor is interface that is responsible for modifieble cell with

text. To implement it you have to create 3 methods:

String getText(); returns text in model accessor.

void setText(String text); handles text change in cell after setting

text with this method editor will use getText to present updated text.

boolean isValidText(String text); Validates text. If text isn't valid

cell will be highlighted with red erorr color.

For you task such an implementation can be suitable

class MyModelAccessor implements ModelAccessor {

   private int myByteNumber;

   private SomeNode myNode;

   public String getText() {

     if (myNode.getText().length() <= myByteNumber) return "?";

     return "" + (int) myNode.getPropertyXXX().charAt(myByteNumber);

   }

   public void setText(String text) {

     int value = Integer.parseInt(text);

     String newText = myNode.getPropertyXXX().

     ...

   }

   public boolean isErrorText(String text) {

     ...

   }

}

0

Please sign in to leave a comment.