Пример #1
0
  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());
  }
Пример #2
0
 @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()));
 }
Пример #3
0
 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);
 }
Пример #4
0
  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);
  }
Пример #5
0
 @Override
 public int getPreferredInnerHeight() {
   return BoxLayout.computePreferredHeightHorizontal(this);
 }
Пример #6
0
 @Override
 public int getPreferredInnerWidth() {
   return BoxLayout.computePreferredWidthVertical(this);
 }
Пример #7
0
 @Override
 public int getMinHeight() {
   return Math.max(
       super.getMinHeight(), getBorderVertical() + BoxLayout.computeMinHeightHorizontal(this));
 }
Пример #8
0
 private void rebuildCurrentFolderGroup() {
   curFolderGroup.removeAllChildren();
   recursiveAddFolder(currentFolder, null);
 }