package com.framsticks.gui; import org.apache.log4j.Logger; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** * @author Piotr Sniegowski */ @SuppressWarnings("serial") public abstract class ModifiablePanel extends Panel { private static final Logger log = Logger.getLogger(ModifiablePanel.class.getName()); /** * Pane to which components will be added. */ protected JPanel contentPanel; final protected JLabel label; final protected JButton applyButton; public ModifiablePanel(Panel.Parameters parameters) { super(parameters); log.debug("create panel for type: " + className); contentPanel = new JPanel(); contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS)); JScrollPane scroll = new JScrollPane(contentPanel); //scroll.setBorder(BorderFactory.createEtchedBorder()); JPanel pageEndPanel = new JPanel(); pageEndPanel.setLayout(new BoxLayout(pageEndPanel, BoxLayout.X_AXIS)); pageEndPanel.add(Box.createHorizontalGlue()); applyButton = new JButton("Apply"); applyButton.setName("apply"); applyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { applyChanges(); } }); pageEndPanel.add(applyButton); pageEndPanel.add(Box.createHorizontalStrut(10)); pageEndPanel.setPreferredSize(new Dimension(0, 30)); label = new JLabel(); JPanel centerPanel = new JPanel(); centerPanel.setLayout(new BorderLayout()); centerPanel.add(Box.createHorizontalStrut(10), BorderLayout.LINE_START); centerPanel.add(Box.createHorizontalStrut(10), BorderLayout.LINE_END); centerPanel.add(label, BorderLayout.PAGE_START); centerPanel.add(scroll, BorderLayout.CENTER); centerPanel.add(pageEndPanel, BorderLayout.PAGE_END); this.setLayout(new BorderLayout()); this.add(centerPanel, BorderLayout.CENTER); //this.add(new ViewerTest(), BorderLayout.PAGE_END); } protected abstract void applyChanges(); }