Example usage for javax.swing JTable addKeyListener

List of usage examples for javax.swing JTable addKeyListener

Introduction

In this page you can find the example usage for javax.swing JTable addKeyListener.

Prototype

public synchronized void addKeyListener(KeyListener l) 

Source Link

Document

Adds the specified key listener to receive key events from this component.

Usage

From source file:Main.java

public Main() {
    DefaultTableModel model = new DefaultTableModel(0, 5) {
        @Override//w  ww  .  j a va  2 s.  c om
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    JTable table = new JTable(model);
    for (int i = 0; i < 20; i++) {
        model.addRow(new String[] { i + ".1", i + ".2", i + ".3", i + ".4", i + ".5", });
    }
    add(table, BorderLayout.CENTER);
    table.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            System.out.println("pressed");
            char key = e.getKeyChar();
            int selectedColumn = table.getSelectedColumn();
            for (int i = 0; i < model.getRowCount(); i++) {
                String value = (String) model.getValueAt(i, selectedColumn);
                model.setValueAt(value + key, i, selectedColumn);
            }
        }
    });
}

From source file:de.wusel.partyplayer.gui.PartyPlayer.java

private Component createSongPanel() {
    final SongsTableModel model = new SongsTableModel(playerModel, settings, this);

    table = new JXTable(model) {

        @Override//from  www. ja v a2  s  . c  om
        public String getToolTipText(MouseEvent event) {
            int viewRowIndex = rowAtPoint(event.getPoint());
            if (viewRowIndex != -1) {
                int modelIndex = convertRowIndexToModel(viewRowIndex);
                SongWrapper songFromList = playerModel.getSongFromList(modelIndex);
                return songFromList.getFileName();
            }
            return super.getToolTipText(event);
        }
    };

    table.setAutoCreateRowSorter(true);
    String numberColumnName = getText("table.songs.column.number.label");
    table.getColumn(numberColumnName).setMaxWidth(25);
    table.getColumn(numberColumnName).setResizable(false);
    TableSortController sorter = (TableSortController) table.getRowSorter();
    sorter.setComparator(2, new SongComparator());

    table.getColumn(numberColumnName).setCellRenderer(new SubstanceDefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,
                    column);
            if (value != null)
                label.setText(((SongWrapper) value).getTrackNumber() + "");
            return label;
        }
    });

    table.getColumn(getText("table.songs.column.duration.label"))
            .setCellRenderer(new SubstanceDefaultTableCellRenderer() {

                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                        boolean hasFocus, int row, int column) {
                    JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected,
                            hasFocus, row, column);
                    if (value != null)
                        label.setText(Util.getTimeString((Double) value));
                    return label;
                }
            });

    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                addSongToPlaylist(
                        playerModel.getSongFromList(table.convertRowIndexToModel(table.getSelectedRow())));
            }
        }
    });

    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                addSongToPlaylist(
                        playerModel.getSongFromList(table.convertRowIndexToModel(table.getSelectedRow())));
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(table);
    table.setFillsViewportHeight(true);
    return scrollPane;
}

From source file:fi.hoski.remote.ui.Admin.java

