Package com.commander4j.sys

Source Code of com.commander4j.sys.JInternalFrameLinePrinters

package com.commander4j.sys;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collections;
import java.util.LinkedList;

import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JDesktopPane;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.border.BevelBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import com.commander4j.db.JDBAutoLabeller;
import com.commander4j.db.JDBLanguage;
import com.commander4j.db.JDBListData;
import com.commander4j.db.JDBPrinterLineMembership;
import com.commander4j.gui.JButton4j;
import com.commander4j.gui.JLabel4j_title;
import com.commander4j.gui.JList4j;
import com.commander4j.util.JHelp;
import com.commander4j.util.JUtility;

public class JInternalFrameLinePrinters extends javax.swing.JInternalFrame
{
  private static final long serialVersionUID = 1;
  private JDesktopPane jDesktopPane1;
  private JScrollPane jScrollPaneUnAssigned;
  private JButton4j jButtonClose;
  private JList4j jListAssigned;
  private JList4j jListUnAssigned;
  private JList4j jListLines;
  private JButton4j jButtonUnAssign;
  private JButton4j jButtonAssign;
  private JButton4j jButtonRefresh;
  private JScrollPane jScrollPaneAssigned;
  private JScrollPane jScrollPaneLines;
  private DefaultComboBoxModel lineModel = new DefaultComboBoxModel();
  private LinkedList<JDBListData> lineList = new LinkedList<JDBListData>();
  private DefaultComboBoxModel unassignedModel = new DefaultComboBoxModel();
  private LinkedList<JDBListData> unassignedList = new LinkedList<JDBListData>();
  private DefaultComboBoxModel assignedModel = new DefaultComboBoxModel();
  private LinkedList<JDBListData> assignedList = new LinkedList<JDBListData>();
  private JButton4j jButtonHelp;
  private JLabel4j_title jLabel3;
  private JLabel4j_title jLabel2;
  private JLabel4j_title jLabel1;
  private JDBLanguage lang = new JDBLanguage(Common.selectedHostID, Common.sessionID);
  private JDBAutoLabeller al = new JDBAutoLabeller(Common.selectedHostID, Common.sessionID);


  public JInternalFrameLinePrinters()
  {
    super();
    initGUI();
    final JHelp help = new JHelp();
    help.enableHelpOnButton(jButtonHelp, JUtility.getHelpSetIDforModule("FRM_ADMIN_MENU"));
   

    populateLineList();
  }

  public void setButtonState() {

    jButtonUnAssign.setEnabled(false);
    jButtonAssign.setEnabled(false);

    if (unassignedList.size() > 0)
    {
      jButtonAssign.setEnabled(true);
    }

    if (assignedList.size() > 0)
    {
      jButtonUnAssign.setEnabled(true);
    }

  }

  private void populateLineList() {
    lineModel.removeAllElements();

    this.setIconifiable(true);

    lineList = al.getLabellerIDs();

    for (int j = 0; j < lineList.size(); j++)
    {
      lineModel.addElement(lineList.get(j));
    }

    ListModel jList1Model = lineModel;
    jListLines.setCellRenderer(Common.renderer_list);
    jListLines.setModel(jList1Model);
  }

  private void refreshJList(JList4j jlist, DefaultComboBoxModel comboboxmodel, LinkedList<JDBListData> linkedlist) {
    comboboxmodel.removeAllElements();

    for (int j = 0; j < linkedlist.size(); j++)
    {
      comboboxmodel.addElement(linkedlist.get(j));
    }
    ListModel jList1Model = comboboxmodel;

    jlist.setModel(jList1Model);
  }

  private void populateUnAssignedList(JDBListData i) {
    unassignedModel.removeAllElements();

    JDBPrinterLineMembership plm = new JDBPrinterLineMembership(Common.selectedHostID, Common.sessionID);
    if (i==null)
    {
      plm.setPrinterId("");
      unassignedList.clear();
    }
    else
    {
      plm.setPrinterId(i.toString());
      unassignedList = plm.getPrintersNotAssignedtoLine(plm.getPrinterId());
    }

    if (unassignedList.size() > 0)
    {
      for (int j = 0; j < unassignedList.size(); j++)
      {
        unassignedModel.addElement(unassignedList.get(j));
      }
      jButtonAssign.setEnabled(true);
      jButtonUnAssign.setEnabled(true);
    }
    else
    {
      jButtonAssign.setEnabled(false);
      jButtonUnAssign.setEnabled(false);
    }

    ListModel jList1Model = unassignedModel;

    jListUnAssigned.setModel(jList1Model);
  }

