Example usage for javax.swing.event MouseInputAdapter MouseInputAdapter

List of usage examples for javax.swing.event MouseInputAdapter MouseInputAdapter

Introduction

In this page you can find the example usage for javax.swing.event MouseInputAdapter MouseInputAdapter.

Prototype

MouseInputAdapter

Source Link

Usage

From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java

/**
 * //from   w w w . j ava 2  s .  c  o  m
 */
protected void setupUI(final boolean isPostSave) throws QueryTask.QueryBuilderContextException {
    if (!isHeadless && !SwingUtilities.isEventDispatchThread()) {
        throw new RuntimeException("Method called from invalid thread.");
    }

    queryFieldsPanel.removeAll();
    queryFieldItems.clear();
    queryFieldsPanel.validate();
    columnDefStr = null;
    tableList.clearSelection();
    contextPanel.setVisible(query == null);
    tableList.setSelectedIndex(-1);
    if (query != null) {
        //query.forceLoad(true); 
        Short tblId = query.getContextTableId();
        if (tblId != null) {
            for (int i = 0; i < tableList.getModel().getSize(); i++) {
                TableQRI qri = (TableQRI) tableList.getModel().getElementAt(i);
                if (qri.getTableInfo().getTableId() == tblId.intValue()) {
                    tableList.setSelectedIndex(i);
                    break;
                }
            }
        }
    }

    List<QueryFieldPanel> qfps = null;
    boolean dirty = false;
    List<String> missingFlds = new LinkedList<String>();
    boolean doAutoMap = query == null || query.getId() == null;
    if (query != null) {
        TableQRI qri = (TableQRI) tableList.getSelectedValue();
        if (qri == null) {
            //throw new RuntimeException("Invalid context for query."); 
            throw ((QueryTask) task).new QueryBuilderContextException();
        }
        //query.forceLoad(true);                   
        qfps = !isExportMapping
                ? getQueryFieldPanels(this, query.getFields(), tableTree, tableTreeHash, saveBtn, missingFlds)
                : getQueryFieldPanelsForMapping(this, query.getFields(), tableTree, tableTreeHash, saveBtn,
                        schemaMapping, missingFlds,
                        (doAutoMap ? ConceptMapUtils.getDefaultDarwinCoreMappings() : null));
        if (missingFlds.size() > 0) {
            JList list = new JList(new Vector<String>(missingFlds));
            CellConstraints cc = new CellConstraints();
            PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p:g,2px,f:p:g"));
            pb.add(UIHelper.createI18NLabel("QB_FIELDS_NOT_ADDED"), cc.xy(1, 1));
            pb.add(UIHelper.createScrollPane(list), cc.xy(1, 3));
            pb.setDefaultDialogBorder();

            dirty = qfps.size() > 0;
            CustomDialog dlg = new CustomDialog((Frame) UIRegistry.getTopWindow(),
                    UIRegistry.getResourceString("QB_FIELD_MISSING_TITLE"), true, CustomDialog.OK_BTN,
                    pb.getPanel());
            dlg.setOkLabel(UIRegistry.getResourceString("CLOSE"));
            dlg.setVisible(true);
        }
    }

    boolean header = true;
    for (final QueryFieldPanel qfp : qfps) {
        if (header) {
            header = false;
            this.queryFieldsScroll.setColumnHeaderView(qfp);
        } else {
            queryFieldItems.add(qfp);
            qfp.addMouseListener(new MouseInputAdapter() {
                @Override
                public void mousePressed(MouseEvent e) {
                    selectQFP(qfp);
                }
            });
            qfp.resetValidator();
            queryFieldsPanel.add(qfp);
            //doAutoMap &= qfp.getFieldQRI() == null;
        }
    }
    qualifyFieldLabels();

    for (QueryFieldPanel qfp : queryFieldItems) {
        if (qfp.isAutoMapped()) {
            SpQueryField qf = new SpQueryField();
            qf.initialize();
            qf.setFieldName(qfp.getFieldQRI().getFieldName());
            qf.setStringId(qfp.getFieldQRI().getStringId());
            qfp.setQueryFieldForAutomapping(qf);
            query.addReference(qf, "fields");
            addNewMapping(qfp.getFieldQRI(), qf, qfp, false);
            dirty = true;
            qfp.setAutoMapped(false);
        }
    }

    /*if (doAutoMap)
    {
       for (QueryFieldPanel qfp : queryFieldItems)
       {
      if (!qfp.isConditionForSchema())
    {
       Vector<MappedFieldInfo> mappedTos = ConceptMapUtils.getDefaultDarwinCoreMappings().get(qfp.getSchemaItem().getFieldName().toLowerCase());
               
       if (mappedTos != null)
       {
          for (MappedFieldInfo mappedTo : mappedTos)
          {
             FieldQRI fqri = getFieldQRI(tableTree, mappedTo
                .getFieldName(), mappedTo.isRel(), mappedTo
                .getStringId(), getTableIds(mappedTo
                .getTableIds()), 0, tableTreeHash);
             if (fqri != null)
             {
                SpQueryField qf = new SpQueryField();
                qf.initialize();
                qf.setFieldName(fqri.getFieldName());
                qf.setStringId(fqri.getStringId());
                query.addReference(qf, "fields");
                addNewMapping(fqri, qf, qfp);
                dirty = true;
                break;
             }
          }
       }
    }
       }
    }*/

    fillNextList(tableList);

    updateAvailableConcepts();

    SwingUtilities.invokeLater(new Runnable() {

        /* (non-Javadoc)
         * @see java.lang.Runnable#run()
         */
        @Override
        public void run() {
            distinctChk.setSelected(query.isSelectDistinct());
            countOnlyChk.setSelected(query.getCountOnly() == null ? false : query.getCountOnly());
            countOnly = countOnlyChk.isSelected();
            searchSynonymyChk.setSelected(
                    query.getSearchSynonymy() == null ? searchSynonymy : query.getSearchSynonymy());
            searchSynonymy = searchSynonymyChk.isSelected();
            smushedChk.setSelected(query.getSmushed() == null ? smushed : query.getSmushed());
            smushed = smushedChk.isSelected();
        }

    });
    final boolean saveBtnEnabled = dirty;
    if (!isHeadless) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                adjustPanelUI(saveBtnEnabled, isPostSave);
            }
        });
    } else {
        adjustPanelUI(saveBtnEnabled, isPostSave);
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java

/**
 * Add QueryFieldItem to the list created with a TableFieldPair.
 * /*from   www. jav a 2  s  .  c om*/
 * @param fieldItem the TableFieldPair to be in the list
 */
protected QueryFieldPanel addQueryFieldItem(final FieldQRI fieldQRI, final SpQueryField queryField,
        final boolean loading) {
    QueryFieldPanel result = null;
    if (fieldQRI != null) {
        final QueryFieldPanel qfp = new QueryFieldPanel(this, fieldQRI, columnDefStr, saveBtn, queryField,
                this.schemaMapping);
        result = qfp;
        qfp.addMouseListener(new MouseInputAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                selectQFP(qfp);
            }
        });
        queryFieldItems.add(qfp);
        qualifyFieldLabels();
        fieldQRI.setIsInUse(true);
        updateUIAfterAddOrMap(fieldQRI, qfp, loading, true, false);
    }
    return result;
}

