diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-24 14:36:43 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-24 14:36:43 +0000 |
commit | a2a390ed6d9f31e144d725dcab5b0fe014a95402 (patch) | |
tree | 1245fecac3a2fde7b518c710176f41187bd82967 /extras/tiopf/demos/Common | |
parent | 91e7bc73a36017ccc7a8d94727b2f6f51c0c83f6 (diff) | |
download | fpGUI-a2a390ed6d9f31e144d725dcab5b0fe014a95402.tar.xz |
* Implement MaxLength in TfpgEdit
* Published some missing properties in TfpgTrackBar.
* TfpgEdit now correctl fires off the OnChange event.
* A new Text property has been implemented in TfpgComboBox.
* Minor fixes to the generic Edit mediators used for tiOPF.
* Added a Edit Mediator demo which tests the implementation. It works!
Diffstat (limited to 'extras/tiopf/demos/Common')
-rw-r--r-- | extras/tiopf/demos/Common/Constants.pas | 14 | ||||
-rw-r--r-- | extras/tiopf/demos/Common/Model.pas | 203 | ||||
-rw-r--r-- | extras/tiopf/demos/Common/Model_View.pas | 151 |
3 files changed, 368 insertions, 0 deletions
diff --git a/extras/tiopf/demos/Common/Constants.pas b/extras/tiopf/demos/Common/Constants.pas new file mode 100644 index 00000000..6c93719d --- /dev/null +++ b/extras/tiopf/demos/Common/Constants.pas @@ -0,0 +1,14 @@ +unit Constants; + +{$mode objfpc}{$H+} + +interface + +const + cNameMissing = 'Please enter a name'; + cAgeOutofRange = 'Please enter a valid age'; + + +implementation + +end. diff --git a/extras/tiopf/demos/Common/Model.pas b/extras/tiopf/demos/Common/Model.pas new file mode 100644 index 00000000..148f94b9 --- /dev/null +++ b/extras/tiopf/demos/Common/Model.pas @@ -0,0 +1,203 @@ +unit Model; + +{$mode objfpc}{$H+} + +interface +uses + tiObject + ; + +type + TGender = (genMale, genFemale); + +const + cGender: array[TGender] of string = ('Male', 'Female'); + +type + TPerson = class; + TPersonList = class; + + { TPerson - The subject being observed } + TPerson = class(TtiObject) + private + FGender: TGender; + FName: string; + FAge: integer; + function GetGenderGUI: string; + procedure SetGender(const AValue: TGender); + procedure SetGenderGUI(const AValue: string); + procedure SetName(const Value: string); + procedure SetAge(const Value: integer); + protected + function GetCaption: string; override; + public + constructor Create; override; + function IsValid(const pErrors: TtiObjectErrors): Boolean; override; + procedure NotifyObservers; override; + property Gender: TGender read FGender write SetGender; + published + property Name: string read FName write SetName; + property Age: integer read FAge write SetAge; + property GenderGUI: string read GetGenderGUI write SetGenderGUI; + end; + + + { TPersonList } + TPersonList = class(TtiObjectList) + private + protected + function GetItems(i: integer): TPerson; reintroduce; + procedure SetItems(i: integer; const Value: TPerson); reintroduce; + public + property Items[i: integer]: TPerson read GetItems write SetItems; + procedure Add(const pObject: TPerson); reintroduce; + end; + + +function GeneratePersonList: TPersonList; + + +implementation +uses + Constants + ; + + +function GeneratePersonList: TPersonList; +var + lList: TPersonList; + lData: TPerson; +begin + lList := TPersonList.Create; + + lData := TPerson.Create; + lData.Name := 'Graeme Geldenhuys'; + lData.Age := 23; + lList.Add(lData); + + lData := TPerson.Create; + lData.Name := 'Peter Hinrichsen'; + lData.Age := 34; + lList.Add(lData); + + lData := TPerson.Create; + lData.Name := 'Ian Krigsman'; + lData.Age := 45; + lData.Deleted := True; + lList.Add(lData); + + lData := TPerson.Create; + lData.Name := 'John Guthrie'; + lData.Age := 56; + lList.Add(lData); + + Result := lList; +end; + + +{ TPerson } + +function TPerson.IsValid(const pErrors: TtiObjectErrors): Boolean; +begin + inherited IsValid(pErrors); + + if Name = '' then + pErrors.AddError('Name', cNameMissing); + + if Age < 1 then + pErrors.AddError('Age', cAgeOutofRange); + + Result := pErrors.Count = 0; +end; + +{ This was used for debugging, so you can see when NotifiObservers get called } +procedure TPerson.NotifyObservers; +begin +// writeln('NotifyObservers'); + inherited NotifyObservers; +end; + +procedure TPerson.SetAge(const Value: integer); +begin + { BeginUpdate and EndUpdate are optional. They allow the observers to only + get updated once, and not continuous for small updates. It doesn't really + make a difference for this simple example though. } + BeginUpdate; + FAge := Value; + EndUpdate; + { If you don't use BeginUpdate and EndUpdate, you need to call NotifyObserver + to they can be updated. } +// NotifyObservers; +end; + +function TPerson.GetCaption: string; +begin + Result := Name; + if Deleted then + Result := Result + ' (deleted)'; +end; + +constructor TPerson.Create; +begin + inherited Create; + FGender := genMale; +end; + +procedure TPerson.SetName(const Value: string); +begin + BeginUpdate; + FName := Value; + EndUpdate; +end; + +procedure TPerson.SetGender(const AValue: TGender); +begin + if FGender = AValue then exit; + BeginUpdate; + FGender := AValue; + EndUpdate; +end; + +function TPerson.GetGenderGUI: string; +begin + result := cGender[FGender]; +end; + +procedure TPerson.SetGenderGUI(const AValue: string); +var + i: TGender; +begin + for i := Low(TGender) to High(TGender) do + begin + if cGender[i] = AValue then + begin + Gender := i; + Exit; //==> + end; + end; + Gender := genMale; +end; + + +{ TPersonList } + +function TPersonList.GetItems(i: integer): TPerson; +begin + result := TPerson(inherited GetItems(i)); +end; + +procedure TPersonList.SetItems(i: integer; const Value: TPerson); +begin + inherited SetItems(i, Value); +end; + +procedure TPersonList.Add(const pObject: TPerson); +begin + BeginUpdate; + inherited Add(pObject); + EndUpdate; +end; + + +end. + diff --git a/extras/tiopf/demos/Common/Model_View.pas b/extras/tiopf/demos/Common/Model_View.pas new file mode 100644 index 00000000..937b51a3 --- /dev/null +++ b/extras/tiopf/demos/Common/Model_View.pas @@ -0,0 +1,151 @@ +unit Model_View; + +{$IFDEF FPC} + {$mode objfpc}{$H+} +{$ENDIF} + +interface + +uses + Classes + ,tiGenericEditMediators +// ,tiGenericListMediators +// ,tiCompositeMediators + ; + +type + { TEdit - Name } + TPerson_Name_TextEdit_View = class(TMediatorEditView) + protected + procedure SetupGUIandObject; override; + end; + + + { TSpinEdit - Age } +{ + TPerson_Age_SpinEdit_View = class(TMediatorSpinEditView) + protected + procedure SetupGUIandObject; override; + end; +} + + { TTrackBar - Age } + TPerson_Age_TrackBar_Mediator = class(TMediatorTrackBarView) + protected + procedure SetupGUIandObject; override; + end; + + + { TMemo - Name } + TPerson_Name_Memo_Mediator = class(TMediatorMemoView) + protected + procedure SetupGUIandObject; override; + end; + + + { TCombobox - Gender } + TPerson_Gender_ComboBox_Mediator = class(TMediatorComboBoxView) + protected + procedure SetupGUIandObject; override; + end; + + + { TPersonList_ComboBox_Mediator } +{ + TPersonList_ComboBox_Mediator = class(TComboBoxMediator) + protected + procedure SetupGUIandObject; override; + end; + + + TPersonList_ListView_CompositeMediator = class(TCompositeListViewMediator) + protected + procedure SetupGUIandObject; override; + end; +} + +implementation + + +{ TPersonNameView } + +procedure TPerson_Name_TextEdit_View.SetupGUIandObject; +begin + inherited; + { The Name field my only contain 25 characters max. } + EditControl.MaxLength := 25; +end; + + +{ TPerson_Name_Memo_Mediator } + +procedure TPerson_Name_Memo_Mediator.SetupGUIandObject; +begin + inherited SetupGUIandObject; + { The Name field my only contain 25 characters max. } +// EditControl.ReadOnly := True; + EditControl.Enabled := False; +end; + + +{ TPerson_Gender_ComboBox_Mediator } + +procedure TPerson_Gender_ComboBox_Mediator.SetupGUIandObject; +begin + inherited SetupGUIandObject; +// EditControl.Style := csDropDownList; +// TComboBox(EditControl).ReadOnly := True; +end; + + +{ TPersonList_ComboBox_Mediator } +(* +procedure TPersonList_ComboBox_Mediator.SetupGUIandObject; +begin + inherited SetupGUIandObject; + View.Style := csDropDownList; +// View.ReadOnly := True; +end; + + +{ TPersonList_ListView_CompositeMediator } + +procedure TPersonList_ListView_CompositeMediator.SetupGUIandObject; +begin + inherited SetupGUIandObject; +// View.OnCustomDrawItem := ListViewCustomDrawItem; +end; +*) + +{ TPerson_Age_SpinEdit_View } +{ +procedure TPerson_Age_SpinEdit_View.SetupGUIandObject; +begin + inherited SetupGUIandObject; + EditControl.MaxValue := 100; +end; +} +{ TPerson_Age_TrackBar_Mediator } + +procedure TPerson_Age_TrackBar_Mediator.SetupGUIandObject; +begin + inherited SetupGUIandObject; + EditControl.Max := 100; +end; + +initialization + {----------------------------------------------------------------------------- + Register all your Mediator Views here + Params: ClassName and Property name of the business object as a string + Mediator View class + -----------------------------------------------------------------------------} + + // This is not used anymore and needs to be removed +{ + gMediatorFactory.RegisterMediatorClass('TPerson.Name' ,TPerson_Name_TextEdit_View); + gMediatorFactory.RegisterMediatorClass('TPerson.Age' ,TPerson_Age_SpinEdit_View); + gMediatorFactory.RegisterMediatorClass('TPerson.Age' ,TPerson_Age_TrackBar_Mediator); + gMediatorFactory.RegisterMediatorClass('TPerson.Name' ,TPerson_Name_Memo_Mediator); + gMediatorFactory.RegisterMediatorClass('TPerson.GenderGUI',TPerson_Gender_ComboBox_Mediator); +} +end. |