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:burlov.ultracipher.swing.MainPanel.java

public MainPanel(Translator translator) {
    editDataPanel = new EditDataPanel(translator);
    translator.addToComponent(searchField);
    listPopup.add(getNewEntryAction());//from   ww w .j  a va 2  s  .  c  om
    listPopup.add(getDeleteEntryAction());

    setLayout(new BorderLayout());
    add(splitPane);

    /*
       * Suchpanel initialisieren
     */
    JPanel panel = new JPanel(new BorderLayout());
    JPanel searchPanel = new JPanel(new BorderLayout());
    searchPanel.add(new JLabel(new ImageIcon(getClass().getResource("find.png"))), BorderLayout.WEST);
    searchPanel.add(searchField, BorderLayout.CENTER);
    searchField.setToolTipText("Search");
    panel.add(searchPanel, BorderLayout.NORTH);
    panel.add(new JScrollPane(searchResults), BorderLayout.CENTER);
    splitPane.setLeftComponent(panel);

    /*
       * Anzeigepanel initialisieren
     */
    panel = new JPanel(new BorderLayout());
    panel.add(editDataPanel, BorderLayout.CENTER);
    panel.add(new PassGeneratorPanel(), BorderLayout.SOUTH);
    splitPane.setRightComponent(panel);

    searchResults.addMouseListener(new MouseAdapter() {

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

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

        private void showDeletePopup(MouseEvent e) {
            if (!e.isPopupTrigger()) {
                return;
            }
            int index = searchResults.locationToIndex(e.getPoint());
            if (index > -1) {
                searchResults.setSelectedIndex(index);
            }
            listPopup.show(e.getComponent(), e.getX(), e.getY());
        }
    });
    searchResults.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            editDataPanel.editData((DataEntry) searchResults.getSelectedValue(), false);
        }
    });
    searchField.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            initResultList();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            initResultList();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            initResultList();
        }
    });

    editDataPanel.addNameChangeListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            int index = searchResultModel.indexOf(editDataPanel.getData());
            if (index >= 0) {
                searchResultModel.set(index, editDataPanel.getData());
            }
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            int index = searchResultModel.indexOf(editDataPanel.getData());
            if (index >= 0) {
                searchResultModel.set(index, editDataPanel.getData());
            }
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            int index = searchResultModel.indexOf(editDataPanel.getData());
            if (index >= 0) {
                searchResultModel.set(index, editDataPanel.getData());
            }
        }
    });
    searchField.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                showTextPopup(e);
            } else {
                //               searchField.selectAll();
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            showTextPopup(e);
        }
    });
    //      searchField.addFocusListener(new FocusListener() {
    //         @Override
    //         public void focusLost(FocusEvent e) {
    //            System.out.println("MainPanel.MainPanel().new FocusListener() {...}.focusLost()");
    //         }
    //         
    //         @Override
    //         public void focusGained(FocusEvent e) {
    //            System.out.println("MainPanel.MainPanel().new FocusListener() {...}.focusGained()");
    //            //searchField.selectAll();
    //         }
    //      });
}

From source file:au.org.ala.delta.editor.ui.ImageDetailsPanel.java

private void addEventHandlers() {

    btnDisplay.setAction(_actions.get("displayImage"));
    btnAdd.setAction(_actions.get("addImage"));
    btnDelete.setAction(_actions.get("deleteImage"));
    btnSettings.setAction(_actions.get("displayImageSettings"));
    imageList.addListSelectionListener(new ListSelectionListener() {

        @Override/*from w w w.  ja  v a2s.  c o m*/
        public void valueChanged(ListSelectionEvent e) {
            _selectedImage = (Image) imageList.getSelectedValue();
            _dataSet.setSelectedImage(_selectedImage);
            updateDisplay();
        }
    });
    imageList.setSelectionAction(_actions.get("displayImage"));
    imageList.setDragEnabled(true);
    imageList.setDropMode(DropMode.INSERT);
    imageList.setTransferHandler(new ImageTransferHandler());

    playSoundButton.setAction(_actions.get("playSound"));
    deleteSoundButton.setAction(_actions.get("deleteSound"));
    insertSoundButton.setAction(_actions.get("addSound"));
    FocusAdapter focusAdaptor = new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            if (e.getComponent() == subjectTextPane) {
                updateSubjectText();
            } else if (e.getComponent() == developerNotesTextPane) {
                updateDeveloperNotes();
            }
        }

    };
    soundComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateSoundActions();
        }
    });
    subjectTextPane.addFocusListener(focusAdaptor);
    developerNotesTextPane.addFocusListener(focusAdaptor);
}

