/**
   * Enable/disable an AbstractAction
   *
   * @param actionName the key that maps this action in actionTable
   * @param b true to enable or false to disable the action
   */
  public static synchronized void setActionEnabled(final Integer actionKey, final boolean b) {
    Action aa = actionTable.get(actionKey);

    if (aa != null) {
      aa.setEnabled(b);
    }
  }
Esempio n. 2
0
 /**
  * This is the hook through which all menu items are created. It registers the result with the
  * menuitem hashtable so that it can be fetched with getMenuItem().
  *
  * @see #getMenuItem
  */
 protected JMenuItem createMenuItem(String cmd) {
   JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
   URL url = getResource(cmd + imageSuffix);
   if (url != null) {
     mi.setHorizontalTextPosition(JButton.RIGHT);
     mi.setIcon(new ImageIcon(url));
   }
   String astr = getResourceString(cmd + actionSuffix);
   if (astr == null) {
     astr = cmd;
   }
   mi.setActionCommand(astr);
   Action myaction = getAction(astr); // if this is a known action
   if (myaction != null) {
     mi.addActionListener(myaction);
     myaction.addPropertyChangeListener(createActionChangeListener(mi));
     // System.out.println("myaction not null: astr:"+astr+" enabled:"+myaction.isEnabled());
     mi.setEnabled(myaction.isEnabled());
   } else {
     System.err.println("Error:TextViewer: createMenuItem: myaction is null: astr:" + astr);
     // causes the item to be greyed out
     mi.setEnabled(false);
   }
   menuItems.put(cmd, mi);
   return mi;
 }
Esempio n. 3
0
  private Action getAction(String name) {
    for (Action action : sourceArea.getActions()) {
      if (name.equals(action.getValue(Action.NAME).toString())) {
        return action;
      }
    }

    return null;
  }
 public void adjustFeedback() {
   actionCancel.setEnabled(true);
   actionChooseNone.setEnabled(true);
   if (getSwingFocus() == null) {
     actionChooseSelected.setEnabled(false);
   } else {
     actionChooseSelected.setEnabled(true);
   }
 }
  public void setChannel(int chan) {
    currentChannel = chan;
    channelLabel.setText("Now tuned to channel: " + currentChannel);
    // enable/disable the Actions as appropriate

    downAction.setEnabled(currentChannel > MIN_CHANNEL);
    upAction.setEnabled(currentChannel < MAX_CHANNEL);
    gotoFavoriteAction.setEnabled(currentChannel != favoriteChannel);
    setFavoriteAction.setEnabled(currentChannel != favoriteChannel);
  }
Esempio n. 6
0
 public void mouseEntered(MouseEvent evt) {
   if (evt.getSource() instanceof AbstractButton) {
     AbstractButton button = (AbstractButton) evt.getSource();
     Action action = button.getAction();
     if (action != null) {
       String message = (String) action.getValue("LongDescription");
       setMessage(message);
     }
   }
 }
Esempio n. 7
0
 @Override
 public void show(Component c, int x, int y) {
   if (c instanceof JTextComponent) {
     JTextComponent textArea = (JTextComponent) c;
     boolean flg = Objects.nonNull(textArea.getSelectedText());
     cutAction.setEnabled(flg);
     copyAction.setEnabled(flg);
     deleteAction.setEnabled(flg);
     super.show(c, x, y);
   }
 }
Esempio n. 8
0
 @Override
 public void ioResult(IOServiceEvent e) {
   if (e.getState() == IOServiceEvent.MOUNT_SUCCESS
       || e.getState() == IOServiceEvent.MOUNT_FAILURE) {
     lumberjack.setFullModel(buildModel(e.getResolverBundle().getResolvers()));
     toggleAction.setEnabled(cpos != null);
     toggleAction.putValue(
         Action.SELECTED_KEY,
         (Boolean) toggleAction.getValue(Action.SELECTED_KEY) && cpos != null);
   }
 }
Esempio n. 9
0
 private boolean proceedKeyEvent(KeyEvent event, KeyStroke stroke) {
   if (myInputMap.get(stroke) != null) {
     final Action action = myActionMap.get(myInputMap.get(stroke));
     if (action != null && action.isEnabled()) {
       action.actionPerformed(
           new ActionEvent(
               getContent(), event.getID(), "", event.getWhen(), event.getModifiers()));
       return true;
     }
   }
   return false;
 }
