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:com.brainflow.application.toplevel.Brainflow.java

private void initializeToolBar() {

    CommandGroup mainToolbarGroup = new CommandGroup("main-toolbar");
    mainToolbarGroup.bind(getApplicationFrame());

    ToggleGroup interpToggleGroup = new ToggleGroup("toggle-interp-group");
    interpToggleGroup.bind(getApplicationFrame());

    OpenImageCommand openImageCommand = new OpenImageCommand();
    openImageCommand.bind(getApplicationFrame());

    SnapshotCommand snapshotCommand = new SnapshotCommand();
    snapshotCommand.bind(getApplicationFrame());

    CreateAxialViewCommand axialCommand = new CreateAxialViewCommand();
    axialCommand.bind(getApplicationFrame());
    axialCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    CreateSagittalViewCommand sagittalCommand = new CreateSagittalViewCommand();
    sagittalCommand.bind(getApplicationFrame());
    sagittalCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    CreateCoronalViewCommand coronalCommand = new CreateCoronalViewCommand();
    coronalCommand.bind(getApplicationFrame());
    coronalCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    CreateVerticalOrthogonalCommand vertCommand = new CreateVerticalOrthogonalCommand();
    vertCommand.bind(getApplicationFrame());
    vertCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    CreateHorizontalOrthogonalCommand horizCommand = new CreateHorizontalOrthogonalCommand();
    horizCommand.bind(getApplicationFrame());
    horizCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    CreateTriangularOrthogonalCommand triCommand = new CreateTriangularOrthogonalCommand();
    triCommand.bind(getApplicationFrame());
    triCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    CommandGroup orthoGroup = new CommandGroup("ortho-view-group");
    orthoGroup.bind(getApplicationFrame());

    final NextSliceCommand nextSliceCommand = new NextSliceCommand();
    nextSliceCommand.bind(getApplicationFrame());
    nextSliceCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    final PreviousSliceCommand previousSliceCommand = new PreviousSliceCommand();
    previousSliceCommand.bind(getApplicationFrame());
    previousSliceCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        public void eventDispatched(AWTEvent event) {
            if (event.getID() == KeyEvent.KEY_PRESSED) {
                KeyEvent ke = (KeyEvent) event;
                if (ke.getKeyCode() == KeyEvent.VK_LEFT) {
                    previousSliceCommand.execute();
                } else if (ke.getKeyCode() == KeyEvent.VK_RIGHT) {
                    nextSliceCommand.execute();
                }/*from ww w  .  j a  v  a2 s .co  m*/

            }

        }
    }, AWTEvent.KEY_EVENT_MASK);

    PageBackSliceCommand pageBackSliceCommand = new PageBackSliceCommand();
    pageBackSliceCommand.bind(getApplicationFrame());
    pageBackSliceCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    PageForwardSliceCommand pageForwardSliceCommand = new PageForwardSliceCommand();
    pageForwardSliceCommand.bind(getApplicationFrame());
    pageForwardSliceCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    IncreaseContrastCommand increaseContrastCommand = new IncreaseContrastCommand();
    increaseContrastCommand.bind(getApplicationFrame());
    increaseContrastCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    DecreaseContrastCommand decreaseContrastCommand = new DecreaseContrastCommand();
    decreaseContrastCommand.bind(getApplicationFrame());
    decreaseContrastCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    ToggleCommand nearest = new NearestInterpolationToggleCommand();
    nearest.bind(getApplicationFrame());
    decreaseContrastCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    ToggleCommand linear = new LinearInterpolationToggleCommand();
    linear.bind(getApplicationFrame());

    ToggleCommand cubic = new CubicInterpolationToggleCommand();
    cubic.bind(getApplicationFrame());

    ToggleCommand toggleAxisLabelCommand = new ToggleAxisLabelCommand();
    toggleAxisLabelCommand.bind(getApplicationFrame());

    JToolBar mainToolbar = mainToolbarGroup.createToolBar();
    //ActionCommand increaseContrastCommand = new IncreaseContrastCommand();
    //increaseContrastCommand.bind(brainFrame);
    //mainToolbar.add(increaseContrastCommand.getActionAdapter());

    //ActionCommand decreaseContrastCommand = new DecreaseContrastCommand();
    //decreaseContrastCommand.bind(brainFrame);
    //mainToolbar.add(decreaseContrastCommand.getActionAdapter());

    brainFrame.getContentPane().add(mainToolbar, BorderLayout.NORTH);

    //InputMap map = documentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    //for (KeyStroke ks : map.keys()) {
    //    System.out.println("key : " + ks);
    //}

}

