Example #1
0
  /** Constructor */
  public MainTabBar() {
    super(new BorderLayout());

    scrollingTabContainer = new BContainer(new BorderLayout());
    add(scrollingTabContainer, BorderLayout.CENTER);

    tabContainer = new BContainer(GroupLayout.makeHoriz(GroupLayout.LEFT)); // buildTabContainer();
    // tabContainer.setStyleClass("main_title");
    // tabContainer.setPreferredSize(getDisplay().getWidth(), TAB_HEIGHT);

    // BScrollPane scrollPane = new BScrollPane(tabContainer, false, false);
    viewport = new BScrollPane.BViewport(tabContainer, false, true, -1);
    scrollingTabContainer.add(viewport, BorderLayout.CENTER);
    scrollingTabContainer.setPreferredSize(getDisplay().getWidth(), TAB_HEIGHT);
    scrollingTabContainer.setStyleClass("main_title");

    diagramLabel = new BLabel("");
    diagramLabel.setStyleClass("menu_background");
    add(diagramLabel, BorderLayout.SOUTH);
    diagramLabel.setPreferredSize(getDisplay().getWidth(), DESCRIPTION_HEIGHT);

    StaticsApplication.getApp()
        .addDiagramListener(
            new DiagramListener() {

              public void onDiagramCreated(Diagram diagram) {
                addTab(diagram);
              }

              public void onDiagramChanged(Diagram newDiagram) {
                activateTab(newDiagram);
              }
            });
  }
Example #2
0
  /** Adds scroll buttons to the tab bar */
  private void addScrollButtons() {
    scrollButtonsAdded = true;

    final BoundedRangeModel hModel = viewport.getHModel();
    ActionListener scrollListener =
        new ActionListener() {

          public void actionPerformed(ActionEvent event) {
            if (event.getAction().equals("scroll_left")) {
              // scroll left
              hModel.setValue(hModel.getValue() - hModel.getScrollIncrement() / 4);
            } else if (event.getAction().equals("scroll_right")) {
              // scroll right
              hModel.setValue(hModel.getValue() + hModel.getScrollIncrement() / 4);
            }
          }
        };

    final BButton left = new BButton("<", scrollListener, "scroll_left");
    scrollingTabContainer.add(left, BorderLayout.WEST);

    final BButton right = new BButton(">", scrollListener, "scroll_right");
    scrollingTabContainer.add(right, BorderLayout.EAST);

    hModel.addChangeListener(
        new ChangeListener() {

          public void stateChanged(ChangeEvent event) {
            left.setEnabled(hModel.getValue() > hModel.getMinimum());
            right.setEnabled(hModel.getValue() < hModel.getMaximum() - hModel.getExtent());
          }
        });
  }
Example #3
0
  /**
   * Adds a tab to diagram
   *
   * @param diagram
   */
  protected void addTab(Diagram diagram) {

    // do not add if tab already exists
    if (getTab(diagram) != null) {
      return;
    }

    // if the diagram key is null, and the exercise does not allow switching to the diagram type,
    // do not create a tab for this diagram.
    if (diagram.getKey() == null
        && !Exercise.getExercise().canSwitchToNullKeyDiagramType(diagram.getType())) {
      return;
    }

    // no existing tab was found, so add a new one.
    MainTab tab = new MainTab(diagram);
    tabContainer.add(tab);

    Dimension tabPreferredSize = tab.getPreferredSize(-1, -1);
    tab.setSize(tabPreferredSize.width, tabPreferredSize.height);
    tabs.add(tab);

    viewport.layout();
    BoundedRangeModel hModel = viewport.getHModel();

    // if there are more tabs than will fit in the viewport, add the buttons for scrolling.
    if (hModel.getRange() != hModel.getExtent() && !scrollButtonsAdded && hModel.getExtent() > 0) {
      addScrollButtons();
      viewport.layout();
    }
  }
 @Override
 public void render(Renderer renderer) {
   label.setSize(getWidth(), 12);
   label.setLocation(0, getHeight() - 14);
   bio.setSize(getWidth(), getHeight() - 14);
   bio.setLocation(0, 0);
   super.render(renderer);
 }
 @Override // from BComponent
 protected void wasRemoved() {
   super.wasRemoved();
   if (_wheelListener != null) {
     removeListener(_wheelListener);
     _wheelListener = null;
   }
 }
    @Override // from BComponent
    public void layout() {
      Insets insets = getInsets();
      int twidth = getWidth() - insets.getHorizontal();
      int theight = getHeight() - insets.getVertical();
      int gap = ((GroupLayout) getLayoutManager()).getGap();

      // first make sure all of our entries have been measured and
      // compute our total height and extent
      int totheight = 0;
      for (Entry<V, C> entry : _values) {
        if (entry.height < 0) {
          if (entry.component == null) {
            entry.component = createComponent(entry.value);
          }
          boolean remove = false;
          if (!entry.component.isAdded()) {
            add(entry.component);
            remove = true;
          }
          entry.height = entry.component.getPreferredSize(twidth, 0).height;
          if (remove) {
            remove(entry.component);
          }
        }
        totheight += entry.height;
      }
      if (_values.size() > 1) {
        totheight += (gap * _values.size() - 1);
      }
      int extent = Math.min(theight, totheight);

      // if our most recent value was added with _snap then we scroll to
      // the bottom on this layout and clear our snappy flag
      int value = _snap ? (totheight - extent) : _model.getValue();
      _snap = false;

      // if our extent or total height have changed, update the model
      // (because we're currently invalid, the resulting call to
      // invalidate() will have no effect)
      if (extent != _model.getExtent() || totheight != _model.getMaximum()) {
        _model.setRange(0, value, extent, totheight);
      }

      // now back up from the last component until we reach the first one
      // that's in view
      _offset = _model.getValue();
      int compIx = 0;
      for (int ii = 0; ii < _values.size(); ii++) {
        Entry<V, C> entry = _values.get(ii);
        if (_offset < entry.height) {
          compIx = ii;
          break;
        }
        _offset -= (entry.height + gap);

        // remove and clear out the components before our top component
        if (entry.component != null) {
          if (entry.component.isAdded()) {
            remove(entry.component);
          }
          entry.component = null;
        }
      }

      // compensate for the partially visible topmost component
      extent += _offset;

      // now add components until we use up our extent
      int topIx = compIx;
      while (compIx < _values.size() && extent > 0) {
        Entry<V, C> entry = _values.get(compIx);
        if (entry.component == null) {
          entry.component = createComponent(entry.value);
        }
        if (!entry.component.isAdded()) {
          add(compIx - topIx, entry.component);
        }
        extent -= (entry.height + gap);
        compIx++;
      }

      // lastly remove any components below the last visible component
      while (compIx < _values.size()) {
        Entry<V, C> entry = _values.get(compIx);
        if (entry.component != null) {
          if (entry.component.isAdded()) {
            remove(entry.component);
          }
          entry.component = null;
        }
        compIx++;
      }

      // now have the layout manager layout our added components
      super.layout();
    }
 @Override // documentation inherited
 protected void wasAdded() {
   super.wasAdded();
   addListener(_wheelListener = _model.createWheelListener());
 }