Example usage for java.awt.event MouseEvent getSource

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

Introduction

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

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

private void fireAddVillagesEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireAddVillagesEvent
    List<Village> villages = new ArrayList<Village>();
    if (evt.getSource() == jAllSources) {
        DefaultListModel model = (DefaultListModel) jSourceVillageList.getModel();
        for (int i = 0; i < model.getSize(); i++) {
            villages.add((Village) model.getElementAt(i));
        }/*from ww  w .  j  a  v a  2  s.c  o  m*/
        fireAddSourcesEvent(villages);
    } else if (evt.getSource() == jSelectedSources) {
        Object[] selection = jSourceVillageList.getSelectedValues();
        if (selection == null || selection.length == 0) {
            showInfo("Keine Drfer gewhlt");
            return;
        }
        for (Object v : selection) {
            villages.add((Village) v);
        }
        fireAddSourcesEvent(villages);
    } else if (evt.getSource() == jAllTargets) {
        DefaultListModel model = (DefaultListModel) jTargetVillageList.getModel();
        for (int i = 0; i < model.getSize(); i++) {
            villages.add((Village) model.getElementAt(i));
        }
        fireAddTargetsEvent(villages);
    } else if (evt.getSource() == jSelectedTargets) {
        Object[] selection = jTargetVillageList.getSelectedValues();
        if (selection == null || selection.length == 0) {
            showInfo("Keine Drfer gewhlt");
            return;
        }
        for (Object v : selection) {
            villages.add((Village) v);
        }
        fireAddTargetsEvent(villages);
    }
    showInfo(villages.size() + ((villages.size() == 1) ? " Dorf " : " Drfer ") + "eingefgt");

}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

private void fireSynchWithAttackPlansEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireSynchWithAttackPlansEvent
    jAttackPlanSelectionDialog.setVisible(false);
    if (evt.getSource() == jCancelSyncButton) {
        return;//ww  w.j av a2  s  .c  o m
    }

    int idx = jideTabbedPane1.getSelectedIndex();

    JXTable table = null;
    int villageIndex = 0;
    if (idx == 0) {
        table = jSourcesTable;
    } else if (idx == 1) {
        table = jVictimTable;
        villageIndex = 1;
    } else {
        showInfo("Diese Funktion ist nur fr Herkunftsdrfer und Ziele verfgbar");
        return;
    }

    DefaultTableModel model = (DefaultTableModel) jAttackPlanTable.getModel();
    List<String> selectedPlans = new LinkedList<String>();
    for (int i = 0; i < jAttackPlanTable.getRowCount(); i++) {
        int row = jAttackPlanTable.convertRowIndexToModel(i);
        if ((Boolean) model.getValueAt(row, jAttackPlanTable.convertColumnIndexToModel(1))) {
            selectedPlans.add((String) model.getValueAt(row, jAttackPlanTable.convertColumnIndexToModel(0)));
        }
    }
    List<Integer> toRemove = new LinkedList<Integer>();
    //process all plans
    for (String plan : selectedPlans) {
        logger.debug("Checking plan '" + plan + "'");
        List<ManageableType> elements = AttackManager.getSingleton().getAllElements(plan);
        //process all attacks
        for (ManageableType e : elements) {
            Attack a = (Attack) e;
            //search attack source village in all table rows
            for (int i = 0; i < table.getRowCount(); i++) {
                Village v = (Village) table.getValueAt(i, villageIndex);
                if (villageIndex == 0 && a.getSource().equals(v)) {
                    if (!toRemove.contains(i)) {
                        toRemove.add(i);
                    }
                } else if (villageIndex == 1 && a.getTarget().equals(v)) {
                    if (!toRemove.contains(i)) {
                        toRemove.add(i);
                    }
                }
            }
        }
    }
    String message = "";
    if (toRemove.isEmpty()) {
        showInfo("Keine Drfer zu entfernen");
        return;
    } else {
        message = (toRemove.size() == 1) ? "Ein Dorf " : toRemove.size() + " Drfer ";
    }
    if (JOptionPaneHelper.showQuestionConfirmBox(this, message + "entfernen?", "Entfernen", "Nein",
            "Ja") == JOptionPane.YES_OPTION) {
        try {
            logger.debug("Removing " + toRemove.size() + " villages");
            Collections.sort(toRemove);
            while (toRemove.size() > 0) {
                Integer row = toRemove.remove(toRemove.size() - 1);
                row = table.convertRowIndexToModel(row);
                ((DefaultTableModel) table.getModel()).removeRow(row);
            }
            showSuccess(message + "entfernt");
        } catch (Exception e) {
            logger.error("Removal failed", e);
            showError("Fehler beim Entfernen");
        }
    }
    updateInfo();
}

