| 1 | package weka.clusterers.forMetisMQI.util; |
|---|
| 2 | |
|---|
| 3 | import java.awt.CardLayout; |
|---|
| 4 | import java.awt.Rectangle; |
|---|
| 5 | import java.awt.event.ActionEvent; |
|---|
| 6 | import java.awt.event.ActionListener; |
|---|
| 7 | |
|---|
| 8 | import javax.swing.JButton; |
|---|
| 9 | import javax.swing.JFrame; |
|---|
| 10 | import javax.swing.JPanel; |
|---|
| 11 | |
|---|
| 12 | public class GraphsFrame extends JFrame { |
|---|
| 13 | |
|---|
| 14 | /** |
|---|
| 15 | * |
|---|
| 16 | */ |
|---|
| 17 | private static final long serialVersionUID = 1L; |
|---|
| 18 | |
|---|
| 19 | private static GraphsFrame instance = null; |
|---|
| 20 | |
|---|
| 21 | private int numberOfPanels = 0; |
|---|
| 22 | |
|---|
| 23 | private JPanel graphPanel = null; |
|---|
| 24 | private JPanel buttonPanel = null; |
|---|
| 25 | private JButton nextButton = null; |
|---|
| 26 | private JButton prevButton = null; |
|---|
| 27 | |
|---|
| 28 | public static GraphsFrame instance() { |
|---|
| 29 | if(instance == null) { |
|---|
| 30 | instance = new GraphsFrame("Graphs Frame"); |
|---|
| 31 | } |
|---|
| 32 | return instance; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | private GraphsFrame() { |
|---|
| 36 | |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | private GraphsFrame(String name) { |
|---|
| 40 | super(name); |
|---|
| 41 | setBounds(new Rectangle(800, 700)); |
|---|
| 42 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | graphPanel = new JPanel(); |
|---|
| 46 | graphPanel.setName("graphPanel"); |
|---|
| 47 | graphPanel.setBounds(0,40,800, 660); |
|---|
| 48 | graphPanel.setLayout(new CardLayout()); |
|---|
| 49 | getContentPane().add(graphPanel); |
|---|
| 50 | |
|---|
| 51 | buttonPanel = new JPanel(); |
|---|
| 52 | nextButton = new JButton(">>"); |
|---|
| 53 | |
|---|
| 54 | nextButton.addActionListener(new ActionListener() { |
|---|
| 55 | @Override |
|---|
| 56 | public void actionPerformed(ActionEvent e) { |
|---|
| 57 | CardLayout c = (CardLayout) graphPanel.getLayout(); |
|---|
| 58 | c.next(graphPanel); |
|---|
| 59 | } |
|---|
| 60 | }); |
|---|
| 61 | prevButton = new JButton("<<"); |
|---|
| 62 | prevButton.addActionListener(new ActionListener() { |
|---|
| 63 | @Override |
|---|
| 64 | public void actionPerformed(ActionEvent e) { |
|---|
| 65 | CardLayout c = (CardLayout) graphPanel.getLayout(); |
|---|
| 66 | c.previous(graphPanel); |
|---|
| 67 | } |
|---|
| 68 | }); |
|---|
| 69 | buttonPanel.setBounds(0, 0, 800, 40); |
|---|
| 70 | buttonPanel.add(prevButton); |
|---|
| 71 | buttonPanel.add(nextButton); |
|---|
| 72 | getContentPane().add(buttonPanel); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | public void addPanel(JPanel panel) { |
|---|
| 76 | graphPanel.add(panel, Integer.toString(numberOfPanels)); |
|---|
| 77 | numberOfPanels++; |
|---|
| 78 | } |
|---|
| 79 | } |
|---|