Example usage for javafx.util Callback call

List of usage examples for javafx.util Callback call

Introduction

In this page you can find the example usage for javafx.util Callback call.

Prototype

public R call(P param);

Source Link

Document

The call method is called when required, and is given a single argument of type P, with a requirement that an object of type R is returned.

Usage

From source file:cz.lbenda.dataman.rc.DbConfigFactory.java

public static String storeToString(Callback<DbConfig, String> cacheDbStructureWriteFactory) {
    cz.lbenda.dataman.schema.dataman.ObjectFactory of = new cz.lbenda.dataman.schema.dataman.ObjectFactory();
    DatamanType config = of.createDatamanType();
    config.setSessions(of.createSessionsType());

    for (DbConfig sc : getConfigurations()) {
        config.getSessions().getSession()
                .add(sc.storeToSessionType(null, cacheDbStructureWriteFactory.call(sc)));
    }/*  ww  w.  j  ava2 s  . c  o  m*/

    try {
        JAXBContext jc = JAXBContext.newInstance(cz.lbenda.dataman.schema.dataman.ObjectFactory.class);
        Marshaller m = jc.createMarshaller();
        StringWriter sw = new StringWriter();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        m.marshal(of.createDataman(config), sw);
        return sw.toString();
    } catch (JAXBException e) {
        LOG.error("Problem with write configuration: " + e.toString(), e);
        throw new RuntimeException("Problem with write configuration: " + e.toString(), e);
    }
}

From source file:ijfx.core.overlay.OverlayStatService.java

public <T> PolygonOverlay createPolygonOverlay(Context context, List<T> pointList,
        Callback<T, RealPoint> pointFactory) {

    PolygonOverlay overlay = new PolygonOverlay(context);

    for (int i = 0; i != pointList.size(); i++) {

        T t = pointList.get(i);/*from  w  w  w  . jav a  2s  .  co m*/
        overlay.getRegionOfInterest().addVertex(i, pointFactory.call(t));

    }

    return overlay;

}

From source file:ijfx.core.overlay.OverlayStatService.java

public Overlay cleanOverlay(PolygonOverlay overlay) {

    PolygonRegionOfInterest roi = (PolygonRegionOfInterest) overlay.getRegionOfInterest();
    int npoints = roi.getVertexCount();

    if (npoints <= 3) {
        return overlay;
    }/*from   w  ww .  jav a2 s.c  o m*/

    Callback<RealLocalizable, Point2D> converter = real -> new Point2D.Double(real.getDoublePosition(0),
            real.getDoublePosition(1));

    List<RealLocalizable> points = new ArrayList<>();

    points.add(overlay.getRegionOfInterest().getVertex(0));

    for (int i = 1; i != npoints - 2; i++) {

        Point2D p1 = converter.call(roi.getVertex(i - 1));
        Point2D p2 = converter.call(roi.getVertex(i));
        Point2D p3 = converter.call(roi.getVertex(i + 1));

        if (!areColinear(p1, p2, p3)) {
            points.add(roi.getVertex(i));
        }

    }

    points.add(overlay.getRegionOfInterest().getVertex(npoints - 1));

    return createPolygonOverlay(getContext(), points, p -> new RealPoint(p));

}

From source file:com.panemu.tiwulfx.table.TableControl.java

protected void resizeToFit(TableColumn col, int maxRows) {
    List<?> items = tblView.getItems();
    if (items == null || items.isEmpty()) {
        return;//from  ww w  . j ava  2 s  .  c om
    }

    Callback cellFactory = col.getCellFactory();
    if (cellFactory == null) {
        return;
    }

    TableCell cell = (TableCell) cellFactory.call(col);
    if (cell == null) {
        return;
    }

    // set this property to tell the TableCell we want to know its actual
    // preferred width, not the width of the associated TableColumn
    cell.getProperties().put("deferToParentPrefWidth", Boolean.TRUE);

    // determine cell padding
    double padding = 10;
    Node n = cell.getSkin() == null ? null : cell.getSkin().getNode();
    if (n instanceof Region) {
        Region r = (Region) n;
        padding = r.getInsets().getLeft() + r.getInsets().getRight();
    }

    int rows = maxRows == -1 ? items.size() : Math.min(items.size(), maxRows);
    double maxWidth = 0;
    for (int row = 0; row < rows; row++) {
        cell.updateTableColumn(col);
        cell.updateTableView(tblView);
        cell.updateIndex(row);

        if ((cell.getText() != null && !cell.getText().isEmpty()) || cell.getGraphic() != null) {
            getChildren().add(cell);
            cell.impl_processCSS(false);
            maxWidth = Math.max(maxWidth, cell.prefWidth(-1));
            getChildren().remove(cell);
        }
    }

    col.impl_setWidth(maxWidth + padding);
}