Example usage for javax.swing SwingUtilities isLeftMouseButton

List of usage examples for javax.swing SwingUtilities isLeftMouseButton

Introduction

In this page you can find the example usage for javax.swing SwingUtilities isLeftMouseButton.

Prototype

public static boolean isLeftMouseButton(MouseEvent anEvent) 

Source Link

Document

Returns true if the mouse event specifies the left mouse button.

Usage

From source file:com.projity.pm.graphic.graph.GraphInteractor.java

public void mouseDragged(MouseEvent e) {
    if (isReadOnly())
        return;/*from   w  ww  .  ja va2s  .c  o m*/
    if (!SwingUtilities.isLeftMouseButton(e))
        return;
    if (selected instanceof GraphicNode) {
        GraphicNode node = (GraphicNode) selected;
        boolean sw = switchOnLinkCreation(e.getX(), e.getY());
        if (state != LINK_CREATION && sw) {
            drawBarShadow(lastShadowX, lastLinkShadowY, true);
            beforeLinkState = state;
            state = LINK_CREATION;
            selectCursor();

            sourceNode = (GraphicNode) selected;
            drawLinkSelectionBarShadow(sourceNode);

            setLinkOrigin();
        } else if (state == LINK_CREATION && !sw && allowLinkSelectionToMove()) {
            drawLinkShadow(lastLinkShadowX, lastLinkShadowY, true);
            drawBarShadow(lastShadowX, lastLinkShadowY, true);
            state = beforeLinkState;
            selectCursor();

            sourceNode = null;

        }
    }
    if (state == LINK_CREATION) {
        GraphZone zone = ui.getNodeAt(e.getX(), e.getY());
        GraphicNode newDestinationNode = zone == null ? null : (GraphicNode) zone.getObject();
        drawLinkSelectionBarShadow(destinationNode);
        drawLinkShadow(lastLinkShadowX, lastLinkShadowY, true);
        scrollToVisible(e.getX(), e.getY());
        drawLinkShadow(e.getX(), e.getY(), true);
        if (newDestinationNode != null && newDestinationNode.isLinkable() && sourceNode != newDestinationNode) {
            destinationNode = newDestinationNode;
            drawLinkSelectionBarShadow(destinationNode);
        } else
            destinationNode = null;
    } else if (isMove()) {
        drawBarShadow(lastShadowX, lastShadowY, true);
        scrollToVisible(e.getX(), e.getY());
        drawBarShadow(e.getX(), e.getY(), true);
    }
}

From source file:com.rapidminer.gui.viewer.metadata.AttributeStatisticsPanel.java

/**
 * Creates a new {@link AttributeStatisticsPanel} instance. Before displaying the panel, an
 * {@link AbstractAttributeStatisticsModel} should be set via
 * {@link #setModel(AbstractAttributeStatisticsModel, boolean)}.
 *
 *///from  w  w  w  .  ja  v a 2s . c om
