Java Code Examples for javax.swing.event.ChangeListener#stateChanged()

The following examples show how to use javax.swing.event.ChangeListener#stateChanged() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataTypePropertyManager.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 2
Source File: WeakChangeSupport.java    From radiance with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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;
    }
}
 
Example 3
Source File: DarkMenuBarUI.java    From darklaf with MIT License 5 votes vote down vote up
@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();
    };
}
 
Example 4
Source File: Palette.java    From nanoleaf-desktop with MIT License 5 votes vote down vote up
protected void fireChangeListeners()
{
    ChangeEvent event = new ChangeEvent(this);
    for (ChangeListener listener : getChangeListeners())
    {
        listener.stateChanged(event);
    }
}
 
Example 5
Source File: ColorEntry.java    From nanoleaf-desktop with MIT License 5 votes vote down vote up
protected void fireChangeListeners()
{
    ChangeEvent event = new ChangeEvent(this);
    for (ChangeListener listener : getChangeListeners())
    {
        listener.stateChanged(event);
    }
}
 
Example 6
Source File: VerticalChoicesPanel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 7
Source File: ColorSliderModel.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void fireStateChanged() {
	ChangeEvent event = new ChangeEvent(this);
	for (Iterator<ChangeListener> i = listeners.iterator(); i.hasNext();) {
		ChangeListener l = i.next();
		l.stateChanged(event);
	}
}
 
Example 8
Source File: VariousChoicesPanel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 9
Source File: ClassSearcher.java    From ghidra with Apache License 2.0 5 votes vote down vote up
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);
		}
	}
}
 
Example 10
Source File: AbstractColumnConstraintEditor.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example 11
Source File: DefaultTransformModel.java    From darklaf with MIT License 5 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 12
Source File: MarkerManager.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void notifyListeners() {
	for (ChangeListener listener : listeners) {
		listener.stateChanged(null);
	}
}
 
Example 13
Source File: ByteViewerClipboardProvider.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void notifyStateChanged() {
	ChangeEvent event = new ChangeEvent(this);
	for (ChangeListener listener : listeners) {
		listener.stateChanged(event);
	}
}
 
Example 14
Source File: CodeBrowserClipboardProvider.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void notifyStateChanged() {
	ChangeEvent event = new ChangeEvent(this);
	for (ChangeListener listener : listeners) {
		listener.stateChanged(event);
	}
}
 
Example 15
Source File: ListingMergePanel.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public void notifyListeners() {
	ChangeEvent event = new ChangeEvent(this);
	for (ChangeListener backgroundListener : backgroundListenerList) {
		backgroundListener.stateChanged(event);
	}
}
 
Example 16
Source File: VariousChoicesPanel.java    From ghidra with Apache License 2.0 4 votes vote down vote up
/**
 * 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();
}
 
Example 17
Source File: FidFileManager.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void notifyListeners() {
	for (ChangeListener listener : listeners) {
		listener.stateChanged(null);
	}
}
 
Example 18
Source File: DecompilerClipboardProvider.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void notifyStateChanged() {
	ChangeEvent event = new ChangeEvent(this);
	for (ChangeListener listener : listeners) {
		listener.stateChanged(event);
	}
}
 
Example 19
Source File: OpenCloseManager.java    From ghidra with Apache License 2.0 4 votes vote down vote up
private void notifyDataToggled() {
	for (ChangeListener l : listeners) {
		l.stateChanged(null);
	}
}
 
Example 20
Source File: ColorWheelPanel.java    From radiance with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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);
}