From source file:it.unibas.spicygui.vista.BestMappingsTopComponent.java

private void addSelectionListener() {
    tabellaBestMappings.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            showAction.actionPerformedWithScenario(scenario);
        }/*from   ww w.  ja v a 2s .c o m*/
    });
}

From source file:gui.AdministracionGrupos.java

/**
     * Creates new form AdministracionGrupos
     *//*from   www.  j a va 2 s  . c  o m*/
    public AdministracionGrupos(Desktop aparent) {
        //         super(aparent, true);
        this.parent = aparent;
        initComponents();
        setLocationRelativeTo(null);

        //        setClosable(true);
        //        this.pack();
        //        this.setFrameIcon(new ImageIcon(this.getClass().getResource("/resources/logo tru-test.png")));
        cargarPuertos();

        cargarStick();

        corralSelector.valor_nuevo = true;
        razaSelector.valor_nuevo = true;

        Frame F = JOptionPane.getFrameForComponent(this);
        reporteEntradas = new ReporteEntradas(F);

        String titulos[] = { "Id Animal", "Arete Visual", "Arete Electronico", "Proveedor", "Fecha de Compra",
                "Arete Siniiga", "Arete Campaa", "Sexo", "Ingreso al Corral", "Numero de Lote", "No. Compra",
                "Peso Actual", "Peso de Compra" };

        t_animales.setTitulos(titulos);
        t_animales.cambiarTitulos();

        t_animales.setFormato(new int[] { Table.letra, Table.letra, Table.letra, Table.letra, Table.fecha,
                Table.letra, Table.letra, Table.letra, Table.fecha, Table.numero_double, Table.letra,
                Table.numero_double, Table.numero_double });

        t_animales.ocultarcolumna(0);

        corralActivo = true;

        //   graficar();
        ListSelectionModel lsm = this.t_animales.getSelectionModel();

        lsm.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                selectAnimal();
            }
        });

        t_pesos = new Table();

        t_pesos.setModel(
                new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "Title 1", "Title 2" }));

        String titulos2[] = { "Fecha", "Peso (kg)" };

        t_pesos.setTitulos(titulos2);
        t_pesos.cambiarTitulos();
        t_pesos.setFormato(new int[] { 3, 1 });

        g = new Grafica();

        Grafica = g.createChart(g.createDatasetPesos(t_pesos));

        jPanel1 = new ChartPanel(Grafica);

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 216, Short.MAX_VALUE));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 186, Short.MAX_VALUE));

        panelGrafica.add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, panelGrafica.getWidth(),
                panelGrafica.getHeight()));

        cargarDatosIniciales();

        graficar();

        //        Image i = null;
        //        i = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/resources/logo tru-test.png"));
        //        setIconImage(i);
        this.t_alimentoIngresado.textFieldDouble();
        this.t_pesoMaximo.textFieldDouble();
        this.t_pesoMinimo.textFieldDouble();
        this.t_pesoPromedio.textFieldDouble();
        this.t_totalKilos.textFieldDouble();

        this.setTitle(this.getTitle() + " " + rancho.descripcion);

        cargarComponentes();

    }

From source file:fr.free.hd.servers.gui.PhonemView.java