public AttributeStatisticsPanel() {
    listOfChartPanels = new LinkedList<>();

    // create listener which listens for hovering/enlarge mouse events on this panel
    enlargeAndHoverAndPopupMouseAdapter = new MouseAdapter() {

        @Override
        public void mousePressed(final MouseEvent e) {
            // only popup trigger for popup menu
            if (e.isPopupTrigger()) {
                handlePopup(e);
            }

            // only left mouse button to enlarge
            if (!SwingUtilities.isLeftMouseButton(e)) {
                return;
            }

            // little hack so hovering over the details button does not remove the hover effect
            // (because MouseExited is called)
            // but clicking the button is still possible and does not enlarge the panel
            if (e.getSource() instanceof JButton) {
                ((JButton) e.getSource()).doClick();
                return;
            }

            // change enlarged status
            if (getModel() != null) {
                getModel().setEnlarged(!getModel().isEnlarged());
            }
        }

        @Override
        public void mouseExited(final MouseEvent e) {
            if (SwingTools.isMouseEventExitedToChildComponents(AttributeStatisticsPanel.this, e)) {
                // we are still hovering over the ASP, just a child component
                return;
            }
            hovered = false;
            repaint();
        }

        @Override
        public void mouseEntered(final MouseEvent e) {
            hovered = true;
            repaint();
        }

        @Override
        public void mouseReleased(final MouseEvent e) {
            if (e.isPopupTrigger()) {
                handlePopup(e);
            }
        }

        /**
         * Handles the popup click event.
         *
         * @param e
         */
        private void handlePopup(final MouseEvent e) {
            if (model.getAttribute().isNumerical()) {
                popupAttributeNumericalStatPanel.show(e.getComponent(), e.getX(), e.getY());
            } else if (model.getAttribute().isNominal()) {
                popupAttributeNominalStatPanel.show(e.getComponent(), e.getX(), e.getY());
            } else if (model.getAttribute().isDateTime()) {
                popupAttributeDateTimeStatPanel.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    };

    // create listener which listens for AttributeStatisticsEvents on the model
    listener = new AttributeStatisticsEventListener() {

        @Override
        public void modelChanged(final AttributeStatisticsEvent e) {
            switch (e.getEventType()) {
            case ALTERNATING_CHANGED:
                repaint();
                break;
            case ENLARGED_CHANGED:
                updateCharts();
                updateVisibilityOfChartPanels();
                if (AttributeStatisticsPanel.this.model.getAttribute().isNominal()) {
                    displayNominalValues();
                }
                break;
            case SHOW_CONSTRUCTION_CHANGED:
                panelStatsConstruction.setVisible(model.isShowConstruction());
                break;
            case STATISTICS_CHANGED:
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        AbstractAttributeStatisticsModel model = AttributeStatisticsPanel.this.model;
                        if (model.getAttribute().isNumerical()) {
                            updateNumericalElements(model);
                        } else if (model.getAttribute().isNominal()) {
                            updateNominalElements(model);
                        } else {
                            updateDateTimeElements(model);
                        }
                    }

                });
                break;
            default:
            }
        }
    };

    initGUI();
}

From source file:ca.sqlpower.swingui.enterprise.client.ServerProjectsManagerPanel.java

/**
 * This constructor creates a dialog for modifying and loading a project
 * from a single server designated by the given serverInfo parameter.
 * //from  ww w .ja v  a  2  s.com
 * @param serverInfo
 *            Projects will be retrieved from this server based on the
 *            information and displayed. The dialog will allow editing the
 *            security as well as creating and deleting projects on this
 *            server.
 * @param dialogOwner
 *            The dialog to parent new dialogs to.
 * @param upf
 *            A user prompter factory for displaying error and warning
 *            messages to users.
 * @param closeAction
 *            An action that will close the dialog or frame that this dialog
 *            is contained in.
 * @param defaultFileDirectory
 *            A default file directory to start looking for files in if the
 *            user wants to upload a project. If null this will default to
 *            the user's home directory.
 * @param cookieStore
 *            A cookie store for HTTP requests. Used by the
 *            {@link ClientSideSessionUtils}.
 */
public ServerProjectsManagerPanel(SPServerInfo serverInfo, Component dialogOwner, UserPrompterFactory upf,
        Action closeAction, File defaultFileDirectory, CookieStore cookieStore) {
    this.serverInfo = serverInfo;
    this.dialogOwner = dialogOwner;
    this.upf = upf;
    this.closeAction = closeAction;
    this.defaultFileDirectory = defaultFileDirectory;
    this.cookieStore = cookieStore;

    cookieStore.clear();

    DefaultFormBuilder builder = new DefaultFormBuilder(
            new FormLayout("pref:grow, 5dlu, pref", "pref, pref, pref"));

    servers = null;

    projects = new JList(new DefaultListModel());
    projects.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            refreshPanel();
            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
                getOpenAction().actionPerformed(null);
            }
        }
    });

    JScrollPane projectsPane = new JScrollPane(projects);
    projectsPane.setPreferredSize(new Dimension(250, 300));

    CellConstraints cc = new CellConstraints();
    builder.add(new JLabel(serverInfo.getName() + "'s projects:"), cc.xyw(1, 1, 2));
    builder.nextLine();
    builder.add(projectsPane, cc.xywh(1, 2, 1, 2));

    DefaultFormBuilder buttonBarBuilder = new DefaultFormBuilder(new FormLayout("pref"));
    buttonBarBuilder.append(new JButton(refreshAction));
    buttonBarBuilder.append(securityButton);
    buttonBarBuilder.append(new JButton(newAction));
    buttonBarBuilder.append(openButton);
    buttonBarBuilder.append(new JButton(deleteAction));
    buttonBarBuilder.append(new JButton(closeAction));
    builder.add(buttonBarBuilder.getPanel(), cc.xy(3, 2));
    builder.setDefaultDialogBorder();
    panel = builder.getPanel();
}

