Example usage for javax.swing JComponent WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

List of usage examples for javax.swing JComponent WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

Introduction

In this page you can find the example usage for javax.swing JComponent WHEN_ANCESTOR_OF_FOCUSED_COMPONENT.

Prototype

int WHEN_ANCESTOR_OF_FOCUSED_COMPONENT

To view the source code for javax.swing JComponent WHEN_ANCESTOR_OF_FOCUSED_COMPONENT.

Click Source Link

Document

Constant used for registerKeyboardAction that means that the command should be invoked when the receiving component is an ancestor of the focused component or is itself the focused component.

Usage

From source file:de.tor.tribes.ui.views.DSWorkbenchFormFrame.java

/** Creates new form DSWorkbenchFormFrame */
DSWorkbenchFormFrame() {//from w  w  w  .j  av a2 s . c o  m
    initComponents();
    centerPanel = new GenericTestPanel();
    jFormPanel.add(centerPanel, BorderLayout.CENTER);
    centerPanel.setChildComponent(jFormTablePanel);
    jFormsTable.setModel(new FormTableModel());
    jFormsTable.getSelectionModel().addListSelectionListener(DSWorkbenchFormFrame.this);
    buildMenu();

    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false);
    KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false);
    KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false);
    KeyStroke find = KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK, false);
    capabilityInfoPanel1.addActionListener(this);
    jFormsTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DSWorkbenchFormFrame.getSingleton().actionPerformed(new ActionEvent(jFormsTable, 0, "Copy"));
        }
    }, "Copy", copy, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    jFormsTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DSWorkbenchFormFrame.getSingleton().actionPerformed(new ActionEvent(jFormsTable, 0, "BBCopy"));
        }
    }, "BBCopy", bbCopy, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    jFormsTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DSWorkbenchFormFrame.getSingleton().actionPerformed(new ActionEvent(jFormsTable, 0, "Delete"));
        }
    }, "Delete", delete, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    jFormsTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //no find
        }
    }, "Find", find, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.form_view",
                GlobalOptions.getHelpBroker().getHelpSet());
    }
    // </editor-fold>
}

From source file:de.tor.tribes.ui.views.DSWorkbenchDistanceFrame.java

/**
 * Creates new form DSWorkbenchDistanceFrame
 *///w w w  . j  a v a2  s .c om
DSWorkbenchDistanceFrame() {
    initComponents();
    centerPanel = new GenericTestPanel(true);
    jDistancePanel.add(centerPanel, BorderLayout.CENTER);
    centerPanel.setChildComponent(jPanel2);
    unitBox = new JComboBox();
    unitBox.setRenderer(new UnitListCellRenderer());
    unitBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            cellRenderer.setUnit((UnitHolder) unitBox.getSelectedItem());
            jDistanceTable.repaint();
        }
    });
    buildMenu();
    jDistanceTable.setModel(new DistanceTableModel());
    KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false);
    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK, false);
    capabilityInfoPanel1.addActionListener(this);
    jDistanceTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DSWorkbenchDistanceFrame.getSingleton()
                    .actionPerformed(new ActionEvent(jDistanceTable, 0, "Delete"));
        }
    }, "Delete", delete, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jDistanceTable.registerKeyboardAction(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DSWorkbenchDistanceFrame.getSingleton()
                    .actionPerformed(new ActionEvent(jDistanceTable, 0, "Paste"));
        }
    }, "Paste", paste, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jDistanceTable.getActionMap().put("find", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //disable find
        }
    });
    jDistanceTable.getSelectionModel().addListSelectionListener(DSWorkbenchDistanceFrame.this);
    cellRenderer.setUnit(UnknownUnit.getSingleton());

    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.distance_overview",
                GlobalOptions.getHelpBroker().getHelpSet());
    }
    // </editor-fold>
}

From source file:JXButtonPanel.java