From source file:brainflow.app.toplevel.BrainFlow.java

private void initializeMenu() {
    log.info("initializing Menu");

    GuiCommands.defaults().setButtonFactory(createToolBarButtonFactory());
    GuiCommands.defaults().setMenuFactory(createMenuFactory());
    //GuiCommands.defaults().

    GoToVoxelCommand gotoVoxelCommand = new GoToVoxelCommand();
    gotoVoxelCommand.bind(getApplicationFrame());
    gotoVoxelCommand.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    CommandGroup fileMenuGroup = new CommandGroup("file-menu");
    fileMenuGroup.bind(getApplicationFrame());

    CommandGroup viewMenuGroup = new CommandGroup("view-menu");
    viewMenuGroup.bind(getApplicationFrame());

    CommandGroup gotoMenuGroup = new CommandGroup("goto-menu");
    gotoMenuGroup.bind(getApplicationFrame());

    CommandBar menuBar = new CommandMenuBar();
    menuBar.setBorder(new EmptyBorder(2, 2, 2, 2));
    //menuBar.setBorder(new LineBorder(Color.black, 1));
    menuBar.setStretch(true);//from  w  w  w.  j ava  2s. c  o m

    // for nimbus look and feel
    menuBar.setPaintBackground(false);
    // for nimbus look and feel

    menuBar.add(fileMenuGroup.createMenuItem());
    menuBar.add(viewMenuGroup.createMenuItem());
    menuBar.add(gotoMenuGroup.createMenuItem());
    menuBar.setKey("menu");
    brainFrame.getDockableBarManager().addDockableBar(menuBar);

    MountFileSystemCommand mountFileSystemCommand = new MountFileSystemCommand();
    mountFileSystemCommand.bind(getApplicationFrame());

    ExitApplicationCommand exitCommand = new ExitApplicationCommand();
    exitCommand.bind(getApplicationFrame());

    ExpansionPointBuilder builder = fileMenuGroup.getExpansionPointBuilder();
    builder.add(pathMenu.getCommandGroup());
    builder.applyChanges();

    menuBar.add(DockWindowManager.getInstance().getDockMenu());

    JMenuItem favMenu = favoritesMenu.getCommandGroup().createMenuItem();
    favMenu.setMnemonic('F');
    menuBar.add(favMenu);

}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

/**
 * Creates new form TribeTribeAttackFrame
 *///w  ww .ja va2s  .c om
