Example usage for java.awt.event MouseEvent getPoint

List of usage examples for java.awt.event MouseEvent getPoint

Introduction

In this page you can find the example usage for java.awt.event MouseEvent getPoint.

Prototype

public Point getPoint() 

Source Link

Document

Returns the x,y position of the event relative to the source component.

Usage

From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakAnnotationCalibrationPanel.java

public void onMousePressed(MouseEvent e) {
    was_moving = is_moving;//  ww w  .jav a2  s. c  o  m
    if (e.getButton() == e.BUTTON1 && theChartPanel.getScreenDataArea().contains(e.getPoint())) {
        mouse_start_point = e.getPoint();
        if ((e.getModifiers() & MOD_MASK) == e.SHIFT_MASK)
            onActivateMoving();
    } else
        mouse_start_point = null;
}

From source file:fi.todoordelay.gui.GuiMainFrame.java

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor./*ww w  .j  a  va  2  s .c  o  m*/
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    menuBar = new javax.swing.JMenuBar();
    projectMenu = new javax.swing.JMenu();
    addprojectMenuItem = new javax.swing.JMenuItem();
    saveMenuItem = new javax.swing.JMenuItem();
    saveAsMenuItem = new javax.swing.JMenuItem();
    exitMenuItem = new javax.swing.JMenuItem();
    taskMenu = new javax.swing.JMenu();
    addtaskMenuItem = new javax.swing.JMenuItem();
    copyMenuItem = new javax.swing.JMenuItem();
    pasteMenuItem = new javax.swing.JMenuItem();
    deleteMenuItem = new javax.swing.JMenuItem();
    ownlistMenu = new javax.swing.JMenu();
    addownlistMenuItem = new javax.swing.JMenuItem();
    aboutMenuItem = new javax.swing.JMenuItem();

    projectListModel = new javax.swing.DefaultListModel();
    projectsList = new javax.swing.JList(projectListModel);
    projectsPane = new javax.swing.JScrollPane(projectsList);

    taskListModel = new javax.swing.DefaultListModel();
    tasksList = new javax.swing.JList(taskListModel);
    tasksPane = new javax.swing.JScrollPane(tasksList);

    informationTextArea = new javax.swing.JTextArea();
    informationPane = new javax.swing.JScrollPane(informationTextArea);

    addItemDialog = new javax.swing.JOptionPane();
    editItemDialog = new javax.swing.JOptionPane();

    mainLogic = new fi.todoordelay.logic.LogicMain();

    projectsListMouseListener = new MouseListener() {
        public void mouseClicked(MouseEvent evt) {
            int index = projectsList.locationToIndex(evt.getPoint());
            selectedProject = index;
            selectionGroup = 0;

            if (evt.getButton() == 3) {
                int d = editItemDialog.showConfirmDialog(null,
                        "ARE YOU SURE YOU WANT TO DELETE CHOSEN PROJECT?", "Delete project dialog",
                        editItemDialog.YES_NO_OPTION, editItemDialog.WARNING_MESSAGE);
                if (d == 0) {
                    mainLogic.removeProject(mainLogic.getProjects().get(selectedProject));
                }
                selectedProject = -1;
                updateProjectListModel();
            }

            if (evt.getClickCount() == 2 && selectedProject > -1) {
                List pl = mainLogic.getProjects();
                Project p = (Project) pl.get(index);

                editItemDialog.setWantsInput(true);
                String name = editItemDialog.showInputDialog(null, "New project name (required):",
                        "Edit project dialog", editItemDialog.INFORMATION_MESSAGE);
                String description = editItemDialog.showInputDialog(null, "New project description:",
                        "Edit project dialog", editItemDialog.INFORMATION_MESSAGE);
                String dueString = editItemDialog.showInputDialog(null, "New due date in x day(s):",
                        "Edit project dialog", editItemDialog.INFORMATION_MESSAGE);

                try {
                    if (name.equals("")) {
                        JOptionPane.showMessageDialog(editItemDialog,
                                "Project name cannot be empty (exiting without changes)");
                    } else if (Long.parseLong(dueString) < 0) {
                        JOptionPane.showMessageDialog(editItemDialog, "Due date must be zero or higher");
                    } else {
                        p.setName(name);
                        p.setDescription(description);
                        p.setDuedate(LocalDateTime.now().plusDays(Long.parseLong(dueString)));
                    }
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(editItemDialog, "Due date must be valid number");
                }

            }

            updateProjectListModel();
            mouseClickedOnProjectActionPerformed(evt);

        }

        public void mouseEntered(MouseEvent evt) {
        }

        public void mouseExited(MouseEvent evt) {
        }

        public void mouseReleased(MouseEvent evt) {
        }

        public void mousePressed(MouseEvent evt) {
        }

    };
    projectsList.addMouseListener(projectsListMouseListener);

    tasksListMouseListener = new MouseListener() {
        public void mouseClicked(MouseEvent evt) {
            int index = tasksList.locationToIndex(evt.getPoint());
            selectedTask = index;
            selectionGroup = 1;

            if (evt.getButton() == 3) {
                int d = editItemDialog.showConfirmDialog(null, "ARE YOU SURE YOU WANT TO DELETE CHOSEN TASK?",
                        "Delete task dialog", editItemDialog.YES_NO_OPTION, editItemDialog.WARNING_MESSAGE);
                if (d == 0) {
                    mainLogic.getProjects().get(selectedProject).removeTask(
                            mainLogic.getProjects().get(selectedProject).getTasks().get(selectedTask));
                }
                updateProjectListModel();
            }

            if (evt.getClickCount() == 2 && selectedTask > -1) {
                List tl = mainLogic.getProjects().get(selectedProject).getTasks();
                Task t = (Task) tl.get(index);

                editItemDialog.setWantsInput(true);
                String name = editItemDialog.showInputDialog(null, "New task name (required):",
                        "Edit task dialog", editItemDialog.INFORMATION_MESSAGE);
                String description = editItemDialog.showInputDialog(null, "New task description:",
                        "Edit task dialog", editItemDialog.INFORMATION_MESSAGE);
                String dueString = editItemDialog.showInputDialog(null, "New due date in x day(s):",
                        "Edit task dialog", editItemDialog.INFORMATION_MESSAGE);

                try {
                    if (name.equals("")) {
                        JOptionPane.showMessageDialog(editItemDialog,
                                "Task name cannot be empty (exiting without changes)");
                    } else if (Long.parseLong(dueString) < 0) {
                        JOptionPane.showMessageDialog(editItemDialog, "Due date must be zero or higher");
                    } else {
                        t.setName(name);
                        t.setDescription(description);
                        t.setDuedate(LocalDateTime.now().plusDays(Long.parseLong(dueString)));
                    }
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(editItemDialog, "Due date must be valid number");
                }

            }

            updateProjectListModel();
            mouseClickedOnProjectActionPerformed(evt);

        }

        public void mouseEntered(MouseEvent evt) {
        }

        public void mouseExited(MouseEvent evt) {
        }

        public void mouseReleased(MouseEvent evt) {
        }

        public void mousePressed(MouseEvent evt) {
        }

    };
    tasksList.addMouseListener(tasksListMouseListener);

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    projectsPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Projects"));
    projectsPane.setViewportBorder(null);

    tasksPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Tasks"));
    tasksPane.setViewportBorder(null);

    informationPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Description"));
    projectsPane.setViewportBorder(null);

    projectMenu.setText("Project");
    addprojectMenuItem.setMnemonic('p');
    addprojectMenuItem.setText("Add Project");
    projectMenu.add(addprojectMenuItem);
    addprojectMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            addItemDialog.setWantsInput(true);
            String name = addItemDialog.showInputDialog(null, "Project name (required):", "Add project dialog",
                    addItemDialog.INFORMATION_MESSAGE);
            String description = addItemDialog.showInputDialog(null, "Project description:",
                    "Add project dialog", addItemDialog.INFORMATION_MESSAGE);
            String due_at = addItemDialog.showInputDialog(null, "Due in x day(s):", "Add project dialog",
                    addItemDialog.INFORMATION_MESSAGE);
            Project newProject = new Project(name, description, Long.parseLong(due_at));
            mainLogic.addProject(newProject);
            projectListModel.addElement(name);

            updateProjectListModel();
            addprojectMenuItemActionPerformed(evt);
        }
    });
    menuBar.add(projectMenu);

    taskMenu.setText("Task");
    addtaskMenuItem.setMnemonic('t');
    addtaskMenuItem.setText("Add Task");
    taskMenu.add(addtaskMenuItem);
    addtaskMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            addItemDialog.setWantsInput(true);
            String name = addItemDialog.showInputDialog(null, "Task name (required):", "Add task dialog",
                    addItemDialog.INFORMATION_MESSAGE);
            String description = addItemDialog.showInputDialog(null, "Task description:", "Add task dialog",
                    addItemDialog.INFORMATION_MESSAGE);
            String due_at = addItemDialog.showInputDialog(null, "Due in x day(s):", "Add task dialog",
                    addItemDialog.INFORMATION_MESSAGE);
            Task newTask = new Task(name, description, Long.parseLong(due_at));

            Project s = mainLogic.getProjects().get(selectedProject);

            s.addTask(newTask);
            taskListModel.addElement(name);

            updateProjectListModel();
            addprojectMenuItemActionPerformed(evt);
        }
    });
    menuBar.add(taskMenu);

    setJMenuBar(menuBar);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(
                                    projectsPane, javax.swing.GroupLayout.PREFERRED_SIZE, 300,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(
                                    layout.createSequentialGroup().addGap(312, 312, 312).addComponent(tasksPane,
                                            javax.swing.GroupLayout.PREFERRED_SIZE, 300,
                                            javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup().addGap(624, 624, 624).addComponent(
                                    informationPane, javax.swing.GroupLayout.PREFERRED_SIZE, 300,
                                    Short.MAX_VALUE)))

                    .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
            javax.swing.GroupLayout.Alignment.TRAILING,
            layout.createSequentialGroup().addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(informationPane, javax.swing.GroupLayout.DEFAULT_SIZE, 860,
                                    Short.MAX_VALUE)
                            .addComponent(tasksPane, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(projectsPane, javax.swing.GroupLayout.Alignment.LEADING))

                    .addContainerGap()));

    pack();
}

