Search in sources :

Example 51 with ObservableList

use of javafx.collections.ObservableList in project Gargoyle by callakrsos.

the class DockNode method setFloating.

/**
	 * Whether the node is currently floating.
	 *
	 * @param floating Whether the node is currently floating.
	 * @param translation null The offset of the node after being set floating. Used for aligning it
	 *        with its layout bounds inside the dock pane when it becomes detached. Can be null
	 *        indicating no translation.
	 *
	 *
	 *        tansalation param value is value set (screenX,screenY)
	 */
public void setFloating(boolean floating, Point2D translation) {
    if (floating && !this.isFloating()) {
        // position the new stage relative to the old scene offset
        Point2D floatScene = this.localToScene(0, 0);
        Point2D floatScreen = this.localToScreen(0, 0);
        // setup window stage
        dockTitleBar.setVisible(this.isCustomTitleBar());
        dockTitleBar.setManaged(this.isCustomTitleBar());
        if (this.isDocked()) {
            this.undock();
        }
        stage = new Stage();
        stage.initStyle(stageStyle);
        stage.titleProperty().bind(titleProperty);
        if (dockPane != null && dockPane.getScene() != null && dockPane.getScene().getWindow() != null) {
            stage.initOwner(dockPane.getScene().getWindow());
        }
        if (null == stage.getOwner() && null != this.owner)
            stage.initOwner(this.owner);
        /* append close handler. 2017-05-29 by kyj.*/
        EventHandler<WindowEvent> closeHandler = ev -> {
            try {
                ObservableList<Node> childrenUnmodifiable = null;
                if (dockPane != null)
                    dockPane.getChildrenUnmodifiable();
                else
                    childrenUnmodifiable = FXCollections.observableArrayList(getContents());
                Consumer<Closeable> clo = n -> {
                    try {
                        n.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                };
                childrenUnmodifiable.stream().filter(n -> n instanceof Closeable).map(n -> (Closeable) n).forEach(clo);
            } catch (Exception e) {
                e.printStackTrace();
            }
        };
        //			stage.setOnCloseRequest(value);
        stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, closeHandler);
        // offset the new stage to cover exactly the area the dock was local to the scene
        // this is useful for when the user presses the + sign and we have no information
        // on where the mouse was clicked
        // the border pane allows the dock node to
        // have a drop shadow effect on the border
        // but also maintain the layout of contents
        // such as a tab that has no content
        borderPane = new BorderPane();
        borderPane.getStyleClass().add("dock-node-border");
        borderPane.setCenter(this);
        borderPane.applyCss();
        Scene scene = new Scene(borderPane);
        scene.getStylesheets().add(SkinManager.getInstance().getSkin());
        // apply the floating property so we can get its padding size
        // while it is floating to offset it by the drop shadow
        // this way it pops out above exactly where it was when docked
        this.floatingProperty.set(floating);
        this.applyCss();
        /*
			 * 2016-10-26 apply default value by kyj
			 * tanslation param value is empty , i call api that stage will be located center
			 */
        if (translation != null) {
            Point2D stagePosition = new Point2D(0, 0);
            if (this.isDecorated()) {
                Window owner = this.owner;
                if (null != owner)
                    stagePosition = floatScene.add(new Point2D(owner.getX(), owner.getY()));
                else
                    stagePosition = floatScene.add(new Point2D(0, 0));
            } else {
                if (floatScreen != null)
                    stagePosition = floatScreen;
            }
            if (translation != null) {
                stagePosition = stagePosition.add(translation);
            }
            //				Insets insetsDelta = borderPane.getInsets();
            stage.setX(/*stagePosition.getX() - insetsDelta.getLeft()*/
            translation.getX());
            stage.setY(/*stagePosition.getY() - insetsDelta.getTop()*/
            translation.getY());
        } else
            stage.centerOnScreen();
        if (stageStyle == StageStyle.TRANSPARENT) {
            scene.setFill(null);
        }
        stage.setResizable(this.isStageResizable());
        if (this.isStageResizable()) {
            stage.addEventFilter(MouseEvent.MOUSE_PRESSED, this);
            stage.addEventFilter(MouseEvent.MOUSE_MOVED, this);
            stage.addEventFilter(MouseEvent.MOUSE_DRAGGED, this);
        }
        // we want to set the client area size
        // without this it subtracts the native border sizes from the scene
        // size
        stage.sizeToScene();
        stage.setScene(scene);
        stage.show();
    } else if (!floating && this.isFloating()) {
        this.floatingProperty.set(floating);
        stage.removeEventFilter(MouseEvent.MOUSE_PRESSED, this);
        stage.removeEventFilter(MouseEvent.MOUSE_MOVED, this);
        stage.removeEventFilter(MouseEvent.MOUSE_DRAGGED, this);
        stage.close();
    }
}
Also used : EventHandler(javafx.event.EventHandler) StageStyle(javafx.stage.StageStyle) Scene(javafx.scene.Scene) PseudoClass(javafx.css.PseudoClass) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) VBox(javafx.scene.layout.VBox) Insets(javafx.geometry.Insets) Point2D(javafx.geometry.Point2D) WindowEvent(javafx.stage.WindowEvent) ObjectProperty(javafx.beans.property.ObjectProperty) Rectangle2D(javafx.geometry.Rectangle2D) Node(javafx.scene.Node) Screen(javafx.stage.Screen) Consumer(java.util.function.Consumer) Cursor(javafx.scene.Cursor) Priority(javafx.scene.layout.Priority) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Closeable(java.io.Closeable) Window(javafx.stage.Window) SkinManager(com.kyj.fx.voeditor.visual.momory.SkinManager) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) StringProperty(javafx.beans.property.StringProperty) Window(javafx.stage.Window) BorderPane(javafx.scene.layout.BorderPane) Consumer(java.util.function.Consumer) Point2D(javafx.geometry.Point2D) ObservableList(javafx.collections.ObservableList) Closeable(java.io.Closeable) WindowEvent(javafx.stage.WindowEvent) Stage(javafx.stage.Stage) Scene(javafx.scene.Scene)

