Package org.pushingpixels.flamingo.api.common

Examples of org.pushingpixels.flamingo.api.common.AbstractCommandButton


      int height = c.getHeight() - ins.top - ins.bottom;
      int width = c.getWidth() - ins.left - ins.right;
      if (buttonStrip.getOrientation() == StripOrientation.HORIZONTAL) {
        int totalPreferredWidth = 0;
        for (int i = 0; i < buttonStrip.getButtonCount(); i++) {
          AbstractCommandButton currButton = buttonStrip.getButton(i);
          totalPreferredWidth += currButton.getPreferredSize().width;
        }
        int deltaX = (width - totalPreferredWidth)
            / buttonStrip.getButtonCount();
        if (buttonStrip.getComponentOrientation().isLeftToRight()) {
          int x = ins.left;
          for (int i = 0; i < buttonStrip.getButtonCount(); i++) {
            AbstractCommandButton currButton = buttonStrip
                .getButton(i);
            currButton.setBounds(x, ins.top, currButton
                .getPreferredSize().width
                + deltaX, height);
            x += (currButton.getPreferredSize().width + deltaX);
          }
        } else {
          int x = c.getWidth() - ins.right;
          for (int i = 0; i < buttonStrip.getButtonCount(); i++) {
            AbstractCommandButton currButton = buttonStrip
                .getButton(i);
            int buttonWidth = currButton.getPreferredSize().width
                + deltaX;
            currButton.setBounds(x - buttonWidth, ins.top,
                buttonWidth, height);
            x -= buttonWidth;
          }
        }
      } else {
        int totalPreferredHeight = 0;
        for (int i = 0; i < buttonStrip.getButtonCount(); i++) {
          AbstractCommandButton currButton = buttonStrip.getButton(i);
          totalPreferredHeight += currButton.getPreferredSize().height;
        }
        float deltaY = (float) (height - totalPreferredHeight)
            / (float) buttonStrip.getButtonCount();
        float y = ins.top;
        for (int i = 0; i < buttonStrip.getButtonCount(); i++) {
          AbstractCommandButton currButton = buttonStrip.getButton(i);
          float buttonHeight = (currButton.getPreferredSize().height + deltaY);
          currButton.setBounds(ins.left, (int) y, width, (int) Math
              .ceil(buttonHeight));
          y += buttonHeight;
        }
      }
    }
View Full Code Here


  private void scan(Container cont) {
    for (int i = 0; i < cont.getComponentCount(); i++) {
      Component comp = cont.getComponent(i);
      if (comp instanceof AbstractCommandButton) {
        AbstractCommandButton acb = (AbstractCommandButton) comp;
        acb.setText(resourceBundle.getString("Click.text"));
        acb.addActionListener(new CounterActionListener());
      }
      if (comp instanceof Container) {
        scan((Container) comp);
      }
    }
View Full Code Here

    public void actionPerformed(final ActionEvent e) {
      SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
          count++;
          AbstractCommandButton acb = (AbstractCommandButton) e
              .getSource();
          MessageFormat mf = new MessageFormat(resourceBundle
              .getString("Clicked.text"));
          mf.setLocale(currLocale);
          acb.setText(mf.format(new Object[] { count }));
          // System.out.println(acb.getText());
        }
      });
    }
