Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
extending [2016/03/24 10:04] christian [Add a new Smalltalk class] |
extending [2016/09/28 23:05] (current) 93.204.170.83 ↷ Links adapted because of a move operation |
||
---|---|---|---|
Line 42: | Line 42: | ||
=== Choose a class name === | === Choose a class name === | ||
- | As name for this example, I use '' | + | As name for this example, I use '' |
=== Choose the superclass === | === Choose the superclass === | ||
Line 87: | Line 87: | ||
Since a new type is defined, the object types have to be reset with | Since a new type is defined, the object types have to be reset with | ||
<code smalltalk> | <code smalltalk> | ||
- | PDF resetObjecttypes | + | PDF resetObjecttypes. |
</ | </ | ||
- | so that the new type can be found. | + | This clears the cache for all the object types (Smalltalk classes - 137 at the time of writing). On next access, the cache is filled with all known types, including the newly defined ones, so that the new type can be found. |
+ | |||
+ | This has to be done only when a new class is defined. | ||
=== Use the new type for the containing attributes === | === Use the new type for the containing attributes === | ||
Line 119: | Line 121: | ||
==== Add attributes ==== | ==== Add attributes ==== | ||
- | add attribute method | + | Attributes are added as methods in protocol '' |
- | add pragmas | + | The first two attributes (of 4) look like this in the PDF specification: |
+ | |||
+ | {{: | ||
+ | |||
+ | The corresponding methods look like this: | ||
+ | |||
+ | <code smalltalk> | ||
+ | Type | ||
+ | <type: #Name> | ||
+ | < | ||
+ | ^self objectAt: #Type ifAbsent: [#Border asPDF] | ||
+ | </ | ||
+ | |||
+ | <code smalltalk> | ||
+ | W | ||
+ | <type: # | ||
+ | < | ||
+ | ^self objectAt: #W ifAbsent: [1 asPDF] | ||
+ | </ | ||
+ | |||
+ | An attribute method consists of a number of describing | ||
+ | |||
+ | === The type: pragma === | ||
+ | |||
+ | Mandatory is the ''< | ||
+ | |||
+ | === The documentation pragma === | ||
+ | |||
+ | The documentation is specified in the ''< | ||
+ | |||
+ | The documentation is taken directly from the specification and edited, so that all information is removed which is expressed directly in the method. In our example, the " | ||
+ | |||
+ | The description of the default value is also removed, because this is evident from the access code. | ||
+ | |||
+ | Also references to other parts of the specification are removed (which is not the case in the example). | ||
+ | |||
+ | === The version: pragma === | ||
+ | |||
+ | Often, new attributes were added with later PDF versions. The version of an attribute, if it is higher than the version of the type, can be noted with the ''< | ||
+ | |||
+ | === The access code === | ||
+ | |||
+ | The access code can be either | ||
+ | <code smalltalk> | ||
+ | ^self objectAt: #Type ifAbsent: [#Border asPDF] | ||
+ | </ | ||
+ | |||
+ | for optional attributes with a default value, or | ||
+ | <code smalltalk> | ||
+ | ^self objectAt: #Type | ||
+ | </ | ||
+ | |||
+ | for a required attribute. This will raise an error if the attribute is not present in the object. | ||
+ | |||
+ | The method will return the object of the value of the attribute. The object is either stored directly in the attribute or a reference to it. In any case, the object is returned. To access the value (object or reference), the following methods can be used: | ||
+ | <code smalltalk> | ||
+ | ^self at: #Type ifAbsent: [#Border asPDF] | ||
+ | </ | ||
+ | <code smalltalk> | ||
+ | ^self at: #Type | ||
+ | </ | ||
- | copy and edit comment | ||
===== Customize an object type ===== | ===== Customize an object type ===== | ||
- | docs, icon, string, attributes | + | Now, the PDF type is sufficiently defined to be usefully displayed in the PDFExplorer. But more can be done by defining some of the following methods. |
+ | |||
+ | ==== Optional customization methods ==== | ||
+ | |||
+ | === Display name === | ||
+ | |||
+ | The method '' | ||
+ | |||
+ | === Icon === | ||
+ | |||
+ | The method '' | ||
+ | |||
+ | === Excluding | ||
+ | |||
+ | Some attributes clutter the treeview on the left side of the PDFExplorer. For example, every '' | ||
+ | |||
+ | By defining the method '' | ||
+ | |||
+ | <code smalltalk> | ||
+ | displayKeysToOmit | ||
+ | ^super displayKeysToOmit | ||
+ | </ |