init
This commit is contained in:
49
jj_vision/interface/fields/comparable_field.e
Normal file
49
jj_vision/interface/fields/comparable_field.e
Normal file
@@ -0,0 +1,49 @@
|
||||
note
|
||||
description: "[
|
||||
A {FIELD} used to create a control to edit a COMPARABLE.
|
||||
]"
|
||||
date: "24 Feb 04"
|
||||
author: "Jimmy J. Johnson"
|
||||
copyright: "Copyright 2012, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum License v2 (see forum.txt)"
|
||||
URL: "$URL: file:///F:/eiffel_repositories/jj_vision/trunk/interface/fields/comparable_field.e $"
|
||||
date: "$Date: 2012-03-16 14:05:07 -0400 (Fri, 16 Mar 2012) $"
|
||||
revision: "$Revision: 7 $"
|
||||
|
||||
|
||||
deferred class
|
||||
COMPARABLE_FIELD
|
||||
|
||||
inherit
|
||||
|
||||
FIELD
|
||||
redefine
|
||||
default_create,
|
||||
as_widget,
|
||||
Type
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
-- Initialize `Current'.
|
||||
do
|
||||
Precursor {FIELD}
|
||||
end
|
||||
|
||||
feature -- Transformation
|
||||
|
||||
as_widget: COMPARABLE_CONTROL
|
||||
-- Each descendent class must create the appropriate control.
|
||||
-- Redefined to change the type.
|
||||
deferred
|
||||
end
|
||||
|
||||
feature --
|
||||
|
||||
Type: COMPARABLE
|
||||
-- Anchor for `value'
|
||||
deferred
|
||||
end
|
||||
|
||||
end
|
483
jj_vision/interface/fields/field.e
Normal file
483
jj_vision/interface/fields/field.e
Normal file
@@ -0,0 +1,483 @@
|
||||
note
|
||||
description: "[
|
||||
Used with {EDITOR} classes.
|
||||
Object that describes how to create a {CONTROL}.
|
||||
]"
|
||||
date: "7 Mar 03"
|
||||
author: "Jimmy J. Johnson"
|
||||
copyright: "Copyright 2012, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum License v2 (see forum.txt)"
|
||||
URL: "$URL: file:///F:/eiffel_repositories/jj_vision/trunk/interface/fields/field.e $"
|
||||
date: "$Date: 2012-03-16 14:05:07 -0400 (Fri, 16 Mar 2012) $"
|
||||
revision: "$Revision: 7 $"
|
||||
|
||||
|
||||
deferred class
|
||||
FIELD
|
||||
|
||||
inherit
|
||||
|
||||
FIELD_CONSTANTS
|
||||
undefine
|
||||
default_create,
|
||||
is_equal
|
||||
end
|
||||
|
||||
EDITABLE
|
||||
redefine
|
||||
default_create,
|
||||
schema,
|
||||
is_schema_available,
|
||||
schema_imp,
|
||||
set_schema,
|
||||
remove_schema
|
||||
end
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
-- Initialize the object.
|
||||
do
|
||||
Precursor {EDITABLE}
|
||||
-- schema_imp := Field_schema
|
||||
-- Add the "data". The data is the lables and positions.
|
||||
set_label (Default_label_field_name)
|
||||
set_x (Default_x)
|
||||
set_y (Default_y)
|
||||
set_width (Default_width)
|
||||
set_height (Default_height)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
schema: FIELD_SCHEMA
|
||||
-- The schema used to display and edit a FIELD.
|
||||
once
|
||||
create Result
|
||||
Result.extend_mandatory (Label_field)
|
||||
Result.extend_mandatory (X_field)
|
||||
Result.extend_mandatory (Y_field)
|
||||
Result.extend_mandatory (Width_field)
|
||||
Result.extend_mandatory (Height_field)
|
||||
-- Result.set_up
|
||||
end
|
||||
|
||||
Type: ANY
|
||||
-- Anchor.
|
||||
deferred
|
||||
end
|
||||
|
||||
label: STRING_32
|
||||
-- Identifier of this field.
|
||||
do
|
||||
check attached {STRING_32} value (Default_label_field_name) as s then
|
||||
Result := s
|
||||
end
|
||||
end
|
||||
|
||||
x: INTEGER_REF
|
||||
-- x-position of field in a dialog
|
||||
do
|
||||
check attached {INTEGER_REF} value (Default_x_field_name) as i then
|
||||
Result := i
|
||||
end
|
||||
end
|
||||
|
||||
y: INTEGER_REF
|
||||
-- y-position of field in a dialog
|
||||
do
|
||||
check attached {INTEGER_REF} value (Default_y_field_name) as i then
|
||||
Result := i
|
||||
end
|
||||
end
|
||||
|
||||
width: INTEGER_REF
|
||||
-- Width of this field. Used to create a control
|
||||
-- that is `width' pixels wide.
|
||||
do
|
||||
check attached {INTEGER_REF} value (Default_width_field_name) as i then
|
||||
Result := i
|
||||
end
|
||||
end
|
||||
|
||||
height: INTEGER_REF
|
||||
-- Height of this field. Used to create a control
|
||||
-- that is `height' pixels tall.
|
||||
do
|
||||
check attached {INTEGER_REF} value (Default_height_field_name) as i then
|
||||
Result := i
|
||||
end
|
||||
end
|
||||
|
||||
-- format: STRING is
|
||||
-- -- Used to set how the data is displayed.
|
||||
-- do
|
||||
-- Result ?= value_by_field (format_field)
|
||||
-- ensure
|
||||
-- valid_result: Result /= Void
|
||||
-- end
|
||||
--
|
||||
-- posible_formats: LINKED_SET [STRING]
|
||||
-- -- Set of posible formats which can be used in `format'.
|
||||
--
|
||||
-- function: STRING_32
|
||||
-- -- Function to be assigned to any widget created from
|
||||
-- -- this field.
|
||||
-- do
|
||||
-- Result ?= value_by_field (schema.formula_field)
|
||||
-- ensure
|
||||
-- valid_result: Result /= Void
|
||||
-- end
|
||||
|
||||
-- function_result_as_string: STRING_32
|
||||
-- -- The result of executing the `function' converted to
|
||||
-- -- a string.
|
||||
-- local
|
||||
---- p: FUNCTION_PARSER
|
||||
-- r: ANY
|
||||
-- t: like Type
|
||||
-- do
|
||||
-- if function = Void then
|
||||
-- Result := "Value is calculated, but no formula entered."
|
||||
-- else
|
||||
---- p.parse_string (function)
|
||||
---- r := parser.last_value
|
||||
-- if r.same_type (Type) then
|
||||
-- t ?= r
|
||||
-- check
|
||||
-- should_not_happen: t /= Void
|
||||
-- -- Because `r.same_type' insures `r' conforms to `t'.
|
||||
-- end
|
||||
-- Result := type_to_string (t)
|
||||
-- else
|
||||
-- -- there was a parse error.
|
||||
-- Result ?= r
|
||||
-- check
|
||||
-- should_not_happen: Result /= Void
|
||||
-- -- Because parser should return an error string
|
||||
-- -- if it failed to get a good result.
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
-- function_result_as_type: like type
|
||||
-- -- The result of executing the `function'.
|
||||
-- require
|
||||
-- has_function: function /= Void
|
||||
-- function_works: is_valid_function (function)
|
||||
-- local
|
||||
---- p: FUNCTION_PARSER
|
||||
-- do
|
||||
---- p.parse_string (function)
|
||||
---- Result := p.last_value
|
||||
-- end
|
||||
|
||||
feature -- Element Change
|
||||
|
||||
set_label (a_string: STRING_32)
|
||||
-- Change the `name'.
|
||||
require
|
||||
string_exists: a_string /= Void
|
||||
do
|
||||
extend_value (a_string, Default_label_field_name)
|
||||
ensure
|
||||
id_was_set: equal (label, a_string)
|
||||
end
|
||||
|
||||
set_x (a_x: INTEGER)
|
||||
do
|
||||
extend_value (a_x, Default_x_field_name)
|
||||
ensure
|
||||
x_was_set: x.item = a_x
|
||||
end
|
||||
|
||||
set_y (a_y: INTEGER)
|
||||
do
|
||||
extend_value (a_y, Default_y_field_name)
|
||||
ensure
|
||||
y_was_set: y.item = a_y
|
||||
end
|
||||
|
||||
set_width (a_width: INTEGER)
|
||||
-- Change `width'
|
||||
require
|
||||
valid_width: a_width > 0
|
||||
do
|
||||
extend_value (a_width, Default_width_field_name)
|
||||
ensure
|
||||
width_was_set: width.item = a_width
|
||||
end
|
||||
|
||||
set_height (a_height: INTEGER)
|
||||
-- Change `height'
|
||||
require
|
||||
valid_height: a_height > 0
|
||||
do
|
||||
extend_value (a_height, Default_height_field_name)
|
||||
ensure
|
||||
height_was_set: height.item = a_height
|
||||
end
|
||||
|
||||
-- set_format (a_format: STRING) is
|
||||
-- -- Change `format'
|
||||
-- require
|
||||
-- schema_exists: schema /= Void
|
||||
-- valid_format: posible_formats.has (a_format)
|
||||
-- do
|
||||
-- extend_with_field (a_format, format_field)
|
||||
-- extend (a_format, "format")
|
||||
-- ensure
|
||||
-- format_was_set: format = a_format
|
||||
-- end
|
||||
|
||||
-- set_function (a_string: STRING) is
|
||||
-- -- Change the `formula'
|
||||
-- require
|
||||
-- schema_exists: schema /= Void
|
||||
-- string_exists: a_string /= Void
|
||||
-- do
|
||||
-- extend_with_field (a_string, schema.formula_field)
|
||||
-- ensure
|
||||
-- formula_was_set: equal (formula, a_string)
|
||||
-- end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
is_calculated: BOOLEAN
|
||||
-- Should the value (produced by any control) use the result
|
||||
-- of executing (parsing) the `formula'? (Oposite is to use
|
||||
-- what ever data is set into the control.)
|
||||
-- fix -- Set by `use_formula' or `use_data'.
|
||||
do
|
||||
-- Result := formula.count >= 1
|
||||
end
|
||||
|
||||
is_schema_available: BOOLEAN
|
||||
-- Does Current have a schema?
|
||||
-- Redefined to always be True to follow the redefinition of `schema'.
|
||||
do
|
||||
Result := True
|
||||
end
|
||||
|
||||
feature -- Status setting
|
||||
|
||||
use_function
|
||||
-- Set `is_calculated' to True
|
||||
do
|
||||
-- is_calculated := True
|
||||
end
|
||||
|
||||
use_data
|
||||
-- Set `is_calculated' to False
|
||||
do
|
||||
-- is_calculated := False
|
||||
end
|
||||
|
||||
feature -- Query
|
||||
|
||||
-- parser: PARSER is
|
||||
-- -- Parser for evaluating the `formula'
|
||||
-- once
|
||||
-- create Result
|
||||
-- end
|
||||
|
||||
is_valid_data (a_value: ANY): BOOLEAN
|
||||
-- Is `a_value' valid data for this field?
|
||||
-- Must redefine `parsed' if redefine this feature.
|
||||
do
|
||||
Result := a_value /= Void and then a_value.conforms_to (Type)
|
||||
end
|
||||
|
||||
is_valid_function (a_function: STRING_32): BOOLEAN
|
||||
-- Can `a_function' be parsed, returning a result
|
||||
-- of the correct `type'?
|
||||
local
|
||||
-- p: FUNCTION_PARSER
|
||||
do
|
||||
-- p.parse_string (a_function)
|
||||
-- Result := p.last_value.same_type (type)
|
||||
end
|
||||
|
||||
string_to_type (a_string: STRING_32): like Type
|
||||
-- Convert `a_string' to an object of `Type'
|
||||
-- Default is to simply return `a_string' since
|
||||
-- it conforms to ANY if it exists.
|
||||
require
|
||||
valid_string: is_valid_data (a_string)
|
||||
do
|
||||
Result := a_string
|
||||
end
|
||||
|
||||
type_to_string (a_value: ANY): STRING_32
|
||||
-- The string representation of `a_value'.
|
||||
-- The default is to call feature `out' on `a_value' or to
|
||||
-- return the string "Void" or "Non-conforming data".
|
||||
do
|
||||
if a_value = Void then
|
||||
Result := "Void"
|
||||
elseif a_value /= Void and then not a_value.conforms_to (Type) then
|
||||
Result := "Non-conforming data"
|
||||
else
|
||||
Result := a_value.out
|
||||
end
|
||||
ensure
|
||||
result_exists: Result /= Void
|
||||
end
|
||||
|
||||
controls_from: LINKED_LIST [CONTROL]
|
||||
-- All the controls whose positioning is dictated by
|
||||
-- this field (i.e. created from this field)
|
||||
local
|
||||
c_list: LINKED_LIST [CONTROL]
|
||||
c: CONTROL
|
||||
do
|
||||
create Result.make
|
||||
c_list := control_list
|
||||
from c_list.start
|
||||
until c_list.exhausted
|
||||
loop
|
||||
c := c_list.item
|
||||
if c.field = Current then -- or c.field.formula.has_field (Current) then
|
||||
-- make a formula class and put parser in it.
|
||||
Result.extend (c)
|
||||
end
|
||||
c_list.forth
|
||||
end
|
||||
end
|
||||
|
||||
controls_dependent: LINKED_LIST [CONTROL]
|
||||
-- All the controls in `controls_from' plus any controls
|
||||
-- whose `formula' contains a reference to Current.
|
||||
local
|
||||
c_list: LINKED_LIST [CONTROL]
|
||||
c: CONTROL
|
||||
do
|
||||
create Result.make
|
||||
c_list := control_list
|
||||
from c_list.start
|
||||
until c_list.exhausted
|
||||
loop
|
||||
c := c_list.item
|
||||
if c.field = Current then -- or c.field.formula.has_field (Current) then
|
||||
-- make a formula class and put parser in it.
|
||||
Result.extend (c)
|
||||
end
|
||||
c_list.forth
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
feature -- Transformation
|
||||
|
||||
as_widget: CONTROL
|
||||
-- Each descendent class must create the appropriate control and
|
||||
-- put the control into `control_list'.
|
||||
deferred
|
||||
ensure
|
||||
result_has_field: Result.field = Current
|
||||
result_added_to_list: control_list.has (Result)
|
||||
end
|
||||
|
||||
feature {CONTROL} -- Implementation
|
||||
|
||||
control_list: LINKED_LIST [CONTROL]
|
||||
-- Keeps track of all the controls so one control can update
|
||||
-- others and used to make formulas work.
|
||||
-- NOTE: This can be a once feature here as these are only valid
|
||||
-- for the current execution.
|
||||
-- The creation procedures for CONTROL should add the created
|
||||
-- widget to the list; `destroy' from CONTROL should remove it.
|
||||
-- Declared as once function so the list (of EV_WIDGETs) does
|
||||
-- not get stored. That could get messy.
|
||||
once
|
||||
create Result.make
|
||||
end
|
||||
|
||||
schema_imp: FIELD_SCHEMA
|
||||
-- Implementation and/or anchor for `schema'. Set by `set_schema' and
|
||||
-- removed by `remove_schema.
|
||||
-- NOTE: The FIELDs in a SCHEMA will determine the keys to be
|
||||
-- used in `data_table' and will be used to build the controls
|
||||
-- for obtaining the values asscociated with the keys.
|
||||
|
||||
feature {NONE} -- Implementation (fields used by `field_schema')
|
||||
|
||||
Label_field: STRING_FIELD
|
||||
-- Create a field to store the `label' of a FIELD
|
||||
once
|
||||
create Result
|
||||
-- Result.extend (Default_name, Default_label_field_name)
|
||||
Result.set_label (Default_label_field_name)
|
||||
Result.set_x (0)
|
||||
Result.set_y (0)
|
||||
Result.set_width (Default_width)
|
||||
Result.set_height (Default_height)
|
||||
end
|
||||
|
||||
X_field: INTEGER_FIELD
|
||||
-- Create a field to store the `x' value of a FIELD
|
||||
once
|
||||
create Result
|
||||
-- Result.extend (Default_x_field_name, Default_x_field_name)
|
||||
Result.set_label (Default_x_field_name)
|
||||
Result.set_x (0)
|
||||
Result.set_y (50)
|
||||
Result.set_width (Default_width)
|
||||
Result.set_height (Default_height)
|
||||
end
|
||||
|
||||
Y_field: INTEGER_FIELD
|
||||
-- Create a field to store the `y' value of a FIELD
|
||||
once
|
||||
create Result
|
||||
Result.set_label (Default_y_field_name)
|
||||
Result.set_x (0)
|
||||
Result.set_y (100)
|
||||
Result.set_width (Default_width)
|
||||
Result.set_height (Default_height)
|
||||
end
|
||||
|
||||
Width_field: INTEGER_FIELD
|
||||
-- Create a field to store the `width' of a FIELD
|
||||
once
|
||||
create Result
|
||||
Result.set_label (Default_width_field_name)
|
||||
Result.set_x (0)
|
||||
Result.set_y (150)
|
||||
Result.set_width (Default_width)
|
||||
Result.set_height (Default_height)
|
||||
end
|
||||
|
||||
Height_field: INTEGER_FIELD
|
||||
-- Create a field to store the `height' of a FIELD
|
||||
once
|
||||
create Result
|
||||
Result.set_label (Default_height_field_name)
|
||||
Result.set_x (0)
|
||||
Result.set_y (200)
|
||||
Result.set_width (Default_width)
|
||||
Result.set_height (Default_height)
|
||||
end
|
||||
|
||||
feature {NONE} -- Inaplicable
|
||||
|
||||
set_schema (a_schema: like schema_imp)
|
||||
-- Change `schema' indirectly by changing `schema_imp'.
|
||||
do
|
||||
check
|
||||
should_not_be_called: False
|
||||
-- Because `schema' was redefined to a constant
|
||||
end
|
||||
end
|
||||
|
||||
remove_schema
|
||||
-- Make `schema' imp Void
|
||||
do
|
||||
check
|
||||
should_not_be_called: False
|
||||
-- Because `schema' was redefined to a constant
|
||||
end
|
||||
end
|
||||
|
||||
end
|
32
jj_vision/interface/fields/field_constants.e
Normal file
32
jj_vision/interface/fields/field_constants.e
Normal file
@@ -0,0 +1,32 @@
|
||||
note
|
||||
description: "[
|
||||
Constants for use by classes dealing with class {FIELD} (i.e {FIELD}
|
||||
and {SCHEMA} and any descendants.
|
||||
]"
|
||||
date: "28 Feb 04"
|
||||
author: "Jimmy J. Johnson"
|
||||
copyright: "Copyright 2012, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum License v2 (see forum.txt)"
|
||||
URL: "$URL: file:///F:/eiffel_repositories/jj_vision/trunk/interface/fields/field_constants.e $"
|
||||
date: "$Date: 2012-03-16 14:05:07 -0400 (Fri, 16 Mar 2012) $"
|
||||
revision: "$Revision: 7 $"
|
||||
|
||||
|
||||
class
|
||||
FIELD_CONSTANTS
|
||||
|
||||
feature -- Access
|
||||
|
||||
Default_label_field_name: STRING = "label"
|
||||
Default_x_field_name: STRING = "x"
|
||||
Default_y_field_name: STRING = "y"
|
||||
Default_height_field_name: STRING = "height"
|
||||
Default_width_field_name: STRING = "width"
|
||||
|
||||
Default_name: STRING = "name: "
|
||||
Default_x: INTEGER = 0
|
||||
Default_y: INTEGER = 0
|
||||
Default_height: INTEGER = 30
|
||||
Default_width: INTEGER = 150
|
||||
|
||||
end
|
33
jj_vision/interface/fields/field_ref.e
Normal file
33
jj_vision/interface/fields/field_ref.e
Normal file
@@ -0,0 +1,33 @@
|
||||
note
|
||||
description: "[
|
||||
A reference to a {FIELD} for use by once feature
|
||||
`user_identifier_field' from {SCHEMA}
|
||||
]"
|
||||
date: "7 Oct 07"
|
||||
author: "Jimmy J. Johnson"
|
||||
copyright: "Copyright 2012, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum License v2 (see forum.txt)"
|
||||
URL: "$URL: file:///F:/eiffel_repositories/jj_vision/trunk/interface/fields/field_ref.e $"
|
||||
date: "$Date: 2012-03-16 14:05:07 -0400 (Fri, 16 Mar 2012) $"
|
||||
revision: "$Revision: 7 $"
|
||||
|
||||
class
|
||||
FIELD_REF
|
||||
|
||||
create
|
||||
set_field
|
||||
|
||||
feature -- Access
|
||||
|
||||
field: FIELD
|
||||
-- Item held by current
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_field (a_field: FIELD)
|
||||
-- Change the `field'.
|
||||
do
|
||||
field := a_field
|
||||
end
|
||||
|
||||
end
|
24
jj_vision/interface/fields/field_schema.e
Normal file
24
jj_vision/interface/fields/field_schema.e
Normal file
@@ -0,0 +1,24 @@
|
||||
note
|
||||
description: "[
|
||||
A {SCHEMA} for a {FIELD}
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
copyright: "Copyright 2012, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum License v2 (see forum.txt)"
|
||||
URL: "$URL: file:///F:/eiffel_repositories/jj_vision/trunk/interface/fields/field_schema.e $"
|
||||
date: "$Date: 2012-03-16 14:05:07 -0400 (Fri, 16 Mar 2012) $"
|
||||
revision: "$Revision: 7 $"
|
||||
|
||||
class
|
||||
FIELD_SCHEMA
|
||||
|
||||
inherit
|
||||
|
||||
SCHEMA
|
||||
|
||||
create
|
||||
default_create
|
||||
create {LINKED_LIST}
|
||||
make
|
||||
|
||||
end
|
42
jj_vision/interface/fields/formula_field.e
Normal file
42
jj_vision/interface/fields/formula_field.e
Normal file
@@ -0,0 +1,42 @@
|
||||
note
|
||||
description: "[
|
||||
A {FIELD} in which to edit formulas
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
copyright: "Copyright 2012, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum License v2 (see forum.txt)"
|
||||
URL: "$URL: file:///F:/eiffel_repositories/jj_vision/trunk/interface/fields/formula_field.e $"
|
||||
date: "$Date: 2012-03-16 14:05:07 -0400 (Fri, 16 Mar 2012) $"
|
||||
revision: "$Revision: 7 $"
|
||||
|
||||
class FORMULA_FIELD
|
||||
-- creates an edit box.
|
||||
|
||||
inherit
|
||||
|
||||
STRING_FIELD
|
||||
redefine
|
||||
is_valid_data
|
||||
end
|
||||
|
||||
create
|
||||
default_create
|
||||
|
||||
feature -- Access
|
||||
|
||||
is_valid_data (a_data: ANY): BOOLEAN
|
||||
-- Is the value in `a_data' a valid representation
|
||||
-- for the `Type' of the data.
|
||||
local
|
||||
-- scan: SCANNER
|
||||
-- s: STRING
|
||||
do
|
||||
---- create scan
|
||||
-- s ?= a_data
|
||||
-- if s /= Void then
|
||||
---- scan.scan_string (s)
|
||||
-- end
|
||||
---- Result := Precursor {STRING_FIELD} (a_data) and then not scan.scanning_error
|
||||
end
|
||||
|
||||
end
|
74
jj_vision/interface/fields/integer_field.e
Normal file
74
jj_vision/interface/fields/integer_field.e
Normal file
@@ -0,0 +1,74 @@
|
||||
note
|
||||
description: "[
|
||||
A {FIELD} used to create a {INTEGER_CONTROL} and position that control.
|
||||
]"
|
||||
date: "24 Feb 04"
|
||||
author: "Jimmy J. Johnson"
|
||||
copyright: "Copyright 2012, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum License v2 (see forum.txt)"
|
||||
URL: "$URL: file:///F:/eiffel_repositories/jj_vision/trunk/interface/fields/integer_field.e $"
|
||||
date: "$Date: 2012-03-16 14:05:07 -0400 (Fri, 16 Mar 2012) $"
|
||||
revision: "$Revision: 7 $"
|
||||
|
||||
class
|
||||
INTEGER_FIELD
|
||||
|
||||
inherit
|
||||
|
||||
COMPARABLE_FIELD
|
||||
redefine
|
||||
default_create,
|
||||
is_valid_data,
|
||||
string_to_type
|
||||
end
|
||||
|
||||
create
|
||||
default_create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
-- Create an instance
|
||||
do
|
||||
Precursor {COMPARABLE_FIELD}
|
||||
end
|
||||
|
||||
feature -- Querry
|
||||
|
||||
Type: INTEGER_REF
|
||||
-- Implementation (and anchor) of `value'.
|
||||
-- Redefined to change type.
|
||||
once
|
||||
create Result
|
||||
end
|
||||
|
||||
string_to_type (a_string: STRING_32): like type
|
||||
-- Convert `a_string' to an object of `Type'.
|
||||
do
|
||||
create Result
|
||||
Result.set_item (a_string.to_integer)
|
||||
end
|
||||
|
||||
is_valid_data (a_value: ANY): BOOLEAN
|
||||
-- Is the value in the display a valid representation
|
||||
-- for the type of the data.
|
||||
do
|
||||
Result := Precursor {COMPARABLE_FIELD} (a_value)
|
||||
if not Result then
|
||||
-- It may be that `a_value' is a STRING representation
|
||||
-- of an integer, so check the string and convert it.
|
||||
if attached {STRING} a_value as s then
|
||||
Result := s.is_integer
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Transformation
|
||||
|
||||
as_widget: INTEGER_CONTROL
|
||||
-- Create the appropriate type of control
|
||||
do
|
||||
create Result.make_from_field (Current)
|
||||
end
|
||||
|
||||
end
|
444
jj_vision/interface/fields/schema.e
Normal file
444
jj_vision/interface/fields/schema.e
Normal file
@@ -0,0 +1,444 @@
|
||||
note
|
||||
description: "[
|
||||
A list of {FIELD} where each {FIELD} describes the placement
|
||||
of a {CONTROL} withing an {EDITOR}
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
copyright: "Copyright 2012, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum License v2 (see forum.txt)"
|
||||
URL: "$URL: file:///F:/eiffel_repositories/jj_vision/trunk/interface/fields/schema.e $"
|
||||
date: "$Date: 2012-03-16 14:05:07 -0400 (Fri, 16 Mar 2012) $"
|
||||
revision: "$Revision: 7 $"
|
||||
|
||||
class
|
||||
SCHEMA
|
||||
|
||||
inherit
|
||||
|
||||
LINKED_LIST [FIELD]
|
||||
rename
|
||||
item as field
|
||||
redefine
|
||||
default_create,
|
||||
make,
|
||||
copy,
|
||||
is_equal,
|
||||
-- Redefine the following in order to set the time the schema was
|
||||
-- changed so the dialog editor can use it to determine if it needs
|
||||
-- to redraw the view.
|
||||
extend,
|
||||
put_front,
|
||||
put_left,
|
||||
put_right,
|
||||
merge_left,
|
||||
merge_right,
|
||||
-- Need to redefine the following in order to preserve the invariant
|
||||
-- dealing with the keys (key fields must reside in current). If a
|
||||
-- field is removed from Current it can no longer be used as a key.
|
||||
-- Other features are defined in terms of this, so these four should
|
||||
-- take care of all features from LINKED_LIST.
|
||||
remove,
|
||||
replace,
|
||||
remove_right,
|
||||
wipe_out
|
||||
select
|
||||
make
|
||||
end
|
||||
|
||||
LINKED_LIST [FIELD] -- inherited identically as above except for `make'
|
||||
rename
|
||||
make as list_make,
|
||||
item as field
|
||||
redefine
|
||||
default_create,
|
||||
-- make,
|
||||
copy,
|
||||
is_equal,
|
||||
-- Redefine the following in order to set the time the schema was
|
||||
-- changed so the dialog editor can use it to determine if it needs
|
||||
-- to redraw the view.
|
||||
extend,
|
||||
put_front,
|
||||
put_left,
|
||||
put_right,
|
||||
merge_left,
|
||||
merge_right,
|
||||
-- Need to redefine the following in order to preserve the invariant
|
||||
-- dealing with the keys (key fields must reside in current). If a
|
||||
-- field is removed from Current it can no longer be used as a key.
|
||||
-- Other features are defined in terms of this, so these four should
|
||||
-- take care of all features from LINKED_LIST.
|
||||
remove,
|
||||
replace,
|
||||
remove_right,
|
||||
wipe_out
|
||||
end
|
||||
|
||||
EDITABLE
|
||||
redefine
|
||||
default_create,
|
||||
copy,
|
||||
is_equal
|
||||
end
|
||||
|
||||
create
|
||||
default_create
|
||||
create {LINKED_LIST}
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
default_create
|
||||
-- Create an instance
|
||||
-- Redefined because `new_chain' from LINKED_LIST uses `make'.
|
||||
do
|
||||
list_make
|
||||
Precursor {EDITABLE}
|
||||
create keys_imp.make
|
||||
create mandatory_fields.make
|
||||
create time_modified.set_now_utc_fine
|
||||
extend_mandatory (Name_field)
|
||||
end
|
||||
|
||||
make
|
||||
-- Called by `new_chain' from LINKED_LIST
|
||||
do
|
||||
Precursor {LINKED_LIST}
|
||||
default_create
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
identifying_field: FIELD
|
||||
-- The field used to get a string which will identify an object.
|
||||
do
|
||||
Result := identifying_field_ref.field
|
||||
end
|
||||
|
||||
keys: LINKED_SET [STRING]
|
||||
-- The keys to use in comparison of EDITABLEs using Current.
|
||||
-- NOTE: Even though FIELDs are used in `keys_imp', ultimately the label
|
||||
-- of the FIELD will be used to access data in an EDITABLE, hence the result type.
|
||||
do
|
||||
create Result.make
|
||||
from keys_imp.start
|
||||
until keys_imp.exhausted
|
||||
loop
|
||||
Result.extend (keys_imp.item.label)
|
||||
keys_imp.forth
|
||||
end
|
||||
end
|
||||
|
||||
key_fields: LINKED_SET [FIELD]
|
||||
-- The fields which are used as keys
|
||||
do
|
||||
create Result.make
|
||||
from keys_imp.start
|
||||
until keys_imp.exhausted
|
||||
loop
|
||||
Result.extend (keys_imp.item)
|
||||
keys_imp.forth
|
||||
end
|
||||
end
|
||||
|
||||
Name_field: STRING_FIELD
|
||||
-- The FIELD used to access the "name" of the object.
|
||||
once
|
||||
create Result
|
||||
Result.set_label ("Name: ")
|
||||
end
|
||||
|
||||
time_modified: YMDHMS_TIME
|
||||
-- Time at which a modification was made (such as adding
|
||||
-- or removing a field).
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_identifying_field (a_field: STRING_FIELD)
|
||||
-- Change the `user_identifying_field'
|
||||
require
|
||||
field_exists: a_field /= Void
|
||||
do
|
||||
identifying_field_ref.set_field (a_field)
|
||||
ensure
|
||||
field_was_assigned: identifying_field = a_field
|
||||
end
|
||||
|
||||
feature -- Basic operations
|
||||
|
||||
put_front (a_field: like field)
|
||||
-- Add `a_field' to beginning.
|
||||
-- Do not move cursor.
|
||||
-- Reset `time_modified'.
|
||||
do
|
||||
Precursor {LINKED_LIST} (a_field)
|
||||
time_modified.set_now_utc_fine
|
||||
end
|
||||
|
||||
extend (a_field: like field)
|
||||
-- Add `a_field' to the end.
|
||||
-- Do not move cursor.
|
||||
-- Reset `time_modified'.
|
||||
do
|
||||
Precursor {LINKED_LIST} (a_field)
|
||||
time_modified.set_now_utc_fine
|
||||
end
|
||||
|
||||
extend_mandatory (a_field: like field)
|
||||
-- Add `a_field' to Current and make it a manditory field.
|
||||
-- Reset `time_modified'.
|
||||
require
|
||||
is_extendible: extendible
|
||||
do
|
||||
check
|
||||
field_exists: a_field /= Void
|
||||
end
|
||||
mandatory_fields.extend (a_field)
|
||||
extend (a_field)
|
||||
ensure
|
||||
has_field: has (a_field)
|
||||
has_as_mandatory: has_mandatory (a_field)
|
||||
end
|
||||
|
||||
put_left (a_field: like field)
|
||||
-- Add `a_field' to the left of cursor position.
|
||||
-- Do not move cursor.
|
||||
-- Reset `time_modified'.
|
||||
do
|
||||
Precursor {LINKED_LIST} (a_field)
|
||||
time_modified.set_now_utc_fine
|
||||
end
|
||||
|
||||
put_right (a_field: like field)
|
||||
-- Add `a_field' to the left of cursor position.
|
||||
-- Do not move cursor.
|
||||
-- Reset `time_modified'.
|
||||
do
|
||||
Precursor {LINKED_LIST} (a_field)
|
||||
time_modified.set_now_utc_fine
|
||||
end
|
||||
|
||||
merge_left (a_other: like Current)
|
||||
-- Merge `a_other' into current structure before cursor
|
||||
-- position. Do not move cursor. Empty `other'.
|
||||
-- Reset `time_modified'.
|
||||
do
|
||||
Precursor {LINKED_LIST} (a_other)
|
||||
time_modified.set_now_utc_fine
|
||||
end
|
||||
|
||||
merge_right (a_other: like Current)
|
||||
-- Merge `a_other' into current structure after cursor
|
||||
-- position. Do not move cursor. Empty `other'.
|
||||
-- Reset `time_modified'.
|
||||
do
|
||||
Precursor {LINKED_LIST} (a_other)
|
||||
time_modified.set_now_utc_fine
|
||||
end
|
||||
|
||||
remove
|
||||
-- Remove current item.
|
||||
-- Move cursor to right neighbor
|
||||
-- (or `after' if no right neighbor).
|
||||
-- Reset `time_modified'.
|
||||
-- Also, redefined to preserve invariant.
|
||||
do
|
||||
if attached {COMPARABLE_FIELD} field as cf then
|
||||
keys_imp.prune (cf)
|
||||
else
|
||||
-- Do not have to worry about it, because if `v' is not
|
||||
-- a COMPARABLE_FIELD it would never be in `keys' anyway.
|
||||
end
|
||||
Precursor {LINKED_LIST}
|
||||
time_modified.set_now_utc_fine
|
||||
end
|
||||
|
||||
replace (v: like field)
|
||||
-- Replace current item by `v'.
|
||||
-- Reset `time_modified'.
|
||||
-- Also, redefined to preserve invariant.
|
||||
do
|
||||
if attached {COMPARABLE_FIELD} v as cf then
|
||||
keys_imp.prune (cf)
|
||||
else
|
||||
-- Do not have to worry about it, because if `v' is not
|
||||
-- a COMPARABLE_FIELD it would never be in `keys' anyway.
|
||||
end
|
||||
Precursor {LINKED_LIST} (v)
|
||||
time_modified.set_now_utc_fine
|
||||
end
|
||||
|
||||
remove_right
|
||||
-- Remove item to the right of cursor position.
|
||||
-- Do not move cursor.
|
||||
-- Reset `time_modified'.
|
||||
-- Also, redefined to preserve invariant.
|
||||
do
|
||||
if attached {COMPARABLE_FIELD} i_th (index + 1) as cf then
|
||||
keys_imp.prune (cf)
|
||||
else
|
||||
-- Do not have to worry about it, because if `v' is not
|
||||
-- a COMPARABLE_FIELD it would never be in `keys' anyway.
|
||||
end
|
||||
Precursor {LINKED_LIST}
|
||||
time_modified.set_now_utc_fine
|
||||
end
|
||||
|
||||
wipe_out
|
||||
-- Remove all items.
|
||||
-- Reset `time_modified'.
|
||||
-- Also, redefined to preserve invariant.
|
||||
do
|
||||
keys_imp.wipe_out
|
||||
Precursor {LINKED_LIST}
|
||||
time_modified.set_now_utc_fine
|
||||
end
|
||||
|
||||
add_key_field (a_field: COMPARABLE_FIELD)
|
||||
-- Add `a_field' to use in comparisons
|
||||
require
|
||||
field_exists: a_field /= Void
|
||||
has_field: has (a_field)
|
||||
do
|
||||
keys_imp.extend (a_field)
|
||||
ensure
|
||||
has_key: keys_imp.has (a_field)
|
||||
end
|
||||
|
||||
prune_key_field (a_field: COMPARABLE_FIELD)
|
||||
-- Remove `a_field' so it no longer is used in comparisons
|
||||
require
|
||||
field_exists: a_field /= Void
|
||||
do
|
||||
keys_imp.prune (a_field)
|
||||
ensure
|
||||
removed: not keys_imp.has (a_field)
|
||||
end
|
||||
|
||||
promote_key_field (a_field: COMPARABLE_FIELD)
|
||||
-- Move `a_field' toward the beginning of `keys' by one, so it
|
||||
-- will be a "more important" key.
|
||||
require
|
||||
field_exists: a_field /= Void
|
||||
has_as_key: key_fields.has (a_field)
|
||||
local
|
||||
i: INTEGER
|
||||
do
|
||||
if keys_imp.count > 1 then
|
||||
i := keys_imp.index_of (a_field, 1)
|
||||
if i > 1 then
|
||||
go_i_th (i - 1)
|
||||
swap (i)
|
||||
end
|
||||
end
|
||||
ensure
|
||||
field_was_promoted:
|
||||
end
|
||||
|
||||
demote_key_field (a_field: COMPARABLE_FIELD)
|
||||
-- Move `a_field' toward the end of `keys' by one, so it
|
||||
-- will be a "less important" key.
|
||||
require
|
||||
field_exists: a_field /= Void
|
||||
has_as_key: key_fields.has (a_field)
|
||||
local
|
||||
i: INTEGER
|
||||
do
|
||||
if keys_imp.count > 1 then
|
||||
i := keys_imp.index_of (a_field, 1)
|
||||
if i < count then
|
||||
go_i_th (i + 1)
|
||||
swap (i)
|
||||
end
|
||||
end
|
||||
ensure
|
||||
field_was_demoted:
|
||||
end
|
||||
|
||||
set_key_primary (a_field: COMPARABLE_FIELD)
|
||||
-- Move `a_field' toward the end of `keys' by one, so it
|
||||
-- will be a "less important" key.
|
||||
require
|
||||
field_exists: a_field /= Void
|
||||
has_as_key: key_fields.has (a_field)
|
||||
local
|
||||
i: INTEGER
|
||||
do
|
||||
if keys_imp.count > 1 then
|
||||
i := keys_imp.index_of (a_field, 1)
|
||||
if i /= 1 then
|
||||
go_i_th (1)
|
||||
swap (i)
|
||||
end
|
||||
end
|
||||
ensure
|
||||
field_is_primary: key_fields.index_of (a_field, 1) = 1
|
||||
end
|
||||
|
||||
feature -- Querry
|
||||
|
||||
has_mandatory (a_field: like field): BOOLEAN
|
||||
-- Is `a_field' required to always be in this schema?
|
||||
-- (I.e. can it never be deleted?)
|
||||
require
|
||||
field_exists: a_field /= Void
|
||||
do
|
||||
Result := mandatory_fields.has (a_field)
|
||||
ensure
|
||||
definition: Result = mandatory_fields.has (a_field)
|
||||
end
|
||||
|
||||
feature -- Duplication
|
||||
|
||||
copy (other: like Current)
|
||||
-- Update current object using fields of object attached
|
||||
-- to `other', so as to yield equal objects.
|
||||
-- Redefined to merge the copy operations from both ancestors.
|
||||
-- NOTE: Feature `infix "<"' from VIEWABLE only checks the `id'
|
||||
-- and assumes if the `id' (and hence the `time_stamp' from both
|
||||
-- objects are equal the object must have been copied and is
|
||||
-- therefore equal.
|
||||
do
|
||||
Precursor {LINKED_LIST} (other)
|
||||
Precursor {EDITABLE} (other)
|
||||
end
|
||||
|
||||
feature -- Comparison
|
||||
|
||||
is_equal (other: like Current): BOOLEAN
|
||||
-- Is Current equal to `other'?
|
||||
do
|
||||
-- Precursor {VIEWABLE} uses feature `infix "<"' to do the
|
||||
-- comparison, and there is no less than feature in LINKED_LIST,
|
||||
-- therefore this feature makes the BIG assumption that if
|
||||
-- the `id' and `time_stamp' (from VIEWABLE) of both objects
|
||||
-- are the same then it must have been a copy. There is no other
|
||||
-- way to make the `time_stamps' equal.
|
||||
Result := Precursor {EDITABLE} (other)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
keys_imp: LINKED_SET [COMPARABLE_FIELD]
|
||||
-- Set of fields whose associated values can be used to compare
|
||||
-- one EDITABLE to another in feature `infix "<"' from EDITABLE.
|
||||
-- The order implies the more significant fields.
|
||||
|
||||
mandatory_fields: LINKED_SET [FIELD]
|
||||
-- Set of fields which can not be deleted from Current.
|
||||
|
||||
identifying_field_ref: FIELD_REF
|
||||
-- The field to be used as `identifying_field' as set by the user
|
||||
-- in place of the default field.
|
||||
once
|
||||
create Result.set_field (Name_field)
|
||||
end
|
||||
|
||||
invariant
|
||||
|
||||
keys_imp_exists: keys_imp /= Void
|
||||
manditory_fields_exists: mandatory_fields /= Void
|
||||
keys_reside_in_current: key_fields.for_all (agent has)
|
||||
mandatory_fields_reside_in_current: mandatory_fields.for_all (agent has)
|
||||
|
||||
end
|
48
jj_vision/interface/fields/string_field.e
Normal file
48
jj_vision/interface/fields/string_field.e
Normal file
@@ -0,0 +1,48 @@
|
||||
note
|
||||
description: "[
|
||||
A {FIELD} describing the placement of a {STRING_CONTROL}
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
copyright: "Copyright 2012, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum License v2 (see forum.txt)"
|
||||
URL: "$URL: file:///F:/eiffel_repositories/jj_vision/trunk/interface/fields/string_field.e $"
|
||||
date: "$Date: 2012-03-16 14:05:07 -0400 (Fri, 16 Mar 2012) $"
|
||||
revision: "$Revision: 7 $"
|
||||
|
||||
class STRING_FIELD
|
||||
-- creates an edit box.
|
||||
|
||||
inherit
|
||||
|
||||
COMPARABLE_FIELD
|
||||
|
||||
create
|
||||
default_create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
feature -- Access
|
||||
|
||||
feature -- Querry
|
||||
|
||||
type: STRING_32
|
||||
-- Implementation (and anchor) of `value'.
|
||||
-- Redefined to change type.
|
||||
once
|
||||
create Result.make_from_string ("")
|
||||
end
|
||||
|
||||
as_type (a_string: STRING_32): like type
|
||||
-- Convert `a_string' to an object of `Type'.
|
||||
do
|
||||
Result := a_string
|
||||
end
|
||||
|
||||
feature -- Transformation
|
||||
|
||||
as_widget: STRING_CONTROL
|
||||
do
|
||||
create Result.make_from_field (Current)
|
||||
end
|
||||
|
||||
end
|
82
jj_vision/interface/fields/ymd_time_field.e
Normal file
82
jj_vision/interface/fields/ymd_time_field.e
Normal file
@@ -0,0 +1,82 @@
|
||||
note
|
||||
description: "[
|
||||
A {FIELD} decribing the placement of a {YMD_TIME_CONTROL}
|
||||
]"
|
||||
author: "Jimmy J. Johnson"
|
||||
copyright: "Copyright 2012, Jimmy J. Johnson"
|
||||
license: "Eiffel Forum License v2 (see forum.txt)"
|
||||
URL: "$URL: file:///F:/eiffel_repositories/jj_vision/trunk/interface/fields/ymd_time_field.e $"
|
||||
date: "$Date: 2012-03-16 14:05:07 -0400 (Fri, 16 Mar 2012) $"
|
||||
revision: "$Revision: 7 $"
|
||||
|
||||
class
|
||||
YMD_TIME_FIELD
|
||||
|
||||
inherit
|
||||
|
||||
COMPARABLE_FIELD
|
||||
redefine
|
||||
is_valid_data,
|
||||
string_to_type,
|
||||
type_to_string
|
||||
end
|
||||
|
||||
create
|
||||
default_create
|
||||
|
||||
feature -- Access
|
||||
|
||||
Type: YMD_TIME
|
||||
-- Implementation (and anchor) of `value'.
|
||||
-- Redefined to change type.
|
||||
once
|
||||
create Result.set_now
|
||||
end
|
||||
|
||||
is_valid_data (a_value: ANY): BOOLEAN
|
||||
-- Is the value in `a_value' a valid representation
|
||||
-- for the `Type' of the data.
|
||||
local
|
||||
f: YMD_TIME_FORMATTER
|
||||
do
|
||||
Result := Precursor {COMPARABLE_FIELD} (a_value)
|
||||
if not Result then
|
||||
-- It may be that `a_value' is a STRING representation
|
||||
-- of a date, so check the string and convert it.
|
||||
create f
|
||||
if attached {STRING} a_value as s then
|
||||
Result := f.is_valid (s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
string_to_type (a_string: STRING_32): like Type
|
||||
-- Convert `a_string' to a YMD_TIME
|
||||
local
|
||||
f: YMD_TIME_FORMATTER
|
||||
do
|
||||
create f
|
||||
Result := f.to_ymd_time (a_string)
|
||||
end
|
||||
|
||||
type_to_string (a_value: ANY): STRING_32
|
||||
-- The string representation of `a_value'.
|
||||
local
|
||||
f: YMD_TIME_FORMATTER
|
||||
do
|
||||
if attached {YMD_TIME} a_value as t then
|
||||
create f
|
||||
Result := f.to_string (t)
|
||||
else
|
||||
Result := Precursor {COMPARABLE_FIELD} (a_value)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Transformation
|
||||
|
||||
as_widget: YMD_TIME_CONTROL
|
||||
do
|
||||
create Result.make_from_field (Current)
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user