From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java

private void selectionDatabase(TreePath selPath, DBBrowserNode selectedNode, MouseEvent e) {
    if (e.getClickCount() == 2) {
        return;//from www  .  ja  v a  2 s .  c  om
    }
    boolean connected = false;
    String name = selectedNode.getDBObject().getName();
    DataSourceManager manager = DefaultDataSourceManager.getInstance();
    DataSource ds = manager.getDataSource(name);
    if (ds.getStatus() == DataSourceType.CONNECTED) {
        connected = true;
    } else {
        connected = false;
    }

    // try to create source directory (may not exists if we copy datasource.xml)
    (new File(FileReportPersistence.CONNECTIONS_DIR + File.separator + name + File.separator
            + FileReportPersistence.QUERIES_FOLDER)).mkdirs();
    (new File(FileReportPersistence.CONNECTIONS_DIR + File.separator + name + File.separator
            + FileReportPersistence.REPORTS_FOLDER)).mkdirs();
    (new File(FileReportPersistence.CONNECTIONS_DIR + File.separator + name + File.separator
            + FileReportPersistence.CHARTS_FOLDER)).mkdirs();

    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem(new DataSourceConnectAction(instance, selPath));
    popupMenu.add(menuItem);
    if (connected) {
        menuItem.setEnabled(false);
    } else {
        menuItem.setEnabled(true);
    }

    JMenuItem menuItem2 = new JMenuItem(new DataSourceDisconnectAction(instance, selectedNode));
    popupMenu.add(menuItem2);
    if (connected) {
        menuItem2.setEnabled(true);
    } else {
        menuItem2.setEnabled(false);
    }

    JMenuItem menuItem5 = new JMenuItem(new DataSourceViewInfoAction(selectedNode));
    popupMenu.add(menuItem5);

    JMenuItem menuItem3 = new JMenuItem(new DataSourceEditAction(instance, selectedNode));
    popupMenu.add(menuItem3);
    if (connected) {
        menuItem3.setEnabled(false);
    } else {
        menuItem3.setEnabled(true);
    }

    JMenuItem menuItem4 = new JMenuItem(new DataSourceDeleteAction(instance, selectedNode));
    popupMenu.add(menuItem4);
    if (connected) {
        menuItem4.setEnabled(false);
    } else {
        menuItem4.setEnabled(true);
    }

    if (!DefaultDataSourceManager.memoryDataSources()) {
        JMenuItem menuItem6 = new JMenuItem(new DataSourceSchemaSelectionAction(instance, selectedNode));
        popupMenu.add(menuItem6);
    }

    popupMenu.show((Component) e.getSource(), e.getX(), e.getY());
}

From source file:GUI.MainWindow.java

private void VulnReferencesListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_VulnReferencesListMouseClicked

    int clicked = evt.getButton();
    if (clicked == MouseEvent.BUTTON1 && evt.getClickCount() == 2) {
        // A double click. Lets see if there is already a link or if we are creating a new one
        Object obj = VulnReferencesList.getSelectedValue();
        if (obj == null) {
            // We should simply show the 'add reference' prompy
        } else if (obj instanceof Reference) {
            // User probably wants to edit the existing reference
            Reference ref = (Reference) obj;
            addReference(VulnTree, VulnReferencesList, ref);
        }/*from www. j a  v a2 s  .c o m*/
    } else if (clicked == MouseEvent.BUTTON3) {
        // A right click. Show the context menu
        //int selected = VulnReferencesList.getSelectedIndex();
        List l = VulnReferencesList.getSelectedValuesList();
        int selected = l.size();

        System.out.println("selected: " + selected);
        // None are selected enable insert and disable all the rest
        InsertReference.setEnabled(true);
        EditReferenceOption.setEnabled(false);
        LaunchInBrowser.setEnabled(false);
        DeleteReferenceOption.setEnabled(false);

        if (selected == 1) {
            // One was selected to enable the right options
            InsertReference.setEnabled(true);
            EditReferenceOption.setEnabled(true);
            LaunchInBrowser.setEnabled(true);
            DeleteReferenceOption.setEnabled(true);
        } else if (selected >= 2) {
            // One was selected to enable the right options
            InsertReference.setEnabled(true);
            EditReferenceOption.setEnabled(false);
            LaunchInBrowser.setEnabled(true);
            DeleteReferenceOption.setEnabled(true);
        }

        VulnReferencesContextMenu.show((Component) evt.getSource(), evt.getX(), evt.getY());
    }
}

