28 |
import java.awt.GridBagConstraints; |
import java.awt.GridBagConstraints; |
29 |
import java.awt.GridBagLayout; |
import java.awt.GridBagLayout; |
30 |
import java.awt.Insets; |
import java.awt.Insets; |
31 |
|
import java.awt.Rectangle; |
32 |
|
|
33 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
34 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
35 |
|
import java.awt.event.HierarchyEvent; |
36 |
|
import java.awt.event.HierarchyListener; |
37 |
import java.awt.event.MouseAdapter; |
import java.awt.event.MouseAdapter; |
38 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
39 |
|
|
40 |
|
import javax.swing.BorderFactory; |
41 |
import javax.swing.Box; |
import javax.swing.Box; |
42 |
import javax.swing.BoxLayout; |
import javax.swing.BoxLayout; |
43 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
44 |
|
import javax.swing.JScrollPane; |
45 |
|
|
46 |
import org.jsampler.CC; |
import org.jsampler.CC; |
47 |
|
|
48 |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
import static org.jsampler.view.fantasia.FantasiaI18n.i18n; |
49 |
|
import static org.jvnet.substance.SubstanceLookAndFeel.SCROLL_PANE_BUTTONS_POLICY; |
50 |
|
import static org.jvnet.substance.utils.SubstanceConstants.ScrollPaneButtonPolicyKind; |
51 |
|
|
52 |
|
|
53 |
/** |
/** |
56 |
*/ |
*/ |
57 |
public class MainPane extends JPanel { |
public class MainPane extends JPanel { |
58 |
private final ChannelsBar channelsBar = new ChannelsBar(); |
private final ChannelsBar channelsBar = new ChannelsBar(); |
59 |
private final ChannelsPane channelsPane = new ChannelsPane(""); |
private final ChannelsPane channelsPane; |
60 |
|
|
61 |
|
final JScrollPane scrollPane; |
62 |
|
|
63 |
/** Creates a new instance of <code>MainPane</code> */ |
/** Creates a new instance of <code>MainPane</code> */ |
64 |
public MainPane() { |
public MainPane() { |
65 |
|
channelsPane = new ChannelsPane("", new ActionListener() { |
66 |
|
public void |
67 |
|
actionPerformed(ActionEvent e) { scrollToBottom(); } |
68 |
|
}); |
69 |
|
|
70 |
GridBagLayout gridbag = new GridBagLayout(); |
GridBagLayout gridbag = new GridBagLayout(); |
71 |
GridBagConstraints c = new GridBagConstraints(); |
GridBagConstraints c = new GridBagConstraints(); |
72 |
|
|
73 |
setLayout(gridbag); |
setLayout(gridbag); |
74 |
|
|
75 |
|
JPanel p = new JPanel(); |
76 |
|
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); |
77 |
|
p.add(channelsBar); |
78 |
|
p.add(Box.createGlue()); |
79 |
|
|
80 |
c.gridx = 0; |
c.gridx = 0; |
81 |
c.gridy = 0; |
c.gridy = 0; |
82 |
c.weightx = 1.0; |
c.weightx = 1.0; |
83 |
c.insets = new Insets(0, 0, 7, 0); |
c.insets = new Insets(0, 0, 0, 0); |
84 |
c.fill = GridBagConstraints.HORIZONTAL; |
c.fill = GridBagConstraints.HORIZONTAL; |
85 |
gridbag.setConstraints(channelsBar, c); |
gridbag.setConstraints(p, c); |
86 |
add(channelsBar); |
add(p); |
87 |
|
|
88 |
|
p = createChannelsPane(); |
89 |
|
p.setAlignmentX(LEFT_ALIGNMENT); |
90 |
|
|
91 |
JPanel p = createChannelsPane(); |
scrollPane = new JScrollPane(p); |
92 |
|
JScrollPane sp = scrollPane; |
93 |
|
sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
94 |
|
//sp.putClientProperty(SCROLL_PANE_BUTTONS_POLICY, ScrollPaneButtonPolicyKind.NONE); |
95 |
|
sp.setBorder(BorderFactory.createEmptyBorder()); |
96 |
|
sp.setOpaque(false); |
97 |
|
javax.swing.JViewport wp = sp.getViewport(); |
98 |
|
wp.setMinimumSize(new Dimension(420, wp.getMinimumSize().height)); |
99 |
|
wp.setOpaque(false); |
100 |
|
sp.setMaximumSize(new Dimension(sp.getMaximumSize().width, Short.MAX_VALUE)); |
101 |
|
sp.getVerticalScrollBar().setBorder(BorderFactory.createEmptyBorder(7, 4, 0, 1)); |
102 |
|
//sp.getVerticalScrollBar().setUnitIncrement(12); |
103 |
|
sp.setPreferredSize(new Dimension(420, sp.getPreferredSize().height)); |
104 |
|
|
105 |
|
sp.getVerticalScrollBar().addHierarchyListener(new HierarchyListener() { |
106 |
|
public void |
107 |
|
hierarchyChanged(HierarchyEvent e) { |
108 |
|
if((e.getChangeFlags() & e.SHOWING_CHANGED) != e.SHOWING_CHANGED) { |
109 |
|
return; |
110 |
|
} |
111 |
|
|
112 |
|
onScrollBarVisibilityChanged(); |
113 |
|
} |
114 |
|
}); |
115 |
|
|
116 |
c.gridx = 0; |
c.gridx = 0; |
117 |
c.gridy = 2; |
c.gridy = 2; |
119 |
c.weighty = 1.0; |
c.weighty = 1.0; |
120 |
c.insets = new Insets(0, 0, 0, 0); |
c.insets = new Insets(0, 0, 0, 0); |
121 |
c.fill = GridBagConstraints.BOTH; |
c.fill = GridBagConstraints.BOTH; |
122 |
gridbag.setConstraints(p, c); |
gridbag.setConstraints(sp, c); |
123 |
add(p); |
add(sp); |
124 |
|
|
125 |
p = new JPanel(); |
//setMaximumSize(new Dimension(420, Short.MAX_VALUE)); |
|
p.setOpaque(false); |
|
|
|
|
|
c.gridx = 0; |
|
|
c.gridy = 3; |
|
|
gridbag.setConstraints(p, c); |
|
|
add(p); |
|
|
|
|
|
setMaximumSize(new Dimension(420, Short.MAX_VALUE)); |
|
126 |
} |
} |
127 |
|
|
128 |
private JPanel |
private JPanel |
129 |
createChannelsPane() { |
createChannelsPane() { |
130 |
JPanel p = new JPanel(); |
JPanel p = new JPanel(); |
131 |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS)); |
132 |
|
channelsPane.setAlignmentX(LEFT_ALIGNMENT); |
133 |
p.add(channelsPane); |
p.add(channelsPane); |
134 |
p.add(new NewChannelPane()); |
JPanel p2 = new NewChannelPane(); |
135 |
|
p2.setAlignmentX(LEFT_ALIGNMENT); |
136 |
|
p.add(p2); |
137 |
p.add(Box.createGlue()); |
p.add(Box.createGlue()); |
138 |
p.setOpaque(false); |
p.setOpaque(false); |
139 |
|
p.setBorder(BorderFactory.createEmptyBorder(7, 0, 0, 0)); |
140 |
|
p.setMinimumSize(new Dimension(420, p.getMinimumSize().height)); |
141 |
return p; |
return p; |
142 |
} |
} |
143 |
|
|
144 |
|
private void |
145 |
|
onScrollBarVisibilityChanged() { |
146 |
|
int h = scrollPane.getPreferredSize().height; |
147 |
|
int scrollbarWidth = scrollPane.getVerticalScrollBar().getPreferredSize().width; |
148 |
|
|
149 |
|
if(scrollPane.getVerticalScrollBar().isVisible()) { |
150 |
|
scrollPane.setPreferredSize(new Dimension(420 + scrollbarWidth, h)); |
151 |
|
} else { |
152 |
|
scrollPane.setPreferredSize(new Dimension(420, h)); |
153 |
|
} |
154 |
|
|
155 |
|
revalidate(); |
156 |
|
} |
157 |
|
|
158 |
|
public void |
159 |
|
scrollToBottom() { |
160 |
|
int h = scrollPane.getViewport().getView().getHeight(); |
161 |
|
scrollPane.getViewport().scrollRectToVisible(new Rectangle(0, h - 2, 1, 1)); |
162 |
|
} |
163 |
|
|
164 |
public ChannelsPane |
public ChannelsPane |
165 |
getChannelsPane() { return channelsPane; } |
getChannelsPane() { return channelsPane; } |
166 |
|
|