FlexSubData.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package ui.view;
  2. import javax.swing.JSplitPane;
  3. import javax.swing.JPanel;
  4. import javax.swing.BoxLayout;
  5. import javax.swing.JButton;
  6. import java.awt.Dimension;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.ItemEvent;
  10. import java.awt.event.ItemListener;
  11. import javax.swing.JToggleButton;
  12. import java.awt.Component;
  13. public class FlexSubData extends JSplitPane {
  14. public static final String HIDE = "Hide Objects";
  15. public static final String SHOW = "Show Objects";
  16. private JPanel subnetInfo;
  17. private JPanel objectInfo;
  18. private JPanel currentObj;
  19. private JButton btnShowObjects;
  20. private FlexiblePane listener;
  21. private boolean shown; // 0 = Hide, 1= Show
  22. public FlexSubData(FlexibleData fD) {
  23. setDividerSize(0);
  24. setAlignmentY(Component.CENTER_ALIGNMENT);
  25. setAlignmentX(Component.CENTER_ALIGNMENT);
  26. setOrientation(JSplitPane.VERTICAL_SPLIT);
  27. //subnetInfo = new FlexibleData("test" , 0, 0);
  28. subnetInfo = fD;
  29. subnetInfo.setMinimumSize(new Dimension(600, 100));
  30. setLeftComponent(subnetInfo);
  31. subnetInfo.setLayout(null);
  32. shown = true;
  33. btnShowObjects = new JButton(SHOW);
  34. btnShowObjects.setBounds(135, 13, 99, 23);
  35. btnShowObjects.addActionListener(new ActionListener(){
  36. public void actionPerformed(ActionEvent e){
  37. if(shown){
  38. objectInfo.removeAll();
  39. objectInfo.add(currentObj);
  40. objectInfo.revalidate();
  41. objectInfo.updateUI();
  42. listener.revalidate();
  43. btnShowObjects.setText(HIDE);
  44. shown = false;
  45. }else{
  46. objectInfo.removeAll();
  47. objectInfo.revalidate();
  48. objectInfo.updateUI();
  49. listener.revalidate();
  50. btnShowObjects.setText(SHOW);
  51. shown = true;
  52. }
  53. }
  54. });
  55. subnetInfo.add(btnShowObjects);
  56. objectInfo = new JPanel();
  57. setRightComponent(objectInfo);
  58. objectInfo.setLayout(new BoxLayout(objectInfo, BoxLayout.X_AXIS));
  59. }
  60. public void setObjects(JPanel obj){
  61. objectInfo.removeAll();
  62. currentObj = obj;
  63. }
  64. public void setListener(FlexiblePane fP){
  65. listener = fP;
  66. }
  67. public JPanel getSubInfo(){
  68. return subnetInfo;
  69. }
  70. public void repaint(){
  71. super.repaint();
  72. }
  73. public void showAction(){
  74. objectInfo.removeAll();
  75. objectInfo.add(currentObj);
  76. objectInfo.revalidate();
  77. objectInfo.updateUI();
  78. listener.revalidate();
  79. shown = false;
  80. btnShowObjects.setText(HIDE);
  81. }
  82. public void hideAction(){
  83. objectInfo.removeAll();
  84. objectInfo.revalidate();
  85. objectInfo.updateUI();
  86. listener.revalidate();
  87. shown = true;
  88. btnShowObjects.setText(SHOW);
  89. }
  90. }