提交 50664a88 编写于 作者: A amenkov

Merge

...@@ -183,10 +183,22 @@ JAVA_JAVA_java = \ ...@@ -183,10 +183,22 @@ JAVA_JAVA_java = \
java/util/MissingFormatWidthException.java \ java/util/MissingFormatWidthException.java \
java/util/UnknownFormatConversionException.java \ java/util/UnknownFormatConversionException.java \
java/util/UnknownFormatFlagsException.java \ java/util/UnknownFormatFlagsException.java \
java/util/IllformedLocaleException.java \
java/util/FormatterClosedException.java \ java/util/FormatterClosedException.java \
java/util/ListResourceBundle.java \ java/util/ListResourceBundle.java \
sun/util/EmptyListResourceBundle.java \ sun/util/EmptyListResourceBundle.java \
java/util/Locale.java \ java/util/Locale.java \
sun/util/locale/AsciiUtil.java \
sun/util/locale/BaseLocale.java \
sun/util/locale/Extension.java \
sun/util/locale/InternalLocaleBuilder.java \
sun/util/locale/LanguageTag.java \
sun/util/locale/LocaleExtensions.java \
sun/util/locale/LocaleObjectCache.java \
sun/util/locale/LocaleSyntaxException.java \
sun/util/locale/ParseStatus.java \
sun/util/locale/StringTokenIterator.java \
sun/util/locale/UnicodeLocaleExtension.java \
java/util/LocaleISOData.java \ java/util/LocaleISOData.java \
sun/util/LocaleServiceProviderPool.java \ sun/util/LocaleServiceProviderPool.java \
sun/util/LocaleDataMetaInfo.java \ sun/util/LocaleDataMetaInfo.java \
......
/* /*
* Copyright (c) 2002, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -31,13 +31,14 @@ import java.util.Collections; ...@@ -31,13 +31,14 @@ import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.applet.Applet;
import java.awt.AWTEvent; import java.awt.AWTEvent;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.awt.Component; import java.awt.Component;
import java.awt.Container; import java.awt.Container;
import java.awt.Window;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.RepaintManager; import javax.swing.RepaintManager;
import javax.swing.SwingUtilities;
/** /**
* A collection of utility methods for Swing. * A collection of utility methods for Swing.
...@@ -91,7 +92,7 @@ public class SwingUtilities3 { ...@@ -91,7 +92,7 @@ public class SwingUtilities3 {
*/ */
public static void setVsyncRequested(Container rootContainer, public static void setVsyncRequested(Container rootContainer,
boolean isRequested) { boolean isRequested) {
assert SwingUtilities.getRoot(rootContainer) == rootContainer; assert (rootContainer instanceof Applet) || (rootContainer instanceof Window);
if (isRequested) { if (isRequested) {
vsyncedMap.put(rootContainer, Boolean.TRUE); vsyncedMap.put(rootContainer, Boolean.TRUE);
} else { } else {
...@@ -106,7 +107,7 @@ public class SwingUtilities3 { ...@@ -106,7 +107,7 @@ public class SwingUtilities3 {
* @return {@code true} if vsync painting is requested for {@code rootContainer} * @return {@code true} if vsync painting is requested for {@code rootContainer}
*/ */
public static boolean isVsyncRequested(Container rootContainer) { public static boolean isVsyncRequested(Container rootContainer) {
assert SwingUtilities.getRoot(rootContainer) == rootContainer; assert (rootContainer instanceof Applet) || (rootContainer instanceof Window);
return Boolean.TRUE == vsyncedMap.get(rootContainer); return Boolean.TRUE == vsyncedMap.get(rootContainer);
} }
......
/* /*
* Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -399,7 +399,7 @@ class GTKPainter extends SynthPainter { ...@@ -399,7 +399,7 @@ class GTKPainter extends SynthPainter {
} }
String detail = "arrow"; String detail = "arrow";
if (name == "ScrollBar.button") { if ((name == "ScrollBar.button") || (name == "TabbedPane.button")) {
if (arrowType == ArrowType.UP || arrowType == ArrowType.DOWN) { if (arrowType == ArrowType.UP || arrowType == ArrowType.DOWN) {
detail = "vscrollbar"; detail = "vscrollbar";
} else { } else {
...@@ -409,7 +409,7 @@ class GTKPainter extends SynthPainter { ...@@ -409,7 +409,7 @@ class GTKPainter extends SynthPainter {
name == "Spinner.previousButton") { name == "Spinner.previousButton") {
detail = "spinbutton"; detail = "spinbutton";
} else if (name != "ComboBox.arrowButton") { } else if (name != "ComboBox.arrowButton") {
assert false; assert false : "unexpected name: " + name;
} }
int gtkState = GTKLookAndFeel.synthStateToGTKState( int gtkState = GTKLookAndFeel.synthStateToGTKState(
...@@ -436,7 +436,7 @@ class GTKPainter extends SynthPainter { ...@@ -436,7 +436,7 @@ class GTKPainter extends SynthPainter {
String name = button.getName(); String name = button.getName();
String detail = "button"; String detail = "button";
int direction = SwingConstants.CENTER; int direction = SwingConstants.CENTER;
if (name == "ScrollBar.button") { if ((name == "ScrollBar.button") || (name == "TabbedPane.button")) {
Integer prop = (Integer) Integer prop = (Integer)
button.getClientProperty("__arrow_direction__"); button.getClientProperty("__arrow_direction__");
direction = (prop != null) ? direction = (prop != null) ?
...@@ -457,7 +457,7 @@ class GTKPainter extends SynthPainter { ...@@ -457,7 +457,7 @@ class GTKPainter extends SynthPainter {
} else if (name == "Spinner.nextButton") { } else if (name == "Spinner.nextButton") {
detail = "spinbutton_up"; detail = "spinbutton_up";
} else if (name != "ComboBox.arrowButton") { } else if (name != "ComboBox.arrowButton") {
assert false; assert false : "unexpected name: " + name;
} }
int state = context.getComponentState(); int state = context.getComponentState();
......
/* /*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -40,8 +40,6 @@ import javax.sound.sampled.AudioFormat.Encoding; ...@@ -40,8 +40,6 @@ import javax.sound.sampled.AudioFormat.Encoding;
*/ */
public abstract class AudioFloatConverter { public abstract class AudioFloatConverter {
public static final Encoding PCM_FLOAT = new Encoding("PCM_FLOAT");
/*************************************************************************** /***************************************************************************
* *
* LSB Filter, used filter least significant byte in samples arrays. * LSB Filter, used filter least significant byte in samples arrays.
...@@ -982,7 +980,7 @@ public abstract class AudioFloatConverter { ...@@ -982,7 +980,7 @@ public abstract class AudioFloatConverter {
format.getSampleSizeInBits() + 7) / 8) - 4); format.getSampleSizeInBits() + 7) / 8) - 4);
} }
} }
} else if (format.getEncoding().equals(PCM_FLOAT)) { } else if (format.getEncoding().equals(Encoding.PCM_FLOAT)) {
if (format.getSampleSizeInBits() == 32) { if (format.getSampleSizeInBits() == 32) {
if (format.isBigEndian()) if (format.isBigEndian())
conv = new AudioFloatConversion32B(); conv = new AudioFloatConversion32B();
......
/* /*
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -175,7 +175,6 @@ public class AudioFloatFormatConverter extends FormatConversionProvider { ...@@ -175,7 +175,6 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
for (int c = 0; c < targetChannels; c++) { for (int c = 0; c < targetChannels; c++) {
for (int i = 0, ix = off + c; i < len2; i++, ix += cs) { for (int i = 0, ix = off + c; i < len2; i++, ix += cs) {
b[ix] = conversion_buffer[i]; b[ix] = conversion_buffer[i];
;
} }
} }
} else if (targetChannels == 1) { } else if (targetChannels == 1) {
...@@ -186,7 +185,6 @@ public class AudioFloatFormatConverter extends FormatConversionProvider { ...@@ -186,7 +185,6 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
for (int c = 1; c < sourceChannels; c++) { for (int c = 1; c < sourceChannels; c++) {
for (int i = c, ix = off; i < len2; i += cs, ix++) { for (int i = c, ix = off; i < len2; i += cs, ix++) {
b[ix] += conversion_buffer[i]; b[ix] += conversion_buffer[i];
;
} }
} }
float vol = 1f / ((float) sourceChannels); float vol = 1f / ((float) sourceChannels);
...@@ -390,6 +388,7 @@ public class AudioFloatFormatConverter extends FormatConversionProvider { ...@@ -390,6 +388,7 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
return -1; return -1;
if (len < 0) if (len < 0)
return 0; return 0;
int offlen = off + len;
int remain = len / nrofchannels; int remain = len / nrofchannels;
int destPos = 0; int destPos = 0;
int in_end = ibuffer_len; int in_end = ibuffer_len;
...@@ -423,7 +422,7 @@ public class AudioFloatFormatConverter extends FormatConversionProvider { ...@@ -423,7 +422,7 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
for (int c = 0; c < nrofchannels; c++) { for (int c = 0; c < nrofchannels; c++) {
int ix = 0; int ix = 0;
float[] buff = cbuffer[c]; float[] buff = cbuffer[c];
for (int i = c; i < b.length; i += nrofchannels) { for (int i = c + off; i < offlen; i += nrofchannels) {
b[i] = buff[ix++]; b[i] = buff[ix++];
} }
} }
...@@ -447,7 +446,7 @@ public class AudioFloatFormatConverter extends FormatConversionProvider { ...@@ -447,7 +446,7 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
} }
public long skip(long len) throws IOException { public long skip(long len) throws IOException {
if (len > 0) if (len < 0)
return 0; return 0;
if (skipbuffer == null) if (skipbuffer == null)
skipbuffer = new float[1024 * targetFormat.getFrameSize()]; skipbuffer = new float[1024 * targetFormat.getFrameSize()];
...@@ -470,7 +469,7 @@ public class AudioFloatFormatConverter extends FormatConversionProvider { ...@@ -470,7 +469,7 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
} }
private Encoding[] formats = { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED, private Encoding[] formats = { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
AudioFloatConverter.PCM_FLOAT }; Encoding.PCM_FLOAT };
public AudioInputStream getAudioInputStream(Encoding targetEncoding, public AudioInputStream getAudioInputStream(Encoding targetEncoding,
AudioInputStream sourceStream) { AudioInputStream sourceStream) {
...@@ -482,7 +481,7 @@ public class AudioFloatFormatConverter extends FormatConversionProvider { ...@@ -482,7 +481,7 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
float samplerate = format.getSampleRate(); float samplerate = format.getSampleRate();
int bits = format.getSampleSizeInBits(); int bits = format.getSampleSizeInBits();
boolean bigendian = format.isBigEndian(); boolean bigendian = format.isBigEndian();
if (targetEncoding.equals(AudioFloatConverter.PCM_FLOAT)) if (targetEncoding.equals(Encoding.PCM_FLOAT))
bits = 32; bits = 32;
AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits, AudioFormat targetFormat = new AudioFormat(encoding, samplerate, bits,
channels, channels * bits / 8, samplerate, bigendian); channels, channels * bits / 8, samplerate, bigendian);
...@@ -521,19 +520,19 @@ public class AudioFloatFormatConverter extends FormatConversionProvider { ...@@ -521,19 +520,19 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
public Encoding[] getSourceEncodings() { public Encoding[] getSourceEncodings() {
return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED, return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
AudioFloatConverter.PCM_FLOAT }; Encoding.PCM_FLOAT };
} }
public Encoding[] getTargetEncodings() { public Encoding[] getTargetEncodings() {
return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED, return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
AudioFloatConverter.PCM_FLOAT }; Encoding.PCM_FLOAT };
} }
public Encoding[] getTargetEncodings(AudioFormat sourceFormat) { public Encoding[] getTargetEncodings(AudioFormat sourceFormat) {
if (AudioFloatConverter.getConverter(sourceFormat) == null) if (AudioFloatConverter.getConverter(sourceFormat) == null)
return new Encoding[0]; return new Encoding[0];
return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED, return new Encoding[] { Encoding.PCM_SIGNED, Encoding.PCM_UNSIGNED,
AudioFloatConverter.PCM_FLOAT }; Encoding.PCM_FLOAT };
} }
public AudioFormat[] getTargetFormats(Encoding targetEncoding, public AudioFormat[] getTargetFormats(Encoding targetEncoding,
...@@ -572,17 +571,17 @@ public class AudioFloatFormatConverter extends FormatConversionProvider { ...@@ -572,17 +571,17 @@ public class AudioFloatFormatConverter extends FormatConversionProvider {
} }
} }
if (targetEncoding.equals(AudioFloatConverter.PCM_FLOAT)) { if (targetEncoding.equals(Encoding.PCM_FLOAT)) {
formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, formats.add(new AudioFormat(Encoding.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4, AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
AudioSystem.NOT_SPECIFIED, false)); AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, formats.add(new AudioFormat(Encoding.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4, AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
AudioSystem.NOT_SPECIFIED, true)); AudioSystem.NOT_SPECIFIED, true));
formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, formats.add(new AudioFormat(Encoding.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8, AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
AudioSystem.NOT_SPECIFIED, false)); AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, formats.add(new AudioFormat(Encoding.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8, AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
AudioSystem.NOT_SPECIFIED, true)); AudioSystem.NOT_SPECIFIED, true));
} }
......
...@@ -42,11 +42,14 @@ public class AudioSynthesizerPropertyInfo { ...@@ -42,11 +42,14 @@ public class AudioSynthesizerPropertyInfo {
*/ */
public AudioSynthesizerPropertyInfo(String name, Object value) { public AudioSynthesizerPropertyInfo(String name, Object value) {
this.name = name; this.name = name;
this.value = value;
if (value instanceof Class) if (value instanceof Class)
valueClass = (Class)value; valueClass = (Class)value;
else if (value != null) else
valueClass = value.getClass(); {
this.value = value;
if (value != null)
valueClass = value.getClass();
}
} }
/** /**
* The name of the property. * The name of the property.
......
/* /*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -781,7 +781,7 @@ public class DLSSoundbank implements Soundbank { ...@@ -781,7 +781,7 @@ public class DLSSoundbank implements Soundbank {
} }
if (sampleformat == 3) { if (sampleformat == 3) {
audioformat = new AudioFormat( audioformat = new AudioFormat(
AudioFloatConverter.PCM_FLOAT, samplerate, bits, Encoding.PCM_FLOAT, samplerate, bits,
channels, framesize, samplerate, false); channels, framesize, samplerate, false);
} }
...@@ -965,7 +965,7 @@ public class DLSSoundbank implements Soundbank { ...@@ -965,7 +965,7 @@ public class DLSSoundbank implements Soundbank {
sampleformat = 1; sampleformat = 1;
else if (audioformat.getEncoding().equals(Encoding.PCM_SIGNED)) else if (audioformat.getEncoding().equals(Encoding.PCM_SIGNED))
sampleformat = 1; sampleformat = 1;
else if (audioformat.getEncoding().equals(AudioFloatConverter.PCM_FLOAT)) else if (audioformat.getEncoding().equals(Encoding.PCM_FLOAT))
sampleformat = 3; sampleformat = 3;
fmt_chunk.writeUnsignedShort(sampleformat); fmt_chunk.writeUnsignedShort(sampleformat);
......
...@@ -205,7 +205,8 @@ public class ModelByteBufferWavetable implements ModelWavetable { ...@@ -205,7 +205,8 @@ public class ModelByteBufferWavetable implements ModelWavetable {
} }
if (buffer.array() == null) { if (buffer.array() == null) {
return AudioFloatInputStream.getInputStream(new AudioInputStream( return AudioFloatInputStream.getInputStream(new AudioInputStream(
buffer.getInputStream(), format, buffer.capacity())); buffer.getInputStream(), format,
buffer.capacity() / format.getFrameSize()));
} }
if (buffer8 != null) { if (buffer8 != null) {
if (format.getEncoding().equals(Encoding.PCM_SIGNED) if (format.getEncoding().equals(Encoding.PCM_SIGNED)
......
...@@ -56,7 +56,7 @@ public abstract class ModelInstrument extends Instrument { ...@@ -56,7 +56,7 @@ public abstract class ModelInstrument extends Instrument {
public ModelDirector getDirector(ModelPerformer[] performers, public ModelDirector getDirector(ModelPerformer[] performers,
MidiChannel channel, ModelDirectedPlayer player) { MidiChannel channel, ModelDirectedPlayer player) {
return new ModelStandardDirector(performers, player); return new ModelStandardIndexedDirector(performers, player);
} }
public ModelPerformer[] getPerformers() { public ModelPerformer[] getPerformers() {
......
/*
* Copyright (c) 2010, Oracle and/or its affiliates. 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.media.sound;
/**
* A standard indexed director who chooses performers
* by there keyfrom,keyto,velfrom,velto properties.
*
* @author Karl Helgason
*/
public class ModelStandardIndexedDirector implements ModelDirector {
ModelPerformer[] performers;
ModelDirectedPlayer player;
boolean noteOnUsed = false;
boolean noteOffUsed = false;
// Variables needed for index
byte[][] trantables;
int[] counters;
int[][] mat;
public ModelStandardIndexedDirector(ModelPerformer[] performers,
ModelDirectedPlayer player) {
this.performers = performers;
this.player = player;
for (int i = 0; i < performers.length; i++) {
ModelPerformer p = performers[i];
if (p.isReleaseTriggered()) {
noteOffUsed = true;
} else {
noteOnUsed = true;
}
}
buildindex();
}
private int[] lookupIndex(int x, int y) {
if ((x >= 0) && (x < 128) && (y >= 0) && (y < 128)) {
int xt = trantables[0][x];
int yt = trantables[1][y];
if (xt != -1 && yt != -1) {
return mat[xt + yt * counters[0]];
}
}
return null;
}
private int restrict(int value) {
if(value < 0) return 0;
if(value > 127) return 127;
return value;
}
private void buildindex() {
trantables = new byte[2][129];
counters = new int[trantables.length];
for (ModelPerformer performer : performers) {
int keyFrom = performer.getKeyFrom();
int keyTo = performer.getKeyTo();
int velFrom = performer.getVelFrom();
int velTo = performer.getVelTo();
if (keyFrom > keyTo) continue;
if (velFrom > velTo) continue;
keyFrom = restrict(keyFrom);
keyTo = restrict(keyTo);
velFrom = restrict(velFrom);
velTo = restrict(velTo);
trantables[0][keyFrom] = 1;
trantables[0][keyTo + 1] = 1;
trantables[1][velFrom] = 1;
trantables[1][velTo + 1] = 1;
}
for (int d = 0; d < trantables.length; d++) {
byte[] trantable = trantables[d];
int transize = trantable.length;
for (int i = transize - 1; i >= 0; i--) {
if (trantable[i] == 1) {
trantable[i] = -1;
break;
}
trantable[i] = -1;
}
int counter = -1;
for (int i = 0; i < transize; i++) {
if (trantable[i] != 0) {
counter++;
if (trantable[i] == -1)
break;
}
trantable[i] = (byte) counter;
}
counters[d] = counter;
}
mat = new int[counters[0] * counters[1]][];
int ix = 0;
for (ModelPerformer performer : performers) {
int keyFrom = performer.getKeyFrom();
int keyTo = performer.getKeyTo();
int velFrom = performer.getVelFrom();
int velTo = performer.getVelTo();
if (keyFrom > keyTo) continue;
if (velFrom > velTo) continue;
keyFrom = restrict(keyFrom);
keyTo = restrict(keyTo);
velFrom = restrict(velFrom);
velTo = restrict(velTo);
int x_from = trantables[0][keyFrom];
int x_to = trantables[0][keyTo + 1];
int y_from = trantables[1][velFrom];
int y_to = trantables[1][velTo + 1];
if (x_to == -1)
x_to = counters[0];
if (y_to == -1)
y_to = counters[1];
for (int y = y_from; y < y_to; y++) {
int i = x_from + y * counters[0];
for (int x = x_from; x < x_to; x++) {
int[] mprev = mat[i];
if (mprev == null) {
mat[i] = new int[] { ix };
} else {
int[] mnew = new int[mprev.length + 1];
mnew[mnew.length - 1] = ix;
for (int k = 0; k < mprev.length; k++)
mnew[k] = mprev[k];
mat[i] = mnew;
}
i++;
}
}
ix++;
}
}
public void close() {
}
public void noteOff(int noteNumber, int velocity) {
if (!noteOffUsed)
return;
int[] plist = lookupIndex(noteNumber, velocity);
if(plist == null) return;
for (int i : plist) {
ModelPerformer p = performers[i];
if (p.isReleaseTriggered()) {
player.play(i, null);
}
}
}
public void noteOn(int noteNumber, int velocity) {
if (!noteOnUsed)
return;
int[] plist = lookupIndex(noteNumber, velocity);
if(plist == null) return;
for (int i : plist) {
ModelPerformer p = performers[i];
if (!p.isReleaseTriggered()) {
player.play(i, null);
}
}
}
}
/* /*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -116,7 +116,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer { ...@@ -116,7 +116,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
protected int tuning_program = 0; protected int tuning_program = 0;
protected SoftInstrument current_instrument = null; protected SoftInstrument current_instrument = null;
protected ModelChannelMixer current_mixer = null; protected ModelChannelMixer current_mixer = null;
private ModelDirector current_director = null; protected ModelDirector current_director = null;
// Controller Destination Settings // Controller Destination Settings
protected int cds_control_number = -1; protected int cds_control_number = -1;
...@@ -1264,13 +1264,16 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer { ...@@ -1264,13 +1264,16 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
} }
public void programChange(int bank, int program) { public void programChange(int bank, int program) {
bank = restrict7Bit(bank); bank = restrict14Bit(bank);
program = restrict7Bit(program); program = restrict7Bit(program);
synchronized (control_mutex) { synchronized (control_mutex) {
mainmixer.activity(); mainmixer.activity();
this.bank = bank; if(this.bank != bank || this.program != program)
this.program = program; {
current_instrument = null; this.bank = bank;
this.program = program;
current_instrument = null;
}
} }
} }
......
/* /*
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -118,16 +118,16 @@ public class SoftMixingMixer implements Mixer { ...@@ -118,16 +118,16 @@ public class SoftMixingMixer implements Mixer {
AudioSystem.NOT_SPECIFIED, bits, channels, channels AudioSystem.NOT_SPECIFIED, bits, channels, channels
* bits / 8, AudioSystem.NOT_SPECIFIED, true)); * bits / 8, AudioSystem.NOT_SPECIFIED, true));
} }
formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, formats.add(new AudioFormat(Encoding.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4, AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
AudioSystem.NOT_SPECIFIED, false)); AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, formats.add(new AudioFormat(Encoding.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4, AudioSystem.NOT_SPECIFIED, 32, channels, channels * 4,
AudioSystem.NOT_SPECIFIED, true)); AudioSystem.NOT_SPECIFIED, true));
formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, formats.add(new AudioFormat(Encoding.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8, AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
AudioSystem.NOT_SPECIFIED, false)); AudioSystem.NOT_SPECIFIED, false));
formats.add(new AudioFormat(AudioFloatConverter.PCM_FLOAT, formats.add(new AudioFormat(Encoding.PCM_FLOAT,
AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8, AudioSystem.NOT_SPECIFIED, 64, channels, channels * 8,
AudioSystem.NOT_SPECIFIED, true)); AudioSystem.NOT_SPECIFIED, true));
} }
......
...@@ -279,9 +279,12 @@ public class SoftVoice extends VoiceStatus { ...@@ -279,9 +279,12 @@ public class SoftVoice extends VoiceStatus {
} }
protected void updateTuning(SoftTuning newtuning) { protected void updateTuning(SoftTuning newtuning) {
tuning = newtuning;
tunedKey = tuning.getTuning(note) / 100.0; tunedKey = tuning.getTuning(note) / 100.0;
if (!portamento) { if (!portamento) {
co_noteon_keynumber[0] = tunedKey * (1.0 / 128.0); co_noteon_keynumber[0] = tunedKey * (1.0 / 128.0);
if(performer == null)
return;
int[] c = performer.midi_connections[4]; int[] c = performer.midi_connections[4];
if (c == null) if (c == null)
return; return;
...@@ -433,6 +436,8 @@ public class SoftVoice extends VoiceStatus { ...@@ -433,6 +436,8 @@ public class SoftVoice extends VoiceStatus {
} }
protected void setPolyPressure(int pressure) { protected void setPolyPressure(int pressure) {
if(performer == null)
return;
int[] c = performer.midi_connections[2]; int[] c = performer.midi_connections[2];
if (c == null) if (c == null)
return; return;
...@@ -441,6 +446,8 @@ public class SoftVoice extends VoiceStatus { ...@@ -441,6 +446,8 @@ public class SoftVoice extends VoiceStatus {
} }
protected void setChannelPressure(int pressure) { protected void setChannelPressure(int pressure) {
if(performer == null)
return;
int[] c = performer.midi_connections[1]; int[] c = performer.midi_connections[1];
if (c == null) if (c == null)
return; return;
...@@ -449,6 +456,8 @@ public class SoftVoice extends VoiceStatus { ...@@ -449,6 +456,8 @@ public class SoftVoice extends VoiceStatus {
} }
protected void controlChange(int controller, int value) { protected void controlChange(int controller, int value) {
if(performer == null)
return;
int[] c = performer.midi_ctrl_connections[controller]; int[] c = performer.midi_ctrl_connections[controller];
if (c == null) if (c == null)
return; return;
...@@ -457,6 +466,8 @@ public class SoftVoice extends VoiceStatus { ...@@ -457,6 +466,8 @@ public class SoftVoice extends VoiceStatus {
} }
protected void nrpnChange(int controller, int value) { protected void nrpnChange(int controller, int value) {
if(performer == null)
return;
int[] c = performer.midi_nrpn_connections.get(controller); int[] c = performer.midi_nrpn_connections.get(controller);
if (c == null) if (c == null)
return; return;
...@@ -465,6 +476,8 @@ public class SoftVoice extends VoiceStatus { ...@@ -465,6 +476,8 @@ public class SoftVoice extends VoiceStatus {
} }
protected void rpnChange(int controller, int value) { protected void rpnChange(int controller, int value) {
if(performer == null)
return;
int[] c = performer.midi_rpn_connections.get(controller); int[] c = performer.midi_rpn_connections.get(controller);
if (c == null) if (c == null)
return; return;
...@@ -473,6 +486,8 @@ public class SoftVoice extends VoiceStatus { ...@@ -473,6 +486,8 @@ public class SoftVoice extends VoiceStatus {
} }
protected void setPitchBend(int bend) { protected void setPitchBend(int bend) {
if(performer == null)
return;
int[] c = performer.midi_connections[0]; int[] c = performer.midi_connections[0];
if (c == null) if (c == null)
return; return;
...@@ -499,6 +514,8 @@ public class SoftVoice extends VoiceStatus { ...@@ -499,6 +514,8 @@ public class SoftVoice extends VoiceStatus {
co_noteon_on[0] = -1; co_noteon_on[0] = -1;
if(performer == null)
return;
int[] c = performer.midi_connections[3]; int[] c = performer.midi_connections[3];
if (c == null) if (c == null)
return; return;
...@@ -527,6 +544,8 @@ public class SoftVoice extends VoiceStatus { ...@@ -527,6 +544,8 @@ public class SoftVoice extends VoiceStatus {
co_noteon_on[0] = 0; co_noteon_on[0] = 0;
if(performer == null)
return;
int[] c = performer.midi_connections[3]; int[] c = performer.midi_connections[3];
if (c == null) if (c == null)
return; return;
...@@ -543,6 +562,8 @@ public class SoftVoice extends VoiceStatus { ...@@ -543,6 +562,8 @@ public class SoftVoice extends VoiceStatus {
sustain = true; sustain = true;
co_noteon_on[0] = 1; co_noteon_on[0] = 1;
if(performer == null)
return;
int[] c = performer.midi_connections[3]; int[] c = performer.midi_connections[3];
if (c == null) if (c == null)
return; return;
...@@ -555,6 +576,11 @@ public class SoftVoice extends VoiceStatus { ...@@ -555,6 +576,11 @@ public class SoftVoice extends VoiceStatus {
active = false; active = false;
stopping = false; stopping = false;
audiostarted = false; audiostarted = false;
instrument = null;
performer = null;
connections = null;
extendedConnectionBlocks = null;
channelmixer = null;
if (osc_stream != null) if (osc_stream != null)
try { try {
osc_stream.close(); osc_stream.close();
......
/* /*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -271,7 +271,7 @@ public class WaveExtensibleFileReader extends AudioFileReader { ...@@ -271,7 +271,7 @@ public class WaveExtensibleFileReader extends AudioFileReader {
bits, channels, framesize, samplerate, false, p); bits, channels, framesize, samplerate, false, p);
} }
} else if (subFormat.equals(SUBTYPE_IEEE_FLOAT)) { } else if (subFormat.equals(SUBTYPE_IEEE_FLOAT)) {
audioformat = new AudioFormat(AudioFloatConverter.PCM_FLOAT, audioformat = new AudioFormat(Encoding.PCM_FLOAT,
samplerate, bits, channels, framesize, samplerate, false, p); samplerate, bits, channels, framesize, samplerate, false, p);
} else } else
throw new UnsupportedAudioFileException(); throw new UnsupportedAudioFileException();
......
/* /*
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,6 +33,7 @@ import java.net.URL; ...@@ -33,6 +33,7 @@ import java.net.URL;
import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioFormat.Encoding;
import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem; import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException; import javax.sound.sampled.UnsupportedAudioFileException;
...@@ -102,7 +103,7 @@ public class WaveFloatFileReader extends AudioFileReader { ...@@ -102,7 +103,7 @@ public class WaveFloatFileReader extends AudioFileReader {
throw new UnsupportedAudioFileException(); throw new UnsupportedAudioFileException();
AudioFormat audioformat = new AudioFormat( AudioFormat audioformat = new AudioFormat(
AudioFloatConverter.PCM_FLOAT, samplerate, bits, channels, Encoding.PCM_FLOAT, samplerate, bits, channels,
framesize, samplerate, false); framesize, samplerate, false);
AudioFileFormat fileformat = new AudioFileFormat( AudioFileFormat fileformat = new AudioFileFormat(
AudioFileFormat.Type.WAVE, audioformat, AudioFileFormat.Type.WAVE, audioformat,
......
/* /*
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,6 +30,7 @@ import java.io.OutputStream; ...@@ -30,6 +30,7 @@ import java.io.OutputStream;
import javax.sound.sampled.AudioFileFormat; import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioFormat.Encoding;
import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem; import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.AudioFileFormat.Type; import javax.sound.sampled.AudioFileFormat.Type;
...@@ -48,8 +49,7 @@ public class WaveFloatFileWriter extends AudioFileWriter { ...@@ -48,8 +49,7 @@ public class WaveFloatFileWriter extends AudioFileWriter {
public Type[] getAudioFileTypes(AudioInputStream stream) { public Type[] getAudioFileTypes(AudioInputStream stream) {
if (!stream.getFormat().getEncoding().equals( if (!stream.getFormat().getEncoding().equals(Encoding.PCM_FLOAT))
AudioFloatConverter.PCM_FLOAT))
return new Type[0]; return new Type[0];
return new Type[] { Type.WAVE }; return new Type[] { Type.WAVE };
} }
...@@ -58,8 +58,7 @@ public class WaveFloatFileWriter extends AudioFileWriter { ...@@ -58,8 +58,7 @@ public class WaveFloatFileWriter extends AudioFileWriter {
if (!Type.WAVE.equals(type)) if (!Type.WAVE.equals(type))
throw new IllegalArgumentException("File type " + type throw new IllegalArgumentException("File type " + type
+ " not supported."); + " not supported.");
if (!stream.getFormat().getEncoding().equals( if (!stream.getFormat().getEncoding().equals(Encoding.PCM_FLOAT))
AudioFloatConverter.PCM_FLOAT))
throw new IllegalArgumentException("File format " throw new IllegalArgumentException("File format "
+ stream.getFormat() + " not supported."); + stream.getFormat() + " not supported.");
} }
......
...@@ -595,7 +595,6 @@ class Character implements java.io.Serializable, Comparable<Character> { ...@@ -595,7 +595,6 @@ class Character implements java.io.Serializable, Comparable<Character> {
/** /**
* Constructs a new <code>Subset</code> instance. * Constructs a new <code>Subset</code> instance.
* *
* @exception NullPointerException if name is <code>null</code>
* @param name The name of this subset * @param name The name of this subset
* @exception NullPointerException if name is <code>null</code> * @exception NullPointerException if name is <code>null</code>
*/ */
......
...@@ -226,7 +226,7 @@ public class DateFormatSymbols implements Serializable, Cloneable { ...@@ -226,7 +226,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
* Unlocalized date-time pattern characters. For example: 'y', 'd', etc. * Unlocalized date-time pattern characters. For example: 'y', 'd', etc.
* All locales use the same these unlocalized pattern characters. * All locales use the same these unlocalized pattern characters.
*/ */
static final String patternChars = "GyMdkHmsSEDFwWahKzZYu"; static final String patternChars = "GyMdkHmsSEDFwWahKzZYuX";
static final int PATTERN_ERA = 0; // G static final int PATTERN_ERA = 0; // G
static final int PATTERN_YEAR = 1; // y static final int PATTERN_YEAR = 1; // y
...@@ -249,6 +249,7 @@ public class DateFormatSymbols implements Serializable, Cloneable { ...@@ -249,6 +249,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
static final int PATTERN_ZONE_VALUE = 18; // Z static final int PATTERN_ZONE_VALUE = 18; // Z
static final int PATTERN_WEEK_YEAR = 19; // Y static final int PATTERN_WEEK_YEAR = 19; // Y
static final int PATTERN_ISO_DAY_OF_WEEK = 20; // u static final int PATTERN_ISO_DAY_OF_WEEK = 20; // u
static final int PATTERN_ISO_ZONE = 21; // X
/** /**
* Localized date-time pattern characters. For example, a locale may * Localized date-time pattern characters. For example, a locale may
......
/* /*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -43,10 +43,10 @@ import java.io.ObjectInputStream; ...@@ -43,10 +43,10 @@ import java.io.ObjectInputStream;
import java.io.Serializable; import java.io.Serializable;
import java.text.spi.DecimalFormatSymbolsProvider; import java.text.spi.DecimalFormatSymbolsProvider;
import java.util.Currency; import java.util.Currency;
import java.util.Hashtable;
import java.util.Locale; import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.spi.LocaleServiceProvider; import java.util.concurrent.ConcurrentHashMap;
import sun.util.LocaleServiceProviderPool; import sun.util.LocaleServiceProviderPool;
import sun.util.resources.LocaleData; import sun.util.resources.LocaleData;
...@@ -527,10 +527,17 @@ public class DecimalFormatSymbols implements Cloneable, Serializable { ...@@ -527,10 +527,17 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
// get resource bundle data - try the cache first // get resource bundle data - try the cache first
boolean needCacheUpdate = false; boolean needCacheUpdate = false;
Object[] data = (Object[]) cachedLocaleData.get(locale); Object[] data = cachedLocaleData.get(locale);
if (data == null) { /* cache miss */ if (data == null) { /* cache miss */
// When numbering system is thai (Locale's extension contains u-nu-thai),
// we read the data from th_TH_TH.
Locale lookupLocale = locale;
String numberType = locale.getUnicodeLocaleType("nu");
if (numberType != null && numberType.equals("thai")) {
lookupLocale = new Locale("th", "TH", "TH");
}
data = new Object[3]; data = new Object[3];
ResourceBundle rb = LocaleData.getNumberFormatData(locale); ResourceBundle rb = LocaleData.getNumberFormatData(lookupLocale);
data[0] = rb.getStringArray("NumberElements"); data[0] = rb.getStringArray("NumberElements");
needCacheUpdate = true; needCacheUpdate = true;
} }
...@@ -586,7 +593,7 @@ public class DecimalFormatSymbols implements Cloneable, Serializable { ...@@ -586,7 +593,7 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
monetarySeparator = decimalSeparator; monetarySeparator = decimalSeparator;
if (needCacheUpdate) { if (needCacheUpdate) {
cachedLocaleData.put(locale, data); cachedLocaleData.putIfAbsent(locale, data);
} }
} }
...@@ -806,7 +813,7 @@ public class DecimalFormatSymbols implements Cloneable, Serializable { ...@@ -806,7 +813,7 @@ public class DecimalFormatSymbols implements Cloneable, Serializable {
* cache to hold the NumberElements and the Currency * cache to hold the NumberElements and the Currency
* of a Locale. * of a Locale.
*/ */
private static final Hashtable cachedLocaleData = new Hashtable(3); private static final ConcurrentHashMap<Locale, Object[]> cachedLocaleData = new ConcurrentHashMap<Locale, Object[]>(3);
/** /**
* Obtains a DecimalFormatSymbols instance from a DecimalFormatSymbolsProvider * Obtains a DecimalFormatSymbols instance from a DecimalFormatSymbolsProvider
......
...@@ -204,6 +204,11 @@ import static java.text.DateFormatSymbols.*; ...@@ -204,6 +204,11 @@ import static java.text.DateFormatSymbols.*;
* <td>Time zone * <td>Time zone
* <td><a href="#rfc822timezone">RFC 822 time zone</a> * <td><a href="#rfc822timezone">RFC 822 time zone</a>
* <td><code>-0800</code> * <td><code>-0800</code>
* <tr bgcolor="#eeeeff">
* <td><code>X</code>
* <td>Time zone
* <td><a href="#iso8601timezone">ISO 8601 time zone</a>
* <td><code>-08</code>; <code>-0800</code>; <code>-08:00</code>
* </table> * </table>
* </blockquote> * </blockquote>
* Pattern letters are usually repeated, as their number determines the * Pattern letters are usually repeated, as their number determines the
...@@ -288,6 +293,7 @@ import static java.text.DateFormatSymbols.*; ...@@ -288,6 +293,7 @@ import static java.text.DateFormatSymbols.*;
* accepted.<br><br></li> * accepted.<br><br></li>
* <li><strong><a name="rfc822timezone">RFC 822 time zone:</a></strong> * <li><strong><a name="rfc822timezone">RFC 822 time zone:</a></strong>
* For formatting, the RFC 822 4-digit time zone format is used: * For formatting, the RFC 822 4-digit time zone format is used:
*
* <pre> * <pre>
* <i>RFC822TimeZone:</i> * <i>RFC822TimeZone:</i>
* <i>Sign</i> <i>TwoDigitHours</i> <i>Minutes</i> * <i>Sign</i> <i>TwoDigitHours</i> <i>Minutes</i>
...@@ -295,8 +301,41 @@ import static java.text.DateFormatSymbols.*; ...@@ -295,8 +301,41 @@ import static java.text.DateFormatSymbols.*;
* <i>Digit Digit</i></pre> * <i>Digit Digit</i></pre>
* <i>TwoDigitHours</i> must be between 00 and 23. Other definitions * <i>TwoDigitHours</i> must be between 00 and 23. Other definitions
* are as for <a href="#timezone">general time zones</a>. * are as for <a href="#timezone">general time zones</a>.
*
* <p>For parsing, <a href="#timezone">general time zones</a> are also * <p>For parsing, <a href="#timezone">general time zones</a> are also
* accepted. * accepted.
* <li><strong><a name="iso8601timezone">ISO 8601 Time zone:</a></strong>
* The number of pattern letters designates the format for both formatting
* and parsing as follows:
* <pre>
* <i>ISO8601TimeZone:</i>
* <i>OneLetterISO8601TimeZone</i>
* <i>TwoLetterISO8601TimeZone</i>
* <i>ThreeLetterISO8601TimeZone</i>
* <i>OneLetterISO8601TimeZone:</i>
* <i>Sign</i> <i>TwoDigitHours</i>
* {@code Z}
* <i>TwoLetterISO8601TimeZone:</i>
* <i>Sign</i> <i>TwoDigitHours</i> <i>Minutes</i>
* {@code Z}
* <i>ThreeLetterISO8601TimeZone:</i>
* <i>Sign</i> <i>TwoDigitHours</i> {@code :} <i>Minutes</i>
* {@code Z}</pre>
* Other definitions are as for <a href="#timezone">general time zones</a> or
* <a href="#rfc822timezone">RFC 822 time zones</a>.
*
* <p>For formatting, if the offset value from GMT is 0, {@code "Z"} is
* produced. If the number of pattern letters is 1, any fraction of an hour
* is ignored. For example, if the pattern is {@code "X"} and the time zone is
* {@code "GMT+05:30"}, {@code "+05"} is produced.
*
* <p>For parsing, {@code "Z"} is parsed as the UTC time zone designator.
* <a href="#timezone">General time zones</a> are <em>not</em> accepted.
*
* <p>If the number of pattern letters is 4 or more, {@link
* IllegalArgumentException} is thrown when constructing a {@code
* SimpleDateFormat} or {@linkplain #applyPattern(String) applying a
* pattern}.
* </ul> * </ul>
* <code>SimpleDateFormat</code> also supports <em>localized date and time * <code>SimpleDateFormat</code> also supports <em>localized date and time
* pattern</em> strings. In these strings, the pattern letters described above * pattern</em> strings. In these strings, the pattern letters described above
...@@ -343,6 +382,9 @@ import static java.text.DateFormatSymbols.*; ...@@ -343,6 +382,9 @@ import static java.text.DateFormatSymbols.*;
* <td><code>"yyyy-MM-dd'T'HH:mm:ss.SSSZ"</code> * <td><code>"yyyy-MM-dd'T'HH:mm:ss.SSSZ"</code>
* <td><code>2001-07-04T12:08:56.235-0700</code> * <td><code>2001-07-04T12:08:56.235-0700</code>
* <tr bgcolor="#eeeeff"> * <tr bgcolor="#eeeeff">
* <td><code>"yyyy-MM-dd'T'HH:mm:ss.SSSXXX"</code>
* <td><code>2001-07-04T12:08:56.235-07:00</code>
* <tr>
* <td><code>"YYYY-'W'ww-u"</code> * <td><code>"YYYY-'W'ww-u"</code>
* <td><code>2001-W27-3</code> * <td><code>2001-W27-3</code>
* </table> * </table>
...@@ -839,6 +881,9 @@ public class SimpleDateFormat extends DateFormat { ...@@ -839,6 +881,9 @@ public class SimpleDateFormat extends DateFormat {
* Encodes the given tag and length and puts encoded char(s) into buffer. * Encodes the given tag and length and puts encoded char(s) into buffer.
*/ */
private static final void encode(int tag, int length, StringBuilder buffer) { private static final void encode(int tag, int length, StringBuilder buffer) {
if (tag == PATTERN_ISO_ZONE && length >= 4) {
throw new IllegalArgumentException("invalid ISO 8601 format: length=" + length);
}
if (length < 255) { if (length < 255) {
buffer.append((char)(tag << 8 | length)); buffer.append((char)(tag << 8 | length));
} else { } else {
...@@ -995,7 +1040,8 @@ public class SimpleDateFormat extends DateFormat { ...@@ -995,7 +1040,8 @@ public class SimpleDateFormat extends DateFormat {
Calendar.ZONE_OFFSET, Calendar.ZONE_OFFSET,
// Pseudo Calendar fields // Pseudo Calendar fields
CalendarBuilder.WEEK_YEAR, CalendarBuilder.WEEK_YEAR,
CalendarBuilder.ISO_DAY_OF_WEEK CalendarBuilder.ISO_DAY_OF_WEEK,
Calendar.ZONE_OFFSET
}; };
// Map index into pattern character string to DateFormat field number // Map index into pattern character string to DateFormat field number
...@@ -1009,7 +1055,8 @@ public class SimpleDateFormat extends DateFormat { ...@@ -1009,7 +1055,8 @@ public class SimpleDateFormat extends DateFormat {
DateFormat.WEEK_OF_MONTH_FIELD, DateFormat.AM_PM_FIELD, DateFormat.WEEK_OF_MONTH_FIELD, DateFormat.AM_PM_FIELD,
DateFormat.HOUR1_FIELD, DateFormat.HOUR0_FIELD, DateFormat.HOUR1_FIELD, DateFormat.HOUR0_FIELD,
DateFormat.TIMEZONE_FIELD, DateFormat.TIMEZONE_FIELD, DateFormat.TIMEZONE_FIELD, DateFormat.TIMEZONE_FIELD,
DateFormat.YEAR_FIELD, DateFormat.DAY_OF_WEEK_FIELD DateFormat.YEAR_FIELD, DateFormat.DAY_OF_WEEK_FIELD,
DateFormat.TIMEZONE_FIELD
}; };
// Maps from DecimalFormatSymbols index to Field constant // Maps from DecimalFormatSymbols index to Field constant
...@@ -1021,7 +1068,8 @@ public class SimpleDateFormat extends DateFormat { ...@@ -1021,7 +1068,8 @@ public class SimpleDateFormat extends DateFormat {
Field.WEEK_OF_YEAR, Field.WEEK_OF_MONTH, Field.WEEK_OF_YEAR, Field.WEEK_OF_MONTH,
Field.AM_PM, Field.HOUR1, Field.HOUR0, Field.TIME_ZONE, Field.AM_PM, Field.HOUR1, Field.HOUR0, Field.TIME_ZONE,
Field.TIME_ZONE, Field.TIME_ZONE,
Field.YEAR, Field.DAY_OF_WEEK Field.YEAR, Field.DAY_OF_WEEK,
Field.TIME_ZONE
}; };
/** /**
...@@ -1189,6 +1237,34 @@ public class SimpleDateFormat extends DateFormat { ...@@ -1189,6 +1237,34 @@ public class SimpleDateFormat extends DateFormat {
CalendarUtils.sprintf0d(buffer, num, width); CalendarUtils.sprintf0d(buffer, num, width);
break; break;
case PATTERN_ISO_ZONE: // 'X'
value = calendar.get(Calendar.ZONE_OFFSET)
+ calendar.get(Calendar.DST_OFFSET);
if (value == 0) {
buffer.append('Z');
break;
}
value /= 60000;
if (value >= 0) {
buffer.append('+');
} else {
buffer.append('-');
value = -value;
}
CalendarUtils.sprintf0d(buffer, value / 60, 2);
if (count == 1) {
break;
}
if (count == 3) {
buffer.append(':');
}
CalendarUtils.sprintf0d(buffer, value % 60, 2);
break;
default: default:
// case PATTERN_DAY_OF_MONTH: // 'd' // case PATTERN_DAY_OF_MONTH: // 'd'
// case PATTERN_HOUR_OF_DAY0: // 'H' 0-based. eg, 23:59 + 1 hour =>> 00:59 // case PATTERN_HOUR_OF_DAY0: // 'H' 0-based. eg, 23:59 + 1 hour =>> 00:59
...@@ -1973,6 +2049,94 @@ public class SimpleDateFormat extends DateFormat { ...@@ -1973,6 +2049,94 @@ public class SimpleDateFormat extends DateFormat {
} }
break parsing; break parsing;
case PATTERN_ISO_ZONE: // 'X'
{
int sign = 0;
int offset = 0;
iso8601: {
try {
char c = text.charAt(pos.index);
if (c == 'Z') {
calb.set(Calendar.ZONE_OFFSET, 0).set(Calendar.DST_OFFSET, 0);
return ++pos.index;
}
// parse text as "+/-hh[[:]mm]" based on count
if (c == '+') {
sign = 1;
} else if (c == '-') {
sign = -1;
}
// Look for hh.
int hours = 0;
c = text.charAt(++pos.index);
if (c < '0' || c > '9') { /* must be from '0' to '9'. */
break parsing;
}
hours = c - '0';
c = text.charAt(++pos.index);
if (c < '0' || c > '9') { /* must be from '0' to '9'. */
break parsing;
}
hours *= 10;
hours += c - '0';
if (hours > 23) {
break parsing;
}
if (count == 1) { // "X"
offset = hours * 60;
break iso8601;
}
c = text.charAt(++pos.index);
// Skip ':' if "XXX"
if (c == ':') {
if (count == 2) {
break parsing;
}
c = text.charAt(++pos.index);
} else {
if (count == 3) {
// missing ':'
break parsing;
}
}
// Look for mm.
int minutes = 0;
if (c < '0' || c > '9') { /* must be from '0' to '9'. */
break parsing;
}
minutes = c - '0';
c = text.charAt(++pos.index);
if (c < '0' || c > '9') { /* must be from '0' to '9'. */
break parsing;
}
minutes *= 10;
minutes += c - '0';
if (minutes > 59) {
break parsing;
}
offset = hours * 60 + minutes;
} catch (StringIndexOutOfBoundsException e) {
break parsing;
}
}
// Do the final processing for both of the above cases. We only
// arrive here if the form GMT+/-... or an RFC 822 form was seen.
if (sign != 0) {
offset *= MILLIS_PER_MINUTE * sign;
calb.set(Calendar.ZONE_OFFSET, offset).set(Calendar.DST_OFFSET, 0);
return ++pos.index;
}
}
break parsing;
default: default:
// case PATTERN_DAY_OF_MONTH: // 'd' // case PATTERN_DAY_OF_MONTH: // 'd'
// case PATTERN_HOUR_OF_DAY0: // 'H' 0-based. eg, 23:59 + 1 hour =>> 00:59 // case PATTERN_HOUR_OF_DAY0: // 'H' 0-based. eg, 23:59 + 1 hour =>> 00:59
...@@ -2102,7 +2266,7 @@ public class SimpleDateFormat extends DateFormat { ...@@ -2102,7 +2266,7 @@ public class SimpleDateFormat extends DateFormat {
* @exception NullPointerException if the given pattern is null * @exception NullPointerException if the given pattern is null
* @exception IllegalArgumentException if the given pattern is invalid * @exception IllegalArgumentException if the given pattern is invalid
*/ */
public void applyPattern (String pattern) public void applyPattern(String pattern)
{ {
compiledPattern = compile(pattern); compiledPattern = compile(pattern);
this.pattern = pattern; this.pattern = pattern;
......
...@@ -1013,19 +1013,30 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca ...@@ -1013,19 +1013,30 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
private static Calendar createCalendar(TimeZone zone, private static Calendar createCalendar(TimeZone zone,
Locale aLocale) Locale aLocale)
{ {
// If the specified locale is a Thai locale, returns a BuddhistCalendar Calendar cal = null;
// instance.
if ("th".equals(aLocale.getLanguage()) String caltype = aLocale.getUnicodeLocaleType("ca");
&& ("TH".equals(aLocale.getCountry()))) { if (caltype == null) {
return new sun.util.BuddhistCalendar(zone, aLocale); // Calendar type is not specified.
} else if ("JP".equals(aLocale.getVariant()) // If the specified locale is a Thai locale,
&& "JP".equals(aLocale.getCountry()) // returns a BuddhistCalendar instance.
&& "ja".equals(aLocale.getLanguage())) { if ("th".equals(aLocale.getLanguage())
return new JapaneseImperialCalendar(zone, aLocale); && ("TH".equals(aLocale.getCountry()))) {
cal = new BuddhistCalendar(zone, aLocale);
} else {
cal = new GregorianCalendar(zone, aLocale);
}
} else if (caltype.equals("japanese")) {
cal = new JapaneseImperialCalendar(zone, aLocale);
} else if (caltype.equals("buddhist")) {
cal = new BuddhistCalendar(zone, aLocale);
} else {
// Unsupported calendar type.
// Use Gregorian calendar as a fallback.
cal = new GregorianCalendar(zone, aLocale);
} }
// else create the default calendar return cal;
return new GregorianCalendar(zone, aLocale);
} }
/** /**
......
...@@ -2160,20 +2160,22 @@ public class GregorianCalendar extends Calendar { ...@@ -2160,20 +2160,22 @@ public class GregorianCalendar extends Calendar {
gc.complete(); gc.complete();
} }
if (!isLenient() &&
(gc.getWeekYear() != weekYear
|| gc.internalGet(WEEK_OF_YEAR) != weekOfYear
|| gc.internalGet(DAY_OF_WEEK) != dayOfWeek)) {
throw new IllegalArgumentException();
}
set(ERA, gc.internalGet(ERA)); set(ERA, gc.internalGet(ERA));
set(YEAR, gc.internalGet(YEAR)); set(YEAR, gc.internalGet(YEAR));
set(MONTH, gc.internalGet(MONTH)); set(MONTH, gc.internalGet(MONTH));
set(DAY_OF_MONTH, gc.internalGet(DAY_OF_MONTH)); set(DAY_OF_MONTH, gc.internalGet(DAY_OF_MONTH));
// to avoid throwing an IllegalArgumentException in // to avoid throwing an IllegalArgumentException in
// non-lenient, set WEEK_OF_YEAR and DAY_OF_WEEK internally // non-lenient, set WEEK_OF_YEAR internally
internalSet(WEEK_OF_YEAR, weekOfYear); internalSet(WEEK_OF_YEAR, weekOfYear);
internalSet(DAY_OF_WEEK, dayOfWeek);
complete(); complete();
assert getWeekYear() == weekYear;
assert get(WEEK_OF_YEAR) == weekOfYear;
assert get(DAY_OF_WEEK) == dayOfWeek;
} }
/** /**
......
/*
* Copyright (c) 2010, Oracle and/or its affiliates. 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
*******************************************************************************
* Copyright (C) 2009-2010, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package java.util;
/**
* Thrown by methods in {@link Locale} and {@link Locale.Builder} to
* indicate that an argument is not a well-formed BCP 47 tag.
*
* @see Locale
* @since 1.7
*/
public class IllformedLocaleException extends RuntimeException {
private static final long serialVersionUID = -5245986824925681401L;
private int _errIdx = -1;
/**
* Constructs a new <code>IllformedLocaleException</code> with no
* detail message and -1 as the error index.
*/
public IllformedLocaleException() {
super();
}
/**
* Constructs a new <code>IllformedLocaleException</code> with the
* given message and -1 as the error index.
*
* @param message the message
*/
public IllformedLocaleException(String message) {
super(message);
}
/**
* Constructs a new <code>IllformedLocaleException</code> with the
* given message and the error index. The error index is the approximate
* offset from the start of the ill-formed value to the point where the
* parse first detected an error. A negative error index value indicates
* either the error index is not applicable or unknown.
*
* @param message the message
* @param errorIndex the index
*/
public IllformedLocaleException(String message, int errorIndex) {
super(message + ((errorIndex < 0) ? "" : " [at index " + errorIndex + "]"));
_errIdx = errorIndex;
}
/**
* Returns the index where the error was found. A negative value indicates
* either the error index is not applicable or unknown.
*
* @return the error index
*/
public int getErrorIndex() {
return _errIdx;
}
}
/* /*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -44,22 +44,23 @@ public abstract class LocaleNameProvider extends LocaleServiceProvider { ...@@ -44,22 +44,23 @@ public abstract class LocaleNameProvider extends LocaleServiceProvider {
} }
/** /**
* Returns a localized name for the given ISO 639 language code and the * Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt">
* given locale that is appropriate for display to the user. * IETF BCP47</a> language code and the given locale that is appropriate for
* display to the user.
* For example, if <code>languageCode</code> is "fr" and <code>locale</code> * For example, if <code>languageCode</code> is "fr" and <code>locale</code>
* is en_US, getDisplayLanguage() will return "French"; if <code>languageCode</code> * is en_US, getDisplayLanguage() will return "French"; if <code>languageCode</code>
* is "en" and <code>locale</code> is fr_FR, getDisplayLanguage() will return "anglais". * is "en" and <code>locale</code> is fr_FR, getDisplayLanguage() will return "anglais".
* If the name returned cannot be localized according to <code>locale</code>, * If the name returned cannot be localized according to <code>locale</code>,
* (say, the provider does not have a Japanese name for Croatian), * (say, the provider does not have a Japanese name for Croatian),
* this method returns null. * this method returns null.
* @param languageCode the ISO 639 language code string in the form of two * @param languageCode the language code string in the form of two to eight
* lower-case letters between 'a' (U+0061) and 'z' (U+007A) * lower-case letters between 'a' (U+0061) and 'z' (U+007A)
* @param locale the desired locale * @param locale the desired locale
* @return the name of the given language code for the specified locale, or null if it's not * @return the name of the given language code for the specified locale, or null if it's not
* available. * available.
* @exception NullPointerException if <code>languageCode</code> or <code>locale</code> is null * @exception NullPointerException if <code>languageCode</code> or <code>locale</code> is null
* @exception IllegalArgumentException if <code>languageCode</code> is not in the form of * @exception IllegalArgumentException if <code>languageCode</code> is not in the form of
* two lower-case letters, or <code>locale</code> isn't * two or three lower-case letters, or <code>locale</code> isn't
* one of the locales returned from * one of the locales returned from
* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
* getAvailableLocales()}. * getAvailableLocales()}.
...@@ -68,22 +69,52 @@ public abstract class LocaleNameProvider extends LocaleServiceProvider { ...@@ -68,22 +69,52 @@ public abstract class LocaleNameProvider extends LocaleServiceProvider {
public abstract String getDisplayLanguage(String languageCode, Locale locale); public abstract String getDisplayLanguage(String languageCode, Locale locale);
/** /**
* Returns a localized name for the given ISO 3166 country code and the * Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt">
* given locale that is appropriate for display to the user. * IETF BCP47</a> script code and the given locale that is appropriate for
* display to the user.
* For example, if <code>scriptCode</code> is "Latn" and <code>locale</code>
* is en_US, getDisplayScript() will return "Latin"; if <code>scriptCode</code>
* is "Cyrl" and <code>locale</code> is fr_FR, getDisplayScript() will return "cyrillique".
* If the name returned cannot be localized according to <code>locale</code>,
* (say, the provider does not have a Japanese name for Cyrillic),
* this method returns null.
* @param scriptCode the four letter script code string in the form of title-case
* letters (the first letter is upper-case character between 'A' (U+0041) and
* 'Z' (U+005A) followed by three lower-case character between 'a' (U+0061)
* and 'z' (U+007A)).
* @param locale the desired locale
* @return the name of the given script code for the specified locale, or null if it's not
* available.
* @exception NullPointerException if <code>scriptCode</code> or <code>locale</code> is null
* @exception IllegalArgumentException if <code>scriptCode</code> is not in the form of
* four title case letters, or <code>locale</code> isn't
* one of the locales returned from
* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
* getAvailableLocales()}.
* @see java.util.Locale#getDisplayScript(java.util.Locale)
* @since 1.7
*/
public abstract String getDisplayScript(String scriptCode, Locale locale);
/**
* Returns a localized name for the given <a href="http://www.rfc-editor.org/rfc/bcp/bcp47.txt">
* IETF BCP47</a> region code (either ISO 3166 country code or UN M.49 area
* codes) and the given locale that is appropriate for display to the user.
* For example, if <code>countryCode</code> is "FR" and <code>locale</code> * For example, if <code>countryCode</code> is "FR" and <code>locale</code>
* is en_US, getDisplayCountry() will return "France"; if <code>countryCode</code> * is en_US, getDisplayCountry() will return "France"; if <code>countryCode</code>
* is "US" and <code>locale</code> is fr_FR, getDisplayCountry() will return "Etats-Unis". * is "US" and <code>locale</code> is fr_FR, getDisplayCountry() will return "Etats-Unis".
* If the name returned cannot be localized according to <code>locale</code>, * If the name returned cannot be localized according to <code>locale</code>,
* (say, the provider does not have a Japanese name for Croatia), * (say, the provider does not have a Japanese name for Croatia),
* this method returns null. * this method returns null.
* @param countryCode the ISO 3166 country code string in the form of two * @param countryCode the country(region) code string in the form of two
* upper-case letters between 'A' (U+0041) and 'Z' (U+005A) * upper-case letters between 'A' (U+0041) and 'Z' (U+005A) or the UN M.49 area code
* in the form of three digit letters between '0' (U+0030) and '9' (U+0039).
* @param locale the desired locale * @param locale the desired locale
* @return the name of the given country code for the specified locale, or null if it's not * @return the name of the given country code for the specified locale, or null if it's not
* available. * available.
* @exception NullPointerException if <code>countryCode</code> or <code>locale</code> is null * @exception NullPointerException if <code>countryCode</code> or <code>locale</code> is null
* @exception IllegalArgumentException if <code>countryCode</code> is not in the form of * @exception IllegalArgumentException if <code>countryCode</code> is not in the form of
* two upper-case letters, or <code>locale</code> isn't * two upper-case letters or three digit letters, or <code>locale</code> isn't
* one of the locales returned from * one of the locales returned from
* {@link java.util.spi.LocaleServiceProvider#getAvailableLocales() * {@link java.util.spi.LocaleServiceProvider#getAvailableLocales()
* getAvailableLocales()}. * getAvailableLocales()}.
......
...@@ -86,18 +86,19 @@ import java.util.Locale; ...@@ -86,18 +86,19 @@ import java.util.Locale;
* Otherwise, they call the <code>getAvailableLocales()</code> methods of * Otherwise, they call the <code>getAvailableLocales()</code> methods of
* installed providers for the appropriate interface to find one that * installed providers for the appropriate interface to find one that
* supports the requested locale. If such a provider is found, its other * supports the requested locale. If such a provider is found, its other
* methods are called to obtain the requested object or name. If neither * methods are called to obtain the requested object or name. When checking
* the Java runtime environment itself nor an installed provider supports * whether a locale is supported, the locale's extensions are ignored.
* the requested locale, a fallback locale is constructed by replacing the * If neither the Java runtime environment itself nor an installed provider
* first of the variant, country, or language strings of the locale that's * supports the requested locale, the methods go through a list of candidate
* not an empty string with an empty string, and the lookup process is * locales and repeat the availability check for each until a match is found.
* restarted. In the case that the variant contains one or more '_'s, the * The algorithm used for creating a list of candidate locales is same as
* fallback locale is constructed by replacing the variant with a new variant * the one used by <code>ResourceBunlde</code> by default (see
* which eliminates the last '_' and the part following it. Even if a * {@link java.util.ResourceBundle.Control#getCandidateLocales getCandidateLocales}
* fallback occurs, methods that return requested objects or name are * for the details). Even if a locale is resolved from the candidate list,
* invoked with the original locale before the fallback.The Java runtime * methods that return requested objects or names are invoked with the original
* environment must support the root locale for all locale sensitive services * requested locale including extensions. The Java runtime environment must
* in order to guarantee that this process terminates. * support the root locale for all locale sensitive services in order to
* guarantee that this process terminates.
* <p> * <p>
* Providers of names (but not providers of other objects) are allowed to * Providers of names (but not providers of other objects) are allowed to
* return null for some name requests even for locales that they claim to * return null for some name requests even for locales that they claim to
...@@ -124,6 +125,11 @@ public abstract class LocaleServiceProvider { ...@@ -124,6 +125,11 @@ public abstract class LocaleServiceProvider {
/** /**
* Returns an array of all locales for which this locale service provider * Returns an array of all locales for which this locale service provider
* can provide localized objects or names. * can provide localized objects or names.
* <p>
* <b>Note:</b> Extensions in a <code>Locale</code> are ignored during
* service provider lookup. So the array returned by this method should
* not include two or more <code>Locale</code> objects only differing in
* their extensions.
* *
* @return An array of all locales for which this locale service provider * @return An array of all locales for which this locale service provider
* can provide localized objects or names. * can provide localized objects or names.
......
/* /*
* Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -554,14 +554,14 @@ public class AudioFormat { ...@@ -554,14 +554,14 @@ public class AudioFormat {
* which is simply a linear (proportional) representation of the sound * which is simply a linear (proportional) representation of the sound
* waveform. With PCM, the number stored in each sample is proportional * waveform. With PCM, the number stored in each sample is proportional
* to the instantaneous amplitude of the sound pressure at that point in * to the instantaneous amplitude of the sound pressure at that point in
* time. The numbers are frequently signed or unsigned integers. * time. The numbers may be signed or unsigned integers or floats.
* Besides PCM, other encodings include mu-law and a-law, which are nonlinear * Besides PCM, other encodings include mu-law and a-law, which are nonlinear
* mappings of the sound amplitude that are often used for recording speech. * mappings of the sound amplitude that are often used for recording speech.
* <p> * <p>
* You can use a predefined encoding by referring to one of the static * You can use a predefined encoding by referring to one of the static
* objects created by this class, such as PCM_SIGNED or * objects created by this class, such as PCM_SIGNED or
* PCM_UNSIGNED. Service providers can create new encodings, such as * PCM_UNSIGNED. Service providers can create new encodings, such as
* compressed audio formats or floating-point PCM samples, and make * compressed audio formats, and make
* these available through the <code>{@link AudioSystem}</code> class. * these available through the <code>{@link AudioSystem}</code> class.
* <p> * <p>
* The <code>Encoding</code> class is static, so that all * The <code>Encoding</code> class is static, so that all
...@@ -591,6 +591,13 @@ public class AudioFormat { ...@@ -591,6 +591,13 @@ public class AudioFormat {
*/ */
public static final Encoding PCM_UNSIGNED = new Encoding("PCM_UNSIGNED"); public static final Encoding PCM_UNSIGNED = new Encoding("PCM_UNSIGNED");
/**
* Specifies floating-point PCM data.
*
* @since 1.7
*/
public static final Encoding PCM_FLOAT = new Encoding("PCM_FLOAT");
/** /**
* Specifies u-law encoded data. * Specifies u-law encoded data.
*/ */
......
/* /*
* Copyright (c) 2002, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -914,6 +914,7 @@ public class SynthTabbedPaneUI extends BasicTabbedPaneUI ...@@ -914,6 +914,7 @@ public class SynthTabbedPaneUI extends BasicTabbedPaneUI
UIResource { UIResource {
public SynthScrollableTabButton(int direction) { public SynthScrollableTabButton(int direction) {
super(direction); super(direction);
setName("TabbedPane.button");
} }
} }
} }
/* /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,18 +28,20 @@ package sun.util; ...@@ -28,18 +28,20 @@ package sun.util;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedActionException; import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction; import java.security.PrivilegedExceptionAction;
import java.util.Arrays; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.IllformedLocaleException;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Locale.Builder;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle.Control;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import java.util.ServiceConfigurationError;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.spi.LocaleServiceProvider; import java.util.spi.LocaleServiceProvider;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
import sun.util.resources.LocaleData; import sun.util.resources.LocaleData;
import sun.util.resources.OpenListResourceBundle; import sun.util.resources.OpenListResourceBundle;
...@@ -89,6 +91,16 @@ public final class LocaleServiceProviderPool { ...@@ -89,6 +91,16 @@ public final class LocaleServiceProviderPool {
*/ */
private Set<Locale> providerLocales = null; private Set<Locale> providerLocales = null;
/**
* Special locale for ja_JP with Japanese calendar
*/
private static Locale locale_ja_JP_JP = new Locale("ja", "JP", "JP");
/**
* Special locale for th_TH with Thai numbering system
*/
private static Locale locale_th_TH_TH = new Locale("th", "TH", "TH");
/** /**
* A factory method that returns a singleton instance * A factory method that returns a singleton instance
*/ */
...@@ -153,14 +165,20 @@ public final class LocaleServiceProviderPool { ...@@ -153,14 +165,20 @@ public final class LocaleServiceProviderPool {
java.util.spi.CurrencyNameProvider.class, java.util.spi.CurrencyNameProvider.class,
java.util.spi.LocaleNameProvider.class, java.util.spi.LocaleNameProvider.class,
java.util.spi.TimeZoneNameProvider.class }; java.util.spi.TimeZoneNameProvider.class };
Set<Locale> all = new HashSet<Locale>(Arrays.asList(
LocaleData.getAvailableLocales()) // Normalize locales for look up
); Locale[] allLocales = LocaleData.getAvailableLocales();
Set<Locale> all = new HashSet<Locale>(allLocales.length);
for (Locale locale : allLocales) {
all.add(getLookupLocale(locale));
}
for (Class providerClass : providerClasses) { for (Class providerClass : providerClasses) {
LocaleServiceProviderPool pool = LocaleServiceProviderPool pool =
LocaleServiceProviderPool.getPool(providerClass); LocaleServiceProviderPool.getPool(providerClass);
all.addAll(pool.getProviderLocales()); all.addAll(pool.getProviderLocales());
} }
allAvailableLocales = all.toArray(new Locale[0]); allAvailableLocales = all.toArray(new Locale[0]);
} }
} }
...@@ -196,7 +214,8 @@ public final class LocaleServiceProviderPool { ...@@ -196,7 +214,8 @@ public final class LocaleServiceProviderPool {
} }
/** /**
* Returns an array of available locales from providers. * Returns an array of available locales (already normalized
* for service lookup) from providers.
* Note that this method does not return a defensive copy. * Note that this method does not return a defensive copy.
* *
* @return list of the provider locales * @return list of the provider locales
...@@ -208,7 +227,7 @@ public final class LocaleServiceProviderPool { ...@@ -208,7 +227,7 @@ public final class LocaleServiceProviderPool {
for (LocaleServiceProvider lsp : providers) { for (LocaleServiceProvider lsp : providers) {
Locale[] locales = lsp.getAvailableLocales(); Locale[] locales = lsp.getAvailableLocales();
for (Locale locale: locales) { for (Locale locale: locales) {
providerLocales.add(locale); providerLocales.add(getLookupLocale(locale));
} }
} }
} }
...@@ -227,15 +246,19 @@ public final class LocaleServiceProviderPool { ...@@ -227,15 +246,19 @@ public final class LocaleServiceProviderPool {
} }
/** /**
* Returns an array of available locales supported by the JRE. * Returns an array of available locales (already normalized for
* service lookup) supported by the JRE.
* Note that this method does not return a defensive copy. * Note that this method does not return a defensive copy.
* *
* @return list of the available JRE locales * @return list of the available JRE locales
*/ */
private synchronized List<Locale> getJRELocales() { private synchronized List<Locale> getJRELocales() {
if (availableJRELocales == null) { if (availableJRELocales == null) {
availableJRELocales = Locale[] allLocales = LocaleData.getAvailableLocales();
Arrays.asList(LocaleData.getAvailableLocales()); availableJRELocales = new ArrayList<Locale>(allLocales.length);
for (Locale locale : allLocales) {
availableJRELocales.add(getLookupLocale(locale));
}
} }
return availableJRELocales; return availableJRELocales;
} }
...@@ -249,7 +272,7 @@ public final class LocaleServiceProviderPool { ...@@ -249,7 +272,7 @@ public final class LocaleServiceProviderPool {
*/ */
private boolean isJRESupported(Locale locale) { private boolean isJRESupported(Locale locale) {
List<Locale> locales = getJRELocales(); List<Locale> locales = getJRELocales();
return locales.contains(locale); return locales.contains(getLookupLocale(locale));
} }
/** /**
...@@ -325,7 +348,7 @@ public final class LocaleServiceProviderPool { ...@@ -325,7 +348,7 @@ public final class LocaleServiceProviderPool {
bundleKey = key; bundleKey = key;
} }
Locale bundleLocale = (bundle != null ? bundle.getLocale() : null); Locale bundleLocale = (bundle != null ? bundle.getLocale() : null);
Locale requested = locale; List<Locale> lookupLocales = getLookupLocales(locale);
P lsp; P lsp;
S providersObj = null; S providersObj = null;
...@@ -333,21 +356,30 @@ public final class LocaleServiceProviderPool { ...@@ -333,21 +356,30 @@ public final class LocaleServiceProviderPool {
// to the requested locale than the bundle we've found (for // to the requested locale than the bundle we've found (for
// localized names), or Java runtime's supported locale // localized names), or Java runtime's supported locale
// (for localized objects) // (for localized objects)
while ((locale = findProviderLocale(locale, bundleLocale)) != null) { Set<Locale> provLoc = getProviderLocales();
for (int i = 0; i < lookupLocales.size(); i++) {
lsp = (P)findProvider(locale); Locale current = lookupLocales.get(i);
if (bundleLocale != null) {
if (lsp != null) { if (current.equals(bundleLocale)) {
providersObj = getter.getObject(lsp, requested, key, params); break;
if (providersObj != null) { }
return providersObj; } else {
} else if (isObjectProvider) { if (isJRESupported(current)) {
config( break;
"A locale sensitive service provider returned null for a localized objects, which should not happen. provider: " + lsp + " locale: " + requested); }
}
if (provLoc.contains(current)) {
lsp = (P)findProvider(current);
if (lsp != null) {
providersObj = getter.getObject(lsp, locale, key, params);
if (providersObj != null) {
return providersObj;
} else if (isObjectProvider) {
config(
"A locale sensitive service provider returned null for a localized objects, which should not happen. provider: " + lsp + " locale: " + locale);
}
} }
} }
locale = getParentLocale(locale);
} }
// look up the JRE bundle and its parent chain. Only // look up the JRE bundle and its parent chain. Only
...@@ -361,7 +393,7 @@ public final class LocaleServiceProviderPool { ...@@ -361,7 +393,7 @@ public final class LocaleServiceProviderPool {
} else { } else {
lsp = (P)findProvider(bundleLocale); lsp = (P)findProvider(bundleLocale);
if (lsp != null) { if (lsp != null) {
providersObj = getter.getObject(lsp, requested, key, params); providersObj = getter.getObject(lsp, locale, key, params);
if (providersObj != null) { if (providersObj != null) {
return providersObj; return providersObj;
} }
...@@ -399,6 +431,8 @@ public final class LocaleServiceProviderPool { ...@@ -399,6 +431,8 @@ public final class LocaleServiceProviderPool {
for (LocaleServiceProvider lsp : providers) { for (LocaleServiceProvider lsp : providers) {
Locale[] locales = lsp.getAvailableLocales(); Locale[] locales = lsp.getAvailableLocales();
for (Locale available: locales) { for (Locale available: locales) {
// normalize
available = getLookupLocale(available);
if (locale.equals(available)) { if (locale.equals(available)) {
LocaleServiceProvider providerInCache = LocaleServiceProvider providerInCache =
providersCache.put(locale, lsp); providersCache.put(locale, lsp);
...@@ -414,66 +448,51 @@ public final class LocaleServiceProviderPool { ...@@ -414,66 +448,51 @@ public final class LocaleServiceProviderPool {
} }
/** /**
* Returns the provider's locale that is the most appropriate * Returns a list of candidate locales for service look up.
* within the range * @param locale the input locale
* * @return the list of candiate locales for the given locale
* @param start the given locale that is used as the starting one
* @param end the given locale that is used as the end one (exclusive),
* or null if it reaching any of the JRE supported locale should
* terminate the look up.
* @return the most specific locale within the range, or null
* if no provider locale found in that range.
*/ */
private Locale findProviderLocale(Locale start, Locale end) { private static List<Locale> getLookupLocales(Locale locale) {
Set<Locale> provLoc = getProviderLocales(); // Note: We currently use the default implementation of
Locale current = start; // ResourceBundle.Control.getCandidateLocales. The result
// returned by getCandidateLocales are already normalized
while (current != null) { // (no extensions) for service look up.
if (end != null) { List<Locale> lookupLocales = new Control(){}.getCandidateLocales("", locale);
if (current.equals(end)) { return lookupLocales;
current = null;
break;
}
} else {
if (isJRESupported(current)) {
current = null;
break;
}
}
if (provLoc.contains(current)) {
break;
}
current = getParentLocale(current);
}
return current;
} }
/** /**
* Returns the parent locale. * Returns an instance of Locale used for service look up.
* The result Locale has no extensions except for ja_JP_JP
* and th_TH_TH
* *
* @param locale the locale * @param locale the locale
* @return the parent locale * @return the locale used for service look up
*/ */
private static Locale getParentLocale(Locale locale) { private static Locale getLookupLocale(Locale locale) {
String variant = locale.getVariant(); Locale lookupLocale = locale;
if (variant != "") { Set<Character> extensions = locale.getExtensionKeys();
int underscoreIndex = variant.lastIndexOf('_'); if (!extensions.isEmpty()
if (underscoreIndex != (-1)) { && !locale.equals(locale_ja_JP_JP)
return new Locale(locale.getLanguage(), locale.getCountry(), && !locale.equals(locale_th_TH_TH)) {
variant.substring(0, underscoreIndex)); // remove extensions
} else { Builder locbld = new Builder();
return new Locale(locale.getLanguage(), locale.getCountry()); try {
locbld.setLocale(locale);
locbld.clearExtensions();
lookupLocale = locbld.build();
} catch (IllformedLocaleException e) {
// A Locale with non-empty extensions
// should have well-formed fields except
// for ja_JP_JP and th_TH_TH. Therefore,
// it should never enter in this catch clause.
config("A locale(" + locale + ") has non-empty extensions, but has illformed fields.");
// Fallback - script field will be lost.
lookupLocale = new Locale(locale.getLanguage(), locale.getCountry(), locale.getVariant());
} }
} else if (locale.getCountry() != "") {
return new Locale(locale.getLanguage());
} else if (locale.getLanguage() != "") {
return Locale.ROOT;
} else {
return null;
} }
return lookupLocale;
} }
/** /**
......
...@@ -30,6 +30,7 @@ import java.io.FileInputStream; ...@@ -30,6 +30,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
import java.nio.file.FileSystems;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.security.PrivilegedActionException; import java.security.PrivilegedActionException;
...@@ -472,17 +473,18 @@ public class ZoneInfoFile { ...@@ -472,17 +473,18 @@ public class ZoneInfoFile {
private static Map<String, ZoneInfo> zoneInfoObjects = null; private static Map<String, ZoneInfo> zoneInfoObjects = null;
private static final String ziDir; private static final String ziDir = AccessController.doPrivileged(
static { new PrivilegedAction<String>() {
String zi = (String) AccessController.doPrivileged( public String run() {
new sun.security.action.GetPropertyAction("java.home")) String zi = System.getProperty("java.home") +
+ File.separator + "lib" + File.separator + "zi"; File.separator + "lib" + File.separator + "zi";
try { try {
zi = new File(zi).getCanonicalPath(); zi = FileSystems.getDefault().getPath(zi).toRealPath(true).toString();
} catch (Exception e) { } catch(Exception e) {
} }
ziDir = zi; return zi;
} }
});
/** /**
* Converts the given time zone ID to a platform dependent path * Converts the given time zone ID to a platform dependent path
......
此差异已折叠。
此差异已折叠。
/*
* Copyright (c) 2010, Oracle and/or its affiliates. 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
*******************************************************************************
* Copyright (C) 2009-2010, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
package sun.util.locale;
public class Extension {
private char _key;
protected String _value;
protected Extension(char key) {
_key = key;
}
Extension(char key, String value) {
_key = key;
_value = value;
}
public char getKey() {
return _key;
}
public String getValue() {
return _value;
}
public String getID() {
return _key + LanguageTag.SEP + _value;
}
public String toString() {
return getID();
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
/* /*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -177,6 +177,11 @@ public class LocaleData { ...@@ -177,6 +177,11 @@ public class LocaleData {
for (Iterator<Locale> l = candidates.iterator(); l.hasNext(); ) { for (Iterator<Locale> l = candidates.iterator(); l.hasNext(); ) {
String lstr = l.next().toString(); String lstr = l.next().toString();
/* truncate extra segment introduced by Java 7 for script and extesions */
int idx = lstr.indexOf("_#");
if (idx >= 0) {
lstr = lstr.substring(0, idx);
}
/* Every locale string in the locale string list returned from /* Every locale string in the locale string list returned from
the above getSupportedLocaleString is enclosed the above getSupportedLocaleString is enclosed
within two white spaces so that we could check some locale within two white spaces so that we could check some locale
......
...@@ -227,6 +227,12 @@ za=\u85cf\u6587 ...@@ -227,6 +227,12 @@ za=\u85cf\u6587
zh=\u4e2d\u6587 zh=\u4e2d\u6587
zu=\u7956\u9c81\u6587 zu=\u7956\u9c81\u6587
# script names
# key is ISO 15924 script code
Hans=\u7b80\u4f53\u4e2d\u6587
Hant=\u7e41\u4f53\u4e2d\u6587
# country names # country names
# key is ISO 3166 country code # key is ISO 3166 country code
......
...@@ -227,6 +227,12 @@ za=\u58ef\u6587 ...@@ -227,6 +227,12 @@ za=\u58ef\u6587
zh=\u4e2d\u6587 zh=\u4e2d\u6587
zu=\u7956\u9b6f\u6587 zu=\u7956\u9b6f\u6587
# script names
# key is ISO 15924 script code
Hans=\u7c21\u9ad4\u4e2d\u6587
Hant=\u7e41\u9ad4\u4e2d\u6587
# country names # country names
# key is ISO 3166 country code # key is ISO 3166 country code
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册