Good work Kirill! I studied the JFlexiSlider example and benifit from your nice work :-). The tasks fulfilled by FlexiSliderLayout (preferredLayoutSize(..), layoutContainer(..)) are just as you said, they are "fairly straightforward". I think using an layout manager existed (such as GridBagLayoutManager) could simplify these tasks.
A simple test made, using GridBagLayoutManager, and it works fine. When installing UI delegate of the component, set the component layout manager to GridBagLayoutManager (or any other layout managers you preferred), adding sub-components of the component just as the normal usage of the GridBagLayoutManager to layout them. Codes are listed below.
private void installComponents() {
slider = new JSlider();
label1 = new JLabel();
label2 = new JLabel();
label4 = new JLabel();
label5 = new JLabel();
flexiSlider.setLayout(new GridBagLayout());
((GridBagLayout)flexiSlider.getLayout()).columnWidths = new int[] {0, 0, 0};
((GridBagLayout)flexiSlider.getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0};
((GridBagLayout)flexiSlider.getLayout()).columnWeights = new double[] {0.0, 1.0, 1.0E-4};
((GridBagLayout)flexiSlider.getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 1.0E-4};
slider.setOrientation(JSlider.VERTICAL);
flexiSlider.add(slider, new GridBagConstraints(0, 0, 1, 4, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 5), 0, 0));
label1.setText("%%1%%");
flexiSlider.add(label1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.1,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 5, 0), 0, 0));
label2.setText("%%2%%");
flexiSlider.add(label2, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.2,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 0), 0, 0));
label4.setText("%%3%%");
flexiSlider.add(label4, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.3,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 5, 0), 0, 0));
label5.setText("%%4%%");
flexiSlider.add(label5, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.4,
GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL,
new Insets(0, 0, 0, 0), 0, 0));
}
Cheers,
Yi Bing |