Esempio n. 1
0
 private void initKeyMap() {
   InputMap map = this.getInputMap();
   int shift = InputEvent.SHIFT_MASK;
   int ctrl = InputEvent.CTRL_MASK;
   map.put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, shift), SikuliEditorKit.deIndentAction);
   map.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, ctrl), SikuliEditorKit.deIndentAction);
 }
Esempio n. 2
0
 public void unbindKey(String keySequence) {
   KeyStroke ks = KeyStroke.getKeyStroke(keySequence);
   if (ks == null) {
     throw new Error("Invalid key sequence \"" + keySequence + "\"");
   }
   textView.getKeymap().removeKeyStrokeBinding(ks);
 }
Esempio n. 3
0
    /** Constructs cell editor. */
    public CellEditor() {
      super(new JFormattedTextField());
      final JFormattedTextField ftf = (JFormattedTextField) getComponent();

      // Set GUI behaviour of text field
      ftf.setValue(null);
      ftf.setHorizontalAlignment(JTextField.LEADING);
      ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);

      // Set that one click on cell is enough for editing
      setClickCountToStart(1);

      // Special handling code for ENTER
      ftf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
      ftf.getActionMap()
          .put(
              "check",
              new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                  if (!ftf.isEditValid()) {
                    if (askEditOrRevert(ftf, null)) {
                      ftf.setValue(ftf.getValue());
                      ftf.postActionEvent();
                    }
                  } else
                    try {
                      ftf.commitEdit();
                      ftf.postActionEvent();
                    } catch (java.text.ParseException exc) {
                      // nothing to do
                    }
                }
              });
    }
Esempio n. 4
0
 public void bindKeyToCommand(String keySequence, LispExpr cmd) {
   // 	see Java API for info on keySequence format
   KeyStroke ks = KeyStroke.getKeyStroke(keySequence);
   if (ks == null) {
     throw new Error("Invalid key sequence \"" + keySequence + "\"");
   }
   textView.getKeymap().addActionForKeyStroke(ks, new KeyAction(cmd));
 }
 // Adds a new keybinding equal to the character provided and the default super key (ctrl/cmd)
 private static void bind(int Character) {
   frame
       .getRootPane()
       .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
       .put(
           KeyStroke.getKeyStroke(Character, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
           "console");
 }
Esempio n. 6
0
  public XmlTextPane() {
    XMLEditorKit kit = new XMLEditorKit(true, this);

    kit.setLineWrappingEnabled(false);

    kit.setStyle(XMLStyleConstants.ELEMENT_NAME, new Color(128, 0, 0), Font.PLAIN);
    kit.setStyle(XMLStyleConstants.ELEMENT_VALUE, new Color(0, 0, 0), Font.PLAIN);
    kit.setStyle(XMLStyleConstants.ELEMENT_PREFIX, new Color(128, 0, 0), Font.PLAIN);

    kit.setStyle(XMLStyleConstants.ATTRIBUTE_NAME, new Color(255, 0, 0), Font.PLAIN);
    kit.setStyle(XMLStyleConstants.ATTRIBUTE_VALUE, new Color(0, 0, 0), Font.PLAIN);
    kit.setStyle(XMLStyleConstants.ATTRIBUTE_PREFIX, new Color(128, 0, 0), Font.PLAIN);

    kit.setStyle(XMLStyleConstants.NAMESPACE_NAME, new Color(102, 102, 102), Font.PLAIN);
    kit.setStyle(XMLStyleConstants.NAMESPACE_VALUE, new Color(0, 51, 51), Font.PLAIN);
    kit.setStyle(XMLStyleConstants.NAMESPACE_PREFIX, new Color(102, 102, 102), Font.PLAIN);

    kit.setStyle(XMLStyleConstants.ENTITY, new Color(0, 0, 0), Font.PLAIN);
    kit.setStyle(XMLStyleConstants.COMMENT, new Color(153, 153, 153), Font.PLAIN);
    kit.setStyle(XMLStyleConstants.CDATA, new Color(0, 0, 0), Font.PLAIN);
    kit.setStyle(XMLStyleConstants.SPECIAL, new Color(0, 0, 0), Font.PLAIN);

    this.setEditorKit(kit);

    this.setFont(new Font("Monospaced", Font.PLAIN, 12));

    this.registerKeyboardAction(
        shiftTabAction,
        KeyStroke.getKeyStroke(KeyEvent.VK_TAB, ActionEvent.SHIFT_MASK),
        JComponent.WHEN_FOCUSED);
    this.registerKeyboardAction(
        deleteLineAction,
        KeyStroke.getKeyStroke(KeyEvent.VK_Y, ActionEvent.CTRL_MASK),
        JComponent.WHEN_FOCUSED);
    ActionListener escAction =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            clearMarkerLine();
            clearErrorLine();
          }
        };
    this.registerKeyboardAction(
        escAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_FOCUSED);
    this.getActionMap().put(tabAction.getValue(Action.NAME), tabAction);
  }
