OSDN Git Service

[#32478] Add infotree to the toggle-focus group
[stew/Stew4.git] / src / net / argius / stew / ui / window / WindowLauncher.java
index 523d0b8..5fe4eb5 100644 (file)
@@ -3,7 +3,6 @@ package net.argius.stew.ui.window;
 import static java.awt.event.ActionEvent.ACTION_PERFORMED;
 import static javax.swing.JOptionPane.*;
 import static javax.swing.JSplitPane.VERTICAL_SPLIT;
-import static javax.swing.KeyStroke.getKeyStroke;
 import static javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
 import static javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
 import static net.argius.stew.ui.window.AnyActionKey.*;
@@ -19,7 +18,6 @@ import java.util.Map.Entry;
 import java.util.List;
 import java.util.Timer;
 import java.util.concurrent.*;
-import java.util.regex.*;
 
 import javax.swing.*;
 import javax.swing.event.*;
@@ -28,7 +26,6 @@ import javax.swing.text.*;
 
 import net.argius.stew.*;
 import net.argius.stew.ui.*;
-import net.argius.stew.ui.window.Menu.Item;
 
 /**
  * The Launcher implementation for GUI(Swing).
@@ -46,7 +43,6 @@ public final class WindowLauncher implements
     private final WindowOutputProcessor op;
     private final Menu menu;
     private final JPanel panel1;
-    private final JPanel panel2;
     private final JSplitPane split1;
     private final JSplitPane split2;
     private final ResultSetTable resultSetTable;
@@ -73,7 +69,6 @@ public final class WindowLauncher implements
         this.op = new WindowOutputProcessor(this, resultSetTable, textArea);
         this.menu = new Menu(this);
         this.panel1 = new JPanel(new BorderLayout());
-        this.panel2 = new JPanel(new BorderLayout());
         this.split1 = split1;
         this.split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
         this.resultSetTable = resultSetTable;
@@ -133,12 +128,7 @@ public final class WindowLauncher implements
          * | | scroll(resultSetTable) | |
          * | +------------------------+ |
          * | +------------------------+ |
-         * | | panel2                 | |
-         * | | +--------------------+ | |
-         * | | | scroll(textArea)   | | |
-         * | | +--------------------+ | |
-         * | | | textSearchPanel    | | |
-         * | | +--------------------+ | |
+         * | | scroll(textArea)       | |
          * | +------------------------+ |
          * +----------------------------+
          * when DatabaseInfoTree is visible
@@ -151,6 +141,8 @@ public final class WindowLauncher implements
          * | | | (infoTree) | |            | | |
          * | | +------------+ +------------+ | |
          * | +-------------------------------+ |
+         * | | textSearchPanel               | |
+         * | +-------------------------------+ |
          * +-----------------------------------+
          * | status bar                        |
          * +-----------------------------------+
@@ -160,15 +152,14 @@ public final class WindowLauncher implements
          * | +-------------------------------+ |
          * | | split2                        | |
          * | +-------------------------------+ |
+         * | | textSearchPanel               | |
+         * | +-------------------------------+ |
          * +-----------------------------------+
          * | status bar                        |
          * +-----------------------------------+
          */
-        panel2.add(new JScrollPane(textArea, VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_NEVER),
-                   BorderLayout.CENTER);
-        panel2.add(textSearchPanel, BorderLayout.SOUTH);
         split2.setTopComponent(new JScrollPane(resultSetTable));
-        split2.setBottomComponent(panel2);
+        split2.setBottomComponent(new JScrollPane(textArea, VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_NEVER));
         op.add(panel1, BorderLayout.CENTER);
         op.add(statusBar, BorderLayout.PAGE_END);
         op.setJMenuBar(menu);
@@ -184,12 +175,6 @@ public final class WindowLauncher implements
         // XXX cannot restore config of status-bar at following code
         // statusBar.removePropertyChangeListener(menu);
         // [Events]
-        op.addWindowListener(new WindowAdapter() {
-            @Override
-            public void windowClosing(WindowEvent e) {
-                requestClose();
-            }
-        });
         ContextMenu.create(infoTree, infoTree);
         ContextMenu.create(resultSetTable);
         ContextMenu.create(resultSetTable.getRowHeader(), resultSetTable, "ResultSetTable");
@@ -282,6 +267,8 @@ public final class WindowLauncher implements
                 textSearchPanel.setVisible(true);
             } else if (ev.isAnyOf(toggleFocus)) {
                 if (textArea.isFocusOwner()) {
+                    infoTree.requestFocus();
+                } else if (infoTree.isFocusOwner()) {
                     resultSetTable.requestFocus();
                 } else {
                     textArea.requestFocus();
@@ -380,6 +367,7 @@ public final class WindowLauncher implements
             split1.setBottomComponent(split2);
             panel1.removeAll();
             panel1.add(split1, BorderLayout.CENTER);
+            panel1.add(textSearchPanel, BorderLayout.PAGE_END);
             infoTree.setEnabled(true);
             if (env != null) {
                 try {
@@ -394,12 +382,13 @@ public final class WindowLauncher implements
             infoTree.setEnabled(false);
             panel1.removeAll();
             panel1.add(split2, BorderLayout.CENTER);
+            panel1.add(textSearchPanel, BorderLayout.PAGE_END);
         }
         SwingUtilities.updateComponentTreeUI(op);
     }
 
     private void loadConfiguration() {
-        Configuration cnf = Configuration.load(Bootstrap.getDirectory());
+        Configuration cnf = Configuration.load();
         op.setSize(cnf.getSize());
         op.setLocation(cnf.getLocation());
         split2.setDividerLocation(cnf.getDividerLocation());
@@ -414,7 +403,7 @@ public final class WindowLauncher implements
     }
 
     private void saveConfiguration() {
-        Configuration cnf = Configuration.load(Bootstrap.getDirectory());
+        Configuration cnf = Configuration.load();
         if ((op.getExtendedState() & Frame.MAXIMIZED_BOTH) == 0) {
             // only not maximized
             cnf.setSize(op.getSize());
@@ -439,8 +428,6 @@ public final class WindowLauncher implements
 
         private static final Logger log = Logger.getLogger(Configuration.class);
 
-        private transient File directory;
-
         private Dimension size;
         private Point location;
         private int dividerLocation;
@@ -465,13 +452,9 @@ public final class WindowLauncher implements
             this.postProcessMode = AnyActionKey.postProcessMode.toString();
         }
 
-        void setDirectory(File directory) {
-            this.directory = directory;
-        }
-
         void save() {
-            final File file = getFile(directory);
-            log.debug("save Configuration to: [%s]", file);
+            final File file = getFile();
+            log.debug("save Configuration to: [%s]", file.getAbsolutePath());
             try {
                 XMLEncoder encoder = new XMLEncoder(new FileOutputStream(file));
                 try {
@@ -484,16 +467,14 @@ public final class WindowLauncher implements
             }
         }
 
-        static Configuration load(File directory) {
-            final File file = getFile(directory);
-            log.debug("load Configuration from: [%s]", file);
+        static Configuration load() {
+            final File file = getFile();
+            log.debug("load Configuration from: [%s]", file.getAbsolutePath());
             if (file.exists()) {
                 try {
                     XMLDecoder decoder = new XMLDecoder(new FileInputStream(file));
                     try {
-                        final Configuration instance = (Configuration)decoder.readObject();
-                        instance.setDirectory(directory);
-                        return instance;
+                        return (Configuration)decoder.readObject();
                     } finally {
                         decoder.close();
                     }
@@ -501,14 +482,11 @@ public final class WindowLauncher implements
                     log.warn(ex);
                 }
             }
-            final Configuration instance = new Configuration();
-            instance.setDirectory(directory);
-            return instance;
+            return new Configuration();
         }
 
-        private static File getFile(File systemDirectory) {
-            final File file = new File(systemDirectory, Configuration.class.getName() + ".xml");
-            return file.getAbsoluteFile();
+        private static File getFile() {
+            return Bootstrap.getSystemFile(Configuration.class.getName() + ".xml");
         }
 
         public Dimension getSize() {
@@ -607,37 +585,6 @@ public final class WindowLauncher implements
         op.showErrorDialog(th);
     }
 
-    /**
-     * Changes key binds.
-     * @param keyBindInfos key bind infos (info is String value of KeyStroke)
-     */
-    static void changeKeyBinds(List<String> keyBindInfos) {
-        final Pattern p = Pattern.compile("\\s*([^=\\s]+)\\s*=(.*)");
-        List<String> errorInfos = new ArrayList<String>();
-        for (String s : keyBindInfos) {
-            if (s.trim().length() == 0 || s.matches("\\s*#.*")) {
-                continue;
-            }
-            Matcher m = p.matcher(s);
-            if (m.matches()) {
-                try {
-                    Item item = Item.valueOf(m.group(1));
-                    KeyStroke keyStroke = getKeyStroke(m.group(2));
-                    for (WindowLauncher instance : instances) {
-                        instance.menu.setAccelerator(item, keyStroke);
-                    }
-                } catch (Exception ex) {
-                    errorInfos.add(s);
-                }
-            } else {
-                errorInfos.add(s);
-            }
-        }
-        if (!errorInfos.isEmpty()) {
-            throw new IllegalArgumentException(errorInfos.toString());
-        }
-    }
-
     static void invoke() {
         invoke(new WindowLauncher());
     }
@@ -646,24 +593,6 @@ public final class WindowLauncher implements
         final Environment env = new Environment();
         env.setOutputProcessor(new WindowOutputProcessor.Bypass(instance.op));
         instance.launch(env);
-        // applies key binds
-        try {
-            File keyBindConf = new File(Bootstrap.getDirectory(), "keybind.conf");
-            if (keyBindConf.exists()) {
-                List<String> a = new ArrayList<String>();
-                Scanner scanner = new Scanner(keyBindConf);
-                try {
-                    while (scanner.hasNextLine()) {
-                        a.add(scanner.nextLine());
-                    }
-                } finally {
-                    scanner.close();
-                }
-                changeKeyBinds(a);
-            }
-        } catch (Exception ex) {
-            instance.handleError(ex);
-        }
     }
 
     /**
@@ -785,21 +714,26 @@ public final class WindowLauncher implements
     }
 
     private static void showHelp() {
-        final String htmlFileName = "MANUAL_ja.html";
+        final File localeFile = new File("MANUAL_" + Locale.getDefault().getLanguage() + ".html");
+        final File htmlFile = (localeFile.exists()) ? localeFile : new File("MANUAL.html");
+        boolean wasOpened = false;
         if (Desktop.isDesktopSupported()) {
             Desktop desktop = Desktop.getDesktop();
             if (desktop.isSupported(Desktop.Action.OPEN)) {
-                File file = new File(htmlFileName);
-                if (file.exists()) {
+                if (htmlFile.exists()) {
                     try {
-                        desktop.open(file);
+                        desktop.open(htmlFile);
+                        wasOpened = true;
                     } catch (IOException ex) {
                         throw new RuntimeException(ex);
                     }
                 }
             }
-        } else {
-            final String msg = res.get("e.cannot-open-help-automatically", htmlFileName);
+        }
+        if (!wasOpened) {
+            final String msg = String.format("%s%nfile=%s",
+                                             res.get("e.cannot-open-help-automatically", htmlFile),
+                                             htmlFile.getAbsolutePath());
             WindowOutputProcessor.showInformationMessageDialog(getRootFrame(), msg, "");
         }
     }