Esempio n. 10
0
 /** Configures a JCheckBoxMenuItem for an Action. */
 public static void configureJCheckBoxMenuItem(final JCheckBoxMenuItem mi, final Action a) {
   mi.setSelected((Boolean) a.getValue(Actions.SELECTED_KEY));
   PropertyChangeListener propertyHandler =
       new PropertyChangeListener() {
         public void propertyChange(PropertyChangeEvent evt) {
           if (evt.getPropertyName().equals(Actions.SELECTED_KEY)) {
             mi.setSelected((Boolean) a.getValue(Actions.SELECTED_KEY));
           }
         }
       };
   a.addPropertyChangeListener(propertyHandler);
   mi.putClientProperty("actionPropertyHandler", propertyHandler);
 }
Esempio n. 11
0
 public void caretUpdate(CaretEvent e) {
   // when the cursor moves on _textView
   // this method will be called. Then, we
   // must determine what the line number is
   // and update the line number view
   Element root = textView.getDocument().getDefaultRootElement();
   int line = root.getElementIndex(e.getDot());
   root = root.getElement(line);
   int col = root.getElementIndex(e.getDot());
   lineNumberView.setText(line + ":" + col);
   // if text is selected then enable copy and cut
   boolean isSelection = e.getDot() != e.getMark();
   copyAction.setEnabled(isSelection);
   cutAction.setEnabled(isSelection);
 }
Esempio n. 12
0
 public void activate() {
   // arranco la primera opcion
   if (m_actionfirst != null) {
     m_actionfirst.actionPerformed(null);
     m_actionfirst = null;
   }
 }
