⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statusbar.java

📁 具有不同语法高亮的编辑器实例
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

	/**
	 * Called whenever the mouse is clicked in a component listened to by this
	 * status bar.  This method should not be overridden.
	 *
	 * @param e The mouse event.
	 */
	public void mouseClicked(MouseEvent e) {
	}


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


	/**
	 * Called whenever the mouse enters a component listened to by this
	 * status bar.  This method should not be overridden.
	 *
	 * @param e The mouse event.
	 */
	public void mouseEntered(MouseEvent e) {

		Component c = e.getComponent();
		String description = null;

		// First check to see if we have a button with an action whose description is
		// defined.
		if (c instanceof AbstractButton) {
			Action a = ((AbstractButton)c).getAction();
			if (a!=null)
				description = (String)a.getValue(Action.LONG_DESCRIPTION);
		}

		// Otherwise, check the accessible context of the component.
		if (description==null)
			description = c.getAccessibleContext().
							getAccessibleDescription();

		if (description != null)
			setStatusMessage(description);

	}


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


	/**
	 * Called whenever the mouse exits in a component listened to by this
	 * status bar.  This method should not be overridden.
	 *
	 * @param e The mouse event.
	 */
	public final void mouseExited(MouseEvent e) {
		setStatusMessage(defaultMessage);
	}


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


	/**
	 * Called whenever the mouse is pressed in a component listened to by this
	 * status bar.  This method should not be overridden.
	 *
	 * @param e The mouse event.
	 */
	public void mousePressed(MouseEvent e) {
	}


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


	/**
	 * Called whenever the mouse is released in a component listened to by this
	 * status bar.  This method should not be overridden.
	 *
	 * @param e The mouse event.
	 */
	public void mouseReleased(MouseEvent e) {
	}


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


	/**
	 * Setter function for message in the status bar.
	 *
	 * @param newMessage The new message to display.
	 * @see #getStatusMessage
	 */
	public void setStatusMessage(String newMessage) {
		statusMessage.setText(newMessage);
		// We paint immediately for components like
		// org.fife.ui.FindInFilesDialog.
		statusMessage.paintImmediately(statusMessage.getBounds());
	}


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


	/**
	 * Sets the "style" used for this status bar.  This method fires a
	 * property change event of type <code>STYLE_PROPERTY</code>.
	 *
	 * @param style The style to use.  If this value is invalid,
	 *              <code>WINDOWS_98_STYLE</code> is used.
	 * @see #getStyle
	 */
	public void setStyle(int style) {

		// Be sure the passed-in style is valid.
		if (style<MIN_STYLE_CONSTANT || style>MAX_STYLE_CONSTANT)
			style = MIN_STYLE_CONSTANT;

		// Only change styles if the new style is different.
		if (this.style != style) {

			// Stuff appropriate for all styles.
			Component[] comps = getComponents();
			int count = comps.length;
			if (sizeGrip!=null)
				count--; // Skip the size grip if necessary.
			int temp = this.style;
			this.style = style;
			for (int i=1; i<count; i++) {
				((JComponent)comps[i]).
							setBorder(getStatusBarComponentBorder());
			}
			this.style = temp;

			// Any specialization needed.
			switch (style) {

				case WINDOWS_98_STYLE:
					if (this.style==WINDOWS_XP_STYLE) {
						remove(count-1); // Remove the filler panel.
					}
					break;

				case WINDOWS_XP_STYLE:
					// Add the filler panel.
					GridBagConstraints c = new GridBagConstraints();
					c.fill = GridBagConstraints.BOTH;
					c.weightx = 0.0;
					JPanel filler = new StatusBarPanel();//JPanel();
					gridBag.setConstraints(filler, c);
					// We can't use addStatusBarComponent as the filler is
					// a special case.
					add(filler, count);
					break;

			}

			// Fire the property change!
			int oldStyle = this.style;
			this.style = style;
			firePropertyChange(STYLE_PROPERTY, oldStyle, style);

		}

	}