public TribeTribeAttackFrame() {
    initComponents();
    centerPanel = new GenericTestPanel();
    jMainPanel.add(centerPanel, BorderLayout.CENTER);
    centerPanel.setChildComponent(jxAttackPlanerPanel);
    buildMenu();
    capabilityInfoPanel1.addActionListener(this, jSourcesTable);
    capabilityInfoPanel2.addActionListener(this, jResultsTable);

    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);
    jSourcesTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Copy", copy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVictimTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Copy", copy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jResultsTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Copy", copy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jSourcesTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Paste", paste,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVictimTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Paste", paste,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jSourcesTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Cut", cut,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVictimTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Cut", cut,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jSourcesTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jVictimTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    jResultsTable.registerKeyboardAction(TribeTribeAttackFrame.this, "Delete", delete,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    jResultsTable.registerKeyboardAction(TribeTribeAttackFrame.this, "BBCopy", bbCopy,
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    Action noFind = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //no find
        }
    };
    jSourcesTable.getActionMap().put("find", noFind);
    jVictimTable.getActionMap().put("find", noFind);
    jResultsTable.getActionMap().put("find", noFind);

    jSourcesTable.getSelectionModel().addListSelectionListener(TribeTribeAttackFrame.this);
    jVictimTable.getSelectionModel().addListSelectionListener(TribeTribeAttackFrame.this);
    jResultsTable.getSelectionModel().addListSelectionListener(TribeTribeAttackFrame.this);

    jideTabbedPane1.setTabShape(JideTabbedPane.SHAPE_OFFICE2003);
    jideTabbedPane1.setTabColorProvider(JideTabbedPane.ONENOTE_COLOR_PROVIDER);
    jideTabbedPane1.setBoldActiveTab(true);
    TagManager.getSingleton().addManagerListener(TribeTribeAttackFrame.this);
    logPanel = new AlgorithmLogPanel();
    mLogFrame = new JFrame("Informationen zur Berechnung");
    mLogFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    mLogFrame.setLayout(new BorderLayout());
    mLogFrame.add(logPanel);
    mLogFrame.pack();
    mTroopSplitDialog = new TroopSplitDialog(TribeTribeAttackFrame.this, true);
    mSettingsPanel = new SettingsPanel(this);
    jSettingsContentPanel.add(mSettingsPanel, BorderLayout.CENTER);
    jAttackResultDetailsFrame.pack();
    jTargetResultDetailsFrame.pack();
    dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(TribeTribeAttackFrame.this, DnDConstants.ACTION_COPY_OR_MOVE,
            TribeTribeAttackFrame.this);
    new DropTarget(jSourcesTable, TribeTribeAttackFrame.this);
    new DropTarget(jVictimTable, TribeTribeAttackFrame.this);
    for (MouseListener l : jAllTargetsComboBox.getMouseListeners()) {
        jAllTargetsComboBox.removeMouseListener(l);
    }
    jAllTargetsComboBox.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            fireAddFilteredTargetVillages();
        }
    });

    filterDialog = new TroopFilterDialog(this, true);

    // <editor-fold defaultstate="collapsed" desc="Add selection listeners">
    jVillageGroupList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterSourceVillagesByGroupEvent();
            }
        }
    });
    jSourceContinentList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterSourceContinentEvent();
            }
        }
    });
    jTargetTribeList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterTargetByTribeEvent();
            }
        }
    });
    jTargetContinentList.addListSelectionListener(new ListSelectionListener() {

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

    jTargetAllyList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                fireFilterTargetByAllyEvent();
            }
        }
    });
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem ">
    if (!Constants.DEBUG) {
        GlobalOptions.getHelpBroker().enableHelp(jSourcePanel, "pages.attack_planer_source",
                GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelp(jTargetPanel, "pages.attack_planer_target",
                GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelp(mSettingsPanel, "pages.attack_planer_settings",
                GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelpKey(jResultFrame.getRootPane(), "pages.attack_planer_results",
                GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelpKey(jTargetResultDetailsFrame.getRootPane(),
                "pages.attack_planer_results_details_targets", GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelpKey(jAttackResultDetailsFrame.getRootPane(),
                "pages.attack_planer_results_details_sources", GlobalOptions.getHelpBroker().getHelpSet());
        GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.attack_planer",
                GlobalOptions.getHelpBroker().getHelpSet());
    }
    // </editor-fold>
}

From source file:com.limegroup.gnutella.gui.GUIUtils.java

/**
 * Fixes the InputMap to have the correct KeyStrokes registered for
 * actions on various OS's./*from  w  ww .  j  a va 2 s  .  com*/
 *
 * Currently, this fixes OSX to use the 'meta' key instead of hard-coding
 * it to use the 'control' key for actions such as 'select all', etc..
 */
public static void fixInputMap(JComponent jc) {
    InputMap map = jc.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    if (OSUtils.isMacOSX()) {
        replaceAction(map, 'A'); // select all
        replaceAction(map, 'C'); // copy
        replaceAction(map, 'V'); // paste
        replaceAction(map, 'X'); // cut
    }
}

From source file:brainflow.app.toplevel.BrainFlow.java

private void bindCommand(ActionCommand command, boolean installShortCut) {
    command.bind(getApplicationFrame());
    if (installShortCut) {
        command.installShortCut(documentPane, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    }/*w w  w  . j a  v  a  2  s .  c om*/
}

From source file:com.mirth.connect.client.ui.SettingsPanelResources.java

private void initComponents() {
    setLayout(new MigLayout("insets 12, novisualpadding, hidemode 3, fill"));
    setBackground(UIConstants.BACKGROUND_COLOR);

    JPanel resourceListPanel = new JPanel(new MigLayout("insets 0, novisualpadding, hidemode 3, fill"));
    resourceListPanel.setBackground(getBackground());
    resourceListPanel.setBorder(BorderFactory.createTitledBorder(
            BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(204, 204, 204)), "Resources",
            TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", 1, 11)));

    resourceTable = new MirthTable();
    resourceTable.setModel(/*from  w w  w  .  j  av a 2  s .c  o  m*/
            new RefreshTableModel(new Object[] { "Properties", "Name", "Type", "Global Scripts" }, 0) {
                @Override
                public boolean isCellEditable(int row, int column) {
                    if (row == 0) {
                        return column == GLOBAL_SCRIPTS_COLUMN;
                    } else {
                        return column == NAME_COLUMN || column == TYPE_COLUMN
                                || column == GLOBAL_SCRIPTS_COLUMN;
                    }
                }
            });
    resourceTable.setDragEnabled(false);
    resourceTable.setRowSelectionAllowed(true);
    resourceTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    resourceTable.setRowHeight(UIConstants.ROW_HEIGHT);
    resourceTable.setFocusable(true);
    resourceTable.setOpaque(true);
    resourceTable.getTableHeader().setReorderingAllowed(false);
    resourceTable.setEditable(true);
    resourceTable.setSortable(false);

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        resourceTable.setHighlighters(HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR,
                UIConstants.BACKGROUND_COLOR));
    }

    for (ResourceClientPlugin plugin : LoadedExtensions.getInstance().getResourceClientPlugins().values()) {
        propertiesPanelMap.put(plugin.getType(), plugin.getPropertiesPanel());
    }

    resourceTable.getColumnModel().getColumn(NAME_COLUMN).setCellEditor(new NameEditor());
    resourceTable.getColumnExt(NAME_COLUMN).setToolTipText("The unique name of the resource.");

    resourceTable.getColumnModel().getColumn(TYPE_COLUMN).setMinWidth(100);
    resourceTable.getColumnModel().getColumn(TYPE_COLUMN).setMaxWidth(200);
    resourceTable.getColumnModel().getColumn(TYPE_COLUMN)
            .setCellRenderer(new ComboBoxRenderer(propertiesPanelMap.keySet().toArray()));
    resourceTable.getColumnModel().getColumn(TYPE_COLUMN).setCellEditor(new ComboBoxEditor(resourceTable,
            propertiesPanelMap.keySet().toArray(), 1, true, new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent evt) {
                    typeComboBoxActionPerformed(evt);
                }
            }));
    resourceTable.getColumnExt(TYPE_COLUMN).setToolTipText("The type of resource.");

    resourceTable.getColumnModel().getColumn(GLOBAL_SCRIPTS_COLUMN).setMinWidth(80);
    resourceTable.getColumnModel().getColumn(GLOBAL_SCRIPTS_COLUMN).setMaxWidth(80);
    resourceTable.getColumnModel().getColumn(GLOBAL_SCRIPTS_COLUMN).setCellRenderer(new CheckBoxRenderer());
    resourceTable.getColumnModel().getColumn(GLOBAL_SCRIPTS_COLUMN).setCellEditor(new CheckBoxEditor());
    resourceTable.getColumnExt(GLOBAL_SCRIPTS_COLUMN).setToolTipText(
            "<html>If checked, libraries associated with the corresponding<br/>resource will be included in global script contexts.</html>");

    resourceTable.removeColumn(resourceTable.getColumnModel().getColumn(PROPERTIES_COLUMN));

    resourceTable.getSelectionModel().addListSelectionListener(this);

    resourceTable
            .setToolTipText("<html>Add or remove resources to use<br/>in specific channels/connectors.</html>");

    resourceTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "selectNextColumnCell");

    resourceListPanel.add(new JScrollPane(resourceTable), "grow, push");

    add(resourceListPanel, "grow, h 20%");

    for (ResourcePropertiesPanel panel : propertiesPanelMap.values()) {
        add(panel, "newline, grow, h 80%");
    }

    fillerPanel = new JPanel(new MigLayout("insets 5, novisualpadding, hidemode 3, fill", "", "[][grow]"));
    fillerPanel.setBackground(getBackground());
    fillerPanel.setBorder(BorderFactory.createTitledBorder(
            BorderFactory.createMatteBorder(1, 0, 0, 0, new Color(204, 204, 204)), "Resource Settings",
            TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", 1, 11)));
    fillerLabel = new JLabel("Select a resource from the table above.");
    fillerPanel.add(fillerLabel);

    exceptionTextPane = new JTextPane();
    exceptionTextPane.setBackground(new Color(224, 223, 227));
    exceptionTextPane.setEditable(false);
    exceptionScrollPane = new JScrollPane(exceptionTextPane);
    fillerPanel.add(exceptionScrollPane, "newline, grow");

    add(fillerPanel, "newline, grow, h 80%");
}

From source file:ca.phon.app.project.ProjectWindow.java

private MultiActionButton createCorpusButton() {
    MultiActionButton retVal = new MultiActionButton();

    ImageIcon newIcn = IconManager.getInstance().getIcon("places/folder", IconSize.SMALL);

    String s1 = "Corpus";
    String s2 = "Enter corpus name and press enter.  Press escape to cancel.";

    retVal.getTopLabel().setText(WorkspaceTextStyler.toHeaderText(s1));
    retVal.getTopLabel().setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    retVal.getTopLabel().setFont(FontPreferences.getTitleFont());
    retVal.getTopLabel().setIcon(newIcn);
    retVal.setAlwaysDisplayActions(true);

    retVal.setOpaque(false);//from  www. ja va  2 s.  c  o  m

    ImageIcon cancelIcn = IconManager.getInstance().getIcon("actions/button_cancel", IconSize.SMALL);
    ImageIcon cancelIcnL = cancelIcn;

    PhonUIAction btnSwapAct = new PhonUIAction(this, "onSwapNewAndCreateCorpus", retVal);
    btnSwapAct.putValue(Action.ACTION_COMMAND_KEY, "CANCEL_CREATE_ITEM");
    btnSwapAct.putValue(Action.NAME, "Cancel create");
    btnSwapAct.putValue(Action.SHORT_DESCRIPTION, "Cancel create");
    btnSwapAct.putValue(Action.SMALL_ICON, cancelIcn);
    btnSwapAct.putValue(Action.LARGE_ICON_KEY, cancelIcnL);
    retVal.addAction(btnSwapAct);

    JPanel corpusNamePanel = new JPanel(new BorderLayout());
    corpusNamePanel.setOpaque(false);

    final JTextField corpusNameField = new JTextField();
    corpusNameField.setDocument(new NameDocument());
    corpusNameField.setText("Corpus Name");
    corpusNamePanel.add(corpusNameField, BorderLayout.CENTER);

    ActionMap actionMap = retVal.getActionMap();
    actionMap.put(btnSwapAct.getValue(Action.ACTION_COMMAND_KEY), btnSwapAct);
    InputMap inputMap = retVal.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);

    inputMap.put(ks, btnSwapAct.getValue(Action.ACTION_COMMAND_KEY));

    retVal.setActionMap(actionMap);
    retVal.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);

    PhonUIAction createNewCorpusAct = new PhonUIAction(this, "onCreateCorpus", corpusNameField);
    createNewCorpusAct.putValue(Action.SHORT_DESCRIPTION, "Create new corpus folder");
    createNewCorpusAct.putValue(Action.SMALL_ICON,
            IconManager.getInstance().getIcon("actions/list-add", IconSize.SMALL));

    JButton createBtn = new JButton(createNewCorpusAct);
    corpusNamePanel.add(createBtn, BorderLayout.EAST);

    corpusNameField.setAction(createNewCorpusAct);

    // swap bottom component in new project button
    retVal.setBottomLabelText(WorkspaceTextStyler.toDescText(s2));
    retVal.add(corpusNamePanel, BorderLayout.CENTER);

    retVal.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
        }

        @Override
        public void focusGained(FocusEvent e) {
            corpusNameField.requestFocus();
        }
    });

    return retVal;
}