From source file:com.pianobakery.complsa.MainGui.java

public MainGui() {

    $$$setupUI$$$();/*from  w  w w .j a  v  a2  s . c  o  m*/
    runtimeParameters();
    trainCorp = new HashMap<String, File>();
    trainSentModels = new HashMap<String, File>();
    indexFilesModel = new HashMap<String, File>();
    searchCorpusModel = new HashMap<String, File>();
    selDocdirContent = new ArrayList<File>();
    langModelsText.setText("None");
    posIndRadiusTextField.setEnabled(false);
    //Disable all Components as long as wDir is not set.
    enableUIElements(false);

    ButtonGroup selSearchGroup = new ButtonGroup();
    selSearchGroup.add(searchSearchCorpRadioButton);
    selSearchGroup.add(searchTopCorpRadioButton);

    ButtonGroup searchSelGroup = new ButtonGroup();
    searchSelGroup.add(selTextRadioButton);
    searchSelGroup.add(selDocRadioButton);

    //licenseKeyGUI = new LicenseKeyGUI(frame, true);

    //Added to get the docSearchTable the focus when opening the Reader without selecting something so up down button will work
    frame.addWindowFocusListener(new WindowAdapter() {
        public void windowGainedFocus(WindowEvent e) {
            docSearchResTable.requestFocusInWindow();
        }
    });

    frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "CTRL + S");
    frame.getRootPane().getActionMap().put("CTRL + S", runSearch());

    frame.addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent evt) {
            formWindowOpened(evt);
        }
    });

    //Needs to get a white background in the termtableview (only in windows)
    termTablePane.getViewport().setBackground(Color.WHITE);

    //Project Page
    //Project Folder
    newFolderButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            newFolderMethod();

        }
    });

    selectFolderButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            selectFolderMethod();

        }
    });

    //Download Language Models
    downloadModelButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            downloadModelMethod();

        }
    });

    //Add-Remove Topic Corpus
    addTopicCorpusButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            addTopicCorpusMethod();

        }
    });

    selectTrainCorp.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            frame.setTitle("Selected Training Corpus: " + selectTrainCorp.getSelectedItem() + " and "
                    + "Sel. Search Corpus: " + searchCorpComboBox.getSelectedItem());
            algTextField.setText("Knowledge Corpus: " + selectTrainCorp.getSelectedItem());

            try {
                updateIndexFileFolder();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    });

    removeTopicCorpusButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) throws ArrayIndexOutOfBoundsException {
            removeTopicCorpusMethod();

        }

    });

    //Update and remove Index
    updateIndexButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateIndexMethod();

        }
    });

    removeIndexButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            removeIndexMethod();

        }
    });

    //Train Semantic
    trainCorpButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            trainCorpMethod();

        }
    });

    indexTypeComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            if (indexTypeComboBox.getSelectedIndex() == 2) {
                logger.debug("Enable indexType Combo with Index: " + indexTypeComboBox.getSelectedIndex());

                posIndRadiusTextField.setEnabled(true);
                return;
            }
            logger.debug("Disable indexType Combo with Index: " + indexTypeComboBox.getSelectedIndex());
            posIndRadiusTextField.setEnabled(false);

        }
    });

    //Import and remove Search Corpora
    impSearchCorpButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            impSearchCorpMethod();

        }
    });

    searchCorpComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            frame.setTitle("Selected Training Corpus: " + selectTrainCorp.getSelectedItem() + " and "
                    + "Sel. Search Corpus: " + searchCorpComboBox.getSelectedItem());
        }
    });

    removeSearchCorpButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) throws ArrayIndexOutOfBoundsException {
            removeSearchCorpMethod();

        }

    });

    //Search Page
    //Choose Index Type
    selectIndexTypeComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            if (searchModelList.isEmpty()) {
                return;
            }

            if (searchModelList.get(selectIndexTypeComboBox.getSelectedItem()) == null) {
                return;
            }

            List<String> theList = searchModelList.get(selectIndexTypeComboBox.getSelectedItem().toString());
            selectTermweightComboBox.removeAllItems();
            for (String aTFItem : theList) {
                selectTermweightComboBox.addItem(aTFItem);
            }

            getSelectedSearchModelFiles();

        }
    });

    selectTermweightComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            if (searchModelList.isEmpty()) {
                return;
            }

            if (searchModelList.get(selectIndexTypeComboBox.getSelectedItem()) == null) {
                return;
            }
            getSelectedSearchModelFiles();
        }
    });

    //Select Search Type
    selTextRadioButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            selectDocumentButton.setEnabled(false);
            searchTextArea.setEnabled(true);
            //searchDocValue.setText("nothing selected");

        }
    });

    selDocRadioButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            selectDocumentButton.setEnabled(true);
            searchTextArea.setText(null);
            searchTextArea.setEnabled(false);

        }
    });

    selectDocumentButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            importSearchFile();
            openSearchDocumentButton.setEnabled(true);

        }
    });

    openSearchDocumentButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (searchDocReader == null) {
                searchDocReader = getReaderLater(null, maingui);
                searchDocReader.setSearchTerms(getSelectedTermTableWords());
            } else if (!searchDocReader.getFrameVisible()) {
                searchDocReader.setFrameVisible(true);
                searchDocReader.setSearchTerms(getSelectedTermTableWords());
            }
            searchDocReader.setDocumentText(searchFileString);
            searchDocReader.setSelFullDocLabel(searchDocValue.toString());
            searchDocReader.setViewPane(2);
            searchDocReader.disableComponents();
            searchDocReader.setSearchTerms(getSelectedTermTableWords());

        }
    });

    //Search Button
    searchButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            searchMethod();

        }

    });

    //Table Listeners
    docSearchResTable.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent me) {
            JTable table = (JTable) me.getSource();
            Point p = me.getPoint();
            int row = docSearchResTable.rowAtPoint(p);
            if (docSearchResModel == null || docSearchResModel.getRowCount() == 0
                    || docSearchResModel.getDocFile(0).getFileName().equals(emptyTable)) {
                return;
            }

            switch (me.getClickCount()) {
            case 1:
                if (row == -1) {
                    break;
                }
                if (docSearchResTable.getRowCount() > 0) {
                    logger.debug("Single click Doc: " + ((DocSearchModel) docSearchResTable.getModel())
                            .getDocSearchFile(row).getFile().toString());
                    fillMetaDataField(
                            ((DocSearchModel) docSearchResTable.getModel()).getDocSearchFile(row).getFile());
                    if (reader != null) {
                        reader.setSearchTerms(getSelectedTermTableWords());
                    }
                    if (searchDocReader != null) {
                        searchDocReader.setSearchTerms(getSelectedTermTableWords());
                    }
                    setSelReaderContent();
                    setDocReaderContent(0);
                    if (reader != null) {
                        reader.setSearchTerms(getSelectedTermTableWords());
                    }
                    if (searchDocReader != null) {
                        searchDocReader.setSearchTerms(getSelectedTermTableWords());
                    }

                }
                break;
            case 2:
                if (row == -1) {
                    break;
                }
                if (docSearchResTable.getRowCount() > 0) {
                    logger.debug("Double click Doc: " + ((DocSearchModel) docSearchResTable.getModel())
                            .getDocSearchFile(row).getFile().toString());
                    fillMetaDataField(
                            ((DocSearchModel) docSearchResTable.getModel()).getDocSearchFile(row).getFile());

                    if (reader == null) {
                        reader = getReaderLater((DocSearchModel) docSearchResTable.getModel(), maingui);
                        reader.setSearchTerms(getSelectedTermTableWords());
                    } else if (!reader.getFrameVisible()) {
                        reader.setFrameVisible(true);
                        reader.setSearchTerms(getSelectedTermTableWords());
                    }
                    setSelReaderContent();
                    setDocReaderContent(0);
                    if (reader != null) {
                        reader.setSearchTerms(getSelectedTermTableWords());
                    }
                    if (searchDocReader != null) {
                        searchDocReader.setSearchTerms(getSelectedTermTableWords());
                    }
                }
                break;
            }

        }
    });

    termSearchResTable.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent me) {
            JTable table = (JTable) me.getSource();
            Point p = me.getPoint();
            int row = docSearchResTable.rowAtPoint(p);
            if (termSearchResTable.getModel() == null || termSearchResTable.getRowCount() == 0
                    || termSearchResTable.getModel().getValueAt(row, 1).equals(emptyTable)) {
                return;
            }
            switch (me.getClickCount()) {
            case 1:
                logger.debug("Single click Term: " + termSearchResTable.getModel().getValueAt(row, 1));
                logger.debug("Selected Terms: " + Arrays.toString(getSelectedTermTableWords()));
                if (reader != null) {
                    reader.setSearchTerms(getSelectedTermTableWords());

                }
                if (searchDocReader != null) {
                    searchDocReader.setSearchTerms(getSelectedTermTableWords());
                }
                break;
            case 2:
                logger.debug("Double click Term: " + termSearchResTable.getModel().getValueAt(row, 1));
                if (reader != null) {
                    reader.setSearchTerms(getSelectedTermTableWords());
                }
                if (searchDocReader != null) {
                    searchDocReader.setSearchTerms(getSelectedTermTableWords());
                }
                break;

            }

        }
    });

    docSearchResTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent event) {
            if (docSearchResModel == null || docSearchResModel.getRowCount() == 0
                    || docSearchResModel.getDocFile(0).getFileName().equals(emptyTable)) {
                return;
            }
            if (docSearchResTable.getSelectedRow() > -1) {
                // print first column value from selected row
                logger.debug("KeyboardSelection: " + ((DocSearchModel) docSearchResTable.getModel())
                        .getDocSearchFile(
                                docSearchResTable.convertRowIndexToModel(docSearchResTable.getSelectedRow()))
                        .getFile().toString());
                fillMetaDataField(((DocSearchModel) docSearchResTable.getModel())
                        .getDocSearchFile(
                                docSearchResTable.convertRowIndexToModel(docSearchResTable.getSelectedRow()))
                        .getFile());
                setSelReaderContent();
                setDocReaderContent(0);
                if (reader != null) {
                    reader.setSearchTerms(getSelectedTermTableWords());
                }
                if (searchDocReader != null) {
                    searchDocReader.setSearchTerms(getSelectedTermTableWords());
                }

            }
        }
    });

    termSearchResTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (termSearchResTable.getModel() == null || termSearchResTable.getRowCount() == 0
                    || termSearchResTable.getModel().getValueAt(0, 1).equals(emptyTable)) {
                return;
            }
            if (termSearchResTable.getSelectedRow() > -1) {
                // print first column value from selected row
                if (reader != null) {
                    reader.setSearchTerms(getSelectedTermTableWords());
                }
                if (searchDocReader != null) {
                    searchDocReader.setSearchTerms(getSelectedTermTableWords());
                }

            }

        }
    });

}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

