1248 ]. |
1239 ]. |
1249 |
1240 |
1250 |
1241 |
1251 ! ! |
1242 ! ! |
1252 |
1243 |
1253 !UIPainterView::ListHolder class methodsFor:'instance creation'! |
|
1254 |
|
1255 for:aPainter |
|
1256 ^ self new for:aPainter |
|
1257 ! ! |
|
1258 |
|
1259 !UIPainterView::ListHolder methodsFor:'accessing'! |
|
1260 |
|
1261 painter |
|
1262 "returns painter |
|
1263 " |
|
1264 ^ painter |
|
1265 ! |
|
1266 |
|
1267 propertyAt:anIndex |
|
1268 "returns property at an index |
|
1269 " |
|
1270 ^ propertyList at:anIndex |
|
1271 ! ! |
|
1272 |
|
1273 !UIPainterView::ListHolder methodsFor:'adding & removing'! |
|
1274 |
|
1275 add:aProperty |
|
1276 "add property and update list |
|
1277 " |
|
1278 |idx list name last| |
|
1279 |
|
1280 list := self list. |
|
1281 idx := self findParentProperty:aProperty. |
|
1282 name := aProperty name. |
|
1283 |
|
1284 idx == 0 ifTrue:[ |
|
1285 last := list size |
|
1286 ] ifFalse:[ |
|
1287 last := self lastInGroupStartingAt:idx. |
|
1288 name := (String new:(4+((list at:idx) leftIndent))), name. |
|
1289 ]. |
|
1290 propertyList add:aProperty afterIndex:last. |
|
1291 list add:name afterIndex:last. |
|
1292 self changed:#size |
|
1293 |
|
1294 |
|
1295 ! |
|
1296 |
|
1297 remove:aView |
|
1298 "remove all view relevant resources |
|
1299 " |
|
1300 |start| |
|
1301 |
|
1302 aView notNil ifTrue:[ |
|
1303 start := self findProperty:[:p| p view == aView ]. |
|
1304 |
|
1305 start ~~ 0 ifTrue:[ |
|
1306 self basicRemove:start. |
|
1307 self changed:#size. |
|
1308 ] |
|
1309 ] |
|
1310 ! |
|
1311 |
|
1312 removeAll |
|
1313 masterElement := nil. |
|
1314 self selection:#(). |
|
1315 |
|
1316 [propertyList notEmpty] whileTrue:[ |
|
1317 self basicRemove:1 |
|
1318 ]. |
|
1319 self changed:#size. |
|
1320 |
|
1321 ! ! |
|
1322 |
|
1323 !UIPainterView::ListHolder methodsFor:'change & update'! |
|
1324 |
|
1325 changed:aParameter |
|
1326 "notify all dependents that the receiver has changed somehow. |
|
1327 Each dependent gets a '#update:'-message with aParameter |
|
1328 as argument. In case of disabled no notifications are raised |
|
1329 " |
|
1330 disabledChanged ifFalse:[ |
|
1331 super changed:aParameter |
|
1332 ] |
|
1333 ! |
|
1334 |
|
1335 disableNotificationsWhileEvaluating:aBlock |
|
1336 "perform block without notification; after evaluation of block, |
|
1337 a #size changed notification is raised |
|
1338 " |
|
1339 |oldState| |
|
1340 |
|
1341 oldState := disabledChanged. |
|
1342 disabledChanged := true. |
|
1343 aBlock value. |
|
1344 disabledChanged := oldState. |
|
1345 self changed:#size. |
|
1346 ! |
|
1347 |
|
1348 propertyChanged:aProperty |
|
1349 "property list changed; update list names |
|
1350 " |
|
1351 |list idx oldName newName wspName view indent mid| |
|
1352 |
|
1353 view := aProperty view. |
|
1354 idx := self findProperty:[:p| p view == view ]. |
|
1355 |
|
1356 idx == 0 ifTrue:[ |
|
1357 ^ self error |
|
1358 ]. |
|
1359 |
|
1360 list := self list. |
|
1361 oldName := list at:idx. |
|
1362 wspName := oldName string withoutSeparators. |
|
1363 newName := aProperty name. |
|
1364 |
|
1365 wspName = newName ifFalse:[ |
|
1366 mid := self masterElement. |
|
1367 list at:idx put:((String new:(oldName leftIndent)), newName). |
|
1368 |
|
1369 idx == mid ifTrue:[ |
|
1370 masterElement := nil. |
|
1371 self masterElement:idx |
|
1372 ]. |
|
1373 ]. |
|
1374 self changed:#property |
|
1375 |
|
1376 ! ! |
|
1377 |
|
1378 !UIPainterView::ListHolder methodsFor:'enumerating'! |
|
1379 |
|
1380 propertiesDo:aBlock |
|
1381 "evaluate a block for each property |
|
1382 " |
|
1383 propertyList do:aBlock |
|
1384 ! ! |
|
1385 |
|
1386 !UIPainterView::ListHolder methodsFor:'initialization'! |
|
1387 |
|
1388 for:aPainter |
|
1389 "initialize for a painter |
|
1390 " |
|
1391 painter := aPainter. |
|
1392 disabledChanged := false. |
|
1393 self list:(OrderedCollection new). |
|
1394 propertyList := OrderedCollection new. |
|
1395 self selection:#(). |
|
1396 self addDependent:painter. |
|
1397 |
|
1398 ! ! |
|
1399 |
|
1400 !UIPainterView::ListHolder methodsFor:'private'! |
|
1401 |
|
1402 basicRemove:start |
|
1403 "remove all resources assigned to a group starting at start; |
|
1404 no notifications are raised |
|
1405 " |
|
1406 |end view superView| |
|
1407 |
|
1408 end := self lastInGroupStartingAt:start. |
|
1409 view := (propertyList at:start) view. |
|
1410 |
|
1411 view notNil ifTrue:[ |
|
1412 superView := view superView. |
|
1413 view destroy. |
|
1414 superView sizeChanged:nil. |
|
1415 ]. |
|
1416 |
|
1417 propertyList removeFromIndex:start toIndex:end. |
|
1418 self list removeFromIndex:start toIndex:end. |
|
1419 ! |
|
1420 |
|
1421 masterElement |
|
1422 "returns index of master |
|
1423 " |
|
1424 ^ self indexOfName:masterElement. |
|
1425 ! |
|
1426 |
|
1427 masterElement:newIndex |
|
1428 "change master of selection |
|
1429 " |
|
1430 |name list oldIdx| |
|
1431 |
|
1432 (oldIdx := self masterElement) ~~ newIndex ifTrue:[ |
|
1433 list := self list. |
|
1434 |
|
1435 oldIdx ~~ 0 ifTrue:[ |
|
1436 list at:oldIdx put:masterElement |
|
1437 ]. |
|
1438 newIndex ~~ 0 ifTrue:[ |
|
1439 masterElement := list at:newIndex. |
|
1440 name := Text string:masterElement. |
|
1441 name emphasizeFrom:(1+(name leftIndent)) with:#(#bold #underline). |
|
1442 list at:newIndex put:name. |
|
1443 ] ifFalse:[ |
|
1444 masterElement := nil |
|
1445 ]. |
|
1446 self changed:#list. |
|
1447 ] |
|
1448 ! ! |
|
1449 |
|
1450 !UIPainterView::ListHolder methodsFor:'recomputing'! |
|
1451 |
|
1452 recompute |
|
1453 |list prop size osel| |
|
1454 |
|
1455 osel := self selection copy. |
|
1456 size := self list size. |
|
1457 list := OrderedCollection new:size. |
|
1458 prop := OrderedCollection new:size. |
|
1459 |
|
1460 painter allSubViewsDo:[:v| |
|
1461 size := self indexOfView:v. |
|
1462 |
|
1463 size ~~ 0 ifTrue:[ |
|
1464 list add:(self list at:size). |
|
1465 prop add:(propertyList at:size) |
|
1466 ] |
|
1467 ]. |
|
1468 propertyList := prop. |
|
1469 self list:list. |
|
1470 self selection:osel. |
|
1471 ! ! |
|
1472 |
|
1473 !UIPainterView::ListHolder methodsFor:'searching'! |
|
1474 |
|
1475 detectProperty:aBlock |
|
1476 "find the property, for which evaluation of the argument, aBlock |
|
1477 returns true; return the property or nil if none detected |
|
1478 " |
|
1479 |idx| |
|
1480 |
|
1481 idx := self findProperty:aBlock. |
|
1482 idx ~~ 0 ifTrue:[ ^ propertyList at:idx ]. |
|
1483 ^ nil |
|
1484 ! |
|
1485 |
|
1486 findParentProperty:aChildProp |
|
1487 "returns index of parent or 0 |
|
1488 " |
|
1489 |view index| |
|
1490 |
|
1491 view := aChildProp view. |
|
1492 |
|
1493 view notNil ifTrue:[ |
|
1494 [ (view := view superView) notNil ] whileTrue:[ |
|
1495 index := self findProperty:[:aProp| aProp view == view ]. |
|
1496 index ~~ 0 ifTrue:[ |
|
1497 ^ index |
|
1498 ] |
|
1499 ] |
|
1500 ]. |
|
1501 ^ 0 |
|
1502 |
|
1503 |
|
1504 ! |
|
1505 |
|
1506 findProperty:aBlock |
|
1507 "find the first property, for which evaluation of the argument, aBlock |
|
1508 returns true; return its index or 0 if none detected |
|
1509 " |
|
1510 ^ propertyList findFirst:aBlock |
|
1511 ! |
|
1512 |
|
1513 indexOfName:aString |
|
1514 "returns index assigned to a string or 0 |
|
1515 " |
|
1516 |name list size| |
|
1517 |
|
1518 aString notNil ifTrue:[ |
|
1519 name := aString string withoutSeparators. |
|
1520 size := name size. |
|
1521 list := self list. |
|
1522 |
|
1523 list keysAndValuesDo:[:anIndex :aName| |
|
1524 |el| |
|
1525 |
|
1526 el := aName string. |
|
1527 (el endsWith:name) ifTrue:[ |
|
1528 (el size - el leftIndent) == name size ifTrue:[ |
|
1529 ^ anIndex |
|
1530 ] |
|
1531 ] |
|
1532 ] |
|
1533 ]. |
|
1534 ^ 0 |
|
1535 |
|
1536 ! |
|
1537 |
|
1538 indexOfView:aView |
|
1539 "returns index assigned to a view or 0 |
|
1540 " |
|
1541 aView notNil ifTrue:[ |
|
1542 ^ propertyList findFirst:[:p| p view == aView ] |
|
1543 ]. |
|
1544 ^ 0 |
|
1545 |
|
1546 ! |
|
1547 |
|
1548 lastInGroupStartingAt:start |
|
1549 "returns last index of a group |
|
1550 " |
|
1551 |end list idt| |
|
1552 |
|
1553 list := self list. |
|
1554 |
|
1555 start < list size ifTrue:[ |
|
1556 idt := (list at:start) leftIndent. |
|
1557 end := list findFirst:[:el|(el leftIndent) <= idt] startingAt:(start+1). |
|
1558 end ~~ 0 ifTrue:[ |
|
1559 ^ end - 1 |
|
1560 ] |
|
1561 ]. |
|
1562 ^ list size |
|
1563 ! ! |
|
1564 |
|
1565 !UIPainterView::ListHolder methodsFor:'selection'! |
|
1566 |
|
1567 selectGroup |
|
1568 "select all elements assigned to master |
|
1569 " |
|
1570 |start end sel size| |
|
1571 |
|
1572 painter enabled ifTrue:[ |
|
1573 (start := self masterElement) ~~ 0 ifTrue:[ |
|
1574 end := self lastInGroupStartingAt:start. |
|
1575 size := end - start + 1. |
|
1576 sel := Array new:size. |
|
1577 |
|
1578 1 to:size do:[:i| |
|
1579 sel at:i put:start. |
|
1580 start := start + 1 |
|
1581 ]. |
|
1582 self selectionIndex:sel. |
|
1583 ] ifFalse:[ |
|
1584 (self selectionIndex) size == 0 ifFalse:[ |
|
1585 self selectionIndex:#() |
|
1586 ]. |
|
1587 ] |
|
1588 ] |
|
1589 ! |
|
1590 |
|
1591 selectedProperty |
|
1592 "returns current selected instance; in case of multiple selection |
|
1593 or no selection nil is returned |
|
1594 " |
|
1595 |selection| |
|
1596 selection := self selectionIndex. |
|
1597 |
|
1598 selection size == 1 ifTrue:[ |
|
1599 propertyList size ~~ 0 ifTrue:[ |
|
1600 ^ propertyList at:(selection first) |
|
1601 ] |
|
1602 ]. |
|
1603 ^ nil |
|
1604 ! |
|
1605 |
|
1606 selectionIndex:aList |
|
1607 |masterIndex aSel| |
|
1608 |
|
1609 painter enabled ifTrue:[aSel := aList] |
|
1610 ifFalse:[aSel := nil]. |
|
1611 |
|
1612 aSel size ~~ 0 ifTrue:[masterIndex := aSel at:1] |
|
1613 ifFalse:[masterIndex := 0]. |
|
1614 |
|
1615 self masterElement:masterIndex. |
|
1616 super selectionIndex:aSel |
|
1617 ! ! |
|
1618 |
|
1619 !UIPainterView::ViewProperty class methodsFor:'instance creation'! |
|
1620 |
|
1621 new |
|
1622 Identifier notNil ifTrue:[Identifier := Identifier + 1] |
|
1623 ifFalse:[Identifier := 1]. |
|
1624 |
|
1625 ^ self basicNew initialize |
|
1626 ! ! |
|
1627 |
|
1628 !UIPainterView::ViewProperty methodsFor:'accessing'! |
|
1629 |
|
1630 identifier |
|
1631 "return the unique identifier assigned to property |
|
1632 " |
|
1633 ^ identifier |
|
1634 ! |
|
1635 |
|
1636 identifier:anIdentifier |
|
1637 "set the unique identifier assigned to property; called after an restore of |
|
1638 a deleted instance |
|
1639 " |
|
1640 identifier := anIdentifier |
|
1641 ! |
|
1642 |
|
1643 spec |
|
1644 "return the value of the instance variable 'spec' (automatically generated)" |
|
1645 |
|
1646 ^ spec! |
|
1647 |
|
1648 spec:something |
|
1649 "set the value of the instance variable 'spec' (automatically generated)" |
|
1650 |
|
1651 spec := something.! |
|
1652 |
|
1653 view |
|
1654 "return the value of the instance variable 'view' (automatically generated)" |
|
1655 |
|
1656 ^ view! |
|
1657 |
|
1658 view:something |
|
1659 "set the value of the instance variable 'view' (automatically generated)" |
|
1660 |
|
1661 view := something.! ! |
|
1662 |
|
1663 !UIPainterView::ViewProperty methodsFor:'initialization'! |
|
1664 |
|
1665 initialize |
|
1666 super initialize. |
|
1667 identifier := Identifier |
|
1668 ! ! |
|
1669 |
|
1670 !UIPainterView::ViewProperty methodsFor:'misc'! |
|
1671 |
|
1672 extractNumberStartingAt:anIndex |
|
1673 "return the number from the name starting at anIndex or 0. |
|
1674 " |
|
1675 |val| |
|
1676 |
|
1677 val := 0. |
|
1678 |
|
1679 self name from:anIndex do:[:c| |
|
1680 c isDigit ifTrue:[val := val * 10 + c digitValue] |
|
1681 ifFalse:[^ 0] |
|
1682 ]. |
|
1683 ^ val |
|
1684 |
|
1685 ! ! |
|
1686 |
|
1687 !UIPainterView::ViewProperty methodsFor:'spec messages'! |
|
1688 |
|
1689 doesNotUnderstand:aMessage |
|
1690 spec notNil ifTrue:[ |
|
1691 (spec respondsTo:(aMessage selector)) ifTrue:[^ aMessage sendTo:spec] |
|
1692 ]. |
|
1693 ^ nil |
|
1694 ! |
|
1695 |
|
1696 layout |
|
1697 spec layout |
|
1698 ! |
|
1699 |
|
1700 layout:aLayout |
|
1701 spec layout:aLayout |
|
1702 ! |
|
1703 |
|
1704 name |
|
1705 ^ spec name |
|
1706 ! |
|
1707 |
|
1708 name:aName |
|
1709 spec name:aName |
|
1710 ! ! |
|
1711 |
|
1712 !UIPainterView class methodsFor:'documentation'! |
1244 !UIPainterView class methodsFor:'documentation'! |
1713 |
1245 |
1714 version |
1246 version |
1715 ^ '$Header$' |
1247 ^ '$Header$' |
1716 ! ! |
1248 ! ! |