From source file:edu.ku.brc.af.ui.forms.FormViewObj.java

/**
 * Constructor with FormView definition.
 * @param view the definition of the view
 * @param altView indicates which AltViewIFace we will be using
 * @param mvParent the mvParent mulitview
 * @param formValidator the form's formValidator
 * @param options the options needed for creating the form
 * @param cellName the name of the outer form's cell for this view (subview)
 * @param bgColor bg color it should use
 *//*from  w  ww .  ja  v  a  2 s . c o  m*/
public FormViewObj(final ViewIFace view, final AltViewIFace altView, final MultiView mvParent,
        final FormValidator formValidator, final int options, final String cellName, final Class<?> dataClass,
        final Color bgColor) {
    this.view = view;
    this.altView = altView;
    this.mvParent = mvParent;
    this.cellName = cellName;
    this.dataClass = dataClass;
    this.bgColor = bgColor;

    businessRules = view.createBusinessRule();

    //XXX bug #9497: isEditing        = altView.getMode() == AltViewIFace.CreationMode.EDIT && MultiView.isOptionOn(options, MultiView.IS_EDITTING);
    isEditing = altView.getMode() == AltViewIFace.CreationMode.EDIT;

    boolean addSearch = mvParent != null
            && MultiView.isOptionOn(mvParent.getOptions(), MultiView.ADD_SEARCH_BTN);
    if (addSearch) {
        isEditing = false;
    }
    this.formViewDef = (FormViewDef) altView.getViewDef();

    // Figure columns
    try {
        JPanel panel = useDebugForm ? new FormDebugPanel() : (restrictablePanel = new RestrictablePanel());
        formLayout = new FormLayout(formViewDef.getColumnDef(), formViewDef.getRowDef());
        builder = new PanelBuilder(formLayout, panel);

    } catch (java.lang.NumberFormatException ex) {
        String msg = "Error in row or column definition for form: `" + view.getName() + "`\n" + ex.getMessage();
        UIRegistry.showError(msg);
        return;
    }

    mainComp = new JPanel(new BorderLayout());
    mainComp.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));

    if (mvParent == null) {
        builder.getPanel().setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    }
    if (bgColor != null) {
        builder.getPanel().setBackground(bgColor);
    }

    this.options = options;
    boolean isSingleObj = MultiView.isOptionOn(options, MultiView.IS_SINGLE_OBJ);
    boolean createResultSetController = MultiView.isOptionOn(options, MultiView.RESULTSET_CONTROLLER);
    boolean hideResultSetController = MultiView.isOptionOn(options, MultiView.HIDE_RESULTSET_CONTROLLER);
    boolean createViewSwitcher = MultiView.isOptionOn(options, MultiView.VIEW_SWITCHER);
    //boolean isNewObject                = MultiView.isOptionOn(options, MultiView.IS_NEW_OBJECT);
    boolean hideSaveBtn = MultiView.isOptionOn(options, MultiView.HIDE_SAVE_BTN);

    isNewlyCreatedDataObj = MultiView.isOptionOn(options, MultiView.IS_NEW_OBJECT);
    if (formValidator != null) {
        formValidator.setNewObj(isNewlyCreatedDataObj);
    }

    //MultiView.printCreateOptions("Creating Form "+altView.getName(), options);

    setValidator(formValidator);

    scrDateFormat = AppPrefsCache.getDateWrapper("ui", "formatting", "scrdateformat");

    AppPreferences.getRemote().addChangeListener("ui.formatting.viewfieldcolor", this);

    boolean addController = mvParent != null && view.getAltViews().size() > 1;

    // See if we need to add a Selector ComboBox
    isSelectorForm = StringUtils.isNotEmpty(view.getSelectorName());

    boolean addSelectorCBX = false;
    //log.debug(altView.getName()+"  "+altView.getMode()+"  "+AltViewIFace.CreationMode.EDIT);
    //if (isSelectorForm && isNewObject && altView.getMode() == AltViewIFace.CreationMode.EDIT)
    if (isSelectorForm && altView.getMode() == AltViewIFace.CreationMode.EDIT) {
        addSelectorCBX = true;
    }

    List<JComponent> comps = new ArrayList<JComponent>();

    int y = 1;
    // Here we create the JComboBox that enables the user to switch between forms
    // when creating a new object
    if (addSelectorCBX) {
        Vector<AltViewIFace> cbxList = new Vector<AltViewIFace>();
        cbxList.add(altView);
        for (AltViewIFace av : view.getAltViews()) {
            if (av != altView && av.getMode() == AltViewIFace.CreationMode.EDIT) {
                cbxList.add(av);
            }
        }
        JPanel p = new JPanel(new BorderLayout());
        p.setOpaque(false);

        p.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        selectorCBX = createComboBox(cbxList);
        selectorCBX.setRenderer(new SelectorCellRenderer());
        p.add(selectorCBX, BorderLayout.WEST);
        mainComp.add(p, BorderLayout.NORTH);

        if (mvParent != null) {
            selectorCBX.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ev) {
                    doSelectorWasSelected(mvParent, ev);
                }
            });
        }
        y += 2;
    }

    //
    // We will add the switchable UI if we are parented to a MultiView and have multiple AltViews
    //
    if (addController) // this says we are the "root" form
    {
        boolean saveWasAdded = false;

        // We want it on the left side of other buttons
        // so wee need to add it before the Save button
        JComponent valInfoBtn = createValidationIndicator(getUIComponent(), formValidator);
        if (valInfoBtn != null) {
            comps.add(valInfoBtn);
        }

        if (createViewSwitcher) // This is passed in outside
        {
            // Now we have a Special case that when when there are only two AltViews and
            // they differ only by Edit & View we hide the switching UI unless we are the root MultiView.
            // This way when switching the Root View all the other views switch
            // (This is because they were created that way. It also makes no sense that while in "View" mode
            // you would want to switch an individual subview to a differe "mode" view than the root).

            altViewsList = new Vector<AltViewIFace>();

            // This will return null if it isn't suppose to have a switcher
            switcherUI = createMenuSwitcherPanel(mvParent, view, altView, altViewsList, restrictablePanel,
                    cellName, dataClass);

            Action action = new AbstractAction() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    if (switcherUI != null && switcherUI.getSwitcherAL() != null) {
                        switcherUI.getSwitcherAL().actionPerformed(e);
                    }
                }
            };

            if (restrictablePanel != null) {
                restrictablePanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
                        .put(KeyStroke.getKeyStroke("control E"), actionName);
                restrictablePanel.getActionMap().put(actionName, action);
            }

            if (altViewsList.size() > 0) {
                if (altView.getMode() == AltViewIFace.CreationMode.EDIT && mvParent != null
                        && mvParent.isTopLevel()) {
                    addSaveBtn();
                    comps.add(saveControl);
                    saveWasAdded = true;
                }

                if (switcherUI != null) {
                    comps.add(switcherUI);

                }
            }

            // rods - 07/21/08 for disabling the switcher when the form is invalid 
            if (formValidator != null && switcherUI != null) {
                formValidator.addEnableItem(switcherUI, FormValidator.EnableType.ValidNotNew);
            }
        }

        if (!saveWasAdded && altView.getMode() == AltViewIFace.CreationMode.EDIT && mvParent != null
                && mvParent.isTopLevel() && !hideSaveBtn) {
            addSaveBtn();
            comps.add(saveControl);
        }
    }

    // This here because the Search mode shouldn't be combined with other modes
    if (altView.getMode() == AltViewIFace.CreationMode.SEARCH) {
        if (!hideSaveBtn) {
            saveControl = createButton(UIRegistry.getResourceString("SEARCH"),
                    IconManager.getImage("Search", IconManager.IconSize.Std16));/*
                                                                                {
                                                                                public void setEnabled(boolean enabled)
                                                                                {
                                                                                System.err.println("Save: "+enabled);
                                                                                super.setEnabled(enabled);
                                                                                }
                                                                                };*/
            saveControl.setOpaque(false);
            comps.add(saveControl);

            addSaveActionMap(saveControl);
        }

    }

    if (ViewFactory.isFormTransparent()) {
        builder.getPanel().setOpaque(false);
    }
    mainComp.add(builder.getPanel(), BorderLayout.CENTER);

    if (comps.size() > 0 || addController || createResultSetController) {
        controlPanel = new ControlBarPanel(bgColor);
        controlPanel.addComponents(comps, false); // false -> right side

        if (ViewFactory.isFormTransparent()) {
            controlPanel.setOpaque(false);
        }

        mainComp.add(controlPanel, BorderLayout.SOUTH);

    }

    if (createResultSetController) {
        addRSController(addSearch);
        if (hideResultSetController) {
            rsController.getPanel().setVisible(false);
        }
        if (addSearch) {
            DBTableInfo tblInfo = DBTableIdMgr.getInstance().getByClassName(view.getClassName());
            if (tblInfo != null) {
                searchName = tblInfo.getSearchDialog();
                if (StringUtils.isEmpty(searchName)) {
                    searchName = ""; // Note not null but empty tells it to disable the search btn

                    log.error("The Search Dialog Name is empty or missing for class[" + view.getClassName()
                            + "]");
                }
            } else {
                log.error("Couldn't find TableInfo for class[" + view.getClassName() + "]");
            }

            if (rsController.getSearchRecBtn() != null) {
                rsController.getSearchRecBtn().setEnabled(true);
                rsController.getSearchRecBtn().addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        doSearch();
                    }
                });
            }
        }

    } else if (isSingleObj) {
        createAddDelSearchPanel();
    }

    if (true) {
        builder.getPanel().addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                showContextMenu(e);
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                showContextMenu(e);

            }

            @Override
            public void mouseClicked(MouseEvent e) {
                //FormViewObj.this.listFieldChanges();
            }
        });
    }

    if (rsController != null) {
        rsController.setNewObj(isNewlyCreatedDataObj);
    }

    isBuildValid = true;

    isAutoNumberOn = AppPreferences.getLocalPrefs().getBoolean(AUTO_NUM, true);
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            updateAutoNumberFieldState();
        }
    });
}

