/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /* * PGroupList.java * * Created on 10/10/2009, 3:42:48 AM */ package org.petah.spring.bai.gui; import org.petah.spring.bai.gui.model.GroupUnitListModel; import org.petah.spring.bai.gui.model.GroupListModel; import java.awt.event.MouseEvent; import javax.swing.SwingUtilities; import org.petah.spring.bai.ThreadManager; import org.petah.spring.bai.delegate.AIDelegate; import org.petah.spring.bai.group.UnitGroup; import org.petah.spring.bai.gui.model.GroupTaskListModel; /** * * @author Petah */ public class PGroupList extends javax.swing.JPanel { private AIDelegate aiDelegate; /** Creates new form PGroupList */ public PGroupList(AIDelegate aiDelegate) { this.aiDelegate = aiDelegate; initComponents(); } private void refresh() { SwingUtilities.invokeLater(new Runnable() { public void run() { lGroups.updateUI(); lUnits.updateUI(); lTasks.updateUI(); } }); } private void startAutoUpdate() { ThreadManager.run("PGroupList.startAutoUpdate()", new Runnable() { public void run() { try { while (cbAutoRefresh.isSelected()) { refresh(); Thread.sleep(1000); } } catch (InterruptedException ex) { } } }); } /** 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() { java.awt.GridBagConstraints gridBagConstraints; toolBar = new javax.swing.JToolBar(); cbAutoRefresh = new javax.swing.JCheckBox(); bRefresh = new javax.swing.JButton(); splitPane = new javax.swing.JSplitPane(); spGroupList = new javax.swing.JScrollPane(); lGroups = new javax.swing.JList(); jSplitPane1 = new javax.swing.JSplitPane(); spUnitList = new javax.swing.JScrollPane(); lUnits = new javax.swing.JList(); jScrollPane1 = new javax.swing.JScrollPane(); lTasks = new javax.swing.JList(); setLayout(new java.awt.GridBagLayout()); toolBar.setFloatable(false); toolBar.setRollover(true); cbAutoRefresh.setText("Auto Refresh"); cbAutoRefresh.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cbAutoRefreshActionPerformed(evt); } }); toolBar.add(cbAutoRefresh); bRefresh.setText("Refresh"); bRefresh.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { bRefreshActionPerformed(evt); } }); toolBar.add(bRefresh); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; add(toolBar, gridBagConstraints); splitPane.setDividerLocation(150); lGroups.setModel(new GroupListModel(aiDelegate)); lGroups.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { lGroupsMouseClicked(evt); } }); spGroupList.setViewportView(lGroups); splitPane.setLeftComponent(spGroupList); jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT); lUnits.setModel(new GroupUnitListModel()); spUnitList.setViewportView(lUnits); jSplitPane1.setBottomComponent(spUnitList); lTasks.setModel(new GroupTaskListModel()); jScrollPane1.setViewportView(lTasks); jSplitPane1.setLeftComponent(jScrollPane1); splitPane.setRightComponent(jSplitPane1); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; add(splitPane, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents private void cbAutoRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbAutoRefreshActionPerformed if (cbAutoRefresh.isSelected()) { startAutoUpdate(); } }//GEN-LAST:event_cbAutoRefreshActionPerformed private void bRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bRefreshActionPerformed refresh(); }//GEN-LAST:event_bRefreshActionPerformed private void lGroupsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lGroupsMouseClicked if (evt.getButton() == MouseEvent.BUTTON1) { UnitGroup group = ((GroupListModel) lGroups.getModel()).getGroup(lGroups.getSelectedIndex()); ((GroupUnitListModel) lUnits.getModel()).setGroup(group); ((GroupTaskListModel) lTasks.getModel()).setGroup(group); refresh(); } }//GEN-LAST:event_lGroupsMouseClicked // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton bRefresh; private javax.swing.JCheckBox cbAutoRefresh; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JSplitPane jSplitPane1; private javax.swing.JList lGroups; private javax.swing.JList lTasks; private javax.swing.JList lUnits; private javax.swing.JScrollPane spGroupList; private javax.swing.JScrollPane spUnitList; private javax.swing.JSplitPane splitPane; private javax.swing.JToolBar toolBar; // End of variables declaration//GEN-END:variables }