Funktion / Übersicht von SwingAnnotationFontFactory-Implementationen

SwingAnnotationFontFactory erweitert das AnnotationFontFactory-Interface um die Methode createAWTFont(FontAttributeSet fontAttributeSet), die aus einer FontAttributeSet-Definition einen passenden Java AWT Font erstellen soll. SwingAnnotationFontFactory-Implementationen werden verwendet um dem Schriftauswahldialog und dem Texteditor (beide Java AWT basierend) passende AWT Font-Instanzen zur Verfügung zu stellen.

Funktionsweise / Ablauf:

In der folgenden Übersicht wird das Zusammenspiel / Verhalten der GUI-Schriftauswahl und der SwingAnnotationFontFactory-Definition erläutert:

Definition der verwendeten SwingAnnotationFontFactory-Implementationen im Annotationsprofil:

<annotation-type name="BaseText" archetype="BaseText" class="com.levigo.jadice.annotation.TextAnnotation">
    ...
    <font-factory class="com.levigo.jadice.demo.font.annotation.SwingAnnotationProfileLogicalFontFactory"/>
    <font-factory class="com.levigo.jadice.demo.font.annotation.SwingAnnotationProfileStandard14FontFactory"/>
    <font-factory class="com.levigo.jadice.demo.font.annotation.SwingAnnotationProfileBasicFontFactory"/>
    ...
</annotation-type>

                    

Entsprechende Verwendung der SwingAnnotationFontFactory-Implementationen via Annotations-Klasse:

FontManagerFuture fontManagerFuture = SwingFontEnvironment.getFontManagerFuture();                        
Annotations.setDefaultAnnotationFontFactory(//
    new ChainedSwingAnnotationFontFactory(//
        new SwingAnnotationLogicalFontFactory(fontManagerFuture), //
        new SwingAnnotationStandard14FontFactory(fontManagerFuture), //
        new SwingAnnotationBasicFontFactory(fontManagerFuture) //
    )//
);

                    

Die Methode getAvailableFontAttributeSets() gibt folgende FamilyName-Attribute zurück:

Alle oben genannten Font-Family-Namen stehen dem Schriftauswahldialog und dem Texteditor zur Verfügung, d. h. die createAWTFont(FontAttributeSet fontAttributeSet)-Methode sollte auch entsprechende Java AWT Font-Instanzen erzeugen um eine korrekte Darstellung in den GUI-Editorkomponenten zu gewährleisten.

Schriftauswahldialog sieht wie folgt aus:

Arimo
Cousine
Dialog
DialogInput
Monospaced
SansSerif
Serif
Tinos

Die Fontauswahl kann im Annotationsprofil definiert / gefiltert werden:

  • Mit folgender Definition sind alle Fonts auswählbar:

    <annotation-type name="BaseText" archetype="BaseText" class="com.levigo.jadice.annotation.TextAnnotation">
        ...
        <unrestricted name="fontFace" propertyType="java.lang.String">
            <editor class="com.levigo.jadice.swing.internal.annotation.editors.FontFaceEditor" />
                <default>Sansserif</default>
        </unrestricted>
        ...
    </annotation-type>
    
                        
  • Mit folgender Einstellung können Fonts gezielt ausgewählt werden:

    <annotation-type name="BaseText" archetype="BaseText" class="com.levigo.jadice.annotation.TextAnnotation">
        ...
        <discrete name="fontFace" propertyType="java.lang.String">
    	    <editor class="com.levigo.jadice.swing.internal.annotation.editors.FontFaceEditor" />
            <default>Sansserif</default>
            <!-- Folgende Fonts sind auswählbar -->
            <allowed>Sansserif</allowed>
            <allowed>Serif</allowed>
            <allowed>Monospaced</allowed>
            <allowed>Arimo</allowed>
            <allowed>Cousine</allowed>
            <allowed>Tinos</allowed>
        </discrete>
        ...
    </annotation-type>
    
                        

Hier werden nur die mit dem allowed-Element definierten Font-Family-Namen im Schriftauswahldialog angezeigt:

Arimo
Cousine
Monospaced
SansSerif
Serif
Tinos

Die Fontdefinitionen werden im Schriftauswahldialog sortiert (alphanumerisch aufsteigend) angezeigt, ist eine Fontdefinition in den SwingAnnotationFontFactory-Implementationen nicht verfügbar, wird sie im Auswahlmenü ausgeblendet.

Wird ein Fontname aus der Liste ausgewählt, wird dieser der entsprechenden TextAnnotation-Instanz via setFontFace(String fontFace)-Methode gesetzt, beim darauf folgenden Darstellungs- / Rendervorgang wird aus dem Fontnamen und den Stilinformationen erneut eine Fontabfrage erstellt und ausgeführt (siehe „Aufbau und Funktion einer Fontabfrage“).

