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

View File

@ -2,18 +2,16 @@
package net.sourceforge.filebot.ui.panel.analyze;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.border.EmptyBorder;
import net.miginfocom.swing.MigLayout;
import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.filebot.ui.transfer.LoadAction;
import net.sourceforge.tuned.ui.LoadingOverlayPane;
@ -26,23 +24,16 @@ class FileTreePanel extends JPanel {
public FileTreePanel() {
super(new BorderLayout());
super(new MigLayout("insets 0, nogrid, fill", "align center"));
setBorder(BorderFactory.createTitledBorder("File Tree"));
Box buttons = Box.createHorizontalBox();
buttons.setBorder(new EmptyBorder(5, 5, 5, 5));
buttons.add(Box.createGlue());
buttons.add(new JButton(loadAction));
buttons.add(Box.createHorizontalStrut(5));
buttons.add(new JButton(clearAction));
buttons.add(Box.createGlue());
add(new LoadingOverlayPane(new JScrollPane(fileTree), ResourceManager.getIcon("loading")), "grow, wrap 1.2mm");
add(new JButton(loadAction));
add(new JButton(clearAction), "gap 1.2mm, wrap 1.2mm");
// Shortcut DELETE
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() {
super("Split");
setLayout(new MigLayout("insets 0, nogrid, fill", "align center"));
JScrollPane treeScrollPane = new JScrollPane(tree);
treeScrollPane.setBorder(BorderFactory.createEmptyBorder());
@ -52,6 +50,8 @@ public class SplitPanel extends ToolPanel implements ChangeListener {
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));
setLayout(new MigLayout("insets 0, nogrid, fill", "align center"));
add(loadingOverlayPane, "grow, wrap");
add(new JLabel("Split every"));

View File

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

View File

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

View File

@ -309,7 +309,7 @@ public class EpisodeListPanel extends FileBotPanel {
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.setVisible(true);

View File

@ -12,6 +12,7 @@ import java.util.regex.Pattern;
import javax.swing.JList;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
@ -19,6 +20,7 @@ import javax.swing.text.Highlighter;
import javax.swing.text.JTextComponent;
import net.sourceforge.tuned.ui.AbstractFancyListCellRenderer;
import net.sourceforge.tuned.ui.TunedUtil;
public class HighlightListCellRenderer extends AbstractFancyListCellRenderer {
@ -30,13 +32,17 @@ public class HighlightListCellRenderer extends AbstractFancyListCellRenderer {
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.highlightPainter = highlightPainter;
textComponent.setBorder(null);
textComponent.setOpaque(false);
// pad the cell from inside the text component,
// 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);
@ -83,7 +89,7 @@ public class HighlightListCellRenderer extends AbstractFancyListCellRenderer {
@Override
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.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.util.List;
import java.util.Collection;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.KeyStroke;
import javax.swing.border.EmptyBorder;
import net.miginfocom.swing.MigLayout;
import net.sourceforge.filebot.FileBotUtil;
import net.sourceforge.filebot.ResourceManager;
import net.sourceforge.filebot.ui.panel.rename.entry.ListEntry;
@ -35,7 +30,7 @@ import net.sourceforge.tuned.ui.TunedUtil;
public class ValidateNamesDialog extends JDialog {
private final List<ListEntry> entries;
private final Collection<ListEntry> entries;
private boolean cancelled = true;
@ -44,7 +39,7 @@ public class ValidateNamesDialog extends JDialog {
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);
this.entries = entries;
@ -60,34 +55,16 @@ public class ValidateNamesDialog extends JDialog {
JComponent c = (JComponent) getContentPane();
int border = 5;
c.setBorder(BorderFactory.createEmptyBorder(border, border, border, border));
c.setLayout(new BorderLayout(border, border));
c.setLayout(new MigLayout("insets dialog, nogrid, fill"));
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();
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();
setSize(365, 280);
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(ContinueAction.ALPHA, 1.0f);
// render list entries again to display changes
repaint();
}
};

View File

@ -40,7 +40,7 @@ public class SfvPanel extends FileBotPanel {
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(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);
this.selectedColumn = selectDialog.getSelectedValue();

View File

@ -98,7 +98,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleClient, SubtitleP
@Override
protected void configureSelectDialog(SelectDialog<SearchResult> selectDialog) throws Exception {
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;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
@ -23,6 +24,9 @@ import javax.swing.Timer;
public final class TunedUtil {
public static final Color TRANSLUCENT = new Color(255, 255, 255, 0);
public static void checkEventDispatchThread() {
if (!SwingUtilities.isEventDispatchThread()) {
throw new IllegalStateException("Method must be accessed from the Swing Event Dispatch Thread, but was called on Thread \"" + Thread.currentThread().getName() + "\"");