Example usage for java.awt FocusTraversalPolicy FocusTraversalPolicy

List of usage examples for java.awt FocusTraversalPolicy FocusTraversalPolicy

Introduction

In this page you can find the example usage for java.awt FocusTraversalPolicy FocusTraversalPolicy.

Prototype

FocusTraversalPolicy

Source Link

Usage

From source file:org.opendatakit.briefcase.ui.MainBriefcaseWindow.java

/**
 * Create the application.//from  www .ja  v  a 2  s. c om
 */
public MainBriefcaseWindow() {
    frame = new JFrame();
    frame.setBounds(100, 100, 680, 595);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.addWindowListener(new WindowListener() {
        @Override
        public void windowOpened(WindowEvent e) {
        }

        @Override
        public void windowClosing(WindowEvent e) {
        }

        @Override
        public void windowClosed(WindowEvent e) {
        }

        @Override
        public void windowIconified(WindowEvent e) {
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
        }

        @Override
        public void windowActivated(WindowEvent e) {
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        }
    });

    JLabel lblBriefcaseDirectory = new JLabel(MessageStrings.BRIEFCASE_STORAGE_LOCATION);

    txtBriefcaseDir = new JTextField();
    txtBriefcaseDir.setFocusable(false);
    txtBriefcaseDir.setEditable(false);
    txtBriefcaseDir.setColumns(10);

    btnChoose = new JButton("Change...");
    btnChoose.addActionListener(new FolderActionListener());

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
    groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout
            .createSequentialGroup().addContainerGap()
            .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
                    .addComponent(tabbedPane, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 628,
                            Short.MAX_VALUE)
                    .addGroup(groupLayout.createSequentialGroup().addComponent(lblBriefcaseDirectory).addGap(18)
                            .addComponent(txtBriefcaseDir, GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
                            .addGap(18).addComponent(btnChoose)))
            .addContainerGap()));
    groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(groupLayout.createSequentialGroup().addContainerGap()
                    .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
                            .addComponent(txtBriefcaseDir, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnChoose).addComponent(lblBriefcaseDirectory))
                    .addGap(33).addComponent(tabbedPane, GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
                    .addContainerGap()));

    gatherPanel = new PullTransferPanel(transferTerminationFuture);
    tabbedPane.addTab(PullTransferPanel.TAB_NAME, null, gatherPanel, null);
    PullTransferPanel.TAB_POSITION = 0;

    uploadPanel = new PushTransferPanel(transferTerminationFuture);
    tabbedPane.addTab(PushTransferPanel.TAB_NAME, null, uploadPanel, null);
    PushTransferPanel.TAB_POSITION = 1;

    exportPanel = new ExportPanel(exportTerminationFuture);
    tabbedPane.addTab(ExportPanel.TAB_NAME, null, exportPanel, null);
    frame.getContentPane().setLayout(groupLayout);
    ExportPanel.TAB_POSITION = 2;

    frame.addWindowListener(this);
    setFullUIEnabled(false);

    frame.setFocusTraversalPolicy(new FocusTraversalPolicy() {

        @Override
        public Component getComponentAfter(Container arg0, Component arg1) {
            ArrayList<Component> componentOrdering = new ArrayList<Component>();
            for (;;) {
                int nextPanel = PullTransferPanel.TAB_POSITION;
                componentOrdering.clear();
                componentOrdering.add(txtBriefcaseDir);
                componentOrdering.add(btnChoose);
                componentOrdering.add(tabbedPane);
                int idx = tabbedPane.getSelectedIndex();
                if (idx == PullTransferPanel.TAB_POSITION) {
                    componentOrdering.addAll(gatherPanel.getTraversalOrdering());
                    nextPanel = PushTransferPanel.TAB_POSITION;
                } else if (idx == PushTransferPanel.TAB_POSITION) {
                    componentOrdering.addAll(uploadPanel.getTraversalOrdering());
                    nextPanel = ExportPanel.TAB_POSITION;
                } else if (idx == ExportPanel.TAB_POSITION) {
                    componentOrdering.addAll(exportPanel.getTraversalOrdering());
                    nextPanel = PullTransferPanel.TAB_POSITION;
                }
                componentOrdering.add(btnChoose);
                boolean found = false;
                for (int i = 0; i < componentOrdering.size() - 1; ++i) {
                    if (found || arg1 == componentOrdering.get(i)) {
                        found = true;
                        Component comp = componentOrdering.get(i + 1);
                        if (comp == tabbedPane) {
                            return comp;
                        }
                        if (comp.isVisible() && comp.isEnabled()
                                && (!(comp instanceof JTextField) || ((JTextField) comp).isEditable())) {
                            return comp;
                        }
                    }
                }
                if (!found) {
                    return componentOrdering.get(0);
                }
                tabbedPane.setSelectedIndex(nextPanel);
            }
        }

        @Override
        public Component getComponentBefore(Container arg0, Component arg1) {
            ArrayList<Component> componentOrdering = new ArrayList<Component>();
            for (;;) {
                int nextPanel = PullTransferPanel.TAB_POSITION;
                componentOrdering.clear();
                componentOrdering.add(txtBriefcaseDir);
                componentOrdering.add(btnChoose);
                componentOrdering.add(tabbedPane);
                int idx = tabbedPane.getSelectedIndex();
                if (idx == PullTransferPanel.TAB_POSITION) {
                    componentOrdering.addAll(gatherPanel.getTraversalOrdering());
                    nextPanel = ExportPanel.TAB_POSITION;
                } else if (idx == PushTransferPanel.TAB_POSITION) {
                    componentOrdering.addAll(uploadPanel.getTraversalOrdering());
                    nextPanel = PullTransferPanel.TAB_POSITION;
                } else if (idx == ExportPanel.TAB_POSITION) {
                    componentOrdering.addAll(exportPanel.getTraversalOrdering());
                    nextPanel = PushTransferPanel.TAB_POSITION;
                }
                componentOrdering.add(btnChoose);
                boolean found = false;
                for (int i = componentOrdering.size() - 1; i > 0; --i) {
                    if (found || arg1 == componentOrdering.get(i)) {
                        found = true;
                        Component comp = componentOrdering.get(i - 1);
                        if (comp == tabbedPane) {
                            return comp;
                        }
                        if (comp.isVisible() && comp.isEnabled()
                                && (!(comp instanceof JTextField) || ((JTextField) comp).isEditable())) {
                            return comp;
                        }
                    }
                }
                if (!found) {
                    return componentOrdering.get(componentOrdering.size() - 1);
                }
                tabbedPane.setSelectedIndex(nextPanel);
            }
        }

        @Override
        public Component getDefaultComponent(Container arg0) {
            return btnChoose;
        }

        @Override
        public Component getFirstComponent(Container arg0) {
            return btnChoose;
        }

        @Override
        public Component getLastComponent(Container arg0) {
            return tabbedPane;
        }
    });
}