FlexSubData.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. public FlexSubData(FlexibleData fD) {
  22. setDividerSize(0);
  23. setAlignmentY(Component.CENTER_ALIGNMENT);
  24. setAlignmentX(Component.CENTER_ALIGNMENT);
  25. setOrientation(JSplitPane.VERTICAL_SPLIT);
  26. //subnetInfo = new FlexibleData("test" , 0, 0);
  27. subnetInfo = fD;
  28. subnetInfo.setMinimumSize(new Dimension(600, 100));
  29. setLeftComponent(subnetInfo);
  30. subnetInfo.setLayout(null);
  31. btnShowObjects = new JButton(SHOW);
  32. btnShowObjects.setBounds(135, 13, 99, 23);
  33. btnShowObjects.addActionListener(new ActionListener(){
  34. public void actionPerformed(ActionEvent e){
  35. if(btnShowObjects.getText() == SHOW){
  36. objectInfo.add(currentObj);
  37. objectInfo.revalidate();
  38. objectInfo.updateUI();
  39. listener.revalidate();
  40. btnShowObjects.setText(HIDE);
  41. }else if(btnShowObjects.getText() == HIDE){
  42. objectInfo.removeAll();
  43. objectInfo.revalidate();
  44. objectInfo.updateUI();
  45. listener.revalidate();
  46. btnShowObjects.setText(SHOW);
  47. }
  48. }
  49. });
  50. subnetInfo.add(btnShowObjects);
  51. objectInfo = new JPanel();
  52. setRightComponent(objectInfo);
  53. objectInfo.setLayout(new BoxLayout(objectInfo, BoxLayout.X_AXIS));
  54. }
  55. public void setObjects(JPanel obj){
  56. objectInfo.removeAll();
  57. currentObj = obj;
  58. }
  59. public void setListener(FlexiblePane fP){
  60. listener = fP;
  61. }
  62. public JPanel getSubInfo(){
  63. return subnetInfo;
  64. }
  65. }