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:Main.java

public static void addMiddleButtonDragSupport(Component targetComponent) {
    MouseInputAdapter mia = new MouseInputAdapter() {
        int m_XDifference, m_YDifference;
        boolean m_dragging = false;

        public void mouseDragged(MouseEvent e) {
            if (!m_dragging)
                return;

            Component target = e.getComponent();
            Container c = target.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - m_XDifference);
                int newY = p.y - (e.getY() - m_YDifference);

                int maxX = target.getWidth() - jv.getWidth();
                int maxY = target.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;//from  ww  w  . j  a va  2s .  co  m
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

                jv.setViewPosition(new Point(newX, newY));
            }
        }

        Cursor oldCursor;

        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isMiddleMouseButton(e)) {
                m_dragging = true;
                oldCursor = e.getComponent().getCursor();
                e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                m_XDifference = e.getX();
                m_YDifference = e.getY();
            }
        }

        public void mouseReleased(MouseEvent e) {
            if (m_dragging) {
                e.getComponent().setCursor(oldCursor);
                m_dragging = false;
            }
        }
    };
    targetComponent.addMouseMotionListener(mia);
    targetComponent.addMouseListener(mia);
}

From source file:Main.java

public GrabAndScrollLabel(ImageIcon i) {
    super(i);//from  ww  w  .  ja  va  2  s.c o  m

    MouseInputAdapter mia = new MouseInputAdapter() {
        int xDiff, yDiff;
        Container c;

        public void mouseDragged(MouseEvent e) {
            c = GrabAndScrollLabel.this.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - xDiff);
                int newY = p.y - (e.getY() - yDiff);

                int maxX = GrabAndScrollLabel.this.getWidth() - jv.getWidth();
                int maxY = GrabAndScrollLabel.this.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

                jv.setViewPosition(new Point(newX, newY));
            }
        }

        public void mousePressed(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
            xDiff = e.getX();
            yDiff = e.getY();
        }

        public void mouseReleased(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };
    addMouseMotionListener(mia);
    addMouseListener(mia);
}

From source file:GrabAndDragDemo.java

public GrabAndScrollLabel(ImageIcon i) {
    super(i);// www  .  j  ava2s .  c  o m

    MouseInputAdapter mia = new MouseInputAdapter() {
        int xDiff, yDiff;

        boolean isDragging;

        Container c;

        public void mouseDragged(MouseEvent e) {
            c = GrabAndScrollLabel.this.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - xDiff);
                int newY = p.y - (e.getY() - yDiff);

                int maxX = GrabAndScrollLabel.this.getWidth() - jv.getWidth();
                int maxY = GrabAndScrollLabel.this.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

                jv.setViewPosition(new Point(newX, newY));
            }
        }

        public void mousePressed(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
            xDiff = e.getX();
            yDiff = e.getY();
        }

        public void mouseReleased(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };
    addMouseMotionListener(mia);
    addMouseListener(mia);
}

From source file:com.bwc.ora.OraUtils.java

/**
 * Create the anchor LRP. Does this by creating the LRP model and then adds
 * it to the LRP collections used by the application for storing LRPs for
 * analysis and display/*from   w  w w . jav a  2 s.c  o m*/
 *
 * @param assisted use fovea finding algorithm or manual click to identify
 *                 fovea
 */
public static void generateAnchorLrp(boolean assisted, JButton buttonToEnable) {
    OCTDisplayPanel octDisplayPanel = OCTDisplayPanel.getInstance();
    LrpSettings lrpSettings = ModelsCollection.getInstance().getLrpSettings();
    DisplaySettings displaySettings = ModelsCollection.getInstance().getDisplaySettings();

    if (assisted) {
        JOptionPane.showMessageDialog(null, "Click and drag a window on the OCT which\n"
                + "contains the foveal pit, some of the vitrious,\n"
                + "and some of the Bruch's membrane and choroid.\n"
                + "ORA will the place a LRP at what it believes is\n" + "the center of the foveal pit.\n" + "\n"
                + "Use the arrow keys to move the LRP if desired after placement.\n"
                + "If any setting are adjusted while in this mode\n"
                + "you'll have to click the mouse on the OCT to regain\n"
                + "the ability to move the LRP with the arrow keys.", "Draw foveal pit window",
                JOptionPane.INFORMATION_MESSAGE);

        //allow the user to select region on screen where fovea should be found
        OctWindowSelector octWindowSelector = ModelsCollection.getInstance().getOctWindowSelector();

        MouseInputAdapter selectorMouseListener = new MouseInputAdapter() {
            Point firstPoint = null;
            Point secondPoint = null;
            Point lastWindowPoint = null;

            @Override
            public void mousePressed(MouseEvent e) {
                Collections.getInstance().getOctDrawnLineCollection().clear();
                Collections.getInstance().getLrpCollection().clearLrps();
                if ((firstPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint())) != null) {
                    octWindowSelector.setDisplay(true);
                    displaySettings.setDisplaySelectorWindow(true);
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                secondPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint());
                octWindowSelector.setDisplay(false);
                displaySettings.setDisplaySelectorWindow(false);
                octDisplayPanel.removeMouseListener(this);
                octDisplayPanel.removeMouseMotionListener(this);
                OctPolyLine ilm = ILMsegmenter.segmentILM(firstPoint,
                        secondPoint == null ? lastWindowPoint : secondPoint);
                Collections.getInstance().getOctDrawnLineCollection().add(ilm);
                //use ILM segmented line to find local minima and place LRP
                Point maxYPoint = ilm.stream().max(Comparator.comparingInt(p -> p.y)).orElse(ilm.get(0));
                int fovealCenterX = (int) Math.round(ilm.stream().filter(p -> p.y == maxYPoint.y)
                        .mapToInt(p -> p.x).average().getAsDouble());

                Lrp newLrp;
                try {
                    newLrp = new Lrp("Fovea", fovealCenterX, Oct.getInstance().getImageHeight() / 2,
                            lrpSettings.getLrpWidth(), lrpSettings.getLrpHeight(), LrpType.FOVEAL);
                    lrpCollection.setLrps(Arrays.asList(newLrp));
                    octDisplayPanel.removeMouseListener(this);
                    if (buttonToEnable != null) {
                        buttonToEnable.setEnabled(true);
                    }
                } catch (LRPBoundaryViolationException e1) {
                    JOptionPane.showMessageDialog(null, e1.getMessage() + " Try again.", "LRP generation error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }

            @Override
            public void mouseDragged(MouseEvent e) {
                Point dragPoint;
                if ((dragPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint())) != null) {
                    lastWindowPoint = dragPoint;
                    int minX = Math.min(firstPoint.x, dragPoint.x);
                    int minY = Math.min(firstPoint.y, dragPoint.y);
                    int width = Math.max(firstPoint.x, dragPoint.x) - minX;
                    int height = Math.max(firstPoint.y, dragPoint.y) - minY;
                    octWindowSelector.setRect(minX, minY, width, height);
                    displaySettings.setDisplaySelectorWindow(false);
                    displaySettings.setDisplaySelectorWindow(true);
                }
            }
        };

        octDisplayPanel.addMouseListener(selectorMouseListener);
        octDisplayPanel.addMouseMotionListener(selectorMouseListener);
    } else {
        JOptionPane.showMessageDialog(null,
                "Click on the OCT where the anchor LRP should go.\n" + "Use the arrow keys to move the LRP.\n"
                        + "If any setting are adjusted while in this mode\n"
                        + "you'll have to click the mouse on the OCT to regain\n"
                        + "the ability to move the LRP with the arrow keys.",
                "Click anchor point", JOptionPane.INFORMATION_MESSAGE);
        //listen for the location on the screen where the user clicks, create LRP at location
        octDisplayPanel.addMouseListener(new MouseInputAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                Point clickPoint;
                if ((clickPoint = octDisplayPanel.convertPanelPointToOctPoint(e.getPoint())) != null) {
                    Lrp newLrp;
                    try {
                        newLrp = new Lrp("Fovea", clickPoint.x, clickPoint.y, lrpSettings.getLrpWidth(),
                                lrpSettings.getLrpHeight(), LrpType.FOVEAL);
                        lrpCollection.setLrps(Arrays.asList(newLrp));
                        octDisplayPanel.removeMouseListener(this);
                        if (buttonToEnable != null) {
                            buttonToEnable.setEnabled(true);
                        }
                    } catch (LRPBoundaryViolationException e1) {
                        JOptionPane.showMessageDialog(null, e1.getMessage() + " Try again.",
                                "LRP generation error", JOptionPane.ERROR_MESSAGE);
                        return;
                    }

                }
            }
        });

    }
}

