use of javafx.geometry.Rectangle2D in project org.csstudio.display.builder by kasemir.
the class ImagePlot method mouseDown.
/**
* onMousePressed
*/
private void mouseDown(final MouseEvent e) {
// Don't start mouse actions when user invokes context menu
if (!e.isPrimaryButtonDown() || (PlatformInfo.is_mac_os_x && e.isControlDown()))
return;
// -> User clicked outside of tracker. Remove it.
if (roi_tracker != null) {
removeROITracker();
// User needs to click again for that.
return;
}
// Select any tracker
final Point2D current = new Point2D(e.getX(), e.getY());
for (RegionOfInterest roi : rois) if (roi.isVisible() && roi.isInteractive()) {
final Rectangle rect = roiToScreen(roi);
if (rect.contains(current.getX(), current.getY())) {
// Check if complete ROI is visible,
// because otherwise tracker would extend beyond the
// current image viewport
final Rectangle2D image_rect = GraphicsUtils.convert(image_area);
if (image_rect.contains(rect.x, rect.y, rect.width, rect.height)) {
roi_tracker = new Tracker(image_rect);
roi_tracker.setPosition(rect.x, rect.y, rect.width, rect.height);
ChildCare.addChild(getParent(), roi_tracker);
final int index = rois.indexOf(roi);
roi_tracker.setListener((old_pos, new_pos) -> updateRoiFromScreen(index, new_pos));
return;
}
}
}
mouse_start = mouse_current = Optional.of(current);
final int clicks = e.getClickCount();
if (mouse_mode == MouseMode.NONE) {
if (crosshair) {
updateLocationInfo(e.getX(), e.getY());
requestRedraw();
}
} else if (mouse_mode == MouseMode.PAN) {
// Determine start of 'pan'
mouse_start_x_range = x_axis.getValueRange();
mouse_start_y_range = y_axis.getValueRange();
mouse_mode = MouseMode.PAN_PLOT;
} else if (mouse_mode == MouseMode.ZOOM_IN && clicks == 1) {
// Reset cursor from SIZE* to CROSS.
if (y_axis.getBounds().contains(current.getX(), current.getY())) {
mouse_mode = MouseMode.ZOOM_IN_Y;
PlotCursors.setCursor(this, mouse_mode);
} else if (image_area.contains(current.getX(), current.getY())) {
mouse_mode = MouseMode.ZOOM_IN_PLOT;
PlotCursors.setCursor(this, mouse_mode);
} else if (x_axis.getBounds().contains(current.getX(), current.getY())) {
mouse_mode = MouseMode.ZOOM_IN_X;
PlotCursors.setCursor(this, mouse_mode);
}
} else if ((mouse_mode == MouseMode.ZOOM_IN && clicks == 2) || mouse_mode == MouseMode.ZOOM_OUT)
zoomInOut(current.getX(), current.getY(), ZOOM_FACTOR);
}
use of javafx.geometry.Rectangle2D in project CapsLock by chrootRISCassembler.
the class AchievementWindow method display.
public final void display() {
if (isDisplayed) {
Logger.INST.critical("AchievementWindow is already shown.");
return;
}
isDisplayed = true;
final Rectangle2D displayRect = Screen.getPrimary().getBounds();
final double width = displayRect.getWidth() * WINDOW_WIDTH_RATIO;
final double height = displayRect.getHeight() * WINDOW_HEIGHT_RATIO;
// Stage#show()を呼び出す前にHBox#resize()やHBox#relocate()を呼び出すと表示がおかしくなる
stage.show();
rootPane.resize(width, height);
rootPane.relocate(displayRect.getWidth() - width - displayRect.getWidth() * MARGIN_LEFT_RIGHT_RATIO, displayRect.getHeight());
rootPane.setStyle("-fx-background-color: rgba(100,0,0,1);");
iconView.setFitWidth(width * ICON_RATIO);
final FadeTransition fadeIn = new FadeTransition(Duration.seconds(1), rootPane);
fadeIn.setFromValue(0);
fadeIn.setToValue(1);
final TranslateTransition moveUp = new TranslateTransition(Duration.seconds(1), rootPane);
moveUp.setByY(-height - displayRect.getHeight() * MARGIN_TOP_BOTTOM_RATIO);
final ParallelTransition in = new ParallelTransition(fadeIn, moveUp);
final PauseTransition pause = new PauseTransition(Duration.seconds(1));
final FadeTransition fadeOut = new FadeTransition(Duration.seconds(1), rootPane);
fadeOut.setFromValue(1);
fadeOut.setToValue(0);
final TranslateTransition moveRight = new TranslateTransition(Duration.seconds(1), rootPane);
moveRight.setByX(width + displayRect.getWidth() * MARGIN_LEFT_RIGHT_RATIO);
final ParallelTransition out = new ParallelTransition(fadeOut, moveRight);
final SequentialTransition sequence = new SequentialTransition(in, pause, out);
sequence.setOnFinished(dummy -> onEnd());
sequence.play();
}
use of javafx.geometry.Rectangle2D in project latexdraw by arnobl.
the class ViewGrid method updatePath.
private void updatePath(final boolean mainGrid, final boolean subGrid, final boolean labels) {
final double minY = model.getGridMinY();
final double maxY = model.getGridMaxY();
final double minX = model.getGridMinX();
final double maxX = model.getGridMaxX();
final double unit = model.getUnit();
double yStep = IShape.PPC * unit;
double xStep = IShape.PPC * unit;
xStep *= model.getGridEndX() < model.getGridStartX() ? -1d : 1d;
yStep *= model.getGridEndY() < model.getGridStartY() ? -1d : 1d;
final double posX = Math.min(model.getGridStartX(), model.getGridEndX()) * IShape.PPC * unit;
final double posY = -Math.min(model.getGridStartY(), model.getGridEndY()) * IShape.PPC * unit;
final double absStep = Math.abs(xStep);
final Rectangle2D bounds = getGridBounds(posX, posY);
final double tlx = bounds.getMinX();
final double tly = bounds.getMinY();
if (subGrid) {
subgrid.getElements().clear();
updatePathSubGrid(unit, minX, maxX, minY, maxY, posX, posY, xStep, yStep, tlx, tly, bounds.getMaxX(), bounds.getMaxY());
}
if (mainGrid) {
maingrid.getElements().clear();
updatePathMainGrid(unit, minX, maxX, minY, maxY, posX, posY, xStep, yStep, tlx, tly, bounds.getMaxX(), bounds.getMaxY(), absStep);
}
if (labels) {
cleanLabels();
updatePathLabels(minX, maxX, minY, maxY, posX, posY, xStep, yStep, tlx, tly, absStep);
}
}
use of javafx.geometry.Rectangle2D in project latexdraw by arnobl.
the class PreferencesSetter method writeXMLPreferences.
/**
* Writes the preferences of latexdraw in an XML document.
* @since 3.0
*/
public void writeXMLPreferences() {
try {
try (final FileOutputStream fos = new FileOutputStream(LPath.PATH_PREFERENCES_XML_FILE)) {
final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
final Stage frame = (Stage) pathExportField.getScene().getWindow();
final Rectangle2D rec = Screen.getPrimary().getBounds();
final Element root = document.createElement(LNamespace.XML_ROOT_PREFERENCES);
Element elt;
Element elt2;
// $NON-NLS-1$
document.setXmlVersion("1.0");
document.setXmlStandalone(true);
document.appendChild(root);
final Attr attr = document.createAttribute(LNamespace.XML_VERSION);
attr.setTextContent(VersionChecker.VERSION);
root.setAttributeNode(attr);
elt = document.createElement(LNamespace.XML_OPENGL);
elt.setTextContent(String.valueOf(openGL.isSelected()));
root.appendChild(elt);
elt = document.createElement(LNamespace.XML_PATH_EXPORT);
elt.setTextContent(pathExportField.getText());
root.appendChild(elt);
elt = document.createElement(LNamespace.XML_PATH_OPEN);
elt.setTextContent(pathOpenField.getText());
root.appendChild(elt);
elt = document.createElement(LNamespace.XML_DISPLAY_GRID);
elt.setTextContent(String.valueOf(styleList.getSelectionModel().getSelectedItem() != GridStyle.NONE));
root.appendChild(elt);
elt = document.createElement(LNamespace.XML_UNIT);
elt.setTextContent(unitChoice.getSelectionModel().getSelectedItem());
root.appendChild(elt);
elt = document.createElement(LNamespace.XML_CHECK_VERSION);
elt.setTextContent(String.valueOf(checkNewVersion.isSelected()));
root.appendChild(elt);
elt = document.createElement(LNamespace.XML_LANG);
elt.setTextContent(langList.getSelectionModel().getSelectedItem().toLanguageTag());
root.appendChild(elt);
elt = document.createElement(LNamespace.XML_MAGNETIC_GRID);
elt.setTextContent(String.valueOf(magneticCB.isSelected()));
root.appendChild(elt);
elt = document.createElement(LNamespace.XML_CLASSIC_GRID);
elt.setTextContent(Boolean.valueOf(styleList.getSelectionModel().getSelectedItem() == GridStyle.STANDARD).toString());
root.appendChild(elt);
elt = document.createElement(LNamespace.XML_GRID_GAP);
elt.setTextContent(persoGridGapField.getValue().toString());
root.appendChild(elt);
elt = document.createElement(LNamespace.XML_LATEX_INCLUDES);
elt.setTextContent(latexIncludes.getText());
root.appendChild(elt);
elt = document.createElement(LNamespace.XML_RECENT_FILES);
elt.setAttribute(LNamespace.XML_NB_RECENT_FILES, nbRecentFilesField.getValue().toString());
root.appendChild(elt);
for (final String recentFile : recentFileNames) {
elt2 = document.createElement(LNamespace.XML_RECENT_FILE);
elt2.setTextContent(recentFile);
elt.appendChild(elt2);
}
elt = document.createElement(LNamespace.XML_MAXIMISED);
elt.setTextContent(String.valueOf(frame.isMaximized()));
root.appendChild(elt);
elt = document.createElement(LNamespace.XML_SIZE);
root.appendChild(elt);
elt2 = document.createElement(LNamespace.XML_WIDTH);
elt2.setTextContent(String.valueOf((int) frame.getWidth()));
elt.appendChild(elt2);
elt2 = document.createElement(LNamespace.XML_HEIGHT);
elt2.setTextContent(String.valueOf((int) frame.getHeight()));
elt.appendChild(elt2);
elt = document.createElement(LNamespace.XML_POSITION);
root.appendChild(elt);
elt2 = document.createElement(LNamespace.XML_POSITION_X);
elt2.setTextContent(String.valueOf((int) (frame.getX() - rec.getMinX())));
elt.appendChild(elt2);
elt2 = document.createElement(LNamespace.XML_POSITION_Y);
elt2.setTextContent(String.valueOf((int) (frame.getY() - rec.getMinY())));
elt.appendChild(elt2);
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
// $NON-NLS-1$
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// $NON-NLS-1$ //$NON-NLS-2$
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
transformer.transform(new DOMSource(document), new StreamResult(fos));
}
} catch (final Exception ex) {
BadaboomCollector.INSTANCE.add(ex);
}
}
use of javafx.geometry.Rectangle2D in project jvarkit by lindenb.
the class IndexCovJfx method repaintCanvas.
private void repaintCanvas() {
final NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
final int[] samplesIndices = this.getSamplesIndices();
final GraphicsContext gc = canvas.getGraphicsContext2D();
gc.setFill(Color.WHITESMOKE);
gc.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
double x = -this.canvasSrollPane.getHvalue();
for (int row_idx = 0; row_idx < this.visibleIndexCovRows.size(); ++row_idx) {
if (x + CHUNK_WIDTH < 0) {
x += CHUNK_WIDTH;
continue;
}
final IndexCovRow row = this.visibleIndexCovRows.get(row_idx);
if (x > this.canvasSrollPane.getWidth())
break;
Color bckg = contig2color.getOrDefault(row.getContig(), Color.ALICEBLUE);
if (row_idx % 2 == 0)
bckg = ligther(bckg);
gc.setFill(bckg);
gc.fillRect(x, 0, CHUNK_WIDTH, canvas.getHeight());
float minV = 0;
float maxV = 2.1f;
for (int sampleIdx : samplesIndices) {
if (sampleIdx < 0 || sampleIdx >= row.folds.length)
continue;
float v = row.folds[sampleIdx];
maxV = Math.max(v, maxV);
}
double x_v1 = x + ((1.0 - minV) / (maxV - minV)) * CHUNK_WIDTH;
double x_v0_5 = x + ((0.5 - minV) / (maxV - minV)) * CHUNK_WIDTH;
double x_v2 = x + ((2 - minV) / (maxV - minV)) * CHUNK_WIDTH;
double y = 0;
gc.setStroke(Color.DARKGRAY);
this.hershey.paint(gc, String.valueOf(row.getContig()), x + 1, y, CHUNK_WIDTH - 2, 11);
y += 12;
gc.setStroke(Color.BLACK);
this.hershey.paint(gc, numberFormat.format(row.getStart()), x + 1, y, CHUNK_WIDTH - 2, 11);
y += 12;
gc.setStroke(Color.BLACK);
this.hershey.paint(gc, numberFormat.format(row.getEnd()), x + 1, y, CHUNK_WIDTH - 2, 11);
y += 12;
if (row_idx + 1 < this.visibleIndexCovRows.size() && row.isJustBefore(this.visibleIndexCovRows.get(row_idx + 1))) {
gc.setFill(Color.BLACK);
gc.fillOval(x + CHUNK_WIDTH - 2.5, 0, 2.5, 2.5);
}
final double topY = y;
final double sampleHeight = Math.min(50.0, (canvas.getHeight() - topY) / samplesIndices.length);
final float delLimit = this.getDeletionTreshold();
final float dupLimit = this.getDuplicationTreshold();
for (int sampleIdx : samplesIndices) {
if (sampleIdx < 0 || sampleIdx >= row.folds.length)
continue;
float v = row.folds[sampleIdx];
double sample_x = x + ((v - minV) / (maxV - minV)) * CHUNK_WIDTH;
Rectangle2D rect;
if (sample_x < x_v1) {
rect = new Rectangle2D(sample_x, y, x_v1 - sample_x, sampleHeight);
if (v <= delLimit) {
gc.setStroke(Color.DARKGRAY);
this.hershey.paint(gc, this.sampleNames.get(sampleIdx).name, x_v1, y, CHUNK_WIDTH - (x_v1 - x), Math.min(10, sampleHeight));
gc.setFill(Color.BLUE);
} else {
gc.setFill(Color.LIGHTGREY);
}
} else {
rect = new Rectangle2D(x_v1, y, sample_x - x_v1, sampleHeight);
if (v >= dupLimit) {
gc.setStroke(Color.DARKGRAY);
this.hershey.paint(gc, this.sampleNames.get(sampleIdx).name, x, y, (x_v1 - x), Math.min(10, sampleHeight));
gc.setFill(Color.RED);
} else {
gc.setFill(Color.LIGHTGREY);
}
}
gc.fillRect(rect.getMinX(), rect.getMinY(), rect.getWidth(), rect.getHeight());
gc.setStroke(Color.DARKGRAY);
gc.strokeRect(rect.getMinX(), rect.getMinY(), rect.getWidth(), rect.getHeight());
y += sampleHeight;
}
gc.setStroke(Color.ORANGE);
gc.strokeLine(x_v0_5, topY, x_v0_5, canvas.getHeight());
gc.setStroke(Color.MAGENTA);
gc.strokeLine(x_v2, topY, x_v2, canvas.getHeight());
gc.setStroke(Color.DARKGRAY);
gc.strokeRect(x, 0, CHUNK_WIDTH, canvas.getHeight());
x += CHUNK_WIDTH;
}
}
Aggregations