Example usage for javax.swing.event ListSelectionListener ListSelectionListener

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

Introduction

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

Prototype

ListSelectionListener

Source Link

Usage

From source file:org.ut.biolab.medsavant.client.view.dialog.FamilySelector.java

private void initUI() {

    JPanel p = new JPanel();
    ViewUtil.applyVerticalBoxLayout(p);/*from   ww  w .  j av a2  s .com*/
    this.add(p);

    topPanel = ViewUtil.getClearPanel();
    middlePanel = ViewUtil.getClearPanel();
    bottomPanel = ViewUtil.getClearPanel();

    p.add(topPanel);
    p.add(middlePanel);
    p.add(bottomPanel);

    // middle
    middlePanel.setLayout(new BorderLayout());

    retriever = new FamilyReceiver();

    stp = new SearchableTablePanel("Individuals", COLUMN_NAMES, COLUMN_CLASSES, HIDDEN_COLUMNS, true, true,
            Integer.MAX_VALUE, false, SearchableTablePanel.TableSelectionType.ROW, Integer.MAX_VALUE,
            retriever);
    stp.setExportButtonVisible(false);

    middlePanel.add(stp, BorderLayout.CENTER);

    // bottom
    ViewUtil.applyVerticalBoxLayout(bottomPanel);

    numselections = ViewUtil.getTitleLabel("0 families selected");

    JPanel text = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(text);

    JButton clearIndividuals = ViewUtil
            .getIconButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.CLOSE));
    clearIndividuals.setToolTipText("Clear selections");
    clearIndividuals.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            clearSelections();
        }
    });

    text.add(numselections);
    text.add(Box.createHorizontalStrut(5));
    text.add(clearIndividuals);
    bottomPanel.add(ViewUtil.centerHorizontally(text));

    final JButton addAllIndividuals = ViewUtil.getSoftButton("Add All");
    bottomPanel.add(addAllIndividuals);

    final JButton addIndividuals = ViewUtil.getSoftButton("Add Selected");
    bottomPanel.add(addIndividuals);

    final JButton removeIndividuals = ViewUtil.getSoftButton("Remove Selected");
    bottomPanel.add(removeIndividuals);

    final JButton removeAllIndividuals = ViewUtil.getSoftButton("Remove All");
    bottomPanel.add(removeAllIndividuals);

    JPanel buttons = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(buttons);

    buttons.add(addAllIndividuals);
    buttons.add(addIndividuals);
    buttons.add(removeIndividuals);
    buttons.add(removeAllIndividuals);

    JPanel windowControlPanel = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(windowControlPanel);
    windowControlPanel.add(Box.createHorizontalGlue());

    JButton cancel = new JButton("Cancel");
    bottomPanel.add(ViewUtil.centerHorizontally(buttons));

    ok = new JButton("OK");
    bottomPanel.add(ViewUtil.alignRight(ok));
    ok.setEnabled(false);

    windowControlPanel.add(cancel);
    windowControlPanel.add(ok);

    bottomPanel.add(windowControlPanel);

    final JDialog instance = this;

    ok.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            instance.setVisible(false);
            setIndividualsChosen(true);
        }
    });

    cancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            instance.setVisible(false);
            setIndividualsChosen(false || hasMadeSelections);
        }
    });

    addIndividuals.setEnabled(false);
    removeIndividuals.setEnabled(false);

    stp.getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent lse) {
            if (!lse.getValueIsAdjusting()) {

                int rows[] = stp.getTable().getSelectedRows();

                boolean someSelection = rows.length > 0;

                addIndividuals.setEnabled(someSelection);
                removeIndividuals.setEnabled(someSelection);

                if (someSelection) {
                    addIndividuals.setText("Add Selected (" + rows.length + ")");
                    removeIndividuals.setText("Remove Selected (" + rows.length + ")");
                } else {
                    addIndividuals.setText("Add Selected");
                    removeIndividuals.setText("Remove Selected");
                }
            }
        }
    });

    stp.getTable().getModel().addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent tme) {
            //addAllIndividuals.setText("Add All (" + stp.getTable().getModel().getRowCount() + ")");
            //removeAllIndividuals.setText("Remove All (" + stp.getTable().getModel().getRowCount() + ")");
        }
    });

    ActionListener addAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            addSelections(false);
        }
    };

    ActionListener addAllAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            addSelections(true);
        }
    };

    ActionListener removeAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            removeSelections(false);
        }
    };

    ActionListener removeAllAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            removeSelections(true);
        }
    };

    addIndividuals.addActionListener(addAction);
    addAllIndividuals.addActionListener(addAllAction);
    removeIndividuals.addActionListener(removeAction);
    removeAllIndividuals.addActionListener(removeAllAction);

    this.pack();
    this.setLocationRelativeTo(MedSavantFrame.getInstance());
}

