public void testLayout() throws Exception { SwingMetawidget metawidget = new SwingMetawidget(); JComponent container = new JPanel(); // startLayout BoxLayout boxLayout = new BoxLayout(); boxLayout.startContainerLayout(container, metawidget); assertTrue(container.getLayout() instanceof javax.swing.BoxLayout); assertFalse((metawidget.getLayout() instanceof javax.swing.BoxLayout)); // layoutWidget assertEquals(0, container.getComponentCount()); Stub stub = new Stub(); boxLayout.layoutWidget(stub, PROPERTY, null, container, metawidget); assertEquals(0, container.getComponentCount()); stub.add(new JSpinner()); boxLayout.layoutWidget(stub, PROPERTY, null, container, metawidget); assertEquals(stub, container.getComponent(0)); assertEquals(1, container.getComponentCount()); boxLayout.layoutWidget(new JTextField(), PROPERTY, null, container, metawidget); assertTrue(container.getComponent(1) instanceof JTextField); assertEquals(2, container.getComponentCount()); }
@Override protected void layout() { curFolderGroup.setPosition(getInnerX(), getInnerY()); curFolderGroup.setSize(getInnerWidth(), curFolderGroup.getHeight()); listbox.setPosition(getInnerX(), curFolderGroup.getBottom()); listbox.setSize(getInnerWidth(), Math.max(0, getInnerBottom() - listbox.getY())); }
private void recursiveAddFolder(final Object folder, final Object subFolder) { if (folder != null) { recursiveAddFolder(fsm.getParent(folder), folder); } if (curFolderGroup.getNumChildren() > 0) { Label l = new Label(fsm.getSeparator()); l.setTheme("pathseparator"); curFolderGroup.add(l); } String name = getFolderName(folder); if (name.endsWith(fsm.getSeparator())) { name = name.substring(0, name.length() - 1); } Button btn = new Button(name); btn.addCallback( new Runnable() { public void run() { if (setCurrentFolder(folder)) { selectFolder(subFolder); } listbox.requestKeyboardFocus(); } }); btn.setTheme("pathbutton"); curFolderGroup.add(btn); }
public FolderBrowser(FileSystemModel fsm) { if (fsm == null) { throw new NullPointerException("fsm"); } this.fsm = fsm; this.model = new FolderModel(); this.listbox = new ListBox<Object>(model); this.curFolderGroup = new BoxLayout(); curFolderGroup.setTheme("currentpathbox"); curFolderGroup.setScroll(true); curFolderGroup.setClip(true); curFolderGroup.setAlignment(Alignment.BOTTOM); listbox.addCallback( new CallbackWithReason<ListBox.CallbackReason>() { private Object lastSelection; public void callback(ListBox.CallbackReason reason) { if (listbox.getSelected() != ListBox.NO_SELECTION) { if (reason.actionRequested()) { setCurrentFolder(model.getFolder(listbox.getSelected())); } } Object selection = getSelectedFolder(); if (selection != lastSelection) { lastSelection = selection; fireSelectionChangedCallback(); } } }); add(listbox); add(curFolderGroup); setCurrentFolder(null); }
@Override public int getPreferredInnerHeight() { return BoxLayout.computePreferredHeightHorizontal(this); }
@Override public int getPreferredInnerWidth() { return BoxLayout.computePreferredWidthVertical(this); }
@Override public int getMinHeight() { return Math.max( super.getMinHeight(), getBorderVertical() + BoxLayout.computeMinHeightHorizontal(this)); }
private void rebuildCurrentFolderGroup() { curFolderGroup.removeAllChildren(); recursiveAddFolder(currentFolder, null); }