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

📄 swtx.java

📁 ktable 是一个由java开发的,对控制报表的项目,它最大的特点是使用独特的算法,能支持巨大的报表(千万以上?).
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	        StringBuffer wrappedText = new StringBuffer();
	        String[] lines = text.split("\n");
	        int cutoffLength = width/gc.getFontMetrics().getAverageCharWidth();
	        if (cutoffLength<3) return text;
	        for (int i=0; i<lines.length; i++) {
	            int breakOffset = 0;
	            while (breakOffset<lines[i].length()) {
	                String lPart = lines[i].substring(breakOffset, Math.min(breakOffset+cutoffLength, lines[i].length()));
	                Point lineSize = getCachedStringExtent(gc, lPart);
	                while ((lPart.length() > 0) && (lineSize.x >= width)) {
	                    lPart = lPart.substring(0, Math.max(lPart.length() - 1, 0));
	                    lineSize = getCachedStringExtent(gc, lPart);
	                }
	                wrappedText.append(lPart);
	                breakOffset += lPart.length();
	                wrappedText.append('\n');
	            }
	        }
	        return wrappedText.substring(0, Math.max(wrappedText.length()-1, 0));
	    } else
	        return text;
	    
	}
	
	public static void drawButtonUp(
			GC gc,
			String text,
			int textAlign,
			Image image,
			int imageAlign,
			int x,
			int y,
			int w,
			int h,
			Color face,
			Color shadowHigh,
			Color shadowNormal,
			Color shadowDark,
			int leftMargin,
			int topMargin) {
		Color prevForeground = gc.getForeground();
		Color prevBackground = gc.getBackground();
		Rectangle clip = gc.getClipping();
		clip.height++;
		clip.width++;
		gc.setClipping(clip);
		
		try {
			gc.setBackground(face);
			gc.setForeground(shadowHigh);
			gc.drawLine(x, y, x, y + h - 1);
			gc.drawLine(x, y, x + w - 2, y);
			gc.setForeground(shadowDark);
			gc.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
			gc.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
			gc.setForeground(shadowNormal);
			gc.drawLine(x + w - 2, y + 1, x + w - 2, y + h - 2);
			gc.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
			
			gc.fillRectangle(x+1, y+1, w-3, h-3);
			gc.setForeground(prevForeground);
			drawTextImage(
					gc,
					text,
					textAlign,
					image,
					imageAlign,
					x + 1 + leftMargin,
					y + 1 + topMargin,
					w - 3 - leftMargin,
					h - 3 - topMargin);
		} finally {
			gc.setForeground(prevForeground);
			gc.setBackground(prevBackground);
		}
	}
	
	public static void drawButtonUp(
			GC gc,
			String text,
			int textAlign,
			Image image,
			int imageAlign,
			int x,
			int y,
			int w,
			int h,
			Color face) {
		Display display = Display.getCurrent();
		drawButtonUp(
				gc,
				text,
				textAlign,
				image,
				imageAlign,
				x,
				y,
				w,
				h,
				face,
				display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW),
				display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
				display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW),
				2,
				2);
	}
	
	public static void drawButtonUp(
			GC gc,
			String text,
			int textAlign,
			Image image,
			int imageAlign,
			Rectangle r,
			int leftMargin,
			int topMargin) {
		Display display = Display.getCurrent();
		drawButtonUp(
				gc,
				text,
				textAlign,
				image,
				imageAlign,
				r.x,
				r.y,
				r.width,
				r.height,
				display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND),
				display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW),
				display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
				display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW),
				leftMargin,
				topMargin);
	}
	
	public static void drawButtonUp(
			GC gc,
			String text,
			int textAlign,
			Image image,
			int imageAlign,
			int x,
			int y,
			int w,
			int h) {
		Display display = Display.getCurrent();
		drawButtonUp(
				gc,
				text,
				textAlign,
				image,
				imageAlign,
				x,
				y,
				w,
				h,
				display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND),
				display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW),
				display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
				display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW),
				2,
				2);
	}
	
	public static void drawButtonUp(GC gc, String text, int textAlign, Image image, int imageAlign, Rectangle r) {
		drawButtonUp(gc, text, textAlign, image, imageAlign, r.x, r.y, r.width, r.height);
	}
	
	public static void drawButtonDown(
			GC gc,
			String text,
			int textAlign,
			Image image,
			int imageAlign,
			int x,
			int y,
			int w,
			int h,
			Color face,
			Color shadowNormal,
			int leftMargin,
			int topMargin) {
		Color prevForeground = gc.getForeground();
		Color prevBackground = gc.getBackground();
		try {
			gc.setBackground(face);
			gc.setForeground(shadowNormal);
			Rectangle clip = gc.getClipping();
			clip.height++;
			clip.width++;
			gc.setClipping(clip);
			gc.drawRectangle(x, y, w - 1, h - 1);
			gc.fillRectangle(x+1, y+1, w-2, h-2);
			gc.setForeground(prevForeground);
			drawTextImage(
					gc,
					text,
					textAlign,
					image,
					imageAlign,
					x + 2 + leftMargin,
					y + 2 + topMargin,
					w - 3 - leftMargin,
					h - 3 - topMargin);
		} finally {
			gc.setForeground(prevForeground);
			gc.setBackground(prevBackground);
		}
	}
	
	public static void drawButtonDown(
			GC gc,
			String text,
			int textAlign,
			Image image,
			int imageAlign,
			int x,
			int y,
			int w,
			int h) {
		Display display = Display.getCurrent();
		drawButtonDown(
				gc,
				text,
				textAlign,
				image,
				imageAlign,
				x,
				y,
				w,
				h,
				display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND),
				display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
				2,
				2);
	}
	
	public static void drawButtonDown(GC gc, String text, int textAlign, Image image, int imageAlign, Rectangle r) {
		drawButtonDown(gc, text, textAlign, image, imageAlign, r.x, r.y, r.width, r.height);
	}
	
	public static void drawButtonDown(
			GC gc,
			String text,
			int textAlign,
			Image image,
			int imageAlign,
			int x,
			int y,
			int w,
			int h,
			Color face) {
		Display display = Display.getCurrent();
		drawButtonDown(
				gc,
				text,
				textAlign,
				image,
				imageAlign,
				x,
				y,
				w,
				h,
				face,
				display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW),
				2,
				2);
	}
	public static void drawButtonDeepDown(
			GC gc,
			String text,
			int textAlign,
			Image image,
			int imageAlign,
			int x,
			int y,
			int w,
			int h) {
		Display display = Display.getCurrent();
		gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
		gc.drawLine(x, y, x + w - 2, y);
		gc.drawLine(x, y, x, y + h - 2);
		gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
		gc.drawLine(x + w - 1, y, x + w - 1, y + h - 1);
		gc.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
		gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
		gc.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
		gc.drawLine(x + w - 2, y + h - 2, x + w - 2, y + 1);
		
		gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_FOREGROUND));
		gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
		gc.fillRectangle(x + 2, y + 2, w - 4, 1);
		gc.fillRectangle(x + 1, y + 2, 2, h - 4);

		gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
		drawTextImage(gc, text, textAlign, image, imageAlign, x + 2 + 1, y + 2 + 1, w - 4, h - 3 - 1);
	}
	public static void drawButtonDeepDown(
			GC gc,
			String text,
			int textAlign,
			Image image,
			int imageAlign,
			Rectangle r) {
		drawButtonDeepDown(gc, text, textAlign, image, imageAlign, r.x, r.y, r.width, r.height);
	}
	public static void drawFlatButtonUp(
			GC gc,
			String text,
			int textAlign,
			Image image,
			int imageAlign,
			int x,
			int y,
			int w,
			int h,
			Color face,
			Color shadowLight,
			Color shadowNormal,
			int leftMargin,
			int topMargin) {
		Color prevForeground = gc.getForeground();
		Color prevBackground = gc.getBackground();
		try {
			gc.setForeground(shadowLight);
			gc.drawLine(x, y, x + w - 1, y);
			gc.drawLine(x, y, x, y + h);
			gc.setForeground(shadowNormal);
			gc.drawLine(x + w, y, x + w, y + h);
			gc.drawLine(x + 1, y + h, x + w, y + h);
			//
			gc.setBackground(face);
			gc.fillRectangle(x + 1, y + 1, leftMargin, h - 1);
			gc.fillRectangle(x + 1, y + 1, w - 1, topMargin);
			//
			gc.setBackground(face);
			gc.setForeground(prevForeground);
			drawTextImage(
					gc,
					text,
					textAlign,
					image,
					imageAlign,
					x + 1 + leftMargin,
					y + 1 + topMargin,
					w - 1 - leftMargin,
					h - 1 - topMargin);
		} finally {
			gc.setForeground(prevForeground);
			gc.setBackground(prevBackground);
		}
	}
	
	/**
	 * 
	 * @param gc
	 * @param image
	 * @param x
	 * @param y
	 * @param alpha
	 */
	public static void drawShadowImage(GC gc, Image image, int x, int y, int alpha) {
		Display display = Display.getCurrent();
		Point imageSize = new Point(image.getBounds().width, image.getBounds().height);
		//
		ImageData imgData = new ImageData(imageSize.x, imageSize.y, 24, new PaletteData(255, 255, 255));
		imgData.alpha = alpha;
		Image img = new Image(display, imgData);
		GC imgGC = new GC(img);
		imgGC.drawImage(image, 0, 0);
		gc.drawImage(img, x, y);
		imgGC.dispose();
		img.dispose();
	}
	
	/**
	 * Loads an image from the root of this package.
	 * @param d The display to use when creating the image.
	 * @param name The string name inclusive path to the image.
	 * @return returns the image or null.
	 */
	public static Image loadImageResource(Display d, String name) {
		try {
			Image ret = null;
			InputStream is = SWTX.class.getResourceAsStream(name);
			if (is != null) {
				ret = new Image(d,is);
				is.close();
			}
			return ret;
		} catch (Exception e1) {
			return null;
		}
	}
}

⌨️ 快捷键说明

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