From source file:org.ut.biolab.medsavant.client.view.dialog.IndividualSelector.java

private void initUI() {

    JPanel p = new JPanel();
    ViewUtil.applyVerticalBoxLayout(p);//from ww  w .  j  av  a2  s  .  co  m
    this.add(p);

    topPanel = ViewUtil.getClearPanel();
    middlePanel = ViewUtil.getClearPanel();
    bottomPanel = ViewUtil.getClearPanel();

    p.add(topPanel);
    p.add(middlePanel);
    p.add(bottomPanel);

    // Only display the bottom panel for multiple patient selection
    if (onlyOnePatient) {
        bottomPanel.setVisible(false);
    }

    // middle
    middlePanel.setLayout(new BorderLayout());

    individualsRetriever = new IndividualsReceiver();
    individualsSTP = new SearchableTablePanel("Individuals", COLUMN_NAMES, COLUMN_CLASSES, HIDDEN_COLUMNS, true,
            true, Integer.MAX_VALUE, false, SearchableTablePanel.TableSelectionType.ROW, Integer.MAX_VALUE,
            individualsRetriever);
    individualsSTP.setExportButtonVisible(false);

    //If patients or cohorts are edited, update the searchabletable.
    CacheController.getInstance().addListener(new Listener<ModificationType>() {
        @Override
        public void handleEvent(ModificationType event) {
            if (event == ModificationType.PATIENT || event == ModificationType.COHORT) {
                if (!individualsSTP.isUpdating()) {
                    forceRefresh = true;
                    individualsSTP.forceRefreshData();
                }
            }
        }

    });

    middlePanel.add(individualsSTP, BorderLayout.CENTER);

    // bottom
    ViewUtil.applyVerticalBoxLayout(bottomPanel);

    numselections = ViewUtil.getTitleLabel("0 individual(s) selected");

    JPanel text = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(text);

    JButton clearIndividuals = ViewUtil
            .getIconButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.CLOSE));
    clearIndividuals.setToolTipText("Clear selections");
    clearIndividuals.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            clearSelections();
        }
    });

    text.add(numselections);
    text.add(Box.createHorizontalStrut(5));
    text.add(clearIndividuals);
    bottomPanel.add(ViewUtil.centerHorizontally(text));

    final JButton addAllIndividuals = ViewUtil.getSoftButton("Add All");
    bottomPanel.add(addAllIndividuals);

    final JButton addIndividuals = ViewUtil.getSoftButton("Add Selected");
    bottomPanel.add(addIndividuals);

    final JButton removeIndividuals = ViewUtil.getSoftButton("Remove Selected");
    bottomPanel.add(removeIndividuals);

    final JButton removeAllIndividuals = ViewUtil.getSoftButton("Remove All");
    bottomPanel.add(removeAllIndividuals);

    JPanel buttons = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(buttons);

    buttons.add(addAllIndividuals);
    buttons.add(addIndividuals);
    buttons.add(removeIndividuals);
    buttons.add(removeAllIndividuals);

    JPanel windowControlPanel = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(windowControlPanel);
    windowControlPanel.add(Box.createHorizontalGlue());

    JButton cancel = new JButton("Cancel");
    bottomPanel.add(ViewUtil.centerHorizontally(buttons));

    ok = new JButton("OK");
    bottomPanel.add(ViewUtil.alignRight(ok));
    ok.setEnabled(false);

    windowControlPanel.add(cancel);
    windowControlPanel.add(ok);

    bottomPanel.add(windowControlPanel);

    final JDialog instance = this;

    ok.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            instance.setVisible(false);
            setIndividualsChosen(true);
        }
    });

    cancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            instance.setVisible(false);
            setIndividualsChosen(false || hasMadeSelections);
        }
    });

    addIndividuals.setEnabled(false);
    removeIndividuals.setEnabled(false);

    individualsSTP.getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent lse) {
            if (!lse.getValueIsAdjusting()) {

                int rows[] = individualsSTP.getTable().getSelectedRows();

                boolean someSelection = rows.length > 0;

                addIndividuals.setEnabled(someSelection);
                removeIndividuals.setEnabled(someSelection);

                if (someSelection) {
                    addIndividuals.setText("Add Selected (" + rows.length + ")");
                    removeIndividuals.setText("Remove Selected (" + rows.length + ")");
                } else {
                    addIndividuals.setText("Add Selected");
                    removeIndividuals.setText("Remove Selected");
                }

                /* Close the dialog if only a single individual is requested. */
                if (onlyOnePatient && rows.length == 1) {
                    selectedRows.clear();
                    selectedHospitalIDs.clear();

                    int realRow = individualsSTP.getActualRowAt(rows[0]);
                    selectedRows.add(realRow);
                    Object[] o = individualsRetriever.getIndividuals().get(realRow);
                    selectedHospitalIDs.add(o[INDEX_OF_HOSPITAL_ID].toString());

                    instance.setVisible(false);
                    setIndividualsChosen(true);

                    individualsSTP.getTable().clearSelection(); // if errors crop up, this line may be causing ListSelectionEvents - can be removed
                }
            }
        }
    });

    individualsSTP.getTable().getModel().addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent tme) {
            //addAllIndividuals.setText("Add All (" + stp.getTable().getModel().getRowCount() + ")");
            //removeAllIndividuals.setText("Remove All (" + stp.getTable().getModel().getRowCount() + ")");
        }
    });

    ActionListener addAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            addSelections(false);
        }
    };

    ActionListener addAllAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            addSelections(true);
        }
    };

    ActionListener removeAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            removeSelections(false);
        }
    };

    ActionListener removeAllAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            removeSelections(true);
        }
    };

    addIndividuals.addActionListener(addAction);
    addAllIndividuals.addActionListener(addAllAction);
    removeIndividuals.addActionListener(removeAction);
    removeAllIndividuals.addActionListener(removeAllAction);

    this.pack();
    this.setLocationRelativeTo(MedSavantFrame.getInstance());
}

