You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/11/27 04:46:24 UTC
svn commit: r479507 [1/2] -
/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/
Author: ndbeyer
Date: Sun Nov 26 19:46:23 2006
New Revision: 479507
URL: http://svn.apache.org/viewvc?view=rev&rev=479507
Log:
Cleanup
* add explicit serialVersionUID fields and comments
* add missing annotations
* format code
Modified:
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JDesktopPane.java
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JDialog.java
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFileChooser.java
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFormattedTextField.java
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFrame.java
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JInternalFrame.java
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JLabel.java
harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JLayeredPane.java
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JDesktopPane.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JDesktopPane.java?view=diff&rev=479507&r1=479506&r2=479507
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JDesktopPane.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JDesktopPane.java Sun Nov 26 19:46:23 2006
@@ -15,28 +15,28 @@
* limitations under the License.
*/
-/**
- * @author Vadim L. Bogdanov
- * @version $Revision$
- */
-
package javax.swing;
import java.awt.Component;
-
-import java.util.Vector;
-
+import java.util.ArrayList;
+import java.util.List;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
-
import javax.swing.plaf.DesktopPaneUI;
/**
- * A container used to create a virtual desktop.
- *
+ * <p>
+ * <i>JDesktopPane</i> is a container used to create a virtual desktop.
+ * </p>
+ * <h3>Implementation Notes:</h3>
+ * <ul>
+ * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
+ * optimization, not as a guarantee of serialization compatibility.</li>
+ * </ul>
*/
public class JDesktopPane extends JLayeredPane implements Accessible {
+ private static final long serialVersionUID = -5428199090710889698L;
/**
* Indicates that the entire content of the component should appear,
@@ -50,6 +50,19 @@
*/
public static final int OUTLINE_DRAG_MODE = 1;
+ protected class AccessibleJDesktopPane extends AccessibleJComponent {
+ private static final long serialVersionUID = -44586801937888192L;
+
+ protected AccessibleJDesktopPane() {
+ super();
+ }
+
+ @Override
+ public AccessibleRole getAccessibleRole() {
+ return AccessibleRole.DESKTOP_PANE;
+ }
+ }
+
// The style of dragging to use.
private int dragMode = LIVE_DRAG_MODE;
@@ -64,15 +77,6 @@
updateUI();
}
- protected class AccessibleJDesktopPane extends AccessibleJComponent {
- protected AccessibleJDesktopPane() {
- }
-
- public AccessibleRole getAccessibleRole() {
- return AccessibleRole.DESKTOP_PANE;
- }
- }
-
/**
* Sets the UI object for this component.
*
@@ -89,36 +93,32 @@
* @return UI object for this component
*/
public DesktopPaneUI getUI() {
- return (DesktopPaneUI)ui;
+ return (DesktopPaneUI) ui;
}
/**
* Resets UI object with the default object from <code>UIManager</code>
*/
+ @Override
public void updateUI() {
- setUI((DesktopPaneUI)UIManager.getUI(this));
+ setUI((DesktopPaneUI) UIManager.getUI(this));
}
/*
* Returns all internal frames in the array including iconified frames.
*/
- private JInternalFrame[] getAllFramesInArray(final Component[] array) {
- Vector vector = new Vector(array.length);
-
+ private JInternalFrame[] getAllFramesInArray(Component[] array) {
+ List<JInternalFrame> result = new ArrayList<JInternalFrame>(array.length);
for (int i = 0; i < array.length; i++) {
if (array[i] instanceof JInternalFrame) {
// internal frame
- vector.add(array[i]);
+ result.add((JInternalFrame) array[i]);
} else if (array[i] instanceof JInternalFrame.JDesktopIcon) {
// iconified internal frame
- vector.add(((JInternalFrame.JDesktopIcon)array[i]).
- getInternalFrame());
+ result.add(((JInternalFrame.JDesktopIcon) array[i]).getInternalFrame());
}
}
-
- JInternalFrame[] frames = new JInternalFrame[vector.size()];
- vector.toArray(frames);
- return frames;
+ return result.toArray(new JInternalFrame[result.size()]);
}
/**
@@ -187,11 +187,11 @@
*
* @return the accessible context for the desktop pane
*/
+ @Override
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJDesktopPane();
}
-
return accessibleContext;
}
@@ -200,6 +200,7 @@
*
* @return string representation of this desktop pane
*/
+ @Override
protected String paramString() {
return super.paramString();
}
@@ -209,6 +210,7 @@
*
* @return the string "DesktopPaneUI"
*/
+ @Override
public String getUIClassID() {
return "DesktopPaneUI";
}
@@ -218,6 +220,7 @@
*
* @return <code>true</code>
*/
+ @Override
public boolean isOpaque() {
return true;
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JDialog.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JDialog.java?view=diff&rev=479507&r1=479506&r2=479507
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JDialog.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JDialog.java Sun Nov 26 19:46:23 2006
@@ -15,11 +15,6 @@
* limitations under the License.
*/
-/**
- * @author Vadim L. Bogdanov
- * @version $Revision$
- */
-
package javax.swing;
import java.awt.AWTEvent;
@@ -32,23 +27,51 @@
import java.awt.HeadlessException;
import java.awt.KeyboardFocusManager;
import java.awt.LayoutManager;
-
import java.awt.event.WindowEvent;
-
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleStateSet;
-
import org.apache.harmony.x.swing.Utilities;
+/**
+ * <p>
+ * <i>JDialog</i>
+ * </p>
+ * <h3>Implementation Notes:</h3>
+ * <ul>
+ * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
+ * optimization, not as a guarantee of serialization compatibility.</li>
+ * </ul>
+ */
+public class JDialog extends Dialog implements WindowConstants, Accessible, RootPaneContainer {
+ private static final long serialVersionUID = -864070866424508218L;
-public class JDialog extends Dialog
- implements WindowConstants, Accessible, RootPaneContainer {
+ private static boolean defaultLookAndFeelDecorated;
- private static boolean defaultLookAndFeelDecorated = false;
+ /**
+ * This class implements accessibility support for <code>JDialog</code>.
+ */
+ protected class AccessibleJDialog extends AccessibleAWTDialog {
+ private static final long serialVersionUID = 7312926302382808523L;
+
+ protected AccessibleJDialog() {
+ }
+
+ @Override
+ public String getAccessibleName() {
+ return getTitle();
+ }
+
+ @Override
+ public AccessibleStateSet getAccessibleStateSet() {
+ return super.getAccessibleStateSet();
+ }
+ }
protected JRootPane rootPane;
+
protected boolean rootPaneCheckingEnabled;
+
protected AccessibleContext accessibleContext;
private int defaultCloseOperation = HIDE_ON_CLOSE;
@@ -65,9 +88,8 @@
* If gc is null, GraphicsConfiguration of the owner will be used.
*/
public JDialog(final Frame owner, final String title, final boolean modal,
- final GraphicsConfiguration gc) {
- super(owner == null ? JFrame.getSharedOwner() : owner,
- title, modal, gc);
+ final GraphicsConfiguration gc) {
+ super(owner == null ? JFrame.getSharedOwner() : owner, title, modal, gc);
dialogInit();
}
@@ -85,7 +107,7 @@
* true.
*/
public JDialog(final Dialog owner, final String title, final boolean modal,
- final GraphicsConfiguration gc) throws HeadlessException {
+ final GraphicsConfiguration gc) throws HeadlessException {
super(owner, title, modal, gc);
dialogInit();
}
@@ -118,8 +140,7 @@
* @throws HeadlessException - if GraphicsEnvironment.isHeadless()
* returns true.
*/
- public JDialog(final Frame owner, final String title)
- throws HeadlessException {
+ public JDialog(final Frame owner, final String title) throws HeadlessException {
this(owner, title, false);
}
@@ -149,8 +170,7 @@
* @throws HeadlessException - if GraphicsEnvironment.isHeadless()
* returns true.
*/
- public JDialog(final Dialog owner, final String title)
- throws HeadlessException {
+ public JDialog(final Dialog owner, final String title) throws HeadlessException {
this(owner, title, false);
}
@@ -165,8 +185,7 @@
* @throws HeadlessException - if GraphicsEnvironment.isHeadless()
* returns true.
*/
- public JDialog(final Frame owner, final boolean modal)
- throws HeadlessException {
+ public JDialog(final Frame owner, final boolean modal) throws HeadlessException {
this(owner, null, modal);
}
@@ -194,8 +213,7 @@
* @throws HeadlessException - if GraphicsEnvironment.isHeadless()
* returns true.
*/
- public JDialog(final Dialog owner, final boolean modal)
- throws HeadlessException {
+ public JDialog(final Dialog owner, final boolean modal) throws HeadlessException {
this(owner, null, modal);
}
@@ -220,35 +238,18 @@
* returns true.
*/
public JDialog() throws HeadlessException {
- this((Frame)null, null, false);
- }
-
- /**
- * This class implements accessibility support for <code>JDialog</code>.
- */
- protected class AccessibleJDialog extends AccessibleAWTDialog {
- protected AccessibleJDialog() {
- }
-
- public String getAccessibleName() {
- return getTitle();
- }
-
- public AccessibleStateSet getAccessibleStateSet() {
- return super.getAccessibleStateSet();
- }
+ this((Frame) null, null, false);
}
/**
*
*/
- protected void addImpl(final Component comp, final Object constraints,
- final int index) {
+ @Override
+ protected void addImpl(final Component comp, final Object constraints, final int index) {
if (isRootPaneCheckingEnabled()) {
getContentPane().add(comp, constraints, index);
return;
}
-
super.addImpl(comp, constraints, index);
}
@@ -261,9 +262,7 @@
if (rootPane != null) {
remove(rootPane);
}
-
rootPane = root;
-
if (root != null) {
super.addImpl(root, null, 0);
}
@@ -328,11 +327,11 @@
*
* @return the accessible context for the dialog
*/
+ @Override
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJDialog();
}
-
return accessibleContext;
}
@@ -341,15 +340,14 @@
*
* @return string representation of this dialog
*/
+ @Override
protected String paramString() {
String result = super.paramString();
-
if (getRootPane() != null) {
result += ",rootPane=" + getRootPane().toString();
} else {
result += ",rootPane=null";
}
-
return result;
}
@@ -358,18 +356,18 @@
*
* @param e - window event
*/
+ @Override
protected void processWindowEvent(final WindowEvent e) {
super.processWindowEvent(e);
-
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
switch (getDefaultCloseOperation()) {
- case DISPOSE_ON_CLOSE: // dispose
+ case DISPOSE_ON_CLOSE: // dispose
dispose();
break;
- case HIDE_ON_CLOSE: // hide
+ case HIDE_ON_CLOSE: // hide
setVisible(false);
break;
- case DO_NOTHING_ON_CLOSE: // do nothing
+ case DO_NOTHING_ON_CLOSE: // do nothing
break;
}
}
@@ -378,6 +376,7 @@
/**
*
*/
+ @Override
public void setLayout(final LayoutManager layout) {
if (isRootPaneCheckingEnabled()) {
getContentPane().setLayout(layout);
@@ -392,6 +391,7 @@
*
* @param g - the graphics context to paint
*/
+ @Override
public void update(final Graphics g) {
paint(g);
}
@@ -426,6 +426,7 @@
/**
*
*/
+ @Override
public void remove(final Component comp) {
if (comp == getRootPane()) {
// remove directly from JDialog
@@ -477,17 +478,13 @@
*/
protected void dialogInit() {
setRootPaneCheckingEnabled(true);
-
setRootPane(createRootPane());
-
setLocale(JComponent.getDefaultLocale());
-
// check isDefaultLookAndFeelDecorated()
if (isDefaultLookAndFeelDecorated()) {
setUndecorated(Utilities.lookAndFeelSupportsWindowDecorations());
getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
}
-
/*
* Enabling WindowEvents is required for processWindowEvent()
* to function.
@@ -498,13 +495,12 @@
* components hierarchy.
*/
enableEvents(AWTEvent.KEY_EVENT_MASK);
-
/*
* This class is a top level container for all Swing components. So,
* it has to define a default focus traversal policy.
*/
- setFocusTraversalPolicy(KeyboardFocusManager.
- getCurrentKeyboardFocusManager().getDefaultFocusTraversalPolicy());
+ setFocusTraversalPolicy(KeyboardFocusManager.getCurrentKeyboardFocusManager()
+ .getDefaultFocusTraversalPolicy());
}
/**
@@ -516,8 +512,7 @@
return defaultCloseOperation;
}
- public static void setDefaultLookAndFeelDecorated(
- final boolean defaultLookAndFeelDecorated) {
+ public static void setDefaultLookAndFeelDecorated(final boolean defaultLookAndFeelDecorated) {
JDialog.defaultLookAndFeelDecorated = defaultLookAndFeelDecorated;
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java?view=diff&rev=479507&r1=479506&r2=479507
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JEditorPane.java Sun Nov 26 19:46:23 2006
@@ -14,16 +14,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-/**
- * @author Evgeniya G. Maenkova
- * @version $Revision$
- */
-
package javax.swing;
import java.awt.Container;
import java.awt.Dimension;
-import java.awt.Rectangle;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -32,7 +26,7 @@
import java.net.URL;
import java.nio.charset.Charset;
import java.util.ArrayList;
-
+import java.util.List;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleHyperlink;
import javax.accessibility.AccessibleHypertext;
@@ -41,7 +35,6 @@
import javax.accessibility.AccessibleText;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
-import javax.swing.text.AbstractDocument;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.ChangedCharSetException;
@@ -54,21 +47,31 @@
import javax.swing.text.View;
import javax.swing.text.ViewFactory;
import javax.swing.text.WrappedPlainView;
-//import javax.swing.text.html.HTML;
-//import javax.swing.text.html.HTMLDocument;
-//import javax.swing.text.html.HTMLEditorKit;
-//import javax.swing.text.rtf.RTFEditorKit;
-
+import org.apache.harmony.luni.util.NotImplementedException;
import org.apache.harmony.x.swing.StringConstants;
+/**
+ * <p>
+ * <i>JEditorPane</i>
+ * </p>
+ * <h3>Implementation Notes:</h3>
+ * <ul>
+ * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
+ * optimization, not as a guarantee of serialization compatibility.</li>
+ * </ul>
+ */
public class JEditorPane extends JTextComponent {
- protected class AccessibleJEditorPane extends
- JTextComponent.AccessibleJTextComponent {
+ private static final long serialVersionUID = -767121239635831550L;
+ protected class AccessibleJEditorPane extends JTextComponent.AccessibleJTextComponent {
+ private static final long serialVersionUID = -6869835326921704467L;
+
+ @Override
public String getAccessibleDescription() {
return getContentType();
}
+ @Override
public AccessibleStateSet getAccessibleStateSet() {
AccessibleStateSet set = super.getAccessibleStateSet();
set.add(AccessibleState.MULTI_LINE);
@@ -77,7 +80,11 @@
}
protected class AccessibleJEditorPaneHTML extends AccessibleJEditorPane {
+ private static final long serialVersionUID = -5072331196784098614L;
+
AccessibleText text;
+
+ @Override
public AccessibleText getAccessibleText() {
if (text == null) {
text = new JEditorPaneAccessibleHypertextSupport();
@@ -86,110 +93,120 @@
}
}
- protected class JEditorPaneAccessibleHypertextSupport extends
- AccessibleJEditorPane implements AccessibleHypertext {
+ protected class JEditorPaneAccessibleHypertextSupport extends AccessibleJEditorPane
+ implements AccessibleHypertext {
+ private static final long serialVersionUID = -1462897229238717575L;
+
//Not implemented
public class HTMLLink extends AccessibleHyperlink {
- public HTMLLink(final Element e) {
-
+ public HTMLLink(Element e) throws NotImplementedException {
+ super();
+ throw new NotImplementedException();
}
- public boolean doAccessibleAction(final int i) {
- return false;
+ @Override
+ public boolean doAccessibleAction(int i) throws NotImplementedException {
+ throw new NotImplementedException();
}
- public Object getAccessibleActionAnchor(final int i) {
- return null;
+ @Override
+ public Object getAccessibleActionAnchor(int i) throws NotImplementedException {
+ throw new NotImplementedException();
}
- public int getAccessibleActionCount() {
- return 0;
+ @Override
+ public int getAccessibleActionCount() throws NotImplementedException {
+ throw new NotImplementedException();
}
- public String getAccessibleActionDescription(final int i) {
- return null;
+ @Override
+ public String getAccessibleActionDescription(int i) throws NotImplementedException {
+ throw new NotImplementedException();
}
- public Object getAccessibleActionObject(final int i) {
- return null;
+ @Override
+ public Object getAccessibleActionObject(int i) throws NotImplementedException {
+ throw new NotImplementedException();
}
- public int getEndIndex() {
- return 0;
+ @Override
+ public int getEndIndex() throws NotImplementedException {
+ throw new NotImplementedException();
}
- public int getStartIndex() {
- return 0;
+ @Override
+ public int getStartIndex() throws NotImplementedException {
+ throw new NotImplementedException();
}
- public boolean isValid() {
- return false;
+ @Override
+ public boolean isValid() throws NotImplementedException {
+ throw new NotImplementedException();
}
}
- public JEditorPaneAccessibleHypertextSupport() {
-
+ public JEditorPaneAccessibleHypertextSupport() throws NotImplementedException {
+ super();
+ throw new NotImplementedException();
}
- public AccessibleHyperlink getLink(final int linkIndex) {
- return null;
+ public AccessibleHyperlink getLink(int linkIndex) throws NotImplementedException {
+ throw new NotImplementedException();
}
- public int getLinkCount() {
- return 0;
+ public int getLinkCount() throws NotImplementedException {
+ throw new NotImplementedException();
}
- public int getLinkIndex(final int charIndex) {
- return 0;
+ public int getLinkIndex(int charIndex) throws NotImplementedException {
+ throw new NotImplementedException();
}
- public String getLinkText(final int linkIndex) {
- return null;
+ public String getLinkText(int linkIndex) throws NotImplementedException {
+ throw new NotImplementedException();
}
-
}
- public static final String HONOR_DISPLAY_PROPERTIES =
- "JEditorPane.honorDisplayProperties";
+ public static final String HONOR_DISPLAY_PROPERTIES = "JEditorPane.honorDisplayProperties";
- public static final String W3C_LENGTH_UNITS =
- "JEditorPane.w3cLengthUnits";
+ public static final String W3C_LENGTH_UNITS = "JEditorPane.w3cLengthUnits";
- private static final String uiClassID =
- "EditorPaneUI";
+ private static final String uiClassID = "EditorPaneUI";
- static final class PlainEditorKit extends DefaultEditorKit implements
- ViewFactory {
- public View create(final Element elem) {
+ static final class PlainEditorKit extends DefaultEditorKit implements ViewFactory {
+ private static final long serialVersionUID = 1L;
+
+ public View create(Element elem) {
return new WrappedPlainView(elem);
}
+ @Override
public ViewFactory getViewFactory() {
return this;
}
}
- private static final String PLAIN_CONTENT_TYPE = "text/plain";
+ private static final String PLAIN_CONTENT_TYPE = "text/plain";
- private static final String HTML_CONTENT_TYPE = "text/html";
+ private static final String HTML_CONTENT_TYPE = "text/html";
- private static final String RTF_CONTENT_TYPE = "text/rtf";
+ private static final String RTF_CONTENT_TYPE = "text/rtf";
private static final String REFERENCE_TAIL_PATTERN = "#.*";
- private static ArrayList contentTypes = new ArrayList();
+ private static List<String> contentTypes = new ArrayList<String>();
- private static ArrayList editorKitNames = new ArrayList();
+ private static List<String> editorKitNames = new ArrayList<String>();
- private static ArrayList classLoaders = new ArrayList();
+ private static List<ClassLoader> classLoaders = new ArrayList<ClassLoader>();
private static final String RTF_HEADER = "{\\rtf";
private static final String HTML_HEADER = "<html";
- private ArrayList localContentTypes = new ArrayList();
+ private List<String> localContentTypes = new ArrayList<String>();
- private ArrayList localEditorKits = new ArrayList();
+ private List<EditorKit> localEditorKits = new ArrayList<EditorKit>();
private String contentType = PLAIN_CONTENT_TYPE;
@@ -200,7 +217,6 @@
private AccessibleContext accessible;
private AccessibleContext accessibleHTML;
-
static {
contentTypes.add(PLAIN_CONTENT_TYPE);
contentTypes.add(HTML_CONTENT_TYPE);
@@ -213,20 +229,17 @@
classLoaders.add(null);
}
- public static EditorKit createEditorKitForContentType(
- final String contentType) {
+ public static EditorKit createEditorKitForContentType(final String contentType) {
int index = contentTypes.indexOf(contentType);
if (index < 0) {
return null;
}
- String kitName = (String)editorKitNames.get(index);
+ String kitName = editorKitNames.get(index);
Object loader = classLoaders.get(index);
EditorKit editorKit = null;
-
try {
- editorKit = (EditorKit)((loader != null) ? ((ClassLoader)loader)
- .loadClass(kitName).newInstance() : Class.forName(kitName)
- .newInstance());
+ editorKit = (EditorKit) ((loader != null) ? ((ClassLoader) loader).loadClass(
+ kitName).newInstance() : Class.forName(kitName).newInstance());
} catch (IllegalAccessException e) {
} catch (ClassNotFoundException e) {
} catch (InstantiationException e) {
@@ -234,20 +247,18 @@
return editorKit;
}
- public static String getEditorKitClassNameForContentType(final String
- type) {
+ public static String getEditorKitClassNameForContentType(final String type) {
int index = contentTypes.indexOf(type);
- return (index >= 0) ? (String)editorKitNames.get(index) : null;
+ return (index >= 0) ? editorKitNames.get(index) : null;
}
public static void registerEditorKitForContentType(final String type,
- final String editorKitName) {
+ final String editorKitName) {
registerEditorKitForContentType(type, editorKitName, null);
-
}
public static void registerEditorKitForContentType(final String type,
- final String editorKitName, final ClassLoader loader) {
+ final String editorKitName, final ClassLoader loader) {
int index = contentTypes.indexOf(type);
if (index >= 0) {
contentTypes.remove(index);
@@ -281,8 +292,7 @@
setPage(page);
}
- public synchronized void addHyperlinkListener(final HyperlinkListener
- listener) {
+ public synchronized void addHyperlinkListener(final HyperlinkListener listener) {
listenerList.add(HyperlinkListener.class, listener);
}
@@ -297,6 +307,7 @@
}
}
+ @Override
public AccessibleContext getAccessibleContext() {
if (HTML_CONTENT_TYPE.equals(contentType)) {
if (accessibleHTML == null) {
@@ -324,20 +335,21 @@
public EditorKit getEditorKitForContentType(final String type) {
int index = localContentTypes.indexOf(type);
if (index >= 0) {
- return (EditorKit)localEditorKits.get(index);
+ return localEditorKits.get(index);
}
EditorKit kit = JEditorPane.createEditorKitForContentType(type);
return (kit == null) ? createDefaultEditorKit() : kit;
}
public synchronized HyperlinkListener[] getHyperlinkListeners() {
- return (HyperlinkListener[])getListeners(HyperlinkListener.class);
+ return getListeners(HyperlinkListener.class);
}
public URL getPage() {
return currentPage;
}
+ @Override
public Dimension getPreferredSize() {
Dimension d = super.getPreferredSize();
Container parent = getParent();
@@ -359,6 +371,7 @@
return d;
}
+ @Override
public boolean getScrollableTracksViewportHeight() {
Container parent = getParent();
if (parent instanceof JViewport) {
@@ -370,6 +383,7 @@
return false;
}
+ @Override
public boolean getScrollableTracksViewportWidth() {
Container parent = getParent();
if (parent instanceof JViewport) {
@@ -398,12 +412,11 @@
}
buffer = new String(bytes);
if (("<" + buffer.toLowerCase()).startsWith(HTML_HEADER)) {
-
return HTML_CONTENT_TYPE;
}
} else {
if (index < RTF_HEADER.length() && !notRtf) {
- if ((char)bytes[0] != RTF_HEADER.charAt(index)) {
+ if ((char) bytes[0] != RTF_HEADER.charAt(index)) {
notRtf = true;
} else {
if (index++ == RTF_HEADER.length() - 1) {
@@ -420,15 +433,14 @@
}
private String getBaseURL(final String url) {
- return (url == null) ? null : url
- .replaceAll(REFERENCE_TAIL_PATTERN, "");
+ return (url == null) ? null : url.replaceAll(REFERENCE_TAIL_PATTERN, "");
}
protected InputStream getStream(final URL url) throws IOException {
InputStream inputStream = url.openStream();
if (url.getProtocol() == "http") {
getDocument().putProperty(Document.StreamDescriptionProperty,
- getBaseURL(url.toString()));
+ getBaseURL(url.toString()));
}
setContentType(getContentTypeByInputStream(inputStream));
//Perhaps, it is not best solution. I'm going to think about this one
@@ -436,6 +448,7 @@
return url.openStream();
}
+ @Override
public String getText() {
StringWriter writer = new StringWriter();
try {
@@ -445,43 +458,40 @@
return writer.toString();
}
+ @Override
public String getUIClassID() {
return uiClassID;
}
+ @Override
protected String paramString() {
- return super.paramString() + ","
- + "contentType=" + contentType + ","
- + "editorKit=" + editorKit + ","
- + "document=" + getDocument() + ","
- + "currentPage=" + currentPage;
- }
-
- public void read(final InputStream stream, final Object type)
- throws IOException {
- if (type instanceof String) {
- setContentType((String)type);
- }
- try {
- Document doc = getDocument();
- doc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE,
- Boolean.TRUE);
- editorKit.read(new InputStreamReader(stream), doc, 0);
- } catch (BadLocationException e) {
- }
+ return super.paramString() + "," + "contentType=" + contentType + "," + "editorKit="
+ + editorKit + "," + "document=" + getDocument() + "," + "currentPage="
+ + currentPage;
+ }
+
+ public void read(final InputStream stream, final Object type) throws IOException {
+ if (type instanceof String) {
+ setContentType((String) type);
+ }
+ try {
+ Document doc = getDocument();
+ doc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE, Boolean.TRUE);
+ editorKit.read(new InputStreamReader(stream), doc, 0);
+ } catch (BadLocationException e) {
+ }
}
- public synchronized void removeHyperlinkListener(final HyperlinkListener
- listener) {
+ public synchronized void removeHyperlinkListener(final HyperlinkListener listener) {
listenerList.remove(HyperlinkListener.class, listener);
}
+ @Override
public synchronized void replaceSelection(final String s) {
if (!isEditable()) {
new DefaultEditorKit.BeepAction().actionPerformed(null);
return;
}
-
int start = getSelectionStart();
int end = getSelectionEnd();
Document doc = getDocument();
@@ -490,8 +500,8 @@
doc.remove(start, end - start);
}
//May be these attributes placed in Document ????
- AttributeSet as = (editorKit instanceof StyledEditorKit)
- ? ((StyledEditorKit)editorKit).getInputAttributes()
+ AttributeSet as = (editorKit instanceof StyledEditorKit) ? ((StyledEditorKit) editorKit)
+ .getInputAttributes()
: null;
if (s != null) {
doc.insertString(start, s, as);
@@ -503,59 +513,59 @@
public void scrollToReference(final String ref) {
// temporarily commented-out: HTMLDocument not implemented
/*
- Document doc = getDocument();
- if (ref == null || !(doc instanceof HTMLDocument)) {
- return;
- }
- HTMLDocument.Iterator it = ((HTMLDocument)doc).getIterator(HTML.Tag.A);
- int offset = 0;
- while (it.isValid()) {
- AttributeSet set = it.getAttributes();
- Object name = set.getAttribute(HTML.Attribute.NAME);
- if (ref.equals(name)) {
- offset = it.getStartOffset();
- break;
- }
- it.next();
- }
- Rectangle rect = null;
- try {
- rect = modelToView(offset);
- } catch (BadLocationException e) {
- }
- Rectangle visibleRect = getVisibleRect();
- if (visibleRect != null) {
- rect.height = visibleRect.height;
- }
- scrollRectToVisible(rect);
- */
+ Document doc = getDocument();
+ if (ref == null || !(doc instanceof HTMLDocument)) {
+ return;
+ }
+ HTMLDocument.Iterator it = ((HTMLDocument)doc).getIterator(HTML.Tag.A);
+ int offset = 0;
+ while (it.isValid()) {
+ AttributeSet set = it.getAttributes();
+ Object name = set.getAttribute(HTML.Attribute.NAME);
+ if (ref.equals(name)) {
+ offset = it.getStartOffset();
+ break;
+ }
+ it.next();
+ }
+ Rectangle rect = null;
+ try {
+ rect = modelToView(offset);
+ } catch (BadLocationException e) {
+ }
+ Rectangle visibleRect = getVisibleRect();
+ if (visibleRect != null) {
+ rect.height = visibleRect.height;
+ }
+ scrollRectToVisible(rect);
+ */
}
/*
- private boolean changeEditoKit(final String contentType) {
- return !((RTF_CONTENT_TYPE.equals(contentType)
- && editorKit instanceof RTFEditorKit)
- || (HTML_CONTENT_TYPE.equals(contentType)
- && editorKit instanceof HTMLEditorKit)
- || (PLAIN_CONTENT_TYPE.equals(contentType)
- && editorKit instanceof PlainEditorKit));
- }
- */
-
+ private boolean changeEditoKit(final String contentType) {
+ return !((RTF_CONTENT_TYPE.equals(contentType)
+ && editorKit instanceof RTFEditorKit)
+ || (HTML_CONTENT_TYPE.equals(contentType)
+ && editorKit instanceof HTMLEditorKit)
+ || (PLAIN_CONTENT_TYPE.equals(contentType)
+ && editorKit instanceof PlainEditorKit));
+ }
+ */
public final void setContentType(final String type) {
if (type == "text/html" || type == "text/rtf") {
- System.err.println("WARNING: HTML/RTF is not supported yet. Plain text will be shown");
+ System.err
+ .println("WARNING: HTML/RTF is not supported yet. Plain text will be shown");
}
/*
- int index = contentTypes.indexOf(type);
- contentType = (index >= 0) ? (String)contentTypes.get(index)
- : PLAIN_CONTENT_TYPE;
- if (changeEditoKit(contentType)) {
- EditorKit kit = getEditorKitForContentType(contentType);
- updateEditorKit((kit != null) ? kit : new PlainEditorKit());
- updateDocument(editorKit);
- }
- */
+ int index = contentTypes.indexOf(type);
+ contentType = (index >= 0) ? (String)contentTypes.get(index)
+ : PLAIN_CONTENT_TYPE;
+ if (changeEditoKit(contentType)) {
+ EditorKit kit = getEditorKitForContentType(contentType);
+ updateEditorKit((kit != null) ? kit : new PlainEditorKit());
+ updateDocument(editorKit);
+ }
+ */
}
private String getContentTypeByEditorKit(final EditorKit kit) {
@@ -564,11 +574,11 @@
}
int index = localEditorKits.indexOf(kit);
if (index >= 0) {
- return (String)localContentTypes.get(index);
+ return localContentTypes.get(index);
}
index = editorKitNames.indexOf(kit.getClass().getName());
if (index >= 0) {
- return (String)contentTypes.get(index);
+ return contentTypes.get(index);
}
return PLAIN_CONTENT_TYPE;
}
@@ -594,7 +604,8 @@
public void setEditorKit(final EditorKit kit) {
String newContentType = getContentTypeByEditorKit(kit);
if (newContentType == "text/html" || newContentType == "text/rtf") {
- System.err.println("WARNING: HTML/RTF is not supported yet. Plain text will be shown");
+ System.err
+ .println("WARNING: HTML/RTF is not supported yet. Plain text will be shown");
} else {
updateEditorKit(kit);
updateDocument(kit);
@@ -607,8 +618,7 @@
*/
}
- public void setEditorKitForContentType(final String type,
- final EditorKit kit) {
+ public void setEditorKitForContentType(final String type, final EditorKit kit) {
int index = localContentTypes.indexOf(contentType);
if (index >= 0) {
localContentTypes.remove(index);
@@ -622,126 +632,102 @@
setPage(new URL(page));
}
- private void documentLoading(final InputStream str, final Document doc,
- final URL url)
+ private void documentLoading(final InputStream str, final Document doc, final URL url)
throws IOException {
try {
editorKit.read(str, doc, 0);
} catch (ChangedCharSetException e) {
try {
- doc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE,
- Boolean.TRUE);
+ doc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE, Boolean.TRUE);
doc.remove(0, doc.getLength());
final String htmlAttribute = e.getCharSetSpec();
final int charSetIndex = htmlAttribute.lastIndexOf("charset=");
if (charSetIndex >= 0) {
String charSet = htmlAttribute.substring(charSetIndex + 8);
- InputStreamReader reader =
- new InputStreamReader(url.openStream(),
- Charset.forName(charSet));
+ InputStreamReader reader = new InputStreamReader(url.openStream(), Charset
+ .forName(charSet));
editorKit.read(reader, doc, 0);
}
- } catch (BadLocationException e1) {
- }
- } catch (BadLocationException e) {
- }
- }
-
- private class AsynchLoad extends Thread {
- InputStream inputStream;
- boolean successfulLoading = true;
- URL url;
- public AsynchLoad(final int priority, final InputStream stream,
- final URL url) {
- super();
- setPriority(priority);
- inputStream = stream;
- this.url = url;
- }
- public void run() {
- try {
- documentLoading(inputStream, getDocument(), url);
- } catch (IOException e) {
- successfulLoading = false;
+ } catch (BadLocationException e1) {
}
+ } catch (BadLocationException e) {
}
}
public void setPage(final URL page) throws IOException {
//temporarily commented-out: HTMLDocument not implemented
/*
- String url = page.toString();
- String baseUrl = getBaseURL(url);
- Document oldDoc = getDocument();
- if (baseUrl != null
- && oldDoc != null
- && baseUrl.equals(oldDoc
- .getProperty(Document.StreamDescriptionProperty))) {
-
- scrollToReference(page.getRef());
- return;
- }
- InputStream stream = getStream(page);
- if (stream == null) {
- return;
- }
- Document newDoc = editorKit.createDefaultDocument();
- //Perhaps, it is reasonable only for HTMLDocument...
- if (newDoc instanceof HTMLDocument) {
- newDoc.putProperty(Document.StreamDescriptionProperty, baseUrl);
- newDoc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE,
- new Boolean(false));
- try {
- ((HTMLDocument)newDoc).setBase(new URL(baseUrl));
- } catch (IOException e) {
- }
- }
- //TODO Asynch loading doesn't work with completely.
- //Also page property change event is written incorrectly now
- //(at the asynchrounous loading), because loading may not be
- //completed.
- //int asynchronousLoadPriority = getAsynchronousLoadPriority(newDoc);
- int asynchronousLoadPriority = -1;
- if (asynchronousLoadPriority >= 0) {
- setDocument(newDoc);
- AsynchLoad newThread = new AsynchLoad(asynchronousLoadPriority,
- stream, page);
- newThread.start();
- if (newThread.successfulLoading) {
- changePage(page);
- }
- } else {
- try {
- documentLoading(stream, newDoc, page);
- stream.close();
- setDocument(newDoc);
- changePage(page);
- } catch (IOException e) {
- }
- }
- */
- }
-
- private void changePage(final URL newPage) {
- URL oldPage = currentPage;
- currentPage = newPage;
- firePropertyChange("page", oldPage, currentPage);
- }
-
- private int getAsynchronousLoadPriority(final Document doc) {
- if (doc instanceof AbstractDocument) {
- return ((AbstractDocument)doc).getAsynchronousLoadPriority();
- }
- return -1;
+ String url = page.toString();
+ String baseUrl = getBaseURL(url);
+ Document oldDoc = getDocument();
+ if (baseUrl != null
+ && oldDoc != null
+ && baseUrl.equals(oldDoc
+ .getProperty(Document.StreamDescriptionProperty))) {
+
+ scrollToReference(page.getRef());
+ return;
+ }
+ InputStream stream = getStream(page);
+ if (stream == null) {
+ return;
+ }
+ Document newDoc = editorKit.createDefaultDocument();
+ //Perhaps, it is reasonable only for HTMLDocument...
+ if (newDoc instanceof HTMLDocument) {
+ newDoc.putProperty(Document.StreamDescriptionProperty, baseUrl);
+ newDoc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE,
+ new Boolean(false));
+ try {
+ ((HTMLDocument)newDoc).setBase(new URL(baseUrl));
+ } catch (IOException e) {
+ }
+ }
+ //TODO Asynch loading doesn't work with completely.
+ //Also page property change event is written incorrectly now
+ //(at the asynchrounous loading), because loading may not be
+ //completed.
+ //int asynchronousLoadPriority = getAsynchronousLoadPriority(newDoc);
+ int asynchronousLoadPriority = -1;
+ if (asynchronousLoadPriority >= 0) {
+ setDocument(newDoc);
+ AsynchLoad newThread = new AsynchLoad(asynchronousLoadPriority,
+ stream, page);
+ newThread.start();
+ if (newThread.successfulLoading) {
+ changePage(page);
+ }
+ } else {
+ try {
+ documentLoading(stream, newDoc, page);
+ stream.close();
+ setDocument(newDoc);
+ changePage(page);
+ } catch (IOException e) {
+ }
+ }
+ */
}
+ //TODO uncomment when the above method is uncommented
+ // private void changePage(final URL newPage) {
+ // URL oldPage = currentPage;
+ // currentPage = newPage;
+ // firePropertyChange("page", oldPage, currentPage);
+ // }
+ //
+ // private int getAsynchronousLoadPriority(final Document doc) {
+ // if (doc instanceof AbstractDocument) {
+ // return ((AbstractDocument)doc).getAsynchronousLoadPriority();
+ // }
+ // return -1;
+ // }
+ @Override
public synchronized void setText(final String content) {
StringReader reader = new StringReader(content);
try {
read(reader, contentType);
} catch (IOException e) {
-
}
}
}
-
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFileChooser.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFileChooser.java?view=diff&rev=479507&r1=479506&r2=479507
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFileChooser.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFileChooser.java Sun Nov 26 19:46:23 2006
@@ -14,12 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-/**
- * @author Anton Avtamonov
- * @version $Revision$
- */
-
package javax.swing;
import java.awt.Component;
@@ -32,7 +26,6 @@
import java.io.File;
import java.util.Collection;
import java.util.LinkedList;
-
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
@@ -40,79 +33,134 @@
import javax.swing.filechooser.FileSystemView;
import javax.swing.filechooser.FileView;
import javax.swing.plaf.FileChooserUI;
-
import org.apache.harmony.x.swing.Utilities;
-
+/**
+ * <p>
+ * <i>JFileChooser</i>
+ * </p>
+ * <h3>Implementation Notes:</h3>
+ * <ul>
+ * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
+ * optimization, not as a guarantee of serialization compatibility.</li>
+ * </ul>
+ */
public class JFileChooser extends JComponent implements Accessible {
+ private static final long serialVersionUID = 1049148651561366602L;
+
public static final String ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY = "acceptAllFileFilterUsedChanged";
+
public static final String ACCESSORY_CHANGED_PROPERTY = "AccessoryChangedProperty";
+
public static final String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY = "ApproveButtonMnemonicChangedProperty";
+
public static final String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY = "ApproveButtonTextChangedProperty";
+
public static final String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY = "ApproveButtonToolTipTextChangedProperty";
+
public static final String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY = "ChoosableFileFilterChangedProperty";
+
public static final String CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY = "ControlButtonsAreShownChangedProperty";
+
public static final String DIALOG_TITLE_CHANGED_PROPERTY = "DialogTitleChangedProperty";
+
public static final String DIALOG_TYPE_CHANGED_PROPERTY = "DialogTypeChangedProperty";
+
public static final String DIRECTORY_CHANGED_PROPERTY = "directoryChanged";
+
public static final String FILE_FILTER_CHANGED_PROPERTY = "fileFilterChanged";
+
public static final String FILE_HIDING_CHANGED_PROPERTY = "FileHidingChanged";
+
public static final String FILE_SELECTION_MODE_CHANGED_PROPERTY = "fileSelectionChanged";
+
public static final String FILE_SYSTEM_VIEW_CHANGED_PROPERTY = "FileSystemViewChanged";
+
public static final String FILE_VIEW_CHANGED_PROPERTY = "fileViewChanged";
+
public static final String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY = "MultiSelectionEnabledChangedProperty";
+
public static final String SELECTED_FILE_CHANGED_PROPERTY = "SelectedFileChangedProperty";
+
public static final String SELECTED_FILES_CHANGED_PROPERTY = "SelectedFilesChangedProperty";
public static final String APPROVE_SELECTION = "ApproveSelection";
+
public static final String CANCEL_SELECTION = "CancelSelection";
public static final int ERROR_OPTION = -1;
+
public static final int APPROVE_OPTION = 0;
+
public static final int CANCEL_OPTION = 1;
public static final int OPEN_DIALOG = 0;
+
public static final int SAVE_DIALOG = 1;
+
public static final int CUSTOM_DIALOG = 2;
public static final int FILES_ONLY = 0;
+
public static final int DIRECTORIES_ONLY = 1;
+
public static final int FILES_AND_DIRECTORIES = 2;
private static final String UI_CLASS_ID = "FileChooserUI";
private File currentDirectory;
+
private FileSystemView fileSystemView;
+
private FileView fileView;
+
private boolean dragEnabled;
+
private boolean controlButtonsAreShown = true;
+
private int dialogType = OPEN_DIALOG;
+
private String dialogTitle;
+
private boolean fileHidingEnabled = true;
+
private FileFilter fileFilter;
+
private boolean multiSelectionEnabled;
+
private File selectedFile;
+
private JComponent accessory;
+
private File[] selectedFiles = new File[0];
- private Collection choosableFileFilters = new LinkedList();
+
+ private Collection<FileFilter> choosableFileFilters = new LinkedList<FileFilter>();
+
private String approveButtonText;
+
private String approveButtonToolTipText;
+
private int approveButtonMnemonic;
+
private int fileSelectionMode = FILES_ONLY;
+
private boolean acceptAllFileFilterUsed = true;
+
private int chooseResult;
- private JDialog fileChooserDialog;
+ private JDialog fileChooserDialog;
protected class AccessibleJFileChooser extends AccessibleJComponent {
+ private static final long serialVersionUID = -6919995775059834138L;
+
+ @Override
public AccessibleRole getAccessibleRole() {
return AccessibleRole.FILE_CHOOSER;
}
}
-
public JFileChooser() {
- this((String)null);
+ this((String) null);
}
public JFileChooser(final String currentDirectoryPath) {
@@ -124,7 +172,7 @@
}
public JFileChooser(final FileSystemView fsv) {
- this((File)null, fsv);
+ this((File) null, fsv);
}
public JFileChooser(final String currentDirectoryPath, final FileSystemView fsv) {
@@ -149,7 +197,7 @@
}
public ActionListener[] getActionListeners() {
- return (ActionListener[])listenerList.getListeners(ActionListener.class);
+ return listenerList.getListeners(ActionListener.class);
}
public void addChoosableFileFilter(final FileFilter filter) {
@@ -158,15 +206,16 @@
return;
}
choosableFileFilters.add(filter);
- firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, toFileFilterArray(choosableFileFilters));
+ firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue,
+ toFileFilterArray(choosableFileFilters));
setFileFilter(filter);
}
public boolean removeChoosableFileFilter(final FileFilter filter) {
FileFilter[] oldValue = toFileFilterArray(choosableFileFilters);
boolean result = choosableFileFilters.remove(filter);
- firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, toFileFilterArray(choosableFileFilters));
-
+ firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue,
+ toFileFilterArray(choosableFileFilters));
return result;
}
@@ -176,14 +225,14 @@
if (isAcceptAllFileFilterUsed()) {
choosableFileFilters.add(getAcceptAllFileFilter());
}
- firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, toFileFilterArray(choosableFileFilters));
+ firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue,
+ toFileFilterArray(choosableFileFilters));
}
public FileFilter[] getChoosableFileFilters() {
return toFileFilterArray(choosableFileFilters);
}
-
public void approveSelection() {
chooseResult = APPROVE_OPTION;
fireActionPerformed(APPROVE_SELECTION);
@@ -229,6 +278,7 @@
}
}
+ @Override
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJFileChooser();
@@ -268,9 +318,9 @@
String oldValue = this.approveButtonText;
this.approveButtonText = approveButtonText;
firePropertyChange(APPROVE_BUTTON_TEXT_CHANGED_PROPERTY, oldValue, approveButtonText);
-
- if (approveButtonText != null && !approveButtonText.equals(getUI().getApproveButtonText(this))) {
-// setDialogType(CUSTOM_DIALOG);
+ if (approveButtonText != null
+ && !approveButtonText.equals(getUI().getApproveButtonText(this))) {
+ // setDialogType(CUSTOM_DIALOG);
}
}
@@ -303,7 +353,8 @@
if (dir != null && dir.exists()) {
if (!dir.isDirectory()) {
File parent = fileSystemView.getParentDirectory(dir);
- while (parent != null && !isTraversable(parent) && !fileSystemView.isRoot(parent)) {
+ while (parent != null && !isTraversable(parent)
+ && !fileSystemView.isRoot(parent)) {
parent = fileSystemView.getParentDirectory(parent);
}
if (parent != null) {
@@ -316,7 +367,6 @@
if (currentDirectory == null) {
currentDirectory = fileSystemView.getDefaultDirectory();
}
-
firePropertyChange(DIRECTORY_CHANGED_PROPERTY, oldValue, currentDirectory);
}
@@ -335,13 +385,10 @@
}
public void setDialogType(final int dialogType) {
- if (dialogType != OPEN_DIALOG
- && dialogType != SAVE_DIALOG
- && dialogType != CUSTOM_DIALOG) {
-
+ if (dialogType != OPEN_DIALOG && dialogType != SAVE_DIALOG
+ && dialogType != CUSTOM_DIALOG) {
throw new IllegalArgumentException("Incorrect dialog type is specified");
}
-
int oldValue = this.dialogType;
this.dialogType = dialogType;
firePropertyChange(DIALOG_TYPE_CHANGED_PROPERTY, oldValue, dialogType);
@@ -365,7 +412,7 @@
firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, oldValue, filter);
}
- public int getFileSelectionMode() {
+ public int getFileSelectionMode() {
return fileSelectionMode;
}
@@ -400,7 +447,7 @@
public Icon getIcon(final File f) {
Icon result = fileView != null ? fileView.getIcon(f) : null;
- return result != null ? result : getUI().getFileView(this).getIcon(f);
+ return result != null ? result : getUI().getFileView(this).getIcon(f);
}
public String getDescription(final File f) {
@@ -415,7 +462,7 @@
public String getName(final File f) {
String result = fileView != null ? fileView.getName(f) : null;
- return result != null ? result : getUI().getFileView(this).getName(f);
+ return result != null ? result : getUI().getFileView(this).getName(f);
}
public File getSelectedFile() {
@@ -445,19 +492,22 @@
}
public FileChooserUI getUI() {
- return (FileChooserUI)ui;
+ return (FileChooserUI) ui;
}
+ @Override
public void updateUI() {
setUI(UIManager.getUI(this));
}
+ @Override
public String getUIClassID() {
return UI_CLASS_ID;
}
public boolean isDirectorySelectionEnabled() {
- return fileSelectionMode == DIRECTORIES_ONLY || fileSelectionMode == FILES_AND_DIRECTORIES;
+ return fileSelectionMode == DIRECTORIES_ONLY
+ || fileSelectionMode == FILES_AND_DIRECTORIES;
}
public boolean isFileHidingEnabled() {
@@ -485,7 +535,8 @@
}
public boolean isTraversable(final File f) {
- Boolean result = fileView != null ? fileView.isTraversable(f) : getUI().getFileView(this).isTraversable(f);
+ Boolean result = fileView != null ? fileView.isTraversable(f) : getUI().getFileView(
+ this).isTraversable(f);
return result != null ? result.booleanValue() : true;
}
@@ -499,7 +550,6 @@
fileChooserDialog = createDialog(parent);
chooseResult = ERROR_OPTION;
fileChooserDialog.setVisible(true);
-
return chooseResult;
}
@@ -524,12 +574,13 @@
}
protected JDialog createDialog(final Component parent) throws HeadlessException {
- Window ancestingWindow = parent instanceof Window ? (Window)parent : SwingUtilities.getWindowAncestor(parent);
+ Window ancestingWindow = parent instanceof Window ? (Window) parent : SwingUtilities
+ .getWindowAncestor(parent);
final JDialog result;
if (ancestingWindow instanceof Frame) {
- result = new JDialog((Frame)ancestingWindow);
+ result = new JDialog((Frame) ancestingWindow);
} else if (ancestingWindow instanceof Dialog) {
- result = new JDialog((Dialog)ancestingWindow);
+ result = new JDialog((Dialog) ancestingWindow);
} else {
result = new JDialog();
}
@@ -540,9 +591,7 @@
if (JDialog.isDefaultLookAndFeelDecorated()) {
result.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
}
-
result.pack();
-
return result;
}
@@ -554,8 +603,7 @@
}
}
-
- private FileFilter[] toFileFilterArray(final Collection fileFilterList) {
- return (FileFilter[])fileFilterList.toArray(new FileFilter[fileFilterList.size()]);
+ private FileFilter[] toFileFilterArray(final Collection<FileFilter> fileFilterList) {
+ return fileFilterList.toArray(new FileFilter[fileFilterList.size()]);
}
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFormattedTextField.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFormattedTextField.java?view=diff&rev=479507&r1=479506&r2=479507
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFormattedTextField.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFormattedTextField.java Sun Nov 26 19:46:23 2006
@@ -14,10 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-/**
- * @author Evgeniya G. Maenkova
- * @version $Revision$
- */
package javax.swing;
import java.awt.Toolkit;
@@ -45,18 +41,29 @@
import javax.swing.text.NumberFormatter;
import javax.swing.text.TextAction;
+/**
+ * <p>
+ * <i>JFormattedTextField</i>
+ * </p>
+ * <h3>Implementation Notes:</h3>
+ * <ul>
+ * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
+ * optimization, not as a guarantee of serialization compatibility.</li>
+ * </ul>
+ */
public class JFormattedTextField extends JTextField {
- public abstract static class AbstractFormatter implements
- Serializable {
+ private static final long serialVersionUID = 7685569367944517634L;
+ public abstract static class AbstractFormatter implements Serializable {
private JFormattedTextField textField;
private class ActionMapFormattersResource extends ActionMap {
+ private static final long serialVersionUID = 1L;
}
+ @Override
protected Object clone() throws CloneNotSupportedException {
- AbstractFormatter formatter = (AbstractFormatter)
- super.clone();
+ AbstractFormatter formatter = (AbstractFormatter) super.clone();
formatter.install(null);
return formatter;
}
@@ -112,8 +119,7 @@
textField.setEditValid(isEditValid);
}
- public abstract Object stringToValue(final String text)
- throws ParseException;
+ public abstract Object stringToValue(final String text) throws ParseException;
public void uninstall() {
removeFormattersActionMap();
@@ -121,14 +127,13 @@
setDocumentFilter(null);
}
- public abstract String valueToString(final Object value)
- throws ParseException;
+ public abstract String valueToString(final Object value) throws ParseException;
private ActionMap createActionMap(final Action[] actions) {
ActionMap result = new ActionMapFormattersResource();
for (int i = 0; i < actions.length; i++) {
- Action action = actions[i];
- result.put(action.getValue(Action.NAME), action);
+ Action action = actions[i];
+ result.put(action.getValue(Action.NAME), action);
}
return result;
}
@@ -165,7 +170,7 @@
private void setDocumentFilter(final DocumentFilter filter) {
Document doc = textField.getDocument();
if (doc instanceof AbstractDocument) {
- ((AbstractDocument)doc).setDocumentFilter(filter);
+ ((AbstractDocument) doc).setDocumentFilter(filter);
}
}
@@ -188,17 +193,18 @@
}
}
-
public abstract static class AbstractFormatterFactory {
- public abstract AbstractFormatter getFormatter(final
- JFormattedTextField tf);
+ public abstract AbstractFormatter getFormatter(final JFormattedTextField tf);
}
static class CommitAction extends NotifyAction {
+ private static final long serialVersionUID = 1L;
+
public CommitAction(final String name) {
super(name);
}
+ @Override
public void actionPerformed(final ActionEvent e) {
JTextComponent source = getTextComponent(e);
if (source instanceof JFormattedTextField) {
@@ -210,6 +216,7 @@
super.actionPerformed(e);
}
+ @Override
public boolean isEnabled() {
final JTextComponent focused = getFocusedComponent();
return focused instanceof JFormattedTextField;
@@ -217,6 +224,8 @@
}
private static class CancelAction extends TextAction {
+ private static final long serialVersionUID = 1L;
+
public CancelAction(final String name) {
super(name);
}
@@ -231,30 +240,45 @@
}
public static final int COMMIT = 0;
+
public static final int COMMIT_OR_REVERT = 1;
+
public static final int PERSIST = 3;
+
public static final int REVERT = 2;
private static final String UI_CLASS_ID = "FormattedTextFieldUI";
- private static final String FORMATTER_FACTORY_PROPERTY_NAME
- = "formatterFactory";
+
+ private static final String FORMATTER_FACTORY_PROPERTY_NAME = "formatterFactory";
+
private static final String TEXT_FORMATTER_PROPERTY_NAME = "textFormatter";
+
private static final String VALUE_PROPERTY_NAME = "value";
+
private static final String EDIT_VALID_PROPERTY_NAME = "editValid";
private static final String COMMIT_ACTION_NAME = "notify-field-accept";
+
private static final String CANCEL_ACTION_NAME = "reset-field-edit";
- private static final TextAction COMMIT_ACTION =
- new CommitAction(COMMIT_ACTION_NAME);
- private static final TextAction CANCEL_ACTION =
- new CancelAction(CANCEL_ACTION_NAME);
+
+ private static final TextAction COMMIT_ACTION = new CommitAction(COMMIT_ACTION_NAME);
+
+ private static final TextAction CANCEL_ACTION = new CancelAction(CANCEL_ACTION_NAME);
+
private static Action[] actions;
+
private AbstractFormatterFactory factory;
+
private Object value;
+
private int focusLostBehaviour = COMMIT_OR_REVERT;
+
private AbstractFormatter formatter;
+
private boolean isEditValid;
+
private DocumentListenerImpl docListener = new DocumentListenerImpl();
+
private String lastSuccessfullyCommittedText;
private class DocumentListenerImpl implements DocumentListener {
@@ -276,7 +300,7 @@
public void run() {
insertUpdate(e);
}
- });
+ });
return;
}
updateFormatterInternalValue();
@@ -287,7 +311,6 @@
SwingUtilities.invokeLater(new Runnable() {
public void run() {
removeUpdate(e);
-
}
});
return;
@@ -319,8 +342,7 @@
setFormatterFactory(createFactory(formatter));
}
- public JFormattedTextField(final AbstractFormatterFactory factory,
- final Object value) {
+ public JFormattedTextField(final AbstractFormatterFactory factory, final Object value) {
setFormatterFactory(factory);
setValue(value);
}
@@ -332,22 +354,22 @@
public void commitEdit() throws ParseException {
String text = getText();
if (formatter != null) {
- setValue(formatter.stringToValue(text));
+ setValue(formatter.stringToValue(text));
}
lastSuccessfullyCommittedText = text;
}
+ @Override
public Action[] getActions() {
if (actions == null) {
- Action[] editorKitActions = ((TextUI) ui).getEditorKit(this)
- .getActions();
+ Action[] editorKitActions = ((TextUI) ui).getEditorKit(this).getActions();
int length = editorKitActions.length;
actions = new Action[length + 2];
System.arraycopy(editorKitActions, 0, actions, 0, length);
actions[length] = COMMIT_ACTION;
actions[length + 1] = CANCEL_ACTION;
}
- return (Action[]) actions.clone();
+ return actions.clone();
}
public int getFocusLostBehavior() {
@@ -362,6 +384,7 @@
return factory;
}
+ @Override
public String getUIClassID() {
return UI_CLASS_ID;
}
@@ -378,6 +401,7 @@
return isEditValid;
}
+ @Override
protected void processFocusEvent(final FocusEvent event) {
if (event.getID() == FocusEvent.FOCUS_LOST && !event.isTemporary()) {
switch (getFocusLostBehavior()) {
@@ -408,11 +432,11 @@
private boolean changeQueryFactoryPolicy() {
int focusLostBehaviour = getFocusLostBehavior();
- return (focusLostBehaviour == PERSIST
- || focusLostBehaviour == COMMIT_OR_REVERT)
+ return (focusLostBehaviour == PERSIST || focusLostBehaviour == COMMIT_OR_REVERT)
&& lastSuccessfullyCommittedText != getText();
}
+ @Override
public void setDocument(final Document doc) {
Document oldValue = getDocument();
if (oldValue != null) {
@@ -429,18 +453,16 @@
}
public void setFocusLostBehavior(final int behavior) {
- if (behavior != COMMIT && behavior != COMMIT_OR_REVERT
- && behavior != PERSIST && behavior != REVERT) {
- throw new IllegalArgumentException("setFocusLostBehavior "
- + "must be one of: "
- + "JFormattedTextField.COMMIT, "
- + "JFormattedTextField.COMMIT_OR_"
- + "REVERT, "
- + "JFormattedTextField.PERSIST "
- + "or JFormattedTextField.REVERT");
+ if (behavior != COMMIT && behavior != COMMIT_OR_REVERT && behavior != PERSIST
+ && behavior != REVERT) {
+ throw new IllegalArgumentException("setFocusLostBehavior " + "must be one of: "
+ + "JFormattedTextField.COMMIT, " + "JFormattedTextField.COMMIT_OR_"
+ + "REVERT, " + "JFormattedTextField.PERSIST "
+ + "or JFormattedTextField.REVERT");
}
focusLostBehaviour = behavior;
}
+
/**
* A PropertyChange event ("textFormatter") is propagated to each listener
*/
@@ -453,9 +475,9 @@
formatter.install(this);
}
this.formatter = formatter;
- firePropertyChange(TEXT_FORMATTER_PROPERTY_NAME,
- oldValue, formatter);
+ firePropertyChange(TEXT_FORMATTER_PROPERTY_NAME, oldValue, formatter);
}
+
/**
* A PropertyChange event ("formattedFactory") is propagated to each
* listener.
@@ -464,8 +486,7 @@
Object oldValue = this.factory;
this.factory = factory;
updateFormatter(true);
- firePropertyChange(FORMATTER_FACTORY_PROPERTY_NAME,
- oldValue, factory);
+ firePropertyChange(FORMATTER_FACTORY_PROPERTY_NAME, oldValue, factory);
}
/**
@@ -492,8 +513,7 @@
return factory;
}
- private AbstractFormatterFactory createFactory(final AbstractFormatter
- formatter) {
+ private AbstractFormatterFactory createFactory(final AbstractFormatter formatter) {
DefaultFormatterFactory factory = new DefaultFormatterFactory();
factory.setDefaultFormatter(formatter);
return factory;
@@ -501,9 +521,9 @@
private AbstractFormatter createFormatter(final Format format) {
if (format instanceof DateFormat) {
- return new DateFormatter((DateFormat)format);
+ return new DateFormatter((DateFormat) format);
} else if (format instanceof NumberFormat) {
- return new NumberFormatter((NumberFormat)format);
+ return new NumberFormatter((NumberFormat) format);
} else {
return new InternationalFormatter(format);
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFrame.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFrame.java?view=diff&rev=479507&r1=479506&r2=479507
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFrame.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/JFrame.java Sun Nov 26 19:46:23 2006
@@ -14,12 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-/**
- * @author Vadim L. Bogdanov
- * @version $Revision$
- */
-
package javax.swing;
import java.awt.AWTEvent;
@@ -32,28 +26,57 @@
import java.awt.Image;
import java.awt.KeyboardFocusManager;
import java.awt.LayoutManager;
-
import java.awt.event.WindowEvent;
-
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleStateSet;
-
import org.apache.harmony.x.swing.StringConstants;
import org.apache.harmony.x.swing.Utilities;
-
-
-public class JFrame extends Frame
- implements WindowConstants, Accessible, RootPaneContainer {
+/**
+ * <p>
+ * <i>JFrame</i>
+ * </p>
+ * <h3>Implementation Notes:</h3>
+ * <ul>
+ * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
+ * optimization, not as a guarantee of serialization compatibility.</li>
+ * </ul>
+ */
+public class JFrame extends Frame implements WindowConstants, Accessible, RootPaneContainer {
+ private static final long serialVersionUID = -1026528232454752719L;
public static final int EXIT_ON_CLOSE = 3;
- private static boolean defaultLookAndFeelDecorated = false;
+ private static boolean defaultLookAndFeelDecorated;
+
private static Frame sharedFrame;
+ /**
+ * This class implements accessibility support for <code>JFrame</code>.
+ */
+ protected class AccessibleJFrame extends AccessibleAWTFrame {
+ private static final long serialVersionUID = -6604775962178425920L;
+
+ protected AccessibleJFrame() {
+ super();
+ }
+
+ @Override
+ public String getAccessibleName() {
+ return getTitle();
+ }
+
+ @Override
+ public AccessibleStateSet getAccessibleStateSet() {
+ return super.getAccessibleStateSet();
+ }
+ }
+
protected JRootPane rootPane;
+
protected boolean rootPaneCheckingEnabled;
+
protected AccessibleContext accessibleContext;
private int defaultCloseOperation = HIDE_ON_CLOSE;
@@ -109,32 +132,12 @@
frameInit();
}
- /**
- * This class implements accessibility support for <code>JFrame</code>.
- */
- protected class AccessibleJFrame extends AccessibleAWTFrame {
- protected AccessibleJFrame() {
- }
-
- public String getAccessibleName() {
- return getTitle();
- }
-
- public AccessibleStateSet getAccessibleStateSet() {
- return super.getAccessibleStateSet();
- }
- }
-
- /**
- *
- */
- protected void addImpl(final Component comp, final Object constraints,
- final int index) {
+ @Override
+ protected void addImpl(final Component comp, final Object constraints, final int index) {
if (isRootPaneCheckingEnabled()) {
getContentPane().add(comp, constraints, index);
return;
}
-
super.addImpl(comp, constraints, index);
}
@@ -147,9 +150,7 @@
if (rootPane != null) {
remove(rootPane);
}
-
rootPane = root;
-
if (root != null) {
super.addImpl(root, null, 0);
}
@@ -214,11 +215,11 @@
*
* @return the accessible context for the frame
*/
+ @Override
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJFrame();
}
-
return accessibleContext;
}
@@ -227,15 +228,14 @@
*
* @return string representation of this frame
*/
+ @Override
protected String paramString() {
String result = super.paramString();
-
if (getRootPane() != null) {
result += ",rootPane=" + getRootPane().toString();
} else {
result += ",rootPane=null";
}
-
return result;
}
@@ -244,20 +244,20 @@
*
* @param e - window event
*/
+ @Override
protected void processWindowEvent(final WindowEvent e) {
super.processWindowEvent(e);
-
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
switch (getDefaultCloseOperation()) {
- case DISPOSE_ON_CLOSE: // dispose
+ case DISPOSE_ON_CLOSE: // dispose
dispose();
break;
- case HIDE_ON_CLOSE: // hide
+ case HIDE_ON_CLOSE: // hide
setVisible(false);
break;
- case DO_NOTHING_ON_CLOSE: // do nothing
+ case DO_NOTHING_ON_CLOSE: // do nothing
break;
- case EXIT_ON_CLOSE: // exit
+ case EXIT_ON_CLOSE: // exit
System.exit(0);
break;
}
@@ -267,6 +267,7 @@
/**
*
*/
+ @Override
public void setLayout(final LayoutManager layout) {
if (isRootPaneCheckingEnabled()) {
getContentPane().setLayout(layout);
@@ -281,6 +282,7 @@
*
* @param g - the graphics context to paint
*/
+ @Override
public void update(final Graphics g) {
paint(g);
}
@@ -315,6 +317,7 @@
/**
*
*/
+ @Override
public void remove(final Component comp) {
// Note: differs from JInternalFrame's behavior,
// how titlePane is removed?
@@ -366,8 +369,8 @@
break;
default:
throw new IllegalArgumentException(
- "defaultCloseOperation must be one of: DO_NOTHING_ON_CLOSE,"
- + " HIDE_ON_CLOSE, DISPOSE_ON_CLOSE, or EXIT_ON_CLOSE");
+ "defaultCloseOperation must be one of: DO_NOTHING_ON_CLOSE,"
+ + " HIDE_ON_CLOSE, DISPOSE_ON_CLOSE, or EXIT_ON_CLOSE");
}
firePropertyChange("defaultCloseOperation", oldOperation, operation);
}
@@ -386,26 +389,19 @@
*/
protected void frameInit() {
setRootPaneCheckingEnabled(true);
-
setRootPane(createRootPane());
-
setLocale(JComponent.getDefaultLocale());
-
// check isDefaultLookAndFeelDecorated()
if (isDefaultLookAndFeelDecorated()) {
setUndecorated(Utilities.lookAndFeelSupportsWindowDecorations());
getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
}
-
setBackground(getContentPane().getBackground());
-
// enable events
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
enableEvents(AWTEvent.KEY_EVENT_MASK);
-
- setFocusTraversalPolicy(KeyboardFocusManager.
- getCurrentKeyboardFocusManager().
- getDefaultFocusTraversalPolicy());
+ setFocusTraversalPolicy(KeyboardFocusManager.getCurrentKeyboardFocusManager()
+ .getDefaultFocusTraversalPolicy());
}
/**
@@ -417,14 +413,14 @@
return defaultCloseOperation;
}
+ @Override
public void setIconImage(final Image image) {
Image oldValue = getIconImage();
super.setIconImage(image);
firePropertyChange(StringConstants.ICON_IMAGE_PROPERTY, oldValue, image);
}
- public static void setDefaultLookAndFeelDecorated(
- final boolean defaultLookAndFeelDecorated) {
+ public static void setDefaultLookAndFeelDecorated(final boolean defaultLookAndFeelDecorated) {
JFrame.defaultLookAndFeelDecorated = defaultLookAndFeelDecorated;
}