From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java

public void setModel(SpreadSheetModel spreadSheetModel, SpreadSheetColumnModel spreadSheetColumnModel) {
    makeCustomTableHeader(spreadSheetColumnModel);
    TableModel oldModel = getModel();
    setModel(spreadSheetModel);//from  w  w w  .  j a v a2s  .co m

    if (spreadSheetColumnModel != null) {
        //System.out.println("creating new ColModel");
        setColumnModel(spreadSheetColumnModel);

        selection = new SpreadSheetSelectionModel(this);
        selection.setRowSelection(new SpreadSheetListSelectionModel(selection, true));
        selection.setColumnSelection(new SpreadSheetListSelectionModel(selection, false));
        setSelectionModel(selection.getRowSelection());
        createDefaultColumnsFromModel(spreadSheetModel.getFieldArray()); //Consume memory
        getColumnModel().setSelectionModel(selection.getColumnSelection());
    }

    registerEditors(); //Consume memory
    initRowHeader(spreadSheetModel);
    initModel();
    initListeners();

    GraphicConfiguration config = GraphicConfiguration.getInstance();
    //fix for substance
    setTableHeader(createDefaultTableHeader());
    JTableHeader header = getTableHeader();
    header.setPreferredSize(
            new Dimension((int) header.getPreferredSize().getWidth(), config.getColumnHeaderHeight()));
    header.addMouseListener(new HeaderMouseListener(this));

    addMouseListener(new MouseAdapter() {
        //         Cursor oldCursor = null;
        //         public void mouseEntered(MouseEvent e) {
        //            Point p = e.getPoint();
        //            int col = columnAtPoint(p);
        //            Field field = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1);
        //            System.out.println("mouse entered field " + field);
        //            if (field != null && field.isHyperlink()) {
        //               oldCursor = getCursor();
        //               setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        //               System.out.println("setting new cursor to " + Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) + " old is " + oldCursor);
        //            } else 
        //               super.mouseEntered(e);
        //
        //         }
        //
        //         public void mouseExited(MouseEvent e) {
        //            Point p = e.getPoint();
        //            int col = columnAtPoint(p);
        //            Field field = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1);
        //            System.out.println("mouse exited field " + field);
        //            if (field != null && field.isHyperlink()) {
        //               setCursor(oldCursor);
        //               System.out.println("setting old cursor to " + oldCursor);
        //               e.consume();
        //            } else 
        //               super.mouseEntered(e);
        //         }

        public void mousePressed(MouseEvent e) { // changed to mousePressed instead of mouseClicked() for snappier handling 17/5/04 hk
            Point p = e.getPoint();
            int row = rowAtPoint(p);
            int col = columnAtPoint(p);
            SpreadSheetPopupMenu popup = getPopup();
            if (SwingUtilities.isLeftMouseButton(e)) {
                SpreadSheetColumnModel columnModel = (SpreadSheetColumnModel) getColumnModel();
                Field field = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1);
                SpreadSheetModel model = (SpreadSheetModel) getModel();
                if (field.isNameField()) {
                    // if (col == columnModel.getNameIndex()) {
                    GraphicNode node = model.getNode(row);
                    if (isOnIcon(e)) {
                        if (model.getCellProperties(node).isCompositeIcon()) {
                            finishCurrentOperations();
                            selection.getRowSelection().clearSelection();
                            boolean change = true;
                            if (!node.isFetched()) // for subprojects
                                change = node.fetch();
                            if (change)
                                model.changeCollapsedState(row);
                            e.consume(); // prevent dbl click treatment below

                            // because editor may have already been
                            // installed we
                            // have to update its collapsed state
                            // updateNameCellEditor(node);

                            // editCellAt(row,model.findGraphicNodeRow(node));
                        }
                    }
                } else if (field != null && field.isHyperlink()) {
                    Hyperlink link = (Hyperlink) model.getValueAt(row, col + 1);
                    if (link != null) {
                        BrowserControl.displayURL(link.getAddress());
                        e.consume(); // prevent dbl click treatment below
                    }

                }
                if (!e.isConsumed()) {
                    if (e.getClickCount() == 2) // if above code didn't treat and is dbl click
                        doDoubleClick(row, col);
                    else
                        doClick(row, col);
                }

            } else if (popup != null && SwingUtilities.isRightMouseButton(e)) { // e.isPopupTrigger() can be used too
                //               selection.getRowSelection().clearSelection();
                //               selection.getRowSelection().addSelectionInterval(row, row);
                popup.setRow(row);
                popup.setCol(col);
                popup.show(SpreadSheet.this, e.getX(), e.getY());
            }
        }
    });

    if (oldModel != spreadSheetModel && oldModel instanceof CommonSpreadSheetModel)
        ((CommonSpreadSheetModel) getModel()).getCache().removeNodeModelListener(this);
    spreadSheetModel.getCache().addNodeModelListener(this);

    //      getColumnModel().addColumnModelListener(new TableColumnModelListener(){
    //         public void columnAdded(TableColumnModelEvent e) {
    //            // TODO Auto-generated method stub
    //            
    //         }
    //         public void columnMarginChanged(ChangeEvent e) {
    //            // TODO Auto-generated method stub
    //            
    //         }
    //         public void columnMoved(TableColumnModelEvent e) {
    //            // TODO Auto-generated method stub
    //            
    //         }
    //         public void columnRemoved(TableColumnModelEvent e) {
    //            // TODO Auto-generated method stub
    //            
    //         }
    //         public void columnSelectionChanged(ListSelectionEvent e) {
    //            System.out.println(((e.getValueIsAdjusting())?"lse=":"LSE=")+e.getFirstIndex()+", "+e.getLastIndex());
    //            SpreadSheet.this.revalidate();
    //            //SpreadSheet.this.paintImmediately(0, 0, getWidth(), GraphicConfiguration.getInstance().getColumnHeaderHeight());
    //         }
    //      });

}

