📄 wavycmd.java
字号:
/**
* Pxb dc Tool
* Copyright (C) 2008 Panxiaobo.
* $Id: WavyCmd.java 2 2008-10-15 12:07:18Z Panxiaobo $
*/
package pxb.dc;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import javax.imageio.ImageIO;
import pxb.cmd.AbstractCmd;
/**
* @author Panxiaobo [pxb1988@126.com]
*/
public class WavyCmd extends AbstractCmd
{
// 信号量
protected int signals[];
//
protected Code[] codes;
protected File file;
protected int width = 310;
protected int height = 310;
protected String type = "png";
@Override
protected boolean checkArgs(String[] args, PrintStream out)
{
if (args.length < 3)
{
return false;
}
// 0
String codes_string = args[0];
String signals_string = args[1];
String codes_array[] = codes_string.split(",");
this.codes = new Code[codes_array.length];
try
{
for (int i = 0; i < codes.length; i++)
codes[i] = (Code) this.instanceClass(codes_array[i]);
} catch (Exception e)
{
out.println("Error while instance codes :" + e.getMessage());
return false;
}
// 1
byte[] signals_byte = signals_string.getBytes();
this.signals = new int[signals_byte.length];
for (int i = 0; i < signals.length; i++)
this.signals[i] = signals_byte[i] == '1' ? 1 : 0;
// 2
file = new File(args[2]);
if (!file.exists())
{
File par = file.getParentFile();
if (par == null)
file = new File(System.getProperty("user.dir")
+ java.io.File.separator + args[2]);
else
{
par.mkdirs();
}
}
if (args.length > 3)
{
// 3
width = Integer.valueOf(args[3]);
}
if (args.length > 4)
{
// 4
height = Integer.valueOf(args[4]);
}
if (args.length > 5)
{
// 5
type = args[5];
} else
{
String name = args[2];
int x = name.lastIndexOf('.');
if (x > -1)
{
type = name.substring(x + 1, name.length());
}
}
out.println("type:" + type);
return super.checkArgs(args, out);
}
@Override
protected void doExecute(String[] args, PrintStream out)
{
// init start
DefaultPainter painter = new DefaultPainter();
painter.setCodes(codes);
painter.setSignals(signals);
for (Code code : codes)
{
code.setSignals(signals);
}
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = image.createGraphics();
graphics.setBackground(Color.WHITE);
graphics.fillRect(0, 0, width, height);
graphics.setColor(Color.BLACK);
painter.paint(graphics, 10, 10, width - 10, height - 10);
try
{
OutputStream os = new FileOutputStream(file);
ImageIO.write(image, type, os);
os.close();
out.println("Done!");
} catch (Exception e)
{
out.println("Error While Saving File:" + e.getMessage());
}
}
@Override
public String[] getExamples()
{
return new String[] { "Wavy Default 001100 a.jpg 310 310 jpg",
"Wavy Default,AMI 001100 a.jpg 310 310 jpg",
"Wavy Default,AMI 001100 a.jpg",
"Wavy Default,AMI 001100 a.png" };
}
@Override
public String getName()
{
return "Pxb DC Wavy CUI Tool";
}
@Override
public String[] getUsages()
{
return new String[] { "Wavy code[,code...] signal file [height weight type]" };
}
@Override
public String getVersion()
{
return "$Id: WavyCmd.java 2 2008-10-15 12:07:18Z Panxiaobo $";
}
protected Object instanceClass(String name) throws Exception
{
Class<?> type = null;
try
{
type = Class.forName(name);
} catch (ClassNotFoundException e)
{
String packageName = WavyCmd.class.getPackage().getName();
try
{
type = Class.forName(packageName + "." + name + "Code");
} catch (Exception ex)
{
}
}
if (type == null)
{
throw new RuntimeException("NoClassFoundException:" + name);
}
return type.newInstance();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -