FlexSubData.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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;
  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. btnShowObjects = new JButton(SHOW);
  33. btnShowObjects.setBounds(135, 13, 99, 23);
  34. btnShowObjects.addActionListener(new ActionListener(){
  35. public void actionPerformed(ActionEvent e){
  36. if(btnShowObjects.getText() == SHOW){
  37. objectInfo.removeAll();
  38. objectInfo.add(currentObj);
  39. objectInfo.revalidate();
  40. objectInfo.updateUI();
  41. listener.revalidate();
  42. btnShowObjects.setText(HIDE);
  43. shown = true;
  44. }else if(btnShowObjects.getText() == HIDE){
  45. objectInfo.removeAll();
  46. objectInfo.revalidate();
  47. objectInfo.updateUI();
  48. listener.revalidate();
  49. btnShowObjects.setText(SHOW);
  50. shown = false;
  51. }
  52. }
  53. });
  54. subnetInfo.add(btnShowObjects);
  55. objectInfo = new JPanel();
  56. setRightComponent(objectInfo);
  57. objectInfo.setLayout(new BoxLayout(objectInfo, BoxLayout.X_AXIS));
  58. shown = false;
  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. if(btnShowObjects != null && listener != null && currentObj != null){
  72. if(shown = true){
  73. showAction();
  74. }
  75. if(shown = false){
  76. hideAction();
  77. }
  78. }
  79. super.repaint();
  80. }
  81. public void showAction(){
  82. objectInfo.removeAll();
  83. objectInfo.add(currentObj);
  84. objectInfo.revalidate();
  85. objectInfo.updateUI();
  86. listener.revalidate();
  87. btnShowObjects.setText(HIDE);
  88. }
  89. public void hideAction(){
  90. objectInfo.removeAll();
  91. objectInfo.revalidate();
  92. objectInfo.updateUI();
  93. listener.revalidate();
  94. btnShowObjects.setText(SHOW);
  95. }
  96. }