import java.util.Vector;
import javax.swing.BoxLayout;
-import javax.swing.DefaultListCellRenderer;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
+import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
+import javax.swing.ListCellRenderer;
import javax.swing.SpringLayout;
+import javax.swing.SwingConstants;
import javax.swing.filechooser.FileFilter;
import javax.swing.plaf.basic.BasicFileChooserUI;
// file filters to fix bug on Mac OSX
setAcceptAllFileFilterUsed(acceptAny);
+ // add a "All known alignment files" option
+ List<String> allExtensions = new ArrayList<>();
+ for (String[] format : formats)
+ {
+ String[] extensions = format[0].split(",");
+ for (String ext : extensions)
+ {
+ if (!allExtensions.contains(ext))
+ {
+ allExtensions.add(ext);
+ }
+ }
+ }
+ allExtensions.sort(null);
+ JalviewFileFilter alljvf = new JalviewFileFilter(
+ allExtensions.toArray(new String[] {}),
+ MessageManager.getString("label.all_known_alignment_files"));
+ alljvf.setExtensionListInDescription(false);
+ addChoosableFileFilter(alljvf);
+
for (String[] format : formats)
{
JalviewFileFilter jvf = new JalviewFileFilter(format[0], format[1]);
}
list = new JList<>(recent);
+ list.setCellRenderer(new recentlyOpenedCellRenderer());
+ /*
DefaultListCellRenderer dlcr = new DefaultListCellRenderer();
dlcr.setHorizontalAlignment(DefaultListCellRenderer.RIGHT);
list.setCellRenderer(dlcr);
+ */
list.addMouseListener(new MouseAdapter()
{
layout.putConstraint(SpringLayout.NORTH, scroller, 5,
SpringLayout.NORTH, this);
+ // TODO are we now all using FlatLaf -- check same dimensions for
+ // everyone?
if (Platform.isAMacAndNotJS())
{
- scroller.setPreferredSize(new Dimension(500, 100));
+ scroller.setPreferredSize(new Dimension(280, 100));
}
else
{
- scroller.setPreferredSize(new Dimension(530, 200));
+ scroller.setPreferredSize(new Dimension(500, 200));
}
this.add(scroller);
}
+ class recentlyOpenedCellRenderer extends JLabel
+ implements ListCellRenderer<String>
+ {
+ private final static int maxChars = 46;
+
+ private final static String ellipsis = "...";
+
+ @Override
+ public Component getListCellRendererComponent(
+ JList<? extends String> list, String value, int index,
+ boolean isSelected, boolean cellHasFocus)
+ {
+ String filename = value.toString();
+ String displayFilename;
+ if (filename.length() > maxChars)
+ {
+ StringBuilder displayFileSB = new StringBuilder();
+ File file = new File(filename);
+ displayFileSB.append(file.getName());
+ if (file.getParent() != null)
+ {
+ File parent = file;
+ boolean spaceleft = true;
+ while (spaceleft && parent.getParent() != null)
+ {
+ parent = parent.getParentFile();
+ String name = parent.getName();
+ displayFileSB.insert(0, File.separator);
+ if (displayFileSB.length() + name.length() < maxChars - 1)
+ {
+ displayFileSB.insert(0, name);
+ }
+ else
+ {
+ displayFileSB.insert(0, ellipsis);
+ spaceleft = false;
+ }
+ }
+ if (spaceleft && filename.startsWith(File.separator)
+ && !(displayFileSB.charAt(0) == File.separatorChar))
+ {
+ displayFileSB.insert(0, File.separator);
+ }
+ }
+ displayFilename = displayFileSB.toString();
+ }
+ else
+ {
+ displayFilename = filename;
+ }
+ this.setText(displayFilename.toString());
+ this.setToolTipText(filename);
+ if (isSelected)
+ {
+ setBackground(list.getSelectionBackground());
+ setForeground(list.getSelectionForeground());
+ }
+ else
+ {
+ setBackground(list.getBackground());
+ setForeground(list.getForeground());
+ }
+ this.setHorizontalAlignment(SwingConstants.TRAILING);
+ this.setEnabled(list.isEnabled());
+ this.setFont(list.getFont().deriveFont(12f));
+ this.setOpaque(true);
+ return this;
+ }
+
+ }
+
/*
@Override
public JalviewFileChooser setResponseHandler(Object response,