import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class MainGui extends JFrame {
private static final long serialVersionUID = -3656238747406546991L;
JPanel panelDecision;
JPanel panelNewConfiguration;
JPanel test;
public MainGui() {
this.setTitle(GuiConstants.LABEL_WINDOW_NAME);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
showPanel(initializeDecision());
}
private JPanel initializeDecision() {
this.setSize(550, 300);
panelDecision = new JPanel(new GridBagLayout());
panelDecision
.setBorder(BorderFactory.createEmptyBorder(30, 30, 30, 30));
GridBagConstraints gbc = new GridBagConstraints();
JLabel labelDecision = new JLabel(GuiConstants.LABEL_DECISION);
JButton buttonNewConfiguration = new JButton("new");
buttonNewConfiguration.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// changeVisiblePanel(initializeNewConfiguration(),
// panelDecision);
List<JPanel> newPanelList = new ArrayList<JPanel>();
newPanelList.add(initializeNewConfiguration());
newPanelList.add(initializeNHashMethods());
changeVisiblePanel(newPanelList, panelDecision);
}
});
JButton buttonExistingConfiguration = new JButton("existing");
gbc.gridwidth = 0;
gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.HORIZONTAL;
panelDecision.add(labelDecision, gbc);
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.anchor = GridBagConstraints.EAST;
gbc.fill = GridBagConstraints.NONE;
panelDecision.add(buttonNewConfiguration, gbc);
gbc.gridx = 1;
gbc.anchor = GridBagConstraints.WEST;
panelDecision.add(buttonExistingConfiguration, gbc);
return panelDecision;
}
private JPanel initializeNewConfiguration() {
setSize(550, 500);
panelNewConfiguration = new JPanel(new GridBagLayout());
panelNewConfiguration.setBorder(BorderFactory.createEmptyBorder(30, 30,
30, 30));
initializeDirectory();
return panelNewConfiguration;
}
private void initializeDirectory() {
GridBagConstraints gbc = new GridBagConstraints();
JLabel labelDirectory = new JLabel("panel 1");
gbc.gridwidth = 0;
gbc.weightx = 1.0;
gbc.fill = GridBagConstraints.HORIZONTAL;
panelNewConfiguration.add(labelDirectory, gbc);
}
private JPanel initializeNHashMethods() {
test = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
JLabel labelHashMethods = new JLabel("Panel 2");
gbc.anchor = GridBagConstraints.WEST;
gbc.gridy = 5;
gbc.fill = GridBagConstraints.VERTICAL;
test.add(labelHashMethods, gbc);
return test;
}
private void changeVisiblePanel(List<JPanel> newPanelList, JPanel oldPanel) {
remove(oldPanel);
for (JPanel newPanel : newPanelList) {
showPanel(newPanel);
}
}
private void changeVisiblePanel(JPanel newPanel, JPanel oldPanel) {
remove(oldPanel);
showPanel(newPanel);
}
private void showPanel(JPanel panel) {
add(panel);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MainGui().setVisible(true);
}
});
}
}