@Override
protected JComponent createControl() {
    final JPanel view = new JPanel(new BorderLayout());

    Collection<Phonem> phonesList = phonemsDAO.getPhonems();
    Map<String, Phonem> mapList = new HashMap<String, Phonem>();
    for (Phonem phonem : phonesList) {
        mapList.put(phonem.getPhonem(), phonem);
    }//from ww  w . j a va  2  s.c  o m

    final StatementListModel model = new StatementListModel(mapList);

    printCommand.setModel(model);
    printCommand.setFace(face);
    copyCommand.setModel(model);
    copyCommand.setFace(face);

    list = new JList(model);
    final JScrollPane sp = new JScrollPane(list);
    final JTextField field = new JTextField();
    field.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void changedUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            model.setString(field.getText());
        }

    });

    final PhonemListModel phonemModel = new PhonemListModel((List<Phonem>) phonesList);
    final JList phonemList = new JList(phonemModel);
    final JScrollPane spPhonemList = new JScrollPane(phonemList);
    phonemList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        // private int oldIndex = -1;
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting() == false) {
                Phonem innerPhonem = (Phonem) phonemModel.getElementAt(phonemList.getSelectedIndex());
                field.setText(field.getText() + innerPhonem.getPhonem());
            }
        }
    });
    phonemList.setCellRenderer(new PhonemListRenderer());
    list.setCellRenderer(new StatementPhonemListRenderer(face));
    list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    list.setVisibleRowCount(1);

    view.add(spPhonemList, BorderLayout.WEST);
    view.add(sp, BorderLayout.CENTER);
    view.add(field, BorderLayout.SOUTH);

    field.requestFocus();

    return view;
}

From source file:edu.ku.brc.af.tasks.subpane.formeditor.RowColDefPanel.java

protected void createUI(final int numInUse, @SuppressWarnings("hiding") final boolean isRow) {
    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("max(125px;p):g,16px,p", "p,2px,p,2px,p:g")); //$NON-NLS-1$ //$NON-NLS-2$

    propsPanel = new DefItemPropPanel(numInUse, isRow);

    ActionListener addAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            addItem();/*from   ww w .ja v  a  2 s  .c o  m*/
        }
    };

    ActionListener delAL = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            delItem();
        }
    };

    controlPanel = new EditDeleteAddPanel(null, delAL, addAL);
    controlPanel.getAddBtn().setEnabled(true);

    itemList = new JList(new DefaultListModel());
    itemList.setCellRenderer(new DefItemRenderer(IconManager.IconSize.Std16));
    JScrollPane sp = UIHelper.createScrollPane(itemList);
    pb.addSeparator((isRow ? "Row" : "Column") + " Items", cc.xy(1, 1)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    pb.add(sp, cc.xy(1, 3));
    pb.add(controlPanel, cc.xy(1, 5));

    pb.addSeparator("Properties", cc.xy(3, 1)); //$NON-NLS-1$
    pb.add(propsPanel, cc.xywh(3, 3, 1, 3));

    itemList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                itemSelected();
            }
        }
    });

    add(pb.getPanel(), BorderLayout.CENTER);
}

From source file:it.unibas.spicygui.vista.RankedTransformationsTopComponent.java

private void addSelectionListener() {
    tabellaRankedTransformations.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            showTransformationAction.actionPerformedWithScenario(scenario);
        }/*from w w  w. j  ava2  s  . c  o m*/
    });
}

From source file:hermes.browser.dialog.GeneralRendererConfigPanel.java

private void init() {
    Border border = BorderFactory.createBevelBorder(BevelBorder.RAISED);
    JPanel topPanel = new JPanel();

    topPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    topPanel.setLayout(new GridLayout(1, 2));

    infoLabel1.setText("Message Renderers");

    setLayout(new BorderLayout());
    setBorder(BorderFactory.createTitledBorder(border, "Renderers"));

    topPanel.add(infoLabel1);/*from   w  w  w .j ava2s .  c  o  m*/
    topSP.setViewportView(classTable);

    classTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);

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

    splitPane.add(topSP, "top");
    splitPane.add(bottomSP, "bottom");
    splitPane.setDividerLocation(200);

    // splitPane.setShowGripper(true) ;

    classTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            doRendererSelected(e);
        }
    });

}

