Search in sources :

Example 6 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class FieldFilterPanel method setFilter.

public void setFilter(final Condition filter) {
    if (!this.fieldNames.isEmpty()) {
        Invoke.later(() -> {
            try (BaseCloseable settingFilter = this.settingFilter.closeable(true)) {
                setSearchFilter(filter);
                boolean simple = false;
                if (Property.isEmpty(filter)) {
                    final Field searchField = (Field) this.searchField;
                    if (searchField != null) {
                        searchField.setFieldValue(null);
                    }
                    setSearchOperator("=");
                    simple = true;
                } else if (filter instanceof Not) {
                    final Not not = (Not) filter;
                    final QueryValue condition = not.getValue();
                    if (condition instanceof IsNull) {
                        final IsNull isNull = (IsNull) condition;
                        final IsNotNull isNotNull = new IsNotNull(isNull.getValue());
                        setFilter(isNotNull);
                        return;
                    }
                } else if (filter instanceof ILike) {
                    final ILike equal = (ILike) filter;
                    final QueryValue leftCondition = equal.getLeft();
                    final QueryValue rightCondition = equal.getRight();
                    if (leftCondition instanceof Column && rightCondition instanceof Value) {
                        final Column column = (Column) leftCondition;
                        final String searchFieldName = column.getName();
                        setSearchFieldName(searchFieldName);
                        if (setSearchOperator("Like")) {
                            final Value value = (Value) rightCondition;
                            final Object searchValue = value.getValue();
                            String searchText = DataTypes.toString(searchValue);
                            if (Property.hasValue(searchText)) {
                                setSearchField(this.searchTextField);
                                searchText = searchText.replaceAll("%", "");
                                final String previousSearchText = this.searchTextField.getText();
                                if (!DataType.equal(searchText, previousSearchText)) {
                                    this.searchTextField.setFieldValue(searchText);
                                }
                                simple = true;
                            } else {
                                setSearchFilter(null);
                            }
                        }
                    }
                } else if (filter instanceof BinaryCondition) {
                    final BinaryCondition condition = (BinaryCondition) filter;
                    final QueryValue leftCondition = condition.getLeft();
                    final QueryValue rightCondition = condition.getRight();
                    if (leftCondition instanceof Column && rightCondition instanceof Value) {
                        final Column column = (Column) leftCondition;
                        final String searchFieldName = column.getName();
                        setSearchFieldName(searchFieldName);
                        final String searchOperator = condition.getOperator();
                        if (setSearchOperator(searchOperator)) {
                            final Value value = (Value) rightCondition;
                            final Object searchValue = value.getValue();
                            final String searchText = DataTypes.toString(searchValue);
                            final Field searchField = (Field) this.searchField;
                            final Object oldValue = searchField.getFieldValue();
                            if (!searchText.equalsIgnoreCase(DataTypes.toString(oldValue))) {
                                searchField.setFieldValue(searchText);
                            }
                            simple = true;
                        }
                    }
                } else if (filter instanceof RightUnaryCondition) {
                    final RightUnaryCondition condition = (RightUnaryCondition) filter;
                    final String operator = condition.getOperator();
                    if (filter instanceof IsNull || filter instanceof IsNotNull) {
                        final QueryValue leftValue = condition.getValue();
                        if (leftValue instanceof Column) {
                            final Column column = (Column) leftValue;
                            final String searchFieldName = column.getName();
                            setSearchFieldName(searchFieldName);
                            if (setSearchOperator(operator)) {
                                simple = true;
                            }
                        }
                    }
                }
                if (simple) {
                    this.whereLabel.setVisible(false);
                    if (this.nameField != null) {
                        this.nameField.setVisible(true);
                    }
                    if (this.operatorField != null) {
                        this.operatorField.setVisible(true);
                    }
                    this.searchFieldPanel.setVisible(true);
                } else {
                    String filterText = filter.toString();
                    if (filterText.length() > 40) {
                        filterText = filterText.substring(0, 40) + "...";
                    }
                    this.whereLabel.setText(filterText);
                    this.whereLabel.setToolTipText(filterText);
                    this.whereLabel.setVisible(true);
                    if (this.nameField != null) {
                        this.nameField.setVisible(false);
                    }
                    this.operatorField.setVisible(false);
                    this.searchFieldPanel.setVisible(false);
                }
            }
        });
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) ILike(com.revolsys.record.query.ILike) QueryValue(com.revolsys.record.query.QueryValue) JXSearchField(org.jdesktop.swingx.JXSearchField) DateField(com.revolsys.swing.field.DateField) AbstractRecordQueryField(com.revolsys.swing.field.AbstractRecordQueryField) Field(com.revolsys.swing.field.Field) TextField(com.revolsys.swing.field.TextField) QueryWhereConditionField(com.revolsys.swing.field.QueryWhereConditionField) RightUnaryCondition(com.revolsys.record.query.RightUnaryCondition) Not(com.revolsys.record.query.Not) IsNotNull(com.revolsys.record.query.IsNotNull) Column(com.revolsys.record.query.Column) BinaryCondition(com.revolsys.record.query.BinaryCondition) QueryValue(com.revolsys.record.query.QueryValue) GlobalBooleanValue(com.revolsys.value.GlobalBooleanValue) Value(com.revolsys.record.query.Value) IsNull(com.revolsys.record.query.IsNull)

Example 7 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class GridLayerRenderer method render.

@Override
public void render(final Viewport2D viewport, final Cancellable cancellable, final GridLayer layer) {
    try {
        final double scaleForVisible = viewport.getScaleForVisible();
        if (layer.isVisible(scaleForVisible)) {
            final BoundingBox boundingBox = viewport.getBoundingBox();
            final RectangularMapGrid grid = layer.getGrid();
            final List<RectangularMapTile> tiles = grid.getTiles(boundingBox);
            final Graphics2D graphics = viewport.getGraphics();
            if (graphics != null) {
                final Font font = graphics.getFont();
                for (final RectangularMapTile tile : cancellable.cancellable(tiles)) {
                    final BoundingBox tileBoundingBox = tile.getBoundingBox();
                    final BoundingBox intersectBoundingBox = boundingBox.intersection(tileBoundingBox);
                    if (!intersectBoundingBox.isEmpty()) {
                        final GeometryFactory geometryFactory = viewport.getGeometryFactory();
                        final Polygon polygon = tile.getPolygon(geometryFactory, 50);
                        try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(graphics, true)) {
                            viewport.drawGeometryOutline(polygon, this.geometryStyle);
                        }
                        try (BaseCloseable transformClosable = viewport.setUseModelCoordinates(false)) {
                            viewport.drawText(tile, polygon, this.textStyle);
                        }
                    }
                    graphics.setFont(font);
                }
            }
        }
    } catch (final IllegalArgumentException e) {
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) BoundingBox(com.revolsys.geometry.model.BoundingBox) Polygon(com.revolsys.geometry.model.Polygon) RectangularMapTile(com.revolsys.gis.grid.RectangularMapTile) Font(java.awt.Font) RectangularMapGrid(com.revolsys.gis.grid.RectangularMapGrid) Graphics2D(java.awt.Graphics2D)

Example 8 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class PointCloudLayerRenderer method render.

@Override
public void render(final Viewport2D viewport, final Cancellable cancellable, final PointCloudLayer layer) {
    // TODO cancellable
    final double scaleForVisible = viewport.getScaleForVisible();
    if (layer.isVisible(scaleForVisible)) {
        if (!layer.isEditable()) {
            final PointCloud<?> pointCloud = layer.getPointCloud();
            if (pointCloud != null) {
                final BoundingBox boundingBox = layer.getBoundingBox();
                final Graphics2D graphics = viewport.getGraphics();
                if (graphics != null) {
                    try (BaseCloseable transformCloseable = viewport.setUseModelCoordinates(true)) {
                        final Polygon polygon = boundingBox.toPolygon(0);
                        viewport.drawGeometryOutline(polygon, STYLE_BOUNDING_BOX);
                    }
                }
            }
        }
    }
}
Also used : BaseCloseable(com.revolsys.io.BaseCloseable) BoundingBox(com.revolsys.geometry.model.BoundingBox) Polygon(com.revolsys.geometry.model.Polygon) Graphics2D(java.awt.Graphics2D)

Example 9 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class FileRecordLayer method revertDo.

protected boolean revertDo() {
    if (this.resource == null) {
        return false;
    } else {
        if (this.resource.exists()) {
            try (final RecordReader reader = RecordReader.newRecordReader(this.resource)) {
                if (reader == null) {
                    Logs.error(this, "Cannot find reader for: " + this.resource);
                    return false;
                } else {
                    final Map<String, Object> properties = getProperties();
                    reader.setProperties(properties);
                    final RecordDefinition recordDefinition = reader.getRecordDefinition();
                    setRecordDefinition(recordDefinition);
                    if (recordDefinition == null) {
                        Logs.error(this, "No record definition found for: " + this.url);
                        return false;
                    } else {
                        GeometryFactory geometryFactory = recordDefinition.getGeometryFactory();
                        clearRecords();
                        try (BaseCloseable eventsDisabled = eventsDisabled()) {
                            for (final Record record : reader) {
                                final Geometry geometry = record.getGeometry();
                                if (geometry != null) {
                                    if (geometryFactory == null || !geometryFactory.isHasCoordinateSystem()) {
                                        final GeometryFactory geometryFactory2 = geometry.getGeometryFactory();
                                        if (geometryFactory2.isHasCoordinateSystem()) {
                                            setGeometryFactory(geometryFactory2);
                                            geometryFactory = geometryFactory2;
                                            recordDefinition.setGeometryFactory(geometryFactory2);
                                        }
                                    }
                                }
                                newRecordInternal(record);
                            }
                        }
                    }
                    refreshBoundingBox();
                    initRecordMenu();
                    setExists(true);
                    return true;
                }
            } catch (final RuntimeException e) {
                Logs.error(this, "Error reading: " + this.resource, e);
            } finally {
                refresh();
            }
        } else {
            Logs.error(this, "Cannot find: " + this.url);
        }
    }
    return false;
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) BaseCloseable(com.revolsys.io.BaseCloseable) GeometryFactory(com.revolsys.geometry.model.GeometryFactory) RecordReader(com.revolsys.record.io.RecordReader) Record(com.revolsys.record.Record) RecordDefinition(com.revolsys.record.schema.RecordDefinition)

Example 10 with BaseCloseable

use of com.revolsys.io.BaseCloseable in project com.revolsys.open by revolsys.

the class AbstractOverlay method drawXorGeometry.

protected void drawXorGeometry(final Graphics2D graphics) {
    Geometry geometry = this.xorGeometry;
    if (geometry != null) {
        geometry = geometry.newGeometry(getViewport().getGeometryFactory2dFloating());
        final Paint paint = graphics.getPaint();
        try {
            graphics.setXORMode(Color.WHITE);
            if (geometry instanceof Point) {
                final Point point = (Point) geometry;
                final Point2D screenPoint = this.viewport.toViewPoint(point);
                final double x = screenPoint.getX() - getHotspotPixels();
                final double y = screenPoint.getY() - getHotspotPixels();
                final int diameter = 2 * getHotspotPixels();
                final Shape shape = new Ellipse2D.Double(x, y, diameter, diameter);
                graphics.setPaint(new Color(0, 0, 255));
                graphics.fill(shape);
            } else {
                XOR_LINE_STYLE.setLineCap(LineCap.BUTT);
                try (BaseCloseable transformCloseable = this.viewport.setUseModelCoordinates(graphics, true)) {
                    GeometryStyleRenderer.renderGeometry(this.viewport, graphics, geometry, XOR_LINE_STYLE);
                }
            }
        } finally {
            graphics.setPaint(paint);
        }
    }
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) BaseCloseable(com.revolsys.io.BaseCloseable) Shape(java.awt.Shape) Point2D(java.awt.geom.Point2D) Color(java.awt.Color) Paint(java.awt.Paint) Point(com.revolsys.geometry.model.Point) Paint(java.awt.Paint) Point(com.revolsys.geometry.model.Point)

Aggregations

BaseCloseable (com.revolsys.io.BaseCloseable)46 Point (com.revolsys.geometry.model.Point)9 BoundingBox (com.revolsys.geometry.model.BoundingBox)8 Geometry (com.revolsys.geometry.model.Geometry)7 GeometryFactory (com.revolsys.geometry.model.GeometryFactory)6 Polygon (com.revolsys.geometry.model.Polygon)6 Record (com.revolsys.record.Record)5 LineString (com.revolsys.geometry.model.LineString)4 Identifier (com.revolsys.identifier.Identifier)4 RecordReader (com.revolsys.record.io.RecordReader)4 Graphics2D (java.awt.Graphics2D)4 ArrayList (java.util.ArrayList)4 Vertex (com.revolsys.geometry.model.vertex.Vertex)3 RecordDefinition (com.revolsys.record.schema.RecordDefinition)3 CloseableAffineTransform (com.revolsys.awt.CloseableAffineTransform)2 GeoreferencedImage (com.revolsys.raster.GeoreferencedImage)2 ArrayRecord (com.revolsys.record.ArrayRecord)2 RecordStore (com.revolsys.record.schema.RecordStore)2 Resource (com.revolsys.spring.resource.Resource)2 MapPanel (com.revolsys.swing.map.MapPanel)2