From source file:org.ut.biolab.medsavant.client.view.genetics.variantinfo.OtherIndividualsSubInspector.java

private HierarchicalTable initHierarchicalTable() {
    hTable = new HierarchicalTable();
    hTable.setModel(otherIndividualsTableModel);
    hTable.setHierarchicalColumn(-1);/*from w ww . j a  v  a2  s . co m*/
    hTable.setName("Individuals");
    hTable.setRowHeight(ROW_HEIGHT);
    hTable.setSingleExpansion(true);
    hTable.setShowGrid(false);
    hTable.setTableHeader(null);
    hTable.setSelectInsertedRows(false);
    hTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    hTable.setComponentFactory(new HierarchicalTableComponentFactory() {
        @Override
        public Component createChildComponent(HierarchicalTable table, Object value, int row) {
            if (value instanceof String) {
                return getIndividualSummaryPanel((String) value); //new VariantSummaryPanel((String) value);
            }
            return null;
        }

        @Override
        public void destroyChildComponent(HierarchicalTable table, Component component, int row) {
            //do Nothing
        }
    });

    hTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            int row = hTable.getSelectedRow();
            if (row != -1) {
                hTable.expandRow(row);
            }
        }
    });
    return hTable;
}

From source file:org.ut.biolab.medsavant.client.view.list.ListView.java