From source file:org.vimarsha.ui.DataLoaderForm.java

public DataLoaderForm() {

    for (String str : UIHandler.getInstance().getArchitectureList()) {
        architectureComboBox.addItem(str);
        architectureComboBox.setSelectedItem(null);
    }//from   w  w  w .java  2  s . c o  m

    architectureComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            UIHandler.getInstance().setArchitecture((String) architectureComboBox.getSelectedItem());
            trainingModelTextBox.setText(UIHandler.getInstance().getTrainingModel());
        }
    });
    openRAWFileButton.addActionListener(new ActionListener() {
        File file = null;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JFileChooser fc = new JFileChooser(".");
            int returnVal = fc.showOpenDialog(Tab0);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
            }
            if ((UIHandler.getInstance().setRawFile(file) == 100)
                    && (UIHandler.getInstance().convertRawToArff() == 100)) {
                saveToARFFFileButton.setEnabled(true);
                attributeList.setListData(UIHandler.getInstance().getArffAttribiutesTableModel().toArray());
                testDataTextField.setText(UIHandler.getInstance().getTestDataName());
            }

        }
    });
    openARFFFileButton.addActionListener(new ActionListener() {
        File file = null;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JFileChooser fc = new JFileChooser(".");
            int returnVal = fc.showOpenDialog(Tab0);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                file = fc.getSelectedFile();
                UIHandler.getInstance().setArffFile(file);
                attributeList.setListData(UIHandler.getInstance().getArffAttribiutesTableModel().toArray());
                saveToARFFFileButton.setEnabled(true);
                testDataTextField.setText(UIHandler.getInstance().getTestDataName());
            }

        }
    });
    saveToARFFFileButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            File file = null;
            JFileChooser fc = new JFileChooser(".");
            int returnVal = fc.showSaveDialog(Tab0);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                System.out.println(fc.getSelectedFile());
                UIHandler.getInstance().saveAsArff(fc.getSelectedFile());
            }

        }
    });

    attributeList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            int selectedEvent = attributeList.getSelectedIndex();
            attributesSummaryTable
                    .setModel(UIHandler.getInstance().getArffAttributeInfo(attributeList.getSelectedIndex()));
            DefaultCategoryDataset data = UIHandler.getInstance().getBarChartDataSet(selectedEvent);
            drawBarChart(data);
        }
    });
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.SimilarCasesFrame.java

/**
 * Constructor./*from w w  w .jav  a 2s.co  m*/
 */
