|
| 1 | +/* |
| 2 | + * Created by JFormDesigner on Sat Apr 27 12:49:11 CEST 2024 |
| 3 | + */ |
| 4 | + |
| 5 | +package mediathek.gui.tabs.tab_film; |
| 6 | + |
| 7 | +import ca.odell.glazedlists.EventList; |
| 8 | +import ca.odell.glazedlists.swing.DefaultEventListModel; |
| 9 | +import ca.odell.glazedlists.swing.GlazedListsSwing; |
| 10 | +import mediathek.tool.ApplicationConfiguration; |
| 11 | +import mediathek.tool.SVGIconUtilities; |
| 12 | +import org.apache.commons.configuration2.sync.LockMode; |
| 13 | + |
| 14 | +import javax.swing.*; |
| 15 | +import javax.swing.border.EmptyBorder; |
| 16 | +import java.awt.*; |
| 17 | +import java.awt.event.WindowAdapter; |
| 18 | +import java.awt.event.WindowEvent; |
| 19 | +import java.util.ArrayList; |
| 20 | + |
| 21 | +/** |
| 22 | + * @author christianfranzke |
| 23 | + */ |
| 24 | +public class EditHistoryDialog extends JDialog { |
| 25 | + private static final String CONFIG_X = "edit_history.x"; |
| 26 | + private static final String CONFIG_Y = "edit_history.y"; |
| 27 | + private static final String CONFIG_HEIGHT = "edit_history.height"; |
| 28 | + private static final String CONFIG_WIDTH = "edit_history.width"; |
| 29 | + |
| 30 | + public EditHistoryDialog(Window owner, JMenuItem menuItem, EventList<String> eventList) { |
| 31 | + super(owner); |
| 32 | + initComponents(); |
| 33 | + |
| 34 | + menuItem.setEnabled(false); |
| 35 | + addWindowListener(new WindowAdapter() { |
| 36 | + @Override |
| 37 | + public void windowClosed(WindowEvent e) { |
| 38 | + menuItem.setEnabled(true); |
| 39 | + savePosition(); |
| 40 | + } |
| 41 | + }); |
| 42 | + |
| 43 | + DefaultEventListModel<String> model = GlazedListsSwing.eventListModelWithThreadProxyList(eventList); |
| 44 | + list.setModel(model); |
| 45 | + list.getSelectionModel().addListSelectionListener(l -> { |
| 46 | + if (l.getValueIsAdjusting()) |
| 47 | + return; |
| 48 | + adjustDeleteButton(); |
| 49 | + }); |
| 50 | + adjustDeleteButton(); |
| 51 | + |
| 52 | + btnDeleteEntries.addActionListener(l -> { |
| 53 | + var changeList = new ArrayList<String>(); |
| 54 | + for (var idx : list.getSelectedIndices()) { |
| 55 | + changeList.add(list.getModel().getElementAt(idx)); |
| 56 | + } |
| 57 | + changeList.forEach(eventList::remove); |
| 58 | + changeList.clear(); |
| 59 | + }); |
| 60 | + |
| 61 | + restorePosition(); |
| 62 | + } |
| 63 | + |
| 64 | + private void restorePosition() { |
| 65 | + var config = ApplicationConfiguration.getConfiguration(); |
| 66 | + try { |
| 67 | + config.lock(LockMode.READ); |
| 68 | + int x = config.getInt(CONFIG_X); |
| 69 | + int y = config.getInt(CONFIG_Y); |
| 70 | + int width = config.getInt(CONFIG_WIDTH); |
| 71 | + int height = config.getInt(CONFIG_HEIGHT); |
| 72 | + |
| 73 | + setSize(width, height); |
| 74 | + setLocation(x, y); |
| 75 | + } catch (Exception ignored) { |
| 76 | + System.out.println("COULD NOT FIND CONFIGURATION"); |
| 77 | + } finally { |
| 78 | + config.unlock(LockMode.READ); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + private void savePosition() { |
| 83 | + var config = ApplicationConfiguration.getConfiguration(); |
| 84 | + try { |
| 85 | + config.lock(LockMode.WRITE); |
| 86 | + var size = getSize(); |
| 87 | + var location = getLocation(); |
| 88 | + config.setProperty(CONFIG_WIDTH, size.width); |
| 89 | + config.setProperty(CONFIG_HEIGHT, size.height); |
| 90 | + config.setProperty(CONFIG_X, location.x); |
| 91 | + config.setProperty(CONFIG_Y, location.y); |
| 92 | + } finally { |
| 93 | + config.unlock(LockMode.WRITE); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + private void adjustDeleteButton() { |
| 98 | + btnDeleteEntries.setEnabled(list.getSelectionModel().getSelectedItemsCount() > 0); |
| 99 | + } |
| 100 | + |
| 101 | + private void initComponents() { |
| 102 | + // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents @formatter:off |
| 103 | + // Generated using JFormDesigner non-commercial license |
| 104 | + var dialogPane = new JPanel(); |
| 105 | + var contentPanel = new JPanel(); |
| 106 | + var scrollPane1 = new JScrollPane(); |
| 107 | + list = new JList<>(); |
| 108 | + var toolBar1 = new JToolBar(); |
| 109 | + btnDeleteEntries = new JButton(); |
| 110 | + btnDeleteEntries.setIcon(SVGIconUtilities.createSVGIcon("icons/fontawesome/trash-can.svg")); //NON-NLS |
| 111 | + |
| 112 | + //======== this ======== |
| 113 | + setTitle("Suchhistorie bearbeiten"); //NON-NLS |
| 114 | + setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); |
| 115 | + setType(Window.Type.UTILITY); |
| 116 | + var contentPane = getContentPane(); |
| 117 | + contentPane.setLayout(new BorderLayout()); |
| 118 | + |
| 119 | + //======== dialogPane ======== |
| 120 | + { |
| 121 | + dialogPane.setBorder(new EmptyBorder(12, 12, 12, 12)); |
| 122 | + dialogPane.setLayout(new BorderLayout()); |
| 123 | + |
| 124 | + //======== contentPanel ======== |
| 125 | + { |
| 126 | + contentPanel.setLayout(new BorderLayout()); |
| 127 | + |
| 128 | + //======== scrollPane1 ======== |
| 129 | + { |
| 130 | + scrollPane1.setViewportView(list); |
| 131 | + } |
| 132 | + contentPanel.add(scrollPane1, BorderLayout.CENTER); |
| 133 | + |
| 134 | + //======== toolBar1 ======== |
| 135 | + { |
| 136 | + toolBar1.setFloatable(false); |
| 137 | + |
| 138 | + //---- btnDeleteEntries ---- |
| 139 | + btnDeleteEntries.setToolTipText("Ausgew\u00e4hlte Eintr\u00e4ge l\u00f6schen"); //NON-NLS |
| 140 | + toolBar1.add(btnDeleteEntries); |
| 141 | + } |
| 142 | + contentPanel.add(toolBar1, BorderLayout.NORTH); |
| 143 | + } |
| 144 | + dialogPane.add(contentPanel, BorderLayout.CENTER); |
| 145 | + } |
| 146 | + contentPane.add(dialogPane, BorderLayout.CENTER); |
| 147 | + pack(); |
| 148 | + setLocationRelativeTo(getOwner()); |
| 149 | + // JFormDesigner - End of component initialization //GEN-END:initComponents @formatter:on |
| 150 | + } |
| 151 | + |
| 152 | + // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables @formatter:off |
| 153 | + // Generated using JFormDesigner non-commercial license |
| 154 | + private JList<String> list; |
| 155 | + private JButton btnDeleteEntries; |
| 156 | + // JFormDesigner - End of variables declaration //GEN-END:variables @formatter:on |
| 157 | +} |
0 commit comments