View Full Code Here

    });
  }

  @Test
  public void testDefaultActionListeners() {
    AbstractCommandButton expandButton1 = GuiActionRunner
        .execute(new GuiQuery<AbstractCommandButton>() {
          @Override
          protected AbstractCommandButton executeInEDT()
              throws Throwable {
            return ((BasicRibbonBandUI) ribbonBand1.getUI())
                .getExpandButton();
          }
        });
    robot().waitForIdle();

    Assertions.assertThat(expandButton1).isNull();

    AbstractCommandButton expandButton2 = GuiActionRunner
        .execute(new GuiQuery<AbstractCommandButton>() {
          @Override
          protected AbstractCommandButton executeInEDT()
              throws Throwable {
            return ((BasicRibbonBandUI) ribbonBand2.getUI())
View Full Code Here

    Assertions.assertThat(count2).isZero();
  }

  @Test
  public void testSwitchFromNoListener() {
    AbstractCommandButton expandButton1 = GuiActionRunner
        .execute(new GuiQuery<AbstractCommandButton>() {
          @Override
          protected AbstractCommandButton executeInEDT()
              throws Throwable {
            return ((BasicRibbonBandUI) ribbonBand1.getUI())
View Full Code Here

    Assertions.assertThat(count2).isZero();
  }

  @Test
  public void testSwitchToNoListener() {
    AbstractCommandButton expandButton2 = GuiActionRunner
        .execute(new GuiQuery<AbstractCommandButton>() {
          @Override
          protected AbstractCommandButton executeInEDT()
              throws Throwable {
            return ((BasicRibbonBandUI) ribbonBand2.getUI())
View Full Code Here

    Assertions.assertThat(expandButton2).isNull();
  }

  @Test
  public void testSwitchToAnotherListener() {
    AbstractCommandButton expandButton2 = GuiActionRunner
        .execute(new GuiQuery<AbstractCommandButton>() {
          @Override
          protected AbstractCommandButton executeInEDT()
              throws Throwable {
            return ((BasicRibbonBandUI) ribbonBand2.getUI())
View Full Code Here

         
          if(action != null) {
            if(mandatory) {
              action.putValue(MANDATORY_PROPERTY, mandatory);
            }
            AbstractCommandButton button;
            if(isSelectionListener(action)) {
              button = createCommandToggleButton(action);
              if (context.hasChildren(context.getCurrentPath())) {
                LogUtils.severe("RibbonActionContributorFactory.getContributor(): can't add popup menu to toggle button for action: "+context.getCurrentPath().toString());
              }
            }
            else {
              button = createCommandButton(action);
              if(context.hasChildren(context.getCurrentPath())) {
                StructurePath path = context.getCurrentPath();
                ((JCommandButton)button).setPopupCallback(getPopupPanelCallBack(path, context));
                ((JCommandButton)button).setCommandButtonKind(CommandButtonKind.ACTION_AND_POPUP_MAIN_ACTION);
                KeyStroke ks = context.getBuilder().getAcceleratorManager().getAccelerator(actionKey);
                updateRichTooltip(button, action, ks);
                updateActionState(action, button);
              }
            }
            button.putClientProperty(ACTION_KEY_PROPERTY, action);
           
            KeyStroke ks = context.getBuilder().getAcceleratorManager().getAccelerator(actionKey);
            if(ks != null) {
              button.putClientProperty(ACTION_ACCELERATOR, ks);
              updateRichTooltip(button, action, ks);
            }
            getAccelChangeListener().addAction(actionKey, button);
           
            builder.getMapChangeAdapter().addListener(new ActionChangeListener(action, button))
            parent.addChild(button, childProps);
          }
        }
        else {
          final String name = attributes.getProperty("name");
          if(name != null) {
            AFreeplaneAction action = ActionUtils.getDummyAction(name);
            final JCommandButton button = new JCommandButton(ActionUtils.getActionTitle(action), ActionUtils.getActionIcon(action));
            button.putClientProperty(ACTION_NAME_PROPERTY, action);
            updateRichTooltip(button, action, null);
            if(context.hasChildren(context.getCurrentPath())) {
              StructurePath path = context.getCurrentPath();
              button.setPopupCallback(getPopupPanelCallBack(path, context));
              button.setCommandButtonKind(CommandButtonKind.POPUP_ONLY);
            }
            button.setFocusable(false);
            parent.addChild(button, childProps);
          }
        }
      }
     
      private PopupPanelCallback getPopupPanelCallBack(StructurePath path, final RibbonBuildContext context) {
        childButtons.clear();
        context.processChildren(path, this);
        return new PopupPanelCallback() {
         
          public JPopupPanel getPopupPanel(JCommandButton commandButton) {
            JCommandPopupMenu popupmenu = new JCommandPopupMenu();
            for (Component comp : childButtons) {
              if(comp instanceof JSeparator) {
                popupmenu.addMenuSeparator();
              }
              else if(comp instanceof AbstractCommandButton) {
                AbstractCommandButton button = (AbstractCommandButton) comp;
               
                AbstractCommandButton menuButton = null;               
                AFreeplaneAction action = (AFreeplaneAction)button.getClientProperty(ACTION_KEY_PROPERTY);
                if(action != null) {
                  if(isSelectionListener(action)) {
                    menuButton = createCommandToggleMenuButton(action);
                    popupmenu.addMenuButton((JCommandToggleMenuButton) menuButton);
                  }
                  else {
                    menuButton = createCommandMenuButton(action);
                    popupmenu.addMenuButton((JCommandMenuButton) menuButton);
                  }
                  menuButton.setEnabled(button.isEnabled());
                  menuButton.putClientProperty(ACTION_KEY_PROPERTY, action);
                  KeyStroke ks = context.getBuilder().getAcceleratorManager().getAccelerator(action.getKey());
                  updateRichTooltip(menuButton, action, ks);
                  updateActionState(action, menuButton);
                }
                else {
                  action = (AFreeplaneAction)button.getClientProperty(ACTION_NAME_PROPERTY);
                  menuButton = createCommandMenuButton(action);
                  if(action != null) {
                    menuButton.putClientProperty(ACTION_NAME_PROPERTY, action);
                    updateRichTooltip(menuButton, action, null);
                  }
                }
               
                if(button instanceof JCommandButton) {
                  if(((JCommandButton) button).getPopupCallback() != null) {
                    ((JCommandMenuButton)menuButton).setPopupCallback(((JCommandButton) button).getPopupCallback());
                    ((JCommandMenuButton)menuButton).setCommandButtonKind(((JCommandButton) button).getCommandButtonKind());                   
                  }
                }
                //clear all RibbonActionListeners from the menuButton
                for (ActionListener listener : menuButton.getListeners(ActionListener.class)) {
                  if(listener instanceof RibbonActionListener) {
                    menuButton.removeActionListener(listener);
                  }
                }
                //add
                for (ActionListener listener : button.getListeners(ActionListener.class)) {
                  if(listener instanceof RibbonActionListener) {
                    menuButton.addActionListener(listener);
                  }
                }
               
              }
            }
View Full Code Here

    public void acceleratorChanged(JMenuItem action, KeyStroke oldStroke, KeyStroke newStroke) {
     
    }
   
    public void acceleratorChanged(AFreeplaneAction action, KeyStroke oldStroke, KeyStroke newStroke) {
      AbstractCommandButton button = actionMap.get(action.getKey());
      if(button != null) {
        updateRichTooltip(button, action, newStroke);
      }

    }
View Full Code Here

      int height = c.getHeight() - ins.top - ins.bottom;
      int width = c.getWidth() - ins.left - ins.right;
      if (buttonStrip.getOrientation() == StripOrientation.HORIZONTAL) {
        int totalPreferredWidth = 0;
        for (int i = 0; i < buttonStrip.getButtonCount(); i++) {
          AbstractCommandButton currButton = buttonStrip.getButton(i);
          totalPreferredWidth += currButton.getPreferredSize().width;
        }
        int deltaX = (width - totalPreferredWidth)
            / buttonStrip.getButtonCount();
        if (buttonStrip.getComponentOrientation().isLeftToRight()) {
          int x = ins.left;
          for (int i = 0; i < buttonStrip.getButtonCount(); i++) {
            AbstractCommandButton currButton = buttonStrip
                .getButton(i);
            currButton.setBounds(x, ins.top, currButton
                .getPreferredSize().width
                + deltaX, height);
            x += (currButton.getPreferredSize().width + deltaX);
          }
        } else {
          int x = c.getWidth() - ins.right;
          for (int i = 0; i < buttonStrip.getButtonCount(); i++) {
            AbstractCommandButton currButton = buttonStrip
                .getButton(i);
            int buttonWidth = currButton.getPreferredSize().width
                + deltaX;
            currButton.setBounds(x - buttonWidth, ins.top,
                buttonWidth, height);
            x -= buttonWidth;
          }
        }
      } else {
        int totalPreferredHeight = 0;
        for (int i = 0; i < buttonStrip.getButtonCount(); i++) {
          AbstractCommandButton currButton = buttonStrip.getButton(i);
          totalPreferredHeight += currButton.getPreferredSize().height;
        }
        float deltaY = (float) (height - totalPreferredHeight)
            / (float) buttonStrip.getButtonCount();
        float y = ins.top;
        for (int i = 0; i < buttonStrip.getButtonCount(); i++) {
          AbstractCommandButton currButton = buttonStrip.getButton(i);
          float buttonHeight = (currButton.getPreferredSize().height + deltaY);
          currButton.setBounds(ins.left, (int) y, width, (int) Math
              .ceil(buttonHeight));
          y += buttonHeight;
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.pushingpixels.flamingo.api.common.AbstractCommandButton

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.