From source file:ca.phon.app.project.ProjectWindow.java

private MultiActionButton createSessionButton() {
    MultiActionButton retVal = new MultiActionButton();

    ImageIcon newIcn = IconManager.getInstance().getIcon("mimetypes/text-xml", IconSize.SMALL);

    String s1 = "Session";
    String s2 = "Enter session name and press enter.  Press escape to cancel.";

    retVal.getTopLabel().setText(WorkspaceTextStyler.toHeaderText(s1));
    retVal.getTopLabel().setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    retVal.getTopLabel().setFont(FontPreferences.getTitleFont());
    retVal.getTopLabel().setIcon(newIcn);
    retVal.setAlwaysDisplayActions(true);

    retVal.setOpaque(false);/*from   www. j ava  2s. c  o m*/

    ImageIcon cancelIcn = IconManager.getInstance().getIcon("actions/button_cancel", IconSize.SMALL);
    ImageIcon cancelIcnL = cancelIcn;

    PhonUIAction btnSwapAct = new PhonUIAction(this, "onSwapNewAndCreateSession", retVal);
    btnSwapAct.putValue(Action.ACTION_COMMAND_KEY, "CANCEL_CREATE_ITEM");
    btnSwapAct.putValue(Action.NAME, "Cancel create");
    btnSwapAct.putValue(Action.SHORT_DESCRIPTION, "Cancel create");
    btnSwapAct.putValue(Action.SMALL_ICON, cancelIcn);
    btnSwapAct.putValue(Action.LARGE_ICON_KEY, cancelIcnL);
    retVal.addAction(btnSwapAct);

    JPanel sessionNamePanel = new JPanel(new BorderLayout());
    sessionNamePanel.setOpaque(false);

    final JTextField sessionNameField = new JTextField();
    sessionNameField.setDocument(new NameDocument());
    sessionNameField.setText("Session Name");
    sessionNamePanel.add(sessionNameField, BorderLayout.CENTER);

    ActionMap actionMap = retVal.getActionMap();
    actionMap.put(btnSwapAct.getValue(Action.ACTION_COMMAND_KEY), btnSwapAct);
    InputMap inputMap = retVal.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);

    inputMap.put(ks, btnSwapAct.getValue(Action.ACTION_COMMAND_KEY));

    retVal.setActionMap(actionMap);
    retVal.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);

    PhonUIAction createNewSessionAct = new PhonUIAction(this, "onCreateSession", sessionNameField);
    createNewSessionAct.putValue(Action.SHORT_DESCRIPTION, "Create new session in selected corpus");
    createNewSessionAct.putValue(Action.SMALL_ICON,
            IconManager.getInstance().getIcon("actions/list-add", IconSize.SMALL));

    JButton createBtn = new JButton(createNewSessionAct);
    sessionNamePanel.add(createBtn, BorderLayout.EAST);

    sessionNameField.setAction(createNewSessionAct);

    // swap bottom component in new project button
    retVal.setBottomLabelText(WorkspaceTextStyler.toDescText(s2));
    retVal.add(sessionNamePanel, BorderLayout.CENTER);

    retVal.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {

        }

        @Override
        public void focusGained(FocusEvent e) {
            sessionNameField.requestFocus();
        }
    });

    return retVal;
}