private void updateShowCard() {
    showCard.removeAll();//from w  w w  .  j ava  2s  .c o m

    showCard.setLayout(new BorderLayout());

    String[] columnNames = detailedModel.getColumnNames();
    Class[] columnClasses = detailedModel.getColumnClasses();
    int[] columnVisibility = detailedModel.getHiddenColumns();

    int firstVisibleColumn = 0;
    while (columnVisibility.length > 0 && firstVisibleColumn == columnVisibility[firstVisibleColumn]) {
        firstVisibleColumn++;
    }

    Set<NiceListItem> selectedItems;
    if (list != null) {
        selectedItems = new HashSet<NiceListItem>(list.getSelectedItems());
    } else {
        selectedItems = new HashSet<NiceListItem>(); // empty set, for simplicity of not having to null check later on
    }

    list = new NiceList();
    if (listColorScheme != null) {
        list.setColorScheme(listColorScheme);
    }
    list.startTransaction();

    List<Integer> selectedIndicies = new ArrayList<Integer>();

    int counter = 0;
    for (Object[] row : data) {
        NiceListItem nli = new NiceListItem(row[firstVisibleColumn].toString(), row);
        list.addItem(nli);

        if (selectedItems.contains(nli)) {
            selectedIndicies.add(counter);
        }
        counter++;
    }

    /*
     int[] selectedIndiciesArray = new int[selectedIndicies.size()];
            
     System.out.println("Reselecting "  + selectedIndicies.size() + " items");
     for (int i = 0; i < selectedIndicies.size();i++) {
     System.out.println("Reselecting "  + list.getItem(selectedIndicies.get(i)).toString() + " at index " + selectedIndicies.get(i));
     selectedIndiciesArray[i] = selectedIndicies.get(i);
     }*/
    list.endTransaction();

    wp.setBackground(list.getColorScheme().getBackgroundColor());

    if (detailedView != null) {
        list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {

                if (!e.getValueIsAdjusting()) {
                    List<Object[]> selectedItems = getSelectedRows();
                    if (selectedItems.size() == 1) {
                        detailedView.setSelectedItem(selectedItems.get(0));
                    } else {
                        detailedView.setMultipleSelections(selectedItems);
                    }
                }
            }
        });

        list.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                if (SwingUtilities.isRightMouseButton(e)) {
                    JPopupMenu popup = detailedView.createPopup();
                    if (popup != null) {
                        popup.show(e.getComponent(), e.getX(), e.getY());
                    }
                }
            }
        });
    }

    if (selectedIndicies.isEmpty()) {
        list.selectItemAtIndex(0);
    } else {
        list.selectItemsAtIndicies(selectedIndicies);
    }

    JScrollPane jsp = ViewUtil.getClearBorderlessScrollPane(list);
    jsp.setHorizontalScrollBar(null);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new MigLayout("wrap, fillx"));

    topPanel.add(ViewUtil.getEmphasizedLabel(pageName.toUpperCase()));
    topPanel.setBackground(list.getColorScheme().getBackgroundColor());

    if (searchBarEnabled) {
        topPanel.add(list.getSearchBar(), "growx 1.0");
    }
    showCard.add(topPanel, BorderLayout.NORTH);

    showCard.add(jsp, BorderLayout.CENTER);

    showCard.add(controlBar.getComponent(), BorderLayout.SOUTH);

}

From source file:org.ut.biolab.medsavant.client.view.list.MasterView.java

