/** Destroy the MenuItem */
 public void destroy() {
   if (meAsAMenu != null) {
     ScilabSwingUtilities.removeFromParent((SwingScilabMenu) meAsAMenu.getAsSimpleMenu());
   } else if (meAsACheckBoxMenuItem != null) {
     ScilabSwingUtilities.removeFromParent(
         (SwingScilabCheckBoxMenuItem) meAsACheckBoxMenuItem.getAsSimpleCheckBoxMenuItem());
   } else {
     ScilabSwingUtilities.removeFromParent(this);
   }
 }
  /**
   * Create a button for a tool bar
   *
   * @param editor the associated editor
   * @param title tooltip for the button
   * @return the button
   */
  public static PushButton createButton(SwingScilabVariableEditor editor, String title) {
    PushButton button = ScilabPushButton.createPushButton();
    ((SwingScilabPushButton) button.getAsSimplePushButton())
        .addActionListener(new SetPrecisionShortAction(editor, title));
    button.setToolTipText(title);
    ImageIcon imageIcon = new ImageIcon(ScilabSwingUtilities.findIcon("short"));
    ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(imageIcon);

    return button;
  }
Beispiel #3
0
  /** Install the static actions properties on the instance */
  private void installProperties() {
    String name = "";
    ImageIcon icon = null;
    int mnemonic = 0;
    int accelerator = 0;
    try {
      name = (String) getClass().getField("NAME").get(null);

      /*
       * Getting icon from the registered icon path
       */
      final String iconName = (String) getClass().getField("SMALL_ICON").get(null);
      if (iconName != null && !iconName.isEmpty()) {
        icon = new ImageIcon(ScilabSwingUtilities.findIcon(iconName));
      }

      mnemonic = getClass().getField("MNEMONIC_KEY").getInt(null);
      accelerator = getClass().getField("ACCELERATOR_KEY").getInt(null);
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (NoSuchFieldException e) {
      e.printStackTrace();
    }

    assert !"".equals(name);
    putValue(Action.NAME, name);
    putValue(Action.SHORT_DESCRIPTION, name);
    putValue(Action.LONG_DESCRIPTION, name);
    if (icon != null) {
      putValue(Action.SMALL_ICON, icon);
    }

    /*
     * Set up the accelerator instead of the mnemonic as the menu is the
     * preferred way on keyboard control. We are using Action.MNEMONIC_KEY
     * as keyboard key and Action.ACCELERATOR_KEY as a mask.
     *
     * Install it only when there is a real shortcut (with a mnemonic).
     */
    if (mnemonic != 0) {
      putValue(Action.MNEMONIC_KEY, mnemonic);
      putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(mnemonic, accelerator));
    }
  }
 /** Destroy the Label */
 public void destroy() {
   ScilabSwingUtilities.removeFromParent(this);
 }
Beispiel #5
0
/**
 * Manage Delete Actions
 *
 * @author Vincent COUVERT
 */
public final class DeleteAction extends CommonCallBack {

  private static final long serialVersionUID = 1L;

  private static ImageIcon icon = new ImageIcon(ScilabSwingUtilities.findIcon("edit-delete"));

  private static final char MNEMONIC = 'D';

  private static final String KEY = "DELETE";
  private static final String SUPPR = "Suppr";

  private final SwingScilabVariableBrowser variableBrowser;

  /** Constructor */
  public DeleteAction(SwingScilabVariableBrowser variableBrowser) {
    super("");
    this.variableBrowser = variableBrowser;
  }

  /**
   * Create a button for a tool bar
   *
   * @param title tooltip for the button
   * @return the button
   */
  public static PushButton createButton(SwingScilabVariableBrowser variableBrowser, String title) {
    PushButton button = ScilabPushButton.createPushButton();
    ((SwingScilabPushButton) button.getAsSimplePushButton())
        .addActionListener(new DeleteAction(variableBrowser));
    button.setToolTipText(title);
    ((SwingScilabPushButton) button.getAsSimplePushButton()).setIcon(icon);

    return button;
  }

  /**
   * Create the associated menu
   *
   * @return the menu
   */
  public MenuItem createMenuItem() {
    MenuItem menuItem = ScilabMenuItem.createMenuItem();
    menuItem.setText(UiDataMessages.DELETE + " '" + getSelectedVariable() + "'");
    menuItem.setMnemonic(MNEMONIC);
    menuItem.setCallback(this);
    ((SwingScilabMenuItem) menuItem.getAsSimpleMenuItem()).setIcon(icon);
    return menuItem;
  }

  /**
   * Action!
   *
   * @see org.scilab.modules.gui.events.callback.CallBack#callBack()
   */
  @Override
  public void callBack() {
    try {
      asynchronousScilabExec(null, "clear('" + getSelectedVariable() + "'); updatebrowsevar()");
    } catch (InterpreterException e1) {
      System.err.println(
          "An error in the interpreter has been catched: " + e1.getLocalizedMessage());
    }
  }

  private String getSelectedVariable() {

    int clickedRow = variableBrowser.getTable().getSelectedRow();
    // Does nothing if no variable selected
    if (clickedRow != -1) {
      return variableBrowser
          .getTable()
          .getValueAt(clickedRow, BrowseVar.NAME_COLUMN_INDEX)
          .toString();
    }
    return "";
  }
}
Beispiel #6
0
/**
 * Manage Cut Actions
 *
 * @author Vincent COUVERT
 */
public final class CutAction extends CommonCallBack {

  private static final long serialVersionUID = 1L;

  private static final String LABEL = CommandHistoryMessages.CUT;
  private static final String ICON = ScilabSwingUtilities.findIcon("edit-cut");
  private static final char MNEMONIC = 'U';

  private static final String KEY = "OSSCKEY X";
  private static final String CUT = "Cut";

  /** Constructor */
  public CutAction() {
    super("");
  }

  /** Register the key for the action */
  public static void registerKeyAction() {
    CommandHistory.getTree().getActionMap().put(CUT, new CutAction());
    CommandHistory.getTree().getInputMap().put(ScilabKeyStroke.getKeyStroke(KEY), CUT);
  }

  /**
   * Create the associated menu
   *
   * @return the menu
   */
  public static MenuItem createMenuItem() {
    MenuItem menuItem = ScilabMenuItem.createMenuItem();
    menuItem.setText(LABEL);
    menuItem.setMnemonic(MNEMONIC);
    menuItem.setCallback(getCallBack());
    ((SwingScilabMenuItem) menuItem.getAsSimpleMenuItem()).setIcon(new ImageIcon(ICON));
    return menuItem;
  }

  /**
   * Create the associated button
   *
   * @return the button
   */
  public static PushButton createPushButton() {
    PushButton pushButton = ScilabPushButton.createPushButton();
    pushButton.setIcon(ICON);
    pushButton.setToolTipText(LABEL);
    pushButton.setCallback(getCallBack());
    return pushButton;
  }

  /**
   * Create a new class instance
   *
   * @return the instance
   */
  private static CommonCallBack getCallBack() {
    CommonCallBack callback = null;
    try {
      callback = CutAction.class.getConstructor().newInstance();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (SecurityException e) {
      e.printStackTrace();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
    } catch (NoSuchMethodException e) {
      e.printStackTrace();
    }
    return callback;
  }

  /**
   * Action!
   *
   * @see org.scilab.modules.gui.events.callback.CallBack#callBack()
   */
  @Override
  public void callBack() {
    CommonCallBack copyAction = new CopyAction();
    copyAction.callBack();
    CommonCallBack deleteAction = new DeleteAction();
    deleteAction.callBack();
  }
}