Nuiton-widgets-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- 163 discussions
Author: sletellier
Date: 2010-11-17 22:27:09 +0100 (Wed, 17 Nov 2010)
New Revision: 299
Url: http://nuiton.org/repositories/revision/nuiton-widgets/299
Log:
Add consistant dependencies
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-11-12 08:33:18 UTC (rev 298)
+++ trunk/pom.xml 2010-11-17 21:27:09 UTC (rev 299)
@@ -81,6 +81,24 @@
<artifactId>commons-lang</artifactId>
</dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.activation</groupId>
+ <artifactId>activation</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+
</dependencies>
<!-- ************************************************************* -->
1
0
12 Nov '10
Author: sletellier
Date: 2010-11-12 09:33:18 +0100 (Fri, 12 Nov 2010)
New Revision: 298
Url: http://nuiton.org/repositories/revision/nuiton-widgets/298
Log:
Update headers
Modified:
trunk/src/main/java/org/nuiton/widget/SwingSession.java
trunk/src/main/java/org/nuiton/widget/editor/SDocEditor.java
Modified: trunk/src/main/java/org/nuiton/widget/SwingSession.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/SwingSession.java 2010-11-09 16:38:36 UTC (rev 297)
+++ trunk/src/main/java/org/nuiton/widget/SwingSession.java 2010-11-12 08:33:18 UTC (rev 298)
@@ -1,3 +1,27 @@
+/*
+ * #%L
+ * Graphical Widget
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2004 - 2010 CodeLutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
package org.nuiton.widget;
Modified: trunk/src/main/java/org/nuiton/widget/editor/SDocEditor.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/editor/SDocEditor.java 2010-11-09 16:38:36 UTC (rev 297)
+++ trunk/src/main/java/org/nuiton/widget/editor/SDocEditor.java 2010-11-12 08:33:18 UTC (rev 298)
@@ -8,16 +8,16 @@
* Copyright (C) 2004 - 2010 CodeLutin
* %%
* This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation, either version 3 of the
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
- *
- * You should have received a copy of the GNU General Lesser Public
+ *
+ * You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%
1
0
Author: sletellier
Date: 2010-11-09 17:38:36 +0100 (Tue, 09 Nov 2010)
New Revision: 297
Url: http://nuiton.org/repositories/revision/nuiton-widgets/297
Log:
#1022 SwingSession dont keep maximized frame
Modified:
trunk/src/main/java/org/nuiton/widget/SwingSession.java
Modified: trunk/src/main/java/org/nuiton/widget/SwingSession.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/SwingSession.java 2010-11-09 11:39:40 UTC (rev 296)
+++ trunk/src/main/java/org/nuiton/widget/SwingSession.java 2010-11-09 16:38:36 UTC (rev 297)
@@ -668,15 +668,17 @@
GraphicsConfiguration gc = c.getGraphicsConfiguration();
Rectangle gcBounds = (gc == null) ? null : gc.getBounds();
Rectangle frameBounds = c.getBounds();
+
/* If this is a JFrame created by FrameView and it's been maximized,
* retrieve the frame's normal (not maximized) bounds. More info:
* see FrameStateListener#windowStateChanged in FrameView.
*/
if ((c instanceof JFrame) && (0 != (frameState & Frame.MAXIMIZED_BOTH))) {
- frameBounds = getWindowNormalBounds((JFrame) c);
+ frameBounds = getWindowNormalBounds(c);
}
+
WindowState result = null;
- if (!frameBounds.isEmpty()) {
+ if (frameBounds != null && !frameBounds.isEmpty()) {
result = new WindowState();
result.setBounds(frameBounds);
result.setGcBounds(gcBounds);
@@ -705,11 +707,10 @@
w.setSize(windowState.getBounds().getSize());
}
}
- if (w instanceof Frame) {
- ((Frame) w).setExtendedState(windowState.getFrameState());
-
- }
}
+ if (w instanceof Frame) {
+ ((Frame) w).setExtendedState(windowState.getFrameState());
+ }
}
}
1
0
r296 - in trunk/src/main: java/org/nuiton/widget/editor resources/i18n
by sletellier@users.nuiton.org 09 Nov '10
by sletellier@users.nuiton.org 09 Nov '10
09 Nov '10
Author: sletellier
Date: 2010-11-09 12:39:40 +0100 (Tue, 09 Nov 2010)
New Revision: 296
Url: http://nuiton.org/repositories/revision/nuiton-widgets/296
Log:
- Can be used without file
- Clean code
Modified:
trunk/src/main/java/org/nuiton/widget/editor/DefaultEditor.java
trunk/src/main/java/org/nuiton/widget/editor/Editor.java
trunk/src/main/java/org/nuiton/widget/editor/EditorInterface.java
trunk/src/main/java/org/nuiton/widget/editor/JEditEditor.java
trunk/src/main/java/org/nuiton/widget/editor/NullEditor.java
trunk/src/main/java/org/nuiton/widget/editor/RSyntaxEditor.java
trunk/src/main/java/org/nuiton/widget/editor/SDocEditor.java
trunk/src/main/resources/i18n/nuiton-widgets-en_GB.properties
trunk/src/main/resources/i18n/nuiton-widgets-fr_FR.properties
Modified: trunk/src/main/java/org/nuiton/widget/editor/DefaultEditor.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/editor/DefaultEditor.java 2010-11-05 13:13:52 UTC (rev 295)
+++ trunk/src/main/java/org/nuiton/widget/editor/DefaultEditor.java 2010-11-09 11:39:40 UTC (rev 296)
@@ -39,12 +39,10 @@
import java.awt.BorderLayout;
import java.io.BufferedReader;
-import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Reader;
@@ -86,56 +84,46 @@
add(scrollPane, BorderLayout.CENTER);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#addDocumentListener(javax.swing.event.DocumentListener)
- */
@Override
public void addDocumentListener(DocumentListener listener) {
editor.getDocument().addDocumentListener(listener);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#removeDocumentListener(javax.swing.event.DocumentListener)
- */
@Override
public void removeDocumentListener(DocumentListener listener) {
editor.getDocument().removeDocumentListener(listener);
}
-
- /*
- * @see org.nuiton.widget.editor.EditorInterface#addCaretListener(javax.swing.event.CaretListener)
- */
@Override
public void addCaretListener(CaretListener listener) {
editor.addCaretListener(listener);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#removeCaretListener(javax.swing.event.CaretListener)
- */
@Override
public void removeCaretListener(CaretListener listener) {
editor.removeCaretListener(listener);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#accept(java.io.File)
- */
+ @Override
public boolean accept(File file) {
return true;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#isModified()
- */
+ @Override
+ public boolean accept(Editor.EditorSyntaxConstant editorSyntaxConstant) {
+ return true;
+ }
+
+ @Override
public boolean isModified() {
return isModified;
}
- /*
- * @see org.nuiton.widget.Editor#open(java.io.File)
- */
+ @Override
+ public void setSyntax(Editor.EditorSyntaxConstant editorSyntax) {
+ }
+
+ @Override
public boolean open(File file) {
try {
Document doc = editor.getDocument();
@@ -160,9 +148,7 @@
return false;
}
- /*
- * @see org.nuiton.widget.Editor#saveAs(java.io.File)
- */
+ @Override
public boolean saveAs(File file) {
try {
FileOutputStream outf = new FileOutputStream(file);
@@ -178,65 +164,42 @@
return false;
}
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.widget.editor.EditorInterface#getText()
- */
+ @Override
public String getText() {
String result = editor.getText();
return result;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#setText(java.lang.String)
- */
+ @Override
public void setText(String text) {
editor.setText(text);
}
- /*
- * @seejavax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
- */
+ @Override
public void insertUpdate(DocumentEvent e) {
isModified = true;
}
- /*
- * @seejavax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
- */
@Override
public void removeUpdate(DocumentEvent e) {
isModified = true;
}
- /*
- * @seejavax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
- */
@Override
public void changedUpdate(DocumentEvent e) {
isModified = true;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#copy()
- */
@Override
public void copy() {
editor.copy();
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#cut()
- */
@Override
public void cut() {
editor.cut();
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#paste()
- */
@Override
public void paste() {
editor.paste();
Modified: trunk/src/main/java/org/nuiton/widget/editor/Editor.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/editor/Editor.java 2010-11-05 13:13:52 UTC (rev 295)
+++ trunk/src/main/java/org/nuiton/widget/editor/Editor.java 2010-11-09 11:39:40 UTC (rev 296)
@@ -95,6 +95,40 @@
static protected EditorInterface DEFAULT_EDITOR = new DefaultEditor();
+ /**
+ * Disponible syntax
+ *
+ * Used to force syntax to use on editor
+ * @see
+ */
+ public enum EditorSyntaxConstant {
+
+ // TODO sletellier 09/11/10 : implement others languages
+ XML(_("nuitonwidgets.editor.syntax.xml")),
+ JAVA(_("nuitonwidgets.editor.syntax.java")),
+ SQL(_("nuitonwidgets.editor.syntax.sql")),
+ R(_("nuitonwidgets.editor.syntax.r"));
+
+ protected String name;
+
+ EditorSyntaxConstant(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isSupported(EditorSyntaxConstant ... constantsSupported) {
+ for (EditorSyntaxConstant supported : constantsSupported) {
+ if (supported.equals(this)) {
+ return true;
+ }
+ }
+ return false;
+ }
+ }
+
static {
registered = new ArrayList<EditorInterface>();
@@ -110,6 +144,7 @@
/**
* register new editor
*
+ * @param editorClassName class name of new editor
* @return the new registered Editor, or null, if new editor can't be
* instanciant.
*/
@@ -213,6 +248,25 @@
}
/**
+ * Force to use syntaxe without file, try to find the better editor for this syntax
+ *
+ * Work only for regis
+ */
+ @Override
+ public void setSyntax(EditorSyntaxConstant editorSyntax) {
+
+ // No file so dont save
+ setAskIfNotSaved(false);
+
+ // Get concerned editor
+ EditorInterface editor = getEditor(editorSyntax);
+ setCurrentEditor(editor);
+
+ // Apply syntax
+ editor.setSyntax(editorSyntax);
+ }
+
+ /**
* @return the askIfNotSaved
*/
public boolean isAskIfNotSaved() {
@@ -243,9 +297,55 @@
/**
* try to find better editor for this file
*
- * @param file
+ * @param editorSyntaxConstant type of syntaxe
* @return the better editor, or Default Editor
*/
+ public EditorInterface getEditor(EditorSyntaxConstant editorSyntaxConstant) {
+ // if no editor found, DEFAULT_EDITOR will be used
+ EditorInterface editor = DEFAULT_EDITOR;
+ if (!isForceDefault()) {
+ for (EditorInterface e : Editor.registered) {
+ if (e.accept(editorSyntaxConstant)) {
+ editor = e;
+ }
+ }
+ }
+
+ EditorInterface newEditor = usedEditor.get(editor);
+ try {
+ if (newEditor == null) {
+ // create new instance for this editor
+ newEditor = editor.getClass().newInstance();
+ usedEditor.put(editor, newEditor);
+ }
+ } catch (InstantiationException eee) {
+ if (log.isDebugEnabled()) {
+ log.debug("Can't instanciant your Editor class: "
+ + editor.getClass().getName(), eee);
+ }
+ if (log.isInfoEnabled()) {
+ log.info("Can't instanciant your Editor class: "
+ + editor.getClass().getName());
+ }
+ } catch (IllegalAccessException eee) {
+ if (log.isDebugEnabled()) {
+ log.debug("Can't access your Editor class: "
+ + editor.getClass().getName(), eee);
+ }
+ if (log.isInfoEnabled()) {
+ log.info("Can't access your Editor class: "
+ + editor.getClass().getName());
+ }
+ }
+ return newEditor;
+ }
+
+ /**
+ * try to find better editor for this file
+ *
+ * @param file concerned
+ * @return the better editor, or Default Editor
+ */
public EditorInterface getEditor(File file) {
// if no editor found, DEFAULT_EDITOR will be used
EditorInterface editor = DEFAULT_EDITOR;
@@ -288,9 +388,11 @@
public void setCurrentEditor(EditorInterface editor) {
// remove old editor
- if (this.currentEditor != null) {
- remove((Component) this.currentEditor);
+ if (this.currentEditor == null) {
+ // Do nothing
+ return;
}
+ remove((Component) this.currentEditor);
// remove all listener on old editor
for (DocumentListener l : documentListeners) {
@@ -389,7 +491,7 @@
* if return true, this editor support this file type. Default implantation
* return true
*
- * @param file
+ * @param file to check
* @return if return true, this editor support this file type.
*/
public boolean accept(File file) {
@@ -397,6 +499,17 @@
}
/**
+ * if return true, this editor support this syntax type. Default implantation
+ * return true
+ *
+ * @param editorSyntaxConstant to check
+ * @return if return true, this editor support this syntax type.
+ */
+ public boolean accept(Editor.EditorSyntaxConstant editorSyntaxConstant) {
+ return true;
+ }
+
+ /**
* indicate if current opened file has been modified
*
* @return true if currend file is modified
Modified: trunk/src/main/java/org/nuiton/widget/editor/EditorInterface.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/editor/EditorInterface.java 2010-11-05 13:13:52 UTC (rev 295)
+++ trunk/src/main/java/org/nuiton/widget/editor/EditorInterface.java 2010-11-09 11:39:40 UTC (rev 296)
@@ -50,28 +50,28 @@
*
* @param listener listener
*/
- public void addDocumentListener(DocumentListener listener);
+ void addDocumentListener(DocumentListener listener);
/**
* Remove document listener.
*
* @param listener listener
*/
- public void removeDocumentListener(DocumentListener listener);
+ void removeDocumentListener(DocumentListener listener);
/**
* Add caret listener.
*
* @param listener listener
*/
- public void addCaretListener(CaretListener listener);
+ void addCaretListener(CaretListener listener);
/**
* Remove caret listener.
*
* @param listener listener
*/
- public void removeCaretListener(CaretListener listener);
+ void removeCaretListener(CaretListener listener);
/**
* If return true, this editor support this file type.
@@ -80,64 +80,80 @@
* @param file file to test
* @return if return {@code true}, this editor support this file type.
*/
- public boolean accept(File file);
+ boolean accept(File file);
/**
+ * If return true, this editor support the syntax type.
+ * Default implementation return {@code true}.
+ *
+ * @param editorSyntaxConstant syntaxe type to test
+ * @return if return {@code true}, this editor support this syntax type.
+ */
+ boolean accept(Editor.EditorSyntaxConstant editorSyntaxConstant);
+
+ /**
* Indicate if current opened file has been modified.
- *
+ *
* @return {@code true} if current file is modified
*/
- public boolean isModified();
+ boolean isModified();
/**
* Replace the current edited file by file passed in argument.
- *
+ *
* @param file the file to open
* @return true if file has been opened
*/
- public boolean open(File file);
+ boolean open(File file);
/**
* Replace the current edited file by file passed in argument.
- *
+ *
* @param file the file to open
* @return true if file has been saved and reopen with new name
*/
- public boolean saveAs(File file);
+ boolean saveAs(File file);
/**
* Return the current content text of the editor as {@link String}.
- *
+ *
* @return return the current content text of the editor as {@link String}
*/
- public String getText();
+ String getText();
/**
* Set all text with text in argument.
- *
+ *
* @param text test to set
*/
- public void setText(String text);
-
+ void setText(String text);
+
/**
* Cut current editor selection into system clipboard.
*/
- public void cut();
-
+ void cut();
+
/**
* Copy current current selection into system clipboard.
*/
- public void copy();
-
+ void copy();
+
/**
* Paste current clicboard content into editor at caret position.
*/
- public void paste();
-
+ void paste();
+
/**
* Enable/disable editor.
- *
+ *
* @param b enable
*/
- public void setEnabled(boolean b);
+ void setEnabled(boolean b);
+
+ /**
+ * Force syntax to use
+ *
+ * @param editorSyntax to use
+ */
+ void setSyntax(Editor.EditorSyntaxConstant editorSyntax);
}
Modified: trunk/src/main/java/org/nuiton/widget/editor/JEditEditor.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/editor/JEditEditor.java 2010-11-05 13:13:52 UTC (rev 295)
+++ trunk/src/main/java/org/nuiton/widget/editor/JEditEditor.java 2010-11-09 11:39:40 UTC (rev 296)
@@ -43,6 +43,7 @@
import org.nuiton.util.FileUtil;
import org.syntax.jedit.JEditTextArea;
import org.syntax.jedit.tokenmarker.JavaTokenMarker;
+import org.syntax.jedit.tokenmarker.TokenMarker;
import org.syntax.jedit.tokenmarker.XMLTokenMarker;
/**
@@ -80,11 +81,29 @@
result = result || "xml".equalsIgnoreCase(ext);
return result;
}
-
- /*
- * @see org.nuiton.widget.editor.DefaultEditor#open(java.io.File)
- */
+
@Override
+ public boolean accept(Editor.EditorSyntaxConstant editorSyntaxConstant) {
+ return editorSyntaxConstant.isSupported(Editor.EditorSyntaxConstant.JAVA, Editor.EditorSyntaxConstant.XML);
+ }
+
+ @Override
+ public void setSyntax(Editor.EditorSyntaxConstant editorSyntax) {
+ TokenMarker tokenMarker = null;
+ if (editorSyntax.equals(Editor.EditorSyntaxConstant.JAVA)) {
+ tokenMarker = new JavaTokenMarker();
+ } else if (editorSyntax.equals(Editor.EditorSyntaxConstant.XML)) {
+ tokenMarker = new XMLTokenMarker();
+ } else {
+ log.warn("Syntax '" + editorSyntax.getName() + "' is not yet supported by JEditEditor");
+ }
+
+ if (tokenMarker != null) {
+ editor.setTokenMarker(tokenMarker);
+ }
+ }
+
+ @Override
public boolean open(File file) {
try {
@@ -96,7 +115,7 @@
String text = "";
char c;
- int last = 0;
+ int last;
while ((last = in.read()) != -1) {
c = (char) last;
@@ -141,67 +160,43 @@
return false;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#addDocumentListener(javax.swing.event.DocumentListener)
- */
@Override
public void addDocumentListener(DocumentListener listener) {
editor.getDocument().addDocumentListener(listener);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#removeDocumentListener(javax.swing.event.DocumentListener)
- */
@Override
public void removeDocumentListener(DocumentListener listener) {
editor.getDocument().removeDocumentListener(listener);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#addCaretListener(javax.swing.event.CaretListener)
- */
@Override
public void addCaretListener(CaretListener listener) {
editor.addCaretListener(listener);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#removeCaretListener(javax.swing.event.CaretListener)
- */
@Override
public void removeCaretListener(CaretListener listener) {
editor.removeCaretListener(listener);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#getText()
- */
@Override
public String getText() {
String result = editor.getText();
return result;
}
- /*
- * @see javax.swing.JComponent#setEnabled(boolean)
- */
@Override
public void setEnabled(boolean b) {
super.setEnabled(b);
editor.setEnabled(b);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#isModified()
- */
@Override
public boolean isModified() {
return isModified;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#saveAs(java.io.File)
- */
@Override
public boolean saveAs(File file) {
try {
@@ -216,57 +211,36 @@
return false;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#setText(java.lang.String)
- */
@Override
public void setText(String text) {
editor.setText(text);
}
- /*
- * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
- */
@Override
public void changedUpdate(DocumentEvent e) {
isModified = true;
}
- /*
- * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
- */
@Override
public void insertUpdate(DocumentEvent e) {
isModified = true;
}
- /*
- * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
- */
@Override
public void removeUpdate(DocumentEvent e) {
isModified = true;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#copy()
- */
@Override
public void copy() {
editor.copy();
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#cut()
- */
@Override
public void cut() {
editor.cut();
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#paste()
- */
@Override
public void paste() {
editor.paste();
Modified: trunk/src/main/java/org/nuiton/widget/editor/NullEditor.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/editor/NullEditor.java 2010-11-05 13:13:52 UTC (rev 295)
+++ trunk/src/main/java/org/nuiton/widget/editor/NullEditor.java 2010-11-09 11:39:40 UTC (rev 296)
@@ -57,44 +57,38 @@
add(noFileLabel, BorderLayout.CENTER);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#addDocumentListener(javax.swing.event.DocumentListener)
- */
@Override
public void addDocumentListener(DocumentListener listener) {
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#removeDocumentListener(javax.swing.event.DocumentListener)
- */
@Override
public void removeDocumentListener(DocumentListener listener) {
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#addCaretListener(javax.swing.event.CaretListener)
- */
@Override
public void addCaretListener(CaretListener listener) {
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#removeCaretListener(javax.swing.event.CaretListener)
- */
@Override
public void removeCaretListener(CaretListener listener) {
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#accept(java.io.File)
- */
@Override
public boolean accept(File file) {
return false;
}
+ @Override
+ public boolean accept(Editor.EditorSyntaxConstant editorSyntaxConstant) {
+ return false;
+ }
+
+ @Override
+ public void setSyntax(Editor.EditorSyntaxConstant editorSyntax) {
+ }
+
/**
* when there is no file opened, the file is not modified.
*
@@ -129,41 +123,26 @@
return true;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#getText()
- */
@Override
public String getText() {
String result = "";
return result;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#setText(java.lang.String)
- */
@Override
public void setText(String text) {
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#copy()
- */
@Override
public void copy() {
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#cut()
- */
@Override
public void cut() {
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#paste()
- */
@Override
public void paste() {
Modified: trunk/src/main/java/org/nuiton/widget/editor/RSyntaxEditor.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/editor/RSyntaxEditor.java 2010-11-05 13:13:52 UTC (rev 295)
+++ trunk/src/main/java/org/nuiton/widget/editor/RSyntaxEditor.java 2010-11-09 11:39:40 UTC (rev 296)
@@ -86,11 +86,36 @@
result = result || "r".equalsIgnoreCase(ext);
return result;
}
-
- /*
- * @see org.nuiton.widget.editor.DefaultEditor#open(java.io.File)
- */
+
@Override
+ public boolean accept(Editor.EditorSyntaxConstant editorSyntaxConstant) {
+ return editorSyntaxConstant.isSupported(
+ Editor.EditorSyntaxConstant.JAVA,
+ Editor.EditorSyntaxConstant.XML,
+ Editor.EditorSyntaxConstant.SQL,
+ Editor.EditorSyntaxConstant.R);
+ }
+
+ @Override
+ public void setSyntax(Editor.EditorSyntaxConstant editorSyntax) {
+ String constant = null;
+ if (editorSyntax.equals(Editor.EditorSyntaxConstant.SQL)) {
+ constant = SyntaxConstants.SYNTAX_STYLE_SQL;
+ } else if (editorSyntax.equals(Editor.EditorSyntaxConstant.JAVA)) {
+ constant = SyntaxConstants.SYNTAX_STYLE_JAVA;
+ } else if (editorSyntax.equals(Editor.EditorSyntaxConstant.XML)) {
+ constant = SyntaxConstants.SYNTAX_STYLE_XML;
+ } else if (editorSyntax.equals(Editor.EditorSyntaxConstant.R)) {
+ constant = SyntaxConstants.SYNTAX_STYLE_PERL;
+ } else {
+ log.warn("Syntax '" + editorSyntax.getName() + "' is not yet supported by RSyntaxEditor");
+ }
+ if (constant != null) {
+ editor.setSyntaxEditingStyle(constant);
+ }
+ }
+
+ @Override
public boolean open(File file) {
try {
@@ -102,7 +127,7 @@
String text = "";
char c;
- int last = 0;
+ int last;
while ((last = in.read()) != -1) {
c = (char) last;
@@ -151,58 +176,37 @@
return false;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#addDocumentListener(javax.swing.event.DocumentListener)
- */
@Override
public void addDocumentListener(DocumentListener listener) {
editor.getDocument().addDocumentListener(listener);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#removeDocumentListener(javax.swing.event.DocumentListener)
- */
@Override
public void removeDocumentListener(DocumentListener listener) {
editor.getDocument().removeDocumentListener(listener);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#addCaretListener(javax.swing.event.CaretListener)
- */
@Override
public void addCaretListener(CaretListener listener) {
editor.addCaretListener(listener);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#removeCaretListener(javax.swing.event.CaretListener)
- */
@Override
public void removeCaretListener(CaretListener listener) {
editor.removeCaretListener(listener);
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#getText()
- */
@Override
public String getText() {
String result = editor.getText();
return result;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#isModified()
- */
@Override
public boolean isModified() {
return isModified;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#saveAs(java.io.File)
- */
@Override
public boolean saveAs(File file) {
Writer out = null;
@@ -231,66 +235,42 @@
return false;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#setText(java.lang.String)
- */
@Override
public void setText(String text) {
editor.setText(text);
}
- /*
- * @see javax.swing.JComponent#setEnabled(boolean)
- */
@Override
public void setEnabled(boolean b) {
super.setEnabled(b);
editor.setEnabled(b);
}
- /*
- * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
- */
@Override
public void changedUpdate(DocumentEvent e) {
isModified = true;
}
- /*
- * @see javax.swing.event.DocumentListener#insertUpdate(javax.swing.event.DocumentEvent)
- */
@Override
public void insertUpdate(DocumentEvent e) {
isModified = true;
}
- /*
- * @see javax.swing.event.DocumentListener#removeUpdate(javax.swing.event.DocumentEvent)
- */
@Override
public void removeUpdate(DocumentEvent e) {
isModified = true;
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#copy()
- */
@Override
public void copy() {
editor.copy();
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#cut()
- */
@Override
public void cut() {
editor.cut();
}
- /*
- * @see org.nuiton.widget.editor.EditorInterface#paste()
- */
@Override
public void paste() {
editor.paste();
Modified: trunk/src/main/java/org/nuiton/widget/editor/SDocEditor.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/editor/SDocEditor.java 2010-11-05 13:13:52 UTC (rev 295)
+++ trunk/src/main/java/org/nuiton/widget/editor/SDocEditor.java 2010-11-09 11:39:40 UTC (rev 296)
@@ -74,12 +74,24 @@
scrollPane.setRowHeaderView(new Gutter(editor, scrollPane));
}
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.widget.editor.DefaultEditor#accept(java.io.File)
- */
@Override
+ public void setSyntax(Editor.EditorSyntaxConstant editorSyntax) {
+ Integer constant = null;
+ if (editorSyntax.equals(Editor.EditorSyntaxConstant.SQL)) {
+ constant = SyntaxSupport.SQL_LEXER;
+ } else if (editorSyntax.equals(Editor.EditorSyntaxConstant.JAVA)) {
+ constant = SyntaxSupport.JAVA_LEXER;
+ } else if (editorSyntax.equals(Editor.EditorSyntaxConstant.XML)) {
+ constant = SyntaxSupport.XML_LEXER;
+ } else {
+ log.warn("Syntax '" + editorSyntax.getName() + "' is not yet supported by SDocEditor");
+ }
+ if (constant != null) {
+ syntaxSupport.addSupport(constant, editor);
+ }
+ }
+
+ @Override
public boolean accept(File file) {
String ext = FileUtil.extension(file);
boolean result = "java".equalsIgnoreCase(ext);
@@ -88,12 +100,16 @@
return result;
}
- /*
- * (non-Javadoc)
- *
- * @see org.nuiton.widget.editor.DefaultEditor#open(java.io.File)
- */
@Override
+ public boolean accept(Editor.EditorSyntaxConstant editorSyntaxConstant) {
+ return editorSyntaxConstant.isSupported(
+ Editor.EditorSyntaxConstant.JAVA,
+ Editor.EditorSyntaxConstant.XML,
+ Editor.EditorSyntaxConstant.SQL,
+ Editor.EditorSyntaxConstant.R);
+ }
+
+ @Override
public boolean open(File file) {
try {
Document doc = editor.getDocument();
@@ -106,7 +122,7 @@
String text = "";
char c;
- int last = 0;
+ int last;
while ((last = in.read()) != -1) {
c = (char) last;
Modified: trunk/src/main/resources/i18n/nuiton-widgets-en_GB.properties
===================================================================
--- trunk/src/main/resources/i18n/nuiton-widgets-en_GB.properties 2010-11-05 13:13:52 UTC (rev 295)
+++ trunk/src/main/resources/i18n/nuiton-widgets-en_GB.properties 2010-11-09 11:39:40 UTC (rev 296)
@@ -3,6 +3,10 @@
nuitonwidgets.aboutframe.ok=OK
nuitonwidgets.common.copy=Copy
nuitonwidgets.editor.saveorcancel=Do you want to save current opened file ?
+nuitonwidgets.editor.syntax.java=Java
+nuitonwidgets.editor.syntax.r=R
+nuitonwidgets.editor.syntax.sql=SQL
+nuitonwidgets.editor.syntax.xml=XML
nuitonwidgets.message.file=File
nuitonwidgets.message.folder=Folder
nuitonwidgets.message.nofile=No file
Modified: trunk/src/main/resources/i18n/nuiton-widgets-fr_FR.properties
===================================================================
--- trunk/src/main/resources/i18n/nuiton-widgets-fr_FR.properties 2010-11-05 13:13:52 UTC (rev 295)
+++ trunk/src/main/resources/i18n/nuiton-widgets-fr_FR.properties 2010-11-09 11:39:40 UTC (rev 296)
@@ -3,6 +3,10 @@
nuitonwidgets.aboutframe.ok=OK
nuitonwidgets.common.copy=Copier
nuitonwidgets.editor.saveorcancel=Voulez vous sauver le fichier modifi\u00E9 ?
+nuitonwidgets.editor.syntax.java=Java
+nuitonwidgets.editor.syntax.r=R
+nuitonwidgets.editor.syntax.sql=SQL
+nuitonwidgets.editor.syntax.xml=XML
nuitonwidgets.message.file=Fichier
nuitonwidgets.message.folder=R\u00E9pertoire
nuitonwidgets.message.nofile=Aucun fichier
1
0
05 Nov '10
Author: echatellier
Date: 2010-11-05 14:13:52 +0100 (Fri, 05 Nov 2010)
New Revision: 295
Url: http://nuiton.org/repositories/revision/nuiton-widgets/295
Log:
Add another deprecated
Modified:
trunk/pom.xml
trunk/src/main/java/org/nuiton/widget/Mailor.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-11-05 12:25:29 UTC (rev 294)
+++ trunk/pom.xml 2010-11-05 13:13:52 UTC (rev 295)
@@ -24,6 +24,7 @@
<scope>compile</scope>
</dependency>
+ <!-- to remove in 1.1 -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
Modified: trunk/src/main/java/org/nuiton/widget/Mailor.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/Mailor.java 2010-11-05 12:25:29 UTC (rev 294)
+++ trunk/src/main/java/org/nuiton/widget/Mailor.java 2010-11-05 13:13:52 UTC (rev 295)
@@ -61,8 +61,9 @@
import javax.mail.internet.MimeMultipart;
/**
- *
+ * @deprecated since 1.0.4 with no replacement (removed in 1.1)
*/
+@Deprecated
public class Mailor {
public static void main(String[] args) {
1
0
05 Nov '10
Author: echatellier
Date: 2010-11-05 13:25:29 +0100 (Fri, 05 Nov 2010)
New Revision: 294
Url: http://nuiton.org/repositories/revision/nuiton-widgets/294
Log:
Add deprecated on components depending on jgoodies or l2fprod
Modified:
trunk/pom.xml
trunk/src/main/java/org/nuiton/widget/Settings.java
trunk/src/main/java/org/nuiton/widget/SwingUtil.java
trunk/src/main/java/org/nuiton/widget/SwingWidgetFactory.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-11-05 11:51:05 UTC (rev 293)
+++ trunk/pom.xml 2010-11-05 12:25:29 UTC (rev 294)
@@ -27,10 +27,11 @@
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
- <version>1.4</version>
+ <version>1.4.1</version>
<scope>compile</scope>
</dependency>
+ <!-- to remove in 1.1 -->
<dependency>
<groupId>jgoodies</groupId>
<artifactId>looks</artifactId>
@@ -38,6 +39,7 @@
<scope>compile</scope>
</dependency>
+ <!-- to remove in 1.1 -->
<dependency>
<groupId>org.nuiton.thirdparty</groupId>
<artifactId>l2fprod-common</artifactId>
Modified: trunk/src/main/java/org/nuiton/widget/Settings.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/Settings.java 2010-11-05 11:51:05 UTC (rev 293)
+++ trunk/src/main/java/org/nuiton/widget/Settings.java 2010-11-05 12:25:29 UTC (rev 294)
@@ -76,7 +76,10 @@
* @see com.jgoodies.plaf.FontSizeHints
* @see com.jgoodies.plaf.HeaderStyle
* @see com.jgoodies.plaf.Options
+ *
+ * @deprecated since 1.0.4 with no replacement (removed in 1.1)
*/
+@Deprecated
public final class Settings {
private LookAndFeel selectedLookAndFeel;
Modified: trunk/src/main/java/org/nuiton/widget/SwingUtil.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/SwingUtil.java 2010-11-05 11:51:05 UTC (rev 293)
+++ trunk/src/main/java/org/nuiton/widget/SwingUtil.java 2010-11-05 12:25:29 UTC (rev 294)
@@ -57,6 +57,10 @@
*/
public class SwingUtil {
+ /**
+ * @deprecated since 1.0.4 with no replacement (removed in 1.1)
+ */
+ @Deprecated
public static void init() throws Exception {
UIManager.put("ClassLoader", LookUtils.class.getClassLoader());
PlasticLookAndFeel.setMyCurrentTheme(new SkyBluerTahoma());
Modified: trunk/src/main/java/org/nuiton/widget/SwingWidgetFactory.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/SwingWidgetFactory.java 2010-11-05 11:51:05 UTC (rev 293)
+++ trunk/src/main/java/org/nuiton/widget/SwingWidgetFactory.java 2010-11-05 12:25:29 UTC (rev 294)
@@ -83,7 +83,10 @@
/**
* Creates and returns a <code>AbstractButton</code>
+ *
+ * @deprecated since 1.0.4, use swingx hyperlink component instead (removed in 1.1)
*/
+ @Deprecated
public static AbstractButton createHyperLinkButton(ApplicationAction action) {
JLinkButton button = new JLinkButton(action);
button.setText((String) action.getValue(AbstractAction.NAME));
@@ -120,7 +123,10 @@
/**
* Creates and returns a <code>JToolBar</code>
+ *
+ * @deprecated since 1.0.4 with no replacement (removed in 1.1)
*/
+ @Deprecated
public static JToolBar createToolBar() {
JToolBar toolBar = new JToolBar();
@@ -148,7 +154,10 @@
/**
* Creates and returns a <code>JMenuBar</code>
+ *
+ * @deprecated since 1.0.4 with no replacement (removed in 1.1)
*/
+ @Deprecated
public static JMenuBar createMenuBar() {
JMenuBar menuBar = new JMenuBar();
1
0
Author: echatellier
Date: 2010-11-05 12:51:05 +0100 (Fri, 05 Nov 2010)
New Revision: 293
Url: http://nuiton.org/repositories/revision/nuiton-widgets/293
Log:
Add deprecated targeted as 1.1
Modified:
trunk/src/main/java/org/nuiton/widget/DatePicker.java
trunk/src/main/java/org/nuiton/widget/SwingWidgetFactory.java
Modified: trunk/src/main/java/org/nuiton/widget/DatePicker.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/DatePicker.java 2010-11-05 11:46:57 UTC (rev 292)
+++ trunk/src/main/java/org/nuiton/widget/DatePicker.java 2010-11-05 11:51:05 UTC (rev 293)
@@ -31,6 +31,9 @@
import javax.swing.JTextField;
+/**
+ * @deprecate since 1.0.4 will be remove in 1.1 use swingx date picker instead
+ */
@Deprecated
public class DatePicker extends JTextField {
Modified: trunk/src/main/java/org/nuiton/widget/SwingWidgetFactory.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/SwingWidgetFactory.java 2010-11-05 11:46:57 UTC (rev 292)
+++ trunk/src/main/java/org/nuiton/widget/SwingWidgetFactory.java 2010-11-05 11:51:05 UTC (rev 293)
@@ -183,6 +183,9 @@
return menuItem;
}
+ /**
+ * @deprecate since 1.0.4 will be remove in 1.1 use swingx date picker instead
+ */
@Deprecated
public static DatePicker createDatePicker(DateFormat dateFormat) {
return new DatePicker(dateFormat);
1
0
Author: echatellier
Date: 2010-11-05 12:46:57 +0100 (Fri, 05 Nov 2010)
New Revision: 292
Url: http://nuiton.org/repositories/revision/nuiton-widgets/292
Log:
Add deprecated on component depending on lutin log
Modified:
trunk/src/main/java/org/nuiton/widget/ApplicationMonitor.java
trunk/src/main/java/org/nuiton/widget/StatusBar.java
Modified: trunk/src/main/java/org/nuiton/widget/ApplicationMonitor.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/ApplicationMonitor.java 2010-11-04 15:22:38 UTC (rev 291)
+++ trunk/src/main/java/org/nuiton/widget/ApplicationMonitor.java 2010-11-05 11:46:57 UTC (rev 292)
@@ -91,6 +91,10 @@
import org.nuiton.log.LutinLogListener;
import org.nuiton.log.LutinProgressEvent;
+/**
+ * @deprecated since 1.0.4, will be removed in 1.1, depends on remove lutinlog
+ */
+@Deprecated
public class ApplicationMonitor extends JPanel {
private static final long serialVersionUID = 1L;
Modified: trunk/src/main/java/org/nuiton/widget/StatusBar.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/StatusBar.java 2010-11-04 15:22:38 UTC (rev 291)
+++ trunk/src/main/java/org/nuiton/widget/StatusBar.java 2010-11-05 11:46:57 UTC (rev 292)
@@ -69,8 +69,9 @@
/**
* TODO: renomer cette statusBar en autre chose, car son role est d'afficher des
* messages par exemple StatusMessageBar ou StatusMessagePanel, ...
- * @deprecated since 1.0.0-rc-3-SNAPSHOT, prefer use the jaxx version in jaxx-runtime-swing-widget module
*
+ * @deprecated since 1.0.0-rc-3-SNAPSHOT, will be remove in 1.1 prefer use the jaxx version in jaxx-runtime-swing-widget module
+ *
* The new classe is renamed jaxx.runtime.swing.StatusMessagePanel
*/
@Deprecated
1
0
Author: bpoussin
Date: 2010-11-04 16:22:38 +0100 (Thu, 04 Nov 2010)
New Revision: 291
Url: http://nuiton.org/repositories/revision/nuiton-widgets/291
Log:
second version without listener, that cause probleme and are not necessary for good usage
Modified:
trunk/src/main/java/org/nuiton/widget/SwingSession.java
Modified: trunk/src/main/java/org/nuiton/widget/SwingSession.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/SwingSession.java 2010-11-04 15:08:51 UTC (rev 290)
+++ trunk/src/main/java/org/nuiton/widget/SwingSession.java 2010-11-04 15:22:38 UTC (rev 291)
@@ -17,8 +17,6 @@
import java.beans.Encoder;
import java.beans.ExceptionListener;
import java.beans.Expression;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.ByteArrayOutputStream;
@@ -31,11 +29,9 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
-import javax.mail.Session;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
@@ -43,8 +39,6 @@
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
@@ -59,10 +53,15 @@
* <li> javax.swing.JSplitPane (and subclasses)
* <li> javax.swing.JTable (and subclasses)
*
- * You can use:
+ * usage:
+ * <li> create SwingSession object
+ * <li> add component that you want save
* <li> explicite call to save
- * <li> auto save
*
+ * You can use same SwingSession for multiple window but in this case you must
+ * have setName for each window with different name, otherwize there are
+ * collision between window component and result is undetermisitic
+ *
* This code is partialy inspired from http://kenai.com/projects/bsaf/pages/Home
* project. This project is under LGPL v2.1 license. We can't reuse directly this
* library because to many fields and methods are private and we can't implements
@@ -232,20 +231,15 @@
registeredComponent.add(c);
walkThrowComponent("", Collections.singleton(c),
new RestoreStateAction());
- if (autoSave) {
- // register do save if necessary
- walkThrowComponent("", Collections.singleton(c),
- new RegisterAsListenerAction());
- }
}
}
+ /**
+ * Remove component from component to save
+ * @param c
+ */
public void remove(Component c) {
registeredComponent.remove(c);
- if (autoSave) {
- walkThrowComponent("/", Collections.singleton(c),
- new UnregisterAsListenerAction());
- }
}
protected String getComponentName(Component c) {
@@ -334,35 +328,10 @@
}
}
- static public class RegisterAsListenerAction implements Action {
- @Override
- public void doAction(SwingSession session, String path, Component c) {
- State state = session.getStates(path);
- if (state == null) {
- State manager = session.getStateManager(c.getClass());
- state = manager.getState(c);
- session.setStates(path, state);
- }
- state.addListener(c, state);
- }
- }
-
- static public class UnregisterAsListenerAction implements Action {
- @Override
- public void doAction(SwingSession session, String path, Component c) {
- State state = session.getStates(path);
- if (state != null) {
- state.removeListener(c, state);
- }
- }
- }
-
/**
* get(save) and set(restore) state of object passed in argument
*/
static public interface State {
- public void addListener(Object o, Object l);
- public void removeListener(Object o, Object l);
public State getState(Object o);
public void setState(Object o, State state);
}
@@ -370,7 +339,7 @@
/**
* State for JTabbedPane
*/
- static public class JTabbedPaneState implements State, ChangeListener {
+ static public class JTabbedPaneState implements State {
protected int selectedIndex = -1;
protected int tabCount;
@@ -405,29 +374,14 @@
return (JTabbedPane) o;
}
-
@Override
- public void addListener(Object o, Object l) {
- JTabbedPane p = checkComponent(o);
- p.addChangeListener((ChangeListener)l);
- }
+ public State getState(Object o) {
+ JTabbedPaneState result = new JTabbedPaneState();
- @Override
- public void removeListener(Object o, Object l) {
JTabbedPane p = checkComponent(o);
- p.removeChangeListener((ChangeListener)l);
- }
+ result.setSelectedIndex(p.getSelectedIndex());
+ result.setTabCount(p.getTabCount());
- public void updateState(Object o, JTabbedPaneState state) {
- JTabbedPane p = checkComponent(o);
- state.setSelectedIndex(p.getSelectedIndex());
- state.setTabCount(p.getTabCount());
- }
-
- @Override
- public State getState(Object o) {
- JTabbedPaneState result = new JTabbedPaneState();
- updateState(o, result);
return result;
}
@@ -447,19 +401,13 @@
throw new IllegalArgumentException("invalid state");
}
}
-
- @Override
- public void stateChanged(ChangeEvent e) {
- updateState(e.getSource(), this);
- }
-
}
/**
* State for JSplit
* FIXME add listener for divider move action
*/
- static public class JSplitPaneState implements State, PropertyChangeListener {
+ static public class JSplitPaneState implements State {
protected int dividerLocation = -1;
protected int orientation = JSplitPane.HORIZONTAL_SPLIT;
@@ -494,27 +442,13 @@
}
@Override
- public void addListener(Object o, Object l) {
- throw new UnsupportedOperationException("Not supported yet.");
- // FIXME poussin 20101104 est ce possible de se mettre listener
- // pour recevoir les events de modification de la possition du split ?
- }
-
- @Override
- public void removeListener(Object o, Object l) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
- protected void updateState(Object o, JSplitPaneState state) {
+ public State getState(Object o) {
JSplitPane p = checkComponent(o);
- state.setDividerLocation(p.getUI().getDividerLocation(p));
- state.setOrientation(p.getOrientation());
- }
- @Override
- public State getState(Object o) {
JSplitPaneState result = new JSplitPaneState();
- updateState(o, result);
+ result.setDividerLocation(p.getUI().getDividerLocation(p));
+ result.setOrientation(p.getOrientation());
+
return result;
}
@@ -534,19 +468,13 @@
throw new IllegalArgumentException("invalid state");
}
}
-
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
-
}
/**
* State for JTable.
* TODO add support for column order change
*/
- static public class JTableState implements State, PropertyChangeListener {
+ static public class JTableState implements State {
protected int[] columnWidths = new int[0];
@@ -576,26 +504,8 @@
}
@Override
- public void addListener(Object o, Object l) {
+ public State getState(Object o) {
JTable table = checkComponent(o);
- for (Enumeration<TableColumn> tc =
- table.getColumnModel().getColumns(); tc.hasMoreElements();) {
- // on se met listener pour recevoir les events de resize
- tc.nextElement().addPropertyChangeListener(this);
- }
- }
-
- @Override
- public void removeListener(Object o, Object l) {
- JTable table = checkComponent(o);
- for (Enumeration<TableColumn> tc =
- table.getColumnModel().getColumns(); tc.hasMoreElements();) {
- tc.nextElement().removePropertyChangeListener(this);
- }
- }
-
- public void updateState(Object o, JTableState state) {
- JTable table = checkComponent(o);
int[] columnWidths = new int[table.getColumnCount()];
boolean resizableColumnExists = false;
for (int i = 0; i < columnWidths.length; i++) {
@@ -605,15 +515,11 @@
resizableColumnExists = true;
}
}
+ JTableState result = null;
if (resizableColumnExists) {
- state.setColumnWidths(columnWidths);
+ result = new JTableState();
+ result.setColumnWidths(columnWidths);
}
- }
-
- @Override
- public State getState(Object o) {
- JTableState result = new JTableState(columnWidths);
- updateState(o, result);
return result;
}
@@ -636,18 +542,12 @@
}
}
}
-
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- updateState(evt.getSource(), this);
- }
-
}
/**
* State for Window
*/
- static public class WindowState implements State, PropertyChangeListener {
+ static public class WindowState implements State {
private static final String WINDOW_STATE_NORMAL_BOUNDS =
"WindowState.normalBounds";
@@ -759,25 +659,7 @@
}
@Override
- public void addListener(Object o, Object l) {
- Window w = checkComponent(o);
- w.addPropertyChangeListener("extendedState", (PropertyChangeListener)l);
- w.addPropertyChangeListener("bounds", (PropertyChangeListener)l);
- }
-
- @Override
- public void removeListener(Object o, Object l) {
- Window w = checkComponent(o);
- w.removePropertyChangeListener("extendedState", (PropertyChangeListener)l);
- w.removePropertyChangeListener("bounds", (PropertyChangeListener)l);
- }
-
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- updateState(evt.getSource(), this);
- }
-
- protected void updateState(Object o, WindowState state) {
+ public State getState(Object o) {
Window c = checkComponent(o);
int frameState = Frame.NORMAL;
if (c instanceof Frame) {
@@ -793,18 +675,14 @@
if ((c instanceof JFrame) && (0 != (frameState & Frame.MAXIMIZED_BOTH))) {
frameBounds = getWindowNormalBounds((JFrame) c);
}
- if (frameBounds.isEmpty()) {
- return;
+ WindowState result = null;
+ if (!frameBounds.isEmpty()) {
+ result = new WindowState();
+ result.setBounds(frameBounds);
+ result.setGcBounds(gcBounds);
+ result.setFrameState(frameState);
}
- state.setBounds(frameBounds);
- state.setGcBounds(gcBounds);
- state.setFrameState(frameState);
- }
- @Override
- public State getState(Object o) {
- WindowState result = new WindowState();
- updateState(o, result);
return result;
}
1
0
Author: bpoussin
Date: 2010-11-04 16:08:51 +0100 (Thu, 04 Nov 2010)
New Revision: 290
Url: http://nuiton.org/repositories/revision/nuiton-widgets/290
Log:
first version of save/restore of swing UI
Added:
trunk/src/main/java/org/nuiton/widget/SwingSession.java
Added: trunk/src/main/java/org/nuiton/widget/SwingSession.java
===================================================================
--- trunk/src/main/java/org/nuiton/widget/SwingSession.java (rev 0)
+++ trunk/src/main/java/org/nuiton/widget/SwingSession.java 2010-11-04 15:08:51 UTC (rev 290)
@@ -0,0 +1,904 @@
+package org.nuiton.widget;
+
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dialog;
+import java.awt.Frame;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.Rectangle;
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.beans.DefaultPersistenceDelegate;
+import java.beans.Encoder;
+import java.beans.ExceptionListener;
+import java.beans.Expression;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.XMLDecoder;
+import java.beans.XMLEncoder;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import javax.mail.Session;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.JTabbedPane;
+import javax.swing.JTable;
+import javax.swing.JTextArea;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableColumn;
+import javax.swing.table.TableModel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Use to store and restore position and size of application. Supported widgets
+ * are:
+ * <li> java.awt.Window (and subclasses)
+ * <li> javax.swing.JTabbedPane (and subclasses)
+ * <li> javax.swing.JSplitPane (and subclasses)
+ * <li> javax.swing.JTable (and subclasses)
+ *
+ * You can use:
+ * <li> explicite call to save
+ * <li> auto save
+ *
+ * This code is partialy inspired from http://kenai.com/projects/bsaf/pages/Home
+ * project. This project is under LGPL v2.1 license. We can't reuse directly this
+ * library because to many fields and methods are private and we can't implements
+ * it and modify some behavior.
+ *
+ * @author poussin
+ * @version $Revision$
+ *
+ * Last update: $Date$
+ * by : $Author$
+ */
+public class SwingSession {
+
+ /** to use log facility, just put in your code: log.info(\"...\"); */
+ static private Log log = LogFactory.getLog(SwingSession.class);
+
+ protected File file;
+ protected boolean autoSave;
+ protected LinkedHashSet<Component> registeredComponent =
+ new LinkedHashSet<Component>();
+ /** State object registered to get and set State.
+ * key: class of component managed by the state; value: the state*/
+ protected Map<Class, State> stateManager = new HashMap<Class, State>();
+ /** state of all component added with add method.
+ * key: path of compoenent; value: State */
+ protected Map<String, State> states;
+
+ public SwingSession(File file, boolean autoSave) {
+ this.file = file;
+ this.autoSave = autoSave;
+ stateManager.put(Window.class, new WindowState());
+ stateManager.put(JTable.class, new JTableState());
+ stateManager.put(JTabbedPane.class, new JTabbedPaneState());
+ stateManager.put(JSplitPane.class, new JSplitPaneState());
+
+ states = loadStates(file);
+ if (states == null) {
+ states = new HashMap<String, State>();
+ }
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+ save();
+ super.finalize();
+ }
+
+
+ /* If an exception occurs in the XMLEncoder/Decoder, we want
+ * to throw an IOException. The exceptionThrow listener method
+ * doesn't throw a checked exception so we just set a flag
+ * here and check it when the encode/decode operation finishes
+ */
+ private static class AbortExceptionListener implements ExceptionListener {
+
+ public Exception exception = null;
+
+ @Override
+ public void exceptionThrown(Exception e) {
+ if (exception == null) {
+ exception = e;
+ }
+ }
+ }
+
+ /* There are some (old) Java classes that aren't proper beans. Rectangle
+ * is one of these. When running within the secure sandbox, writing a
+ * Rectangle with XMLEncoder causes a security exception because
+ * DefaultPersistenceDelegate calls Field.setAccessible(true) to gain
+ * access to private fields. This is a workaround for that problem.
+ * A bug has been filed, see JDK bug ID 4741757
+ */
+ private static class RectanglePD extends DefaultPersistenceDelegate {
+
+ public RectanglePD() {
+ super(new String[]{"x", "y", "width", "height"});
+ }
+
+ @Override
+ protected Expression instantiate(Object oldInstance, Encoder out) {
+ Rectangle oldR = (Rectangle) oldInstance;
+ Object[] constructorArgs = new Object[]{
+ oldR.x, oldR.y, oldR.width, oldR.height
+ };
+ return new Expression(oldInstance, oldInstance.getClass(), "new", constructorArgs);
+ }
+ }
+
+ public void save() {
+ updateState();
+ AbortExceptionListener el = new AbortExceptionListener();
+ ByteArrayOutputStream bst = new ByteArrayOutputStream();
+ XMLEncoder e = null;
+ /* Buffer the XMLEncoder's output so that decoding errors don't
+ * cause us to trash the current version of the specified file.
+ */
+ try {
+ e = new XMLEncoder(bst);
+ e.setPersistenceDelegate(Rectangle.class, new RectanglePD());
+ e.setExceptionListener(el);
+ e.writeObject(states);
+ } finally {
+ if (e != null) {
+ e.close();
+ }
+ }
+ if (el.exception != null) {
+ log.warn("save failed \"" + file + "\"", el.exception);
+ } else {
+ OutputStream ost = null;
+ try {
+ ost = new FileOutputStream(file);
+ ost.write(bst.toByteArray());
+ } catch (IOException eee) {
+ log.warn("save failed \"" + file + "\"", eee);
+ } finally {
+ if (ost != null) {
+ try {
+ ost.close();
+ } catch (IOException eee) {
+ log.warn("can't close properly \"" + file + "\"", eee);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Loads the states from the file
+ */
+ public Map<String, State> loadStates(File file) {
+ Map<String, State> result = null;
+ if (file.exists()) {
+ XMLDecoder d = null;
+ try {
+ InputStream ist = new FileInputStream(file);
+ d = new XMLDecoder(ist);
+ AbortExceptionListener eee = new AbortExceptionListener();
+ d.setExceptionListener(eee);
+ Object bean = d.readObject();
+ if (eee.exception != null) {
+ log.warn("load failed \"" + file + "\"", eee.exception);
+ } else {
+ result = (Map<String, State>) bean;
+ }
+ } catch (IOException eee) {
+ log.warn("load failed \"" + file + "\"", eee);
+ } finally {
+ if (d != null) {
+ d.close();
+ }
+ }
+ }
+ return result;
+ }
+
+ public void updateState() {
+ walkThrowComponent("", registeredComponent,
+ new SaveStateAction());
+ }
+
+ public void add(Component c) {
+ if (registeredComponent.contains(c)) {
+ log.warn(String.format(
+ "Component already added %s(%s)", c.getClass(), c.getName()));
+ } else {
+ registeredComponent.add(c);
+ walkThrowComponent("", Collections.singleton(c),
+ new RestoreStateAction());
+ if (autoSave) {
+ // register do save if necessary
+ walkThrowComponent("", Collections.singleton(c),
+ new RegisterAsListenerAction());
+ }
+ }
+ }
+
+ public void remove(Component c) {
+ registeredComponent.remove(c);
+ if (autoSave) {
+ walkThrowComponent("/", Collections.singleton(c),
+ new UnregisterAsListenerAction());
+ }
+ }
+
+ protected String getComponentName(Component c) {
+ String name = c.getName();
+ if (name == null) {
+ int n = c.getParent().getComponentZOrder(c);
+ if (n >= 0) {
+ Class clazz = c.getClass();
+ name = clazz.getSimpleName();
+ if (name.length() == 0) {
+ name = "Anonymous" + clazz.getSuperclass().getSimpleName();
+ }
+ name = name + n;
+ } else {
+ // Implies that the component tree is changing
+ // while we're computing the path. Punt.
+ log.warn("Couldn't compute pathname for " + c);
+ }
+ }
+ return name;
+ }
+
+ public State getStateManager(Class clazz) {
+ State result = null;
+ while (result == null && clazz != null) {
+ result = stateManager.get(clazz);
+ clazz = clazz.getSuperclass();
+ }
+ return result;
+ }
+
+ public State getStates(String path) {
+ return states.get(path);
+ }
+
+ public void setStates(String path, State state) {
+ this.states.put(path, state);
+ }
+
+ protected void walkThrowComponent(
+ String path, Collection<Component> roots, Action action) {
+ for (Component root : roots) {
+ if (root != null) {
+ String pathname = path + "/" + getComponentName(root);
+ State state = getStateManager(root.getClass());
+ if (state != null) {
+ action.doAction(this, pathname, root);
+ }
+ if (root instanceof Container) {
+ Component[] children = ((Container) root).getComponents();
+ if ((children != null) && (children.length > 0)) {
+ walkThrowComponent(pathname, Arrays.asList(children), action);
+ }
+ }
+ if (root instanceof JFrame) {
+ Component[] children = ((JFrame) root).getContentPane().getComponents();
+ if ((children != null) && (children.length > 0)) {
+ walkThrowComponent(pathname, Arrays.asList(children), action);
+ }
+ }
+ }
+ }
+ }
+
+ static public interface Action {
+ public void doAction(SwingSession session, String path, Component c);
+ }
+
+ static public class SaveStateAction implements Action {
+ @Override
+ public void doAction(SwingSession session, String path, Component c) {
+ State manager = session.getStateManager(c.getClass());
+ State state = manager.getState(c);
+ session.setStates(path, state);
+ }
+ }
+
+ static public class RestoreStateAction implements Action {
+ @Override
+ public void doAction(SwingSession session, String path, Component c) {
+ State manager = session.getStateManager(c.getClass());
+ State state = session.getStates(path);
+ if (state != null) {
+ manager.setState(c, state);
+ }
+ }
+ }
+
+ static public class RegisterAsListenerAction implements Action {
+ @Override
+ public void doAction(SwingSession session, String path, Component c) {
+ State state = session.getStates(path);
+ if (state == null) {
+ State manager = session.getStateManager(c.getClass());
+ state = manager.getState(c);
+ session.setStates(path, state);
+ }
+ state.addListener(c, state);
+ }
+ }
+
+ static public class UnregisterAsListenerAction implements Action {
+ @Override
+ public void doAction(SwingSession session, String path, Component c) {
+ State state = session.getStates(path);
+ if (state != null) {
+ state.removeListener(c, state);
+ }
+ }
+ }
+
+ /**
+ * get(save) and set(restore) state of object passed in argument
+ */
+ static public interface State {
+ public void addListener(Object o, Object l);
+ public void removeListener(Object o, Object l);
+ public State getState(Object o);
+ public void setState(Object o, State state);
+ }
+
+ /**
+ * State for JTabbedPane
+ */
+ static public class JTabbedPaneState implements State, ChangeListener {
+
+ protected int selectedIndex = -1;
+ protected int tabCount;
+
+ public JTabbedPaneState() {
+ }
+
+ public int getSelectedIndex() {
+ return selectedIndex;
+ }
+
+ public void setSelectedIndex(int selectedIndex) {
+ this.selectedIndex = selectedIndex;
+ }
+
+ public int getTabCount() {
+ return tabCount;
+ }
+
+ public void setTabCount(int tabCount) {
+ this.tabCount = tabCount;
+ }
+
+
+ protected JTabbedPane checkComponent(Object o) {
+ if (o == null) {
+ throw new IllegalArgumentException("null component");
+ }
+ if (!(o instanceof JTabbedPane)) {
+ throw new IllegalArgumentException("invalid component");
+ }
+ return (JTabbedPane) o;
+ }
+
+
+ @Override
+ public void addListener(Object o, Object l) {
+ JTabbedPane p = checkComponent(o);
+ p.addChangeListener((ChangeListener)l);
+ }
+
+ @Override
+ public void removeListener(Object o, Object l) {
+ JTabbedPane p = checkComponent(o);
+ p.removeChangeListener((ChangeListener)l);
+ }
+
+ public void updateState(Object o, JTabbedPaneState state) {
+ JTabbedPane p = checkComponent(o);
+ state.setSelectedIndex(p.getSelectedIndex());
+ state.setTabCount(p.getTabCount());
+ }
+
+ @Override
+ public State getState(Object o) {
+ JTabbedPaneState result = new JTabbedPaneState();
+ updateState(o, result);
+ return result;
+ }
+
+ @Override
+ public void setState(Object o, State state) {
+ if (state == null) {
+ return;
+ }
+ if (state instanceof JTabbedPaneState) {
+ JTabbedPane p = checkComponent(o);
+ JTabbedPaneState tps = (JTabbedPaneState) state;
+ if (tps.getSelectedIndex() != -1
+ && p.getTabCount() == tps.getTabCount()) {
+ p.setSelectedIndex(tps.getSelectedIndex());
+ }
+ } else {
+ throw new IllegalArgumentException("invalid state");
+ }
+ }
+
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ updateState(e.getSource(), this);
+ }
+
+ }
+
+ /**
+ * State for JSplit
+ * FIXME add listener for divider move action
+ */
+ static public class JSplitPaneState implements State, PropertyChangeListener {
+
+ protected int dividerLocation = -1;
+ protected int orientation = JSplitPane.HORIZONTAL_SPLIT;
+
+ public JSplitPaneState() {
+ }
+
+ public int getDividerLocation() {
+ return dividerLocation;
+ }
+
+ public void setDividerLocation(int dividerLocation) {
+ this.dividerLocation = dividerLocation;
+ }
+
+ public int getOrientation() {
+ return orientation;
+ }
+
+ public void setOrientation(int orientation) {
+ this.orientation = orientation;
+ }
+
+ protected JSplitPane checkComponent(Object o) {
+ if (o == null) {
+ throw new IllegalArgumentException("null component");
+ }
+ if (!(o instanceof JSplitPane)) {
+ throw new IllegalArgumentException("invalid component");
+ }
+ return (JSplitPane) o;
+ }
+
+ @Override
+ public void addListener(Object o, Object l) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ // FIXME poussin 20101104 est ce possible de se mettre listener
+ // pour recevoir les events de modification de la possition du split ?
+ }
+
+ @Override
+ public void removeListener(Object o, Object l) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ protected void updateState(Object o, JSplitPaneState state) {
+ JSplitPane p = checkComponent(o);
+ state.setDividerLocation(p.getUI().getDividerLocation(p));
+ state.setOrientation(p.getOrientation());
+ }
+
+ @Override
+ public State getState(Object o) {
+ JSplitPaneState result = new JSplitPaneState();
+ updateState(o, result);
+ return result;
+ }
+
+ @Override
+ public void setState(Object o, State state) {
+ if (state == null) {
+ return;
+ }
+ JSplitPane p = checkComponent(o);
+ if (state instanceof JSplitPaneState) {
+ JSplitPaneState sps = (JSplitPaneState) state;
+ if (sps.getDividerLocation() != -1
+ && p.getOrientation() == sps.getOrientation()) {
+ p.setDividerLocation(sps.getDividerLocation());
+ }
+ } else {
+ throw new IllegalArgumentException("invalid state");
+ }
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ }
+
+ /**
+ * State for JTable.
+ * TODO add support for column order change
+ */
+ static public class JTableState implements State, PropertyChangeListener {
+
+ protected int[] columnWidths = new int[0];
+
+ public JTableState() {
+ }
+
+ public JTableState(int[] columnWidths) {
+ this.columnWidths = columnWidths;
+ }
+
+ public int[] getColumnWidths() {
+ return columnWidths;
+ }
+
+ public void setColumnWidths(int[] columnWidths) {
+ this.columnWidths = columnWidths;
+ }
+
+ protected JTable checkComponent(Object o) {
+ if (o == null) {
+ throw new IllegalArgumentException("null component");
+ }
+ if (!(o instanceof JTable)) {
+ throw new IllegalArgumentException("invalid component");
+ }
+ return (JTable) o;
+ }
+
+ @Override
+ public void addListener(Object o, Object l) {
+ JTable table = checkComponent(o);
+ for (Enumeration<TableColumn> tc =
+ table.getColumnModel().getColumns(); tc.hasMoreElements();) {
+ // on se met listener pour recevoir les events de resize
+ tc.nextElement().addPropertyChangeListener(this);
+ }
+ }
+
+ @Override
+ public void removeListener(Object o, Object l) {
+ JTable table = checkComponent(o);
+ for (Enumeration<TableColumn> tc =
+ table.getColumnModel().getColumns(); tc.hasMoreElements();) {
+ tc.nextElement().removePropertyChangeListener(this);
+ }
+ }
+
+ public void updateState(Object o, JTableState state) {
+ JTable table = checkComponent(o);
+ int[] columnWidths = new int[table.getColumnCount()];
+ boolean resizableColumnExists = false;
+ for (int i = 0; i < columnWidths.length; i++) {
+ TableColumn tc = table.getColumnModel().getColumn(i);
+ columnWidths[i] = (tc.getResizable()) ? tc.getWidth() : -1;
+ if (tc.getResizable()) {
+ resizableColumnExists = true;
+ }
+ }
+ if (resizableColumnExists) {
+ state.setColumnWidths(columnWidths);
+ }
+ }
+
+ @Override
+ public State getState(Object o) {
+ JTableState result = new JTableState(columnWidths);
+ updateState(o, result);
+ return result;
+ }
+
+ @Override
+ public void setState(Object o, State state) {
+ if (!(state instanceof JTableState)) {
+ throw new IllegalArgumentException("invalid state");
+ }
+ JTable table = checkComponent(o);
+ int[] columnWidths = ((JTableState) state).getColumnWidths();
+ if (columnWidths != null
+ && table.getColumnCount() == columnWidths.length) {
+ for (int i = 0; i < columnWidths.length; i++) {
+ if (columnWidths[i] != -1) {
+ TableColumn tc = table.getColumnModel().getColumn(i);
+ if (tc.getResizable()) {
+ tc.setPreferredWidth(columnWidths[i]);
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ updateState(evt.getSource(), this);
+ }
+
+ }
+
+ /**
+ * State for Window
+ */
+ static public class WindowState implements State, PropertyChangeListener {
+ private static final String WINDOW_STATE_NORMAL_BOUNDS =
+ "WindowState.normalBounds";
+
+ protected Rectangle bounds;
+ protected Rectangle gcBounds;
+ protected int frameState = Frame.NORMAL;
+
+ public WindowState() {
+ }
+
+ public WindowState(Rectangle bounds, Rectangle gcBounds, int frameState) {
+ this.bounds = new Rectangle(bounds);
+ this.gcBounds = new Rectangle(gcBounds);
+ this.frameState = frameState;
+ }
+
+ public Rectangle getBounds() {
+ return bounds;
+ }
+
+ public void setBounds(Rectangle bounds) {
+ this.bounds = bounds;
+ }
+
+ public Rectangle getGcBounds() {
+ return gcBounds;
+ }
+
+ public void setGcBounds(Rectangle gcBounds) {
+ this.gcBounds = gcBounds;
+ }
+
+ public int getFrameState() {
+ return frameState;
+ }
+
+ public void setFrameState(int frameState) {
+ this.frameState = frameState;
+ }
+
+ protected Window checkComponent(Object o) {
+ if (o == null) {
+ throw new IllegalArgumentException("null component");
+ }
+ if (!(o instanceof Window)) {
+ throw new IllegalArgumentException("invalid component");
+ }
+ return (Window) o;
+ }
+
+ /**
+ * Checks whether the window supports resizing
+ * @param window the {@code Window} to be checked
+ * @return true if the window supports resizing
+ */
+ protected static boolean isResizable(Window window) {
+ boolean resizable = true;
+ if (window instanceof Frame) {
+ resizable = ((Frame) window).isResizable();
+ } else if (window instanceof Dialog) {
+ resizable = ((Dialog) window).isResizable();
+ }
+ return resizable;
+ }
+
+ /**
+ * Gets {@code Window} bounds from the client property
+ * @param window the source {@code Window}
+ * @return bounds from the client property
+ */
+ protected static Rectangle getWindowNormalBounds(Window window) {
+ Rectangle result = null;
+ if (window instanceof JFrame) {
+ Object res = ((JFrame) window).getRootPane().getClientProperty(
+ WINDOW_STATE_NORMAL_BOUNDS);
+ if (res instanceof Rectangle) {
+ result = (Rectangle) res;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Calculates virtual graphic bounds.
+ * On multiscreen systems all screens are united into one virtual screen.
+ * @return the graphic bounds
+ */
+ public static Rectangle computeVirtualGraphicsBounds() {
+ Rectangle virtualBounds = new Rectangle();
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ GraphicsDevice[] gs = ge.getScreenDevices();
+ for (GraphicsDevice gd : gs) {
+ GraphicsConfiguration gc = gd.getDefaultConfiguration();
+ virtualBounds = virtualBounds.union(gc.getBounds());
+ }
+ return virtualBounds;
+ }
+
+ /**
+ * Puts {@code Window} bounds to client property.
+ * @param window the target {@code Window}
+ * @param bounds bounds
+ */
+ public static void putWindowNormalBounds(Window window, Rectangle bounds) {
+ if (window instanceof JFrame) {
+ ((JFrame) window).getRootPane().putClientProperty(
+ WINDOW_STATE_NORMAL_BOUNDS, bounds);
+ }
+ }
+
+ @Override
+ public void addListener(Object o, Object l) {
+ Window w = checkComponent(o);
+ w.addPropertyChangeListener("extendedState", (PropertyChangeListener)l);
+ w.addPropertyChangeListener("bounds", (PropertyChangeListener)l);
+ }
+
+ @Override
+ public void removeListener(Object o, Object l) {
+ Window w = checkComponent(o);
+ w.removePropertyChangeListener("extendedState", (PropertyChangeListener)l);
+ w.removePropertyChangeListener("bounds", (PropertyChangeListener)l);
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ updateState(evt.getSource(), this);
+ }
+
+ protected void updateState(Object o, WindowState state) {
+ Window c = checkComponent(o);
+ int frameState = Frame.NORMAL;
+ if (c instanceof Frame) {
+ frameState = ((Frame) c).getExtendedState();
+ }
+ GraphicsConfiguration gc = c.getGraphicsConfiguration();
+ Rectangle gcBounds = (gc == null) ? null : gc.getBounds();
+ Rectangle frameBounds = c.getBounds();
+ /* If this is a JFrame created by FrameView and it's been maximized,
+ * retrieve the frame's normal (not maximized) bounds. More info:
+ * see FrameStateListener#windowStateChanged in FrameView.
+ */
+ if ((c instanceof JFrame) && (0 != (frameState & Frame.MAXIMIZED_BOTH))) {
+ frameBounds = getWindowNormalBounds((JFrame) c);
+ }
+ if (frameBounds.isEmpty()) {
+ return;
+ }
+ state.setBounds(frameBounds);
+ state.setGcBounds(gcBounds);
+ state.setFrameState(frameState);
+ }
+
+ @Override
+ public State getState(Object o) {
+ WindowState result = new WindowState();
+ updateState(o, result);
+ return result;
+ }
+
+ @Override
+ public void setState(Object o, State state) {
+ Window w = checkComponent(o);
+ if ((state != null) && !(state instanceof WindowState)) {
+ throw new IllegalArgumentException("invalid state");
+ }
+ WindowState windowState = (WindowState) state;
+ if (windowState.getBounds() != null) {
+ putWindowNormalBounds(w, windowState.getBounds());
+ if (!w.isLocationByPlatform() && (state != null)) {
+
+ Rectangle gcBounds0 = windowState.getGcBounds();
+ if (gcBounds0 != null && isResizable(w)) {
+ if (computeVirtualGraphicsBounds().contains(gcBounds0.getLocation())) {
+ w.setBounds(windowState.getBounds());
+ } else {
+ w.setSize(windowState.getBounds().getSize());
+ }
+ }
+ if (w instanceof Frame) {
+ ((Frame) w).setExtendedState(windowState.getFrameState());
+
+ }
+ }
+ }
+ }
+
+ }
+
+
+ /**
+ * Just for test rapidly
+ * @param args
+ */
+ static public void main(String[] args) {
+ final SwingSession session =
+ new SwingSession(new File("/tmp/SwingSession.config"), false);
+
+ JFrame frame = new JFrame("truc");
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.setBounds(10, 20, 300, 500);
+
+ TableModel dataModel = new AbstractTableModel() {
+
+ @Override
+ public String getColumnName(int column) {
+ return "c" + column;
+ }
+
+ @Override
+ public int getColumnCount() {
+ return 5;
+ }
+
+ @Override
+ public int getRowCount() {
+ return 10;
+ }
+
+ @Override
+ public Object getValueAt(int row, int col) {
+ return new Integer(row * col);
+ }
+ };
+ JTable table = new JTable(dataModel);
+ table.setName("MaTable");
+
+ JTabbedPane tab = new JTabbedPane();
+ tab.setName("MaTab");
+ tab.add("tab1", new JTextArea());
+ tab.add("tab2", new JTextArea());
+ tab.add("tab3", new JTextArea());
+
+ JSplitPane split = new JSplitPane();
+ split.setTopComponent(new JScrollPane(table));
+ split.setBottomComponent(tab);
+
+ JButton button = new JButton("Save");
+ button.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ session.save();
+ }
+ });
+
+ frame.getContentPane().setLayout(new BorderLayout());
+ frame.getContentPane().add(button, BorderLayout.NORTH);
+ frame.getContentPane().add(split, BorderLayout.CENTER);
+
+ frame.setVisible(true);
+ session.add(frame);
+ session.save();
+ }
+}
1
0