From source file:au.org.ala.delta.intkey.ui.TaxonInformationDialog.java

public TaxonInformationDialog(Frame owner, List<Item> taxa, IntkeyContext context,
        boolean imageDisplayEnabled) {
    super(owner, false);

    setPreferredSize(new Dimension(550, 280));
    setMinimumSize(new Dimension(550, 280));

    ResourceMap resourceMap = Application.getInstance().getContext()
            .getResourceMap(TaxonInformationDialog.class);
    resourceMap.injectFields(this);
    ActionMap actionMap = Application.getInstance().getContext().getActionMap(TaxonInformationDialog.class,
            this);

    setTitle(title);/*from  w ww. j a  v  a 2s. c o m*/
    getContentPane().setLayout(new BorderLayout(0, 0));

    _mainPanel = new JPanel();
    getContentPane().add(_mainPanel, BorderLayout.CENTER);
    _mainPanel.setLayout(new BorderLayout(0, 0));

    _comboPanel = new JPanel();
    _comboPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
    _mainPanel.add(_comboPanel, BorderLayout.NORTH);
    _comboPanel.setLayout(new BorderLayout(0, 0));

    _comboBox = new JComboBox();
    _comboBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            displayTaxon(_comboBox.getSelectedIndex());
        }
    });

    _comboPanel.add(_comboBox, BorderLayout.CENTER);

    _btnPanel = new JPanel();
    _btnPanel.setBorder(new EmptyBorder(0, 0, 10, 0));
    _mainPanel.add(_btnPanel, BorderLayout.SOUTH);

    _btnDisplay = new JButton();
    _btnDisplay.setAction(actionMap.get("displaySelectedTaxonInformation"));
    _btnPanel.add(_btnDisplay);

    _btnMultipleImages = new JButton();
    _btnMultipleImages.setAction(actionMap.get("displayMultipleImages"));
    _btnMultipleImages.setEnabled(!context.displayContinuous() && imageDisplayEnabled);
    _btnPanel.add(_btnMultipleImages);

    _btnWebSearch = new JButton();
    _btnWebSearch.setAction(actionMap.get("webSearch"));
    _btnWebSearch.setEnabled(true);
    _btnPanel.add(_btnWebSearch);

    _btnDeselectAll = new JButton();
    _btnDeselectAll.setAction(actionMap.get("deselectAllTaxonInformation"));
    _btnPanel.add(_btnDeselectAll);

    _btnDone = new JButton();
    _btnDone.setAction(actionMap.get("done"));
    _btnPanel.add(_btnDone);

    _pnlCenter = new JPanel();
    _mainPanel.add(_pnlCenter, BorderLayout.CENTER);
    _pnlCenter.setLayout(new BorderLayout(0, 0));

    _pnlNavigationButtons = new JPanel();
    _pnlCenter.add(_pnlNavigationButtons, BorderLayout.NORTH);

    _btnStart = new JButton();
    _btnStart.setAction(actionMap.get("firstTaxon"));
    _pnlNavigationButtons.add(_btnStart);

    _btnPrevious = new JButton();
    _btnPrevious.setAction(actionMap.get("previousTaxon"));
    _pnlNavigationButtons.add(_btnPrevious);

    _btnForward = new JButton();
    _btnForward.setAction(actionMap.get("nextTaxon"));
    _pnlNavigationButtons.add(_btnForward);

    _btnEnd = new JButton();
    _btnEnd.setAction(actionMap.get("lastTaxon"));
    _pnlNavigationButtons.add(_btnEnd);

    _pnlLists = new JPanel();
    _pnlCenter.add(_pnlLists, BorderLayout.CENTER);
    _pnlLists.setLayout(new GridLayout(0, 2, 0, 0));

    _pnlListOther = new JPanel();
    _pnlListOther.setBorder(new EmptyBorder(5, 5, 5, 5));
    _pnlLists.add(_pnlListOther);
    _pnlListOther.setLayout(new BorderLayout(0, 0));

    _listOther = new JList();
    _listOther.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                int selectedIndex = _listOther.getSelectedIndex();
                _cmds.get(selectedIndex).execute();
            }
        }

    });

    _sclPnOther = new JScrollPane();
    _sclPnOther.setViewportView(_listOther);
    _pnlListOther.add(_sclPnOther, BorderLayout.CENTER);

    _lblOther = new JLabel();
    _pnlListOther.add(_lblOther, BorderLayout.NORTH);

    _pnlListIllustrations = new JPanel();
    _pnlListIllustrations.setBorder(new EmptyBorder(5, 5, 5, 5));
    _pnlLists.add(_pnlListIllustrations);
    _pnlListIllustrations.setLayout(new BorderLayout(0, 0));

    _lblIllustrations = new JLabel();
    _pnlListIllustrations.add(_lblIllustrations, BorderLayout.NORTH);

    _listIllustrations = new JList();
    _listIllustrations.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                if (_imageDisplayEnabled) {
                    int selectedListIndex = _listIllustrations.getSelectedIndex();
                    displaySelectedTaxonImage(selectedListIndex, true);
                } else {
                    _context.getUI()
                            .displayErrorMessage(UIUtils.getResourceString("ImageDisplayDisabled.error"));
                }
            }
        }

    });

    _sclPnIllustrations = new JScrollPane();

    _sclPnIllustrations.setViewportView(_listIllustrations);
    _pnlListIllustrations.add(_sclPnIllustrations);

    _context = context;
    _imageDisplayEnabled = imageDisplayEnabled;
    _definedDirectiveCommands = _context.getTaxonInformationDialogCommands();

    _infoSettings = _context.getInfoSettings();
    _imageSettings = _context.getImageSettings();
    _itemFormatter = new ItemFormatter(_context.displayNumbering(), CommentStrippingMode.RETAIN,
            AngleBracketHandlingMode.REMOVE, true, false, false);
    _imageDescriptionFormatter = new Formatter(CommentStrippingMode.RETAIN, AngleBracketHandlingMode.RETAIN,
            true, false);

    int totalNumberImages = 0;
    _taxa = taxa;
    _taxaWithImages = new ArrayList<Item>();
    for (Item taxon : taxa) {
        totalNumberImages += taxon.getImageCount();
        if (taxon.getImageCount() > 0) {
            _taxaWithImages.add(taxon);
        }
    }

    if (totalNumberImages < 2) {
        _btnMultipleImages.setEnabled(false);
    }

    initialize();

    loadDesktopInBackground();

    this.pack();
}

