Package javax.swing

Examples of javax.swing.Action


    return mSpaceAction;
  }

  private Action createAction(String name, String id, String description,
      Icon smallIcon, Icon bigIcon, int type, final ActionListener listener) {
    Action action = new AbstractAction() {
      public void actionPerformed(ActionEvent e) {
        listener.actionPerformed(new ActionEvent(this, e.getID(), e
            .getActionCommand()));
      }
    };
    action.putValue(Action.NAME, name);
    action.putValue(Action.SMALL_ICON, smallIcon);
    action.putValue(Plugin.BIG_ICON, bigIcon);
    action.putValue(Action.SHORT_DESCRIPTION, description);
    action.putValue(ToolBar.ACTION_TYPE_KEY, type);
    action.putValue(ToolBar.ACTION_ID_KEY, id);
    mAvailableActions.put(id, action);
    actionOrder.add(action);
    return action;
  }
View Full Code Here


        StringBuilder text = new StringBuilder();
        Icon icon = null;
        // Action[] actionArr = plugin.getContextMenuActions(exampleProgram);
        ActionMenu actionMenu = menuIf.getContextMenuActions(exampleProgram);
        if (actionMenu != null) {
          Action action = actionMenu.getAction();
          if (action != null) {
            text.append((String) action.getValue(Action.NAME));
            icon = (Icon) action.getValue(Action.SMALL_ICON);
            if (icon != null) {
              icon = new FixedSizeIcon(16, 16, icon);
            }
          } else if (menuIf instanceof PluginProxy) {
            text.append(((PluginProxy) menuIf).getInfo().getName());
View Full Code Here

    Transferable tr = e.getTransferable();
    DataFlavor[] flavors = tr.getTransferDataFlavors();
    try {
      String name = (String) tr.getTransferData(flavors[0]);
      int index = ((Integer) tr.getTransferData(flavors[1])).intValue();
      Action separator = DefaultToolBarModel.getInstance().getSeparatorAction();
      Action glue = DefaultToolBarModel.getInstance().getGlueAction();
      Action space = DefaultToolBarModel.getInstance().getSpaceAction();

      JComponent target = (JComponent) ((DropTarget) e.getSource())
          .getComponent();

      if (target.equals(mButtonPanel)) {
        if (index == -1 && !separator.getValue(Action.NAME).equals(name)
            && !glue.getValue(Action.NAME).equals(name)
            && !space.getValue(Action.NAME).equals(name)) {
          for (Action a : mCurrentActions) {
            if (a.getValue(Action.NAME).equals(name)) {
              mCurrentActions.removeElement(a);
              mAvailableActions.addElement(a);
              break;
            }
          }
        } else if (index != -1) {
          Action a = mCurrentActions.elementAt(index);
          mCurrentActions.removeElementAt(index);
          if (!separator.getValue(Action.NAME).equals(name)
              && !glue.getValue(Action.NAME).equals(name)
              && !space.getValue(Action.NAME).equals(name)
              ) {
            mAvailableActions.addElement(a);
          }
        }
        saveSettings();
      } else if (target.equals(MainFrame.getInstance().getToolbar())
          || ((DropTarget) e.getSource()).getComponent().equals(
              MainFrame.getInstance().getToolBarPanel())) {

        Point location = e.getLocation();

        if (mWest) {
          location.setLocation(10, location.y);
        } else {
          location.setLocation(location.x, MainFrame.getInstance().getToolbar()
              .getHeight() / 2);
        }

        JComponent c = (JComponent) MainFrame.getInstance().getToolbar()
            .getComponentAt(location);

        if ((c == null || c instanceof JToolBar) && MainFrame.getInstance().getToolbar().getComponentCount() > 0) {
          c = (JComponent) MainFrame.getInstance().getToolbar().getComponent(
              MainFrame.getInstance().getToolbar().getComponentCount() - 1);

          if (c != null) {
            location.setLocation(c.getLocation().x + c.getWidth() - 1, c
                .getLocation().y
                + c.getHeight() - 1);
          }
        }

        int n = 0;

        if (c != null) {
          Point p = SwingUtilities.convertPoint(MainFrame.getInstance().getToolBarPanel(), location, c);

          n = MainFrame.getInstance().getToolbar().getComponentIndex(c);

          if (!((mWest && (p.y < c.getHeight() / 2)) || (!mWest && (p.x < c
              .getWidth() / 2)))) {
            n++;
          }
        }

        if (index != -1) {
          Action a = mCurrentActions.remove(index);

          if (index < n) {
            n--;
          }

          if (n > MainFrame.getInstance().getToolbar().getComponentCount() - 1) {
            mCurrentActions.insertElementAt(a, n - 1);
          } else {
            mCurrentActions.insertElementAt(a, n);
          }
        } else {
          if(n < 0) {
            n = 0;
          }

          for (Action a : mAvailableActions) {
            if (a.getValue(Action.NAME).equals(name)) {
              if (!separator.getValue(Action.NAME).equals(name)
                  && !glue.getValue(Action.NAME).equals(name)
                  && !space.getValue(Action.NAME).equals(name)) {
                mAvailableActions.removeElement(a);
              }
View Full Code Here

    mCueLine.setRect(0,0,0,0);
  }

  public void dragGestureRecognized(DragGestureEvent e) {
    /* Start drag of an ActionButton */
    Action separator = DefaultToolBarModel.getInstance().getSeparatorAction();
    Action glue = DefaultToolBarModel.getInstance().getGlueAction();
    Action space = DefaultToolBarModel.getInstance().getSpaceAction();
    Action[] actions = DefaultToolBarModel.getInstance().getAvailableActions();

    JComponent c = (JComponent) e.getComponent();

    for (Action action : actions) {
      String text;
      if (c instanceof JToolBar.Separator) {
        text = (String) separator.getValue(Action.NAME);
      } else if(c instanceof JPanel) {
        text = (String) glue.getValue(Action.NAME);
      } else {
        if (((AbstractButton) c).getText() == null) {
          text = "notext";
        } else if (!((AbstractButton) c).getText().startsWith("<html>")) {
          text = ((AbstractButton) c).getText();
        } else {
          text = ((AbstractButton) c).getText().substring(37,
              ((AbstractButton) c).getText().length() - 13);
        }
      }
      if (action.getValue(Action.NAME).equals(text)
          || separator.getValue(Action.NAME).equals(text)
          || glue.getValue(Action.NAME).equals(text)
          || space.getValue(Action.NAME).equals(text)
          || text.equals("notext")) {
        c.setBackground(Color.WHITE);

        e.startDrag(null, new TransferAction(text, MainFrame.getInstance()
            .getToolbar().getComponentIndex(e.getComponent())));
View Full Code Here

   */
  private void saveSettings() {
    int size = mCurrentActions.size();
    String[] ids = new String[size];
    for (int i = 0; i < size; i++) {
      Action action = mCurrentActions.elementAt(i);
      ids[i] = (String) action.getValue(ToolBar.ACTION_ID_KEY);
    }
    DefaultToolBarModel.getInstance().setButtonIds(ids);
    Settings.propToolbarButtons.setStringArray(ids);

    ToolBar toolbar = MainFrame.getInstance().getToolbar();
View Full Code Here

  public void mouseClicked(MouseEvent e) {
    if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
      int index = MainFrame.getInstance().getToolbar().getComponentIndex(
          e.getComponent());
      int n = MainFrame.getInstance().getToolbar().getComponentCount();
      Action separator = DefaultToolBarModel.getInstance().getSeparatorAction();
      Action glue = DefaultToolBarModel.getInstance().getGlueAction();
      Action space = DefaultToolBarModel.getInstance().getSpaceAction();

      if (index != -1) {
        Action a = mCurrentActions.elementAt(index);
        mCurrentActions.removeElementAt(index);
        if (!a.equals(separator) && !a.equals(glue) && !a.equals(space)) {
          mAvailableActions.addElement(a);
        }
      } else {
        String name = ((AbstractButton) e.getComponent()).getText().substring(
            37, ((AbstractButton) e.getComponent()).getText().length() - 13);

        for (int i = 0; i < mAvailableActions.size(); i++) {
          Action a = mAvailableActions.elementAt(i);
          if (a.getValue(Action.NAME).equals(name)) {
            if (!separator.getValue(Action.NAME).equals(name)
                && !glue.getValue(Action.NAME).equals(name)
                && !space.getValue(Action.NAME).equals(name)) {
              mAvailableActions.removeElement(a);
            }
View Full Code Here

        // Get the context menu item text
        StringBuilder text = new StringBuilder();
        Icon icon = null;
        ActionMenu actionMenu = menuIf.getContextMenuActions(exampleProgram);
        if (actionMenu != null) {
          Action action = actionMenu.getAction();
          if (action != null) {
            text.append((String) action.getValue(Action.NAME));
            icon = (Icon) action.getValue(Action.SMALL_ICON);
          } else if (menuIf instanceof PluginProxy) {
            text.append(((PluginProxy) menuIf).getInfo().getName());
            icon = ((PluginProxy) menuIf).getMarkIcon();
          } else {
            text.append("unknown");
View Full Code Here

    buttonPn.add(buttonBuilder.getPanel(), BorderLayout.SOUTH);

    /*
     * The action for the search button in the function panel.
     */
    final Action searchAction = new AbstractAction() {
      private static final long serialVersionUID = 1L;

      public void actionPerformed(ActionEvent e) {
        // Open the SearchPanel
        if (mFindAsYouType.getCloseButton().isVisible()) {
          mFindAsYouType.interrupt();
          mFindAsYouType.getSearchBar().setVisible(false);
          mFindAsYouType.getCloseButton().setVisible(false);
        } else {
          mFindAsYouType.showSearchBar();
        }
      }
    };

    searchAction.putValue(Action.SMALL_ICON, TVBrowserIcons
        .search(TVBrowserIcons.SIZE_SMALL));
    searchAction.putValue(Action.ACTION_COMMAND_KEY, "action");
    searchAction.putValue(Action.NAME, mLocalizer.msg("search", "Search Text"));

    mSearchMenu = new ActionMenu(searchAction);

    mFindAsYouType.installKeyListener(scrollPane);
    mFindAsYouType.installKeyListener(mMainPanel);
    mFindAsYouType.installKeyListener(mConfigBtn);
    mFindAsYouType.installKeyListener(mCloseBtn);
    mFindAsYouType.installKeyListener(buttonPn);
    mFindAsYouType.installKeyListener(mPluginsPane);
    mFindAsYouType.installKeyListener(mActionsPane);
    mFindAsYouType.installKeyListener(mFunctionGroup);
    mFindAsYouType.installKeyListener(mActionsPane.getVerticalScrollBar());
    mFindAsYouType.installKeyListener(scrollPane.getVerticalScrollBar());

    mFindAsYouType.getCloseButton().addComponentListener(
        new ComponentAdapter() {
          @Override
          public void componentHidden(ComponentEvent e) {
            if (mTextSearch != null) {
              mTextSearch.setText(mLocalizer.msg("search", "Search Text"));
            }
            searchAction.putValue(Action.NAME, mLocalizer.msg("search",
                "Search Text"));
          }

          @Override
          public void componentShown(ComponentEvent e) {
            if (mTextSearch != null) {
              mTextSearch.setText(mLocalizer.msg("closeSearch",
                  "Close search bar"));
            }
            searchAction.putValue(Action.NAME, mLocalizer.msg("closeSearch",
                "Close search bar"));
          }
        });

    // Scroll to the beginning
View Full Code Here

          mFunctionGroup.add(Box.createRigidArea(new Dimension(0, 2)));
          lastEntry = contextMenuIf;
        }
      } else if (contextMenuIf.getId().compareTo(ConfigMenuItem.CONFIG) == 0
          && mShowSettings) {
        Action action = new AbstractAction() {
          private static final long serialVersionUID = 1L;

          public void actionPerformed(ActionEvent e) {
            MainFrame.getInstance()
                .showSettingsDialog(SettingsItem.CONTEXTMENU);
          }
        };

        action.putValue(Action.SMALL_ICON, TVBrowserIcons
            .preferences(TVBrowserIcons.SIZE_SMALL));
        action.putValue(Action.NAME, ConfigMenuItem.getInstance().toString());

        ActionMenu configure = new ActionMenu(action);
        new TaskMenuAction(mFunctionGroup, mProgram, configure, this,
            "id_configure", mFindAsYouType);
        lastEntry = contextMenuIf;
View Full Code Here

    return null;
  }

  // Adds the action to the TaskPaneGroup.
  private void addAction(final JTaskPaneGroup parent, final ActionMenu menu) {
    final Action a = menu.getAction();

    mAction = new AbstractAction() {
      private static final long serialVersionUID = 1L;

      public void actionPerformed(final ActionEvent e) {
        a.actionPerformed(e);

        if (mAction.getValue(Action.ACTION_COMMAND_KEY) == null
            || !mAction.getValue(Action.ACTION_COMMAND_KEY).equals("action")) {
          mInfo.addPluginActions(true);
        }
      }
    };

    mAction.putValue(Action.NAME,"<html>" + a.getValue(Action.NAME)+ "</html>");
    mAction.putValue(Action.ACTION_COMMAND_KEY,a.getValue(Action.ACTION_COMMAND_KEY));
    mAction.putValue(Action.SMALL_ICON,a.getValue(Action.SMALL_ICON));

    Component c;

    if(ContextMenuSeparatorAction.getInstance().equals(menu.getAction())) {
      parent.add(Box.createRigidArea(new Dimension(0,2)));
View Full Code Here

TOP

Related Classes of javax.swing.Action

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.