private void init() {
    setFocusTraversalPolicyProvider(true);
    setFocusTraversalPolicy(new JXButtonPanelFocusTraversalPolicy());
    ActionListener actionHandler = new ActionHandler();
    registerKeyboardAction(actionHandler, ActionHandler.FORWARD, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0),
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    registerKeyboardAction(actionHandler, ActionHandler.FORWARD, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0),
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    registerKeyboardAction(actionHandler, ActionHandler.BACKWARD, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0),
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    registerKeyboardAction(actionHandler, ActionHandler.BACKWARD, KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0),
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    setGroupSelectionFollowFocus(true);/* w  w w. j av  a 2  s .c om*/
}

From source file:org.angnysa.yaba.swing.BudgetFrame.java

private void buildTransactionTable() {
    transactionModel = new TransactionTableModel(service);
    transactionTable = new JTable(transactionModel);
    transactionTable.setRowHeight((int) (transactionTable.getRowHeight() * 1.2));
    transactionTable.getColumnModel().getColumn(TransactionTableModel.COL_END)
            .setCellEditor(new CustomCellEditor(
                    new JFormattedTextField(new OptionalValueFormatter(new JodaLocalDateFormat()))));
    transactionTable.setDefaultEditor(LocalDate.class,
            new CustomCellEditor(new JFormattedTextField(new JodaLocalDateFormat())));
    transactionTable.setDefaultEditor(ReadablePeriod.class,
            new CustomCellEditor(new JFormattedTextField(new OptionalValueFormatter(new JodaPeriodFormat()))));
    transactionTable.setDefaultEditor(Double.class,
            new CustomCellEditor(new JFormattedTextField(NumberFormat.getNumberInstance())));
    transactionTable.setDefaultRenderer(LocalDate.class,
            new FormattedTableCellRenderer(new JodaLocalDateFormat()));
    transactionTable.setDefaultRenderer(ReadablePeriod.class,
            new FormattedTableCellRenderer(new JodaPeriodFormat()));
    transactionTable.setDefaultRenderer(Double.class,
            new FormattedTableCellRenderer(TransactionAmountFormatFactory.getFormat()));
    transactionTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    transactionTable.setAutoCreateRowSorter(true);
    transactionTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete"); //$NON-NLS-1$
    transactionTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "delete"); //$NON-NLS-1$
    transactionTable.getActionMap().put("delete", new AbstractAction() { //$NON-NLS-1$
        private static final long serialVersionUID = 1L;

        @Override// w ww.  j  ava 2  s . com
        public void actionPerformed(ActionEvent e) {

            int row = transactionTable.getSelectedRow();
            if (row >= 0) {
                row = transactionTable.getRowSorter().convertRowIndexToModel(row);
                transactionModel.deleteRow(row);
            }
        }
    });
}

From source file:de.tor.tribes.ui.views.DSWorkbenchSOSRequestAnalyzer.java

/**
 * Creates new form DSWorkbenchSOSRequestAnalyzer
 */// www .j  a  v a2 s.  c  o m