From source file:ca.sqlpower.swingui.enterprise.client.ServerProjectsManagerPanel.java

/**
 * Creates a dialog that lets the user choose a server connection and then a
 * project./* w w  w  .ja  va  2 s.  c o  m*/
 * 
 * @param serverManager
 *            This object contains all of the server information objects
 *            known and the servers based on their information will be
 *            displayed in a list so a user can navigate to different
 *            projects in different servers.
 * @param dialogOwner
 *            The dialog to parent new dialogs to.
 * @param upf
 *            A user prompter factory for displaying error and warning
 *            messages to users.
 * @param closeAction
 *            An action that will close the dialog or frame that this dialog
 *            is contained in.
 * @param defaultFileDirectory
 *            A default file directory to start looking for files in if the
 *            user wants to upload a project. If null this will default to
 *            the user's home directory.
 * @param cookieStore
 *            A cookie store for HTTP requests. Used by the
 *            {@link ClientSideSessionUtils}.
 */
public ServerProjectsManagerPanel(SPServerInfoManager serverManager, Component dialogOwner,
        UserPrompterFactory upf, Action closeAction, File defaultFileDirectory, CookieStore cookieStore) {
    this.dialogOwner = dialogOwner;
    this.upf = upf;
    this.closeAction = closeAction;
    this.defaultFileDirectory = defaultFileDirectory;
    this.cookieStore = cookieStore;

    cookieStore.clear();

    DefaultFormBuilder builder = new DefaultFormBuilder(
            new FormLayout("pref:grow, 5dlu, pref:grow, 5dlu, pref", "pref, pref, pref"));

    servers = new JList(new DefaultListModel());
    servers.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e)) {
                refreshInfoList();
            }
        }
    });

    DefaultListModel serversModel = (DefaultListModel) servers.getModel();
    serversModel.removeAllElements();
    if (serverManager.getServers(false).size() > 0) {
        for (SPServerInfo serverInfo : serverManager.getServers(false)) {
            serversModel.addElement(serverInfo);
        }
    } else {
        serversModel.addElement("No Servers");
        servers.setEnabled(false);
    }

    projects = new JList(new DefaultListModel());
    projects.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            refreshPanel();
            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
                getOpenAction().actionPerformed(null);
            }
        }
    });

    JScrollPane projectsPane = new JScrollPane(projects);
    projectsPane.setPreferredSize(new Dimension(250, 300));

    JScrollPane serverPane = new JScrollPane(servers);
    serverPane.setPreferredSize(new Dimension(250, 300));

    CellConstraints cc = new CellConstraints();
    builder.add(new JLabel("Servers:"), cc.xyw(1, 1, 2));
    builder.add(new JLabel("Projects:"), cc.xyw(3, 1, 2));
    builder.nextLine();
    builder.add(serverPane, cc.xywh(1, 2, 1, 2));
    builder.add(projectsPane, cc.xywh(3, 2, 1, 2));

    DefaultFormBuilder buttonBarBuilder = new DefaultFormBuilder(new FormLayout("pref"));
    buttonBarBuilder.append(new JButton(refreshAction));
    buttonBarBuilder.append(securityButton);
    buttonBarBuilder.append(new JButton(newAction));
    buttonBarBuilder.append(openButton);
    buttonBarBuilder.append(new JButton(uploadAction));
    buttonBarBuilder.append(new JButton(deleteAction));
    buttonBarBuilder.append(new JButton(closeAction));
    builder.add(buttonBarBuilder.getPanel(), cc.xy(5, 2));
    builder.setDefaultDialogBorder();
    panel = builder.getPanel();
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.link_and_brush.LinkAndBrushChartPanel.java

