package jfconfig; /** * Created : Mar 18, 2012 * * @author pquiring */ import javax.swing.*; public class AsteriskPanel extends javax.swing.JPanel { /** * Creates new form AsteriskPanel */ public AsteriskPanel() { initComponents(); } /** * 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() { jToolBar1 = new javax.swing.JToolBar(); back = new javax.swing.JButton(); add = new javax.swing.JButton(); edit = new javax.swing.JButton(); del = new javax.swing.JButton(); reload = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); cats = new javax.swing.JList(); jScrollPane2 = new javax.swing.JScrollPane(); values = new javax.swing.JList(); jToolBar1.setFloatable(false); jToolBar1.setRollover(true); back.setText("<Back"); back.setFocusable(false); back.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); back.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar1.add(back); add.setText("Add Entry"); add.setFocusable(false); add.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); add.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar1.add(add); edit.setText("Edit Entry"); edit.setFocusable(false); edit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); edit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar1.add(edit); del.setText("Del Entry"); del.setFocusable(false); del.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); del.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar1.add(del); reload.setText("Reload Config"); reload.setFocusable(false); reload.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); reload.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jToolBar1.add(reload); cats.setModel(new javax.swing.AbstractListModel() { String[] strings = { "Extensions", "Trunks" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); cats.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); cats.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { catsValueChanged(evt); } }); jScrollPane1.setViewportView(cats); values.setModel(model); values.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); jScrollPane2.setViewportView(values); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 624, Short.MAX_VALUE) .addComponent(jScrollPane2))) ); }// </editor-fold>//GEN-END:initComponents private void catsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_catsValueChanged int idx = cats.getSelectedIndex(); if (idx == -1) return; loadCategory(idx); }//GEN-LAST:event_catsValueChanged // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton add; private javax.swing.JButton back; private javax.swing.JList cats; private javax.swing.JButton del; private javax.swing.JButton edit; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JToolBar jToolBar1; private javax.swing.JButton reload; private javax.swing.JList values; // End of variables declaration//GEN-END:variables private DefaultListModel model = new DefaultListModel(); public static class Ext { public String number; public String cid; //external caller id public String pass; } public static class Trunk { public String ip; } public static class Route { public String did; public String cid; public String dest; } public static class Config { public Ext ext[]; public Trunk trunk[]; public Route inRoutes[]; } private void loadCategory(int idx) { switch (idx) { case 0: //Extensions case 1: //Trunks } } private void apply() { //save config to /etc/asterisk/* } }