Die Implementationen im Paket com.levigo.jadice.appbase.annotation.font im jadice document platform 5 Swing-Appbase-Modul benötigen im Konstruktor eine FontManagerFuture-Instanz und können daher nicht im Annotationsprofil verwendet werden. Bei erfolgreicher Suche in der entsprechenden FontManager-Instanz wird ein Font-Objekt zurückgegeben. Diese Klassen stehen auch als Quellcode zur Verfügung. Die Implementationen werden aktuell in der SwingFontEnvironments-Klasse im Swing-Demo-Client-Modul verwendet.

  • SwingAnnotationBasicFontFactory

    Diese Klasse liefert eine vektorbasierte Font-Basisimplementation mit einem eingeschränkten Zeichensatz (a-z, A-Z, 0-9, Leerzeichen), es sind keine Sonderzeichen vorhanden. Die getAvailableFontAttributeSets()-Methode gibt eine leere Collection zurück. Die FontManagerFuture-Instanz muss die Standard-14 Fonts registriert haben, damit die createAWTFont(FontAttributeSet fontAttributeSet)-Methode eine passende Java AWT Font-Instanz erzeugen kann, hier wird immer der Standard-14-Font 'Arimo' zurückgegeben, ist ein anderer Font gewünscht, muss eine eigene Implementation erstellt werden.

  • SwingAnnotationLogicalFontFactory

    Diese Implementation löst logische Fontnamen nach jadice Standard-14 Fonts auf (siehe LogicalFontIdentifier, LogicalFontFactory), die getAvailableFontAttributeSets()-Methode stellt alle logische Fontdefinitionen zur Verfügung. Die benötigte FontManagerFuture-Instanz muss die Standard-14 Fonts registriert haben, die createAWTFont(FontAttributeSet fontAttributeSet)-Methode erstellt aus dem Standard-14 Fontdatenstrom eine Java AWT Font-Instanz.

  • SwingAnnotationStandard14FontFactory

    Diese Implementation löst alle jadice Standard-14 Fontnamen auf (siehe Standard14Substitute, Standard14FontFactory), die getAvailableFontAttributeSets()-Methode stellt alle Standard-14 Fontdefinitionen zur Verfügung. Die benötigte FontManagerFuture-Instanz muss die Standard-14 Fonts registriert haben, die createAWTFont(FontAttributeSet fontAttributeSet)-Methode erstellt aus dem Standard-14 Fontdatenstrom eine Java AWT Font-Instanz.

  • SwingAnnotationSystemFontFactory

    Diese Implementation versucht Fontnamen nach Systemfonts aufzulösen, die getAvailableFontAttributeSets()-Methode stellt alle System-Fontdefinitionen zur Verfügung. Die benötigte FontManagerFuture-Instanz muss System-Fonts registriert haben, die createAWTFont(FontAttributeSet fontAttributeSet)-Methode erstellt aus dem Font-Family-Namen eine passende Java AWT Font-Instanz.

  • SwingAnnotationGenericStylesSystemFontFactory

    Funktionsweise entspricht der SwingAnnotationSystemFontFactory-Implementation, die getAvailableFontAttributeSets()-Methode stellt nur System-Fontdefinitionen zur Verfügung, die die Stilarten plain / normal, bold / fett, italic / kursiv und bold-italic / fett-kursiv erfüllen.

  • ChainedSwingAnnotationFontFactory

    Diese Implementation fasst mehrere SwingAnnotationFontFactory-Instanzen zusammen, die getAvailableFontAttributeSets()-Methode stellt die Fontdefinitionen aus allen registrierten AnnotationFontFactory-Instanz zur Verfügung. Die createAWTFont(FontAttributeSet fontAttributeSet)-Methode gibt den ersten Treffer von den registrierten Instanzen zurück.

Die Implementationen im Paket com.levigo.jadice.demo.font.annotation im jadice document platform 5 Swing-Demo-Client-Modul besitzen einen Standardkonstruktor und können somit im Annotationsprofil verwendet werden, hier wird intern eine FontManagerFuture-Instanz mit Standard-14 / System-Fonts verwendet. Diese Klassen befinden sich in einem Demo-Modul, stehen als Quellcode zur Verfügung und sollten bei Verwendung kopiert und entsprechend angepasst werden, da sich der Quelltext der Klassen in Zukunft ändern kann.

[jadice document platform Version 5.6.10.6: Dokumentation für Entwickler. Veröffentlicht: 2024-01-18]