From source file:JavaXWin.java

public WindowWatcher(JDesktopPane desktop) {
    m_desktop = desktop;//from   www  .jav  a  2  s.c  o  m
    setOpaque(true);

    m_northResizer = new NorthResizeEdge(this);
    m_southResizer = new SouthResizeEdge(this);
    m_eastResizer = new EastResizeEdge(this);
    m_westResizer = new WestResizeEdge(this);

    setLayout(new BorderLayout());
    add(m_northResizer, BorderLayout.NORTH);
    add(m_southResizer, BorderLayout.SOUTH);
    add(m_eastResizer, BorderLayout.EAST);
    add(m_westResizer, BorderLayout.WEST);

    MouseInputAdapter ma = new MouseInputAdapter() {
        public void mousePressed(MouseEvent e) {
            m_XDifference = e.getX();
            m_YDifference = e.getY();
        }

        public void mouseDragged(MouseEvent e) {
            int vx = 0;
            int vy = 0;
            if (m_desktop.getParent() instanceof JViewport) {
                vx = ((JViewport) m_desktop.getParent()).getViewPosition().x;
                vy = ((JViewport) m_desktop.getParent()).getViewPosition().y;
            }
            int w = m_desktop.getParent().getWidth();
            int h = m_desktop.getParent().getHeight();
            int x = getX();
            int y = getY();
            int ex = e.getX();
            int ey = e.getY();
            if ((ey + y > vy && ey + y < h + vy) && (ex + x > vx && ex + x < w + vx)) {
                setLocation(ex - m_XDifference + x, ey - m_YDifference + y);
            } else if (!(ey + y > vy && ey + y < h + vy) && (ex + x > vx && ex + x < w + vx)) {
                if (!(ey + y > vy) && ey + y < h + vy)
                    setLocation(ex - m_XDifference + x, vy - m_YDifference);
                else if (ey + y > vy && !(ey + y < h + vy))
                    setLocation(ex - m_XDifference + x, (h + vy) - m_YDifference);
            } else if ((ey + y > vy && ey + y < h + vy) && !(ex + x > vx && ex + x < w + vx)) {
                if (!(ex + x > vx) && ex + x < w + vx)
                    setLocation(vx - m_XDifference, ey - m_YDifference + y);
                else if (ex + x > vx && !(ex + x < w))
                    setLocation((w + vx) - m_XDifference, ey - m_YDifference + y);
            } else if (!(ey + y > vy) && ey + y < h + vy && !(ex + x > vx) && ex + x < w + vx)
                setLocation(vx - m_XDifference, vy - m_YDifference);
            else if (!(ey + y > vy) && ey + y < h + vy && ex + x > vx && !(ex + x < w + vx))
                setLocation((w + vx) - m_XDifference, vy - m_YDifference);
            else if (ey + y > vy && !(ey + y < h + vy) && !(ex + x > vx) && ex + x < w + vx)
                setLocation(vx - m_XDifference, (h + vy) - m_YDifference);
            else if (ey + y > vy && !(ey + y < h + vy) && ex + x > vx && !(ex + x < w + vx))
                setLocation((w + vx) - m_XDifference, (h + vy) - m_YDifference);
        }

        public void mouseEntered(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
        }

        public void mouseExited(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };
    addMouseListener(ma);
    addMouseMotionListener(ma);
}

From source file:ca.phon.app.session.editor.view.session_information.SessionInfoEditorView.java

private void init() {
    setLayout(new BorderLayout());

    contentPanel = new TierDataLayoutPanel();

    dateField = createDateField();/* w w  w . j a  va  2 s  .  co  m*/
    dateField.getTextField().setColumns(10);
    dateField.setBackground(Color.white);

    mediaLocationField = new MediaSelectionField(getEditor().getProject());
    mediaLocationField.setEditor(getEditor());
    mediaLocationField.getTextField().setColumns(10);
    mediaLocationField.addPropertyChangeListener(FileSelectionField.FILE_PROP, mediaLocationListener);

    participantTable = new JXTable();
    participantTable.setVisibleRowCount(3);

    ComponentInputMap participantTableInputMap = new ComponentInputMap(participantTable);
    ActionMap participantTableActionMap = new ActionMap();

    ImageIcon deleteIcon = IconManager.getInstance().getIcon("actions/delete_user", IconSize.SMALL);
    final PhonUIAction deleteAction = new PhonUIAction(this, "deleteParticipant");
    deleteAction.putValue(PhonUIAction.SHORT_DESCRIPTION, "Delete selected participant");
    deleteAction.putValue(PhonUIAction.SMALL_ICON, deleteIcon);
    participantTableActionMap.put("DELETE_PARTICIPANT", deleteAction);
    participantTableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "DELETE_PARTICIPANT");
    participantTableInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "DELETE_PARTICIPANT");

    removeParticipantButton = new JButton(deleteAction);

    participantTable.setInputMap(WHEN_FOCUSED, participantTableInputMap);
    participantTable.setActionMap(participantTableActionMap);

    addParticipantButton = new JButton(new NewParticipantAction(getEditor(), this));
    addParticipantButton.setFocusable(false);

    ImageIcon editIcon = IconManager.getInstance().getIcon("actions/edit_user", IconSize.SMALL);
    final PhonUIAction editParticipantAct = new PhonUIAction(this, "editParticipant");
    editParticipantAct.putValue(PhonUIAction.NAME, "Edit participant...");
    editParticipantAct.putValue(PhonUIAction.SHORT_DESCRIPTION, "Edit selected participant...");
    editParticipantAct.putValue(PhonUIAction.SMALL_ICON, editIcon);
    editParticipantButton = new JButton(editParticipantAct);
    editParticipantButton.setFocusable(false);

    final CellConstraints cc = new CellConstraints();
    FormLayout participantLayout = new FormLayout("fill:pref:grow, pref, pref, pref", "pref, pref, pref:grow");
    JPanel participantPanel = new JPanel(participantLayout);
    participantPanel.setBackground(Color.white);
    participantPanel.add(new JScrollPane(participantTable), cc.xywh(1, 2, 3, 2));
    participantPanel.add(addParticipantButton, cc.xy(2, 1));
    participantPanel.add(editParticipantButton, cc.xy(3, 1));
    participantPanel.add(removeParticipantButton, cc.xy(4, 2));
    participantTable.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent arg0) {
            if (arg0.getClickCount() == 2 && arg0.getButton() == MouseEvent.BUTTON1) {
                editParticipantAct.actionPerformed(new ActionEvent(arg0.getSource(), arg0.getID(), "edit"));
            }
        }

    });

    languageField = new LanguageField();
    languageField.getDocument().addDocumentListener(languageFieldListener);

    int rowIdx = 0;
    final JLabel dateLbl = new JLabel("Session Date");
    dateLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(dateLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(dateField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    final JLabel mediaLbl = new JLabel("Media");
    mediaLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(mediaLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(mediaLocationField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    final JLabel partLbl = new JLabel("Participants");
    partLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(partLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(participantPanel, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    final JLabel langLbl = new JLabel("Language");
    langLbl.setHorizontalAlignment(SwingConstants.RIGHT);
    contentPanel.add(langLbl, new TierDataConstraint(TierDataConstraint.TIER_LABEL_COLUMN, rowIdx));
    contentPanel.add(languageField, new TierDataConstraint(TierDataConstraint.FLAT_TIER_COLUMN, rowIdx++));

    add(new JScrollPane(contentPanel), BorderLayout.CENTER);

    update();
}

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

private void init() {
    /* Layout *//*from  w ww  . j  a  v a2 s. c om*/
    setLayout(new BorderLayout());

    final ProjectDataTransferHandler transferHandler = new ProjectDataTransferHandler(this);

    /* Create components */
    newCorpusButton = createNewCorpusButton();
    createCorpusButton = createCorpusButton();

    corpusList = new JList<String>();
    corpusModel = new CorpusListModel(getProject());
    corpusList.setModel(corpusModel);
    corpusList.setCellRenderer(new CorpusListCellRenderer());
    corpusList.setVisibleRowCount(20);
    corpusList.addListSelectionListener(e -> {
        if (getSelectedCorpus() != null) {
            String corpus = getSelectedCorpus();
            sessionModel.setCorpus(corpus);
            sessionList.clearSelection();
            corpusDetails.setCorpus(corpus);

            if (getProject().getCorpusSessions(corpus).size() == 0) {
                onSwapNewAndCreateSession(newSessionButton);
            } else {
                onSwapNewAndCreateSession(createSessionButton);
            }
        }
    });
    corpusList.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            doPopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            doPopup(e);
        }

        public void doPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                int clickedIdx = corpusList.locationToIndex(e.getPoint());
                if (clickedIdx >= 0 && Arrays.binarySearch(corpusList.getSelectedIndices(), clickedIdx) < 0) {
                    corpusList.setSelectedIndex(clickedIdx);
                }
                showCorpusListContextMenu(e.getPoint());
            }
        }
    });

    final DragSource corpusDragSource = new DragSource();
    corpusDragSource.createDefaultDragGestureRecognizer(corpusList, DnDConstants.ACTION_COPY, (event) -> {
        final List<ProjectPath> paths = new ArrayList<>();
        for (String corpus : getSelectedCorpora()) {
            final ProjectPath corpusPath = new ProjectPath(getProject(), corpus, null);
            paths.add(corpusPath);
        }
        final ProjectPathTransferable transferable = new ProjectPathTransferable(paths);
        event.startDrag(DragSource.DefaultCopyDrop, transferable);
    });

    corpusList.setDragEnabled(true);
    corpusList.setTransferHandler(transferHandler);

    corpusDetails = new CorpusDetailsPane(getProject());
    corpusDetails.setWrapStyleWord(true);
    corpusDetails.setRows(6);
    corpusDetails.setLineWrap(true);
    corpusDetails.setBackground(Color.white);
    corpusDetails.setOpaque(true);
    JScrollPane corpusDetailsScroller = new JScrollPane(corpusDetails);

    sessionList = new JList<String>();
    newSessionButton = createNewSessionButton();
    createSessionButton = createSessionButton();
    sessionModel = new SessionListModel(getProject());
    sessionList.setModel(sessionModel);
    sessionList.setCellRenderer(new SessionListCellRenderer());
    sessionList.setVisibleRowCount(20);
    sessionList.addListSelectionListener(e -> {
        if (sessionList.getSelectedValue() != null && !e.getValueIsAdjusting()) {
            String corpus = getSelectedCorpus();
            String session = getSelectedSessionName();

            sessionDetails.setSession(corpus, session);
        }
    });
    sessionList.addMouseListener(new MouseInputAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && e.getButton() == 1) {
                // get the clicked item
                int clickedItem = sessionList.locationToIndex(e.getPoint());
                if (sessionList.getModel().getElementAt(clickedItem) == null)
                    return;

                final String session = sessionList.getModel().getElementAt(clickedItem).toString();
                final String corpus = ((SessionListModel) sessionList.getModel()).getCorpus();

                msgPanel.reset();
                msgPanel.setMessageLabel("Opening '" + corpus + "." + session + "'");
                msgPanel.setIndeterminate(true);
                msgPanel.repaint();

                SwingUtilities.invokeLater(() -> {
                    final ActionEvent ae = new ActionEvent(sessionList, -1, "openSession");
                    (new OpenSessionAction(ProjectWindow.this, corpus, session)).actionPerformed(ae);

                    msgPanel.setIndeterminate(false);
                });
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            doPopup(e);
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            doPopup(e);
        }

        public void doPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                int clickedIdx = sessionList.locationToIndex(e.getPoint());
                if (clickedIdx >= 0 && Arrays.binarySearch(sessionList.getSelectedIndices(), clickedIdx) < 0) {
                    sessionList.setSelectedIndex(clickedIdx);
                }
                showSessionListContextMenu(e.getPoint());
            }
        }
    });

    sessionList.setDragEnabled(true);
    sessionList.setTransferHandler(transferHandler);

    final DragSource sessionDragSource = new DragSource();
    sessionDragSource.createDefaultDragGestureRecognizer(sessionList, DnDConstants.ACTION_COPY, (event) -> {
        final List<ProjectPath> paths = new ArrayList<>();
        final String corpus = getSelectedCorpus();
        if (corpus == null)
            return;
        for (String session : getSelectedSessionNames()) {
            final ProjectPath sessionPath = new ProjectPath(getProject(), corpus, session);
            paths.add(sessionPath);
        }
        final ProjectPathTransferable transferable = new ProjectPathTransferable(paths);
        event.startDrag(DragSource.DefaultCopyDrop, transferable);
    });

    sessionDetails = new SessionDetailsPane(getProject());
    sessionDetails.setLineWrap(true);
    sessionDetails.setRows(6);
    sessionDetails.setWrapStyleWord(true);
    sessionDetails.setBackground(Color.white);
    sessionDetails.setOpaque(true);
    JScrollPane sessionDetailsScroller = new JScrollPane(sessionDetails);

    JScrollPane corpusScroller = new JScrollPane(corpusList);
    JScrollPane sessionScroller = new JScrollPane(sessionList);

    blindModeBox = new JCheckBox("Blind transcription");
    blindModeBox.setSelected(false);

    msgPanel = new StatusPanel();

    corpusPanel = new JPanel(new BorderLayout());
    corpusPanel.add(newCorpusButton, BorderLayout.NORTH);
    corpusPanel.add(corpusScroller, BorderLayout.CENTER);
    corpusPanel.add(corpusDetailsScroller, BorderLayout.SOUTH);

    sessionPanel = new JPanel(new BorderLayout());
    sessionPanel.add(newSessionButton, BorderLayout.NORTH);
    sessionPanel.add(sessionScroller, BorderLayout.CENTER);
    sessionPanel.add(sessionDetailsScroller, BorderLayout.SOUTH);

    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setLeftComponent(corpusPanel);
    splitPane.setRightComponent(sessionPanel);
    splitPane.setResizeWeight(0.5);

    // invoke later
    SwingUtilities.invokeLater(() -> {
        splitPane.setDividerLocation(0.5);
    });

    // the frame layout
    String projectName = null;
    projectName = getProject().getName();

    DialogHeader header = new DialogHeader(projectName, StringUtils.abbreviate(projectLoadPath, 80));

    add(header, BorderLayout.NORTH);

    CellConstraints cc = new CellConstraints();
    final JPanel topPanel = new JPanel(new FormLayout("pref, fill:pref:grow, right:pref", "pref"));
    topPanel.add(msgPanel, cc.xy(1, 1));
    topPanel.add(blindModeBox, cc.xy(3, 1));

    add(splitPane, BorderLayout.CENTER);
    add(topPanel, BorderLayout.SOUTH);

    // if no corpora are currently available, 'prompt' the user to create a new one
    if (getProject().getCorpora().size() == 0) {
        SwingUtilities.invokeLater(() -> {
            onSwapNewAndCreateCorpus(newCorpusButton);
        });
    } else {
        SwingUtilities.invokeLater(() -> {
            corpusList.setSelectedIndex(0);
        });
    }
}

