home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kompon / d123456 / CHEMPLOT.ZIP / TPlot / Dataedit.pas < prev    next >
Pascal/Delphi Source File  |  2001-07-24  |  10KB  |  331 lines

  1. unit Dataedit;
  2.  
  3. {$I Plot.inc}
  4.  
  5. {-----------------------------------------------------------------------------
  6. The contents of this file are subject to the Q Public License
  7. ("QPL"); you may not use this file except in compliance
  8. with the QPL. You may obtain a copy of the QPL from 
  9. the file QPL.html in this distribution, derived from:
  10.  
  11. http://www.trolltech.com/products/download/freelicense/license.html
  12.  
  13. The QPL prohibits development of proprietary software. 
  14. There is a Professional Version of this software available for this. 
  15. Contact sales@chemware.hypermart.net for more information.
  16.  
  17. Software distributed under the QPL is distributed on an "AS IS" basis,
  18. WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the QPL for
  19. the specific language governing rights and limitations under the QPL.
  20.  
  21. The Original Code is: Dataedit.pas, released 15 March 2001.
  22.  
  23. The Initial Developer of the Original Code is Mat Ballard.
  24. Portions created by Mat Ballard are Copyright (C) 1999 Mat Ballard.
  25. Portions created by Microsoft are Copyright (C) 1998, 1999 Microsoft Corp.
  26. All Rights Reserved.
  27.  
  28. Contributor(s): Mat Ballard                 e-mail: mat.ballard@chemware.hypermart.net.
  29.  
  30. Last Modified: 03/13/2001
  31. Current Version: 2.00
  32.  
  33. You may retrieve the latest version of this file from:
  34.  
  35.         http://Chemware.hypermart.net/
  36.  
  37. This work was created with the Project JEDI VCL guidelines:
  38.  
  39.         http://www.delphi-jedi.org/Jedi:VCLVCL
  40.  
  41. in mind. 
  42.  
  43. Purpose:
  44. To facilitate user manipluation of Series Data (ie: the numbers !).
  45.  
  46. Known Issues:
  47. -----------------------------------------------------------------------------}
  48.  
  49. interface
  50.  
  51. uses
  52.   Classes, SysUtils,
  53. {$IFDEF WINDOWS}
  54.   WinTypes, WinProcs,
  55.   Buttons, Clipbrd, Controls, ComCtrls, Forms, Graphics, Grids, StdCtrls,
  56. {$ENDIF}
  57. {$IFDEF WIN32}
  58.   Windows,
  59.   Buttons, Clipbrd, Controls, ComCtrls, Forms, Graphics, Grids, StdCtrls,
  60. {$ENDIF}
  61. {$IFDEF LINUX}
  62.   Untranslated,
  63.   QButtons, QClipbrd, QControls, QComCtrls, QExtCtrls, QForms, QGrids, QGraphics, QStdCtrls,
  64. {$ENDIF}
  65.   Misc, Nedit, Plotdefs;
  66.  
  67. type
  68.   TDataEditorForm = class(TForm)
  69.     DataStringGrid: TStringGrid;
  70.     HelpBitBtn: TBitBtn;
  71.     CancelBitBtn: TBitBtn;
  72.     OKBitBtn: TBitBtn;
  73.     ZDataLabel: TLabel;
  74.     AddRowBitBtn: TBitBtn;
  75.     DeleteRowBitBtn: TBitBtn;
  76.     ZDataNEdit: TNEdit;
  77.     CopyBitBtn: TBitBtn;
  78.     ApplyBitBtn: TBitBtn;
  79.     SeriesNameLabel: TLabel;
  80.     procedure FormCreate(Sender: TObject);
  81.     procedure FormResize(Sender: TObject);
  82.     procedure DataStringGridKeyDown(Sender: TObject; var Key: Word;
  83.       Shift: TShiftState);
  84.     procedure AddRowBitBtnClick(Sender: TObject);
  85.     procedure DeleteRowBitBtnClick(Sender: TObject);
  86.     procedure CopyBitBtnClick(Sender: TObject);
  87.     procedure HelpBitBtnClick(Sender: TObject);
  88.     procedure ApplyBitBtnClick(Sender: TObject);
  89.   private
  90.     { Private declarations }
  91.   public
  92.     NumericDataChanged: Boolean;
  93. {Has the X or Y numeric data, or the Z data, changed ?}
  94.     StringDataChanged: Boolean;
  95. {Has the X String data been changed ?}
  96.     RowCountChanged: Boolean;
  97. {Has the number of rows (points) changed ?}
  98.     ExternalXSeries: Boolean;
  99. {Is the X Data maintained in a different series ?
  100.  If it is, then it cannot be changed here.}
  101.     DependentXSeries: Boolean;
  102.     TheSeries: TObject;
  103.  
  104. {$IFNDEF LANG_ENGLISH}
  105.     procedure DoCaptionsFromResource;
  106. {$ENDIF}
  107.     procedure DoHintsFromResource;
  108.   end;
  109.  
  110. var
  111.   DataEditorForm: TDataEditorForm;
  112.  
  113. implementation
  114.  
  115. uses
  116.   Data;
  117.  
  118. {$R *.dfm}
  119.  
  120. {------------------------------------------------------------------------------
  121.     Procedure: TDataEditorForm.FormCreate
  122.   Description: standard FormCreate procedure
  123.        Author: Mat Ballard
  124.  Date created: 04/25/2000
  125. Date modified: 04/25/2000 by Mat Ballard
  126.       Purpose: sets the position and Grid row titles
  127.  Known Issues:
  128.  ------------------------------------------------------------------------------}
  129. procedure TDataEditorForm.FormCreate(Sender: TObject);
  130. begin
  131. {$IFNDEF LANG_ENGLISH}
  132.   DoCaptionsFromResource;
  133. {$ENDIF}
  134.   DoHintsFromResource;
  135.   Left := 10;
  136.   Top := 10;
  137.  
  138.   AddRowBitBtn.Width := 145;
  139.   DeleteRowBitBtn.Width := 145;
  140.   ZDataNEdit.Width := 97;
  141.   ApplyBitBtn.Width := 97;
  142.   HelpBitBtn.Width := 97;
  143.   OKBitBtn.Width := 97;
  144.   CancelBitBtn.Width := 97;
  145.   CopyBitBtn.Width := 97;
  146.  
  147. {do the geometry of the grid:}
  148.   DataStringGrid.Cells[0,0] := sPoint;
  149.   DataStringGrid.ColWidths[0] := Canvas.TextWidth('Point') + 6;
  150.   DataStringGrid.Cells[1, 0] := 'X ' + sData;
  151.   DataStringGrid.Cells[2, 0] := 'Y ' + sData;
  152.   DataStringGrid.Cells[3, 0] := 'X ' + sText;
  153.  
  154.   //ClientHeight := OKBitBtn.Top + 3 * OKBitBtn.Height div 2;
  155.  
  156.   NumericDataChanged := FALSE;
  157.   StringDataChanged := FALSE;
  158.   RowCountChanged := FALSE;
  159. end;
  160.  
  161. {------------------------------------------------------------------------------
  162.     Procedure: TDataEditorForm.DoCaptionsFromResource
  163.   Description: standard loading of labels from resources
  164.        Author: Mat Ballard
  165.  Date created: 06/25/2001
  166. Date modified: 06/25/2001 by Mat Ballard
  167.       Purpose: display in different languages
  168.  Known Issues:
  169.  ------------------------------------------------------------------------------}
  170. {$IFNDEF LANG_ENGLISH}
  171. procedure TDataEditorForm.DoCaptionsFromResource;
  172. begin
  173.   Self.Caption := sData + ' ' + sEditor;
  174.   HelpBitBtn.Caption := sHelp;
  175.   OKBitBtn.Caption := sOK;
  176.   CancelBitBtn.Caption := sCancel;
  177.   ApplyBitBtn.Caption := sApply;
  178.   CopyBitBtn.Caption := sCopy;
  179.   AddRowBitBtn.Caption := sAddRow;
  180.   DeleteRowBitBtn.Caption := sDelRow;
  181.   ZDataLabel.Caption := 'Z ' + sData;
  182. end;
  183. {$ENDIF}
  184.  
  185. {------------------------------------------------------------------------------
  186.     Procedure: TDataEditorForm.DoHintsFromResource
  187.   Description: standard loading of labels from resources
  188.        Author: Mat Ballard
  189.  Date created: 06/25/2001
  190. Date modified: 06/25/2001 by Mat Ballard
  191.       Purpose: display hints in different languages
  192.  Known Issues:
  193.  ------------------------------------------------------------------------------}
  194. procedure TDataEditorForm.DoHintsFromResource;
  195. begin
  196.   ApplyBitBtn.Hint := sApplyHint;
  197.   CopyBitBtn.Hint := sCopyBitBtnHint;
  198.   AddRowBitBtn.Hint := sAddRowBitBtnHint;
  199.   DeleteRowBitBtn.Hint := sDelRowBitBtnHint;
  200.   ZDataNEdit.Hint := sZDataEditHint;
  201.   DataStringGrid.Hint := sDataStringGridHint;
  202. end;
  203.  
  204. procedure TDataEditorForm.FormResize(Sender: TObject);
  205. begin
  206.   OKBitBtn.Top := ClientHeight - 3 * OKBitBtn.Height div 2;
  207.   HelpBitBtn.Top := OKBitBtn.Top;
  208.   CancelBitBtn.Top := OKBitBtn.Top;
  209.   ApplyBitBtn.Top := OKBitBtn.Top;
  210.   DataStringGrid.Width := ClientWidth - 2;
  211.   DataStringGrid.ColWidths[3] := DataStringGrid.Width -
  212.     DataStringGrid.ColWidths[0] -
  213.     DataStringGrid.ColWidths[1] -
  214.     DataStringGrid.ColWidths[2] - 25;
  215.   DataStringGrid.Height := ClientHeight - DataStringGrid.Top - 2*OKBitBtn.Height;
  216. end;
  217.  
  218. procedure TDataEditorForm.DataStringGridKeyDown(Sender: TObject;
  219.   var Key: Word; Shift: TShiftState);
  220. begin
  221.   if (((Key > 31) and (Key < 127)) or (Key = VK_BACK))then
  222.   begin
  223. { ' ' thru to '~':}
  224.     case DataStringGrid.Col of
  225.       1:
  226.         begin
  227.           if (ExternalXSeries) then
  228.             Key := 0
  229.           else
  230.             NumericDataChanged := TRUE;
  231.         end;
  232.       2: NumericDataChanged := TRUE;
  233.       3: StringDataChanged := TRUE;
  234.     end;
  235.   end;
  236. end;
  237.  
  238. procedure TDataEditorForm.AddRowBitBtnClick(Sender: TObject);
  239. var
  240.   i: Integer;
  241. begin
  242.   with DataStringGrid do
  243.   begin
  244.     RowCount := RowCount + 1;
  245.     Cells[0, RowCount-1] :=
  246.       IntToStr(RowCount-2);
  247.     for i := RowCount-2 downto Row+1 do
  248.     begin
  249.       Cells[1, i+1] := Cells[1, i];
  250.       Cells[2, i+1] := Cells[2, i];
  251.       Cells[3, i+1] := Cells[3, i];
  252.     end;
  253.     Cells[1, Row+1] := '';
  254.     Cells[2, Row+1] := '';
  255.     Cells[3, Row+1] := '';
  256.     Row := Row + 1;
  257.     SetFocus;
  258.   end;
  259.   RowCountChanged := TRUE;
  260. end;
  261.  
  262. procedure TDataEditorForm.DeleteRowBitBtnClick(Sender: TObject);
  263. var
  264.   i: Integer;
  265. begin
  266.   with DataStringGrid do
  267.   begin
  268.     for i := Row to RowCount-2 do
  269.     begin
  270.       Cells[0, i] := Cells[0, i+1];
  271.       Cells[1, i] := Cells[1, i+1];
  272.       Cells[2, i] := Cells[2, i+1];
  273.       Cells[3, i] := Cells[3, i+1];
  274.     end;
  275.     RowCount := RowCount - 1;
  276.     SetFocus;
  277.   end;
  278.   RowCountChanged := TRUE;
  279. end;
  280.  
  281. procedure TDataEditorForm.CopyBitBtnClick(Sender: TObject);
  282. var
  283.   i: Integer;
  284.   TheStringList: TStringList;
  285. begin
  286.   TheStringList := TStringList.Create;
  287.   with DataStringGrid do
  288.   begin
  289.     for i := 0 to RowCount-1 do
  290.     begin
  291.       TheStringList.Add(
  292.         Cells[0, i] + Chr(VK_TAB) +
  293.         Cells[1, i] + Chr(VK_TAB) +
  294.         Cells[2, i] + Chr(VK_TAB) +
  295.         Cells[3, i]);
  296.     end;
  297.     Clipboard.AsText := TheStringList.Text;
  298.   end;  
  299.   TheStringList.Free;
  300. end;
  301.  
  302. procedure TDataEditorForm.HelpBitBtnClick(Sender: TObject);
  303. {$IFDEF LINUX}
  304. var
  305.   TheHelpFile: String;
  306. {$ENDIF}
  307. begin
  308. {$IFDEF LINUX}
  309.   TheHelpFile := 'hs' + IntToStr(HelpBitBtn.HelpContext) + '.htm';
  310. {$ENDIF}
  311. end;
  312.  
  313. {------------------------------------------------------------------------------
  314.     Procedure: TPlotDataEditorForm.ApplyBitBtnClick
  315.   Description: Standard ButtonClick event handler
  316.        Author: Mat Ballard
  317.  Date created: 03/28/2001
  318. Date modified: 03/28/2001 by Mat Ballard
  319.       Purpose: Applies the current Data to the Series
  320.  Known Issues:
  321.  ------------------------------------------------------------------------------}
  322. procedure TDataEditorForm.ApplyBitBtnClick(Sender: TObject);
  323. begin
  324.   TSeries(TheSeries).ApplyDataChange(Self);
  325.   NumericDataChanged := FALSE;
  326.   StringDataChanged := FALSE;
  327. end;
  328.  
  329.  
  330. end.
  331.