From source file:org.rdv.datapanel.AbstractDataPanel.java

/**
 * Get a component for displaying the title in top bar. This implementation
 * includes a button to remove a specific channel.
 * //from  ww w  .  j a  v  a2s  . c  o  m
 * Subclasses should overide this method if they don't want the default
 * implementation.
 * 
 * @return  A component for the top bar
 * @since   1.3
 */
JComponent getTitleComponent() {
    JPanel titleBar = new JPanel();
    titleBar.setOpaque(false);
    titleBar.setLayout(new BorderLayout());

    JPopupMenu popupMenu = new ScrollablePopupMenu();

    final String title;
    if (description != null) {
        title = "Edit description";
    } else {
        title = "Add description";
    }

    JMenuItem addDescriptionMenuItem = new JMenuItem(title);
    addDescriptionMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            String response = (String) JOptionPane.showInputDialog(null, "Enter a description", title,
                    JOptionPane.QUESTION_MESSAGE, null, null, description);
            if (response == null) {
                return;
            } else if (response.length() == 0) {
                setDescription(null);
            } else {
                setDescription(response);
            }
        }
    });
    popupMenu.add(addDescriptionMenuItem);

    if (description != null) {
        JMenuItem removeDescriptionMenuItem = new JMenuItem("Remove description");
        removeDescriptionMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                setDescription(null);
            }
        });
        popupMenu.add(removeDescriptionMenuItem);
    }

    popupMenu.addSeparator();

    final JCheckBoxMenuItem showChannelsInTitleMenuItem = new JCheckBoxMenuItem("Show channels in title",
            showChannelsInTitle);
    showChannelsInTitleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setShowChannelsInTitle(showChannelsInTitleMenuItem.isSelected());
        }
    });
    popupMenu.add(showChannelsInTitleMenuItem);

    if (channels.size() > 0) {
        popupMenu.addSeparator();

        Iterator<String> i = channels.iterator();
        while (i.hasNext()) {
            final String channelName = i.next();

            JMenuItem unsubscribeChannelMenuItem = new JMenuItem("Unsubscribe from " + channelName);
            unsubscribeChannelMenuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    removeChannel(channelName);
                }
            });
            popupMenu.add(unsubscribeChannelMenuItem);
        }
    }

    // set component popup and mouselistener to trigger it
    titleBar.setComponentPopupMenu(popupMenu);
    titleBar.addMouseListener(new MouseInputAdapter() {
    });

    if (description != null) {
        titleBar.add(getDescriptionComponent(), BorderLayout.WEST);
    }

    JComponent titleComponent = getChannelComponent();
    if (titleComponent != null) {
        titleBar.add(titleComponent, BorderLayout.CENTER);
    }

    return titleBar;
}

