下面列出了javax.swing.event.ChangeListener#stateChanged() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void stateChanged(ChangeEvent e) {
ChangeListener originalListener = this.listenerRef.get();
if (originalListener != null) {
originalListener.stateChanged(e);
} else {
// the original is gone - unregister explicitly
if (this.sourceRef != null) {
ChangeAware source = this.sourceRef.get();
if (source != null) {
source.removeChangeListener(this);
}
}
this.listenerRef = null;
this.sourceRef = null;
}
}
/**
* Notify listeners that the favorites list changed.
*/
private void notifyListeners() {
if (changeListeners.isEmpty()) {
return;
}
Runnable notifyRunnable = new Runnable() {
@Override
public void run() {
ChangeEvent event = new ChangeEvent(DataTypePropertyManager.this);
for (ChangeListener l : changeListeners) {
l.stateChanged(event);
}
}
};
SystemUtilities.runSwingNow(notifyRunnable);
}
/**
* If {!oldValue.equals(newValue)}, a {@link ChangeEvent} will be fired.
*
* @param oldValue an old value
* @param newValue a new value
*/
protected void fireChangeEvent(final Object oldValue, final Object newValue) {
if (!oldValue.equals(newValue)) {
ChangeEvent event = new ChangeEvent(this);
for (ChangeListener listener : listeners.keySet()) {
listener.stateChanged(event);
}
}
}
@Override
protected ChangeListener createChangeListener() {
ChangeListener listener = super.createChangeListener();
return e -> {
listener.stateChanged(e);
// Fixes popup graphics creeping into the component when it is not opaque.
menuBar.repaint();
};
}
/**
* Notify all monitors that the configuration of the constraint has changed.
*/
protected void notifyConstraintChanged() {
ChangeEvent changeEvent = new ChangeEvent(this);
for (ChangeListener changeListener : listeners) {
changeListener.stateChanged(changeEvent);
}
}
private static void fireClassListChanged() {
for (ChangeListener listener : listenerList) {
try {
listener.stateChanged(null);
}
catch (Throwable t) {
Msg.showError(ClassSearcher.class, null, "Exception",
"Error in listener for class list changed", t);
}
}
}
/**
* Adds checkbox choices as a row of the table.
* Check boxes allow you to select one or more choices in the row.
*
* @param title title the is placed at the beginning of the row
* @param choices the text for each choice in the row
* @param listener listener that gets notified whenever the state of
* one of the checkboxes in this row changes.
*/
void addMultipleChoice(final String title, final String[] choices,
final ChangeListener listener) {
adjustColumnCount(choices.length + 1);
MyLabel titleComp = new MyLabel(title);
MyCheckBox[] cb = new MyCheckBox[choices.length];
final int row = rows.size();
final ChoiceRow choiceRow = new ChoiceRow(titleComp, cb);
ItemListener itemListener = new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
adjustUseForAllEnablement();
if (listener != null) {
ResolveConflictChangeEvent re =
new ResolveConflictChangeEvent(e.getSource(), row, choiceRow.getChoice());
listener.stateChanged(re);
}
}
};
for (int i = 0; i < choices.length; i++) {
cb[i] = new MyCheckBox(choices[i]);
cb[i].setName(getComponentName(row, (i + 1)));
cb[i].addItemListener(itemListener);
}
if (choices.length > 0) {
titleComp.setBorder(checkBoxBorder);
}
addRow(choiceRow);
rowPanel.validate();
validate();
invalidate();
adjustUseForAllEnablement();
}
public void fireStateChanged() {
ChangeEvent event = new ChangeEvent(this);
for (Iterator<ChangeListener> i = listeners.iterator(); i.hasNext();) {
ChangeListener l = i.next();
l.stateChanged(event);
}
}
/**
* Adds a row with the items in each column. The first item's component is a check box.
* @param items the text for each column.
* @param name the name for the check box component.
* @param conflictOption the conflict option value associated with selecting this row's check box.
* @param listener listener to be notified when the check box is selected or not selected.
*/
void addCheckBoxRow(final String[] items, final String name, final int conflictOption,
final ChangeListener listener) {
adjustColumnCount(items.length);
int row = rows.size();
rowTypes.add(CHECK_BOX);
rows.add(items);
MyCheckBox firstComp = new MyCheckBox(items[0], conflictOption);
firstComp.setName(name);
ItemListener itemListener = new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (listener != null) {
listener.stateChanged(null);
}
}
};
firstComp.addItemListener(itemListener);
setRowComponent(firstComp, row, 0, defaultInsets);
for (int i = 1; i < items.length; i++) {
MyLabel newComp = new MyLabel(items[i]);
newComp.setName(getComponentName(row, i));
setRowComponent(newComp, row, i, textVsCheckBoxInsets);
}
rowPanel.validate();
validate();
invalidate();
}
protected void fireChangeListeners()
{
ChangeEvent event = new ChangeEvent(this);
for (ChangeListener listener : getChangeListeners())
{
listener.stateChanged(event);
}
}
protected void fireChangeListeners()
{
ChangeEvent event = new ChangeEvent(this);
for (ChangeListener listener : getChangeListeners())
{
listener.stateChanged(event);
}
}
private void notifyStateChanged() {
ChangeEvent event = new ChangeEvent(this);
for (ChangeListener listener : listeners) {
listener.stateChanged(event);
}
}
private void notifyListeners() {
for (ChangeListener listener : listeners) {
listener.stateChanged(null);
}
}
private void notifyStateChanged() {
ChangeEvent event = new ChangeEvent(this);
for (ChangeListener listener : listeners) {
listener.stateChanged(event);
}
}
private void notifyListeners() {
for (ChangeListener listener : listeners) {
listener.stateChanged(null);
}
}
private void notifyStateChanged() {
ChangeEvent event = new ChangeEvent(this);
for (ChangeListener listener : listeners) {
listener.stateChanged(event);
}
}
public void notifyListeners() {
ChangeEvent event = new ChangeEvent(this);
for (ChangeListener backgroundListener : backgroundListenerList) {
backgroundListener.stateChanged(event);
}
}
/**
* Adds radiobutton choices as a row of the table.
* Radiobuttons allow you to select only one choice in the row.
*
* @param title title the is placed at the beginning of the row
* @param choices the text for each choice in the row
* @param listener listener that gets notified whenever the state of
* one of the radiobuttons in this row changes.
*/
void addSingleChoice(final String title, final String[] choices,
final ChangeListener listener) {
adjustColumnCount(choices.length + 1);
for (int i = 0; i < choices.length; i++) {
if (choices[i] == null) {
choices[i] = "-- none --";
}
else if (choices[i].length() == 0) {
choices[i] = "-- empty --";
}
}
MyLabel titleComp = new MyLabel(title);
MyRadioButton[] rb = new MyRadioButton[choices.length];
final int row = rows.size();
final ChoiceRow choiceRow = new ChoiceRow(titleComp, rb);
ItemListener itemListener = new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
adjustUseForAllEnablement();
if (listener != null) {
Object source = e.getSource();
if (((MyRadioButton) source).isSelected()) {
ResolveConflictChangeEvent re =
new ResolveConflictChangeEvent(source, row, choiceRow.getChoice());
listener.stateChanged(re);
}
}
}
};
ButtonGroup group = new ButtonGroup();
for (int i = 0; i < choices.length; i++) {
rb[i] = new MyRadioButton(choices[i]);
rb[i].setName("ChoiceComponentRow" + row + "Col" + (i + 1));
group.add(rb[i]);
rb[i].addItemListener(itemListener);
}
if (choices.length > 0) {
titleComp.setBorder(radioButtonBorder);
}
addRow(choiceRow);
rowPanel.validate();
validate();
invalidate();
adjustUseForAllEnablement();
}
private void notifyDataToggled() {
for (ChangeListener l : listeners) {
l.stateChanged(null);
}
}
public void setColor(Color c) {
systemColor = null;
if (c != null) {
int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();
if (useWebColors.isSelected()) {
r = Math.round(r / 51) * 51;
g = Math.round(g / 51) * 51;
b = Math.round(b / 51) * 51;
}
chooserColor = new ModelColor(r, g, b);
}
// else
c = new Color(chooserColor.R, chooserColor.G, chooserColor.B);
values = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), values);
if (values[1] == 0.0F) {
s = values[1];
b = values[2];
} else if (values[2] == 0.0F) {
b = values[2];
} else {
h = values[0];
s = values[1];
b = values[2];
}
h = Math.min(Math.max(h, 0.0), 1.0);
s = Math.min(Math.max(s, 0.0), 1.0);
b = Math.min(Math.max(b, 0.0), 1.0);
if (values[1] != 0.0F) {
if (values[1] != 0.0F)
setHue();
setSaturation();
}
setBrightness();
busy = true;
brightnessSlider.setValue(Integer.parseInt(brightEdit.getText()));
saturationSlider.setValue(Integer.parseInt(satEdit.getText()));
busy = false;
baseColorLabel.setBackground(new Color(chooserColor.R, chooserColor.G,
chooserColor.B));
if (SubstanceColorUtilities.getColorBrightness(
baseColorLabel.getBackground().getRGB()) < 128)
baseColorLabel.setForeground(Color.white);
else
baseColorLabel.setForeground(Color.black);
String colorStr;
if (decimalRGB.isSelected()) {
// Output decimal values
colorStr = " " + c.getRed() + "."
+ c.getGreen() + "."
+ c.getBlue();
} else {
// Output HEX values
colorStr = " " + ModelColor.toHexString(c.getRed())
+ ModelColor.toHexString(c.getGreen())
+ ModelColor.toHexString(c.getBlue());
}
baseColorLabel.setText(colorStr);
baseColorEdit.setText(colorStr);
ChangeEvent evt = new ChangeEvent(this);
int numListeners = changeListeners.size();
for (int i = 0; i < numListeners; i++) {
ChangeListener l = changeListeners.get(i);
l.stateChanged(evt);
}
if (hasChooser)
getColorSelectionModel().setSelectedColor(c);
}