1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

* fix layout issues

This commit is contained in:
Reinhard Pointner 2014-08-02 19:56:19 +00:00
parent 478dbef16b
commit 989fd687da

View File

@ -1,7 +1,5 @@
package net.filebot.ui; package net.filebot.ui;
import static net.filebot.util.ui.SwingUI.*; import static net.filebot.util.ui.SwingUI.*;
import java.awt.Component; import java.awt.Component;
@ -29,113 +27,106 @@ import net.filebot.util.ui.DefaultFancyListCellRenderer;
import net.filebot.util.ui.SwingUI; import net.filebot.util.ui.SwingUI;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
public class SelectDialog<T> extends JDialog { public class SelectDialog<T> extends JDialog {
private final JLabel headerLabel = new JLabel(); private final JLabel headerLabel = new JLabel();
private final JList list; private final JList list;
private boolean valueSelected = false; private boolean valueSelected = false;
public SelectDialog(Component parent, Collection<? extends T> options) { public SelectDialog(Component parent, Collection<? extends T> options) {
super(getWindow(parent), "Select", ModalityType.DOCUMENT_MODAL); super(getWindow(parent), "Select", ModalityType.DOCUMENT_MODAL);
setDefaultCloseOperation(DISPOSE_ON_CLOSE); setDefaultCloseOperation(DISPOSE_ON_CLOSE);
// initialize list // initialize list
list = new JList(options.toArray()); list = new JList(options.toArray());
// select first element // select first element
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSelectedIndex(0); list.setSelectedIndex(0);
DefaultFancyListCellRenderer renderer = new DefaultFancyListCellRenderer(4) { DefaultFancyListCellRenderer renderer = new DefaultFancyListCellRenderer(4) {
@Override @Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
return super.getListCellRendererComponent(list, convertValueToString(value), index, isSelected, cellHasFocus); return super.getListCellRendererComponent(list, convertValueToString(value), index, isSelected, cellHasFocus);
} }
}; };
renderer.setHighlightingEnabled(false); renderer.setHighlightingEnabled(false);
list.setCellRenderer(renderer); list.setCellRenderer(renderer);
list.addMouseListener(mouseListener); list.addMouseListener(mouseListener);
JComponent c = (JComponent) getContentPane(); JComponent c = (JComponent) getContentPane();
c.setLayout(new MigLayout("insets 1.5mm 1.5mm 2.7mm 1.5mm, nogrid, fill", "", "[pref!][fill][pref!]")); c.setLayout(new MigLayout("insets 1.5mm 1.5mm 2.7mm 1.5mm, nogrid, fill", "", "[pref!][fill][pref!]"));
c.add(headerLabel, "wrap"); c.add(headerLabel, "wmin 150px, wrap");
c.add(new JScrollPane(list), "grow, wrap 2mm"); c.add(new JScrollPane(list), "wmin 150px, hmin 150px, grow, wrap 2mm");
c.add(new JButton(selectAction), "align center, id select"); c.add(new JButton(selectAction), "align center, id select");
c.add(new JButton(cancelAction), "gap unrel, id cancel"); c.add(new JButton(cancelAction), "gap unrel, id cancel");
// set default size and location // set default size and location
setSize(new Dimension(210, 210)); setMinimumSize(new Dimension(220, 240));
setSize(new Dimension(240, 260));
// Shortcut Enter // Shortcut Enter
SwingUI.installAction(list, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), selectAction); SwingUI.installAction(list, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), selectAction);
} }
protected String convertValueToString(Object value) { protected String convertValueToString(Object value) {
return value.toString(); return value.toString();
} }
public JLabel getHeaderLabel() { public JLabel getHeaderLabel() {
return headerLabel; return headerLabel;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public T getSelectedValue() { public T getSelectedValue() {
if (!valueSelected) if (!valueSelected)
return null; return null;
return (T) list.getSelectedValue(); return (T) list.getSelectedValue();
} }
public void close() { public void close() {
setVisible(false); setVisible(false);
dispose(); dispose();
} }
public Action getSelectAction() { public Action getSelectAction() {
return selectAction; return selectAction;
} }
public Action getCancelAction() { public Action getCancelAction() {
return cancelAction; return cancelAction;
} }
private final Action selectAction = new AbstractAction("Select", ResourceManager.getIcon("dialog.continue")) { private final Action selectAction = new AbstractAction("Select", ResourceManager.getIcon("dialog.continue")) {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
valueSelected = true; valueSelected = true;
close(); close();
} }
}; };
private final Action cancelAction = new AbstractAction("Cancel", ResourceManager.getIcon("dialog.cancel")) { private final Action cancelAction = new AbstractAction("Cancel", ResourceManager.getIcon("dialog.cancel")) {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
valueSelected = false; valueSelected = false;
close(); close();
} }
}; };
private final MouseAdapter mouseListener = new MouseAdapter() { private final MouseAdapter mouseListener = new MouseAdapter() {
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e) && (e.getClickCount() == 2)) { if (SwingUtilities.isLeftMouseButton(e) && (e.getClickCount() == 2)) {
@ -143,5 +134,5 @@ public class SelectDialog<T> extends JDialog {
} }
} }
}; };
} }