From source file:org.rdv.datapanel.DigitalTabularDataPanel.java

/**
 * Initialize the container and add the header.
 * /*w  w  w.j a va2 s.com*/
 * @since 1.2
 */
private void initComponents() {
    mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());

    panelBox = Box.createHorizontalBox();

    dataCellRenderer = new DataTableCellRenderer();
    doubleCellRenderer = new DoubleTableCellRenderer();

    showMinMaxCheckBoxGroup = new CheckBoxGroup();
    showThresholdCheckBoxGroup = new CheckBoxGroup();

    addColumn();

    mainPanel.add(panelBox, BorderLayout.CENTER);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BorderLayout());

    JPanel offsetsPanel = new JPanel();

    useOffsetsCheckBox = new JCheckBox("Use Offsets");
    useOffsetsCheckBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            boolean checked = ((JCheckBox) ae.getSource()).isSelected();

            useOffsetRenderer(checked);
        }
    });
    offsetsPanel.add(useOffsetsCheckBox);

    JButton takeOffsetsButton = new JButton("Take Offsets");
    takeOffsetsButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            useOffsetsCheckBox.setSelected(true); // this moved from above
            // repaint
            for (int i = 0; i < columnGroupCount; i++) {
                ((DataTableModel) tableModels.get(i)).takeOffsets();
                ((DataTableModel) tableModels.get(i)).useOffsets(true);
                ((JTable) tables.get(i)).repaint();
            } // for
        } // actionPerformed ()
    }); // actionlistener
    offsetsPanel.add(takeOffsetsButton);

    buttonPanel.add(offsetsPanel, BorderLayout.WEST);

    JPanel formatPanel = new JPanel();

    decimalButton = new JToggleButton("Decimal", true);
    decimalButton.setSelected(true);
    decimalButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            useEngineeringRenderer(false);
        }
    });
    formatPanel.add(decimalButton);

    engineeringButton = new JToggleButton("Engineering");
    engineeringButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            useEngineeringRenderer(true);
        }
    });
    formatPanel.add(engineeringButton);

    ButtonGroup formatButtonGroup = new ButtonGroup();
    formatButtonGroup.add(decimalButton);
    formatButtonGroup.add(engineeringButton);

    buttonPanel.add(formatPanel, BorderLayout.EAST);

    mainPanel.add(buttonPanel, BorderLayout.SOUTH);

    mainPanel.addMouseListener(new MouseInputAdapter() {
    });

}

From source file:org.rdv.viz.image.ImageViz.java

private void initRoboticMouseClickListener() {
    roboticMouseClickListener = new MouseInputAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1) {
                Point imagePoint = imagePanel.panelToScaledImagePoint(e.getPoint());
                if (imagePoint != null) {
                    center(imagePoint);//from   w  w  w .j av a 2 s. c  om
                }
            }
        }
    };
}

From source file:org.rdv.viz.image.ImageViz.java