private void updateShowCard() {
    showCard.removeAll();//  www.  j  ava2s. c o  m

    showCard.setLayout(new BorderLayout());
    showCard.setBackground(ViewUtil.getTertiaryMenuColor());
    showCard.setBorder(ViewUtil.getBigBorder());

    String[] columnNames = detailedModel.getColumnNames();
    Class[] columnClasses = detailedModel.getColumnClasses();
    int[] columnVisibility = detailedModel.getHiddenColumns();

    stp = new ListViewTablePanel(data, columnNames, columnClasses, columnVisibility) {
        @Override
        public void forceRefreshData() {
            refreshList();
        }
    };

    selectionGrabber = new RowSelectionGrabber(stp.getTable(), data);

    if (detailedView != null) {
        stp.getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {

                if (!e.getValueIsAdjusting()) {
                    List<Object[]> selectedItems = selectionGrabber.getSelectedItems();
                    if (selectedItems.size() == 1) {
                        detailedView.setSelectedItem(selectedItems.get(0));
                    } else {
                        detailedView.setMultipleSelections(selectedItems);
                    }
                }
            }
        });

        stp.getTable().addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                if (SwingUtilities.isRightMouseButton(e)) {
                    JPopupMenu popup = detailedView.createPopup();
                    if (popup != null) {
                        popup.show(e.getComponent(), e.getX(), e.getY());
                    }
                }
            }
        });
    }

    stp.getTable().getSelectionModel().setSelectionInterval(0, 0);

    showCard.add(stp, BorderLayout.CENTER);

    showCard.add(buttonPanel, BorderLayout.SOUTH);

}

From source file:org.zaproxy.zap.extension.ascan.PolicyManagerDialog.java

private JTable getParamsTable() {
    if (paramsTable == null) {
        paramsTable = new JTable();
        paramsTable.setModel(getParamsModel());
        paramsTable.addMouseListener(new MouseListener() {
            @Override/*www.j  a  v  a  2s. co  m*/
            public void mouseClicked(MouseEvent e) {
            }

            @Override
            public void mousePressed(MouseEvent e) {
                if (e.getClickCount() >= 2) {
                    int row = paramsTable.rowAtPoint(e.getPoint());
                    if (row >= 0) {
                        String name = (String) getParamsModel().getValueAt(row, 0);
                        if (name != null) {
                            try {
                                extension.showPolicyDialog(PolicyManagerDialog.this, name);
                            } catch (ConfigurationException e1) {
                                logger.error(e1.getMessage(), e1);
                            }
                        }
                    }
                }
            }

            @Override
            public void mouseReleased(MouseEvent e) {
            }

            @Override
            public void mouseEntered(MouseEvent e) {
            }

            @Override
            public void mouseExited(MouseEvent e) {
            }
        });
        paramsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (getParamsTable().getSelectedRowCount() == 0) {
                    getModifyButton().setEnabled(false);
                    getRemoveButton().setEnabled(false);
                    getExportButton().setEnabled(false);
                } else if (getParamsTable().getSelectedRowCount() == 1) {
                    getModifyButton().setEnabled(true);
                    // Dont let the last policy be removed
                    getRemoveButton().setEnabled(getParamsModel().getRowCount() > 1);
                    getExportButton().setEnabled(true);
                } else {
                    getModifyButton().setEnabled(false);
                    getRemoveButton().setEnabled(false);
                    getExportButton().setEnabled(false);
                }
            }
        });
    }
    return paramsTable;
}

From source file:org.zaproxy.zap.extension.zest.dialogs.ZestRequestDialog.java

private JTable getCookiesTable() {
    if (cookiesTable == null) {
        cookiesTable = new JTable();
        cookiesTable.setModel(getCookieModel());
        cookiesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override/*from   w w w  .j  av  a2  s.  c o m*/
            public void valueChanged(ListSelectionEvent e) {
                if (getCookiesTable().getSelectedRowCount() == 0) {
                    modifyButton.setEnabled(false);
                    removeButton.setEnabled(false);
                } else if (getCookiesTable().getSelectedRowCount() == 1) {
                    modifyButton.setEnabled(true);
                    removeButton.setEnabled(true);
                } else {
                    modifyButton.setEnabled(false);
                    // TODO allow multiple deletions?
                    removeButton.setEnabled(false);
                }
            }
        });
    }
    return cookiesTable;
}