private void editReservations(final EventType eventType) {
    final Event event = chooseEvent(eventType, "CHOOSE");
    if (event != null) {
        final String eventTitle = TextUtil.getText(event.getEventType().name()) + " "
                + event.get(Event.EventDate);
        safeTitle = frame.getTitle();//from w  ww  .j  a  va  2  s  .co  m
        frame.setTitle(eventTitle);
        reservationList = dss.getReservations(event);
        selectedReservations = new ArrayList<Reservation>();
        unSelectedReservations = new ArrayList<Reservation>();
        if (Event.isInspection(eventType)) {
            for (Reservation reservation : reservationList) {
                Boolean inspected = (Boolean) reservation.get(Reservation.INSPECTED);
                if (inspected != null && inspected) {
                    selectedReservations.add(reservation);
                } else {
                    unSelectedReservations.add(reservation);
                }
            }
        } else {
            for (Reservation reservation : reservationList) {
                Long order = (Long) reservation.get(Reservation.ORDER);
                if (order != null && order != 0) {
                    selectedReservations.add(reservation);
                } else {
                    unSelectedReservations.add(reservation);
                }
            }
        }
        DataObjectModel baseModel = Reservation.getModel(eventType);
        DataObjectModel unorderedModel = null;
        DataObjectModel orderedModel = null;
        switch (eventType) {
        case LAUNCH:
        case LIFT:
        case HULL_INSPECTION:
            unorderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR);
            orderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR);
            break;
        case INSPECTION:
            unorderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR,
                    Reservation.EMAIL, Reservation.MOBILEPHONE, Reservation.DOCK, Reservation.DOCKNUMBER,
                    Reservation.INSPECTION_GASS, Reservation.INSPECTOR);
            orderedModel = baseModel.hide(Reservation.BOAT, Reservation.INSPECTED, Reservation.CREATOR,
                    Reservation.EMAIL, Reservation.MOBILEPHONE, Reservation.DOCK, Reservation.DOCKNUMBER,
                    Reservation.NOTES);
            break;
        }

        final DataObjectListTableModel<Reservation> unorderedTableModel = new DataObjectListTableModel<Reservation>(
                unorderedModel, unSelectedReservations);
        final JTable unorderedtable = new FitTable(unorderedTableModel);
        TableSelectionHandler tsh1 = new TableSelectionHandler(unorderedtable);
        unorderedtable.setDefaultRenderer(String.class, new StringTableCellRenderer());
        unorderedtable.setDefaultRenderer(Text.class, new TextTableCellRenderer());

        unorderedtable.addKeyListener(unorderedTableModel.getRemover(dss));
        unorderedtable.setDragEnabled(true);
        unorderedtable.setDropMode(DropMode.INSERT_ROWS);
        TransferHandler unorderedTransferHandler = new DataObjectTransferHandler<Reservation>(
                unorderedTableModel);
        unorderedtable.setTransferHandler(unorderedTransferHandler);

        final DataObjectListTableModel<Reservation> orderedTableModel = new DataObjectListTableModel<Reservation>(
                orderedModel, selectedReservations);
        orderedTableModel.setEditable(Reservation.INSPECTION_CLASS, Reservation.INSPECTION_GASS,
                Reservation.BASICINSPECTION, Reservation.INSPECTOR);
        final JTable orderedtable = new FitTable(orderedTableModel);
        TableSelectionHandler tsh2 = new TableSelectionHandler(orderedtable);
        orderedtable.setDefaultRenderer(String.class, new StringTableCellRenderer());
        orderedtable.setDefaultRenderer(Text.class, new TextTableCellRenderer());

        orderedtable.addKeyListener(orderedTableModel.getRemover(dss));
        orderedtable.setDragEnabled(true);
        orderedtable.setDropMode(DropMode.INSERT_ROWS);
        TransferHandler orderedTransferHandler = new DataObjectTransferHandler<Reservation>(orderedTableModel);
        orderedtable.setTransferHandler(orderedTransferHandler);
        if (Event.isInspection(eventType)) {
            unorderedtable.setAutoCreateRowSorter(true);
            orderedtable.setAutoCreateRowSorter(true);
        }
        leftPane = new JScrollPane();
        leftPane.setViewport(new InfoViewport(TextUtil.getText(eventType.name() + "-leftPane")));
        leftPane.setViewportView(unorderedtable);
        leftPane.setTransferHandler(unorderedTransferHandler);

        rightPane = new JScrollPane();
        rightPane.setViewport(new InfoViewport(TextUtil.getText(eventType.name() + "-rightPane")));
        rightPane.setViewportView(orderedtable);
        rightPane.setTransferHandler(orderedTransferHandler);

        splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPane, rightPane);
        splitPane.setDividerLocation(0.5);
        menuReservation.setEnabled(false);
        safeContainer = frame.getContentPane();
        JPanel contentPane = new JPanel(new BorderLayout());
        contentPane.add(splitPane, BorderLayout.CENTER);

        JPanel buttonPanel = new JPanel();
        buttonPanel.setLayout(new FlowLayout());
        contentPane.add(buttonPanel, BorderLayout.SOUTH);

        JButton saveButton = new JButton();
        TextUtil.populate(saveButton, "SAVE");
        saveButton.setEnabled(!Event.isInspection(eventType));
        ActionListener saveAction = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                saveReservations();
            }
        };
        saveButton.addActionListener(saveAction);
        buttonPanel.add(saveButton);

        switch (eventType) {
        case INSPECTION: {
            if (privileged) {
                JButton inspectButton = new JButton();
                TextUtil.populate(inspectButton, "SET INSPECTED");
                ActionListener inspectAction = new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        TableCellEditor cellEditor = orderedtable.getCellEditor();
                        if (cellEditor != null) {
                            cellEditor.stopCellEditing();
                        }
                        try {
                            setAsInspected();
                        } catch (SQLException | ClassNotFoundException ex) {
                            ex.printStackTrace();
                            JOptionPane.showMessageDialog(null, ex.getMessage());
                        }
                    }
                };
                inspectButton.addActionListener(inspectAction);
                buttonPanel.add(inspectButton);
            }

            JButton addBoat = new JButton();
            TextUtil.populate(addBoat, "ADD BOAT");
            ActionListener addBoatAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    Reservation reservation = reservate(eventType, event);
                    if (reservation != null) {
                        reservationList.add(reservation);
                        unSelectedReservations.add(reservation);
                        unorderedTableModel.fireTableDataChanged();
                    }
                }
            };
            addBoat.addActionListener(addBoatAction);
            buttonPanel.add(addBoat);

            JButton printTypeButton = new JButton();
            TextUtil.populate(printTypeButton, "PRINT");
            ActionListener printTypeAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        printNameBoatTypeOrder(eventTitle);
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            printTypeButton.addActionListener(printTypeAction);
            buttonPanel.add(printTypeButton);

            JButton printDockButton = new JButton();
            TextUtil.populate(printDockButton, "PRINT DOCK ORDER");
            ActionListener printDockAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        printDockOrder(eventTitle);
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            printDockButton.addActionListener(printDockAction);
            buttonPanel.add(printDockButton);

        }
            break;
        case HULL_INSPECTION: {
            JButton print = new JButton();
            TextUtil.populate(print, "PRINT");
            ActionListener printAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        printAlphaOrder(eventTitle);
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            print.addActionListener(printAction);
            buttonPanel.add(print);

        }
            break;
        case LAUNCH:
        case LIFT: {
            JButton addBoat = new JButton();
            TextUtil.populate(addBoat, "ADD BOAT");
            ActionListener addBoatAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    Reservation reservation = reservate(eventType, event);
                    if (reservation != null) {
                        reservationList.add(reservation);
                        unSelectedReservations.add(reservation);
                        unorderedTableModel.fireTableDataChanged();
                    }
                }
            };
            addBoat.addActionListener(addBoatAction);
            buttonPanel.add(addBoat);

            JButton printBrief = new JButton();
            TextUtil.populate(printBrief, "BRIEF PRINT");
            ActionListener printBriefAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        printOrderBrief(eventTitle);
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            printBrief.addActionListener(printBriefAction);
            buttonPanel.add(printBrief);

            JButton print = new JButton();
            TextUtil.populate(print, "PRINT");
            ActionListener printAction = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        if (eventType == EventType.LAUNCH) {
                            printLaunchOrder(eventTitle);
                        } else {
                            printLiftOrder(eventTitle);
                        }
                    } catch (PrinterException ex) {
                        ex.printStackTrace();
                        JOptionPane.showMessageDialog(null, ex.getMessage());
                    }
                }
            };
            print.addActionListener(printAction);
            buttonPanel.add(print);
        }
            break;
        }

        JButton cancelButton = new JButton();
        TextUtil.populate(cancelButton, "CANCEL");
        ActionListener cancelAction = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                cancel();
            }
        };
        cancelButton.addActionListener(cancelAction);
        buttonPanel.add(cancelButton);

        frame.setContentPane(contentPane);
        frame.pack();
        frame.setVisible(true);
        KeyListener keyListener = new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == 10) {
                    int selectedRow = unorderedtable.getSelectedRow();
                    if (selectedRow != -1) {
                        RowSorter<? extends TableModel> rowSorter = unorderedtable.getRowSorter();
                        if (rowSorter != null) {
                            selectedRow = rowSorter.convertRowIndexToModel(selectedRow);
                        }
                        Reservation reservation = unorderedTableModel.getObject(selectedRow);
                        orderedTableModel.add(reservation);
                        unorderedTableModel.remove(reservation);
                        e.consume();
                        unorderedtable.changeSelection(selectedRow, 0, false, false);
                    }
                }
            }
        };
        unorderedtable.addKeyListener(keyListener);
        unorderedtable.requestFocusInWindow();
    }
}

