Package org.pushingpixels.flamingo.api.ribbon

Examples of org.pushingpixels.flamingo.api.ribbon.RibbonTask


    this.propertyChangeListener = new PropertyChangeListener() {
      @Override
      public void propertyChange(PropertyChangeEvent evt) {
        if ("selectedTask".equals(evt.getPropertyName())) {
          RibbonTask old = (RibbonTask) evt.getOldValue();
          final RibbonTask curr = (RibbonTask) evt.getNewValue();
          if ((old != null) && (taskToggleButtons.get(old) != null)) {
            taskToggleButtons.get(old).getActionModel()
                .setSelected(false);
          }
          if ((curr != null) && (taskToggleButtons.get(curr) != null)) {
View Full Code Here


    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setColor(FlamingoUtilities.getBorderColor());
    g2d.draw(outerContour);

    // check whether the currently selected task is a contextual task
    RibbonTask selected = this.ribbon.getSelectedTask();
    RibbonContextualTaskGroup contextualGroup = selected
        .getContextualGroup();
    if (contextualGroup != null) {
      // paint a small gradient directly below the task area
      Insets ins = this.ribbon.getInsets();
      int topY = ins.top + getTaskbarHeight();
View Full Code Here

    }

    // go over all visible ribbon tasks and create a toggle button
    // for each one of them
    List<RibbonTask> visibleTasks = this.getCurrentlyShownRibbonTasks();
    final RibbonTask selectedTask = this.ribbon.getSelectedTask();
    for (final RibbonTask task : visibleTasks) {
      final JRibbonTaskToggleButton taskToggleButton = new JRibbonTaskToggleButton(
          task);
      taskToggleButton.setKeyTip(task.getKeyTip());
      // wire listener to select the task when the button is
      // selected
      taskToggleButton.addActionListener(new ActionListener() {
        @Override
                public void actionPerformed(ActionEvent e) {
          SwingUtilities.invokeLater(new Runnable() {
            @Override
                        public void run() {
              scrollAndRevealTaskToggleButton(taskToggleButton);

              ribbon.setSelectedTask(task);

              // System.out.println("Button click on "
              // + task.getTitle() + ", ribbon minimized? "
              // + ribbon.isMinimized());

              if (ribbon.isMinimized()) {
                if (Boolean.TRUE.equals(ribbon
                    .getClientProperty(JUST_MINIMIZED))) {
                  ribbon.putClientProperty(JUST_MINIMIZED,
                      null);
                  return;
                }

                // special case - do we have this task currently
                // shown in a popup?
                List<PopupPanelManager.PopupInfo> popups = PopupPanelManager
                    .defaultManager().getShownPath();
                if (popups.size() > 0) {
                  for (PopupPanelManager.PopupInfo popup : popups) {
                    if (popup.getPopupOriginator() == taskToggleButton) {
                      // hide all popups and return (hides
                      // the task popup and does not
                      // show any additional popup).
                      PopupPanelManager.defaultManager()
                          .hidePopups(null);
                      return;
                    }
                  }
                }

                PopupPanelManager.defaultManager().hidePopups(
                    null);
                ribbon.remove(bandScrollablePanel);

                int prefHeight = bandScrollablePanel.getView()
                    .getPreferredSize().height;
                Insets ins = ribbon.getInsets();
                prefHeight += ins.top + ins.bottom;
                AbstractRibbonBand band = (ribbon
                    .getSelectedTask().getBandCount() > 0) ? ribbon
                    .getSelectedTask().getBand(0)
                    : null;
                if (band != null) {
                  Insets bandIns = band.getInsets();
                  prefHeight += bandIns.top + bandIns.bottom;
                }

                // System.out.println(prefHeight
                // + ":"
                // + bandScrollablePanel.getView()
                // .getComponentCount());

                JPopupPanel popupPanel = new BandHostPopupPanel(
                    bandScrollablePanel, new Dimension(
                        ribbon.getWidth(), prefHeight));

                int x = ribbon.getLocationOnScreen().x;
                int y = ribbon.getLocationOnScreen().y
                    + ribbon.getHeight();

                // make sure that the popup stays in
                // bounds
                Rectangle scrBounds = ribbon
                    .getGraphicsConfiguration().getBounds();
                int pw = popupPanel.getPreferredSize().width;
                if ((x + pw) > (scrBounds.x + scrBounds.width)) {
                  x = scrBounds.x + scrBounds.width - pw;
                }
                int ph = popupPanel.getPreferredSize().height;
                if ((y + ph) > (scrBounds.y + scrBounds.height)) {
                  y = scrBounds.y + scrBounds.height - ph;
                }

                // get the popup and show it
                popupPanel.setPreferredSize(new Dimension(
                    ribbon.getWidth(), prefHeight));
                Popup popup = PopupFactory.getSharedInstance()
                    .getPopup(taskToggleButton, popupPanel,
                        x, y);
                PopupPanelManager.PopupListener tracker = new PopupPanelManager.PopupListener() {
                  @Override
                  public void popupShown(PopupEvent event) {
                    JComponent originator = event
                        .getPopupOriginator();
                    if (originator instanceof JRibbonTaskToggleButton) {
                      bandScrollablePanel.doLayout();
                      bandScrollablePanel.repaint();
                    }
                  }

                  @Override
                  public void popupHidden(PopupEvent event) {
                    JComponent originator = event
                        .getPopupOriginator();
                    if (originator instanceof JRibbonTaskToggleButton) {
                      ribbon.add(bandScrollablePanel);
                      PopupPanelManager.defaultManager()
                          .removePopupListener(this);
                      ribbon.revalidate();
                      ribbon.doLayout();
                      ribbon.repaint();
                    }
                  }
                };
                PopupPanelManager.defaultManager()
                    .addPopupListener(tracker);
                PopupPanelManager.defaultManager().addPopup(
                    taskToggleButton, popup, popupPanel);
              }
            }
          });
        }
      });
      // wire listener to toggle ribbon minimization on double
      // mouse click
      taskToggleButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
          if ((ribbon.getSelectedTask() == task)
              && (e.getClickCount() == 2)) {
            boolean wasMinimized = ribbon.isMinimized();
            ribbon.setMinimized(!wasMinimized);
            if (!wasMinimized) {
              // fix for issue 69 - mark the ribbon as
              // "just minimized" to prevent the action handler
              // of the toggle button to show the ribbon in
              // popup mode
              ribbon.putClientProperty(JUST_MINIMIZED,
                  Boolean.TRUE);
            }
          }
        }
      });
      // set the background hue color on the tab buttons
      // of tasks in contextual groups
      if (task.getContextualGroup() != null) {
        taskToggleButton.setContextualGroupHueColor(task
            .getContextualGroup().getHueColor());
      }

      taskToggleButton.putClientProperty(
          BasicCommandButtonUI.DONT_DISPOSE_POPUPS, Boolean.TRUE);

      this.taskToggleButtonGroup.add(taskToggleButton);
      taskToggleButtonsHostPanel.add(taskToggleButton);
      this.taskToggleButtons.put(task, taskToggleButton);
    }

    JRibbonTaskToggleButton toSelect = this.taskToggleButtons
        .get(selectedTask);
    if (toSelect != null) {
      toSelect.getActionModel().setSelected(true);
    }

    for (int i = 0; i < this.ribbon.getTaskCount(); i++) {
      RibbonTask task = this.ribbon.getTask(i);
      for (AbstractRibbonBand band : task.getBands()) {
        bandHostPanel.add(band);
        band.setVisible(selectedTask == task);
      }
    }
    for (int i = 0; i < this.ribbon.getContextualTaskGroupCount(); i++) {
      RibbonContextualTaskGroup taskGroup = this.ribbon
          .getContextualTaskGroup(i);
      for (int j = 0; j < taskGroup.getTaskCount(); j++) {
        RibbonTask task = taskGroup.getTask(j);
        for (AbstractRibbonBand band : task.getBands()) {
          bandHostPanel.add(band);
          band.setVisible(selectedTask == task);
        }
      }
    }
View Full Code Here

  protected List<RibbonTask> getCurrentlyShownRibbonTasks() {
    List<RibbonTask> result = new ArrayList<RibbonTask>();

    // add all regular tasks
    for (int i = 0; i < this.ribbon.getTaskCount(); i++) {
      RibbonTask task = this.ribbon.getTask(i);
      result.add(task);
    }
    // add all tasks of visible contextual groups
    for (int i = 0; i < this.ribbon.getContextualTaskGroupCount(); i++) {
      RibbonContextualTaskGroup group = this.ribbon
          .getContextualTaskGroup(i);
      if (this.ribbon.isVisible(group)) {
        for (int j = 0; j < group.getTaskCount(); j++) {
          RibbonTask task = group.getTask(j);
          result.add(task);
        }
      }
    }
View Full Code Here

      Insets ins = c.getInsets();
      int maxPrefBandHeight = 0;
      boolean isRibbonMinimized = ribbon.isMinimized();
      if (!isRibbonMinimized) {
        if (ribbon.getTaskCount() > 0) {
          RibbonTask selectedTask = ribbon.getSelectedTask();
          for (AbstractRibbonBand<?> ribbonBand : selectedTask
              .getBands()) {
            int bandPrefHeight = ribbonBand.getPreferredSize().height;
            Insets bandInsets = ribbonBand.getInsets();
            maxPrefBandHeight = Math.max(maxPrefBandHeight,
                bandPrefHeight + bandInsets.top
View Full Code Here

        extraHeight += getTaskbarHeight();

      if (ribbon.getTaskCount() > 0) {
        boolean isRibbonMinimized = ribbon.isMinimized();
        // minimum is when all the tasks are collapsed
        RibbonTask selectedTask = ribbon.getSelectedTask();
        for (AbstractRibbonBand ribbonBand : selectedTask.getBands()) {
          int bandPrefHeight = ribbonBand.getMinimumSize().height;
          Insets bandInsets = ribbonBand.getInsets();
          RibbonBandUI bandUI = ribbonBand.getUI();
          width += bandUI.getPreferredCollapsedWidth();
          if (!isRibbonMinimized) {
            maxMinBandHeight = Math.max(maxMinBandHeight,
                bandPrefHeight + bandInsets.top
                    + bandInsets.bottom);
          }
        }
        // add inter-band gaps
        width += gap * (selectedTask.getBandCount() - 1);
      } else {
        // fix for issue 44 (empty ribbon)
        width = 50;
      }
      return new Dimension(width, maxMinBandHeight + extraHeight
View Full Code Here

    @Override
        public Dimension preferredLayoutSize(Container c) {
      // Insets ins = c.getInsets();
      int maxPrefBandHeight = 0;
      if (ribbon.getTaskCount() > 0) {
        RibbonTask selectedTask = ribbon.getSelectedTask();
        for (AbstractRibbonBand<?> ribbonBand : selectedTask.getBands()) {
          int bandPrefHeight = ribbonBand.getPreferredSize().height;
          Insets bandInsets = ribbonBand.getInsets();
          maxPrefBandHeight = Math
              .max(maxPrefBandHeight, bandPrefHeight
                  + bandInsets.top + bandInsets.bottom);
View Full Code Here

      int width = 0;
      int maxMinBandHeight = 0;
      int gap = getBandGap();

      // minimum is when all the tasks are collapsed
      RibbonTask selectedTask = ribbon.getSelectedTask();
      // System.out.println(selectedTask.getTitle() + " min width");
      for (AbstractRibbonBand ribbonBand : selectedTask.getBands()) {
        int bandPrefHeight = ribbonBand.getMinimumSize().height;
        Insets bandInsets = ribbonBand.getInsets();
        RibbonBandUI bandUI = ribbonBand.getUI();
        int preferredCollapsedWidth = bandUI
            .getPreferredCollapsedWidth()
            + bandInsets.left + bandInsets.right;
        width += preferredCollapsedWidth;
        // System.out.println("\t" + ribbonBand.getTitle() + ":" +
        // preferredCollapsedWidth);
        maxMinBandHeight = Math.max(maxMinBandHeight, bandPrefHeight
        // + bandInsets.top + bandInsets.bottom
            );
      }
      // add inter-band gaps
      width += gap * (selectedTask.getBandCount() + 1);
      // System.out.println("\t" + gap + "*" +
      // (selectedTask.getBandCount() + 1));

      // System.out.println(selectedTask.getTitle() + " min width:" +
      // width);
View Full Code Here

      // the top row - task bar components
      int x = 0;
      int y = 0;

      RibbonTask selectedTask = ribbon.getSelectedTask();
      if (selectedTask == null)
        return;

      // check that the resize policies are still consistent
      for (AbstractRibbonBand<?> band : selectedTask.getBands()) {
        FlamingoUtilities.checkResizePoliciesConsistency(band);
      }

      // start with the most "permissive" resize policy for each band
      for (AbstractRibbonBand<?> band : selectedTask.getBands()) {
        List<RibbonBandResizePolicy> policies = band
            .getResizePolicies();
        RibbonBandResizePolicy last = policies.get(0);
        band.setCurrentResizePolicy(last);
      }

      int availableBandHeight = c.getHeight();
      int availableWidth = c.getWidth();
      if (selectedTask.getBandCount() > 0) {
        RibbonBandResizeSequencingPolicy resizeSequencingPolicy = selectedTask
            .getResizeSequencingPolicy();
        resizeSequencingPolicy.reset();
        AbstractRibbonBand<?> currToTakeFrom = resizeSequencingPolicy
            .next();
        while (true) {
          // check whether all bands have the current resize
          // policy as their last (most restrictive) registered policy
          boolean noMore = true;
          for (AbstractRibbonBand<?> band : selectedTask.getBands()) {
            RibbonBandResizePolicy currentResizePolicy = band
                .getCurrentResizePolicy();
            List<RibbonBandResizePolicy> resizePolicies = band
                .getResizePolicies();
            if (currentResizePolicy != resizePolicies
                .get(resizePolicies.size() - 1)) {
              noMore = false;
              break;
            }
          }
          if (noMore)
            break;

          // get the current preferred width of the bands
          int totalWidth = 0;
          // System.out.println("Iteration");
          for (AbstractRibbonBand<?> ribbonBand : selectedTask
              .getBands()) {
            RibbonBandResizePolicy currentResizePolicy = ribbonBand
                .getCurrentResizePolicy();

            Insets ribbonBandInsets = ribbonBand.getInsets();
            AbstractBandControlPanel controlPanel = ribbonBand
                .getControlPanel();
            if (controlPanel == null) {
              controlPanel = ribbonBand.getPopupRibbonBand()
                  .getControlPanel();
            }
            Insets controlPanelInsets = controlPanel.getInsets();
            int controlPanelGap = controlPanel.getUI()
                .getLayoutGap();
            int ribbonBandHeight = availableBandHeight
                - ribbonBandInsets.top
                - ribbonBandInsets.bottom;
            int availableHeight = ribbonBandHeight
                - ribbonBand.getUI().getBandTitleHeight();
            if (controlPanel != null) {
              availableHeight = availableHeight
                  - controlPanelInsets.top
                  - controlPanelInsets.bottom;
            }
            int preferredWidth = currentResizePolicy
                .getPreferredWidth(availableHeight,
                    controlPanelGap)
                + ribbonBandInsets.left
                + ribbonBandInsets.right;
            totalWidth += preferredWidth + bandGap;
            // System.out.println("\t"
            // + ribbonBand.getTitle()
            // + ":"
            // + currentResizePolicy.getClass()
            // .getSimpleName() + ":" + preferredWidth
            // + " under " + availableHeight + " with "
            // + controlPanel.getComponentCount()
            // + " children");
          }
          // System.out.println("\t:Total:" + totalWidth + "("
          // + availableWidth + ")");
          // System.out.println("\n");
          if (totalWidth < availableWidth)
            break;

          // try to take from the currently rotating band
          List<RibbonBandResizePolicy> policies = currToTakeFrom
              .getResizePolicies();
          int currPolicyIndex = policies.indexOf(currToTakeFrom
              .getCurrentResizePolicy());
          if (currPolicyIndex == (policies.size() - 1)) {
            // nothing to take
          } else {
            currToTakeFrom.setCurrentResizePolicy(policies
                .get(currPolicyIndex + 1));
          }
          currToTakeFrom = resizeSequencingPolicy.next();
        }
      }

      boolean ltr = c.getComponentOrientation().isLeftToRight();
      x = ltr ? 1 : c.getWidth() - 1;
      // System.out.println("Will get [" + availableWidth + "]:");
      for (AbstractRibbonBand<?> ribbonBand : selectedTask.getBands()) {
        Insets ribbonBandInsets = ribbonBand.getInsets();
        RibbonBandResizePolicy currentResizePolicy = ribbonBand
            .getCurrentResizePolicy();
        AbstractBandControlPanel controlPanel = ribbonBand
            .getControlPanel();
View Full Code Here

  public Collection<RibbonTask> createRibbon(String name, CustomRibbonBandGenerator customBandsGenerator) throws MissingResourceException, ResourceFormatException, MissingListenerException {
    List<RibbonTask> ribbonTasks=new ArrayList<RibbonTask>();
    @SuppressWarnings("unchecked")
    List<String> taskNames = (List<String>)getStringList(name);
    for (String taskName : taskNames){
      RibbonTask task=createRibbonTask(taskName, customBandsGenerator);
      ribbonTasks.add(task);
    }
    return ribbonTasks;
  }
View Full Code Here

TOP

Related Classes of org.pushingpixels.flamingo.api.ribbon.RibbonTask

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.