/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package jrex.ui; import java.util.Collection; import java.util.List; import jrex.ui.model.SimpleListModel; /** * * @author mark */ public class ColumnSelectionPanel extends javax.swing.JPanel { private final SimpleListModel modelLeft = new SimpleListModel(); private final SimpleListModel modelRight = new SimpleListModel(); /** * Creates new form ColumnSelectionPanel */ public ColumnSelectionPanel() { initComponents(); lstLeft.setModel(modelLeft); lstRight.setModel(modelRight); } public ColumnSelectionPanel(String rightLabel, Collection<Object> right) { this(); modelRight.addAll(right); } public void setLeftContent(String leftLabel, Collection<Object> left) { lblLeft.setText(leftLabel); modelLeft.addAll(left); } public void setRightContent(String rightLabel, Collection<Object> right) { lblRight.setText(rightLabel); modelRight.addAll(right); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { scrollLeft = new javax.swing.JScrollPane(); lstLeft = new javax.swing.JList<>(); lblLeft = new javax.swing.JLabel(); scrollRight = new javax.swing.JScrollPane(); lstRight = new javax.swing.JList<>(); btnMoveRight = new javax.swing.JButton(); btnMoveLeft = new javax.swing.JButton(); lblRight = new javax.swing.JLabel(); btnMoveAllRight = new javax.swing.JButton(); scrollLeft.setViewportView(lstLeft); lblLeft.setText("left heading"); scrollRight.setViewportView(lstRight); btnMoveRight.setText(">"); btnMoveRight.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnMoveRightActionPerformed(evt); } }); btnMoveLeft.setText("<"); btnMoveLeft.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnMoveLeftActionPerformed(evt); } }); lblRight.setText("right heading"); btnMoveAllRight.setText(">>"); btnMoveAllRight.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnMoveAllRightActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lblLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(scrollLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnMoveRight, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnMoveLeft, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnMoveAllRight, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lblRight, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(scrollRight, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnMoveAllRight, btnMoveLeft, btnMoveRight}); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {lblLeft, lblRight}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblLeft) .addComponent(lblRight)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(scrollLeft) .addGroup(layout.createSequentialGroup() .addComponent(btnMoveRight) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnMoveAllRight) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnMoveLeft)) .addComponent(scrollRight, javax.swing.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)) .addContainerGap()) ); }// </editor-fold>//GEN-END:initComponents private void btnMoveRightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMoveRightActionPerformed if (lstLeft.isSelectionEmpty()) { return; } List selectedValuesList = lstLeft.getSelectedValuesList(); for (Object selected : selectedValuesList) { modelRight.addElement(selected); modelLeft.removeElement(selected); } }//GEN-LAST:event_btnMoveRightActionPerformed private void btnMoveLeftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMoveLeftActionPerformed if (lstRight.isSelectionEmpty()) { return; } List selectedValuesList = lstRight.getSelectedValuesList(); for (Object selected : selectedValuesList) { modelLeft.addElement(selected); modelRight.removeElement(selected); } }//GEN-LAST:event_btnMoveLeftActionPerformed private void btnMoveAllRightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMoveAllRightActionPerformed for (Object selected : modelLeft.getAll()) { modelRight.addElement(selected); } modelLeft.clear(); }//GEN-LAST:event_btnMoveAllRightActionPerformed public Collection<Object> getLeftItems() { return modelLeft.getAll(); } public Collection<Object> getRightItems() { return modelRight.getAll(); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnMoveAllRight; private javax.swing.JButton btnMoveLeft; private javax.swing.JButton btnMoveRight; private javax.swing.JLabel lblLeft; private javax.swing.JLabel lblRight; private javax.swing.JList<String> lstLeft; private javax.swing.JList<String> lstRight; private javax.swing.JScrollPane scrollLeft; private javax.swing.JScrollPane scrollRight; // End of variables declaration//GEN-END:variables }