Example 52 with ObservableList

use of javafx.collections.ObservableList in project Gargoyle by callakrsos.

the class FxUtil method exportExcelFile.

/**
	 * tableView의 item을 엑셀파일로 전환
	 * @작성자 : KYJ
	 * @작성일 : 2017. 3. 31. 
	 * @param saveFile
	 * @param tableView
	 */
public static void exportExcelFile(File saveFile, TableView<?> tableView) {
    List<Map<String, Object>> items = tableView.getItems().stream().map(v -> {
        if (v instanceof Map) {
            return (Map<String, Object>) v;
        }
        return (Map<String, Object>) ObjectUtil.toMap(v);
    }).collect(Collectors.toList());
    //		ObservableList<Map<String, Object>> items = this.tbResult.getItems();
    ToExcelFileFunction toExcelFileFunction = new ToExcelFileFunction();
    List<String> columns = tableView.getColumns().stream().map(col -> col.getText()).collect(Collectors.toList());
    toExcelFileFunction.generate0(saveFile, columns, items);
    DialogUtil.showMessageDialog("complete...");
}
Also used : StageStyle(javafx.stage.StageStyle) PageOrientation(javafx.print.PageOrientation) Printer(javafx.print.Printer) SnapshotParameters(javafx.scene.SnapshotParameters) Transition(javafx.animation.Transition) AnimationType(jidefx.animation.AnimationType) PageLayout(javafx.print.PageLayout) TabPane(javafx.scene.control.TabPane) FontPosture(javafx.scene.text.FontPosture) Map(java.util.Map) Point2D(javafx.geometry.Point2D) PopOver(org.controlsfx.control.PopOver) Rectangle2D(javafx.geometry.Rectangle2D) Pair(javafx.util.Pair) Set(java.util.Set) SnapshotResult(javafx.scene.SnapshotResult) KeyEvent(javafx.scene.input.KeyEvent) Screen(javafx.stage.Screen) ScmCommitComposite(com.kyj.fx.voeditor.visual.component.scm.ScmCommitComposite) Platform(javafx.application.Platform) Stream(java.util.stream.Stream) Region(javafx.scene.layout.Region) FxContextManager(com.kyj.fx.voeditor.visual.framework.contextmenu.FxContextManager) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) MouseButton(javafx.scene.input.MouseButton) TreeItem(javafx.scene.control.TreeItem) DockNode(com.kyj.fx.voeditor.visual.component.dock.pane.DockNode) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) FXMLLoader(javafx.fxml.FXMLLoader) GargoyleButtonBuilder(com.kyj.fx.voeditor.visual.framework.builder.GargoyleButtonBuilder) Color(javafx.scene.paint.Color) Properties(java.util.Properties) TitledPane(javafx.scene.control.TitledPane) Node(javafx.scene.Node) PopupFeatures(javafx.scene.web.PopupFeatures) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) FileChooser(javafx.stage.FileChooser) Tab(javafx.scene.control.Tab) ImageView(javafx.scene.image.ImageView) ObservableValue(javafx.beans.value.ObservableValue) SkinManager(com.kyj.fx.voeditor.visual.momory.SkinManager) Image(javafx.scene.image.Image) Button(javafx.scene.control.Button) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) JavaTextArea(com.kyj.fx.voeditor.visual.component.text.JavaTextArea) ToExcelFileFunction(com.kyj.fx.voeditor.visual.functions.ToExcelFileFunction) WebEvent(javafx.scene.web.WebEvent) JavaSVNManager(com.kyj.scm.manager.svn.java.JavaSVNManager) SvnChagnedCodeComposite(com.kyj.fx.voeditor.visual.component.scm.SvnChagnedCodeComposite) Parent(javafx.scene.Parent) FileSystemView(javax.swing.filechooser.FileSystemView) Task(javafx.concurrent.Task) InstanceTypes(com.kyj.fx.voeditor.visual.framework.InstanceTypes) ImageIO(javax.imageio.ImageIO) WindowEvent(javafx.stage.WindowEvent) TableView(javafx.scene.control.TableView) Method(java.lang.reflect.Method) AutoCompletionTextFieldBinding(impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding) FxSVNHistoryDataSupplier(com.kyj.fx.voeditor.visual.component.scm.FxSVNHistoryDataSupplier) TextField(javafx.scene.control.TextField) GargoyleLoadBar(com.kyj.fx.voeditor.visual.component.bar.GargoyleLoadBar) Paper(javafx.print.Paper) BufferedImage(java.awt.image.BufferedImage) Predicate(java.util.function.Predicate) FXMLController(com.kyj.fx.voeditor.visual.framework.annotation.FXMLController) Font(javafx.scene.text.Font) Icon(javax.swing.Icon) Collectors(java.util.stream.Collectors) FxPostInitialize(com.kyj.fx.voeditor.visual.framework.annotation.FxPostInitialize) MarginType(javafx.print.Printer.MarginType) List(java.util.List) Modifier(java.lang.reflect.Modifier) Scale(javafx.scene.transform.Scale) Optional(java.util.Optional) FontWeight(javafx.scene.text.FontWeight) AnimationUtils(jidefx.animation.AnimationUtils) Scene(javafx.scene.Scene) GargoyleBuilderFactory(com.kyj.fx.voeditor.visual.framework.builder.GargoyleBuilderFactory) WebEngine(javafx.scene.web.WebEngine) TextArea(javafx.scene.control.TextArea) MouseEvent(javafx.scene.input.MouseEvent) WebViewConsole(com.kyj.fx.voeditor.visual.component.console.WebViewConsole) Function(java.util.function.Function) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) Charset(java.nio.charset.Charset) State(javafx.concurrent.Worker.State) JavaTextView(com.kyj.fx.voeditor.visual.component.popup.JavaTextView) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) FxMemory(com.kyj.fx.voeditor.visual.momory.FxMemory) PrinterJob(javafx.print.PrinterJob) OutputStream(java.io.OutputStream) KeyCode(javafx.scene.input.KeyCode) WebView(javafx.scene.web.WebView) Modality(javafx.stage.Modality) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) CloseableParent(com.kyj.fx.voeditor.visual.main.layout.CloseableParent) TablePosition(javafx.scene.control.TablePosition) WritableImage(javafx.scene.image.WritableImage) FileInputStream(java.io.FileInputStream) Consumer(java.util.function.Consumer) GargoyleSynchLoadBar(com.kyj.fx.voeditor.visual.component.bar.GargoyleSynchLoadBar) Stage(javafx.stage.Stage) Closeable(java.io.Closeable) SwingFXUtils(javafx.embed.swing.SwingFXUtils) Window(javafx.stage.Window) ChangeListener(javafx.beans.value.ChangeListener) InputStream(java.io.InputStream) SharedMemory(com.kyj.fx.voeditor.visual.momory.SharedMemory) ToExcelFileFunction(com.kyj.fx.voeditor.visual.functions.ToExcelFileFunction) Map(java.util.Map)

