-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathEditorSplitPane.java
More file actions
95 lines (80 loc) · 3.15 KB
/
EditorSplitPane.java
File metadata and controls
95 lines (80 loc) · 3.15 KB
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
package nodebox.client;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
import javax.swing.plaf.basic.BasicSplitPaneUI;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
public class EditorSplitPane extends CustomSplitPane {
private static Image editorSplitterBackground, editorSplitterHandle;
private static int editorSplitterHandleWidth;
private static final int DIVIDER_SIZE = 15;
static {
try {
// The height of this image should be equal to DIVIDER_SIZE.
editorSplitterBackground = ImageIO.read(new File("res/editor-splitter-background.png"));
editorSplitterHandle = ImageIO.read(new File("res/editor-splitter-handle.png"));
editorSplitterHandleWidth = editorSplitterHandle.getWidth(null);
} catch (IOException e) {
e.printStackTrace();
}
}
private String positionString = "";
private boolean showMessages = false;
public EditorSplitPane(int orientation, Component c1, Component c2) {
super(orientation, c1, c2);
setDividerSize(DIVIDER_SIZE);
c2.setVisible(false);
setEnabled(false);
}
public void setLocation(int line, int column) {
positionString = String.format(Locale.US, "Line: %4d Column: %4d", line, column);
repaint();
}
public boolean isShowMessages() {
return showMessages;
}
public void setShowMessages(boolean showMessages) {
if (showMessages == this.showMessages)
return;
this.showMessages = showMessages;
if (showMessages) {
setEnabled(true);
setDividerLocation(0.6);
setResizeWeight(0.6);
getBottomComponent().setVisible(true);
} else {
setEnabled(false);
setDividerLocation(1.0);
setResizeWeight(1.0);
getBottomComponent().setVisible(false);
}
}
@Override
protected BasicSplitPaneUI createUI() {
return new EditorSplitPaneUI();
}
private class EditorSplitPaneUI extends BasicSplitPaneUI {
public BasicSplitPaneDivider createDefaultDivider() {
return new BasicSplitPaneDivider(EditorSplitPaneUI.this) {
@Override
public void paint(Graphics g) {
int width = getWidth();
//int height = getHeight();
//Rectangle r = g.getClipBounds();
if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
throw new AssertionError("Horizontal split is not implemented.");
g.drawImage(editorSplitterBackground, 0, 0, width, DIVIDER_SIZE, null);
if (isShowMessages()) {
g.drawImage(editorSplitterHandle, width - 3 - editorSplitterHandleWidth, 1, null);
}
g.setFont(Theme.SMALL_BOLD_FONT);
g.setColor(Theme.TEXT_NORMAL_COLOR);
SwingUtils.drawShadowText((Graphics2D) g, positionString, 5, 13);
}
};
}
}
}