codegenutils.java

来自「基于eclipse的工具开发代码」· Java 代码 · 共 52 行

JAVA
52
字号
package com.cownew.uidesigner.common;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.draw2d.geometry.Rectangle;

import com.cownew.ctk.io.ResourceUtils;
import com.cownew.uidesigner.Activator;

public class CodeGenUtils
{
	public static void saveToFile(IFile file, String value,
			IProgressMonitor monitor) throws CoreException
	{
		InputStream stream = null;
		try
		{
			stream = new ByteArrayInputStream(value.getBytes());

			if (file.exists())
			{
				file.setContents(stream, true, true, monitor);
			} else
			{
				file.create(stream, true, monitor);
			}
			stream.close();
		} catch (IOException e)
		{
			Activator.logException(e);
		} finally
		{
			ResourceUtils.close(stream);
		}
	}

	public static String translateBounds(Rectangle rect)
	{
		StringBuffer sb = new StringBuffer();
		sb.append("new Rectangle(").append(rect.x).append(",").append(rect.y)
				.append(",").append(rect.width).append(",").append(rect.height)
				.append(")");
		return sb.toString();
	}

}

⌨️ 快捷键说明

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