This commit is contained in:
Lana Steuck 2009-12-10 09:50:09 -08:00
commit ac644fa9f8
98 changed files with 3997 additions and 1485 deletions

View file

@ -108,22 +108,14 @@ ifeq ($(PLATFORM), linux)
endif # PLATFORM linux endif # PLATFORM linux
ifeq ($(PLATFORM), solaris) ifeq ($(PLATFORM), solaris)
ifneq ($(ARCH), amd64)
# build with ports and direct audio # build with ports and direct audio
CPPFLAGS += -DUSE_PORTS=TRUE \ CPPFLAGS += -DUSE_PORTS=TRUE \
-DUSE_DAUDIO=TRUE -DUSE_DAUDIO=TRUE
INCLUDE_PORTS = TRUE INCLUDE_PORTS = TRUE
INCLUDE_DAUDIO = TRUE INCLUDE_DAUDIO = TRUE
INCLUDE_MIDI = TRUE
else
# build with empty MIDI i/o # build with empty MIDI i/o
INCLUDE_MIDI = TRUE INCLUDE_MIDI = TRUE
# build with empty ports
INCLUDE_PORTS = TRUE
# build with empty direct audio
INCLUDE_DAUDIO = TRUE
endif
endif # PLATFORM solaris endif # PLATFORM solaris
# for dynamic inclusion of extra sound libs: these # for dynamic inclusion of extra sound libs: these

View file

@ -81,4 +81,11 @@ public final class WeakCache<K, V> {
this.map.remove(key); this.map.remove(key);
} }
} }
/**
* Removes all of the mappings from this cache.
*/
public void clear() {
this.map.clear();
}
} }

View file

@ -24,7 +24,6 @@
*/ */
package com.sun.java.swing.plaf.gtk; package com.sun.java.swing.plaf.gtk;
import sun.swing.plaf.synth.SynthUI;
import sun.awt.UNIXToolkit; import sun.awt.UNIXToolkit;
import javax.swing.plaf.synth.*; import javax.swing.plaf.synth.*;

View file

@ -0,0 +1,41 @@
/*
* Copyright 2009 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 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.
*/
package com.sun.media.sound;
import javax.sound.midi.MidiDevice;
import javax.sound.midi.Receiver;
/**
* A Receiver with reference to it's MidiDevice object.
*
* @author Karl Helgason
*/
public interface MidiDeviceReceiver extends Receiver {
/** Obtains the MidiDevice object associated with this Receiver.
*/
public MidiDevice getMidiDevice();
}

View file

@ -48,6 +48,30 @@ public class SoftAudioBuffer {
converter = AudioFloatConverter.getConverter(format); converter = AudioFloatConverter.getConverter(format);
} }
public void swap(SoftAudioBuffer swap)
{
int bak_size = size;
float[] bak_buffer = buffer;
boolean bak_empty = empty;
AudioFormat bak_format = format;
AudioFloatConverter bak_converter = converter;
byte[] bak_converter_buffer = converter_buffer;
size = swap.size;
buffer = swap.buffer;
empty = swap.empty;
format = swap.format;
converter = swap.converter;
converter_buffer = swap.converter_buffer;
swap.size = bak_size;
swap.buffer = bak_buffer;
swap.empty = bak_empty;
swap.format = bak_format;
swap.converter = bak_converter;
swap.converter_buffer = bak_converter_buffer;
}
public AudioFormat getFormat() { public AudioFormat getFormat() {
return format; return format;
} }

View file

@ -218,6 +218,15 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
} }
private int findFreeVoice(int x) { private int findFreeVoice(int x) {
if(x == -1)
{
// x = -1 means that there where no available voice
// last time we called findFreeVoice
// and it hasn't changed because no audio has been
// rendered in the meantime.
// Therefore we have to return -1.
return -1;
}
for (int i = x; i < voices.length; i++) for (int i = x; i < voices.length; i++)
if (!voices[i].active) if (!voices[i].active)
return i; return i;
@ -328,7 +337,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
} }
protected void initVoice(SoftVoice voice, SoftPerformer p, int voiceID, protected void initVoice(SoftVoice voice, SoftPerformer p, int voiceID,
int noteNumber, int velocity, ModelConnectionBlock[] connectionBlocks, int noteNumber, int velocity, int delay, ModelConnectionBlock[] connectionBlocks,
ModelChannelMixer channelmixer, boolean releaseTriggered) { ModelChannelMixer channelmixer, boolean releaseTriggered) {
if (voice.active) { if (voice.active) {
// Voice is active , we must steal the voice // Voice is active , we must steal the voice
@ -363,7 +372,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
voice.objects.put("midi_cc", co_midi_cc); voice.objects.put("midi_cc", co_midi_cc);
voice.objects.put("midi_rpn", co_midi_rpn); voice.objects.put("midi_rpn", co_midi_rpn);
voice.objects.put("midi_nrpn", co_midi_nrpn); voice.objects.put("midi_nrpn", co_midi_nrpn);
voice.noteOn(noteNumber, velocity); voice.noteOn(noteNumber, velocity, delay);
voice.setMute(mute); voice.setMute(mute);
voice.setSoloMute(solomute); voice.setSoloMute(solomute);
if (releaseTriggered) if (releaseTriggered)
@ -399,14 +408,21 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
} }
public void noteOn(int noteNumber, int velocity) { public void noteOn(int noteNumber, int velocity) {
noteOn(noteNumber, velocity, 0);
}
/* A special noteOn with delay parameter, which is used to
* start note within control buffers.
*/
protected void noteOn(int noteNumber, int velocity, int delay) {
noteNumber = restrict7Bit(noteNumber); noteNumber = restrict7Bit(noteNumber);
velocity = restrict7Bit(velocity); velocity = restrict7Bit(velocity);
noteOn_internal(noteNumber, velocity); noteOn_internal(noteNumber, velocity, delay);
if (current_mixer != null) if (current_mixer != null)
current_mixer.noteOn(noteNumber, velocity); current_mixer.noteOn(noteNumber, velocity);
} }
private void noteOn_internal(int noteNumber, int velocity) { private void noteOn_internal(int noteNumber, int velocity, int delay) {
if (velocity == 0) { if (velocity == 0) {
noteOff_internal(noteNumber, 64); noteOff_internal(noteNumber, 64);
@ -490,6 +506,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
int tunedKey = (int)(Math.round(tuning.getTuning()[noteNumber]/100.0)); int tunedKey = (int)(Math.round(tuning.getTuning()[noteNumber]/100.0));
play_noteNumber = noteNumber; play_noteNumber = noteNumber;
play_velocity = velocity; play_velocity = velocity;
play_delay = delay;
play_releasetriggered = false; play_releasetriggered = false;
lastVelocity[noteNumber] = velocity; lastVelocity[noteNumber] = velocity;
current_director.noteOn(tunedKey, velocity); current_director.noteOn(tunedKey, velocity);
@ -594,6 +611,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
play_noteNumber = noteNumber; play_noteNumber = noteNumber;
play_velocity = lastVelocity[noteNumber]; play_velocity = lastVelocity[noteNumber];
play_releasetriggered = true; play_releasetriggered = true;
play_delay = 0;
current_director.noteOff(tunedKey, velocity); current_director.noteOff(tunedKey, velocity);
} }
@ -604,12 +622,14 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
private int voiceNo = 0; private int voiceNo = 0;
private int play_noteNumber = 0; private int play_noteNumber = 0;
private int play_velocity = 0; private int play_velocity = 0;
private int play_delay = 0;
private boolean play_releasetriggered = false; private boolean play_releasetriggered = false;
public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks) { public void play(int performerIndex, ModelConnectionBlock[] connectionBlocks) {
int noteNumber = play_noteNumber; int noteNumber = play_noteNumber;
int velocity = play_velocity; int velocity = play_velocity;
int delay = play_delay;
boolean releasetriggered = play_releasetriggered; boolean releasetriggered = play_releasetriggered;
SoftPerformer p = current_instrument.getPerformers()[performerIndex]; SoftPerformer p = current_instrument.getPerformers()[performerIndex];
@ -633,7 +653,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
if (voiceNo == -1) if (voiceNo == -1)
return; return;
initVoice(voices[voiceNo], p, prevVoiceID, noteNumber, velocity, initVoice(voices[voiceNo], p, prevVoiceID, noteNumber, velocity, delay,
connectionBlocks, current_mixer, releasetriggered); connectionBlocks, current_mixer, releasetriggered);
} }

View file

@ -79,7 +79,7 @@ public class SoftLimiter implements SoftAudioProcessor {
if (silentcounter > 60) { if (silentcounter > 60) {
if (!mix) { if (!mix) {
bufferLout.clear(); bufferLout.clear();
bufferRout.clear(); if (bufferRout != null) bufferRout.clear();
} }
return; return;
} }

View file

@ -26,7 +26,6 @@ package com.sun.media.sound;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
@ -46,28 +45,37 @@ import javax.sound.sampled.AudioSystem;
*/ */
public class SoftMainMixer { public class SoftMainMixer {
// A private class thats contains a ModelChannelMixer and it's private buffers.
// This becomes necessary when we want to have separate delay buffers for each channel mixer.
private class SoftChannelMixerContainer
{
ModelChannelMixer mixer;
SoftAudioBuffer[] buffers;
}
public final static int CHANNEL_LEFT = 0; public final static int CHANNEL_LEFT = 0;
public final static int CHANNEL_RIGHT = 1; public final static int CHANNEL_RIGHT = 1;
public final static int CHANNEL_MONO = 2; public final static int CHANNEL_MONO = 2;
public final static int CHANNEL_EFFECT1 = 3; public final static int CHANNEL_DELAY_LEFT = 3;
public final static int CHANNEL_EFFECT2 = 4; public final static int CHANNEL_DELAY_RIGHT = 4;
public final static int CHANNEL_EFFECT3 = 5; public final static int CHANNEL_DELAY_MONO = 5;
public final static int CHANNEL_EFFECT4 = 6; public final static int CHANNEL_EFFECT1 = 6;
public final static int CHANNEL_EFFECT2 = 7;
public final static int CHANNEL_DELAY_EFFECT1 = 8;
public final static int CHANNEL_DELAY_EFFECT2 = 9;
public final static int CHANNEL_LEFT_DRY = 10; public final static int CHANNEL_LEFT_DRY = 10;
public final static int CHANNEL_RIGHT_DRY = 11; public final static int CHANNEL_RIGHT_DRY = 11;
public final static int CHANNEL_SCRATCH1 = 12; public final static int CHANNEL_SCRATCH1 = 12;
public final static int CHANNEL_SCRATCH2 = 13; public final static int CHANNEL_SCRATCH2 = 13;
public final static int CHANNEL_CHANNELMIXER_LEFT = 14;
public final static int CHANNEL_CHANNELMIXER_RIGHT = 15;
public final static int CHANNEL_CHANNELMIXER_MONO = 16;
protected boolean active_sensing_on = false; protected boolean active_sensing_on = false;
private long msec_last_activity = -1; private long msec_last_activity = -1;
private boolean pusher_silent = false; private boolean pusher_silent = false;
private int pusher_silent_count = 0; private int pusher_silent_count = 0;
private long msec_pos = 0; private long sample_pos = 0;
protected boolean readfully = true; protected boolean readfully = true;
private Object control_mutex; private Object control_mutex;
private SoftSynthesizer synth; private SoftSynthesizer synth;
private float samplerate = 44100;
private int nrofchannels = 2; private int nrofchannels = 2;
private SoftVoice[] voicestatus = null; private SoftVoice[] voicestatus = null;
private SoftAudioBuffer[] buffers; private SoftAudioBuffer[] buffers;
@ -75,7 +83,10 @@ public class SoftMainMixer {
private SoftAudioProcessor chorus; private SoftAudioProcessor chorus;
private SoftAudioProcessor agc; private SoftAudioProcessor agc;
private long msec_buffer_len = 0; private long msec_buffer_len = 0;
private int buffer_len = 0;
protected TreeMap<Long, Object> midimessages = new TreeMap<Long, Object>(); protected TreeMap<Long, Object> midimessages = new TreeMap<Long, Object>();
private int delay_midievent = 0;
private int max_delay_midievent = 0;
double last_volume_left = 1.0; double last_volume_left = 1.0;
double last_volume_right = 1.0; double last_volume_right = 1.0;
private double[] co_master_balance = new double[1]; private double[] co_master_balance = new double[1];
@ -83,9 +94,9 @@ public class SoftMainMixer {
private double[] co_master_coarse_tuning = new double[1]; private double[] co_master_coarse_tuning = new double[1];
private double[] co_master_fine_tuning = new double[1]; private double[] co_master_fine_tuning = new double[1];
private AudioInputStream ais; private AudioInputStream ais;
private Set<ModelChannelMixer> registeredMixers = null; private Set<SoftChannelMixerContainer> registeredMixers = null;
private Set<ModelChannelMixer> stoppedMixers = null; private Set<ModelChannelMixer> stoppedMixers = null;
private ModelChannelMixer[] cur_registeredMixers = null; private SoftChannelMixerContainer[] cur_registeredMixers = null;
protected SoftControl co_master = new SoftControl() { protected SoftControl co_master = new SoftControl() {
double[] balance = co_master_balance; double[] balance = co_master_balance;
@ -413,26 +424,68 @@ public class SoftMainMixer {
Iterator<Entry<Long, Object>> iter = midimessages.entrySet().iterator(); Iterator<Entry<Long, Object>> iter = midimessages.entrySet().iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
Entry<Long, Object> entry = iter.next(); Entry<Long, Object> entry = iter.next();
if (entry.getKey() > (timeStamp + 100)) if (entry.getKey() >= (timeStamp + msec_buffer_len))
return; return;
long msec_delay = entry.getKey() - timeStamp;
delay_midievent = (int)(msec_delay * (samplerate / 1000000.0) + 0.5);
if(delay_midievent > max_delay_midievent)
delay_midievent = max_delay_midievent;
if(delay_midievent < 0)
delay_midievent = 0;
processMessage(entry.getValue()); processMessage(entry.getValue());
iter.remove(); iter.remove();
} }
delay_midievent = 0;
} }
protected void processAudioBuffers() { protected void processAudioBuffers() {
if(synth.weakstream != null && synth.weakstream.silent_samples != 0)
{
sample_pos += synth.weakstream.silent_samples;
synth.weakstream.silent_samples = 0;
}
for (int i = 0; i < buffers.length; i++) { for (int i = 0; i < buffers.length; i++) {
if(i != CHANNEL_DELAY_LEFT &&
i != CHANNEL_DELAY_RIGHT &&
i != CHANNEL_DELAY_MONO &&
i != CHANNEL_DELAY_EFFECT1 &&
i != CHANNEL_DELAY_EFFECT2)
buffers[i].clear(); buffers[i].clear();
} }
if(!buffers[CHANNEL_DELAY_LEFT].isSilent())
{
buffers[CHANNEL_LEFT].swap(buffers[CHANNEL_DELAY_LEFT]);
}
if(!buffers[CHANNEL_DELAY_RIGHT].isSilent())
{
buffers[CHANNEL_RIGHT].swap(buffers[CHANNEL_DELAY_RIGHT]);
}
if(!buffers[CHANNEL_DELAY_MONO].isSilent())
{
buffers[CHANNEL_MONO].swap(buffers[CHANNEL_DELAY_MONO]);
}
if(!buffers[CHANNEL_DELAY_EFFECT1].isSilent())
{
buffers[CHANNEL_EFFECT1].swap(buffers[CHANNEL_DELAY_EFFECT1]);
}
if(!buffers[CHANNEL_DELAY_EFFECT2].isSilent())
{
buffers[CHANNEL_EFFECT2].swap(buffers[CHANNEL_DELAY_EFFECT2]);
}
double volume_left; double volume_left;
double volume_right; double volume_right;
ModelChannelMixer[] act_registeredMixers; SoftChannelMixerContainer[] act_registeredMixers;
// perform control logic // perform control logic
synchronized (control_mutex) { synchronized (control_mutex) {
long msec_pos = (long)(sample_pos * (1000000.0 / samplerate));
processMessages(msec_pos); processMessages(msec_pos);
if (active_sensing_on) { if (active_sensing_on) {
@ -450,7 +503,7 @@ public class SoftMainMixer {
for (int i = 0; i < voicestatus.length; i++) for (int i = 0; i < voicestatus.length; i++)
if (voicestatus[i].active) if (voicestatus[i].active)
voicestatus[i].processControlLogic(); voicestatus[i].processControlLogic();
msec_pos += msec_buffer_len; sample_pos += buffer_len;
double volume = co_master_volume[0]; double volume = co_master_volume[0];
volume_left = volume; volume_left = volume;
@ -469,7 +522,7 @@ public class SoftMainMixer {
if (cur_registeredMixers == null) { if (cur_registeredMixers == null) {
if (registeredMixers != null) { if (registeredMixers != null) {
cur_registeredMixers = cur_registeredMixers =
new ModelChannelMixer[registeredMixers.size()]; new SoftChannelMixerContainer[registeredMixers.size()];
registeredMixers.toArray(cur_registeredMixers); registeredMixers.toArray(cur_registeredMixers);
} }
} }
@ -483,44 +536,61 @@ public class SoftMainMixer {
if (act_registeredMixers != null) { if (act_registeredMixers != null) {
// Reroute default left,right output // Make backup of left,right,mono channels
// to channelmixer left,right input/output
SoftAudioBuffer leftbak = buffers[CHANNEL_LEFT]; SoftAudioBuffer leftbak = buffers[CHANNEL_LEFT];
SoftAudioBuffer rightbak = buffers[CHANNEL_RIGHT]; SoftAudioBuffer rightbak = buffers[CHANNEL_RIGHT];
SoftAudioBuffer monobak = buffers[CHANNEL_MONO]; SoftAudioBuffer monobak = buffers[CHANNEL_MONO];
buffers[CHANNEL_LEFT] = buffers[CHANNEL_CHANNELMIXER_LEFT]; SoftAudioBuffer delayleftbak = buffers[CHANNEL_DELAY_LEFT];
buffers[CHANNEL_RIGHT] = buffers[CHANNEL_CHANNELMIXER_RIGHT]; SoftAudioBuffer delayrightbak = buffers[CHANNEL_DELAY_RIGHT];
buffers[CHANNEL_MONO] = buffers[CHANNEL_CHANNELMIXER_MONO]; SoftAudioBuffer delaymonobak = buffers[CHANNEL_DELAY_MONO];
int bufferlen = buffers[CHANNEL_LEFT].getSize(); int bufferlen = buffers[CHANNEL_LEFT].getSize();
float[][] cbuffer = new float[nrofchannels][]; float[][] cbuffer = new float[nrofchannels][];
cbuffer[0] = buffers[CHANNEL_LEFT].array();
if (nrofchannels != 1)
cbuffer[1] = buffers[CHANNEL_RIGHT].array();
float[][] obuffer = new float[nrofchannels][]; float[][] obuffer = new float[nrofchannels][];
obuffer[0] = leftbak.array(); obuffer[0] = leftbak.array();
if (nrofchannels != 1) if (nrofchannels != 1)
obuffer[1] = rightbak.array(); obuffer[1] = rightbak.array();
for (ModelChannelMixer cmixer : act_registeredMixers) { for (SoftChannelMixerContainer cmixer : act_registeredMixers) {
for (int i = 0; i < cbuffer.length; i++)
Arrays.fill(cbuffer[i], 0); // Reroute default left,right output
// to channelmixer left,right input/output
buffers[CHANNEL_LEFT] = cmixer.buffers[CHANNEL_LEFT];
buffers[CHANNEL_RIGHT] = cmixer.buffers[CHANNEL_RIGHT];
buffers[CHANNEL_MONO] = cmixer.buffers[CHANNEL_MONO];
buffers[CHANNEL_DELAY_LEFT] = cmixer.buffers[CHANNEL_DELAY_LEFT];
buffers[CHANNEL_DELAY_RIGHT] = cmixer.buffers[CHANNEL_DELAY_RIGHT];
buffers[CHANNEL_DELAY_MONO] = cmixer.buffers[CHANNEL_DELAY_MONO];
buffers[CHANNEL_LEFT].clear();
buffers[CHANNEL_RIGHT].clear();
buffers[CHANNEL_MONO].clear(); buffers[CHANNEL_MONO].clear();
if(!buffers[CHANNEL_DELAY_LEFT].isSilent())
{
buffers[CHANNEL_LEFT].swap(buffers[CHANNEL_DELAY_LEFT]);
}
if(!buffers[CHANNEL_DELAY_RIGHT].isSilent())
{
buffers[CHANNEL_RIGHT].swap(buffers[CHANNEL_DELAY_RIGHT]);
}
if(!buffers[CHANNEL_DELAY_MONO].isSilent())
{
buffers[CHANNEL_MONO].swap(buffers[CHANNEL_DELAY_MONO]);
}
cbuffer[0] = buffers[CHANNEL_LEFT].array();
if (nrofchannels != 1)
cbuffer[1] = buffers[CHANNEL_RIGHT].array();
boolean hasactivevoices = false; boolean hasactivevoices = false;
for (int i = 0; i < voicestatus.length; i++) for (int i = 0; i < voicestatus.length; i++)
if (voicestatus[i].active) if (voicestatus[i].active)
if (voicestatus[i].channelmixer == cmixer) { if (voicestatus[i].channelmixer == cmixer.mixer) {
voicestatus[i].processAudioLogic(buffers); voicestatus[i].processAudioLogic(buffers);
hasactivevoices = true; hasactivevoices = true;
} }
if (!cmixer.process(cbuffer, 0, bufferlen)) {
synchronized (control_mutex) {
registeredMixers.remove(cmixer);
cur_registeredMixers = null;
}
}
if(!buffers[CHANNEL_MONO].isSilent()) if(!buffers[CHANNEL_MONO].isSilent())
{ {
@ -542,6 +612,13 @@ public class SoftMainMixer {
} }
} }
if (!cmixer.mixer.process(cbuffer, 0, bufferlen)) {
synchronized (control_mutex) {
registeredMixers.remove(cmixer);
cur_registeredMixers = null;
}
}
for (int i = 0; i < cbuffer.length; i++) { for (int i = 0; i < cbuffer.length; i++) {
float[] cbuff = cbuffer[i]; float[] cbuff = cbuffer[i];
float[] obuff = obuffer[i]; float[] obuff = obuffer[i];
@ -554,7 +631,7 @@ public class SoftMainMixer {
if (stoppedMixers != null) { if (stoppedMixers != null) {
if (stoppedMixers.contains(cmixer)) { if (stoppedMixers.contains(cmixer)) {
stoppedMixers.remove(cmixer); stoppedMixers.remove(cmixer);
cmixer.stop(); cmixer.mixer.stop();
} }
} }
} }
@ -565,6 +642,9 @@ public class SoftMainMixer {
buffers[CHANNEL_LEFT] = leftbak; buffers[CHANNEL_LEFT] = leftbak;
buffers[CHANNEL_RIGHT] = rightbak; buffers[CHANNEL_RIGHT] = rightbak;
buffers[CHANNEL_MONO] = monobak; buffers[CHANNEL_MONO] = monobak;
buffers[CHANNEL_DELAY_LEFT] = delayleftbak;
buffers[CHANNEL_DELAY_RIGHT] = delayrightbak;
buffers[CHANNEL_DELAY_MONO] = delaymonobak;
} }
@ -649,6 +729,14 @@ public class SoftMainMixer {
if(buffers[CHANNEL_LEFT].isSilent() if(buffers[CHANNEL_LEFT].isSilent()
&& buffers[CHANNEL_RIGHT].isSilent()) && buffers[CHANNEL_RIGHT].isSilent())
{
int midimessages_size;
synchronized (control_mutex) {
midimessages_size = midimessages.size();
}
if(midimessages_size == 0)
{ {
pusher_silent_count++; pusher_silent_count++;
if(pusher_silent_count > 5) if(pusher_silent_count > 5)
@ -661,6 +749,7 @@ public class SoftMainMixer {
} }
} }
} }
}
else else
pusher_silent_count = 0; pusher_silent_count = 0;
@ -672,14 +761,19 @@ public class SoftMainMixer {
// Must only we called within control_mutex synchronization // Must only we called within control_mutex synchronization
public void activity() public void activity()
{ {
msec_last_activity = msec_pos; long silent_samples = 0;
if(pusher_silent) if(pusher_silent)
{ {
pusher_silent = false; pusher_silent = false;
if(synth.weakstream != null) if(synth.weakstream != null)
{
synth.weakstream.setInputStream(ais); synth.weakstream.setInputStream(ais);
silent_samples = synth.weakstream.silent_samples;
} }
} }
msec_last_activity = (long)((sample_pos + silent_samples)
* (1000000.0 / samplerate));
}
public void stopMixer(ModelChannelMixer mixer) { public void stopMixer(ModelChannelMixer mixer) {
if (stoppedMixers == null) if (stoppedMixers == null)
@ -689,15 +783,22 @@ public class SoftMainMixer {
public void registerMixer(ModelChannelMixer mixer) { public void registerMixer(ModelChannelMixer mixer) {
if (registeredMixers == null) if (registeredMixers == null)
registeredMixers = new HashSet<ModelChannelMixer>(); registeredMixers = new HashSet<SoftChannelMixerContainer>();
registeredMixers.add(mixer); SoftChannelMixerContainer mixercontainer = new SoftChannelMixerContainer();
mixercontainer.buffers = new SoftAudioBuffer[6];
for (int i = 0; i < mixercontainer.buffers.length; i++) {
mixercontainer.buffers[i] =
new SoftAudioBuffer(buffer_len, synth.getFormat());
}
mixercontainer.mixer = mixer;
registeredMixers.add(mixercontainer);
cur_registeredMixers = null; cur_registeredMixers = null;
} }
public SoftMainMixer(SoftSynthesizer synth) { public SoftMainMixer(SoftSynthesizer synth) {
this.synth = synth; this.synth = synth;
msec_pos = 0; sample_pos = 0;
co_master_balance[0] = 0.5; co_master_balance[0] = 0.5;
co_master_volume[0] = 1; co_master_volume[0] = 1;
@ -705,14 +806,18 @@ public class SoftMainMixer {
co_master_fine_tuning[0] = 0.5; co_master_fine_tuning[0] = 0.5;
msec_buffer_len = (long) (1000000.0 / synth.getControlRate()); msec_buffer_len = (long) (1000000.0 / synth.getControlRate());
samplerate = synth.getFormat().getSampleRate();
nrofchannels = synth.getFormat().getChannels(); nrofchannels = synth.getFormat().getChannels();
int buffersize = (int) (synth.getFormat().getSampleRate() int buffersize = (int) (synth.getFormat().getSampleRate()
/ synth.getControlRate()); / synth.getControlRate());
buffer_len = buffersize;
max_delay_midievent = buffersize;
control_mutex = synth.control_mutex; control_mutex = synth.control_mutex;
buffers = new SoftAudioBuffer[17]; buffers = new SoftAudioBuffer[14];
for (int i = 0; i < buffers.length; i++) { for (int i = 0; i < buffers.length; i++) {
buffers[i] = new SoftAudioBuffer(buffersize, synth.getFormat()); buffers[i] = new SoftAudioBuffer(buffersize, synth.getFormat());
} }
@ -994,6 +1099,9 @@ public class SoftMainMixer {
switch (cmd) { switch (cmd) {
case ShortMessage.NOTE_ON: case ShortMessage.NOTE_ON:
if(delay_midievent != 0)
softchannel.noteOn(data1, data2, delay_midievent);
else
softchannel.noteOn(data1, data2); softchannel.noteOn(data1, data2);
break; break;
case ShortMessage.NOTE_OFF: case ShortMessage.NOTE_OFF:
@ -1021,7 +1129,15 @@ public class SoftMainMixer {
} }
public long getMicrosecondPosition() { public long getMicrosecondPosition() {
return msec_pos; if(pusher_silent)
{
if(synth.weakstream != null)
{
return (long)((sample_pos + synth.weakstream.silent_samples)
* (1000000.0 / samplerate));
}
}
return (long)(sample_pos * (1000000.0 / samplerate));
} }
public void close() { public void close() {

View file

@ -26,8 +26,8 @@ package com.sun.media.sound;
import java.util.TreeMap; import java.util.TreeMap;
import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiMessage; import javax.sound.midi.MidiMessage;
import javax.sound.midi.Receiver;
import javax.sound.midi.ShortMessage; import javax.sound.midi.ShortMessage;
/** /**
@ -35,7 +35,7 @@ import javax.sound.midi.ShortMessage;
* *
* @author Karl Helgason * @author Karl Helgason
*/ */
public class SoftReceiver implements Receiver { public class SoftReceiver implements MidiDeviceReceiver {
protected boolean open = true; protected boolean open = true;
private Object control_mutex; private Object control_mutex;
@ -51,6 +51,10 @@ public class SoftReceiver implements Receiver {
this.midimessages = mainmixer.midimessages; this.midimessages = mainmixer.midimessages;
} }
public MidiDevice getMidiDevice() {
return synth;
}
public void send(MidiMessage message, long timeStamp) { public void send(MidiMessage message, long timeStamp) {
synchronized (control_mutex) { synchronized (control_mutex) {
@ -60,6 +64,7 @@ public class SoftReceiver implements Receiver {
if (timeStamp != -1) { if (timeStamp != -1) {
synchronized (control_mutex) { synchronized (control_mutex) {
mainmixer.activity();
while (midimessages.get(timeStamp) != null) while (midimessages.get(timeStamp) != null)
timeStamp++; timeStamp++;
if (message instanceof ShortMessage if (message instanceof ShortMessage

View file

@ -66,6 +66,8 @@ public class SoftSynthesizer implements AudioSynthesizer,
public SoftAudioPusher pusher = null; public SoftAudioPusher pusher = null;
public AudioInputStream jitter_stream = null; public AudioInputStream jitter_stream = null;
public SourceDataLine sourceDataLine = null; public SourceDataLine sourceDataLine = null;
public volatile long silent_samples = 0;
private int framesize = 0;
private WeakReference<AudioInputStream> weak_stream_link; private WeakReference<AudioInputStream> weak_stream_link;
private AudioFloatConverter converter; private AudioFloatConverter converter;
private float[] silentbuffer = null; private float[] silentbuffer = null;
@ -101,6 +103,8 @@ public class SoftSynthesizer implements AudioSynthesizer,
silentbuffer = new float[flen]; silentbuffer = new float[flen];
converter.toByteArray(silentbuffer, flen, b, off); converter.toByteArray(silentbuffer, flen, b, off);
silent_samples += (long)((len / framesize));
if(pusher != null) if(pusher != null)
if(weak_stream_link.get() == null) if(weak_stream_link.get() == null)
{ {
@ -136,6 +140,7 @@ public class SoftSynthesizer implements AudioSynthesizer,
weak_stream_link = new WeakReference<AudioInputStream>(stream); weak_stream_link = new WeakReference<AudioInputStream>(stream);
converter = AudioFloatConverter.getConverter(stream.getFormat()); converter = AudioFloatConverter.getConverter(stream.getFormat());
samplesize = stream.getFormat().getFrameSize() / stream.getFormat().getChannels(); samplesize = stream.getFormat().getFrameSize() / stream.getFormat().getChannels();
framesize = stream.getFormat().getFrameSize();
} }
public AudioInputStream getAudioInputStream() public AudioInputStream getAudioInputStream()

View file

@ -43,6 +43,7 @@ public class SoftVoice extends VoiceStatus {
private int noteOn_noteNumber = 0; private int noteOn_noteNumber = 0;
private int noteOn_velocity = 0; private int noteOn_velocity = 0;
private int noteOff_velocity = 0; private int noteOff_velocity = 0;
private int delay = 0;
protected ModelChannelMixer channelmixer = null; protected ModelChannelMixer channelmixer = null;
protected double tunedKey = 0; protected double tunedKey = 0;
protected SoftTuning tuning = null; protected SoftTuning tuning = null;
@ -294,7 +295,7 @@ public class SoftVoice extends VoiceStatus {
tunedKey = tuning.getTuning(noteNumber) / 100.0; tunedKey = tuning.getTuning(noteNumber) / 100.0;
} }
protected void noteOn(int noteNumber, int velocity) { protected void noteOn(int noteNumber, int velocity, int delay) {
sustain = false; sustain = false;
sostenuto = false; sostenuto = false;
@ -308,6 +309,7 @@ public class SoftVoice extends VoiceStatus {
noteOn_noteNumber = noteNumber; noteOn_noteNumber = noteNumber;
noteOn_velocity = velocity; noteOn_velocity = velocity;
this.delay = delay;
lastMuteValue = 0; lastMuteValue = 0;
lastSoloMuteValue = 0; lastSoloMuteValue = 0;
@ -562,7 +564,7 @@ public class SoftVoice extends VoiceStatus {
if (stealer_channel != null) { if (stealer_channel != null) {
stealer_channel.initVoice(this, stealer_performer, stealer_channel.initVoice(this, stealer_performer,
stealer_voiceID, stealer_noteNumber, stealer_velocity, stealer_voiceID, stealer_noteNumber, stealer_velocity, 0,
stealer_extendedConnectionBlocks, stealer_channelmixer, stealer_extendedConnectionBlocks, stealer_channelmixer,
stealer_releaseTriggered); stealer_releaseTriggered);
stealer_releaseTriggered = false; stealer_releaseTriggered = false;
@ -733,10 +735,41 @@ public class SoftVoice extends VoiceStatus {
} }
protected void mixAudioStream(SoftAudioBuffer in, SoftAudioBuffer out, protected void mixAudioStream(SoftAudioBuffer in, SoftAudioBuffer out,
SoftAudioBuffer dout,
float amp_from, float amp_to) { float amp_from, float amp_to) {
int bufferlen = in.getSize(); int bufferlen = in.getSize();
if (amp_from < 0.000000001 && amp_to < 0.000000001) if (amp_from < 0.000000001 && amp_to < 0.000000001)
return; return;
if(dout != null && delay != 0)
{
if (amp_from == amp_to) {
float[] fout = out.array();
float[] fin = in.array();
int j = 0;
for (int i = delay; i < bufferlen; i++)
fout[i] += fin[j++] * amp_to;
fout = dout.array();
for (int i = 0; i < delay; i++)
fout[i] += fin[j++] * amp_to;
} else {
float amp = amp_from;
float amp_delta = (amp_to - amp_from) / bufferlen;
float[] fout = out.array();
float[] fin = in.array();
int j = 0;
for (int i = delay; i < bufferlen; i++) {
amp += amp_delta;
fout[i] += fin[j++] * amp;
}
fout = dout.array();
for (int i = 0; i < delay; i++) {
amp += amp_delta;
fout[i] += fin[j++] * amp;
}
}
}
else
{
if (amp_from == amp_to) { if (amp_from == amp_to) {
float[] fout = out.array(); float[] fout = out.array();
float[] fin = in.array(); float[] fin = in.array();
@ -752,6 +785,7 @@ public class SoftVoice extends VoiceStatus {
fout[i] += fin[i] * amp; fout[i] += fin[i] * amp;
} }
} }
}
} }
@ -785,6 +819,13 @@ public class SoftVoice extends VoiceStatus {
SoftAudioBuffer mono = buffer[SoftMainMixer.CHANNEL_MONO]; SoftAudioBuffer mono = buffer[SoftMainMixer.CHANNEL_MONO];
SoftAudioBuffer eff1 = buffer[SoftMainMixer.CHANNEL_EFFECT1]; SoftAudioBuffer eff1 = buffer[SoftMainMixer.CHANNEL_EFFECT1];
SoftAudioBuffer eff2 = buffer[SoftMainMixer.CHANNEL_EFFECT2]; SoftAudioBuffer eff2 = buffer[SoftMainMixer.CHANNEL_EFFECT2];
SoftAudioBuffer dleft = buffer[SoftMainMixer.CHANNEL_DELAY_LEFT];
SoftAudioBuffer dright = buffer[SoftMainMixer.CHANNEL_DELAY_RIGHT];
SoftAudioBuffer dmono = buffer[SoftMainMixer.CHANNEL_DELAY_MONO];
SoftAudioBuffer deff1 = buffer[SoftMainMixer.CHANNEL_DELAY_EFFECT1];
SoftAudioBuffer deff2 = buffer[SoftMainMixer.CHANNEL_DELAY_EFFECT2];
SoftAudioBuffer leftdry = buffer[SoftMainMixer.CHANNEL_LEFT_DRY]; SoftAudioBuffer leftdry = buffer[SoftMainMixer.CHANNEL_LEFT_DRY];
SoftAudioBuffer rightdry = buffer[SoftMainMixer.CHANNEL_RIGHT_DRY]; SoftAudioBuffer rightdry = buffer[SoftMainMixer.CHANNEL_RIGHT_DRY];
@ -799,42 +840,42 @@ public class SoftVoice extends VoiceStatus {
if (nrofchannels == 1) { if (nrofchannels == 1) {
out_mixer_left = (out_mixer_left + out_mixer_right) / 2; out_mixer_left = (out_mixer_left + out_mixer_right) / 2;
mixAudioStream(leftdry, left, last_out_mixer_left, out_mixer_left); mixAudioStream(leftdry, left, dleft, last_out_mixer_left, out_mixer_left);
if (rightdry != null) if (rightdry != null)
mixAudioStream(rightdry, left, last_out_mixer_left, mixAudioStream(rightdry, left, dleft, last_out_mixer_left,
out_mixer_left); out_mixer_left);
} else { } else {
if(rightdry == null && if(rightdry == null &&
last_out_mixer_left == last_out_mixer_right && last_out_mixer_left == last_out_mixer_right &&
out_mixer_left == out_mixer_right) out_mixer_left == out_mixer_right)
{ {
mixAudioStream(leftdry, mono, last_out_mixer_left, out_mixer_left); mixAudioStream(leftdry, mono, dmono, last_out_mixer_left, out_mixer_left);
} }
else else
{ {
mixAudioStream(leftdry, left, last_out_mixer_left, out_mixer_left); mixAudioStream(leftdry, left, dleft, last_out_mixer_left, out_mixer_left);
if (rightdry != null) if (rightdry != null)
mixAudioStream(rightdry, right, last_out_mixer_right, mixAudioStream(rightdry, right, dright, last_out_mixer_right,
out_mixer_right); out_mixer_right);
else else
mixAudioStream(leftdry, right, last_out_mixer_right, mixAudioStream(leftdry, right, dright, last_out_mixer_right,
out_mixer_right); out_mixer_right);
} }
} }
if (rightdry == null) { if (rightdry == null) {
mixAudioStream(leftdry, eff1, last_out_mixer_effect1, mixAudioStream(leftdry, eff1, deff1, last_out_mixer_effect1,
out_mixer_effect1); out_mixer_effect1);
mixAudioStream(leftdry, eff2, last_out_mixer_effect2, mixAudioStream(leftdry, eff2, deff2, last_out_mixer_effect2,
out_mixer_effect2); out_mixer_effect2);
} else { } else {
mixAudioStream(leftdry, eff1, last_out_mixer_effect1 * 0.5f, mixAudioStream(leftdry, eff1, deff1, last_out_mixer_effect1 * 0.5f,
out_mixer_effect1 * 0.5f); out_mixer_effect1 * 0.5f);
mixAudioStream(leftdry, eff2, last_out_mixer_effect2 * 0.5f, mixAudioStream(leftdry, eff2, deff2, last_out_mixer_effect2 * 0.5f,
out_mixer_effect2 * 0.5f); out_mixer_effect2 * 0.5f);
mixAudioStream(rightdry, eff1, last_out_mixer_effect1 * 0.5f, mixAudioStream(rightdry, eff1, deff1, last_out_mixer_effect1 * 0.5f,
out_mixer_effect1 * 0.5f); out_mixer_effect1 * 0.5f);
mixAudioStream(rightdry, eff2, last_out_mixer_effect2 * 0.5f, mixAudioStream(rightdry, eff2, deff2, last_out_mixer_effect2 * 0.5f,
out_mixer_effect2 * 0.5f); out_mixer_effect2 * 0.5f);
} }

View file

@ -313,11 +313,14 @@ perty.
} }
/** /**
* Gets the <code>Class</code> object of the indexed properties' type. * Returns the Java type info for the indexed property.
* The returned <code>Class</code> may describe a primitive type such as <code>int</code>. * Note that the {@code Class} object may describe
* primitive Java types such as {@code int}.
* This type is returned by the indexed read method
* or is used as the parameter type of the indexed write method.
* *
* @return The <code>Class</code> for the indexed properties' type; may return <code>null</code> * @return the {@code Class} object that represents the Java type info,
* if the type cannot be determined. * or {@code null} if the type cannot be determined
*/ */
public synchronized Class<?> getIndexedPropertyType() { public synchronized Class<?> getIndexedPropertyType() {
Class type = getIndexedPropertyType0(); Class type = getIndexedPropertyType0();

View file

@ -25,26 +25,19 @@
package java.beans; package java.beans;
import com.sun.beans.WeakCache;
import com.sun.beans.finder.BeanInfoFinder; import com.sun.beans.finder.BeanInfoFinder;
import com.sun.beans.finder.ClassFinder; import com.sun.beans.finder.ClassFinder;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.EventListener; import java.util.EventListener;
import java.util.List; import java.util.List;
import java.util.WeakHashMap;
import java.util.TreeMap; import java.util.TreeMap;
import sun.awt.AppContext; import sun.awt.AppContext;
@ -85,20 +78,7 @@ import sun.reflect.misc.ReflectUtil;
* patterns to identify property accessors, event sources, or public * patterns to identify property accessors, event sources, or public
* methods. We then proceed to analyze the class's superclass and add * methods. We then proceed to analyze the class's superclass and add
* in the information from it (and possibly on up the superclass chain). * in the information from it (and possibly on up the superclass chain).
*
* <p> * <p>
* Because the Introspector caches BeanInfo classes for better performance,
* take care if you use it in an application that uses
* multiple class loaders.
* In general, when you destroy a <code>ClassLoader</code>
* that has been used to introspect classes,
* you should use the
* {@link #flushCaches <code>Introspector.flushCaches</code>}
* or
* {@link #flushFromCaches <code>Introspector.flushFromCaches</code>} method
* to flush all of the introspected classes out of the cache.
*
* <P>
* For more information about introspection and design patterns, please * For more information about introspection and design patterns, please
* consult the * consult the
* <a href="http://java.sun.com/products/javabeans/docs/index.html">JavaBeans specification</a>. * <a href="http://java.sun.com/products/javabeans/docs/index.html">JavaBeans specification</a>.
@ -112,8 +92,8 @@ public class Introspector {
public final static int IGNORE_ALL_BEANINFO = 3; public final static int IGNORE_ALL_BEANINFO = 3;
// Static Caches to speed up introspection. // Static Caches to speed up introspection.
private static Map declaredMethodCache = private static WeakCache<Class<?>, Method[]> declaredMethodCache =
Collections.synchronizedMap(new WeakHashMap()); new WeakCache<Class<?>, Method[]>();
private static final Object BEANINFO_CACHE = new Object(); private static final Object BEANINFO_CACHE = new Object();
@ -174,20 +154,21 @@ public class Introspector {
if (!ReflectUtil.isPackageAccessible(beanClass)) { if (!ReflectUtil.isPackageAccessible(beanClass)) {
return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo(); return (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
} }
Map<Class<?>, BeanInfo> map;
synchronized (BEANINFO_CACHE) { synchronized (BEANINFO_CACHE) {
map = (Map<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE); WeakCache<Class<?>, BeanInfo> beanInfoCache =
if (map == null) { (WeakCache<Class<?>, BeanInfo>) AppContext.getAppContext().get(BEANINFO_CACHE);
map = Collections.synchronizedMap(new WeakHashMap<Class<?>, BeanInfo>());
AppContext.getAppContext().put(BEANINFO_CACHE, map); if (beanInfoCache == null) {
beanInfoCache = new WeakCache<Class<?>, BeanInfo>();
AppContext.getAppContext().put(BEANINFO_CACHE, beanInfoCache);
} }
BeanInfo beanInfo = beanInfoCache.get(beanClass);
if (beanInfo == null) {
beanInfo = (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
beanInfoCache.put(beanClass, beanInfo);
} }
BeanInfo bi = map.get(beanClass); return beanInfo;
if (bi == null) {
bi = (new Introspector(beanClass, null, USE_ALL_BEANINFO)).getBeanInfo();
map.put(beanClass, bi);
} }
return bi;
} }
/** /**
@ -359,12 +340,14 @@ public class Introspector {
*/ */
public static void flushCaches() { public static void flushCaches() {
Map map = (Map) AppContext.getAppContext().get(BEANINFO_CACHE); synchronized (BEANINFO_CACHE) {
if (map != null) { WeakCache beanInfoCache = (WeakCache) AppContext.getAppContext().get(BEANINFO_CACHE);
map.clear(); if (beanInfoCache != null) {
beanInfoCache.clear();
} }
declaredMethodCache.clear(); declaredMethodCache.clear();
} }
}
/** /**
* Flush the Introspector's internal cached information for a given class. * Flush the Introspector's internal cached information for a given class.
@ -385,11 +368,13 @@ public class Introspector {
if (clz == null) { if (clz == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
Map map = (Map) AppContext.getAppContext().get(BEANINFO_CACHE); synchronized (BEANINFO_CACHE) {
if (map != null) { WeakCache beanInfoCache = (WeakCache) AppContext.getAppContext().get(BEANINFO_CACHE);
map.remove(clz); if (beanInfoCache != null) {
beanInfoCache.put(clz, null);
}
declaredMethodCache.put(clz, null);
} }
declaredMethodCache.remove(clz);
} }
//====================================================================== //======================================================================
@ -1272,42 +1257,27 @@ public class Introspector {
/* /*
* Internal method to return *public* methods within a class. * Internal method to return *public* methods within a class.
*/ */
private static synchronized Method[] getPublicDeclaredMethods(Class clz) { private static Method[] getPublicDeclaredMethods(Class clz) {
// Looking up Class.getDeclaredMethods is relatively expensive, // Looking up Class.getDeclaredMethods is relatively expensive,
// so we cache the results. // so we cache the results.
Method[] result = null;
if (!ReflectUtil.isPackageAccessible(clz)) { if (!ReflectUtil.isPackageAccessible(clz)) {
return new Method[0]; return new Method[0];
} }
final Class fclz = clz; synchronized (BEANINFO_CACHE) {
Reference ref = (Reference)declaredMethodCache.get(fclz); Method[] result = declaredMethodCache.get(clz);
if (ref != null) { if (result == null) {
result = (Method[])ref.get(); result = clz.getMethods();
if (result != null) {
return result;
}
}
// We have to raise privilege for getDeclaredMethods
result = (Method[]) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return fclz.getDeclaredMethods();
}
});
// Null out any non-public methods.
for (int i = 0; i < result.length; i++) { for (int i = 0; i < result.length; i++) {
Method method = result[i]; Method method = result[i];
int mods = method.getModifiers(); if (!method.getDeclaringClass().equals(clz)) {
if (!Modifier.isPublic(mods)) {
result[i] = null; result[i] = null;
} }
} }
// Add it to the cache. declaredMethodCache.put(clz, result);
declaredMethodCache.put(fclz, new SoftReference(result)); }
return result; return result;
} }
}
//====================================================================== //======================================================================
// Package private support methods. // Package private support methods.

View file

@ -164,14 +164,16 @@ public class PropertyDescriptor extends FeatureDescriptor {
} }
/** /**
* Gets the Class object for the property. * Returns the Java type info for the property.
* Note that the {@code Class} object may describe
* primitive Java types such as {@code int}.
* This type is returned by the read method
* or is used as the parameter type of the write method.
* Returns {@code null} if the type is an indexed property
* that does not support non-indexed access.
* *
* @return The Java type info for the property. Note that * @return the {@code Class} object that represents the Java type info,
* the "Class" object may describe a built-in Java type such as "int". * or {@code null} if the type cannot be determined
* The result may be "null" if this is an indexed property that
* does not support non-indexed access.
* <p>
* This is the type that will be returned by the ReadMethod.
*/ */
public synchronized Class<?> getPropertyType() { public synchronized Class<?> getPropertyType() {
Class type = getPropertyType0(); Class type = getPropertyType0();

View file

@ -42,9 +42,11 @@ import java.util.EventListener;
* has been added to the <code>java.beans</code> package. * has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}. * Please see {@link java.beans.XMLEncoder}.
* *
* @param <E> the type of the elements of this model
*
* @author Hans Muller * @author Hans Muller
*/ */
public abstract class AbstractListModel implements ListModel, Serializable public abstract class AbstractListModel<E> implements ListModel<E>, Serializable
{ {
protected EventListenerList listenerList = new EventListenerList(); protected EventListenerList listenerList = new EventListenerList();

View file

@ -71,7 +71,7 @@ import sun.swing.DefaultLookup;
* @author Hans Muller * @author Hans Muller
*/ */
public class DefaultListCellRenderer extends JLabel public class DefaultListCellRenderer extends JLabel
implements ListCellRenderer, Serializable implements ListCellRenderer<Object>, Serializable
{ {
/** /**
@ -111,7 +111,7 @@ public class DefaultListCellRenderer extends JLabel
} }
public Component getListCellRendererComponent( public Component getListCellRendererComponent(
JList list, JList<?> list,
Object value, Object value,
int index, int index,
boolean isSelected, boolean isSelected,

View file

@ -48,11 +48,13 @@ import javax.swing.event.*;
* has been added to the <code>java.beans</code> package. * has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}. * Please see {@link java.beans.XMLEncoder}.
* *
* @param <E> the type of the elements of this model
*
* @author Hans Muller * @author Hans Muller
*/ */
public class DefaultListModel extends AbstractListModel public class DefaultListModel<E> extends AbstractListModel<E>
{ {
private Vector delegate = new Vector(); private Vector<E> delegate = new Vector<E>();
/** /**
* Returns the number of components in this list. * Returns the number of components in this list.
@ -83,7 +85,7 @@ public class DefaultListModel extends AbstractListModel
* list * list
* @see #get(int) * @see #get(int)
*/ */
public Object getElementAt(int index) { public E getElementAt(int index) {
return delegate.elementAt(index); return delegate.elementAt(index);
} }
@ -175,7 +177,7 @@ public class DefaultListModel extends AbstractListModel
* @return an enumeration of the components of this list * @return an enumeration of the components of this list
* @see Vector#elements() * @see Vector#elements()
*/ */
public Enumeration<?> elements() { public Enumeration<E> elements() {
return delegate.elements(); return delegate.elements();
} }
@ -260,7 +262,7 @@ public class DefaultListModel extends AbstractListModel
* @see #get(int) * @see #get(int)
* @see Vector#elementAt(int) * @see Vector#elementAt(int)
*/ */
public Object elementAt(int index) { public E elementAt(int index) {
return delegate.elementAt(index); return delegate.elementAt(index);
} }
@ -271,7 +273,7 @@ public class DefaultListModel extends AbstractListModel
* @return the first component of this list * @return the first component of this list
* @see Vector#firstElement() * @see Vector#firstElement()
*/ */
public Object firstElement() { public E firstElement() {
return delegate.firstElement(); return delegate.firstElement();
} }
@ -283,13 +285,13 @@ public class DefaultListModel extends AbstractListModel
* @return the last component of the list * @return the last component of the list
* @see Vector#lastElement() * @see Vector#lastElement()
*/ */
public Object lastElement() { public E lastElement() {
return delegate.lastElement(); return delegate.lastElement();
} }
/** /**
* Sets the component at the specified <code>index</code> of this * Sets the component at the specified <code>index</code> of this
* list to be the specified object. The previous component at that * list to be the specified element. The previous component at that
* position is discarded. * position is discarded.
* <p> * <p>
* Throws an <code>ArrayIndexOutOfBoundsException</code> if the index * Throws an <code>ArrayIndexOutOfBoundsException</code> if the index
@ -300,13 +302,13 @@ public class DefaultListModel extends AbstractListModel
* <code>List</code> interface defined in the 1.2 Collections framework. * <code>List</code> interface defined in the 1.2 Collections framework.
* </blockquote> * </blockquote>
* *
* @param obj what the component is to be set to * @param element what the component is to be set to
* @param index the specified index * @param index the specified index
* @see #set(int,Object) * @see #set(int,Object)
* @see Vector#setElementAt(Object,int) * @see Vector#setElementAt(Object,int)
*/ */
public void setElementAt(Object obj, int index) { public void setElementAt(E element, int index) {
delegate.setElementAt(obj, index); delegate.setElementAt(element, index);
fireContentsChanged(this, index, index); fireContentsChanged(this, index, index);
} }
@ -331,7 +333,7 @@ public class DefaultListModel extends AbstractListModel
} }
/** /**
* Inserts the specified object as a component in this list at the * Inserts the specified element as a component in this list at the
* specified <code>index</code>. * specified <code>index</code>.
* <p> * <p>
* Throws an <code>ArrayIndexOutOfBoundsException</code> if the index * Throws an <code>ArrayIndexOutOfBoundsException</code> if the index
@ -342,26 +344,26 @@ public class DefaultListModel extends AbstractListModel
* <code>List</code> interface defined in the 1.2 Collections framework. * <code>List</code> interface defined in the 1.2 Collections framework.
* </blockquote> * </blockquote>
* *
* @param obj the component to insert * @param element the component to insert
* @param index where to insert the new component * @param index where to insert the new component
* @exception ArrayIndexOutOfBoundsException if the index was invalid * @exception ArrayIndexOutOfBoundsException if the index was invalid
* @see #add(int,Object) * @see #add(int,Object)
* @see Vector#insertElementAt(Object,int) * @see Vector#insertElementAt(Object,int)
*/ */
public void insertElementAt(Object obj, int index) { public void insertElementAt(E element, int index) {
delegate.insertElementAt(obj, index); delegate.insertElementAt(element, index);
fireIntervalAdded(this, index, index); fireIntervalAdded(this, index, index);
} }
/** /**
* Adds the specified component to the end of this list. * Adds the specified component to the end of this list.
* *
* @param obj the component to be added * @param element the component to be added
* @see Vector#addElement(Object) * @see Vector#addElement(Object)
*/ */
public void addElement(Object obj) { public void addElement(E element) {
int index = delegate.size(); int index = delegate.size();
delegate.addElement(obj); delegate.addElement(element);
fireIntervalAdded(this, index, index); fireIntervalAdded(this, index, index);
} }
@ -441,7 +443,7 @@ public class DefaultListModel extends AbstractListModel
* *
* @param index index of element to return * @param index index of element to return
*/ */
public Object get(int index) { public E get(int index) {
return delegate.elementAt(index); return delegate.elementAt(index);
} }
@ -457,8 +459,8 @@ public class DefaultListModel extends AbstractListModel
* @param element element to be stored at the specified position * @param element element to be stored at the specified position
* @return the element previously at the specified position * @return the element previously at the specified position
*/ */
public Object set(int index, Object element) { public E set(int index, E element) {
Object rv = delegate.elementAt(index); E rv = delegate.elementAt(index);
delegate.setElementAt(element, index); delegate.setElementAt(element, index);
fireContentsChanged(this, index, index); fireContentsChanged(this, index, index);
return rv; return rv;
@ -474,7 +476,7 @@ public class DefaultListModel extends AbstractListModel
* @param index index at which the specified element is to be inserted * @param index index at which the specified element is to be inserted
* @param element element to be inserted * @param element element to be inserted
*/ */
public void add(int index, Object element) { public void add(int index, E element) {
delegate.insertElementAt(element, index); delegate.insertElementAt(element, index);
fireIntervalAdded(this, index, index); fireIntervalAdded(this, index, index);
} }
@ -488,9 +490,10 @@ public class DefaultListModel extends AbstractListModel
* (<code>index &lt; 0 || index &gt;= size()</code>). * (<code>index &lt; 0 || index &gt;= size()</code>).
* *
* @param index the index of the element to removed * @param index the index of the element to removed
* @return the element previously at the specified position
*/ */
public Object remove(int index) { public E remove(int index) {
Object rv = delegate.elementAt(index); E rv = delegate.elementAt(index);
delegate.removeElementAt(index); delegate.removeElementAt(index);
fireIntervalRemoved(this, index, index); fireIntervalRemoved(this, index, index);
return rv; return rv;

View file

@ -25,11 +25,24 @@
package javax.swing; package javax.swing;
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.*; import java.awt.event.*;
import java.awt.*;
import java.util.Vector; import java.util.Vector;
import java.util.Locale; import java.util.Locale;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
@ -59,28 +72,30 @@ import static sun.swing.SwingUtilities2.Section.*;
* constructor that automatically builds a read-only {@code ListModel} instance * constructor that automatically builds a read-only {@code ListModel} instance
* for you: * for you:
* <pre> * <pre>
* {@code
* // Create a JList that displays strings from an array * // Create a JList that displays strings from an array
* *
* String[] data = {"one", "two", "three", "four"}; * String[] data = {"one", "two", "three", "four"};
* JList myList = new JList(data); * JList<String> myList = new JList<String>(data);
* *
* // Create a JList that displays the superclasses of JList.class, by * // Create a JList that displays the superclasses of JList.class, by
* // creating it with a Vector populated with this data * // creating it with a Vector populated with this data
* *
* Vector superClasses = new Vector(); * Vector<Class<?>> superClasses = new Vector<Class<?>>();
* Class rootClass = javax.swing.JList.class; * Class<JList> rootClass = javax.swing.JList.class;
* for(Class cls = rootClass; cls != null; cls = cls.getSuperclass()) { * for(Class<?> cls = rootClass; cls != null; cls = cls.getSuperclass()) {
* superClasses.addElement(cls); * superClasses.addElement(cls);
* } * }
* JList myList = new JList(superClasses); * JList<Class<?>> myList = new JList<Class<?>>(superClasses);
* *
* // The automatically created model is stored in JList's "model" * // The automatically created model is stored in JList's "model"
* // property, which you can retrieve * // property, which you can retrieve
* *
* ListModel model = myList.getModel(); * ListModel<Class<?>> model = myList.getModel();
* for(int i = 0; i < model.getSize(); i++) { * for(int i = 0; i < model.getSize(); i++) {
* System.out.println(model.getElementAt(i)); * System.out.println(model.getElementAt(i));
* } * }
* }
* </pre> * </pre>
* <p> * <p>
* A {@code ListModel} can be supplied directly to a {@code JList} by way of a * A {@code ListModel} can be supplied directly to a {@code JList} by way of a
@ -103,12 +118,14 @@ import static sun.swing.SwingUtilities2.Section.*;
* notifying listeners. For example, a read-only implementation of * notifying listeners. For example, a read-only implementation of
* {@code AbstractListModel}: * {@code AbstractListModel}:
* <pre> * <pre>
* {@code
* // This list model has about 2^16 elements. Enjoy scrolling. * // This list model has about 2^16 elements. Enjoy scrolling.
* *
* ListModel bigData = new AbstractListModel() { * ListModel<String> bigData = new AbstractListModel<String>() {
* public int getSize() { return Short.MAX_VALUE; } * public int getSize() { return Short.MAX_VALUE; }
* public Object getElementAt(int index) { return "Index " + index; } * public String getElementAt(int index) { return "Index " + index; }
* }; * };
* }
* </pre> * </pre>
* <p> * <p>
* The selection state of a {@code JList} is managed by another separate * The selection state of a {@code JList} is managed by another separate
@ -150,9 +167,10 @@ import static sun.swing.SwingUtilities2.Section.*;
* component to render, is installed by the lists's {@code ListUI}. You can * component to render, is installed by the lists's {@code ListUI}. You can
* substitute your own renderer using code like this: * substitute your own renderer using code like this:
* <pre> * <pre>
* {@code
* // Display an icon and a string for each object in the list. * // Display an icon and a string for each object in the list.
* *
* class MyCellRenderer extends JLabel implements ListCellRenderer { * class MyCellRenderer extends JLabel implements ListCellRenderer<Object> {
* final static ImageIcon longIcon = new ImageIcon("long.gif"); * final static ImageIcon longIcon = new ImageIcon("long.gif");
* final static ImageIcon shortIcon = new ImageIcon("short.gif"); * final static ImageIcon shortIcon = new ImageIcon("short.gif");
* *
@ -160,7 +178,7 @@ import static sun.swing.SwingUtilities2.Section.*;
* // We just reconfigure the JLabel each time we're called. * // We just reconfigure the JLabel each time we're called.
* *
* public Component getListCellRendererComponent( * public Component getListCellRendererComponent(
* JList list, // the list * JList<?> list, // the list
* Object value, // value to display * Object value, // value to display
* int index, // cell index * int index, // cell index
* boolean isSelected, // is the cell selected * boolean isSelected, // is the cell selected
@ -184,6 +202,7 @@ import static sun.swing.SwingUtilities2.Section.*;
* } * }
* *
* myList.setCellRenderer(new MyCellRenderer()); * myList.setCellRenderer(new MyCellRenderer());
* }
* </pre> * </pre>
* <p> * <p>
* Another job for the cell renderer is in helping to determine sizing * Another job for the cell renderer is in helping to determine sizing
@ -195,7 +214,8 @@ import static sun.swing.SwingUtilities2.Section.*;
* automatically based on a single prototype value: * automatically based on a single prototype value:
* <a name="prototype_example"> * <a name="prototype_example">
* <pre> * <pre>
* JList bigDataList = new JList(bigData); * {@code
* JList<String> bigDataList = new JList<String>(bigData);
* *
* // We don't want the JList implementation to compute the width * // We don't want the JList implementation to compute the width
* // or height of all of the list cells, so we give it a string * // or height of all of the list cells, so we give it a string
@ -204,6 +224,7 @@ import static sun.swing.SwingUtilities2.Section.*;
* // properties. * // properties.
* *
* bigDataList.setPrototypeCellValue("Index 1234567890"); * bigDataList.setPrototypeCellValue("Index 1234567890");
* }
* </pre> * </pre>
* <p> * <p>
* {@code JList} doesn't implement scrolling directly. To create a list that * {@code JList} doesn't implement scrolling directly. To create a list that
@ -260,13 +281,15 @@ import static sun.swing.SwingUtilities2.Section.*;
* @see ListCellRenderer * @see ListCellRenderer
* @see DefaultListCellRenderer * @see DefaultListCellRenderer
* *
* @param <E> the type of the elements of this list
*
* @beaninfo * @beaninfo
* attribute: isContainer false * attribute: isContainer false
* description: A component which allows for the selection of one or more objects from a list. * description: A component which allows for the selection of one or more objects from a list.
* *
* @author Hans Muller * @author Hans Muller
*/ */
public class JList extends JComponent implements Scrollable, Accessible public class JList<E> extends JComponent implements Scrollable, Accessible
{ {
/** /**
* @see #getUIClassID * @see #getUIClassID
@ -301,15 +324,15 @@ public class JList extends JComponent implements Scrollable, Accessible
private int fixedCellWidth = -1; private int fixedCellWidth = -1;
private int fixedCellHeight = -1; private int fixedCellHeight = -1;
private int horizontalScrollIncrement = -1; private int horizontalScrollIncrement = -1;
private Object prototypeCellValue; private E prototypeCellValue;
private int visibleRowCount = 8; private int visibleRowCount = 8;
private Color selectionForeground; private Color selectionForeground;
private Color selectionBackground; private Color selectionBackground;
private boolean dragEnabled; private boolean dragEnabled;
private ListSelectionModel selectionModel; private ListSelectionModel selectionModel;
private ListModel dataModel; private ListModel<E> dataModel;
private ListCellRenderer cellRenderer; private ListCellRenderer<? super E> cellRenderer;
private ListSelectionListener selectionListener; private ListSelectionListener selectionListener;
/** /**
@ -402,7 +425,7 @@ public class JList extends JComponent implements Scrollable, Accessible
* @param dataModel the model for the list * @param dataModel the model for the list
* @exception IllegalArgumentException if the model is {@code null} * @exception IllegalArgumentException if the model is {@code null}
*/ */
public JList(ListModel dataModel) public JList(ListModel<E> dataModel)
{ {
if (dataModel == null) { if (dataModel == null) {
throw new IllegalArgumentException("dataModel must be non null"); throw new IllegalArgumentException("dataModel must be non null");
@ -437,12 +460,12 @@ public class JList extends JComponent implements Scrollable, Accessible
* @param listData the array of Objects to be loaded into the data model, * @param listData the array of Objects to be loaded into the data model,
* {@code non-null} * {@code non-null}
*/ */
public JList(final Object[] listData) public JList(final E[] listData)
{ {
this ( this (
new AbstractListModel() { new AbstractListModel<E>() {
public int getSize() { return listData.length; } public int getSize() { return listData.length; }
public Object getElementAt(int i) { return listData[i]; } public E getElementAt(int i) { return listData[i]; }
} }
); );
} }
@ -462,11 +485,11 @@ public class JList extends JComponent implements Scrollable, Accessible
* @param listData the <code>Vector</code> to be loaded into the * @param listData the <code>Vector</code> to be loaded into the
* data model, {@code non-null} * data model, {@code non-null}
*/ */
public JList(final Vector<?> listData) { public JList(final Vector<? extends E> listData) {
this ( this (
new AbstractListModel() { new AbstractListModel<E>() {
public int getSize() { return listData.size(); } public int getSize() { return listData.size(); }
public Object getElementAt(int i) { return listData.elementAt(i); } public E getElementAt(int i) { return listData.elementAt(i); }
} }
); );
} }
@ -477,9 +500,9 @@ public class JList extends JComponent implements Scrollable, Accessible
*/ */
public JList() { public JList() {
this ( this (
new AbstractListModel() { new AbstractListModel<E>() {
public int getSize() { return 0; } public int getSize() { return 0; }
public Object getElementAt(int i) { return "No Data Model"; } public E getElementAt(int i) { throw new IndexOutOfBoundsException("No Data Model"); }
} }
); );
} }
@ -526,7 +549,7 @@ public class JList extends JComponent implements Scrollable, Accessible
public void updateUI() { public void updateUI() {
setUI((ListUI)UIManager.getUI(this)); setUI((ListUI)UIManager.getUI(this));
ListCellRenderer renderer = getCellRenderer(); ListCellRenderer<? super E> renderer = getCellRenderer();
if (renderer instanceof Component) { if (renderer instanceof Component) {
SwingUtilities.updateComponentTreeUI((Component)renderer); SwingUtilities.updateComponentTreeUI((Component)renderer);
} }
@ -560,8 +583,8 @@ public class JList extends JComponent implements Scrollable, Accessible
*/ */
private void updateFixedCellSize() private void updateFixedCellSize()
{ {
ListCellRenderer cr = getCellRenderer(); ListCellRenderer<? super E> cr = getCellRenderer();
Object value = getPrototypeCellValue(); E value = getPrototypeCellValue();
if ((cr != null) && (value != null)) { if ((cr != null) && (value != null)) {
Component c = cr.getListCellRendererComponent(this, value, 0, false, false); Component c = cr.getListCellRendererComponent(this, value, 0, false, false);
@ -592,7 +615,7 @@ public class JList extends JComponent implements Scrollable, Accessible
* @return the value of the {@code prototypeCellValue} property * @return the value of the {@code prototypeCellValue} property
* @see #setPrototypeCellValue * @see #setPrototypeCellValue
*/ */
public Object getPrototypeCellValue() { public E getPrototypeCellValue() {
return prototypeCellValue; return prototypeCellValue;
} }
@ -632,8 +655,8 @@ public class JList extends JComponent implements Scrollable, Accessible
* attribute: visualUpdate true * attribute: visualUpdate true
* description: The cell prototype value, used to compute cell width and height. * description: The cell prototype value, used to compute cell width and height.
*/ */
public void setPrototypeCellValue(Object prototypeCellValue) { public void setPrototypeCellValue(E prototypeCellValue) {
Object oldValue = this.prototypeCellValue; E oldValue = this.prototypeCellValue;
this.prototypeCellValue = prototypeCellValue; this.prototypeCellValue = prototypeCellValue;
/* If the prototypeCellValue has changed and is non-null, /* If the prototypeCellValue has changed and is non-null,
@ -727,7 +750,7 @@ public class JList extends JComponent implements Scrollable, Accessible
* @see #setCellRenderer * @see #setCellRenderer
*/ */
@Transient @Transient
public ListCellRenderer getCellRenderer() { public ListCellRenderer<? super E> getCellRenderer() {
return cellRenderer; return cellRenderer;
} }
@ -755,8 +778,8 @@ public class JList extends JComponent implements Scrollable, Accessible
* attribute: visualUpdate true * attribute: visualUpdate true
* description: The component used to draw the cells. * description: The component used to draw the cells.
*/ */
public void setCellRenderer(ListCellRenderer cellRenderer) { public void setCellRenderer(ListCellRenderer<? super E> cellRenderer) {
ListCellRenderer oldValue = this.cellRenderer; ListCellRenderer<? super E> oldValue = this.cellRenderer;
this.cellRenderer = cellRenderer; this.cellRenderer = cellRenderer;
/* If the cellRenderer has changed and prototypeCellValue /* If the cellRenderer has changed and prototypeCellValue
@ -1455,7 +1478,7 @@ public class JList extends JComponent implements Scrollable, Accessible
* @since 1.4 * @since 1.4
*/ */
public int getNextMatch(String prefix, int startIndex, Position.Bias bias) { public int getNextMatch(String prefix, int startIndex, Position.Bias bias) {
ListModel model = getModel(); ListModel<E> model = getModel();
int max = model.getSize(); int max = model.getSize();
if (prefix == null) { if (prefix == null) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
@ -1469,16 +1492,16 @@ public class JList extends JComponent implements Scrollable, Accessible
int increment = (bias == Position.Bias.Forward) ? 1 : -1; int increment = (bias == Position.Bias.Forward) ? 1 : -1;
int index = startIndex; int index = startIndex;
do { do {
Object o = model.getElementAt(index); E element = model.getElementAt(index);
if (o != null) { if (element != null) {
String string; String string;
if (o instanceof String) { if (element instanceof String) {
string = ((String)o).toUpperCase(); string = ((String)element).toUpperCase();
} }
else { else {
string = o.toString(); string = element.toString();
if (string != null) { if (string != null) {
string = string.toUpperCase(); string = string.toUpperCase();
} }
@ -1516,7 +1539,7 @@ public class JList extends JComponent implements Scrollable, Accessible
if(event != null) { if(event != null) {
Point p = event.getPoint(); Point p = event.getPoint();
int index = locationToIndex(p); int index = locationToIndex(p);
ListCellRenderer r = getCellRenderer(); ListCellRenderer<? super E> r = getCellRenderer();
Rectangle cellBounds; Rectangle cellBounds;
if (index != -1 && r != null && (cellBounds = if (index != -1 && r != null && (cellBounds =
@ -1634,7 +1657,7 @@ public class JList extends JComponent implements Scrollable, Accessible
* list of items * list of items
* @see #setModel * @see #setModel
*/ */
public ListModel getModel() { public ListModel<E> getModel() {
return dataModel; return dataModel;
} }
@ -1656,11 +1679,11 @@ public class JList extends JComponent implements Scrollable, Accessible
* attribute: visualUpdate true * attribute: visualUpdate true
* description: The object that contains the data to be drawn by this JList. * description: The object that contains the data to be drawn by this JList.
*/ */
public void setModel(ListModel model) { public void setModel(ListModel<E> model) {
if (model == null) { if (model == null) {
throw new IllegalArgumentException("model must be non null"); throw new IllegalArgumentException("model must be non null");
} }
ListModel oldValue = dataModel; ListModel<E> oldValue = dataModel;
dataModel = model; dataModel = model;
firePropertyChange("model", oldValue, dataModel); firePropertyChange("model", oldValue, dataModel);
clearSelection(); clearSelection();
@ -1668,7 +1691,7 @@ public class JList extends JComponent implements Scrollable, Accessible
/** /**
* Constructs a read-only <code>ListModel</code> from an array of objects, * Constructs a read-only <code>ListModel</code> from an array of items,
* and calls {@code setModel} with this model. * and calls {@code setModel} with this model.
* <p> * <p>
* Attempts to pass a {@code null} value to this method results in * Attempts to pass a {@code null} value to this method results in
@ -1676,15 +1699,15 @@ public class JList extends JComponent implements Scrollable, Accessible
* references the given array directly. Attempts to modify the array * references the given array directly. Attempts to modify the array
* after invoking this method results in undefined behavior. * after invoking this method results in undefined behavior.
* *
* @param listData an array of {@code Objects} containing the items to * @param listData an array of {@code E} containing the items to
* display in the list * display in the list
* @see #setModel * @see #setModel
*/ */
public void setListData(final Object[] listData) { public void setListData(final E[] listData) {
setModel ( setModel (
new AbstractListModel() { new AbstractListModel<E>() {
public int getSize() { return listData.length; } public int getSize() { return listData.length; }
public Object getElementAt(int i) { return listData[i]; } public E getElementAt(int i) { return listData[i]; }
} }
); );
} }
@ -1703,11 +1726,11 @@ public class JList extends JComponent implements Scrollable, Accessible
* display in the list * display in the list
* @see #setModel * @see #setModel
*/ */
public void setListData(final Vector<?> listData) { public void setListData(final Vector<? extends E> listData) {
setModel ( setModel (
new AbstractListModel() { new AbstractListModel<E>() {
public int getSize() { return listData.size(); } public int getSize() { return listData.size(); }
public Object getElementAt(int i) { return listData.elementAt(i); } public E getElementAt(int i) { return listData.elementAt(i); }
} }
); );
} }
@ -2235,10 +2258,13 @@ public class JList extends JComponent implements Scrollable, Accessible
* @see #isSelectedIndex * @see #isSelectedIndex
* @see #getModel * @see #getModel
* @see #addListSelectionListener * @see #addListSelectionListener
*
* @deprecated As of JDK 1.7, replaced by {@link #getSelectedValuesList()}
*/ */
@Deprecated
public Object[] getSelectedValues() { public Object[] getSelectedValues() {
ListSelectionModel sm = getSelectionModel(); ListSelectionModel sm = getSelectionModel();
ListModel dm = getModel(); ListModel<E> dm = getModel();
int iMin = sm.getMinSelectionIndex(); int iMin = sm.getMinSelectionIndex();
int iMax = sm.getMaxSelectionIndex(); int iMax = sm.getMaxSelectionIndex();
@ -2259,6 +2285,37 @@ public class JList extends JComponent implements Scrollable, Accessible
return rv; return rv;
} }
/**
* Returns a list of all the selected items, in increasing order based
* on their indices in the list.
*
* @return the selected items, or an empty list if nothing is selected
* @see #isSelectedIndex
* @see #getModel
* @see #addListSelectionListener
*
* @since 1.7
*/
public List<E> getSelectedValuesList() {
ListSelectionModel sm = getSelectionModel();
ListModel<E> dm = getModel();
int iMin = sm.getMinSelectionIndex();
int iMax = sm.getMaxSelectionIndex();
if ((iMin < 0) || (iMax < 0)) {
return Collections.emptyList();
}
List<E> selectedItems = new ArrayList<E>();
for(int i = iMin; i <= iMax; i++) {
if (sm.isSelectedIndex(i)) {
selectedItems.add(dm.getElementAt(i));
}
}
return selectedItems;
}
/** /**
* Returns the smallest selected cell index; <i>the selection</i> when only * Returns the smallest selected cell index; <i>the selection</i> when only
@ -2291,7 +2348,7 @@ public class JList extends JComponent implements Scrollable, Accessible
* @see #getModel * @see #getModel
* @see #addListSelectionListener * @see #addListSelectionListener
*/ */
public Object getSelectedValue() { public E getSelectedValue() {
int i = getMinSelectionIndex(); int i = getMinSelectionIndex();
return (i == -1) ? null : getModel().getElementAt(i); return (i == -1) ? null : getModel().getElementAt(i);
} }
@ -2309,7 +2366,7 @@ public class JList extends JComponent implements Scrollable, Accessible
setSelectedIndex(-1); setSelectedIndex(-1);
else if(!anObject.equals(getSelectedValue())) { else if(!anObject.equals(getSelectedValue())) {
int i,c; int i,c;
ListModel dm = getModel(); ListModel<E> dm = getModel();
for(i=0,c=dm.getSize();i<c;i++) for(i=0,c=dm.getSize();i<c;i++)
if(anObject.equals(dm.getElementAt(i))){ if(anObject.equals(dm.getElementAt(i))){
setSelectedIndex(i); setSelectedIndex(i);
@ -3138,14 +3195,14 @@ public class JList extends JComponent implements Scrollable, Accessible
*/ */
protected class AccessibleJListChild extends AccessibleContext protected class AccessibleJListChild extends AccessibleContext
implements Accessible, AccessibleComponent { implements Accessible, AccessibleComponent {
private JList parent = null; private JList<E> parent = null;
private int indexInParent; private int indexInParent;
private Component component = null; private Component component = null;
private AccessibleContext accessibleContext = null; private AccessibleContext accessibleContext = null;
private ListModel listModel; private ListModel<E> listModel;
private ListCellRenderer cellRenderer = null; private ListCellRenderer<? super E> cellRenderer = null;
public AccessibleJListChild(JList parent, int indexInParent) { public AccessibleJListChild(JList<E> parent, int indexInParent) {
this.parent = parent; this.parent = parent;
this.setAccessibleParent(parent); this.setAccessibleParent(parent);
this.indexInParent = indexInParent; this.indexInParent = indexInParent;
@ -3175,7 +3232,7 @@ public class JList extends JComponent implements Scrollable, Accessible
if ((parent != null) if ((parent != null)
&& (listModel != null) && (listModel != null)
&& cellRenderer != null) { && cellRenderer != null) {
Object value = listModel.getElementAt(index); E value = listModel.getElementAt(index);
boolean isSelected = parent.isSelectedIndex(index); boolean isSelected = parent.isSelectedIndex(index);
boolean isFocussed = parent.isFocusOwner() boolean isFocussed = parent.isFocusOwner()
&& (index == parent.getLeadSelectionIndex()); && (index == parent.getLeadSelectionIndex());

View file

@ -1337,7 +1337,11 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
return (TableCellRenderer)renderer; return (TableCellRenderer)renderer;
} }
else { else {
return getDefaultRenderer(columnClass.getSuperclass()); Class c = columnClass.getSuperclass();
if (c == null && columnClass != Object.class) {
c = Object.class;
}
return getDefaultRenderer(c);
} }
} }
} }

View file

@ -33,12 +33,13 @@ import java.awt.Component;
* the cells in a JList. For example, to use a JLabel as a * the cells in a JList. For example, to use a JLabel as a
* ListCellRenderer, you would write something like this: * ListCellRenderer, you would write something like this:
* <pre> * <pre>
* class MyCellRenderer extends JLabel implements ListCellRenderer { * {@code
* class MyCellRenderer extends JLabel implements ListCellRenderer<Object> {
* public MyCellRenderer() { * public MyCellRenderer() {
* setOpaque(true); * setOpaque(true);
* } * }
* *
* public Component getListCellRendererComponent(JList list, * public Component getListCellRendererComponent(JList<?> list,
* Object value, * Object value,
* int index, * int index,
* boolean isSelected, * boolean isSelected,
@ -75,14 +76,17 @@ import java.awt.Component;
* return this; * return this;
* } * }
* } * }
* }
* </pre> * </pre>
* *
* @param <E> the type of values this renderer can be used for
*
* @see JList * @see JList
* @see DefaultListCellRenderer * @see DefaultListCellRenderer
* *
* @author Hans Muller * @author Hans Muller
*/ */
public interface ListCellRenderer public interface ListCellRenderer<E>
{ {
/** /**
* Return a component that has been configured to display the specified * Return a component that has been configured to display the specified
@ -104,8 +108,8 @@ public interface ListCellRenderer
* @see ListModel * @see ListModel
*/ */
Component getListCellRendererComponent( Component getListCellRendererComponent(
JList list, JList<? extends E> list,
Object value, E value,
int index, int index,
boolean isSelected, boolean isSelected,
boolean cellHasFocus); boolean cellHasFocus);

View file

@ -35,10 +35,12 @@ import javax.swing.event.ListDataListener;
* length of the data model must be reported to all of the * length of the data model must be reported to all of the
* ListDataListeners. * ListDataListeners.
* *
* @param <E> the type of the elements of this model
*
* @author Hans Muller * @author Hans Muller
* @see JList * @see JList
*/ */
public interface ListModel public interface ListModel<E>
{ {
/** /**
* Returns the length of the list. * Returns the length of the list.
@ -51,7 +53,7 @@ public interface ListModel
* @param index the requested index * @param index the requested index
* @return the value at <code>index</code> * @return the value at <code>index</code>
*/ */
Object getElementAt(int index); E getElementAt(int index);
/** /**
* Adds a listener to the list that's notified each time a change * Adds a listener to the list that's notified each time a change

View file

@ -60,13 +60,13 @@ public abstract class ComponentUI {
} }
/** /**
* Configures the specified component appropriate for the look and feel. * Configures the specified component appropriately for the look and feel.
* This method is invoked when the <code>ComponentUI</code> instance is being installed * This method is invoked when the <code>ComponentUI</code> instance is being installed
* as the UI delegate on the specified component. This method should * as the UI delegate on the specified component. This method should
* completely configure the component for the look and feel, * completely configure the component for the look and feel,
* including the following: * including the following:
* <ol> * <ol>
* <li>Install any default property values for color, fonts, borders, * <li>Install default property values for color, fonts, borders,
* icons, opacity, etc. on the component. Whenever possible, * icons, opacity, etc. on the component. Whenever possible,
* property values initialized by the client program should <i>not</i> * property values initialized by the client program should <i>not</i>
* be overridden. * be overridden.
@ -116,7 +116,7 @@ public abstract class ComponentUI {
} }
/** /**
* Paints the specified component appropriate for the look and feel. * Paints the specified component appropriately for the look and feel.
* This method is invoked from the <code>ComponentUI.update</code> method when * This method is invoked from the <code>ComponentUI.update</code> method when
* the specified component is being painted. Subclasses should override * the specified component is being painted. Subclasses should override
* this method and use the specified <code>Graphics</code> object to * this method and use the specified <code>Graphics</code> object to
@ -134,15 +134,15 @@ public abstract class ComponentUI {
} }
/** /**
* Notifies this UI delegate that it's time to paint the specified * Notifies this UI delegate that it is time to paint the specified
* component. This method is invoked by <code>JComponent</code> * component. This method is invoked by <code>JComponent</code>
* when the specified component is being painted. * when the specified component is being painted.
* By default this method will fill the specified component with *
* its background color (if its <code>opaque</code> property is * <p>By default this method fills the specified component with
* <code>true</code>) and then immediately call <code>paint</code>. * its background color if its {@code opaque} property is {@code true},
* In general this method need not be overridden by subclasses; * and then immediately calls {@code paint}. In general this method need
* all look-and-feel rendering code should reside in the <code>paint</code> * not be overridden by subclasses; all look-and-feel rendering code should
* method. * reside in the {@code paint} method.
* *
* @param g the <code>Graphics</code> context in which to paint * @param g the <code>Graphics</code> context in which to paint
* @param c the component being painted; * @param c the component being painted;

View file

@ -24,14 +24,10 @@
*/ */
package javax.swing.plaf.basic; package javax.swing.plaf.basic;
import javax.swing.*; import javax.swing.ComboBoxEditor;
import javax.swing.JTextField;
import javax.swing.border.Border; import javax.swing.border.Border;
import java.awt.Component;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;
import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -73,12 +69,17 @@ public class BasicComboBoxEditor implements ComboBoxEditor,FocusListener {
* @param anObject the displayed value of the editor * @param anObject the displayed value of the editor
*/ */
public void setItem(Object anObject) { public void setItem(Object anObject) {
if ( anObject != null ) { String text;
editor.setText(anObject.toString());
if ( anObject != null ) {
text = anObject.toString();
oldValue = anObject; oldValue = anObject;
} else { } else {
editor.setText(""); text = "";
}
// workaround for 4530952
if (! text.equals(editor.getText())) {
editor.setText(text);
} }
} }

View file

@ -30,7 +30,6 @@ import java.awt.event.*;
import javax.swing.*; import javax.swing.*;
import javax.accessibility.*; import javax.accessibility.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.border.*;
import javax.swing.text.*; import javax.swing.text.*;
import javax.swing.event.*; import javax.swing.event.*;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
@ -189,19 +188,20 @@ public class BasicComboBoxUI extends ComboBoxUI {
/** /**
* Indicates whether or not the combo box button should be square. * Indicates whether or not the combo box button should be square.
* If square, then the width and height are equal, and are both set to * If square, then the width and height are equal, and are both set to
* the height of the combo (minus appropriate insets). * the height of the combo minus appropriate insets.
*
* @since 1.7
*/ */
private boolean squareButton = true; protected boolean squareButton = true;
/** /**
* Optional: if specified, these insets act as padding around the cell * If specified, these insets act as padding around the cell renderer when
* renderer when laying out and painting the "selected" item in the * laying out and painting the "selected" item in the combo box. These
* combo box. BasicComboBoxUI uses a single combo box renderer for rendering * insets add to those specified by the cell renderer.
* both the main combo box item and also all the items in the dropdown *
* for the combo box. padding allows you to specify addition insets in * @since 1.7
* addition to those specified by the cell renderer.
*/ */
private Insets padding; protected Insets padding;
// Used for calculating the default size. // Used for calculating the default size.
private static ListCellRenderer getDefaultListCellRenderer() { private static ListCellRenderer getDefaultListCellRenderer() {
@ -345,7 +345,7 @@ public class BasicComboBoxUI extends ComboBoxUI {
} }
/** /**
* Create and install the listeners for the combo box and its model. * Creates and installs listeners for the combo box and its model.
* This method is called when the UI is installed. * This method is called when the UI is installed.
*/ */
protected void installListeners() { protected void installListeners() {
@ -379,8 +379,8 @@ public class BasicComboBoxUI extends ComboBoxUI {
} }
/** /**
* Uninstalls the default colors, default font, default renderer, and default * Uninstalls the default colors, default font, default renderer,
* editor into the JComboBox. * and default editor from the combo box.
*/ */
protected void uninstallDefaults() { protected void uninstallDefaults() {
LookAndFeel.installColorsAndFont( comboBox, LookAndFeel.installColorsAndFont( comboBox,
@ -391,7 +391,7 @@ public class BasicComboBoxUI extends ComboBoxUI {
} }
/** /**
* Remove the installed listeners from the combo box and its model. * Removes the installed listeners from the combo box and its model.
* The number and types of listeners removed and in this method should be * The number and types of listeners removed and in this method should be
* the same that was added in <code>installListeners</code> * the same that was added in <code>installListeners</code>
*/ */
@ -839,7 +839,7 @@ public class BasicComboBoxUI extends ComboBoxUI {
} }
/** /**
* Creates an button which will be used as the control to show or hide * Creates a button which will be used as the control to show or hide
* the popup portion of the combo box. * the popup portion of the combo box.
* *
* @return a button which represents the popup control * @return a button which represents the popup control
@ -1392,12 +1392,17 @@ public class BasicComboBoxUI extends ComboBoxUI {
} }
/** /**
* This has been refactored out in hopes that it may be investigated and * Returns the size a component would have if used as a cell renderer.
* simplified for the next major release. adding/removing *
* the component to the currentValuePane and changing the font may be * @param comp a {@code Component} to check
* redundant operations. * @return size of the component
* @since 1.7
*/ */
private Dimension getSizeForComponent(Component comp) { protected Dimension getSizeForComponent(Component comp) {
// This has been refactored out in hopes that it may be investigated and
// simplified for the next major release. adding/removing
// the component to the currentValuePane and changing the font may be
// redundant operations.
currentValuePane.add(comp); currentValuePane.add(comp);
comp.setFont(comboBox.getFont()); comp.setFont(comboBox.getFont());
Dimension d = comp.getPreferredSize(); Dimension d = comp.getPreferredSize();

View file

@ -141,11 +141,10 @@ public class BasicLabelUI extends LabelUI implements PropertyChangeListener
} }
/** /**
* Paint the label text in the foreground color, if the label * Paints the label text with the foreground color, if the label is opaque
* is opaque then paint the entire background with the background * then paints the entire background with the background color. The Label
* color. The Label text is drawn by paintEnabledText() or * text is drawn by {@link #paintEnabledText} or {@link #paintDisabledText}.
* paintDisabledText(). The locations of the label parts are computed * The locations of the label parts are computed by {@link #layoutCL}.
* by layoutCL.
* *
* @see #paintEnabledText * @see #paintEnabledText
* @see #paintDisabledText * @see #paintDisabledText

View file

@ -685,7 +685,7 @@ public class BasicListUI extends ListUI
/** /**
* Create and install the listeners for the JList, its model, and its * Creates and installs the listeners for the JList, its model, and its
* selectionModel. This method is called at installUI() time. * selectionModel. This method is called at installUI() time.
* *
* @see #installUI * @see #installUI
@ -728,7 +728,7 @@ public class BasicListUI extends ListUI
/** /**
* Remove the listeners for the JList, its model, and its * Removes the listeners from the JList, its model, and its
* selectionModel. All of the listener fields, are reset to * selectionModel. All of the listener fields, are reset to
* null here. This method is called at uninstallUI() time, * null here. This method is called at uninstallUI() time,
* it should be kept in sync with installListeners. * it should be kept in sync with installListeners.
@ -764,8 +764,8 @@ public class BasicListUI extends ListUI
/** /**
* Initialize JList properties, e.g. font, foreground, and background, * Initializes list properties such as font, foreground, and background,
* and add the CellRendererPane. The font, foreground, and background * and adds the CellRendererPane. The font, foreground, and background
* properties are only set if their current value is either null * properties are only set if their current value is either null
* or a UIResource, other properties are set if the current * or a UIResource, other properties are set if the current
* value is null. * value is null.
@ -820,9 +820,9 @@ public class BasicListUI extends ListUI
/** /**
* Set the JList properties that haven't been explicitly overridden to * Sets the list properties that have not been explicitly overridden to
* null. A property is considered overridden if its current value * {@code null}. A property is considered overridden if its current value
* is not a UIResource. * is not a {@code UIResource}.
* *
* @see #installDefaults * @see #installDefaults
* @see #uninstallUI * @see #uninstallUI

View file

@ -32,7 +32,6 @@ import java.beans.PropertyChangeListener;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*; import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.text.View; import javax.swing.text.View;
@ -54,7 +53,12 @@ public class BasicMenuItemUI extends MenuItemUI
protected Color disabledForeground; protected Color disabledForeground;
protected Color acceleratorForeground; protected Color acceleratorForeground;
protected Color acceleratorSelectionForeground; protected Color acceleratorSelectionForeground;
private String acceleratorDelimiter;
/**
* Accelerator delimiter string, such as {@code '+'} in {@code 'Ctrl+C'}.
* @since 1.7
*/
protected String acceleratorDelimiter;
protected int defaultTextIconGap; protected int defaultTextIconGap;
protected Font acceleratorFont; protected Font acceleratorFont;

View file

@ -93,10 +93,13 @@ public class BasicScrollBarUI
* scrollbar. */ * scrollbar. */
private boolean supportsAbsolutePositioning; private boolean supportsAbsolutePositioning;
/** Hint as to what width (when vertical) or height (when horizontal) /**
* Hint as to what width (when vertical) or height (when horizontal)
* should be. * should be.
*
* @since 1.7
*/ */
private int scrollBarWidth; protected int scrollBarWidth;
private Handler handler; private Handler handler;
@ -117,18 +120,18 @@ public class BasicScrollBarUI
* number. If negative, then an overlap between the button and track will occur, * number. If negative, then an overlap between the button and track will occur,
* which is useful for shaped buttons. * which is useful for shaped buttons.
* *
* TODO This should be made protected in a feature release * @since 1.7
*/ */
private int incrGap; protected int incrGap;
/** /**
* Distance between the decrement button and the track. This may be a negative * Distance between the decrement button and the track. This may be a negative
* number. If negative, then an overlap between the button and track will occur, * number. If negative, then an overlap between the button and track will occur,
* which is useful for shaped buttons. * which is useful for shaped buttons.
* *
* TODO This should be made protected in a feature release * @since 1.7
*/ */
private int decrGap; protected int decrGap;
static void loadActionMap(LazyActionMap map) { static void loadActionMap(LazyActionMap map) {
map.put(new Actions(Actions.POSITIVE_UNIT_INCREMENT)); map.put(new Actions(Actions.POSITIVE_UNIT_INCREMENT));
@ -586,7 +589,7 @@ public class BasicScrollBarUI
/** /**
* Return the smallest acceptable size for the thumb. If the scrollbar * Returns the smallest acceptable size for the thumb. If the scrollbar
* becomes so small that this size isn't available, the thumb will be * becomes so small that this size isn't available, the thumb will be
* hidden. * hidden.
* <p> * <p>
@ -601,7 +604,7 @@ public class BasicScrollBarUI
} }
/** /**
* Return the largest acceptable size for the thumb. To create a fixed * Returns the largest acceptable size for the thumb. To create a fixed
* size thumb one make this method and <code>getMinimumThumbSize</code> * size thumb one make this method and <code>getMinimumThumbSize</code>
* return the same value. * return the same value.
* <p> * <p>

View file

@ -1409,9 +1409,10 @@ public class BasicSliderUI extends SliderUI{
} }
/** /**
* Returns a value give a y position. If yPos is past the track at the top or the * Returns the value at the y position. If {@code yPos} is beyond the
* bottom it will set the value to the min or max of the slider, depending if the * track at the the bottom or the top, this method sets the value to either
* slider is inverted or not. * the minimum or maximum value of the slider, depending on if the slider
* is inverted or not.
*/ */
public int valueForYPosition( int yPos ) { public int valueForYPosition( int yPos ) {
int value; int value;
@ -1440,9 +1441,10 @@ public class BasicSliderUI extends SliderUI{
} }
/** /**
* Returns a value give an x position. If xPos is past the track at the left or the * Returns the value at the x position. If {@code xPos} is beyond the
* right it will set the value to the min or max of the slider, depending if the * track at the left or the right, this method sets the value to either the
* slider is inverted or not. * minimum or maximum value of the slider, depending on if the slider is
* inverted or not.
*/ */
public int valueForXPosition( int xPos ) { public int valueForXPosition( int xPos ) {
int value; int value;

View file

@ -268,7 +268,7 @@ public class BasicSpinnerUI extends SpinnerUI
} }
/** /**
* Create a <code>LayoutManager</code> that manages the <code>editor</code>, * Creates a <code>LayoutManager</code> that manages the <code>editor</code>,
* <code>nextButton</code>, and <code>previousButton</code> * <code>nextButton</code>, and <code>previousButton</code>
* children of the JSpinner. These three children must be * children of the JSpinner. These three children must be
* added with a constraint that identifies their role: * added with a constraint that identifies their role:
@ -286,7 +286,7 @@ public class BasicSpinnerUI extends SpinnerUI
/** /**
* Create a <code>PropertyChangeListener</code> that can be * Creates a <code>PropertyChangeListener</code> that can be
* added to the JSpinner itself. Typically, this listener * added to the JSpinner itself. Typically, this listener
* will call replaceEditor when the "editor" property changes, * will call replaceEditor when the "editor" property changes,
* since it's the <code>SpinnerUI's</code> responsibility to * since it's the <code>SpinnerUI's</code> responsibility to
@ -302,16 +302,13 @@ public class BasicSpinnerUI extends SpinnerUI
/** /**
* Create a component that will replace the spinner models value * Creates a decrement button, i.e. component that replaces the spinner
* with the object returned by <code>spinner.getPreviousValue</code>. * value with the object returned by <code>spinner.getPreviousValue</code>.
* By default the <code>previousButton</code> is a JButton. This * By default the <code>previousButton</code> is a {@code JButton}. If the
* method invokes <code>installPreviousButtonListeners</code> to * decrement button is not needed this method should return {@code null}.
* install the necessary listeners to update the <code>JSpinner</code>'s
* model in response to a user gesture. If a previousButton isn't needed
* (in a subclass) then override this method to return null.
* *
* @return a component that will replace the spinners model with the * @return a component that will replace the spinner's value with the
* next value in the sequence, or null * previous value in the sequence, or {@code null}
* @see #installUI * @see #installUI
* @see #createNextButton * @see #createNextButton
* @see #installPreviousButtonListeners * @see #installPreviousButtonListeners
@ -325,15 +322,13 @@ public class BasicSpinnerUI extends SpinnerUI
/** /**
* Create a component that will replace the spinner models value * Creates an increment button, i.e. component that replaces the spinner
* with the object returned by <code>spinner.getNextValue</code>. * value with the object returned by <code>spinner.getNextValue</code>.
* By default the <code>nextButton</code> is a JButton * By default the <code>nextButton</code> is a {@code JButton}. If the
* who's <code>ActionListener</code> updates it's <code>JSpinner</code> * increment button is not needed this method should return {@code null}.
* ancestors model. If a nextButton isn't needed (in a subclass)
* then override this method to return null.
* *
* @return a component that will replace the spinners model with the * @return a component that will replace the spinner's value with the
* next value in the sequence, or null * next value in the sequence, or {@code null}
* @see #installUI * @see #installUI
* @see #createPreviousButton * @see #createPreviousButton
* @see #installNextButtonListeners * @see #installNextButtonListeners

View file

@ -829,7 +829,7 @@ public class BasicSplitPaneUI extends SplitPaneUI
/** /**
* Returns the default non continuous layout divider, which is an * Returns the default non continuous layout divider, which is an
* instanceof Canvas that fills the background in dark gray. * instance of {@code Canvas} that fills in the background with dark gray.
*/ */
protected Component createDefaultNonContinuousLayoutDivider() { protected Component createDefaultNonContinuousLayoutDivider() {
return new Canvas() { return new Canvas() {
@ -1041,11 +1041,11 @@ public class BasicSplitPaneUI extends SplitPaneUI
/** /**
* Messaged after the JSplitPane the receiver is providing the look * Called when the specified split pane has finished painting
* and feel for paints its children. * its children.
*/ */
public void finishedPaintingChildren(JSplitPane jc, Graphics g) { public void finishedPaintingChildren(JSplitPane sp, Graphics g) {
if(jc == splitPane && getLastDragLocation() != -1 && if(sp == splitPane && getLastDragLocation() != -1 &&
!isContinuousLayout() && !draggingHW) { !isContinuousLayout() && !draggingHW) {
Dimension size = splitPane.getSize(); Dimension size = splitPane.getSize();
@ -1062,7 +1062,7 @@ public class BasicSplitPaneUI extends SplitPaneUI
/** /**
* Messaged to paint the look and feel. * @inheritDoc
*/ */
public void paint(Graphics g, JComponent jc) { public void paint(Graphics g, JComponent jc) {
if (!painted && splitPane.getDividerLocation()<0) { if (!painted && splitPane.getDividerLocation()<0) {

View file

@ -306,7 +306,7 @@ public class BasicTableHeaderUI extends TableHeaderUI {
} }
/** /**
* Initialize JTableHeader properties, e.g. font, foreground, and background. * Initializes JTableHeader properties such as font, foreground, and background.
* The font, foreground, and background properties are only set if their * The font, foreground, and background properties are only set if their
* current value is either null or a UIResource, other properties are set * current value is either null or a UIResource, other properties are set
* if the current value is null. * if the current value is null.
@ -403,9 +403,9 @@ public class BasicTableHeaderUI extends TableHeaderUI {
} }
/** /**
* This method gets called every time the rollover column in the table * This method gets called every time when a rollover column in the table
* header is updated. Every look and feel supporting rollover effect * header is updated. Every look and feel that supports a rollover effect
* in table header should override this method and repaint the header. * in a table header should override this method and repaint the header.
* *
* @param oldColumn the index of the previous rollover column or -1 if the * @param oldColumn the index of the previous rollover column or -1 if the
* mouse was not over a column * mouse was not over a column
@ -736,7 +736,6 @@ public class BasicTableHeaderUI extends TableHeaderUI {
} }
private Dimension createHeaderSize(long width) { private Dimension createHeaderSize(long width) {
TableColumnModel columnModel = header.getColumnModel();
// None of the callers include the intercell spacing, do it here. // None of the callers include the intercell spacing, do it here.
if (width > Integer.MAX_VALUE) { if (width > Integer.MAX_VALUE) {
width = Integer.MAX_VALUE; width = Integer.MAX_VALUE;

View file

@ -37,6 +37,7 @@ import javax.swing.text.*;
import javax.swing.event.*; import javax.swing.event.*;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import javax.swing.plaf.synth.SynthUI;
import sun.swing.DefaultLookup; import sun.swing.DefaultLookup;
import sun.awt.AppContext; import sun.awt.AppContext;
import javax.swing.plaf.basic.DragRecognitionSupport.BeforeDrag; import javax.swing.plaf.basic.DragRecognitionSupport.BeforeDrag;
@ -221,8 +222,7 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
// is ==, which is the case for the windows look and feel. // is ==, which is the case for the windows look and feel.
// Until an appropriate solution is found, the code is being // Until an appropriate solution is found, the code is being
// reverted to what it was before the original fix. // reverted to what it was before the original fix.
if (this instanceof sun.swing.plaf.synth.SynthUI || if (this instanceof SynthUI || (c instanceof JTextArea)) {
(c instanceof JTextArea)) {
return; return;
} }
Color background = c.getBackground(); Color background = c.getBackground();
@ -289,7 +289,7 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
protected abstract String getPropertyPrefix(); protected abstract String getPropertyPrefix();
/** /**
* Initializes component properties, e.g. font, foreground, * Initializes component properties, such as font, foreground,
* background, caret color, selection color, selected text color, * background, caret color, selection color, selected text color,
* disabled text color, and border color. The font, foreground, and * disabled text color, and border color. The font, foreground, and
* background properties are only set if their current value is either null * background properties are only set if their current value is either null
@ -377,9 +377,9 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
} }
/** /**
* Sets the component properties that haven't been explicitly overridden to * Sets the component properties that have not been explicitly overridden
* null. A property is considered overridden if its current value * to {@code null}. A property is considered overridden if its current
* is not a UIResource. * value is not a {@code UIResource}.
* *
* @see #installDefaults * @see #installDefaults
* @see #uninstallUI * @see #uninstallUI
@ -756,18 +756,18 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
* things. * things.
* <ol> * <ol>
* <li> * <li>
* Set the associated component to opaque (can be changed * Sets the associated component to opaque (can be changed
* easily by a subclass or on JTextComponent directly), * easily by a subclass or on JTextComponent directly),
* which is the most common case. This will cause the * which is the most common case. This will cause the
* component's background color to be painted. * component's background color to be painted.
* <li> * <li>
* Install the default caret and highlighter into the * Installs the default caret and highlighter into the
* associated component. * associated component.
* <li> * <li>
* Attach to the editor and model. If there is no * Attaches to the editor and model. If there is no
* model, a default one is created. * model, a default one is created.
* <li> * <li>
* create the view factory and the view hierarchy used * Creates the view factory and the view hierarchy used
* to represent the model. * to represent the model.
* </ol> * </ol>
* *
@ -784,7 +784,7 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
// This is a workaround as these should not override what synth has // This is a workaround as these should not override what synth has
// set them to // set them to
if (!(this instanceof sun.swing.plaf.synth.SynthUI)){ if (! (this instanceof SynthUI)) {
// common case is background painted... this can // common case is background painted... this can
// easily be changed by subclasses or from outside // easily be changed by subclasses or from outside
// of the component. // of the component.
@ -857,9 +857,9 @@ public abstract class BasicTextUI extends TextUI implements ViewFactory {
* To prevent this from happening twice, this method is * To prevent this from happening twice, this method is
* reimplemented to simply paint. * reimplemented to simply paint.
* <p> * <p>
* <em>NOTE:</em> Superclass is also not thread-safe in * <em>NOTE:</em> NOTE: Superclass is also not thread-safe in its
* it's rendering of the background, although that's not * rendering of the background, although that is not an issue with the
* an issue with the default rendering. * default rendering.
*/ */
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
paint(g, c); paint(g, c);

View file

@ -669,7 +669,7 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants
/** /**
* Sets the border of the component to have a rollover border which * Sets the border of the component to have a rollover border which
* was created by <code>createRolloverBorder</code>. * was created by the {@link #createRolloverBorder} method.
* *
* @param c component which will have a rollover border installed * @param c component which will have a rollover border installed
* @see #createRolloverBorder * @see #createRolloverBorder
@ -709,7 +709,7 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants
/** /**
* Sets the border of the component to have a non-rollover border which * Sets the border of the component to have a non-rollover border which
* was created by <code>createNonRolloverBorder</code>. * was created by the {@link #createNonRolloverBorder} method.
* *
* @param c component which will have a non-rollover border installed * @param c component which will have a non-rollover border installed
* @see #createNonRolloverBorder * @see #createNonRolloverBorder

View file

@ -30,16 +30,12 @@ import javax.swing.event.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.datatransfer.*; import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.beans.*; import java.beans.*;
import java.io.*;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.TooManyListenersException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import javax.swing.plaf.ActionMapUIResource;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import javax.swing.plaf.TreeUI; import javax.swing.plaf.TreeUI;
@ -1244,11 +1240,26 @@ public class BasicTreeUI extends TreeUI
drawingCache.clear(); drawingCache.clear();
} }
private boolean isDropLine(JTree.DropLocation loc) { /**
* Tells if a {@code DropLocation} should be indicated by a line between
* nodes. This is meant for {@code javax.swing.DropMode.INSERT} and
* {@code javax.swing.DropMode.ON_OR_INSERT} drop modes.
*
* @param loc a {@code DropLocation}
* @return {@code true} if the drop location should be shown as a line
* @since 1.7
*/
protected boolean isDropLine(JTree.DropLocation loc) {
return loc != null && loc.getPath() != null && loc.getChildIndex() != -1; return loc != null && loc.getPath() != null && loc.getChildIndex() != -1;
} }
private void paintDropLine(Graphics g) { /**
* Paints the drop line.
*
* @param g {@code Graphics} object to draw on
* @since 1.7
*/
protected void paintDropLine(Graphics g) {
JTree.DropLocation loc = tree.getDropLocation(); JTree.DropLocation loc = tree.getDropLocation();
if (!isDropLine(loc)) { if (!isDropLine(loc)) {
return; return;
@ -1262,7 +1273,14 @@ public class BasicTreeUI extends TreeUI
} }
} }
private Rectangle getDropLineRect(JTree.DropLocation loc) { /**
* Returns a ubounding box for the drop line.
*
* @param loc a {@code DropLocation}
* @return bounding box for the drop line
* @since 1.7
*/
protected Rectangle getDropLineRect(JTree.DropLocation loc) {
Rectangle rect; Rectangle rect;
TreePath path = loc.getPath(); TreePath path = loc.getPath();
int index = loc.getChildIndex(); int index = loc.getChildIndex();
@ -1684,7 +1702,7 @@ public class BasicTreeUI extends TreeUI
treeState.setExpandedState(path, true); treeState.setExpandedState(path, true);
} }
} }
updateLeadRow(); updateLeadSelectionRow();
updateSize(); updateSize();
} }
} }
@ -2425,11 +2443,21 @@ public class BasicTreeUI extends TreeUI
return tree.getLeadSelectionPath(); return tree.getLeadSelectionPath();
} }
private void updateLeadRow() { /**
* Updates the lead row of the selection.
* @since 1.7
*/
protected void updateLeadSelectionRow() {
leadRow = getRowForPath(tree, getLeadSelectionPath()); leadRow = getRowForPath(tree, getLeadSelectionPath());
} }
private int getLeadSelectionRow() { /**
* Returns the lead row of the selection.
*
* @return selection lead row
* @since 1.7
*/
protected int getLeadSelectionRow() {
return leadRow; return leadRow;
} }
@ -3345,7 +3373,7 @@ public class BasicTreeUI extends TreeUI
if (changeName == JTree.LEAD_SELECTION_PATH_PROPERTY) { if (changeName == JTree.LEAD_SELECTION_PATH_PROPERTY) {
if (!ignoreLAChange) { if (!ignoreLAChange) {
updateLeadRow(); updateLeadSelectionRow();
repaintPath((TreePath)event.getOldValue()); repaintPath((TreePath)event.getOldValue());
repaintPath((TreePath)event.getNewValue()); repaintPath((TreePath)event.getNewValue());
} }
@ -3763,7 +3791,7 @@ public class BasicTreeUI extends TreeUI
completeEditing(); completeEditing();
if(path != null && tree.isVisible(path)) { if(path != null && tree.isVisible(path)) {
treeState.setExpandedState(path, false); treeState.setExpandedState(path, false);
updateLeadRow(); updateLeadSelectionRow();
updateSize(); updateSize();
} }
} }
@ -3823,7 +3851,7 @@ public class BasicTreeUI extends TreeUI
if(treeState != null && e != null) { if(treeState != null && e != null) {
treeState.treeNodesInserted(e); treeState.treeNodesInserted(e);
updateLeadRow(); updateLeadSelectionRow();
TreePath path = e.getTreePath(); TreePath path = e.getTreePath();
@ -3848,7 +3876,7 @@ public class BasicTreeUI extends TreeUI
if(treeState != null && e != null) { if(treeState != null && e != null) {
treeState.treeNodesRemoved(e); treeState.treeNodesRemoved(e);
updateLeadRow(); updateLeadSelectionRow();
TreePath path = e.getTreePath(); TreePath path = e.getTreePath();
@ -3862,7 +3890,7 @@ public class BasicTreeUI extends TreeUI
if(treeState != null && e != null) { if(treeState != null && e != null) {
treeState.treeStructureChanged(e); treeState.treeStructureChanged(e);
updateLeadRow(); updateLeadSelectionRow();
TreePath pPath = e.getTreePath(); TreePath pPath = e.getTreePath();

View file

@ -34,7 +34,7 @@ import java.awt.Dimension;
/** /**
* The default layout manager for Popup menus and menubars. This * The default layout manager for Popup menus and menubars. This
* class is an extension of BoxLayout which adds the UIResource tag * class is an extension of BoxLayout which adds the UIResource tag
* so that plauggable L&Fs can distinguish it from user-installed * so that pluggable L&Fs can distinguish it from user-installed
* layout managers on menus. * layout managers on menus.
* *
* @author Georges Saab * @author Georges Saab

View file

@ -257,12 +257,40 @@ public class NimbusLookAndFeel extends SynthLookAndFeel {
/** /**
* @inheritDoc * @inheritDoc
* @return true * @return {@code true}
*/ */
@Override public boolean shouldUpdateStyleOnAncestorChanged() { @Override public boolean shouldUpdateStyleOnAncestorChanged() {
return true; return true;
} }
/**
* @inheritDoc
*
* <p>Overridden to return {@code true} when one of the following
* properties change:
* <ul>
* <li>{@code "Nimbus.Overrides"}
* <li>{@code "Nimbus.Overrides.InheritDefaults"}
* <li>{@code "JComponent.sizeVariant"}
* </ul>
*
* @since 1.7
*/
@Override
protected boolean shouldUpdateStyleOnEvent(PropertyChangeEvent ev) {
String eName = ev.getPropertyName();
// Always update when overrides or size variant change
if ("Nimbus.Overrides" == eName ||
"Nimbus.Overrides.InheritDefaults" == eName ||
"JComponent.sizeVariant" == eName) {
return true;
}
return super.shouldUpdateStyleOnEvent(ev);
}
/** /**
* <p>Registers a third party component with the NimbusLookAndFeel.</p> * <p>Registers a third party component with the NimbusLookAndFeel.</p>
* *

View file

@ -88,9 +88,8 @@ encouraged.
<p><strong>Note:</strong> <p><strong>Note:</strong>
Most of the Swing API is <em>not</em> thread safe. Most of the Swing API is <em>not</em> thread safe.
For details, see For details, see
<a <a href="http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html"
href="http://java.sun.com/docs/books/tutorial/uiswing/overview/threads.html" target="_top">Concurrency in Swing</a>,
target="_top">Threads and Swing</a>,
a section in a section in
<em><a href="http://java.sun.com/docs/books/tutorial/" <em><a href="http://java.sun.com/docs/books/tutorial/"
target="_top">The Java Tutorial</a></em>. target="_top">The Java Tutorial</a></em>.

View file

@ -29,7 +29,6 @@ import javax.swing.*;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import javax.swing.border.*; import javax.swing.border.*;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import sun.swing.plaf.synth.SynthUI;
/** /**
* SynthBorder is a border that delegates to a Painter. The Insets * SynthBorder is a border that delegates to a Painter. The Insets

View file

@ -25,40 +25,49 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import java.awt.*;
import java.awt.event.*;
import java.io.Serializable;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*;
import java.beans.*; import java.beans.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicButtonUI; import javax.swing.plaf.basic.BasicButtonUI;
import javax.swing.plaf.basic.BasicHTML; import javax.swing.plaf.basic.BasicHTML;
import javax.swing.text.View; import javax.swing.text.View;
import sun.swing.plaf.synth.SynthUI;
import sun.swing.plaf.synth.DefaultSynthStyle;
/** /**
* Synth's ButtonUI implementation. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JButton}.
* *
* @author Scott Violet * @author Scott Violet
* @since 1.7
*/ */
class SynthButtonUI extends BasicButtonUI implements public class SynthButtonUI extends BasicButtonUI implements
PropertyChangeListener, SynthUI { PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthButtonUI(); return new SynthButtonUI();
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults(AbstractButton b) { protected void installDefaults(AbstractButton b) {
updateStyle(b); updateStyle(b);
LookAndFeel.installProperty(b, "rolloverEnabled", Boolean.TRUE); LookAndFeel.installProperty(b, "rolloverEnabled", Boolean.TRUE);
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners(AbstractButton b) { protected void installListeners(AbstractButton b) {
super.installListeners(b); super.installListeners(b);
b.addPropertyChangeListener(this); b.addPropertyChangeListener(this);
@ -99,11 +108,19 @@ class SynthButtonUI extends BasicButtonUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners(AbstractButton b) { protected void uninstallListeners(AbstractButton b) {
super.uninstallListeners(b); super.uninstallListeners(b);
b.removePropertyChangeListener(this); b.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults(AbstractButton b) { protected void uninstallDefaults(AbstractButton b) {
SynthContext context = getContext(b, ENABLED); SynthContext context = getContext(b, ENABLED);
@ -112,20 +129,20 @@ class SynthButtonUI extends BasicButtonUI implements
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
SynthContext getContext(JComponent c, int state) { SynthContext getContext(JComponent c, int state) {
Region region = getRegion(c); Region region = SynthLookAndFeel.getRegion(c);
return SynthContext.getContext(SynthContext.class, c, region, return SynthContext.getContext(SynthContext.class, c, region,
style, state); style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
/** /**
* Returns the current state of the passed in <code>AbstractButton</code>. * Returns the current state of the passed in <code>AbstractButton</code>.
*/ */
@ -164,6 +181,10 @@ class SynthButtonUI extends BasicButtonUI implements
return state; return state;
} }
/**
* @inheritDoc
*/
@Override
public int getBaseline(JComponent c, int width, int height) { public int getBaseline(JComponent c, int width, int height) {
if (c == null) { if (c == null) {
throw new NullPointerException("Component must be non-null"); throw new NullPointerException("Component must be non-null");
@ -215,6 +236,10 @@ class SynthButtonUI extends BasicButtonUI implements
// Paint Methods // Paint Methods
// ******************************** // ********************************
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -224,6 +249,10 @@ class SynthButtonUI extends BasicButtonUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -231,6 +260,12 @@ class SynthButtonUI extends BasicButtonUI implements
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
AbstractButton b = (AbstractButton)context.getComponent(); AbstractButton b = (AbstractButton)context.getComponent();
@ -253,19 +288,22 @@ class SynthButtonUI extends BasicButtonUI implements
} }
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintButtonBorder(context, g, x, y, w, h); context.getPainter().paintButtonBorder(context, g, x, y, w, h);
} }
/** /**
* Returns the default icon. This should NOT callback * Returns the default icon. This should not callback
* to the JComponent. * to the JComponent.
* *
* @param b AbstractButton the icon is associated with * @param b button the icon is associated with
* @return default icon * @return default icon
*/ */
protected Icon getDefaultIcon(AbstractButton b) { protected Icon getDefaultIcon(AbstractButton b) {
SynthContext context = getContext(b); SynthContext context = getContext(b);
Icon icon = context.getStyle().getIcon(context, getPropertyPrefix() + "icon"); Icon icon = context.getStyle().getIcon(context, getPropertyPrefix() + "icon");
@ -274,7 +312,11 @@ class SynthButtonUI extends BasicButtonUI implements
} }
/** /**
* Returns the Icon to use in painting the button. * Returns the Icon to use for painting the button. The icon is chosen with
* respect to the current state of the button.
*
* @param b button the icon is associated with
* @return an icon
*/ */
protected Icon getIcon(AbstractButton b) { protected Icon getIcon(AbstractButton b) {
Icon icon = b.getIcon(); Icon icon = b.getIcon();
@ -374,7 +416,7 @@ class SynthButtonUI extends BasicButtonUI implements
/** /**
* Returns the amount to shift the text/icon when painting. * Returns the amount to shift the text/icon when painting.
*/ */
protected int getTextShiftOffset(SynthContext state) { private int getTextShiftOffset(SynthContext state) {
AbstractButton button = (AbstractButton)state.getComponent(); AbstractButton button = (AbstractButton)state.getComponent();
ButtonModel model = button.getModel(); ButtonModel model = button.getModel();
@ -389,6 +431,11 @@ class SynthButtonUI extends BasicButtonUI implements
// ******************************** // ********************************
// Layout Methods // Layout Methods
// ******************************** // ********************************
/**
* @inheritDoc
*/
@Override
public Dimension getMinimumSize(JComponent c) { public Dimension getMinimumSize(JComponent c) {
if (c.getComponentCount() > 0 && c.getLayout() != null) { if (c.getComponentCount() > 0 && c.getLayout() != null) {
return null; return null;
@ -406,6 +453,10 @@ class SynthButtonUI extends BasicButtonUI implements
return size; return size;
} }
/**
* @inheritDoc
*/
@Override
public Dimension getPreferredSize(JComponent c) { public Dimension getPreferredSize(JComponent c) {
if (c.getComponentCount() > 0 && c.getLayout() != null) { if (c.getComponentCount() > 0 && c.getLayout() != null) {
return null; return null;
@ -423,6 +474,10 @@ class SynthButtonUI extends BasicButtonUI implements
return size; return size;
} }
/**
* @inheritDoc
*/
@Override
public Dimension getMaximumSize(JComponent c) { public Dimension getMaximumSize(JComponent c) {
if (c.getComponentCount() > 0 && c.getLayout() != null) { if (c.getComponentCount() > 0 && c.getLayout() != null) {
return null; return null;
@ -442,7 +497,8 @@ class SynthButtonUI extends BasicButtonUI implements
} }
/** /**
* Returns the Icon used in calculating the pref/min/max size. * Returns the Icon used in calculating the
* preferred/minimum/maximum size.
*/ */
protected Icon getSizingIcon(AbstractButton b) { protected Icon getSizingIcon(AbstractButton b) {
Icon icon = getEnabledIcon(b, b.getIcon()); Icon icon = getEnabledIcon(b, b.getIcon());
@ -452,6 +508,10 @@ class SynthButtonUI extends BasicButtonUI implements
return icon; return icon;
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((AbstractButton)e.getSource()); updateStyle((AbstractButton)e.getSource());

View file

@ -27,56 +27,50 @@ package javax.swing.plaf.synth;
import java.awt.*; import java.awt.*;
import java.awt.event.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.border.*;
import java.io.Serializable;
/** /**
* Synth's CheckBoxMenuItemUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JCheckBoxMenuItem}.
* *
* @author Leif Samuelsson * @author Leif Samuelsson
* @author Georges Saab * @author Georges Saab
* @author David Karlton * @author David Karlton
* @author Arnaud Weber * @author Arnaud Weber
* @since 1.7
*/ */
class SynthCheckBoxMenuItemUI extends SynthMenuItemUI { public class SynthCheckBoxMenuItemUI extends SynthMenuItemUI {
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthCheckBoxMenuItemUI(); return new SynthCheckBoxMenuItemUI();
} }
/**
* @inheritDoc
*/
@Override
protected String getPropertyPrefix() { protected String getPropertyPrefix() {
return "CheckBoxMenuItem"; return "CheckBoxMenuItem";
} }
public void processMouseEvent(JMenuItem item, MouseEvent e, @Override
MenuElement path[], MenuSelectionManager manager) {
Point p = e.getPoint();
if (p.x >= 0 && p.x < item.getWidth() && p.y >= 0 && p.y < item.getHeight()) {
if (e.getID() == MouseEvent.MOUSE_RELEASED) {
manager.clearSelectedPath();
item.doClick(0);
} else {
manager.setSelectedPath(path);
}
} else if (item.getModel().isArmed()) {
int c = path.length - 1;
MenuElement newPath[] = new MenuElement[c];
for (int i = 0; i < c; i++) {
newPath[i] = path[i];
}
manager.setSelectedPath(newPath);
}
}
void paintBackground(SynthContext context, Graphics g, JComponent c) { void paintBackground(SynthContext context, Graphics g, JComponent c) {
context.getPainter().paintCheckBoxMenuItemBackground(context, g, 0, 0, context.getPainter().paintCheckBoxMenuItemBackground(context, g, 0, 0,
c.getWidth(), c.getHeight()); c.getWidth(), c.getHeight());
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintCheckBoxMenuItemBorder(context, g, x, y, w, h); context.getPainter().paintCheckBoxMenuItemBorder(context, g, x, y, w, h);

View file

@ -25,36 +25,51 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import javax.swing.*; import javax.swing.JComponent;
import java.awt.*; import java.awt.Graphics;
import java.awt.event.*; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.*;
import java.io.Serializable;
/** /**
* Synth's CheckBoxUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JCheckBox}.
* *
* @author Jeff Dinkins * @author Jeff Dinkins
* @since 1.7
*/ */
class SynthCheckBoxUI extends SynthRadioButtonUI { public class SynthCheckBoxUI extends SynthRadioButtonUI {
// ******************************** // ********************************
// Create PLAF // Create PLAF
// ******************************** // ********************************
/**
* Creates a new UI object for the given component.
*
* @param b component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent b) { public static ComponentUI createUI(JComponent b) {
return new SynthCheckBoxUI(); return new SynthCheckBoxUI();
} }
/**
* @inheritDoc
*/
@Override
protected String getPropertyPrefix() { protected String getPropertyPrefix() {
return "CheckBox."; return "CheckBox.";
} }
@Override
void paintBackground(SynthContext context, Graphics g, JComponent c) { void paintBackground(SynthContext context, Graphics g, JComponent c) {
context.getPainter().paintCheckBoxBackground(context, g, 0, 0, context.getPainter().paintCheckBoxBackground(context, g, 0, 0,
c.getWidth(), c.getHeight()); c.getWidth(), c.getHeight());
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintCheckBoxBorder(context, g, x, y, w, h); context.getPainter().paintCheckBoxBorder(context, g, x, y, w, h);

View file

@ -28,34 +28,39 @@ package javax.swing.plaf.synth;
import javax.swing.*; import javax.swing.*;
import javax.swing.colorchooser.*; import javax.swing.colorchooser.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicColorChooserUI; import javax.swing.plaf.basic.BasicColorChooserUI;
import java.util.*;
import java.awt.*; import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.io.Serializable;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's ColorChooserUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JColorChooser}.
* *
* @author Tom Santos * @author Tom Santos
* @author Steve Wilson * @author Steve Wilson
* @since 1.7
*/ */
class SynthColorChooserUI extends BasicColorChooserUI implements public class SynthColorChooserUI extends BasicColorChooserUI implements
PropertyChangeListener, SynthUI { PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthColorChooserUI(); return new SynthColorChooserUI();
} }
/**
* @inheritDoc
*/
@Override
protected AbstractColorChooserPanel[] createDefaultChoosers() { protected AbstractColorChooserPanel[] createDefaultChoosers() {
SynthContext context = getContext(chooser, ENABLED); SynthContext context = getContext(chooser, ENABLED);
AbstractColorChooserPanel[] panels = (AbstractColorChooserPanel[]) AbstractColorChooserPanel[] panels = (AbstractColorChooserPanel[])
@ -68,6 +73,10 @@ class SynthColorChooserUI extends BasicColorChooserUI implements
return panels; return panels;
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults() { protected void installDefaults() {
super.installDefaults(); super.installDefaults();
updateStyle(chooser); updateStyle(chooser);
@ -79,6 +88,10 @@ class SynthColorChooserUI extends BasicColorChooserUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(chooser, ENABLED); SynthContext context = getContext(chooser, ENABLED);
@ -88,16 +101,28 @@ class SynthColorChooserUI extends BasicColorChooserUI implements
super.uninstallDefaults(); super.uninstallDefaults();
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
chooser.addPropertyChangeListener(this); chooser.addPropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
chooser.removePropertyChangeListener(this); chooser.removePropertyChangeListener(this);
super.uninstallListeners(); super.uninstallListeners();
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -107,14 +132,14 @@ class SynthColorChooserUI extends BasicColorChooserUI implements
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -125,6 +150,10 @@ class SynthColorChooserUI extends BasicColorChooserUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -132,14 +161,29 @@ class SynthColorChooserUI extends BasicColorChooserUI implements
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
* This implementation does not perform any actions.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintColorChooserBorder(context, g, x, y,w,h); context.getPainter().paintColorChooserBorder(context, g, x, y,w,h);
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((JColorChooser)e.getSource()); updateStyle((JColorChooser)e.getSource());

View file

@ -27,21 +27,21 @@ package javax.swing.plaf.synth;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.lang.reflect.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.event.*; import javax.swing.event.*;
import javax.swing.plaf.basic.*; import javax.swing.plaf.basic.*;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's ComboBoxUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JComboBox}.
* *
* @author Scott Violet * @author Scott Violet
* @since 1.7
*/ */
class SynthComboBoxUI extends BasicComboBoxUI implements public class SynthComboBoxUI extends BasicComboBoxUI implements
PropertyChangeListener, SynthUI { PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
private boolean useListColors; private boolean useListColors;
@ -93,12 +93,11 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
private boolean forceOpaque = false; private boolean forceOpaque = false;
/** /**
* NOTE: This serves the same purpose as the same field in BasicComboBoxUI. * Creates a new UI object for the given component.
* It is here because I could not give the padding field in *
* BasicComboBoxUI protected access in an update release. * @param c component to create UI object for
* @return the UI object
*/ */
private Insets padding;
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthComboBoxUI(); return new SynthComboBoxUI();
} }
@ -118,21 +117,6 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
@Override @Override
protected void installDefaults() { protected void installDefaults() {
//NOTE: This next line of code was added because, since squareButton in
//BasicComboBoxUI is private, I need to have some way of reading it from UIManager.
//This is an incomplete solution (since it implies that squareButons,
//once set, cannot be reset per state. Probably ok, but not always ok).
//This line of code should be removed at the same time that squareButton
//is made protected in the super class.
super.installDefaults();
//This is here instead of in updateStyle because the value for padding
//needs to remain consistent with the value for padding in
//BasicComboBoxUI. I wouldn't have this value here at all if not
//for the fact that I cannot make "padding" protected in any way
//for an update release. This *should* be fixed in Java 7
padding = UIManager.getInsets("ComboBox.padding");
updateStyle(comboBox); updateStyle(comboBox);
} }
@ -142,6 +126,7 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
style = SynthLookAndFeel.updateStyle(context, this); style = SynthLookAndFeel.updateStyle(context, this);
if (style != oldStyle) { if (style != oldStyle) {
padding = (Insets) style.get(context, "ComboBox.padding");
popupInsets = (Insets)style.get(context, "ComboBox.popupInsets"); popupInsets = (Insets)style.get(context, "ComboBox.popupInsets");
useListColors = style.getBoolean(context, useListColors = style.getBoolean(context,
"ComboBox.rendererUseListColors", true); "ComboBox.rendererUseListColors", true);
@ -149,6 +134,8 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
"ComboBox.buttonWhenNotEditable", false); "ComboBox.buttonWhenNotEditable", false);
pressedWhenPopupVisible = style.getBoolean(context, pressedWhenPopupVisible = style.getBoolean(context,
"ComboBox.pressedWhenPopupVisible", false); "ComboBox.pressedWhenPopupVisible", false);
squareButton = style.getBoolean(context,
"ComboBox.squareButton", true);
if (oldStyle != null) { if (oldStyle != null) {
uninstallKeyboardActions(); uninstallKeyboardActions();
@ -164,6 +151,9 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
} }
} }
/**
* @inheritDoc
*/
@Override @Override
protected void installListeners() { protected void installListeners() {
comboBox.addPropertyChangeListener(this); comboBox.addPropertyChangeListener(this);
@ -172,6 +162,9 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
super.installListeners(); super.installListeners();
} }
/**
* @inheritDoc
*/
@Override @Override
public void uninstallUI(JComponent c) { public void uninstallUI(JComponent c) {
if (popup instanceof SynthComboPopup) { if (popup instanceof SynthComboPopup) {
@ -181,6 +174,9 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
buttonHandler = null; buttonHandler = null;
} }
/**
* @inheritDoc
*/
@Override @Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(comboBox, ENABLED); SynthContext context = getContext(comboBox, ENABLED);
@ -190,6 +186,9 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override @Override
protected void uninstallListeners() { protected void uninstallListeners() {
editorFocusHandler.unregister(); editorFocusHandler.unregister();
@ -200,6 +199,9 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
super.uninstallListeners(); super.uninstallListeners();
} }
/**
* @inheritDoc
*/
@Override @Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
@ -210,10 +212,6 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
// currently we have a broken situation where if a developer // currently we have a broken situation where if a developer
// takes the border from a JComboBox and sets it on a JTextField // takes the border from a JComboBox and sets it on a JTextField
@ -252,6 +250,9 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
} }
} }
/**
* @inheritDoc
*/
@Override @Override
protected ComboPopup createPopup() { protected ComboPopup createPopup() {
SynthComboPopup p = new SynthComboPopup(comboBox); SynthComboPopup p = new SynthComboPopup(comboBox);
@ -259,11 +260,17 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
return p; return p;
} }
/**
* @inheritDoc
*/
@Override @Override
protected ListCellRenderer createRenderer() { protected ListCellRenderer createRenderer() {
return new SynthComboBoxRenderer(); return new SynthComboBoxRenderer();
} }
/**
* @inheritDoc
*/
@Override @Override
protected ComboBoxEditor createEditor() { protected ComboBoxEditor createEditor() {
return new SynthComboBoxEditor(); return new SynthComboBoxEditor();
@ -273,6 +280,9 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
// end UI Initialization // end UI Initialization
//====================== //======================
/**
* @inheritDoc
*/
@Override @Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
@ -280,6 +290,9 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
} }
} }
/**
* @inheritDoc
*/
@Override @Override
protected JButton createArrowButton() { protected JButton createArrowButton() {
SynthArrowButton button = new SynthArrowButton(SwingConstants.SOUTH); SynthArrowButton button = new SynthArrowButton(SwingConstants.SOUTH);
@ -291,6 +304,9 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
//================================= //=================================
// begin ComponentUI Implementation // begin ComponentUI Implementation
/**
* @inheritDoc
*/
@Override @Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -302,6 +318,9 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override @Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -310,6 +329,12 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
hasFocus = comboBox.hasFocus(); hasFocus = comboBox.hasFocus();
if ( !comboBox.isEditable() ) { if ( !comboBox.isEditable() ) {
@ -318,6 +343,9 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
} }
} }
/**
* @inheritDoc
*/
@Override @Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
@ -375,7 +403,7 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
} }
/** /**
* Return the default size of an empty display area of the combo box using * Returns the default size of an empty display area of the combo box using
* the current renderer and font. * the current renderer and font.
* *
* This method was overridden to use SynthComboBoxRenderer instead of * This method was overridden to use SynthComboBoxRenderer instead of
@ -393,23 +421,6 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
return new Dimension(d.width, d.height); return new Dimension(d.width, d.height);
} }
/**
* This has been refactored out in hopes that it may be investigated and
* simplified for the next major release. adding/removing
* the component to the currentValuePane and changing the font may be
* redundant operations.
*
* NOTE: This method was copied in its entirety from BasicComboBoxUI. Might
* want to make it protected in BasicComboBoxUI in Java 7
*/
private Dimension getSizeForComponent(Component comp) {
currentValuePane.add(comp);
comp.setFont(comboBox.getFont());
Dimension d = comp.getPreferredSize();
currentValuePane.remove(comp);
return d;
}
/** /**
* From BasicComboBoxRenderer v 1.18. * From BasicComboBoxRenderer v 1.18.
* *
@ -478,84 +489,16 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
} }
/** private static class SynthComboBoxEditor
* From BasicCombBoxEditor v 1.24. extends BasicComboBoxEditor.UIResource {
*/
private static class SynthComboBoxEditor implements
ComboBoxEditor, UIResource {
protected JTextField editor;
private Object oldValue;
public SynthComboBoxEditor() { @Override public JTextField createEditorComponent() {
editor = new JTextField("",9); JTextField f = new JTextField("", 9);
editor.setName("ComboBox.textField"); f.setName("ComboBox.textField");
} return f;
@Override
public Component getEditorComponent() {
return editor;
}
/**
* Sets the item that should be edited.
*
* @param anObject the displayed value of the editor
*/
@Override
public void setItem(Object anObject) {
String text;
if ( anObject != null ) {
text = anObject.toString();
oldValue = anObject;
} else {
text = "";
}
// workaround for 4530952
if (!text.equals(editor.getText())) {
editor.setText(text);
} }
} }
@Override
public Object getItem() {
Object newValue = editor.getText();
if (oldValue != null && !(oldValue instanceof String)) {
// The original value is not a string. Should return the value in it's
// original type.
if (newValue.equals(oldValue.toString())) {
return oldValue;
} else {
// Must take the value from the editor and get the value and cast it to the new type.
Class<?> cls = oldValue.getClass();
try {
Method method = cls.getMethod("valueOf", new Class[]{String.class});
newValue = method.invoke(oldValue, new Object[] { editor.getText()});
} catch (Exception ex) {
// Fail silently and return the newValue (a String object)
}
}
}
return newValue;
}
@Override
public void selectAll() {
editor.selectAll();
editor.requestFocus();
}
@Override
public void addActionListener(ActionListener l) {
editor.addActionListener(l);
}
@Override
public void removeActionListener(ActionListener l) {
editor.removeActionListener(l);
}
}
/** /**
* Handles all the logic for treating the combo as a button when it is * Handles all the logic for treating the combo as a button when it is
@ -620,7 +563,7 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
//------------------------------------------------------------------ //------------------------------------------------------------------
/** /**
* {@inheritDoc} * @inheritDoc
* *
* Ensures that isPressed() will return true if the combo is pressed, * Ensures that isPressed() will return true if the combo is pressed,
* or the arrowButton is pressed, <em>or</em> if the combo popup is * or the arrowButton is pressed, <em>or</em> if the combo popup is
@ -634,7 +577,7 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
} }
/** /**
* {@inheritDoc} * @inheritDoc
* *
* Ensures that the armed state is in sync with the pressed state * Ensures that the armed state is in sync with the pressed state
* if shouldActLikeButton is true. Without this method, the arrow * if shouldActLikeButton is true. Without this method, the arrow
@ -649,7 +592,7 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
} }
/** /**
* {@inheritDoc} * @inheritDoc
* *
* Ensures that isRollover() will return true if the combo is * Ensures that isRollover() will return true if the combo is
* rolled over, or the arrowButton is rolled over. * rolled over, or the arrowButton is rolled over.
@ -660,7 +603,7 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
} }
/** /**
* {@inheritDoc} * @inheritDoc
* *
* Forwards pressed states to the internal "pressed" field * Forwards pressed states to the internal "pressed" field
*/ */
@ -671,7 +614,7 @@ class SynthComboBoxUI extends BasicComboBoxUI implements
} }
/** /**
* {@inheritDoc} * @inheritDoc
* *
* Forwards rollover states to the internal "over" field * Forwards rollover states to the internal "over" field
*/ */

View file

@ -27,7 +27,6 @@ package javax.swing.plaf.synth;
import sun.swing.DefaultLookup; import sun.swing.DefaultLookup;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import sun.swing.plaf.synth.SynthUI;
/** /**
* SynthDefaultLookup redirects all lookup calls to the SynthContext. * SynthDefaultLookup redirects all lookup calls to the SynthContext.

View file

@ -28,36 +28,44 @@ package javax.swing.plaf.synth;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicDesktopIconUI; import javax.swing.plaf.basic.BasicDesktopIconUI;
import java.beans.*; import java.beans.*;
import java.io.Serializable;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth L&F for a minimized window on a desktop. * Provides the Synth L&F UI delegate for a minimized internal frame on a desktop.
* *
* @author Joshua Outwater * @author Joshua Outwater
* @since 1.7
*/ */
class SynthDesktopIconUI extends BasicDesktopIconUI implements SynthUI, public class SynthDesktopIconUI extends BasicDesktopIconUI
ActionListener, PropertyChangeListener { implements SynthUI, PropertyChangeListener {
private SynthStyle style; private SynthStyle style;
private Handler handler = new Handler();
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthDesktopIconUI(); return new SynthDesktopIconUI();
} }
/**
* @inheritDoc
*/
@Override
protected void installComponents() { protected void installComponents() {
if (UIManager.getBoolean("InternalFrame.useTaskBar")) { if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
iconPane = new JToggleButton(frame.getTitle(), frame.getFrameIcon()) { iconPane = new JToggleButton(frame.getTitle(), frame.getFrameIcon()) {
public String getToolTipText() { @Override public String getToolTipText() {
return getText(); return getText();
} }
public JPopupMenu getComponentPopupMenu() { @Override public JPopupMenu getComponentPopupMenu() {
return frame.getComponentPopupMenu(); return frame.getComponentPopupMenu();
} }
}; };
@ -73,24 +81,37 @@ class SynthDesktopIconUI extends BasicDesktopIconUI implements SynthUI,
desktopIcon.add(iconPane, BorderLayout.CENTER); desktopIcon.add(iconPane, BorderLayout.CENTER);
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
desktopIcon.addPropertyChangeListener(this); desktopIcon.addPropertyChangeListener(this);
if (iconPane instanceof JToggleButton) { if (iconPane instanceof JToggleButton) {
frame.addPropertyChangeListener(this); frame.addPropertyChangeListener(this);
((JToggleButton)iconPane).addActionListener(this); ((JToggleButton)iconPane).addActionListener(handler);
} }
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
if (iconPane instanceof JToggleButton) { if (iconPane instanceof JToggleButton) {
((JToggleButton)iconPane).removeActionListener(handler);
frame.removePropertyChangeListener(this); frame.removePropertyChangeListener(this);
} }
desktopIcon.removePropertyChangeListener(this); desktopIcon.removePropertyChangeListener(this);
super.uninstallListeners(); super.uninstallListeners();
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults() { protected void installDefaults() {
updateStyle(desktopIcon); updateStyle(desktopIcon);
} }
@ -101,6 +122,10 @@ class SynthDesktopIconUI extends BasicDesktopIconUI implements SynthUI,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(desktopIcon, ENABLED); SynthContext context = getContext(desktopIcon, ENABLED);
style.uninstallDefaults(context); style.uninstallDefaults(context);
@ -108,12 +133,16 @@ class SynthDesktopIconUI extends BasicDesktopIconUI implements SynthUI,
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
private SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
Region region = getRegion(c); Region region = SynthLookAndFeel.getRegion(c);
return SynthContext.getContext(SynthContext.class, c, region, return SynthContext.getContext(SynthContext.class, c, region,
style, state); style, state);
} }
@ -122,10 +151,10 @@ class SynthDesktopIconUI extends BasicDesktopIconUI implements SynthUI,
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
Region getRegion(JComponent c) { /**
return SynthLookAndFeel.getRegion(c); * @inheritDoc
} */
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -136,6 +165,10 @@ class SynthDesktopIconUI extends BasicDesktopIconUI implements SynthUI,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -143,33 +176,24 @@ class SynthDesktopIconUI extends BasicDesktopIconUI implements SynthUI,
context.dispose(); context.dispose();
} }
/**
* Paints the specified component. This implementation does nothing.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintDesktopIconBorder(context, g, x, y, w, h); context.getPainter().paintDesktopIconBorder(context, g, x, y, w, h);
} }
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() instanceof JToggleButton) {
// Either iconify the frame or deiconify and activate it.
JToggleButton button = (JToggleButton)evt.getSource();
try {
boolean selected = button.isSelected();
if (!selected && !frame.isIconifiable()) {
button.setSelected(true);
} else {
frame.setIcon(!selected);
if (selected) {
frame.setSelected(true);
}
}
} catch (PropertyVetoException e2) {
}
}
}
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if (evt.getSource() instanceof JInternalFrame.JDesktopIcon) { if (evt.getSource() instanceof JInternalFrame.JDesktopIcon) {
if (SynthLookAndFeel.shouldUpdateStyle(evt)) { if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
@ -191,4 +215,25 @@ class SynthDesktopIconUI extends BasicDesktopIconUI implements SynthUI,
} }
} }
} }
private final class Handler implements ActionListener {
public void actionPerformed(ActionEvent evt) {
if (evt.getSource() instanceof JToggleButton) {
// Either iconify the frame or deiconify and activate it.
JToggleButton button = (JToggleButton)evt.getSource();
try {
boolean selected = button.isSelected();
if (!selected && !frame.isIconifiable()) {
button.setSelected(true);
} else {
frame.setIcon(!selected);
if (selected) {
frame.setSelected(true);
}
}
} catch (PropertyVetoException e2) {
}
}
}
}
} }

View file

@ -29,34 +29,38 @@ import javax.swing.*;
import javax.swing.border.*; import javax.swing.border.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicDesktopPaneUI; import javax.swing.plaf.basic.BasicDesktopPaneUI;
import java.beans.*; import java.beans.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Graphics;
import java.awt.KeyboardFocusManager;
import java.awt.*; import java.awt.*;
import java.util.Vector;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth L&F for a desktop. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JDesktopPane}.
* *
* @author Joshua Outwater * @author Joshua Outwater
* @author Steve Wilson * @author Steve Wilson
* @since 1.7
*/ */
class SynthDesktopPaneUI extends BasicDesktopPaneUI implements public class SynthDesktopPaneUI extends BasicDesktopPaneUI implements
PropertyChangeListener, SynthUI { PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
private TaskBar taskBar; private TaskBar taskBar;
private DesktopManager oldDesktopManager; private DesktopManager oldDesktopManager;
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthDesktopPaneUI(); return new SynthDesktopPaneUI();
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
desktop.addPropertyChangeListener(this); desktop.addPropertyChangeListener(this);
@ -68,6 +72,10 @@ class SynthDesktopPaneUI extends BasicDesktopPaneUI implements
} }
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults() { protected void installDefaults() {
updateStyle(desktop); updateStyle(desktop);
@ -114,6 +122,10 @@ class SynthDesktopPaneUI extends BasicDesktopPaneUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
if (taskBar != null) { if (taskBar != null) {
desktop.removeComponentListener(taskBar); desktop.removeComponentListener(taskBar);
@ -123,6 +135,10 @@ class SynthDesktopPaneUI extends BasicDesktopPaneUI implements
super.uninstallListeners(); super.uninstallListeners();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(desktop, ENABLED); SynthContext context = getContext(desktop, ENABLED);
@ -147,6 +163,10 @@ class SynthDesktopPaneUI extends BasicDesktopPaneUI implements
} }
} }
/**
* @inheritDoc
*/
@Override
protected void installDesktopManager() { protected void installDesktopManager() {
if (UIManager.getBoolean("InternalFrame.useTaskBar")) { if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
desktopManager = oldDesktopManager = desktop.getDesktopManager(); desktopManager = oldDesktopManager = desktop.getDesktopManager();
@ -159,6 +179,10 @@ class SynthDesktopPaneUI extends BasicDesktopPaneUI implements
} }
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDesktopManager() { protected void uninstallDesktopManager() {
if (oldDesktopManager != null && !(oldDesktopManager instanceof UIResource)) { if (oldDesktopManager != null && !(oldDesktopManager instanceof UIResource)) {
desktopManager = desktop.getDesktopManager(); desktopManager = desktop.getDesktopManager();
@ -397,7 +421,10 @@ class SynthDesktopPaneUI extends BasicDesktopPaneUI implements
} }
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -407,14 +434,14 @@ class SynthDesktopPaneUI extends BasicDesktopPaneUI implements
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -425,6 +452,10 @@ class SynthDesktopPaneUI extends BasicDesktopPaneUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -432,14 +463,28 @@ class SynthDesktopPaneUI extends BasicDesktopPaneUI implements
context.dispose(); context.dispose();
} }
/**
* Paints the specified component. This implementation does nothing.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintDesktopPaneBorder(context, g, x, y, w, h); context.getPainter().paintDesktopPaneBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if (SynthLookAndFeel.shouldUpdateStyle(evt)) { if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
updateStyle((JDesktopPane)evt.getSource()); updateStyle((JDesktopPane)evt.getSource());

View file

@ -31,47 +31,52 @@ import javax.swing.text.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicEditorPaneUI; import javax.swing.plaf.basic.BasicEditorPaneUI;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Provides the look and feel for a JEditorPane in the * Provides the Synth L&F UI delegate for
* Synth look and feel. * {@link javax.swing.JEditorPane}.
* *
* @author Shannon Hickey * @author Shannon Hickey
* @since 1.7
*/ */
class SynthEditorPaneUI extends BasicEditorPaneUI implements SynthUI { public class SynthEditorPaneUI extends BasicEditorPaneUI implements SynthUI {
private SynthStyle style; private SynthStyle style;
/* /*
* I would prefer to use UIResource instad of this. * I would prefer to use UIResource instad of this.
* Unfortunately Boolean is a final class * Unfortunately Boolean is a final class
*/ */
private Boolean localTrue = Boolean.TRUE; private Boolean localTrue = Boolean.TRUE;
private Boolean localFalse = Boolean.FALSE;
/** /**
* Creates a UI for the JTextPane. * Creates a new UI object for the given component.
* *
* @param c the JTextPane component * @param c component to create UI object for
* @return the UI * @return the UI object
*/ */
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthEditorPaneUI(); return new SynthEditorPaneUI();
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults() { protected void installDefaults() {
// Installs the text cursor on the component // Installs the text cursor on the component
super.installDefaults(); super.installDefaults();
JComponent c = getComponent(); JComponent c = getComponent();
Object clientProperty = Object clientProperty =
c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES); c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES);
if (clientProperty == null if (clientProperty == null) {
|| clientProperty == localFalse) { c.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, localTrue);
c.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
localTrue);
} }
updateStyle(getComponent()); updateStyle(getComponent());
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(getComponent(), ENABLED); SynthContext context = getContext(getComponent(), ENABLED);
JComponent c = getComponent(); JComponent c = getComponent();
@ -84,7 +89,7 @@ class SynthEditorPaneUI extends BasicEditorPaneUI implements SynthUI {
Object clientProperty = Object clientProperty =
c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES); c.getClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES);
if (clientProperty == localTrue) { if (clientProperty == localTrue) {
getComponent().putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, c.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
Boolean.FALSE); Boolean.FALSE);
} }
super.uninstallDefaults(); super.uninstallDefaults();
@ -100,6 +105,7 @@ class SynthEditorPaneUI extends BasicEditorPaneUI implements SynthUI {
* *
* @param evt the property change event * @param evt the property change event
*/ */
@Override
protected void propertyChange(PropertyChangeEvent evt) { protected void propertyChange(PropertyChangeEvent evt) {
if (SynthLookAndFeel.shouldUpdateStyle(evt)) { if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
updateStyle((JTextComponent)evt.getSource()); updateStyle((JTextComponent)evt.getSource());
@ -124,6 +130,10 @@ class SynthEditorPaneUI extends BasicEditorPaneUI implements SynthUI {
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -137,6 +147,10 @@ class SynthEditorPaneUI extends BasicEditorPaneUI implements SynthUI {
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -146,10 +160,20 @@ class SynthEditorPaneUI extends BasicEditorPaneUI implements SynthUI {
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
super.paint(g, getComponent()); super.paint(g, getComponent());
} }
/**
* @inheritDoc
*/
@Override
protected void paintBackground(Graphics g) { protected void paintBackground(Graphics g) {
// Overriden to do nothing, all our painting is done from update/paint. // Overriden to do nothing, all our painting is done from update/paint.
} }
@ -159,6 +183,10 @@ class SynthEditorPaneUI extends BasicEditorPaneUI implements SynthUI {
c.getWidth(), c.getHeight()); c.getWidth(), c.getHeight());
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintEditorPaneBorder(context, g, x, y, w, h); context.getPainter().paintEditorPaneBorder(context, g, x, y, w, h);

View file

@ -24,16 +24,17 @@
*/ */
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import java.awt.*; import java.awt.Graphics;
import javax.swing.*; import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
/** /**
* Provides the look and feel implementation for * Provides the Synth L&F UI delegate for
* <code>JFormattedTextField</code>. * {@link javax.swing.JFormattedTextField}.
* *
* @since 1.7
*/ */
class SynthFormattedTextFieldUI extends SynthTextFieldUI { public class SynthFormattedTextFieldUI extends SynthTextFieldUI {
/** /**
* Creates a UI for a JFormattedTextField. * Creates a UI for a JFormattedTextField.
* *
@ -51,15 +52,24 @@ class SynthFormattedTextFieldUI extends SynthTextFieldUI {
* *
* @return the name "FormattedTextField" * @return the name "FormattedTextField"
*/ */
@Override
protected String getPropertyPrefix() { protected String getPropertyPrefix() {
return "FormattedTextField"; return "FormattedTextField";
} }
/**
* @inheritDoc
*/
@Override
void paintBackground(SynthContext context, Graphics g, JComponent c) { void paintBackground(SynthContext context, Graphics g, JComponent c) {
context.getPainter().paintFormattedTextFieldBackground(context, g, 0, context.getPainter().paintFormattedTextFieldBackground(context, g, 0,
0, c.getWidth(), c.getHeight()); 0, c.getWidth(), c.getHeight());
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintFormattedTextFieldBorder(context, g, x, y, context.getPainter().paintFormattedTextFieldBorder(context, g, x, y,

View file

@ -30,14 +30,9 @@ import java.awt.event.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane; import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
import javax.swing.border.*;
import javax.swing.event.InternalFrameEvent;
import java.util.EventListener;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.VetoableChangeListener;
import java.beans.PropertyVetoException; import java.beans.PropertyVetoException;
import sun.swing.plaf.synth.SynthUI;
import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2;
/** /**

View file

@ -27,52 +27,61 @@ package javax.swing.plaf.synth;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.peer.LightweightPeer;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicInternalFrameUI; import javax.swing.plaf.basic.BasicInternalFrameUI;
import javax.swing.event.*;
import java.beans.*; import java.beans.*;
import java.io.Serializable;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's InternalFrameUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JInternalFrame}.
* *
* @author David Kloba * @author David Kloba
* @author Joshua Outwater * @author Joshua Outwater
* @author Rich Schiavi * @author Rich Schiavi
* @since 1.7
*/ */
class SynthInternalFrameUI extends BasicInternalFrameUI implements SynthUI, public class SynthInternalFrameUI extends BasicInternalFrameUI
PropertyChangeListener { implements SynthUI, PropertyChangeListener {
private SynthStyle style; private SynthStyle style;
private static DesktopManager sharedDesktopManager; /**
private boolean componentListenerAdded = false; * Creates a new UI object for the given component.
*
private Rectangle parentBounds; * @param b component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent b) { public static ComponentUI createUI(JComponent b) {
return new SynthInternalFrameUI((JInternalFrame)b); return new SynthInternalFrameUI((JInternalFrame)b);
} }
public SynthInternalFrameUI(JInternalFrame b) { protected SynthInternalFrameUI(JInternalFrame b) {
super(b); super(b);
} }
/**
* @inheritDoc
*/
@Override
public void installDefaults() { public void installDefaults() {
frame.setLayout(internalFrameLayout = createLayoutManager()); frame.setLayout(internalFrameLayout = createLayoutManager());
updateStyle(frame); updateStyle(frame);
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
frame.addPropertyChangeListener(this); frame.addPropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallComponents() { protected void uninstallComponents() {
if (frame.getComponentPopupMenu() instanceof UIResource) { if (frame.getComponentPopupMenu() instanceof UIResource) {
frame.setComponentPopupMenu(null); frame.setComponentPopupMenu(null);
@ -80,6 +89,10 @@ class SynthInternalFrameUI extends BasicInternalFrameUI implements SynthUI,
super.uninstallComponents(); super.uninstallComponents();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
frame.removePropertyChangeListener(this); frame.removePropertyChangeListener(this);
super.uninstallListeners(); super.uninstallListeners();
@ -104,6 +117,10 @@ class SynthInternalFrameUI extends BasicInternalFrameUI implements SynthUI,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(frame, ENABLED); SynthContext context = getContext(frame, ENABLED);
style.uninstallDefaults(context); style.uninstallDefaults(context);
@ -115,6 +132,10 @@ class SynthInternalFrameUI extends BasicInternalFrameUI implements SynthUI,
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -124,24 +145,28 @@ class SynthInternalFrameUI extends BasicInternalFrameUI implements SynthUI,
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) { private int getComponentState(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
public int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override
protected JComponent createNorthPane(JInternalFrame w) { protected JComponent createNorthPane(JInternalFrame w) {
titlePane = new SynthInternalFrameTitlePane(w); titlePane = new SynthInternalFrameTitlePane(w);
titlePane.setName("InternalFrame.northPane"); titlePane.setName("InternalFrame.northPane");
return titlePane; return titlePane;
} }
/**
* @inheritDoc
*/
@Override
protected ComponentListener createComponentListener() { protected ComponentListener createComponentListener() {
if (UIManager.getBoolean("InternalFrame.useTaskBar")) { if (UIManager.getBoolean("InternalFrame.useTaskBar")) {
return new ComponentHandler() { return new ComponentHandler() {
public void componentResized(ComponentEvent e) { @Override public void componentResized(ComponentEvent e) {
if (frame != null && frame.isMaximum()) { if (frame != null && frame.isMaximum()) {
JDesktopPane desktop = (JDesktopPane)e.getSource(); JDesktopPane desktop = (JDesktopPane)e.getSource();
for (Component comp : desktop.getComponents()) { for (Component comp : desktop.getComponents()) {
@ -168,6 +193,10 @@ class SynthInternalFrameUI extends BasicInternalFrameUI implements SynthUI,
} }
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -178,6 +207,10 @@ class SynthInternalFrameUI extends BasicInternalFrameUI implements SynthUI,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -185,15 +218,29 @@ class SynthInternalFrameUI extends BasicInternalFrameUI implements SynthUI,
context.dispose(); context.dispose();
} }
/**
* Paints the specified component. This implementation does nothing.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintInternalFrameBorder(context, context.getPainter().paintInternalFrameBorder(context,
g, x, y, w, h); g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
SynthStyle oldStyle = style; SynthStyle oldStyle = style;
JInternalFrame f = (JInternalFrame)evt.getSource(); JInternalFrame f = (JInternalFrame)evt.getSource();

View file

@ -29,38 +29,37 @@ import javax.swing.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.*; import javax.swing.plaf.basic.*;
import javax.swing.text.View; import javax.swing.text.View;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.Insets; import java.awt.Insets;
import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Font;
import java.awt.FontMetrics; import java.awt.FontMetrics;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's LabelUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JLabel}.
* *
* @author Scott Violet * @author Scott Violet
* @since 1.7
*/ */
class SynthLabelUI extends BasicLabelUI implements SynthUI { public class SynthLabelUI extends BasicLabelUI implements SynthUI {
private SynthStyle style; private SynthStyle style;
/** /**
* Returns the LabelUI implementation used for the skins look and feel. * Returns the LabelUI implementation used for the skins look and feel.
*
* @param c component to create UI object for
* @return the UI object
*/ */
public static ComponentUI createUI(JComponent c){ public static ComponentUI createUI(JComponent c){
return new SynthLabelUI(); return new SynthLabelUI();
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults(JLabel c) { protected void installDefaults(JLabel c) {
updateStyle(c); updateStyle(c);
} }
@ -71,6 +70,10 @@ class SynthLabelUI extends BasicLabelUI implements SynthUI {
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults(JLabel c){ protected void uninstallDefaults(JLabel c){
SynthContext context = getContext(c, ENABLED); SynthContext context = getContext(c, ENABLED);
@ -79,6 +82,10 @@ class SynthLabelUI extends BasicLabelUI implements SynthUI {
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -88,10 +95,6 @@ class SynthLabelUI extends BasicLabelUI implements SynthUI {
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
int state = SynthLookAndFeel.getComponentState(c); int state = SynthLookAndFeel.getComponentState(c);
if (SynthLookAndFeel.selectedUI == this && if (SynthLookAndFeel.selectedUI == this &&
@ -101,6 +104,10 @@ class SynthLabelUI extends BasicLabelUI implements SynthUI {
return state; return state;
} }
/**
* @inheritDoc
*/
@Override
public int getBaseline(JComponent c, int width, int height) { public int getBaseline(JComponent c, int width, int height) {
if (c == null) { if (c == null) {
throw new NullPointerException("Component must be non-null"); throw new NullPointerException("Component must be non-null");
@ -153,6 +160,10 @@ class SynthLabelUI extends BasicLabelUI implements SynthUI {
* component. This method is invoked by <code>JComponent</code> * component. This method is invoked by <code>JComponent</code>
* when the specified component is being painted. * when the specified component is being painted.
*/ */
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -163,6 +174,10 @@ class SynthLabelUI extends BasicLabelUI implements SynthUI {
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -170,6 +185,12 @@ class SynthLabelUI extends BasicLabelUI implements SynthUI {
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
JLabel label = (JLabel)context.getComponent(); JLabel label = (JLabel)context.getComponent();
Icon icon = (label.isEnabled()) ? label.getIcon() : Icon icon = (label.isEnabled()) ? label.getIcon() :
@ -185,11 +206,19 @@ class SynthLabelUI extends BasicLabelUI implements SynthUI {
label.getIconTextGap(), label.getDisplayedMnemonicIndex(), 0); label.getIconTextGap(), label.getDisplayedMnemonicIndex(), 0);
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintLabelBorder(context, g, x, y, w, h); context.getPainter().paintLabelBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
public Dimension getPreferredSize(JComponent c) { public Dimension getPreferredSize(JComponent c) {
JLabel label = (JLabel)c; JLabel label = (JLabel)c;
Icon icon = (label.isEnabled()) ? label.getIcon() : Icon icon = (label.isEnabled()) ? label.getIcon() :
@ -207,7 +236,10 @@ class SynthLabelUI extends BasicLabelUI implements SynthUI {
return size; return size;
} }
/**
* @inheritDoc
*/
@Override
public Dimension getMinimumSize(JComponent c) { public Dimension getMinimumSize(JComponent c) {
JLabel label = (JLabel)c; JLabel label = (JLabel)c;
Icon icon = (label.isEnabled()) ? label.getIcon() : Icon icon = (label.isEnabled()) ? label.getIcon() :
@ -225,6 +257,10 @@ class SynthLabelUI extends BasicLabelUI implements SynthUI {
return size; return size;
} }
/**
* @inheritDoc
*/
@Override
public Dimension getMaximumSize(JComponent c) { public Dimension getMaximumSize(JComponent c) {
JLabel label = (JLabel)c; JLabel label = (JLabel)c;
Icon icon = (label.isEnabled()) ? label.getIcon() : Icon icon = (label.isEnabled()) ? label.getIcon() :
@ -242,7 +278,10 @@ class SynthLabelUI extends BasicLabelUI implements SynthUI {
return size; return size;
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
super.propertyChange(e); super.propertyChange(e);
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {

View file

@ -27,38 +27,39 @@ package javax.swing.plaf.synth;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.*; import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.*; import javax.swing.plaf.basic.*;
import javax.swing.text.Position;
import java.awt.*; import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.*;
import java.util.ArrayList;
import java.util.TooManyListenersException;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's ListUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JList}.
* *
* @author Scott Violet * @author Scott Violet
* @since 1.7
*/ */
class SynthListUI extends BasicListUI implements PropertyChangeListener, public class SynthListUI extends BasicListUI
SynthUI { implements PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
private boolean useListColors; private boolean useListColors;
private boolean useUIBorder; private boolean useUIBorder;
/**
* Creates a new UI object for the given component.
*
* @param list component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent list) { public static ComponentUI createUI(JComponent list) {
return new SynthListUI(); return new SynthListUI();
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -69,27 +70,47 @@ class SynthListUI extends BasicListUI implements PropertyChangeListener,
paint(g, c); paint(g, c);
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintListBorder(context, g, x, y, w, h); context.getPainter().paintListBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
list.addPropertyChangeListener(this); list.addPropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((JList)e.getSource()); updateStyle((JList)e.getSource());
} }
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
list.removePropertyChangeListener(this); list.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults() { protected void installDefaults() {
if (list.getCellRenderer() == null || if (list.getCellRenderer() == null ||
(list.getCellRenderer() instanceof UIResource)) { (list.getCellRenderer() instanceof UIResource)) {
@ -135,6 +156,10 @@ class SynthListUI extends BasicListUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
super.uninstallDefaults(); super.uninstallDefaults();
@ -145,6 +170,10 @@ class SynthListUI extends BasicListUI implements PropertyChangeListener,
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -154,27 +183,23 @@ class SynthListUI extends BasicListUI implements PropertyChangeListener,
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
private class SynthListCellRenderer extends DefaultListCellRenderer.UIResource { private class SynthListCellRenderer extends DefaultListCellRenderer.UIResource {
public String getName() { @Override public String getName() {
return "List.cellRenderer"; return "List.cellRenderer";
} }
public void setBorder(Border b) { @Override public void setBorder(Border b) {
if (useUIBorder || b instanceof SynthBorder) { if (useUIBorder || b instanceof SynthBorder) {
super.setBorder(b); super.setBorder(b);
} }
} }
public Component getListCellRendererComponent(JList list, Object value, @Override public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) { int index, boolean isSelected, boolean cellHasFocus) {
if (!useListColors && (isSelected || cellHasFocus)) { if (!useListColors && (isSelected || cellHasFocus)) {
SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel. SynthLookAndFeel.setSelectedUI((SynthLabelUI)SynthLookAndFeel.
@ -190,7 +215,7 @@ class SynthListUI extends BasicListUI implements PropertyChangeListener,
return this; return this;
} }
public void paint(Graphics g) { @Override public void paint(Graphics g) {
super.paint(g); super.paint(g);
SynthLookAndFeel.resetSelectedUI(); SynthLookAndFeel.resetSelectedUI();
} }

View file

@ -234,44 +234,9 @@ public class SynthLookAndFeel extends BasicLookAndFeel {
* <code>shouldUpdateStyleOnAncestorChanged</code> as necessary. * <code>shouldUpdateStyleOnAncestorChanged</code> as necessary.
*/ */
static boolean shouldUpdateStyle(PropertyChangeEvent event) { static boolean shouldUpdateStyle(PropertyChangeEvent event) {
String eName = event.getPropertyName();
if ("name" == eName) {
// Always update on a name change
return true;
}
else if ("componentOrientation" == eName) {
// Always update on a component orientation change
return true;
}
else if ("ancestor" == eName && event.getNewValue() != null) {
// Only update on an ancestor change when getting a valid
// parent and the LookAndFeel wants this.
LookAndFeel laf = UIManager.getLookAndFeel(); LookAndFeel laf = UIManager.getLookAndFeel();
return (laf instanceof SynthLookAndFeel && return (laf instanceof SynthLookAndFeel &&
((SynthLookAndFeel)laf). ((SynthLookAndFeel) laf).shouldUpdateStyleOnEvent(event));
shouldUpdateStyleOnAncestorChanged());
}
// Note: The following two nimbus based overrides should be refactored
// to be in the Nimbus LAF. Due to constraints in an update release,
// we couldn't actually provide the public API necessary to allow
// NimbusLookAndFeel (a subclass of SynthLookAndFeel) to provide its
// own rules for shouldUpdateStyle.
else if ("Nimbus.Overrides" == eName) {
// Always update when the Nimbus.Overrides client property has
// been changed
return true;
}
else if ("Nimbus.Overrides.InheritDefaults" == eName) {
// Always update when the Nimbus.Overrides.InheritDefaults
// client property has changed
return true;
}
else if ("JComponent.sizeVariant" == eName) {
// Always update when the JComponent.sizeVariant
// client property has changed
return true;
}
return false;
} }
/** /**
@ -303,12 +268,6 @@ public class SynthLookAndFeel extends BasicLookAndFeel {
* @param c Component to update style for. * @param c Component to update style for.
*/ */
public static void updateStyles(Component c) { public static void updateStyles(Component c) {
_updateStyles(c);
c.repaint();
}
// Implementation for updateStyles
private static void _updateStyles(Component c) {
if (c instanceof JComponent) { if (c instanceof JComponent) {
// Yes, this is hacky. A better solution is to get the UI // Yes, this is hacky. A better solution is to get the UI
// and cast, but JComponent doesn't expose a getter for the UI // and cast, but JComponent doesn't expose a getter for the UI
@ -332,6 +291,7 @@ public class SynthLookAndFeel extends BasicLookAndFeel {
updateStyles(child); updateStyles(child);
} }
} }
c.repaint();
} }
/** /**
@ -788,6 +748,27 @@ public class SynthLookAndFeel extends BasicLookAndFeel {
return false; return false;
} }
/**
* Returns whether or not the UIs should update their styles when a
* particular event occurs.
*
* @param ev a {@code PropertyChangeEvent}
* @return whether or not the UIs should update their styles
* @since 1.7
*/
protected boolean shouldUpdateStyleOnEvent(PropertyChangeEvent ev) {
String eName = ev.getPropertyName();
if ("name" == eName || "componentOrientation" == eName) {
return true;
}
if ("ancestor" == eName && ev.getNewValue() != null) {
// Only update on an ancestor change when getting a valid
// parent and the LookAndFeel wants this.
return shouldUpdateStyleOnAncestorChanged();
}
return false;
}
/** /**
* Returns the antialiasing information as specified by the host desktop. * Returns the antialiasing information as specified by the host desktop.
* Antialiasing might be forced off if the desktop is GNOME and the user * Antialiasing might be forced off if the desktop is GNOME and the user

View file

@ -25,45 +25,49 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.*;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import javax.swing.border.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.*; import javax.swing.plaf.basic.*;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's MenuBarUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JMenuBar}.
* *
* @author Scott Violet * @author Scott Violet
* @since 1.7
*/ */
class SynthMenuBarUI extends BasicMenuBarUI implements PropertyChangeListener, public class SynthMenuBarUI extends BasicMenuBarUI
SynthUI { implements PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
/**
* Creates a new UI object for the given component.
*
* @param x component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent x) { public static ComponentUI createUI(JComponent x) {
return new SynthMenuBarUI(); return new SynthMenuBarUI();
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults() { protected void installDefaults() {
if (menuBar.getLayout() == null || if (menuBar.getLayout() == null ||
menuBar.getLayout() instanceof UIResource) { menuBar.getLayout() instanceof UIResource) {
menuBar.setLayout(new DefaultMenuLayout(menuBar,BoxLayout.LINE_AXIS)); menuBar.setLayout(new SynthMenuLayout(menuBar,BoxLayout.LINE_AXIS));
} }
updateStyle(menuBar); updateStyle(menuBar);
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
menuBar.addPropertyChangeListener(this); menuBar.addPropertyChangeListener(this);
@ -82,6 +86,10 @@ class SynthMenuBarUI extends BasicMenuBarUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(menuBar, ENABLED); SynthContext context = getContext(menuBar, ENABLED);
@ -90,11 +98,19 @@ class SynthMenuBarUI extends BasicMenuBarUI implements PropertyChangeListener,
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
menuBar.removePropertyChangeListener(this); menuBar.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -104,14 +120,14 @@ class SynthMenuBarUI extends BasicMenuBarUI implements PropertyChangeListener,
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -122,6 +138,10 @@ class SynthMenuBarUI extends BasicMenuBarUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -129,14 +149,28 @@ class SynthMenuBarUI extends BasicMenuBarUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* Paints the specified component. This implementation does nothing.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintMenuBarBorder(context, g, x, y, w, h); context.getPainter().paintMenuBarBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((JMenuBar)e.getSource()); updateStyle((JMenuBar)e.getSource());

View file

@ -24,41 +24,44 @@
*/ */
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import javax.swing.plaf.basic.BasicHTML;
import java.awt.*; import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.*; import javax.swing.plaf.basic.*;
import javax.swing.text.View;
import sun.swing.plaf.synth.*;
import sun.swing.MenuItemLayoutHelper; import sun.swing.MenuItemLayoutHelper;
/** /**
* Synth's MenuItemUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JMenuItem}.
* *
* @author Georges Saab * @author Georges Saab
* @author David Karlton * @author David Karlton
* @author Arnaud Weber * @author Arnaud Weber
* @author Fredrik Lagerblad * @author Fredrik Lagerblad
* @since 1.7
*/ */
class SynthMenuItemUI extends BasicMenuItemUI implements public class SynthMenuItemUI extends BasicMenuItemUI implements
PropertyChangeListener, SynthUI { PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
private SynthStyle accStyle; private SynthStyle accStyle;
private String acceleratorDelimiter; /**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthMenuItemUI(); return new SynthMenuItemUI();
} }
/**
* @inheritDoc
*/
@Override
public void uninstallUI(JComponent c) { public void uninstallUI(JComponent c) {
super.uninstallUI(c); super.uninstallUI(c);
// Remove values from the parent's Client Properties. // Remove values from the parent's Client Properties.
@ -69,10 +72,18 @@ class SynthMenuItemUI extends BasicMenuItemUI implements
} }
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults() { protected void installDefaults() {
updateStyle(menuItem); updateStyle(menuItem);
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
menuItem.addPropertyChangeListener(this); menuItem.addPropertyChangeListener(this);
@ -122,6 +133,10 @@ class SynthMenuItemUI extends BasicMenuItemUI implements
accContext.dispose(); accContext.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(menuItem, ENABLED); SynthContext context = getContext(menuItem, ENABLED);
style.uninstallDefaults(context); style.uninstallDefaults(context);
@ -137,11 +152,19 @@ class SynthMenuItemUI extends BasicMenuItemUI implements
super.uninstallDefaults(); super.uninstallDefaults();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
menuItem.removePropertyChangeListener(this); menuItem.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -151,7 +174,7 @@ class SynthMenuItemUI extends BasicMenuItemUI implements
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
public SynthContext getContext(JComponent c, Region region) { SynthContext getContext(JComponent c, Region region) {
return getContext(c, region, getComponentState(c, region)); return getContext(c, region, getComponentState(c, region));
} }
@ -160,10 +183,6 @@ class SynthMenuItemUI extends BasicMenuItemUI implements
region, accStyle, state); region, accStyle, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
int state; int state;
@ -186,6 +205,10 @@ class SynthMenuItemUI extends BasicMenuItemUI implements
return getComponentState(c); return getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override
protected Dimension getPreferredMenuItemSize(JComponent c, protected Dimension getPreferredMenuItemSize(JComponent c,
Icon checkIcon, Icon checkIcon,
Icon arrowIcon, Icon arrowIcon,
@ -203,6 +226,10 @@ class SynthMenuItemUI extends BasicMenuItemUI implements
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -212,6 +239,10 @@ class SynthMenuItemUI extends BasicMenuItemUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -219,6 +250,12 @@ class SynthMenuItemUI extends BasicMenuItemUI implements
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
SynthContext accContext = getContext(menuItem, SynthContext accContext = getContext(menuItem,
Region.MENU_ITEM_ACCELERATOR); Region.MENU_ITEM_ACCELERATOR);
@ -236,11 +273,19 @@ class SynthMenuItemUI extends BasicMenuItemUI implements
SynthGraphicsUtils.paintBackground(context, g, c); SynthGraphicsUtils.paintBackground(context, g, c);
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintMenuItemBorder(context, g, x, y, w, h); context.getPainter().paintMenuItemBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((JMenuItem)e.getSource()); updateStyle((JMenuItem)e.getSource());

View file

@ -25,43 +25,28 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import javax.swing.*; import javax.swing.plaf.basic.DefaultMenuLayout;
import javax.swing.plaf.UIResource; import javax.swing.JPopupMenu;
import java.awt.Container; import java.awt.Container;
import java.awt.Dimension; import java.awt.Dimension;
/** /**
* The default layout manager for Popup menus and menubars. This * @inheritDoc
* class is an extension of BoxLayout which adds the UIResource tag
* so that plauggable L&Fs can distinguish it from user-installed
* layout managers on menus.
*
* Derived from javax.swing.plaf.basic.DefaultMenuLayout
* *
* @author Georges Saab * @author Georges Saab
*/ */
class DefaultMenuLayout extends BoxLayout implements UIResource { class SynthMenuLayout extends DefaultMenuLayout {
public DefaultMenuLayout(Container target, int axis) { public SynthMenuLayout(Container target, int axis) {
super(target, axis); super(target, axis);
} }
public Dimension preferredLayoutSize(Container target) { public Dimension preferredLayoutSize(Container target) {
if (target instanceof JPopupMenu) { if (target instanceof JPopupMenu) {
JPopupMenu popupMenu = (JPopupMenu) target; JPopupMenu popupMenu = (JPopupMenu) target;
popupMenu.putClientProperty( popupMenu.putClientProperty(
SynthMenuItemLayoutHelper.MAX_ACC_OR_ARROW_WIDTH, null); SynthMenuItemLayoutHelper.MAX_ACC_OR_ARROW_WIDTH, null);
sun.swing.MenuItemLayoutHelper.clearUsedClientProperties(popupMenu);
if (popupMenu.getComponentCount() == 0) {
return new Dimension(0, 0);
} }
}
// Make BoxLayout recalculate cached preferred sizes
super.invalidateLayout(target);
return super.preferredLayoutSize(target); return super.preferredLayoutSize(target);
} }

View file

@ -25,40 +25,48 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import java.awt.*; import java.awt.*;
import java.awt.event.*;
import java.beans.*; import java.beans.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.*; import javax.swing.plaf.basic.*;
import javax.swing.border.*;
import java.util.Arrays;
import java.util.ArrayList;
import sun.swing.plaf.synth.SynthUI;
import sun.swing.MenuItemLayoutHelper; import sun.swing.MenuItemLayoutHelper;
/** /**
* Synth's MenuUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JMenu}.
* *
* @author Georges Saab * @author Georges Saab
* @author David Karlton * @author David Karlton
* @author Arnaud Weber * @author Arnaud Weber
* @since 1.7
*/ */
class SynthMenuUI extends BasicMenuUI implements PropertyChangeListener, public class SynthMenuUI extends BasicMenuUI
SynthUI { implements PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
private SynthStyle accStyle; private SynthStyle accStyle;
private String acceleratorDelimiter; /**
* Creates a new UI object for the given component.
*
* @param x component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent x) { public static ComponentUI createUI(JComponent x) {
return new SynthMenuUI(); return new SynthMenuUI();
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults() { protected void installDefaults() {
updateStyle(menuItem); updateStyle(menuItem);
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
menuItem.addPropertyChangeListener(this); menuItem.addPropertyChangeListener(this);
@ -111,6 +119,10 @@ class SynthMenuUI extends BasicMenuUI implements PropertyChangeListener,
accContext.dispose(); accContext.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void uninstallUI(JComponent c) { public void uninstallUI(JComponent c) {
super.uninstallUI(c); super.uninstallUI(c);
// Remove values from the parent's Client Properties. // Remove values from the parent's Client Properties.
@ -121,6 +133,10 @@ class SynthMenuUI extends BasicMenuUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(menuItem, ENABLED); SynthContext context = getContext(menuItem, ENABLED);
style.uninstallDefaults(context); style.uninstallDefaults(context);
@ -136,22 +152,30 @@ class SynthMenuUI extends BasicMenuUI implements PropertyChangeListener,
super.uninstallDefaults(); super.uninstallDefaults();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
menuItem.removePropertyChangeListener(this); menuItem.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
SynthContext getContext(JComponent c, int state) { SynthContext getContext(JComponent c, int state) {
Region region = getRegion(c); Region region = SynthLookAndFeel.getRegion(c);
return SynthContext.getContext(SynthContext.class, c, region, return SynthContext.getContext(SynthContext.class, c, region,
style, state); style, state);
} }
public SynthContext getContext(JComponent c, Region region) { SynthContext getContext(JComponent c, Region region) {
return getContext(c, region, getComponentState(c, region)); return getContext(c, region, getComponentState(c, region));
} }
@ -160,10 +184,6 @@ class SynthMenuUI extends BasicMenuUI implements PropertyChangeListener,
region, accStyle, state); region, accStyle, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
int state; int state;
@ -186,6 +206,10 @@ class SynthMenuUI extends BasicMenuUI implements PropertyChangeListener,
return getComponentState(c); return getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override
protected Dimension getPreferredMenuItemSize(JComponent c, protected Dimension getPreferredMenuItemSize(JComponent c,
Icon checkIcon, Icon checkIcon,
Icon arrowIcon, Icon arrowIcon,
@ -202,7 +226,10 @@ class SynthMenuUI extends BasicMenuUI implements PropertyChangeListener,
return value; return value;
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -213,6 +240,10 @@ class SynthMenuUI extends BasicMenuUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -220,6 +251,12 @@ class SynthMenuUI extends BasicMenuUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* Paints the specified component. This implementation does nothing.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
SynthContext accContext = getContext(menuItem, SynthContext accContext = getContext(menuItem,
Region.MENU_ITEM_ACCELERATOR); Region.MENU_ITEM_ACCELERATOR);
@ -232,11 +269,19 @@ class SynthMenuUI extends BasicMenuUI implements PropertyChangeListener,
accContext.dispose(); accContext.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintMenuBorder(context, g, x, y, w, h); context.getPainter().paintMenuBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((JMenu)e.getSource()); updateStyle((JMenu)e.getSource());

View file

@ -28,34 +28,45 @@ package javax.swing.plaf.synth;
import java.awt.*; import java.awt.*;
import java.beans.*; import java.beans.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.*; import javax.swing.plaf.basic.*;
import sun.swing.DefaultLookup; import sun.swing.DefaultLookup;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's OptionPaneUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JOptionPane}.
* *
* @author James Gosling * @author James Gosling
* @author Scott Violet * @author Scott Violet
* @author Amy Fowler * @author Amy Fowler
* @since 1.7
*/ */
class SynthOptionPaneUI extends BasicOptionPaneUI implements public class SynthOptionPaneUI extends BasicOptionPaneUI implements
PropertyChangeListener, SynthUI { PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
/** /**
* Creates a new BasicOptionPaneUI instance. * Creates a new UI object for the given component.
*
* @param x component to create UI object for
* @return the UI object
*/ */
public static ComponentUI createUI(JComponent x) { public static ComponentUI createUI(JComponent x) {
return new SynthOptionPaneUI(); return new SynthOptionPaneUI();
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults() { protected void installDefaults() {
updateStyle(optionPane); updateStyle(optionPane);
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
optionPane.addPropertyChangeListener(this); optionPane.addPropertyChangeListener(this);
@ -80,6 +91,10 @@ class SynthOptionPaneUI extends BasicOptionPaneUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(optionPane, ENABLED); SynthContext context = getContext(optionPane, ENABLED);
@ -88,11 +103,19 @@ class SynthOptionPaneUI extends BasicOptionPaneUI implements
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
optionPane.removePropertyChangeListener(this); optionPane.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void installComponents() { protected void installComponents() {
optionPane.add(createMessageArea()); optionPane.add(createMessageArea());
@ -108,6 +131,10 @@ class SynthOptionPaneUI extends BasicOptionPaneUI implements
optionPane.applyComponentOrientation(optionPane.getComponentOrientation()); optionPane.applyComponentOrientation(optionPane.getComponentOrientation());
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -117,14 +144,14 @@ class SynthOptionPaneUI extends BasicOptionPaneUI implements
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -135,6 +162,10 @@ class SynthOptionPaneUI extends BasicOptionPaneUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -142,30 +173,49 @@ class SynthOptionPaneUI extends BasicOptionPaneUI implements
context.dispose(); context.dispose();
} }
/**
* Paints the specified component. This implementation does nothing.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintOptionPaneBorder(context, g, x, y, w, h); context.getPainter().paintOptionPaneBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((JOptionPane)e.getSource()); updateStyle((JOptionPane)e.getSource());
} }
} }
/**
* @inheritDoc
*/
@Override
protected boolean getSizeButtonsToSameWidth() { protected boolean getSizeButtonsToSameWidth() {
return DefaultLookup.getBoolean(optionPane, this, return DefaultLookup.getBoolean(optionPane, this,
"OptionPane.sameSizeButtons", true); "OptionPane.sameSizeButtons", true);
} }
/** /**
* Messaged from installComponents to create a Container containing the * Called from {@link #installComponents} to create a {@code Container}
* body of the message. The icon is the created by calling * containing the body of the message. The icon is the created by calling
* <code>addIcon</code>. * {@link #addIcon}.
*/ */
@Override
protected Container createMessageArea() { protected Container createMessageArea() {
JPanel top = new JPanel(); JPanel top = new JPanel();
top.setName("OptionPane.messageArea"); top.setName("OptionPane.messageArea");
@ -206,6 +256,10 @@ class SynthOptionPaneUI extends BasicOptionPaneUI implements
return top; return top;
} }
/**
* @inheritDoc
*/
@Override
protected Container createSeparator() { protected Container createSeparator() {
JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL); JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);

View file

@ -25,7 +25,6 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import java.awt.*; import java.awt.*;
import javax.swing.*;
/** /**
* <code>SynthPainter</code> is used for painting portions of * <code>SynthPainter</code> is used for painting portions of

View file

@ -25,29 +25,37 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import java.awt.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicPanelUI; import javax.swing.plaf.basic.BasicPanelUI;
import java.awt.*; import java.awt.*;
import java.awt.event.*;
import java.beans.*; import java.beans.*;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's PanelUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JPanel}.
* *
* @author Steve Wilson * @author Steve Wilson
* @since 1.7
*/ */
class SynthPanelUI extends BasicPanelUI implements PropertyChangeListener, public class SynthPanelUI extends BasicPanelUI
SynthUI { implements PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthPanelUI(); return new SynthPanelUI();
} }
/**
* @inheritDoc
*/
@Override
public void installUI(JComponent c) { public void installUI(JComponent c) {
JPanel p = (JPanel)c; JPanel p = (JPanel)c;
@ -55,6 +63,10 @@ class SynthPanelUI extends BasicPanelUI implements PropertyChangeListener,
installListeners(p); installListeners(p);
} }
/**
* @inheritDoc
*/
@Override
public void uninstallUI(JComponent c) { public void uninstallUI(JComponent c) {
JPanel p = (JPanel)c; JPanel p = (JPanel)c;
@ -62,18 +74,36 @@ class SynthPanelUI extends BasicPanelUI implements PropertyChangeListener,
super.uninstallUI(c); super.uninstallUI(c);
} }
/**
* Installs listeners into the panel.
*
* @param p the {@code JPanel} object
*/
protected void installListeners(JPanel p) { protected void installListeners(JPanel p) {
p.addPropertyChangeListener(this); p.addPropertyChangeListener(this);
} }
/**
* Uninstalls listeners from the panel.
*
* @param p the {@code JPanel} object
*/
protected void uninstallListeners(JPanel p) { protected void uninstallListeners(JPanel p) {
p.removePropertyChangeListener(this); p.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults(JPanel p) { protected void installDefaults(JPanel p) {
updateStyle(p); updateStyle(p);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults(JPanel p) { protected void uninstallDefaults(JPanel p) {
SynthContext context = getContext(p, ENABLED); SynthContext context = getContext(p, ENABLED);
@ -88,6 +118,10 @@ class SynthPanelUI extends BasicPanelUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -97,14 +131,14 @@ class SynthPanelUI extends BasicPanelUI implements PropertyChangeListener,
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -115,6 +149,10 @@ class SynthPanelUI extends BasicPanelUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -122,15 +160,29 @@ class SynthPanelUI extends BasicPanelUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* Paints the specified component. This implementation does nothing.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
// do actual painting // do actual painting
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintPanelBorder(context, g, x, y, w, h); context.getPainter().paintPanelBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent pce) { public void propertyChange(PropertyChangeEvent pce) {
if (SynthLookAndFeel.shouldUpdateStyle(pce)) { if (SynthLookAndFeel.shouldUpdateStyle(pce)) {
updateStyle((JPanel)pce.getSource()); updateStyle((JPanel)pce.getSource());

View file

@ -25,21 +25,19 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import java.awt.*; import java.awt.Graphics;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.*; import javax.swing.text.*;
import javax.swing.plaf.*; import javax.swing.plaf.ComponentUI;
/** /**
* Provides the Synth look and feel for a password field. * Provides the Synth L&F UI delegate for
* The only difference from the standard text field is that * {@link javax.swing.JPasswordField}.
* the view of the text is simply a string of the echo
* character as specified in JPasswordField, rather than the
* real text contained in the field.
* *
* @author Shannon Hickey * @author Shannon Hickey
* @since 1.7
*/ */
class SynthPasswordFieldUI extends SynthTextFieldUI { public class SynthPasswordFieldUI extends SynthTextFieldUI {
/** /**
* Creates a UI for a JPasswordField. * Creates a UI for a JPasswordField.
@ -58,6 +56,7 @@ class SynthPasswordFieldUI extends SynthTextFieldUI {
* *
* @return the name ("PasswordField") * @return the name ("PasswordField")
*/ */
@Override
protected String getPropertyPrefix() { protected String getPropertyPrefix() {
return "PasswordField"; return "PasswordField";
} }
@ -68,20 +67,33 @@ class SynthPasswordFieldUI extends SynthTextFieldUI {
* @param elem the element * @param elem the element
* @return the view * @return the view
*/ */
@Override
public View create(Element elem) { public View create(Element elem) {
return new PasswordView(elem); return new PasswordView(elem);
} }
/**
* @inheritDoc
*/
@Override
void paintBackground(SynthContext context, Graphics g, JComponent c) { void paintBackground(SynthContext context, Graphics g, JComponent c) {
context.getPainter().paintPasswordFieldBackground(context, g, 0, 0, context.getPainter().paintPasswordFieldBackground(context, g, 0, 0,
c.getWidth(), c.getHeight()); c.getWidth(), c.getHeight());
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintPasswordFieldBorder(context, g, x, y, w, h); context.getPainter().paintPasswordFieldBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
protected void installKeyboardActions() { protected void installKeyboardActions() {
super.installKeyboardActions(); super.installKeyboardActions();
ActionMap map = SwingUtilities.getUIActionMap(getComponent()); ActionMap map = SwingUtilities.getUIActionMap(getComponent());

View file

@ -26,49 +26,43 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.*; import javax.swing.plaf.basic.*;
import javax.swing.border.*;
import java.applet.Applet;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.KeyboardFocusManager;
import java.awt.Window;
import java.awt.event.*;
import java.awt.AWTEvent;
import java.awt.Toolkit;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.util.*;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's PopupMenuUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JPopupMenu}.
* *
* @author Georges Saab * @author Georges Saab
* @author David Karlton * @author David Karlton
* @author Arnaud Weber * @author Arnaud Weber
* @since 1.7
*/ */
class SynthPopupMenuUI extends BasicPopupMenuUI implements public class SynthPopupMenuUI extends BasicPopupMenuUI
PropertyChangeListener, SynthUI { implements PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
/**
* Creates a new UI object for the given component.
*
* @param x component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent x) { public static ComponentUI createUI(JComponent x) {
return new SynthPopupMenuUI(); return new SynthPopupMenuUI();
} }
/**
* @inheritDoc
*/
@Override
public void installDefaults() { public void installDefaults() {
if (popupMenu.getLayout() == null || if (popupMenu.getLayout() == null ||
popupMenu.getLayout() instanceof UIResource) { popupMenu.getLayout() instanceof UIResource) {
popupMenu.setLayout(new DefaultMenuLayout( popupMenu.setLayout(new SynthMenuLayout(popupMenu, BoxLayout.Y_AXIS));
popupMenu, BoxLayout.Y_AXIS));
} }
updateStyle(popupMenu); updateStyle(popupMenu);
} }
@ -86,11 +80,19 @@ class SynthPopupMenuUI extends BasicPopupMenuUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
popupMenu.addPropertyChangeListener(this); popupMenu.addPropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(popupMenu, ENABLED); SynthContext context = getContext(popupMenu, ENABLED);
@ -103,11 +105,19 @@ class SynthPopupMenuUI extends BasicPopupMenuUI implements
} }
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
popupMenu.removePropertyChangeListener(this); popupMenu.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -117,14 +127,14 @@ class SynthPopupMenuUI extends BasicPopupMenuUI implements
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -135,6 +145,10 @@ class SynthPopupMenuUI extends BasicPopupMenuUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -142,14 +156,28 @@ class SynthPopupMenuUI extends BasicPopupMenuUI implements
context.dispose(); context.dispose();
} }
/**
* Paints the specified component. This implementation does nothing.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintPopupMenuBorder(context, g, x, y, w, h); context.getPainter().paintPopupMenuBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle(popupMenu); updateStyle(popupMenu);

View file

@ -32,16 +32,17 @@ import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicProgressBarUI; import javax.swing.plaf.basic.BasicProgressBarUI;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import sun.swing.plaf.synth.SynthUI;
import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2;
/** /**
* Synth's ProgressBarUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JProgressBar}.
* *
* @author Joshua Outwater * @author Joshua Outwater
* @since 1.7
*/ */
class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI, public class SynthProgressBarUI extends BasicProgressBarUI
PropertyChangeListener { implements SynthUI, PropertyChangeListener {
private SynthStyle style; private SynthStyle style;
private int progressPadding; private int progressPadding;
private boolean rotateText; // added for Nimbus LAF private boolean rotateText; // added for Nimbus LAF
@ -49,22 +50,37 @@ class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI,
private boolean tileWhenIndeterminate; //whether to tile indeterminate painting private boolean tileWhenIndeterminate; //whether to tile indeterminate painting
private int tileWidth; //the width of each tile private int tileWidth; //the width of each tile
/**
* Creates a new UI object for the given component.
*
* @param x component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent x) { public static ComponentUI createUI(JComponent x) {
return new SynthProgressBarUI(); return new SynthProgressBarUI();
} }
/**
* @inheritDoc
*/
@Override @Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
progressBar.addPropertyChangeListener(this); progressBar.addPropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override @Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
progressBar.removePropertyChangeListener(this); progressBar.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override @Override
protected void installDefaults() { protected void installDefaults() {
updateStyle(progressBar); updateStyle(progressBar);
@ -101,6 +117,9 @@ class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override @Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(progressBar, ENABLED); SynthContext context = getContext(progressBar, ENABLED);
@ -110,6 +129,10 @@ class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI,
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -119,14 +142,13 @@ class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI,
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override @Override
public int getBaseline(JComponent c, int width, int height) { public int getBaseline(JComponent c, int width, int height) {
super.getBaseline(c, width, height); super.getBaseline(c, width, height);
@ -142,6 +164,9 @@ class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI,
return -1; return -1;
} }
/**
* @inheritDoc
*/
@Override @Override
protected Rectangle getBox(Rectangle r) { protected Rectangle getBox(Rectangle r) {
if (tileWhenIndeterminate) { if (tileWhenIndeterminate) {
@ -151,6 +176,9 @@ class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI,
} }
} }
/**
* @inheritDoc
*/
@Override @Override
protected void setAnimationIndex(int newValue) { protected void setAnimationIndex(int newValue) {
if (paintOutsideClip) { if (paintOutsideClip) {
@ -164,6 +192,9 @@ class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI,
} }
} }
/**
* @inheritDoc
*/
@Override @Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -176,6 +207,9 @@ class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override @Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -184,6 +218,12 @@ class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI,
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
JProgressBar pBar = (JProgressBar)context.getComponent(); JProgressBar pBar = (JProgressBar)context.getComponent();
int x = 0, y = 0, width = 0, height = 0; int x = 0, y = 0, width = 0, height = 0;
@ -261,8 +301,14 @@ class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI,
} }
} }
protected void paintText(SynthContext context, Graphics g, /**
String title) { * Paints the component's text.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
* @param title the text to paint
*/
protected void paintText(SynthContext context, Graphics g, String title) {
if (progressBar.isStringPainted()) { if (progressBar.isStringPainted()) {
SynthStyle style = context.getStyle(); SynthStyle style = context.getStyle();
Font font = style.getFont(context); Font font = style.getFont(context);
@ -323,12 +369,20 @@ class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI,
} }
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintProgressBarBorder(context, g, x, y, w, h, context.getPainter().paintProgressBarBorder(context, g, x, y, w, h,
progressBar.getOrientation()); progressBar.getOrientation());
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e) || if (SynthLookAndFeel.shouldUpdateStyle(e) ||
"indeterminate".equals(e.getPropertyName())) { "indeterminate".equals(e.getPropertyName())) {
@ -336,6 +390,9 @@ class SynthProgressBarUI extends BasicProgressBarUI implements SynthUI,
} }
} }
/**
* @inheritDoc
*/
@Override @Override
public Dimension getPreferredSize(JComponent c) { public Dimension getPreferredSize(JComponent c) {
Dimension size = null; Dimension size = null;

View file

@ -27,49 +27,46 @@ package javax.swing.plaf.synth;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.border.*;
/** /**
* Synth's RadioButtonMenuItemUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JRadioButtonMenuItem}.
* *
* @author Georges Saab * @author Georges Saab
* @author David Karlton * @author David Karlton
* @since 1.7
*/
public class SynthRadioButtonMenuItemUI extends SynthMenuItemUI {
/**
* Creates a new UI object for the given component.
*
* @param b component to create UI object for
* @return the UI object
*/ */
class SynthRadioButtonMenuItemUI extends SynthMenuItemUI {
public static ComponentUI createUI(JComponent b) { public static ComponentUI createUI(JComponent b) {
return new SynthRadioButtonMenuItemUI(); return new SynthRadioButtonMenuItemUI();
} }
/**
* @inheritDoc
*/
@Override
protected String getPropertyPrefix() { protected String getPropertyPrefix() {
return "RadioButtonMenuItem"; return "RadioButtonMenuItem";
} }
public void processMouseEvent(JMenuItem item,MouseEvent e,MenuElement path[],MenuSelectionManager manager) { @Override
Point p = e.getPoint();
if(p.x >= 0 && p.x < item.getWidth() &&
p.y >= 0 && p.y < item.getHeight()) {
if(e.getID() == MouseEvent.MOUSE_RELEASED) {
manager.clearSelectedPath();
item.doClick(0);
item.setArmed(false);
} else
manager.setSelectedPath(path);
} else if(item.getModel().isArmed()) {
MenuElement newPath[] = new MenuElement[path.length-1];
int i,c;
for(i=0,c=path.length-1;i<c;i++)
newPath[i] = path[i];
manager.setSelectedPath(newPath);
}
}
void paintBackground(SynthContext context, Graphics g, JComponent c) { void paintBackground(SynthContext context, Graphics g, JComponent c) {
context.getPainter().paintRadioButtonMenuItemBackground(context, g, 0, context.getPainter().paintRadioButtonMenuItemBackground(context, g, 0,
0, c.getWidth(), c.getHeight()); 0, c.getWidth(), c.getHeight());
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintRadioButtonMenuItemBorder(context, g, x, context.getPainter().paintRadioButtonMenuItemBorder(context, g, x,

View file

@ -26,42 +26,58 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import java.awt.*; import java.awt.*;
import java.awt.event.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.text.View;
/** /**
* Synth's RadioButtonUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JRadioButton}.
* *
* @author Jeff Dinkins * @author Jeff Dinkins
* @since 1.7
*/ */
class SynthRadioButtonUI extends SynthToggleButtonUI { public class SynthRadioButtonUI extends SynthToggleButtonUI {
// ******************************** // ********************************
// Create PLAF // Create PLAF
// ******************************** // ********************************
/**
* Creates a new UI object for the given component.
*
* @param b component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent b) { public static ComponentUI createUI(JComponent b) {
return new SynthRadioButtonUI(); return new SynthRadioButtonUI();
} }
/**
* @inheritDoc
*/
@Override
protected String getPropertyPrefix() { protected String getPropertyPrefix() {
return "RadioButton."; return "RadioButton.";
} }
/** /**
* Returns the Icon used in calculating the pref/min/max size. * Returns the Icon used in calculating the
* preferred/minimum/maximum size.
*/ */
@Override
protected Icon getSizingIcon(AbstractButton b) { protected Icon getSizingIcon(AbstractButton b) {
return getIcon(b); return getIcon(b);
} }
@Override
void paintBackground(SynthContext context, Graphics g, JComponent c) { void paintBackground(SynthContext context, Graphics g, JComponent c) {
context.getPainter().paintRadioButtonBackground(context, g, 0, 0, context.getPainter().paintRadioButtonBackground(context, g, 0, 0,
c.getWidth(), c.getHeight()); c.getWidth(), c.getHeight());
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintRadioButtonBorder(context, g, x, y, w, h); context.getPainter().paintRadioButtonBorder(context, g, x, y, w, h);

View file

@ -26,30 +26,43 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicRootPaneUI; import javax.swing.plaf.basic.BasicRootPaneUI;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's RootPaneUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JRootPane}.
* *
* @author Scott Violet * @author Scott Violet
* @since 1.7
*/ */
class SynthRootPaneUI extends BasicRootPaneUI implements SynthUI { public class SynthRootPaneUI extends BasicRootPaneUI implements SynthUI {
private SynthStyle style; private SynthStyle style;
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthRootPaneUI(); return new SynthRootPaneUI();
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults(JRootPane c){ protected void installDefaults(JRootPane c){
updateStyle(c); updateStyle(c);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults(JRootPane root) { protected void uninstallDefaults(JRootPane root) {
SynthContext context = getContext(root, ENABLED); SynthContext context = getContext(root, ENABLED);
@ -58,6 +71,10 @@ class SynthRootPaneUI extends BasicRootPaneUI implements SynthUI {
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -67,10 +84,6 @@ class SynthRootPaneUI extends BasicRootPaneUI implements SynthUI {
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
@ -88,6 +101,10 @@ class SynthRootPaneUI extends BasicRootPaneUI implements SynthUI {
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -98,6 +115,10 @@ class SynthRootPaneUI extends BasicRootPaneUI implements SynthUI {
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -105,9 +126,19 @@ class SynthRootPaneUI extends BasicRootPaneUI implements SynthUI {
context.dispose(); context.dispose();
} }
/**
* Paints the specified component. This implementation does nothing.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintRootPaneBorder(context, g, x, y, w, h); context.getPainter().paintRootPaneBorder(context, g, x, y, w, h);
@ -118,6 +149,7 @@ class SynthRootPaneUI extends BasicRootPaneUI implements SynthUI {
* indicates the <code>defaultButton</code> has changed, this will * indicates the <code>defaultButton</code> has changed, this will
* reinstall the keyboard actions. * reinstall the keyboard actions.
*/ */
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((JRootPane)e.getSource()); updateStyle((JRootPane)e.getSource());

View file

@ -30,41 +30,33 @@ import java.beans.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.*; import javax.swing.plaf.basic.*;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's ScrollBarUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JScrollBar}.
* *
* @author Scott Violet * @author Scott Violet
* @since 1.7
*/ */
class SynthScrollBarUI extends BasicScrollBarUI implements public class SynthScrollBarUI extends BasicScrollBarUI
PropertyChangeListener, SynthUI { implements PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
private SynthStyle thumbStyle; private SynthStyle thumbStyle;
private SynthStyle trackStyle; private SynthStyle trackStyle;
private boolean validMinimumThumbSize; private boolean validMinimumThumbSize;
private int scrollBarWidth;
//These two variables should be removed when the corrosponding ones in BasicScrollBarUI are made protected
private int incrGap;
private int decrGap;
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthScrollBarUI(); return new SynthScrollBarUI();
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults() { protected void installDefaults() {
//NOTE: This next line of code was added because, since incrGap and decrGap in
//BasicScrollBarUI are private, I need to have some way of updating them.
//This is an incomplete solution (since it implies that the incrGap and decrGap
//are set once, and not reset per state. Probably ok, but not always ok).
//This line of code should be removed at the same time that incrGap and
//decrGap are removed and made protected in the super class.
super.installDefaults();
trackHighlight = NO_HIGHLIGHT; trackHighlight = NO_HIGHLIGHT;
if (scrollbar.getLayout() == null || if (scrollbar.getLayout() == null ||
(scrollbar.getLayout() instanceof UIResource)) { (scrollbar.getLayout() instanceof UIResource)) {
@ -73,6 +65,10 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
updateStyle(scrollbar); updateStyle(scrollbar);
} }
/**
* @inheritDoc
*/
@Override
protected void configureScrollBarColors() { protected void configureScrollBarColors() {
} }
@ -137,16 +133,28 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
scrollbar.addPropertyChangeListener(this); scrollbar.addPropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
scrollbar.removePropertyChangeListener(this); scrollbar.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults(){ protected void uninstallDefaults(){
SynthContext context = getContext(scrollbar, ENABLED); SynthContext context = getContext(scrollbar, ENABLED);
style.uninstallDefaults(context); style.uninstallDefaults(context);
@ -166,9 +174,12 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
super.uninstallDefaults(); super.uninstallDefaults();
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, SynthLookAndFeel.getComponentState(c));
} }
private SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
@ -176,14 +187,6 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c);
}
private SynthContext getContext(JComponent c, Region region) { private SynthContext getContext(JComponent c, Region region) {
return getContext(c, region, getComponentState(c, region)); return getContext(c, region, getComponentState(c, region));
} }
@ -206,6 +209,10 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override
public boolean getSupportsAbsolutePositioning() { public boolean getSupportsAbsolutePositioning() {
SynthContext context = getContext(scrollbar); SynthContext context = getContext(scrollbar);
boolean value = style.getBoolean(context, boolean value = style.getBoolean(context,
@ -214,6 +221,10 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
return value; return value;
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -225,6 +236,10 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -232,6 +247,12 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
SynthContext subcontext = getContext(scrollbar, SynthContext subcontext = getContext(scrollbar,
Region.SCROLL_BAR_TRACK); Region.SCROLL_BAR_TRACK);
@ -243,31 +264,49 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
subcontext.dispose(); subcontext.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintScrollBarBorder(context, g, x, y, w, h, context.getPainter().paintScrollBarBorder(context, g, x, y, w, h,
scrollbar.getOrientation()); scrollbar.getOrientation());
} }
protected void paintTrack(SynthContext ss, Graphics g, /**
* Paints the scrollbar track.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
* @param trackBounds bounding box for the track
*/
protected void paintTrack(SynthContext context, Graphics g,
Rectangle trackBounds) { Rectangle trackBounds) {
SynthLookAndFeel.updateSubregion(ss, g, trackBounds); SynthLookAndFeel.updateSubregion(context, g, trackBounds);
ss.getPainter().paintScrollBarTrackBackground(ss, g, trackBounds.x, context.getPainter().paintScrollBarTrackBackground(context, g, trackBounds.x,
trackBounds.y, trackBounds.width, trackBounds.height, trackBounds.y, trackBounds.width, trackBounds.height,
scrollbar.getOrientation()); scrollbar.getOrientation());
ss.getPainter().paintScrollBarTrackBorder(ss, g, trackBounds.x, context.getPainter().paintScrollBarTrackBorder(context, g, trackBounds.x,
trackBounds.y, trackBounds.width, trackBounds.height, trackBounds.y, trackBounds.width, trackBounds.height,
scrollbar.getOrientation()); scrollbar.getOrientation());
} }
protected void paintThumb(SynthContext ss, Graphics g, /**
* Paints the scrollbar thumb.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
* @param thumbBounds bounding box for the thumb
*/
protected void paintThumb(SynthContext context, Graphics g,
Rectangle thumbBounds) { Rectangle thumbBounds) {
SynthLookAndFeel.updateSubregion(ss, g, thumbBounds); SynthLookAndFeel.updateSubregion(context, g, thumbBounds);
int orientation = scrollbar.getOrientation(); int orientation = scrollbar.getOrientation();
ss.getPainter().paintScrollBarThumbBackground(ss, g, thumbBounds.x, context.getPainter().paintScrollBarThumbBackground(context, g, thumbBounds.x,
thumbBounds.y, thumbBounds.width, thumbBounds.height, thumbBounds.y, thumbBounds.width, thumbBounds.height,
orientation); orientation);
ss.getPainter().paintScrollBarThumbBorder(ss, g, thumbBounds.x, context.getPainter().paintScrollBarThumbBorder(context, g, thumbBounds.x,
thumbBounds.y, thumbBounds.width, thumbBounds.height, thumbBounds.y, thumbBounds.width, thumbBounds.height,
orientation); orientation);
} }
@ -288,6 +327,7 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
* @see #getMaximumSize * @see #getMaximumSize
* @see #getMinimumSize * @see #getMinimumSize
*/ */
@Override
public Dimension getPreferredSize(JComponent c) { public Dimension getPreferredSize(JComponent c) {
Insets insets = c.getInsets(); Insets insets = c.getInsets();
return (scrollbar.getOrientation() == JScrollBar.VERTICAL) return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
@ -295,6 +335,10 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
: new Dimension(48, scrollBarWidth + insets.top + insets.bottom); : new Dimension(48, scrollBarWidth + insets.top + insets.bottom);
} }
/**
* @inheritDoc
*/
@Override
protected Dimension getMinimumThumbSize() { protected Dimension getMinimumThumbSize() {
if (!validMinimumThumbSize) { if (!validMinimumThumbSize) {
if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { if (scrollbar.getOrientation() == JScrollBar.VERTICAL) {
@ -308,6 +352,10 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
return minimumThumbSize; return minimumThumbSize;
} }
/**
* @inheritDoc
*/
@Override
protected JButton createDecreaseButton(int orientation) { protected JButton createDecreaseButton(int orientation) {
SynthArrowButton synthArrowButton = new SynthArrowButton(orientation) { SynthArrowButton synthArrowButton = new SynthArrowButton(orientation) {
@Override @Override
@ -333,6 +381,10 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
return synthArrowButton; return synthArrowButton;
} }
/**
* @inheritDoc
*/
@Override
protected JButton createIncreaseButton(int orientation) { protected JButton createIncreaseButton(int orientation) {
SynthArrowButton synthArrowButton = new SynthArrowButton(orientation) { SynthArrowButton synthArrowButton = new SynthArrowButton(orientation) {
@Override @Override
@ -360,6 +412,10 @@ class SynthScrollBarUI extends BasicScrollBarUI implements
return synthArrowButton; return synthArrowButton;
} }
/**
* @inheritDoc
*/
@Override
protected void setThumbRollover(boolean active) { protected void setThumbRollover(boolean active) {
if (isThumbRollover() != active) { if (isThumbRollover() != active) {
scrollbar.repaint(getThumbBounds()); scrollbar.repaint(getThumbBounds());

View file

@ -40,24 +40,32 @@ import java.awt.event.ContainerEvent;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's ScrollPaneUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JScrollPane}.
* *
* @author Scott Violet * @author Scott Violet
* @since 1.7
*/ */
class SynthScrollPaneUI extends BasicScrollPaneUI implements public class SynthScrollPaneUI extends BasicScrollPaneUI
PropertyChangeListener, SynthUI { implements PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
private boolean viewportViewHasFocus = false; private boolean viewportViewHasFocus = false;
private ViewportViewFocusHandler viewportViewFocusHandler; private ViewportViewFocusHandler viewportViewFocusHandler;
/**
* Creates a new UI object for the given component.
*
* @param x component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent x) { public static ComponentUI createUI(JComponent x) {
return new SynthScrollPaneUI(); return new SynthScrollPaneUI();
} }
/**
* @inheritDoc
*/
@Override @Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -69,6 +77,9 @@ class SynthScrollPaneUI extends BasicScrollPaneUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override @Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -77,6 +88,12 @@ class SynthScrollPaneUI extends BasicScrollPaneUI implements
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
Border vpBorder = scrollpane.getViewportBorder(); Border vpBorder = scrollpane.getViewportBorder();
if (vpBorder != null) { if (vpBorder != null) {
@ -85,12 +102,18 @@ class SynthScrollPaneUI extends BasicScrollPaneUI implements
} }
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintScrollPaneBorder(context, g, x, y, w, h); context.getPainter().paintScrollPaneBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override @Override
protected void installDefaults(JScrollPane scrollpane) { protected void installDefaults(JScrollPane scrollpane) {
updateStyle(scrollpane); updateStyle(scrollpane);
@ -114,7 +137,9 @@ class SynthScrollPaneUI extends BasicScrollPaneUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override @Override
protected void installListeners(JScrollPane c) { protected void installListeners(JScrollPane c) {
super.installListeners(c); super.installListeners(c);
@ -129,6 +154,9 @@ class SynthScrollPaneUI extends BasicScrollPaneUI implements
} }
} }
/**
* @inheritDoc
*/
@Override @Override
protected void uninstallDefaults(JScrollPane c) { protected void uninstallDefaults(JScrollPane c) {
SynthContext context = getContext(c, ENABLED); SynthContext context = getContext(c, ENABLED);
@ -141,7 +169,9 @@ class SynthScrollPaneUI extends BasicScrollPaneUI implements
} }
} }
/**
* @inheritDoc
*/
@Override @Override
protected void uninstallListeners(JComponent c) { protected void uninstallListeners(JComponent c) {
super.uninstallListeners(c); super.uninstallListeners(c);
@ -156,7 +186,10 @@ class SynthScrollPaneUI extends BasicScrollPaneUI implements
} }
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -166,12 +199,6 @@ class SynthScrollPaneUI extends BasicScrollPaneUI implements
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
int baseState = SynthLookAndFeel.getComponentState(c); int baseState = SynthLookAndFeel.getComponentState(c);
if (viewportViewFocusHandler!=null && viewportViewHasFocus){ if (viewportViewFocusHandler!=null && viewportViewHasFocus){

View file

@ -34,33 +34,51 @@ import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.SeparatorUI; import javax.swing.plaf.SeparatorUI;
import javax.swing.plaf.UIResource; import javax.swing.plaf.UIResource;
import javax.swing.plaf.DimensionUIResource; import javax.swing.plaf.DimensionUIResource;
import sun.swing.plaf.synth.SynthUI;
/** /**
* A Synth L&F implementation of SeparatorUI. This implementation * Provides the Synth L&F UI delegate for
* is a "combined" view/controller. * {@link javax.swing.JSeparator}.
* *
* @author Shannon Hickey * @author Shannon Hickey
* @author Joshua Outwater * @author Joshua Outwater
* @since 1.7
*/ */
class SynthSeparatorUI extends SeparatorUI implements PropertyChangeListener, public class SynthSeparatorUI extends SeparatorUI
SynthUI { implements PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthSeparatorUI(); return new SynthSeparatorUI();
} }
/**
* @inheritDoc
*/
@Override
public void installUI(JComponent c) { public void installUI(JComponent c) {
installDefaults((JSeparator)c); installDefaults((JSeparator)c);
installListeners((JSeparator)c); installListeners((JSeparator)c);
} }
public void uninstallDefaults(JComponent c) { /**
* @inheritDoc
*/
@Override
public void uninstallUI(JComponent c) {
uninstallListeners((JSeparator)c); uninstallListeners((JSeparator)c);
uninstallDefaults((JSeparator)c); uninstallDefaults((JSeparator)c);
} }
/**
* Installs default setting. This method is called when a
* {@code LookAndFeel} is installed.
*/
public void installDefaults(JSeparator c) { public void installDefaults(JSeparator c) {
updateStyle(c); updateStyle(c);
} }
@ -88,6 +106,10 @@ class SynthSeparatorUI extends SeparatorUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* Uninstalls default setting. This method is called when a
* {@code LookAndFeel} is uninstalled.
*/
public void uninstallDefaults(JSeparator c) { public void uninstallDefaults(JSeparator c) {
SynthContext context = getContext(c, ENABLED); SynthContext context = getContext(c, ENABLED);
@ -96,14 +118,26 @@ class SynthSeparatorUI extends SeparatorUI implements PropertyChangeListener,
style = null; style = null;
} }
/**
* Installs listeners. This method is called when a
* {@code LookAndFeel} is installed.
*/
public void installListeners(JSeparator c) { public void installListeners(JSeparator c) {
c.addPropertyChangeListener(this); c.addPropertyChangeListener(this);
} }
/**
* Uninstalls listeners. This method is called when a
* {@code LookAndFeel} is uninstalled.
*/
public void uninstallListeners(JSeparator c) { public void uninstallListeners(JSeparator c) {
c.removePropertyChangeListener(this); c.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -116,6 +150,10 @@ class SynthSeparatorUI extends SeparatorUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -123,6 +161,12 @@ class SynthSeparatorUI extends SeparatorUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
JSeparator separator = (JSeparator)context.getComponent(); JSeparator separator = (JSeparator)context.getComponent();
context.getPainter().paintSeparatorForeground(context, g, 0, 0, context.getPainter().paintSeparatorForeground(context, g, 0, 0,
@ -130,6 +174,10 @@ class SynthSeparatorUI extends SeparatorUI implements PropertyChangeListener,
separator.getOrientation()); separator.getOrientation());
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
JSeparator separator = (JSeparator)context.getComponent(); JSeparator separator = (JSeparator)context.getComponent();
@ -137,6 +185,10 @@ class SynthSeparatorUI extends SeparatorUI implements PropertyChangeListener,
separator.getOrientation()); separator.getOrientation());
} }
/**
* @inheritDoc
*/
@Override
public Dimension getPreferredSize(JComponent c) { public Dimension getPreferredSize(JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -155,16 +207,28 @@ class SynthSeparatorUI extends SeparatorUI implements PropertyChangeListener,
return size; return size;
} }
/**
* @inheritDoc
*/
@Override
public Dimension getMinimumSize(JComponent c) { public Dimension getMinimumSize(JComponent c) {
return getPreferredSize(c); return getPreferredSize(c);
} }
/**
* @inheritDoc
*/
@Override
public Dimension getMaximumSize(JComponent c) { public Dimension getMaximumSize(JComponent c) {
return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE); return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, SynthLookAndFeel.getComponentState(c));
} }
private SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
@ -172,14 +236,6 @@ class SynthSeparatorUI extends SeparatorUI implements PropertyChangeListener,
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c);
}
public void propertyChange(PropertyChangeEvent evt) { public void propertyChange(PropertyChangeEvent evt) {
if (SynthLookAndFeel.shouldUpdateStyle(evt)) { if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
updateStyle((JSeparator)evt.getSource()); updateStyle((JSeparator)evt.getSource());

View file

@ -38,20 +38,20 @@ import java.util.Enumeration;
import javax.swing.*; import javax.swing.*;
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.SwingUtilities2; import sun.swing.SwingUtilities2;
/** /**
* Synth's SliderUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JSlider}.
* *
* @author Joshua Outwater * @author Joshua Outwater
* @since 1.7
*/ */
class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener, public class SynthSliderUI extends BasicSliderUI
SynthUI { implements PropertyChangeListener, SynthUI {
protected Dimension contentDim = new Dimension(); private Rectangle valueRect = new Rectangle();
protected Rectangle valueRect = new Rectangle(); private boolean paintValue;
protected boolean paintValue;
/** /**
* When a JSlider is used as a renderer in a JTable, its layout is not * When a JSlider is used as a renderer in a JTable, its layout is not
@ -83,18 +83,32 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
// ComponentUI Interface Implementation methods // ComponentUI Interface Implementation methods
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthSliderUI((JSlider)c); return new SynthSliderUI((JSlider)c);
} }
public SynthSliderUI(JSlider c) { protected SynthSliderUI(JSlider c) {
super(c); super(c);
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults(JSlider slider) { protected void installDefaults(JSlider slider) {
updateStyle(slider); updateStyle(slider);
} }
/**
* Uninstalls default setting. This method is called when a
* {@code LookAndFeel} is uninstalled.
*/
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(slider, ENABLED); SynthContext context = getContext(slider, ENABLED);
style.uninstallDefaults(context); style.uninstallDefaults(context);
@ -112,11 +126,19 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
sliderThumbStyle = null; sliderThumbStyle = null;
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners(JSlider slider) { protected void installListeners(JSlider slider) {
super.installListeners(slider); super.installListeners(slider);
slider.addPropertyChangeListener(this); slider.addPropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners(JSlider slider) { protected void uninstallListeners(JSlider slider) {
slider.removePropertyChangeListener(this); slider.removePropertyChangeListener(this);
super.uninstallListeners(slider); super.uninstallListeners(slider);
@ -177,6 +199,10 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected TrackListener createTrackListener(JSlider s) { protected TrackListener createTrackListener(JSlider s) {
return new SynthTrackListener(); return new SynthTrackListener();
} }
@ -204,6 +230,10 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override
public int getBaseline(JComponent c, int width, int height) { public int getBaseline(JComponent c, int width, int height) {
if (c == null) { if (c == null) {
throw new NullPointerException("Component must be non-null"); throw new NullPointerException("Component must be non-null");
@ -271,9 +301,13 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
return -1; return -1;
} }
/**
* @inheritDoc
*/
@Override
public Dimension getPreferredSize(JComponent c) { public Dimension getPreferredSize(JComponent c) {
recalculateIfInsetsChanged(); recalculateIfInsetsChanged();
Dimension d = new Dimension(contentDim); Dimension d = new Dimension(contentRect.width, contentRect.height);
if (slider.getOrientation() == JSlider.VERTICAL) { if (slider.getOrientation() == JSlider.VERTICAL) {
d.height = 200; d.height = 200;
} else { } else {
@ -285,9 +319,13 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
return d; return d;
} }
/**
* @inheritDoc
*/
@Override
public Dimension getMinimumSize(JComponent c) { public Dimension getMinimumSize(JComponent c) {
recalculateIfInsetsChanged(); recalculateIfInsetsChanged();
Dimension d = new Dimension(contentDim); Dimension d = new Dimension(contentRect.width, contentRect.height);
if (slider.getOrientation() == JSlider.VERTICAL) { if (slider.getOrientation() == JSlider.VERTICAL) {
d.height = thumbRect.height + insetCache.top + insetCache.bottom; d.height = thumbRect.height + insetCache.top + insetCache.bottom;
} else { } else {
@ -296,11 +334,18 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
return d; return d;
} }
/**
* @inheritDoc
*/
@Override
protected void calculateGeometry() { protected void calculateGeometry() {
layout(); layout();
calculateThumbLocation(); calculateThumbLocation();
} }
/**
* Lays out the slider.
*/
protected void layout() { protected void layout() {
SynthContext context = getContext(slider); SynthContext context = getContext(slider);
SynthGraphicsUtils synthGraphics = style.getGraphicsUtils(context); SynthGraphicsUtils synthGraphics = style.getGraphicsUtils(context);
@ -336,10 +381,10 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
labelRect.height = getHeightOfTallestLabel(); labelRect.height = getHeightOfTallestLabel();
} }
contentDim.height = valueRect.height + trackRect.height contentRect.height = valueRect.height + trackRect.height
+ trackInsets.top + trackInsets.bottom + trackInsets.top + trackInsets.bottom
+ tickRect.height + labelRect.height + 4; + tickRect.height + labelRect.height + 4;
contentDim.width = slider.getWidth() - insetCache.left contentRect.width = slider.getWidth() - insetCache.left
- insetCache.right; - insetCache.right;
// Check if any of the labels will paint out of bounds. // Check if any of the labels will paint out of bounds.
@ -348,7 +393,7 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
// Calculate the track rectangle. It is necessary for // Calculate the track rectangle. It is necessary for
// xPositionForValue to return correct values. // xPositionForValue to return correct values.
trackRect.x = insetCache.left; trackRect.x = insetCache.left;
trackRect.width = contentDim.width; trackRect.width = contentRect.width;
Dictionary dictionary = slider.getLabelTable(); Dictionary dictionary = slider.getLabelTable();
if (dictionary != null) { if (dictionary != null) {
@ -381,9 +426,9 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
valueRect.x = trackRect.x = tickRect.x = labelRect.x = valueRect.x = trackRect.x = tickRect.x = labelRect.x =
(insetCache.left + pad); (insetCache.left + pad);
valueRect.width = trackRect.width = tickRect.width = valueRect.width = trackRect.width = tickRect.width =
labelRect.width = (contentDim.width - (pad * 2)); labelRect.width = (contentRect.width - (pad * 2));
int centerY = slider.getHeight() / 2 - contentDim.height / 2; int centerY = slider.getHeight() / 2 - contentRect.height / 2;
valueRect.y = centerY; valueRect.y = centerY;
centerY += valueRect.height + 2; centerY += valueRect.height + 2;
@ -430,18 +475,18 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
int w1 = trackInsets.left + trackRect.width / 2; int w1 = trackInsets.left + trackRect.width / 2;
int w2 = trackRect.width / 2 + trackInsets.right + int w2 = trackRect.width / 2 + trackInsets.right +
tickRect.width + labelRect.width; tickRect.width + labelRect.width;
contentDim.width = Math.max(w1, l) + Math.max(w2, l) + contentRect.width = Math.max(w1, l) + Math.max(w2, l) +
2 + insetCache.left + insetCache.right; 2 + insetCache.left + insetCache.right;
contentDim.height = slider.getHeight() - contentRect.height = slider.getHeight() -
insetCache.top - insetCache.bottom; insetCache.top - insetCache.bottom;
// Layout the components. // Layout the components.
trackRect.y = tickRect.y = labelRect.y = trackRect.y = tickRect.y = labelRect.y =
valueRect.y + valueRect.height; valueRect.y + valueRect.height;
trackRect.height = tickRect.height = labelRect.height = trackRect.height = tickRect.height = labelRect.height =
contentDim.height - valueRect.height; contentRect.height - valueRect.height;
int startX = slider.getWidth() / 2 - contentDim.width / 2; int startX = slider.getWidth() / 2 - contentRect.width / 2;
if (SynthLookAndFeel.isLeftToRight(slider)) { if (SynthLookAndFeel.isLeftToRight(slider)) {
if (l > w1) { if (l > w1) {
startX += (l - w1); startX += (l - w1);
@ -491,6 +536,10 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
return pad; return pad;
} }
/**
* @inheritDoc
*/
@Override
protected void calculateThumbLocation() { protected void calculateThumbLocation() {
super.calculateThumbLocation(); super.calculateThumbLocation();
if (slider.getOrientation() == JSlider.HORIZONTAL) { if (slider.getOrientation() == JSlider.HORIZONTAL) {
@ -504,6 +553,10 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override
protected void calculateTickRect() { protected void calculateTickRect() {
if (slider.getOrientation() == JSlider.HORIZONTAL) { if (slider.getOrientation() == JSlider.HORIZONTAL) {
tickRect.x = trackRect.x; tickRect.x = trackRect.x;
@ -533,6 +586,10 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override
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
@ -542,6 +599,10 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
setThumbActive(false); setThumbActive(false);
} }
/**
* @inheritDoc
*/
@Override
protected int xPositionForValue(int value) { protected int xPositionForValue(int value) {
int min = slider.getMinimum(); int min = slider.getMinimum();
int max = slider.getMaximum(); int max = slider.getMaximum();
@ -567,6 +628,10 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
return xPosition; return xPosition;
} }
/**
* @inheritDoc
*/
@Override
protected int yPositionForValue(int value, int trackY, int trackHeight) { protected int yPositionForValue(int value, int trackY, int trackHeight) {
int min = slider.getMinimum(); int min = slider.getMinimum();
int max = slider.getMaximum(); int max = slider.getMaximum();
@ -593,10 +658,9 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
} }
/** /**
* Returns a value give a y position. If yPos is past the track at the * @inheritDoc
* top or the bottom it will set the value to the min or max of the
* slider, depending if the slider is inverted or not.
*/ */
@Override
public int valueForYPosition(int yPos) { public int valueForYPosition(int yPos) {
int value; int value;
int minValue = slider.getMinimum(); int minValue = slider.getMinimum();
@ -623,10 +687,9 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
} }
/** /**
* Returns a value give an x position. If xPos is past the track at the * @inheritDoc
* left or the right it will set the value to the min or max of the
* slider, depending if the slider is inverted or not.
*/ */
@Override
public int valueForXPosition(int xPos) { public int valueForXPosition(int xPos) {
int value; int value;
int minValue = slider.getMinimum(); int minValue = slider.getMinimum();
@ -652,6 +715,10 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
return value; return value;
} }
/**
* @inheritDoc
*/
@Override
protected Dimension getThumbSize() { protected Dimension getThumbSize() {
Dimension size = new Dimension(); Dimension size = new Dimension();
@ -665,6 +732,10 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
return size; return size;
} }
/**
* @inheritDoc
*/
@Override
protected void recalculateIfInsetsChanged() { protected void recalculateIfInsetsChanged() {
SynthContext context = getContext(slider); SynthContext context = getContext(slider);
Insets newInsets = style.getInsets(context, null); Insets newInsets = style.getInsets(context, null);
@ -678,20 +749,20 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
public Region getRegion(JComponent c) { /**
return SynthLookAndFeel.getRegion(c); * @inheritDoc
} */
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, SynthLookAndFeel.getComponentState(c));
} }
public SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c, return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
public SynthContext getContext(JComponent c, Region subregion) { private SynthContext getContext(JComponent c, Region subregion) {
return getContext(c, subregion, getComponentState(c, subregion)); return getContext(c, subregion, getComponentState(c, subregion));
} }
@ -707,10 +778,6 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
return SynthContext.getContext(klass, c, subregion, style, state); return SynthContext.getContext(klass, c, subregion, style, state);
} }
public int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c);
}
private int getComponentState(JComponent c, Region region) { private int getComponentState(JComponent c, Region region) {
if (region == Region.SLIDER_THUMB && thumbActive &&c.isEnabled()) { if (region == Region.SLIDER_THUMB && thumbActive &&c.isEnabled()) {
int state = thumbPressed ? PRESSED : MOUSE_OVER; int state = thumbPressed ? PRESSED : MOUSE_OVER;
@ -720,6 +787,10 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
SynthLookAndFeel.update(context, g); SynthLookAndFeel.update(context, g);
@ -730,13 +801,23 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
paint(context, g); paint(context, g);
context.dispose(); context.dispose();
} }
public void paint(SynthContext context, Graphics g) { /**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) {
recalculateIfInsetsChanged(); recalculateIfInsetsChanged();
recalculateIfOrientationChanged(); recalculateIfOrientationChanged();
Rectangle clip = g.getClipBounds(); Rectangle clip = g.getClipBounds();
@ -755,8 +836,8 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
// For horizontal sliders, make sure value is not painted // For horizontal sliders, make sure value is not painted
// outside slider bounds. // outside slider bounds.
if (slider.getOrientation() == JSlider.HORIZONTAL) { if (slider.getOrientation() == JSlider.HORIZONTAL) {
if (valueRect.x + labelWidth > insetCache.left + contentDim.width) { if (valueRect.x + labelWidth > insetCache.left + contentRect.width) {
valueRect.x = (insetCache.left + contentDim.width) - labelWidth; valueRect.x = (insetCache.left + contentRect.width) - labelWidth;
} }
valueRect.x = Math.max(valueRect.x, 0); valueRect.x = Math.max(valueRect.x, 0);
} }
@ -785,13 +866,24 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintSliderBorder(context, g, x, y, w, h, context.getPainter().paintSliderBorder(context, g, x, y, w, h,
slider.getOrientation()); slider.getOrientation());
} }
public void paintThumb(SynthContext context, Graphics g, /**
* Paints the slider thumb.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
* @param thumbBounds bounding box for the thumb
*/
protected void paintThumb(SynthContext context, Graphics g,
Rectangle thumbBounds) { Rectangle thumbBounds) {
int orientation = slider.getOrientation(); int orientation = slider.getOrientation();
SynthLookAndFeel.updateSubregion(context, g, thumbBounds); SynthLookAndFeel.updateSubregion(context, g, thumbBounds);
@ -803,7 +895,14 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
thumbBounds.height, orientation); thumbBounds.height, orientation);
} }
public void paintTrack(SynthContext context, Graphics g, /**
* Paints the slider track.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
* @param trackBounds bounding box for the track
*/
protected void paintTrack(SynthContext context, Graphics g,
Rectangle trackBounds) { Rectangle trackBounds) {
int orientation = slider.getOrientation(); int orientation = slider.getOrientation();
SynthLookAndFeel.updateSubregion(context, g, trackBounds); SynthLookAndFeel.updateSubregion(context, g, trackBounds);
@ -815,6 +914,10 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
trackBounds.height, orientation); trackBounds.height, orientation);
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((JSlider)e.getSource()); updateStyle((JSlider)e.getSource());
@ -827,23 +930,23 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
/** /**
* Track mouse movements. * Track mouse movements.
*/ */
protected class SynthTrackListener extends TrackListener { private class SynthTrackListener extends TrackListener {
public void mouseExited(MouseEvent e) { @Override public void mouseExited(MouseEvent e) {
setThumbActive(false); setThumbActive(false);
} }
public void mousePressed(MouseEvent e) { @Override public void mousePressed(MouseEvent e) {
super.mousePressed(e); super.mousePressed(e);
setThumbPressed(thumbRect.contains(e.getX(), e.getY())); setThumbPressed(thumbRect.contains(e.getX(), e.getY()));
} }
public void mouseReleased(MouseEvent e) { @Override public void mouseReleased(MouseEvent e) {
super.mouseReleased(e); super.mouseReleased(e);
updateThumbState(e.getX(), e.getY(), false); updateThumbState(e.getX(), e.getY(), false);
} }
public void mouseDragged(MouseEvent e) { @Override public void mouseDragged(MouseEvent e) {
int thumbMiddle; int thumbMiddle;
if (!slider.isEnabled()) { if (!slider.isEnabled()) {
@ -914,7 +1017,7 @@ class SynthSliderUI extends BasicSliderUI implements PropertyChangeListener,
} }
} }
public void mouseMoved(MouseEvent e) { @Override public void mouseMoved(MouseEvent e) {
updateThumbState(e.getX(), e.getY()); updateThumbState(e.getX(), e.getY());
} }
} }

View file

@ -26,22 +26,21 @@ package javax.swing.plaf.synth;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicSpinnerUI; import javax.swing.plaf.basic.BasicSpinnerUI;
import java.beans.*; import java.beans.*;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's SpinnerUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JSpinner}.
* *
* @author Hans Muller * @author Hans Muller
* @author Joshua Outwater * @author Joshua Outwater
* @since 1.7
*/ */
class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener, public class SynthSpinnerUI extends BasicSpinnerUI
SynthUI { implements PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
/** /**
* A FocusListener implementation which causes the entire spinner to be * A FocusListener implementation which causes the entire spinner to be
@ -65,6 +64,9 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
return new SynthSpinnerUI(); return new SynthSpinnerUI();
} }
/**
* @inheritDoc
*/
@Override @Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
@ -79,12 +81,7 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
} }
/** /**
* Removes the <code>propertyChangeListener</code> added * @inheritDoc
* by installListeners.
* <p>
* This method is called by <code>uninstallUI</code>.
*
* @see #installListeners
*/ */
@Override @Override
protected void uninstallListeners() { protected void uninstallListeners() {
@ -100,7 +97,7 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
} }
/** /**
* Initialize the <code>JSpinner</code> <code>border</code>, * Initializes the <code>JSpinner</code> <code>border</code>,
* <code>foreground</code>, and <code>background</code>, properties * <code>foreground</code>, and <code>background</code>, properties
* based on the corresponding "Spinner.*" properties from defaults table. * based on the corresponding "Spinner.*" properties from defaults table.
* The <code>JSpinners</code> layout is set to the value returned by * The <code>JSpinners</code> layout is set to the value returned by
@ -112,6 +109,7 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
* @see LookAndFeel#installBorder * @see LookAndFeel#installBorder
* @see LookAndFeel#installColors * @see LookAndFeel#installColors
*/ */
@Override
protected void installDefaults() { protected void installDefaults() {
LayoutManager layout = spinner.getLayout(); LayoutManager layout = spinner.getLayout();
@ -144,6 +142,7 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
* @see #installDefaults * @see #installDefaults
* @see #uninstallUI * @see #uninstallUI
*/ */
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
if (spinner.getLayout() instanceof UIResource) { if (spinner.getLayout() instanceof UIResource) {
spinner.setLayout(null); spinner.setLayout(null);
@ -156,25 +155,19 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override
protected LayoutManager createLayout() { protected LayoutManager createLayout() {
return new SpinnerLayout(); return new SpinnerLayout();
} }
/** /**
* Create a component that will replace the spinner models value * @inheritDoc
* with the object returned by <code>spinner.getPreviousValue</code>.
* By default the <code>previousButton</code> is a JButton
* who's <code>ActionListener</code> updates it's <code>JSpinner</code>
* ancestors model. If a previousButton isn't needed (in a subclass)
* then override this method to return null.
*
* @return a component that will replace the spinners model with the
* next value in the sequence, or null
* @see #installUI
* @see #createNextButton
*/ */
@Override
protected Component createPreviousButton() { protected Component createPreviousButton() {
JButton b = new SynthArrowButton(SwingConstants.SOUTH); JButton b = new SynthArrowButton(SwingConstants.SOUTH);
b.setName("Spinner.previousButton"); b.setName("Spinner.previousButton");
@ -184,18 +177,9 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
/** /**
* Create a component that will replace the spinner models value * @inheritDoc
* with the object returned by <code>spinner.getNextValue</code>.
* By default the <code>nextButton</code> is a JButton
* who's <code>ActionListener</code> updates it's <code>JSpinner</code>
* ancestors model. If a nextButton isn't needed (in a subclass)
* then override this method to return null.
*
* @return a component that will replace the spinners model with the
* next value in the sequence, or null
* @see #installUI
* @see #createPreviousButton
*/ */
@Override
protected Component createNextButton() { protected Component createNextButton() {
JButton b = new SynthArrowButton(SwingConstants.NORTH); JButton b = new SynthArrowButton(SwingConstants.NORTH);
b.setName("Spinner.nextButton"); b.setName("Spinner.nextButton");
@ -227,6 +211,7 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
* @see #replaceEditor * @see #replaceEditor
* @see JSpinner#getEditor * @see JSpinner#getEditor
*/ */
@Override
protected JComponent createEditor() { protected JComponent createEditor() {
JComponent editor = spinner.getEditor(); JComponent editor = spinner.getEditor();
editor.setName("Spinner.editor"); editor.setName("Spinner.editor");
@ -250,6 +235,7 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
* @see #createEditor * @see #createEditor
* @see #createPropertyChangeListener * @see #createPropertyChangeListener
*/ */
@Override
protected void replaceEditor(JComponent oldEditor, JComponent newEditor) { protected void replaceEditor(JComponent oldEditor, JComponent newEditor) {
spinner.remove(oldEditor); spinner.remove(oldEditor);
spinner.add(newEditor, "Editor"); spinner.add(newEditor, "Editor");
@ -283,8 +269,12 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, SynthLookAndFeel.getComponentState(c));
} }
private SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
@ -292,17 +282,10 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
/**
private Region getRegion(JComponent c) { * @inheritDoc
return SynthLookAndFeel.getRegion(c); */
} @Override
private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c);
}
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -314,6 +297,10 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -321,10 +308,19 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* Paints the specified component. This implementation does nothing.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintSpinnerBorder(context, g, x, y, w, h); context.getPainter().paintSpinnerBorder(context, g, x, y, w, h);
@ -426,9 +422,11 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
String propertyName = e.getPropertyName();
JSpinner spinner = (JSpinner)(e.getSource()); JSpinner spinner = (JSpinner)(e.getSource());
SpinnerUI spinnerUI = spinner.getUI(); SpinnerUI spinnerUI = spinner.getUI();
@ -444,34 +442,13 @@ class SynthSpinnerUI extends BasicSpinnerUI implements PropertyChangeListener,
/** Listen to editor text field focus changes and repaint whole spinner */ /** Listen to editor text field focus changes and repaint whole spinner */
private class EditorFocusHandler implements FocusListener{ private class EditorFocusHandler implements FocusListener{
/** Invoked when a editor text field gains the keyboard focus. */ /** Invoked when a editor text field gains the keyboard focus. */
public void focusGained(FocusEvent e) { @Override public void focusGained(FocusEvent e) {
spinner.repaint(); spinner.repaint();
} }
/** Invoked when a editor text field loses the keyboard focus. */ /** Invoked when a editor text field loses the keyboard focus. */
public void focusLost(FocusEvent e) { @Override public void focusLost(FocusEvent e) {
spinner.repaint(); spinner.repaint();
} }
} }
/** Override the arrowbuttons focus handling to follow the text fields focus */
private class SpinnerArrowButton extends SynthArrowButton{
public SpinnerArrowButton(int direction) {
super(direction);
}
@Override
public boolean isFocusOwner() {
if (spinner == null){
return super.isFocusOwner();
} else if (spinner.getEditor() instanceof JSpinner.DefaultEditor){
return ((JSpinner.DefaultEditor)spinner.getEditor())
.getTextField().isFocusOwner();
} else if (spinner.getEditor()!= null) {
return spinner.getEditor().isFocusOwner();
} else {
return super.isFocusOwner();
}
}
}
} }

View file

@ -31,19 +31,19 @@ import java.awt.event.*;
import java.beans.*; import java.beans.*;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.*; import javax.swing.plaf.basic.*;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's SplitPaneUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JSplitPane}.
* *
* @author Scott Violet * @author Scott Violet
* @since 1.7
*/ */
class SynthSplitPaneUI extends BasicSplitPaneUI implements public class SynthSplitPaneUI extends BasicSplitPaneUI
PropertyChangeListener, SynthUI { implements PropertyChangeListener, SynthUI {
/** /**
* Keys to use for forward focus traversal when the JComponent is * Keys to use for forward focus traversal when the JComponent is
* managing focus. * managing focus.
@ -68,6 +68,9 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements
/** /**
* Creates a new SynthSplitPaneUI instance * Creates a new SynthSplitPaneUI instance
*
* @param x component to create UI object for
* @return the UI object
*/ */
public static ComponentUI createUI(JComponent x) { public static ComponentUI createUI(JComponent x) {
return new SynthSplitPaneUI(); return new SynthSplitPaneUI();
@ -76,6 +79,7 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements
/** /**
* Installs the UI defaults. * Installs the UI defaults.
*/ */
@Override
protected void installDefaults() { protected void installDefaults() {
updateStyle(splitPane); updateStyle(splitPane);
@ -161,6 +165,7 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements
/** /**
* Installs the event listeners for the UI. * Installs the event listeners for the UI.
*/ */
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
splitPane.addPropertyChangeListener(this); splitPane.addPropertyChangeListener(this);
@ -169,6 +174,7 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements
/** /**
* Uninstalls the UI defaults. * Uninstalls the UI defaults.
*/ */
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(splitPane, ENABLED); SynthContext context = getContext(splitPane, ENABLED);
@ -186,16 +192,20 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements
/** /**
* Uninstalls the event listeners for the UI. * Uninstalls the event listeners from the UI.
*/ */
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
splitPane.removePropertyChangeListener(this); splitPane.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, SynthLookAndFeel.getComponentState(c));
} }
private SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
@ -203,14 +213,6 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c);
}
SynthContext getContext(JComponent c, Region region) { SynthContext getContext(JComponent c, Region region) {
return getContext(c, region, getComponentState(c, region)); return getContext(c, region, getComponentState(c, region));
} }
@ -233,7 +235,10 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements
return state; return state;
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((JSplitPane)e.getSource()); updateStyle((JSplitPane)e.getSource());
@ -243,6 +248,7 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements
/** /**
* Creates the default divider. * Creates the default divider.
*/ */
@Override
public BasicSplitPaneDivider createDefaultDivider() { public BasicSplitPaneDivider createDefaultDivider() {
SynthSplitPaneDivider divider = new SynthSplitPaneDivider(this); SynthSplitPaneDivider divider = new SynthSplitPaneDivider(this);
@ -250,6 +256,10 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements
return divider; return divider;
} }
/**
* @inheritDoc
*/
@Override
protected Component createDefaultNonContinuousLayoutDivider() { protected Component createDefaultNonContinuousLayoutDivider() {
return new Canvas() { return new Canvas() {
public void paint(Graphics g) { public void paint(Graphics g) {
@ -258,6 +268,10 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements
}; };
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -268,6 +282,10 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -275,13 +293,22 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements
context.dispose(); context.dispose();
} }
/**
* Paints the specified component. This implementation does nothing.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
// This is done to update package private variables in // This is done to update package private variables in
// BasicSplitPaneUI // BasicSplitPaneUI
super.paint(g, splitPane); super.paint(g, splitPane);
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintSplitPaneBorder(context, g, x, y, w, h); context.getPainter().paintSplitPaneBorder(context, g, x, y, w, h);
@ -299,6 +326,10 @@ class SynthSplitPaneUI extends BasicSplitPaneUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void finishedPaintingChildren(JSplitPane jc, Graphics g) { public void finishedPaintingChildren(JSplitPane jc, Graphics g) {
if(jc == splitPane && getLastDragLocation() != -1 && if(jc == splitPane && getLastDragLocation() != -1 &&
!isContinuousLayout() && !draggingHW) { !isContinuousLayout() && !draggingHW) {

View file

@ -33,7 +33,6 @@ import javax.swing.text.DefaultEditorKit;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.swing.text.JTextComponent; import javax.swing.text.JTextComponent;
import sun.swing.plaf.synth.SynthUI;
/** /**
* <code>SynthStyle</code> is a set of style properties. * <code>SynthStyle</code> is a set of style properties.

View file

@ -24,10 +24,7 @@
*/ */
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import java.awt.*; import javax.swing.JComponent;
import java.util.*;
import javax.swing.plaf.*;
import javax.swing.*;
/** /**
* Factory used for obtaining <code>SynthStyle</code>s. Each of the * Factory used for obtaining <code>SynthStyle</code>s. Each of the

View file

@ -34,19 +34,21 @@ import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import sun.swing.plaf.synth.SynthUI;
import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2;
/** /**
* A Synth L&F implementation of TabbedPaneUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JTabbedPane}.
*
* <p>Looks up the {@code selectedTabPadInsets} property from the Style,
* which represents additional insets for the selected tab.
* *
* @author Scott Violet * @author Scott Violet
* @since 1.7
*/ */
/** public class SynthTabbedPaneUI extends BasicTabbedPaneUI
* Looks up 'selectedTabPadInsets' from the Style, which will be additional implements PropertyChangeListener, SynthUI {
* insets for the selected tab.
*/
class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyChangeListener {
/** /**
* <p>If non-zero, tabOverlap indicates the amount that the tab bounds * <p>If non-zero, tabOverlap indicates the amount that the tab bounds
* should be altered such that they would overlap with a tab on either the * should be altered such that they would overlap with a tab on either the
@ -103,11 +105,17 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
private boolean selectedTabIsPressed = false; private boolean selectedTabIsPressed = false;
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthTabbedPaneUI(); return new SynthTabbedPaneUI();
} }
SynthTabbedPaneUI() { private SynthTabbedPaneUI() {
textRect = new Rectangle(); textRect = new Rectangle();
iconRect = new Rectangle(); iconRect = new Rectangle();
} }
@ -116,6 +124,10 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
return (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT); return (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT);
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults() { protected void installDefaults() {
updateStyle(tabPane); updateStyle(tabPane);
} }
@ -175,16 +187,28 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
tabContentStyle.getInsets(tabContentContext, null); tabContentStyle.getInsets(tabContentContext, null);
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
tabPane.addPropertyChangeListener(this); tabPane.addPropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
tabPane.removePropertyChangeListener(this); tabPane.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(tabPane, ENABLED); SynthContext context = getContext(tabPane, ENABLED);
style.uninstallDefaults(context); style.uninstallDefaults(context);
@ -207,19 +231,19 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
tabContentStyle = null; tabContentStyle = null;
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, SynthLookAndFeel.getComponentState(c));
} }
public SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
return SynthContext.getContext(SynthContext.class, c, return SynthContext.getContext(SynthContext.class, c,
SynthLookAndFeel.getRegion(c),style, state); SynthLookAndFeel.getRegion(c),style, state);
} }
public SynthContext getContext(JComponent c, Region subregion) {
return getContext(c, subregion, getComponentState(c));
}
private SynthContext getContext(JComponent c, Region subregion, int state){ private SynthContext getContext(JComponent c, Region subregion, int state){
SynthStyle style = null; SynthStyle style = null;
Class klass = SynthContext.class; Class klass = SynthContext.class;
@ -236,14 +260,10 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
return SynthContext.getContext(klass, c, subregion, style, state); return SynthContext.getContext(klass, c, subregion, style, state);
} }
private Region getRegion(JComponent c) { /**
return SynthLookAndFeel.getRegion(c); * @inheritDoc
} */
@Override
private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c);
}
protected JButton createScrollButton(int direction) { protected JButton createScrollButton(int direction) {
// added for Nimbus LAF so that it can use the basic arrow buttons // added for Nimbus LAF so that it can use the basic arrow buttons
// UIManager is queried directly here because this is called before // UIManager is queried directly here because this is called before
@ -256,6 +276,10 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
return new SynthScrollableTabButton(direction); return new SynthScrollableTabButton(direction);
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle(tabPane); updateStyle(tabPane);
@ -313,6 +337,9 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
}; };
} }
/**
* @inheritDoc
*/
@Override @Override
protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) { protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) {
if (nudgeSelectedLabel) { if (nudgeSelectedLabel) {
@ -322,6 +349,9 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
} }
} }
/**
* @inheritDoc
*/
@Override @Override
protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) { protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) {
if (nudgeSelectedLabel) { if (nudgeSelectedLabel) {
@ -331,6 +361,10 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
} }
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -341,6 +375,10 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected int getBaseline(int tab) { protected int getBaseline(int tab) {
if (tabPane.getTabComponentAt(tab) != null || if (tabPane.getTabComponentAt(tab) != null ||
getTextViewForTab(tab) != null) { getTextViewForTab(tab) != null) {
@ -361,11 +399,19 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
return textRect.y + metrics.getAscent() + getBaselineOffset(); return textRect.y + metrics.getAscent() + getBaselineOffset();
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintTabbedPaneBorder(context, g, x, y, w, h); context.getPainter().paintTabbedPaneBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -373,6 +419,12 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
int selectedIndex = tabPane.getSelectedIndex(); int selectedIndex = tabPane.getSelectedIndex();
int tabPlacement = tabPane.getTabPlacement(); int tabPlacement = tabPane.getTabPlacement();
@ -426,6 +478,10 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
} }
/**
* @inheritDoc
*/
@Override
protected void paintTabArea(Graphics g, int tabPlacement, protected void paintTabArea(Graphics g, int tabPlacement,
int selectedIndex) { int selectedIndex) {
// This can be invoked from ScrollabeTabPanel // This can be invoked from ScrollabeTabPanel
@ -439,7 +495,7 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
new Rectangle(x, y, width, height)); new Rectangle(x, y, width, height));
} }
protected void paintTabArea(SynthContext ss, Graphics g, private void paintTabArea(SynthContext ss, Graphics g,
int tabPlacement, int selectedIndex, int tabPlacement, int selectedIndex,
Rectangle tabAreaBounds) { Rectangle tabAreaBounds) {
Rectangle clipRect = g.getClipBounds(); Rectangle clipRect = g.getClipBounds();
@ -493,6 +549,10 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
} }
} }
/**
* @inheritDoc
*/
@Override
protected void setRolloverTab(int index) { protected void setRolloverTab(int index) {
int oldRolloverTab = getRolloverTab(); int oldRolloverTab = getRolloverTab();
super.setRolloverTab(index); super.setRolloverTab(index);
@ -519,7 +579,7 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
} }
} }
protected void paintTab(SynthContext ss, Graphics g, private void paintTab(SynthContext ss, Graphics g,
int tabPlacement, Rectangle[] rects, int tabIndex, int tabPlacement, Rectangle[] rects, int tabIndex,
Rectangle iconRect, Rectangle textRect) { Rectangle iconRect, Rectangle textRect) {
Rectangle tabRect = rects[tabIndex]; Rectangle tabRect = rects[tabIndex];
@ -587,7 +647,7 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
} }
} }
protected void layoutLabel(SynthContext ss, int tabPlacement, private void layoutLabel(SynthContext ss, int tabPlacement,
FontMetrics metrics, int tabIndex, FontMetrics metrics, int tabIndex,
String title, Icon icon, String title, Icon icon,
Rectangle tabRect, Rectangle iconRect, Rectangle tabRect, Rectangle iconRect,
@ -614,7 +674,7 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
textRect.y += yNudge; textRect.y += yNudge;
} }
protected void paintText(SynthContext ss, private void paintText(SynthContext ss,
Graphics g, int tabPlacement, Graphics g, int tabPlacement,
Font font, FontMetrics metrics, int tabIndex, Font font, FontMetrics metrics, int tabIndex,
String title, Rectangle textRect, String title, Rectangle textRect,
@ -636,7 +696,7 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
} }
protected void paintContentBorder(SynthContext ss, Graphics g, private void paintContentBorder(SynthContext ss, Graphics g,
int tabPlacement, int selectedIndex) { int tabPlacement, int selectedIndex) {
int width = tabPane.getWidth(); int width = tabPane.getWidth();
int height = tabPane.getHeight(); int height = tabPane.getHeight();
@ -683,7 +743,10 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
} }
} }
/**
* @inheritDoc
*/
@Override
protected int calculateMaxTabHeight(int tabPlacement) { protected int calculateMaxTabHeight(int tabPlacement) {
FontMetrics metrics = getFontMetrics(tabContext.getStyle().getFont( FontMetrics metrics = getFontMetrics(tabContext.getStyle().getFont(
tabContext)); tabContext));
@ -696,6 +759,10 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
return result; return result;
} }
/**
* @inheritDoc
*/
@Override
protected int calculateTabWidth(int tabPlacement, int tabIndex, protected int calculateTabWidth(int tabPlacement, int tabIndex,
FontMetrics metrics) { FontMetrics metrics) {
Icon icon = getIconForTab(tabIndex); Icon icon = getIconForTab(tabIndex);
@ -723,6 +790,10 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
return width; return width;
} }
/**
* @inheritDoc
*/
@Override
protected int calculateMaxTabWidth(int tabPlacement) { protected int calculateMaxTabWidth(int tabPlacement) {
FontMetrics metrics = getFontMetrics(tabContext.getStyle().getFont( FontMetrics metrics = getFontMetrics(tabContext.getStyle().getFont(
tabContext)); tabContext));
@ -735,17 +806,25 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
return result; return result;
} }
/**
* @inheritDoc
*/
@Override
protected Insets getTabInsets(int tabPlacement, int tabIndex) { protected Insets getTabInsets(int tabPlacement, int tabIndex) {
updateTabContext(tabIndex, false, false, false, updateTabContext(tabIndex, false, false, false,
(getFocusIndex() == tabIndex)); (getFocusIndex() == tabIndex));
return tabInsets; return tabInsets;
} }
/**
* @inheritDoc
*/
@Override
protected FontMetrics getFontMetrics() { protected FontMetrics getFontMetrics() {
return getFontMetrics(tabContext.getStyle().getFont(tabContext)); return getFontMetrics(tabContext.getStyle().getFont(tabContext));
} }
protected FontMetrics getFontMetrics(Font font) { private FontMetrics getFontMetrics(Font font) {
return tabPane.getFontMetrics(font); return tabPane.getFontMetrics(font);
} }
@ -787,7 +866,8 @@ class SynthTabbedPaneUI extends BasicTabbedPaneUI implements SynthUI, PropertyCh
* Overridden to create a TabbedPaneLayout subclass which takes into * Overridden to create a TabbedPaneLayout subclass which takes into
* account tabOverlap. * account tabOverlap.
*/ */
@Override protected LayoutManager createLayoutManager() { @Override
protected LayoutManager createLayoutManager() {
if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) { if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) {
return super.createLayoutManager(); return super.createLayoutManager();
} else { /* WRAP_TAB_LAYOUT */ } else { /* WRAP_TAB_LAYOUT */

View file

@ -32,19 +32,18 @@ import javax.swing.border.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.*; import javax.swing.plaf.basic.*;
import javax.swing.table.*; import javax.swing.table.*;
import sun.swing.DefaultLookup;
import sun.swing.plaf.synth.*;
import sun.swing.table.*; import sun.swing.table.*;
/** /**
* SynthTableHeaderUI implementation * Provides the Synth L&F UI delegate for
* {@link javax.swing.table.JTableHeader}.
* *
* @author Alan Chung * @author Alan Chung
* @author Philip Milne * @author Philip Milne
* @since 1.7
*/ */
class SynthTableHeaderUI extends BasicTableHeaderUI implements public class SynthTableHeaderUI extends BasicTableHeaderUI
PropertyChangeListener, SynthUI { implements PropertyChangeListener, SynthUI {
// //
// Instance Variables // Instance Variables
@ -54,10 +53,20 @@ class SynthTableHeaderUI extends BasicTableHeaderUI implements
private SynthStyle style; private SynthStyle style;
/**
* Creates a new UI object for the given component.
*
* @param h component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent h) { public static ComponentUI createUI(JComponent h) {
return new SynthTableHeaderUI(); return new SynthTableHeaderUI();
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults() { protected void installDefaults() {
prevRenderer = header.getDefaultRenderer(); prevRenderer = header.getDefaultRenderer();
if (prevRenderer instanceof UIResource) { if (prevRenderer instanceof UIResource) {
@ -79,11 +88,19 @@ class SynthTableHeaderUI extends BasicTableHeaderUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
header.addPropertyChangeListener(this); header.addPropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
if (header.getDefaultRenderer() instanceof HeaderRenderer) { if (header.getDefaultRenderer() instanceof HeaderRenderer) {
header.setDefaultRenderer(prevRenderer); header.setDefaultRenderer(prevRenderer);
@ -96,11 +113,19 @@ class SynthTableHeaderUI extends BasicTableHeaderUI implements
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
header.removePropertyChangeListener(this); header.removePropertyChangeListener(this);
super.uninstallListeners(); super.uninstallListeners();
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -111,6 +136,10 @@ class SynthTableHeaderUI extends BasicTableHeaderUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -118,10 +147,20 @@ class SynthTableHeaderUI extends BasicTableHeaderUI implements
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
super.paint(g, context.getComponent()); super.paint(g, context.getComponent());
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintTableHeaderBorder(context, g, x, y, w, h); context.getPainter().paintTableHeaderBorder(context, g, x, y, w, h);
@ -129,8 +168,12 @@ class SynthTableHeaderUI extends BasicTableHeaderUI implements
// //
// SynthUI // SynthUI
// //
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, SynthLookAndFeel.getComponentState(c));
} }
private SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
@ -138,26 +181,25 @@ class SynthTableHeaderUI extends BasicTableHeaderUI implements
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) { /**
return SynthLookAndFeel.getRegion(c); * @inheritDoc
} */
private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c);
}
public void propertyChange(PropertyChangeEvent evt) {
if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
updateStyle((JTableHeader)evt.getSource());
}
}
@Override @Override
protected void rolloverColumnUpdated(int oldColumn, int newColumn) { protected void rolloverColumnUpdated(int oldColumn, int newColumn) {
header.repaint(header.getHeaderRect(oldColumn)); header.repaint(header.getHeaderRect(oldColumn));
header.repaint(header.getHeaderRect(newColumn)); header.repaint(header.getHeaderRect(newColumn));
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
updateStyle((JTableHeader)evt.getSource());
}
}
private class HeaderRenderer extends DefaultTableCellHeaderRenderer { private class HeaderRenderer extends DefaultTableCellHeaderRenderer {
HeaderRenderer() { HeaderRenderer() {
setHorizontalAlignment(JLabel.LEADING); setHorizontalAlignment(JLabel.LEADING);

View file

@ -54,15 +54,15 @@ import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn; import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel; import javax.swing.table.TableColumnModel;
import sun.swing.plaf.synth.SynthUI;
/** /**
* SynthTableUI implementation * Provides the Synth L&F UI delegate for
* {@link javax.swing.JTable}.
* *
* @author Philip Milne * @author Philip Milne
* @since 1.7
*/ */
class SynthTableUI extends BasicTableUI implements SynthUI, public class SynthTableUI extends BasicTableUI
PropertyChangeListener { implements SynthUI, PropertyChangeListener {
// //
// Instance Variables // Instance Variables
// //
@ -88,18 +88,25 @@ class SynthTableUI extends BasicTableUI implements SynthUI,
// The installation/uninstall procedures and support // The installation/uninstall procedures and support
// //
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthTableUI(); return new SynthTableUI();
} }
/** /**
* Initialize JTable properties, e.g. font, foreground, and background. * Initializes JTable properties, such as font, foreground, and background.
* The font, foreground, and background properties are only set if their * The font, foreground, and background properties are only set if their
* current value is either null or a UIResource, other properties are set * current value is either null or a UIResource, other properties are set
* if the current value is null. * if the current value is null.
* *
* @see #installUI * @see #installUI
*/ */
@Override
protected void installDefaults() { protected void installDefaults() {
dateRenderer = installRendererIfPossible(Date.class, null); dateRenderer = installRendererIfPossible(Date.class, null);
numberRenderer = installRendererIfPossible(Number.class, null); numberRenderer = installRendererIfPossible(Number.class, null);
@ -189,11 +196,16 @@ class SynthTableUI extends BasicTableUI implements SynthUI,
/** /**
* Attaches listeners to the JTable. * Attaches listeners to the JTable.
*/ */
@Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
table.addPropertyChangeListener(this); table.addPropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
table.setDefaultRenderer(Date.class, dateRenderer); table.setDefaultRenderer(Date.class, dateRenderer);
table.setDefaultRenderer(Number.class, numberRenderer); table.setDefaultRenderer(Number.class, numberRenderer);
@ -213,6 +225,10 @@ class SynthTableUI extends BasicTableUI implements SynthUI,
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners() { protected void uninstallListeners() {
table.removePropertyChangeListener(this); table.removePropertyChangeListener(this);
super.uninstallListeners(); super.uninstallListeners();
@ -221,8 +237,13 @@ class SynthTableUI extends BasicTableUI implements SynthUI,
// //
// SynthUI // SynthUI
// //
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, SynthLookAndFeel.getComponentState(c));
} }
private SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
@ -230,18 +251,14 @@ class SynthTableUI extends BasicTableUI implements SynthUI,
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c);
}
// //
// Paint methods and support // Paint methods and support
// //
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -252,11 +269,19 @@ class SynthTableUI extends BasicTableUI implements SynthUI,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintTableBorder(context, g, x, y, w, h); context.getPainter().paintTableBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -264,6 +289,12 @@ class SynthTableUI extends BasicTableUI implements SynthUI,
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
Rectangle clip = g.getClipBounds(); Rectangle clip = g.getClipBounds();
@ -647,6 +678,10 @@ class SynthTableUI extends BasicTableUI implements SynthUI,
} }
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent event) { public void propertyChange(PropertyChangeEvent event) {
if (SynthLookAndFeel.shouldUpdateStyle(event)) { if (SynthLookAndFeel.shouldUpdateStyle(event)) {
updateStyle((JTable)event.getSource()); updateStyle((JTable)event.getSource());

View file

@ -33,7 +33,6 @@ import java.awt.*;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Provides the look and feel for a plain text editor in the * Provides the look and feel for a plain text editor in the
@ -50,40 +49,42 @@ import sun.swing.plaf.synth.SynthUI;
* Please see {@link java.beans.XMLEncoder}. * Please see {@link java.beans.XMLEncoder}.
* *
* @author Shannon Hickey * @author Shannon Hickey
* @since 1.7
*/ */
class SynthTextAreaUI extends BasicTextAreaUI implements SynthUI, FocusListener { public class SynthTextAreaUI extends BasicTextAreaUI implements SynthUI {
private Handler handler = new Handler();
private SynthStyle style; private SynthStyle style;
/** /**
* Creates a UI for a JTextArea. * Creates a UI object for a JTextArea.
* *
* @param ta a text area * @param ta a text area
* @return the UI * @return the UI object
*/ */
public static ComponentUI createUI(JComponent ta) { public static ComponentUI createUI(JComponent ta) {
return new SynthTextAreaUI(); return new SynthTextAreaUI();
} }
public void focusGained(FocusEvent e) { /**
getComponent().repaint(); * @inheritDoc
} */
@Override
public void focusLost(FocusEvent e) {
getComponent().repaint();
}
protected void installDefaults() { protected void installDefaults() {
// Installs the text cursor on the component // Installs the text cursor on the component
super.installDefaults(); super.installDefaults();
updateStyle(getComponent()); updateStyle(getComponent());
getComponent().addFocusListener(this); getComponent().addFocusListener(handler);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(getComponent(), ENABLED); SynthContext context = getContext(getComponent(), ENABLED);
getComponent().putClientProperty("caretAspectRatio", null); getComponent().putClientProperty("caretAspectRatio", null);
getComponent().removeFocusListener(this); getComponent().removeFocusListener(handler);
style.uninstallDefaults(context); style.uninstallDefaults(context);
context.dispose(); context.dispose();
@ -91,10 +92,6 @@ class SynthTextAreaUI extends BasicTextAreaUI implements SynthUI, FocusListener
super.uninstallDefaults(); super.uninstallDefaults();
} }
public void installUI(JComponent c) {
super.installUI(c);
}
private void updateStyle(JTextComponent comp) { private void updateStyle(JTextComponent comp) {
SynthContext context = getContext(comp, ENABLED); SynthContext context = getContext(comp, ENABLED);
SynthStyle oldStyle = style; SynthStyle oldStyle = style;
@ -112,8 +109,12 @@ class SynthTextAreaUI extends BasicTextAreaUI implements SynthUI, FocusListener
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, SynthLookAndFeel.getComponentState(c));
} }
private SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
@ -121,10 +122,10 @@ class SynthTextAreaUI extends BasicTextAreaUI implements SynthUI, FocusListener
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private int getComponentState(JComponent c) { /**
return SynthLookAndFeel.getComponentState(c); * @inheritDoc
} */
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -135,14 +136,30 @@ class SynthTextAreaUI extends BasicTextAreaUI implements SynthUI, FocusListener
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
super.paint(g, getComponent()); super.paint(g, getComponent());
} }
/**
* @inheritDoc
*
* Overridden to do nothing.
*/
@Override
protected void paintBackground(Graphics g) { protected void paintBackground(Graphics g) {
// Overriden to do nothing, all our painting is done from update/paint. // Overriden to do nothing, all our painting is done from update/paint.
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintTextAreaBorder(context, g, x, y, w, h); context.getPainter().paintTextAreaBorder(context, g, x, y, w, h);
@ -158,10 +175,21 @@ class SynthTextAreaUI extends BasicTextAreaUI implements SynthUI, FocusListener
* *
* @param evt the property change event * @param evt the property change event
*/ */
@Override
protected void propertyChange(PropertyChangeEvent evt) { protected void propertyChange(PropertyChangeEvent evt) {
if (SynthLookAndFeel.shouldUpdateStyle(evt)) { if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
updateStyle((JTextComponent)evt.getSource()); updateStyle((JTextComponent)evt.getSource());
} }
super.propertyChange(evt); super.propertyChange(evt);
} }
private final class Handler implements FocusListener {
public void focusGained(FocusEvent e) {
getComponent().repaint();
}
public void focusLost(FocusEvent e) {
getComponent().repaint();
}
}
} }

View file

@ -27,7 +27,6 @@ package javax.swing.plaf.synth;
import javax.swing.*; import javax.swing.*;
import javax.swing.text.*; import javax.swing.text.*;
import javax.swing.event.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicTextFieldUI; import javax.swing.plaf.basic.BasicTextFieldUI;
import java.awt.*; import java.awt.*;
@ -35,11 +34,9 @@ import java.awt.event.FocusEvent;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Basis of a look and feel for a JTextField in the Synth * Provides the Synth L&F UI delegate for {@link javax.swing.JTextField}.
* look and feel.
* <p> * <p>
* <strong>Warning:</strong> * <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with * Serialized objects of this class will not be compatible with
@ -51,27 +48,22 @@ import sun.swing.plaf.synth.SynthUI;
* Please see {@link java.beans.XMLEncoder}. * Please see {@link java.beans.XMLEncoder}.
* *
* @author Shannon Hickey * @author Shannon Hickey
* @since 1.7
*/ */
class SynthTextFieldUI public class SynthTextFieldUI extends BasicTextFieldUI implements SynthUI {
extends BasicTextFieldUI private Handler handler = new Handler();
implements SynthUI, FocusListener
{
private SynthStyle style; private SynthStyle style;
/** /**
* Creates a UI for a JTextField. * Creates a UI for a JTextField.
* *
* @param c the text field * @param c the text field
* @return the UI * @return the UI object
*/ */
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthTextFieldUI(); return new SynthTextFieldUI();
} }
public SynthTextFieldUI() {
super();
}
private void updateStyle(JTextComponent comp) { private void updateStyle(JTextComponent comp) {
SynthContext context = getContext(comp, ENABLED); SynthContext context = getContext(comp, ENABLED);
SynthStyle oldStyle = style; SynthStyle oldStyle = style;
@ -155,8 +147,12 @@ class SynthTextFieldUI
} }
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, SynthLookAndFeel.getComponentState(c));
} }
private SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
@ -164,10 +160,10 @@ class SynthTextFieldUI
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private int getComponentState(JComponent c) { /**
return SynthLookAndFeel.getComponentState(c); * @inheritDoc
} */
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -178,12 +174,15 @@ class SynthTextFieldUI
} }
/** /**
* Paints the interface. This is routed to the * Paints the specified component.
* paintSafely method under the guarantee that * <p>This is routed to the {@link #paintSafely} method under
* the model won't change from the view of this thread * the guarantee that the model does not change from the view of this
* while it's rendering (if the associated model is * thread while it is rendering (if the associated model is
* derived from AbstractDocument). This enables the * derived from {@code AbstractDocument}). This enables the
* model to potentially be updated asynchronously. * model to potentially be updated asynchronously.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/ */
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
super.paint(g, getComponent()); super.paint(g, getComponent());
@ -194,11 +193,20 @@ class SynthTextFieldUI
c.getWidth(), c.getHeight()); c.getWidth(), c.getHeight());
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintTextFieldBorder(context, g, x, y, w, h); context.getPainter().paintTextFieldBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
* Overridden to do nothing.
*/
@Override
protected void paintBackground(Graphics g) { protected void paintBackground(Graphics g) {
// Overriden to do nothing, all our painting is done from update/paint. // Overriden to do nothing, all our painting is done from update/paint.
} }
@ -214,6 +222,7 @@ class SynthTextFieldUI
* *
* @param evt the property change event * @param evt the property change event
*/ */
@Override
protected void propertyChange(PropertyChangeEvent evt) { protected void propertyChange(PropertyChangeEvent evt) {
if (SynthLookAndFeel.shouldUpdateStyle(evt)) { if (SynthLookAndFeel.shouldUpdateStyle(evt)) {
updateStyle((JTextComponent)evt.getSource()); updateStyle((JTextComponent)evt.getSource());
@ -221,26 +230,26 @@ class SynthTextFieldUI
super.propertyChange(evt); super.propertyChange(evt);
} }
public void focusGained(FocusEvent e) { /**
getComponent().repaint(); * @inheritDoc
} */
@Override
public void focusLost(FocusEvent e) {
getComponent().repaint();
}
protected void installDefaults() { protected void installDefaults() {
// Installs the text cursor on the component // Installs the text cursor on the component
super.installDefaults(); super.installDefaults();
updateStyle(getComponent()); updateStyle(getComponent());
getComponent().addFocusListener(this); getComponent().addFocusListener(handler);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(getComponent(), ENABLED); SynthContext context = getContext(getComponent(), ENABLED);
getComponent().putClientProperty("caretAspectRatio", null); getComponent().putClientProperty("caretAspectRatio", null);
getComponent().removeFocusListener(this); getComponent().removeFocusListener(handler);
style.uninstallDefaults(context); style.uninstallDefaults(context);
context.dispose(); context.dispose();
@ -248,7 +257,13 @@ class SynthTextFieldUI
super.uninstallDefaults(); super.uninstallDefaults();
} }
public void installUI(JComponent c) { private final class Handler implements FocusListener {
super.installUI(c); public void focusGained(FocusEvent e) {
getComponent().repaint();
}
public void focusLost(FocusEvent e) {
getComponent().repaint();
}
} }
} }

View file

@ -45,14 +45,15 @@ import java.awt.*;
* Please see {@link java.beans.XMLEncoder}. * Please see {@link java.beans.XMLEncoder}.
* *
* @author Shannon Hickey * @author Shannon Hickey
* @since 1.7
*/ */
class SynthTextPaneUI extends SynthEditorPaneUI { public class SynthTextPaneUI extends SynthEditorPaneUI {
/** /**
* Creates a UI for the JTextPane. * Creates a UI for the JTextPane.
* *
* @param c the JTextPane object * @param c the JTextPane object
* @return the UI * @return the UI object
*/ */
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthTextPaneUI(); return new SynthTextPaneUI();
@ -65,10 +66,15 @@ class SynthTextPaneUI extends SynthEditorPaneUI {
* *
* @return the name ("TextPane") * @return the name ("TextPane")
*/ */
@Override
protected String getPropertyPrefix() { protected String getPropertyPrefix() {
return "TextPane"; return "TextPane";
} }
/**
* @inheritDoc
*/
@Override
public void installUI(JComponent c) { public void installUI(JComponent c) {
super.installUI(c); super.installUI(c);
updateForeground(c.getForeground()); updateForeground(c.getForeground());
@ -86,6 +92,7 @@ class SynthTextPaneUI extends SynthEditorPaneUI {
* *
* @param evt the property change event * @param evt the property change event
*/ */
@Override
protected void propertyChange(PropertyChangeEvent evt) { protected void propertyChange(PropertyChangeEvent evt) {
super.propertyChange(evt); super.propertyChange(evt);
@ -150,11 +157,16 @@ class SynthTextPaneUI extends SynthEditorPaneUI {
} }
} }
@Override
void paintBackground(SynthContext context, Graphics g, JComponent c) { void paintBackground(SynthContext context, Graphics g, JComponent c) {
context.getPainter().paintTextPaneBackground(context, g, 0, 0, context.getPainter().paintTextPaneBackground(context, g, 0, 0,
c.getWidth(), c.getHeight()); c.getWidth(), c.getHeight());
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintTextPaneBorder(context, g, x, y, w, h); context.getPainter().paintTextPaneBorder(context, g, x, y, w, h);

View file

@ -31,18 +31,30 @@ import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
/** /**
* Synth's ToggleButtonUI. * Provides the Synth L&F UI delegate for
* <p> * {@link javax.swing.JToggleButton}.
*
* @author Jeff Dinkins * @author Jeff Dinkins
* @since 1.7
*/ */
class SynthToggleButtonUI extends SynthButtonUI { public class SynthToggleButtonUI extends SynthButtonUI {
// ******************************** // ********************************
// Create PLAF // Create PLAF
// ******************************** // ********************************
/**
* Creates a new UI object for the given component.
*
* @param b component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent b) { public static ComponentUI createUI(JComponent b) {
return new SynthToggleButtonUI(); return new SynthToggleButtonUI();
} }
/**
* @inheritDoc
*/
@Override @Override
protected String getPropertyPrefix() { protected String getPropertyPrefix() {
return "ToggleButton."; return "ToggleButton.";
@ -57,6 +69,9 @@ class SynthToggleButtonUI extends SynthButtonUI {
} }
} }
/**
* @inheritDoc
*/
@Override @Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {

View file

@ -42,39 +42,53 @@ import javax.swing.JToolBar;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicToolBarUI; import javax.swing.plaf.basic.BasicToolBarUI;
import sun.swing.plaf.synth.SynthIcon; import sun.swing.plaf.synth.SynthIcon;
import sun.swing.plaf.synth.SynthUI;
/** /**
* A Synth L&F implementation of ToolBarUI. This implementation * Provides the Synth L&F UI delegate for
* is a "combined" view/controller. * {@link javax.swing.JToolBar}.
* <p>
* *
* @since 1.7
*/ */
class SynthToolBarUI extends BasicToolBarUI implements PropertyChangeListener, public class SynthToolBarUI extends BasicToolBarUI
SynthUI { implements PropertyChangeListener, SynthUI {
protected Icon handleIcon = null; private Icon handleIcon = null;
protected Rectangle contentRect = new Rectangle(); private Rectangle contentRect = new Rectangle();
private SynthStyle style; private SynthStyle style;
private SynthStyle contentStyle; private SynthStyle contentStyle;
private SynthStyle dragWindowStyle; private SynthStyle dragWindowStyle;
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthToolBarUI(); return new SynthToolBarUI();
} }
/**
* @inheritDoc
*/
@Override @Override
protected void installDefaults() { protected void installDefaults() {
toolBar.setLayout(createLayout()); toolBar.setLayout(createLayout());
updateStyle(toolBar); updateStyle(toolBar);
} }
/**
* @inheritDoc
*/
@Override @Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
toolBar.addPropertyChangeListener(this); toolBar.addPropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override @Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
@ -106,6 +120,9 @@ class SynthToolBarUI extends BasicToolBarUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override @Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(toolBar, ENABLED); SynthContext context = getContext(toolBar, ENABLED);
@ -131,18 +148,33 @@ class SynthToolBarUI extends BasicToolBarUI implements PropertyChangeListener,
toolBar.setLayout(null); toolBar.setLayout(null);
} }
/**
* @inheritDoc
*/
@Override @Override
protected void installComponents() {} protected void installComponents() {}
/**
* @inheritDoc
*/
@Override @Override
protected void uninstallComponents() {} protected void uninstallComponents() {}
/**
* Creates a {@code LayoutManager} to use with the toolbar.
*
* @return a {@code LayoutManager} instance
*/
protected LayoutManager createLayout() { protected LayoutManager createLayout() {
return new SynthToolBarLayoutManager(); return new SynthToolBarLayoutManager();
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, SynthLookAndFeel.getComponentState(c));
} }
private SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
@ -161,18 +193,13 @@ class SynthToolBarUI extends BasicToolBarUI implements PropertyChangeListener,
style, state); style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c);
}
private int getComponentState(JComponent c, Region region) { private int getComponentState(JComponent c, Region region) {
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override @Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -185,6 +212,9 @@ class SynthToolBarUI extends BasicToolBarUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override @Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -193,6 +223,10 @@ class SynthToolBarUI extends BasicToolBarUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintToolBarBorder(context, g, x, y, w, h, context.getPainter().paintToolBarBorder(context, g, x, y, w, h,
@ -200,17 +234,32 @@ class SynthToolBarUI extends BasicToolBarUI implements PropertyChangeListener,
} }
// Overloaded to do nothing so we can share listeners. // Overloaded to do nothing so we can share listeners.
/**
* @inheritDoc
*/
@Override @Override
protected void setBorderToNonRollover(Component c) {} protected void setBorderToNonRollover(Component c) {}
// Overloaded to do nothing so we can share listeners. // Overloaded to do nothing so we can share listeners.
/**
* @inheritDoc
*/
@Override @Override
protected void setBorderToRollover(Component c) {} protected void setBorderToRollover(Component c) {}
// Overloaded to do nothing so we can share listeners. // Overloaded to do nothing so we can share listeners.
/**
* @inheritDoc
*/
@Override @Override
protected void setBorderToNormal(Component c) {} protected void setBorderToNormal(Component c) {}
/**
* Paints the toolbar.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
if (handleIcon != null && toolBar.isFloatable()) { if (handleIcon != null && toolBar.isFloatable()) {
int startX = toolBar.getComponentOrientation().isLeftToRight() ? int startX = toolBar.getComponentOrientation().isLeftToRight() ?
@ -227,7 +276,14 @@ class SynthToolBarUI extends BasicToolBarUI implements PropertyChangeListener,
subcontext.dispose(); subcontext.dispose();
} }
public void paintContent(SynthContext context, Graphics g, /**
* Paints the toolbar content.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
* @param bounds bounding box for the toolbar
*/
protected void paintContent(SynthContext context, Graphics g,
Rectangle bounds) { Rectangle bounds) {
SynthLookAndFeel.updateSubregion(context, g, bounds); SynthLookAndFeel.updateSubregion(context, g, bounds);
context.getPainter().paintToolBarContentBackground(context, g, context.getPainter().paintToolBarContentBackground(context, g,
@ -238,6 +294,9 @@ class SynthToolBarUI extends BasicToolBarUI implements PropertyChangeListener,
toolBar.getOrientation()); toolBar.getOrientation());
} }
/**
* @inheritDoc
*/
@Override @Override
protected void paintDragWindow(Graphics g) { protected void paintDragWindow(Graphics g) {
int w = dragWindow.getWidth(); int w = dragWindow.getWidth();
@ -258,6 +317,10 @@ class SynthToolBarUI extends BasicToolBarUI implements PropertyChangeListener,
// PropertyChangeListener // PropertyChangeListener
// //
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((JToolBar)e.getSource()); updateStyle((JToolBar)e.getSource());

View file

@ -34,23 +34,33 @@ import javax.swing.plaf.basic.BasicHTML;
import javax.swing.plaf.basic.BasicToolTipUI; import javax.swing.plaf.basic.BasicToolTipUI;
import javax.swing.plaf.ComponentUI; import javax.swing.plaf.ComponentUI;
import javax.swing.text.View; import javax.swing.text.View;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's ToolTipUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JToolTip}.
* *
* @author Joshua Outwater * @author Joshua Outwater
* @since 1.7
*/ */
class SynthToolTipUI extends BasicToolTipUI implements PropertyChangeListener, public class SynthToolTipUI extends BasicToolTipUI
SynthUI { implements PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthToolTipUI(); return new SynthToolTipUI();
} }
/**
* @inheritDoc
*/
@Override
protected void installDefaults(JComponent c) { protected void installDefaults(JComponent c) {
updateStyle(c); updateStyle(c);
} }
@ -61,6 +71,10 @@ class SynthToolTipUI extends BasicToolTipUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallDefaults(JComponent c) { protected void uninstallDefaults(JComponent c) {
SynthContext context = getContext(c, ENABLED); SynthContext context = getContext(c, ENABLED);
style.uninstallDefaults(context); style.uninstallDefaults(context);
@ -68,14 +82,26 @@ class SynthToolTipUI extends BasicToolTipUI implements PropertyChangeListener,
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override
protected void installListeners(JComponent c) { protected void installListeners(JComponent c) {
c.addPropertyChangeListener(this); c.addPropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
protected void uninstallListeners(JComponent c) { protected void uninstallListeners(JComponent c) {
c.removePropertyChangeListener(this); c.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, getComponentState(c));
} }
@ -85,10 +111,6 @@ class SynthToolTipUI extends BasicToolTipUI implements PropertyChangeListener,
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JComponent c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) { private int getComponentState(JComponent c) {
JComponent comp = ((JToolTip)c).getComponent(); JComponent comp = ((JToolTip)c).getComponent();
@ -98,6 +120,10 @@ class SynthToolTipUI extends BasicToolTipUI implements PropertyChangeListener,
return SynthLookAndFeel.getComponentState(c); return SynthLookAndFeel.getComponentState(c);
} }
/**
* @inheritDoc
*/
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -108,11 +134,19 @@ class SynthToolTipUI extends BasicToolTipUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintToolTipBorder(context, g, x, y, w, h); context.getPainter().paintToolTipBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -120,9 +154,14 @@ class SynthToolTipUI extends BasicToolTipUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* Paints the specified component.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
JToolTip tip = (JToolTip)context.getComponent(); JToolTip tip = (JToolTip)context.getComponent();
String tipText = tip.getToolTipText();
Insets insets = tip.getInsets(); Insets insets = tip.getInsets();
View v = (View)tip.getClientProperty(BasicHTML.propertyKey); View v = (View)tip.getClientProperty(BasicHTML.propertyKey);
@ -140,6 +179,10 @@ class SynthToolTipUI extends BasicToolTipUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override
public Dimension getPreferredSize(JComponent c) { public Dimension getPreferredSize(JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
Insets insets = c.getInsets(); Insets insets = c.getInsets();
@ -164,6 +207,10 @@ class SynthToolTipUI extends BasicToolTipUI implements PropertyChangeListener,
return prefSize; return prefSize;
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((JToolTip)e.getSource()); updateStyle((JToolTip)e.getSource());

View file

@ -48,15 +48,16 @@ import javax.swing.tree.TreeCellRenderer;
import javax.swing.tree.TreeModel; import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath; import javax.swing.tree.TreePath;
import sun.swing.plaf.synth.SynthIcon; import sun.swing.plaf.synth.SynthIcon;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Skinnable TreeUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JTree}.
* *
* @author Scott Violet * @author Scott Violet
* @since 1.7
*/ */
class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener, public class SynthTreeUI extends BasicTreeUI
SynthUI { implements PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
private SynthStyle cellStyle; private SynthStyle cellStyle;
@ -67,27 +68,33 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
private Object linesStyle; private Object linesStyle;
private int leadRow;
private int padding; private int padding;
private boolean useTreeColors; private boolean useTreeColors;
private Icon expandedIconWrapper; private Icon expandedIconWrapper = new ExpandedIconWrapper();
/**
* Creates a new UI object for the given component.
*
* @param x component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent x) { public static ComponentUI createUI(JComponent x) {
return new SynthTreeUI(); return new SynthTreeUI();
} }
SynthTreeUI() { /**
expandedIconWrapper = new ExpandedIconWrapper(); * @inheritDoc
} */
@Override @Override
public Icon getExpandedIcon() { public Icon getExpandedIcon() {
return expandedIconWrapper; return expandedIconWrapper;
} }
/**
* @inheritDoc
*/
@Override @Override
protected void installDefaults() { protected void installDefaults() {
updateStyle(tree); updateStyle(tree);
@ -148,15 +155,21 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override @Override
protected void installListeners() { protected void installListeners() {
super.installListeners(); super.installListeners();
tree.addPropertyChangeListener(this); tree.addPropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override @Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, SynthLookAndFeel.getComponentState(c));
} }
private SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
@ -164,14 +177,6 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
SynthLookAndFeel.getRegion(c), style, state); SynthLookAndFeel.getRegion(c), style, state);
} }
private Region getRegion(JTree c) {
return SynthLookAndFeel.getRegion(c);
}
private int getComponentState(JComponent c) {
return SynthLookAndFeel.getComponentState(c);
}
private SynthContext getContext(JComponent c, Region region) { private SynthContext getContext(JComponent c, Region region) {
return getContext(c, region, getComponentState(c, region)); return getContext(c, region, getComponentState(c, region));
} }
@ -187,6 +192,9 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
return ENABLED | SELECTED; return ENABLED | SELECTED;
} }
/**
* @inheritDoc
*/
@Override @Override
protected TreeCellEditor createDefaultCellEditor() { protected TreeCellEditor createDefaultCellEditor() {
TreeCellRenderer renderer = tree.getCellRenderer(); TreeCellRenderer renderer = tree.getCellRenderer();
@ -202,11 +210,17 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
return editor; return editor;
} }
/**
* @inheritDoc
*/
@Override @Override
protected TreeCellRenderer createDefaultCellRenderer() { protected TreeCellRenderer createDefaultCellRenderer() {
return new SynthTreeCellRenderer(); return new SynthTreeCellRenderer();
} }
/**
* @inheritDoc
*/
@Override @Override
protected void uninstallDefaults() { protected void uninstallDefaults() {
SynthContext context = getContext(tree, ENABLED); SynthContext context = getContext(tree, ENABLED);
@ -226,12 +240,18 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override @Override
protected void uninstallListeners() { protected void uninstallListeners() {
super.uninstallListeners(); super.uninstallListeners();
tree.removePropertyChangeListener(this); tree.removePropertyChangeListener(this);
} }
/**
* @inheritDoc
*/
@Override @Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -243,11 +263,18 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
context.getPainter().paintTreeBorder(context, g, x, y, w, h); context.getPainter().paintTreeBorder(context, g, x, y, w, h);
} }
/**
* @inheritDoc
*/
@Override @Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -256,14 +283,16 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
context.dispose(); context.dispose();
} }
private void updateLeadRow() { /**
leadRow = getRowForPath(tree, tree.getLeadSelectionPath()); * Paints the specified component.
} *
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
paintContext = context; paintContext = context;
updateLeadRow(); updateLeadSelectionRow();
Rectangle paintBounds = g.getClipBounds(); Rectangle paintBounds = g.getClipBounds();
Insets insets = tree.getInsets(); Insets insets = tree.getInsets();
@ -288,7 +317,6 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
boolean isExpanded; boolean isExpanded;
boolean hasBeenExpanded; boolean hasBeenExpanded;
boolean isLeaf; boolean isLeaf;
Rectangle boundsBuffer = new Rectangle();
Rectangle rowBounds = new Rectangle(0, 0, tree.getWidth(),0); Rectangle rowBounds = new Rectangle(0, 0, tree.getWidth(),0);
Rectangle bounds; Rectangle bounds;
TreePath path; TreePath path;
@ -392,83 +420,6 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
rendererPane.removeAll(); rendererPane.removeAll();
} }
private boolean isDropLine(JTree.DropLocation loc) {
return loc != null && loc.getPath() != null && loc.getChildIndex() != -1;
}
private void paintDropLine(Graphics g) {
JTree.DropLocation loc = tree.getDropLocation();
if (!isDropLine(loc)) {
return;
}
Color c = (Color)style.get(paintContext, "Tree.dropLineColor");
if (c != null) {
g.setColor(c);
Rectangle rect = getDropLineRect(loc);
g.fillRect(rect.x, rect.y, rect.width, rect.height);
}
}
private Rectangle getDropLineRect(JTree.DropLocation loc) {
Rectangle rect;
TreePath path = loc.getPath();
int index = loc.getChildIndex();
boolean ltr = tree.getComponentOrientation().isLeftToRight();
Insets insets = tree.getInsets();
if (tree.getRowCount() == 0) {
rect = new Rectangle(insets.left,
insets.top,
tree.getWidth() - insets.left - insets.right,
0);
} else {
int row = tree.getRowForPath(path);
TreeModel model = getModel();
Object root = model.getRoot();
if (path.getLastPathComponent() == root
&& index >= model.getChildCount(root)) {
rect = tree.getRowBounds(tree.getRowCount() - 1);
rect.y = rect.y + rect.height;
Rectangle xRect;
if (!tree.isRootVisible()) {
xRect = tree.getRowBounds(0);
} else if (model.getChildCount(root) == 0){
xRect = tree.getRowBounds(0);
xRect.x += totalChildIndent;
xRect.width -= totalChildIndent + totalChildIndent;
} else {
TreePath lastChildPath = path.pathByAddingChild(
model.getChild(root, model.getChildCount(root) - 1));
xRect = tree.getPathBounds(lastChildPath);
}
rect.x = xRect.x;
rect.width = xRect.width;
} else {
rect = tree.getPathBounds(path.pathByAddingChild(
model.getChild(path.getLastPathComponent(), index)));
}
}
if (rect.y != 0) {
rect.y--;
}
if (!ltr) {
rect.x = rect.x + rect.width - 100;
}
rect.width = 100;
rect.height = 2;
return rect;
}
private void configureRenderer(SynthContext context) { private void configureRenderer(SynthContext context) {
TreeCellRenderer renderer = tree.getCellRenderer(); TreeCellRenderer renderer = tree.getCellRenderer();
@ -502,6 +453,9 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override @Override
protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds,
Insets insets, Rectangle bounds, Insets insets, Rectangle bounds,
@ -516,6 +470,9 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override @Override
protected void paintHorizontalLine(Graphics g, JComponent c, int y, protected void paintHorizontalLine(Graphics g, JComponent c, int y,
int left, int right) { int left, int right) {
@ -523,6 +480,9 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
paintContext, "Tree.horizontalLine", g, left, y, right, y, linesStyle); paintContext, "Tree.horizontalLine", g, left, y, right, y, linesStyle);
} }
/**
* @inheritDoc
*/
@Override @Override
protected void paintVerticalPartOfLeg(Graphics g, protected void paintVerticalPartOfLeg(Graphics g,
Rectangle clipBounds, Insets insets, Rectangle clipBounds, Insets insets,
@ -532,6 +492,9 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override @Override
protected void paintVerticalLine(Graphics g, JComponent c, int x, int top, protected void paintVerticalLine(Graphics g, JComponent c, int x, int top,
int bottom) { int bottom) {
@ -539,7 +502,7 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
paintContext, "Tree.verticalLine", g, x, top, x, bottom, linesStyle); paintContext, "Tree.verticalLine", g, x, top, x, bottom, linesStyle);
} }
protected void paintRow(TreeCellRenderer renderer, private void paintRow(TreeCellRenderer renderer,
DefaultTreeCellRenderer dtcr, SynthContext treeContext, DefaultTreeCellRenderer dtcr, SynthContext treeContext,
SynthContext cellContext, Graphics g, Rectangle clipBounds, SynthContext cellContext, Graphics g, Rectangle clipBounds,
Insets insets, Rectangle bounds, Rectangle rowBounds, Insets insets, Rectangle bounds, Rectangle rowBounds,
@ -558,7 +521,7 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
state |= SELECTED; state |= SELECTED;
} }
if (tree.isFocusOwner() && row == leadRow) { if (tree.isFocusOwner() && row == getLeadSelectionRow()) {
state |= FOCUSED; state |= FOCUSED;
} }
@ -583,7 +546,7 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
int leadIndex; int leadIndex;
if (tree.hasFocus()) { if (tree.hasFocus()) {
leadIndex = leadRow; leadIndex = getLeadSelectionRow();
} }
else { else {
leadIndex = -1; leadIndex = -1;
@ -625,6 +588,9 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
paintContext.setComponentState(state); paintContext.setComponentState(state);
} }
/**
* @inheritDoc
*/
@Override @Override
protected void drawCentered(Component c, Graphics graphics, Icon icon, protected void drawCentered(Component c, Graphics graphics, Icon icon,
int x, int y) { int x, int y) {
@ -636,6 +602,10 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
y - h/2, w, h); y - h/2, w, h);
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent event) { public void propertyChange(PropertyChangeEvent event) {
if (SynthLookAndFeel.shouldUpdateStyle(event)) { if (SynthLookAndFeel.shouldUpdateStyle(event)) {
updateStyle((JTree)event.getSource()); updateStyle((JTree)event.getSource());
@ -648,6 +618,24 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override
protected void paintDropLine(Graphics g) {
JTree.DropLocation loc = tree.getDropLocation();
if (!isDropLine(loc)) {
return;
}
Color c = (Color)style.get(paintContext, "Tree.dropLineColor");
if (c != null) {
g.setColor(c);
Rectangle rect = getDropLineRect(loc);
g.fillRect(rect.x, rect.y, rect.width, rect.height);
}
}
private void repaintDropLocation(JTree.DropLocation loc) { private void repaintDropLocation(JTree.DropLocation loc) {
if (loc == null) { if (loc == null) {
return; return;
@ -670,6 +658,9 @@ class SynthTreeUI extends BasicTreeUI implements PropertyChangeListener,
} }
} }
/**
* @inheritDoc
*/
@Override @Override
protected int getRowX(int row, int depth) { protected int getRowX(int row, int depth) {
return super.getRowX(row, depth) + padding; return super.getRowX(row, depth) + padding;

View file

@ -22,18 +22,19 @@
* CA 95054 USA or visit www.sun.com if you need additional information or * CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions. * have any questions.
*/ */
package sun.swing.plaf.synth; package javax.swing.plaf.synth;
import java.awt.Graphics; import java.awt.Graphics;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.plaf.synth.*;
/** /**
* SynthUI is used to fetch the SynthContext for a particular Component. * SynthUI is used to fetch the SynthContext for a particular Component.
* *
* @author Scott Violet * @author Scott Violet
* @since 1.7
*/ */
public interface SynthUI extends SynthConstants { public interface SynthUI extends SynthConstants {
/** /**
* Returns the Context for the specified component. * Returns the Context for the specified component.
* *
@ -44,6 +45,13 @@ public interface SynthUI extends SynthConstants {
/** /**
* Paints the border. * Paints the border.
*
* @param context a component context
* @param g {@code Graphics} to paint on
* @param x the X coordinate
* @param y the Y coordinate
* @param w width of the border
* @param h height of the border
*/ */
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h); int y, int w, int h);

View file

@ -25,40 +25,57 @@
package javax.swing.plaf.synth; package javax.swing.plaf.synth;
import java.awt.*;
import java.beans.*; import java.beans.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.*;
import javax.swing.plaf.*; import javax.swing.plaf.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*;
import sun.swing.plaf.synth.SynthUI;
/** /**
* Synth's ViewportUI. * Provides the Synth L&F UI delegate for
* {@link javax.swing.JViewport}.
* *
* @since 1.7
*/ */
class SynthViewportUI extends ViewportUI implements public class SynthViewportUI extends ViewportUI
PropertyChangeListener, SynthUI { implements PropertyChangeListener, SynthUI {
private SynthStyle style; private SynthStyle style;
/**
* Creates a new UI object for the given component.
*
* @param c component to create UI object for
* @return the UI object
*/
public static ComponentUI createUI(JComponent c) { public static ComponentUI createUI(JComponent c) {
return new SynthViewportUI(); return new SynthViewportUI();
} }
/**
* @inheritDoc
*/
@Override
public void installUI(JComponent c) { public void installUI(JComponent c) {
super.installUI(c); super.installUI(c);
installDefaults(c); installDefaults(c);
installListeners(c); installListeners(c);
} }
/**
* @inheritDoc
*/
@Override
public void uninstallUI(JComponent c) { public void uninstallUI(JComponent c) {
super.uninstallUI(c); super.uninstallUI(c);
uninstallListeners(c); uninstallListeners(c);
uninstallDefaults(c); uninstallDefaults(c);
} }
/**
* Installs defaults for a viewport.
*
* @param c a {@code JViewport} object
*/
protected void installDefaults(JComponent c) { protected void installDefaults(JComponent c) {
updateStyle(c); updateStyle(c);
} }
@ -85,14 +102,29 @@ class SynthViewportUI extends ViewportUI implements
context.dispose(); context.dispose();
} }
/**
* Installs listeners into the viewport.
*
* @param c a {@code JViewport} object
*/
protected void installListeners(JComponent c) { protected void installListeners(JComponent c) {
c.addPropertyChangeListener(this); c.addPropertyChangeListener(this);
} }
/**
* Uninstalls listeners from the viewport.
*
* @param c a {@code JViewport} object
*/
protected void uninstallListeners(JComponent c) { protected void uninstallListeners(JComponent c) {
c.removePropertyChangeListener(this); c.removePropertyChangeListener(this);
} }
/**
* Uninstalls defaults from a viewport.
*
* @param c a {@code JViewport} object
*/
protected void uninstallDefaults(JComponent c) { protected void uninstallDefaults(JComponent c) {
SynthContext context = getContext(c, ENABLED); SynthContext context = getContext(c, ENABLED);
style.uninstallDefaults(context); style.uninstallDefaults(context);
@ -100,8 +132,12 @@ class SynthViewportUI extends ViewportUI implements
style = null; style = null;
} }
/**
* @inheritDoc
*/
@Override
public SynthContext getContext(JComponent c) { public SynthContext getContext(JComponent c) {
return getContext(c, getComponentState(c)); return getContext(c, SynthLookAndFeel.getComponentState(c));
} }
private SynthContext getContext(JComponent c, int state) { private SynthContext getContext(JComponent c, int state) {
@ -113,10 +149,10 @@ class SynthViewportUI extends ViewportUI implements
return SynthLookAndFeel.getRegion(c); return SynthLookAndFeel.getRegion(c);
} }
private int getComponentState(JComponent c) { /**
return SynthLookAndFeel.getComponentState(c); * @inheritDoc
} */
@Override
public void update(Graphics g, JComponent c) { public void update(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -127,12 +163,20 @@ class SynthViewportUI extends ViewportUI implements
context.dispose(); context.dispose();
} }
/**
* @inheritDoc
*/
@Override
public void paintBorder(SynthContext context, Graphics g, int x, public void paintBorder(SynthContext context, Graphics g, int x,
int y, int w, int h) { int y, int w, int h) {
// This does nothing on purpose, JViewport doesn't allow a border // This does nothing on purpose, JViewport doesn't allow a border
// and therefor this will NEVER be called. // and therefor this will NEVER be called.
} }
/**
* @inheritDoc
*/
@Override
public void paint(Graphics g, JComponent c) { public void paint(Graphics g, JComponent c) {
SynthContext context = getContext(c); SynthContext context = getContext(c);
@ -140,9 +184,19 @@ class SynthViewportUI extends ViewportUI implements
context.dispose(); context.dispose();
} }
/**
* Paints the specified component. This implementation does nothing.
*
* @param context context for the component being painted
* @param g {@code Graphics} object used for painting
*/
protected void paint(SynthContext context, Graphics g) { protected void paint(SynthContext context, Graphics g) {
} }
/**
* @inheritDoc
*/
@Override
public void propertyChange(PropertyChangeEvent e) { public void propertyChange(PropertyChangeEvent e) {
if (SynthLookAndFeel.shouldUpdateStyle(e)) { if (SynthLookAndFeel.shouldUpdateStyle(e)) {
updateStyle((JComponent)e.getSource()); updateStyle((JComponent)e.getSource());

View file

@ -143,8 +143,12 @@ void DAUDIO_GetFormats(INT32 mixerIndex, INT32 deviceID, int isSource, void* cre
ERROR1("snd_pcm_hw_params_malloc returned error %d\n", ret); ERROR1("snd_pcm_hw_params_malloc returned error %d\n", ret);
} else { } else {
ret = snd_pcm_hw_params_any(handle, hwParams); ret = snd_pcm_hw_params_any(handle, hwParams);
if (ret != 0) { /* snd_pcm_hw_params_any can return a positive value on success too */
if (ret < 0) {
ERROR1("snd_pcm_hw_params_any returned error %d\n", ret); ERROR1("snd_pcm_hw_params_any returned error %d\n", ret);
} else {
/* for the logic following this code, set ret to 0 to indicate success */
ret = 0;
} }
} }
snd_pcm_hw_params_get_format_mask(hwParams, formatMask); snd_pcm_hw_params_get_format_mask(hwParams, formatMask);

View file

@ -92,7 +92,7 @@ Bangkok Standard Time:14,15::Asia/Bangkok:
North Asia Standard Time:14,15::Asia/Krasnoyarsk: North Asia Standard Time:14,15::Asia/Krasnoyarsk:
SE Asia:14,15::Asia/Bangkok: SE Asia:14,15::Asia/Bangkok:
SE Asia Standard Time:14,15::Asia/Bangkok: SE Asia Standard Time:14,15::Asia/Bangkok:
North Asia East Standard Time:16,17::Asia/Ulaanbaatar: North Asia East Standard Time:16,17:RU:Asia/Irkutsk:
Singapore:16,17:SG:Asia/Singapore: Singapore:16,17:SG:Asia/Singapore:
Singapore Standard Time:16,17:SG:Asia/Singapore: Singapore Standard Time:16,17:SG:Asia/Singapore:
Taipei:16,17::Asia/Taipei: Taipei:16,17::Asia/Taipei:
@ -184,4 +184,5 @@ Venezuela Standard Time:915,915::America/Caracas:
Kamchatka Standard Time:916,916:RU:Asia/Kamchatka: Kamchatka Standard Time:916,916:RU:Asia/Kamchatka:
Paraguay Standard Time:917,917:PY:America/Asuncion: Paraguay Standard Time:917,917:PY:America/Asuncion:
Western Brazilian Standard Time:918,918:BR:America/Rio_Branco: Western Brazilian Standard Time:918,918:BR:America/Rio_Branco:
Armenian Standard Time:919,919:AM:Asia/Yerevan: Ulaanbaatar Standard Time:919,919::Asia/Ulaanbaatar:
Armenian Standard Time:920,920:AM:Asia/Yerevan:

View file

@ -485,7 +485,7 @@ DWORD WINAPI __stdcall DS_StartBufferHelper::ThreadProc(void *param)
} }
if (data.line2Start->isSource) { if (data.line2Start->isSource) {
data.startResult = data.startResult =
data.line2Start->playBuffer->Play(0, 0, DSCBSTART_LOOPING); data.line2Start->playBuffer->Play(0, 0, DSBPLAY_LOOPING);
} else { } else {
data.startResult = data.startResult =
data.line2Start->captureBuffer->Start(DSCBSTART_LOOPING); data.line2Start->captureBuffer->Start(DSCBSTART_LOOPING);

View file

@ -36,7 +36,7 @@ public class Test6788531 {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
JButton button = new JButton("hi"); JButton button = new JButton("hi");
button.addActionListener(EventHandler.create(ActionListener.class, new Private(), "run")); button.addActionListener(EventHandler.create(ActionListener.class, new Private(), "run"));
button.addActionListener(EventHandler.create(ActionListener.class, new PrivateGeneric(), "run", "generic")); button.addActionListener(EventHandler.create(ActionListener.class, new PrivateGeneric(), "run", "actionCommand"));
button.doClick(); button.doClick();
} }

View file

@ -0,0 +1,155 @@
/*
* Copyright 2009 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 5102804
* @summary Tests memory leak
* @author Sergey Malenkov
*/
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.net.URLClassLoader;
public class Test5102804 {
private static final String BEAN_NAME = "Test5102804$Example";
private static final String BEAN_INFO_NAME = BEAN_NAME + "BeanInfo";
public static void main(String[] args) {
if (!isCollectible(getReference()))
throw new Error("Reference is not collected");
}
private static Reference getReference() {
try {
ClassLoader loader = new Loader();
Class type = Class.forName(BEAN_NAME, true, loader);
if (!type.getClassLoader().equals(loader)) {
throw new Error("Wrong class loader");
}
BeanInfo info = Introspector.getBeanInfo(type);
if (0 != info.getDefaultPropertyIndex()) {
throw new Error("Wrong bean info found");
}
return new WeakReference<Class>(type);
}
catch (IntrospectionException exception) {
throw new Error("Introspection Error", exception);
}
catch (ClassNotFoundException exception) {
throw new Error("Class Not Found", exception);
}
}
private static boolean isCollectible(Reference reference) {
int[] array = new int[10];
while (true) {
try {
array = new int[array.length + array.length / 3];
}
catch (OutOfMemoryError error) {
return null == reference.get();
}
}
}
/**
* Custom class loader to load the Example class by itself.
* Could also load it from a different code source, but this is easier to set up.
*/
private static final class Loader extends URLClassLoader {
Loader() {
super(new URL[] {
Test5102804.class.getProtectionDomain().getCodeSource().getLocation()
});
}
@Override
protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
Class c = findLoadedClass(name);
if (c == null) {
if (BEAN_NAME.equals(name) || BEAN_INFO_NAME.equals(name)) {
c = findClass(name);
}
else try {
c = getParent().loadClass(name);
}
catch (ClassNotFoundException exception) {
c = findClass(name);
}
}
if (resolve) {
resolveClass(c);
}
return c;
}
}
/**
* A simple bean to load from the Loader class, not main class loader.
*/
public static final class Example {
private int value;
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
/**
* The BeanInfo for the Example class.
* It is also loaded from the Loader class.
*/
public static final class ExampleBeanInfo extends SimpleBeanInfo {
@Override
public int getDefaultPropertyIndex() {
return 0;
}
@Override
public PropertyDescriptor[] getPropertyDescriptors() {
try {
return new PropertyDescriptor[] {
new PropertyDescriptor("value", Class.forName(BEAN_NAME))
};
}
catch (ClassNotFoundException exception) {
return null;
}
catch (IntrospectionException exception) {
return null;
}
}
}
}

View file

@ -33,43 +33,70 @@ import java.beans.XMLDecoder;
import java.beans.XMLEncoder; import java.beans.XMLEncoder;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
public class Test6329581 implements ExceptionListener { public class Test6329581 extends URLClassLoader implements ExceptionListener {
public static final class Bean {
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
ExceptionListener listener = new Test6329581(); new Test6329581().decode(new Test6329581().encode(Bean.class.getName()));
// write bean to byte array
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder(out);
encoder.setExceptionListener(listener);
encoder.writeObject(getClassLoader("beans.jar").loadClass("test.Bean").newInstance());
encoder.close();
// read bean from byte array
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
XMLDecoder decoder = new XMLDecoder(in, null, listener, getClassLoader("beans.jar"));
Object object = decoder.readObject();
decoder.close();
if (!object.getClass().getClassLoader().getClass().equals(URLClassLoader.class)) {
throw new Error("bean is loaded with unexpected class loader");
}
} }
private static ClassLoader getClassLoader(String name) throws Exception { private Test6329581() {
StringBuilder sb = new StringBuilder(256); super(new URL[] {
sb.append("file:"); Test6329581.class.getProtectionDomain().getCodeSource().getLocation()
sb.append(System.getProperty("test.src", ".")); });
sb.append(File.separatorChar); }
sb.append(name);
URL[] url = { new URL(sb.toString()) }; @Override
return new URLClassLoader(url); protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
Class c = findLoadedClass(name);
if (c == null) {
if (Bean.class.getName().equals(name)) {
c = findClass(name);
}
else try {
c = getParent().loadClass(name);
}
catch (ClassNotFoundException exception) {
c = findClass(name);
}
}
if (resolve) {
resolveClass(c);
}
return c;
} }
public void exceptionThrown(Exception exception) { public void exceptionThrown(Exception exception) {
throw new Error("unexpected exception", exception); throw new Error("unexpected exception", exception);
} }
private void validate(Object object) {
if (!object.getClass().getClassLoader().equals(this)) {
throw new Error("Bean is loaded with unexpected class loader");
}
}
private byte[] encode(String name) throws Exception {
Object object = loadClass(name).newInstance();
validate(object);
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder(out);
encoder.setExceptionListener(this);
encoder.writeObject(object);
encoder.close();
return out.toByteArray();
}
private Object decode(byte[] array) {
ByteArrayInputStream in = new ByteArrayInputStream(array);
XMLDecoder decoder = new XMLDecoder(in, null, this, this);
Object object = decoder.readObject();
validate(object);
decoder.close();
return object;
}
} }

View file

@ -0,0 +1,103 @@
/*
* Copyright 2009 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 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
@summary Test SoftChannel overflow test 2 */
import java.util.HashMap;
import java.util.Map;
import javax.sound.midi.MidiChannel;
import javax.sound.midi.Patch;
import javax.sound.midi.VoiceStatus;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import com.sun.media.sound.AudioSynthesizer;
import com.sun.media.sound.SF2Instrument;
import com.sun.media.sound.SF2InstrumentRegion;
import com.sun.media.sound.SF2Layer;
import com.sun.media.sound.SF2LayerRegion;
import com.sun.media.sound.SF2Region;
import com.sun.media.sound.SF2Sample;
import com.sun.media.sound.SF2Soundbank;
import com.sun.media.sound.SoftSynthesizer;
public class NoteOverFlowTest2 {
public static void main(String[] args) throws Exception
{
// Create instance of the synthesizer with very low polyphony
AudioSynthesizer synth = new SoftSynthesizer();
AudioFormat format = new AudioFormat(44100, 16, 2, true, false);
Map<String, Object> p = new HashMap<String, Object>();
p.put("max polyphony", new Integer(5));
AudioInputStream stream = synth.openStream(format, p);
// Create instrument with too many regions (more than max polyphony)
SF2Soundbank sf2 = new SF2Soundbank();
SF2Sample sample = new SF2Sample(sf2);
sample.setName("test sample");
sample.setData(new byte[100]);
sample.setSampleRate(44100);
sample.setOriginalPitch(20);
sf2.addResource(sample);
SF2Layer layer = new SF2Layer(sf2);
layer.setName("test layer");
sf2.addResource(layer);
for (int i = 0; i < 100; i++) {
SF2LayerRegion region = new SF2LayerRegion();
region.setSample(sample);
layer.getRegions().add(region);
}
SF2Instrument ins = new SF2Instrument(sf2);
ins.setPatch(new Patch(0,0));
ins.setName("test instrument");
sf2.addInstrument(ins);
SF2InstrumentRegion insregion = new SF2InstrumentRegion();
insregion.setLayer(layer);
ins.getRegions().add(insregion);
// Load the test soundbank into the synthesizer
synth.unloadAllInstruments(synth.getDefaultSoundbank());
synth.loadAllInstruments(sf2);
// Send out one midi on message
MidiChannel ch1 = synth.getChannels()[0];
ch1.programChange(0);
ch1.noteOn(64, 64);
// Read 1 sec from stream
stream.skip(format.getFrameSize() * ((int)(format.getFrameRate() * 2)));
// Close the synthesizer after use
synth.close();
}
}

View file

@ -0,0 +1,48 @@
/*
* Copyright 2009 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 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
@summary Test SoftReceiver getMidiDevice method */
import javax.sound.midi.Receiver;
import com.sun.media.sound.AudioSynthesizer;
import com.sun.media.sound.SoftReceiver;
import com.sun.media.sound.SoftSynthesizer;
public class GetMidiDevice {
public static void main(String[] args) throws Exception {
AudioSynthesizer synth = new SoftSynthesizer();
synth.openStream(null, null);
Receiver recv = synth.getReceiver();
if (((SoftReceiver) recv).getMidiDevice() != synth) {
throw new Exception("SoftReceiver.getMidiDevice() doesn't return "
+ "instance of the synthesizer");
}
synth.close();
}
}

View file

@ -0,0 +1,208 @@
/*
* Copyright 2009 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 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
@summary Test rendering when using precise timestamps */
import java.util.Arrays;
import java.util.Random;
import javax.sound.midi.MidiChannel;
import javax.sound.midi.Receiver;
import javax.sound.midi.ShortMessage;
import javax.sound.midi.Soundbank;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import com.sun.media.sound.AudioFloatConverter;
import com.sun.media.sound.AudioSynthesizer;
import com.sun.media.sound.ModelAbstractChannelMixer;
import com.sun.media.sound.ModelChannelMixer;
import com.sun.media.sound.SF2Instrument;
import com.sun.media.sound.SF2InstrumentRegion;
import com.sun.media.sound.SF2Layer;
import com.sun.media.sound.SF2LayerRegion;
import com.sun.media.sound.SF2Sample;
import com.sun.media.sound.SF2Soundbank;
import com.sun.media.sound.SimpleInstrument;
import com.sun.media.sound.SimpleSoundbank;
import com.sun.media.sound.SoftSynthesizer;
public class TestPreciseTimestampRendering {
public static AudioFormat format = new AudioFormat(44100, 16, 1, true,
false);
public static SF2Soundbank createTestSoundbank() {
// Create impulse instrument
// used to measure timing of note-on playback
SF2Soundbank soundbank = new SF2Soundbank();
float[] data = new float[100];
Arrays.fill(data, 0);
data[0] = 1.0f;
byte[] bdata = new byte[data.length * format.getFrameSize()];
AudioFloatConverter.getConverter(format).toByteArray(data, bdata);
SF2Sample sample = new SF2Sample(soundbank);
sample.setName("Test Sample");
sample.setData(bdata);
sample.setSampleRate((long) format.getSampleRate());
sample.setOriginalPitch(69);
soundbank.addResource(sample);
SF2Layer layer = new SF2Layer(soundbank);
layer.setName("Test Layer");
soundbank.addResource(layer);
SF2LayerRegion region = new SF2LayerRegion();
region.setSample(sample);
layer.getRegions().add(region);
SF2Instrument ins = new SF2Instrument(soundbank);
ins.setName("Test Instrument");
soundbank.addInstrument(ins);
SF2InstrumentRegion insregion = new SF2InstrumentRegion();
insregion.setLayer(layer);
ins.getRegions().add(insregion);
return soundbank;
}
public static Soundbank createTestSoundbankWithChannelMixer() {
SF2Soundbank soundbank = createTestSoundbank();
SimpleSoundbank simplesoundbank = new SimpleSoundbank();
SimpleInstrument simpleinstrument = new SimpleInstrument() {
public ModelChannelMixer getChannelMixer(MidiChannel channel,
AudioFormat format) {
return new ModelAbstractChannelMixer() {
boolean active = true;
public boolean process(float[][] buffer, int offset, int len) {
for (int i = 0; i < buffer.length; i++) {
float[] cbuffer = buffer[i];
for (int j = 0; j < cbuffer.length; j++) {
cbuffer[j] = -cbuffer[j];
}
}
return active;
}
public void stop() {
active = false;
}
};
}
};
simpleinstrument.add(soundbank.getInstruments()[0]);
simplesoundbank.addInstrument(simpleinstrument);
return simplesoundbank;
}
public static void main(String[] args) throws Exception {
test(createTestSoundbank());
test(createTestSoundbankWithChannelMixer());
}
public static void test(Soundbank soundbank) throws Exception {
// Create instance of synthesizer using the testing soundbank above
AudioSynthesizer synth = new SoftSynthesizer();
AudioInputStream stream = synth.openStream(format, null);
synth.unloadAllInstruments(synth.getDefaultSoundbank());
synth.loadAllInstruments(soundbank);
Receiver recv = synth.getReceiver();
// Set volume to max and turn reverb off
ShortMessage reverb_off = new ShortMessage();
reverb_off.setMessage(ShortMessage.CONTROL_CHANGE, 91, 0);
recv.send(reverb_off, -1);
ShortMessage full_volume = new ShortMessage();
full_volume.setMessage(ShortMessage.CONTROL_CHANGE, 7, 127);
recv.send(full_volume, -1);
Random random = new Random(3485934583945l);
// Create random timestamps
long[] test_timestamps = new long[30];
for (int i = 1; i < test_timestamps.length; i++) {
test_timestamps[i] = i * 44100
+ (int) (random.nextDouble() * 22050.0);
}
// Send midi note on message to synthesizer
for (int i = 0; i < test_timestamps.length; i++) {
ShortMessage midi_on = new ShortMessage();
midi_on.setMessage(ShortMessage.NOTE_ON, 69, 127);
recv.send(midi_on,
(long) ((test_timestamps[i] / 44100.0) * 1000000.0));
}
// Measure timing from rendered audio
float[] fbuffer = new float[100];
byte[] buffer = new byte[fbuffer.length * format.getFrameSize()];
long firsts = -1;
int counter = 0;
long s = 0;
long max_jitter = 0;
outerloop: for (int k = 0; k < 10000000; k++) {
stream.read(buffer);
AudioFloatConverter.getConverter(format).toFloatArray(buffer,
fbuffer);
for (int i = 0; i < fbuffer.length; i++) {
if (fbuffer[i] != 0) {
if (firsts == -1)
firsts = s;
long measure_time = (s - firsts);
long predicted_time = test_timestamps[counter];
long jitter = Math.abs(measure_time - predicted_time);
if (jitter > 10)
max_jitter = jitter;
counter++;
if (counter == test_timestamps.length)
break outerloop;
}
s++;
}
}
synth.close();
if (counter == 0)
throw new Exception("Nothing was measured!");
if (max_jitter != 0) {
throw new Exception("Jitter has occurred! "
+ "(max jitter = " + max_jitter + ")");
}
}
}

View file

@ -0,0 +1,247 @@
/*
* Copyright 2009 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 6823603
@summary Generics: JList
@author Florian Brunner
@run main bug6823603
*/
import java.util.Arrays;
import java.util.List;
import java.util.Vector;
import java.util.Enumeration;
import java.awt.*;
import javax.swing.*;
public class bug6823603 {
private static final String TEST_ELEMENT = "Test1";
/**
* @param args the command line arguments
*/
@SuppressWarnings("unchecked")
public static void main(String[] args) {
testRawSignatures();
testGenericSignatures();
testGetSelectedValuesList(); // new method
}
@SuppressWarnings("unchecked")
private static void testRawSignatures() {
// Test JList
ListModel rawTestModel = new DefaultListModel();
new JList();
new JList(rawTestModel);
new JList(new Object[]{TEST_ELEMENT});
JList rawTestList = new JList(new Vector());
rawTestList.getPrototypeCellValue();
rawTestList.setPrototypeCellValue(TEST_ELEMENT);
rawTestList.getCellRenderer();
rawTestList.setCellRenderer(new DefaultListCellRenderer());
rawTestList.getModel();
rawTestList.setModel(rawTestModel);
rawTestList.setListData(new Object[]{TEST_ELEMENT});
rawTestList.setListData(new Vector());
@SuppressWarnings("deprecation")
Object[] selectedValues = rawTestList.getSelectedValues();
rawTestList.getSelectedValue();
// Test ListCellRenderer
ListCellRenderer rawTestCellRenderer = new DefaultListCellRenderer();
String testEntry = "Test";
@SuppressWarnings("unchecked")
JList rawJList = new JList(new Object[]{testEntry});
rawTestCellRenderer.getListCellRendererComponent(rawJList,
testEntry, 0, true, true);
// Test ListModel
DefaultListModel testModel = new DefaultListModel();
testModel.addElement(TEST_ELEMENT);
rawTestModel = testModel;
rawTestModel.getElementAt(0);
// Test DefaultListModel
DefaultListModel defaultListModel = new DefaultListModel();
defaultListModel.addElement(TEST_ELEMENT);
defaultListModel.getElementAt(0);
defaultListModel.elements();
defaultListModel.elementAt(0);
defaultListModel.firstElement();
defaultListModel.lastElement();
String testElement2 = "Test2";
defaultListModel.setElementAt(testElement2, 0);
defaultListModel.insertElementAt(TEST_ELEMENT, 0);
defaultListModel.get(0);
defaultListModel.set(0, testElement2);
defaultListModel.add(0, TEST_ELEMENT);
defaultListModel.remove(0);
// Test AbstractListModel
@SuppressWarnings("serial")
ListModel abstractListModel = new AbstractListModel() {
public int getSize() {
throw new UnsupportedOperationException("Not supported yet.");
}
public Object getElementAt(int index) {
throw new UnsupportedOperationException("Not supported yet.");
}
};
// Test DefaultListCellRenderer
DefaultListCellRenderer cellRenderer = new DefaultListCellRenderer();
@SuppressWarnings("unchecked")
JList list = new JList(new Object[]{testEntry});
cellRenderer.getListCellRendererComponent(rawJList, testEntry, 0, true, true);
}
private static <E> void testGenericSignatures() {
// Test JList
ListModel<String> stringListModel = new DefaultListModel<String>();
new JList<String>();
new JList<String>(stringListModel);
new JList<String>(new String[]{TEST_ELEMENT});
JList<String> stringTestList = new JList<String>(new Vector<String>());
stringTestList.getPrototypeCellValue();
stringTestList.setPrototypeCellValue(TEST_ELEMENT);
ListCellRenderer<? super String> cellRenderer = stringTestList.getCellRenderer();
stringTestList.setCellRenderer(new DefaultListCellRenderer());
ListModel<String> model = stringTestList.getModel();
stringTestList.setModel(stringListModel);
stringTestList.setListData(new String[]{TEST_ELEMENT});
stringTestList.setListData(new Vector<String>());
@SuppressWarnings("deprecation")
Object[] selectedValues = stringTestList.getSelectedValues();
stringTestList.getSelectedValue();
// Test ListCellRenderer
ListCellRenderer<Object> stringTestCellRenderer =
new DefaultListCellRenderer();
String testEntry = "Test";
JList<String> stringJList = new JList<String>(new String[]{testEntry});
Component listCellRendererComponent2 =
stringTestCellRenderer.getListCellRendererComponent(stringJList,
testEntry, 0, true, true);
// Test ListModel
DefaultListModel<String> testModel = new DefaultListModel<String>();
testModel.addElement(TEST_ELEMENT);
stringListModel = testModel;
String element1 = stringListModel.getElementAt(0);
// Test DefaultListModel
DefaultListModel<String> stringTestModel = new DefaultListModel<String>();
stringTestModel.addElement(TEST_ELEMENT);
element1 = stringTestModel.getElementAt(0);
Enumeration<String> elements = stringTestModel.elements();
String element2 = stringTestModel.elementAt(0);
String firstElement = stringTestModel.firstElement();
String lastElement = stringTestModel.lastElement();
String testElement2 = "Test2";
stringTestModel.setElementAt(testElement2, 0);
stringTestModel.insertElementAt(TEST_ELEMENT, 0);
String element3 = stringTestModel.get(0);
String element4 = stringTestModel.set(0, testElement2);
stringTestModel.add(0, TEST_ELEMENT);
String removedElement = stringTestModel.remove(0);
// Test AbstractListModel
stringListModel = new AbstractListModel<String>() {
public int getSize() {
throw new UnsupportedOperationException("Not supported yet.");
}
public String getElementAt(int index) {
throw new UnsupportedOperationException("Not supported yet.");
}
};
@SuppressWarnings("serial")
ListModel<E> genericTestModel = new AbstractListModel<E>() {
public int getSize() {
throw new UnsupportedOperationException("Not supported yet.");
}
public E getElementAt(int index) {
throw new UnsupportedOperationException("Not supported yet.");
}
};
// Test DefaultListCellRenderer
cellRenderer = new DefaultListCellRenderer();
stringJList = new JList<String>(new String[]{testEntry});
listCellRendererComponent2 = cellRenderer.getListCellRendererComponent(stringJList, testEntry, 0, true, true);
}
private static void testGetSelectedValuesList() {
Vector<Integer> data = new Vector<Integer>();
for (int i = 0; i < 10; i++) {
data.add(i);
}
JList<Integer> list = new JList<Integer>(data);
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
list.setSelectedIndices(new int[]{1, 2, 3, 5, 6, 8});
@SuppressWarnings("deprecation")
Object[] expectedSelectedValues = list.getSelectedValues();
List<Integer> selectedValuesList = list.getSelectedValuesList();
assertEquals(expectedSelectedValues, selectedValuesList.toArray());
}
private static void assertEquals(Object[] expectedArray,
Object[] actualArray) {
if (!Arrays.equals(expectedArray, actualArray)) {
throw new RuntimeException("Expected: " + Arrays.toString(
expectedArray) + " but was: " + Arrays.toString(actualArray));
}
}
}

View file

@ -0,0 +1,98 @@
/*
* 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 6888156
@summary Tests table column of class Icon.class with Synth LAF
@author Peter Zhelezniakov
@run main Test6888156
*/
import java.awt.Component;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
public class Test6888156 {
private JTable table;
private Icon ICON = new Icon() {
@Override public int getIconWidth() {
return 24;
}
@Override public int getIconHeight() {
return 24;
}
@Override public void paintIcon(Component c, Graphics g, int w, int h) {
}
};
public Test6888156() {
TableModel model = new AbstractTableModel() {
@Override public int getRowCount() {
return 3;
}
@Override public int getColumnCount() {
return 2;
}
@Override public Object getValueAt(int rowIndex, int columnIndex) {
return (columnIndex == 1 ? ICON : 4);
}
@Override public Class<?> getColumnClass(int columnIndex) {
return (columnIndex == 1 ? Icon.class : int.class);
}
};
table = new JTable(model);
}
public void test(final LookAndFeel laf) throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
try {
UIManager.setLookAndFeel(laf);
} catch (UnsupportedLookAndFeelException e) {
System.err.println(laf.getDescription() +
" is unsupported; continuing");
return;
}
SwingUtilities.updateComponentTreeUI(table);
table.setSize(100, 100);
table.paint(
new BufferedImage(100, 100, BufferedImage.OPAQUE).
getGraphics());
}
});
}
public static void main(String[] args) throws Exception {
Test6888156 t = new Test6888156();
t.test(new javax.swing.plaf.nimbus.NimbusLookAndFeel());
t.test(new com.sun.java.swing.plaf.gtk.GTKLookAndFeel());
}
}