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

📄 borderstyler.java

📁 lumaQQ的源文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			});
			lblMax.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					Label lbl = (Label)e.getSource();
					lbl.setImage(shell.getMaximized() ? res.getImage(Resources.bmpRestoreDown) : res.getImage(Resources.bmpMaxDown));
				}
				
				@Override
				public void mouseUp(MouseEvent e) {
					doMaximize();
				}
			});
			
			referenceLabel = lblMax;
		}		
		
		// 最小化按钮
		if(showMinButton) {
			Label lblMin = new Label(topDown, SWT.CENTER);		
			lblMin.setImage(res.getImage(Resources.bmpMinNormal));
			fd = new FormData();
			fd.top = new FormAttachment(0, 0);
			fd.bottom = new FormAttachment(0, 16);
			fd.right = new FormAttachment(referenceLabel, 0, SWT.LEFT);
			fd.left = new FormAttachment(referenceLabel, -16, SWT.LEFT);
			lblMin.setLayoutData(fd);
			lblMin.addMouseTrackListener(new MouseTrackAdapter() {
				@Override
				public void mouseEnter(MouseEvent e) {
					Label lbl = (Label)e.getSource();
					lbl.setImage(res.getImage(Resources.bmpMinHover));
				}
				
				@Override
				public void mouseExit(MouseEvent e) {
					Label lbl = (Label)e.getSource();
					lbl.setImage(res.getImage(Resources.bmpMinNormal));
				}
			});
			lblMin.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					Label lbl = (Label)e.getSource();
					lbl.setImage(res.getImage(Resources.bmpMinDown));
				}
				
				@Override
				public void mouseUp(MouseEvent e) {
					Label lbl = (Label)e.getSource();
					lbl.setImage(res.getImage(Resources.bmpMinHover));
					shell.setMinimized(true);
					if(hideWhenMinimize)
						shell.setVisible(false);
				}
			});			
			
			referenceLabel = lblMin;
		}
		
		// 扩展按钮
		if(showPlusButton) {
			Label lblPlus = new Label(topDown, SWT.CENTER);
			lblPlus.setImage(res.getImage(Resources.bmpPlusNormal));
			fd = new FormData();
			fd.top = new FormAttachment(0, 0);
			fd.bottom = new FormAttachment(0, 16);
			fd.right = new FormAttachment(referenceLabel, -1, SWT.LEFT);
			fd.left = new FormAttachment(referenceLabel, -17, SWT.LEFT);
			lblPlus.setLayoutData(fd);
			lblPlus.addMouseTrackListener(new MouseTrackAdapter() {
				@Override
				public void mouseEnter(MouseEvent e) {
					Label lbl = (Label)e.getSource();
					lbl.setImage(res.getImage(Resources.bmpPlusHover));
				}
				
				@Override
				public void mouseExit(MouseEvent e) {
					Label lbl = (Label)e.getSource();
					lbl.setImage(res.getImage(Resources.bmpPlusNormal));
				}
			});
			lblPlus.addMouseListener(new MouseListener() {
				public void mouseDown(MouseEvent e) {
					Label lbl = (Label)e.getSource();
					lbl.setImage(res.getImage(Resources.bmpPlusDown));
					if(plusMouseListener != null)
						plusMouseListener.mouseDown(e);
				}
				
				public void mouseDoubleClick(MouseEvent e) {
					if(plusMouseListener != null)
						plusMouseListener.mouseDoubleClick(e);
				}
				
				public void mouseUp(MouseEvent e) {
					Label lbl = (Label)e.getSource();
					lbl.setImage(res.getImage(Resources.bmpPlusHover));
					if(plusMouseListener != null)
						plusMouseListener.mouseUp(e);
				}
			});	
		}

		right = new Label(shell, SWT.LEFT);
		gd = new GridData(GridData.FILL_VERTICAL);
		gd.widthHint = 5;
		gd.verticalSpan = 2;
		right.setLayoutData(gd);
		if(resizable)
			right.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEWE));
		right.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent e) {
				Rectangle bound = ((Control) e.getSource()).getBounds();
				int i = 4;
				for(Color c : Colors.MAINSHELL_BORDERS) {
					e.gc.setForeground(c);
					e.gc.drawLine(i, 0, i, bound.height);
					i--;
				}
			}
		});
		if(resizable) {
			right.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					Control control = (Control)e.getSource();
					downX = control.toDisplay(e.x, e.y).x;
				}
				@Override
				public void mouseUp(MouseEvent e) {
					Control control = (Control)e.getSource();
					int newX = control.toDisplay(e.x, e.y).x;
					int dx = newX - downX;
					if(dx == 0)
						return;
					Point size = shell.getSize();
					size.x += dx;
					setShellSize(size);
				}
			});			
		}
		
		center = new Composite(shell, SWT.NONE);
		center.setLayoutData(new GridData(GridData.FILL_BOTH));
		layout = new GridLayout();
		layout.marginHeight = layout.marginWidth = layout.horizontalSpacing = layout.verticalSpacing = 0;
		center.setLayout(layout);

		Composite leftBottom = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND);
		if(resizable)
			leftBottom.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENESW));
		gd = new GridData();
		gd.widthHint = gd.heightHint = 5;
		leftBottom.setLayoutData(gd);
		leftBottom.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent e) {
				Rectangle bound = ((Control) e.getSource()).getBounds();
				int i = 0;
				for(Color c : Colors.MAINSHELL_BORDERS) {
					e.gc.setForeground(c);
					e.gc.drawLine(i, bound.height - i - 1, i, 0);
					e.gc.drawLine(i, bound.height - i - 1, bound.width, bound.height - i - 1);
					i++;
				}
			}
		});
		if(resizable) {
			leftBottom.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					Control control = (Control)e.getSource();
					Point loc = control.toDisplay(e.x, e.y);
					downX = loc.x;
					downY = loc.y;
				}
				@Override
				public void mouseUp(MouseEvent e) {
					Control control = (Control)e.getSource();
					Point loc = control.toDisplay(e.x, e.y);
					int dx = downX - loc.x;
					int dy = loc.y - downY;
					if(dx == 0 && dy == 0)
						return;
					Rectangle bound = shell.getBounds();
					bound.x -= dx;					
					bound.width += dx;
					bound.height += dy;					
					setShellBound(bound);
				}
			});			
		}
		
		bottom = new Label(shell, SWT.LEFT);
		if(resizable)
			bottom.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS));
		gd = new GridData(GridData.FILL_HORIZONTAL);
		gd.heightHint = 5;
		bottom.setLayoutData(gd);
		bottom.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent e) {
				Rectangle bound = ((Control) e.getSource()).getBounds();
				int i = 0;
				for(Color c : Colors.MAINSHELL_BORDERS) {
					e.gc.setForeground(c);
					e.gc.drawLine(0, 5 - i - 1, bound.width, 5 - i - 1);
					i++;
				}
			}
		});
		if(resizable) {
			bottom.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					Control control = (Control)e.getSource();
					downY = control.toDisplay(e.x, e.y).y;
				}
				@Override
				public void mouseUp(MouseEvent e) {
					Control control = (Control)e.getSource();
					int newY = control.toDisplay(e.x, e.y).y;
					int dy = newY - downY;	
					if(dy == 0)
						return;
					Point size = shell.getSize();
					size.y += dy;
					setShellSize(size);
				}
			});			
		}
		
		Composite rightBottom = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND);
		if(resizable)
			rightBottom.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENWSE));
		gd = new GridData();
		gd.widthHint = gd.heightHint = 5;
		rightBottom.setLayoutData(gd);
		rightBottom.addPaintListener(new PaintListener() {
			public void paintControl(PaintEvent e) {
				Rectangle bound = ((Control) e.getSource()).getBounds();
				int i = 0;
				for(Color c : Colors.MAINSHELL_BORDERS) {
					e.gc.setForeground(c);
					e.gc.drawLine(bound.width - i - 1, bound.height - i - 1, bound.width - i - 1, 0);
					e.gc.drawLine(bound.width - i - 1, bound.height - i - 1, 0, bound.height - i - 1);
					i++;
				}
			}
		});
		if(resizable) {
			rightBottom.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					Control control = (Control)e.getSource();
					Point loc = control.toDisplay(e.x, e.y);
					downX = loc.x;
					downY = loc.y;
				}
				@Override
				public void mouseUp(MouseEvent e) {
					Control control = (Control)e.getSource();
					Point loc = control.toDisplay(e.x, e.y);
					int dx = loc.x - downX;
					int dy = loc.y - downY;
					if(dx == 0 && dy == 0)
						return;
					Point size = shell.getSize();
					size.x += dx;
					size.y += dy;
					setShellSize(size);
				}
			});			
		}
		
		return center;
	}

	/**
	 * 最大化或还原
	 */
	protected void doMaximize() {
		// 不知道为什么,在linux下面setMaximize方法没作用,nnd
		// 而且setBounds之后还需要setLocation,没办法
		if(LumaQQ.IS_GTK) {
			if(shell.getMaximized()) {						
				shell.setBounds(oldBound);	
				shell.setLocation(oldBound.x, oldBound.y);
				shell.setMaximized(false);
			} else {
				oldBound = shell.getBounds();
				shell.setBounds(display.getClientArea());
				shell.setMaximized(true);
			}
		} else
			shell.setMaximized(!shell.getMaximized());
		lblMax.setImage(shell.getMaximized() ? res.getImage(Resources.bmpRestoreHover) : res.getImage(Resources.bmpMaxHover));
	}

	protected void fireMouseUpEvent(MouseEvent e) {
		if(mouseListeners == null)
			return;
		
		for(MouseListener ml : mouseListeners)
			ml.mouseUp(e);
	}

	protected void fireMouseDownEvent(MouseEvent e) {
		if(mouseListeners == null)
			return;
		
		for(MouseListener ml : mouseListeners)
			ml.mouseDown(e);
	}

	/**
	 * @return Returns the hideWhenMinimize.
	 */
	public boolean isHideWhenMinimize() {
		return hideWhenMinimize;
	}

	/**
	 * @param hideWhenMinimize The hideWhenMinimize to set.
	 */
	public void setHideWhenMinimize(boolean hideWhenMinimize) {
		this.hideWhenMinimize = hideWhenMinimize;
	}

	/**
	 * @return Returns the resizable.
	 */
	public boolean isResizable() {
		return resizable;
	}

	/**
	 * @param resizable The resizable to set.
	 */
	public void setResizable(boolean resizable) {
		this.resizable = resizable;
	}

	/**
	 * @return Returns the showMaxButton.
	 */
	public boolean isShowMaxButton() {
		return showMaxButton;
	}

	/**
	 * @param showMaxButton The showMaxButton to set.
	 */
	public void setShowMaxButton(boolean showMaxButton) {
		this.showMaxButton = showMaxButton;
	}

	public Control getLeft() {
		return left;
	}

	public Control getRight() {
		return right;
	}

	public Control getTop() {
		return top;
	}

	public Control getBottom() {
		return bottom;
	}

	/**
	 * @return Returns the center.
	 */
	public Composite getCenter() {
		return center;
	}

	/**
	 * @return Returns the checkMinimizeWhenClose.
	 */
	public boolean isCheckMinimizeWhenClose() {
		return checkMinimizeWhenClose;
	}

	/**
	 * @param checkMinimizeWhenClose The checkMinimizeWhenClose to set.
	 */
	public void setCheckMinimizeWhenClose(boolean checkMinimizeWhenClose) {
		this.checkMinimizeWhenClose = checkMinimizeWhenClose;
	}

	/**
	 * @return Returns the maximizeWhenDoubleClick.
	 */
	public boolean isMaximizeWhenDoubleClick() {
		return maximizeWhenDoubleClick;
	}

	/**
	 * @param maximizeWhenDoubleClick The maximizeWhenDoubleClick to set.
	 */
	public void setMaximizeWhenDoubleClick(boolean maximizeWhenDoubleClick) {
		this.maximizeWhenDoubleClick = maximizeWhenDoubleClick;
	}

	/**
	 * @return Returns the minHeight.
	 */
	public int getMinHeight() {
		return minHeight;
	}

	/**
	 * @param minHeight The minHeight to set.
	 */
	public void setMinHeight(int minHeight) {
		this.minHeight = minHeight;
	}

	/**
	 * @return Returns the minWidth.
	 */
	public int getMinWidth() {
		return minWidth;
	}

	/**
	 * @param minWidth The minWidth to set.
	 */
	public void setMinWidth(int minWidth) {
		this.minWidth = minWidth;
	}

	/**
	 * @return the showMinButton
	 */
	public boolean isShowMinButton() {
		return showMinButton;
	}

	/**
	 * @param showMinButton the showMinButton to set
	 */
	public void setShowMinButton(boolean showMinButton) {
		this.showMinButton = showMinButton;
	}

	/**
	 * @return the showPlusButton
	 */
	public boolean isShowPlusButton() {
		return showPlusButton;
	}

	/**
	 * @param showPlusButton the showPlusButton to set
	 */
	public void setShowPlusButton(boolean showPlusButton) {
		this.showPlusButton = showPlusButton;
	}

	/**
	 * @param plusMouseListener the plusMouseListener to set
	 */
	public void setPlusMouseListener(MouseListener plusMouseListener) {
		this.plusMouseListener = plusMouseListener;
	}
}

⌨️ 快捷键说明

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