Esempio n. 7
0
  // ------------------------------------------------------------------
  // from Java Swing 1.2 Orielly - Robert Eckstein
  // ------------------------------------------------------------------
  protected JTextComponent updateKeymapForWord(JTextComponent textComp) {
    // create a new child keymap
    Keymap map = JTextComponent.addKeymap("NslmMap", textComp.getKeymap());

    // define the keystrokeds to be added
    KeyStroke next = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, InputEvent.CTRL_MASK, false);
    // add the new mappings used DefaultEditorKit actions
    map.addActionForKeyStroke(next, getAction(DefaultEditorKit.nextWordAction));

    KeyStroke prev = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(prev, getAction(DefaultEditorKit.previousWordAction));

    KeyStroke selNext =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_RIGHT, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(selNext, getAction(DefaultEditorKit.selectionNextWordAction));
    KeyStroke selPrev =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_LEFT, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(selPrev, getAction(DefaultEditorKit.selectionPreviousWordAction));

    KeyStroke find = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(find, getAction("find"));

    KeyStroke findAgain = KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(findAgain, getAction("findAgain"));

    // set the keymap for the text component
    textComp.setKeymap(map);
    return (textComp);
  } // end updateKeymapForWord
Esempio n. 8
0
 @Override
 public void keyPressed(KeyEvent e) {
   // Accept "copy" key strokes
   KeyStroke ks = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
   JComponent comp = (JComponent) e.getSource();
   for (int i = 0; i < 3; i++) {
     InputMap im = comp.getInputMap(i);
     Object key = im.get(ks);
     if (defaultEditorKitCopyActionName.equals(key)
         || transferHandlerCopyActionName.equals(key)) {
       return;
     }
   }
   // Accept JTable navigation key strokes
   if (!tableNavigationKeys.contains(e.getKeyCode())) {
     e.consume();
   }
 }
  public TextFieldDemo() {
    initComponents();

    InputStream in = getClass().getResourceAsStream("content.txt");
    try {
      textArea.read(new InputStreamReader(in), null);
    } catch (IOException e) {
      e.printStackTrace();
    }

    hilit = new DefaultHighlighter();
    painter = new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR);
    textArea.setHighlighter(hilit);

    entryBg = entry.getBackground();
    entry.getDocument().addDocumentListener(this);

    InputMap im = entry.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap am = entry.getActionMap();
    im.put(KeyStroke.getKeyStroke("ESCAPE"), CANCEL_ACTION);
    am.put(CANCEL_ACTION, new CancelAction());
  }
  private void registerActions() {
    myExternalDocAction.registerCustomShortcutSet(
        ActionManager.getInstance().getAction(IdeActions.ACTION_EXTERNAL_JAVADOC).getShortcutSet(),
        myEditorPane);

    myKeyboardActions.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0),
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JScrollBar scrollBar = myScrollPane.getVerticalScrollBar();
            int value = scrollBar.getValue() - scrollBar.getUnitIncrement(-1);
            value = Math.max(value, 0);
            scrollBar.setValue(value);
          }
        });

    myKeyboardActions.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0),
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JScrollBar scrollBar = myScrollPane.getVerticalScrollBar();
            int value = scrollBar.getValue() + scrollBar.getUnitIncrement(+1);
            value = Math.min(value, scrollBar.getMaximum());
            scrollBar.setValue(value);
          }
        });

    myKeyboardActions.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0),
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JScrollBar scrollBar = myScrollPane.getHorizontalScrollBar();
            int value = scrollBar.getValue() - scrollBar.getUnitIncrement(-1);
            value = Math.max(value, 0);
            scrollBar.setValue(value);
          }
        });

    myKeyboardActions.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0),
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JScrollBar scrollBar = myScrollPane.getHorizontalScrollBar();
            int value = scrollBar.getValue() + scrollBar.getUnitIncrement(+1);
            value = Math.min(value, scrollBar.getMaximum());
            scrollBar.setValue(value);
          }
        });

    myKeyboardActions.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0),
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JScrollBar scrollBar = myScrollPane.getVerticalScrollBar();
            int value = scrollBar.getValue() - scrollBar.getBlockIncrement(-1);
            value = Math.max(value, 0);
            scrollBar.setValue(value);
          }
        });

    myKeyboardActions.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0),
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JScrollBar scrollBar = myScrollPane.getVerticalScrollBar();
            int value = scrollBar.getValue() + scrollBar.getBlockIncrement(+1);
            value = Math.min(value, scrollBar.getMaximum());
            scrollBar.setValue(value);
          }
        });

    myKeyboardActions.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0),
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JScrollBar scrollBar = myScrollPane.getHorizontalScrollBar();
            scrollBar.setValue(0);
          }
        });

    myKeyboardActions.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_END, 0),
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JScrollBar scrollBar = myScrollPane.getHorizontalScrollBar();
            scrollBar.setValue(scrollBar.getMaximum());
          }
        });

    myKeyboardActions.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_HOME, KeyEvent.CTRL_MASK),
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JScrollBar scrollBar = myScrollPane.getVerticalScrollBar();
            scrollBar.setValue(0);
          }
        });

    myKeyboardActions.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_END, KeyEvent.CTRL_MASK),
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            JScrollBar scrollBar = myScrollPane.getVerticalScrollBar();
            scrollBar.setValue(scrollBar.getMaximum());
          }
        });
  }