DSWorkbenchSOSRequestAnalyzer() {
    initComponents();
    centerPanel = new GenericTestPanel(true);
    jSOSPanel.add(centerPanel, BorderLayout.CENTER);
    centerPanel.setChildComponent(jSOSInputPanel);
    buildMenu();
    jButton1.setIcon(new ImageIcon("./graphics/big/find.png"));
    capabilityInfoPanel1.addActionListener(DSWorkbenchSOSRequestAnalyzer.this);
    //  KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false);
    KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false);
    KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false);
    //KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK, false);
    // jAttacksTable.registerKeyboardAction(DSWorkbenchSOSRequestAnalyzer.this, "Copy", copy, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jAttacksTable.registerKeyboardAction(DSWorkbenchSOSRequestAnalyzer.this, "BBCopy", bbCopy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jAttacksTable.registerKeyboardAction(DSWorkbenchSOSRequestAnalyzer.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    // jAttacksTable.registerKeyboardAction(DSWorkbenchSOSRequestAnalyzer.this, "Cut", cut, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jAttacksTable.getActionMap().put("find", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //ignore find
        }
    });

    jAttacksTable.setModel(new DefenseToolModel());
    jAttacksTable.setHighlighters(
            HighlighterFactory.createAlternateStriping(Constants.DS_ROW_A, Constants.DS_ROW_B));
    jAttacksTable.getColumnExt("Tendenz").setCellRenderer(new TendencyTableCellRenderer());
    jAttacksTable.getColumnExt("Status").setCellRenderer(new DefenseStatusTableCellRenderer());
    //jAttacksTable.getColumnExt("Wall").setCellRenderer(new WallLevellCellRenderer());
    jAttacksTable.getColumnExt("Verlustrate").setCellRenderer(new LossRatioTableCellRenderer());
    jAttacksTable.setDefaultRenderer(Date.class, new DateCellRenderer());
    jAttacksTable.setColumnControlVisible(false);
    jAttacksTable.setDefaultRenderer(Date.class, new DateCellRenderer());
    jAttacksTable.getTableHeader().setDefaultRenderer(new DefaultTableHeaderRenderer());
    jAttacksTable.requestFocus();

    jSupportsTable.setModel(new SupportsModel());
    jSupportsTable.setHighlighters(
            HighlighterFactory.createAlternateStriping(Constants.DS_ROW_A, Constants.DS_ROW_B));
    jSupportsTable.getTableHeader().setDefaultRenderer(new DefaultTableHeaderRenderer());
    jSupportsTable.setDefaultRenderer(Date.class, new ColoredDateCellRenderer());
    jSupportsTable.setDefaultRenderer(Boolean.class,
            new CustomBooleanRenderer(CustomBooleanRenderer.LayoutStyle.SENT_NOTSENT));

    new SupportCountdownThread().start();
    new SupportColorUpdateThread().start();
    jXInfoLabel.setLineWrap(true);

    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.sos_analyzer",
                GlobalOptions.getHelpBroker().getHelpSet());
    }
    // </editor-fold>
}

From source file:de.tor.tribes.ui.views.DSWorkbenchTagFrame.java

/** Creates new form DSWorkbenchTagFrame */
DSWorkbenchTagFrame() {/*from   w w  w. ja v a 2s .c  o  m*/
    initComponents();
    centerPanel = new GenericTestPanel();
    jTagPanel.add(centerPanel, BorderLayout.CENTER);
    centerPanel.setChildComponent(jTagsPanel);
    buildMenu();
    capabilityInfoPanel1.addActionListener(this);
    jTagsTable.setModel(new TagTableModel());
    jTagsTable.getSelectionModel().addListSelectionListener(DSWorkbenchTagFrame.this);
    jTagsTable.getActionMap().put("find", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //ignore find
        }
    });

    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK, false);
    KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false);
    KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false);
    jTagsTable.registerKeyboardAction(DSWorkbenchTagFrame.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jTagsTable.registerKeyboardAction(DSWorkbenchTagFrame.this, "BBCopy", bbCopy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVillageList.registerKeyboardAction(DSWorkbenchTagFrame.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVillageList.registerKeyboardAction(DSWorkbenchTagFrame.this, "BBCopy_Village", bbCopy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jTagsTable.registerKeyboardAction(DSWorkbenchTagFrame.this, "Paste", paste,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.tag_view",
                GlobalOptions.getHelpBroker().getHelpSet());
    }
    // </editor-fold>

    initialize();
    pack();
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopComponentsHelper.java

/**
 * Add shortcut action to any JComponent.
 *
 * @param name name of action that used as action key in {@link InputMap} and {@link ActionMap}.
 * @param component/* w w w . ja v a2 s. co  m*/
 * @param key
 * @param action
 */
public static void addShortcutAction(String name, JComponent component, KeyStroke key, Action action) {
    ActionMap actionMap = component.getActionMap();
    InputMap inputMap = component.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(key, name);
    actionMap.put(name, action);
}

From source file:de.tor.tribes.ui.views.DSWorkbenchDoItYourselfAttackPlaner.java

/**
 * Creates new form DSWorkbenchDoItYourselflAttackPlaner
 *//* w w w.j a v a2 s  . c om*/
DSWorkbenchDoItYourselfAttackPlaner() {
    initComponents();

    jAttackTable.setModel(new DoItYourselfAttackTableModel());
    jAttackTable.getSelectionModel().addListSelectionListener(DSWorkbenchDoItYourselfAttackPlaner.this);

    jArriveTime.setDate(Calendar.getInstance().getTime());
    jNewArriveSpinner.setDate(Calendar.getInstance().getTime());
    capabilityInfoPanel1.addActionListener(this);
    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false);
    KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false);
    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK, false);
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK, false);
    KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false);
    jAttackTable.registerKeyboardAction(DSWorkbenchDoItYourselfAttackPlaner.this, "Copy", copy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jAttackTable.registerKeyboardAction(DSWorkbenchDoItYourselfAttackPlaner.this, "Cut", cut,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jAttackTable.registerKeyboardAction(DSWorkbenchDoItYourselfAttackPlaner.this, "Paste", paste,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jAttackTable.registerKeyboardAction(DSWorkbenchDoItYourselfAttackPlaner.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jAttackTable.registerKeyboardAction(DSWorkbenchDoItYourselfAttackPlaner.this, "BBCopy", bbCopy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jAttackTable.getActionMap().put("find", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //no find
        }
    });

    DoItYourselfCountdownThread thread = new DoItYourselfCountdownThread();
    thread.start();

    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.manual_attack_planer",
                GlobalOptions.getHelpBroker().getHelpSet());
    }
    // </editor-fold>
    pack();
}