From source file:Panels.LocationPanel.java

public LocationPanel() throws IOException, ParserConfigurationException, SAXException {//create LocationPanel object and set parameters

    this.locationfromInternetIcon = new ImageIcon(getClass().getResource(locationInternetIconSetting));//location from internet label icon
    this.loaderIcon = new ImageIcon(getClass().getResource(loaderSettingsPath));
    this.setLayout(null);
    this.setVisible(true);
    this.setSize(400, 340);
    this.color = Color.WHITE;
    this.setOpaque(false);

    this.locationFromInternet = new JLabel();
    this.countriesLabel = new JLabel(PropertiesHandler.getSingleton().getValue(1049));
    this.citiesLabel = new JLabel(PropertiesHandler.getSingleton().getValue(1050));
    this.longitudeLabel = new JLabel(PropertiesHandler.getSingleton().getValue(1051));
    this.latitudeLabel = new JLabel(PropertiesHandler.getSingleton().getValue(1052));
    this.timezoneLabel = new JLabel(PropertiesHandler.getSingleton().getValue(1053));
    this.longitudeValue = new JLabel();
    this.latitudeValue = new JLabel();
    this.timezoneValue = new JLabel();
    this.getLocationFromInternet = new JLabel(PropertiesHandler.getSingleton().getValue(1105));
    this.getLocationFromInternet.setFont(new Font("TimesRoman", Font.ROMAN_BASELINE, 13));
    this.applyButton = new JButton(PropertiesHandler.getSingleton().getValue(1054));
    this.applyButton.setEnabled(false);
    this.applyButton.addActionListener(new ActionListener() {

        @Override// www  .  j  a v  a2s  .c  om
        public void actionPerformed(ActionEvent e) {//Applay button click handler
            try {
                applyButtonListener(e);
            } catch (Exception e1) {
                try {
                    JOptionPane.showMessageDialog(null, PropertiesHandler.getSingleton().getValue(1070),
                            PropertiesHandler.getSingleton().getValue(1069), JOptionPane.ERROR_MESSAGE);
                } catch (Exception e2) {
                }
            }
        }
    });

    if (UserConfig.getSingleton().getLanguage().equalsIgnoreCase(ar)) {
        this.getLocationFromInternet.setBounds(50, 20, 280, 20);
        this.locationFromInternet.setBounds(10, 10, 30, 30);
    } else if (UserConfig.getSingleton().getLanguage().equalsIgnoreCase(eng)) {
        this.getLocationFromInternet.setBounds(10, 20, 280, 20);
        this.locationFromInternet.setBounds(280, 10, 30, 30);
    } else {
        this.getLocationFromInternet.setBounds(10, 20, 280, 20);
        this.locationFromInternet.setBounds(250, 10, 30, 30);
    }

    this.locationFromInternet.setIcon(locationfromInternetIcon);
    this.locationFromInternet.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(final MouseEvent e) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    if (locationFromInternet.isEnabled()) {
                        locationFromInternet.setEnabled(false);
                        locationFromInternet.setIcon(loaderIcon);
                        locationFromInternetLabelMouseClicked(e);
                    }
                }
            }).start();
        }
    });

    this.countriesLabel.setForeground(color);
    this.citiesLabel.setForeground(color);
    this.longitudeLabel.setForeground(color);
    this.latitudeLabel.setForeground(color);
    this.timezoneLabel.setForeground(color);
    this.longitudeValue.setForeground(color);
    this.latitudeValue.setForeground(color);
    this.timezoneValue.setForeground(color);
    this.getLocationFromInternet.setForeground(color);

    this.countriesLabel.setBounds(5, 50, 100, 25);
    this.citiesLabel.setBounds(195, 50, 100, 25);

    this.longitudeLabel.setBounds(10, 240, 120, 30);
    this.latitudeLabel.setBounds(140, 240, 120, 30);
    this.timezoneLabel.setBounds(260, 240, 120, 30);
    this.longitudeValue.setBounds(20, 265, 120, 30);
    this.latitudeValue.setBounds(150, 265, 120, 30);
    this.timezoneValue.setBounds(270, 265, 60, 30);
    this.applyButton.setBounds(125, 300, 150, 30);

    this.countriesModel = new DefaultListModel();
    this.citiesModel = new DefaultListModel();

    this.countriesList = new JList();
    this.countriesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    this.countriesList.setSelectedIndex(0);

    this.countriesList.setSelectionBackground(Color.GRAY);
    this.countriesList.setSelectionForeground(Color.WHITE);

    this.citiesList = new JList();
    this.citiesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    this.citiesList.setSelectedIndex(0);

    this.citiesList.setSelectionBackground(Color.GRAY);
    this.citiesList.setSelectionForeground(Color.WHITE);

    this.countriesList.setModel(countriesModel);
    this.citiesList.setModel(citiesModel);

    this.arrayCountries = new ArrayList<Country>();
    this.arrayCountries = XmlHandler.getSingleton().getAllCountries();//get all countries names from country xml file 
    this.arrayCities = new ArrayList<City>();
    this.arrayCities = XmlHandler.getSingleton().getAllCities(arrayCountries.get(0).getName());//get all cities for first country from xml file

    for (Country country : arrayCountries) {
        countriesModel.addElement(country.getName());//set all countries names to countries model
    }

    this.countriesList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!country.equalsIgnoreCase("") && countriesList.getSelectedIndex() == 0) {

            } else {
                citiesModel.clear();
                try {
                    arrayCities2 = XmlHandler.getSingleton()
                            .getAllCities((String) countriesList.getSelectedValue());
                } catch (Exception e1) {
                    try {
                        JOptionPane.showMessageDialog(null, PropertiesHandler.getSingleton().getValue(1070),
                                PropertiesHandler.getSingleton().getValue(1069), JOptionPane.ERROR_MESSAGE);
                    } catch (Exception e2) {
                    }
                }
                for (City city : arrayCities2) {
                    citiesModel.addElement(city.getName());//set all cities names to cities model for selected country
                }
            }
        }
    });

    for (City city : arrayCities) {
        citiesModel.addElement(city.getName());//set all cities names to cities model
    }

    this.citiesList.addListSelectionListener(new ListSelectionListener() {//set longitude , latitude and time zone from selected city

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!city.equalsIgnoreCase("") && citiesList.getSelectedIndex() == 0) {
            } else {
                applyButton.setEnabled(true);
                if (arrayCities2 != null && arrayCities2.size() >= 1) {
                    if (citiesList != null && citiesList.getSelectedIndex() >= 0) {
                        City city = arrayCities2.get(citiesList.getSelectedIndex());
                        longitudeValue.setText(String.valueOf(Double.valueOf(city.getLongitude()) / 10000));
                        latitudeValue.setText(String.valueOf(Double.valueOf(city.getLatitude()) / 10000));
                        timezoneValue.setText(String.valueOf(Double.valueOf(city.getTimezone()) / 100));
                    }
                }
            }
        }
    });

    //set longitude , latitude and time zone values to labels from selected city
    this.longitudeValue.setText(String.valueOf(Double.valueOf(arrayCities.get(0).getLongitude()) / 10000));
    this.latitudeValue.setText(String.valueOf(Double.valueOf(arrayCities.get(0).getLatitude()) / 10000));
    this.timezoneValue.setText(String.valueOf(Double.valueOf(arrayCities.get(0).getTimezone()) / 100));

    this.countriesListScrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    this.countriesListScrollPane.setViewportView(countriesList);
    this.countriesListScrollPane.setBounds(5, 80, 180, 150);

    this.citiesListScrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    this.citiesListScrollPane.setViewportView(citiesList);
    this.citiesListScrollPane.setBounds(195, 80, 180, 150);

    this.add(countriesLabel);
    this.add(citiesLabel);
    this.add(countriesListScrollPane);
    this.add(citiesListScrollPane);
    this.add(longitudeLabel);
    this.add(longitudeValue);
    this.add(latitudeLabel);
    this.add(latitudeValue);
    this.add(timezoneLabel);
    this.add(timezoneValue);
    this.add(applyButton);
    this.add(locationFromInternet);
    this.add(getLocationFromInternet);

    this.setVisible(true);
}