SimilarCasesFrame(final Instances ds, final int dateIdx, final StationsDataProvider gcp, String attrname,
        final int gapsize, final int position, final double x, final double y, final int year,
        final String season, final boolean isDuringRising) throws Exception {
    LogoHelper.setLogo(this);
    this.setTitle("KnowledgeDB: Suggested configurations / similar cases");

    this.inputCaseTablePanel = new JXPanel();
    this.inputCaseTablePanel.setBorder(new TitledBorder("Present case"));
    this.inputCaseChartPanel = new JXPanel();
    this.inputCaseChartPanel.setBorder(new TitledBorder("Profile of the present case"));
    this.outputCasesTablePanel = new JXPanel();
    this.outputCasesTablePanel.setBorder(new TitledBorder("Suggested cases"));
    this.outputCasesChartPanel = new JXPanel();
    this.outputCasesChartPanel.setBorder(new TitledBorder("Profile of the selected suggested case"));

    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
    getContentPane().add(inputCaseTablePanel);
    getContentPane().add(inputCaseChartPanel);
    getContentPane().add(outputCasesTablePanel);
    getContentPane().add(outputCasesChartPanel);

    final Instances res = GapFillingKnowledgeDB.findSimilarCases(attrname, x, y, year, season, gapsize,
            position, isDuringRising, gcp.findDownstreamStation(attrname) != null,
            gcp.findUpstreamStation(attrname) != null,
            GapsUtil.measureHighMiddleLowInterval(ds, ds.attribute(attrname).index(), position - 1));

    final Instances inputCase = new Instances(res);
    while (inputCase.numInstances() > 1)
        inputCase.remove(1);
    final JXTable inputCaseTable = buidJXTable(inputCase);
    final JScrollPane inputScrollPane = new JScrollPane(inputCaseTable);
    //System.out.println(inputScrollPane.getPreferredSize());
    inputScrollPane.setPreferredSize(
            new Dimension(COMPONENT_WIDTH, (int) (50 + inputScrollPane.getPreferredSize().getHeight())));
    this.inputCaseTablePanel.add(inputScrollPane);

    final ChartPanel inputcp = GapsUIUtil.buildGapChartPanel(ds, dateIdx, ds.attribute(attrname), gapsize,
            position);
    inputcp.getChart().removeLegend();
    inputcp.setPreferredSize(CHART_DIMENSION);
    this.inputCaseChartPanel.add(inputcp);

    final Instances outputCases = new Instances(res);
    outputCases.remove(0);
    final JXTable outputCasesTable = buidJXTable(outputCases);
    final JScrollPane outputScrollPane = new JScrollPane(outputCasesTable);
    outputScrollPane.setPreferredSize(
            new Dimension(COMPONENT_WIDTH, (int) (50 + outputScrollPane.getPreferredSize().getHeight())));
    this.outputCasesTablePanel.add(outputScrollPane);

    outputCasesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    outputCasesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                final int modelRow = outputCasesTable.getSelectedRow();

                final String attrname = outputCasesTable.getModel().getValueAt(modelRow, 1).toString();
                final int gapsize = (int) Double
                        .valueOf(outputCasesTable.getModel().getValueAt(modelRow, 4).toString()).doubleValue();
                final int position = (int) Double
                        .valueOf(outputCasesTable.getModel().getValueAt(modelRow, 5).toString()).doubleValue();

                try {
                    final ChartPanel cp = GapsUIUtil.buildGapChartPanel(ds, dateIdx, ds.attribute(attrname),
                            gapsize, position);
                    cp.getChart().removeLegend();
                    cp.setPreferredSize(CHART_DIMENSION);
                    outputCasesChartPanel.removeAll();
                    outputCasesChartPanel.add(cp);
                    getContentPane().repaint();
                    pack();
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
    });

    outputCasesTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(final MouseEvent e) {
            final InstanceTableModel instanceTableModel = (InstanceTableModel) outputCasesTable.getModel();
            final int row = outputCasesTable.rowAtPoint(e.getPoint());
            final int modelRow = outputCasesTable.convertRowIndexToModel(row);

            final String attrname = instanceTableModel.getValueAt(modelRow, 1).toString();
            final int gapsize = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 4).toString())
                    .doubleValue();
            final int position = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 5).toString())
                    .doubleValue();

            if (e.isPopupTrigger()) {
                final JPopupMenu jPopupMenu = new JPopupMenu("feur");

                final JMenuItem mi = new JMenuItem("Use this configuration");
                mi.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(final ActionEvent e) {
                        System.out.println("not implemented!");
                    }
                });
                jPopupMenu.add(mi);
                jPopupMenu.show(outputCasesTable, e.getX(), e.getY());
            } else {
                // nothing?
            }
        }
    });

    setPreferredSize(new Dimension(FRAME_WIDTH, 900));

    pack();
    setVisible(true);

    /* select the first row */
    outputCasesTable.setRowSelectionInterval(0, 0);
}