private void refresh() { tilePane.getChildren().clear(); map = LibraryLoader.getMappedItems(); for (String s : map.keySet()) { LibraryEntry e = new LibraryEntry(map.get(s), new File(s)); tilePane.getChildren().add(e); } }
private void updateChildren(boolean useButtons) { hboxLayout.getChildren().clear(); hboxLayout.getChildren().addAll(createChildren(useButtons)); vboxLayout.getChildren().clear(); vboxLayout.getChildren().addAll(createChildren(useButtons)); flowLayout.getChildren().clear(); flowLayout.getChildren().addAll(createChildren(useButtons)); List<Node> contents1 = createChildren(useButtons); gridLayout.getChildren().clear(); gridLayout.add(contents1.get(0), 0, 0); gridLayout.add(contents1.get(1), 1, 0); gridLayout.add(contents1.get(2), 0, 1, 2, 1); List<Node> contents = createChildren(useButtons); borderLayout.getChildren().clear(); borderLayout.setLeft(contents.get(0)); borderLayout.setTop(contents.get(1)); borderLayout.setRight(contents.get(2)); borderLayout.setBottom(contents.get(3)); borderLayout.setCenter(contents.get(4)); stackLayout.getChildren().clear(); stackLayout.getChildren().addAll(createChildren(useButtons)); tileLayout.getChildren().clear(); tileLayout.getChildren().addAll(createChildren(useButtons)); }
@Test public void testSceneSizeWithContentBiasOnRoot() { Rectangle r1 = new Rectangle(20, 20); Rectangle r2 = new Rectangle(20, 20); Rectangle r3 = new Rectangle(100, 20); TilePane tilePane = new TilePane(); tilePane.getChildren().addAll(r1, r2); final VBox root = new VBox(); root.getChildren().addAll(tilePane, r3); Scene scene = new Scene(root); stage.setScene(scene); assertEquals(100, (int) scene.getWidth()); assertEquals(40, (int) scene.getHeight()); }
private Node createLoadPane() { loadPane = new TilePane(5, 5); loadPane.setPrefColumns(3); loadPane.setPadding(new Insets(5)); for (int i = 0; i < 9; i++) { StackPane waitingPane = new StackPane(); Rectangle background = new Rectangle((380) / 3, (380) / 3, Color.WHITE); indicators[i] = new ProgressIndicator(); indicators[i].setPrefSize(50, 50); indicators[i].setMaxSize(50, 50); indicators[i].setTranslateY(-25); indicators[i].setTranslateX(-10); loading[i] = new Label(); loading[i].setTranslateY(25); waitingPane.getChildren().addAll(background, indicators[i], loading[i]); loadPane.getChildren().add(waitingPane); } return loadPane; }
public void applyTo(javafx.scene.layout.TilePane x) { super.applyTo(x); int set = __set; while (set != 0) { int i = Integer.numberOfTrailingZeros(set); set &= ~(1 << i); switch (i) { case 0: x.setAlignment(this.alignment); break; case 1: x.setHgap(this.hgap); break; case 2: x.setOrientation(this.orientation); break; case 3: x.setPrefColumns(this.prefColumns); break; case 4: x.setPrefRows(this.prefRows); break; case 5: x.setPrefTileHeight(this.prefTileHeight); break; case 6: x.setPrefTileWidth(this.prefTileWidth); break; case 7: x.setTileAlignment(this.tileAlignment); break; case 8: x.setVgap(this.vgap); break; } } }
@Override public void initialize(URL url, ResourceBundle rb) { // TODO // tilePane.setPrefColumns(4); tilePane.setHgap(5); tilePane.setVgap(15); tilePane.setPrefTileHeight(85); tilePane.setPrefTileWidth(150); tilePane.setPadding(new Insets(5, 5, 15, 5)); map = LibraryLoader.getMappedItems(); for (String s : map.keySet()) { LibraryEntry e = new LibraryEntry(map.get(s), new File(s)); libEntries.add(e); } tilePane.getChildren().addAll(libEntries); }
@FXML public void handleOk() { String tituloAux = titulo.getText().replaceAll(" ", "+").toLowerCase(); String toJson = readUrl(BASE + tituloAux + "&type=series" + "&r=json"); resultados.getChildren().clear(); try { JSONObject busqueda = new JSONObject(toJson); if (busqueda.getString("Response").equals("True")) { JSONArray res = busqueda.getJSONArray("Search"); resultados.setPrefRows(res.length()); for (int i = 0; i < res.length(); i++) { JSONObject resActual = new JSONObject(res.get(i).toString()); HBox resultadoActual = new HBox(50); resultadoActual.setMaxWidth(Double.MAX_VALUE); resultadoActual.setAlignment(Pos.CENTER_LEFT); ImageView posterActual = new ImageView(); try { Image image = new Image(resActual.getString("Poster")); posterActual.setImage(image); posterActual.setFitHeight(240); posterActual.setFitWidth(180); posterActual.setPreserveRatio(false); resultadoActual.getChildren().add(posterActual); } catch (IllegalArgumentException e) { // System.out.println("Bad url"); Image image = new Image(MainApp.class.getResource("resources/no-image.png").toExternalForm()); posterActual.setImage(image); posterActual.setFitHeight(240); posterActual.setFitWidth(180); posterActual.setPreserveRatio(false); resultadoActual.getChildren().add(posterActual); } String details; String nomSerie = new String(resActual.getString("Title").getBytes(), "UTF-8"); String anoSerie = new String(resActual.getString("Year").getBytes(), "UTF-8"); if (nomSerie.length() > 15) { details = "%-12.12s...\t\t Año: %-10s"; } else { details = "%-12s\t\t Año: %-10s"; } details = String.format(details, nomSerie, anoSerie); Label elemento = new Label(details); elemento.setMaxWidth(Double.MAX_VALUE); elemento.setMaxHeight(Double.MAX_VALUE); resultadoActual.getChildren().add(elemento); posterActual.setId(resActual.getString("imdbID")); posterActual.setOnMouseClicked( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { ImageView clickedButton = (ImageView) event.getSource(); Stage stage = (Stage) clickedButton.getScene().getWindow(); Task task = new Task() { @Override protected Object call() throws Exception { mainController.mainApp.scene.setCursor(Cursor.WAIT); Serie toAdd = new Serie(clickedButton.getId()); boolean possible = true; for (Serie serie : mainController.getSeries()) { if (serie.equals(toAdd)) possible = false; } if (possible) mainController.getSeries().add(toAdd); try { mainController.populateImagenes(); mainController.showDetallesMes(mainController.getMesActual()); } catch (Exception e) { e.printStackTrace(); } finally { mainController.mainApp.scene.setCursor(Cursor.DEFAULT); return mainController.getSeries(); } } }; Thread th = new Thread(task); th.setDaemon(true); th.start(); stage.close(); } }); resultados.getChildren().add(resultadoActual); } } else { resultados.getChildren().add(new Label("La busqueda no obtuvo resultados")); } } catch (JSONException e) { e.printStackTrace(); } catch (UnsupportedEncodingException ex) { Logger.getLogger(NewSerieController.class.getName()).log(Level.SEVERE, null, ex); } }
@Override public void start(Stage primaryStage) { primaryStage.setTitle("JavaFX layouts samples"); Tab hboxTab = new Tab(); hboxTab.setText("HBox"); hboxTab.setClosable(false); hboxLayout.setBackground(createBackground(Color.LIGHTGREEN)); hboxTab.setContent(hboxLayout); Tab vboxTab = new Tab(); vboxTab.setText("VBox"); vboxTab.setClosable(false); vboxLayout.setBackground(createBackground(Color.ORANGE)); vboxTab.setContent(vboxLayout); Tab flowPaneTab = new Tab(); flowPaneTab.setText("FlowPane"); flowPaneTab.setClosable(false); flowLayout.setBackground(createBackground(Color.LIGHTSKYBLUE)); flowPaneTab.setContent(flowLayout); Tab gridPaneTab = new Tab("GridPane"); gridPaneTab.setClosable(false); gridLayout.setBackground(createBackground(Color.LIGHTCORAL)); gridLayout.setGridLinesVisible(true); gridPaneTab.setContent(gridLayout); Tab borderPaneTab = new Tab(); borderPaneTab.setText("BorderPane"); borderPaneTab.setClosable(false); borderLayout.setBackground(createBackground(Color.LIGHTYELLOW)); borderPaneTab.setContent(borderLayout); Tab stackPaneTab = new Tab(); stackPaneTab.setText("StackPane"); stackPaneTab.setClosable(false); stackLayout.setBackground(createBackground(Color.YELLOW)); stackPaneTab.setContent(stackLayout); Tab tilePaneTab = new Tab("TilePane"); tilePaneTab.setClosable(false); tileLayout.setBackground(createBackground(Color.LIGHTGOLDENRODYELLOW)); tilePaneTab.setContent(tileLayout); updateChildren(false); TabPane tabPane = new TabPane(); tabPane .getTabs() .addAll( hboxTab, vboxTab, flowPaneTab, gridPaneTab, borderPaneTab, stackPaneTab, tilePaneTab); VBox optionsPanel = new VBox(); CheckBox componentType = new CheckBox("Use Buttons instead of Rectangles"); componentType .selectedProperty() .addListener((observable, oldValue, newValue) -> updateChildren(newValue)); optionsPanel.getChildren().add(componentType); optionsPanel.setPadding(new Insets(10)); BorderPane mainLayout = new BorderPane(); mainLayout.setCenter(tabPane); mainLayout.setLeft(optionsPanel); // show the generated scene graph Scene scene = new Scene(mainLayout); primaryStage.setScene(scene); primaryStage.show(); }