Repository: alexbodogit/AnchorFX
Branch: master
Commit: 0773eb4419e1
Files: 30
Total size: 133.0 KB
Directory structure:
gitextract_hez4baxt/
├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
└── src/
├── main/
│ ├── java/
│ │ └── com/
│ │ └── anchorage/
│ │ ├── docks/
│ │ │ ├── containers/
│ │ │ │ ├── SingleDockContainer.java
│ │ │ │ ├── StageFloatable.java
│ │ │ │ ├── common/
│ │ │ │ │ ├── AnchorageSettings.java
│ │ │ │ │ └── DockCommons.java
│ │ │ │ ├── interfaces/
│ │ │ │ │ ├── DockContainableComponent.java
│ │ │ │ │ └── DockContainer.java
│ │ │ │ ├── subcontainers/
│ │ │ │ │ ├── DockSplitterContainer.java
│ │ │ │ │ └── DockTabberContainer.java
│ │ │ │ └── zones/
│ │ │ │ ├── DockZones.java
│ │ │ │ └── ZoneSelector.java
│ │ │ ├── node/
│ │ │ │ ├── DockNode.java
│ │ │ │ ├── interfaces/
│ │ │ │ │ ├── DockNodeCloseRequestHandler.java
│ │ │ │ │ └── DockNodeCreationListener.java
│ │ │ │ └── ui/
│ │ │ │ ├── DockCommandsBox.java
│ │ │ │ ├── DockUIPanel.java
│ │ │ │ └── Popover.java
│ │ │ └── stations/
│ │ │ ├── DockStation.java
│ │ │ └── DockSubStation.java
│ │ └── system/
│ │ └── AnchorageSystem.java
│ └── resources/
│ └── AnchorFX.css
└── test/
└── java/
└── com/
└── anchorage/
└── demo/
├── AnchorFX_CommonStations.java
├── AnchorFX_events.java
├── AnchorFX_settings.java
├── AnchorFX_substations.java
└── AnchorFX_test.java
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
# Auto detect text files and perform LF normalization
* text=false
# Custom for Visual Studio
*.cs diff=csharp
# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
================================================
FILE: .gitignore
================================================
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msm
*.msp
# Windows shortcuts
*.lnk
# =========================
# Operating System Files
# =========================
# OSX
# =========================
.DS_Store
.AppleDouble
.LSOverride
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
# maven build directory
target
.idea
*.iml
================================================
FILE: LICENSE
================================================
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
================================================
FILE: README.md
================================================

### Docking framework for JavaFX platform

AnchorFX is a gratis and open source library for JavaFX to create graphical interfaces with docking features