From source file:pcgen.gui2.converter.panel.CampaignPanel.java

/**
 * @see pcgen.gui2.converter.panel.ConvertSubPanel#setupDisplay(javax.swing.JPanel, pcgen.cdom.base.CDOMObject)
 *///  w  ww .  j a  v a  2s.  c  o  m
@Override
public void setupDisplay(JPanel panel, final CDOMObject pc) {
    panel.setLayout(new GridBagLayout());
    JLabel introLabel = new JLabel("Please select the Campaign(s) to Convert:");
    GridBagConstraints gbc = new GridBagConstraints();
    Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0,
            GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
    gbc.insets = new Insets(25, 25, 5, 25);
    panel.add(introLabel, gbc);

    final CampaignTableModel model = new CampaignTableModel(gameModeCampaigns, folderName);
    final JTable table = new JTable(model) {
        //Implement table cell tool tips.
        @Override
        public String getToolTipText(MouseEvent e) {
            java.awt.Point p = e.getPoint();
            int rowIndex = rowAtPoint(p);
            int colIndex = columnAtPoint(p);
            String tip = String.valueOf(getValueAt(rowIndex, colIndex));
            return tip;
        }
    };
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent event) {
            pc.removeListFor(ListKey.CAMPAIGN);
            int[] selRows = table.getSelectedRows();
            if (selRows.length == 0) {
                saveSourceSelection(pc);
                fireProgressEvent(ProgressEvent.NOT_ALLOWED);
            } else {
                for (int row : selRows) {
                    Campaign selCampaign = (Campaign) model.getValueAt(row, 0);
                    pc.addToListFor(ListKey.CAMPAIGN, selCampaign);
                }
                saveSourceSelection(pc);
                fireProgressEvent(ProgressEvent.ALLOWED);
            }
        }
    });

    JScrollPane listScroller = new JScrollPane(table);
    Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.0, 1.0);
    gbc.fill = GridBagConstraints.BOTH;
    panel.add(listScroller, gbc);

    initSourceSelection(model, table);
}