Esempio n. 11
0
  // ------------------------------------------------------------------
  // from Java Swing 1.2 Orielly - Robert Eckstein
  // ------------------------------------------------------------------
  protected JTextComponent updateKeymapForEmacs(JTextComponent textComp) {
    // note: it does not look like a key can do more than one action
    // thus no modes.
    // todo: not all of these are correct. such as ctrlK
    // todo: add saving - ctrlXS

    // create a new child keymap
    Keymap map = JTextComponent.addKeymap("NslmMap", textComp.getKeymap());

    KeyStroke selNext =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_RIGHT, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(selNext, getAction(DefaultEditorKit.selectionNextWordAction));

    KeyStroke selPrev =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_LEFT, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(selPrev, getAction(DefaultEditorKit.selectionPreviousWordAction));

    KeyStroke next = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(next, getAction(DefaultEditorKit.forwardAction));
    KeyStroke prev = KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(prev, getAction(DefaultEditorKit.backwardAction));

    KeyStroke selectionDown = KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(selectionDown, getAction(DefaultEditorKit.downAction));
    KeyStroke selectionUp = KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(selectionUp, getAction(DefaultEditorKit.upAction));

    KeyStroke pageDown = KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(pageDown, getAction(DefaultEditorKit.pageDownAction));

    KeyStroke pageUp = KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(pageUp, getAction(DefaultEditorKit.pageUpAction));

    KeyStroke endDoc =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_GREATER, InputEvent.META_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(endDoc, getAction(DefaultEditorKit.endAction));
    KeyStroke beginingDoc =
        KeyStroke.getKeyStroke(
            KeyEvent.VK_LESS, InputEvent.META_MASK | InputEvent.SHIFT_MASK, false);
    map.addActionForKeyStroke(beginingDoc, getAction(DefaultEditorKit.beginAction));

    // the VK_SPACE and VK_W not working as in Emacs - space deleting
    // KeyStroke
    // selectionStart=KeyStroke.getKeyStroke(KeyEvent.VK_SPACE,InputEvent.CTRL_MASK,false);
    // map.addActionForKeyStroke(selectionStart,getAction(DefaultEditorKit.selectionForwardAction));
    // //todo: setCharPosAction
    // this is doing nothing because only one char to can be assigned to cut
    // KeyStroke cut1=KeyStroke.getKeyStroke(KeyEvent.VK_W,InputEvent.CTRL_MASK,false);
    // map.addActionForKeyStroke(cut1,getAction(DefaultEditorKit.cutAction));

    // if we do save as XS, this will have to change
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(cut, getAction(DefaultEditorKit.cutAction));

    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(paste, getAction(DefaultEditorKit.pasteAction));

    KeyStroke moveToEndLine = KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(moveToEndLine, getAction(DefaultEditorKit.endLineAction));

    // not emacs like
    KeyStroke selWord = KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(selWord, getAction(DefaultEditorKit.selectWordAction));

    KeyStroke selLine = KeyStroke.getKeyStroke(KeyEvent.VK_K, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(selLine, getAction(DefaultEditorKit.selectLineAction));

    KeyStroke delNext = KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(delNext, getAction(DefaultEditorKit.deleteNextCharAction));

    KeyStroke insertLine = KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(insertLine, getAction(DefaultEditorKit.insertBreakAction));

    KeyStroke searchBackward = KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(searchBackward, getAction("findAgain"));

    KeyStroke searchForward = KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK, false);
    map.addActionForKeyStroke(searchForward, getAction("findAgain"));

    // set the keymap for the text component
    textComp.setKeymap(map);
    return (textComp);
  } // end updateKeymapForEmacs
