11package org .fxmisc .richtext ;
22
3- import static org .fxmisc .richtext .PopupAlignment .*;
43import static org .reactfx .EventStreams .*;
54import static org .reactfx .util .Tuples .*;
65
5352import javafx .scene .paint .Color ;
5453import javafx .scene .paint .Paint ;
5554import javafx .scene .text .TextFlow ;
56- import javafx .stage .PopupWindow ;
5755
5856import org .fxmisc .flowless .Cell ;
5957import org .fxmisc .flowless .VirtualFlow ;
@@ -505,8 +503,6 @@ public Optional<Tuple2<Codec<PS>, Codec<SEG>>> getStyleCodecs() {
505503 // Remembers horizontal position when traversing up / down.
506504 private Optional <ParagraphBox .CaretOffsetX > targetCaretOffset = Optional .empty ();
507505
508- private final Val <UnaryOperator <Point2D >> _popupAnchorAdjustment ;
509-
510506 private final VirtualFlow <Paragraph <PS , SEG , S >, Cell <Paragraph <PS , SEG , S >, ParagraphBox <PS , SEG , S >>> virtualFlow ;
511507
512508 // used for two-level navigation, where on the higher level are
@@ -701,26 +697,6 @@ public GenericStyledArea(
701697 .subscribe (evt -> Event .fireEvent (this , evt ));
702698
703699 new StyledTextAreaBehavior (this );
704-
705- // Code below this point is deprecated Popup API. It will be removed in the future
706-
707- // relayout the popup when any of its settings values change (besides the caret being dirty)
708- EventStream <?> popupAlignmentDirty = invalidationsOf (popupAlignmentProperty ());
709- EventStream <?> popupAnchorAdjustmentDirty = invalidationsOf (popupAnchorAdjustmentProperty ());
710- EventStream <?> popupAnchorOffsetDirty = invalidationsOf (popupAnchorOffsetProperty ());
711- EventStream <?> popupDirty = merge (popupAlignmentDirty , popupAnchorAdjustmentDirty , popupAnchorOffsetDirty );
712- subscribeTo (popupDirty , x -> layoutPopup ());
713-
714- // Adjust popup anchor by either a user-provided function,
715- // or user-provided offset, or don't adjust at all.
716- Val <UnaryOperator <Point2D >> userOffset = Val .map (
717- popupAnchorOffsetProperty (),
718- offset -> anchor -> anchor .add (offset ));
719- _popupAnchorAdjustment =
720- Val .orElse (
721- popupAnchorAdjustmentProperty (),
722- userOffset )
723- .orElseConst (UnaryOperator .identity ());
724700 }
725701
726702 /* ********************************************************************** *
@@ -1209,9 +1185,6 @@ protected void layoutChildren() {
12091185 }
12101186 }
12111187 });
1212-
1213- // position popup
1214- layoutPopup ();
12151188 }
12161189
12171190 /* ********************************************************************** *
@@ -1310,42 +1283,6 @@ private int getParagraphOffset(int parIdx) {
13101283 return position (parIdx , 0 ).toOffset ();
13111284 }
13121285
1313- private void layoutPopup () {
1314- PopupWindow popup = getPopupWindow ();
1315- PopupAlignment alignment = getPopupAlignment ();
1316- UnaryOperator <Point2D > adjustment = _popupAnchorAdjustment .getValue ();
1317- if (popup != null ) {
1318- positionPopup (popup , alignment , adjustment );
1319- }
1320- }
1321-
1322- private void positionPopup (
1323- PopupWindow popup ,
1324- PopupAlignment alignment ,
1325- UnaryOperator <Point2D > adjustment ) {
1326- Optional <Bounds > bounds = null ;
1327- switch (alignment .getAnchorObject ()) {
1328- case CARET : bounds = getCaretBoundsOnScreen (); break ;
1329- case SELECTION : bounds = impl_popup_getSelectionBoundsOnScreen (); break ;
1330- }
1331- bounds .ifPresent (b -> {
1332- double x = 0 , y = 0 ;
1333- switch (alignment .getHorizontalAlignment ()) {
1334- case LEFT : x = b .getMinX (); break ;
1335- case H_CENTER : x = (b .getMinX () + b .getMaxX ()) / 2 ; break ;
1336- case RIGHT : x = b .getMaxX (); break ;
1337- }
1338- switch (alignment .getVerticalAlignment ()) {
1339- case TOP : y = b .getMinY ();
1340- case V_CENTER : y = (b .getMinY () + b .getMaxY ()) / 2 ; break ;
1341- case BOTTOM : y = b .getMaxY (); break ;
1342- }
1343- Point2D anchor = adjustment .apply (new Point2D (x , y ));
1344- popup .setAnchorX (anchor .getX ());
1345- popup .setAnchorY (anchor .getY ());
1346- });
1347- }
1348-
13491286 private Optional <Bounds > getRangeBoundsOnScreen (int paragraphIndex , int from , int to ) {
13501287 return virtualFlow .getCellIfVisible (paragraphIndex )
13511288 .map (c -> c .getNode ().getRangeBoundsOnScreen (from , to ));
@@ -1361,31 +1298,7 @@ public final Optional<Bounds> getCaretBoundsOnScreen(int paragraphIndex) {
13611298 .map (c -> c .getNode ().getCaretBoundsOnScreen ());
13621299 }
13631300
1364- private Optional <Bounds > impl_popup_getSelectionBoundsOnScreen () {
1365- IndexRange selection = getSelection ();
1366- if (selection .getLength () == 0 ) {
1367- return getCaretBoundsOnScreen ();
1368- }
1369-
1370- return impl_getSelectionBoundsOnScreen ();
1371- }
1372-
1373- private Optional <Bounds > impl_bounds_getSelectionBoundsOnScreen () {
1374- IndexRange selection = getSelection ();
1375- if (selection .getLength () == 0 ) {
1376- return Optional .empty ();
1377- }
1378- return impl_getSelectionBoundsOnScreen ();
1379- }
1380-
1381- final Optional <Bounds > impl_bounds_getSelectionBoundsOnScreen (UnboundedSelection selection ) {
1382- if (selection .getLength () == 0 ) {
1383- return Optional .empty ();
1384- }
1385- return impl_getSelectionBoundsOnScreen (selection );
1386- }
1387-
1388- private Optional <Bounds > impl_getSelectionBoundsOnScreen (UnboundedSelection selection ) {
1301+ final Optional <Bounds > getSelectionBoundsOnScreen (UnboundedSelection selection ) {
13891302 if (selection .getLength () == 0 ) {
13901303 return Optional .empty ();
13911304 }
@@ -1400,20 +1313,6 @@ private Optional<Bounds> impl_getSelectionBoundsOnScreen(UnboundedSelection sele
14001313 });
14011314 }
14021315
1403- return reduceBoundsList (bounds );
1404- }
1405-
1406- private Optional <Bounds > impl_getSelectionBoundsOnScreen () {
1407- List <Bounds > bounds = virtualFlow .visibleCells ().stream ()
1408- .map (c -> c .getNode ().getSelectionBoundsOnScreen ())
1409- .filter (Optional ::isPresent )
1410- .map (Optional ::get )
1411- .collect (Collectors .toCollection (ArrayList ::new ));
1412-
1413- return reduceBoundsList (bounds );
1414- }
1415-
1416- private Optional <Bounds > reduceBoundsList (List <Bounds > bounds ) {
14171316 if (bounds .size () == 0 ) {
14181317 return Optional .empty ();
14191318 }
@@ -1543,153 +1442,4 @@ public StyleableProperty<javafx.util.Duration> getStyleableProperty(GenericStyle
15431442 return CSS_META_DATA_LIST ;
15441443 }
15451444
1546- /* ********************************************************************** *
1547- * *
1548- * Deprecated Popup API (Originally a part of "Properties" section *
1549- * *
1550- * Code was moved to bottom of this file to make it easier to stay *
1551- * focused on code still in use. This whole section should be deleted *
1552- * at a later time. *
1553- * *
1554- * ********************************************************************** */
1555-
1556- /**
1557- * Popup window that will be positioned by this text area relative to the
1558- * caret or selection. Use {@link #popupAlignmentProperty()} to specify
1559- * how the popup should be positioned relative to the caret or selection.
1560- * Use {@link #popupAnchorOffsetProperty()} or
1561- * {@link #popupAnchorAdjustmentProperty()} to further adjust the position.
1562- *
1563- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1564- * {@link #selectionBoundsProperty()} instead.
1565- */
1566- @ Deprecated
1567- private final ObjectProperty <PopupWindow > popupWindow = new SimpleObjectProperty <>();
1568- /**
1569- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1570- * {@link #selectionBoundsProperty()} instead.
1571- */
1572- @ Deprecated
1573- public void setPopupWindow (PopupWindow popup ) { popupWindow .set (popup ); }
1574- /**
1575- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1576- * {@link #selectionBoundsProperty()} instead.
1577- */
1578- @ Deprecated
1579- public PopupWindow getPopupWindow () { return popupWindow .get (); }
1580- /**
1581- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1582- * {@link #selectionBoundsProperty()} instead.
1583- */
1584- @ Deprecated
1585- public ObjectProperty <PopupWindow > popupWindowProperty () { return popupWindow ; }
1586-
1587- /**
1588- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1589- * {@link #selectionBoundsProperty()} instead.
1590- */
1591- @ Deprecated
1592- public void setPopupAtCaret (PopupWindow popup ) { popupWindow .set (popup ); }
1593- /**
1594- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1595- * {@link #selectionBoundsProperty()} instead.
1596- */
1597- @ Deprecated
1598- public PopupWindow getPopupAtCaret () { return popupWindow .get (); }
1599- /**
1600- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1601- * {@link #selectionBoundsProperty()} instead.
1602- */
1603- @ Deprecated
1604- public ObjectProperty <PopupWindow > popupAtCaretProperty () { return popupWindow ; }
1605-
1606- /**
1607- * Specifies further offset (in pixels) of the popup window from the
1608- * position specified by {@link #popupAlignmentProperty()}.
1609- *
1610- * <p>If {@link #popupAnchorAdjustmentProperty()} is also specified, then
1611- * it overrides the offset set by this property.
1612- *
1613- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1614- * {@link #selectionBoundsProperty()} instead.
1615- */
1616- @ Deprecated
1617- private final ObjectProperty <Point2D > popupAnchorOffset = new SimpleObjectProperty <>();
1618- /**
1619- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1620- * {@link #selectionBoundsProperty()} instead.
1621- */
1622- @ Deprecated
1623- public void setPopupAnchorOffset (Point2D offset ) { popupAnchorOffset .set (offset ); }
1624- /**
1625- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1626- * {@link #selectionBoundsProperty()} instead.
1627- */
1628- @ Deprecated
1629- public Point2D getPopupAnchorOffset () { return popupAnchorOffset .get (); }
1630- /**
1631- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1632- * {@link #selectionBoundsProperty()} instead.
1633- */
1634- @ Deprecated
1635- public ObjectProperty <Point2D > popupAnchorOffsetProperty () { return popupAnchorOffset ; }
1636-
1637- /**
1638- * Specifies how to adjust the popup window's anchor point. The given
1639- * operator is invoked with the screen position calculated according to
1640- * {@link #popupAlignmentProperty()} and should return a new screen
1641- * position. This position will be used as the popup window's anchor point.
1642- *
1643- * <p>Setting this property overrides {@link #popupAnchorOffsetProperty()}.
1644- */
1645- @ Deprecated
1646- private final ObjectProperty <UnaryOperator <Point2D >> popupAnchorAdjustment = new SimpleObjectProperty <>();
1647- /**
1648- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1649- * {@link #selectionBoundsProperty()} instead.
1650- */
1651- @ Deprecated
1652- public void setPopupAnchorAdjustment (UnaryOperator <Point2D > f ) { popupAnchorAdjustment .set (f ); }
1653- /**
1654- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1655- * {@link #selectionBoundsProperty()} instead.
1656- */
1657- @ Deprecated
1658- public UnaryOperator <Point2D > getPopupAnchorAdjustment () { return popupAnchorAdjustment .get (); }
1659- /**
1660- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1661- * {@link #selectionBoundsProperty()} instead.
1662- */
1663- @ Deprecated
1664- public ObjectProperty <UnaryOperator <Point2D >> popupAnchorAdjustmentProperty () { return popupAnchorAdjustment ; }
1665-
1666- /**
1667- * Defines where the popup window given in {@link #popupWindowProperty()}
1668- * is anchored, i.e. where its anchor point is positioned. This position
1669- * can further be adjusted by {@link #popupAnchorOffsetProperty()} or
1670- * {@link #popupAnchorAdjustmentProperty()}.
1671- *
1672- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1673- * {@link #selectionBoundsProperty()} instead.
1674- */
1675- @ Deprecated
1676- private final ObjectProperty <PopupAlignment > popupAlignment = new SimpleObjectProperty <>(CARET_TOP );
1677- /**
1678- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1679- * {@link #selectionBoundsProperty()} instead.
1680- */
1681- @ Deprecated
1682- public void setPopupAlignment (PopupAlignment pos ) { popupAlignment .set (pos ); }
1683- /**
1684- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1685- * {@link #selectionBoundsProperty()} instead.
1686- */
1687- @ Deprecated
1688- public PopupAlignment getPopupAlignment () { return popupAlignment .get (); }
1689- /**
1690- * @deprecated Use {@link #getCaretBounds()}/{@link #caretBoundsProperty()} or {@link #getSelectionBounds()}/
1691- * {@link #selectionBoundsProperty()} instead.
1692- */
1693- @ Deprecated
1694- public ObjectProperty <PopupAlignment > popupAlignmentProperty () { return popupAlignment ; }
16951445}
0 commit comments