Skip to content

Commit

Permalink
synchronized console window status
Browse files Browse the repository at this point in the history
  • Loading branch information
clausnagel committed Jan 9, 2019
1 parent 1fa564b commit b3ddcfa
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 51 deletions.
19 changes: 8 additions & 11 deletions impexp-client/src/main/java/org/citydb/gui/ImpExpGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ public void enableConsoleWindow(boolean enable, boolean resizeMain) {
main.setPreferredSize(new Dimension(width, 1));
splitPane.setDividerLocation(dividerLocation);
}

config.getGui().getConsoleWindow().setDetached(enable);
}

public boolean saveProjectSettings() {
Expand Down Expand Up @@ -654,21 +656,15 @@ private final class ConsolePopupMenuWrapper {
popupMenu.add(detach);

clear.addActionListener(e -> clearConsole());

detach.addActionListener(e -> {
boolean status = !config.getGui().getConsoleWindow().isDetached();
config.getGui().getConsoleWindow().setDetached(status);
enableConsoleWindow(status, true);

detach.setText(!status ? Language.I18N.getString("console.label.detach") :
Language.I18N.getString("console.label.attach"));
});
detach.addActionListener(e -> enableConsoleWindow(!config.getGui().getConsoleWindow().isDetached(), true));

popupMenu.addPopupMenuListener(new PopupMenuListener() {

@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
clear.setEnabled(consoleText.getDocument().getLength() != 0);
detach.setText(config.getGui().getConsoleWindow().isDetached() ?
Language.I18N.getString("console.label.attach") :
Language.I18N.getString("console.label.detach"));
}

@Override
Expand All @@ -687,7 +683,8 @@ public void popupMenuCanceled(PopupMenuEvent e) {
private void doTranslation() {
clear.setText(Language.I18N.getString("main.console.popup.clear"));
detach.setText(config.getGui().getConsoleWindow().isDetached() ?
Language.I18N.getString("console.label.attach") : Language.I18N.getString("console.label.detach"));
Language.I18N.getString("console.label.attach") :
Language.I18N.getString("console.label.detach"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
*/
package org.citydb.gui.components.menubar;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.xml.bind.JAXBContext;

import org.citydb.config.Config;
import org.citydb.config.i18n.Language;
import org.citydb.gui.ImpExpGui;
Expand All @@ -39,6 +35,12 @@
import org.citydb.plugin.PluginManager;
import org.citydb.plugin.extension.menu.MenuExtension;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import javax.xml.bind.JAXBContext;

@SuppressWarnings("serial")
public class MenuBar extends JMenuBar {
private final PluginManager pluginManager;
Expand Down Expand Up @@ -81,6 +83,19 @@ public MenuBar(ImpExpGui mainView, JAXBContext ctx, Config config) {

add(view);
add(help);

view.addMenuListener(new MenuListener() {
@Override
public void menuSelected(MenuEvent e) {
view.update();
}

@Override
public void menuDeselected(MenuEvent e) { }

@Override
public void menuCanceled(MenuEvent e) { }
});
}

public void doTranslation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,19 @@
*/
package org.citydb.gui.components.menubar;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;

import org.citydb.config.Config;
import org.citydb.config.gui.Gui;
import org.citydb.config.i18n.Language;
import org.citydb.gui.ImpExpGui;
import org.citydb.gui.components.mapviewer.MapWindow;
import org.citydb.gui.util.GuiUtil;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import java.util.List;

@SuppressWarnings("serial")
public class MenuView extends JMenu {
private final ImpExpGui mainView;
Expand All @@ -64,37 +61,24 @@ private void init() {
detachConsole.setSelected(config.getGui().getConsoleWindow().isDetached());
defaults = new JMenuItem();

map.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final MapWindow map = MapWindow.getInstance(mainView, config);
map.addActionListener(e -> {
final MapWindow map = MapWindow.getInstance(mainView, config);

SwingUtilities.invokeLater(new Runnable() {
public void run() {
map.setVisible(true);
}
});
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
map.setVisible(true);
}
});
});

detachConsole.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
boolean status = !config.getGui().getConsoleWindow().isDetached();
config.getGui().getConsoleWindow().setDetached(status);
mainView.enableConsoleWindow(status, true);
detachConsole.setSelected(status);
}
});
detachConsole.addActionListener(e -> mainView.enableConsoleWindow(!config.getGui().getConsoleWindow().isDetached(), true));

defaults.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// do not loose recently used projects
List<String> recentlyUsedProjects = config.getGui().getRecentlyUsedProjectFiles();
config.setGui(new Gui());

config.getGui().setRecentlyUsedProjectFiles(recentlyUsedProjects);
detachConsole.setSelected(config.getGui().getConsoleWindow().isDetached());
mainView.restoreDefaults();
}
defaults.addActionListener(e -> {
// do not loose recently used projects
List<String> recentlyUsedProjects = config.getGui().getRecentlyUsedProjectFiles();
config.setGui(new Gui());
config.getGui().setRecentlyUsedProjectFiles(recentlyUsedProjects);
mainView.restoreDefaults();
});

add(map);
Expand All @@ -113,5 +97,9 @@ public void doTranslation() {
GuiUtil.setMnemonic(detachConsole, "menu.view.detach.label", "menu.view.detach.label.mnemonic");
GuiUtil.setMnemonic(defaults, "menu.view.defaults.label", "menu.view.defaults.label.mnemonic");
}

public void update() {
detachConsole.setSelected(config.getGui().getConsoleWindow().isDetached());
}

}

0 comments on commit b3ddcfa

Please sign in to comment.