From source file:org.formic.wizard.step.gui.FeatureListStep.java

/**
 * {@inheritDoc}//from   w  ww .  ja  va  2s.c o m
 * @see org.formic.wizard.step.GuiStep#init()
 */
public Component init() {
    featureInfo = new JEditorPane("text/html", StringUtils.EMPTY);
    featureInfo.setEditable(false);
    featureInfo.addHyperlinkListener(new HyperlinkListener());

    Feature[] features = provider.getFeatures();
    JTable table = new JTable(features.length, 1) {
        private static final long serialVersionUID = 1L;

        public Class getColumnClass(int column) {
            return getValueAt(0, column).getClass();
        }

        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    table.setBackground(new javax.swing.JList().getBackground());

    GuiForm form = createForm();

    for (int ii = 0; ii < features.length; ii++) {
        final Feature feature = (Feature) features[ii];
        final JCheckBox box = new JCheckBox();

        String name = getName() + '.' + feature.getKey();
        form.bind(name, box);

        box.putClientProperty("feature", feature);
        featureMap.put(feature.getKey(), box);

        if (feature.getInfo() == null) {
            feature.setInfo(Installer.getString(getName() + "." + feature.getKey() + ".html"));
        }
        feature.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent event) {
                if (Feature.ENABLED_PROPERTY.equals(event.getPropertyName())) {
                    if (box.isSelected() != feature.isEnabled()) {
                        box.setSelected(feature.isEnabled());
                    }
                }
            }
        });

        box.setText(Installer.getString(name));
        box.setBackground(table.getBackground());
        if (!feature.isAvailable()) {
            box.setSelected(false);
            box.setEnabled(false);
        }
        table.setValueAt(box, ii, 0);
    }

    FeatureListMouseListener mouseListener = new FeatureListMouseListener();
    for (int ii = 0; ii < features.length; ii++) {
        Feature feature = (Feature) features[ii];
        if (feature.isEnabled() && feature.isAvailable()) {
            JCheckBox box = (JCheckBox) featureMap.get(feature.getKey());
            box.setSelected(true);
            mouseListener.processDependencies(feature);
            mouseListener.processExclusives(feature);
        }
    }

    table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setShowHorizontalLines(false);
    table.setShowVerticalLines(false);
    table.setDefaultRenderer(JCheckBox.class, new ComponentTableCellRenderer());

    table.addKeyListener(new FeatureListKeyListener());
    table.addMouseListener(mouseListener);
    table.getSelectionModel().addListSelectionListener(new FeatureListSelectionListener(table));

    table.setRowSelectionInterval(0, 0);

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    JPanel container = new JPanel(new BorderLayout());
    container.add(table, BorderLayout.CENTER);
    panel.add(new JScrollPane(container), BorderLayout.CENTER);
    JScrollPane infoScroll = new JScrollPane(featureInfo);
    infoScroll.setMinimumSize(new Dimension(0, 50));
    infoScroll.setMaximumSize(new Dimension(0, 50));
    infoScroll.setPreferredSize(new Dimension(0, 50));
    panel.add(infoScroll, BorderLayout.SOUTH);

    return panel;
}