private void initPopupMenu() {
    final JPopupMenu popupMenu = new JPopupMenu();

    // create a popup to copy an image to the clipboard
    final JMenuItem copyImageMenuItem = new JMenuItem("Copy");
    copyImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            copyImage();/*w w w.j  av a2 s .  co m*/
        }
    });
    popupMenu.add(copyImageMenuItem);

    popupMenu.addSeparator();

    // create a popup to save an image
    final JMenuItem saveImageMenuItem = new JMenuItem("Save as...");
    saveImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            saveImage();
        }
    });
    popupMenu.add(saveImageMenuItem);

    popupMenu.addSeparator();

    // create a popup to copy an image to the clipboard
    final JMenuItem printImageMenuItem = new JMenuItem("Print...");
    printImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            printImage();
        }
    });
    popupMenu.add(printImageMenuItem);

    popupMenu.addSeparator();

    final JMenuItem zoomInMenuItem = new JMenuItem("Zoom in");
    zoomInMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomIn();
        }
    });
    popupMenu.add(zoomInMenuItem);

    final JMenuItem zoomOutMenuItem = new JMenuItem("Zoom out");
    zoomOutMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            imagePanel.zoomOut();
        }
    });
    popupMenu.add(zoomOutMenuItem);

    final JSeparator zoomMenuSeparator = new JPopupMenu.Separator();
    popupMenu.add(zoomMenuSeparator);

    autoScaleMenuItem = new JCheckBoxMenuItem("Auto scale", true);
    autoScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setAutoScale(autoScaleMenuItem.isSelected());
        }
    });
    popupMenu.add(autoScaleMenuItem);

    final JMenuItem resetScaleMenuItem = new JMenuItem("Reset scale");
    resetScaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            imagePanel.setScale(1);
        }
    });
    popupMenu.add(resetScaleMenuItem);

    showNavigationImageMenuItem = new JCheckBoxMenuItem("Show navigation image",
            imagePanel.isNavigationImageEnabled());
    showNavigationImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setShowNavigationImage(showNavigationImageMenuItem.isSelected());
        }
    });
    popupMenu.add(showNavigationImageMenuItem);

    final JMenu maximumFilmstripImagesMenu = new JMenu("Maximum number of images");
    maximumFilmstripImagesButtonGroup = new ButtonGroup();
    for (final int maximumFilmstripImagesValue : MAXIMUM_FILMSTRIP_IMAGES_VALUES) {
        boolean selected = filmstripPanel.getMaximumImages() == maximumFilmstripImagesValue;
        JMenuItem maximumFilmStripImagesMenuItem = new JRadioButtonMenuItem(
                Integer.toString(maximumFilmstripImagesValue), selected);
        maximumFilmStripImagesMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                filmstripPanel.setMaximumImages(maximumFilmstripImagesValue);
            }
        });
        maximumFilmstripImagesButtonGroup.add(maximumFilmStripImagesMenuItem);
        maximumFilmstripImagesMenu.add(maximumFilmStripImagesMenuItem);
    }
    popupMenu.add(maximumFilmstripImagesMenu);

    popupMenu.addSeparator();

    final JCheckBoxMenuItem showAsFilmstripMenuItem = new JCheckBoxMenuItem("Show as filmstrip", filmstripMode);
    showAsFilmstripMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            boolean filmstripMode = showAsFilmstripMenuItem.isSelected();
            setFilmstripMode(filmstripMode);
        }
    });
    popupMenu.add(showAsFilmstripMenuItem);

    final JCheckBoxMenuItem useThumbnailImageMenuItem = new JCheckBoxMenuItem("Use thumbnail image",
            useThumbnailImage);
    useThumbnailImageMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setUseThumbnailImage(useThumbnailImageMenuItem.isSelected());
        }
    });
    popupMenu.add(useThumbnailImageMenuItem);

    hideRoboticControlsMenuItem = new JCheckBoxMenuItem("Disable robotic controls", false);
    hideRoboticControlsMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setRoboticControls();
        }
    });
    popupMenu.add(hideRoboticControlsMenuItem);

    // enable the save image popup if an image is being displayed
    popupMenu.addPopupMenuListener(new PopupMenuListener() {
        public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
            boolean hasImage = displayedImageData != null;
            saveImageMenuItem.setEnabled(hasImage);
            copyImageMenuItem.setEnabled(hasImage);
            printImageMenuItem.setEnabled(hasImage);

            boolean enableZoom = hasImage && !filmstripMode;
            zoomInMenuItem.setEnabled(enableZoom);
            zoomInMenuItem.setVisible(!filmstripMode);
            zoomOutMenuItem.setEnabled(enableZoom);
            zoomOutMenuItem.setVisible(!filmstripMode);
            zoomMenuSeparator.setVisible(!filmstripMode);

            autoScaleMenuItem.setVisible(!filmstripMode);
            resetScaleMenuItem.setVisible(!filmstripMode);
            showNavigationImageMenuItem.setVisible(!filmstripMode);
            maximumFilmstripImagesMenu.setVisible(filmstripMode);

            showAsFilmstripMenuItem.setSelected(filmstripMode);

            useThumbnailImageMenuItem.setSelected(useThumbnailImage);
            useThumbnailImageMenuItem.setVisible(imageHasThumbnail());

            hideRoboticControlsMenuItem.setVisible(flexTPSStream != null);
        }

        public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
        }

        public void popupMenuCanceled(PopupMenuEvent arg0) {
        }
    });

    // set component popup and mouselistener to trigger it
    panel.setComponentPopupMenu(popupMenu);
    imagePanel.setComponentPopupMenu(popupMenu);
    filmstripPanel.setComponentPopupMenu(popupMenu);
    panel.addMouseListener(new MouseInputAdapter() {
    });
}