From source file:org.drugis.addis.gui.builder.NetworkMetaAnalysisView.java

private MouseAdapter treatmentCategorizationListener(final NetworkRelativeEffectTableCellRenderer renderer) {
    return new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
                JTable table = (JTable) e.getComponent();
                int row = table.convertRowIndexToModel(table.rowAtPoint(e.getPoint()));
                int col = table.convertColumnIndexToModel(table.columnAtPoint(e.getPoint()));
                if (col == row) {
                    Treatment treatment = renderer.getTreatment(table.getModel(), col);
                    TreatmentDefinition treatmentDefinition = d_pm.getTreatmentDefinition(treatment);
                    Category category = treatmentDefinition.getContents().first();
                    if (category != null && !category.isTrivial()) {
                        d_mainWindow.leftTreeFocus(category.getCategorization());
                    }//from   ww  w  . java 2 s.c  o m
                }
            }
        }
    };
}

From source file:org.smart.migrate.ui.MappingDialog.java

private void tblFieldMappingMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblFieldMappingMouseClicked
    int row = tblFieldMapping.rowAtPoint(evt.getPoint());
    int col = tblFieldMapping.columnAtPoint(evt.getPoint());
    if (row >= 0 && col == 2) {
        for (int i = 0; i < tblFieldMapping.getRowCount(); i++) {
            if (i != row) {
                tblFieldMapping.setValueAt(false, i, 2);
            }/*from w  w w  .  j ava  2 s.co  m*/
        }
    }
}