From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.ImportDialog.java

/**
 * Initializes the components composing the display.
 * /*from ww w .j a v a 2 s.  com*/
 * @param filters The filters to handle.
 * @param importerAction The cancel-all-imports action.
 */
private void initComponents(FileFilter[] filters, ImporterAction importerAction) {
    canvas = new QuotaCanvas();
    sizeImportLabel = new JLabel();
    diskSpacePane = new JPanel();
    diskSpacePane.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0));
    diskSpacePane.add(UIUtilities.setTextFont(TEXT_FREE_SPACE));
    diskSpacePane.add(canvas);

    showThumbnails = new JCheckBox(TEXT_SHOW_THUMBNAILS);
    showThumbnails.setVisible(false);

    Registry registry = ImporterAgent.getRegistry();

    Boolean loadThumbnails = (Boolean) registry.lookup(LOAD_THUMBNAIL);

    if (loadThumbnails != null) {
        if (loadThumbnails.booleanValue()) {
            showThumbnails.setVisible(true);
            showThumbnails.setSelected(loadThumbnails.booleanValue());
        }
    }

    if (!isFastConnection()) // slow connection
        showThumbnails.setSelected(false);
    long groupId = -1;
    if (model.getSelectedGroup() != null)
        groupId = model.getSelectedGroup().getGroupId();
    if (groupId < 0)
        groupId = ImporterAgent.getUserDetails().getGroupId();

    locationDialog = new LocationDialog(owner, selectedContainer, type, objects, model, groupId, true);
    locationDialog.addPropertyChangeListener(this);

    int plugin = ImporterAgent.runAsPlugin();

    if (plugin == LookupNames.IMAGE_J_IMPORT || plugin == LookupNames.IMAGE_J) {
        detachedDialog = new LocationDialog(owner, selectedContainer, type, objects, model, groupId, false);
        detachedDialog.addPropertyChangeListener(this);
    }
    tagSelectionListener = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Object src = e.getSource();
            if (src instanceof JButton) {
                TagAnnotationData tag = tagsMap.get(src);
                if (tag != null) {
                    tagsMap.remove(src);
                    handleTagsSelection(tagsMap.values());
                }
            }
        }
    };

    tabbedPane = new JTabbedPane();
    numberOfFolders = new NumericalTextField();
    numberOfFolders.setMinimum(0);
    numberOfFolders.setText("0");
    numberOfFolders.setColumns(3);
    numberOfFolders.addPropertyChangeListener(this);
    tagsMap = new LinkedHashMap<JButton, TagAnnotationData>();

    IconManager icons = IconManager.getInstance();

    refreshFilesButton = new JButton(TEXT_REFRESH_FILES);
    refreshFilesButton.setBackground(UIUtilities.BACKGROUND);
    refreshFilesButton.setToolTipText(TOOLTIP_REFRESH_FILES);
    refreshFilesButton.setActionCommand("" + CMD_REFRESH_FILES);
    refreshFilesButton.addActionListener(this);

    tagButton = new JButton(icons.getIcon(IconManager.PLUS_12));
    UIUtilities.unifiedButtonLookAndFeel(tagButton);
    tagButton.addActionListener(this);
    tagButton.setActionCommand("" + CMD_TAG);
    tagButton.setToolTipText(TOOLTIP_ADD_TAGS);
    tagsPane = new JPanel();
    tagsPane.setLayout(new BoxLayout(tagsPane, BoxLayout.Y_AXIS));

    overrideName = new JCheckBox(TEXT_OVERRIDE_FILE_NAMING);
    overrideName.setToolTipText(UIUtilities.formatToolTipText(WARNING));
    overrideName.setSelected(true);
    ButtonGroup group = new ButtonGroup();
    fullName = new JRadioButton(TEXT_NAMING_FULL_PATH);
    group.add(fullName);
    partialName = new JRadioButton();
    partialName.setText(TEXT_NAMING_PARTIAL_PATH);
    partialName.setSelected(true);
    group.add(partialName);

    table = new FileSelectionTable(this);
    table.addPropertyChangeListener(this);
    chooser = new GenericFileChooser();
    JList list = (JList) UIUtilities.findComponent(chooser, JList.class);
    KeyAdapter ka = new KeyAdapter() {

        /**
         * Adds the files to the import queue.
         * 
         * @see KeyListener#keyPressed(KeyEvent)
         */
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                handleEnterKeyPressed(e.getSource());
            }
        }
    };
    if (list != null)
        list.addKeyListener(ka);
    if (list == null) {
        JTable t = (JTable) UIUtilities.findComponent(chooser, JTable.class);
        if (t != null)
            t.addKeyListener(ka);
    }

    try {
        File f = UIUtilities.getDefaultFolder();
        if (f != null)
            chooser.setCurrentDirectory(f);
    } catch (Exception e) {
        // Ignore: could not set the default container
    }

    chooser.addPropertyChangeListener(this);
    chooser.setMultiSelectionEnabled(true);
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setControlButtonsAreShown(false);
    chooser.setApproveButtonText(TEXT_IMPORT);
    chooser.setApproveButtonToolTipText(TOOLTIP_IMPORT);

    bioFormatsFileFilters = new ArrayList<FileFilter>();

    if (filters != null) {
        chooser.setAcceptAllFileFilterUsed(false);

        for (FileFilter fileFilter : filters) {
            if (fileFilter instanceof ComboFileFilter) {
                bioFormatsFileFiltersCombined = fileFilter;

                ComboFileFilter comboFilter = (ComboFileFilter) fileFilter;
                FileFilter[] extensionFilters = comboFilter.getFilters();

                for (FileFilter combinedFilter : extensionFilters) {
                    bioFormatsFileFilters.add(combinedFilter);
                }
                break;
            }
        }

        chooser.addChoosableFileFilter(bioFormatsFileFiltersCombined);

        for (FileFilter fileFilter : bioFormatsFileFilters) {
            chooser.addChoosableFileFilter(fileFilter);
        }

        chooser.setFileFilter(bioFormatsFileFiltersCombined);
    } else {
        chooser.setAcceptAllFileFilterUsed(true);
    }

    closeButton = new JButton(TEXT_CLOSE);
    closeButton.setToolTipText(TOOLTIP_CLOSE);
    closeButton.setActionCommand("" + CMD_CLOSE);
    closeButton.addActionListener(this);

    cancelImportButton = new JButton(importerAction);
    importerAction.setEnabled(false);

    importButton = new JButton(TEXT_IMPORT);
    importButton.setToolTipText(TOOLTIP_IMPORT);
    importButton.setActionCommand("" + CMD_IMPORT);
    importButton.addActionListener(this);
    importButton.setEnabled(false);

    pixelsSize = new ArrayList<NumericalTextField>();
    NumericalTextField field;
    for (int i = 0; i < 3; i++) {
        field = new NumericalTextField();
        field.setNumberType(Double.class);
        field.setColumns(2);
        pixelsSize.add(field);
    }

    List<Component> boxes = UIUtilities.findComponents(chooser, JComboBox.class);
    if (boxes != null) {
        JComboBox box;
        JComboBox filterBox = null;
        Iterator<Component> i = boxes.iterator();
        while (i.hasNext()) {
            box = (JComboBox) i.next();
            Object o = box.getItemAt(0);
            if (o instanceof FileFilter) {
                filterBox = box;
                break;
            }
        }
        if (filterBox != null) {
            filterBox.addKeyListener(new KeyAdapter() {

                public void keyPressed(KeyEvent e) {
                    String value = KeyEvent.getKeyText(e.getKeyCode());
                    JComboBox box = (JComboBox) e.getSource();
                    int n = box.getItemCount();
                    FileFilter filter;
                    FileFilter selectedFilter = null;
                    String d;
                    for (int j = 0; j < n; j++) {
                        filter = (FileFilter) box.getItemAt(j);
                        d = filter.getDescription();
                        if (d.startsWith(value)) {
                            selectedFilter = filter;
                            break;
                        }
                    }
                    if (selectedFilter != null)
                        box.setSelectedItem(selectedFilter);
                }
            });
        }
    }
}