From source file:pl.otros.logview.filter.ThreadFilter.java

public ThreadFilter() {
    super(NAME, DESCRIPTION);
    selectedThread = new HashSet<String>();
    listModel = new DefaultListModel();
    jList = new JList(listModel);
    jList.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    jList.addListSelectionListener(new ListSelectionListener() {
        @Override/*  w  w  w  .j a  v  a 2 s  .c  o m*/
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                selectedThread.clear();
                Object[] selectedValues = jList.getSelectedValues();
                for (Object selectedValue : selectedValues) {
                    selectedThread.add((String) selectedValue);
                }
                listener.valueChanged();
            }
        }
    });
    JLabel jLabel = new JLabel("Threads:");
    jLabel.setLabelFor(jList);
    jLabel.setDisplayedMnemonic('t');
    panel = new JPanel(new MigLayout());
    panel.add(jLabel, "wrap");
    panel.add(new JScrollPane(jList), "wrap, right, growx");
    panel.add(new JLabel("Use CTRL for multi selection"), "wrap");
    panel.add(new JXHyperlink(new AbstractAction("Invert selection") {
        @Override
        public void actionPerformed(ActionEvent e) {
            invertSelection();
        }
    }), "wrap");
    panel.add(new JXHyperlink(new AbstractAction("Clear selection") {
        @Override
        public void actionPerformed(ActionEvent e) {
            clearSelection();
        }
    }), "wrap");
    panel.add(new JXHyperlink(new AbstractAction("Reload threads") {
        @Override
        public void actionPerformed(ActionEvent e) {
            reloadThreads();
        }
    }), "wrap");
}