@Override
public void mousePressed(MouseEvent e) {
    // this is used to only allow left mouse button zoom / selection
    if (!SwingUtilities.isLeftMouseButton(e)) {
        blockSelectionOrZoom = true;/*from w  w w  . j av a2s.  c  om*/
    } else {
        blockSelectionOrZoom = false;
    }
    super.mousePressed(e);
}

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

public void fileTableClicked(FileObjectTableModel fileObjectTableModel, JTableX<FileObject> table,
        MouseEvent e) {//  w  ww .j  a  v  a2 s . c o m
    int row = table.convertRowIndexToModel(table.rowAtPoint(e.getPoint()));
    //int column = table.convertColumnIndexToModel(table.columnAtPoint(e.getPoint()));
    final Collection<FileObject> selectedFileObjects = table.getSelectedObjects();

    final FileObject f = fileObjectTableModel.getRowObjects().get(row);

    if (SwingUtilities.isRightMouseButton(e)) {
        JPopupMenu m = new JPopupMenu();
        {
            JMenuItem menuitem = new JMenuItem("ffnen");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openFile(f);
                }
            });
            m.add(menuitem);
        }
        {
            JMenuItem menuitem = new JMenuItem("Ordner ffnen");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openFolder(f);
                }
            });
            m.add(menuitem);
        }
        {
            JMenuItem menuitem = new JMenuItem("Herunterladen (ber SOAP)");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    downloadFiles(selectedFileObjects, DownloadMethod.WEBSERVICE);
                }

            });
            m.add(menuitem);
        }
        {
            JMenuItem menuitem = new JMenuItem("Herunterladen (ber WEBDAV)");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    if (!syncService.getIliasSoapService().isWebdavAuthenticationActive()) {
                        syncService.getIliasSoapService().enableWebdavAuthentication(
                                mainFrame.getFieldLogin().getText(),
                                mainFrame.getFieldPassword().getPassword());
                    }
                    downloadFiles(selectedFileObjects, DownloadMethod.WEBDAV);
                }

            });
            m.add(menuitem);
        }
        {
            JMenuItem menuitem = new JMenuItem("In Ilias ffnen");
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    openInIlias(f);
                }
            });
            m.add(menuitem);
        }
        {
            m.add(new JSeparator());
        }
        {
            JCheckBoxMenuItem menuitem = new JCheckBoxMenuItem("Ignorieren");
            menuitem.setSelected(iliasProperties.getBlockedFiles().contains(f.getRefId()));
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    switchIgnoreState(selectedFileObjects);
                }
            });
            m.add(menuitem);
        }
        {
            m.add(new JSeparator());
        }
        {
            JMenuItem menuitem = new JMenuItem("Fehler anzeigen");
            menuitem.setEnabled(f.getException() != null);
            menuitem.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    showError("Fehler bei " + f.getTargetFile().getAbsolutePath(), f.getException());
                }

            });
            m.add(menuitem);
        }
        m.show(table, e.getX(), e.getY());
    }

    if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) {
        openFile(f);
    }
}

