* use MigLayout in FileTreePanel

* use MigLayout in ValidateNamesDialog
* use MigLayout in SelectDialog
This commit is contained in:
Reinhard Pointner 2008-10-21 17:49:08 +00:00
parent a77ff635da
commit d0725404ef
11 changed files with 79 additions and 128 deletions

View File

@ -2,7 +2,6 @@
package net.sourceforge.filebot.ui; package net.sourceforge.filebot.ui;
import java.awt.BorderLayout;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Window; import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@ -11,19 +10,16 @@ import java.awt.event.MouseEvent;
import java.util.Collection; import java.util.Collection;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import net.miginfocom.swing.MigLayout;
import net.sourceforge.filebot.ResourceManager; import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.tuned.ui.ArrayListModel; import net.sourceforge.tuned.ui.ArrayListModel;
import net.sourceforge.tuned.ui.DefaultFancyListCellRenderer; import net.sourceforge.tuned.ui.DefaultFancyListCellRenderer;
@ -32,11 +28,11 @@ import net.sourceforge.tuned.ui.TunedUtil;
public class SelectDialog<T> extends JDialog { public class SelectDialog<T> extends JDialog {
private JLabel label = new JLabel(); private final JLabel headerLabel = new JLabel();
private JList list = new JList(); private final JList list;
private T selectedValue = null; private boolean valueSelected = false;
public SelectDialog(Window owner, Collection<T> options) { public SelectDialog(Window owner, Collection<T> options) {
@ -44,43 +40,30 @@ public class SelectDialog<T> extends JDialog {
setDefaultCloseOperation(DISPOSE_ON_CLOSE); setDefaultCloseOperation(DISPOSE_ON_CLOSE);
list.setCellRenderer(new SelectListCellRenderer()); // initialize list and select first element
list.addMouseListener(mouseListener); list = new JList(new ArrayListModel(options));
list.setSelectedIndex(0);
setText("Select:"); DefaultFancyListCellRenderer cellRenderer = new DefaultFancyListCellRenderer(4);
cellRenderer.setHighlightingEnabled(false);
list.setCellRenderer(cellRenderer);
list.addMouseListener(mouseListener);
JComponent c = (JComponent) getContentPane(); JComponent c = (JComponent) getContentPane();
int border = 5; c.setLayout(new MigLayout("insets 1.5mm, nogrid, fill"));
c.setBorder(BorderFactory.createEmptyBorder(border, border, border, border));
c.setLayout(new BorderLayout(border, border));
JPanel listPanel = new JPanel(new BorderLayout()); c.add(headerLabel, "wrap");
c.add(new JScrollPane(list), "grow, wrap 2mm");
listPanel.add(new JScrollPane(list), BorderLayout.CENTER); c.add(new JButton(selectAction), "align center");
c.add(new JButton(cancelAction), "gap unrel, wrap 1.2mm");
Box buttonBox = Box.createHorizontalBox(); // set default size and location
buttonBox.setBorder(new EmptyBorder(5, 5, 5, 5)); setSize(new Dimension(210, 210));
buttonBox.add(Box.createHorizontalGlue());
buttonBox.add(new JButton(selectAction));
buttonBox.add(Box.createHorizontalStrut(10));
buttonBox.add(new JButton(cancelAction));
buttonBox.add(Box.createHorizontalGlue());
c.add(label, BorderLayout.NORTH);
c.add(listPanel, BorderLayout.CENTER);
c.add(buttonBox, BorderLayout.SOUTH);
// bounds and location
setMinimumSize(new Dimension(175, 175));
setSize(new Dimension(200, 190));
setLocation(TunedUtil.getPreferredLocation(this)); setLocation(TunedUtil.getPreferredLocation(this));
// default selection
list.setModel(new ArrayListModel(options));
list.setSelectedIndex(0);
// Shortcut Enter // Shortcut Enter
TunedUtil.putActionForKeystroke(list, KeyStroke.getKeyStroke("released ENTER"), selectAction); TunedUtil.putActionForKeystroke(list, KeyStroke.getKeyStroke("released ENTER"), selectAction);
@ -89,57 +72,43 @@ public class SelectDialog<T> extends JDialog {
} }
public void setText(String s) { protected String convertValueToString(Object value) {
label.setText(s); return value.toString();
} }
public JLabel getHeaderLabel() {
return headerLabel;
}
@SuppressWarnings("unchecked")
public T getSelectedValue() { public T getSelectedValue() {
return selectedValue; if (!valueSelected)
return null;
return (T) list.getSelectedValue();
} }
public void setSelectedValue(T value) { public void close() {
this.selectedValue = value; setVisible(false);
list.setSelectedValue(value, true); dispose();
} }
private AbstractAction selectAction = new AbstractAction("Select", ResourceManager.getIcon("dialog.continue")) { private AbstractAction selectAction = new AbstractAction("Select", ResourceManager.getIcon("dialog.continue")) {
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
selectedValue = (T) list.getSelectedValue(); valueSelected = true;
setVisible(false); close();
dispose();
} }
}; };
private AbstractAction cancelAction = new AbstractAction("Cancel", ResourceManager.getIcon("dialog.cancel")) { private AbstractAction cancelAction = new AbstractAction("Cancel", ResourceManager.getIcon("dialog.cancel")) {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
selectedValue = null; valueSelected = false;
setVisible(false); close();
dispose();
}
};
protected String convertValueToString(Object value) {
return value.toString();
}
private class SelectListCellRenderer extends DefaultFancyListCellRenderer {
public SelectListCellRenderer() {
super(4);
setHighlightingEnabled(false);
}
@Override
public void configureListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.configureListCellRendererComponent(list, convertValueToString(value), index, isSelected, cellHasFocus);
} }
}; };
@ -147,8 +116,9 @@ public class SelectDialog<T> extends JDialog {
@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)) {
selectAction.actionPerformed(null); selectAction.actionPerformed(null);
}
} }
}; };
} }