Esempio n. 13
0
  @SuppressWarnings("OverridableMethodCallInConstructor")
  Notepad() {
    super(true);

    // Trying to set Nimbus look and feel
    try {
      for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (Exception ignored) {
    }

    setBorder(BorderFactory.createEtchedBorder());
    setLayout(new BorderLayout());

    // create the embedded JTextComponent
    editor = createEditor();
    // Add this as a listener for undoable edits.
    editor.getDocument().addUndoableEditListener(undoHandler);

    // install the command table
    commands = new HashMap<Object, Action>();
    Action[] actions = getActions();
    for (Action a : actions) {
      commands.put(a.getValue(Action.NAME), a);
    }

    JScrollPane scroller = new JScrollPane();
    JViewport port = scroller.getViewport();
    port.add(editor);

    String vpFlag = getProperty("ViewportBackingStore");
    if (vpFlag != null) {
      Boolean bs = Boolean.valueOf(vpFlag);
      port.setScrollMode(bs ? JViewport.BACKINGSTORE_SCROLL_MODE : JViewport.BLIT_SCROLL_MODE);
    }

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add("North", createToolbar());
    panel.add("Center", scroller);
    add("Center", panel);
    add("South", createStatusbar());
  }
Esempio n. 14
0
 /** Unconfigures a JCheckBoxMenuItem for an Action. */
 public static void unconfigureJCheckBoxMenuItem(JCheckBoxMenuItem mi, Action a) {
   PropertyChangeListener propertyHandler =
       (PropertyChangeListener) mi.getClientProperty("actionPropertyHandler");
   if (propertyHandler != null) {
     a.removePropertyChangeListener(propertyHandler);
     mi.putClientProperty("actionPropertyHandler", null);
   }
 }
Esempio n. 15
0
 /**
  * The disconnect method will stop the eventreplayer, and send null to the other peers, to stop
  * their reading from their streams. The GUI-menu is updated appropriately.
  */
 public void disconnect() {
   setTitle("Disconnected");
   active = false;
   if (connected == true) {
     er.stopStreamToQueue();
     ert.interrupt();
     setDocumentFilter(null);
     connected = false;
     setLocked(false);
   }
   deregisterOnPort();
   Disconnect.setEnabled(false);
   Connect.setEnabled(true);
   Listen.setEnabled(true);
   Save.setEnabled(true);
   SaveAs.setEnabled(true);
 }
Esempio n. 16
0
  /**
   * Tests that the returned JButton of <code>createManualToolBarButton</code>: 1. Is disabled upon
   * return. 2. Inherits the tooltip of the Action parameter <code>a</code>.
   */
  public void testCreateManualToolBarButton() {
    final Action a =
        new AbstractAction("Test Action") {
          public void actionPerformed(ActionEvent ae) {}
        };

    a.putValue(Action.LONG_DESCRIPTION, "test tooltip");
    Utilities.invokeAndWait(
        new Runnable() {
          public void run() {
            _but = _frame._createManualToolBarButton(a);
          }
        });

    assertTrue("Returned JButton is enabled.", !_but.isEnabled());
    assertEquals("Tooltip text not set.", "test tooltip", _but.getToolTipText());
    _log.log("testCreateManualToobarButton completed");
  }
Esempio n. 17
0
  public ToolBarFrame() {
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // add a panel for color change

    panel = new JPanel();
    add(panel, BorderLayout.CENTER);

    // set up actions

    Action blueAction = new ColorAction("Blue", new ImageIcon("blue-ball.gif"), Color.BLUE);
    Action yellowAction = new ColorAction("Yellow", new ImageIcon("yellow-ball.gif"), Color.YELLOW);
    Action redAction = new ColorAction("Red", new ImageIcon("red-ball.gif"), Color.RED);

    Action exitAction =
        new AbstractAction("Exit", new ImageIcon("exit.gif")) {
          public void actionPerformed(ActionEvent event) {
            System.exit(0);
          }
        };
    exitAction.putValue(Action.SHORT_DESCRIPTION, "Exit");

    // populate tool bar

    JToolBar bar = new JToolBar();
    bar.add(blueAction);
    bar.add(yellowAction);
    bar.add(redAction);
    bar.addSeparator();
    bar.add(exitAction);
    add(bar, BorderLayout.NORTH);

    // populate menu

    JMenu menu = new JMenu("Color");
    menu.add(yellowAction);
    menu.add(blueAction);
    menu.add(redAction);
    menu.add(exitAction);
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(menu);
    setJMenuBar(menuBar);
  }
Esempio n. 18
0
 public Action getNewFolderAction() {
   if (newFolderAction == null) {
     newFolderAction = new NewFolderAction();
     // Note: Don't return null for readOnly, it might
     // break older apps.
     if (readOnly) {
       newFolderAction.setEnabled(false);
     }
   }
   return newFolderAction;
 }
Esempio n. 19
0
 private void saveFile(String fileName) {
   try {
     FileWriter w = new FileWriter(fileName);
     area1.write(w);
     w.close();
     currentFile = fileName;
     changed = false;
     Save.setEnabled(false);
   } catch (IOException e) {
   }
 }
  @SuppressWarnings("HardCodedStringLiteral")
  private void processListSelection(final KeyEvent e) {
    if (togglePopup(e)) return;

    if (!isPopupShowing()) return;

    final InputMap map = myPathTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    if (map != null) {
      final Object object = map.get(KeyStroke.getKeyStrokeForEvent(e));
      if (object instanceof Action) {
        final Action action = (Action) object;
        if (action.isEnabled()) {
          action.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "action"));
          e.consume();
          return;
        }
      }
    }

    final Object action = getAction(e, myList);

    if ("selectNextRow".equals(action)) {
      if (ensureSelectionExists()) {
        ListScrollingUtil.moveDown(myList, e.getModifiersEx());
      }
    } else if ("selectPreviousRow".equals(action)) {
      ListScrollingUtil.moveUp(myList, e.getModifiersEx());
    } else if ("scrollDown".equals(action)) {
      ListScrollingUtil.movePageDown(myList);
    } else if ("scrollUp".equals(action)) {
      ListScrollingUtil.movePageUp(myList);
    } else if (getSelectedFileFromCompletionPopup() != null
        && (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB)
        && e.getModifiers() == 0) {
      hideCurrentPopup();
      e.consume();
      processChosenFromCompletion(e.getKeyCode() == KeyEvent.VK_TAB);
    }
  }
 private void saveFile(String fileName) {
   try {
     FileWriter w = new FileWriter(fileName);
     area.write(w);
     w.close();
     currentFile = fileName;
     setTitle(currentFile + " - CoreyTextEditor");
     changed = false;
     Save.setEnabled(false);
   } catch (IOException e) {
     // No handling done here
   }
 }
Esempio n. 22
0
 /** This is the hook through which all menu items are created. */
 protected JMenuItem createMenuItem(String cmd) {
   JMenuItem mi = new JMenuItem(getResourceString(cmd + labelSuffix));
   URL url = getResource(cmd + imageSuffix);
   if (url != null) {
     mi.setHorizontalTextPosition(JButton.RIGHT);
     mi.setIcon(new ImageIcon(url));
   }
   String astr = getProperty(cmd + actionSuffix);
   if (astr == null) {
     astr = cmd;
   }
   mi.setActionCommand(astr);
   Action a = getAction(astr);
   if (a != null) {
     mi.addActionListener(a);
     a.addPropertyChangeListener(createActionChangeListener(mi));
     mi.setEnabled(a.isEnabled());
   } else {
     mi.setEnabled(false);
   }
   return mi;
 }
