提交 3f677623 编写于 作者: L lana

Merge

...@@ -1222,9 +1222,7 @@ public class MotifLookAndFeel extends BasicLookAndFeel ...@@ -1222,9 +1222,7 @@ public class MotifLookAndFeel extends BasicLookAndFeel
"FileChooser.enterFileNameLabelMnemonic", new Integer (KeyEvent.VK_N), // 'n' "FileChooser.enterFileNameLabelMnemonic", new Integer (KeyEvent.VK_N), // 'n'
"FileChooser.ancestorInputMap", "FileChooser.ancestorInputMap",
new UIDefaults.LazyInputMap(new Object[] { new UIDefaults.LazyInputMap(new Object[] {
"ESCAPE", "cancelSelection", "ESCAPE", "cancelSelection"
"ENTER", "approveSelection",
"ctrl ENTER", "approveSelection"
}), }),
......
...@@ -825,9 +825,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel ...@@ -825,9 +825,7 @@ public class WindowsLookAndFeel extends BasicLookAndFeel
"ESCAPE", "cancelSelection", "ESCAPE", "cancelSelection",
"F2", "editFileName", "F2", "editFileName",
"F5", "refresh", "F5", "refresh",
"BACK_SPACE", "Go Up", "BACK_SPACE", "Go Up"
"ENTER", "approveSelection",
"ctrl ENTER", "approveSelection"
}), }),
"FileView.directoryIcon", SwingUtilities2.makeIcon(getClass(), "FileView.directoryIcon", SwingUtilities2.makeIcon(getClass(),
......
...@@ -636,7 +636,7 @@ public class EventHandler implements InvocationHandler { ...@@ -636,7 +636,7 @@ public class EventHandler implements InvocationHandler {
* time a mouse button is pressed, one would write: * time a mouse button is pressed, one would write:
*<blockquote> *<blockquote>
*<pre> *<pre>
*EventHandler.create(MouseListener.class, "mousePressed", target, "origin", "point"); *EventHandler.create(MouseListener.class, target, "origin", "point", "mousePressed");
*</pre> *</pre>
*</blockquote> *</blockquote>
* *
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
package java.io; package java.io;
import java.beans.ConstructorProperties;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.net.MalformedURLException; import java.net.MalformedURLException;
...@@ -234,6 +235,7 @@ public class File ...@@ -234,6 +235,7 @@ public class File
* @throws NullPointerException * @throws NullPointerException
* If the <code>pathname</code> argument is <code>null</code> * If the <code>pathname</code> argument is <code>null</code>
*/ */
@ConstructorProperties("path")
public File(String pathname) { public File(String pathname) {
if (pathname == null) { if (pathname == null) {
throw new NullPointerException(); throw new NullPointerException();
......
...@@ -770,7 +770,8 @@ public class JFileChooser extends JComponent implements Accessible { ...@@ -770,7 +770,8 @@ public class JFileChooser extends JComponent implements Accessible {
* @since 1.4 * @since 1.4
*/ */
protected JDialog createDialog(Component parent) throws HeadlessException { protected JDialog createDialog(Component parent) throws HeadlessException {
String title = getUI().getDialogTitle(this); FileChooserUI ui = getUI();
String title = ui.getDialogTitle(this);
putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY, putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY,
title); title);
...@@ -794,6 +795,7 @@ public class JFileChooser extends JComponent implements Accessible { ...@@ -794,6 +795,7 @@ public class JFileChooser extends JComponent implements Accessible {
dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG); dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
} }
} }
dialog.getRootPane().setDefaultButton(ui.getDefaultButton(this));
dialog.pack(); dialog.pack();
dialog.setLocationRelativeTo(parent); dialog.setLocationRelativeTo(parent);
......
...@@ -41,6 +41,7 @@ import javax.swing.plaf.PopupMenuUI; ...@@ -41,6 +41,7 @@ import javax.swing.plaf.PopupMenuUI;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicComboPopup; import javax.swing.plaf.basic.BasicComboPopup;
import javax.swing.event.*; import javax.swing.event.*;
import sun.security.util.SecurityConstants;
import java.applet.Applet; import java.applet.Applet;
...@@ -320,17 +321,67 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { ...@@ -320,17 +321,67 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
* This adustment may be cancelled by invoking the application with * This adustment may be cancelled by invoking the application with
* -Djavax.swing.adjustPopupLocationToFit=false * -Djavax.swing.adjustPopupLocationToFit=false
*/ */
Point adjustPopupLocationToFitScreen(int xposition, int yposition) { Point adjustPopupLocationToFitScreen(int xPosition, int yPosition) {
Point p = new Point(xposition, yposition); Point popupLocation = new Point(xPosition, yPosition);
if(popupPostionFixDisabled == true || GraphicsEnvironment.isHeadless()) if(popupPostionFixDisabled == true || GraphicsEnvironment.isHeadless()) {
return p; return popupLocation;
}
// Get screen bounds
Rectangle scrBounds;
GraphicsConfiguration gc = getCurrentGraphicsConfiguration(popupLocation);
Toolkit toolkit = Toolkit.getDefaultToolkit(); Toolkit toolkit = Toolkit.getDefaultToolkit();
Rectangle screenBounds; if(gc != null) {
// If we have GraphicsConfiguration use it to get screen bounds
scrBounds = gc.getBounds();
} else {
// If we don't have GraphicsConfiguration use primary screen
scrBounds = new Rectangle(toolkit.getScreenSize());
}
// Calculate the screen size that popup should fit
Dimension popupSize = JPopupMenu.this.getPreferredSize();
int popupRightX = popupLocation.x + popupSize.width;
int popupBottomY = popupLocation.y + popupSize.height;
int scrWidth = scrBounds.width;
int scrHeight = scrBounds.height;
if (!canPopupOverlapTaskBar()) {
// Insets include the task bar. Take them into account.
Insets scrInsets = toolkit.getScreenInsets(gc);
scrBounds.x += scrInsets.left;
scrBounds.y += scrInsets.top;
scrWidth -= scrInsets.left + scrInsets.right;
scrHeight -= scrInsets.top + scrInsets.bottom;
}
int scrRightX = scrBounds.x + scrWidth;
int scrBottomY = scrBounds.y + scrHeight;
// Ensure that popup menu fits the screen
if (popupRightX > scrRightX) {
popupLocation.x = scrRightX - popupSize.width;
if( popupLocation.x < scrBounds.x ) {
popupLocation.x = scrBounds.x ;
}
}
if (popupBottomY > scrBottomY) {
popupLocation.y = scrBottomY - popupSize.height;
if( popupLocation.y < scrBounds.y ) {
popupLocation.y = scrBounds.y;
}
}
return popupLocation;
}
/**
* Tries to find GraphicsConfiguration
* that contains the mouse cursor position.
* Can return null.
*/
private GraphicsConfiguration getCurrentGraphicsConfiguration(
Point popupLocation) {
GraphicsConfiguration gc = null; GraphicsConfiguration gc = null;
// Try to find GraphicsConfiguration, that includes mouse
// pointer position
GraphicsEnvironment ge = GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gd = ge.getScreenDevices(); GraphicsDevice[] gd = ge.getScreenDevices();
...@@ -338,50 +389,36 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement { ...@@ -338,50 +389,36 @@ public class JPopupMenu extends JComponent implements Accessible,MenuElement {
if(gd[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) { if(gd[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
GraphicsConfiguration dgc = GraphicsConfiguration dgc =
gd[i].getDefaultConfiguration(); gd[i].getDefaultConfiguration();
if(dgc.getBounds().contains(p)) { if(dgc.getBounds().contains(popupLocation)) {
gc = dgc; gc = dgc;
break; break;
} }
} }
} }
// If not found and we have invoker, ask invoker about his gc // If not found and we have invoker, ask invoker about his gc
if(gc == null && getInvoker() != null) { if(gc == null && getInvoker() != null) {
gc = getInvoker().getGraphicsConfiguration(); gc = getInvoker().getGraphicsConfiguration();
} }
return gc;
if(gc != null) {
// If we have GraphicsConfiguration use it to get
// screen bounds
screenBounds = gc.getBounds();
} else {
// If we don't have GraphicsConfiguration use primary screen
screenBounds = new Rectangle(toolkit.getScreenSize());
} }
Dimension size; /**
* Checks that there are enough security permissions
size = JPopupMenu.this.getPreferredSize(); * to make popup "always on top", which allows to show it above the task bar.
// Use long variables to prevent overflow
long pw = (long) p.x + (long) size.width;
long ph = (long) p.y + (long) size.height;
if( pw > screenBounds.x + screenBounds.width )
p.x = screenBounds.x + screenBounds.width - size.width;
if( ph > screenBounds.y + screenBounds.height)
p.y = screenBounds.y + screenBounds.height - size.height;
/* Change is made to the desired (X,Y) values, when the
PopupMenu is too tall OR too wide for the screen
*/ */
if( p.x < screenBounds.x ) static boolean canPopupOverlapTaskBar() {
p.x = screenBounds.x ; boolean result = true;
if( p.y < screenBounds.y ) try {
p.y = screenBounds.y; SecurityManager sm = System.getSecurityManager();
if (sm != null) {
return p; sm.checkPermission(
SecurityConstants.SET_WINDOW_ALWAYS_ON_TOP_PERMISSION);
}
} catch (SecurityException se) {
// There is no permission to show popups over the task bar
result = false;
}
return result;
} }
......
...@@ -25,18 +25,15 @@ ...@@ -25,18 +25,15 @@
package javax.swing; package javax.swing;
import javax.swing.border.*;
import javax.swing.event.*; import javax.swing.event.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.accessibility.*; import javax.accessibility.*;
import java.io.Serializable; import java.io.Serializable;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException; import java.io.IOException;
import java.awt.Color; import java.awt.*;
import java.awt.Font;
import java.util.*; import java.util.*;
import java.beans.*; import java.beans.*;
...@@ -409,8 +406,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { ...@@ -409,8 +406,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
* @since 1.4 * @since 1.4
*/ */
public ChangeListener[] getChangeListeners() { public ChangeListener[] getChangeListeners() {
return (ChangeListener[])listenerList.getListeners( return listenerList.getListeners(ChangeListener.class);
ChangeListener.class);
} }
...@@ -642,9 +638,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { ...@@ -642,9 +638,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
/** /**
* Sets the model's {@code valueIsAdjusting} property. Slider look and * Sets the model's {@code valueIsAdjusting} property. Slider look and
* feel implementations should set this property to {@code true} when * feel implementations should set this property to {@code true} when
* a knob drag begins, and to {@code false} when the drag ends. The * a knob drag begins, and to {@code false} when the drag ends.
* slider model will not generate {@code ChangeEvent}s while
* {@code valueIsAdjusting} is {@code true}.
* *
* @param b the new value for the {@code valueIsAdjusting} property * @param b the new value for the {@code valueIsAdjusting} property
* @see #getValueIsAdjusting * @see #getValueIsAdjusting
...@@ -764,6 +758,33 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { ...@@ -764,6 +758,33 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
updateLabelSizes(); updateLabelSizes();
} }
/**
* {@inheritDoc}
* @since 1.7
*/
public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
if (!isShowing()) {
return false;
}
// Check that there is a label with such image
Enumeration elements = labelTable.elements();
while (elements.hasMoreElements()) {
Component component = (Component) elements.nextElement();
if (component instanceof JLabel) {
JLabel label = (JLabel) component;
if (SwingUtilities.doesIconReferenceImage(label.getIcon(), img) ||
SwingUtilities.doesIconReferenceImage(label.getDisabledIcon(), img)) {
return super.imageUpdate(img, infoflags, x, y, w, h);
}
}
}
return false;
}
/** /**
* Returns the dictionary of what labels to draw at which values. * Returns the dictionary of what labels to draw at which values.
...@@ -826,17 +847,16 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { ...@@ -826,17 +847,16 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
* @see JComponent#updateUI * @see JComponent#updateUI
*/ */
protected void updateLabelUIs() { protected void updateLabelUIs() {
if ( getLabelTable() == null ) { Dictionary labelTable = getLabelTable();
if (labelTable == null) {
return; return;
} }
Enumeration labels = getLabelTable().keys(); Enumeration labels = labelTable.keys();
while ( labels.hasMoreElements() ) { while ( labels.hasMoreElements() ) {
Object value = getLabelTable().get( labels.nextElement() ); JComponent component = (JComponent) labelTable.get(labels.nextElement());
if ( value instanceof JComponent ) {
JComponent component = (JComponent)value;
component.updateUI(); component.updateUI();
component.setSize( component.getPreferredSize() ); component.setSize(component.getPreferredSize());
}
} }
} }
...@@ -845,14 +865,11 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { ...@@ -845,14 +865,11 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
if (labelTable != null) { if (labelTable != null) {
Enumeration labels = labelTable.elements(); Enumeration labels = labelTable.elements();
while (labels.hasMoreElements()) { while (labels.hasMoreElements()) {
Object value = labels.nextElement(); JComponent component = (JComponent) labels.nextElement();
if (value instanceof JComponent) {
JComponent component = (JComponent)value;
component.setSize(component.getPreferredSize()); component.setSize(component.getPreferredSize());
} }
} }
} }
}
/** /**
...@@ -960,14 +977,14 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { ...@@ -960,14 +977,14 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
if ( e.getPropertyName().equals( "minimum" ) || if ( e.getPropertyName().equals( "minimum" ) ||
e.getPropertyName().equals( "maximum" ) ) { e.getPropertyName().equals( "maximum" ) ) {
Enumeration keys = getLabelTable().keys(); Dictionary labelTable = getLabelTable();
Object key = null; Enumeration keys = labelTable.keys();
Hashtable hashtable = new Hashtable(); Hashtable hashtable = new Hashtable();
// Save the labels that were added by the developer // Save the labels that were added by the developer
while ( keys.hasMoreElements() ) { while ( keys.hasMoreElements() ) {
key = keys.nextElement(); Object key = keys.nextElement();
Object value = getLabelTable().get( key ); Object value = labelTable.get(key);
if ( !(value instanceof LabelUIResource) ) { if ( !(value instanceof LabelUIResource) ) {
hashtable.put( key, value ); hashtable.put( key, value );
} }
...@@ -979,7 +996,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { ...@@ -979,7 +996,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
// Add the saved labels // Add the saved labels
keys = hashtable.keys(); keys = hashtable.keys();
while ( keys.hasMoreElements() ) { while ( keys.hasMoreElements() ) {
key = keys.nextElement(); Object key = keys.nextElement();
put( key, hashtable.get( key ) ); put( key, hashtable.get( key ) );
} }
...@@ -996,8 +1013,10 @@ public class JSlider extends JComponent implements SwingConstants, Accessible { ...@@ -996,8 +1013,10 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
SmartHashtable table = new SmartHashtable( increment, start ); SmartHashtable table = new SmartHashtable( increment, start );
if ( getLabelTable() != null && (getLabelTable() instanceof PropertyChangeListener) ) { Dictionary labelTable = getLabelTable();
removePropertyChangeListener( (PropertyChangeListener)getLabelTable() );
if (labelTable != null && (labelTable instanceof PropertyChangeListener)) {
removePropertyChangeListener((PropertyChangeListener) labelTable);
} }
addPropertyChangeListener( table ); addPropertyChangeListener( table );
......
...@@ -548,47 +548,46 @@ public class PopupFactory { ...@@ -548,47 +548,46 @@ public class PopupFactory {
} }
/** /**
* Returns true if the Popup can fit on the screen. * Returns true if popup can fit the screen and the owner's top parent.
* It determines can popup be lightweight or mediumweight.
*/ */
boolean fitsOnScreen() { boolean fitsOnScreen() {
boolean result = false;
Component component = getComponent(); Component component = getComponent();
if (owner != null && component != null) { if (owner != null && component != null) {
Container parent; Container parent = (Container) SwingUtilities.getRoot(owner);
int width = component.getWidth(); int popupWidth = component.getWidth();
int height = component.getHeight(); int popupHeight = component.getHeight();
for(parent = owner.getParent(); parent != null ; Rectangle parentBounds = parent.getBounds();
parent = parent.getParent()) {
if (parent instanceof JFrame || if (parent instanceof JFrame ||
parent instanceof JDialog || parent instanceof JDialog ||
parent instanceof JWindow) { parent instanceof JWindow) {
Rectangle r = parent.getBounds();
Insets i = parent.getInsets(); Insets i = parent.getInsets();
r.x += i.left; parentBounds.x += i.left;
r.y += i.top; parentBounds.y += i.top;
r.width -= (i.left + i.right); parentBounds.width -= i.left + i.right;
r.height -= (i.top + i.bottom); parentBounds.height -= i.top + i.bottom;
GraphicsConfiguration gc = parent.getGraphicsConfiguration(); if (JPopupMenu.canPopupOverlapTaskBar()) {
GraphicsConfiguration gc =
parent.getGraphicsConfiguration();
Rectangle popupArea = getContainerPopupArea(gc); Rectangle popupArea = getContainerPopupArea(gc);
return r.intersection(popupArea).contains(x, y, width, height); result = parentBounds.intersection(popupArea)
.contains(x, y, popupWidth, popupHeight);
} else {
result = parentBounds
.contains(x, y, popupWidth, popupHeight);
}
} else if (parent instanceof JApplet) { } else if (parent instanceof JApplet) {
Rectangle r = parent.getBounds();
Point p = parent.getLocationOnScreen(); Point p = parent.getLocationOnScreen();
parentBounds.x = p.x;
r.x = p.x; parentBounds.y = p.y;
r.y = p.y; result = parentBounds
return r.contains(x, y, width, height); .contains(x, y, popupWidth, popupHeight);
} else if (parent instanceof Window ||
parent instanceof Applet) {
// No suitable swing component found
break;
} }
} }
} return result;
return false;
} }
Rectangle getContainerPopupArea(GraphicsConfiguration gc) { Rectangle getContainerPopupArea(GraphicsConfiguration gc) {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
package javax.swing.plaf; package javax.swing.plaf;
import javax.swing.JFileChooser; import javax.swing.*;
import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileView; import javax.swing.filechooser.FileView;
import java.io.File; import java.io.File;
...@@ -46,4 +46,15 @@ public abstract class FileChooserUI extends ComponentUI ...@@ -46,4 +46,15 @@ public abstract class FileChooserUI extends ComponentUI
public abstract void rescanCurrentDirectory(JFileChooser fc); public abstract void rescanCurrentDirectory(JFileChooser fc);
public abstract void ensureFileIsVisible(JFileChooser fc, File f); public abstract void ensureFileIsVisible(JFileChooser fc, File f);
/**
* Returns default button for current <code>LookAndFeel</code>.
* <code>JFileChooser</code> will use this button as default button
* for dialog windows.
*
* @since 1.7
*/
public JButton getDefaultButton(JFileChooser fc) {
return null;
}
} }
...@@ -196,7 +196,7 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh ...@@ -196,7 +196,7 @@ public class BasicDirectoryModel extends AbstractListModel implements PropertyCh
} }
protected void sort(Vector<? extends File> v){ protected void sort(Vector<? extends File> v){
ShellFolder.sortFiles(v); ShellFolder.sort(v);
} }
// Obsolete - not used // Obsolete - not used
......
...@@ -384,6 +384,10 @@ public class BasicFileChooserUI extends FileChooserUI { ...@@ -384,6 +384,10 @@ public class BasicFileChooserUI extends FileChooserUI {
return null; return null;
} }
public JButton getDefaultButton(JFileChooser fc) {
return getApproveButton(fc);
}
public String getApproveButtonToolTipText(JFileChooser fc) { public String getApproveButtonToolTipText(JFileChooser fc) {
String tooltipText = fc.getApproveButtonToolTipText(); String tooltipText = fc.getApproveButtonToolTipText();
if(tooltipText != null) { if(tooltipText != null) {
......
...@@ -25,25 +25,12 @@ ...@@ -25,25 +25,12 @@
package javax.swing.plaf.basic; package javax.swing.plaf.basic;
import java.awt.Component;
import java.awt.Container;
import java.awt.Adjustable;
import java.awt.event.*; import java.awt.event.*;
import java.awt.FontMetrics; import java.awt.*;
import java.awt.Graphics;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Point;
import java.awt.Insets;
import java.awt.Color;
import java.awt.IllegalComponentStateException;
import java.awt.Polygon;
import java.beans.*; import java.beans.*;
import java.util.Dictionary; import java.util.Dictionary;
import java.util.Enumeration; import java.util.Enumeration;
import javax.swing.border.AbstractBorder;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*; import javax.swing.event.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
...@@ -409,7 +396,7 @@ public class BasicSliderUI extends SliderUI{ ...@@ -409,7 +396,7 @@ public class BasicSliderUI extends SliderUI{
Enumeration elements = dictionary.elements(); Enumeration elements = dictionary.elements();
int baseline = -1; int baseline = -1;
while (elements.hasMoreElements()) { while (elements.hasMoreElements()) {
Component label = (Component)elements.nextElement(); JComponent label = (JComponent) elements.nextElement();
Dimension pref = label.getPreferredSize(); Dimension pref = label.getPreferredSize();
int labelBaseline = label.getBaseline(pref.width, int labelBaseline = label.getBaseline(pref.width,
pref.height); pref.height);
...@@ -634,7 +621,7 @@ public class BasicSliderUI extends SliderUI{ ...@@ -634,7 +621,7 @@ public class BasicSliderUI extends SliderUI{
protected void calculateTrackRect() { protected void calculateTrackRect() {
int centerSpacing = 0; // used to center sliders added using BorderLayout.CENTER (bug 4275631) int centerSpacing; // used to center sliders added using BorderLayout.CENTER (bug 4275631)
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
centerSpacing = thumbRect.height; centerSpacing = thumbRect.height;
if ( slider.getPaintTicks() ) centerSpacing += getTickLength(); if ( slider.getPaintTicks() ) centerSpacing += getTickLength();
...@@ -764,7 +751,7 @@ public class BasicSliderUI extends SliderUI{ ...@@ -764,7 +751,7 @@ public class BasicSliderUI extends SliderUI{
if ( dictionary != null ) { if ( dictionary != null ) {
Enumeration keys = dictionary.keys(); Enumeration keys = dictionary.keys();
while ( keys.hasMoreElements() ) { while ( keys.hasMoreElements() ) {
Component label = (Component)dictionary.get( keys.nextElement() ); JComponent label = (JComponent) dictionary.get(keys.nextElement());
widest = Math.max( label.getPreferredSize().width, widest ); widest = Math.max( label.getPreferredSize().width, widest );
} }
} }
...@@ -777,7 +764,7 @@ public class BasicSliderUI extends SliderUI{ ...@@ -777,7 +764,7 @@ public class BasicSliderUI extends SliderUI{
if ( dictionary != null ) { if ( dictionary != null ) {
Enumeration keys = dictionary.keys(); Enumeration keys = dictionary.keys();
while ( keys.hasMoreElements() ) { while ( keys.hasMoreElements() ) {
Component label = (Component)dictionary.get( keys.nextElement() ); JComponent label = (JComponent) dictionary.get(keys.nextElement());
tallest = Math.max( label.getPreferredSize().height, tallest ); tallest = Math.max( label.getPreferredSize().height, tallest );
} }
} }
...@@ -1001,22 +988,14 @@ public class BasicSliderUI extends SliderUI{ ...@@ -1001,22 +988,14 @@ public class BasicSliderUI extends SliderUI{
public void paintTicks(Graphics g) { public void paintTicks(Graphics g) {
Rectangle tickBounds = tickRect; Rectangle tickBounds = tickRect;
int i;
int maj, min, max;
int w = tickBounds.width;
int h = tickBounds.height;
int centerEffect, tickHeight;
g.setColor(DefaultLookup.getColor(slider, this, "Slider.tickColor", Color.black)); g.setColor(DefaultLookup.getColor(slider, this, "Slider.tickColor", Color.black));
maj = slider.getMajorTickSpacing();
min = slider.getMinorTickSpacing();
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
g.translate( 0, tickBounds.y); g.translate( 0, tickBounds.y);
int value = slider.getMinimum(); int value = slider.getMinimum();
int xPos = 0; int xPos;
if ( slider.getMinorTickSpacing() > 0 ) { if ( slider.getMinorTickSpacing() > 0 ) {
while ( value <= slider.getMaximum() ) { while ( value <= slider.getMaximum() ) {
...@@ -1042,7 +1021,7 @@ public class BasicSliderUI extends SliderUI{ ...@@ -1042,7 +1021,7 @@ public class BasicSliderUI extends SliderUI{
g.translate(tickBounds.x, 0); g.translate(tickBounds.x, 0);
int value = slider.getMinimum(); int value = slider.getMinimum();
int yPos = 0; int yPos;
if ( slider.getMinorTickSpacing() > 0 ) { if ( slider.getMinorTickSpacing() > 0 ) {
int offset = 0; int offset = 0;
...@@ -1111,10 +1090,19 @@ public class BasicSliderUI extends SliderUI{ ...@@ -1111,10 +1090,19 @@ public class BasicSliderUI extends SliderUI{
Integer key = (Integer)keys.nextElement(); Integer key = (Integer)keys.nextElement();
int value = key.intValue(); int value = key.intValue();
if (value >= minValue && value <= maxValue) { if (value >= minValue && value <= maxValue) {
Component label = (Component)dictionary.get( key ); JComponent label = (JComponent) dictionary.get(key);
if (label instanceof JComponent) { label.setEnabled(enabled);
((JComponent)label).setEnabled(enabled);
if (label instanceof JLabel) {
Icon icon = label.isEnabled() ? ((JLabel) label).getIcon() : ((JLabel) label).getDisabledIcon();
if (icon instanceof ImageIcon) {
// Register Slider as an image observer. It allows to catch notifications about
// image changes (e.g. gif animation)
Toolkit.getDefaultToolkit().checkImage(((ImageIcon) icon).getImage(), -1, -1, slider);
} }
}
if ( slider.getOrientation() == JSlider.HORIZONTAL ) { if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
g.translate( 0, labelBounds.y ); g.translate( 0, labelBounds.y );
paintHorizontalLabel( g, value, label ); paintHorizontalLabel( g, value, label );
...@@ -1364,7 +1352,7 @@ public class BasicSliderUI extends SliderUI{ ...@@ -1364,7 +1352,7 @@ public class BasicSliderUI extends SliderUI{
int min = slider.getMinimum(); int min = slider.getMinimum();
int max = slider.getMaximum(); int max = slider.getMaximum();
double valueRange = (double)max - (double)min; double valueRange = (double)max - (double)min;
double pixelsPerValue = (double)trackHeight / (double)valueRange; double pixelsPerValue = (double)trackHeight / valueRange;
int trackBottom = trackY + (trackHeight - 1); int trackBottom = trackY + (trackHeight - 1);
int yPosition; int yPosition;
...@@ -1715,7 +1703,7 @@ public class BasicSliderUI extends SliderUI{ ...@@ -1715,7 +1703,7 @@ public class BasicSliderUI extends SliderUI{
* of the thumb relative to the origin of the track. * of the thumb relative to the origin of the track.
*/ */
public void mouseDragged(MouseEvent e) { public void mouseDragged(MouseEvent e) {
int thumbMiddle = 0; int thumbMiddle;
if (!slider.isEnabled()) { if (!slider.isEnabled()) {
return; return;
...@@ -1841,7 +1829,7 @@ public class BasicSliderUI extends SliderUI{ ...@@ -1841,7 +1829,7 @@ public class BasicSliderUI extends SliderUI{
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
getHandler().componentResized(e); getHandler().componentResized(e);
} }
}; }
/** /**
* Focus-change listener. * Focus-change listener.
...@@ -1903,7 +1891,7 @@ public class BasicSliderUI extends SliderUI{ ...@@ -1903,7 +1891,7 @@ public class BasicSliderUI extends SliderUI{
return b; return b;
} }
}; }
/** /**
......
...@@ -853,9 +853,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel ...@@ -853,9 +853,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel
"ESCAPE", "cancelSelection", "ESCAPE", "cancelSelection",
"F2", "editFileName", "F2", "editFileName",
"F5", "refresh", "F5", "refresh",
"BACK_SPACE", "Go Up", "BACK_SPACE", "Go Up"
"ENTER", "approveSelection",
"ctrl ENTER", "approveSelection"
}), }),
......
...@@ -25,26 +25,17 @@ ...@@ -25,26 +25,17 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import java.awt.Component;
import java.awt.Container;
import java.awt.Adjustable;
import java.awt.event.*; import java.awt.event.*;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Point; import java.awt.Point;
import java.awt.Insets; import java.awt.Insets;
import java.awt.Color;
import java.awt.IllegalComponentStateException;
import java.awt.Polygon;
import java.beans.*; import java.beans.*;
import java.util.Dictionary; import java.util.Dictionary;
import java.util.Enumeration; import java.util.Enumeration;
import javax.swing.border.AbstractBorder;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicSliderUI; import javax.swing.plaf.basic.BasicSliderUI;
import sun.swing.plaf.synth.SynthUI; import sun.swing.plaf.synth.SynthUI;
...@@ -203,8 +194,7 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener, ...@@ -203,8 +194,7 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
centerY += valueHeight + 2; centerY += valueHeight + 2;
centerY += trackHeight + trackInsets.top + trackInsets.bottom; centerY += trackHeight + trackInsets.top + trackInsets.bottom;
centerY += tickHeight + 2; centerY += tickHeight + 2;
Component label = (Component)slider.getLabelTable(). JComponent label = (JComponent) slider.getLabelTable().elements().nextElement();
elements().nextElement();
Dimension pref = label.getPreferredSize(); Dimension pref = label.getPreferredSize();
return centerY + label.getBaseline(pref.width, pref.height); return centerY + label.getBaseline(pref.width, pref.height);
} }
...@@ -226,8 +216,7 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener, ...@@ -226,8 +216,7 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
int trackHeight = contentHeight - valueHeight; int trackHeight = contentHeight - valueHeight;
int yPosition = yPositionForValue(value.intValue(), trackY, int yPosition = yPositionForValue(value.intValue(), trackY,
trackHeight); trackHeight);
Component label = (Component)slider.getLabelTable(). JComponent label = (JComponent) slider.getLabelTable().get(value);
get(value);
Dimension pref = label.getPreferredSize(); Dimension pref = label.getPreferredSize();
return yPosition - pref.height / 2 + return yPosition - pref.height / 2 +
label.getBaseline(pref.width, pref.height); label.getBaseline(pref.width, pref.height);
...@@ -434,16 +423,14 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener, ...@@ -434,16 +423,14 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
/** /**
* Calculates the pad for the label at the specified index. * Calculates the pad for the label at the specified index.
* *
* @param index index of the label to calculate pad for. * @param i index of the label to calculate pad for.
* @return padding required to keep label visible. * @return padding required to keep label visible.
*/ */
private int getPadForLabel(int i) { private int getPadForLabel(int i) {
Dictionary dictionary = slider.getLabelTable();
int pad = 0; int pad = 0;
Object o = dictionary.get(i); JComponent c = (JComponent) slider.getLabelTable().get(i);
if (o != null) { if (c != null) {
Component c = (Component)o;
int centerX = xPositionForValue(i); int centerX = xPositionForValue(i);
int cHalfWidth = c.getPreferredSize().width / 2; int cHalfWidth = c.getPreferredSize().width / 2;
if (centerX - cHalfWidth < insetCache.left) { if (centerX - cHalfWidth < insetCache.left) {
...@@ -500,8 +487,6 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener, ...@@ -500,8 +487,6 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
} }
} }
private static Rectangle unionRect = new Rectangle();
public void setThumbLocation(int x, int y) { public void setThumbLocation(int x, int y) {
super.setThumbLocation(x, y); super.setThumbLocation(x, y);
// Value rect is tied to the thumb location. We need to repaint when // Value rect is tied to the thumb location. We need to repaint when
...@@ -544,7 +529,7 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener, ...@@ -544,7 +529,7 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
trackBorder; trackBorder;
int trackLength = trackBottom - trackTop; int trackLength = trackBottom - trackTop;
double valueRange = (double)max - (double)min; double valueRange = (double)max - (double)min;
double pixelsPerValue = (double)trackLength / (double)valueRange; double pixelsPerValue = (double)trackLength / valueRange;
int yPosition; int yPosition;
if (!drawInverted()) { if (!drawInverted()) {
...@@ -802,8 +787,7 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener, ...@@ -802,8 +787,7 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
} }
public void mouseDragged(MouseEvent e) { public void mouseDragged(MouseEvent e) {
SynthScrollBarUI ui; int thumbMiddle;
int thumbMiddle = 0;
if (!slider.isEnabled()) { if (!slider.isEnabled()) {
return; return;
......
...@@ -333,17 +333,24 @@ public abstract class FlowView extends BoxView { ...@@ -333,17 +333,24 @@ public abstract class FlowView extends BoxView {
* @since 1.3 * @since 1.3
*/ */
public static class FlowStrategy { public static class FlowStrategy {
int damageStart = Integer.MAX_VALUE; Position damageStart = null;
Vector<View> viewBuffer; Vector<View> viewBuffer;
void addDamage(FlowView fv, int offset) { void addDamage(FlowView fv, int offset) {
if (offset >= fv.getStartOffset() && offset < fv.getEndOffset()) { if (offset >= fv.getStartOffset() && offset < fv.getEndOffset()) {
damageStart = Math.min(damageStart, offset); if (damageStart == null || offset < damageStart.getOffset()) {
try {
damageStart = fv.getDocument().createPosition(offset);
} catch (BadLocationException e) {
// shouldn't happen since offset is inside view bounds
assert(false);
}
}
} }
} }
void unsetDamage() { void unsetDamage() {
damageStart = Integer.MAX_VALUE; damageStart = null;
} }
/** /**
...@@ -438,13 +445,14 @@ public abstract class FlowView extends BoxView { ...@@ -438,13 +445,14 @@ public abstract class FlowView extends BoxView {
int p1 = fv.getEndOffset(); int p1 = fv.getEndOffset();
if (fv.majorAllocValid) { if (fv.majorAllocValid) {
if (damageStart == Integer.MAX_VALUE) { if (damageStart == null) {
return; return;
} }
// In some cases there's no view at position damageStart, so // In some cases there's no view at position damageStart, so
// step back and search again. See 6452106 for details. // step back and search again. See 6452106 for details.
while ((rowIndex = fv.getViewIndexAtPosition(damageStart)) < 0) { int offset = damageStart.getOffset();
damageStart--; while ((rowIndex = fv.getViewIndexAtPosition(offset)) < 0) {
offset--;
} }
if (rowIndex > 0) { if (rowIndex > 0) {
rowIndex--; rowIndex--;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
package sun.awt.shell; package sun.awt.shell;
import javax.swing.*;
import java.awt.Image; import java.awt.Image;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.io.*; import java.io.*;
...@@ -37,6 +38,10 @@ import java.util.*; ...@@ -37,6 +38,10 @@ import java.util.*;
*/ */
public abstract class ShellFolder extends File { public abstract class ShellFolder extends File {
private static final String COLUMN_NAME = "FileChooser.fileNameHeaderText";
private static final String COLUMN_SIZE = "FileChooser.fileSizeHeaderText";
private static final String COLUMN_DATE = "FileChooser.fileDateHeaderText";
protected ShellFolder parent; protected ShellFolder parent;
/** /**
...@@ -268,8 +273,45 @@ public abstract class ShellFolder extends File { ...@@ -268,8 +273,45 @@ public abstract class ShellFolder extends File {
// Override File methods // Override File methods
public static void sortFiles(List files) { public static void sort(List<? extends File> files) {
shellFolderManager.sortFiles(files); if (files == null || files.size() <= 1) {
return;
}
// Check that we can use the ShellFolder.sortChildren() method:
// 1. All files have the same non-null parent
// 2. All files is ShellFolders
File commonParent = null;
for (File file : files) {
File parent = file.getParentFile();
if (parent == null || !(file instanceof ShellFolder)) {
commonParent = null;
break;
}
if (commonParent == null) {
commonParent = parent;
} else {
if (commonParent != parent && !commonParent.equals(parent)) {
commonParent = null;
break;
}
}
}
if (commonParent instanceof ShellFolder) {
((ShellFolder) commonParent).sortChildren(files);
} else {
Collections.sort(files, FILE_COMPARATOR);
}
}
public void sortChildren(List<? extends File> files) {
Collections.sort(files, FILE_COMPARATOR);
} }
public boolean isAbsolute() { public boolean isAbsolute() {
...@@ -356,18 +398,131 @@ public abstract class ShellFolder extends File { ...@@ -356,18 +398,131 @@ public abstract class ShellFolder extends File {
} }
public static ShellFolderColumnInfo[] getFolderColumns(File dir) { public static ShellFolderColumnInfo[] getFolderColumns(File dir) {
return shellFolderManager.getFolderColumns(dir); ShellFolderColumnInfo[] columns = null;
if (dir instanceof ShellFolder) {
columns = ((ShellFolder) dir).getFolderColumns();
} }
public static Object getFolderColumnValue(File file, int column) { if (columns == null) {
return shellFolderManager.getFolderColumnValue(file, column); columns = new ShellFolderColumnInfo[]{
new ShellFolderColumnInfo(COLUMN_NAME, 150,
SwingConstants.LEADING, true, null,
FILE_COMPARATOR),
new ShellFolderColumnInfo(COLUMN_SIZE, 75,
SwingConstants.RIGHT, true, null,
DEFAULT_COMPARATOR, true),
new ShellFolderColumnInfo(COLUMN_DATE, 130,
SwingConstants.LEADING, true, null,
DEFAULT_COMPARATOR, true)
};
}
return columns;
} }
public ShellFolderColumnInfo[] getFolderColumns() { public ShellFolderColumnInfo[] getFolderColumns() {
return null; return null;
} }
public static Object getFolderColumnValue(File file, int column) {
if (file instanceof ShellFolder) {
Object value = ((ShellFolder)file).getFolderColumnValue(column);
if (value != null) {
return value;
}
}
if (file == null || !file.exists()) {
return null;
}
switch (column) {
case 0:
// By default, file name will be rendered using getSystemDisplayName()
return file;
case 1: // size
return file.isDirectory() ? null : Long.valueOf(file.length());
case 2: // date
if (isFileSystemRoot(file)) {
return null;
}
long time = file.lastModified();
return (time == 0L) ? null : new Date(time);
default:
return null;
}
}
public Object getFolderColumnValue(int column) { public Object getFolderColumnValue(int column) {
return null; return null;
} }
/**
* Provides a default comparator for the default column set
*/
private static final Comparator DEFAULT_COMPARATOR = new Comparator() {
public int compare(Object o1, Object o2) {
int gt;
if (o1 == null && o2 == null) {
gt = 0;
} else if (o1 != null && o2 == null) {
gt = 1;
} else if (o1 == null && o2 != null) {
gt = -1;
} else if (o1 instanceof Comparable) {
gt = ((Comparable) o1).compareTo(o2);
} else {
gt = 0;
}
return gt;
}
};
private static final Comparator<File> FILE_COMPARATOR = new Comparator<File>() {
public int compare(File f1, File f2) {
ShellFolder sf1 = null;
ShellFolder sf2 = null;
if (f1 instanceof ShellFolder) {
sf1 = (ShellFolder) f1;
if (sf1.isFileSystem()) {
sf1 = null;
}
}
if (f2 instanceof ShellFolder) {
sf2 = (ShellFolder) f2;
if (sf2.isFileSystem()) {
sf2 = null;
}
}
if (sf1 != null && sf2 != null) {
return sf1.compareTo(sf2);
} else if (sf1 != null) {
// Non-file shellfolders sort before files
return -1;
} else if (sf2 != null) {
return 1;
} else {
String name1 = f1.getName();
String name2 = f2.getName();
// First ignore case when comparing
int diff = name1.compareToIgnoreCase(name2);
if (diff != 0) {
return diff;
} else {
// May differ in case (e.g. "mail" vs. "Mail")
// We need this test for consistent sorting
return name1.compareTo(name2);
}
}
}
};
} }
...@@ -27,8 +27,6 @@ package sun.awt.shell; ...@@ -27,8 +27,6 @@ package sun.awt.shell;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.*;
import javax.swing.SwingConstants;
/** /**
* @author Michael Martak * @author Michael Martak
...@@ -36,10 +34,6 @@ import javax.swing.SwingConstants; ...@@ -36,10 +34,6 @@ import javax.swing.SwingConstants;
*/ */
class ShellFolderManager { class ShellFolderManager {
private static final String COLUMN_NAME = "FileChooser.fileNameHeaderText";
private static final String COLUMN_SIZE = "FileChooser.fileSizeHeaderText";
private static final String COLUMN_DATE = "FileChooser.fileDateHeaderText";
/** /**
* Create a shell folder from a file. * Create a shell folder from a file.
* Override to return machine-dependent behavior. * Override to return machine-dependent behavior.
...@@ -107,142 +101,4 @@ class ShellFolderManager { ...@@ -107,142 +101,4 @@ class ShellFolderManager {
} }
return (dir.getParentFile() == null); return (dir.getParentFile() == null);
} }
public void sortFiles(List files) {
Collections.sort(files, fileComparator);
}
private Comparator fileComparator = new Comparator() {
public int compare(Object a, Object b) {
return compare((File)a, (File)b);
}
public int compare(File f1, File f2) {
ShellFolder sf1 = null;
ShellFolder sf2 = null;
if (f1 instanceof ShellFolder) {
sf1 = (ShellFolder)f1;
if (sf1.isFileSystem()) {
sf1 = null;
}
}
if (f2 instanceof ShellFolder) {
sf2 = (ShellFolder)f2;
if (sf2.isFileSystem()) {
sf2 = null;
}
}
if (sf1 != null && sf2 != null) {
return sf1.compareTo(sf2);
} else if (sf1 != null) {
return -1; // Non-file shellfolders sort before files
} else if (sf2 != null) {
return 1;
} else {
String name1 = f1.getName();
String name2 = f2.getName();
// First ignore case when comparing
int diff = name1.toLowerCase().compareTo(name2.toLowerCase());
if (diff != 0) {
return diff;
} else {
// May differ in case (e.g. "mail" vs. "Mail")
// We need this test for consistent sorting
return name1.compareTo(name2);
}
}
}
};
public ShellFolderColumnInfo[] getFolderColumns(File dir) {
ShellFolderColumnInfo[] columns = null;
if (dir instanceof ShellFolder) {
columns = ((ShellFolder)dir).getFolderColumns();
}
if (columns == null) {
columns = new ShellFolderColumnInfo[]{
new ShellFolderColumnInfo(COLUMN_NAME, 150,
SwingConstants.LEADING, true, null,
fileComparator),
new ShellFolderColumnInfo(COLUMN_SIZE, 75,
SwingConstants.RIGHT, true, null,
ComparableComparator.getInstance(), true),
new ShellFolderColumnInfo(COLUMN_DATE, 130,
SwingConstants.LEADING, true, null,
ComparableComparator.getInstance(), true)
};
}
return columns;
}
public Object getFolderColumnValue(File file, int column) {
if (file instanceof ShellFolder) {
Object value = ((ShellFolder)file).getFolderColumnValue(column);
if (value != null) {
return value;
}
}
if (file == null || !file.exists()) {
return null;
}
switch (column) {
case 0:
// By default, file name will be rendered using getSystemDisplayName()
return file;
case 1: // size
return file.isDirectory() ? null : new Long(file.length());
case 2: // date
if (isFileSystemRoot(file)) {
return null;
}
long time = file.lastModified();
return (time == 0L) ? null : new Date(time);
default:
return null;
}
}
/**
* This class provides a default comparator for the default column set
*/
private static class ComparableComparator implements Comparator {
private static Comparator instance;
public static Comparator getInstance() {
if (instance == null) {
instance = new ComparableComparator();
}
return instance;
}
public int compare(Object o1, Object o2) {
int gt;
if (o1 == null && o2 == null) {
gt = 0;
} else if (o1 != null && o2 == null) {
gt = 1;
} else if (o1 == null && o2 != null) {
gt = -1;
} else if (o1 instanceof Comparable) {
gt = ((Comparable) o1).compareTo(o2);
} else {
gt = 0;
}
return gt;
}
}
} }
...@@ -306,7 +306,7 @@ final class Win32ShellFolder2 extends ShellFolder { ...@@ -306,7 +306,7 @@ final class Win32ShellFolder2 extends ShellFolder {
* <code>java.io.File</code> instead. If not, then the object depends * <code>java.io.File</code> instead. If not, then the object depends
* on native PIDL state and should not be serialized. * on native PIDL state and should not be serialized.
* *
* @returns a <code>java.io.File</code> replacement object. If the folder * @return a <code>java.io.File</code> replacement object. If the folder
* is a not a normal directory, then returns the first non-removable * is a not a normal directory, then returns the first non-removable
* drive (normally "C:\"). * drive (normally "C:\").
*/ */
...@@ -605,10 +605,10 @@ final class Win32ShellFolder2 extends ShellFolder { ...@@ -605,10 +605,10 @@ final class Win32ShellFolder2 extends ShellFolder {
// parent so we have an IShellFolder to query. // parent so we have an IShellFolder to query.
long pIShellFolder = getIShellFolder(); long pIShellFolder = getIShellFolder();
// Now we can enumerate the objects in this folder. // Now we can enumerate the objects in this folder.
ArrayList list = new ArrayList(); ArrayList<Win32ShellFolder2> list = new ArrayList<Win32ShellFolder2>();
long pEnumObjects = getEnumObjects(pIShellFolder, includeHiddenFiles); long pEnumObjects = getEnumObjects(pIShellFolder, includeHiddenFiles);
if (pEnumObjects != 0) { if (pEnumObjects != 0) {
long childPIDL = 0; long childPIDL;
int testedAttrs = ATTRIB_FILESYSTEM | ATTRIB_FILESYSANCESTOR; int testedAttrs = ATTRIB_FILESYSTEM | ATTRIB_FILESYSANCESTOR;
do { do {
if (Thread.currentThread().isInterrupted()) { if (Thread.currentThread().isInterrupted()) {
...@@ -635,7 +635,7 @@ final class Win32ShellFolder2 extends ShellFolder { ...@@ -635,7 +635,7 @@ final class Win32ShellFolder2 extends ShellFolder {
} while (childPIDL != 0); } while (childPIDL != 0);
releaseEnumObjects(pEnumObjects); releaseEnumObjects(pEnumObjects);
} }
return (ShellFolder[])list.toArray(new ShellFolder[list.size()]); return list.toArray(new ShellFolder[list.size()]);
} }
...@@ -648,7 +648,7 @@ final class Win32ShellFolder2 extends ShellFolder { ...@@ -648,7 +648,7 @@ final class Win32ShellFolder2 extends ShellFolder {
long pIShellFolder = getIShellFolder(); long pIShellFolder = getIShellFolder();
long pEnumObjects = getEnumObjects(pIShellFolder, true); long pEnumObjects = getEnumObjects(pIShellFolder, true);
Win32ShellFolder2 child = null; Win32ShellFolder2 child = null;
long childPIDL = 0; long childPIDL;
while ((childPIDL = getNextChild(pEnumObjects)) != 0) { while ((childPIDL = getNextChild(pEnumObjects)) != 0) {
if (getAttributes0(pIShellFolder, childPIDL, ATTRIB_FILESYSTEM) != 0) { if (getAttributes0(pIShellFolder, childPIDL, ATTRIB_FILESYSTEM) != 0) {
...@@ -983,7 +983,7 @@ final class Win32ShellFolder2 extends ShellFolder { ...@@ -983,7 +983,7 @@ final class Win32ShellFolder2 extends ShellFolder {
? SwingConstants.CENTER ? SwingConstants.CENTER
: SwingConstants.LEADING); : SwingConstants.LEADING);
column.setComparator(new ColumnComparator(i)); column.setComparator(new ColumnComparator(getIShellFolder(), i));
notNullColumns.add(column); notNullColumns.add(column);
} }
...@@ -1002,22 +1002,29 @@ final class Win32ShellFolder2 extends ShellFolder { ...@@ -1002,22 +1002,29 @@ final class Win32ShellFolder2 extends ShellFolder {
private native Object doGetColumnValue(long parentIShellFolder2, long childPIDL, int columnIdx); private native Object doGetColumnValue(long parentIShellFolder2, long childPIDL, int columnIdx);
private native int compareIDsByColumn(long pParentIShellFolder, long pidl1, long pidl2, int columnIdx); private static native int compareIDsByColumn(long pParentIShellFolder, long pidl1, long pidl2, int columnIdx);
private class ColumnComparator implements Comparator { public void sortChildren(List<? extends File> files) {
Collections.sort(files, new ColumnComparator(getIShellFolder(), 0));
}
private static class ColumnComparator implements Comparator<File> {
private final long parentIShellFolder;
private final int columnIdx; private final int columnIdx;
public ColumnComparator(int columnIdx) { public ColumnComparator(long parentIShellFolder, int columnIdx) {
this.parentIShellFolder = parentIShellFolder;
this.columnIdx = columnIdx; this.columnIdx = columnIdx;
} }
// compares 2 objects within this folder by the specified column // compares 2 objects within this folder by the specified column
public int compare(Object o, Object o1) { public int compare(File o, File o1) {
if (o instanceof Win32ShellFolder2 if (o instanceof Win32ShellFolder2
&& o1 instanceof Win32ShellFolder2) { && o1 instanceof Win32ShellFolder2) {
// delegates comparison to native method // delegates comparison to native method
return compareIDsByColumn(getIShellFolder(), return compareIDsByColumn(parentIShellFolder,
((Win32ShellFolder2) o).getRelativePIDL(), ((Win32ShellFolder2) o).getRelativePIDL(),
((Win32ShellFolder2) o1).getRelativePIDL(), ((Win32ShellFolder2) o1).getRelativePIDL(),
columnIdx); columnIdx);
......
...@@ -234,11 +234,11 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -234,11 +234,11 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
// Add third level for "My Computer" // Add third level for "My Computer"
if (folder.equals(drives)) { if (folder.equals(drives)) {
File[] thirdLevelFolders = folder.listFiles(); File[] thirdLevelFolders = folder.listFiles();
if (thirdLevelFolders != null) { if (thirdLevelFolders != null && thirdLevelFolders.length > 0) {
Arrays.sort(thirdLevelFolders, driveComparator); List<File> thirdLevelFoldersList = Arrays.asList(thirdLevelFolders);
for (File thirdLevelFolder : thirdLevelFolders) {
folders.add(thirdLevelFolder); folder.sortChildren(thirdLevelFoldersList);
} folders.addAll(thirdLevelFoldersList);
} }
} }
} }
...@@ -362,27 +362,6 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -362,27 +362,6 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
return false; return false;
} }
private Comparator driveComparator = new Comparator() {
public int compare(Object o1, Object o2) {
Win32ShellFolder2 shellFolder1 = (Win32ShellFolder2) o1;
Win32ShellFolder2 shellFolder2 = (Win32ShellFolder2) o2;
// Put drives at first
boolean isDrive1 = shellFolder1.getPath().endsWith(":\\");
if (isDrive1 ^ shellFolder2.getPath().endsWith(":\\")) {
return isDrive1 ? -1 : 1;
} else {
return shellFolder1.getPath().compareTo(shellFolder2.getPath());
}
}
};
public void sortFiles(List files) {
Collections.sort(files, fileComparator);
}
private static List topFolderList = null; private static List topFolderList = null;
static int compareShellFolders(Win32ShellFolder2 sf1, Win32ShellFolder2 sf2) { static int compareShellFolders(Win32ShellFolder2 sf1, Win32ShellFolder2 sf2) {
boolean special1 = sf1.isSpecial(); boolean special1 = sf1.isSpecial();
...@@ -418,19 +397,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -418,19 +397,9 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
return compareNames(sf1.getAbsolutePath(), sf2.getAbsolutePath()); return compareNames(sf1.getAbsolutePath(), sf2.getAbsolutePath());
} }
static int compareFiles(File f1, File f2) {
if (f1 instanceof Win32ShellFolder2) {
return f1.compareTo(f2);
}
if (f2 instanceof Win32ShellFolder2) {
return -1 * f2.compareTo(f1);
}
return compareNames(f1.getName(), f2.getName());
}
static int compareNames(String name1, String name2) { static int compareNames(String name1, String name2) {
// First ignore case when comparing // First ignore case when comparing
int diff = name1.toLowerCase().compareTo(name2.toLowerCase()); int diff = name1.compareToIgnoreCase(name2);
if (diff != 0) { if (diff != 0) {
return diff; return diff;
} else { } else {
...@@ -439,14 +408,4 @@ public class Win32ShellFolderManager2 extends ShellFolderManager { ...@@ -439,14 +408,4 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
return name1.compareTo(name2); return name1.compareTo(name2);
} }
} }
private Comparator fileComparator = new Comparator() {
public int compare(Object a, Object b) {
return compare((File)a, (File)b);
}
public int compare(File f1, File f2) {
return compareFiles(f1, f2);
}
};
} }
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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 Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6708550
* @summary Tests File encoding
* @author Sergey Malenkov
*/
import java.io.File;
public final class java_io_File extends AbstractTest<File> {
public static void main(String[] args) {
new java_io_File().test(true);
}
@Override
protected File getObject() {
return new File("test.txt"); // NON-NLS: local file
}
@Override
protected File getAnotherObject() {
return new File("/pub/demo/"); // NON-NLS: path
}
}
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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 Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6694823
* @summary Checks that popup menu cannot be partially hidden
* by the task bar in applets.
* @author Mikhail Lapshin
* @run main bug6694823
*/
import javax.swing.*;
import java.awt.*;
import sun.awt.SunToolkit;
public class bug6694823 {
private static JFrame frame;
private static JPopupMenu popup;
private static SunToolkit toolkit;
private static Insets screenInsets;
public static void main(String[] args) throws Exception {
toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGui();
}
});
// Get screen insets
screenInsets = toolkit.getScreenInsets(frame.getGraphicsConfiguration());
if (screenInsets.bottom == 0) {
// This test is only for configurations with taskbar on the bottom
return;
}
// Show popup as if from a standalone application
// The popup should be able to overlap the task bar
showPopup(false);
// Emulate applet security restrictions
toolkit.realSync();
System.setSecurityManager(new SecurityManager());
// Show popup as if from an applet
// The popup shouldn't overlap the task bar. It should be shifted up.
showPopup(true);
toolkit.realSync();
System.out.println("Test passed!");
frame.dispose();
}
private static void createGui() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setUndecorated(true);
popup = new JPopupMenu("Menu");
for (int i = 0; i < 7; i++) {
popup.add(new JMenuItem("MenuItem"));
}
JPanel panel = new JPanel();
panel.setComponentPopupMenu(popup);
frame.add(panel);
frame.setSize(200, 200);
}
private static void showPopup(final boolean shouldBeShifted) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// Place frame just above the task bar
Dimension screenSize = toolkit.getScreenSize();
frame.setLocation(screenSize.width / 2,
screenSize.height - frame.getHeight() - screenInsets.bottom);
frame.setVisible(true);
// Place popup over the task bar
Point frameLoc = frame.getLocationOnScreen();
int x = 0;
int y = frame.getHeight()
- popup.getPreferredSize().height + screenInsets.bottom;
popup.show(frame, x, y);
if (shouldBeShifted) {
if (popup.getLocationOnScreen()
.equals(new Point(frameLoc.x, frameLoc.y + y))) {
throw new RuntimeException("Popup is not shifted");
}
} else {
if (!popup.getLocationOnScreen()
.equals(new Point(frameLoc.x, frameLoc.y + y))) {
throw new RuntimeException("Popup is unexpectedly shifted");
}
}
popup.setVisible(false);
}
});
}
}
<html>
<body>
<applet code="bug4987336.class" width=600 height=400></applet>
There are four Sliders. Each of them has a label with animated gif (a cup of coffee)
and a label with static image.
Check that for every LAF animation works for all Sliders.
</body>
</html>
/*
* Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code 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 Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/* @test
@bug 4987336
@summary JSlider doesn't show label's animated icon.
@author Pavel Porvatov
@run applet/manual=done bug4987336.html
*/
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Hashtable;
public class bug4987336 extends JApplet {
private static final String IMAGE_RES = "box.gif";
private static final String ANIM_IMAGE_RES = "cupanim.gif";
public void init() {
JPanel pnLafs = new JPanel();
pnLafs.setLayout(new BoxLayout(pnLafs, BoxLayout.Y_AXIS));
ButtonGroup group = new ButtonGroup();
pnLafs.setBorder(new TitledBorder("Available Lafs"));
for (UIManager.LookAndFeelInfo lafInfo : UIManager.getInstalledLookAndFeels()) {
LafRadioButton comp = new LafRadioButton(lafInfo);
pnLafs.add(comp);
group.add(comp);
}
JPanel pnContent = new JPanel();
pnContent.setLayout(new BoxLayout(pnContent, BoxLayout.Y_AXIS));
pnContent.add(pnLafs);
pnContent.add(createSlider(true, IMAGE_RES, IMAGE_RES, ANIM_IMAGE_RES, ANIM_IMAGE_RES));
pnContent.add(createSlider(false, IMAGE_RES, IMAGE_RES, ANIM_IMAGE_RES, ANIM_IMAGE_RES));
pnContent.add(createSlider(true, ANIM_IMAGE_RES, null, IMAGE_RES, IMAGE_RES));
pnContent.add(createSlider(false, ANIM_IMAGE_RES, null, IMAGE_RES, IMAGE_RES));
getContentPane().add(new JScrollPane(pnContent));
}
private static JSlider createSlider(boolean enabled,
String firstEnabledImage, String firstDisabledImage,
String secondEnabledImage, String secondDisabledImage) {
Hashtable<Integer, JComponent> dictionary = new Hashtable<Integer, JComponent>();
dictionary.put(0, createLabel(firstEnabledImage, firstDisabledImage));
dictionary.put(1, createLabel(secondEnabledImage, secondDisabledImage));
JSlider result = new JSlider(0, 1);
result.setLabelTable(dictionary);
result.setPaintLabels(true);
result.setEnabled(enabled);
return result;
}
private static JLabel createLabel(String enabledImage, String disabledImage) {
ImageIcon enabledIcon = enabledImage == null ? null :
new ImageIcon(bug4987336.class.getResource(enabledImage));
ImageIcon disabledIcon = disabledImage == null ? null :
new ImageIcon(bug4987336.class.getResource(disabledImage));
JLabel result = new JLabel(enabledImage == null && disabledImage == null ? "No image" : "Image",
enabledIcon, SwingConstants.LEFT);
result.setDisabledIcon(disabledIcon);
return result;
}
private class LafRadioButton extends JRadioButton {
public LafRadioButton(final UIManager.LookAndFeelInfo lafInfo) {
super(lafInfo.getName(), lafInfo.getName().equals(UIManager.getLookAndFeel().getName()));
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
UIManager.setLookAndFeel(lafInfo.getClassName());
SwingUtilities.updateComponentTreeUI(bug4987336.this);
} catch (Exception ex) {
// Ignore such errors
System.out.println("Cannot set LAF " + lafInfo.getName());
}
}
});
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册