home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d12345 / CHEMPLOT.ZIP / TPlot / Dataedit.pas < prev    next >
Pascal/Delphi Source File  |  2001-05-28  |  8KB  |  269 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.   Nedit;
  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.     procedure FormCreate(Sender: TObject);
  80.     procedure FormResize(Sender: TObject);
  81.     procedure DataStringGridKeyDown(Sender: TObject; var Key: Word;
  82.       Shift: TShiftState);
  83.     procedure AddRowBitBtnClick(Sender: TObject);
  84.     procedure DeleteRowBitBtnClick(Sender: TObject);
  85.     procedure CopyBitBtnClick(Sender: TObject);
  86.     procedure HelpBitBtnClick(Sender: TObject);
  87.     procedure ApplyBitBtnClick(Sender: TObject);
  88.   private
  89.     { Private declarations }
  90.   public
  91.     NumericDataChanged: Boolean;
  92. {Has the X or Y numeric data, or the Z data, changed ?}
  93.     StringDataChanged: Boolean;
  94. {Has the X String data been changed ?}
  95.     RowCountChanged: Boolean;
  96. {Has the number of rows (points) changed ?}
  97.     ExternalXSeries: Boolean;
  98. {Is the X Data maintained in a different series ?
  99.  If it is, then it cannot be changed here.}    
  100.     DependentXSeries: Boolean;
  101.     TheSeries: TObject;
  102.   end;
  103.  
  104. var
  105.   DataEditorForm: TDataEditorForm;
  106.  
  107. implementation
  108.  
  109. uses
  110.   Data;
  111. {$R *.dfm}
  112.  
  113. procedure TDataEditorForm.FormCreate(Sender: TObject);
  114. begin
  115.   Left := 10;
  116.   Top := 10;
  117.  
  118.   AddRowBitBtn.Width := 88;
  119.   DeleteRowBitBtn.Width := 88;
  120.   ZDataNEdit.Width := 88;
  121.   ApplyBitBtn.Width := 75;
  122.   HelpBitBtn.Width := 75;
  123.   OKBitBtn.Width := 75;
  124.   CancelBitBtn.Width := 75;
  125.  
  126. {do the geometry of the grid:}
  127.   DataStringGrid.Cells[0,0] := 'Point';
  128.   DataStringGrid.ColWidths[0] := Canvas.TextWidth('Point') + 6;
  129.   DataStringGrid.Cells[1, 0] := 'X Data';
  130.   DataStringGrid.Cells[2, 0] := 'Y Data';
  131.   DataStringGrid.Cells[3, 0] := 'X String';
  132.  
  133.   //ClientHeight := OKBitBtn.Top + 3 * OKBitBtn.Height div 2;
  134.  
  135.   DataStringGrid.Hint := 'Press "F2" to edit, or just overtype,' + #10 +
  136.     'and Ctrl-C to copy a single cell.';
  137.   NumericDataChanged := FALSE;
  138.   StringDataChanged := FALSE;
  139.   RowCountChanged := FALSE;
  140. end;
  141.  
  142. procedure TDataEditorForm.FormResize(Sender: TObject);
  143. begin
  144.   OKBitBtn.Top := ClientHeight - 3 * OKBitBtn.Height div 2;
  145.   HelpBitBtn.Top := OKBitBtn.Top;
  146.   CancelBitBtn.Top := OKBitBtn.Top;
  147.   ApplyBitBtn.Top := OKBitBtn.Top;
  148.   DataStringGrid.Width := ClientWidth - 2;
  149.   DataStringGrid.ColWidths[3] := DataStringGrid.Width -
  150.     DataStringGrid.ColWidths[0] -
  151.     DataStringGrid.ColWidths[1] -
  152.     DataStringGrid.ColWidths[2] - 25;
  153.   DataStringGrid.Height := ClientHeight - DataStringGrid.Top - 2*OKBitBtn.Height;  
  154. end;
  155.  
  156. procedure TDataEditorForm.DataStringGridKeyDown(Sender: TObject;
  157.   var Key: Word; Shift: TShiftState);
  158. begin
  159.   if (((Key > 31) and (Key < 127)) or (Key = VK_BACK))then
  160.   begin
  161. { ' ' thru to '~':}
  162.     case DataStringGrid.Col of
  163.       1:
  164.         begin
  165.           if (ExternalXSeries) then
  166.             Key := 0
  167.           else
  168.             NumericDataChanged := TRUE;
  169.         end;
  170.       2: NumericDataChanged := TRUE;
  171.       3: StringDataChanged := TRUE;
  172.     end;
  173.   end;
  174. end;
  175.  
  176. procedure TDataEditorForm.AddRowBitBtnClick(Sender: TObject);
  177. var
  178.   i: Integer;
  179. begin
  180.   with DataStringGrid do
  181.   begin
  182.     RowCount := RowCount + 1;
  183.     Cells[0, RowCount-1] :=
  184.       IntToStr(RowCount-2);
  185.     for i := RowCount-2 downto Row+1 do
  186.     begin
  187.       Cells[1, i+1] := Cells[1, i];
  188.       Cells[2, i+1] := Cells[2, i];
  189.       Cells[3, i+1] := Cells[3, i];
  190.     end;
  191.     Cells[1, Row+1] := '';
  192.     Cells[2, Row+1] := '';
  193.     Cells[3, Row+1] := '';
  194.     Row := Row + 1;
  195.     SetFocus;
  196.   end;
  197.   RowCountChanged := TRUE;
  198. end;
  199.  
  200. procedure TDataEditorForm.DeleteRowBitBtnClick(Sender: TObject);
  201. var
  202.   i: Integer;
  203. begin
  204.   with DataStringGrid do
  205.   begin
  206.     for i := Row to RowCount-2 do
  207.     begin
  208.       Cells[0, i] := Cells[0, i+1];
  209.       Cells[1, i] := Cells[1, i+1];
  210.       Cells[2, i] := Cells[2, i+1];
  211.       Cells[3, i] := Cells[3, i+1];
  212.     end;
  213.     RowCount := RowCount - 1;
  214.     SetFocus;
  215.   end;
  216.   RowCountChanged := TRUE;
  217. end;
  218.  
  219. procedure TDataEditorForm.CopyBitBtnClick(Sender: TObject);
  220. var
  221.   i: Integer;
  222.   TheStringList: TStringList;
  223. begin
  224.   TheStringList := TStringList.Create;
  225.   with DataStringGrid do
  226.   begin
  227.     for i := 0 to RowCount-1 do
  228.     begin
  229.       TheStringList.Add(
  230.         Cells[0, i] + Chr(VK_TAB) +
  231.         Cells[1, i] + Chr(VK_TAB) +
  232.         Cells[2, i] + Chr(VK_TAB) +
  233.         Cells[3, i]);
  234.     end;
  235.     Clipboard.AsText := TheStringList.Text;
  236.   end;  
  237.   TheStringList.Free;
  238. end;
  239.  
  240. procedure TDataEditorForm.HelpBitBtnClick(Sender: TObject);
  241. {$IFDEF LINUX}
  242. var
  243.   TheHelpFile: String;
  244. {$ENDIF}
  245. begin
  246. {$IFDEF LINUX}
  247.   TheHelpFile := 'hs' + IntToStr(HelpBitBtn.HelpContext) + '.htm';
  248. {$ENDIF}
  249. end;
  250.  
  251. {------------------------------------------------------------------------------
  252.     Procedure: TPlotDataEditorForm.ApplyBitBtnClick
  253.   Description: Standard ButtonClick event handler
  254.        Author: Mat Ballard
  255.  Date created: 03/28/2001
  256. Date modified: 03/28/2001 by Mat Ballard
  257.       Purpose: Applies the current Data to the Series
  258.  Known Issues:
  259.  ------------------------------------------------------------------------------}
  260. procedure TDataEditorForm.ApplyBitBtnClick(Sender: TObject);
  261. begin
  262.   TSeries(TheSeries).ApplyDataChange(Self);
  263.   NumericDataChanged := FALSE;
  264.   StringDataChanged := FALSE;
  265. end;
  266.  
  267.  
  268. end.
  269.