Esempio n. 23
0
  public void redoAction() {
    try {
      if (undoMgr.canRedo()) {
        redoAction.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Redo"));

        setRedoItem();
      } else {
        java.awt.Toolkit.getDefaultToolkit().beep();
      }
    } catch (CannotUndoException ex) {
      ex.printStackTrace();
    }
  }
  // Add icons and friendly names to actions we care about.
  protected void makeActionsPretty() {
    Action a;
    a = textComp.getActionMap().get(DefaultEditorKit.cutAction);
    a.putValue(Action.SMALL_ICON, new ImageIcon("icons/cut.gif"));
    a.putValue(Action.NAME, "Cut");

    a = textComp.getActionMap().get(DefaultEditorKit.copyAction);
    a.putValue(Action.SMALL_ICON, new ImageIcon("icons/copy.gif"));
    a.putValue(Action.NAME, "Copy");

    a = textComp.getActionMap().get(DefaultEditorKit.pasteAction);
    a.putValue(Action.SMALL_ICON, new ImageIcon("icons/paste.gif"));
    a.putValue(Action.NAME, "Paste");

    a = textComp.getActionMap().get(DefaultEditorKit.selectAllAction);
    a.putValue(Action.NAME, "Select All");
  }
Esempio n. 25
0
    private void addAction(Action act) {

      if (m_appuser.hasPermission((String) act.getValue(AppUserView.ACTION_TASKNAME))) {
        // add the action
        Component c = taskGroup.add(act);
        c.setFocusable(false);
        // c.setRequestFocusEnabled(false);

        taskGroup.setVisible(true);

        if (m_actionfirst == null) {
          m_actionfirst = act;
        }
      }
    }
Esempio n. 26
0
  private static void constructActions() {
    final Action lExitAction = new ExitAction();
    lExitAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_X);
    viewModel.put("action.exit", lExitAction);

    final Action lHelpAction = new HelpAction();
    lHelpAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_T);
    viewModel.put("action.help", lHelpAction);

    final Action lAboutAction = new AboutAction();
    lAboutAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
    viewModel.put("action.about", lAboutAction);
  }
  public void adjustFinderMenuBar() {
    JMenuItem menuItem;
    Action act;
    String itemLabel;
    ICFSecurityServiceTypeObj selectedObj = getSwingFocusAsServiceType();
    boolean enableState;
    if (selectedObj == null) {
      enableState = false;
    } else {
      enableState = true;
    }

    if (actionViewSelected != null) {
      actionViewSelected.setEnabled(enableState);
    }
    if (actionEditSelected != null) {
      actionEditSelected.setEnabled(enableState);
    }
    if (actionDeleteSelected != null) {
      actionDeleteSelected.setEnabled(enableState);
    }
    if (actionAddServiceType != null) {
      actionAddServiceType.setEnabled(true);
    }

    if (menuFile != null) {
      int itemCount = menuFile.getItemCount();
      for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
        menuItem = menuFile.getItem(itemIdx);
        act = menuItem.getAction();
        if (act != null) {
          if (act == actionViewSelected) {
            menuItem.setEnabled(enableState);
          } else if (act == actionEditSelected) {
            menuItem.setEnabled(enableState);
          } else if (act == actionDeleteSelected) {
            menuItem.setEnabled(enableState);
          } else if (act == actionAddServiceType) {
            menuItem.setEnabled(true);
          }
        }
      }
    }
  }
 public void setPanelMode(CFJPanel.PanelMode value) {
   CFJPanel.PanelMode oldMode = getPanelMode();
   if (oldMode == value) {
     return;
   }
   super.setPanelMode(value);
   ((ICFFreeSwitchSwingFSSFExtensionJPanelCommon) swingViewEditJPanel).setPanelMode(value);
   if (value == CFJPanel.PanelMode.View) {
     if (actionEdit != null) {
       actionEdit.setEnabled(true);
     }
     if (actionSave != null) {
       actionSave.setEnabled(false);
     }
     if (actionDelete != null) {
       actionDelete.setEnabled(true);
     }
     if (actionClose != null) {
       actionClose.setEnabled(true);
     }
   } else if (value == CFJPanel.PanelMode.Edit) {
     if (actionEdit != null) {
       actionEdit.setEnabled(false);
     }
     if (actionSave != null) {
       actionSave.setEnabled(true);
     }
     if (actionDelete != null) {
       actionDelete.setEnabled(false);
     }
     if (actionClose != null) {
       actionClose.setEnabled(true);
     }
   } else if (value == CFJPanel.PanelMode.Add) {
     if (actionEdit != null) {
       actionEdit.setEnabled(false);
     }
     if (actionSave != null) {
       actionSave.setEnabled(true);
     }
     if (actionDelete != null) {
       actionDelete.setEnabled(false);
     }
     if (actionClose != null) {
       actionClose.setEnabled(true);
     }
   } else {
     if (actionEdit != null) {
       actionEdit.setEnabled(false);
     }
     if (actionSave != null) {
       actionSave.setEnabled(false);
     }
     if (actionDelete != null) {
       actionDelete.setEnabled(false);
     }
     if (actionClose != null) {
       actionClose.setEnabled(true);
     }
   }
 }