  private void populateAssignedList(JDBListData i) {
    assignedModel.removeAllElements();

    JDBPrinterLineMembership plm = new JDBPrinterLineMembership(Common.selectedHostID, Common.sessionID);
   
    if (i==null)
    {
      plm.setPrinterId("");
    }
    else
    {
      plm.setPrinterId(i.toString());
    }

    assignedList = plm.getPrintersAssignedtoLine(plm.getPrinterId());

    if (assignedList.size() > 0)
    {
      for (int j = 0; j < assignedList.size(); j++)
      {
        assignedModel.addElement(assignedList.get(j));
      }
    }

    ListModel jList1Model = assignedModel;

    jListAssigned.setModel(jList1Model);
  }

  public void addToList(LinkedList<JDBListData> list, JDBListData newValue, boolean sort) {
    list.add(newValue);
    if (sort == true)
      Collections.sort(list);
  }

  public void removeFromList(LinkedList<JDBListData> list, Object oldValue) {
    list.remove(list.indexOf(oldValue));
  }

  private void initGUI() {
    try
    {
      this.setPreferredSize(new java.awt.Dimension(761, 450));
      this.setBounds(0, 0, 647, 465);
      setVisible(true);
      this.setTitle("Menu Structure");
      this.setClosable(true);
      {
        jDesktopPane1 = new JDesktopPane();
        jDesktopPane1.setBackground(Color.WHITE);
        this.getContentPane().add(jDesktopPane1, BorderLayout.NORTH);
        jDesktopPane1.setPreferredSize(new java.awt.Dimension(792, 421));
        jDesktopPane1.setLayout(null);
        {
          jScrollPaneLines = new JScrollPane();
          jDesktopPane1.add(jScrollPaneLines);
          jScrollPaneLines.setBounds(10, 25, 180, 345);
          jScrollPaneLines.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
          {
            ListModel jListLinesModel = new DefaultComboBoxModel(new String[] { "" });
            jListLines = new JList4j();
            jScrollPaneLines.setViewportView(jListLines);
            jListLines.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            jListLines.setFont(Common.font_list);
            jListLines.addListSelectionListener(new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent evt) {
                int sel = jListLines.getSelectedIndex();
                if (sel > -1)
                {
                  JDBListData item = (JDBListData) jListLines.getModel().getElementAt(sel);
                  populateUnAssignedList(item);
                  populateAssignedList(item);
                  setButtonState();
                }

              }
            });
            jListLines.setModel(jListLinesModel);
          }
        }
        {
          jScrollPaneUnAssigned = new JScrollPane();
          jDesktopPane1.add(jScrollPaneUnAssigned);
          jScrollPaneUnAssigned.setBounds(427, 25, 180, 345);
          jScrollPaneUnAssigned.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
          {
            ListModel jListUnAssignedModel = new DefaultComboBoxModel(new String[] { "" });
            jListUnAssigned = new JList4j();
            jScrollPaneUnAssigned.setViewportView(jListUnAssigned);
            jListUnAssigned.setModel(jListUnAssignedModel);
            jListUnAssigned.setFont(Common.font_list);
            jListUnAssigned.setCellRenderer(Common.renderer_list_assigned);
            jListUnAssigned.setBackground(Common.color_list_unassigned);
          }
        }
        {
          jScrollPaneAssigned = new JScrollPane();
          jDesktopPane1.add(jScrollPaneAssigned);
          jScrollPaneAssigned.setBounds(202, 25, 180, 345);
          jScrollPaneAssigned.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
          {
            ListModel jListAssignedModel = new DefaultComboBoxModel(new String[] { "" });
            jListAssigned = new JList4j();
            jScrollPaneAssigned.setViewportView(jListAssigned);
            jListAssigned.setModel(jListAssignedModel);
            jListAssigned.setFont(Common.font_list);
            jListAssigned.setCellRenderer(Common.renderer_list_assigned);
            jListAssigned.setBackground(Common.color_list_assigned);
          }
        }
        {
          jButtonRefresh = new JButton4j(Common.icon_refresh);
          jButtonRefresh.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
              populateLineList();
              populateUnAssignedList(null);
              populateAssignedList(null);
            }
          });
          jButtonRefresh.setText(lang.get("btn_Refresh"));
          jButtonRefresh.setBounds(113, 382, 116, 30);
          jDesktopPane1.add(jButtonRefresh);
        }
        {
          jButtonAssign = new JButton4j(Common.icon_arrow_left);
          jDesktopPane1.add(jButtonAssign);
          jButtonAssign.setBounds(390, 156, 25, 25);
          jButtonAssign.setEnabled(false);
          jButtonAssign.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              if (jListUnAssigned.getSelectedIndex() > -1)
              {
                JDBPrinterLineMembership plm = new JDBPrinterLineMembership(Common.selectedHostID, Common.sessionID);
                for (int j = jListUnAssigned.getMaxSelectionIndex(); j >= jListUnAssigned.getMinSelectionIndex(); j--)
                {
                  if (jListUnAssigned.isSelectedIndex(j))
                  {
                    JDBListData item = (JDBListData) jListUnAssigned.getModel().getElementAt(j);

                    if (plm.addPrintertoLine(jListLines.getSelectedValue().toString(), item.toString()))
                    {
                      addToList(assignedList, item, false);
                    }
                  }
                }

                for (int j = jListUnAssigned.getMaxSelectionIndex(); j >= jListUnAssigned.getMinSelectionIndex(); j--)
                {
                  if (jListUnAssigned.isSelectedIndex(j))
                  {
                    Object item = jListUnAssigned.getModel().getElementAt(j);

                      removeFromList(unassignedList, item);

                  }
                }

                refreshJList(jListAssigned, assignedModel, assignedList);
                refreshJList(jListUnAssigned, unassignedModel, unassignedList);

                setButtonState();
              }

            }
          });
        }
        {
          jButtonUnAssign = new JButton4j(Common.icon_arrow_right);
          jDesktopPane1.add(jButtonUnAssign);
          jButtonUnAssign.setBounds(390, 185, 25, 25);
          jButtonUnAssign.setEnabled(false);
          jButtonUnAssign.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              if (jListAssigned.getSelectedIndex() > -1)
              {
                JDBPrinterLineMembership plm = new JDBPrinterLineMembership(Common.selectedHostID, Common.sessionID);
                for (int j = jListAssigned.getMaxSelectionIndex(); j >= jListAssigned.getMinSelectionIndex(); j--)
                {
                  if (jListAssigned.isSelectedIndex(j))
                  {
                    JDBListData item = (JDBListData) jListAssigned.getModel().getElementAt(j);

                    addToList(unassignedList, item, true);
                  }
                }

                for (int j = jListAssigned.getMaxSelectionIndex(); j >= jListAssigned.getMinSelectionIndex(); j--)
                {
                  if (jListAssigned.isSelectedIndex(j))
                  {
                    Object item = jListAssigned.getModel().getElementAt(j);

                   
                   
                    if (plm.removePrinterfromLine(jListLines.getSelectedValue().toString(), item.toString()))
                    {
                      removeFromList(assignedList, item);
                    }
                  }
                }
                refreshJList(jListUnAssigned, unassignedModel, unassignedList);
                refreshJList(jListAssigned, assignedModel, assignedList);

                setButtonState();
              }
            }
          });
        }

        {
          jButtonClose = new JButton4j(Common.icon_close);
          jDesktopPane1.add(jButtonClose);
          jButtonClose.setText(lang.get("btn_Close"));
          jButtonClose.setBounds(350, 382, 116, 30);
          jButtonClose.setMnemonic(lang.getMnemonicChar());
          jButtonClose.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              dispose();
            }
          });
        }
        {
          jLabel1 = new JLabel4j_title();
          jDesktopPane1.add(jLabel1);
          jLabel1.setText(lang.get("lbl_Line_ID"));
          jLabel1.setBounds(12, 7, 60, 16);
        }
        {
          jLabel2 = new JLabel4j_title();
          jDesktopPane1.add(jLabel2);
          jLabel2.setText("Unassigned");
          jLabel2.setBounds(427, 5, 136, 21);
        }
        {
          jLabel3 = new JLabel4j_title();
          jDesktopPane1.add(jLabel3);
          jLabel3.setText("Assigned");
          jLabel3.setBounds(202, 6, 71, 18);
        }
        {
          jButtonHelp = new JButton4j(Common.icon_help);
          jDesktopPane1.add(jButtonHelp);
          jButtonHelp.setText(lang.get("btn_Help"));
          jButtonHelp.setBounds(232, 382, 116, 30);
          jButtonHelp.setMnemonic(lang.getMnemonicChar());
        }
      }
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}
TOP

Related Classes of com.commander4j.sys.JInternalFrameLinePrinters

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.