From source file:de.ipk_gatersleben.ag_nw.graffiti.services.GUIhelper.java

private void myInit() {
    super.dialogInit();
    setTitle(title);//from  w  w  w.ja  va  2 s.  com

    double[][] size = { { border, TableLayoutConstants.PREFERRED, border }, // Columns
            { border, TableLayoutConstants.PREFERRED, border } }; // Rows
    setLayout(new TableLayout(size));

    JButton[] commandButtons = new JButton[buttons.length];
    ArrayList<JComponent> buttonArr = new ArrayList<JComponent>();
    for (int i = 0; i < buttons.length; i++) {
        JButton button = new JButton(buttons[i]);
        final int fi = i;
        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
                returnValue = fi;
                dispose();
            }
        });
        commandButtons[i] = button;
        buttonArr.add(button);
    }
    // final JScrollPane sp = new JScrollPane(mainView);
    // SwingUtilities.invokeLater(new Runnable() {
    // public void run() {
    // sp.getVerticalScrollBar().setValue(0);
    // }});
    add(TableLayout.getSplitVertical(mainView,
            TableLayout.getMultiSplit(buttonArr, TableLayoutConstants.PREFERRED, 5, 0, 5, 3),
            TableLayoutConstants.FILL, TableLayoutConstants.PREFERRED), "1,1");
    validate();

    setResizable(false);
    // setSize(getPreferredSize());
    setModal(true);
    getRootPane().setDefaultButton(commandButtons[0]);
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    final String ESC_ACTION_KEY = "ESC_ACTION_KEY";
    getRootPane().getActionMap().put(ESC_ACTION_KEY, new AbstractAction() {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            setVisible(false);
            dispose();
        }
    });

    getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ESC_ACTION_KEY);
    pack();
}