From source file:lu.lippmann.cdb.graph.mouse.CadralEditingGraphMousePlugin.java

/**
 * {@inheritDoc}/*from  www .  ja v a 2  s  .c  o m*/
 */

@Override
public void mouseDragged(MouseEvent e) {
    if (checkModifiers(e)) {
        @SuppressWarnings("unchecked")
        final VisualizationViewer<CNode, CEdge> vv = (VisualizationViewer<CNode, CEdge>) e.getSource();
        final Layout<CNode, CEdge> layout = vv.getModel().getGraphLayout();
        final GraphElementAccessor<CNode, CEdge> pickSupport = vv.getPickSupport();
        if (startVertex != null) {
            transformEdgeShape(down, e.getPoint());
            if (edgeIsDirected == EdgeType.DIRECTED) {
                transformArrowShape(down, e.getPoint());
                final CNode pointedVertex = pickSupport.getVertex(layout, e.getX(), e.getY());
                if (pointedVertex != null && pointedVertex != startVertex) {
                    if (!pointedVertices.containsKey(pointedVertex)) {
                        pointedVertices.put(pointedVertex, pointedVertex.getColor()); //save original color
                    }
                    Color prevColor = pointedVertex.getColor();
                    if (pointedVertex.getColor().equals(pointedVertices.get(pointedVertex))) {

                        if (pointedVertex != this.lastDragVertex && this.lastDragVertex != null) {
                            lastDragVertex.setColor(pointedVertices.get(lastDragVertex));
                        }
                        //Don't change color if there is an existing edge
                        if (layout.getGraph().findEdge(startVertex, pointedVertex) == null) {
                            if (GraphUtil.isDarkNode(pointedVertex)) {
                                if (prevColor.darker().equals(prevColor)) {
                                    pointedVertex.setColor(Color.GRAY);
                                } else {
                                    if (prevColor.brighter().equals(prevColor)) {
                                        pointedVertex.setColor(Color.GRAY);
                                    } else {
                                        pointedVertex.setColor(pointedVertices.get(pointedVertex).brighter());
                                    }
                                }
                            } else {
                                pointedVertex.setColor(pointedVertices.get(pointedVertex).darker());
                            }
                        }
                    }
                    this.lastDragVertex = this.dragVertex;
                    this.dragVertex = pointedVertex;
                } else if (dragVertex != null) {
                    dragVertex.setColor(pointedVertices.get(dragVertex));
                }
            }
        }
        vv.repaint();
    }
}

