Example usage for javax.swing JTextPane getActionMap

List of usage examples for javax.swing JTextPane getActionMap

Introduction

In this page you can find the example usage for javax.swing JTextPane getActionMap.

Prototype

public final ActionMap getActionMap() 

Source Link

Document

Returns the ActionMap used to determine what Action to fire for particular KeyStroke binding.

Usage

From source file:com.hp.alm.ali.idea.ui.editor.field.HTMLAreaField.java

public static void installNavigationShortCuts(final JTextPane desc) {
    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // default action moves to the end of the document - override
            desc.getActionMap().get(DefaultEditorKit.endLineAction).actionPerformed(null);
        }/*  w  w  w . ja v  a2  s  .c o  m*/
    }.registerCustomShortcutSet(
            new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_EDITOR_MOVE_LINE_END)), desc);
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // default action moves to the beginning of the document - override
            desc.getActionMap().get(DefaultEditorKit.beginLineAction).actionPerformed(null);
        }
    }.registerCustomShortcutSet(
            new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_EDITOR_MOVE_LINE_START)), desc);
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // default action moves to the end of the document - override
            desc.getActionMap().get(DefaultEditorKit.selectionEndLineAction).actionPerformed(null);
        }
    }.registerCustomShortcutSet(
            new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_END, InputEvent.SHIFT_MASK)), desc);
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // default action moves to the beginning of the document - override
            desc.getActionMap().get(DefaultEditorKit.selectionBeginLineAction).actionPerformed(null);
        }
    }.registerCustomShortcutSet(
            new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, InputEvent.SHIFT_MASK)), desc);
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // when editing html insert hard break
            new InsertHardBreakAction().actionPerformed(null);
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)), desc);
}

From source file:com.hp.alm.ali.idea.ui.editor.field.HTMLAreaField.java

public static void enableCapability(final JTextPane desc, Project project, String value, boolean editable,
        boolean navigation) {
    value = removeSmallFont(value);/*from ww  w.j  a  v a2 s.c  om*/
    HTMLEditorKit kit = new HTMLLetterWrappingEditorKit();
    desc.setEditorKit(kit);
    desc.setDocument(kit.createDefaultDocument());
    if (!editable && navigation) {
        value = NavigationDecorator.explodeHtml(project, value);
    }
    desc.setText(value);
    if (!editable) {
        desc.setCaret(new NonAdjustingCaret());
    }
    desc.addCaretListener(new BodyLimitCaretListener(desc));
    if (editable) {
        String element = checkElements(desc.getDocument().getDefaultRootElement());
        if (element != null) {
            desc.setToolTipText("Found unsupported element '" + element + "', editing is disabled.");
            editable = false;
        }
    }
    desc.setEditable(editable);

    if (editable && SpellCheckerManager.isAvailable()
            && ApplicationManager.getApplication().getComponent(AliConfiguration.class).spellChecker) {
        desc.getDocument().addDocumentListener(new SpellCheckDocumentListener(project, desc));
    }

    Font font = UIManager.getFont("Label.font");
    String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize()
            + "pt; }";
    ((HTMLDocument) desc.getDocument()).getStyleSheet().addRule(bodyRule);

    // AGM uses plain "p" to create lines, we need to avoid excessive spacing this by default creates
    String paragraphRule = "p { margin-top: 0px; }";
    ((HTMLDocument) desc.getDocument()).getStyleSheet().addRule(paragraphRule);

    Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // following is needed to make copy work in the IDE
            try {
                StringSelection selection = new StringSelection(desc.getText(desc.getSelectionStart(),
                        desc.getSelectionEnd() - desc.getSelectionStart()));
                CopyPasteManager.getInstance().setContents(selection);
            } catch (Exception ex) {
                // no clipboard, so what
            }
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_COPY)), desc);
    new AnAction() {
        public void actionPerformed(AnActionEvent e) {
            // avoid pasting non-supported HTML markup by always converting to plain text
            Transferable contents = CopyPasteManager.getInstance().getContents();
            try {
                desc.getActionMap().get(DefaultEditorKit.cutAction).actionPerformed(null);
                desc.getDocument().insertString(desc.getSelectionStart(),
                        (String) contents.getTransferData(DataFlavor.stringFlavor), null);
            } catch (Exception ex) {
                // no clipboard, so what
            }
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_PASTE)), desc);
    installNavigationShortCuts(desc);

}

From source file:org.executequery.gui.ExportResultSetPanel.java

