package org.pegadi.disposal; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ResourceBundle; public class SettingsDialog extends JDialog { ResourceBundle messages; GridBagConstraints c; JTable testTable; public SettingsDialog(JFrame owner, JTable pageTable) { super(owner); messages = ResourceBundle.getBundle("org.pegadi.publicationcontrol.PublicationControlStrings"); setTitle(messages.getString("edit_button")); /* sections part */ JPanel sectionsPanel = new JPanel(new GridBagLayout()); c = new GridBagConstraints(); JLabel sectionsLabel = new JLabel(messages.getString("sections") + ":"); testTable = new JTable(new SectionsTableModel(pageTable)); testTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane tableScroll = new JScrollPane(testTable); tableScroll.setPreferredSize(new Dimension(200, 200)); JButton addSectionBtn = new JButton(messages.getString("new_section")); addSectionBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ((SectionsTableModel)testTable.getModel()).addNewSection(); } }); JButton removeSectionBtn = new JButton(messages.getString("delete_section")); removeSectionBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { testTable.getModel().setValueAt(false, testTable.getSelectedRow(), 1); } }); JPanel sectionBtnPanel = new JPanel(); sectionBtnPanel.add(addSectionBtn); sectionBtnPanel.add(removeSectionBtn); c.anchor = GridBagConstraints.LINE_START; sectionsPanel.add(sectionsLabel, c); c.gridy = 1; c.fill = GridBagConstraints.HORIZONTAL; sectionsPanel.add(tableScroll, c); c.anchor = GridBagConstraints.LINE_END; c.fill = GridBagConstraints.NONE; c.gridy = 2; sectionsPanel.add(sectionBtnPanel, c); JSeparator sep = new JSeparator(JSeparator.HORIZONTAL); sep.setPreferredSize(new Dimension(5, 1)); c.gridy = 3; c.fill = GridBagConstraints.HORIZONTAL; sectionsPanel.add(sep, c); /* next part * TODO: Add create new from template JPanel sectionsPanel2 = new JPanel(); sectionsPanel2.add(new JButton("1hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh")); sectionsPanel2.add(new JButton("2")); */ /* close button */ JButton closeBtn = new JButton(messages.getString("action_close")); closeBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); // Add everything to a main container JPanel mainPanel = new JPanel(new GridBagLayout()); c = new GridBagConstraints(); c.insets = new Insets(15, 15, 5, 15); c.gridy = 0; mainPanel.add(sectionsPanel, c); /* c.gridy = 1; mainPanel.add(sectionsPanel2, c);*/ c.gridy = 1; c.anchor = GridBagConstraints.LINE_END; mainPanel.add(closeBtn, c); JScrollPane mainScroll = new JScrollPane(mainPanel); add(mainScroll); pack(); setLocationRelativeTo(owner); setVisible(true); } }