private void fireUpdateSelectionEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireUpdateSelectionEvent
    int start = 1;
    int end = 10;

    start = UIHelper.parseIntFromField(jSelectionStart, 1);
    end = UIHelper.parseIntFromField(jSelectionEnd, 10);

    try {//from w w w. ja  v a  2 s. co  m
        //switch numbers if start larger than end
        if (start > end) {
            int tmp = start;
            start = end;
            end = tmp;
        }
        int diff = end - start + 1;
        if (evt == null || evt.getSource() == jSelectButton) {
            //do nothing
        } else if (evt.getSource() == jSelectionBeginButton && jSelectionBeginButton.isEnabled()) {
            start = 1;
            end = diff;
        } else if (evt.getSource() == jPrevSelectionButton) {
            start -= diff;
            if (start <= 0) {
                start = 1;
            }
            end = start + diff - 1;
        } else if (evt.getSource() == jNextSelectionButton) {
            start = end + 1;
            end = (start + diff - 1 > jSourceVillageList.getModel().getSize())
                    ? jSourceVillageList.getModel().getSize()
                    : (start + diff - 1);
        } else if (evt.getSource() == jSelectionEndButton && jSelectionEnd.isEnabled()) {
            end = jSourceVillageList.getModel().getSize();
            start = end - diff + 1;
        }
        jSelectionEndButton.setEnabled(!(end == jSourceVillageList.getModel().getSize()));
        jSelectionBeginButton.setEnabled(!(start == 1));
        jSelectionStart.setText(Integer.toString(start));
        jSelectionEnd.setText(Integer.toString(end));
        jSourceVillageList.getSelectionModel().setSelectionInterval(start - 1, end - 1);
        jSourceVillageList.scrollRectToVisible(jSourceVillageList.getCellBounds(start - 1, end - 1));
    } catch (Exception e) {
        logger.warn("Error while calculating source selection step", e);
    }
}

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