From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java

public void setTabsPane(final JTabbedPane tabsPane) {
    this.tabsPane = tabsPane;

    // todo move to config
    tabsPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("control W"),
            "closeTab");
    tabsPane.getActionMap().put("closeTab", new ValidationAwareAction() {
        @Override//from w ww  .ja  v a 2 s.  c om
        public void actionPerformedAfterValidation(ActionEvent e) {
            closeTab((JComponent) tabsPane.getSelectedComponent());
        }
    });
}

From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java

/** Creates new form DSWorkbenchReTimerFrame */
DSWorkbenchReTimerFrame() {/*from  w w w . j av  a 2s  .c om*/
    initComponents();

    centerPanel = new GenericTestPanel(true);
    jReTimePanel.add(centerPanel, BorderLayout.CENTER);
    centerPanel.setChildComponent(jideRetimeTabbedPane);
    jideRetimeTabbedPane.setTabShape(JideTabbedPane.SHAPE_OFFICE2003);
    jideRetimeTabbedPane.setTabColorProvider(JideTabbedPane.ONENOTE_COLOR_PROVIDER);
    jideRetimeTabbedPane.setBoldActiveTab(true);
    jideRetimeTabbedPane.addTab("Festlegen des Angriffs", jInputPanel);
    jideRetimeTabbedPane.addTab("Errechnete Gegenangriffe", jResultPanel);
    buildMenu();
    capabilityInfoPanel1.addActionListener(this);
    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false);
    KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false);
    KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false);
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK, false);
    jResultTable.registerKeyboardAction(DSWorkbenchReTimerFrame.this, "Copy", copy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jResultTable.registerKeyboardAction(DSWorkbenchReTimerFrame.this, "BBCopy", bbCopy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jResultTable.registerKeyboardAction(DSWorkbenchReTimerFrame.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jResultTable.registerKeyboardAction(DSWorkbenchReTimerFrame.this, "Cut", cut,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jResultTable.getActionMap().put("find", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //ignore find
        }
    });
    jCommandArea.setPrompt("<Angriffsbefehl hier einfgen>");
    jResultTable.getSelectionModel().addListSelectionListener(DSWorkbenchReTimerFrame.this);
    jPossibleUnits.setCellRenderer(new UnitListCellRenderer());
    jPossibleUnits.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                updateAttackBBView();
            }
        }
    });

    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.retime_tool",
                GlobalOptions.getHelpBroker().getHelpSet());
    }
    // </editor-fold>
}