Esempio n. 12
0
  /** 程式的GUI畫面配置,並登入按鈕、選項監聽。 */
  private void GUI() {
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    JMenuItem file_newMenuItem = new JMenuItem("New");
    file_newMenuItem.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource("/javax/swing/plaf/metal/icons/ocean/file.gif")));
    file_newMenuItem.addActionListener(new SystemFileNew());
    fileMenu.add(file_newMenuItem);

    JMenuItem file_openMenuItem = new JMenuItem("Open File...");
    file_openMenuItem.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource(
                "/com/sun/java/swing/plaf/windows/icons/TreeOpen.gif")));
    file_openMenuItem.addActionListener(new SystemFileOpen());
    fileMenu.add(file_openMenuItem);

    JMenu file_saveMenu = new JMenu("Save");
    fileMenu.add(file_saveMenu);

    JMenuItem file_save_saveMenuItem = new JMenuItem("Save");
    file_save_saveMenuItem.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource(
                "/com/sun/java/swing/plaf/windows/icons/FloppyDrive.gif")));
    file_save_saveMenuItem.addActionListener(new SystemFileSave());
    file_save_saveMenuItem.setAccelerator(
        KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
    file_saveMenu.add(file_save_saveMenuItem);

    JMenuItem file_save_save_asMenuItem = new JMenuItem("Save as");
    file_save_save_asMenuItem.addActionListener(new SystemFileSaveAS());
    file_saveMenu.add(file_save_save_asMenuItem);

    JMenuItem file_save_save_allMenuItem = new JMenuItem("Save all");
    file_save_save_allMenuItem.setAccelerator(
        KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
    file_save_save_allMenuItem.addActionListener(new SystemFileSaveAll());
    file_saveMenu.add(file_save_save_allMenuItem);

    JMenu file_closeMenu = new JMenu("Close");
    fileMenu.add(file_closeMenu);

    JMenuItem file_close_closeMenuItem = new JMenuItem("Close File");
    file_close_closeMenuItem.addActionListener(new SystemFileClose());
    file_closeMenu.add(file_close_closeMenuItem);

    JMenuItem file_close_close_all_fileMenuItem = new JMenuItem("Close all File");
    file_close_close_all_fileMenuItem.addActionListener(new SystemFileCloseAll());
    file_closeMenu.add(file_close_close_all_fileMenuItem);

    JMenuItem file_exitMenuItem = new JMenuItem("Exit");
    file_exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK));
    file_exitMenuItem.addActionListener(new SystemExit());
    fileMenu.add(file_exitMenuItem);

    JMenu editMenu = new JMenu("Edit");
    menuBar.add(editMenu);

    replace_searchMenuItem.addActionListener(replace_search);
    replace_searchMenuItem.setAccelerator(
        KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK));
    editMenu.add(replace_searchMenuItem);

    SystemEditCut_Copy_Paste cut_copy_paste = new SystemEditCut_Copy_Paste();
    cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    cutMenuItem.addActionListener(cut_copy_paste);
    editMenu.add(cutMenuItem);
    copyMenutem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));

    copyMenutem.addActionListener(cut_copy_paste);
    editMenu.add(copyMenutem);
    pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK));

    pasteMenuItem.addActionListener(cut_copy_paste);
    editMenu.add(pasteMenuItem);

    JMenuItem pathMenuItem = new JMenuItem("Default AutoSave-Path");
    pathMenuItem.addActionListener(new SystemEditSetPath());
    editMenu.add(pathMenuItem);

    JMenu helpMenu = new JMenu("Help");
    menuBar.add(helpMenu);

    JMenuItem HelpMenuItem = new JMenuItem("Help");
    HelpMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            JOptionPane.showMessageDialog(null, help, "Help!", JOptionPane.INFORMATION_MESSAGE);
          }
        });
    helpMenu.add(HelpMenuItem);

    JMenuItem AboutNewMenuItem = new JMenuItem("About");
    AboutNewMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, about, "About...", JOptionPane.INFORMATION_MESSAGE);
          }
        });
    helpMenu.add(AboutNewMenuItem);

    JToolBar toolBar = new JToolBar();
    getContentPane().add(toolBar, BorderLayout.NORTH);

    scrollPane.setViewportView(td);
    JButton newFileButton = new JButton("New");
    newFileButton.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource("/javax/swing/plaf/metal/icons/ocean/file.gif")));
    newFileButton.setToolTipText("New File.");
    newFileButton.addActionListener(new SystemFileNew());
    toolBar.add(newFileButton);

    JButton openFileButton = new JButton("Open");
    openFileButton.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource(
                "/javax/swing/plaf/metal/icons/ocean/directory.gif")));
    openFileButton.setToolTipText("Open File.");
    openFileButton.addActionListener(new SystemFileOpen());
    toolBar.add(openFileButton);

    JButton save_asFileButton = new JButton("Save as");
    save_asFileButton.setToolTipText("Save as File.");
    save_asFileButton.addActionListener(new SystemFileSaveAS());
    toolBar.add(save_asFileButton);

    JButton saveFileButton = new JButton("Save");
    saveFileButton.setIcon(
        new ImageIcon(
            DocumentEditGUI.class.getResource("/javax/swing/plaf/metal/icons/ocean/floppy.gif")));
    saveFileButton.setToolTipText("Savet his File.");
    saveFileButton.addActionListener(new SystemFileSave());
    toolBar.add(saveFileButton);

    JButton save_allFileButton = new JButton("Save all");
    save_allFileButton.setToolTipText("Save all File.");
    save_allFileButton.addActionListener(new SystemFileSaveAll());
    toolBar.add(save_allFileButton);

    JButton closeButton = new JButton("Close");
    closeButton.setToolTipText("Close this file.");
    closeButton.addActionListener(new SystemFileClose());
    toolBar.add(closeButton);

    JButton close_allButton = new JButton("Close all");
    close_allButton.setToolTipText("Close al File.");
    close_allButton.addActionListener(new SystemFileCloseAll());
    toolBar.add(close_allButton);
  }