From source file:com.ivli.roim.controls.ChartControl.java

@Override
public void mousePressed(MouseEvent e) {
    ChartEntity entity = findEntity(e);/*from   w w  w.  j  a v  a  2  s .c  o  m*/

    if (entity instanceof XYItemEntity) {
        selectItem(entity);
        setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    } else if (null != (iMarker = findMarker(e))) {
        if (SwingUtilities.isLeftMouseButton(e))
            setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    } else
        super.mousePressed(e);
}

From source file:ded.ui.DiagramController.java

@Override
public void mousePressed(MouseEvent e) {
    this.eventReceived(e);

    switch (this.mode) {
    case DCM_SELECT: {
        // Clicked a controller?
        Controller c = this.hitTest(e.getPoint(), null);
        if (c == null) {
            // Missed controls, start a lasso selection
            // if left button.
            if (SwingUtilities.isLeftMouseButton(e)) {
                this.lassoOriginalSelected.clear();
                if (SwingUtil.controlPressed(e)) {
                    // Control is pressed.  Keep current selections.
                    this.lassoOriginalSelected.addAll(this.getAllSelected());
                } else {
                    if (this.deselectAll() > 0) {
                        this.repaint();
                    }/* ww  w. j  av  a  2 s  .c o m*/
                }

                // Enter lasso mode.
                setMode(Mode.DCM_RECT_LASSO);
                this.lassoStart = this.lassoEnd = e.getPoint();
            }
        } else {
            c.mousePressed(e);
        }
        break;
    }

    case DCM_CREATE_RELATION: {
        // Make a Relation that starts and ends at the current location.
        RelationEndpoint start = this.getRelationEndpoint(e.getPoint());
        RelationEndpoint end = new RelationEndpoint(start);
        end.arrowStyle = ArrowStyle.AS_FILLED_TRIANGLE;
        Relation r = new Relation(start, end);
        this.diagram.relations.add(r);
        this.setDirty();

        // Build a controller and select it.
        RelationController rc = this.buildRelationController(r);
        this.selectOnly(rc);

        // Drag the end point while the mouse button is held.
        this.beginDragging(rc.getEndHandle(), e.getPoint());

        this.repaint();
        break;
    }

    case DCM_CREATE_ENTITY: {
        EntityController.createEntityAt(this, e.getPoint());
        this.setMode(Mode.DCM_SELECT);
        this.setDirty();
        break;
    }

    case DCM_CREATE_INHERITANCE: {
        if (SwingUtilities.isLeftMouseButton(e)) {
            this.createInheritanceAt(e.getPoint());
            this.setDirty();
        }
        break;
    }

    case DCM_DRAGGING:
    case DCM_RECT_LASSO:
        // These modes are entered with a mouse press and
        // exited with mouse release, so we should not get
        // a mouse press while already in such a mode.
        // Ignore it if it happens.
        break;
    }
}

From source file:com.diversityarrays.kdxplore.trials.TrialOverviewPanel.java