From source file:org.revager.tools.GUITools.java

/**
 * Creates a new standard table.//from  ww  w. j  av  a2s.c o m
 * 
 * @param model
 *            the table model
 * @param showHeader
 *            true if the header of the table should be visible
 * 
 * @return the newly created table
 */
@SuppressWarnings("serial")
public static JTable newStandardTable(TableModel model, boolean showHeader) {
    /*
     * Prep. for rollover
     */
    if (lastRolloverKey == Integer.MAX_VALUE) {
        lastRolloverKey = 0;
    } else {
        lastRolloverKey++;
    }

    final int keyIdx = lastRolloverKey;

    rollOverRowIndex.put(keyIdx, -1);

    final JTable table = new JTable(model) {

        @Override
        public boolean editCellAt(int row, int column, java.util.EventObject e) {
            boolean result = super.editCellAt(row, column, e);
            final Component editor = getEditorComponent();

            TableCellRenderer renderer = this.getColumnModel().getColumn(column).getCellRenderer();
            Font cellFont = null;
            if (renderer instanceof DefaultTableCellRenderer) {
                cellFont = ((DefaultTableCellRenderer) renderer).getFont();
            }
            if (editor != null && editor instanceof JTextComponent) {
                JTextComponent jTextComponent = (JTextComponent) editor;
                if (e == null) {
                    jTextComponent.selectAll();
                } else {
                    SwingUtilities.invokeLater(jTextComponent::selectAll);
                }
                jTextComponent.setBorder(UI.MARKED_BORDER_INLINE);
                if (cellFont != null) {
                    jTextComponent.setFont(cellFont);
                }
                editor.requestFocusInWindow();
            }
            return result;
        }

        @Override
        public TableCellRenderer getCellRenderer(int row, int column) {
            TableCellRenderer renderer = super.getCellRenderer(row, column);
            if (renderer instanceof DefaultTableCellRenderer) {
                ((DefaultTableCellRenderer) renderer).setBorder(new EmptyBorder(3, 3, 3, 3));
            }
            return renderer;
        }

        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int row, int col) {
            Component comp = super.prepareRenderer(renderer, row, col);
            // Rollover
            comp.setBackground(getBackground());
            comp = super.prepareRenderer(renderer, row, col);
            if (!isRowSelected(row) && row == rollOverRowIndex.get(keyIdx)) {
                comp.setForeground(getForeground());
                comp.setBackground(UI.BLUE_BACKGROUND_COLOR);
            }

            // Tooltips
            JComponent jcomp = (JComponent) comp;
            if (renderer instanceof DefaultTableCellRenderer) {
                String toolTip = ((DefaultTableCellRenderer) renderer).getToolTipText();
                if (!StringUtils.isEmpty(toolTip)) {
                    jcomp.setToolTipText(toolTip);
                }
            }
            return comp;
        }
    };

    // Table properties
    table.setRowHeight(UI.TABLE_ROW_HEIGHT);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setShowGrid(false);
    table.setShowHorizontalLines(true);
    table.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

    // Rollover
    MouseInputAdapter rolloverListener = new MouseInputAdapter() {
        @Override
        public void mouseExited(MouseEvent e) {
            rollOverRowIndex.put(keyIdx, -1);
            table.repaint();
        }

        @Override
        public void mouseMoved(MouseEvent e) {
            int row = table.rowAtPoint(e.getPoint());
            if (row != rollOverRowIndex.get(keyIdx)) {
                rollOverRowIndex.put(keyIdx, row);
                table.repaint();
            }
        }
    };
    table.addMouseMotionListener(rolloverListener);
    table.addMouseListener(rolloverListener);

    // Header
    if (!showHeader) {
        table.setTableHeader(null);
    }
    return table;
}