From source file:io.github.jeremgamer.editor.panels.Others.java

public Others(final JFrame frame, final OtherPanel op, final PanelSave ps) {
    this.frame = frame;

    this.setBorder(BorderFactory.createTitledBorder(""));
    JButton add = null;/*  w  w w.  j  av  a 2s  .com*/
    try {
        add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    add.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                JOptionPane jop = new JOptionPane();
                @SuppressWarnings("static-access")
                String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(otherList),
                        "Nommez le composant :", "Crer un composant", JOptionPane.QUESTION_MESSAGE);

                if (name != null) {
                    for (int i = 0; i < data.getSize(); i++) {
                        if (data.get(i).equals(name)) {
                            name += "1";
                        }
                    }
                    data.addElement(name);
                    new OtherSave(name);
                    ActionPanel.updateLists();
                    PanelsPanel.updateLists();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    });

    JButton remove = null;
    try {
        remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
    } catch (IOException e) {
        e.printStackTrace();
    }
    remove.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                if (otherList.getSelectedValue() != null) {
                    File file = new File("projects/" + Editor.getProjectName() + "/others/"
                            + otherList.getSelectedValue() + ".rbd");
                    JOptionPane jop = new JOptionPane();
                    @SuppressWarnings("static-access")
                    int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(otherList),
                            "tes-vous sr de vouloir supprimer ce composant?", "Avertissement",
                            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);

                    if (option == JOptionPane.OK_OPTION) {
                        File dir = new File("projects/" + Editor.getProjectName() + "/panels");
                        for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE,
                                TrueFileFilter.INSTANCE)) {
                            if (!f.isDirectory()) {
                                try {
                                    ps.load(f);
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }

                                OtherSave os = new OtherSave();
                                try {
                                    os.load(file);
                                } catch (IOException e1) {
                                    e1.printStackTrace();
                                }
                                String type = null;
                                switch (os.getInt("type")) {
                                case 0:
                                    type = "Zone de saisie";
                                    break;
                                case 1:
                                    type = "Zone de saisie de mot de passe";
                                    break;
                                case 2:
                                    type = "Zone de saisie (Grande)";
                                    break;
                                case 3:
                                    type = "Case  cocher";
                                    break;
                                case 4:
                                    type = "Menu droulant";
                                    break;
                                case 5:
                                    type = "Barre de progression";
                                    break;
                                case 6:
                                    type = "Slider";
                                    break;
                                case 7:
                                    type = "Spinner";
                                    break;
                                }
                                for (String section : ps.getSectionsContaining(
                                        otherList.getSelectedValue() + " (" + type + ")")) {
                                    ps.removeSection(section);
                                    try {
                                        ps.save(f);
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }
                        }
                        if (otherList.getSelectedValue().equals(op.getFileName())) {
                            op.setFileName("");
                        }
                        op.hide();
                        file.delete();
                        data.remove(otherList.getSelectedIndex());
                        ActionPanel.updateLists();
                        OtherPanel.updateLists();
                        PanelsPanel.updateLists();
                    }
                }
            } catch (NullPointerException npe) {
                npe.printStackTrace();
            }

        }

    });

    JPanel buttons = new JPanel();
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS));
    buttons.add(add);
    buttons.add(remove);

    updateList();
    otherList.addMouseListener(new MouseAdapter() {
        @SuppressWarnings("unchecked")
        public void mouseClicked(MouseEvent evt) {
            JList<String> list = (JList<String>) evt.getSource();
            if (evt.getClickCount() == 2) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    op.show();
                    op.load(new File("projects/" + Editor.getProjectName() + "/others/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            op.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            op.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            op.load(new File("projects/" + Editor.getProjectName() + "/others/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        op.hide();
                        list.clearSelection();
                    }
                }
            } else if (evt.getClickCount() == 3) {
                int index = list.locationToIndex(evt.getPoint());
                if (isOpen == false) {
                    op.show();
                    op.load(new File("projects/" + Editor.getProjectName() + "/others/"
                            + list.getModel().getElementAt(index) + ".rbd"));
                    previousSelection = list.getSelectedValue();
                    isOpen = true;
                } else {
                    try {
                        if (previousSelection.equals(list.getModel().getElementAt(index))) {
                            op.hide();
                            previousSelection = list.getSelectedValue();
                            list.clearSelection();
                            isOpen = false;
                        } else {
                            op.hideThenShow();
                            previousSelection = list.getSelectedValue();
                            op.load(new File("projects/" + Editor.getProjectName() + "/others/"
                                    + list.getModel().getElementAt(index) + ".rbd"));
                        }
                    } catch (NullPointerException npe) {
                        op.hide();
                        list.clearSelection();
                    }
                }
            }
        }
    });
    JScrollPane listPane = new JScrollPane(otherList);
    listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED);
    this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    this.add(buttons);
    this.add(listPane);
    OtherPanel.updateLists();
}

