77
88/**
99 * Fest vorgegebene Textvorlagen für neu eingefügte Elemente (keine freie Eingabe).
10+ * Zwei Pakete — wie VisuStruct-SwiftUI: syntaxnahe Java-Vorgaben oder Begriffe gemäß Oberflächensprache.
1011 * Muss dieselbe Länge haben wie {@link EinstellungsDialog#anzahlStruktogrammElemente}.
1112 */
1213public final class ElementBeschriftungPresets {
1314
14- public static final int PRESET_KLASSISCH = 0 ;
15- public static final int PRESET_FORMAL = 1 ;
16- public static final int PRESET_JAVA_NA = 2 ;
17- /** Syntaxnahe Java-Vorgaben — Programm-Standard; neue Blöcke mit Platzhaltertext, Palette mit {@link #javaStandardPaletteButtonLabel(int)}. */
18- public static final int PRESET_ENGLISH_JAVA = 3 ;
19- /** Didaktische Begriffe gemäß UI-Sprache ({@link StructureElementI18n}). */
20- public static final int PRESET_DIDACTIC_I18N = 4 ;
21- public static final int ANZAHL_PRESETS = 5 ;
15+ /** Syntaxnahe Java-Vorgaben; Palette mit {@link #javaStandardPaletteButtonLabel(int)}. */
16+ public static final int PRESET_ENGLISH_JAVA = 0 ;
17+ /** Begriffe und Platzhalter gemäß gewählter Oberflächensprache ({@link StructureElementI18n}). */
18+ public static final int PRESET_DIDACTIC_I18N = 1 ;
19+ public static final int ANZAHL_PRESETS = 2 ;
2220
23- /**
24- * Reihenfolge im Dialog „Beschriftung (Struktogramm)“: zuerst Java (syntaxnah), danach
25- * {@link #PRESET_DIDACTIC_I18N} — Standardtexte in der <b>gewählten Oberflächensprache</b> —, dann die
26- * fest deutschsprachigen Pakete (Formal, Java-ähnlich, Klassisch).
27- */
2821 public static final int [] PRESET_DIALOG_REIHENFOLGE = {
2922 PRESET_ENGLISH_JAVA ,
3023 PRESET_DIDACTIC_I18N ,
31- PRESET_FORMAL ,
32- PRESET_JAVA_NA ,
33- PRESET_KLASSISCH ,
3424 };
3525
3626 private static final int N = 10 ;
3727
38- private static final String [][] PRESETS = {
39- {"Anweisung" , "Verzweigung" , "Fallauswahl" , "0 < i < anzahl" , "While Schleife" , "Do-While Schleife" ,
40- "Endlosschleife" , "Aussprung" , "Aufruf" , "\u00f8 " },
41- {"Anweisung" , "Verzweigung" , "Fallauswahl" , "Z\u00e4 hlergesteuerte Schleife" , "Kopfgesteuerte Schleife" ,
42- "Fu\u00df gesteuerte Schleife" , "Endlosschleife" , "Aussprung" , "Aufruf" , "Leeres Element" },
43- {"Anweisung" , "if (Verzweigung)" , "switch (Auswahl)" , "For Schleife" , "While Schleife" , "Do-While Schleife" ,
44- "Endlosschleife" , "Aussprung" , "Aufruf" , "Leeres Element" },
45- {"Statement" , "condition" , "selector" , "i = 0; i < n; i++" ,
46- "condition" , "condition" , "\u221e " , "break" , "method()" , "\u00f8 " },
28+ /** Standardtexte für {@link #PRESET_ENGLISH_JAVA} (Platzhalter in neuen Blöcken). */
29+ private static final String [] ENGLISH_JAVA_ROW = {
30+ "Statement" , "condition" , "selector" , "i = 0; i < n; i++" ,
31+ "condition" , "condition" , "\u221e " , "break" , "method()" , "\u00f8 " ,
4732 };
4833
4934 /**
50- * Nur Palette bei {@link #PRESET_ENGLISH_JAVA}: echte Java-Schlüsselwörter / übliche Kurzformen (nicht {@code condition} für alles).
51- * Reihenfolge = Elementtypen 0–9 wie {@link #PRESETS} .
35+ * Nur Palette bei {@link #PRESET_ENGLISH_JAVA}: echte Java-Schlüsselwörter / übliche Kurzformen
36+ * (nicht {@code condition} für alles) .
5237 */
5338 private static final String [] JAVA_STANDARD_PALETTE_LABELS = {
5439 "Statement" ,
@@ -64,25 +49,32 @@ public final class ElementBeschriftungPresets {
6449 };
6550
6651 static {
67- if (PRESETS .length != ANZAHL_PRESETS - 1 ) {
68- throw new IllegalStateException ("Preset-Anzahl" );
69- }
7052 if (PRESET_DIALOG_REIHENFOLGE .length != ANZAHL_PRESETS ) {
7153 throw new IllegalStateException ("Preset-Dialog-Reihenfolge" );
7254 }
7355 if (JAVA_STANDARD_PALETTE_LABELS .length != N ) {
7456 throw new IllegalStateException ("Java-Palette-L\u00e4 nge" );
7557 }
76- for (String [] row : PRESETS ) {
77- if (row .length != N ) {
78- throw new IllegalStateException ("Preset-L\u00e4 nge" );
79- }
58+ if (ENGLISH_JAVA_ROW .length != N ) {
59+ throw new IllegalStateException ("English-Java-Preset-L\u00e4 nge" );
8060 }
8161 }
8262
8363 private ElementBeschriftungPresets () {
8464 }
8565
66+ /**
67+ * Alte Einstellungen (0–4) aus {@code elementbeschriftungpreset} auf die zwei verbleibenden
68+ * Presets abbilden.
69+ */
70+ public static int migrateLegacyPresetIndex (int legacy ) {
71+ return switch (legacy ) {
72+ case 0 , 1 , 4 -> PRESET_DIDACTIC_I18N ;
73+ case 2 , 3 -> PRESET_ENGLISH_JAVA ;
74+ default -> PRESET_ENGLISH_JAVA ;
75+ };
76+ }
77+
8678 /** Gespeichertes Preset → Index der zugehörigen Radio-Option im Dialog. */
8779 public static int dialogPlatzFuerPreset (int presetIndex ) {
8880 for (int u = 0 ; u < PRESET_DIALOG_REIHENFOLGE .length ; u ++) {
@@ -110,30 +102,21 @@ public static String javaStandardPaletteButtonLabel(int typ) {
110102 }
111103
112104 public static String getPresetAnzeigename (int index ) {
113- switch (index ) {
114- case PRESET_KLASSISCH :
115- return I18n .tr ("elementPreset.classic" );
116- case PRESET_FORMAL :
117- return I18n .tr ("elementPreset.formal" );
118- case PRESET_JAVA_NA :
119- return I18n .tr ("elementPreset.javaLikeDe" );
120- case PRESET_ENGLISH_JAVA :
121- return I18n .tr ("elementPreset.englishJava" );
122- case PRESET_DIDACTIC_I18N :
123- return I18n .tr ("menu.settings.labelsStruktogramm" );
124- default :
125- return I18n .tr ("elementPreset.englishJava" );
126- }
105+ return switch (index ) {
106+ case PRESET_ENGLISH_JAVA -> I18n .tr ("elementPreset.englishJava" );
107+ case PRESET_DIDACTIC_I18N -> I18n .tr ("elementPreset.didacticUiLanguage" );
108+ default -> I18n .tr ("elementPreset.englishJava" );
109+ };
127110 }
128111
129112 public static String [] gibPresetZeile (int index ) {
130113 if (index == PRESET_DIDACTIC_I18N ) {
131114 return StructureElementI18n .didacticDefaultTexts ();
132115 }
133116 if (index < 0 || index >= ANZAHL_PRESETS ) {
134- return PRESETS [ PRESET_ENGLISH_JAVA ] ;
117+ return Arrays . copyOf ( ENGLISH_JAVA_ROW , N ) ;
135118 }
136- return PRESETS [ index ] ;
119+ return Arrays . copyOf ( ENGLISH_JAVA_ROW , N ) ;
137120 }
138121
139122 public static String [] kopierePreset (int index ) {
0 commit comments