package ui.view; import javax.swing.JSplitPane; import javax.swing.JPanel; import javax.swing.BoxLayout; import javax.swing.JButton; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.JToggleButton; import java.awt.Component; public class FlexSubData extends JSplitPane { public static final String HIDE = "Hide Objects"; public static final String SHOW = "Show Objects"; private JPanel subnetInfo; private JPanel objectInfo; private JPanel currentObj; private JButton btnShowObjects; private FlexiblePane listener; private boolean shown; public FlexSubData(FlexibleData fD) { setDividerSize(0); setAlignmentY(Component.CENTER_ALIGNMENT); setAlignmentX(Component.CENTER_ALIGNMENT); setOrientation(JSplitPane.VERTICAL_SPLIT); //subnetInfo = new FlexibleData("test" , 0, 0); subnetInfo = fD; subnetInfo.setMinimumSize(new Dimension(600, 100)); setLeftComponent(subnetInfo); subnetInfo.setLayout(null); btnShowObjects = new JButton(SHOW); btnShowObjects.setBounds(135, 13, 99, 23); btnShowObjects.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ if(btnShowObjects.getText() == SHOW){ objectInfo.removeAll(); objectInfo.add(currentObj); objectInfo.revalidate(); objectInfo.updateUI(); listener.revalidate(); btnShowObjects.setText(HIDE); shown = true; }else if(btnShowObjects.getText() == HIDE){ objectInfo.removeAll(); objectInfo.revalidate(); objectInfo.updateUI(); listener.revalidate(); btnShowObjects.setText(SHOW); shown = false; } } }); subnetInfo.add(btnShowObjects); objectInfo = new JPanel(); setRightComponent(objectInfo); objectInfo.setLayout(new BoxLayout(objectInfo, BoxLayout.X_AXIS)); shown = false; } public void setObjects(JPanel obj){ objectInfo.removeAll(); currentObj = obj; } public void setListener(FlexiblePane fP){ listener = fP; } public JPanel getSubInfo(){ return subnetInfo; } public void repaint(){ /* if(btnShowObjects != null && listener != null && currentObj != null){ if(shown){ btnShowObjects.setText(SHOW); }else{ btnShowObjects.setText(HIDE); } btnShowObjects.doClick(); } */ super.repaint(); } public void showAction(){ objectInfo.removeAll(); objectInfo.add(currentObj); objectInfo.revalidate(); objectInfo.updateUI(); listener.revalidate(); btnShowObjects.setText(HIDE); } public void hideAction(){ objectInfo.removeAll(); objectInfo.revalidate(); objectInfo.updateUI(); listener.revalidate(); btnShowObjects.setText(SHOW); } }