Example 53 with ObservableList

use of javafx.collections.ObservableList in project Gargoyle by callakrsos.

the class FxTableViewUtil method installCopyHandler.

@SuppressWarnings("rawtypes")
public static void installCopyHandler(TableView<?> table) {
    table.addEventHandler(KeyEvent.KEY_PRESSED, e -> {
        if (e.isConsumed())
            return;
        int type = -1;
        if (e.isControlDown() && e.getCode() == KeyCode.C) {
            if (e.isShiftDown()) {
                type = 2;
            } else {
                type = 1;
            }
        }
        if (type == -1)
            return;
        TableViewSelectionModel<?> selectionModel = table.getSelectionModel();
        SelectionMode selectionMode = selectionModel.getSelectionMode();
        boolean cellSelectionEnabled = selectionModel.isCellSelectionEnabled();
        if (!cellSelectionEnabled) {
            Object selectedItem = table.getSelectionModel().getSelectedItem();
            ObservableList<?> columns = table.getColumns();
            Optional<String> reduce = columns.stream().filter(ob -> ob instanceof TableColumn).map(obj -> (TableColumn) obj).map(tc -> tc.getCellData(selectedItem)).filter(v -> v != null).map(v -> v.toString()).reduce((o1, o2) -> o1.toString().concat("\t").concat(o2.toString()));
            reduce.ifPresent(str -> {
                FxClipboardUtil.putString(str);
                e.consume();
            });
        } else if (cellSelectionEnabled) {
            ObservableList<TablePosition> selectedCells = selectionModel.getSelectedCells();
            TablePosition tablePosition = selectedCells.get(0);
            TableColumn tableColumn = tablePosition.getTableColumn();
            int row = tablePosition.getRow();
            int col = table.getColumns().indexOf(tableColumn);
            switch(type) {
                case 1:
                    StringBuilder sb = new StringBuilder();
                    for (TablePosition cell : selectedCells) {
                        if (row != cell.getRow()) {
                            sb.append("\n");
                            row++;
                        } else if (col != table.getColumns().indexOf(cell.getTableColumn())) {
                            sb.append("\t");
                        }
                        Object cellData = cell.getTableColumn().getCellData(cell.getRow());
                        sb.append(ValueUtil.decode(cellData, cellData, "").toString());
                    }
                    FxClipboardUtil.putString(sb.toString());
                    e.consume();
                    break;
                case 2:
                    Object cellData = tableColumn.getCellData(row);
                    FxClipboardUtil.putString(ValueUtil.decode(cellData, cellData, "").toString());
                    e.consume();
                    break;
            }
        }
    });
}
Also used : KeyCode(javafx.scene.input.KeyCode) ObjectProperty(javafx.beans.property.ObjectProperty) TablePosition(javafx.scene.control.TablePosition) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) KeyEvent(javafx.scene.input.KeyEvent) StringConverter(javafx.util.StringConverter) Field(java.lang.reflect.Field) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) SelectionMode(javafx.scene.control.SelectionMode) ComboBoxTableCell(javafx.scene.control.cell.ComboBoxTableCell) Clipboard(javafx.scene.input.Clipboard) Optional(java.util.Optional) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Method(java.lang.reflect.Method) TableViewSelectionModel(javafx.scene.control.TableView.TableViewSelectionModel) TableColumn(javafx.scene.control.TableColumn) ObservableList(javafx.collections.ObservableList) TablePosition(javafx.scene.control.TablePosition) SelectionMode(javafx.scene.control.SelectionMode)

