Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package hu.kazocsaba.imageviewer;
 
Stores the x and y coordinate of a pixel. Either both coordinate is positive or zero, indicating a valid pixel, or both are -1, indicating no pixel is selected or should be shown.

Author(s):
Kazó Csaba
public class PixelModel {
	private final EventListenerList listenerList = new EventListenerList();
	private int x = -1, y = -1;

Adds a ChangeListener to the model. @param listener the listener to add
	public void addChangeListener(ChangeListener listener) {
		.add(ChangeListener.classlistener);
	}

Removes a ChangeListener from the model.

Parameters:
listener the listener to remove
	public void removeChangeListener(ChangeListener listener) {
	}

Notifies the registered listeners that the model has changed.
	protected void fireChange() {
		ChangeEvent event = new ChangeEvent(this);
		for (int i = listeners.length - 2; i >= 0; i -= 2) {
			if (listeners[i] == ChangeListener.class) {
				((ChangeListener)listeners[i + 1]).stateChanged(event);
			}
		}
	}

Changes the pixel stored in this model. If either coordinate is negative, the new value of the model will be (-1, -1).

Parameters:
x the new x coordinate
y the new y coordinate
	public void set(int xint y) {
		if (x<0 || y<0) {
			x=-1;
			y=-1;
		}
		if (this.!=x || this.!=y) {
			this.=x;
			this.=y;
		}
	}

Returns the current x coordinate.

Returns:
the x coordinate
	public int getX() {return ;}
Returns the current y coordinate.

Returns:
the y coordinate
	public int getY() {return ;}

Returns whether the pixel is marked as invalid by setting one of the coordinates to -1.

Returns:
true if the model does not have a valid pixel
	public boolean isInvalid() {
		return <0;
	}
New to GrepCode? Check out our FAQ X