From source file:com.lfv.lanzius.server.WorkspaceView.java

public void mousePressed(MouseEvent e) {
    Point p = e.getPoint();
    if (e.getButton() == MouseEvent.BUTTON1) {

        Document doc = server.getDocument();
        if (doc == null)
            return;

        List<Integer> selectionList = new LinkedList<Integer>();

        boolean selectionChanged = false;

        // Clicked on a group?
        Iterator<Group> iterg = groupList.iterator();
        while (iterg.hasNext()) {
            Group g = iterg.next();
            if (g.boundingRect.contains(p)) {
                g.isSelected = !g.isSelected;
                synchronized (doc) {
                    Element egd = DomTools.getElementFromSection(doc, "GroupDefs", "id", String.valueOf(g.gid));
                    if (egd != null)
                        egd.setAttribute("selected", String.valueOf(g.isSelected));
                }/*from  www  . ja v  a 2  s  .c o m*/
                selectionChanged = true;
            }
            if (g.isSelected)
                selectionList.add(g.gid);
        }

        if (selectionChanged) {
            // Update panel and view
            deselectTerminals();
            panel.updateButtons(false, selectionList);
            repaint();
            return;
        }

        // Clicked a terminal?
        selectionList.clear();
        Iterator<Terminal> itert = terminalMap.values().iterator();
        while (itert.hasNext()) {
            Terminal t = itert.next();
            if ((p.x >= t.x) && (p.x < t.x + SERVERVIEW_TERMINAL_WIDTH) && (p.y >= t.y)
                    && (p.y < t.y + SERVERVIEW_TERMINAL_HEIGHT)) {
                t.isSelected = !t.isSelected;
                synchronized (doc) {
                    Element etd = DomTools.getElementFromSection(doc, "TerminalDefs", "id",
                            String.valueOf(t.tid));
                    if (etd != null)
                        etd.setAttribute("selected", String.valueOf(t.isSelected));
                }
                selectionChanged = true;
            }
            if (t.isSelected)
                selectionList.add(t.tid);
        }

        if (selectionChanged) {
            // Update panel and view
            deselectGroups();
            panel.updateButtons(true, selectionList);
            repaint();
        }

        // Clicked on the workspace, deselect all
        else {
            panel.deselectAll();
        }
    }
}