Esempio n. 29
0
  public InterpreterFrame() {
    super("Simple Lisp Interpreter");

    // Create the menu
    menubar = buildMenuBar();
    setJMenuBar(menubar);
    // Create the toolbar
    toolbar = buildToolBar();
    // disable cut and copy actions
    cutAction.setEnabled(false);
    copyAction.setEnabled(false);
    // Setup text area for editing source code
    // and setup document listener so interpreter
    // is notified when current file modified and
    // when the cursor is moved.
    textView = buildEditor();
    textView.getDocument().addDocumentListener(this);
    textView.addCaretListener(this);

    // set default key bindings
    bindKeyToCommand("ctrl C", "(buffer-copy)");
    bindKeyToCommand("ctrl X", "(buffer-cut)");
    bindKeyToCommand("ctrl V", "(buffer-paste)");
    bindKeyToCommand("ctrl E", "(buffer-eval)");
    bindKeyToCommand("ctrl O", "(file-open)");
    bindKeyToCommand("ctrl S", "(file-save)");
    bindKeyToCommand("ctrl Q", "(exit)");

    // Give text view scrolling capability
    Border border =
        BorderFactory.createCompoundBorder(
            BorderFactory.createEmptyBorder(3, 3, 3, 3),
            BorderFactory.createLineBorder(Color.gray));
    JScrollPane topSplit = addScrollers(textView);
    topSplit.setBorder(border);

    // Create tabbed pane for console/problems
    consoleView = makeConsoleArea(10, 50, true);
    problemsView = makeConsoleArea(10, 50, false);
    tabbedPane = buildProblemsConsole();

    // Plug the editor and problems/console together
    // using a split pane. This allows one to change
    // their relative size using the split-bar in
    // between them.
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topSplit, tabbedPane);

    // Create status bar
    statusView = new JLabel(" Status");
    lineNumberView = new JLabel("0:0");
    statusbar = buildStatusBar();

    // Now, create the outer panel which holds
    // everything together
    outerpanel = new JPanel();
    outerpanel.setLayout(new BorderLayout());
    outerpanel.add(toolbar, BorderLayout.PAGE_START);
    outerpanel.add(splitPane, BorderLayout.CENTER);
    outerpanel.add(statusbar, BorderLayout.SOUTH);
    getContentPane().add(outerpanel);

    // tell frame to fire a WindowsListener event
    // but not to close when "x" button clicked.
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(this);
    // set minimised icon to use
    setIconImage(makeImageIcon("spi.png").getImage());

    // setup additional internal functions
    InternalFunctions.setup_internals(interpreter, this);

    // set default window size
    Component top = splitPane.getTopComponent();
    Component bottom = splitPane.getBottomComponent();
    top.setPreferredSize(new Dimension(100, 400));
    bottom.setPreferredSize(new Dimension(100, 200));
    pack();

    // load + run user configuration file (if there is one)
    String homedir = System.getProperty("user.home");
    try {
      interpreter.load(homedir + "/.simplelisp");
    } catch (FileNotFoundException e) {
      // do nothing if file does not exist!
      System.out.println("Didn't find \"" + homedir + "/.simplelisp\"");
    }

    textView.grabFocus();
    setVisible(true);

    // redirect all I/O to problems/console
    redirectIO();

    // start highlighter thread
    highlighter = new DisplayThread(250);
    highlighter.setDaemon(true);
    highlighter.start();
  }
Esempio n. 30
0
 public void selectLine() {
   Action selectLine = getAction(DefaultEditorKit.selectLineAction);
   if (selectLine != null) {
     selectLine.actionPerformed(null);
   }
 }