-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathFxDockPane.java
142 lines (109 loc) · 3.2 KB
/
FxDockPane.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright © 2016-2024 Andy Goryachev <[email protected]>
package goryachev.fxdock;
import goryachev.fx.FX;
import goryachev.fx.FxAction;
import goryachev.fxdock.internal.DockTools;
import goryachev.fxdock.internal.DragAndDropHandler;
import goryachev.fxdock.internal.FxDockBorderPane;
import goryachev.fxdock.internal.FxDockTabPane;
import javafx.beans.property.ReadOnlyBooleanProperty;
import javafx.beans.property.ReadOnlyBooleanWrapper;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ToolBar;
/**
* FxDockPane is a base class for all panes that can be placed in the docking framework.
*
* When restoring the layout, concrete instances of FxDockPanes are created by the application FxDockWindow
* implementation.
*/
public abstract class FxDockPane
extends FxDockBorderPane
{
public final FxAction closeAction = new FxAction(this::actionClose);
public final FxAction popToWindowAction = new FxAction(this::actionPopToWindow);
public final Label titleField;
private final ReadOnlyBooleanWrapper tabMode = new ReadOnlyBooleanWrapper();
private final SimpleStringProperty title = new SimpleStringProperty();
private final String type;
public FxDockPane(String type)
{
this.type = type;
FX.style(this, FxDockStyles.FX_DOCK_PANE);
titleField = new Label();
FX.style(titleField, FxDockStyles.TOOLBAR_TITLE);
titleField.textProperty().bindBidirectional(titleProperty());
DragAndDropHandler.attach(titleField, this);
parent.addListener((s,old,cur) -> setTabMode(cur instanceof FxDockTabPane));
}
public final String getDockPaneType()
{
return type;
}
protected final void setTabMode(boolean on)
{
tabMode.set(on);
Node tb = createToolBar(on);
setTop(tb);
}
public final boolean isTabMode()
{
return tabModeProperty().get();
}
public final boolean isPaneMode()
{
return !tabModeProperty().get();
}
public final ReadOnlyBooleanProperty tabModeProperty()
{
return tabMode.getReadOnlyProperty();
}
/** override to create your own toolbar, possibly with custom icons and buttons */
protected Node createToolBar(boolean tabMode)
{
if(tabMode)
{
return null;
}
else
{
Button b = new Button("x");
FX.style(b, FxDockStyles.TOOLBAR_CLOSE_BUTTON);
closeAction.attach(b);
ToolBar t = new ToolBar();
FX.style(t, FxDockStyles.TOOLBAR);
t.getItems().addAll(titleField, b);
return t;
}
}
public final void setTitle(String s)
{
titleProperty().set(s);
}
public final String getTitle()
{
return titleProperty().get();
}
public final SimpleStringProperty titleProperty()
{
return title;
}
/**
* while FxDockPane extends BorderPane, it's better to insert a custom content using this method only,
* because the top is used by the toolbar.
*/
public void setContent(Node n)
{
setCenter(n);
}
public void actionClose()
{
DockTools.remove(this);
}
public void actionPopToWindow()
{
DockTools.moveToNewWindow(this);
}
}