From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphPanel.java

/**
 * Handle mouse pressed event/*from   ww  w  .  j  a  va2 s. c om*/
 *
 * @param e the mouse event
 */
public void mousePressed(MouseEvent e) {
    checkPopup(e);

    if (showHeadHotSpot) {
        connectingSourceFromHead = true;
    } else if (showTailHotSpot) {
        connectingSourceFromTail = true;
    }

    lastMousePos = e.getPoint();
}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.querycreationtreepanel.QueryComponentExpressionPanel.java

/**
 * Creates the excluded terms panel./*from   ww w  .  j  a  v a  2s  .  co m*/
 */
private synchronized void createExcludedTermsPanel() {

    // create table for displaying excluded constraints
    excludedConstraintTableModel = new TerminologyConstraintTableModel();
    excludedConstraintsTable = new JTable(excludedConstraintTableModel);
    excludedConstraintsTable.setDefaultRenderer(TerminologyConstraint.class,
            new TerminologyConstraintTableCellRenderer(humanReadableRender));
    excludedConstraintsTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            // get row a click
            int row = excludedConstraintsTable.rowAtPoint(e.getPoint());
            if (row > -1 && e.getClickCount() == 2) {
                //                    addingNew = false;
                editingExisting = true;
                // get constraint at row
                activeTerminologyConstraint = excludedConstraintTableModel.getConstraintAtRow(row);
                // set constraint in activeConstraintPanel and display activeConstraintsDialog
                activeConstraintPanel.setConstraint(activeTerminologyConstraint);
                activeConstraintsDialog.setVisible(true);
            }
        }
    });

    // create a label and control buttons for editing excluded constraints
    JPanel p3 = new JPanel();
    p3.setLayout(new BoxLayout(p3, BoxLayout.LINE_AXIS));
    p3.add(new JLabel("Edit excluded constraints"));
    p3.add(Box.createHorizontalGlue());

    // add panel for editing excluded terms
    JideButton addExclusionTermButton = new JideButton(new AbstractAction("", addExclusionIcon) {

        public void actionPerformed(ActionEvent e) {
            // show activeConstraintsDialog
            //                addingNew = true;
            activeConstraintsDialog.setVisible(true);
        }
    });
    addExclusionTermButton.setName("addExclusionTermButton");

    JideButton deleteExclusionTermButton = new JideButton(new AbstractAction("", deleteExclusionIcon) {

        public void actionPerformed(ActionEvent e) {
            final int row = excludedConstraintsTable.getSelectedRow();
            if (row > -1) {
                QueryStatement oldValue = queryService.getActiveQuery();
                // get term at row
                TerminologyConstraint term = (TerminologyConstraint) excludedConstraintTableModel
                        .getValueAt(row, 1);
                // remove term from sub query
                componentExpression.removeExcludedConstraint(term);
                Runnable runnable = new Runnable() {
                    public void run() {
                        excludedConstraintTableModel.deleteRow(row);
                    }
                };
                SwingUtilities.invokeLater(runnable);
                // notify listeners
                propertyChangeTrackerService.firePropertyChanged(ACTIVE_QUERY_CHANGED, oldValue,
                        queryService.getActiveQuery(), QueryComponentExpressionPanel.this);
            }
        }
    });
    deleteExclusionTermButton.setName("deleteExclusionTermButton");

    // add buttons to p3
    p3.add(addExclusionTermButton);
    p3.add(deleteExclusionTermButton);

    // create panel that contains excluded constraints
    excludedConstraintsPanel = new JPanel(new BorderLayout());
    excludedConstraintsPanel.setBorder(BorderFactory.createTitledBorder("Excluded constraints"));
    excludedConstraintsPanel.add(p3, BorderLayout.NORTH);
    JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(excludedConstraintsTable);
    excludedConstraintsPanel.add(scrollPane, BorderLayout.CENTER);
}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.querycreationtreepanel.QueryComponentExpressionPanel.java

