public DraggableComponentBox(int iconSize, boolean useDefaultScrollButtons) { this.iconSize = iconSize; this.useDefaultScrollButtons = useDefaultScrollButtons; // Fix minimum size when flipping direction final DirectionLayout layout = new DirectionLayout( componentDirection == Direction.UP ? Direction.RIGHT : componentDirection == Direction.LEFT ? Direction.DOWN : componentDirection == Direction.DOWN ? Direction.RIGHT : Direction.DOWN) { public Dimension minimumLayoutSize(Container parent) { Dimension min = super.minimumLayoutSize(parent); Dimension pref = super.preferredLayoutSize(parent); return componentDirection.isHorizontal() ? new Dimension(pref.width, min.height) : new Dimension(min.width, pref.height); } public void layoutContainer(Container parent) { if (DraggableComponentBox.this != null && componentBoxEnabled) { // long millis = System.currentTimeMillis(); doSort(); super.layoutContainer(parent); // System.out.println("Layout: " + (System.currentTimeMillis() - millis)); } } public Dimension preferredLayoutSize(Container parent) { doSort(); return super.preferredLayoutSize(parent); } }; layout.setLayoutOrderList(layoutOrderList); componentBox = new SimplePanel(layout) { public boolean isOptimizedDrawingEnabled() { return DraggableComponentBox.this != null && getComponentSpacing() >= 0; } }; componentBox.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent e) { // fireChangedEvent(); } public void componentMoved(ComponentEvent e) { fireChangedEvent(); } }); initialize(); }
private void initialize() { if (componentContainer != null) remove(componentContainer); DirectionLayout layout = getDirectionLayout(); layout.setCompressing(!scrollEnabled); if (scrollEnabled) { if (useDefaultScrollButtons) scrollButtonBox = new ScrollButtonBox(componentDirection.isHorizontal(), iconSize); else scrollButtonBox = new ScrollButtonBox(componentDirection.isHorizontal(), null, null, null, null); final ScrollableBox scrollableBox = new ScrollableBox(componentBox, componentDirection.isHorizontal(), scrollOffset); scrollableBox.setLayoutOrderList(layoutOrderList); scrollButtonBox.addListener( new ScrollButtonBoxListener() { public void scrollButton1() { scrollableBox.scrollLeft(1); } public void scrollButton2() { scrollableBox.scrollRight(1); } }); scrollableBox.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent e) { scrollButtonBox.setButton1Enabled(!scrollableBox.isLeftEnd()); scrollButtonBox.setButton2Enabled(!scrollableBox.isRightEnd()); } }); scrollButtonBox.setButton1Enabled(!scrollableBox.isLeftEnd()); scrollButtonBox.setButton2Enabled(!scrollableBox.isRightEnd()); scrollableBox.addScrollableBoxListener( new ScrollableBoxListener() { public void scrolledLeft(ScrollableBox box) { scrollButtonBox.setButton1Enabled(!box.isLeftEnd()); scrollButtonBox.setButton2Enabled(true); } public void scrolledRight(ScrollableBox box) { scrollButtonBox.setButton1Enabled(true); scrollButtonBox.setButton2Enabled(!box.isRightEnd()); } public void changed(ScrollableBox box) { fireChangedEvent(); } }); componentContainer = scrollableBox; } else { scrollButtonBox = null; componentContainer = componentBox; } componentContainer.setAlignmentY(0); add(componentContainer, BorderLayout.CENTER); revalidate(); }