FlexSubData.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. showAction();
  38. }else if(btnShowObjects.getText() == HIDE){
  39. hideAction();
  40. }
  41. }
  42. });
  43. subnetInfo.add(btnShowObjects);
  44. objectInfo = new JPanel();
  45. setRightComponent(objectInfo);
  46. objectInfo.setLayout(new BoxLayout(objectInfo, BoxLayout.X_AXIS));
  47. shown = false;
  48. }
  49. public void setObjects(JPanel obj){
  50. objectInfo.removeAll();
  51. currentObj = obj;
  52. }
  53. public void setListener(FlexiblePane fP){
  54. listener = fP;
  55. }
  56. public JPanel getSubInfo(){
  57. return subnetInfo;
  58. }
  59. public void repaint(){
  60. if(btnShowObjects != null){
  61. if(shown = true){
  62. showAction();
  63. System.out.println("show");
  64. }else if(shown = false){
  65. hideAction();
  66. System.out.println("hide");
  67. }
  68. }
  69. super.repaint();
  70. }
  71. public void showAction(){
  72. if(currentObj != null && listener != null){
  73. objectInfo.removeAll();
  74. objectInfo.add(currentObj);
  75. objectInfo.revalidate();
  76. objectInfo.updateUI();
  77. listener.revalidate();
  78. btnShowObjects.setText(HIDE);
  79. }
  80. super.repaint();
  81. }
  82. public void hideAction(){
  83. if(listener != null){
  84. objectInfo.removeAll();
  85. objectInfo.revalidate();
  86. objectInfo.updateUI();
  87. listener.revalidate();
  88. btnShowObjects.setText(SHOW);
  89. }
  90. }
  91. }