|
Letzte
Bearbeitung dieses Dokuments: |
Code
Erklärungen
und Anwendungsbeispiele
Verwandte
Dokumentation
package
js_base.frame;
import
java.awt.*;
import
java.awt.event.*;
import
java.net.*;
import
javax.swing.*;
import
js_base.bo.JSBS_BO;import
js_base.boc.JSBS_FramePosition_BOC;import
js_base.xml.JSBS_XML_ErrorMessages;
/**
*
* @author kurt[at]javascout(dot)biziz
*
@date 2008-08-04
*
* @description
* de: *
Frame zum Anzeigen einer Rückfrage an den Anwender wenn Daten
geändert aber nicht *
gespeichert wurden.
*
* Diese Klasse
kann 'konstruiert' werden wenn das Fenster geschlossen werden soll
oder *
die Daten eines anderen Datensatzes angezeigt werden sollen obwohl
die angezeigten *
Daten verändert und noch nicht gespeichert wurden.
*
*
Der Text zur Anzeige der Information wird aus der XML-Struktur in der
Datei
* 'ErrorMessages.xml' (im Verzeichnis TEXT.ln -
wobei ln durch den ISO-code der Sprache
* ersetzt
wird) gelesen.
* en: *
Frame to inform the user that displayed data was changed and not
already stored and to *
get a confirmation from the user what to do.
*
*
This class can be constructed when the window should be closed or
data of another dataset *
should be displayed and the already displayed data was changed and
not already saved.
*
* The informative text
is held in a XML-structure in the file named 'ErrorMessages.xml'
*
in the directory TEXT.ln (where ln is replaced by the ISO-code of the
language).
*
* @change-log
*
when who why
*
--------------------------------------------------------
*
*/public
class JSBS_UnstoredChangesDialog
extends
JDialog
implements
ActionListener,
KeyListener, WindowListener {/*
*
de: *
Referenz auf das 'Start-Frame', auch als 'CommandCenter' oder 'CC'
bezeichnet. *
Das 'CC' enthält die generellen Werte des
Anwendungsprogramms. *
en: *
Reference to the 'Start-Frame', also referred as 'Command-Center' or
'CC'.
* The 'CC' helds general values of the application.
*/
private
JSBS_StartFrame
frmCC
=
null;
/*
* de: *
Frame in dem das Ereignis ausgelöst wurde und welches gesperrt
ist *
solange dieser Dialog angezeigt wird. *
en: *
Frame where the Error- or Warning-Event was triggered and which is
locked
* as long as this Dialog is shown.
*/
private
JSBS_TaskFrame
frmParent
=
null;
/*
*
de: Variable die beim Aufrufen des 'Constructors' übergeben
wurden. *
en: Variables that are passed with the call of the constructor.
*/
private
boolean bol_Storeable;
/*
*
de: Wert mit der Auswahl des Anwenders (über die Schaltfläche)
in diesem Dialog. *
en: Values with the choice of the user (clicking a Button) in this
dialog. */
public
static
String CONST_PROCESS_STORE
=
"S";
public
static
String CONST_PROCESS_DISCARD
=
"D";
public
static
String CONST_PROCESS_BACK
=
"B"; public
String
strProcessIndicator
=
"";
/*
*
de: Text für den Hinweis an den Anwender (aus der Datei mit der
XML-Struktur). *
en: text with the information for the user (from the file with the
XML-structure). */
private
String
strUserInfoText
=
"";
/*
*
de: Name der Datei mit dem Graphischen Symbol für die
Schaltfläche 'btn_WarningIcon'. *
en: Name of the file with the Icon for the Button 'btn_WarningIcon'.
*/
private
String
strIconFileNameIncludingDirectory
=
"";
/*
*
de:
* Text der in der 'Title-Bar' des aufrufenden Frames
angezeigt wird.
* Als Teil der Information angezeigt, die
dem Anwender Hinweise gibt, welches Frame
* betroffen ist
wenn er das gesamte Anwendungsprogramm beendet und damit die noch
*
offenen Task-Frames automatisch geschlossen werden. *
en:
* Text of the 'Title-Bar' of the calling Frame.
*
Shown as part of the Information to give the user guidance, which
frame ist concerned
* when he closes the whole application
and thereby open task-frames automatically.
*/
private
String
strCallingFrameTitleBarText
=
"";/*
*
de:
* Schaltfläche die 'angeklickt' wird wenn die
Eingabe-Taste auf der Tastatur
* betätigt wird.
*
Diese Variable kann dynamisch durch das Anwendungsprogramm mit einem
Wert versorgt
* werden und damit kann dem Anwender
signalisiert werden welche Schaltfläche als
* nächstes
empfohlen wird.
* en:
* Button that is 'clicked'
when the Enter-Key on the keyboard is pressed.
* This
variable can be dynamically filled by the application to guide the
user
* what button is recommended to be used next.
*/ private
JButton
btnEnterTriggeredButton
=
null;
/*
*
de:
* Flags (Merker) zum merken ob 'Modifier'-Tasten (Alt,
Steuerung, Umschalten)
* betätigt wurden,
*
Diese Merker werden gebraucht weil Tasten-Kombinationen
'hintereinander' von der
* Tastatur an das
Anwendungsprogramm 'geliefert' werden
* en:
* Flags
to keep if 'modifier'-keys were typed.
* Those flags are
necessary as key-combinations are delivered from the keyboard *
to
the application
as
sequential key-strokes. */
private
boolean
bolAltKeyModifier
=
false;
private
boolean
bolCtrlKeyModifier
=
false; private
boolean
bolShiftKeyModifier
=
false;/*
*
de:
* Business-Object, dass die Information über Größe
(Breite, Höhe) und Position
* (Abstand zwischen linker
oberer Ecke des Monitors und linker oberer Ecke des Frames)
*
in Bildpunkten speichert.
* Weiters enthält dieses BO
10 Arrays für die Aufnahme von Spaltenbreiten von JTables.
*
Diese Struktur kann von Task-Frames, die von dieser Basisklasse
erben, verwendet werden.
* en: *
Business-Object that stores the information about the Frame-Size
(width, height)
* and Position (distance between the
upper-left corner of the frame from the
* upper-left corner
of the display-screen) in pixels.
* Further, this BO holds
10 arrays to describe the column-widths of JTables.
* Those
structure can be utilized by Task-Frames inheriting this base-class.
*/ public
JSBS_FramePosition_BOC
structJSBS_FramePosition_BOC;
/*
*
de: GUI-Elemente für das Layout des Dialogs. *
en: GUI-elements for the layout of the dialog. */ protected
JPanel
pnl_Main; protected
JScrollPane pnl_UserInfoScroll; protected
JTextArea
txt_UserInfo; protected
JButton
btn_WarningIcon; protected
JButton
btn_Back; protected
JButton
btn_Store; protected
JButton
btn_Discard;/*
*
-------------------------------
* de: Constructor dieser
Klasse. *
en: Constructor of this class. */ public
JSBS_UnstoredChangesDialog(JSBS_TaskFrame
parmParent, boolean parmStoreable) {/*
*
de:
* Superklasse verwenden um diesen Dialog an ein Frame zu
binden und den Dialog
* 'modal' zu machen. 'Modal'
bedeutet, dass das Frame für Eingaben des Benutzers
*
'gesperrt' ist solange der Dialog angezeigt wird.
* en: *
Use the superclass to 'attach' this Dialog to a Frame and make it
'modal'.
* 'Modal' means, that the Frame is 'locked' (for
user-entries) while the Dialog
* is shown.
*/
super(parmParent,
true);/*
*
de: Übertragen der als Parameter übergebenen Werte auf die
Variablen dieser Klasse. *
en: Transfer the values passed as parameters to the variables of this
class. */ frmCC
=
parmParent.frmCC; frmParent
=
parmParent; bol_Storeable
=
parmStoreable;/*
*
de: *
Setzen einer Standard-Auswahl für den Fall, dass der Anwender
das Dialog-Fenster *
schließt ohne eine Auswahl per Schaltfläche gewählt
zu haben. *
en: *
Set a selection for the case that the user closes the Dialog-window
without clicking *
a Button for a choice. */ if
(bol_Storeable) strProcessIndicator
= CONST_PROCESS_STORE; else
strProcessIndicator
= CONST_PROCESS_DISCARD;/*
*
de: Starten der Verarbeitung des Codes *
en: Start processing of the code.
*/ initialize_before_frame(); initialize_frame(); initialize_after_frame();
}
/*
*
-------------------------------
* de: Methode mit dem Code
der ausgeführt wird bevor die GUI aufgebaut wird. *
en: Method with code that is executed before the GUI is built.
*/ private
void initialize_before_frame()
{/*
* de:
* 'Konstruieren' des BOC mit den
Positions-Informationen des Fensters
* und bestimmter
GUI-Elemente (z.B. die Breite der Spalten in einer JTable).
*
en:
* 'Construct'
the
BOC containing Position-informations of the frame
* and
certain GUI-Elements (e.g. column-size within a JTable). */
structJSBS_FramePosition_BOC
=
new
JSBS_FramePosition_BOC(frmParent);
}/*
*
de: Methode mit dem Code zum Aufbau der Benutzer-Oberfläche
(GUI).
*
en: Method with code to build the User-Interface (GUI).
*/ private
void initialize_frame()
{/*
* de: Fenster ('Dialog') mit der GUI 'bauen'.
*
en: Build the GUI-window ('Dialog'). */ setSize(700,
550);
setContentPane(get_pnl_Main());/*
* de:
* Bearbeiten der GUI-Elemente mit den
sprach-spezifischen Texten und
*
anderen
Layout-Spezifikationen.
* en:
*
Process
the GUI-Elements with the language-specific texts and other
*
layout-specifications.
*/ JSBS_GUIServices.processLanguageDependantElements(frmCC,
this); JSBS_GUIServices.setButtonBorders(get_pnl_Main(),frmCC.structJSBS_UniversalParameters); JSBS_GUIServices.setPanelBorders(get_pnl_Main(),frmCC.structJSBS_UniversalParameters);/*
* de: Informations-Text auf die GUI-Elemente
übertragen.
* en: Transfer the information-text
to the GUI-elements. */ fillGUIElementsWithValues();/*
* de: Schaltfläche, die durch die 'Eingabe'-Taste
ausgelöst wird festlegen und Rand färben.
* en:
Define the Button that is triggered by the 'Enter'-Key and color the
border. */ btnEnterTriggeredButton
=
get_btn_Back(); JSBS_GUIServices.setButtonBorders(get_pnl_Main(),
frmCC.structJSBS_UniversalParameters,
get_btn_Back());/*
* de: Listeners zu den GUI-Elementen hinzufügen.
*
en: Add the Listeners to the GUI-elements.
*/ addListeners(get_pnl_Main());/*
* de: Größe und Position des Fenster beim
letzten Schließen wieder herstellen.
*
en: Restore size and position at the time of last closing. */
setFramePosition();/*
* de: Dialog anzeigen.
*
en: Show the Dialog. */ setVisible(true); }/*
*
de: Methode mit dem Code der nach der Anzeige der GUI ausgeführt
wird. *
en: Method with code to be processed after the GUI was shown.
*/ private
void initialize_after_frame()
{/*
* Will
contain the processing for writing to the Log-File.
*/ }/*
* ********************
*
de: GUI-Elemente erstellen.
*
en: Create the GUI-elements. */ protected
JPanel
get_pnl_Main() {/*
Auto-create the GUI-element if it does not already exist. */
if
(pnl_Main
==
null)
{ try
{
pnl_Main
=
new
JPanel();
pnl_Main.setName("pnl_Main");
pnl_Main.setLayout(new
GridBagLayout());/*
*
Define GridBagConstraints for the element to be added.
*/ GridBagConstraints
gbc_pnl_UserInfoScroll = new
GridBagConstraints();
gbc_pnl_UserInfoScroll.gridx
=
0;
gbc_pnl_UserInfoScroll.gridy
=
0;
gbc_pnl_UserInfoScroll.gridwidth
=
2;
gbc_pnl_UserInfoScroll.gridheight
=
6; gbc_pnl_UserInfoScroll.fill
=
GridBagConstraints.BOTH;
gbc_pnl_UserInfoScroll.weightx
=
5;
gbc_pnl_UserInfoScroll.weighty
=
0;
gbc_pnl_UserInfoScroll.anchor
=
GridBagConstraints.CENTER;
gbc_pnl_UserInfoScroll.insets
=
new
Insets(3,3,3,3);/*
Add the element to the panel; element-position is controlled by
GridBagConstraints.
*/ get_pnl_Main().add(get_pnl_UserInfoScroll(), gbc_pnl_UserInfoScroll);/*
*
Define GridBagConstraints for the element to be added.
*/ GridBagConstraints
gbc_btn_WarningIcon = new
GridBagConstraints();
gbc_btn_WarningIcon.gridx
=
2;
gbc_btn_WarningIcon.gridy
=
0;
gbc_btn_WarningIcon.gridwidth
=
1;
gbc_btn_WarningIcon.gridheight
=
3;
gbc_btn_WarningIcon.fill
=
GridBagConstraints.BOTH;
gbc_btn_WarningIcon.weightx
=
1;
gbc_btn_WarningIcon.weighty
=
1;
gbc_btn_WarningIcon.anchor
=
GridBagConstraints.CENTER;
gbc_btn_WarningIcon.insets
=
new
Insets(3,3,3,3);/*
Add the element to the panel; element-position is controlled by
GridBagConstraints.
*/ get_pnl_Main().add(get_btn_WarningIcon(),
gbc_btn_WarningIcon);/*
*
Define GridBagConstraints for the element to be added.
*/ GridBagConstraints
gbc_btn_Back = new
GridBagConstraints();
gbc_btn_Back.gridx
=
2;
gbc_btn_Back.gridy
= 3;
gbc_btn_Back.fill
=
GridBagConstraints.BOTH;
gbc_btn_Back.weightx
=
1;
gbc_btn_Back.weighty
=
1;
gbc_btn_Back.anchor
=
GridBagConstraints.CENTER;
gbc_btn_Back.insets
=
new
Insets(3,3,3,3);/*
Add the element to the panel; element-position is controlled by
GridBagConstraints. */ get_pnl_Main().add(get_btn_Back(),
gbc_btn_Back);/*
*
Define GridBagConstraints for the element to be added.
*/ GridBagConstraints
gbc_btn_Store = new
GridBagConstraints();
gbc_btn_Store.gridx
=
2;
gbc_btn_Store.gridy
= 4;
gbc_btn_Store.fill
=
GridBagConstraints.BOTH;
gbc_btn_Store.weightx
=
1;
gbc_btn_Store.weighty
=
1;
gbc_btn_Store.anchor
=
GridBagConstraints.CENTER;
gbc_btn_Store.insets
=
new
Insets(3,3,3,3);/*
Add the element to the panel; element-position is controlled by
GridBagConstraints. */ get_pnl_Main().add(get_btn_Store(),
gbc_btn_Store);/*
*
Define GridBagConstraints for the element to be added.
*/ GridBagConstraints
gbc_btn_Discard = new
GridBagConstraints();
gbc_btn_Discard.gridx
=
2;
gbc_btn_Discard.gridy
=
5;
gbc_btn_Discard.fill
=
GridBagConstraints.BOTH;
gbc_btn_Discard.weightx
=
1;
gbc_btn_Discard.weighty
=
1;
gbc_btn_Discard.anchor
=
GridBagConstraints.CENTER;
gbc_btn_Discard.insets
=
new
Insets(3,3,3,3);/*
Add the element to the panel; element-position is controlled by
GridBagConstraints.
*/ get_pnl_Main().add(get_btn_Discard(),
gbc_btn_Discard);
}
catch
(Throwable
Exc) {
System.out.println("Error
while building pnl_Main in class
JSBS_UnstoredChangesDialog");
Exc.printStackTrace();
}
} return
pnl_Main; }
/*
* ********************
*/ public
JScrollPane
get_pnl_UserInfoScroll() {/*
Auto-create the GUI-element if it does not already exist. */
if
(pnl_UserInfoScroll
==
null)
{ try
{
pnl_UserInfoScroll
=
new
JScrollPane();
pnl_UserInfoScroll.setName("pnl_UserInfoScroll"); pnl_UserInfoScroll.setAutoscrolls(true); pnl_UserInfoScroll.setMinimumSize(new
Dimension(200,100));
pnl_UserInfoScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
pnl_UserInfoScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); pnl_UserInfoScroll.setEnabled(false); pnl_UserInfoScroll.setViewportView(get_txt_UserInfo()); }
catch
(Throwable
Exc) {
System.out.println("Error
while building pnl_UserInfoScroll
in
class
JSBS_UnstoredChangesDialog");
Exc.printStackTrace();
}
} return pnl_UserInfoScroll; }
/*
* ********************
*/ public
JTextArea
get_txt_UserInfo() {/*
Auto-create the GUI-element if it does not already exist. */
if
(txt_UserInfo
==
null)
{ try
{
txt_UserInfo
=
new
JTextArea();
txt_UserInfo.setName("txt_UserInfo");
txt_UserInfo.setMinimumSize(new
Dimension(300,200));/*
Do not allow editing of the element as it is intended for display
only.
*/ txt_UserInfo.setEditable(false); }
catch
(Throwable
Exc) {
System.out.println("Error
while building txt_UserInfo in class
JSBS_UnstoredChangesDialog");
Exc.printStackTrace();
}
} return
txt_UserInfo; }
/*
* ********************
*/ public
JButton
get_btn_WarningIcon() {/*
Auto-create the GUI-element if it does not already exist. */
if
(btn_WarningIcon
==
null)
{ try
{
btn_WarningIcon
=
new
JButton();
btn_WarningIcon.setName("btn_WarningIcon");/*
de: Bei dieser Schaltfläche den Text unterhalb des Graphischen
Symbols (Icons) platzieren. *
en: Place the text below the Icon at this button.
*/
btn_WarningIcon.setVerticalAlignment(SwingConstants.TOP);
btn_WarningIcon.setHorizontalAlignment(SwingConstants.CENTER);
btn_WarningIcon.setVerticalTextPosition(SwingConstants.BOTTOM);
btn_WarningIcon.setHorizontalTextPosition(SwingConstants.CENTER);/*
de: Bei einem Mausklick auf diese Schaltfläche einen ActionEvent
auslösen. *
en: Trigger an ActionEvent when this button is clicked with the
mouse.
*/
btn_WarningIcon.setActionCommand("btn_WarningIcon");
btn_WarningIcon.addActionListener(this); }
catch
(Throwable
Exc) {
System.out.println("Error
while building btn_WarningIcon in class
JSBS_UnstoreChangesDialog");
Exc.printStackTrace();
}
} return
btn_WarningIcon; }
/*
* ********************
*/ public
JButton
get_btn_Back() {/*
Auto-create the GUI-element if it does not already exist. */
if
(btn_Back
==
null)
{ try
{
btn_Back
=
new
JButton();
btn_Back.setName("btn_Back");
btn_Back.setHorizontalAlignment(SwingConstants.LEADING);
btn_Back.setActionCommand("btn_Back");
btn_Back.addActionListener(this); }
catch
(Throwable
Exc) {
System.out.println("Error
while building btn_Back
in
class
JSBS_UnstoreChangesDialog");
Exc.printStackTrace();
}
} return
btn_Back; }
/*
* ********************
*/ public
JButton
get_btn_Store() {/*
Auto-create the GUI-element if it does not already exist. */
if
(btn_Store
==
null)
{ try
{
btn_Store
=
new
JButton();
btn_Store.setName("btn_Store");
btn_Store.setHorizontalAlignment(SwingConstants.LEADING);
btn_Store.setActionCommand("btn_Store");
btn_Store.addActionListener(this); }
catch
(Throwable
Exc) {
System.out.println("Error
while building btn_Store in class
JSBS_UnstoreChangesDialog");
Exc.printStackTrace();
}
} return
btn_Store; }
/*
* ********************
*/ public
JButton
get_btn_Discard() {/*
Auto-create the GUI-element if it does not already exist. */
if
(btn_Discard
==
null)
{ try
{
btn_Discard
=
new
JButton();
btn_Discard.setName("btn_Discard");
btn_Discard.setHorizontalAlignment(SwingConstants.LEADING);
btn_Discard.setActionCommand("btn_Discard");
btn_Discard.addActionListener(this); }
catch
(Throwable
Exc) {
System.out.println("Error
while building btn_Discard
in
class
JSBS_UnstoreChangesDialog");
Exc.printStackTrace();
}
} return
btn_Discard; }/*
*
de:
* Methode um die GUI-Elemente mit den individuellen
Werten zu füllen.
* Anschließend werden die
Verarbeitungen, die nach dem Aufbau der GUI notwendig sind
*
ausgeführt. *
en:
* Method to fill the GUI-elements with individual
values.
* Thereafter follows the processing that has to be
done after the GUI is built.
*/ private
void fillGUIElementsWithValues()
{/*
* de: Text der Title-Bar aus dem als Parameter übergebenen
Task-Frame holen.
*
en: Get the text of the Title-Bar from the Task-Frame passed as
parameter. */
strCallingFrameTitleBarText
= frmParent.getTitle();/*
*
de: Initialisieren der XML-Struktur mit den Fehler- und
Warn-Hinweisen. *
en: Initialize the XML-structure with Error- and Warning-Messages.
*/
JSBS_XML_ErrorMessages
structJSBS_XML_ErrorMessages =
new
JSBS_XML_ErrorMessages(frmCC);/*
*
de: Prüfen ob die XML-Struktur ohne Fehler konstruiert wurde. *
en: Verify if the XML-structure was constructed without an error.
*/ if
(structJSBS_XML_ErrorMessages.StatusCode
==
structJSBS_XML_ErrorMessages.CONST_OK)
{/*
*
de:
*
Abhängig vom Parameter ob die geänderten Daten fehlerfrei
sind und gespeichert werden können:
*
Erklärungs-Text für die Schaltflächen holen.
*
en:
*
Depending on the parameter if the changed data are error-free and can
be stored:
* Fetch the explanatory text for the
Buttons. */ if
(bol_Storeable)
strUserInfoText
=
structJSBS_XML_ErrorMessages.getStoreableExplanationText();
else
strUserInfoText
=
structJSBS_XML_ErrorMessages.getNotStoreableExplanationText();
}
else
{/*
* de: XML-Struktur konnte nicht geladen werden;
Minimal-Nachricht anzeigen.
*
en: XML-structure could not be loaded; show minimum-message.
*/
strUserInfoText
=
"Unable
to load file with Error-Messages";
}/*
* de: Integrieren des Title-Bar-Textes des aufrufenden
Frames.
*
en: Integrate the Title-Bar-Text of the calling frame. */
integrateTitleBarTextIntoMessageText();/*
* de: Übertragen des Textes in das GUI-Element.
*
en: Transfer the text to the GUI-Element.
*/ JSBS_GUIServices.setStringWithNewLineToJTextArea(get_txt_UserInfo(),
strUserInfoText);/*
*
de: Prüfen ob die XML-Struktur ohne Fehler konstruiert wurde. *
en: Verify if the XML-structure was constructed without an error.
*/ if
(structJSBS_XML_ErrorMessages.StatusCode
==
structJSBS_XML_ErrorMessages.CONST_OK)
{/*
* de:
* Datei-Name für das Graphische Symbol
zur Anzeige auf 'btn_WarningIcon' aus der
* XML-Struktur
auslesen.
*
en:
* Get the file-name for the Icon to be displayed on
'btn_WarningIcon' out of the
* XML-structure. */
strIconFileNameIncludingDirectory
=
structJSBS_XML_ErrorMessages.getWarningIconFileName();/*
*
de:
*
Wenn ein Wert für den Datei-Namen zurück geliefert wurde
dann erweitern des Datei-Namens
*
um das komplette Verzeichnis und Anzeigen des Graphischen Symbols auf
der Schaltfläche.
* en:
*
If a value for the file-name was returned then extend the file-name
by the complete
* directory and display of the Icon on the
Button. */ if
(strIconFileNameIncludingDirectory.length()
> 0) {
strIconFileNameIncludingDirectory
=
frmCC.structJSBS_UniversalParameters.strGraphicElementsDirectoryName
+
strIconFileNameIncludingDirectory;
get_btn_WarningIcon().setIcon(new
ImageIcon(strIconFileNameIncludingDirectory));
}
}/*
*
de:
* Wenn die Daten nicht gespeichert werden können
dann wird die Schaltfläche btn_Store inaktiviert. *
en:
* If the data can not be stored then the button
btn_Store is disabled.
*/ get_btn_Store().setEnabled(bol_Storeable);
}/*
*
de:
* Methode um den Text aus der Title-Bar des
verursachenden Task-Frame in die Nachricht an
* den
Anwender zu integrieren.
* Damit wird beim automatischen
Schliessen der Frames dem Anwender mitgeteilt, welches Frame
*
nicht automatisch geschlossen werden kann. *
en:
* Method to integrate the text of the Title-Bar of the
Task-Frame causing this Dialog in
* the message-text
presented to the user.
* If the frames are closed
automatically, the the user gets a clue which frame can not be
*
closed automatically.
*/ private
void integrateTitleBarTextIntoMessageText()
{/*
*
de:
* Ersetzen in einer for-Schleife weil für einen
Parameter auch mehrere Platzhalter
*
erlaubt sind.
* Zuerst wird ein Flag gesetzt das
signalisiert, ob der Parameter-Wert in den Text
*
eingefügt wurde oder nicht.
*
en:
* Replacement within a for-loop because for one
parameter there is more than
*
one placeholder allowed.
*
First, a flag is set signalling if the parameter-value is already
inserted into
*
the text.
*/ boolean bolNotAlreadyReplaced
= true; String
strPlaceholder = "%FrameTitle%"; for (;;)
{/*
* de: Prüfen ob ein 'Platzhalter' vorhanden ist.
*
en: Check if a 'placeholder' is present. */
int
intPlaceholderIndex
= strUserInfoText.indexOf(strPlaceholder);
if
(intPlaceholderIndex
>= 0) {/*
* de: Fehler-Text in 2 Teile aufteilen und den
'Platzhalter' entfernen.
* en: Split error-text into 2
parts to eliminate 'placeholder' string. */
String
strLeftPart =
strUserInfoText.substring(0,
intPlaceholderIndex);
String
strRightPart =
strUserInfoText.substring(intPlaceholderIndex
+ strPlaceholder.length());/*
*
de: Zusammensetzen mit dem Parameter-Wert.
*
en: Concatenate including parameter-value. */
strUserInfoText
=
strLeftPart + strCallingFrameTitleBarText
+
strRightPart; /*
*
de: Flag signalisieren lassen, dass der Parameter-Wert bereits
eingefügt wurde.
*
en: Let the flag signal that the parameter-value
was
already inserted. */
bolNotAlreadyReplaced =
false;
}
else
{/*
*
de:
*
Platzhalter nicht gefunden; Wert des Parameters in einer neuen Zeile
anhängen.
* Aber nur wenn der Wert noch nicht in den
Text eingefügt wurde und der Parameter
* auch einen
Text enthält.
*
en:
*
Placeholder not found; append value in a new line.
* But
do this only if the parameter-value was not already inserted into the
text and the
* value contains text. */
if
(bolNotAlreadyReplaced
&& (strCallingFrameTitleBarText.trim().length()
> 0)) {
strUserInfoText
+=
"\n"
+ strCallingFrameTitleBarText;
}/*
*
de: for-Schleife abbrechen.
*
en: End the for-loop. */
break;
} } }/*
*
-------------------------------
* de:
* Methode,
die den KeyListener zu einem GUI-Element und
allen
seinen untergeordneten
* Komponenten hinzufügt.
*
Diese Methode untersucht jeden 'Conteiner' auf untergeordnete
Komponenten und für jede
* gefundene Komponente ruft
sich diese Methode selbst auf und übergibt die Komponente als
*
Parameter.
*
* en:
* Method that adds the
KeyListener to a GUI-element and all its subordinate
components.
* This method inspects each 'Container' for
components and calls itself for each component
* and passes
that component as parameter. */ private
void addListeners(Container
parmContainer) {
/*
de: KeyListener werden zu jedem Typ eines
GUI-Elementeshinzugefügt.
* en: KeyListener are added
to any type of a GUI-element.
*/
parmContainer.addKeyListener(this);
/*
de:
* Untersuchen ob der 'Container' weitere Komponenten
enthält. Wenn Komponenten in diesem
* 'Container'
vorhanden sind, dann diese Methode rekursiv für jeden
'Container' aufrufen.
* en:
* Inspect if the
'Container' has components in it. If there are components
* within
this 'Container', call this method recursively for each of it.
*/
Component
comps[] = parmContainer.getComponents();
for(int
i
= 0; i < comps.length;
i++) {
Component
comp = comps[i];
addListeners((Container)
comp);
} }/*
*
-------------------------------
* de:
* Methoden
die zusammen mit der Interface KeyListener implementiert werden
müssen.
* Wenn eine Methode dieser Basis-Klasse Code
enthält und diese Methode in einer
* abgeleiteten
Klasse überschrieben werden muß, dann muß die
Methode dieser
* Basis-Klasse auf folgende Weise aufgerufen
werden:
* super.keyPressed(e);.
* en:
*
Methods that are requiered together with the interface
KeyListener.
* If a method of this base-class contains
code and has to be overwritten
* in the derived class, the
method in this base class has to be called in the * overwriting
method like this example:
* super.keyPressed(e);.
*/ public
void keyPressed(KeyEvent
e) {/*
de:
* Diese Methode wird verwendet um zu prüfen ob eine
Funktionstaste (der Tastatur)
* betätigt wurde.
*
en:
* This method is used to check if a Function-Key (of the
keyboard) was pressed. */
/* de:
* Zeichenkette die den
internen Tastatur-Code enthalten wird. Das ist jener Code
*
der innerhalb des JavaScout Fat-Client-Framework (JS-FCF) verwendet
wird.
* en:
* String that will contain the Internal
Key-Code. That ist the code that is
* used within the
JavaScout Fat-Client-Framework (JS-FCF). */ String
strInternalKeyCode = "";/*
de: Flag ob eine Funktionstaste (F1 bis F12) betätigt wurde.
*
en: Flag to indicate if a Function-Key (F1 to F12) was pressed.
*/ boolean bolFunctionKeyPressed
= false;/*
de: Den Java-internen Tastatur-Code aus dem KeyEvent ermitteln.
*
en: Derive the Java-internal key-code from the KeyEvent. */ int
intKeyCode
= e.getKeyCode();/*
de:
* Untersuchen des Key-Events ob die 'Enter'- (Eingabe-)
Taste betätigt wurde.
* Diese simuliert einen Mausklick
auf eine definierte Schaltfläche (JButton).
* en:
*
Inspect the Key-Event if the 'Enter'-Key was pressed. This key
simulates
* a mouse-click to the defined 'JButton'.
*/ if
(intKeyCode
== KeyEvent.VK_ENTER)
{/*
de:
* 'Eingabe'- (Enter-) Taste gedrückt; prüfen
ob dieser eine Schaltfläche
* (JButton) zugeordnet
ist.
* en: Enter-key was pressed; verify if a Button is
attached to the Enter-key. */
if
(btnEnterTriggeredButton
!=
null)
{/*
de:
* Schaltfläche (JButton) ist zugeordnet; Prüfen
ob er 'enabled' ist und dann
* den 'Mausklick'
simulieren.
* en: JButton is defined, see if the Button is
enabled and simulate the 'click'. */
if
(btnEnterTriggeredButton.isEnabled())
{
btnEnterTriggeredButton.doClick();
e.consume();
}
/*
de: Schaltfläche nicht 'enabled'; einen 'Beep' zur Warnung
ausgeben.
* en: Button not enabled; produce a beep to warn
the user. */
else getToolkit().beep();/*
de: Aufgabe der Methode erfüllt; Methode beenden.
* en:
Mission of this method completed; end the method. */
return;
}
}/*
de:
* Untersuchen des Key-Events ob eine 'Modifier'-Taste
betätigt wurde.
* Nur so ist eine Prüfung
unabhängig von Betriebssystem und gewählter
*
Sprache möglich.
* en:
* Inspect the
Key-Event if a 'Modifier'-Key was pressed. This code is the only
*
way to check independent from operating system and chosen language.
*/ if
(intKeyCode
== KeyEvent.VK_ALT)
{ bolAltKeyModifier
= true;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_CONTROL)
{ bolCtrlKeyModifier
= true;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_SHIFT)
{ bolShiftKeyModifier
= true;
e.consume();
}/*
de:
* Wenn 'Modifier'-Tasten gedrückt sind dann den
internen Code für diese jetzt in
* die Zeichenkette
für den Internen Key-Code einfügen.
* en:
*
If 'Modifier'-keys are pressed then insert the internal code for them
* now to the string for the Internal Key-Code. */ if
(bolAltKeyModifier)
strInternalKeyCode += "Alt-"; if
(bolCtrlKeyModifier)
strInternalKeyCode += "Ctrl-"; if
(bolShiftKeyModifier)
strInternalKeyCode += "Shift-";/*
de:
* Untersuchen des Key-Events ob eine Funktionstaste
betätigt wurde.
* Nur so ist eine Prüfung
unabhängig von Betriebssystem und gewählter
*
Sprache möglich.
* en:
* Inspect the
Key-Event if a Function-Key was pressed. This code is the only
*
way to check independent from operating system and chosen language.
*/ if
(intKeyCode
== KeyEvent.VK_F1)
{
strInternalKeyCode
+= "F1"; bolFunctionKeyPressed
= true;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_F2)
{
strInternalKeyCode
+= "F2"; bolFunctionKeyPressed
= true;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_F3)
{
strInternalKeyCode
+= "F3"; bolFunctionKeyPressed
= true;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_F4)
{
strInternalKeyCode
+= "F4"; bolFunctionKeyPressed
= true;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_F5)
{
strInternalKeyCode
+= "F5"; bolFunctionKeyPressed
= true;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_F6)
{
strInternalKeyCode
+= "F6"; bolFunctionKeyPressed
= true;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_F7)
{
strInternalKeyCode
+= "F7"; bolFunctionKeyPressed
= true;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_F8)
{
strInternalKeyCode
+= "F8"; bolFunctionKeyPressed
= true;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_F9)
{
strInternalKeyCode
+= "F9"; bolFunctionKeyPressed
= true;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_F10)
{
strInternalKeyCode
+= "F10"; bolFunctionKeyPressed
= true;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_F11)
{
strInternalKeyCode
+= "F11"; bolFunctionKeyPressed
= true;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_F12)
{
strInternalKeyCode
+= "F12"; bolFunctionKeyPressed
= true;
e.consume();
}/*
de: *
Wenn kein definierter 'Virtual-Key' für eine Funktionstaste
gedrückt wurde *
dann wird der Internal Key-Code mit der in Java festgelegten
Bezeichnung
* für die Taste gebildet. Diese Bezeichnung
der Taste kann vom Betriebssystem
* oder der gewählten
Sprache abhängen.
* en:
* If no defined
'Virtual-Key' for a Function-Key was pressed then the
*
Internal Key-Code is build with the Java-defined Text of the key.
*
This text might depend on the operating system or chosen language.
*/ if (!
bolFunctionKeyPressed)
strInternalKeyCode += KeyEvent.getKeyText(intKeyCode);/*
de:
* Untersuchen der XML-Struktur ob ein ButtonName dem
Internal Key-Code
* zugeordnet ist.
* en:
*
Inspect the XML-structure if a ButtonName is associated with the
*
Internal Key-Code. */
String
strButtonName
= frmCC.structJSBS_XML_FunctionKeys.getButtonName(
this.getClass().getName(),
strInternalKeyCode);/*
de:
* Wenn ein 'ButtonName' gefunden wurde dann wird die
Methode aufgerufen,
* die unter den GUI-Elementen den
'JButton' mit dem passenden Namen sucht
* und einen
'Mausklick' auf diesen 'JButton' simuliert.
* en:
*
If a 'ButtonName' was found then the method is called to find
the 'JButton'
* with the fitting ButtonName amongst the
GUI-Elements and simulate a 'mouse-click'
* on that
'JButton'. */ if
(strButtonName.length()
> 0) { JSBS_GUIServices.clickButton(this.getContentPane(),
strButtonName);/*
de:
* 'Consume' (Verbrauchen) des
KeyEvent
damit er nichts anderes auslöst.
* en:
*
'Consume' the KeyEvent so it can not trigger something esle.
*/ e.consume(); }
} public
void keyReleased(KeyEvent
e) {/*
de:
* Diese Methode setzt die Markierungen für die
Midifier-Tasten (Alt, Steuerung,
* Umschalten) zurück.
*
Zuerst wird der numerische Tastatur-Code ermittelt und dieser wird
dann mit
* dem 'Virtual-Key' verglichen.
*
Der Vergleich mit dem 'Virtual Key' liefert ein eindeutiges Ergebnis
das nicht
* vom verwendeten Betriebssystem
oder
der eingestellten Sprache abhängt.
* en:
* This
method is used to reset the flags for Modifier-keys (Alt, Control,
Shift).
* First derive the numeric key-code and then
compare it with the 'Virtual-Key'.
* The comparison with the
'Virtual-Key' gives a unique result independent from
* the
underlying operating-system or the chosen language. */ int
intKeyCode
= e.getKeyCode();/*
de:
* Untersuchen ob ein 'Modifier-Key' losgelassen wurde.
*
Wenn es ein 'Midifier-Key' war dann das entsprechende 'Flag'
zurücksetzen und
*
den KeyEvent als 'consumed' markieren.
*
en:
* Inspect if a Modifier-key was released.
* If
it was a Modifier-Key, reset the flag and mark the KeyEvent as
'consumed'. */ if
(intKeyCode
== KeyEvent.VK_ALT)
{
bolAltKeyModifier
=
false;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_CONTROL)
{ bolCtrlKeyModifier
=
false;
e.consume();
} if
(intKeyCode
== KeyEvent.VK_SHIFT)
{ bolShiftKeyModifier
=
false;
e.consume();
}
} public
void keyTyped(KeyEvent
e) {
}/*
*
-------------------------------
* de:
* Methoden
die zusammen mit der interface WindowListener erforderlich sind.
*
Wenn Methoden Code enthalten und von einer erbenden Klasse
überschrieben werden,
* dann muss die Methode in dieser
Klasse wie in diesem Beispiel aufgerufen werden:
*
super.windowActivated(e); .
* en: *
Methods that are requiered together with the interface
WindowListener.
* If these methods contain code and are
overwritten in the derived class,
* the method in this
base class has to be called in the overwriting method
* like
this example:
* super.windowActivated(e); .
*/ public
void windowActivated(WindowEvent
e) {
} public
void windowClosed(WindowEvent
e) {
this.dispose();
} public
void windowClosing(WindowEvent
e) {/*
de: Methode aufrufen, die Größe und Position des JFrame
auf der Datenbank speichert.
* en: Call the method that
stores size and position of the JFrame to the database. */
storeFramePosition();
this.dispose();
} public
void windowDeactivated(WindowEvent
e) {
} public
void windowDeiconified(WindowEvent
e) {
} public
void windowIconified(WindowEvent
e) {
} public
void windowOpened(WindowEvent
e) {
}/*
*
-------------------------------
* de:
* Methode zum
'Holen' der Eigenschaften (Größe und Postion) des Frames
und der Spaltenbreiten
* für JTables von der Datenbank
und Anpassen von Größe und Position des Frames
*
en: *
Methods to retrieve the Frame-Properties (size and position) and the
column-widths for JTables
* from the database and resize and
position the Frame according to them. */
/*
* de:
*
Die folgende Methode muss von der erbenden Klasse (Teilprogramm /
Task-Frame mit der spezifischen
* Geschäftsanwendung)
aufgerufen werden nachdem die Verbindung zur Datenbank (oder zum
EJB-Server)
* hergestellt ist und das JFrame konstruiert
wurde.
* en: *
The following method has to be called by the derived class
(application-specific Task-Frame)
* after the access to the
database (or EJB-server) is established and the JFrame is
constructed. */
public
void setFramePosition()
{/*
de: Holen der FramePosition-Eigenschaften von der Datenbank.
*
en: Retrieve the FramePosition-properties from the database. */
structJSBS_FramePosition_BOC.getValidByUserKnownKey(this.getClass().getName(),
frmCC.structJSBS_UniversalParameters.strUserName);
/*
de:
* Nachdem die Datenbank-Tabelle 'Parameter' im
Anwendungprogramm, das diese Klasse erbt, nicht
* erstellt
sein kann führt ein Fehler beim Zugriff auf die Datenbank nicht
zu einem Ereignis
* über das der Benutzer informiert
wird. *
Der Unterschied zwischen fehlerfreier Abfrage und Auftreten eines
Fehler ist nur, wie das BOS *
mit Daten versorgt wird.
* en:
* As there is
no obligation for an application using this base-class to have a
database-table
* named 'Parameter', a failure of the
data-access is not an error to be reported.
* The
differentiation is just the way, how the BOS is supplied with values.
*/
if
(structJSBS_FramePosition_BOC.StatusCode
==
JSBS_BO.CONST_OK)
{/*
de: Eigenschaften auf der Tabelle gefunden; Frame anpassen.
*
en: Frame-Position-properties found on the database; adapt the Frame.
*/
this.setSize(structJSBS_FramePosition_BOC.FrameWidth,
structJSBS_FramePosition_BOC.FrameHeight);
this.setLocation(structJSBS_FramePosition_BOC.PosX,
structJSBS_FramePosition_BOC.PosY);
}
else
{/*
de:
* Eigenschaften für die Frame-Position nicht auf
der Datenbank gefunden;
* Dieses BO mit dem Namen des JFrame
und des Benutzer versorgen - für den Fall, dass das
*
BO beim Schließen des Fenster gespeichert wird.
*
en:
* Frame-Position-properties not found on the database;
* Supply the BO with the name of the JFrame and the user -
in case that this information is stored
* when the JFrame is
closing. */
structJSBS_FramePosition_BOC.FrameClassName
=
this.getClass().getName();
structJSBS_FramePosition_BOC.UserID
=
frmCC.structJSBS_UniversalParameters.strUserName;
}
}/*
*
de:
* Die folgende Methode wird aufgerufen wenn das JFrame
(Window) geschlossen wird.
* Innerhalb dieser Methode wird
die Größe und Position des JFrame ermittelt und in der
Datenbank
* gespeichert. *
en:
* The following method is called when the JFrame
(window) is 'closing'.
* Within this method, the size and
the position of the JFrame is taken and stored to the database.
*/
public
void storeFramePosition()
{/*
Check if the BOC is constructed.
* As the construction
happens in the derived Task-Frame (application-specific)
*
the application might not make use of keeping the Frame-postion and
-size within the database. */
if
(structJSBS_FramePosition_BOC
==
null)
return;
/*
Get the properties from the frame; the properties can be derived as
type Rectangle. */
Rectangle
locRectangle = new
Rectangle();
locRectangle
= this.getBounds();
structJSBS_FramePosition_BOC.PosX
=
locRectangle.x;
structJSBS_FramePosition_BOC.PosY
=
locRectangle.y;
structJSBS_FramePosition_BOC.FrameWidth
=
locRectangle.width;
structJSBS_FramePosition_BOC.FrameHeight
=
locRectangle.height;
/*
Store the values to the database.
* As there might be not
database-table 'Parameter' existing for the application,
*
The result is not checked and an error is not reported. */
structJSBS_FramePosition_BOC.store();
}/*
*
-------------------------------
* de:
* Methode die
aufgerufen wird wenn ein GUI-Element mit zugewiesenem
'ActionListener'
* angeklickt wurde.
* en:
*
Method that is triggered when a GUI-element with attached
'ActionListener'
* is clicked. */ public
void actionPerformed(ActionEvent
e) {/*
*
de:
* Ermitteln des 'ActionCommand'.
* Dieser wurde
dem GUI-Element mit der Methode 'setActionCommand' zugewiesen.
*
en:
* Derive the 'ActionCommand'.
* That was
attached to the GUI-element through the method 'setActionCommand'.
*/
String
cmd = e.getActionCommand();/*
* de: Feststellen welchen ActionCommand übergeben
wurde und die passende Aktion ausführen.
* en: Check
which ActionCommand was handed over and perform the appropriate
action.
* */ if
(cmd.equals("btn_WarningIcon"))
{/*
de: Diese Schaltfläche wird auch für den Aufruf der
Hilfe-Information genutzt.
* en: This JButton is also used
to call the 'Help'-Information. */ String
strHelpFileName =
frmCC.structJSBS_XML_DisplayStrings.getFrameHelpFileName(this); if
(strHelpFileName
!= null)
{/*
de: Erste
Prüfung ob ein Datei-Name gefunden wurde.
* en: First
verification if a file-name was found. */
if
(strHelpFileName.length()
> 0) {/*
de: Zweite
Prüfung ob ein Datei-Name gefunden wurde.
* en: Second
verification if a file-name was found. *//*
de: Erweitern
des Datei-Namens auf gesamte Verzeichnis-Struktur.
* en:
Expand the file-name to the complete directory-structure. */
strHelpFileName
=
frmCC.structJSBS_UniversalParameters.strHelpElementsDirectoryName +
strHelpFileName;/*
de: Anzeigen
des Hilfe-Dokumentes.
* en: Display the Help-document. */
try {Desktop.getDesktop().browse(new
URI("file:///"
+ strHelpFileName));}/*
de: Fehler
beim Anzeigen des Hilfe-Dokumentes - kein Grund für eine
Fehlerbehandlung.
* en: Error when displaying the
help-document - no reason for error-handling. */
catch (Exception
wwwExc) {wwwExc.printStackTrace();}
}
} }/*
* de:
* Bei den übrigen Schaltflächen
wird der jeweilige Process-Indicator gesetzt (dieser
* muss
dann im Frame, das diesen Dialog aufgerufen hat abgefragt werden und
damit die
* weiter Verarbeitung gesteuert werden)
und
dieser
Dialog geschlossen.
* en:
* With the other
JButton, the Process-Indicator is set (this has to lead to
further
* processing
in
the Frame that called this Dialog) and this Dialog is closed.
*/ if
(cmd.equals("btn_Back"))
{ strProcessIndicator
= CONST_PROCESS_BACK;/*
de: Methode aufrufen, die Größe und Position des JFrame
auf der Datenbank speichert.
* en: Call the method that
stores size and position of the JFrame to the database.
*/ storeFramePosition(); this.dispose();
} if
(cmd.equals("btn_Store"))
{ strProcessIndicator
= CONST_PROCESS_STORE;/*
de: Methode aufrufen, die Größe und Position des JFrame
auf der Datenbank speichert.
* en: Call the method that
stores size and position of the JFrame to the database.
*/ storeFramePosition(); this.dispose();
} if
(cmd.equals("btn_Discard"))
{ strProcessIndicator
= CONST_PROCESS_DISCARD;/*
de: Methode aufrufen, die Größe und Position des JFrame
auf der Datenbank speichert.
* en: Call the method that
stores size and position of the JFrame to the database.
*/ storeFramePosition(); this.dispose();
}
}}
xxx
|
Dokument |
Inhalt |
|
Dieser
Leitfaden enthält die notwendigen Tätigkeiten für
die Entwicklung eines StartFrame (auch als Command-Center
bekannt). |