View File

@ -2,18 +2,16 @@
package net.sourceforge.filebot.ui.panel.analyze; package net.sourceforge.filebot.ui.panel.analyze;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import javax.swing.border.EmptyBorder;
import net.miginfocom.swing.MigLayout;
import net.sourceforge.filebot.ResourceManager; import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.filebot.ui.transfer.LoadAction; import net.sourceforge.filebot.ui.transfer.LoadAction;
import net.sourceforge.tuned.ui.LoadingOverlayPane; import net.sourceforge.tuned.ui.LoadingOverlayPane;
@ -26,23 +24,16 @@ class FileTreePanel extends JPanel {
public FileTreePanel() { public FileTreePanel() {
super(new BorderLayout()); super(new MigLayout("insets 0, nogrid, fill", "align center"));
setBorder(BorderFactory.createTitledBorder("File Tree")); setBorder(BorderFactory.createTitledBorder("File Tree"));
Box buttons = Box.createHorizontalBox(); add(new LoadingOverlayPane(new JScrollPane(fileTree), ResourceManager.getIcon("loading")), "grow, wrap 1.2mm");
buttons.setBorder(new EmptyBorder(5, 5, 5, 5)); add(new JButton(loadAction));
buttons.add(Box.createGlue()); add(new JButton(clearAction), "gap 1.2mm, wrap 1.2mm");
buttons.add(new JButton(loadAction));
buttons.add(Box.createHorizontalStrut(5));
buttons.add(new JButton(clearAction));
buttons.add(Box.createGlue());
// Shortcut DELETE // Shortcut DELETE
TunedUtil.putActionForKeystroke(fileTree, KeyStroke.getKeyStroke("pressed DELETE"), removeAction); TunedUtil.putActionForKeystroke(fileTree, KeyStroke.getKeyStroke("pressed DELETE"), removeAction);
add(new LoadingOverlayPane(new JScrollPane(fileTree), ResourceManager.getIcon("loading")), BorderLayout.CENTER);
add(buttons, BorderLayout.SOUTH);
} }

View File

@ -41,8 +41,6 @@ public class SplitPanel extends ToolPanel implements ChangeListener {
public SplitPanel() { public SplitPanel() {
super("Split"); super("Split");
setLayout(new MigLayout("insets 0, nogrid, fill", "align center"));
JScrollPane treeScrollPane = new JScrollPane(tree); JScrollPane treeScrollPane = new JScrollPane(tree);
treeScrollPane.setBorder(BorderFactory.createEmptyBorder()); treeScrollPane.setBorder(BorderFactory.createEmptyBorder());
@ -52,6 +50,8 @@ public class SplitPanel extends ToolPanel implements ChangeListener {
LoadingOverlayPane loadingOverlayPane = new LoadingOverlayPane(treeScrollPane, ResourceManager.getIcon("loading")); LoadingOverlayPane loadingOverlayPane = new LoadingOverlayPane(treeScrollPane, ResourceManager.getIcon("loading"));
loadingOverlayPane.setBorder(new SeparatorBorder(2, new Color(0, 0, 0, 90), GradientStyle.TOP_TO_BOTTOM, SeparatorBorder.Position.BOTTOM)); loadingOverlayPane.setBorder(new SeparatorBorder(2, new Color(0, 0, 0, 90), GradientStyle.TOP_TO_BOTTOM, SeparatorBorder.Position.BOTTOM));
setLayout(new MigLayout("insets 0, nogrid, fill", "align center"));
add(loadingOverlayPane, "grow, wrap"); add(loadingOverlayPane, "grow, wrap");
add(new JLabel("Split every")); add(new JLabel("Split every"));

View File

@ -17,6 +17,7 @@ public abstract class ToolPanel extends JPanel {
public ToolPanel(String name) { public ToolPanel(String name) {
super(null);
this.name = name; this.name = name;
} }

View File

@ -33,6 +33,7 @@ public class TypePanel extends ToolPanel {
public TypePanel() { public TypePanel() {
super("Types"); super("Types");
setLayout(new BorderLayout()); setLayout(new BorderLayout());
JScrollPane sp = new JScrollPane(tree); JScrollPane sp = new JScrollPane(tree);

View File

@ -309,7 +309,7 @@ public class EpisodeListPanel extends FileBotPanel {
SelectDialog<SearchResult> select = new SelectDialog<SearchResult>(window, searchResults); SelectDialog<SearchResult> select = new SelectDialog<SearchResult>(window, searchResults);
select.setText("Select a Show:"); select.getHeaderLabel().setText("Select a Show:");
select.setIconImage(TunedUtil.getImage(episodeList.getIcon())); select.setIconImage(TunedUtil.getImage(episodeList.getIcon()));
select.setVisible(true); select.setVisible(true);

View File

@ -12,6 +12,7 @@ import java.util.regex.Pattern;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException; import javax.swing.text.BadLocationException;
@ -19,6 +20,7 @@ import javax.swing.text.Highlighter;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import net.sourceforge.tuned.ui.AbstractFancyListCellRenderer; import net.sourceforge.tuned.ui.AbstractFancyListCellRenderer;
import net.sourceforge.tuned.ui.TunedUtil;
public class HighlightListCellRenderer extends AbstractFancyListCellRenderer { public class HighlightListCellRenderer extends AbstractFancyListCellRenderer {
@ -30,13 +32,17 @@ public class HighlightListCellRenderer extends AbstractFancyListCellRenderer {
public HighlightListCellRenderer(Pattern pattern, Highlighter.HighlightPainter highlightPainter, int padding) { public HighlightListCellRenderer(Pattern pattern, Highlighter.HighlightPainter highlightPainter, int padding) {
super(new Insets(padding, padding, padding, padding)); super(new Insets(0, 0, 0, 0));
this.pattern = pattern; this.pattern = pattern;
this.highlightPainter = highlightPainter; this.highlightPainter = highlightPainter;
textComponent.setBorder(null); // pad the cell from inside the text component,
textComponent.setOpaque(false); // so the HighlightPainter may paint in this space as well
textComponent.setBorder(new EmptyBorder(padding, padding, padding, padding));
// make text component transparent, should work for all LAFs (setOpaque(false) may not, e.g. Nimbus)
textComponent.setBackground(TunedUtil.TRANSLUCENT);
this.add(textComponent, BorderLayout.WEST); this.add(textComponent, BorderLayout.WEST);
@ -83,7 +89,7 @@ public class HighlightListCellRenderer extends AbstractFancyListCellRenderer {
@Override @Override
public void changedUpdate(DocumentEvent e) { public void changedUpdate(DocumentEvent e) {
updateHighlighter();
} }

View File

@ -3,29 +3,24 @@ package net.sourceforge.filebot.ui.panel.rename;
import java.awt.AlphaComposite; import java.awt.AlphaComposite;
import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Window; import java.awt.Window;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.util.List; import java.util.Collection;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.KeyStroke; import javax.swing.KeyStroke;
import javax.swing.border.EmptyBorder;
import net.miginfocom.swing.MigLayout;
import net.sourceforge.filebot.FileBotUtil; import net.sourceforge.filebot.FileBotUtil;
import net.sourceforge.filebot.ResourceManager; import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.filebot.ui.panel.rename.entry.ListEntry; import net.sourceforge.filebot.ui.panel.rename.entry.ListEntry;
@ -35,7 +30,7 @@ import net.sourceforge.tuned.ui.TunedUtil;
public class ValidateNamesDialog extends JDialog { public class ValidateNamesDialog extends JDialog {
private final List<ListEntry> entries; private final Collection<ListEntry> entries;
private boolean cancelled = true; private boolean cancelled = true;
@ -44,7 +39,7 @@ public class ValidateNamesDialog extends JDialog {
private final CancelAction cancelAction = new CancelAction(); private final CancelAction cancelAction = new CancelAction();
public ValidateNamesDialog(Window owner, List<ListEntry> entries) { public ValidateNamesDialog(Window owner, Collection<ListEntry> entries) {
super(owner, "Invalid Names", ModalityType.DOCUMENT_MODAL); super(owner, "Invalid Names", ModalityType.DOCUMENT_MODAL);
this.entries = entries; this.entries = entries;
@ -60,34 +55,16 @@ public class ValidateNamesDialog extends JDialog {
JComponent c = (JComponent) getContentPane(); JComponent c = (JComponent) getContentPane();
int border = 5; c.setLayout(new MigLayout("insets dialog, nogrid, fill"));
c.setBorder(BorderFactory.createEmptyBorder(border, border, border, border));
c.setLayout(new BorderLayout(border, border));
JPanel listPanel = new JPanel(new BorderLayout()); c.add(label, "wrap");
c.add(new JScrollPane(list), "grow, wrap 2mm");
listPanel.add(new JScrollPane(list), BorderLayout.CENTER); c.add(new JButton(validateAction), "align center");
c.add(new AlphaButton(continueAction), "gap related");
c.add(new JButton(cancelAction), "gap 12mm");
Box buttonBox = Box.createHorizontalBox(); setSize(365, 280);
buttonBox.setBorder(new EmptyBorder(5, 5, 5, 5));
buttonBox.add(Box.createHorizontalGlue());
buttonBox.add(new JButton(validateAction));
buttonBox.add(Box.createHorizontalStrut(10));
buttonBox.add(new AlphaButton(continueAction));
buttonBox.add(Box.createHorizontalStrut(40));
buttonBox.add(new JButton(cancelAction));
buttonBox.add(Box.createHorizontalGlue());
c.add(label, BorderLayout.NORTH);
c.add(listPanel, BorderLayout.CENTER);
c.add(buttonBox, BorderLayout.SOUTH);
setLocation(TunedUtil.getPreferredLocation(this));
setPreferredSize(new Dimension(365, 280));
pack();
TunedUtil.putActionForKeystroke(c, KeyStroke.getKeyStroke("released ESCAPE"), cancelAction); TunedUtil.putActionForKeystroke(c, KeyStroke.getKeyStroke("released ESCAPE"), cancelAction);
} }
@ -126,6 +103,7 @@ public class ValidateNamesDialog extends JDialog {
continueAction.putValue(SMALL_ICON, getValue(SMALL_ICON)); continueAction.putValue(SMALL_ICON, getValue(SMALL_ICON));
continueAction.putValue(ContinueAction.ALPHA, 1.0f); continueAction.putValue(ContinueAction.ALPHA, 1.0f);
// render list entries again to display changes
repaint(); repaint();
} }
}; };

View File

@ -40,7 +40,7 @@ public class SfvPanel extends FileBotPanel {
setLayout(new MigLayout("insets 0, nogrid, fill", "", "align bottom")); setLayout(new MigLayout("insets 0, nogrid, fill", "", "align bottom"));
add(new JScrollPane(sfvTable), "grow, gap bottom 5px, wrap"); add(new JScrollPane(sfvTable), "grow, wrap 10px");
add(new JButton(loadAction), "gap 15px, gap bottom 4px"); add(new JButton(loadAction), "gap 15px, gap bottom 4px");
add(new JButton(saveAction), "gap rel, gap bottom 4px"); add(new JButton(saveAction), "gap rel, gap bottom 4px");
@ -145,7 +145,7 @@ public class SfvPanel extends FileBotPanel {
} }
}; };
selectDialog.setText("Select checksum column:"); selectDialog.getHeaderLabel().setText("Select checksum column:");
selectDialog.setVisible(true); selectDialog.setVisible(true);
this.selectedColumn = selectDialog.getSelectedValue(); this.selectedColumn = selectDialog.getSelectedValue();

View File

@ -98,7 +98,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleClient, SubtitleP
@Override @Override
protected void configureSelectDialog(SelectDialog<SearchResult> selectDialog) throws Exception { protected void configureSelectDialog(SelectDialog<SearchResult> selectDialog) throws Exception {
super.configureSelectDialog(selectDialog); super.configureSelectDialog(selectDialog);
selectDialog.setText("Select a Show / Movie:"); selectDialog.getHeaderLabel().setText("Select a Show / Movie:");
} }
} }

View File

@ -2,6 +2,7 @@
package net.sourceforge.tuned.ui; package net.sourceforge.tuned.ui;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Image; import java.awt.Image;
@ -23,6 +24,9 @@ import javax.swing.Timer;
public final class TunedUtil { public final class TunedUtil {
public static final Color TRANSLUCENT = new Color(255, 255, 255, 0);
public static void checkEventDispatchThread() { public static void checkEventDispatchThread() {
if (!SwingUtilities.isEventDispatchThread()) { if (!SwingUtilities.isEventDispatchThread()) {
throw new IllegalStateException("Method must be accessed from the Swing Event Dispatch Thread, but was called on Thread \"" + Thread.currentThread().getName() + "\""); throw new IllegalStateException("Method must be accessed from the Swing Event Dispatch Thread, but was called on Thread \"" + Thread.currentThread().getName() + "\"");