scrollbar.java

来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 640 行 · 第 1/2 页

JAVA
640
字号
	}

	/*************************************************************************/

	/**
	  * Sets the width of the scrollbar's thumb, in units relative to the
	  * maximum and minimum value of the scrollbar.
	  *
	  * @param visibileAmount The new visible amount value of the scrollbar.
	  */
	public void setVisibleAmount(int visibleAmount) {
		setValues(value, visibleAmount, minimum, maximum);
	}

	/*************************************************************************/

	/**
	  * Sets the current value, visible amount, minimum, and maximum for this
	  * scrollbar.  These values are adjusted to be internally consistent
	  * if necessary.
	  *
	  * @param value The new value for this scrollbar.
	  * @param visibleAmount The new visible amount for this scrollbar.
	  * @param minimum The new minimum value for this scrollbar.
	  * @param maximum The new maximum value for this scrollbar.
	  */
	public synchronized void setValues(int value, int visibleAmount, int minimum, int maximum) {
		if (maximum < minimum)
			maximum = minimum;

		if (value < minimum)
			value = minimum;

		if (value > maximum)
			value = maximum;

		if (visibleAmount > value)
			visibleAmount = value;

		this.value = value;
		this.visibleAmount = visibleAmount;
		this.minimum = minimum;
		this.maximum = maximum;

		ScrollbarPeer sp = (ScrollbarPeer) getPeer();
		if (sp != null)
			sp.setValues(value, visibleAmount, minimum, maximum);

		int range = maximum - minimum;
		if (lineIncrement > range) {
			if (range == 0)
				lineIncrement = 1;
			else
				lineIncrement = range;

			if (sp != null)
				sp.setLineIncrement(lineIncrement);
		}

		if (pageIncrement > range) {
			if (range == 0)
				pageIncrement = 1;
			else
				pageIncrement = range;

			if (sp != null)
				sp.setPageIncrement(pageIncrement);
		}
	}

	/*************************************************************************/

	/**
	  * Returns the value added or subtracted when the user activates the scrollbar
	  * scroll by a "unit" amount.
	  *
	  * @return The unit increment value.
	  */
	public int getUnitIncrement() {
		return (lineIncrement);
	}

	/*************************************************************************/

	/**
	  * Returns the value added or subtracted when the user selects the scrollbar
	  * scroll by a "unit" amount control.
	  *
	  * @return The unit increment value.
	  *
	  * @deprecated This method is deprecated in favor of 
	  * <code>getUnitIncrement()</code>.
	  */
	public int getLineIncrement() {
		return (lineIncrement);
	}

	/*************************************************************************/

	/**
	  * Sets the value added or subtracted to the scrollbar value when the
	  * user selects the scroll by a "unit" amount control.
	  *
	  * @param unitIncrement The new unit increment amount.
	  */
	public synchronized void setUnitIncrement(int unitIncrement) {
		if (unitIncrement < 0)
			throw new IllegalArgumentException("Unit increment less than zero.");

		int range = maximum - minimum;
		if (unitIncrement > range) {
			if (range == 0)
				unitIncrement = 1;
			else
				unitIncrement = range;
		}

		if (unitIncrement == lineIncrement)
			return;

		lineIncrement = unitIncrement;

		ScrollbarPeer sp = (ScrollbarPeer) getPeer();
		if (sp != null)
			sp.setLineIncrement(lineIncrement);
	}

	/*************************************************************************/

	/**
	  * Sets the value added or subtracted to the scrollbar value when the
	  * user selects the scroll by a "unit" amount control.
	  *
	  * @param lineIncrement The new unit increment amount.
	  *
	  * @deprecated This method is deprecated in favor of
	  * <code>setUnitIncrement()</code>.
	  */
	public void setLineIncrement(int lineIncrement) {
		setUnitIncrement(lineIncrement);
	}

	/*************************************************************************/

	/**
	  * Returns the value added or subtracted when the user activates the scrollbar
	  * scroll by a "block" amount.
	  *
	  * @return The block increment value.
	  */
	public int getBlockIncrement() {
		return (pageIncrement);
	}

	/*************************************************************************/

	/**
	  * Returns the value added or subtracted when the user selects the scrollbar
	  * scroll by a "block" amount control.
	  *
	  * @return The block increment value.
	  *
	  * @deprecated This method is deprecated in favor of 
	  * <code>getBlockIncrement()</code>.
	  */
	public int getPageIncrement() {
		return (pageIncrement);
	}

	/*************************************************************************/

	/**
	  * Sets the value added or subtracted to the scrollbar value when the
	  * user selects the scroll by a "block" amount control.
	  *
	  * @param blockIncrement The new block increment amount.
	  */
	public synchronized void setBlockIncrement(int blockIncrement) {
		if (blockIncrement < 0)
			throw new IllegalArgumentException("Block increment less than zero.");

		int range = maximum - minimum;
		if (blockIncrement > range) {
			if (range == 0)
				blockIncrement = 1;
			else
				blockIncrement = range;
		}

		if (blockIncrement == pageIncrement)
			return;

		pageIncrement = blockIncrement;

		ScrollbarPeer sp = (ScrollbarPeer) getPeer();
		if (sp != null)
			sp.setPageIncrement(pageIncrement);
	}

	/*************************************************************************/

	/**
	  * Sets the value added or subtracted to the scrollbar value when the
	  * user selects the scroll by a "block" amount control.
	  *
	  * @param pageIncrement The new block increment amount.
	  *
	  * @deprecated This method is deprecated in favor of
	  * <code>setBlockIncrement()</code>.
	  */
	public void setPageIncrement(int pageIncrement) {
		setBlockIncrement(pageIncrement);
	}

	/*************************************************************************/

	/**
	  * Notifies this object to create its native peer.
	  */
	public synchronized void addNotify() {
		if (peer == null)
			peer = getToolkit().createScrollbar(this);
		super.addNotify();
	}

	/*************************************************************************/

	/**
	  * Adds a new adjustment listener to the list of registered listeners
	  * for this object.
	  *
	  * @param listener The listener to add.
	  */
	public synchronized void addAdjustmentListener(AdjustmentListener listener) {
		adjustment_listeners = AWTEventMulticaster.add(adjustment_listeners, listener);
		enableEvents(AWTEvent.ADJUSTMENT_EVENT_MASK);
	}

	/*************************************************************************/

	/**
	  * Removes the specified listener from the list of registered listeners
	  * for this object.
	  *
	  * @param listener The listener to remove.
	  */
	public synchronized void removeAdjustmentListener(AdjustmentListener listener) {
		adjustment_listeners = AWTEventMulticaster.remove(adjustment_listeners, listener);
	}

	/*************************************************************************/

	/**
	  * Processes events for this scrollbar.  It does this by calling
	  * <code>processAdjustmentEvent()</code> if the event is an instance of
	  * <code>AdjustmentEvent</code>, otherwise it calls the superclass to
	  * process the event.
	  *
	  * @param event The event to process.
	  */
	protected void processEvent(AWTEvent event) {
		if (event instanceof AdjustmentEvent)
			processAdjustmentEvent((AdjustmentEvent) event);
		else
			super.processEvent(event);
	}

	/*************************************************************************/

	/**
	  * Processes adjustment events for this object by dispatching them to
	  * any registered listeners.  Note that this method will only be called
	  * if adjustment events are enabled.  This will happen automatically if
	  * any listeners are registered.  Otherwise, it can be enabled by a
	  * call to <code>enableEvents()</code>.
	  *
	  * @param event The event to process.
	  */
	protected void processAdjustmentEvent(AdjustmentEvent event) {
		if (adjustment_listeners != null)
			adjustment_listeners.adjustmentValueChanged(event);
	}

	void dispatchEventImpl(AWTEvent e) {
		if (e.id <= AdjustmentEvent.ADJUSTMENT_LAST
			&& e.id >= AdjustmentEvent.ADJUSTMENT_FIRST
			&& (adjustment_listeners != null || (eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0))
			processEvent(e);
		else
			super.dispatchEventImpl(e);
	}

	/*************************************************************************/

	/**
	  * Returns a debugging string for this object.
	  *
	  * @return A debugging string for this object.
	  */
	protected String paramString() {
		return (
			"value="
				+ getValue()
				+ ",visibleAmount="
				+ getVisibleAmount()
				+ ",minimum="
				+ getMinimum()
				+ ",maximum="
				+ getMaximum()
				+ ",pageIncrement="
				+ pageIncrement
				+ ",lineIncrement="
				+ lineIncrement
				+ ",orientation="
				+ (orientation == HORIZONTAL ? "HORIZONTAL" : "VERTICAL")
				+ super.paramString());
	}

} // class Scrollbar 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?