Guest User

Untitled

a guest
Apr 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. /*
  2. * InputPanel.java
  3. *
  4. * Created on March 12, 2008, 8:13 PM
  5. */
  6.  
  7. package edu.ohiou.cs550.manufacturing.gui;
  8. import edu.ohiou.cs550.manufacturing.renderers.*;
  9. import edu.ohiou.cs550.manufacturing.listeners.*;
  10. import edu.ohiou.cs550.manufacturing.*;
  11. import javax.swing.table.*;
  12. import java.awt.event.*;
  13. import javax.swing.event.*;
  14. import javax.swing.table.*;
  15. /**
  16. *
  17. * @author alex
  18. */
  19. public class InputPanel extends javax.swing.JPanel {
  20. protected ManufacturingLayout layout;
  21. protected ManufacturingLayoutModel mlModel;
  22. protected InputTableValues itv = new InputTableValues();
  23. protected MachineRenderer machineCellRenderer = new MachineRenderer();
  24. protected MachineEditor machineCellEditor = new MachineEditor();
  25. protected SlotRenderer slotCellRenderer = new SlotRenderer();
  26. InputPartListener pListener = new InputPartListener();
  27. InputMachineListener mListener = new InputMachineListener();
  28. MachineCellListener mcListener = new MachineCellListener();
  29.  
  30. /** Creates new form InputPanel */
  31. public InputPanel() {
  32. initComponents();
  33.  
  34. }
  35.  
  36. public void loadSystem(ManufacturingLayout layout, ManufacturingLayoutModel mlModel){
  37. this.layout = layout;
  38. this.mlModel = mlModel;
  39.  
  40. if(this.layout != null){
  41. itv.loadSystem(layout, mlModel);
  42. machineCellRenderer.loadSystem(layout, mlModel);
  43. machineCellEditor.loadSystem(layout, mlModel);
  44. slotCellRenderer.loadSystem(layout, mlModel, itv);
  45. machineCellEditor.addCellEditorListener(mcListener);
  46. TableColumnModel tcm = inputTable.getColumnModel();
  47. TableColumn tcMachine = tcm.getColumn(InputTableValues.MACHINE);
  48. TableColumn tcSlot = tcm.getColumn(InputTableValues.SLOT);
  49.  
  50. tcMachine.setCellRenderer(machineCellRenderer);
  51. tcMachine.setCellEditor(machineCellEditor);
  52.  
  53. tcSlot.setCellRenderer(slotCellRenderer);
  54.  
  55.  
  56. if(mlModel != null){
  57. mlModel.addPartListener(pListener);
  58. mlModel.addMachineListener(mListener);
  59. }
  60. }
  61. }
  62.  
  63. /** This method is called from within the constructor to
  64. * initialize the form.
  65. * WARNING: Do NOT modify this code. The content of this method is
  66. * always regenerated by the Form Editor.
  67. */
  68. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  69. private void initComponents() {
  70.  
  71. inputLabel = new javax.swing.JLabel();
  72. jScrollPane1 = new javax.swing.JScrollPane();
  73. inputTable = new javax.swing.JTable();
  74. inputTextArea = new javax.swing.JTextArea();
  75.  
  76. setLayout(new java.awt.BorderLayout());
  77.  
  78. inputLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  79. inputLabel.setText("Input Information"); // NOI18N
  80. add(inputLabel, java.awt.BorderLayout.PAGE_START);
  81.  
  82. inputTable.setModel(itv);
  83. inputTable.setRowSelectionAllowed(false);
  84. jScrollPane1.setViewportView(inputTable);
  85.  
  86. add(jScrollPane1, java.awt.BorderLayout.CENTER);
  87.  
  88. inputTextArea.setColumns(20);
  89. inputTextArea.setEditable(false);
  90. inputTextArea.setRows(5);
  91. inputTextArea.setText("For each part set the machine and slot it should be routed to."); // NOI18N
  92. inputTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Instructions"));
  93. add(inputTextArea, java.awt.BorderLayout.SOUTH);
  94. }// </editor-fold>
  95.  
  96.  
  97. // Variables declaration - do not modify
  98. private javax.swing.JLabel inputLabel;
  99. private javax.swing.JTable inputTable;
  100. private javax.swing.JTextArea inputTextArea;
  101. private javax.swing.JScrollPane jScrollPane1;
  102. // End of variables declaration
  103.  
  104. protected class InputPartListener implements PartListener {
  105. public void partAdded(String name, int loc){
  106.  
  107. itv.addRow();
  108. }
  109.  
  110. public void partRemoved(String name, int loc){
  111.  
  112. itv.removeRow();
  113. }
  114.  
  115. public void partSelected(String name){
  116.  
  117. }
  118. }
  119.  
  120. protected class InputMachineListener implements MachineListener {
  121. public void machineAdded(String name, int loc){
  122.  
  123. machineCellEditor.loadItems();
  124. itv.fireTableRowsUpdated(0, itv.getRowCount()-1);
  125. }
  126.  
  127. public void machineRemoved(String name, int loc){
  128. for(int i = 0; i < itv.getRowCount(); i++){
  129. if(itv.getValueAt(i, 0).equals(name)){
  130. itv.setValueAt("",i,0);
  131. }
  132. }
  133. machineCellEditor.loadItems();
  134. itv.fireTableRowsUpdated(0, itv.getRowCount()-1);
  135. }
  136.  
  137. public void machineSelected(String name){
  138.  
  139. }
  140. }
  141.  
  142. public class MachineCellListener implements CellEditorListener {
  143. public void editingStopped(ChangeEvent e){
  144. itv.fireTableRowsUpdated(0, itv.getRowCount()-1);
  145. }
  146.  
  147. public void editingCanceled(ChangeEvent e){
  148.  
  149. }
  150. }
  151. }
Add Comment
Please, Sign In to add comment