From source file:org.ut.biolab.medsavant.client.project.ProjectWizard.java

private AbstractWizardPage getVCFFieldsPage() {

    //setup page//from w ww.  j  a va 2 s .  c  om
    final DefaultWizardPage page = new DefaultWizardPage(PAGENAME_VCF) {
        @Override
        public void setupWizardButtons() {
            fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK);
            fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.BACK);
            fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH);
            fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT);
        }
    };

    page.addText("Add extra fields to parse from INFO text in VCF files. ");

    JScrollPane scrollpane = new JScrollPane();
    scrollpane.setPreferredSize(new Dimension(300, 250));
    scrollpane.getViewport().setBackground(Color.white);

    final JTable table = new JTable() {
        @Override
        public Class<?> getColumnClass(int column) {
            if (column == 2) {
                return Boolean.class;
            } else {
                return String.class;
            }
        }
    };

    variantFormatModel = new DefaultTableModel();

    variantFormatModel.addColumn("Key");
    variantFormatModel.addColumn("Type");
    variantFormatModel.addColumn("Filterable");
    variantFormatModel.addColumn("Alias");
    variantFormatModel.addColumn("Description");

    if (modify) {
        try {
            int firstRef = manager.getReferenceIDsForProject(LoginController.getSessionID(), projectID)[0];
            CustomField[] fields = manager.getCustomVariantFields(LoginController.getSessionID(), projectID,
                    firstRef,
                    manager.getNewestUpdateID(LoginController.getSessionID(), projectID, firstRef, false));
            for (CustomField f : fields) {
                //casing of f.getColumnName should match database.
                variantFormatModel.addRow(new Object[] { f.getColumnName(), f.getTypeString(), f.isFilterable(),
                        f.getAlias(), f.getDescription() });
            }
        } catch (Exception ex) {
            LOG.error("Error getting reference IDs for project.", ex);
        }
    } else {
        variantFormatModel
                .addRow(new Object[] { AA.getColumnName(), AA.getTypeString(), true, AA.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { AC.getColumnName(), AC.getTypeString(), true, AC.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { AF.getColumnName(), AF.getTypeString(), true, AF.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { AN.getColumnName(), AN.getTypeString(), true, AN.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { BQ.getColumnName(), BQ.getTypeString(), true, BQ.getAlias(), "" });
        variantFormatModel.addRow(
                new Object[] { CIGAR.getColumnName(), CIGAR.getTypeString(), true, CIGAR.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { DB.getColumnName(), DB.getTypeString(), true, DB.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { DP.getColumnName(), DP.getTypeString(), true, DP.getAlias(), "" });
        //variantFormatModel.addRow(new Object[]{END.getColumnName(), END.getTypeString(), true, END.getAlias(), ""});
        variantFormatModel
                .addRow(new Object[] { H2.getColumnName(), H2.getTypeString(), true, H2.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { MQ.getColumnName(), MQ.getTypeString(), true, MQ.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { MQ0.getColumnName(), MQ0.getTypeString(), true, MQ0.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { NS.getColumnName(), NS.getTypeString(), true, NS.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { SB.getColumnName(), SB.getTypeString(), true, SB.getAlias(), "" });
        variantFormatModel.addRow(new Object[] { SOMATIC.getColumnName(), SOMATIC.getTypeString(), true,
                SOMATIC.getAlias(), "" });
        variantFormatModel.addRow(new Object[] { VALIDATED.getColumnName(), VALIDATED.getTypeString(), true,
                VALIDATED.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { JANNOVAR_EFFECT.getColumnName(), JANNOVAR_EFFECT.getTypeString(),
                        JANNOVAR_EFFECT.isFilterable(), JANNOVAR_EFFECT.getAlias(), "" });
        variantFormatModel
                .addRow(new Object[] { JANNOVAR_SYMBOL.getColumnName(), JANNOVAR_SYMBOL.getTypeString(),
                        JANNOVAR_SYMBOL.isFilterable(), JANNOVAR_SYMBOL.getAlias(), "" });
        variantFormatModel.addRow(new Object[] { FORMAT.getColumnName(), FORMAT.getTypeString(),
                FORMAT.isFilterable(), FORMAT.getAlias(), "" });
        variantFormatModel.addRow(new Object[] { SAMPLE_INFO.getColumnName(), SAMPLE_INFO.getTypeString(),
                SAMPLE_INFO.isFilterable(), SAMPLE_INFO.getAlias(), "" });
    }

    table.setModel(variantFormatModel);
    table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    scrollpane.getViewport().add(table);
    page.addComponent(scrollpane);

    table.addKeyListener(new KeyListener() {
        @Override
        public void keyTyped(KeyEvent e) {
            variantFieldsChanged = true;
        }

        @Override
        public void keyPressed(KeyEvent e) {
            variantFieldsChanged = true;
        }

        @Override
        public void keyReleased(KeyEvent e) {
            variantFieldsChanged = true;
        }
    });

    JButton addFieldButton = new JButton("Add Field");
    addFieldButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            variantFormatModel.addRow(new Object[2]);
            table.setModel(variantFormatModel);
            variantFieldsChanged = true;
        }
    });
    page.addComponent(addFieldButton);

    JButton removeFieldButton = new JButton("Remove Field");
    removeFieldButton.setEnabled(false);
    removeFieldButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            int row = table.getSelectedRow();
            if (row >= 0) {
                variantFormatModel.removeRow(row);
                table.setModel(variantFormatModel);
                variantFieldsChanged = true;
            }
        }
    });
    table.getSelectionModel().addListSelectionListener(new RemovalEnabler(0, removeFieldButton));
    page.addComponent(removeFieldButton);

    return page;
}