From source file:au.org.ala.delta.intkey.Intkey.java

/**
 * Creates and shows the GUI. Called by the swing application framework
 *//*from  w ww .  j av a 2  s.c om*/
@Override
protected void startup() {
    final JFrame mainFrame = getMainFrame();
    _defaultGlassPane = mainFrame.getGlassPane();
    mainFrame.setTitle("Intkey");
    mainFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
    mainFrame.setIconImages(IconHelper.getRedIconList());

    _helpController = new HelpController(HELPSET_PATH);

    _taxonformatter = new ItemFormatter(false, CommentStrippingMode.STRIP_ALL, AngleBracketHandlingMode.REMOVE,
            true, false, true);
    _context = new IntkeyContext(new IntkeyUIInterceptor(this), new DirectivePopulatorInterceptor(this));

    _advancedModeOnlyDynamicButtons = new ArrayList<JButton>();
    _normalModeOnlyDynamicButtons = new ArrayList<JButton>();
    _activeOnlyWhenCharactersUsedButtons = new ArrayList<JButton>();
    _dynamicButtonsFullHelp = new HashMap<JButton, String>();

    ActionMap actionMap = getContext().getActionMap();

    _rootPanel = new JPanel();
    _rootPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    _rootPanel.setBackground(SystemColor.control);
    _rootPanel.setLayout(new BorderLayout(0, 0));

    _globalOptionBar = new JPanel();
    _globalOptionBar.setBorder(new EmptyBorder(0, 5, 0, 5));
    _rootPanel.add(_globalOptionBar, BorderLayout.NORTH);
    _globalOptionBar.setLayout(new BorderLayout(0, 0));

    _pnlDynamicButtons = new JPanel();
    FlowLayout flowLayout_1 = (FlowLayout) _pnlDynamicButtons.getLayout();
    flowLayout_1.setVgap(0);
    flowLayout_1.setHgap(0);
    _globalOptionBar.add(_pnlDynamicButtons, BorderLayout.WEST);

    _btnContextHelp = new JButton();
    _btnContextHelp.setMinimumSize(new Dimension(30, 30));
    _btnContextHelp.setMaximumSize(new Dimension(30, 30));
    _btnContextHelp.setAction(actionMap.get("btnContextHelp"));
    _btnContextHelp.setPreferredSize(new Dimension(30, 30));
    _btnContextHelp.setMargin(new Insets(2, 5, 2, 5));
    _btnContextHelp.addActionListener(actionMap.get("btnContextHelp"));
    _globalOptionBar.add(_btnContextHelp, BorderLayout.EAST);

    _rootSplitPane = new JSplitPane();
    _rootSplitPane.setDividerSize(3);
    _rootSplitPane.setResizeWeight(0.5);
    _rootSplitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
    _rootSplitPane.setContinuousLayout(true);
    _rootPanel.add(_rootSplitPane);

    _innerSplitPaneLeft = new JSplitPane();
    _innerSplitPaneLeft.setMinimumSize(new Dimension(25, 25));
    _innerSplitPaneLeft.setAlignmentX(Component.CENTER_ALIGNMENT);
    _innerSplitPaneLeft.setDividerSize(3);
    _innerSplitPaneLeft.setResizeWeight(0.5);

    _innerSplitPaneLeft.setContinuousLayout(true);
    _innerSplitPaneLeft.setOrientation(JSplitPane.VERTICAL_SPLIT);
    _rootSplitPane.setLeftComponent(_innerSplitPaneLeft);

    _pnlAvailableCharacters = new JPanel();
    _innerSplitPaneLeft.setLeftComponent(_pnlAvailableCharacters);
    _pnlAvailableCharacters.setLayout(new BorderLayout(0, 0));

    _sclPaneAvailableCharacters = new JScrollPane();
    _pnlAvailableCharacters.add(_sclPaneAvailableCharacters, BorderLayout.CENTER);

    _listAvailableCharacters = new JList();
    // _listAvailableCharacters.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    _listAvailableCharacters.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    _listAvailableCharacters.setCellRenderer(_availableCharactersListCellRenderer);
    _listAvailableCharacters.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                int selectedIndex = _listAvailableCharacters.getSelectedIndex();
                if (selectedIndex >= 0) {
                    try {
                        Character ch = (Character) _availableCharacterListModel.getElementAt(selectedIndex);
                        executeDirective(new UseDirective(), Integer.toString(ch.getCharacterId()));
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    });

    _sclPaneAvailableCharacters.setViewportView(_listAvailableCharacters);

    _pnlAvailableCharactersHeader = new JPanel();
    _pnlAvailableCharacters.add(_pnlAvailableCharactersHeader, BorderLayout.NORTH);
    _pnlAvailableCharactersHeader.setLayout(new BorderLayout(0, 0));

    _lblNumAvailableCharacters = new JLabel();
    _lblNumAvailableCharacters.setBorder(new EmptyBorder(0, 5, 0, 0));
    _lblNumAvailableCharacters.setFont(new Font("Tahoma", Font.PLAIN, 15));
    _lblNumAvailableCharacters.setText(MessageFormat.format(availableCharactersCaption, 0));
    _pnlAvailableCharactersHeader.add(_lblNumAvailableCharacters, BorderLayout.WEST);

    _pnlAvailableCharactersButtons = new JPanel();
    FlowLayout flowLayout = (FlowLayout) _pnlAvailableCharactersButtons.getLayout();
    flowLayout.setVgap(2);
    flowLayout.setHgap(2);
    _pnlAvailableCharactersHeader.add(_pnlAvailableCharactersButtons, BorderLayout.EAST);

    // All toolbar buttons should be disabled until a dataset is loaded.
    _btnRestart = new JButton();
    _btnRestart.setAction(actionMap.get("btnRestart"));
    _btnRestart.setPreferredSize(new Dimension(30, 30));
    _btnRestart.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnRestart);

    _btnBestOrder = new JButton();
    _btnBestOrder.setAction(actionMap.get("btnBestOrder"));
    _btnBestOrder.setPreferredSize(new Dimension(30, 30));
    _btnBestOrder.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnBestOrder);

    _btnSeparate = new JButton();
    _btnSeparate.setAction(actionMap.get("btnSeparate"));
    _btnSeparate.setVisible(_advancedMode);
    _btnSeparate.setPreferredSize(new Dimension(30, 30));
    _btnSeparate.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnSeparate);

    _btnNaturalOrder = new JButton();
    _btnNaturalOrder.setAction(actionMap.get("btnNaturalOrder"));
    _btnNaturalOrder.setPreferredSize(new Dimension(30, 30));
    _btnNaturalOrder.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnNaturalOrder);

    _btnDiffSpecimenTaxa = new JButton();
    _btnDiffSpecimenTaxa.setAction(actionMap.get("btnDiffSpecimenTaxa"));
    _btnDiffSpecimenTaxa.setEnabled(false);
    _btnDiffSpecimenTaxa.setPreferredSize(new Dimension(30, 30));
    _pnlAvailableCharactersButtons.add(_btnDiffSpecimenTaxa);

    _btnSetTolerance = new JButton();
    _btnSetTolerance.setAction(actionMap.get("btnSetTolerance"));
    _btnSetTolerance.setPreferredSize(new Dimension(30, 30));
    _btnSetTolerance.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnSetTolerance);

    _btnSetMatch = new JButton();
    _btnSetMatch.setAction(actionMap.get("btnSetMatch"));
    _btnSetMatch.setVisible(_advancedMode);
    _btnSetMatch.setPreferredSize(new Dimension(30, 30));
    _btnSetMatch.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnSetMatch);

    _btnSubsetCharacters = new JButton();
    _btnSubsetCharacters.setAction(actionMap.get("btnSubsetCharacters"));
    _btnSubsetCharacters.setPreferredSize(new Dimension(30, 30));
    _btnSubsetCharacters.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnSubsetCharacters);

    _btnFindCharacter = new JButton();
    _btnFindCharacter.setAction(actionMap.get("btnFindCharacter"));
    _btnFindCharacter.setPreferredSize(new Dimension(30, 30));
    _btnFindCharacter.setEnabled(false);
    _pnlAvailableCharactersButtons.add(_btnFindCharacter);

    _pnlAvailableCharactersButtons.setEnabled(false);

    _pnlUsedCharacters = new JPanel();
    _innerSplitPaneLeft.setRightComponent(_pnlUsedCharacters);
    _pnlUsedCharacters.setLayout(new BorderLayout(0, 0));

    _sclPnUsedCharacters = new JScrollPane();
    _pnlUsedCharacters.add(_sclPnUsedCharacters, BorderLayout.CENTER);

    _listUsedCharacters = new JList();
    _listUsedCharacters.setCellRenderer(_usedCharactersListCellRenderer);
    _listUsedCharacters.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    _listUsedCharacters.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                int selectedIndex = _listUsedCharacters.getSelectedIndex();
                if (selectedIndex >= 0) {
                    try {
                        Attribute attr = (Attribute) _usedCharacterListModel.getElementAt(selectedIndex);

                        if (_context.charactersFixed() && _context.getFixedCharactersList()
                                .contains(attr.getCharacter().getCharacterId())) {
                            return;
                        }

                        executeDirective(new ChangeDirective(),
                                Integer.toString(attr.getCharacter().getCharacterId()));
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
        }
    });

    _sclPnUsedCharacters.setViewportView(_listUsedCharacters);

    _pnlUsedCharactersHeader = new JPanel();
    _pnlUsedCharacters.add(_pnlUsedCharactersHeader, BorderLayout.NORTH);
    _pnlUsedCharactersHeader.setLayout(new BorderLayout(0, 0));

    _lblNumUsedCharacters = new JLabel();
    _lblNumUsedCharacters.setBorder(new EmptyBorder(7, 5, 7, 0));
    _lblNumUsedCharacters.setFont(new Font("Tahoma", Font.PLAIN, 15));
    _lblNumUsedCharacters.setText(MessageFormat.format(usedCharactersCaption, 0));
    _pnlUsedCharactersHeader.add(_lblNumUsedCharacters, BorderLayout.WEST);

    _innerSplitPaneRight = new JSplitPane();
    _innerSplitPaneRight.setMinimumSize(new Dimension(25, 25));
    _innerSplitPaneRight.setDividerSize(3);
    _innerSplitPaneRight.setResizeWeight(0.5);
    _innerSplitPaneRight.setContinuousLayout(true);
    _innerSplitPaneRight.setOrientation(JSplitPane.VERTICAL_SPLIT);
    _rootSplitPane.setRightComponent(_innerSplitPaneRight);

    _pnlRemainingTaxa = new JPanel();
    _innerSplitPaneRight.setLeftComponent(_pnlRemainingTaxa);
    _pnlRemainingTaxa.setLayout(new BorderLayout(0, 0));

    _sclPnRemainingTaxa = new JScrollPane();
    _pnlRemainingTaxa.add(_sclPnRemainingTaxa, BorderLayout.CENTER);

    _listRemainingTaxa = new JList();

    _listRemainingTaxa.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                displayInfoForSelectedTaxa();
            }
        }
    });

    _sclPnRemainingTaxa.setViewportView(_listRemainingTaxa);

    _pnlRemainingTaxaHeader = new JPanel();
    _pnlRemainingTaxa.add(_pnlRemainingTaxaHeader, BorderLayout.NORTH);
    _pnlRemainingTaxaHeader.setLayout(new BorderLayout(0, 0));

    _lblNumRemainingTaxa = new JLabel();
    _lblNumRemainingTaxa.setBorder(new EmptyBorder(0, 5, 0, 0));
    _lblNumRemainingTaxa.setFont(new Font("Tahoma", Font.PLAIN, 15));
    _lblNumRemainingTaxa.setText(MessageFormat.format(remainingTaxaCaption, 0));
    _pnlRemainingTaxaHeader.add(_lblNumRemainingTaxa, BorderLayout.WEST);

    _pnlRemainingTaxaButtons = new JPanel();
    FlowLayout fl_pnlRemainingTaxaButtons = (FlowLayout) _pnlRemainingTaxaButtons.getLayout();
    fl_pnlRemainingTaxaButtons.setVgap(2);
    fl_pnlRemainingTaxaButtons.setHgap(2);
    _pnlRemainingTaxaHeader.add(_pnlRemainingTaxaButtons, BorderLayout.EAST);

    // All toolbar buttons should be disabled until a dataset is loaded.
    _btnTaxonInfo = new JButton();
    _btnTaxonInfo.setAction(actionMap.get("btnTaxonInfo"));
    _btnTaxonInfo.setPreferredSize(new Dimension(30, 30));
    _btnTaxonInfo.setEnabled(false);
    _pnlRemainingTaxaButtons.add(_btnTaxonInfo);

    _btnDiffTaxa = new JButton();
    _btnDiffTaxa.setAction(actionMap.get("btnDiffTaxa"));
    _btnDiffTaxa.setPreferredSize(new Dimension(30, 30));
    _btnDiffTaxa.setEnabled(false);
    _pnlRemainingTaxaButtons.add(_btnDiffTaxa);

    _btnSubsetTaxa = new JButton();
    _btnSubsetTaxa.setAction(actionMap.get("btnSubsetTaxa"));
    _btnSubsetTaxa.setPreferredSize(new Dimension(30, 30));
    _btnSubsetTaxa.setEnabled(false);
    _pnlRemainingTaxaButtons.add(_btnSubsetTaxa);

    _btnFindTaxon = new JButton();
    _btnFindTaxon.setAction(actionMap.get("btnFindTaxon"));
    _btnFindTaxon.setPreferredSize(new Dimension(30, 30));
    _btnFindTaxon.setEnabled(false);
    _pnlRemainingTaxaButtons.add(_btnFindTaxon);

    _pnlEliminatedTaxa = new JPanel();
    _innerSplitPaneRight.setRightComponent(_pnlEliminatedTaxa);
    _pnlEliminatedTaxa.setLayout(new BorderLayout(0, 0));

    _sclPnEliminatedTaxa = new JScrollPane();
    _pnlEliminatedTaxa.add(_sclPnEliminatedTaxa, BorderLayout.CENTER);

    _listEliminatedTaxa = new JList();

    _listEliminatedTaxa.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() >= 2) {
                displayInfoForSelectedTaxa();
            }
        }
    });

    _sclPnEliminatedTaxa.setViewportView(_listEliminatedTaxa);

    _pnlEliminatedTaxaHeader = new JPanel();
    _pnlEliminatedTaxa.add(_pnlEliminatedTaxaHeader, BorderLayout.NORTH);
    _pnlEliminatedTaxaHeader.setLayout(new BorderLayout(0, 0));

    _lblEliminatedTaxa = new JLabel();
    _lblEliminatedTaxa.setBorder(new EmptyBorder(7, 5, 7, 0));
    _lblEliminatedTaxa.setFont(new Font("Tahoma", Font.PLAIN, 15));
    _lblEliminatedTaxa.setText(MessageFormat.format(eliminatedTaxaCaption, 0));
    _pnlEliminatedTaxaHeader.add(_lblEliminatedTaxa, BorderLayout.WEST);

    JMenuBar menuBar = buildMenus(_advancedMode);
    getMainView().setMenuBar(menuBar);

    _txtFldCmdBar = new JTextField();
    _txtFldCmdBar.setCaretColor(Color.WHITE);
    _txtFldCmdBar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            String cmdStr = _txtFldCmdBar.getText();

            cmdStr = cmdStr.trim();
            if (_cmdMenus.containsKey(cmdStr)) {
                JMenu cmdMenu = _cmdMenus.get(cmdStr);
                cmdMenu.doClick();
            } else {
                _context.parseAndExecuteDirective(cmdStr);
            }
            _txtFldCmdBar.setText(null);
        }
    });

    _txtFldCmdBar.setFont(new Font("Courier New", Font.BOLD, 13));
    _txtFldCmdBar.setForeground(SystemColor.text);
    _txtFldCmdBar.setBackground(Color.BLACK);
    _txtFldCmdBar.setOpaque(true);
    _txtFldCmdBar.setVisible(_advancedMode);
    _rootPanel.add(_txtFldCmdBar, BorderLayout.SOUTH);
    _txtFldCmdBar.setColumns(10);

    _logDialog = new RtfReportDisplayDialog(getMainFrame(), new SimpleRtfEditorKit(null), null, logDialogTitle);

    // Set context-sensitive help keys for toolbar buttons
    _helpController.setHelpKeyForComponent(_btnRestart, HELP_ID_CHARACTERS_TOOLBAR_RESTART);
    _helpController.setHelpKeyForComponent(_btnBestOrder, HELP_ID_CHARACTERS_TOOLBAR_BEST);
    _helpController.setHelpKeyForComponent(_btnSeparate, HELP_ID_CHARACTERS_TOOLBAR_SEPARATE);
    _helpController.setHelpKeyForComponent(_btnNaturalOrder, HELP_ID_CHARACTERS_TOOLBAR_NATURAL);
    _helpController.setHelpKeyForComponent(_btnDiffSpecimenTaxa,
            HELP_ID_CHARACTERS_TOOLBAR_DIFF_SPECIMEN_REMAINING);
    _helpController.setHelpKeyForComponent(_btnSetTolerance, HELP_ID_CHARACTERS_TOOLBAR_TOLERANCE);
    _helpController.setHelpKeyForComponent(_btnSetMatch, HELP_ID_CHARACTERS_TOOLBAR_SET_MATCH);
    _helpController.setHelpKeyForComponent(_btnSubsetCharacters, HELP_ID_CHARACTERS_TOOLBAR_SUBSET_CHARACTERS);
    _helpController.setHelpKeyForComponent(_btnFindCharacter, HELP_ID_CHARACTERS_TOOLBAR_FIND_CHARACTERS);

    _helpController.setHelpKeyForComponent(_btnTaxonInfo, HELP_ID_TAXA_TOOLBAR_INFO);
    _helpController.setHelpKeyForComponent(_btnDiffTaxa, HELP_ID_TAXA_TOOLBAR_DIFF_TAXA);
    _helpController.setHelpKeyForComponent(_btnSubsetTaxa, HELP_ID_TAXA_TOOLBAR_SUBSET_TAXA);
    _helpController.setHelpKeyForComponent(_btnFindTaxon, HELP_ID_TAXA_TOOLBAR_FIND_TAXA);

    // This mouse listener on the default glasspane is to assist with
    // context senstive help. It intercepts the mouse events,
    // determines what component was being clicked on, then takes the
    // appropriate action to provide help for the component
    _defaultGlassPane.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            // Determine what point has been clicked on
            Point glassPanePoint = e.getPoint();
            Point containerPoint = SwingUtilities.convertPoint(getMainFrame().getGlassPane(), glassPanePoint,
                    getMainFrame().getContentPane());
            Component component = SwingUtilities.getDeepestComponentAt(getMainFrame().getContentPane(),
                    containerPoint.x, containerPoint.y);

            // Get the java help ID for this component. If none has been
            // defined, this will be null
            String helpID = _helpController.getHelpKeyForComponent(component);

            // change the cursor back to the normal one and take down the
            // classpane
            mainFrame.setCursor(Cursor.getDefaultCursor());
            mainFrame.getGlassPane().setVisible(false);

            // If a help ID was found, display the related help page in the
            // help viewer
            if (_helpController.getHelpKeyForComponent(component) != null) {
                _helpController.helpAction().actionPerformed(new ActionEvent(component, 0, null));
                _helpController.displayHelpTopic(mainFrame, helpID);
            } else {
                // If a dynamically-defined toolbar button was clicked, show
                // the help for this button in the ToolbarHelpDialog.
                if (component instanceof JButton) {
                    JButton button = (JButton) component;
                    if (_dynamicButtonsFullHelp.containsKey(button)) {
                        String fullHelpText = _dynamicButtonsFullHelp.get(button);
                        if (fullHelpText == null) {
                            fullHelpText = noHelpAvailableCaption;
                        }
                        RTFBuilder builder = new RTFBuilder();
                        builder.startDocument();
                        builder.appendText(fullHelpText);
                        builder.endDocument();
                        ToolbarHelpDialog dlg = new ToolbarHelpDialog(mainFrame, builder.toString(),
                                button.getIcon());
                        show(dlg);
                    }
                }
            }
        }
    });

    show(_rootPanel);
}