#### AnchorFX and its source code is licensed under the GNU Lesser General Public License version 3 and you can make adaptations of this work
#### Features
* Stations and sub stations support
* Dockable and floatable panels
* Splitter and Tabs containers support
* CSS styling
#### Usage
##### Create a DockStation
```java
DockStation station = AnchorageSystem.createStation();
```
Once created the station, we can create the panels and hook them to the station
##### Create a DockNode
```java
Pane myPanel...
DockNode dockNode = AnchorageSystem.createDock("My Title", myPanel);
dockNode.dock(station, DockNode.DOCK_POSITION.CENTER);
```
A DockNode is the window built around your panel. This window has a title and an icon and it can be defined as:
* Closeable
* Resizable
* Maximizable
* Floatable
If we want to create a node that can not be closed, we will write
```java
dockNode.closeableProperty().set(false);
```
##### Get ower DockNode from content panel
To know the reference of DockNode that contains your panel, implements the DockNodeCreationListener interface in your panel.
```java
class MyPanel extends Pane implements DockNodeCreationListener {
@Override
public void onDockNodeCreated(DockNode node) {
// now you can work with events of your DockNode
}
}
```
##### Add a DockNode to a Dockstation
To be visible, a node must be associated with a station. To do this procedure, we use the function dock (...) of DockNode
```java
dockNode.dock(station, DockNode.DOCK_POSITION.CENTER);
```
In this case, the node will be added to the station in a central position. When a station is empty, the location will always be central, otherwise, will be taken the position provided and will be changed the layout
You may also add a node by specifying the percentage of placement of the divider. This percentage is only effective if the position is provided different from the central
```java
dockNode.dock(station, DockNode.DOCK_POSITION.CENTER, 0.8);
```
#### Adding a node over another specific node
AnchorFX provides the possibility to add a node in a generic position respect to another node already present in the station.
This feature lets you design a custom layout when your application starts
```java
dockNode.dock(otherNode, DockNode.DOCK_POSITION.CENTER);
```
##### Create a DockSubStation
A Dock SubStation is a station that also has the functionality of DockNode
The nodes that are associated with a DockSubStation can only be moved within the DockSubStation associated.
```java
DockSubStation subStation = AnchorageSystem.createSubStation(station, "SubStation");
dockSubNode.dock(subStation, DockNode.DOCK_POSITION.CENTER);
subStation.dock(station, DockNode.DOCK_POSITION.LEFT,0.7);
```
##### Styling with AnchorFX.css
The file AnchorFX.css located within resource, defines a simple default style
```css
.docknode-title-bar {
-fx-background-color: rgb(100,100,100);
}
.docknode-title-text{
-fx-text-fill: rgb(255,255,255);
}
.docknode-content-panel{
-fx-background-color: rgb(100,100,100);
-fx-padding: 0
}
.docknode-floating-stack-container-panel {
-fx-background-color: rgb(100,100,100);
-fx-padding: 4
}
.docknode-split-pane {
-fx-padding: 0;
}
.docknode-split-pane *.split-pane-divider {
-fx-padding: 2;
-fx-border-color:transparent;
-fx-color: darkgray;
}
.docknode-tab-panel{
-fx-padding: 0;
}
.docknode-command-button{
-fx-background-color:transparent;
-fx-background-radius: 0,0,0;
}
.docknode-command-button:hover{
-fx-background-color:darkgray;
}
.docknode-command-button:pressed{
-fx-background-color:darkgray;
}
.docknode-command-button:focused{
-fx-background-color:transparent;
}
.docknode-command-button-close{
-fx-background-color:transparent;
-fx-background-radius: 0,0,0;
}
.docknode-command-button-close:pressed{
-fx-background-color:red;
}
.docknode-command-button-close:hover{
-fx-background-color:red;
}
.docknode-command-button-close:focused{
-fx-background-color:transparent;
}
.station {
-fx-background-color: rgb(0,0,0);
-fx-padding: 0
}
.substation-title-bar {
-fx-background-color: rgb(0,0,0);
}
.substation-title-text{
-fx-text-fill: rgb(255,255,255);
}
.dockzone-circle-container-selectors {
-fx-fill: rgba(0,0,0,0.7);
}
.dockzone-circle-selector {
-fx-fill: rgba(0,0,0,0.8);
}
.dockzone-rectangle-preview {
-fx-fill: rgba(63,138,163,0.8);
}
```
## Explore the examples on test package
The examples will use the functionality described
* AnchorFX_test.java
* AnchorFX_substations.java
* AnchorFX_settings.java
* AnchorFX_events.java
* AnchorFX_CommonStations.java
================================================
FILE: pom.xml
================================================
4.0.0
com.anchorfx
anchorfx
0.1-SNAPSHOT
jar
UTF-8
1.8
1.8
================================================
FILE: src/main/java/com/anchorage/docks/containers/SingleDockContainer.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.anchorage.docks.containers;
import com.anchorage.docks.containers.common.DockCommons;
import com.anchorage.docks.containers.interfaces.DockContainableComponent;
import com.anchorage.docks.containers.interfaces.DockContainer;
import com.anchorage.docks.containers.subcontainers.DockSplitterContainer;
import com.anchorage.docks.containers.subcontainers.DockTabberContainer;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.stations.DockStation;
import javafx.scene.Node;
import javafx.scene.layout.StackPane;
public class SingleDockContainer extends StackPane implements DockContainer {
private DockContainer container;
@Override
public void putDock(DockNode node, DockNode.DockPosition position, double percentage) {
if (getChildren().isEmpty()) {
getChildren().add(node);
node.setParentContainer(this);
} else {
manageSubContainers(node, position, percentage);
}
}
@Override
public void putDock(DockNode node, DockNode nodeTarget, DockNode.DockPosition position, double percentage) {
if (getChildren().get(0) == nodeTarget) {
manageSubContainers(node, position, percentage);
}
}
@Override
public boolean isDockVisible(DockNode node) {
return true;
}
@Override
public int indexOf(Node node) {
return (getChildren().get(0) == node) ? 0 : -1;
}
@Override
public void removeNode(Node node) {
getChildren().remove(node);
((DockContainableComponent) node).setParentContainer(null);
}
@Override
public void insertNode(Node node, int index) {
getChildren().set(index, node);
((DockContainableComponent) node).setParentContainer(this);
}
@Override
public void undock(DockNode node) {
if (getChildren().get(0) == node) {
getChildren().remove(node);
node.setParentContainer(null);
}
}
private void manageSubContainers(DockNode node, DockNode.DockPosition position, double percentage) {
Node existNode = getChildren().get(0);
if (DockCommons.isABorderPosition(position)) {
getChildren().remove(existNode);
DockSplitterContainer splitter = DockCommons.createSplitter(existNode, node, position, percentage);
getChildren().add(splitter);
splitter.setParentContainer(this);
} else if (existNode instanceof DockTabberContainer) {
DockTabberContainer tabber = (DockTabberContainer) existNode;
tabber.putDock(node, DockNode.DockPosition.CENTER, percentage);
} else if (existNode instanceof DockSplitterContainer) {
position = DockNode.DockPosition.BOTTOM;
DockSplitterContainer splitter = (DockSplitterContainer) existNode;
node.dock((DockStation)this, position);
} else {
getChildren().remove(existNode);
DockTabberContainer tabber = DockCommons.createTabber(existNode, node, position);
getChildren().add(tabber);
tabber.setParentContainer(this);
}
}
@Override
public void setParentContainer(DockContainer container) {
this.container = container;
}
@Override
public DockContainer getParentContainer() {
return container;
}
}
================================================
FILE: src/main/java/com/anchorage/docks/containers/StageFloatable.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anchorage.docks.containers;
import static com.anchorage.docks.containers.common.AnchorageSettings.FLOATING_NODE_DROPSHADOW_RADIUS;
import static com.anchorage.docks.containers.common.AnchorageSettings.FLOATING_NODE_MINIMUM_HEIGHT;
import static com.anchorage.docks.containers.common.AnchorageSettings.FLOATING_NODE_MINIMUM_WIDTH;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.stations.DockStation;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Point2D;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.SnapshotParameters;
import javafx.scene.effect.BlurType;
import javafx.scene.effect.DropShadow;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;
/**
*
* @author avinerbi
*/
public class StageFloatable extends Stage {
private Scene scene;
private DockNode node;
private StackPane transparentRootPanel;
private StackPane stackPanelContainer;
private Window owner;
private Point2D mousePositionStart;
private EventHandler eventsHandler;
private double startX;
private double startWidth;
private double startY;
private double startHeight;
private ImageView imageView;
private WritableImage ghostImage;
private StageFloatable() {
}
public StageFloatable(DockNode node, Window owner, double startX, double startY) {
this.node = node;
this.owner = owner;
buildUI(startX, startY);
setAlwaysOnTop(true);
}
private void setupMouseEvents() {
eventsHandler = event -> {
if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
mousePositionStart = new Point2D(event.getScreenX(), event.getScreenY());
startWidth = getWidth();
startX = getX();
startHeight = getHeight();
startY = getY();
}
if (event.getEventType() == MouseEvent.MOUSE_MOVED) {
boolean sizeRight = valueInRange(event.getX(), stackPanelContainer.getWidth() - stackPanelContainer.getPadding().getLeft(), stackPanelContainer.getWidth());
boolean sizeLeft = valueInRange(event.getX(), 0, stackPanelContainer.getPadding().getRight());
boolean sizeTop = valueInRange(event.getY(), 0, stackPanelContainer.getPadding().getTop());
boolean sizeBottom = valueInRange(event.getY(), stackPanelContainer.getHeight() - stackPanelContainer.getPadding().getBottom(), stackPanelContainer.getHeight());
Cursor cursor = changeCursor(sizeLeft, sizeRight, sizeTop, sizeBottom);
getScene().setCursor(cursor);
}
if (event.getEventType() == MouseEvent.MOUSE_DRAGGED && (getScene().getCursor() != null && getScene().getCursor() != Cursor.DEFAULT)) {
if (getScene().getCursor() == Cursor.E_RESIZE || getScene().getCursor() == Cursor.SE_RESIZE || getScene().getCursor() == Cursor.NE_RESIZE) {
if (event.getScreenX() - getX() + FLOATING_NODE_DROPSHADOW_RADIUS > FLOATING_NODE_MINIMUM_WIDTH) {
setWidth(event.getScreenX() - getX() + FLOATING_NODE_DROPSHADOW_RADIUS);
}
}
else if (getScene().getCursor() == Cursor.S_RESIZE || getScene().getCursor() == Cursor.SE_RESIZE || getScene().getCursor() == Cursor.SW_RESIZE) {
if (event.getScreenY() - getY() + FLOATING_NODE_DROPSHADOW_RADIUS > FLOATING_NODE_MINIMUM_HEIGHT) {
setHeight(event.getScreenY() - getY() + FLOATING_NODE_DROPSHADOW_RADIUS);
}
}
else if (getScene().getCursor() == Cursor.W_RESIZE || getScene().getCursor() == Cursor.NW_RESIZE || getScene().getCursor() == Cursor.SW_RESIZE) {
double newX = event.getScreenX() - FLOATING_NODE_DROPSHADOW_RADIUS;
double newWidth = startX - newX + startWidth;
if (newWidth > FLOATING_NODE_MINIMUM_WIDTH) {
setX(newX);
setWidth(newWidth);
}
}
else if (getScene().getCursor() == Cursor.N_RESIZE || getScene().getCursor() == Cursor.NW_RESIZE || getScene().getCursor() == Cursor.NE_RESIZE) {
double newY = event.getScreenY() - FLOATING_NODE_DROPSHADOW_RADIUS;
double newHeight = startY - newY + startHeight;
if (newHeight > FLOATING_NODE_MINIMUM_HEIGHT) {
setY(newY);
setHeight(newHeight);
}
}
}
/*
else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) {
// TODO: handle this event?
}
*/
};
stackPanelContainer.addEventFilter(MouseEvent.MOUSE_PRESSED, eventsHandler);
stackPanelContainer.addEventFilter(MouseEvent.MOUSE_MOVED, eventsHandler);
stackPanelContainer.addEventFilter(MouseEvent.MOUSE_DRAGGED, eventsHandler);
stackPanelContainer.addEventFilter(MouseEvent.MOUSE_RELEASED, eventsHandler);
}
public boolean inResizing() {
return (getScene().getCursor() != null && getScene().getCursor() != Cursor.DEFAULT);
}
private Cursor changeCursor(boolean sizeLeft, boolean sizeRight, boolean sizeTop, boolean sizeBottom) {
Cursor cursor = Cursor.DEFAULT;
if (sizeLeft) {
if (sizeTop) {
cursor = Cursor.NW_RESIZE;
}
else if (sizeBottom) {
cursor = Cursor.SW_RESIZE;
}
else {
cursor = Cursor.W_RESIZE;
}
}
else if (sizeRight) {
if (sizeTop) {
cursor = Cursor.NE_RESIZE;
}
else if (sizeBottom) {
cursor = Cursor.SE_RESIZE;
}
else {
cursor = Cursor.E_RESIZE;
}
}
else if (sizeTop) {
cursor = Cursor.N_RESIZE;
}
else if (sizeBottom) {
cursor = Cursor.S_RESIZE;
}
return cursor;
}
private boolean valueInRange(double value, double min, double max) {
return (value >= min && value <= max);
}
private void removeMouseEvents() {
removeEventFilter(MouseEvent.MOUSE_PRESSED, eventsHandler);
removeEventFilter(MouseEvent.MOUSE_MOVED, eventsHandler);
removeEventFilter(MouseEvent.MOUSE_DRAGGED, eventsHandler);
removeEventFilter(MouseEvent.MOUSE_RELEASED, eventsHandler);
}
private void buildUI(double startX, double startY) {
initOwner(owner);
setX(startX - FLOATING_NODE_DROPSHADOW_RADIUS);
setY(startY - FLOATING_NODE_DROPSHADOW_RADIUS);
createContainerPanel();
initStyle(StageStyle.TRANSPARENT);
scene = new Scene(transparentRootPanel, node.getWidth() + FLOATING_NODE_DROPSHADOW_RADIUS * 2,
node.getHeight() + FLOATING_NODE_DROPSHADOW_RADIUS * 2,
Color.TRANSPARENT);
setOnShown(e -> {
setWidth(getWidth() + stackPanelContainer.getPadding().getLeft() + stackPanelContainer.getPadding().getRight());
setHeight(getHeight() + stackPanelContainer.getPadding().getTop() + stackPanelContainer.getPadding().getBottom());
});
setScene(scene);
}
private void createContainerPanel() {
ghostImage = node.snapshot(new SnapshotParameters(), null);
imageView = new ImageView(ghostImage);
stackPanelContainer = new StackPane(imageView);
transparentRootPanel = new StackPane(stackPanelContainer);
transparentRootPanel.setPadding(new Insets(FLOATING_NODE_DROPSHADOW_RADIUS));
transparentRootPanel.setStyle("-fx-background-color:rgba(0,0,0,0);");
stackPanelContainer.getStyleClass().add("docknode-floating-stack-container-panel");
stackPanelContainer.setEffect(new DropShadow(BlurType.GAUSSIAN, new Color(0, 0, 0, 0.6), FLOATING_NODE_DROPSHADOW_RADIUS, 0.2, 0, 0));
stackPanelContainer.relocate(FLOATING_NODE_DROPSHADOW_RADIUS, FLOATING_NODE_DROPSHADOW_RADIUS);
}
public void move(double x, double y) {
setX(x);
setY(y);
}
public void makeNodeActiveOnFloatableStage() {
DockStation station = node.stationProperty().get(); // save the station
node.undock();
node.stationProperty().set(station); // resume station
stackPanelContainer.getChildren().remove(imageView);
stackPanelContainer.getChildren().add(node);
if (node.resizableProperty().get()) {
setupMouseEvents();
}
}
public void closeStage() {
transparentRootPanel.getChildren().removeAll();
setScene(null);
hide();
}
public void makeFloatable() {
}
public Insets getPaddingOffset() {
return stackPanelContainer.getPadding();
}
}
================================================
FILE: src/main/java/com/anchorage/docks/containers/common/AnchorageSettings.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.anchorage.docks.containers.common;
/**
*
* @author Alessio
*/
public class AnchorageSettings {
public static final int FLOATING_NODE_DROPSHADOW_RADIUS = 10;
public static final int FLOATING_NODE_MINIMUM_WIDTH = 150;
public static final int FLOATING_NODE_MINIMUM_HEIGHT = 150;
private static boolean dockingPositionPreview = true;
public static void setDockingPositionPreview(boolean value)
{
dockingPositionPreview = value;
}
public static boolean isDockingPositionPreview() {
return dockingPositionPreview;
}
}
================================================
FILE: src/main/java/com/anchorage/docks/containers/common/DockCommons.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.anchorage.docks.containers.common;
import com.anchorage.docks.containers.interfaces.DockContainableComponent;
import com.anchorage.docks.containers.subcontainers.DockSplitterContainer;
import com.anchorage.docks.containers.subcontainers.DockTabberContainer;
import com.anchorage.docks.node.DockNode;
import javafx.geometry.Orientation;
import javafx.scene.Node;
import javafx.scene.control.Tab;
/**
*
* @author Alessio
*/
public class DockCommons {
public static boolean isABorderPosition(DockNode.DockPosition position) {
return position != DockNode.DockPosition.CENTER;
}
public static DockSplitterContainer createSplitter(Node existNode, Node newNode, DockNode.DockPosition position, double percentage) {
DockSplitterContainer splitter = createEmptySplitter();
if (position == DockNode.DockPosition.BOTTOM || position == DockNode.DockPosition.TOP) {
splitter.setOrientation(Orientation.VERTICAL);
}
DockContainableComponent existContainableComponent = (DockContainableComponent) existNode;
DockContainableComponent newContainableComponent = (DockContainableComponent) newNode;
existContainableComponent.setParentContainer(splitter);
newContainableComponent.setParentContainer(splitter);
if (position == DockNode.DockPosition.BOTTOM || position == DockNode.DockPosition.RIGHT) {
splitter.getItems().addAll(existNode, newNode);
}
else {
splitter.getItems().addAll(newNode, existNode);
}
splitter.getStyleClass().add("docknode-split-pane");
splitter.setDividerPositions(percentage);
return splitter;
}
public static DockSplitterContainer createEmptySplitter() {
return new DockSplitterContainer();
}
public static DockTabberContainer createTabber(Node existNode, Node newNode, DockNode.DockPosition position) {
if (existNode instanceof DockNode && newNode instanceof DockNode) {
DockNode existDockNode = (DockNode) existNode;
DockNode newDockNode = (DockNode) newNode;
DockTabberContainer tabber = new DockTabberContainer();
Tab existTabPanel = new Tab(existDockNode.getContent().titleProperty().get());
Tab newTabPanel = new Tab(newDockNode.getContent().titleProperty().get());
existTabPanel.setOnCloseRequest(event -> {
if (existDockNode.getCloseRequestHandler() == null || existDockNode.getCloseRequestHandler().canClose()) {
existDockNode.undock();
event.consume();
}
});
newTabPanel.setOnCloseRequest(event -> {
if (newDockNode.getCloseRequestHandler() == null || newDockNode.getCloseRequestHandler().canClose()) {
newDockNode.undock();
event.consume();
}
});
existTabPanel.closableProperty().bind(existDockNode.closeableProperty());
newTabPanel.closableProperty().bind(newDockNode.closeableProperty());
existTabPanel.setContent(existDockNode);
newTabPanel.setContent(newDockNode);
DockContainableComponent existContainableComponent = (DockContainableComponent) existNode;
DockContainableComponent newContainableComponent = (DockContainableComponent) newNode;
existContainableComponent.setParentContainer(tabber);
newContainableComponent.setParentContainer(tabber);
tabber.getTabs().addAll(existTabPanel, newTabPanel);
tabber.getStyleClass().add("docknode-tab-pane");
newDockNode.ensureVisibility();
return tabber;
}
return null;
}
}
================================================
FILE: src/main/java/com/anchorage/docks/containers/interfaces/DockContainableComponent.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.anchorage.docks.containers.interfaces;
/**
*
* @author Alessio
*/
public interface DockContainableComponent {
public void setParentContainer(DockContainer container);
public DockContainer getParentContainer();
}
================================================
FILE: src/main/java/com/anchorage/docks/containers/interfaces/DockContainer.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.anchorage.docks.containers.interfaces;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.stations.DockStation;
import javafx.scene.Node;
/**
*
* @author Alessio
*/
public interface DockContainer extends DockContainableComponent {
public void putDock(DockNode node, DockNode.DockPosition position, double percentage);
public void putDock(DockNode node, DockNode nodeTarget, DockNode.DockPosition position, double percentage);
public void undock(DockNode node);
public int indexOf(Node node);
public void insertNode(Node node, int index);
public void removeNode(Node node);
public boolean isDockVisible(DockNode node);
}
================================================
FILE: src/main/java/com/anchorage/docks/containers/subcontainers/DockSplitterContainer.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.anchorage.docks.containers.subcontainers;
import com.anchorage.docks.containers.common.DockCommons;
import com.anchorage.docks.containers.interfaces.DockContainableComponent;
import com.anchorage.docks.containers.interfaces.DockContainer;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.stations.DockStation;
import javafx.scene.Node;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.BorderPane;
/**
*
* @author Alessio
*/
public final class DockSplitterContainer extends SplitPane implements DockContainer {
private DockContainer container;
@Override
public void putDock(DockNode node, DockNode.DockPosition position, double percentage) {
// NOTHING
}
@Override
public void putDock(DockNode node, DockNode nodeTarget, DockNode.DockPosition position, double percentage) {
// get index of current node target
int indexOfTarget = getItems().indexOf(nodeTarget);
if (DockCommons.isABorderPosition(position)) {
// create a splitter with node and nodeTarget
DockSplitterContainer splitter = DockCommons.createSplitter(nodeTarget, node, position,percentage);
getChildren().add(splitter);
splitter.setParentContainer(this);
// set the splitter on index of target
getItems().set(indexOfTarget, splitter);
} else {
DockTabberContainer tabber = DockCommons.createTabber(nodeTarget, node, position);
getChildren().add(tabber);
tabber.setParentContainer(this);
getItems().set(indexOfTarget, tabber);
}
// remove target from splitter
getItems().remove(nodeTarget);
}
@Override
public boolean isDockVisible(DockNode node)
{
return true;
}
@Override
public void undock(DockNode node) {
Node remainingNode = (getItems().get(0) == node) ? getItems().get(1) : getItems().get(0);
getItems().remove(remainingNode);
getItems().remove(node);
// WORKAROUND for bug on split panel. After getItems().remove(node) the parent of node is not set to null !!!!!
BorderPane workAroundPane = new BorderPane(node);
workAroundPane.getChildren().remove(node);
// END WORKAROUND
int indexInsideParent = getParentContainer().indexOf(this);
getParentContainer().insertNode(remainingNode, indexInsideParent);
getParentContainer().removeNode(this);
((DockContainableComponent) node).setParentContainer(null);
}
@Override
public void insertNode(Node node, int index) {
getItems().set(index, node);
((DockContainableComponent) node).setParentContainer(this);
}
@Override
public void removeNode(Node node) {
getItems().remove(node);
((DockContainableComponent) node).setParentContainer(null);
}
@Override
public int indexOf(Node node) {
return getItems().indexOf(node);
}
@Override
public void setParentContainer(DockContainer container) {
this.container = container;
}
@Override
public DockContainer getParentContainer() {
return container;
}
}
================================================
FILE: src/main/java/com/anchorage/docks/containers/subcontainers/DockTabberContainer.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.anchorage.docks.containers.subcontainers;
import com.anchorage.docks.containers.common.DockCommons;
import com.anchorage.docks.containers.interfaces.DockContainableComponent;
import com.anchorage.docks.containers.interfaces.DockContainer;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.stations.DockStation;
import javafx.scene.Node;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
/**
*
* @author Alessio
*/
public final class DockTabberContainer extends TabPane implements DockContainer {
private DockContainer container;
@Override
public void putDock(DockNode node, DockNode.DockPosition position, double percentage) {
Tab newTab = new Tab(node.getContent().titleProperty().get());
newTab.closableProperty().bind(node.closeableProperty());
getTabs().add(newTab);
newTab.setContent(node);
node.setParentContainer(this);
node.ensureVisibility();
}
private void createSplitter(DockNode node, DockNode.DockPosition position) {
DockContainer currentContainer = container;
DockSplitterContainer splitter = DockCommons.createSplitter(this, node, position, 0.5);
int indexOf = currentContainer.indexOf(this);
currentContainer.insertNode(splitter, indexOf);
currentContainer.removeNode(this);
container = splitter;
}
private Tab getTabByNode(DockNode node) {
return getTabs().stream().filter(t -> t.getContent() == node).findFirst().get();
}
@Override
public boolean isDockVisible(DockNode node) {
Tab nodeTab = getTabByNode(node);
return getSelectionModel().getSelectedItem() == nodeTab;
}
@Override
public void putDock(DockNode node, DockNode nodeTarget, DockNode.DockPosition position, double percentage) {
if (position != DockNode.DockPosition.CENTER) {
createSplitter(node, position);
} else {
DockContainableComponent containableComponent = (DockContainableComponent) node;
if (containableComponent.getParentContainer() != this) {
Tab newTab = new Tab(node.getContent().titleProperty().get());
newTab.closableProperty().bind(node.closeableProperty());
getTabs().add(newTab);
newTab.setContent(node);
node.setParentContainer(this);
node.ensureVisibility();
}
}
}
@Override
public int indexOf(Node node) {
int index = 0;
boolean found = false;
for (Tab tab : getTabs()) {
if (tab.getContent() == node) {
found = true;
break;
}
index++;
}
return (found) ? index : -1;
}
@Override
public void undock(DockNode node) {
int index = indexOf(node);
Tab tab = getTabs().get(index);
getTabs().remove(tab);
((DockContainableComponent) node).setParentContainer(null);
if (getTabs().size() == 1) {
DockNode remainingNode = (DockNode) getTabs().get(0).getContent();
getTabs().remove(0);
int indexInsideParent = getParentContainer().indexOf(this);
getParentContainer().insertNode(remainingNode, indexInsideParent);
getParentContainer().removeNode(this);
}
}
@Override
public void insertNode(Node node, int index) {
// NOTHING
}
@Override
public void removeNode(Node node) {
// NOTHING
}
@Override
public void setParentContainer(DockContainer container) {
this.container = container;
}
@Override
public DockContainer getParentContainer() {
return container;
}
public void manageDragOnSameNode(DockNode node, DockNode.DockPosition position) {
if (getTabByNode(node) != null && getTabs().size() == 2) {
DockNode otherNode = (getTabs().get(0).getContent() == node) ? (DockNode) getTabs().get(1).getContent() : (DockNode) getTabs().get(0).getContent();
node.undock();
node.dock(otherNode, position);
} else if (getTabByNode(node) != null && getTabs().size() > 2) {
node.undock();
DockContainer currentContainer = container;
DockSplitterContainer splitter = DockCommons.createSplitter(this, node, position, 0.5);
int indexOf = currentContainer.indexOf(this);
currentContainer.insertNode(splitter, indexOf);
currentContainer.removeNode(this);
container = splitter;
node.stationProperty().get().add(node);
}
}
public void ensureVisibility(DockNode node) {
Tab tabNode = getTabByNode(node);
getSelectionModel().select(tabNode);
}
}
================================================
FILE: src/main/java/com/anchorage/docks/containers/zones/DockZones.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.anchorage.docks.containers.zones;
import com.anchorage.docks.containers.common.AnchorageSettings;
import static com.anchorage.docks.containers.common.AnchorageSettings.FLOATING_NODE_DROPSHADOW_RADIUS;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.node.ui.DockUIPanel;
import com.anchorage.docks.stations.DockStation;
import com.anchorage.docks.stations.DockSubStation;
import java.util.ArrayList;
import java.util.List;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.geometry.BoundingBox;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;
/**
*
* @author avinerbi
*/
public final class DockZones extends Stage {
private static final double CIRCLE_RADIUS = 100;
public static final int OFFSET_IMAGE = 15;
///////// MAIN STAGE SCENE AND ROOT
private Scene scene;
private Pane mainRoot;
////////////////////////////////////
/////////// CIRCLE EXTERNAL STAGE
private Stage circleStage;
private Scene circleStageScene;
private Pane circleStageRoot;
private Circle circleZone;
////////////////////////////////////
private static Image dragTopImage;
private static Image dragBottomImage;
private static Image dragLeftImage;
private static Image dragRightImage;
private static Image dragCenterImage;
private List selectors;
///////////////////////////////////////////////
private DockStation ownerStation;
private Rectangle currentAreaSelected;
private DockNode currentNodeTarget;
private DockNode nodeToMove;
private DockNode.DockPosition currentPosition;
private ZoneSelector currentZoneSelector = null;
private Rectangle rectanglePreview;
private Timeline opacityAnimationPreview;
static {
dragTopImage = new Image("dragtop.png");
dragBottomImage = new Image("dragbottom.png");
dragLeftImage = new Image("dragleft.png");
dragRightImage = new Image("dragright.png");
dragCenterImage = new Image("dragcenter.png");
}
private DockZones() {
}
public DockZones(DockStation station, DockNode nodeToMove) {
this.nodeToMove = nodeToMove;
this.ownerStation = station;
initOwner(ownerStation.getStationWindow());
initStyle(StageStyle.TRANSPARENT);
buildUI();
buildCircleStage();
makeSelectors();
createRectangleForPreview();
setAlwaysOnTop(true);
circleStage.setAlwaysOnTop(true);
}
private void createRectangleForPreview() {
rectanglePreview = new Rectangle(0, 0, 50, 50);
rectanglePreview.getStyleClass().add("dockzone-rectangle-preview");
rectanglePreview.setOpacity(0);
opacityAnimationPreview = new Timeline(new KeyFrame(Duration.seconds(0.5), new KeyValue(rectanglePreview.opacityProperty(), 0.5, Interpolator.LINEAR)));
opacityAnimationPreview.setAutoReverse(true);
opacityAnimationPreview.setCycleCount(-1);
mainRoot.getChildren().add(rectanglePreview);
}
private void makeSelectors() {
selectors = new ArrayList<>();
if (ownerStation.getChildren().size() > 0) {
// selectors of station
selectors.add(new ZoneSelector(dragTopImage, DockNode.DockPosition.TOP, true, mainRoot, (mainRoot.getWidth() - dragTopImage.getWidth()) / 2, OFFSET_IMAGE));
selectors.add(new ZoneSelector(dragBottomImage, DockNode.DockPosition.BOTTOM, true, mainRoot, (mainRoot.getWidth() - dragTopImage.getWidth()) / 2, mainRoot.getHeight() - dragBottomImage.getHeight() - OFFSET_IMAGE));
selectors.add(new ZoneSelector(dragLeftImage, DockNode.DockPosition.LEFT, true, mainRoot, OFFSET_IMAGE, (mainRoot.getHeight() - dragLeftImage.getWidth()) / 2));
selectors.add(new ZoneSelector(dragRightImage, DockNode.DockPosition.RIGHT, true, mainRoot, (mainRoot.getWidth() - dragRightImage.getWidth() - OFFSET_IMAGE), (mainRoot.getHeight() - dragRightImage.getWidth()) / 2));
// selectors of node
selectors.add(new ZoneSelector(dragTopImage, DockNode.DockPosition.TOP, false, circleStageRoot, (circleStageRoot.getWidth() - dragTopImage.getWidth()) / 2, OFFSET_IMAGE));
selectors.add(new ZoneSelector(dragBottomImage, DockNode.DockPosition.BOTTOM, false, circleStageRoot, (circleStageRoot.getWidth() - dragBottomImage.getWidth()) / 2, circleStageRoot.getHeight() - dragBottomImage.getHeight() - OFFSET_IMAGE));
selectors.add(new ZoneSelector(dragLeftImage, DockNode.DockPosition.LEFT, false, circleStageRoot, OFFSET_IMAGE, (circleStageRoot.getHeight() - dragLeftImage.getHeight()) / 2));
selectors.add(new ZoneSelector(dragRightImage, DockNode.DockPosition.RIGHT, false, circleStageRoot, circleStageRoot.getWidth() - dragRightImage.getWidth() - OFFSET_IMAGE, (circleStageRoot.getHeight() - dragRightImage.getHeight()) / 2));
selectors.add(new ZoneSelector(dragCenterImage, DockNode.DockPosition.CENTER, false, circleStageRoot, (circleStageRoot.getWidth() - dragCenterImage.getWidth()) / 2, (circleStageRoot.getHeight() - dragCenterImage.getHeight()) / 2));
}
else {
selectors.add(new ZoneSelector(dragCenterImage, DockNode.DockPosition.CENTER, true, mainRoot, (mainRoot.getWidth() - dragCenterImage.getWidth()) / 2, (mainRoot.getHeight() - dragCenterImage.getHeight()) / 2));
}
}
private void buildCircleStage() {
circleStage = new Stage();
circleStage.initStyle(StageStyle.TRANSPARENT);
circleStage.initOwner(this);
circleZone = new Circle(CIRCLE_RADIUS);
circleZone.setCenterX(CIRCLE_RADIUS);
circleZone.setCenterY(CIRCLE_RADIUS);
circleZone.getStyleClass().add("dockzone-circle-container-selectors");
circleStageRoot = new Pane(circleZone);
circleStageRoot.setStyle("-fx-background-color:rgba(0,0,0,0);");
circleStageScene = new Scene(circleStageRoot, CIRCLE_RADIUS * 2, CIRCLE_RADIUS * 2, Color.TRANSPARENT);
circleStage.setScene(circleStageScene);
circleStageRoot.setOpacity(0);
}
private void buildUI() {
mainRoot = new Pane();
mainRoot.setStyle("-fx-background-color:rgba(0,0,0,0);");
scene = new Scene(mainRoot, ownerStation.getWidth(), ownerStation.getHeight(), Color.TRANSPARENT);
setScene(scene);
Point2D screenOrigin = ownerStation.localToScreen(ownerStation.getBoundsInLocal().getMinX(), ownerStation.getBoundsInLocal().getMinY());
setX(screenOrigin.getX());
setY(screenOrigin.getY());
}
public void showZones() {
show();
circleStage.show();
}
public void moveAt(DockNode node) {
currentNodeTarget = node;
Bounds screenBounds = node.getScreenBounds();
if (circleStageRoot.opacityProperty().get() == 0) {
circleStageRoot.setOpacity(1);
}
circleStage.setX(screenBounds.getMinX() + (screenBounds.getWidth() - circleStageRoot.getWidth()) / 2);
circleStage.setY(screenBounds.getMinY() + (screenBounds.getHeight() - circleStageRoot.getHeight()) / 2);
}
public void hideCircleZones() {
hidePreview();
currentNodeTarget = null;
if (currentZoneSelector != null) {
currentZoneSelector.reset();
}
currentZoneSelector = null;
currentPosition = null;
circleStageRoot.setOpacity(0);
}
private void checkVisibilityConditions() {
selectors.
stream().
forEach(z -> z.setZoneDisabled(false));
if (currentNodeTarget == nodeToMove) {
// disable border zones
selectors.
stream().
filter(z -> !z.isStationZone() && z.getPosition() != DockNode.DockPosition.CENTER).
forEach(z -> z.setZoneDisabled(true));
}
}
public boolean searchArea(double x, double y) {
checkVisibilityConditions();
ZoneSelector selector = selectors.stream()
.filter(s -> s.overMe(x, y) && !s.isZoneDisabled())
.findFirst()
.orElse(null);
highLight(selector);
if (selector != null && selector != currentZoneSelector) {
currentZoneSelector = selector;
makePreview(currentZoneSelector, currentNodeTarget);
currentPosition = currentZoneSelector.getPosition();
}
else {
if (selector == null) {
hidePreview();
currentZoneSelector = null;
currentPosition = null;
}
}
return selector != null;
}
public DockNode getCurrentNodeTarget() {
return currentNodeTarget;
}
public ZoneSelector getCurrentZoneSelector() {
return currentZoneSelector;
}
public DockNode getNodeSource() {
return nodeToMove;
}
public DockNode.DockPosition getCurrentPosition() {
return currentPosition;
}
private void highLight(ZoneSelector selector) {
selectors.stream().forEach(s -> s.reset());
if (selector != null) {
if (selector.isStationZone()) {
circleStageRoot.setOpacity(0);
}
else {
circleStageRoot.setOpacity(1);
}
selector.highLight();
}
else {
if (rectanglePreview != null) {
hidePreview();
}
currentNodeTarget = null;
}
}
private DockStation getStation() {
return ownerStation;
}
private void hidePreview() {
if (AnchorageSettings.isDockingPositionPreview()) {
stopAnimatePreview();
rectanglePreview.setOpacity(0);
}
}
private void showPreview(Bounds sceneBounds, ZoneSelector selector) {
if (selector.getPosition() == DockNode.DockPosition.LEFT) {
rectanglePreview.setX(sceneBounds.getMinX());
rectanglePreview.setY(sceneBounds.getMinY());
rectanglePreview.setWidth(sceneBounds.getWidth() / 2);
rectanglePreview.setHeight(sceneBounds.getHeight());
}
if (selector.getPosition() == DockNode.DockPosition.TOP) {
rectanglePreview.setX(sceneBounds.getMinX());
rectanglePreview.setY(sceneBounds.getMinY());
rectanglePreview.setWidth(sceneBounds.getWidth());
rectanglePreview.setHeight(sceneBounds.getHeight() / 2);
}
if (selector.getPosition() == DockNode.DockPosition.RIGHT) {
rectanglePreview.setX(sceneBounds.getMinX() + sceneBounds.getWidth() / 2);
rectanglePreview.setY(sceneBounds.getMinY());
rectanglePreview.setWidth(sceneBounds.getWidth() / 2);
rectanglePreview.setHeight(sceneBounds.getHeight());
}
if (selector.getPosition() == DockNode.DockPosition.BOTTOM) {
rectanglePreview.setX(sceneBounds.getMinX());
rectanglePreview.setY(sceneBounds.getMinY() + sceneBounds.getHeight() / 2);
rectanglePreview.setWidth(sceneBounds.getWidth());
rectanglePreview.setHeight(sceneBounds.getHeight() / 2);
}
if (selector.getPosition() == DockNode.DockPosition.CENTER) {
rectanglePreview.setX(sceneBounds.getMinX());
rectanglePreview.setY(sceneBounds.getMinY());
rectanglePreview.setWidth(sceneBounds.getWidth());
rectanglePreview.setHeight(sceneBounds.getHeight());
}
}
private void animatePreview() {
stopAnimatePreview();
rectanglePreview.setOpacity(1);
rectanglePreview.toFront();
opacityAnimationPreview.play();
}
private void stopAnimatePreview() {
opacityAnimationPreview.stop();
}
private void makePreview(ZoneSelector selector, DockNode currentNodeTarget) {
if (AnchorageSettings.isDockingPositionPreview()) {
if (selector.isStationZone()) {
Bounds sceneBounds = ownerStation.getBoundsInParent();
showPreview(sceneBounds,selector);
}
else {
Bounds nodeSceneBounds = currentNodeTarget.localToScene(currentNodeTarget.getBoundsInLocal());
Bounds stationSceneBounds = ownerStation.localToScene(ownerStation.getBoundsInLocal());
Bounds sceneBounds = new BoundingBox(nodeSceneBounds.getMinX()-stationSceneBounds.getMinX(),
nodeSceneBounds.getMinY()-stationSceneBounds.getMinY(),
nodeSceneBounds.getWidth(),nodeSceneBounds.getHeight());
if (ownerStation.isSubStation())
{
DockSubStation subStationNode = ownerStation.getDockNodeForSubStation();
if (subStationNode.floatingProperty().get())
{
sceneBounds = new BoundingBox(sceneBounds.getMinX()-FLOATING_NODE_DROPSHADOW_RADIUS-subStationNode.getFloatableStage().getPaddingOffset().getLeft(),
sceneBounds.getMinY()-FLOATING_NODE_DROPSHADOW_RADIUS-subStationNode.getFloatableStage().getPaddingOffset().getTop()-DockUIPanel.BAR_HEIGHT,
sceneBounds.getWidth(),
sceneBounds.getHeight());
}
}
showPreview(sceneBounds,selector);
}
animatePreview();
}
}
}
================================================
FILE: src/main/java/com/anchorage/docks/containers/zones/ZoneSelector.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.anchorage.docks.containers.zones;
import com.anchorage.docks.node.DockNode;
import javafx.geometry.Bounds;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Circle;
/**
*
* @author Alessio
*/
public final class ZoneSelector extends Pane {
private final DockNode.DockPosition position;
private ImageView iconView;
private Circle iconCircle;
private final boolean stationZone;
private final Pane parent;
private boolean zoneDisabled = false;
public ZoneSelector(Image image, DockNode.DockPosition position, boolean stationZone, Pane parent, double x, double y)
{
this.position = position;
this.stationZone = stationZone;
this.parent = parent;
buildUI(image,x,y);
}
public void setZoneDisabled(boolean value)
{
zoneDisabled = value;
setOpacity((value) ? 0 : 1);
}
public boolean isZoneDisabled()
{
return zoneDisabled;
}
public void reset()
{
setOpacity((zoneDisabled) ? 0 : 0.3);
}
public void highLight()
{
setOpacity((zoneDisabled) ? 0 : 1);
}
private void buildUI(Image image, double x, double y)
{
setPrefWidth(image.getWidth());
setPrefHeight(image.getHeight());
iconView = new ImageView(image);
setStyle("-fx-background-color:rgba(0,0,0,0);");
iconCircle = new Circle(image.getWidth()/2+10);
iconCircle.setCenterX(getPrefWidth() / 2);
iconCircle.setCenterY(getPrefHeight() / 2);
iconCircle.getStyleClass().add("dockzone-circle-selector");
iconView.relocate((getPrefWidth()-image.getWidth()) / 2, (getPrefWidth()-image.getHeight()) / 2);
getChildren().addAll(iconCircle,iconView);
parent.getChildren().add(this);
relocate(x, y);
}
/**
* Get the value of stationZone
*
* @return the value of stationZone
*/
public boolean isStationZone() {
return stationZone;
}
public boolean overMe(double x, double y)
{
Bounds screenBounds = localToScreen(getBoundsInLocal());
return (screenBounds.contains(x, y));
}
public DockNode.DockPosition getPosition()
{
return position;
}
}
================================================
FILE: src/main/java/com/anchorage/docks/node/DockNode.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anchorage.docks.node;
import com.anchorage.docks.containers.StageFloatable;
import static com.anchorage.docks.containers.common.AnchorageSettings.FLOATING_NODE_DROPSHADOW_RADIUS;
import com.anchorage.docks.node.ui.DockUIPanel;
import javafx.scene.layout.StackPane;
import com.anchorage.docks.containers.interfaces.DockContainableComponent;
import com.anchorage.docks.containers.interfaces.DockContainer;
import com.anchorage.docks.containers.subcontainers.DockTabberContainer;
import com.anchorage.docks.node.interfaces.DockNodeCloseRequestHandler;
import com.anchorage.docks.node.interfaces.DockNodeCreationListener;
import com.anchorage.docks.stations.DockStation;
import com.anchorage.docks.stations.DockSubStation;
import com.anchorage.system.AnchorageSystem;
import java.util.Objects;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyBooleanWrapper;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.ObservableList;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
import javafx.scene.image.Image;
import javafx.scene.layout.Pane;
import javafx.stage.Screen;
import javafx.stage.Window;
/**
*
* @author Alessio
*/
public class DockNode extends StackPane implements DockContainableComponent {
public enum DockPosition {
LEFT,
RIGHT,
TOP,
BOTTOM,
CENTER
}
private DockUIPanel content;
private BooleanProperty floatableProperty;
private BooleanProperty closeableProperty;
private BooleanProperty resizableProperty;
private BooleanProperty maximizableProperty;
private ObjectProperty station;
private ReadOnlyBooleanWrapper floatingProperty;
private ReadOnlyBooleanWrapper draggingProperty;
private ReadOnlyBooleanWrapper resizingProperty;
private ReadOnlyBooleanWrapper maximizingProperty;
private ReadOnlyObjectWrapper container;
private StageFloatable stageFloatable;
private double floatingStateCoordinateX;
private double floatingStateCoordinateY;
private double floatingStateWidth;
private double floatingStateHeight;
private DockNodeCloseRequestHandler closeRequestHanlder;
private DockNode() {
station = new SimpleObjectProperty<>(null);
floatableProperty = new SimpleBooleanProperty(true);
closeableProperty = new SimpleBooleanProperty(true);
resizableProperty = new SimpleBooleanProperty(true);
maximizableProperty = new SimpleBooleanProperty(true);
floatingProperty = new ReadOnlyBooleanWrapper(false);
draggingProperty = new ReadOnlyBooleanWrapper(false);
resizingProperty = new ReadOnlyBooleanWrapper(false);
maximizingProperty = new ReadOnlyBooleanWrapper(false);
container = new ReadOnlyObjectWrapper<>(null);
}
public DockNode(DockUIPanel node) {
this();
this.content = node;
buildUI(node);
callCreationCallBack();
}
private void callCreationCallBack() {
if (content.getNodeContent() instanceof DockNodeCreationListener) {
((DockNodeCreationListener) content.getNodeContent()).onDockNodeCreated(this);
}
}
public void ensureVisibility() {
if (container.get() instanceof DockTabberContainer) {
((DockTabberContainer) container.get()).ensureVisibility(this);
}
}
public void setCloseRequestHandler(DockNodeCloseRequestHandler handler) {
Objects.requireNonNull(handler);
closeRequestHanlder = handler;
}
public DockNodeCloseRequestHandler getCloseRequestHandler() {
return closeRequestHanlder;
}
public BooleanProperty floatableProperty() {
return floatableProperty;
}
public BooleanProperty closeableProperty() {
return closeableProperty;
}
public BooleanProperty resizableProperty() {
return resizableProperty;
}
public BooleanProperty maximizableProperty() {
return maximizableProperty;
}
public ReadOnlyBooleanProperty floatingProperty() {
return floatingProperty.getReadOnlyProperty();
}
public ReadOnlyBooleanProperty draggingProperty() {
return draggingProperty.getReadOnlyProperty();
}
public ReadOnlyBooleanProperty maximizingProperty() {
return maximizingProperty.getReadOnlyProperty();
}
public ReadOnlyObjectProperty containerProperty() {
return container.getReadOnlyProperty();
}
public void setIcon(Image icon) {
content.setIcon(icon);
}
public void restore() {
if (draggingProperty.get()) {
closeFloatingStage();
}
disableDragging();
}
public boolean isDockVisible() {
if (containerProperty().get() == null || floatingProperty.get()) {
return true;
} else {
return container.get().isDockVisible(this);
}
}
public void closeFloatingStage() {
if (stageFloatable != null) {
stageFloatable.closeStage();
stageFloatable = null;
}
floatingProperty.set(false);
}
public StageFloatable getFloatableStage() {
return stageFloatable;
}
private void buildUI(DockUIPanel panel) {
getChildren().add(panel);
panel.setDockNode(this);
}
public void moveFloatable(double x, double y) {
if (!maximizingProperty.get()) {
stageFloatable.move(x, y);
}
}
public void makeGhostFloatable(Window owner, double x, double y) {
if (!floatingProperty.get()) {
stageFloatable = new StageFloatable(this, owner, x, y);
stageFloatable.show();
makeTransparent();
}
}
public void enableDraggingOnPosition(double x, double y) {
draggingProperty.set(true);
makeGhostFloatable(station.get().getScene().getWindow(), x, y);
if (!maximizingProperty().get()) {
AnchorageSystem.prepareDraggingZoneFor(station.get(), this);
}
}
public void disableDragging() {
draggingProperty.set(false);
makeOpaque();
}
private void makeTransparent() {
content.setOpacity(0.4);
}
private void makeOpaque() {
content.setOpacity(1);
}
public void makeNodeActiveOnFloatableStage(Window owner, double x, double y) {
disableDragging();
if (!floatingProperty.get()) {
if (floatableProperty.get()) {
if (stageFloatable == null) {
makeGhostFloatable(owner, x, y);
}
stageFloatable.makeNodeActiveOnFloatableStage();
floatingProperty.set(true);
} else {
closeFloatingStage();
}
}
}
/**
* Get the value of station
*
* @return the value of station
*/
public ObjectProperty stationProperty() {
return station;
}
@Override
public void setParentContainer(DockContainer container) {
this.container.set(container);
}
@Override
public DockContainer getParentContainer() {
return container.get();
}
public void dockAsFloating(Window owner, DockStation station, double x, double y, double width, double height) {
if (stationProperty().get() != null) {
ensureVisibility();
return;
}
station.add(this);
stageFloatable = new StageFloatable(this, owner, x, y);
stageFloatable.show();
stageFloatable.setWidth(width);
stageFloatable.setHeight(height);
floatingProperty.set(true);
this.station.set((DockStation) station);
}
public void dock(DockStation station, DockPosition position) {
if (stationProperty().get() != null) {
ensureVisibility();
return;
}
station.add(this);
station.putDock(this, position, 0.5);
this.station.set((DockStation) station);
}
public void dock(DockNode nodeTarget, DockPosition position) {
if (stationProperty().get() != null) {
ensureVisibility();
return;
}
nodeTarget.stationProperty().get().add(this);
nodeTarget.getParentContainer().putDock(this, nodeTarget, position, 0.5);
station.set(nodeTarget.station.get());
}
public void dock(DockStation station, DockPosition position, double percentage) {
if (stationProperty().get() != null) {
ensureVisibility();
return;
}
station.add(this);
station.putDock(this, position, percentage);
this.station.set((DockStation) station);
}
public void dock(DockNode nodeTarget, DockPosition position, double percentage) {
if (stationProperty().get() != null) {
ensureVisibility();
return;
}
nodeTarget.stationProperty().get().add(this);
nodeTarget.getParentContainer().putDock(this, nodeTarget, position, percentage);
station.set(nodeTarget.station.get());
}
public void dock(DockSubStation subStation, DockPosition position) {
if (stationProperty().get() != null) {
ensureVisibility();
return;
}
subStation.putDock(this, position, 0.5);
}
public void dock(DockSubStation subStation, DockPosition position, double percentage) {
if (stationProperty().get() != null) {
ensureVisibility();
return;
}
subStation.putDock(this, position, percentage);
}
public void undock() {
if (stationProperty().get() == null) {
return;
}
boolean isFloating = floatingProperty.get();
restore();
if (getParentContainer() != null) {
getParentContainer().undock(this);
station.get().remove(this);
} else if (isFloating) {
station.get().remove(this);
station.set(null);
}
}
public DockUIPanel getContent() {
return content;
}
@Override
public String toString() {
return content.titleProperty().get();
}
public Bounds getSceneBounds() {
return localToScene(getBoundsInLocal());
}
public Bounds getScreenBounds() {
return localToScreen(getBoundsInLocal());
}
public boolean checkForTarget(double x, double y) {
Point2D screenToScenePoint = getScene().getRoot().screenToLocal(x, y);
Bounds sceneBounds = getSceneBounds();
return sceneBounds.contains(screenToScenePoint.getX(), screenToScenePoint.getY());
}
public boolean insideTabContainer() {
return container.get() instanceof DockTabberContainer;
}
public void maximizeOrRestore() {
if (maximizingProperty.get()) {
restoreLayout();
} else {
maximizeLayout();
}
}
public void restoreLayout() {
if (maximizableProperty.get()) {
if (floatingProperty.get()) {
stageFloatable.setX(floatingStateCoordinateX);
stageFloatable.setY(floatingStateCoordinateY);
stageFloatable.setWidth(floatingStateWidth);
stageFloatable.setHeight(floatingStateHeight);
maximizingProperty.set(false);
} else if (station.get().restore(this)) {
maximizingProperty.set(false);
}
}
}
private void moveStateToFullScreen() {
// Get current screen of the stage
ObservableList screens = Screen.getScreensForRectangle(new Rectangle2D(stageFloatable.getX(), stageFloatable.getY(), stageFloatable.getWidth(), stageFloatable.getHeight()));
// Change stage properties
Rectangle2D bounds = screens.get(0).getBounds();
stageFloatable.setX(bounds.getMinX() - FLOATING_NODE_DROPSHADOW_RADIUS);
stageFloatable.setY(bounds.getMinY() - FLOATING_NODE_DROPSHADOW_RADIUS);
stageFloatable.setWidth(bounds.getWidth() + FLOATING_NODE_DROPSHADOW_RADIUS * 2);
stageFloatable.setHeight(bounds.getHeight() + FLOATING_NODE_DROPSHADOW_RADIUS * 2);
}
public void maximizeLayout() {
if (maximizableProperty.get()) {
if (floatingProperty.get()) {
floatingStateCoordinateX = stageFloatable.getX();
floatingStateCoordinateY = stageFloatable.getY();
floatingStateWidth = stageFloatable.getWidth();
floatingStateHeight = stageFloatable.getHeight();
moveStateToFullScreen();
maximizingProperty.set(true);
} else if (station.get().maximize(this)) {
maximizingProperty.set(true);
}
}
}
public boolean isMenuButtonEnable() {
return content.isMenuButtonEnable();
}
}
================================================
FILE: src/main/java/com/anchorage/docks/node/interfaces/DockNodeCloseRequestHandler.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anchorage.docks.node.interfaces;
/**
*
* @author Alessio
*/
@FunctionalInterface
public interface DockNodeCloseRequestHandler {
public boolean canClose();
}
================================================
FILE: src/main/java/com/anchorage/docks/node/interfaces/DockNodeCreationListener.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anchorage.docks.node.interfaces;
import com.anchorage.docks.node.DockNode;
/**
*
* @author Alessio
*/
public interface DockNodeCreationListener {
public void onDockNodeCreated(DockNode node);
}
================================================
FILE: src/main/java/com/anchorage/docks/node/ui/DockCommandsBox.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.anchorage.docks.node.ui;
import com.anchorage.docks.containers.SingleDockContainer;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.stations.DockSubStation;
import javafx.animation.RotateTransition;
import javafx.geometry.Point2D;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.util.Duration;
/**
*
* @author Alessio
*/
public class DockCommandsBox extends HBox {
private Button closeButton;
private Button maximizeRestoreButton;
private Runnable openAction = null;
private Runnable hideAction = null;
private Pane externalContent;
private final DockNode node;
private Button menuButton;
private boolean isMenuOpen;
public DockCommandsBox(DockNode node) {
this.node = node;
buildUI();
setSpacing(0);
setStyle("-fx-background-color:transparent;");
}
private void changeCommandsState() {
if (node instanceof DockSubStation || !node.closeableProperty().get()) {
closeButton.setMouseTransparent(true);
closeButton.setOpacity(0.4);
} else {
closeButton.setMouseTransparent(false);
closeButton.setOpacity(1);
}
if (node.getParentContainer() instanceof SingleDockContainer) {
if (node.maximizableProperty().get()) {
maximizeRestoreButton.setMouseTransparent(true);
maximizeRestoreButton.setOpacity(0.4);
}
} else if (node.maximizableProperty().get()) {
maximizeRestoreButton.setMouseTransparent(false);
maximizeRestoreButton.setOpacity(1);
}
}
private void changeStateForFloatingState() {
if (node.maximizableProperty().get() && node.floatingProperty().get()) {
maximizeRestoreButton.setMouseTransparent(false);
maximizeRestoreButton.setOpacity(1);
} else {
maximizeRestoreButton.setMouseTransparent(true);
maximizeRestoreButton.setOpacity(0.4);
}
}
private void createCloseButton() {
Image closeImage = new Image("close.png");
closeButton = new Button() {
@Override
public void requestFocus() {
}
};
closeButton.setGraphic(new ImageView(closeImage));
closeButton.getStyleClass().add("docknode-command-button-close");
closeButton.setOnAction(e -> {
if (node.getCloseRequestHandler() != null) {
if (node.getCloseRequestHandler().canClose()) {
node.undock();
}
}
else {
node.undock();
}
});
node.closeableProperty().addListener((observer, oldValue, newValue) -> changeCommandsState());
node.containerProperty().addListener((observer, oldValue, newValue) -> changeCommandsState());
node.floatingProperty().addListener((observer, oldValue, newValue) -> changeStateForFloatingState());
getChildren().add(closeButton);
}
private void createMaxRestoreButton() {
Image maximizeImage = new Image("maximize.png");
Image restoreImage = new Image("restore.png");
maximizeRestoreButton = new Button() {
@Override
public void requestFocus() {
}
};
maximizeRestoreButton.setGraphic(new ImageView(maximizeImage));
maximizeRestoreButton.getStyleClass().add("docknode-command-button");
node.maximizingProperty().addListener((observer, oldValue, newValue) -> {
if (newValue) {
maximizeRestoreButton.setGraphic(new ImageView(restoreImage));
} else {
maximizeRestoreButton.setGraphic(new ImageView(maximizeImage));
}
});
maximizeRestoreButton.setOnAction(e -> node.maximizeOrRestore());
getChildren().add(maximizeRestoreButton);
node.maximizableProperty().addListener((observer, oldValue, newValue) -> {
if (newValue) {
maximizeRestoreButton.setMouseTransparent(false);
maximizeRestoreButton.setOpacity(1);
} else {
maximizeRestoreButton.setMouseTransparent(true);
maximizeRestoreButton.setOpacity(0.4);
}
});
}
private void buildUI() {
createMaxRestoreButton();
createCloseButton();
}
void enableMenuButton(boolean enable) {
menuButton.setVisible(enable);
}
boolean isMenuButtonEnable() {
return menuButton.isVisible();
}
private void showContent(Point2D localToScreen) {
Popover popover = new Popover(this, externalContent);
popover.show(localToScreen.getX(), localToScreen.getY());
}
void notifyCloseAction() {
if (isMenuOpen) {
isMenuOpen = false;
RotateTransition rotate = new RotateTransition(Duration.seconds(0.2), menuButton.getGraphic());
rotate.setToAngle(0);
rotate.play();
hideAction.run();
}
}
void notifyOpenAction() {
RotateTransition rotate = new RotateTransition(Duration.seconds(0.2), menuButton.getGraphic());
rotate.setToAngle(90);
rotate.play();
openAction.run();
}
}
================================================
FILE: src/main/java/com/anchorage/docks/node/ui/DockUIPanel.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anchorage.docks.node.ui;
import com.anchorage.docks.node.DockNode;
import com.anchorage.system.AnchorageSystem;
import java.util.Objects;
import javafx.beans.property.StringProperty;
import javafx.geometry.Bounds;
import javafx.geometry.Point2D;
import javafx.scene.CacheHint;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
/**
*
* @author Alessio
*/
public final class DockUIPanel extends Pane {
public static final double BAR_HEIGHT = 25;
private Node nodeContent;
private Label titleLabel;
private Pane barPanel;
private StackPane contentPanel;
private DockCommandsBox commandsBox;
private DockNode node;
private Point2D deltaDragging;
private boolean subStationStype;
private ImageView iconView;
private DockUIPanel() {
}
public DockUIPanel(String title, Node nodeContent, boolean subStationStype, Image imageIcon) {
getStylesheets().add("anchorfx.css");
this.subStationStype = subStationStype;
Objects.requireNonNull(nodeContent);
Objects.requireNonNull(title);
this.nodeContent = nodeContent;
buildNode(title,imageIcon);
installDragEventMananger();
}
public void setIcon(Image icon)
{
Objects.requireNonNull(icon);
iconView.setImage(icon);
}
private void makeCommands() {
commandsBox = new DockCommandsBox(node);
barPanel.getChildren().add(commandsBox);
commandsBox.layoutXProperty().bind(barPanel.prefWidthProperty().subtract(commandsBox.getChildren().size() * 30 + 10));
commandsBox.setLayoutY(0);
titleLabel.prefWidthProperty().bind(commandsBox.layoutXProperty().subtract(10));
}
public void setDockNode(DockNode node) {
this.node = node;
makeCommands();
}
public StringProperty titleProperty() {
return titleLabel.textProperty();
}
private void installDragEventMananger() {
barPanel.setOnMouseClicked(event -> {
if (event.getButton() == MouseButton.PRIMARY && event.getClickCount() == 2) {
node.maximizeOrRestore();
}
});
barPanel.setOnMouseDragged(event -> {
if (event.getButton() == MouseButton.PRIMARY) {
manageDragEvent(event);
}
});
barPanel.setOnMouseReleased(event -> {
if (event.getButton() == MouseButton.PRIMARY) {
manageReleaseEvent();
}
});
}
private void manageDragEvent(MouseEvent event) {
if (!node.draggingProperty().get()) {
if (!node.maximizingProperty().get()) {
Bounds bounds = node.localToScreen(barPanel.getBoundsInLocal());
deltaDragging = new Point2D(event.getScreenX() - bounds.getMinX(),
event.getScreenY() - bounds.getMinY());
node.enableDraggingOnPosition(event.getScreenX() - deltaDragging.getX(), event.getScreenY() - deltaDragging.getY());
}
}
else {
if (node.getFloatableStage() != null && !node.getFloatableStage().inResizing() && node.draggingProperty().get()) {
if (!node.maximizingProperty().get()) {
node.moveFloatable(event.getScreenX() - deltaDragging.getX(),
event.getScreenY() - deltaDragging.getY());
//node.stationProperty().get().searchTargetNode(event.getScreenX(), event.getScreenY());
AnchorageSystem.searchTargetNode(event.getScreenX(), event.getScreenY());
}
}
}
}
private void manageReleaseEvent() {
if (node.draggingProperty().get() && !node.maximizingProperty().get()) {
AnchorageSystem.finalizeDragging();
}
}
private void buildNode(String title, Image iconImage) {
Objects.requireNonNull(iconImage);
Objects.requireNonNull(title);
barPanel = new Pane();
String titleBarStyle = (!subStationStype) ? "docknode-title-bar" : "substation-title-bar";
barPanel.getStyleClass().add(titleBarStyle);
barPanel.setPrefHeight(BAR_HEIGHT);
barPanel.relocate(0, 0);
barPanel.prefWidthProperty().bind(widthProperty());
titleLabel = new Label(title);
String titleTextStyle = (!subStationStype) ? "docknode-title-text" : "substation-title-text";
iconView = new ImageView(iconImage);
iconView.setFitWidth(15);
iconView.setFitHeight(15);
iconView.setPreserveRatio(false);
iconView.setSmooth(true);
iconView.relocate(1,(BAR_HEIGHT-iconView.getFitHeight()) / 2);
titleLabel.getStyleClass().add(titleTextStyle);
barPanel.getChildren().addAll(iconView,titleLabel);
titleLabel.relocate(25, 5);
contentPanel = new StackPane();
contentPanel.getStyleClass().add("docknode-content-panel");
contentPanel.relocate(0, BAR_HEIGHT);
contentPanel.prefWidthProperty().bind(widthProperty());
contentPanel.prefHeightProperty().bind(heightProperty().subtract(BAR_HEIGHT));
contentPanel.getChildren().add(nodeContent);
contentPanel.setCache(true);
contentPanel.setCacheHint(CacheHint.SPEED);
if (nodeContent instanceof Pane)
{
Pane nodeContentPane = (Pane)nodeContent;
nodeContentPane.setMinHeight(USE_COMPUTED_SIZE);
nodeContentPane.setMinWidth(USE_COMPUTED_SIZE);
nodeContentPane.setMaxWidth(USE_COMPUTED_SIZE);
nodeContentPane.setMaxHeight(USE_COMPUTED_SIZE);
}
getChildren().addAll(barPanel, contentPanel);
}
public StackPane getContentContainer()
{
return contentPanel;
}
/**
* Get the value of nodeContent
*
* @return the value of nodeContent
*/
public Node getNodeContent() {
return nodeContent;
}
public boolean isMenuButtonEnable(){
return commandsBox.isMenuButtonEnable();
}
}
================================================
FILE: src/main/java/com/anchorage/docks/node/ui/Popover.java
================================================
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anchorage.docks.node.ui;
import javafx.animation.FadeTransition;
import javafx.beans.value.ChangeListener;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;
/**
*
* @author Alessio
*/
public class Popover extends Stage {
private final Pane content;
private final Scene scene;
private DockCommandsBox commandBox;
private ChangeListener positionListener;
private EventHandler eventFilter;
public Popover(DockCommandsBox commandBox, Pane content) {
this.content = content;
this.commandBox = commandBox;
scene = new Scene(content, Color.TRANSPARENT);
setScene(scene);
initStyle(StageStyle.TRANSPARENT);
initOwner(commandBox.getScene().getWindow());
positionListener = (obs, oldvalue, newvalue) -> hideAndNotify();
eventFilter = evt -> hideAndNotify();
setOnShown(e -> {
Stage ownerStage = (Stage) commandBox.getScene().getWindow();
commandBox.getScene().addEventFilter(MouseEvent.MOUSE_PRESSED, eventFilter);
ownerStage.xProperty().addListener(positionListener);
ownerStage.yProperty().addListener(positionListener);
content.setOpacity(0);
FadeTransition fade = new FadeTransition(Duration.seconds(0.2), content);
fade.setToValue(1);
fade.play();
});
}
public void show(double x, double y) {
commandBox.notifyOpenAction();
setX(x);
setY(y);
show();
}
public void hideAndNotify() {
Stage ownerStage = (Stage) commandBox.getScene().getWindow();
ownerStage.xProperty().removeListener(positionListener);
ownerStage.yProperty().removeListener(positionListener);
commandBox.getScene().removeEventFilter(MouseEvent.MOUSE_PRESSED, eventFilter);
System.out.println("hideAndNotify");
hide();
scene.setRoot(new Region()); // elimina il content dalla scena
commandBox.notifyCloseAction();
}
}
================================================
FILE: src/main/java/com/anchorage/docks/stations/DockStation.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anchorage.docks.stations;
import com.anchorage.docks.containers.SingleDockContainer;
import com.anchorage.docks.containers.subcontainers.DockTabberContainer;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.containers.zones.DockZones;
import com.anchorage.docks.containers.zones.ZoneSelector;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Rectangle;
import javafx.stage.Window;
/**
*
* @author Alessio
*/
public final class DockStation extends SingleDockContainer {
private final List nodes;
private DockZones dockZones;
private DockNode currentNodeTarget;
private Node currentNodeBeforeMaximization;
private DockNode currentNodeMaximized;
private Parent currentNodeMaximizedParent;
private boolean substation;
private DockSubStation dockNodeForSubstation;
private boolean commonStation;
private boolean selected = false;
/**
* Get the value of selected
*
* @return the value of selected
*/
public boolean isSelected() {
return selected;
}
public DockStation() {
nodes = new ArrayList<>();
substation = false;
buildUI();
}
public DockStation(boolean commonStation) {
this();
this.commonStation = commonStation;
}
public boolean isCommonStation() {
return commonStation;
}
private void buildUI() {
getStyleClass().add("station");
}
public Window getStationWindow() {
return getStationScene().getWindow();
}
public Scene getStationScene() {
return getScene();
}
public boolean isInnerPosition(double x, double y) {
Window window = getStationWindow();
Rectangle bounds = new Rectangle(window.getX(), window.getY(), window.getWidth(), window.getHeight());
return bounds.contains(x, y);
}
public void prepareZones(DockNode nodeToMove) {
if (currentNodeMaximized == null) {
dockZones = new DockZones(this, nodeToMove);
dockZones.showZones();
}
}
public boolean isSubStation() {
return substation;
}
public void add(DockNode node) {
if (!nodes.contains(node)) {
nodes.add(node);
}
}
public void remove(DockNode node) {
if (nodes.contains(node)) {
nodes.remove(node);
node.stationProperty().set(null);
}
}
public void searchTargetNode(double x, double y) {
selected = false;
if (currentNodeMaximized != null) {
return;
}
Optional nodeTarget = nodes.stream()
.filter(node
-> !node.floatingProperty().get()
&& node.checkForTarget(x, y)
&& node.isDockVisible()).findFirst();
nodeTarget.map(node -> (Runnable) () -> {
currentNodeTarget = node;
dockZones.moveAt(node);
}).orElse((Runnable) () -> {
if (currentNodeTarget != null) {
dockZones.hideCircleZones();
}
}).run();
selected = dockZones.searchArea(x, y);
}
public void addOverlay(Node node) {
getChildren().add(node);
}
public void removeOverlay(Node node) {
getChildren().remove(node);
}
public void hideZones() {
dockZones.close();
}
private void manageDragOnSameNode() {
DockTabberContainer tabContainer = (DockTabberContainer) dockZones.getCurrentNodeTarget().getParentContainer();
tabContainer.manageDragOnSameNode(dockZones.getCurrentNodeTarget(), dockZones.getCurrentPosition());
}
public void finalizeDrag() {
if (currentNodeMaximized != null) {
return;
}
ZoneSelector selector = dockZones.getCurrentZoneSelector();
if (selector == null) {
dockZones.getNodeSource().makeNodeActiveOnFloatableStage(getScene().getWindow(), getScene().getX(), getScene().getY());
}
else {
DockNode.DockPosition position = selector.getPosition();
if (selector.isStationZone()) {
dockZones.getNodeSource().undock();
dockZones.getNodeSource().dock(this, position);
}
else {
manageDockDestination();
}
}
}
public void closeZones()
{
dockZones.close();
}
private void manageDockDestination() {
if (dockZones.getCurrentNodeTarget() == dockZones.getNodeSource()) {
if (dockZones.getCurrentNodeTarget().getParentContainer() instanceof DockTabberContainer
&& dockZones.getCurrentPosition() != DockNode.DockPosition.CENTER) {
manageDragOnSameNode();
}
else {
dockZones.getNodeSource().restore();
}
}
else {
dockZones.getNodeSource().undock();
dockZones.getNodeSource().dock(dockZones.getCurrentNodeTarget(), dockZones.getCurrentPosition());
}
}
public boolean maximize(DockNode node) {
if (!node.maximizingProperty().get() && getChildren().get(0) != node) {
currentNodeBeforeMaximization = getChildren().get(0);
getChildren().remove(0);
currentNodeMaximizedParent = node.getParent();
getChildren().add(node);
currentNodeMaximized = node;
return true;
}
return false;
}
public boolean restore(DockNode node) {
if (currentNodeMaximized != null && currentNodeMaximized == node) {
Pane panelParent = (Pane) currentNodeMaximizedParent;
panelParent.getChildren().add(currentNodeMaximized);
getChildren().add(currentNodeBeforeMaximization);
currentNodeMaximized = null;
currentNodeBeforeMaximization = null;
return true;
}
else {
return false;
}
}
public void markAsSubStation(DockSubStation dockNodeForSubstation) {
substation = true;
this.dockNodeForSubstation = dockNodeForSubstation;
}
public DockSubStation getDockNodeForSubStation() {
return dockNodeForSubstation;
}
}
================================================
FILE: src/main/java/com/anchorage/docks/stations/DockSubStation.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anchorage.docks.stations;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.node.ui.DockUIPanel;
import javafx.scene.Scene;
import javafx.stage.Window;
/**
*
* @author avinerbi
*/
public final class DockSubStation extends DockNode {
private final DockStation substation;
/**
* Get the value of station
*
* @return the value of station
*/
public DockStation getSubStation() {
return substation;
}
public Window getStationWindow()
{
return stationProperty().get().getStationScene().getWindow();
}
public Scene getStationScene()
{
return stationProperty().get().getStationScene();
}
public void putDock(DockNode dockNode, DockPosition position, double percentage) {
substation.add(dockNode);
substation.putDock(dockNode, position,percentage);
dockNode.stationProperty().set(substation);
}
public DockSubStation(DockUIPanel uiPanel) {
super(uiPanel);
substation = (DockStation)getContent().getNodeContent();
substation.markAsSubStation(this);
}
}
================================================
FILE: src/main/java/com/anchorage/system/AnchorageSystem.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anchorage.system;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.node.ui.DockUIPanel;
import com.anchorage.docks.stations.DockStation;
import com.anchorage.docks.stations.DockSubStation;
import com.sun.javafx.css.StyleManager;
import javafx.scene.Parent;
import java.util.ArrayList;
import java.util.List;
import javafx.scene.Node;
import javafx.scene.image.Image;
/**
*
* @author Alessio
*/
public class AnchorageSystem {
private static final List stations;
private static DockNode nodeInDragging;
private static final Image emptyIconImage;
private static final Image emptySubstationIconImage;
private static DockStation currentStationFromDrag;
static {
stations = new ArrayList<>();
emptyIconImage = new Image("empty.png");
emptySubstationIconImage = new Image("substation.png");
}
public static DockStation createStation() {
DockStation station = new DockStation();
stations.add(station);
return station;
}
public static DockStation createCommonStation() {
DockStation station = new DockStation(true);
stations.add(station);
return station;
}
public static DockSubStation createSubStation(DockStation parentStation, String title) {
DockSubStation station = new DockSubStation(new DockUIPanel(title, new DockStation(), true, emptySubstationIconImage));
return station;
}
public static DockNode createDock(String title, Node content) {
DockUIPanel panel = new DockUIPanel(title, content, false, emptyIconImage);
DockNode container = new DockNode(panel);
return container;
}
public static DockNode createDock(String title, Parent content, Image icon) {
DockUIPanel panel = new DockUIPanel(title, content, false, icon);
DockNode container = new DockNode(panel);
return container;
}
public static void installDefaultStyle() {
StyleManager.getInstance()
.addUserAgentStylesheet("AnchorFX.css");
}
public static void prepareDraggingZoneFor(DockStation station, DockNode source) {
currentStationFromDrag = station;
station.prepareZones(source);
if (currentStationFromDrag.isSubStation())
return;
if (station.isCommonStation()) {
stations.stream().filter(s -> s != station && s.isCommonStation()).forEach(s -> s.prepareZones(source));
}
}
public static void searchTargetNode(double x, double y) {
if (currentStationFromDrag.isCommonStation() && !currentStationFromDrag.isSubStation()) {
stations.stream().filter(s -> s.isCommonStation()).forEach(s -> s.searchTargetNode(x, y));
} else {
currentStationFromDrag.searchTargetNode(x, y);
}
}
public static void finalizeDragging() {
if (currentStationFromDrag.isSubStation()) {
currentStationFromDrag.closeZones();
currentStationFromDrag.finalizeDrag();
} else {
if (currentStationFromDrag.isCommonStation())
stations.stream().filter(s -> s.isCommonStation()).forEach(s -> s.closeZones());
else
currentStationFromDrag.closeZones();
DockStation selectedStation = stations.stream().filter(s -> s.isSelected()).findFirst().orElse(null);
if (selectedStation != null && currentStationFromDrag.isCommonStation()) {
selectedStation.finalizeDrag();
} else {
currentStationFromDrag.finalizeDrag();
}
}
}
}
================================================
FILE: src/main/resources/AnchorFX.css
================================================
/**
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/*
Created on : 27-dic-2015, 13.25.27
Author : Alessio Vinerbi
*/
.docknode-title-bar {
-fx-background-color: rgb(100,100,100);
}
.docknode-title-text{
-fx-text-fill: rgb(255,255,255);
}
.docknode-content-panel{
-fx-background-color: rgb(100,100,100);
-fx-padding: 0
}
.docknode-floating-stack-container-panel {
-fx-background-color: rgb(100,100,100);
-fx-padding: 4
}
.docknode-split-pane {
-fx-padding: 0;
}
.docknode-split-pane *.split-pane-divider {
-fx-padding: 2;
-fx-border-color:transparent;
-fx-color: darkgray;
}
.docknode-tab-panel{
-fx-padding: 0;
}
.docknode-command-button{
-fx-background-color:transparent;
-fx-background-radius: 0,0,0;
}
.docknode-command-button:hover{
-fx-background-color:darkgray;
}
.docknode-command-button:pressed{
-fx-background-color:darkgray;
}
.docknode-command-button:focused{
-fx-background-color:transparent;
}
.docknode-command-button-close{
-fx-background-color:transparent;
-fx-background-radius: 0,0,0;
}
.docknode-command-button-close:pressed{
-fx-background-color:red;
}
.docknode-command-button-close:hover{
-fx-background-color:red;
}
.docknode-command-button-close:focused{
-fx-background-color:transparent;
}
.station {
-fx-background-color: rgb(0,0,0);
-fx-padding: 0
}
.substation-title-bar {
-fx-background-color: rgb(0,0,0);
}
.substation-title-text{
-fx-text-fill: rgb(255,255,255);
}
.dockzone-circle-container-selectors {
-fx-fill: rgba(0,0,0,0.7);
}
.dockzone-circle-selector {
-fx-fill: rgba(0,0,0,0.8);
}
.dockzone-rectangle-preview {
-fx-fill: rgba(63,138,163,0.8);
}
================================================
FILE: src/test/java/com/anchorage/demo/AnchorFX_CommonStations.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anchorage.demo;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.stations.DockStation;
import com.anchorage.system.AnchorageSystem;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.stage.Stage;
import java.util.Random;
/**
*
* @author Alessio
*/
public class AnchorFX_CommonStations extends Application {
@Override
public void start(Stage primaryStage) {
DockStation station = AnchorageSystem.createCommonStation();
Scene scene = new Scene(station, 500,500);
DockNode node1 = AnchorageSystem.createDock("Tree 1", generateRandomTree());
node1.dock(station, DockNode.DockPosition.CENTER);
DockNode node2 = AnchorageSystem.createDock("Tree 2", generateRandomTree());
node2.dock(station, DockNode.DockPosition.RIGHT);
primaryStage.setTitle("Station 1");
primaryStage.setScene(scene);
primaryStage.show();
makeSecondStage();
AnchorageSystem.installDefaultStyle();
}
private void makeSecondStage()
{
Stage stage = new Stage();
DockStation station = AnchorageSystem.createCommonStation();
Scene scene = new Scene(station, 500, 500);
stage.setScene(scene);
stage.setTitle("Station 2");
DockNode node1 = AnchorageSystem.createDock("Tree 3", generateRandomTree());
node1.dock(station, DockNode.DockPosition.CENTER);
DockNode node2 = AnchorageSystem.createDock("Tree 4", generateRandomTree());
node2.dock(station, DockNode.DockPosition.RIGHT);
stage.setX(600);
stage.show();
}
private TreeView generateRandomTree() {
// create a demonstration tree view to use as the contents for a dock node
TreeItem root = new TreeItem("Root");
TreeView treeView = new TreeView(root);
treeView.setShowRoot(false);
// populate the prototype tree with some random nodes
Random rand = new Random();
for (int i = 4 + rand.nextInt(8); i > 0; i--) {
TreeItem treeItem = new TreeItem("Item " + i);
root.getChildren().add(treeItem);
for (int j = 2 + rand.nextInt(4); j > 0; j--) {
TreeItem childItem = new TreeItem("Child " + j);
treeItem.getChildren().add(childItem);
}
}
return treeView;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
================================================
FILE: src/test/java/com/anchorage/demo/AnchorFX_events.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.anchorage.demo;
import com.anchorage.docks.containers.common.AnchorageSettings;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.node.interfaces.DockNodeCreationListener;
import com.anchorage.docks.stations.DockStation;
import com.anchorage.system.AnchorageSystem;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
*
* @author Alessio
*/
public class AnchorFX_events extends Application {
@Override
public void start(Stage primaryStage) {
AnchorageSettings.setDockingPositionPreview(false);
DockStation station = AnchorageSystem.createStation();
Scene scene = new Scene(station, 1024, 768);
DockNode node1 = AnchorageSystem.createDock("Events", new MyPanel());
node1.dock(station, DockNode.DockPosition.LEFT);
AnchorageSystem.installDefaultStyle();
primaryStage.setTitle("AnchorFX ");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
class MyPanel extends VBox implements DockNodeCreationListener {
private DockNode myNode;
private Label floatingLabel;
private Label draggingLabel;
private Label maximizedLabel;
@Override
public void onDockNodeCreated(DockNode node) {
myNode = node;
setSpacing(20);
floatingLabel = new Label("Floating : false");
myNode.floatingProperty().addListener((ov,oldv,newv)->floatingLabel.setText("Floating : "+newv));
draggingLabel = new Label("Dragging : false");
myNode.draggingProperty().addListener((ov,oldv,newv)->draggingLabel.setText("Dragging : "+newv));
maximizedLabel = new Label("Maximizing : false");
myNode.maximizingProperty().addListener((ov,oldv,newv)->maximizedLabel.setText("Maximizing : "+newv));
setStyle("-fx-background-color:rgb(200,200,200); -fx-padding:15;");
getChildren().addAll(floatingLabel,draggingLabel,maximizedLabel);
}
}
================================================
FILE: src/test/java/com/anchorage/demo/AnchorFX_settings.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anchorage.demo;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.stations.DockStation;
import com.anchorage.system.AnchorageSystem;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.stage.Stage;
import java.util.Random;
/**
*
* @author Alessio
*/
public class AnchorFX_settings extends Application {
@Override
public void start(Stage primaryStage) {
//AnchorageSettings.setDockingPositionPreview(false);
DockStation station = AnchorageSystem.createStation();
Scene scene = new Scene(station, 1024, 768);
DockNode node1 = AnchorageSystem.createDock("Not floatable", generateRandomTree());
node1.dock(station, DockNode.DockPosition.LEFT);
node1.floatableProperty().set(false);
DockNode node2 = AnchorageSystem.createDock("Not resizable", generateRandomTree());
node2.dock(station, DockNode.DockPosition.RIGHT);
node2.resizableProperty().set(false);
DockNode node3 = AnchorageSystem.createDock("Not maximizable", generateRandomTree());
node3.dock(station, DockNode.DockPosition.TOP);
node3.maximizableProperty().set(false);
DockNode node4 = AnchorageSystem.createDock("Not closeable", generateRandomTree());
node4.dock(station, DockNode.DockPosition.BOTTOM);
node4.closeableProperty().set(false);
primaryStage.setTitle("AnchorFX ");
primaryStage.setScene(scene);
primaryStage.show();
AnchorageSystem.installDefaultStyle();
}
private TreeView generateRandomTree() {
// create a demonstration tree view to use as the contents for a dock node
TreeItem root = new TreeItem("Root");
TreeView treeView = new TreeView(root);
treeView.setShowRoot(false);
// populate the prototype tree with some random nodes
Random rand = new Random();
for (int i = 4 + rand.nextInt(8); i > 0; i--) {
TreeItem treeItem = new TreeItem("Item " + i);
root.getChildren().add(treeItem);
for (int j = 2 + rand.nextInt(4); j > 0; j--) {
TreeItem childItem = new TreeItem("Child " + j);
treeItem.getChildren().add(childItem);
}
}
return treeView;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
================================================
FILE: src/test/java/com/anchorage/demo/AnchorFX_substations.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anchorage.demo;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.stations.DockStation;
import com.anchorage.docks.stations.DockSubStation;
import com.anchorage.system.AnchorageSystem;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
/**
*
* @author Alessio
*/
public class AnchorFX_substations extends Application {
@Override
public void start(Stage primaryStage) {
DockStation station = AnchorageSystem.createStation();
Scene scene = new Scene(station, 1024, 768);
DockNode node1 = AnchorageSystem.createDock("Node", new TableView());
node1.dock(station, DockNode.DockPosition.CENTER);
DockSubStation station1 = AnchorageSystem.createSubStation(station, "SubStation");
station1.dock(station, DockNode.DockPosition.LEFT,0.7);
DockNode subNode = AnchorageSystem.createDock("subNode 1", new TableView());
subNode.dock(station1, DockNode.DockPosition.LEFT);
subNode.floatableProperty().set(false);
DockNode subNode2 = AnchorageSystem.createDock("subNode 2", new TableView());
subNode2.dock(station1, DockNode.DockPosition.LEFT);
AnchorageSystem.installDefaultStyle();
primaryStage.setTitle("AnchorFX SubStation");
primaryStage.setScene(scene);
primaryStage.show();
//node4.makeNodeActiveOnFloatableStage();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
================================================
FILE: src/test/java/com/anchorage/demo/AnchorFX_test.java
================================================
/*
* Copyright 2015-2016 Alessio Vinerbi. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.anchorage.demo;
import com.anchorage.docks.node.DockNode;
import com.anchorage.docks.stations.DockStation;
import com.anchorage.system.AnchorageSystem;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.web.HTMLEditor;
import javafx.stage.Stage;
import java.util.Random;
/**
*
* @author Alessio
*/
public class AnchorFX_test extends Application {
@Override
public void start(Stage primaryStage) {
DockStation station = AnchorageSystem.createStation();
Scene scene = new Scene(station, 1024, 768);
DockNode node1 = AnchorageSystem.createDock("Not floatable", new HTMLEditor());
node1.dock(station, DockNode.DockPosition.LEFT);
node1.floatableProperty().set(false);
DockNode node2 = AnchorageSystem.createDock("Not resizable", new HTMLEditor());
node2.dock(station, DockNode.DockPosition.RIGHT);
node2.resizableProperty().set(false);
// DockNode node1 = AnchorageSystem.createDock("Tree", generateRandomTree());
// node1.dock(station, DockNode.DockPosition.CENTER);
//
// DockNode node2 = AnchorageSystem.createDock("Editor", new HTMLEditor());
// node2.dock(station, DockNode.DockPosition.RIGHT);
//
// DockNode node3 = AnchorageSystem.createDock("Below the editor", generateRandomTree());
// node3.dock(node2, DockNode.DockPosition.BOTTOM,0.8);
AnchorageSystem.installDefaultStyle();
primaryStage.setTitle("AnchorFX");
primaryStage.setScene(scene);
primaryStage.show();
// DockNode node4 = AnchorageSystem.createDock("Floating", new TableView());
// node4.dockAsFloating(primaryStage, station, 0, 0, 400, 200);
AnchorageSystem.installDefaultStyle();
}
private TreeView generateRandomTree() {
// create a demonstration tree view to use as the contents for a dock node
TreeItem root = new TreeItem("Root");
TreeView treeView = new TreeView(root);
treeView.setShowRoot(false);
// populate the prototype tree with some random nodes
Random rand = new Random();
for (int i = 4 + rand.nextInt(8); i > 0; i--) {
TreeItem treeItem = new TreeItem("Item " + i);
root.getChildren().add(treeItem);
for (int j = 2 + rand.nextInt(4); j > 0; j--) {
TreeItem childItem = new TreeItem("Child " + j);
treeItem.getChildren().add(childItem);
}
}
return treeView;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}