public TrialOverviewPanel(String title, OfflineData offdata, TrialExplorerManager manager,
        FileListTransferHandler flth, MessagePrinter mp, final Closure<List<Trial>> onTrialSelected) {
    super(new BorderLayout());

    offlineData = offdata;//w w w  .  j  a v  a 2s .  c  o  m
    KdxploreDatabase kdxdb = offlineData.getKdxploreDatabase();
    if (kdxdb != null) {
        kdxdb.addEntityChangeListener(trialChangeListener);
        kdxdb.addEntityChangeListener(traitChangeListener);
    }

    this.messagePrinter = mp;

    TableTransferHandler tth = TableTransferHandler.initialiseForCopySelectAll(trialsTable, true);
    trialsTable.setTransferHandler(new ChainingTransferHandler(flth, tth));
    trialsTable.setAutoCreateRowSorter(true);

    trialsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                List<Trial> selectedTrials = getSelectedTrials();
                if (selectedTrials.size() == 1) {
                    trialTraitsTableModel.setSelectedTrial(selectedTrials.get(0));
                } else {
                    trialTraitsTableModel.setSelectedTrial(null);
                }
                onTrialSelected.execute(selectedTrials);
            }
        }
    });
    trialsTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
                fireEditCommand(e);
            }
        }
    });

    GuiUtil.setVisibleRowCount(trialsTable, MAX_INITIAL_VISIBLE_TRIAL_ROWS);

    offlineData.addOfflineDataChangeListener(offlineDataChangeListener);

    trialTableModel.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            updateRefreshAction();
        }
    });
    trialTraitsTableModel.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            updateAddTraitAction();
            updateRemoveTraitAction();
            updateScoringOrderAction();
        }
    });
    trialTraitsTable.addMouseListener(new MouseAdapter() {

        List<Trait> selectedTraits;
        JPopupMenu popupMenu;
        Action showTraitsAction = new AbstractAction("Select in Trait Explorer") {
            @Override
            public void actionPerformed(ActionEvent e) {
                manager.showTraitsInTraitExplorer(selectedTraits);
            }
        };

        @Override
        public void mouseClicked(MouseEvent e) {

            if (SwingUtilities.isLeftMouseButton(e) && 2 == e.getClickCount()) {
                // Start editing the Trait
                e.consume();
                int vrow = trialTraitsTable.rowAtPoint(e.getPoint());
                if (vrow >= 0) {
                    int mrow = trialTraitsTable.convertRowIndexToModel(vrow);
                    if (mrow >= 0) {
                        Trait trait = trialTraitsTableModel.getTraitAt(mrow);
                        if (trait != null) {
                            traitExplorer.startEditing(trait);
                            ;
                        }
                    }
                }
            } else if (SwingUtilities.isRightMouseButton(e) && 1 == e.getClickCount()) {
                // Select the traits in the traitExplorer
                e.consume();
                List<Integer> modelRows = GuiUtil.getSelectedModelRows(trialTraitsTable);
                if (!modelRows.isEmpty()) {
                    selectedTraits = modelRows.stream().map(trialTraitsTableModel::getTraitAt)
                            .collect(Collectors.toList());

                    if (popupMenu == null) {
                        popupMenu = new JPopupMenu();
                        popupMenu.add(showTraitsAction);
                    }
                    Point pt = e.getPoint();
                    popupMenu.show(trialTraitsTable, pt.x, pt.y);
                }
            }
        }
    });
    trialTraitsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                updateRemoveTraitAction();
            }
        }
    });
    updateAddTraitAction();
    updateRemoveTraitAction();
    updateScoringOrderAction();
    updateRefreshAction();

    KDClientUtils.initAction(ImageId.REFRESH_24, refreshTrialTraitsAction, "Refresh");
    KDClientUtils.initAction(ImageId.MINUS_GOLD_24, removeTraitAction, "Remove selected Traits");
    KDClientUtils.initAction(ImageId.PLUS_BLUE_24, addTraitAction, "Add Traits to Trial");
    KDClientUtils.initAction(ImageId.TRAIT_ORDER_24, setScoringOrderAction, "Define Trait Scoring Order");

    Box buttons = Box.createHorizontalBox();

    buttons.add(new JButton(setScoringOrderAction));
    buttons.add(Box.createHorizontalGlue());
    buttons.add(new JButton(addTraitAction));
    buttons.add(new JButton(removeTraitAction));
    buttons.add(Box.createHorizontalStrut(10));
    buttons.add(refreshTrialTraitsButton);

    JPanel traitsPanel = new JPanel(new BorderLayout());
    traitsPanel.add(GuiUtil.createLabelSeparator("Uses Traits", buttons), BorderLayout.NORTH);
    traitsPanel.add(new PromptScrollPane(trialTraitsTable,
            "If the (single) selected Trial has Traits they will appear here"), BorderLayout.CENTER);

    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JScrollPane(trialsTable), traitsPanel);
    splitPane.setResizeWeight(0.5);

    add(splitPane, BorderLayout.CENTER);
}