private void updateSrcControl() { Parent parent = getParent(); if (parent != null) { Node control = parent.lookup(getSrc()); srcControl.set(control); } }
@SuppressWarnings("JavadocMethod") public ProjectSettingsEditor( Parent root, ProjectSettings projectSettings, AppSettings appSettings) { super(); VBox content = new VBox( new CustomPropertySheet(BeanPropertyUtils.getProperties(projectSettings)), new Separator(), new CustomPropertySheet(BeanPropertyUtils.getProperties(appSettings))); content.setSpacing(5.0); DialogPane pane = getDialogPane(); pane.getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL); pane.setContent(content); pane.styleProperty().bind(root.styleProperty()); pane.getStylesheets().addAll(root.getStylesheets()); pane.setPrefSize(DPIUtility.SETTINGS_DIALOG_SIZE, DPIUtility.SETTINGS_DIALOG_SIZE); ImageView graphic = new ImageView(new Image(getClass().getResourceAsStream("icons/settings.png"))); graphic.setFitWidth(DPIUtility.SMALL_ICON_SIZE); graphic.setFitHeight(DPIUtility.SMALL_ICON_SIZE); setTitle("Settings"); setHeaderText("Settings"); setGraphic(graphic); setResizable(true); }
private static Bounds computeUnclippedBounds(Node node) { final Bounds layoutBounds; double minX, minY, maxX, maxY, minZ, maxZ; assert node != null; assert node.getLayoutBounds().isEmpty() == false; layoutBounds = node.getLayoutBounds(); minX = layoutBounds.getMinX(); minY = layoutBounds.getMinY(); maxX = layoutBounds.getMaxX(); maxY = layoutBounds.getMaxY(); minZ = layoutBounds.getMinZ(); maxZ = layoutBounds.getMaxZ(); if (node instanceof Parent) { final Parent parent = (Parent) node; for (Node child : parent.getChildrenUnmodifiable()) { final Bounds childBounds = child.getBoundsInParent(); minX = Math.min(minX, childBounds.getMinX()); minY = Math.min(minY, childBounds.getMinY()); maxX = Math.max(maxX, childBounds.getMaxX()); maxY = Math.max(maxY, childBounds.getMaxY()); minZ = Math.min(minZ, childBounds.getMinZ()); maxZ = Math.max(maxZ, childBounds.getMaxZ()); } } assert minX <= maxX; assert minY <= maxY; assert minZ <= maxZ; return new BoundingBox(minX, minY, minZ, maxX - minX, maxY - minY, maxZ - minZ); }
private void showFinishingPage() { getChildren().remove(finishingPage); for (Node child : getChildren()) child.setVisible(false); finishingPage.setVisible(true); getChildren().add(finishingPage); finishingPage.requestFocus(); }
private void removeEmptyGroups() { for (Parent p : emptyParents) { Parent parent = p.getParent(); Group g = (Group) parent; g.getChildren().addAll(p.getChildrenUnmodifiable()); g.getChildren().remove(p); } }
private int getIndexOfComponentInParent(Node component) { Parent parent = component.getParent(); if (parent == null) return -1; ObservableList<Node> components = parent.getChildrenUnmodifiable(); for (int i = 0; i < components.size(); i++) { if (components.get(i) == component) return i; } return -1; }
public static void addListenerDeeply(final Node node, final EventHandler<MouseEvent> listener) { node.addEventHandler(MouseEvent.MOUSE_MOVED, listener); node.addEventHandler(MouseEvent.MOUSE_PRESSED, listener); node.addEventHandler(MouseEvent.MOUSE_DRAGGED, listener); if (node instanceof Parent) { final Parent parent = (Parent) node; final ObservableList<Node> children = parent.getChildrenUnmodifiable(); for (final Node child : children) { ResizeAndMoveHelper.addListenerDeeply(child, listener); } } }
protected void refreshHandleLocation(Node hostVisual) { // position vbox top-right next to the host Bounds hostBounds = hostVisual.getBoundsInParent(); Parent parent = hostVisual.getParent(); if (parent != null) { hostBounds = parent.localToScene(hostBounds); } Point2D location = getVisual().getParent().sceneToLocal(hostBounds.getMaxX(), hostBounds.getMinY()); getVisual().setLayoutX(location.getX()); getVisual().setLayoutY(location.getY()); }
@Override public void start(Stage primaryStage) throws Exception { primaryStage.initStyle(StageStyle.UNDECORATED); FXMLLoader fxmlLoader = new FXMLLoader(getClass().getClassLoader().getResource(MAIN_VIEW_LOCATION)); Parent root = (Parent) fxmlLoader.load(); root.getStylesheets().add(STYLESHEET); Scene scene = new Scene(root, WIDTH, HEIGHT); primaryStage.setScene(scene); primaryStage.show(); // layout containers wont be initialized until primary stage is shown MainController controller = (MainController) fxmlLoader.getController(); controller.init(); }
public Jidget( String id, String name, String author, String version, Map<String, Object> beans, Parent root, List<File> styles, BeanUtilsImpl beanUtils, SaveTrigger save) { this.id = id; this.name = name != null ? name : ""; this.author = author != null ? author : ""; this.version = version != null ? version : ""; this.beans = new HashMap<>(beans); this.root = root; this.styles = styles; this.beanUtils = beanUtils; this.save = save; root.setOnMousePressed( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent arg0) { dragX = frame.getX() - arg0.getScreenX(); dragY = frame.getY() - arg0.getScreenY(); arg0.setDragDetect(true); dragged = false; } }); root.setOnMouseDragged( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent arg0) { dragged = true; frame.setLocation(dragX + arg0.getScreenX(), dragY + arg0.getScreenY()); } }); root.setOnMouseReleased( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent arg0) { if (dragged) { memento.x = frame.getX(); memento.y = frame.getY(); Jidget.this.save.scheduleSave(); } } }); initFrame(); }
private List<Effect> initEffects(Parent parent) { ArrayList<Effect> effects = new ArrayList<>(); for (int i = 1; i <= 6; i++) { ImageView image = (ImageView) parent.lookup("#image_" + i); Button button = (Button) parent.lookup("#state_" + i); Effect effect = new Effect(i, image, button); effect.setPedalName("None"); effect.setListener(toggleListener); effects.add(effect); } return effects; }
@Override public void deactivate() { super.deactivate(); model.getTxId().removeListener(txIdChangeListener); txIdTextField.cleanup(); if (root != null) root.setMouseTransparent(false); }
private void hideFinishingPage() { finishingPage.setVisible(false); getChildren().remove(finishingPage); getChildren().add(0, finishingPage); final WizardPage currentPage = getCurrentPage(); if (currentPage != null) currentPage.setVisible(true); }
private void optimize(Node node) { ObservableList<Transform> transforms = node.getTransforms(); Iterator<Transform> iterator = transforms.iterator(); boolean prevIsStatic = false; while (iterator.hasNext()) { Transform transform = iterator.next(); trTotal++; if (transform.isIdentity()) { if (timeline == null || !bound.contains(transform)) { iterator.remove(); trRemoved++; } } else { if (timeline == null || !bound.contains(transform)) { if (prevIsStatic) { trCandidate++; } prevIsStatic = true; } else { prevIsStatic = false; } } } if (node instanceof Parent) { groupsTotal++; Parent p = (Parent) node; for (Node n : p.getChildrenUnmodifiable()) { optimize(n); } if (transforms.isEmpty()) { Parent parent = p.getParent(); if (parent instanceof Group) { trEmpty++; // System.out.println("Empty group = " + node.getId()); emptyParents.add(p); } else { // System.err.println("parent is not group = " + parent); } } } if (node instanceof MeshView) { meshViews.add((MeshView) node); } }
/* This code has been taken from: * https://community.oracle.com/thread/2534556?tstart=0 * AND WAS MODIFIED!*/ public static final Node getCaretNode(Parent parent) { for (Node n : parent.getChildrenUnmodifiable()) { if (n instanceof Path) return n; else if (n instanceof Parent) { Node k = getCaretNode((Parent) n); if (k != null) return k; } } return null; }
@Override public void handle(MouseEvent event) { // TODO Auto-generated method stub if (event.getEventType().equals(MouseEvent.MOUSE_CLICKED)) { if (parent != null) { kioskMain.setMode(dispMode.MODE_BUS); parent.getScene().setRoot(kioskMain); } } }
/** * Method loadTableScene calls if login and password is correct, and do more beautiful change * scene. */ public void loadTableScene() { stage = (Stage) userField.getScene().getWindow(); Node node = root.lookup("#table"); node.setOpacity(0); FadeTransition fadeTransition = new FadeTransition(Duration.seconds(2), node); fadeTransition.setToValue(1); fadeTransition.play(); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); }
@Override public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() { if (STYLEABLES == null) { final List<CssMetaData<? extends Styleable, ?>> styleables = new ArrayList<CssMetaData<? extends Styleable, ?>>(Parent.getClassCssMetaData()); styleables.addAll(getClassCssMetaData()); styleables.addAll(super.getClassCssMetaData()); STYLEABLES = Collections.unmodifiableList(styleables); } return STYLEABLES; }
private void onPaymentReceived(ActionEvent actionEvent) { log.debug("onPaymentReceived"); confirmFiatReceivedButton.setDisable(true); statusLabel.setText("Sending message to trading peer..."); statusProgressIndicator.setVisible(true); statusProgressIndicator.setProgress(-1); root = statusProgressIndicator.getScene().getRoot(); // We deactivate mouse interaction to avoid that user leaves screen root.setMouseTransparent(true); model.fiatPaymentReceived(); }
@Nullable protected Node loadFromFXML(@Nonnull String baseName) { requireNonBlank(baseName, "Argument 'baseName' must not be blank"); if (baseName.endsWith(FXML_SUFFIX)) { baseName = stripFilenameExtension(baseName); } baseName = baseName.replace('.', '/'); String viewName = baseName + FXML_SUFFIX; String styleName = baseName + ".css"; URL viewResource = getResourceAsURL(viewName); if (viewResource == null) { return null; } FXMLLoader fxmlLoader = new FXMLLoader(viewResource); fxmlLoader.setResources(getApplication().getMessageSource().asResourceBundle()); fxmlLoader.setBuilderFactory( new JavaFXBuilderFactory(getApplication().getApplicationClassLoader().get())); fxmlLoader.setClassLoader(getApplication().getApplicationClassLoader().get()); fxmlLoader.setControllerFactory(klass -> getMvcGroup().getView()); try { fxmlLoader.load(); } catch (IOException e) { throw new GriffonException(e); } Parent node = fxmlLoader.getRoot(); URL cssResource = getResourceAsURL(styleName); if (cssResource != null) { String uriToCss = cssResource.toExternalForm(); node.getStylesheets().add(uriToCss); } return node; }
protected List<IJavaFXElement> found(List<IJavaFXElement> pElements, IJavaFXAgent driver) { List<IJavaFXElement> r = new ArrayList<IJavaFXElement>(); for (IJavaFXElement je : pElements) { Node component = je.getComponent(); if (!(component instanceof Parent)) continue; int index = getIndexOfComponentInParent(component); if (index < 0) continue; Parent parent = component.getParent(); JFXWindow topContainer = driver.switchTo().getTopContainer(); ObservableList<Node> children = parent.getChildrenUnmodifiable(); for (int i = index + 1; i < children.size(); i++) { Node c = children.get(i); IJavaFXElement je2 = JavaFXElementFactory.createElement(c, driver, driver.switchTo().getTopContainer()); if (sibling.matchesSelector(je2).size() > 0) { IJavaFXElement e = topContainer.addElement(JavaFXElementFactory.createElement(c, driver, topContainer)); if (!r.contains(e)) r.add(e); } } } return r; }
/** * Traverse the scene graph for all open stages and pick an event target for a dock event based on * the location. Once the event target is chosen run the event task with the target and the * previous target of the last dock event if one is cached. If an event target is not found fire * the explicit dock event on the stage root if one is provided. * * @param location The location of the dock event in screen coordinates. * @param eventTask The event task to be run when the event target is found. * @param explicit The explicit event to be fired on the stage root when no event target is found. */ private void pickEventTarget(Point2D location, EventTask eventTask, Event explicit) { // RFE for public scene graph traversal API filed but closed: // https://bugs.openjdk.java.net/browse/JDK-8133331 ObservableList<Stage> stages = FXCollections.unmodifiableObservableList(StageHelper.getStages()); // fire the dock over event for the active stages for (Stage targetStage : stages) { // obviously this title bar does not need to receive its own events // though users of this library may want to know when their // dock node is being dragged by subclassing it or attaching // an event listener in which case a new event can be defined or // this continue behavior can be removed if (targetStage == this.dockNode.getStage()) continue; eventTask.reset(); Node dragNode = dragNodes.get(targetStage); Parent root = targetStage.getScene().getRoot(); Stack<Parent> stack = new Stack<Parent>(); if (root.contains(root.screenToLocal(location.getX(), location.getY())) && !root.isMouseTransparent()) { stack.push(root); } // depth first traversal to find the deepest node or parent with no children // that intersects the point of interest while (!stack.isEmpty()) { Parent parent = stack.pop(); // if this parent contains the mouse click in screen coordinates in its local bounds // then traverse its children boolean notFired = true; for (Node node : parent.getChildrenUnmodifiable()) { if (node.contains(node.screenToLocal(location.getX(), location.getY())) && !node.isMouseTransparent()) { if (node instanceof Parent) { stack.push((Parent) node); } else { eventTask.run(node, dragNode); } notFired = false; break; } } // if none of the children fired the event or there were no children // fire it with the parent as the target to receive the event if (notFired) { eventTask.run(parent, dragNode); } } if (explicit != null && dragNode != null && eventTask.getExecutions() < 1) { Event.fireEvent(dragNode, explicit.copyFor(this, dragNode)); dragNodes.put(targetStage, null); } } }
@FXML protected void addPlaylistButtom() { // wybieranie playlisty FileChooser fc = new FileChooser(); fc.getExtensionFilters().add(new ExtensionFilter("Playlist", "*.fpl")); File playlistFile = fc.showOpenDialog(root.getScene().getWindow()); // kopiowanie playlisty i dodanie jej do biblioteki File destinationDirectory = new File("Playlists/" + playlistFile.getName()); if (playlistFile.exists()) { try { FileUtils.copyFile(playlistFile, destinationDirectory); playlistList.add(playlistFile); flowPane.getChildren().clear(); drawPlaylists(); } catch (IOException e) { e.printStackTrace(); } } SystemTrayIcon.trayMessage("Succes", "Added new playlist"); }
@FXML protected void addAlbumButton() { // wybieranie folderu z albumem DirectoryChooser directoryChooser = new DirectoryChooser(); directoryChooser.setTitle("Choose album folder"); File selectedDirectory = directoryChooser.showDialog(root.getScene().getWindow()); // kopiowanie albumu do folderu biblioteki File destinationDirectory = new File("C:/Users/Public/Music/" + selectedDirectory.getName()); try { FileUtils.copyDirectory(selectedDirectory, destinationDirectory); flowPane.getChildren().clear(); clearData(); loadAlbums(); drawAlbums(); } catch (IOException e) { e.printStackTrace(); } SystemTrayIcon.trayMessage("Succes", "Added new album"); }
/** * Obtain this controller's stage * * @return the controller stage */ protected Stage getStage() { return (Stage) root.getScene().getWindow(); }
public void poblarVista() throws IOException { GridPane grid_avance = (GridPane) this.lookup("#grid_avance"); grid_avance.getChildren().clear(); ArrayList<String> cursosAprobados = new ArrayList<String>(); ArrayList<String> cursosFaltantes = new ArrayList<String>(); for (Semestre sem : ha.semestres) { for (int index = 0; index < sem.ramos.size(); index++) { if (sem.notas.get(index) >= 4) { cursosAprobados.add(sem.ramos.get(index).descriptor.sigla); } } } for (Semestre sem : ha.semestres) { for (int index = 0; index < sem.ramos.size(); index++) { if (sem.notas.get(index) < 4) { String sigla = sem.ramos.get(index).descriptor.sigla; if (!cursosAprobados.contains(sigla)) { if (!cursosFaltantes.contains(sigla)) { cursosFaltantes.add(sigla); } } } } } /* for (Ramo ramoMalla : ha.malla.ramos) { String sigla = ramoMalla.descriptor.sigla; if (!cursosAprobados.contains(sigla)) { if (!cursosFaltantes.contains(sigla)) { cursosFaltantes.add(sigla); } } } */ Parent header1_gui = FXMLLoader.load(getClass().getClassLoader().getResource("FXML/ramo.fxml")); Text label1_sigla = (Text) header1_gui.lookup("#label_sigla"); header1_gui.setStyle("-fx-background-color: blue"); label1_sigla.setText("Aprobados"); grid_avance.add(header1_gui, 0, 0); Parent header2_gui = FXMLLoader.load(getClass().getClassLoader().getResource("FXML/ramo.fxml")); Text label2_sigla = (Text) header2_gui.lookup("#label_sigla"); header2_gui.setStyle("-fx-background-color: red"); label2_sigla.setText("Faltantes"); grid_avance.add(header2_gui, 1, 0); int index = 1; for (String ramoAprobado : cursosAprobados) { Parent ramo_gui = FXMLLoader.load(getClass().getClassLoader().getResource("FXML/ramo.fxml")); Text label_sigla = (Text) ramo_gui.lookup("#label_sigla"); String sigla = ramoAprobado; ramo_gui.setStyle("-fx-background-color: blue"); label_sigla.setText(sigla); grid_avance.add(ramo_gui, 0, index); index++; } index = 1; for (String ramoFaltante : cursosFaltantes) { Parent ramo_gui = FXMLLoader.load(getClass().getClassLoader().getResource("FXML/ramo.fxml")); Text label_sigla = (Text) ramo_gui.lookup("#label_sigla"); String sigla = ramoFaltante; ramo_gui.setStyle("-fx-background-color: red"); label_sigla.setText(sigla); grid_avance.add(ramo_gui, 1, index); index++; } }
static { final List<CssMetaData<? extends Styleable, ?>> styleables = new ArrayList<CssMetaData<? extends Styleable, ?>>(Parent.getClassCssMetaData()); Collections.addAll(styleables, DIALOG_TRANSITION); CHILD_STYLEABLES = Collections.unmodifiableList(styleables); }