• R/O
  • SSH
  • HTTPS

nine: Commit


Commit MetaInfo

Révision59 (tree)
l'heure2009-09-29 07:06:49
Auteurmshio

Message de Log

change how to layout windows (testing)

Change Summary

Modification

--- nine/trunk/src/jp/sourceforge/nine/BufferWindow.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/BufferWindow.java (revision 59)
@@ -25,13 +25,11 @@
2525 import java.awt.BorderLayout;
2626 import java.awt.Color;
2727 import java.awt.Component;
28-import java.awt.Container;
2928 import java.awt.FlowLayout;
3029 import java.awt.GradientPaint;
3130 import java.awt.Graphics;
3231 import java.awt.Graphics2D;
3332 import java.awt.Paint;
34-import java.awt.Point;
3533 import java.awt.event.ActionEvent;
3634 import java.awt.event.ActionListener;
3735 import java.awt.event.ComponentAdapter;
@@ -45,8 +43,6 @@
4543 import javax.swing.JPanel;
4644 import javax.swing.JPopupMenu;
4745 import javax.swing.JScrollPane;
48-import javax.swing.JSplitPane;
49-import javax.swing.JViewport;
5046 import javax.swing.SwingUtilities;
5147 import javax.swing.border.EmptyBorder;
5248 import javax.swing.event.ChangeEvent;
@@ -141,12 +137,15 @@
141137 int l = s.getInsets().left;
142138 int r = s.getInsets().right;
143139 int sw = s.getVerticalScrollBar().getWidth();
144- int rw = NineUtilities.getRootPanel(win).getWidth();
145- int wd = rw - l - r - sw;
146- if (scrollpane.getRowHeader() != null) {
147- wd -= scrollpane.getRowHeader().getWidth();
140+ RootPanel rootPanel = NineUtilities.getRootPanel(win);
141+ if (rootPanel != null) {
142+ int rw = NineUtilities.getRootPanel(win).getWidth();
143+ int wd = rw - l - r - sw;
144+ if (scrollpane.getRowHeader() != null) {
145+ wd -= scrollpane.getRowHeader().getWidth();
146+ }
147+ c.setSize(wd, c.getHeight());
148148 }
149- c.setSize(wd, c.getHeight());
150149 }
151150 });
152151 }
@@ -218,53 +217,14 @@
218217 */
219218 public void split(final MainBufferPane buffer, final int orientation,
220219 final boolean focus) {
221- final Container parent = getParent();
222- final int size = (orientation == VERTICAL_SPLIT) ?
223- getHeight() : getWidth();
224-
220+ int direction = orientation == VERTICAL_SPLIT ? 0 : 1;
221+ final NineLayout.Constraints c = new NineLayout.Constraints(direction, this);
225222 final RootPanel root = NineUtilities.getRootPanel(this);
226223 root.minibuffer().acceptUserInput();
227-
228- final JSplitPane newPane = new JSplitPane(orientation,
229- content.renewWindow(), buffer.getWindow());
230- newPane.setBorder(null);
231-
232- SwingUtilities.invokeLater(new Runnable() {
233- public void run() {
234- if (parent instanceof JPanel) {
235- executeSplit((JPanel) parent, newPane, size);
236- } else if (parent instanceof JSplitPane) {
237- executeSplit((JSplitPane) parent, newPane, size);
238- }
239-
240- copyContentViewPositionTo(buffer);
241- copyContentViewSizeTo(buffer);
242- // TODO:
243-// scrollToMakeCaretVisible();
244-
245- if (focus) { content.requestFocusInWindow(); }
246- root.minibuffer().reset();
247- }
248- });
224+ root.add(buffer.getWindow(), c);
225+ root.minibuffer().reset();
249226 }
250227
251- private void executeSplit(JSplitPane parent, JSplitPane newPane, int size) {
252- int loc = parent.getDividerLocation();
253- if (parent.getRightComponent() == this) {
254- parent.setRightComponent(newPane);
255- } else {
256- parent.setLeftComponent(newPane);
257- }
258- parent.setDividerLocation(loc);
259- newPane.setDividerLocation(size / 2);
260- }
261-
262- private void executeSplit(JPanel parent, JSplitPane newPane, int size) {
263- parent.remove(this);
264- parent.add(newPane, BorderLayout.CENTER);
265- newPane.setDividerLocation(size / 2);
266- }
267-
268228 /**
269229 * Shows a {@code LineNumberView} component, only when
270230 * the buffer window has a buffer of which type is
@@ -286,19 +246,6 @@
286246 }
287247 }
288248
289- private void copyContentViewPositionTo(MainBufferPane m) {
290- Point p = getViewport(content).getViewPosition();
291- getViewport(m).setViewPosition(p);
292- }
293-
294- private void copyContentViewSizeTo(MainBufferPane m) {
295- getViewport(m).setViewSize(getViewport(content).getViewSize());
296- }
297-
298- private JViewport getViewport(MainBufferPane m) {
299- return m.getWindow().getScrollPane().getViewport();
300- }
301-
302249 private MainBufferPane cloneContent() {
303250 BufferInfo info = content.getBufferInfo();
304251 return info.getBufferPane();
--- nine/trunk/src/jp/sourceforge/nine/RootPanel.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/RootPanel.java (revision 59)
@@ -18,8 +18,9 @@
1818 */
1919 package jp.sourceforge.nine;
2020
21-import java.awt.BorderLayout;
21+import java.awt.Component;
2222 import java.awt.Frame;
23+import java.awt.LayoutManager;
2324 import java.awt.Window;
2425
2526 import javax.swing.JPanel;
@@ -26,28 +27,15 @@
2627 import javax.swing.SwingUtilities;
2728
2829 import jp.sourceforge.nine.buffer.BufferManager;
29-import jp.sourceforge.nine.js.FrameSettings;
3030
31-import static java.awt.BorderLayout.CENTER;
32-
3331 public class RootPanel extends JPanel {
3432
3533 private static final long serialVersionUID = -517639066431514619L;
36- private MinibufferPanel minibuffer;
3734 private MainBufferPane currentbuffer;
3835
39- public RootPanel(MainBufferPane bufferPane) {
40- initialize(bufferPane);
41- }
36+ public RootPanel(final MainBufferPane bufferPane) {
37+ setLayout(new NineLayout());
4238
43- private void initialize(MainBufferPane bufferPane) {
44-
45- setLayout(new BorderLayout());
46-
47- String l = FrameSettings.instance.getMinibufferLocation();
48- minibuffer = new MinibufferPanel();
49- add(minibuffer, l);
50-
5139 if (bufferPane == null) {
5240 String nm = BufferManager.SCRATCH_BUFFER_NAME;
5341 currentbuffer = MainTextPane.getNewInstance(nm);
@@ -54,14 +42,19 @@
5442 } else {
5543 currentbuffer = bufferPane;
5644 }
57- add(currentbuffer.getWindow(), CENTER);
5845 BufferManager.getInstance().addBuffer(currentbuffer);
46+ add(currentbuffer.getWindow());
5947
6048 setOpaque(true);
6149 }
6250
6351 public MinibufferPanel minibuffer() {
64- return minibuffer;
52+ MinibufferPanel ret = null;
53+ Window w = SwingUtilities.getWindowAncestor(this);
54+ if (w instanceof NineFrame) {
55+ ret = ((NineFrame) w).getMinibufferPanel();
56+ }
57+ return ret;
6558 }
6659
6760 public MainBufferPane currentBufferPanel() {
@@ -74,12 +67,10 @@
7467 }
7568
7669 public void setMinibufferLocation(final String location) {
77- SwingUtilities.invokeLater(new Runnable() {
78- public void run() {
79- remove(minibuffer);
80- add(minibuffer, location);
81- }
82- });
70+ Window w = SwingUtilities.getWindowAncestor(RootPanel.this);
71+ if (w instanceof NineFrame) {
72+ ((NineFrame) w).moveMinibufferLocation(location);
73+ }
8374 }
8475
8576 private void switchFrameTitle(String bufferName) {
@@ -89,4 +80,16 @@
8980 ((Frame) w).setTitle(t);
9081 }
9182 }
83+
84+ public void replace(Component currentComponent, Component newComponent) {
85+ LayoutManager manager = getLayout();
86+ if (manager instanceof NineLayout) {
87+ NineLayout m = (NineLayout) manager;
88+ m.setReplacing(true);
89+ remove(currentComponent);
90+ add(newComponent);
91+ m.setReplacing(false);
92+ m.replaceLayoutComponent(currentComponent, newComponent);
93+ }
94+ }
9295 }
--- nine/trunk/src/jp/sourceforge/nine/NineFrame.java (nonexistent)
+++ nine/trunk/src/jp/sourceforge/nine/NineFrame.java (revision 59)
@@ -0,0 +1,71 @@
1+/*
2+ * Copyright (C) 2008-2009, mshio <mshio@users.sourceforge.jp>
3+ *
4+ * This program is free software: you can redistribute it and/or
5+ * modify it under the terms of the GNU General Public License
6+ * as published by the Free Software Foundation; either version 2
7+ * of the License, or any later version.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ *
17+ * Require JDK 1.5 (or later)
18+ */
19+
20+package jp.sourceforge.nine;
21+
22+import java.awt.BorderLayout;
23+import java.awt.Container;
24+import java.awt.event.WindowEvent;
25+
26+import javax.swing.JFrame;
27+import javax.swing.SwingUtilities;
28+
29+import jp.sourceforge.nine.js.FrameSettings;
30+
31+public class NineFrame extends JFrame {
32+ private static final long serialVersionUID = -1709487996193137453L;
33+
34+ private final MinibufferPanel minibuffer;
35+
36+ public NineFrame(String caption) {
37+ super(caption);
38+ setDefaultCloseOperation(EXIT_ON_CLOSE);
39+ Container c = getContentPane();
40+ c.setLayout(new BorderLayout());
41+ minibuffer = new MinibufferPanel();
42+ String l = FrameSettings.instance.getMinibufferLocation();
43+ c.add(minibuffer, l);
44+ }
45+
46+ public void setRootPanel(RootPanel rootPanel) {
47+ getContentPane().add(rootPanel, BorderLayout.CENTER);
48+ }
49+
50+ public MinibufferPanel getMinibufferPanel() {
51+ return minibuffer;
52+ }
53+
54+ void moveMinibufferLocation(final String location) {
55+ SwingUtilities.invokeLater(new Runnable() {
56+ public void run() {
57+ remove(minibuffer);
58+ add(minibuffer, location);
59+ }
60+ });
61+ }
62+
63+ @Override
64+ protected void processWindowEvent(WindowEvent e) {
65+ super.processWindowEvent(e);
66+
67+ if (e.getID() == WindowEvent.WINDOW_CLOSING) {
68+ Main.application.deleteFrame(this);
69+ }
70+ }
71+}
--- nine/trunk/src/jp/sourceforge/nine/MinibufferPanel.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/MinibufferPanel.java (revision 59)
@@ -1,8 +1,19 @@
11 /*
22 * Copyright (C) 2008-2009, mshio <mshio@users.sourceforge.jp>
3- * You can redistribute it and/or modify it under GPLv2,
4- * as published by the Free Software Foundation.
53 *
4+ * This program is free software: you can redistribute it and/or
5+ * modify it under the terms of the GNU General Public License
6+ * as published by the Free Software Foundation; either version 2
7+ * of the License, or any later version.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ * ---
617 * Require JDK 1.5 (or later)
718 */
819 package jp.sourceforge.nine;
--- nine/trunk/src/jp/sourceforge/nine/Main.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/Main.java (revision 59)
@@ -18,7 +18,8 @@
1818 */
1919 package jp.sourceforge.nine;
2020
21-import java.awt.event.WindowEvent;
21+import java.awt.Component;
22+import java.awt.event.ActionEvent;
2223 import java.io.File;
2324 import java.lang.reflect.InvocationHandler;
2425 import java.lang.reflect.InvocationTargetException;
@@ -172,17 +173,7 @@
172173 * in this method.
173174 */
174175 public void createFrame(MainBufferPane bufferPane) {
175- JFrame f = new JFrame(APPLICATION_NAME) {
176- private static final long serialVersionUID = 5445261111336818689L;
177-
178- @Override protected void processWindowEvent(WindowEvent e) {
179- super.processWindowEvent(e);
180-
181- if (e.getID() == WindowEvent.WINDOW_CLOSING) {
182- deleteFrame(this);
183- }
184- }
185- };
176+ NineFrame f = new NineFrame(APPLICATION_NAME);
186177 frames.add(f);
187178
188179 if (OS_TYPE == NineUtilities.OS.WINDOWS) {
@@ -189,10 +180,8 @@
189180 changeLookAndFeel(f, WINDOWS_LOOK_AND_FEEL);
190181 }
191182
192- f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
193183 f.setSize(600, 600);
194- f.getContentPane().add(new RootPanel(bufferPane));
195- f.setLocationByPlatform(true);
184+ f.setRootPanel(new RootPanel(bufferPane));
196185 f.setVisible(true);
197186
198187 }
@@ -273,7 +262,18 @@
273262 private void confirmBeforeQuit() {
274263 // TODO
275264 Action a = new SaveBuffersKillNineAction();
276- a.actionPerformed(null); // null ok?
265+ MainBufferPane current = null;
266+ JFrame f = frames.get(0);
267+ Component[] comps = f.getContentPane().getComponents();
268+ for (Component c : comps) {
269+ if (c instanceof RootPanel) {
270+ current = ((RootPanel) c).currentBufferPanel();
271+ }
272+ }
273+ if (current != null) {
274+ ActionEvent e = new ActionEvent(current, ActionEvent.ACTION_PERFORMED, "");
275+ a.actionPerformed(e);
276+ }
277277 }
278278
279279 /**
--- nine/trunk/src/jp/sourceforge/nine/NineLayout.java (nonexistent)
+++ nine/trunk/src/jp/sourceforge/nine/NineLayout.java (revision 59)
@@ -0,0 +1,314 @@
1+/*
2+ * Copyright (C) 2008-2009, mshio <mshio@users.sourceforge.jp>
3+ *
4+ * This program is free software: you can redistribute it and/or
5+ * modify it under the terms of the GNU General Public License
6+ * as published by the Free Software Foundation; either version 2
7+ * of the License, or any later version.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ *
17+ * Require JDK 1.5 (or later)
18+ */
19+
20+package jp.sourceforge.nine;
21+
22+import java.awt.Component;
23+import java.awt.Container;
24+import java.awt.Dimension;
25+import java.awt.LayoutManager2;
26+import java.awt.Point;
27+
28+public class NineLayout implements LayoutManager2 {
29+ // TODO: rename this field...
30+ // This is NOT an instance of jp.sourceforge.nine.RootPanel... Confusing!!
31+ // The Panel object means a metaphor of JPanel or JSplitPane.
32+ // This rootPanel is a root panel of these Panels.
33+ private Panel rootPanel = null;
34+ // LayoutManager do not have a method to replace a specified component.
35+ // Then in order to do it, the app must done remove method first, and
36+ // add method next. But in the remove method, LayoutManager does change
37+ // the component's layout. This flag is not to make such action done.
38+ private boolean replacing = false;
39+
40+ /* (non-Javadoc)
41+ * @see java.awt.LayoutManager2#addLayoutComponent(java.awt.Component, java.lang.Object)
42+ */
43+ public void addLayoutComponent(Component comp, Object constraints) {
44+ if (replacing) { return; }
45+
46+ if (rootPanel == null) {
47+ rootPanel = new SinglePanel(null, comp);
48+ } else if (constraints instanceof Constraints) {
49+ Constraints c = (Constraints) constraints;
50+ if (rootPanel instanceof SinglePanel &&
51+ c.currentComponent == ((SinglePanel) rootPanel).component) {
52+ DoublePanel root = new DoublePanel(null, c.direction);
53+ Panel p0 = new SinglePanel(root, c.currentComponent);
54+ Panel p1 = new SinglePanel(root, comp);
55+ root.add(p0, p1);
56+ rootPanel = root;
57+ } else {
58+ SinglePanel s = searchPanel(rootPanel, c.currentComponent);
59+ if (s != null) {
60+ DoublePanel parent = (DoublePanel) s.parent;
61+ boolean numIsZero = parent.child0 == s;
62+ DoublePanel d = new DoublePanel(parent, c.direction);
63+ Panel p0 = new SinglePanel(d, c.currentComponent);
64+ Panel p1 = new SinglePanel(d, comp);
65+ d.add(p0, p1);
66+ if (numIsZero) {
67+ parent.child0 = d;
68+ } else {
69+ parent.child1 = d;
70+ }
71+ }
72+ }
73+ }
74+ }
75+
76+ private SinglePanel searchPanel(Panel start, Component component) {
77+ Panel p = start;
78+ SinglePanel ret = null;
79+ if (p instanceof SinglePanel) {
80+ SinglePanel s = (SinglePanel) p;
81+ return s.component == component ? s : null;
82+ } else if (p instanceof DoublePanel) {
83+ DoublePanel d = (DoublePanel) p;
84+ ret = searchPanel(d.child0, component);
85+ if (ret == null) {
86+ ret = searchPanel(d.child1, component);
87+ }
88+ }
89+ return ret;
90+ }
91+
92+ /* (non-Javadoc)
93+ * @see java.awt.LayoutManager2#getLayoutAlignmentX(java.awt.Container)
94+ */
95+ public float getLayoutAlignmentX(Container target) {
96+ // TODO Auto-generated method stub
97+ return 0;
98+ }
99+
100+ /* (non-Javadoc)
101+ * @see java.awt.LayoutManager2#getLayoutAlignmentY(java.awt.Container)
102+ */
103+ public float getLayoutAlignmentY(Container target) {
104+ // TODO Auto-generated method stub
105+ return 0;
106+ }
107+
108+ /* (non-Javadoc)
109+ * @see java.awt.LayoutManager2#invalidateLayout(java.awt.Container)
110+ */
111+ public void invalidateLayout(Container target) {
112+ // TODO Auto-generated method stub
113+ }
114+
115+ /* (non-Javadoc)
116+ * @see java.awt.LayoutManager2#maximumLayoutSize(java.awt.Container)
117+ */
118+ public Dimension maximumLayoutSize(Container target) {
119+ // TODO Auto-generated method stub
120+ return null;
121+ }
122+
123+ /* (non-Javadoc)
124+ * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
125+ */
126+ public void addLayoutComponent(String name, Component comp) {
127+ // TODO Auto-generated method stub
128+ }
129+
130+ /* (non-Javadoc)
131+ * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
132+ */
133+ public void layoutContainer(Container parent) {
134+ if (rootPanel == null) { return; }
135+ if (rootPanel instanceof SinglePanel) {
136+ Component c = ((SinglePanel) rootPanel).component;
137+ c.setLocation(0, 0);
138+ c.setSize(parent.getSize());
139+ } else if (rootPanel instanceof DoublePanel) {
140+ layoutPanel((DoublePanel) rootPanel, new Point(0, 0), parent.getSize());
141+ }
142+ }
143+
144+ private void layoutPanel(DoublePanel panel, Point location, Dimension size) {
145+ Panel c0 = panel.child0;
146+ Panel c1 = panel.child1;
147+ int d = panel.direction;
148+ float f = panel.dividerLocation;
149+
150+ // child0
151+ Point p0 = location;
152+ Dimension d0 = (d == 0) ?
153+ new Dimension(size.width, (int) (size.height * f)) :
154+ new Dimension((int) (size.width * f), size.height);
155+
156+ // child1
157+ Point p1;
158+ Dimension d1;
159+ if (d == 0) {
160+ p1 = new Point(p0.x, p0.y + d0.height);
161+ d1 = new Dimension(size.width, size.height - d0.height);
162+ } else {
163+ p1 = new Point(p0.x + d0.width, p0.y);
164+ d1 = new Dimension(size.width - d0.width, size.height);
165+ }
166+
167+ applyLayout(c0, p0, d0);
168+ applyLayout(c1, p1, d1);
169+ }
170+
171+ private void applyLayout(Panel panel, Point location, Dimension size) {
172+ if (panel instanceof SinglePanel) {
173+ Component comp = ((SinglePanel) panel).component;
174+ comp.setLocation(location);
175+ comp.setSize(size);
176+ } else if (panel instanceof DoublePanel) {
177+ layoutPanel((DoublePanel) panel, location, size);
178+ }
179+ }
180+
181+ /* (non-Javadoc)
182+ * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
183+ */
184+ public Dimension minimumLayoutSize(Container parent) {
185+ // TODO Auto-generated method stub
186+ return null;
187+ }
188+
189+ /* (non-Javadoc)
190+ * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
191+ */
192+ public Dimension preferredLayoutSize(Container parent) {
193+ // TODO Auto-generated method stub
194+ return null;
195+ }
196+
197+ /* (non-Javadoc)
198+ * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
199+ */
200+ public void removeLayoutComponent(Component comp) {
201+ if (replacing) { return; }
202+
203+ SinglePanel found = searchPanel(rootPanel, comp);
204+ if (found != null) {
205+ removeComponent(found);
206+ }
207+ }
208+
209+ private void removeComponent(SinglePanel found) {
210+ DoublePanel parent = (DoublePanel) found.parent;
211+ if (parent == null) {
212+ rootPanel = null;
213+ } else {
214+ int childID = parent.child0 == found ? 1 : 0;
215+ Panel child = parent.getChild(childID);
216+ DoublePanel grandparent = (DoublePanel) parent.parent;
217+ if (grandparent == null) {
218+ rootPanel = child;
219+ child.changeParent(null);
220+ } else {
221+ grandparent.replaceChild(grandparent.child0 == parent ? 0 : 1, child);
222+ }
223+
224+ }
225+ }
226+
227+ public void replaceLayoutComponent(Component currentComp, Component newComp) {
228+ newComp.setLocation(currentComp.getLocation());
229+ newComp.setSize(currentComp.getSize());
230+ SinglePanel found = searchPanel(rootPanel, currentComp);
231+
232+ if (found != null) {
233+ SinglePanel newPanel = new SinglePanel(found.parent, newComp);
234+ DoublePanel parent = (DoublePanel) found.parent;
235+ if (parent == null) {
236+ rootPanel = newPanel;
237+ } else {
238+ int childID = parent.child0 == found ? 0 : 1;
239+ if (childID == 0) {
240+ parent.child0 = newPanel;
241+ } else {
242+ parent.child1 = newPanel;
243+ }
244+ }
245+ }
246+ }
247+
248+ public void setReplacing(boolean isReplacing) {
249+ replacing = isReplacing;
250+ }
251+
252+
253+ abstract class Panel {
254+ Panel parent;
255+
256+ Panel(Panel parent) {
257+ this.parent = parent;
258+ }
259+
260+ void changeParent(Panel parent) {
261+ this.parent = parent;
262+ }
263+ }
264+
265+ class SinglePanel extends Panel {
266+ Component component;
267+
268+ SinglePanel(Panel parent, Component component) {
269+ super(parent);
270+ this.component = component;
271+ }
272+ }
273+
274+ class DoublePanel extends Panel {
275+ int direction = 0;
276+ float dividerLocation = 0.5f;
277+ Panel child0;
278+ Panel child1;
279+
280+ DoublePanel(Panel parent, int direction) {
281+ super(parent);
282+ this.direction = direction;
283+ }
284+
285+ void add(Panel child0, Panel child1) {
286+ this.child0 = child0;
287+ this.child1 = child1;
288+ }
289+
290+ Panel getChild(int id) {
291+ return id == 0 ? child0 : id == 1 ? child1 : null;
292+ }
293+
294+ void replaceChild(final int id, final Panel p) {
295+ p.changeParent(this);
296+ if (id == 0) {
297+ child0 = p;
298+ } else if (id == 1) {
299+ child1 = p;
300+ }
301+ }
302+ }
303+
304+
305+ public static class Constraints {
306+ final int direction;
307+ final Component currentComponent;
308+
309+ public Constraints(int direction, Component currentComponent) {
310+ this.direction = direction;
311+ this.currentComponent = currentComponent;
312+ }
313+ }
314+}
--- nine/trunk/src/jp/sourceforge/nine/NineWrappedPlainView.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/NineWrappedPlainView.java (revision 59)
@@ -10,9 +10,11 @@
1010
1111 import java.lang.reflect.InvocationTargetException;
1212 import java.lang.reflect.Method;
13+
1314 import javax.swing.JComponent;
1415 import javax.swing.event.DocumentEvent;
1516 import javax.swing.text.BadLocationException;
17+import javax.swing.text.Caret;
1618 import javax.swing.text.DefaultEditorKit;
1719 import javax.swing.text.Document;
1820 import javax.swing.text.Element;
@@ -29,10 +31,11 @@
2931 private final boolean wordWrap;
3032 private int tabBase;
3133 private Color unselected;
34+ private Color selected;
3235 private boolean widthChanging;
3336 // TODO: how to define this color
3437 private static final Color CONTROL_CHAR_COLOR = Color.decode("#8B0000");
35- private Method drawChars = null;
38+ private Method drawChars = null;
3639
3740 public NineWrappedPlainView(Element element, boolean wordWrap) {
3841 super(element, wordWrap);
@@ -55,6 +58,9 @@
5558 JTextComponent host = (JTextComponent) getContainer();
5659 unselected = (host.isEnabled()) ?
5760 host.getForeground() : host.getDisabledTextColor();
61+ Caret c = host.getCaret();
62+ selected = c.isSelectionVisible() && host.getHighlighter() != null ?
63+ host.getSelectedTextColor() : unselected;
5864 super.paint(g, a);
5965 }
6066
@@ -82,12 +88,21 @@
8288 @Override
8389 protected int drawUnselectedText(Graphics g, int x, int y, int p0, int p1)
8490 throws BadLocationException {
85- int ret = x;
86- g.setColor(unselected);
91+ return drawText(g, x, y, p0, p1, unselected);
92+ }
93+
94+ @Override
95+ protected int drawSelectedText(Graphics g, int x, int y, int p0, int p1)
96+ throws BadLocationException {
97+ return drawText(g, x, y, p0, p1, selected);
98+ }
99+
100+ private int drawText(Graphics g, int x, int y, int p0, int p1, Color c)
101+ throws BadLocationException {
102+ g.setColor(c);
87103 Segment s = new Segment();
88104 getDocument().getText(p0, p1 - p0, s);
89- ret = drawTabbedText(s, x, y, g, p0);
90- return ret;
105+ return drawTabbedText(s, x, y, g, p0);
91106 }
92107
93108 private String getNewlineCode() {
@@ -268,7 +283,7 @@
268283 if (n > 0) {
269284 View[] added = new View[n];
270285 for (int i = 0; i < n; i++) {
271- added[i] = new WrappedLine(e.getElement(i));
286+ added[i] = new NineWrappedLine(e.getElement(i));
272287 }
273288 replace(0, 0, added);
274289 }
@@ -283,7 +298,7 @@
283298 Element[] addedElems = ec.getChildrenAdded();
284299 View[] added = new View[addedElems.length];
285300 for (int i = 0; i < addedElems.length; i++) {
286- added[i] = new WrappedLine(addedElems[i]);
301+ added[i] = new NineWrappedLine(addedElems[i]);
287302 }
288303 replace(ec.getIndex(), removedElems.length, added);
289304
@@ -336,9 +351,9 @@
336351 * state of it's own and sharing the state of the outer class
337352 * with it's sibblings.
338353 */
339- class WrappedLine extends View {
354+ class NineWrappedLine extends View {
340355
341- WrappedLine(Element elem) {
356+ NineWrappedLine(Element elem) {
342357 super(elem);
343358 lineCount = -1;
344359 }
@@ -422,7 +437,7 @@
422437 * @see View#modelToView
423438 */
424439 public Shape modelToView(int pos, Shape a, Position.Bias b)
425- throws BadLocationException {
440+ throws BadLocationException {
426441 Rectangle alloc = a.getBounds();
427442 alloc.height = getFontMetrics().getHeight();
428443 alloc.width = 1;
--- nine/trunk/src/jp/sourceforge/nine/action/MinibufferPopupAction.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/action/MinibufferPopupAction.java (revision 59)
@@ -103,7 +103,7 @@
103103 }
104104 }
105105 return textComponent != null &&
106- rootPanel != null && minibuffer != null;
106+ rootPanel != null && minibuffer != null;
107107 }
108108 }
109109
--- nine/trunk/src/jp/sourceforge/nine/action/PrintBufferAction.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/action/PrintBufferAction.java (revision 59)
@@ -18,6 +18,7 @@
1818 import java.awt.print.Printable;
1919 import java.awt.print.PrinterException;
2020 import java.awt.print.PrinterJob;
21+import java.io.File;
2122 import java.util.LinkedList;
2223
2324 import javax.swing.text.JTextComponent;
@@ -42,7 +43,9 @@
4243 JTextComponent t = getTextComponent(e);
4344 PrinterJob job = PrinterJob.getPrinterJob();
4445 if (t instanceof MainTextPane) {
45- String nm = ((MainTextPane) t).getBufferFile().getName();
46+ MainTextPane textPane = (MainTextPane) t;
47+ File f = textPane.getBufferFile();
48+ String nm = f == null ? textPane.getBufferName() : f.getName();
4649 job.setJobName(nm);
4750 }
4851 PageFormat f0 = new PageFormat();
@@ -89,6 +92,7 @@
8992 Font font = textComponent.getFont();
9093 FontMetrics fm = g.getFontMetrics(font);
9194 g.setFont(font);
95+
9296 int lineHeight = fm.getHeight();
9397
9498 if (ranges.isEmpty()) { makeTextToLineList(g); }
@@ -202,4 +206,5 @@
202206 int startPosition() { return startPosition; }
203207 int endPosition() { return endPosition; }
204208 }
209+
205210 }
--- nine/trunk/src/jp/sourceforge/nine/action/ListBuffersAction.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/action/ListBuffersAction.java (revision 59)
@@ -18,12 +18,12 @@
1818 */
1919 package jp.sourceforge.nine.action;
2020
21-import java.awt.Component;
2221 import java.awt.event.ActionEvent;
2322 import java.io.File;
2423 import java.lang.reflect.Constructor;
2524 import java.lang.reflect.InvocationTargetException;
2625
26+import javax.swing.JComponent;
2727 import javax.swing.JSplitPane;
2828 import javax.swing.SwingUtilities;
2929
@@ -33,7 +33,6 @@
3333 import jp.sourceforge.nine.MainTableData;
3434 import jp.sourceforge.nine.MainTablePane;
3535 import jp.sourceforge.nine.RootPanel;
36-import jp.sourceforge.nine.action.util.BufferSwitcher;
3736 import jp.sourceforge.nine.buffer.BufferManager;
3837 import jp.sourceforge.nine.util.NineUtilities;
3938
@@ -40,6 +39,7 @@
4039 public class ListBuffersAction extends ScriptableTextAction {
4140 private static final long serialVersionUID = 4857774137409224921L;
4241 public static final String ACTION_NAME = "list-buffers";
42+ public static final String BUFFER_NAME = "*Buffer List*";
4343
4444 public ListBuffersAction() {
4545 super(ACTION_NAME);
@@ -47,32 +47,25 @@
4747
4848 @Override
4949 public void perform(ActionEvent e) {
50- final RootPanel p = NineUtilities.getRootPanel(getTextComponent(e));
51- final MainBufferPane mb = p.currentBufferPanel();
52- // TODO:
53- String name = "jp.sourceforge.nine.bufferlist.BufferlistTableData";
54- ClassLoader loader = Main.getPluginClassLoader();
50+ Object o = e.getSource();
51+ final JComponent comp = o instanceof JComponent ? (JComponent) o : null;
52+ // TODO: when this component is null, the app should throw any errors?
53+ if (comp == null) { return; }
54+ final RootPanel rootPanel = NineUtilities.getRootPanel(comp);
55+ final MainBufferPane mb = rootPanel.currentBufferPanel();
56+
5557 try {
56- Class<? extends MainTableData> clazz =
57- Class.forName(name, true, loader).asSubclass(MainTableData.class);
58- Constructor<? extends MainTableData> c =
59- clazz.getConstructor(File.class);
60- MainTableData d = c.newInstance((File) null);
61- BufferManager m = BufferManager.getInstance();
62- String nm = "*Buffer List*";
63- m.removeBuffer(nm);
64- final MainTablePane t = MainTablePane.getInstance(nm, null, d);
65- m.addBuffer(t);
58+ MainTableData data = getBufferListTableData();
59+ BufferManager manager = BufferManager.getInstance();
60+ manager.removeBuffer(BUFFER_NAME);
61+ final MainTablePane table = MainTablePane.getInstance(BUFFER_NAME, null, data);
62+ manager.addBuffer(table);
6663 SwingUtilities.invokeLater(new Runnable() {
6764 public void run() {
68- p.minibuffer().acceptUserInput();
69- switchBuffer(p, t);
70- SwingUtilities.invokeLater(new Runnable() {
71- public void run() {
72- p.minibuffer().reset();
73- mb.requestFocusInWindow();
74- }
75- });
65+ rootPanel.minibuffer().acceptUserInput();
66+ showBuffer(rootPanel, table);
67+ rootPanel.minibuffer().reset();
68+ mb.requestFocusInWindow();
7669 }
7770 });
7871 } catch (ClassNotFoundException ex) {
@@ -93,23 +86,25 @@
9386 }
9487 }
9588
96- private void switchBuffer(final RootPanel rootPanel,
89+ private MainTableData getBufferListTableData()
90+ throws ClassNotFoundException, SecurityException, NoSuchMethodException,
91+ IllegalArgumentException, InstantiationException,
92+ IllegalAccessException, InvocationTargetException {
93+ // TODO: how to get the name of table data class of buffer list plugin.
94+ String name = "jp.sourceforge.nine.bufferlist.BufferlistTableData";
95+ ClassLoader loader = Main.getPluginClassLoader();
96+ Class<? extends MainTableData> clazz =
97+ Class.forName(name, true, loader).asSubclass(MainTableData.class);
98+ Constructor<? extends MainTableData> c = clazz.getConstructor(File.class);
99+ return c.newInstance((File) null);
100+ }
101+
102+ private void showBuffer(final RootPanel rootPanel,
97103 final MainTablePane tablePane) {
98104
99105 BufferWindow w = rootPanel.currentBufferPanel().getWindow();
100- if (w.getParent() instanceof JSplitPane) {
101- execute(rootPanel, tablePane);
102- } else {
103- w.split(tablePane, JSplitPane.VERTICAL_SPLIT, false);
104- }
106+ // TODO: when already having a splitted window,
107+ // the app should replace its contents into buffer list.
108+ w.split(tablePane, JSplitPane.VERTICAL_SPLIT, false);
105109 }
106-
107- private void execute(RootPanel root, MainBufferPane requestedBuffer) {
108- Component n = NineUtilities.getNextComponent(root);
109-
110- if (n instanceof MainBufferPane) {
111- Runnable r = new BufferSwitcher(requestedBuffer, (MainBufferPane) n, false);
112- SwingUtilities.invokeLater(r);
113- }
114- }
115110 }
--- nine/trunk/src/jp/sourceforge/nine/action/util/BufferSwitcher.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/action/util/BufferSwitcher.java (revision 59)
@@ -18,13 +18,7 @@
1818 */
1919 package jp.sourceforge.nine.action.util;
2020
21-import java.awt.BorderLayout;
22-import java.awt.Container;
23-import java.awt.Dimension;
24-
2521 import javax.swing.JComponent;
26-import javax.swing.JPanel;
27-import javax.swing.JSplitPane;
2822 import javax.swing.SwingUtilities;
2923
3024 import jp.sourceforge.nine.BufferWindow;
@@ -63,36 +57,10 @@
6357 }
6458
6559 public void run() {
66- BufferWindow bp = bufferToBeReplaced.getWindow();
67- Container p = bp.getParent();
60+ final BufferWindow bp = bufferToBeReplaced.getWindow();
6861
69- // User focus could escap here...
7062 rootPanel.minibuffer().acceptUserInput();
71-
72- if (p instanceof JPanel) {
73- p.remove(bp);
74- p.add(bufferPane.getWindow(), BorderLayout.CENTER);
75- } else if (p instanceof JSplitPane) {
76- final JSplitPane splitter = (JSplitPane) p;
77- BufferWindow toBeReplaced = bufferToBeReplaced.getWindow();
78-
79- final int loc = splitter.getDividerLocation();
80- Dimension d = toBeReplaced.getSize();
81- boolean right = splitter.getRightComponent() == toBeReplaced;
82- bufferPane.getWindow().setSize(d);
83- if (right) {
84- splitter.setRightComponent(bufferPane.getWindow());
85- } else {
86- splitter.setLeftComponent(bufferPane.getWindow());
87- }
88- splitter.setDividerLocation(loc);
89- SwingUtilities.invokeLater(new Runnable() {
90- public void run() {
91- splitter.setDividerLocation(loc);
92- }
93- });
94- }
95-
63+ rootPanel.replace(bp, bufferPane.getWindow());
9664 rootPanel.minibuffer().reset();
9765
9866 SwingUtilities.invokeLater(new Runnable() {
--- nine/trunk/src/jp/sourceforge/nine/action/util/KillBufferCommand.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/action/util/KillBufferCommand.java (revision 59)
@@ -1,8 +1,19 @@
11 /*
22 * Copyright (C) 2008-2009, mshio <mshio@users.sourceforge.jp>
3- * You can redistribute it and/or modify it under GPLv2,
4- * as published by the Free Software Foundation.
53 *
4+ * This program is free software: you can redistribute it and/or
5+ * modify it under the terms of the GNU General Public License
6+ * as published by the Free Software Foundation; either version 2
7+ * of the License, or any later version.
8+ *
9+ * This program is distributed in the hope that it will be useful,
10+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ * GNU General Public License for more details.
13+ *
14+ * You should have received a copy of the GNU General Public License
15+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
16+ * ---
617 * Require JDK 1.5 (or later)
718 */
819 package jp.sourceforge.nine.action.util;
@@ -9,9 +20,12 @@
920
1021 import java.awt.Component;
1122 import java.awt.Container;
23+import java.awt.Dimension;
24+import java.awt.Point;
1225
1326 import javax.swing.SwingUtilities;
1427
28+import jp.sourceforge.nine.BufferWindow;
1529 import jp.sourceforge.nine.MainBufferPane;
1630 import jp.sourceforge.nine.MinibufferPanel;
1731 import jp.sourceforge.nine.RootPanel;
@@ -20,12 +34,11 @@
2034 public class KillBufferCommand implements Command<Void> {
2135 final String bufferName;
2236 final RootPanel rootPanel;
23- boolean minibufferReset = true;
24- boolean requestFocus = true;
37+ final boolean minibufferReset;
38+ final boolean requestFocus;
2539
2640 public KillBufferCommand(String bufferName, RootPanel rootPanel) {
27- this.bufferName = bufferName;
28- this.rootPanel = rootPanel;
41+ this(bufferName, rootPanel, true, true);
2942 }
3043
3144 public KillBufferCommand(String bufferName, RootPanel rootPanel,
@@ -47,27 +60,20 @@
4760 }
4861 if (next.equals("*Buffer List*")) { next = bm.peekInBuffer(1); }
4962
50- MainBufferPane nextBuffer = bm.getBuffer(next);
51- if (requestFocus) {
52- SwingUtilities.invokeLater(new BufferSwitcher(rootPanel, nextBuffer));
63+ final Point current = getCurrentBufferLocation();
64+ switchBuffer(rootPanel, rootPanel, bufferName, next);
65+ if (! bufferName.equals(BufferManager.SCRATCH_BUFFER_NAME)) {
66+ bm.removeBuffer(bufferName);
5367 }
54- final String nextBufferName = next;
5568 SwingUtilities.invokeLater(new Runnable() {
5669 public void run() {
57- switchBuffer(rootPanel, rootPanel, bufferName, nextBufferName);
58- if (! bufferName.equals(BufferManager.SCRATCH_BUFFER_NAME)) {
59- bm.removeBuffer(bufferName);
60- }
61- if (minibufferReset) {
62- MinibufferPanel m = rootPanel.minibuffer();
63- m.reset();
64- m.setTextToLabel(" ");
65- }
6670 if (requestFocus) {
67- MainBufferPane b = rootPanel.currentBufferPanel();
68- b.requestFocusInWindow();
69- b.getWindow().repaint();
71+ Component c = rootPanel.getComponentAt(current);
72+ if (c instanceof BufferWindow) {
73+ ((BufferWindow) c).getContent().requestFocusInWindow();
74+ }
7075 }
76+ if (minibufferReset) { rootPanel.minibuffer().reset(); }
7177 }
7278 });
7379
@@ -74,6 +80,13 @@
7480 return null;
7581 }
7682
83+ private Point getCurrentBufferLocation() {
84+ BufferWindow w = rootPanel.currentBufferPanel().getWindow();
85+ Point point = w.getLocation();
86+ Dimension size = w.getSize();
87+ return new Point(point.x + size.width / 2, point.y + size.height / 2);
88+ }
89+
7790 private void processLastBuffer() {
7891 if (requestFocus) {
7992 rootPanel.currentBufferPanel().requestFocusInWindow();
@@ -81,11 +94,10 @@
8194 if (minibufferReset) {
8295 MinibufferPanel m = rootPanel.minibuffer();
8396 m.reset();
84- m.setTextToLabel(" ");
8597 }
8698 }
8799
88- private void switchBuffer(RootPanel root, Container container,
100+ private void switchBuffer(final RootPanel root, Container container,
89101 String current, String next) {
90102 Component[] his = container.getComponents();
91103 if (his == null) return;
@@ -96,8 +108,9 @@
96108 if (something instanceof MainBufferPane) {
97109 MainBufferPane finding = (MainBufferPane) something;
98110 if (finding.getBufferName().equals(current)) {
111+ final MainBufferPane buffer = bm.getBuffer(next);
99112 Runnable r =
100- new BufferSwitcher(bm.getBuffer(next), finding, false);
113+ new BufferSwitcher(buffer, finding, false);
101114 SwingUtilities.invokeLater(r);
102115 }
103116 } else if (something instanceof Container) {
--- nine/trunk/src/jp/sourceforge/nine/action/DeleteOtherWindowsAction.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/action/DeleteOtherWindowsAction.java (revision 59)
@@ -18,18 +18,12 @@
1818 */
1919 package jp.sourceforge.nine.action;
2020
21-import java.awt.BorderLayout;
2221 import java.awt.Component;
2322 import java.awt.event.ActionEvent;
2423
2524 import javax.swing.JComponent;
26-import javax.swing.JSplitPane;
2725 import javax.swing.SwingUtilities;
28-import javax.swing.text.BadLocationException;
29-import javax.swing.text.JTextComponent;
3026
31-import jp.sourceforge.nine.MainBufferPane;
32-import jp.sourceforge.nine.BufferWindow;
3327 import jp.sourceforge.nine.RootPanel;
3428 import jp.sourceforge.nine.util.NineUtilities;
3529
@@ -42,7 +36,6 @@
4236 * @author mshio
4337 */
4438 public class DeleteOtherWindowsAction extends ScriptableTextAction {
45-
4639 private static final long serialVersionUID = -5407099002160023082L;
4740 public static final String ACTION_NAME = "delete-other-windows";
4841
@@ -59,42 +52,19 @@
5952 * @param e the action event
6053 */
6154 @Override
62- public void perform(ActionEvent e) {
63- Object o = e.getSource();
64- RootPanel root = NineUtilities.getRootPanel((JComponent) o);
65- SwingUtilities.invokeLater(new OtherWindowsDeleter(root));
66- }
67-}
68-
69-
70-class OtherWindowsDeleter implements Runnable {
71- RootPanel root;
72- OtherWindowsDeleter(RootPanel root) {
73- this.root = root;
74- }
75-
76- public void run() {
77- for (Component c : root.getComponents()) {
78- if (c instanceof BufferWindow || c instanceof JSplitPane) {
79- root.remove(c);
80- break;
81- }
82- }
83- final MainBufferPane m = root.currentBufferPanel();
84- root.minibuffer().acceptUserInput();
85- root.add(m.getWindow(), BorderLayout.CENTER);
86- if (m instanceof JTextComponent) {
87- JTextComponent t = (JTextComponent)m;
88- try {
89- t.scrollRectToVisible(t.modelToView(t.getCaretPosition()));
90- } catch (BadLocationException e) {
91- e.printStackTrace();
92- }
93- }
94- root.minibuffer().reset();
55+ public void perform(final ActionEvent e) {
56+ final Object o = e.getSource();
57+ final RootPanel rootPanel = NineUtilities.getRootPanel((JComponent) o);
58+ rootPanel.minibuffer().acceptUserInput();
9559 SwingUtilities.invokeLater(new Runnable() {
9660 public void run() {
97- m.requestFocusInWindow();
61+ final Component[] components = rootPanel.getComponents();
62+ for (final Component c : components) {
63+ rootPanel.remove(c);
64+ }
65+ rootPanel.add(rootPanel.currentBufferPanel().getWindow());
66+ rootPanel.repaint();
67+ rootPanel.minibuffer().reset();
9868 }
9969 });
10070 }
--- nine/trunk/src/jp/sourceforge/nine/action/DeleteWindowAction.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/action/DeleteWindowAction.java (revision 59)
@@ -18,21 +18,15 @@
1818 */
1919 package jp.sourceforge.nine.action;
2020
21-import java.awt.Component;
22-import java.awt.Container;
2321 import java.awt.event.ActionEvent;
2422
2523 import javax.swing.JComponent;
26-import javax.swing.JSplitPane;
2724
28-import jp.sourceforge.nine.BufferWindow;
2925 import jp.sourceforge.nine.MainBufferPane;
3026 import jp.sourceforge.nine.RootPanel;
3127 import jp.sourceforge.nine.util.MessageUtility;
3228 import jp.sourceforge.nine.util.NineUtilities;
3329
34-import static javax.swing.SwingUtilities.invokeLater;
35-
3630 /**
3731 * An action to delete the selected window.
3832 *
@@ -50,17 +44,19 @@
5044
5145 @Override
5246 public void perform(ActionEvent e) {
53- JComponent c = getTextComponent(e);
47+ Object o = e.getSource();
48+ JComponent c = o instanceof JComponent ? (JComponent) o : null;
5449 if (c != null) {
5550 final RootPanel r = NineUtilities.getRootPanel(c);
5651 final MainBufferPane current = r.currentBufferPanel();
57- final Container parent = current.getWindow().getParent();
58- if (parent instanceof JSplitPane) {
59- Runnable run = new WindowDeleter(current, (JSplitPane) parent);
60- invokeLater(run);
61- invokeLater(new Runnable() { public void run() { r.repaint(); } });
52+
53+ if (r.getComponentCount() == 1) {
54+ showCannotDeleteMessage(r);
6255 } else {
63- showCannotDeleteMessage(r);
56+ r.minibuffer().acceptUserInput();
57+ r.remove(current.getWindow());
58+ r.repaint();
59+ r.minibuffer().reset();
6460 }
6561 }
6662 }
@@ -71,71 +67,4 @@
7167 root.minibuffer().reset(s);
7268 }
7369
74-
75- static class WindowDeleter implements Runnable {
76- final JSplitPane splitPane;
77- final MainBufferPane currentPane;
78-
79- WindowDeleter(MainBufferPane current, JSplitPane splitPane) {
80- this.splitPane = splitPane;
81- this.currentPane = current;
82- }
83-
84- public void run() {
85- final Component other = getOtherComponent();
86- final RootPanel root = NineUtilities.getRootPanel(splitPane);
87- root.minibuffer().acceptUserInput();
88- // usually, other is an instance of buffer window.
89- if (other instanceof BufferWindow) {
90- deleteWhenOtherIsWindow(root, (BufferWindow) other);
91- } else if (other instanceof JSplitPane) {
92- deleteWhenOtherIsSplit(root, (JSplitPane) other);
93- }
94- }
95-
96- private void deleteWhenOtherIsWindow(final RootPanel root, BufferWindow other) {
97- splitPane.remove(currentPane.getWindow());
98- final Container pane = splitPane.getParent();
99- final boolean isSplitPane = pane instanceof JSplitPane;
100- final JSplitPane split = isSplitPane ? (JSplitPane) pane : null;
101- final int location = isSplitPane ? split.getDividerLocation() : 0;
102- pane.remove(splitPane);
103- pane.add(other);
104- if (isSplitPane) { split.setDividerLocation(location); }
105- final MainBufferPane next = other.getContent();
106- invokeLater(new Runnable() {
107- public void run() {
108- root.setCurrentBufferPanel(next);
109- root.minibuffer().reset();
110- invokeLater(new Runnable() {
111- public void run() { next.requestFocusInWindow(); }
112- });
113- }
114- });
115- }
116-
117- private void deleteWhenOtherIsSplit(RootPanel root, JSplitPane other) {
118- final Component next = NineUtilities.getNextComponent(root);
119- Container parent = splitPane.getParent();
120- parent.remove(splitPane);
121- parent.add(other);
122- invokeLater(new Runnable() {
123- public void run() { next.requestFocusInWindow(); }
124- });
125- }
126-
127- /**
128- * Returns a component which is not a deleting window
129- * on the split pane.
130- * @return component which is not a deleting window
131- */
132- private Component getOtherComponent() {
133- Component other = splitPane.getTopComponent();
134- if (other == currentPane.getWindow()) {
135- other = splitPane.getBottomComponent();
136- }
137- return other;
138- }
139- }
140-
14170 }
--- nine/trunk/src/jp/sourceforge/nine/action/NineMinibufferAction.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/action/NineMinibufferAction.java (revision 59)
@@ -23,7 +23,7 @@
2323
2424 import javax.swing.Action;
2525 import javax.swing.ActionMap;
26-import javax.swing.text.JTextComponent;
26+import javax.swing.JComponent;
2727
2828 import jp.sourceforge.nine.MinibufferPanel;
2929 import jp.sourceforge.nine.RootPanel;
@@ -127,9 +127,11 @@
127127 }
128128
129129 private RootPanel getRootPanel(ActionEvent e) {
130- // This text component means the minibuffer.
131- JTextComponent t = getTextComponent(e);
132- return rootPanel = t == null ? null : NineUtilities.getRootPanel(t);
130+ Object o = e.getSource();
131+ if (o instanceof JComponent) {
132+ return rootPanel = NineUtilities.getRootPanel((JComponent) o);
133+ }
134+ return rootPanel = null;
133135 }
134136
135137 private MinibufferPanel getMinibufferPanel(ActionEvent e) {
@@ -136,9 +138,4 @@
136138 RootPanel r = getRootPanel(e);
137139 return r == null ? null : r.minibuffer();
138140 }
139-
140-
141-// @Retention(RetentionPolicy.RUNTIME)
142-// @Target(ElementType.FIELD)
143-// protected @interface PromptLabelKey { }
144141 }
--- nine/trunk/src/jp/sourceforge/nine/action/FindFileSuggestionAction.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/action/FindFileSuggestionAction.java (revision 59)
@@ -44,7 +44,6 @@
4444 * unlike original Emacs, as the need arises.
4545 */
4646 public class FindFileSuggestionAction extends MinibufferPopupAction {
47-
4847 private static final long serialVersionUID = 4143362895935712636L;
4948
5049 private FindFileSuggestionPopup popup = null;
@@ -54,9 +53,7 @@
5453 if (! p.initialize(e)) { return; }
5554 String text = p.minibuffer.getTextFromInputArea();
5655 if (text == null) { return; }
57-
5856 if (expandVariables(text, p.minibuffer)) { return; }
59-
6057 int sep = text.lastIndexOf(File.separatorChar);
6158 if (sep != -1) {
6259 suggest(text, sep, p);
--- nine/trunk/src/jp/sourceforge/nine/util/NineUtilities.java (revision 58)
+++ nine/trunk/src/jp/sourceforge/nine/util/NineUtilities.java (revision 59)
@@ -24,6 +24,7 @@
2424 import java.awt.FocusTraversalPolicy;
2525 import java.awt.GraphicsEnvironment;
2626 import java.awt.Rectangle;
27+import java.awt.Window;
2728 import java.io.BufferedReader;
2829 import java.io.File;
2930 import java.io.FileNotFoundException;
@@ -36,10 +37,12 @@
3637 import javax.swing.Icon;
3738 import javax.swing.ImageIcon;
3839 import javax.swing.JComponent;
40+import javax.swing.JFrame;
3941 import javax.swing.SwingUtilities;
4042 import javax.swing.UIManager;
4143
4244 import jp.sourceforge.nine.MainBufferPane;
45+import jp.sourceforge.nine.MinibufferPanel;
4346 import jp.sourceforge.nine.RootPanel;
4447 import jp.sourceforge.nine.js.FrameSettings;
4548
@@ -63,10 +66,28 @@
6366 */
6467 public static RootPanel getRootPanel(JComponent component) {
6568 Container c = component.getParent();
69+ if (c == null) { return null; }
6670 do {
67- if (c instanceof RootPanel) return (RootPanel)c;
71+ if (c instanceof RootPanel) {
72+ return (RootPanel) c;
73+ } else if (c instanceof MinibufferPanel) {
74+ return getRootPanelFromMinibuffer((MinibufferPanel) c);
75+ }
6876 } while ((c = c.getParent()) != null);
77+ return null;
78+ }
6979
80+ private static RootPanel getRootPanelFromMinibuffer(MinibufferPanel minibuffer) {
81+ Window w = SwingUtilities.getWindowAncestor(minibuffer);
82+ if (w instanceof JFrame) {
83+ Container container = ((JFrame) w).getContentPane();
84+ Component[] comp = container.getComponents();
85+ for (Component c : comp) {
86+ if (c instanceof RootPanel) {
87+ return (RootPanel) c;
88+ }
89+ }
90+ }
7091 return null;
7192 }
7293
--- nine/trunk/site-js/dired/dired.js (revision 58)
+++ nine/trunk/site-js/dired/dired.js (revision 59)
@@ -55,6 +55,7 @@
5555 'split-window-vertically': text['split-window-vertically'],
5656 'split-window-horizontally': text['split-window-horizontally'],
5757 'delete-other-windows': text['delete-other-windows'],
58+ 'delete-window': text['delete-window'],
5859 'other-window': text['other-window'],
5960 'kill-buffer': text['kill-buffer'],
6061 'execute-extended-command': text['execute-extended-command'],
Afficher sur ancien navigateur de dépôt.