Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix that swing dialogs are hidden behind main window #4205

Merged
merged 5 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@

public class JabRefGUI {

private static final String NIMBUS_LOOK_AND_FEEL = "javax.swing.plaf.nimbus.NimbusLookAndFeel";
private static final String WINDOWS_LOOK_AND_FEEL = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
private static final String OSX_AQUA_LOOK_AND_FEEL = "apple.laf.AquaLookAndFeel";

private static final Logger LOGGER = LoggerFactory.getLogger(JabRefGUI.class);

private static JabRefFrame mainFrame;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ private void setupActions() {
actions.put(Actions.PREVIOUS_PREVIEW_STYLE, this::previousPreviewStyle);

actions.put(Actions.MANAGE_SELECTORS, () -> {
ContentSelectorDialog csd = new ContentSelectorDialog(null, frame, BasePanel.this, false, null);
ContentSelectorDialog csd = new ContentSelectorDialog(frame, BasePanel.this, false, null);
csd.setVisible(true);
});

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/DuplicateResolverDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import org.jabref.gui.help.HelpAction;
Expand Down Expand Up @@ -46,7 +45,7 @@ public enum DuplicateResolverResult {
private MergeEntries me;

public DuplicateResolverDialog(JabRefFrame frame, BibEntry one, BibEntry two, DuplicateResolverType type) {
super((JFrame) null, Localization.lang("Possible duplicate entries"), true, DuplicateResolverDialog.class);
super(Localization.lang("Possible duplicate entries"), true, DuplicateResolverDialog.class);
this.frame = frame;
init(one, two, type);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/EntryTypeDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class EntryTypeDialog extends JabRefDialog implements ActionListener {

public EntryTypeDialog(JabRefFrame frame) {
// modal dialog
super(null, true, EntryTypeDialog.class);
super(true, EntryTypeDialog.class);

this.frame = frame;

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/jabref/gui/FindUnlinkedFilesDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
Expand Down Expand Up @@ -158,8 +157,8 @@ public class FindUnlinkedFilesDialog extends JabRefDialog {

private boolean checkBoxWhyIsThereNoGetSelectedStupidSwing;

public FindUnlinkedFilesDialog(Frame owner, JabRefFrame frame) {
super(owner, Localization.lang("Find unlinked files"), true, FindUnlinkedFilesDialog.class);
public FindUnlinkedFilesDialog(JabRefFrame frame) {
super(Localization.lang("Find unlinked files"), true, FindUnlinkedFilesDialog.class);
this.frame = frame;

restoreSizeOfDialog();
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/GenFieldsCustomizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
Expand Down Expand Up @@ -51,7 +50,7 @@ public class GenFieldsCustomizer extends JabRefDialog {
private final JButton revert = new JButton();

public GenFieldsCustomizer(JabRefFrame frame) {
super((JFrame) null, Localization.lang("Set general fields"), false, GenFieldsCustomizer.class);
super(Localization.lang("Set general fields"), false, GenFieldsCustomizer.class);
helpBut = new HelpAction(HelpFile.GENERAL_FIELDS).getHelpButton();
jbInit();
setSize(new Dimension(650, 300));
Expand Down
43 changes: 19 additions & 24 deletions src/main/java/org/jabref/gui/JabRefDialog.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
package org.jabref.gui;

import java.awt.Frame;
import java.awt.Window;

import javax.swing.JDialog;

import org.jabref.Globals;

public class JabRefDialog extends JDialog {

public <T extends JabRefDialog> JabRefDialog(Frame owner, boolean modal, Class<T> clazz) {
super(owner, modal);

trackDialogOpening(clazz);
public <T extends JabRefDialog> JabRefDialog(boolean modal, Class<T> clazz) {
this("JabRef", modal, clazz);
}

public <T extends JabRefDialog> JabRefDialog(Class<T> clazz) {
super();

trackDialogOpening(clazz);
this(true, clazz);
}

public <T extends JabRefDialog> JabRefDialog(Frame owner, Class<T> clazz) {
super(owner);

trackDialogOpening(clazz);
public <T extends JabRefDialog> JabRefDialog(String title, Class<T> clazz) {
this(title, true, clazz);
}

public <T extends JabRefDialog> JabRefDialog(Frame owner, String title, Class<T> clazz) {
this(owner, title, true, clazz);
}

public <T extends JabRefDialog> JabRefDialog(Frame owner, String title, boolean modal, Class<T> clazz) {
super(owner, title, modal);
public <T extends JabRefDialog> JabRefDialog(String title, boolean modal, Class<T> clazz) {
super((Frame) null, title, modal);

trackDialogOpening(clazz);
}
Expand All @@ -47,13 +36,19 @@ public <T extends JabRefDialog> JabRefDialog(java.awt.Dialog owner, String titl
trackDialogOpening(clazz);
}

public <T extends JabRefDialog> JabRefDialog(Window owner, String title, Class<T> clazz) {
super(owner, title);

trackDialogOpening(clazz);
}

private <T extends JabRefDialog> void trackDialogOpening(Class<T> clazz) {
Globals.getTelemetryClient().ifPresent(client -> client.trackPageView(clazz.getName()));
}

@Override
public void setVisible(boolean visible) {
super.setVisible(visible);

if (visible) {
// Ugly hack to ensure that new dialogs are not hidden behind the main window
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a FIXME otherwise this will be there forever, I guess.

setAlwaysOnTop(true);
requestFocus();
setAlwaysOnTop(false);
}
}
}
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/MergeDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

import org.jabref.Globals;
Expand Down Expand Up @@ -41,7 +40,7 @@ public class MergeDialog extends JabRefDialog {
private boolean okPressed;

public MergeDialog(JabRefFrame frame, String title, boolean modal) {
super((JFrame) null, title, modal, MergeDialog.class);
super(title, modal, MergeDialog.class);
jbInit();
pack();
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/ReplaceStringDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
Expand Down Expand Up @@ -48,7 +47,7 @@ class ReplaceStringDialog extends JabRefDialog {


public ReplaceStringDialog(JabRefFrame parent) {
super((JFrame) null, Localization.lang("Replace string"), true, ReplaceStringDialog.class);
super(Localization.lang("Replace string"), true, ReplaceStringDialog.class);

ButtonGroup bg = new ButtonGroup();
bg.add(allFi);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/StringDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class StringDialog extends JabRefDialog {


public StringDialog(JabRefFrame frame, BasePanel panel, BibDatabase base) {
super(null, StringDialog.class);
super(StringDialog.class);
this.panel = panel;
this.base = base;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public DatabasePropertiesAction(JabRefFrame frame) {

@Override
public void execute() {
DatabasePropertiesDialog propertiesDialog = new DatabasePropertiesDialog(null, frame.getCurrentBasePanel());
DatabasePropertiesDialog propertiesDialog = new DatabasePropertiesDialog(frame.getCurrentBasePanel());
propertiesDialog.updateEnableStatus();
propertiesDialog.setVisible(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public FindUnlinkedFilesAction(JabRefFrame jabRefFrame) {

@Override
public void execute() {
FindUnlinkedFilesDialog dlg = new FindUnlinkedFilesDialog(null, jabRefFrame);
FindUnlinkedFilesDialog dlg = new FindUnlinkedFilesDialog(jabRefFrame);
dlg.setVisible(true);
}

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/jabref/gui/actions/WriteXMPAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
Expand Down Expand Up @@ -95,7 +94,7 @@ public void init() {
errors = entriesChanged = skipped = 0;

if (optionsDialog == null) {
optionsDialog = new OptionsDialog(null);
optionsDialog = new OptionsDialog();
}
optionsDialog.open();

Expand Down Expand Up @@ -182,9 +181,8 @@ class OptionsDialog extends JabRefDialog {

private final JTextArea progressArea;


public OptionsDialog(JFrame parent) {
super(parent, Localization.lang("Writing XMP-metadata for selected entries..."), false, WriteXMPAction.OptionsDialog.class);
public OptionsDialog() {
super(Localization.lang("Writing XMP-metadata for selected entries..."), false, WriteXMPAction.OptionsDialog.class);
okButton.setEnabled(false);

okButton.addActionListener(e -> dispose());
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/gui/auximport/FromAuxDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
Expand Down Expand Up @@ -69,7 +68,7 @@ public class FromAuxDialog extends JabRefDialog {
private final JabRefFrame parentFrame;

public FromAuxDialog(JabRefFrame frame, String title, boolean modal, TabPane viewedDBs) {
super((JFrame) null, title, modal, FromAuxDialog.class);
super(title, modal, FromAuxDialog.class);

parentTabbedPane = viewedDBs;
parentFrame = frame;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

Expand All @@ -31,7 +30,7 @@ public class BibtexKeyPatternDialog extends JabRefDialog {
private final BibtexKeyPatternPanel bibtexKeyPatternPanel;

public BibtexKeyPatternDialog(BasePanel panel) {
super((JFrame) null, Localization.lang("BibTeX key patterns"), true, BibtexKeyPatternDialog.class);
super(Localization.lang("BibTeX key patterns"), true, BibtexKeyPatternDialog.class);
this.bibtexKeyPatternPanel = new BibtexKeyPatternPanel(panel);
this.panel = panel;
this.metaData = panel.getBibDatabaseContext().getMetaData();
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/org/jabref/gui/collab/ChangeDisplayDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
Expand All @@ -35,10 +34,9 @@ class ChangeDisplayDialog extends JabRefDialog implements TreeSelectionListener
private JComponent infoShown;
private boolean okPressed;


public ChangeDisplayDialog(JFrame owner, final BasePanel panel,
BibDatabase secondary, final DefaultMutableTreeNode root) {
super(owner, Localization.lang("External changes"), true, ChangeDisplayDialog.class);
public ChangeDisplayDialog(final BasePanel panel,
BibDatabase secondary, final DefaultMutableTreeNode root) {
super(Localization.lang("External changes"), true, ChangeDisplayDialog.class);
BibDatabase localSecondary;

// Just to be sure, put in an empty secondary base if none is given:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/collab/ChangeScanner.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static BibEntry bestFit(BibEntry targetEntry, List<BibEntry> entries) {
public void displayResult(final DisplayResultCallback fup) {
if (changes.getChildCount() > 0) {
SwingUtilities.invokeLater(() -> {
ChangeDisplayDialog changeDialog = new ChangeDisplayDialog(null, panel, databaseInTemp.getDatabase(), changes);
ChangeDisplayDialog changeDialog = new ChangeDisplayDialog(panel, databaseInTemp.getDatabase(), changes);
changeDialog.setVisible(true);
fup.scanResultsResolved(changeDialog.isOkPressed());
if (changeDialog.isOkPressed()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
Expand Down Expand Up @@ -82,14 +81,13 @@ public class ContentSelectorDialog extends JabRefDialog {

/**
*
* @param owner the parent Window (Dialog or Frame)
* @param frame the JabRef Frame
* @param panel the currently selected BasePanel
* @param modal should this dialog be modal?
* @param fieldName the field this selector is initialized for. May be null.
*/
public ContentSelectorDialog(Window owner, JabRefFrame frame, BasePanel panel, boolean modal, String fieldName) {
super(owner, Localization.lang("Manage content selectors"), ContentSelectorDialog.class);
public ContentSelectorDialog(JabRefFrame frame, BasePanel panel, boolean modal, String fieldName) {
super(Localization.lang("Manage content selectors"), ContentSelectorDialog.class);
this.setModal(modal);
this.metaData = panel.getBibDatabaseContext().getMetaData();
this.frame = frame;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;
Expand Down Expand Up @@ -75,7 +74,7 @@ public class EntryTypeCustomizationDialog extends JabRefDialog implements ListSe
* Creates a new instance of EntryTypeCustomizationDialog
*/
public EntryTypeCustomizationDialog(JabRefFrame frame) {
super((JFrame) null, Localization.lang("Customize entry types"), false, EntryTypeCustomizationDialog.class);
super(Localization.lang("Customize entry types"), false, EntryTypeCustomizationDialog.class);

this.frame = frame;
initGui();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

Expand Down Expand Up @@ -69,8 +68,8 @@ public class DatabasePropertiesDialog extends JabRefDialog {

private FieldFormatterCleanupsPanel fieldFormatterCleanupsPanel;

public DatabasePropertiesDialog(JFrame parent, BasePanel panel) {
super(parent, Localization.lang("Library properties"), true, DatabasePropertiesDialog.class);
public DatabasePropertiesDialog(BasePanel panel) {
super(Localization.lang("Library properties"), true, DatabasePropertiesDialog.class);
encoding = new JComboBox<>();
encoding.setModel(new DefaultComboBoxModel<>(Encodings.ENCODINGS));
ok = new JButton(Localization.lang("OK"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import javax.swing.InputMap;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
Expand Down Expand Up @@ -57,7 +56,7 @@ public CustomExportDialog(final JabRefFrame parent, final String exporterName, f
}

public CustomExportDialog(final JabRefFrame parent) {
super((JFrame) null, Localization.lang("Edit custom export"), true, CustomExportDialog.class);
super(Localization.lang("Edit custom export"), true, CustomExportDialog.class);
frame = parent;
ActionListener okListener = e -> {
Path layoutFileDir = Paths.get(layoutFile.getText()).getParent();
Expand Down
Loading