Esempio n. 13
0
  /** Helper method to initialize the actions used for the buttons. */
  private void initActions() {

    /*actionUndo = new AbstractAction() {
    	public void actionPerformed(ActionEvent ae) {
    		try {
    			// do redo
    			undoManager.undo();

    			// notify undo manager/toolbar of change
    			GUIPrism.getGUI().notifyEventListeners(
    					new GUIClipboardEvent(GUIClipboardEvent.UNDOMANAGER_CHANGE,
    							GUIPrism.getGUI().getFocussedPlugin().getFocussedComponent()));
    		} catch (CannotUndoException ex) {
    			//GUIPrism.getGUI().getMultiLogger().logMessage(PrismLogLevel.PRISM_ERROR, ex.getMessage());
    		}
    	}
    };
    actionUndo.putValue(Action.LONG_DESCRIPTION, "Undo the most recent action.");
    actionUndo.putValue(Action.NAME, "Undo");
    actionUndo.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallUndo.png"));

    actionRedo = new AbstractAction() {
    	public void actionPerformed(ActionEvent ae) {
    		try {
    			// do redo
    			undoManager.redo();

    			// notify undo manager/toolbar of change
    			GUIPrism.getGUI().notifyEventListeners(
    					new GUIClipboardEvent(GUIClipboardEvent.UNDOMANAGER_CHANGE,
    							GUIPrism.getGUI().getFocussedPlugin().getFocussedComponent()));
    		} catch (CannotRedoException ex) {
    			//GUIPrism.getGUI().getMultiLogger().logMessage(PrismLogLevel.PRISM_ERROR, ex.getMessage());
    		}
    	}
    };


    actionRedo.putValue(Action.LONG_DESCRIPTION, "Redos the most recent undo");
    actionRedo.putValue(Action.NAME, "Redo");
    actionRedo.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallRedo.png"));
    */
    actionJumpToError =
        new AbstractAction() {
          public void actionPerformed(ActionEvent ae) {
            jumpToError();
          }
        };

    actionJumpToError.putValue(Action.NAME, "Jump to error");
    actionJumpToError.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("tinyError.png"));
    actionJumpToError.putValue(
        Action.ACCELERATOR_KEY,
        KeyStroke.getKeyStroke(
            KeyEvent.VK_E, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    // search and replace action
    actionSearch =
        new AbstractAction() {
          public void actionPerformed(ActionEvent ae) {
            /*
                		// System.out.println("search button pressed");
                		if (GUIMultiModelHandler.isDoingSearch()) {

            } else {
            	try {
            		GUIMultiModelHandler.setDoingSearch(true);
            		FindReplaceForm.launch(GUIPrism.getGUI().getMultiModel());
            	} catch (PluginNotFoundException pnfe) {
            		GUIPrism.getGUI().getMultiLogger().logMessage(prism.log.PrismLogLevel.PRISM_ERROR,
            				pnfe.getMessage());
            	}
            }
            */
          }
        };
    actionSearch.putValue(Action.LONG_DESCRIPTION, "Opens a find and replace dialog.");
    // actionSearch.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("find.png"));
    actionSearch.putValue(Action.NAME, "Find/Replace");
    // actionSearch.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_R,
    // Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    insertDTMC =
        new AbstractAction() {
          public void actionPerformed(ActionEvent ae) {
            int caretPosition = editor.getCaretPosition();
            try {
              editor.getDocument().insertString(caretPosition, "dtmc", new SimpleAttributeSet());
            } catch (BadLocationException ble) {
              // todo log?
            }
          }
        };

    insertDTMC.putValue(
        Action.LONG_DESCRIPTION, "Marks this model as a \"Discrete-Time Markov Chain\"");
    // actionSearch.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("find.png"));
    insertDTMC.putValue(Action.NAME, "Probabilistic (DTMC)");

    insertCTMC =
        new AbstractAction() {
          public void actionPerformed(ActionEvent ae) {
            int caretPosition = editor.getCaretPosition();
            try {
              editor.getDocument().insertString(caretPosition, "ctmc", new SimpleAttributeSet());
            } catch (BadLocationException ble) {
              // todo log?
            }
          }
        };

    insertCTMC.putValue(
        Action.LONG_DESCRIPTION, "Marks this model as a \"Continous-Time Markov Chain\"");
    // actionSearch.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("find.png"));
    insertCTMC.putValue(Action.NAME, "Stochastic (CTMC)");

    insertMDP =
        new AbstractAction() {
          public void actionPerformed(ActionEvent ae) {
            int caretPosition = editor.getCaretPosition();
            try {
              editor.getDocument().insertString(caretPosition, "mdp", new SimpleAttributeSet());
            } catch (BadLocationException ble) {
              // todo log?
            }
          }
        };

    insertMDP.putValue(
        Action.LONG_DESCRIPTION, "Marks this model as a \"Markov Decision Process\"");
    // actionSearch.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("find.png"));
    insertMDP.putValue(Action.NAME, "Non-deterministic (MDP)");
  }
Esempio n. 14
0
  /**
   * Constructor, initialises the editor components.
   *
   * @param initialText The initial text to be displayed in the editor.
   * @param handler The GUI handler for this component.
   */
  public GUITextModelEditor(String initialText, GUIMultiModelHandler handler) {
    this.handler = handler;
    setLayout(new BorderLayout());

    // Setup the editor with it's custom editor kits. To switch between
    // editor kits just use setContentType() for the desired content type.
    editor =
        new JEditorPane() {
          @Override
          public String getToolTipText(MouseEvent event) {
            if (parseError != null) {
              try {
                int offset = this.viewToModel(new Point(event.getX(), event.getY()));

                int startOffset =
                    computeDocumentOffset(parseError.getBeginLine(), parseError.getBeginColumn());
                int endOffset =
                    computeDocumentOffset(parseError.getEndLine(), parseError.getEndColumn()) + 1;

                if (offset >= startOffset && offset <= endOffset) return parseError.getMessage();
              } catch (BadLocationException e) {
              }
            }

            return null;
          }
        };

    editor.setToolTipText("dummy");

    editor.setEditorKitForContentType("text/prism", new PrismEditorKit(handler));
    editor.setEditorKitForContentType("text/pepa", new PepaEditorKit(handler));
    // The default editor kit is the Prism one.
    editor.setContentType("text/prism");
    editor.setBackground(Color.white);
    editor.addMouseListener(editorMouseListener);
    editor.setEditable(true);
    editor.setText(initialText);
    editor.getDocument().addDocumentListener(this);
    editor.addCaretListener(
        new CaretListener() {
          public void caretUpdate(CaretEvent e) {
            GUITextModelEditor.this
                .handler
                .getGUIPlugin()
                .getSelectionChangeHandler()
                .notifyListeners(new GUIEvent(1));
          }
        });
    editor.getDocument().putProperty(PlainDocument.tabSizeAttribute, new Integer(4));

    editor.addMouseListener(this);
    errorHighlightPainter =
        new DefaultHighlighter.DefaultHighlightPainter(new Color(255, 192, 192));
    undoManager = new GUIUndoManager(GUIPrism.getGUI());
    undoManager.setLimit(200);

    // Setup the scrollpane
    editorScrollPane = new JScrollPane(editor);
    add(editorScrollPane, BorderLayout.CENTER);
    gutter = new GUITextModelEditorGutter(editor);

    // Get the 'show line numbers' setting to determine
    // if the line numbers should be shown.
    showLineNumbersSetting =
        handler
            .getGUIPlugin()
            .getPrism()
            .getSettings()
            .getBoolean(PrismSettings.MODEL_SHOW_LINE_NUMBERS);
    if (showLineNumbersSetting) {
      editorScrollPane.setRowHeaderView(gutter);
    }

    // Add a Prism settings listener to catch changes made to the
    // 'show line numbers' setting.
    handler
        .getGUIPlugin()
        .getPrism()
        .getSettings()
        .addSettingsListener(
            new PrismSettingsListener() {
              public void notifySettings(PrismSettings settings) {
                // Check if the setting has changed.
                if (settings.getBoolean(PrismSettings.MODEL_SHOW_LINE_NUMBERS)
                    != showLineNumbersSetting) {
                  showLineNumbersSetting = !showLineNumbersSetting;
                  if (showLineNumbersSetting) {
                    editorScrollPane.setRowHeaderView(gutter);
                  } else {
                    editorScrollPane.setRowHeaderView(null);
                  }
                }
              }
            });

    // initialize the actions for the context menu
    initActions();

    // method to initialize the context menu popup
    initContextMenu();

    InputMap inputMap = editor.getInputMap();
    inputMap.clear();

    inputMap.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
        "prism_undo");
    inputMap.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
        "prism_undo");
    inputMap.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
        "prism_redo");
    inputMap.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
        "prism_selectall");
    inputMap.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
        "prism_delete");
    inputMap.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
        "prism_cut");
    inputMap.put(
        KeyStroke.getKeyStroke(
            KeyEvent.VK_Z,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
                | java.awt.event.InputEvent.SHIFT_MASK),
        "prism_redo");
    inputMap.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
        "prism_paste");
    inputMap.put(
        KeyStroke.getKeyStroke(KeyEvent.VK_E, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
        "prism_jumperr");

    ActionMap actionMap = editor.getActionMap();
    actionMap.put("prism_undo", GUIPrism.getClipboardPlugin().getUndoAction());
    actionMap.put("prism_redo", GUIPrism.getClipboardPlugin().getRedoAction());
    actionMap.put("prism_selectall", GUIPrism.getClipboardPlugin().getSelectAllAction());
    actionMap.put("prism_cut", GUIPrism.getClipboardPlugin().getCutAction());
    actionMap.put("prism_copy", GUIPrism.getClipboardPlugin().getCopyAction());
    actionMap.put("prism_paste", GUIPrism.getClipboardPlugin().getPasteAction());
    actionMap.put("prism_delete", GUIPrism.getClipboardPlugin().getDeleteAction());
    actionMap.put("prism_jumperr", actionJumpToError);

    // Attempt to programmatically allow all accelerators
    /*ArrayList plugins = ((GUIMultiModel)handler.getGUIPlugin()).getGUI().getPlugins();
    Iterator it = plugins.iterator();

    while (it.hasNext())
    {
    	GUIPlugin plugin = ((GUIPlugin)it.next());
    	System.out.println(plugin.getName());
    	JMenu firstMenu = plugin.getMenu();

    	Stack<MenuElement> menuStack = new Stack<MenuElement>();

    	menuStack.add(firstMenu);

    	while (!menuStack.empty())
    	{
    		MenuElement menu = menuStack.pop();

    		if (menu instanceof JMenuItem)
    		{
    			JMenuItem menuItem = ((JMenuItem)menu);

    			KeyStroke accelerator = menuItem.getAccelerator();
    			Action action = menuItem.getAction();

    			if (action != null && accelerator != null && menuItem.getText() != null)
    			{
    				System.out.println(menuItem.getText() + " " + menuItem.getName());
    				inputMap.put(accelerator, "prism_" + menuItem.getText());
    				actionMap.put("prism_" + menuItem.getText(), action);
    			}
    		}

    		MenuElement[] subelements = menu.getSubElements();

    		if (subelements != null)
    		{
    			for (int i = 0; i < subelements.length; i++)
    				menuStack.push(subelements[i]);
    		}
    	}
    }*/

    editor.getDocument().addUndoableEditListener(undoManager);
    editor
        .getDocument()
        .addUndoableEditListener(
            new UndoableEditListener() {
              public void undoableEditHappened(UndoableEditEvent e) {
                System.out.println("adding undo edit");
              }
            });
  }