/*****************************************************************************/
/********************* PRIVATE INNER CLASSES *********************************/
/*****************************************************************************/


	/**
	 * A gripper object placed in the bottom right-hand corner of a
	 * status bar.
	 *
	 * @author Robert Futrell
	 * @version 1.0
	 */
	private class SizeGrip extends StatusBarPanel {

		/**
		 * 
		 */
		private static final long serialVersionUID = 3324594137498581125L;

		private Window window;
		private ComponentAdapter maximizeWindow;

		/**
		 * Whether or not to paint the grip.  This is set to
		 * <code>false</code> when the parent window is maximized.
		 */
		private boolean paintGrip;

		/**
		 * Creates the size grip.  If the system doesn't support
		 * <code>java.awt.Robot</code> (such as UNIX systems which don't have
		 * XTEST 2.2 installed), the grip will be visible but cannot be used
		 * to stretch the window.
		 */
		public SizeGrip() {

			// Only enable resize functionality if we have a Robot.
			if (getRobot()!=null) {
				enableEvents(AWTEvent.MOUSE_EVENT_MASK);
				setAutoscrolls(true);
				setCursor(Cursor.getPredefinedCursor(
										Cursor.NW_RESIZE_CURSOR));
			}

			// Listens for the parent window being maximized.  When it is,
			// the size grip doesn't paint itself to visually show that the
			// window cannot be stretched anymore.
			maximizeWindow = new ComponentAdapter() {
				long prevTime;
				boolean isLastResize;
				public void componentResized(ComponentEvent e) {
					checkMaximize(true);
				}
				public void componentMoved(ComponentEvent e) {
					checkMaximize(false);
				}
				public void componentShown(ComponentEvent e) {
					// Must do this to display size grip on first display.
					checkMaximize(!isLastResize);
				}
				public void checkMaximize(boolean resize) {
					long currTime = System.currentTimeMillis();
					if((isLastResize!=resize) && (prevTime+100>currTime)) {
						paintGrip = shouldPaintGrip();
					}
					isLastResize = resize;
					prevTime = currTime;
				}
			};

		}

		protected void processMouseEvent(MouseEvent e) {

			super.processMouseEvent(e);

			switch(e.getID()) {

				case MouseEvent.MOUSE_PRESSED:
					Robot robot = getRobot();
					if (robot!=null) {
						Dimension dim = window.getSize();
						Point p = e.getPoint();
						Point point = SwingUtilities.convertPoint(this, p,
														window);
						int offsetX = dim.width  - point.x-2;
						int offsetY = dim.height - point.y-2;
						SwingUtilities.convertPointToScreen(p,this);
						robot.mouseRelease(InputEvent.BUTTON1_MASK);
						robot.mouseMove(p.x+offsetX, p.y+offsetY);
						robot.mousePress(InputEvent.BUTTON1_MASK);
					}
					break;
			}

		}

		public Dimension getMinimumSize(){
			return new Dimension(20,20);
		}

		public Dimension getPreferredSize(){
			return getMinimumSize();
		}

		/**
		 * Called when this component loses its parent.  This method is
		 * overridden so we can remove the component listener we added
		 * to the parent.
		 */
		public void removeNotify() {
			window.removeComponentListener(maximizeWindow);
		}

		/**
		 * Called when this component receives a parent.  This method is
		 * overridden so we can add a component listener to the parent window
		 * to know when it is maximized/de-maximized.
		 */
		public void addNotify() {
			super.addNotify();
			window = (Window)SwingUtilities.getRoot(this);
			window.addComponentListener(maximizeWindow);
		}

		private boolean shouldPaintGrip() {
			Rectangle rect = window.getBounds();
			Dimension dim = Toolkit.getDefaultToolkit().
									getScreenSize();
			if((rect.x == rect.y) && (rect.x <= 0) &&
				(rect.x>-20) && (dim.width-20<rect.width) &&
				(dim.width +20 > rect.width))
					return false;
			return true;
		}

		public void paintComponent(Graphics g) {

			Dimension dim = getSize();

			// Paint the background.
			super.paintComponent(g);

			// If the window isn't maximized, paint the grip part.
			if (paintGrip==true) {

				Color c1 = UIManager.getColor("Label.disabledShadow");
				Color c2 = UIManager.getColor("Label.disabledForeground");

				switch (style) {

					case WINDOWS_98_STYLE:
						int width = dim.width;
						int height = dim.height;
						g.setColor(c1.brighter());
						g.drawLine(7,height, width,7);
						g.drawLine(11,height, width,11);
						g.drawLine(15,height, width,15);
						g.setColor(c2.darker());
						g.drawLine(8,height, width,8);
						g.drawLine(12,height, width,12);
						g.drawLine(16,height, width,16);
						break;

					default:// WINDOWS_XP_STYLE:
						width  = dim.width  - 3;
						height = dim.height - 3;
						g.setColor(c1);
						g.fillRect(width-9,height-1, 3,3);
						g.fillRect(width-5,height-1, 3,3);
						g.fillRect(width-1,height-1, 3,3);
						g.fillRect(width-5,height-5, 3,3);
						g.fillRect(width-1,height-5, 3,3);
						g.fillRect(width-1,height-9, 3,3);
						g.setColor(c2);
						g.fillRect(width-9,height-1, 2,2);
						g.fillRect(width-5,height-1, 2,2);
						g.fillRect(width-1,height-1, 2,2);
						g.fillRect(width-5,height-5, 2,2);
						g.fillRect(width-1,height-5, 2,2);
						g.fillRect(width-1,height-9, 2,2);
						break;

				}

			}

		}

	}


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

}

⌨️ 快捷键说明

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