Example 54 with ObservableList

use of javafx.collections.ObservableList in project Gargoyle by callakrsos.

the class ProjectFileTreeItemCreator method buildChildren.

private ObservableList<TreeItem<FileWrapper>> buildChildren(TreeItem<FileWrapper> treeItem, FILE_TREE_TYPE type) {
    FileWrapper f = treeItem.getValue();
    boolean isParentSvnConnected = f.isSVNConnected();
    File parentWcDbFile = f.getWcDbFile();
    if (f == null) {
        return FXCollections.emptyObservableList();
    }
    if (f.isFile()) {
        return FXCollections.emptyObservableList();
    }
    File[] files = f.listFiles();
    if (files != null) {
        ObservableList<TreeItem<FileWrapper>> children = FXCollections.observableArrayList();
        switch(type) {
            case NOMAL:
                for (File childFile : files) {
                    TreeItem<FileWrapper> createNode = createDefaultNode(createFileWrapper(childFile));
                    children.add(createNode);
                }
                break;
            case JAVA_PROJECT:
                for (File childFile : files) {
                    TreeItem<FileWrapper> createNode = createJavaProjectMemberNode(createFileWrapper(childFile, fw -> {
                        fw.setWcDbFile(parentWcDbFile);
                        fw.setSVNConnected(isParentSvnConnected);
                    }));
                    children.add(createNode);
                }
                break;
            case JAVA_PROJECT_MEMBER:
                for (File childFile : files) {
                    TreeItem<FileWrapper> createNode = createJavaProjectMemberNode(createFileWrapper(childFile, fw -> {
                        fw.setWcDbFile(parentWcDbFile);
                        fw.setSVNConnected(isParentSvnConnected);
                    }));
                    children.add(createNode);
                }
                break;
        }
        return children;
    }
    return FXCollections.emptyObservableList();
}
Also used : FilenameFilter(java.io.FilenameFilter) Logger(org.slf4j.Logger) TreeItem(javafx.scene.control.TreeItem) ObjectInputStream(java.io.ObjectInputStream) LoggerFactory(org.slf4j.LoggerFactory) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) FXCollections(javafx.collections.FXCollections) IOException(java.io.IOException) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) FileInputStream(java.io.FileInputStream) RuntimeClassUtil(com.kyj.fx.voeditor.visual.util.RuntimeClassUtil) File(java.io.File) HashSet(java.util.HashSet) Consumer(java.util.function.Consumer) ObjectOutputStream(java.io.ObjectOutputStream) ObservableList(javafx.collections.ObservableList) TreeItem(javafx.scene.control.TreeItem) File(java.io.File)

