Bug 8135 fixed: An exception was thrown when restoring files on MacOS X
[scilab.git] / scilab / modules / scinotes / src / java / org / scilab / modules / scinotes / actions / SplitAction.java
index 13f6657..6bd2664 100644 (file)
  */
 package org.scilab.modules.scinotes.actions;
 
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.util.StringTokenizer;
 
 import javax.swing.ButtonGroup;
+import javax.swing.JComponent;
 import javax.swing.JMenu;
 import javax.swing.JRadioButtonMenuItem;
+import javax.swing.JSplitPane;
 import javax.swing.KeyStroke;
 
 import org.scilab.modules.gui.menu.Menu;
@@ -69,7 +73,7 @@ public final class SplitAction extends DefaultAction {
      * @param key KeyStroke
      * @return createMenu
      */
-    public static Menu createMenu(String label, SciNotes editor, KeyStroke key) {
+    public static Menu createMenu(String label, final SciNotes editor, KeyStroke key) {
         StringTokenizer tokens = new StringTokenizer(label, ";");
         String labelSplitView = tokens.nextToken();
         String labelOff = tokens.nextToken();
@@ -82,7 +86,7 @@ public final class SplitAction extends DefaultAction {
 
         ButtonGroup group = new ButtonGroup();
         JRadioButtonMenuItem radio;
-        JRadioButtonMenuItem[] arr = new JRadioButtonMenuItem[3];
+        final JRadioButtonMenuItem[] arr = new JRadioButtonMenuItem[3];
         String[] labels = new String[]{labelOff, labelH, labelV};
 
         for (int i = 0; i < 3; i++) {
@@ -94,6 +98,24 @@ public final class SplitAction extends DefaultAction {
 
         arr[0].setSelected(true);
 
+        ((JMenu) menu.getAsSimpleMenu()).addPropertyChangeListener(new PropertyChangeListener() {
+                public void propertyChange(PropertyChangeEvent e) {
+                    if (editor.getTextPane() != null) {
+                        JComponent c = editor.getTextPane().getParentComponent();
+                        int state = 0;
+                        if (c instanceof JSplitPane) {
+                            JSplitPane split = (JSplitPane) c;
+                            if (split.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
+                                state = 1;
+                            } else {
+                                state = 2;
+                            }
+                        }
+                        arr[state].setSelected(true);
+                    }
+                }
+            });
+
         return menu;
     }