From source file:ca.phon.ipamap.IpaMap.java

private JButton getMapButton(Cell cell) {
    PhonUIAction action = new PhonUIAction(this, "onCellClicked", cell);
    action.putValue(Action.NAME, cell.getText());
    action.putValue(Action.SHORT_DESCRIPTION, cell.getText());

    JButton retVal = new CellButton(cell);
    retVal.setAction(action);//from  w ww . j ava  2  s . co  m

    final Cell cellData = cell;
    retVal.addMouseListener(new MouseInputAdapter() {

        @Override
        public void mouseEntered(MouseEvent me) {
            String txt = cellData.getText();
            txt = txt.replaceAll("\u25cc", "");

            final IPATokens tokens = IPATokens.getSharedInstance();
            String uniVal = "";
            String name = "";
            for (Character c : txt.toCharArray()) {
                String cText = "0x" + StringUtils.leftPad(Integer.toHexString((int) c), 4, '0');
                uniVal += (uniVal.length() > 0 ? " + " : "") + cText;

                String cName = tokens.getCharacterName(c);
                name += (name.length() > 0 ? " + " : "") + cName;
            }
            String infoTxt = "[" + uniVal + "] " + name;
            infoLabel.setText(infoTxt);
        }

        @Override
        public void mouseExited(MouseEvent me) {
            infoLabel.setText("[]");
        }
    });

    retVal.addMouseListener(new ContextMouseHandler());

    // set tooltip delay to 10 minutes for the buttons
    retVal.addMouseListener(new MouseAdapter() {
        final int defaultDismissTimeout = ToolTipManager.sharedInstance().getDismissDelay();
        final int dismissDelayMinutes = (int) TimeUnit.MINUTES.toMillis(10); // 10 minutes

        @Override
        public void mouseEntered(MouseEvent me) {
            ToolTipManager.sharedInstance().setDismissDelay(dismissDelayMinutes);
        }

        @Override
        public void mouseExited(MouseEvent me) {
            ToolTipManager.sharedInstance().setDismissDelay(defaultDismissTimeout);
        }
    });

    return retVal;
}