Skip to content

Commit

Permalink
Fixes #223
Browse files Browse the repository at this point in the history
  • Loading branch information
simonharrer committed Oct 9, 2015
1 parent 0fad359 commit 8fe4c28
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 62 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
- Tweak of preference defaults: Autolink requires that the filename starts with the given BibTeX key and the default filename patterns is key followed by title
- Remove support to the move-to-SysTray action
- Feature: case changers now leave protected areas (enclosed with curly brakets) alone
- Fix #223: Window is displayed in visible area even when having multiple screens
[dev_2.11]
- Backports from 2.80: Fix bug #194: JabRef starts again on Win XP and Win Vista
- Backports from 2.80: Fixes #103: JDialog for auto set links is openend and closed correctly
Expand Down
112 changes: 50 additions & 62 deletions src/main/java/net/sf/jabref/gui/JabRefFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -542,26 +542,62 @@ public void windowClosing(WindowEvent e) {
tlb.setVisible(Globals.prefs.getBoolean(JabRefPreferences.TOOLBAR_VISIBLE));

setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds());
positionWindowOnScreen();

tabbedPane.setBorder(null);
tabbedPane.setForeground(GUIGlobals.inActiveTabbed);

/*
* The following state listener makes sure focus is registered with the
* correct database when the user switches tabs. Without this,
* cut/paste/copy operations would some times occur in the wrong tab.
*/
tabbedPane.addChangeListener(new ChangeListener() {

@Override
public void stateChanged(ChangeEvent e) {
markActiveBasePanel();

BasePanel bp = basePanel();
if (bp != null) {
groupToggle.setSelected(sidePaneManager.isComponentVisible("groups"));
searchToggle.setSelected(sidePaneManager.isComponentVisible("search"));
previewToggle.setSelected(Globals.prefs.getBoolean(JabRefPreferences.PREVIEW_ENABLED));
highlightAny
.setSelected(Globals.prefs.getBoolean(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING_ANY));
highlightAll
.setSelected(Globals.prefs.getBoolean(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING_ALL));
Globals.focusListener.setFocused(bp.mainTable);
setWindowTitle();
// Update search autocompleter with information for the correct database:
bp.updateSearchManager();
// Set correct enabled state for Back and Forward actions:
bp.setBackAndForwardEnabledState();
new FocusRequester(bp.mainTable);
}
}
});

//Note: The registration of Apple event is at the end of initialization, because
//if the events happen too early (ie when the window is not initialized yet), the
//opened (double-clicked) documents are not displayed.
if (OS.OS_X) {
try {
new MacAdapter().registerMacEvents(this);
} catch (Exception e) {
LOGGER.fatal("could not interface with Mac OS X methods", e);
}
}
}

private void positionWindowOnScreen() {
if (!prefs.getBoolean(JabRefPreferences.WINDOW_MAXIMISED)) {

int sizeX = prefs.getInt(JabRefPreferences.SIZE_X);
int sizeY = prefs.getInt(JabRefPreferences.SIZE_Y);
int posX = prefs.getInt(JabRefPreferences.POS_X);
int posY = prefs.getInt(JabRefPreferences.POS_Y);

/*
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
// Get size of each screen
for (int i=0; i<gs.length; i++) {
DisplayMode dm = gs[i].getDisplayMode();
int screenWidth = dm.getWidth();
int screenHeight = dm.getHeight();
System.out.println(gs[i].getDefaultConfiguration().getBounds());
}*/

//
// Fix for [ 1738920 ] Windows Position in Multi-Monitor environment
//
Expand All @@ -570,8 +606,7 @@ public void windowClosing(WindowEvent e) {
// Useful reference: http://www.exampledepot.com/egs/java.awt/screen_ScreenSize.html?l=rel
// googled on forums.java.sun.com graphicsenvironment second screen java
//
if (GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices().length == 1) {

if (GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices().length >= 1) {
Rectangle bounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()[0]
.getDefaultConfiguration().getBounds();
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
Expand All @@ -587,8 +622,6 @@ public void windowClosing(WindowEvent e) {
int height = (int) dim.getHeight();
int width = (int) dim.getWidth();

//if (posX < )

if (posX + sizeX > width) {
if (sizeX <= width) {
posX = width - sizeX;
Expand All @@ -609,51 +642,6 @@ public void windowClosing(WindowEvent e) {
}
setBounds(posX, posY, sizeX, sizeY);
}

tabbedPane.setBorder(null);
tabbedPane.setForeground(GUIGlobals.inActiveTabbed);

/*
* The following state listener makes sure focus is registered with the
* correct database when the user switches tabs. Without this,
* cut/paste/copy operations would some times occur in the wrong tab.
*/
tabbedPane.addChangeListener(new ChangeListener() {

@Override
public void stateChanged(ChangeEvent e) {
markActiveBasePanel();

BasePanel bp = basePanel();
if (bp != null) {
groupToggle.setSelected(sidePaneManager.isComponentVisible("groups"));
searchToggle.setSelected(sidePaneManager.isComponentVisible("search"));
previewToggle.setSelected(Globals.prefs.getBoolean(JabRefPreferences.PREVIEW_ENABLED));
highlightAny
.setSelected(Globals.prefs.getBoolean(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING_ANY));
highlightAll
.setSelected(Globals.prefs.getBoolean(JabRefPreferences.HIGHLIGHT_GROUPS_MATCHING_ALL));
Globals.focusListener.setFocused(bp.mainTable);
setWindowTitle();
// Update search autocompleter with information for the correct database:
bp.updateSearchManager();
// Set correct enabled state for Back and Forward actions:
bp.setBackAndForwardEnabledState();
new FocusRequester(bp.mainTable);
}
}
});

//Note: The registration of Apple event is at the end of initialization, because
//if the events happen too early (ie when the window is not initialized yet), the
//opened (double-clicked) documents are not displayed.
if (OS.OS_X) {
try {
new MacAdapter().registerMacEvents(this);
} catch (Exception e) {
LOGGER.fatal("could not interface with Mac OS X methods", e);
}
}
}

public void setWindowTitle() {
Expand Down

0 comments on commit 8fe4c28

Please sign in to comment.