/**
 * Creates the additional constraints table panel.
 *//*ww  w.j ava 2  s  .co  m*/
private synchronized void createAdditionalConstraintsTablePanel() {

    constraintsTableModel = new ConstraintTableModel(constraints);
    constraintsTable = new JXTable(constraintsTableModel);
    constraintsTable.setPreferredScrollableViewportSize(new Dimension(400, 80));
    constraintsTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            // get row at click point
            int row = constraintsTable.rowAtPoint(e.getPoint());
            if (row > -1) {
                // check if double click
                if (e.getClickCount() == 2) {
                    // get term at row
                    Constraint constraint = constraintsTableModel.getConstraintAtRow(row);
                    // set as active constraint
                    activeAdditionalConstraint = constraint;
                    // show in active constraint dialog
                    constraintPanel.setConstraint(activeAdditionalConstraint);
                    // set editing tag to true
                    editingExisting = true;
                    constraintCollapsiblePane.setCollapsed(false);
                }
            }
        }
    });

    // add panel for editing excluded terms
    JideButton addConstraintButton = new JideButton(new AbstractAction("", addConstraintIcon) {

        public void actionPerformed(ActionEvent e) {
            constraintCollapsiblePane.setCollapsed(false);
            // disable editing tag
            editingExisting = false;
        }
    });
    addConstraintButton.setName("addConstraintButton");
    addConstraintButton.setBorderPainted(false);

    JideButton deleteConstraintButton = new JideButton(new AbstractAction("", deleteConstraintIcon) {

        public void actionPerformed(ActionEvent e) {
            final int row = constraintsTable.getSelectedRow();
            if (row > -1) {
                // get constraint at row
                Constraint cons = constraintsTableModel.getConstraintAtRow(row);
                // remove from subquery
                componentExpression.removeAdditionalConstraint(cons);
                Runnable runnable = new Runnable() {
                    public void run() {
                        // delete constraint at row
                        constraintsTableModel.deleteRow(row);
                        constraintsTable.revalidate();
                        QueryComponentExpressionPanel.this.revalidate();
                    }
                };
                SwingUtilities.invokeLater(runnable);
                // notify listeners of query change
                queryService.queryChanged(queryService.getActiveQuery(), QueryComponentExpressionPanel.this);
            }
        }
    });
    deleteConstraintButton.setName("deleteConstraintButton");
    deleteConstraintButton.setBorderPainted(false);

    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.LINE_AXIS));
    buttonsPanel.add(new JLabel("Edit constraints"));
    buttonsPanel.add(Box.createHorizontalGlue());
    buttonsPanel.add(addConstraintButton);
    buttonsPanel.add(deleteConstraintButton);

    additionalConstraintsPanel = new JPanel(new BorderLayout());
    additionalConstraintsPanel.setBorder(BorderFactory.createTitledBorder("Additional Constraints"));
    additionalConstraintsPanel.add(buttonsPanel, BorderLayout.NORTH);
    additionalConstraintsPanel.add(new JScrollPane(constraintsTable), BorderLayout.CENTER);
    additionalConstraintsPanel.add(constraintCollapsiblePane, BorderLayout.SOUTH);

}