private void init() throws Exception {

    fileNameField = WidgetFactory.createTextField();
    connectionsCombo = WidgetFactory.createComboBox();

    String[] delims = { "|", ",", ";", "#" };
    delimiterCombo = WidgetFactory.createComboBox(delims);
    delimiterCombo.setEditable(true);//from   www .  java 2  s  .  c o  m

    combosGroup = new TableSelectionCombosGroup(connectionsCombo);

    includeColumNamesCheck = new JCheckBox("Include column names as first row");

    sqlText = new SimpleSqlTextPanel();
    //        sqlText.getTextPane().setBackground(Color.WHITE);
    sqlText.setBorder(null);
    sqlText.setScrollPaneBorder(BorderFactory.createMatteBorder(1, 1, 0, 1, UIUtils.getDefaultBorderColour()));

    statusBar = new SqlTextPaneStatusBar();
    JPanel sqlPanel = new JPanel(new BorderLayout());
    sqlPanel.add(sqlText, BorderLayout.CENTER);
    sqlPanel.add(statusBar, BorderLayout.SOUTH);
    statusBar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 1));

    outputPanel = new LoggingOutputPanel();
    FlatSplitPane splitPane = new FlatSplitPane(JSplitPane.VERTICAL_SPLIT, sqlPanel, outputPanel);
    splitPane.setResizeWeight(0.5);
    splitPane.setDividerLocation(0.8);
    splitPane.setDividerSize(5);

    JButton button = WidgetFactory.createInlineFieldButton("Browse");
    button.setActionCommand("browse");
    button.addActionListener(this);
    button.setMnemonic('r');

    JPanel mainPanel = new JPanel(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridy = 0;
    gbc.gridx = 0;
    gbc.gridheight = 1;
    gbc.insets.top = 5;
    gbc.insets.bottom = 5;
    gbc.insets.right = 5;
    gbc.insets.left = 5;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    mainPanel.add(new JLabel("Connection:"), gbc);
    gbc.gridx = 1;
    gbc.weightx = 1.0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(connectionsCombo, gbc);
    gbc.insets.left = 5;
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.weightx = 0;
    gbc.gridwidth = 1;
    gbc.insets.top = 0;
    mainPanel.add(new JLabel("Data Delimiter:"), gbc);
    gbc.gridx = 1;
    gbc.weightx = 1.0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(delimiterCombo, gbc);
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.weightx = 0;
    gbc.gridwidth = 1;
    gbc.insets.top = 2;
    mainPanel.add(new JLabel("Output File:"), gbc);
    gbc.gridx = 1;
    gbc.weightx = 1.0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(fileNameField, gbc);
    gbc.gridx = 2;
    gbc.weightx = 0;
    gbc.insets.left = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    mainPanel.add(button, gbc);
    gbc.gridy++;
    gbc.gridx = 0;
    gbc.weightx = 0;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets.top = 2;
    gbc.insets.left = 5;
    mainPanel.add(includeColumNamesCheck, gbc);
    gbc.gridy++;
    gbc.insets.bottom = 10;
    mainPanel.add(new JLabel(instructionNote()), gbc);

    gbc.gridy++;
    gbc.gridx = 0;
    gbc.weighty = 1.0;
    gbc.weightx = 1.0;
    gbc.insets.top = 0;
    gbc.insets.left = 5;
    gbc.insets.bottom = 5;
    gbc.fill = GridBagConstraints.BOTH;
    mainPanel.add(splitPane, gbc);

    mainPanel.setBorder(BorderFactory.createEtchedBorder());

    int minimumButtonWidth = 85;
    executeButton = new MinimumWidthActionButton(minimumButtonWidth, this, "Execute", "executeAndExport");
    stopButton = new MinimumWidthActionButton(minimumButtonWidth, this, "Stop", "stop");
    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 2, 5));
    buttonPanel.add(executeButton);
    buttonPanel.add(stopButton);

    stopButton.setEnabled(false);

    add(mainPanel, BorderLayout.CENTER);
    add(buttonPanel, BorderLayout.SOUTH);
    setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));

    // register as a keyword and connection listener
    EventMediator.registerListener(this);

    JTextPane textPane = sqlText.getTextPane();
    ActionMap actionMap = textPane.getActionMap();

    String actionKey = "executeQueryAction";
    actionMap.put(actionKey, executeQueryAction);

    InputMap inputMap = textPane.getInputMap();
    inputMap.put(EXECUTE_KEYSTROKE, actionKey);

    JPopupMenu popupMenu = sqlText.getPopup();
    popupMenu.addSeparator();
    popupMenu.add(executeQueryAction);
}