/**
 * @param parentList/*from ww w.j a va 2s. c  o m*/
 */
protected void fillNextList(final JList parentList) {
    if (processingLists) {
        return;
    }

    processingLists = true;

    final int curInx = listBoxList.indexOf(parentList);
    if (curInx > -1) {
        int startSize = listBoxPanel.getComponentCount();
        for (int i = curInx + 1; i < listBoxList.size(); i++) {
            listBoxPanel.remove(spList.get(i));
        }
        int removed = startSize - listBoxPanel.getComponentCount();
        for (int i = 0; i < removed; i++) {
            tableTreeList.remove(tableTreeList.size() - 1);
        }

    } else {
        listBoxPanel.removeAll();
        tableTreeList.clear();
    }

    QryListRendererIFace item = (QryListRendererIFace) parentList.getSelectedValue();
    if (item instanceof ExpandableQRI) {
        JList newList;
        DefaultListModel model;
        JScrollPane sp;

        if (curInx == listBoxList.size() - 1) {
            newList = new JList(model = new DefaultListModel());
            newList.addMouseListener(new MouseAdapter() {

                /* (non-Javadoc)
                 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
                 */
                @Override
                public void mouseClicked(MouseEvent e) {
                    if (e.getClickCount() == 2) {
                        if (currentInx != -1) {
                            JList list = (JList) e.getSource();
                            QryListRendererIFace qriFace = (QryListRendererIFace) list.getSelectedValue();
                            if (BaseQRI.class.isAssignableFrom(qriFace.getClass())) {
                                BaseQRI qri = (BaseQRI) qriFace;
                                if (qri.isInUse()) {
                                    //remove the field
                                    for (QueryFieldPanel qfp : QueryBldrPane.this.queryFieldItems) {
                                        FieldQRI fqri = qfp.getFieldQRI();
                                        if (fqri == qri || (fqri instanceof RelQRI && fqri.getTable() == qri)) {
                                            boolean clearIt = qfp.getSchemaItem() != null;
                                            QueryBldrPane.this.removeQueryFieldItem(qfp);
                                            if (clearIt) {
                                                qfp.setField(null, null);
                                            }
                                            break;
                                        }
                                    }
                                } else {
                                    // add the field
                                    try {
                                        FieldQRI fieldQRI = buildFieldQRI(qri);
                                        if (fieldQRI == null) {
                                            throw new Exception("null FieldQRI");
                                        }
                                        SpQueryField qf = new SpQueryField();
                                        qf.initialize();
                                        qf.setFieldName(fieldQRI.getFieldName());
                                        qf.setStringId(fieldQRI.getStringId());
                                        query.addReference(qf, "fields");
                                        if (!isExportMapping) {
                                            addQueryFieldItem(fieldQRI, qf, false);
                                        } else {
                                            addNewMapping(fieldQRI, qf, null, false);
                                        }
                                    } catch (Exception ex) {
                                        log.error(ex);
                                        UsageTracker.incrHandledUsageCount();
                                        edu.ku.brc.exceptions.ExceptionTracker.getInstance()
                                                .capture(QueryBldrPane.class, ex);
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            });
            newList.setCellRenderer(qryRenderer);
            listBoxList.add(newList);
            sp = new JScrollPane(newList, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            JLabel colHeader = UIHelper.createLabel(item.getTitle());
            colHeader.setHorizontalAlignment(SwingConstants.CENTER);
            colHeader.setBackground(listBoxPanel.getBackground());
            colHeader.setOpaque(true);

            sp.setColumnHeaderView(colHeader);

            spList.add(sp);

            newList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
                public void valueChanged(ListSelectionEvent e) {
                    if (!e.getValueIsAdjusting()) {
                        fillNextList(listBoxList.get(curInx + 1));
                    }
                }
            });

        } else {
            newList = listBoxList.get(curInx + 1);
            model = (DefaultListModel) newList.getModel();
            sp = spList.get(curInx + 1);
            JLabel colHeaderLbl = (JLabel) sp.getColumnHeader().getComponent(0);
            if (item instanceof TableQRI) {
                colHeaderLbl.setText(((TableQRI) item).getTitle());
            } else {
                colHeaderLbl.setText(getResourceString("QueryBldrPane.QueryFields"));
            }
        }

        createNewList((TableQRI) item, model);

        listBoxPanel.remove(addBtn);
        listBoxPanel.add(sp);
        tableTreeList.add(((ExpandableQRI) item).getTableTree());
        listBoxPanel.add(addBtn);
        currentInx = -1;

    } else {
        listBoxPanel.add(addBtn);
    }

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            updateAddBtnState();

            // Is all this really necessary
            listBoxPanel.validate();
            listBoxPanel.repaint();
            scrollPane.validate();
            scrollPane.invalidate();
            scrollPane.doLayout();
            scrollPane.repaint();
            validate();
            invalidate();
            doLayout();
            repaint();
            UIRegistry.forceTopFrameRepaint();
        }
    });

    processingLists = false;
    currentInx = curInx;

}

From source file:base.BasePlayer.Main.java

@Override
public void mouseReleased(MouseEvent event) {

    if (event.getSource() == splitPaneDivider) {
        Main.bedCanvas.resize = false;/*from  w w w.  ja  v a  2  s . co  m*/
        Main.bedCanvas.repaint();
    }
    if (event.getSource() == varPaneDivider) {

        Main.bedCanvas.resize = false;
        Main.bedCanvas.repaint();
        Draw.updatevars = true;
        Draw.updateReads = true;
        Draw.updateCoverages = true;
        drawCanvas.repaint();
    }

    if (event.getSource() == drawScroll.getVerticalScrollBar()) {

        if (Main.drawScroll.getVerticalScrollBar()
                .getValue() > (drawCanvas.drawVariables.visiblestart * drawCanvas.drawVariables.sampleHeight
                        + drawCanvas.drawVariables.sampleHeight / 2.0)) {
            drawCanvas.drawVariables.visiblestart++;

            Draw.setScrollbar(
                    (int) (drawCanvas.drawVariables.visiblestart * drawCanvas.drawVariables.sampleHeight));
        } else {
            Draw.setScrollbar(
                    (int) (drawCanvas.drawVariables.visiblestart * drawCanvas.drawVariables.sampleHeight));
        }

    }

    if (!drawCanvas.loading) {
        Draw.setGlasspane(false);
    }
    drawCanvas.scrolldrag = false;

    if (Main.bedCanvas.bedTrack.size() > 0) {
        for (int i = 0; i < Main.bedCanvas.bedTrack.size(); i++) {

            Main.bedCanvas.getMoreBeds(Main.bedCanvas.bedTrack.get(i));
        }
    }
}

From source file:base.BasePlayer.Main.java

@Override
/*   public boolean dispatchKeyEvent(KeyEvent e) {
              /*from  w ww. j  a v a 2s . c  o m*/
      int keyCode = e.getKeyCode();
              
      if(e.getID() == KeyEvent.KEY_PRESSED) {
         
 if((e.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
    Main.drawCanvas.ctrlpressed = 100;
    if(keyCode == KeyEvent.VK_S) {
       if(drawCanvas.drawVariables.projectName.equals("Untitled")) {
          saveProjectAs.doClick();
       }
       else {
          Serializer ser = new Serializer();
          ser.serialize(drawCanvas.drawVariables.projectFile);
       }
    }
         
 }
 else if(keyCode == KeyEvent.VK_7) {
            
 }      
 else if(keyCode == KeyEvent.VK_O && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) {
              
 }
 else if(keyCode == KeyEvent.VK_ENTER) {
            
    if(e.getSource() == searchField) {
       drawCanvas.scrollbar = false;
       searchString = searchField.getText();
       if(searchField.getText().toUpperCase().startsWith("S ") && searchField.getText().length() > 2) {
                  
          for(int i = 0; i<Main.drawCanvas.sampleList.size(); i++) {
                     
             if(Main.drawCanvas.sampleList.get(i).getName().toUpperCase().contains(searchField.getText().toUpperCase().substring(2))) {
                drawCanvas.drawVariables.visiblestart = (short)i;
                drawCanvas.drawVariables.visibleend = (short)i;
                        
                drawCanvas.resizeCanvas(this.getWidth(), (int)(Main.samples*drawCanvas.drawVariables.sampleHeight));
                Draw.setScrollbar((int)(i*drawCanvas.drawVariables.sampleHeight));                        
                break;
             }
          }
          return true;
       }
       if(searchField.getText().replace(" ", "").toUpperCase().matches("CHR.{1,2}(?!:)")) {
                  
           if(Main.chromnamevector.contains(searchField.getText().replace(" ", "").toUpperCase().substring(3))) {
              Main.chromosomeDropdown.setSelectedItem(searchField.getText().toUpperCase().substring(3));                     
           }                  
           return true;
       }
       if(searchField.getText().contains(",")) {
          searchString = searchField.getText().replace(" ", "").replace(",", "");
       }
       if(searchString.contains("chr")) {
          searchString = searchString.replace(" ", "").replace("chr", "");
       }
               
       if(searchTable.containsKey(searchString.toUpperCase())) {
                  
          FileRead.search = true;
          String[] result = searchTable.get(searchString.toUpperCase());
          drawCanvas.clearReads();
          FileRead.searchStart = Integer.parseInt(result[1]);
                  
          FileRead.searchEnd = Integer.parseInt(result[2]);
          searchChrom = result[0];
                  
          searchStart = Integer.parseInt(result[1]);
                  
          searchEnd = Integer.parseInt(result[2]);
                  
          drawCanvas.gotoPos(result[0], Integer.parseInt(result[1]), Integer.parseInt(result[2]));
       }
       else if(searchString.replace(" ", "").matches("\\d+-?\\d+?")) {
          FileRead.search = true;
          if(searchString.contains("-")) {
             drawCanvas.clearReads();
             drawCanvas.gotoPos(Main.drawCanvas.splits.get(0).chrom,Integer.parseInt(searchString.replace(" ", "").split("-")[0]), Integer.parseInt(searchString.replace(" ", "").split("-")[1]));      
          }
          else {
             drawCanvas.clearReads();
             drawCanvas.gotoPos(Main.drawCanvas.splits.get(0).chrom,Integer.parseInt(searchString.replace(" ", ""))-200, Integer.parseInt(searchString.replace(" ", ""))+200);      
          }   
               
       }
               
       else if(searchString.replace(" ", "").matches(".+:\\d+-?\\d+?")) {
          String[] result = searchString.replace(" ", "").split(":");
          FileRead.search = true;
          if(result[1].contains("-")) {
             drawCanvas.clearReads();
             drawCanvas.gotoPos(result[0].replace(" ", ""), Integer.parseInt(result[1].split("-")[0]), Integer.parseInt(result[1].split("-")[1]));
          }
          else {
             drawCanvas.clearReads();
             drawCanvas.gotoPos(result[0].replace(" ", ""), Integer.parseInt(result[1])-200, Integer.parseInt(result[1])+200);
          }
       }
               
    }
         
 }
      }
              
      return false;
   }
   @Override*/
public void mouseDragged(MouseEvent event) {

    if (event.getSource() == drawScroll.getVerticalScrollBar()) {
        glassPane.setVisible(true);
        drawCanvas.scrolldrag = true;
        /*      drawCanvas.drawVariables.visiblestart = (short)(Main.drawScroll.getVerticalScrollBar().getValue()/drawCanvas.drawVariables.sampleHeight);      
              //   if(drawCanvas.drawVariables.visiblestart + drawCanvas.drawVariables.visiblesamples < Main.samples-1) {
                      
                 drawCanvas.scrolldrag = true;
                         
                 if(drawCanvas.splits.size() > 1) {
                    for(int i = 0; i<drawCanvas.splits.size(); i++) {
                       drawCanvas.splits.get(i).updateReads = true;               
                    }
                 }
                 else {
                    Draw.updateReads = true;
                    Draw.updatevars = true;
                 }
                 Draw.updatevars = true;
                         
        //      }
         */
        Draw.updatevars = true;
        //drawCanvas.repaint();
        // TODO Auto-generated method stub
    }

}

From source file:base.BasePlayer.Main.java

@Override
public void mouseExited(MouseEvent event) {

    //   if(!drawCanvas.loading && !drawCanvas.scrollbar && event.getSource() == drawScroll.getVerticalScrollBar()) {

    //   Draw.setGlasspane(false);
    //   }//from   w  w w  . j av  a2  s  .c  om
    if (event.getSource() == drawCanvas) {
        Main.drawCanvas.sidebar = false;

        //   Main.drawCanvas.selectedSampleIndex = -1;
        Main.drawCanvas.repaint();

    }

}