Skip to content

Commit

Permalink
Refactored some more dialogs
Browse files Browse the repository at this point in the history
Use BrowseAction where possible
Remove unnecessary
  • Loading branch information
Siedlerchr committed Aug 5, 2016
1 parent 93c20e9 commit 003d4e4
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 140 deletions.
11 changes: 9 additions & 2 deletions src/main/java/net/sf/jabref/external/ExternalFileTypeEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -58,6 +59,7 @@
* Editor for external file types.
*/
public class ExternalFileTypeEditor extends JDialog {

private JFrame frame;
private JDialog dialog;
private List<ExternalFileType> fileTypes;
Expand Down Expand Up @@ -111,6 +113,7 @@ private void init() {
dispose();
});
Action cancelAction = new AbstractAction() {

@Override
public void actionPerformed(ActionEvent e) {
dispose();
Expand All @@ -134,9 +137,10 @@ public void actionPerformed(ActionEvent e) {
//}
});

add.addActionListener(e -> {
add.addActionListener(e -> {
// Generate a new file type:
ExternalFileType type = new ExternalFileType("", "", "", "", "new", IconTheme.JabRefIcon.FILE.getSmallIcon());
ExternalFileType type = new ExternalFileType("", "", "", "", "new",
IconTheme.JabRefIcon.FILE.getSmallIcon());
// Show the file type editor:
getEditor(type).setVisible(true);
if (entryEditor.okPressed()) {
Expand Down Expand Up @@ -246,6 +250,7 @@ public static AbstractAction getAction(JDialog dialog) {
return new EditExternalFileTypesAction(dialog);
}


class EditListener implements ActionListener {

@Override
Expand Down Expand Up @@ -276,6 +281,7 @@ public Component getTableCellRendererComponent(JTable tab, Object value, boolean
}

private class FileTypeTableModel extends AbstractTableModel {

@Override
public int getColumnCount() {
return 5;
Expand Down Expand Up @@ -354,6 +360,7 @@ public void mouseReleased(MouseEvent e) {
}

public static class EditExternalFileTypesAction extends MnemonicAwareAction {

private JabRefFrame frame;
private JDialog dialog;
private ExternalFileTypeEditor editor;
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/sf/jabref/gui/FileExtensions.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ public enum FileExtensions {
//importatn: No dot before the extension
BIBTEX_DB(
"BibTeX Database", "bib"),
AUX(
"Aux file", "aux"),
SILVER_PLATTERN(
"SilverPlatter", "dat"),
JSTYLE(
"Style File", "jstyle"),
LAYOUT(
"Custom Layout File", "layout");
"Custom Layout File", "layout"),
XML(
"XML File", "xml");

private final String[] extension;
private final String description;
Expand All @@ -32,6 +36,6 @@ public String getDescription() {
}

public String getFirstExtensionWithDot() {
return "." + extension[0];
return "." + extension[0].trim();
}
}
15 changes: 11 additions & 4 deletions src/main/java/net/sf/jabref/gui/actions/BrowseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;

import javax.swing.AbstractAction;
Expand Down Expand Up @@ -48,18 +49,24 @@ public static BrowseAction buildForDir(JTextField tc) {
}

public static BrowseAction buildForFile(JTextField tc) {

return new BrowseAction(null, tc, false, Collections.emptySet());
}

public static BrowseAction buildForFile(JTextField tc, FileExtensions extensions) {

public static BrowseAction buildForFile(JTextField tc, Set<FileExtensions> extension) {
return new BrowseAction(null, tc, false, extension);
return new BrowseAction(null, tc, false, EnumSet.of(extensions));
}

public static BrowseAction buildForFile(JTextField tc, Set<FileExtensions> extensions) {
return new BrowseAction(null, tc, false, extensions);
}

/* public static BrowseAction buildForFile(JTextField tc, <FileExtensions> extension...) {
return new BrowseAction(null, tc, false, extension);
}*/

private BrowseAction(JFrame frame, JTextField tc, boolean dirsOnly,
Set<FileExtensions> extensions) {
private BrowseAction(JFrame frame, JTextField tc, boolean dirsOnly, Set<FileExtensions> extensions) {
super(Localization.lang("Browse"));
this.frame = frame;
this.dirsOnly = dirsOnly;
Expand Down
53 changes: 15 additions & 38 deletions src/main/java/net/sf/jabref/gui/auximport/FromAuxDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.Collections;

import javax.swing.AbstractAction;
import javax.swing.ActionMap;
Expand All @@ -49,7 +47,6 @@
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
Expand All @@ -60,8 +57,9 @@

import net.sf.jabref.Globals;
import net.sf.jabref.gui.BasePanel;
import net.sf.jabref.gui.FileDialogs;
import net.sf.jabref.gui.FileExtensions;
import net.sf.jabref.gui.JabRefFrame;
import net.sf.jabref.gui.actions.BrowseAction;
import net.sf.jabref.gui.keyboard.KeyBinding;
import net.sf.jabref.logic.auxparser.AuxParser;
import net.sf.jabref.logic.auxparser.AuxParserResult;
Expand All @@ -73,6 +71,7 @@
import com.jgoodies.forms.layout.FormLayout;

public class FromAuxDialog extends JDialog {

private final JPanel statusPanel = new JPanel();
private final JPanel buttons = new JPanel();
private final JButton generateButton = new JButton();
Expand All @@ -95,8 +94,7 @@ public class FromAuxDialog extends JDialog {
private final JabRefFrame parentFrame;


public FromAuxDialog(JabRefFrame frame, String title, boolean modal,
JTabbedPane viewedDBs) {
public FromAuxDialog(JabRefFrame frame, String title, boolean modal, JTabbedPane viewedDBs) {
super(frame, title, modal);

parentTabbedPane = viewedDBs;
Expand Down Expand Up @@ -141,9 +139,11 @@ private void jbInit() {
this.setTitle(Localization.lang("AUX file import"));
JLabel desc = new JLabel("<html><h3>" + Localization.lang("AUX file import") + "</h3><p>"
+ Localization.lang("This feature generates a new database based on which entries "
+ "are needed in an existing LaTeX document.") + "</p>"
+ "<p>" + Localization.lang("You need to select one of your open databases from which to choose "
+ "entries, as well as the AUX file produced by LaTeX when compiling your document.") + "</p></html>");
+ "are needed in an existing LaTeX document.")
+ "</p>" + "<p>"
+ Localization.lang("You need to select one of your open databases from which to choose "
+ "entries, as well as the AUX file produced by LaTeX when compiling your document.")
+ "</p></html>");
desc.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
panel1.add(desc, BorderLayout.NORTH);

Expand All @@ -160,6 +160,7 @@ private void jbInit() {
InputMap im = statusPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
am.put("close", new AbstractAction() {

@Override
public void actionPerformed(ActionEvent e) {
dispose();
Expand All @@ -184,15 +185,15 @@ private void initPanels() {

auxFileField = new JTextField("", 25);
JButton browseAuxFileButton = new JButton(Localization.lang("Browse"));
browseAuxFileButton.addActionListener(new BrowseAction(auxFileField, parentFrame));
browseAuxFileButton.addActionListener(BrowseAction.buildForFile(auxFileField, FileExtensions.AUX));
notFoundList = new JList<>();
JScrollPane listScrollPane = new JScrollPane(notFoundList);
statusInfos = new JTextArea("", 5, 20);
JScrollPane statusScrollPane = new JScrollPane(statusInfos);
statusInfos.setEditable(false);

DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout(
"left:pref, 4dlu, fill:pref:grow, 4dlu, left:pref", ""), buttons);
DefaultFormBuilder b = new DefaultFormBuilder(
new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, left:pref", ""), buttons);
b.appendSeparator(Localization.lang("Options"));
b.append(Localization.lang("Reference database") + ":");
b.append(dbChooser, 3);
Expand All @@ -202,8 +203,8 @@ private void initPanels() {
b.append(browseAuxFileButton);
b.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

b = new DefaultFormBuilder(new FormLayout(
"fill:pref:grow, 4dlu, fill:pref:grow", "pref, pref, fill:pref:grow"), statusPanel);
b = new DefaultFormBuilder(new FormLayout("fill:pref:grow, 4dlu, fill:pref:grow", "pref, pref, fill:pref:grow"),
statusPanel);
b.appendSeparator(Localization.lang("Result"));
b.append(Localization.lang("Unknown BibTeX entries") + ":");
b.append(Localization.lang("Messages") + ":");
Expand Down Expand Up @@ -249,28 +250,4 @@ public BibDatabase getGenerateDB() {
return auxParser.parse().getGeneratedBibDatabase();
}

/**
* Action used to produce a "Browse" button for one of the text fields.
*/
static class BrowseAction extends AbstractAction {
private final JTextField comp;
private final JabRefFrame frame;


public BrowseAction(JTextField tc, JabRefFrame frame) {
super(Localization.lang("Browse"));
this.frame = frame;
comp = tc;
}

@Override
public void actionPerformed(ActionEvent e) {
String chosen = FileDialogs.getNewFile(frame, new File(comp.getText()), Collections.singletonList(".aux"),
JFileChooser.OPEN_DIALOG, false);
if (chosen != null) {
File newFile = new File(chosen);
comp.setText(newFile.getPath());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.EnumSet;

import javax.swing.AbstractAction;
import javax.swing.ActionMap;
Expand Down Expand Up @@ -104,7 +104,7 @@ public CustomExportDialog(final JabRefFrame parent) {
cancel.addActionListener(e -> dispose());

JButton browse = new JButton(Localization.lang("Browse"));
browse.addActionListener(BrowseAction.buildForFile(layoutFile, EnumSet.of(FileExtensions.LAYOUT)));
browse.addActionListener(BrowseAction.buildForFile(layoutFile, FileExtensions.LAYOUT));

AbstractAction cancelAction = new AbstractAction() {

Expand Down
Loading

0 comments on commit 003d4e4

Please sign in to comment.