Example 55 with ObservableList

use of javafx.collections.ObservableList in project on-track by michaelplazek.

the class MainMenuController method initializeTrackControllers.

/**
 * This function sets the lines to the initial line values.
 */
private void initializeTrackControllers() {
    ObservableList<String> lineList = FXCollections.observableArrayList();
    // ObservableList[] ctrlrLists = FXCollections.observableArrayList()[];
    HashMap<String, ObservableList> ctrlrLists = new HashMap<>();
    lineList.add("Select Line");
    for (TrackControllerLineManager lm : TrackControllerLineManager.getLines()) {
        lineList.add(lm.getLine());
        ObservableList<String> currLineList = FXCollections.observableArrayList();
        currLineList.addAll(lm.getObservableListOfIds());
        ctrlrLists.put(lm.getLine(), currLineList);
    }
    trackControllerLineChoiceBox.setItems(lineList);
    trackControllerLineChoiceBox.setValue("Select Line");
    // Disable invalid operations
    trackControllerIdChoiceBox.setDisable(true);
    trackControllerButton.setDisable(true);
    // Action Event for line selection
    trackControllerLineChoiceBox.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
        if (!(trackControllerLineChoiceBox.getSelectionModel().getSelectedItem().equals("Select Line"))) {
            // Line Selected, select Id, get proper list
            trackControllerIdChoiceBox.setItems(ctrlrLists.get(newValue));
            trackControllerIdChoiceBox.setValue((String) ctrlrLists.get(newValue).get(0));
            trackControllerIdChoiceBox.setDisable(false);
        } else {
            trackControllerLineChoiceBox.setValue(oldValue);
        }
    });
    // Action Event for id selection
    trackControllerIdChoiceBox.getSelectionModel().selectedItemProperty().addListener((observableValue, oldValue, newValue) -> {
        if (!(trackControllerIdChoiceBox.getSelectionModel().getSelectedItem().equals("Select ID"))) {
            // Line Selected, Id selected, enable button
            trackControllerButton.setDisable(false);
        }
    });
}
Also used : ObservableList(javafx.collections.ObservableList) HashMap(java.util.HashMap) TrackControllerLineManager(trackctrl.model.TrackControllerLineManager)

Aggregations

ObservableList (javafx.collections.ObservableList)77 List (java.util.List)46 ArrayList (java.util.ArrayList)31 Collectors (java.util.stream.Collectors)29 Map (java.util.Map)28 FXCollections (javafx.collections.FXCollections)28 HashMap (java.util.HashMap)21 Node (javafx.scene.Node)20 TableColumn (javafx.scene.control.TableColumn)20 Label (javafx.scene.control.Label)18 Optional (java.util.Optional)17 ActionEvent (javafx.event.ActionEvent)16 FXML (javafx.fxml.FXML)16 TableView (javafx.scene.control.TableView)16 MouseEvent (javafx.scene.input.MouseEvent)16 Logger (org.slf4j.Logger)16 LoggerFactory (org.slf4j.LoggerFactory)16 Button (javafx.scene.control.Button)15 BorderPane (javafx.scene.layout.BorderPane)15 File (java.io.File)14