192
194
;; links in editor text
199
;; 1) fix link position - should cover the length of the component
200
;; 2) make sure the component has linkID attribute (and clickback?)
201
;; 3) update link start/end in datastructure when saving (currently its constantly updated, is this a problem?)
204
; parse a document to find the components
205
(define (parse-document)
206
(let* ((the-editor (ask this-obj 'getcomponent))
207
(the-doc (ask this-obj 'getdocument))
208
(the-text (get-text the-editor))
210
(iterator (<javax.swing.text.ElementIterator> the-doc)))
212
; helper function to walk the document
213
(define (walk-document element :: <javax.swing.text.Element>)
214
(if (not (is-null? element))
217
(let* ((as :: <javax.swing.text.AttributeSet> (element:getAttributes))
218
(this-linkID (get-attribute-linkID as)))
219
(format #t "element attributes: ~a [~a]~%~!" as this-linkID)
220
; is it a link? (element is a panel, and has a linkID)
222
(as:containsAttribute
223
javax.swing.text.AbstractDocument:ElementNameAttribute
224
javax.swing.text.StyleConstants:ComponentElementName)
225
(not (is-null? this-linkID)))
226
(let* ((the-component :: <javax.swing.JComponent> (javax.swing.text.StyleConstants:getComponent as))
227
(the-component-class (the-component:getClass)))
228
(format #t "component: ~a~%~!" the-component-class)
229
(if (instance? the-component javax.swing.JPanel)
230
(let* ((children (get-container-children the-component))
231
(first-panel (list-ref children 0))
232
(first-panel-children (get-container-children first-panel))
233
(the-text-pane :: <javax.swing.JTextPane> (list-ref first-panel-children 0))
234
(this-link (get 'links this-linkID))
235
(link-text (the-text-pane:getText))
236
(link-text-len (string-length link-text))
237
(offset-link-start (+ (element:getStartOffset) link-offset))
238
(offset-link-end (+ (element:getEndOffset) link-offset))
239
(doc-link-len (- offset-link-end offset-link-start)))
240
(format #t "the-text-pane: ~a~%~!" (the-text-pane:getText))
242
; insert link text into the extracted document content
243
(set! the-text (string-replace the-text
248
; update the link positions
249
(if (not (is-null? this-link))
251
(ask this-link 'set-start-index! offset-link-start)
252
(ask this-link 'set-end-index! (+ offset-link-start link-text-len))))
254
; update the link offset
255
(set! link-offset (+ link-offset (- link-text-len doc-link-len)))
257
(format #t "doc text after insert (link-offset: ~a): ~a~%~!" link-offset the-text)
259
(walk-document (iterator:next)))))
261
(format #t "doc text: ~a~%~!" the-text)
262
(walk-document (iterator:next))
194
272
; clickback for links
195
273
(define (clickback this-linkID)
196
274
(display "clickback in hypertext pane ")(newline)
1251
1334
(lambda (self proc)
1252
1335
(set! htp-endupdate proc)
1337
(obj-put this-obj 'set-clickback
1338
(lambda (self this-linkID start-index len)
1339
(set-clickback this-linkID start-index len)
1254
1341
;; based on the selection, determine whether to enable newlink button
1255
1342
(obj-put this-obj 'selection-newlink-check
1257
1344
(check-links-overlap (getselstart) (getselend))))
1260
1347
; read-only hypertextpane
1261
1348
(define (make-hypertextpane-readonly