计算矩阵的秩和解及其解情况的SWT代码
这里我使用的是Jama-1.0.2.jar矩阵计算的包;
关于这个包前面的文章有介绍:
http://www.blogjava.net/lusm/archive/2007/07/07/128767.html
界面:
package
com.lusm;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import com.swtdesigner.SWTResourceManager;
import org.eclipse.swt.widgets.MessageBox;
/**/ /*
* 主程序
*
* */
public class MatTest {
private static StyledText r4;
private static StyledText r3;
private static StyledText r2;
private static StyledText r1;
private static StyledText m4;
private static StyledText m3;
private static StyledText m2;
private static StyledText m1;
private static StyledText z4;
private static StyledText z3;
private static StyledText z2;
private static StyledText z1;
private static StyledText y4;
private static StyledText y3;
private static StyledText y2;
private static StyledText y1;
private static StyledText x4;
private static StyledText x3;
private static StyledText x2;
private static StyledText x1;
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setImage(SWTResourceManager.getImage(MatTest.class, "/com/sun/java/swing/plaf/windows/icons/JavaCup32.png"));
shell.setForeground(SWTResourceManager.getColor(255, 255, 255));
shell.setSize(428, 393);
shell.setText("4元一次方程");
//
shell.open();
final CLabel label = new CLabel(shell, SWT.NONE);
label.setText("运行结果:该方程组对应矩阵的秩为:");
label.setBounds(10, 194, 210, 19);
final CLabel xLabel = new CLabel(shell, SWT.NONE);
xLabel.setText("X=");
xLabel.setBounds(64, 219, 20, 19);
final CLabel rs1 = new CLabel(shell, SWT.NONE);
rs1.setBounds(115, 219, 269, 19);
final CLabel xLabel_1 = new CLabel(shell, SWT.NONE);
xLabel_1.setBounds(64, 244, 20, 19);
xLabel_1.setText("Y=");
final CLabel rs2 = new CLabel(shell, SWT.NONE);
rs2.setBounds(115, 244, 269, 19);
final CLabel xLabel_2 = new CLabel(shell, SWT.NONE);
xLabel_2.setBounds(64, 269, 20, 19);
xLabel_2.setText("Z=");
final CLabel rs3 = new CLabel(shell, SWT.NONE);
rs3.setBounds(115, 269, 269, 19);
final CLabel xLabel_3 = new CLabel(shell, SWT.NONE);
xLabel_3.setBounds(64, 294, 20, 19);
xLabel_3.setText("M=");
final CLabel rs4 = new CLabel(shell, SWT.NONE);
rs4.setBounds(115, 294, 269, 19);
x1 = new StyledText(shell, SWT.BORDER);
x1.setBackground(SWTResourceManager.getColor(241, 225, 216));
x1.setBounds(10, 10, 48, 19);
x2 = new StyledText(shell, SWT.BORDER);
x2.setBackground(SWTResourceManager.getColor(241, 225, 216));
x2.setBounds(10, 55, 48, 19);
x3 = new StyledText(shell, SWT.BORDER);
x3.setBackground(SWTResourceManager.getColor(241, 225, 216));
x3.setBounds(10, 101, 48, 19);
x4 = new StyledText(shell, SWT.BORDER);
x4.setBackground(SWTResourceManager.getColor(241, 225, 216));
x4.setBounds(10, 151, 48, 19);
y1 = new StyledText(shell, SWT.BORDER);
y1.setBackground(SWTResourceManager.getColor(241, 225, 216));
y1.setBounds(92, 10, 48, 19);
y2 = new StyledText(shell, SWT.BORDER);
y2.setBackground(SWTResourceManager.getColor(241, 225, 216));
y2.setBounds(92, 55, 48, 19);
y3 = new StyledText(shell, SWT.BORDER);
y3.setBackground(SWTResourceManager.getColor(241, 225, 216));
y3.setBounds(92, 101, 48, 19);
y4 = new StyledText(shell, SWT.BORDER);
y4.setBackground(SWTResourceManager.getColor(241, 225, 216));
y4.setBounds(92, 151, 48, 19);
z1 = new StyledText(shell, SWT.BORDER);
z1.setBackground(SWTResourceManager.getColor(241, 225, 216));
z1.setBounds(183, 10, 48, 19);
z2 = new StyledText(shell, SWT.BORDER);
z2.setBackground(SWTResourceManager.getColor(241, 225, 216));
z2.setBounds(183, 55, 48, 19);
z3 = new StyledText(shell, SWT.BORDER);
z3.setBackground(SWTResourceManager.getColor(241, 225, 216));
z3.setBounds(183, 101, 48, 19);
z4 = new StyledText(shell, SWT.BORDER);
z4.setBackground(SWTResourceManager.getColor(241, 225, 216));
z4.setBounds(183, 151, 48, 19);
m1 = new StyledText(shell, SWT.BORDER);
m1.setBackground(SWTResourceManager.getColor(241, 225, 216));
m1.setBounds(274, 10, 48, 19);
m2 = new StyledText(shell, SWT.BORDER);
m2.setBackground(SWTResourceManager.getColor(241, 225, 216));
m2.setBounds(274, 55, 48, 19);
m3 = new StyledText(shell, SWT.BORDER);
m3.setBackground(SWTResourceManager.getColor(241, 225, 216));
m3.setBounds(274, 101, 48, 19);
m4 = new StyledText(shell, SWT.BORDER);
m4.setBackground(SWTResourceManager.getColor(241, 225, 216));
m4.setBounds(274, 151, 48, 19);
r1 = new StyledText(shell, SWT.BORDER);
r1.setBackground(SWTResourceManager.getColor(241, 225, 216));
r1.setBounds(362, 10, 48, 19);
r2 = new StyledText(shell, SWT.BORDER);
r2.setBackground(SWTResourceManager.getColor(241, 225, 216));
r2.setBounds(362, 55, 48, 19);
r3 = new StyledText(shell, SWT.BORDER);
r3.setBackground(SWTResourceManager.getColor(241, 225, 216));
r3.setBounds(362, 101, 48, 19);
r4 = new StyledText(shell, SWT.BORDER);
r4.setBackground(SWTResourceManager.getColor(241, 225, 216));
r4.setBounds(362, 151, 48, 19);
final CLabel mLabel = new CLabel(shell, SWT.NONE);
mLabel.setText("M =");
mLabel.setBounds(328, 10, 40, 19);
final CLabel mLabel_1 = new CLabel(shell, SWT.NONE);
mLabel_1.setBounds(328, 55, 40, 19);
mLabel_1.setText("M =");
final CLabel mLabel_2 = new CLabel(shell, SWT.NONE);
mLabel_2.setBounds(328, 101, 40, 19);
mLabel_2.setText("M =");
final CLabel mLabel_3 = new CLabel(shell, SWT.NONE);
mLabel_3.setBounds(328, 151, 40, 19);
mLabel_3.setText("M =");
final CLabel mLabel_4 = new CLabel(shell, SWT.NONE);
mLabel_4.setBounds(237, 10, 31, 19);
mLabel_4.setText("Z +");
final CLabel mLabel_1_1 = new CLabel(shell, SWT.NONE);
mLabel_1_1.setBounds(237, 55, 31, 19);
mLabel_1_1.setText("Z +");
final CLabel mLabel_2_1 = new CLabel(shell, SWT.NONE);
mLabel_2_1.setBounds(237, 101, 31, 19);
mLabel_2_1.setText("Z +");
final CLabel mLabel_3_1 = new CLabel(shell, SWT.NONE);
mLabel_3_1.setBounds(237, 151, 31, 19);
mLabel_3_1.setText("Z +");
final CLabel mLabel_4_1 = new CLabel(shell, SWT.NONE);
mLabel_4_1.setBounds(146, 10, 31, 19);
mLabel_4_1.setText("Y +");
final CLabel mLabel_1_1_1 = new CLabel(shell, SWT.NONE);
mLabel_1_1_1.setBounds(146, 55, 31, 19);
mLabel_1_1_1.setText("Y +");
final CLabel mLabel_2_1_1 = new CLabel(shell, SWT.NONE);
mLabel_2_1_1.setBounds(146, 101, 31, 19);
mLabel_2_1_1.setText("Y +");
final CLabel mLabel_3_1_1 = new CLabel(shell, SWT.NONE);
mLabel_3_1_1.setBounds(146, 151, 31, 19);
mLabel_3_1_1.setText("Y +");
final CLabel mLabel_4_2 = new CLabel(shell, SWT.NONE);
mLabel_4_2.setBounds(64, 10, 31, 19);
mLabel_4_2.setText("X +");
final CLabel mLabel_1_1_2 = new CLabel(shell, SWT.NONE);
mLabel_1_1_2.setBounds(64, 55, 31, 19);
mLabel_1_1_2.setText("X +");
final CLabel mLabel_2_1_2 = new CLabel(shell, SWT.NONE);
mLabel_2_1_2.setBounds(64, 101, 31, 19);
mLabel_2_1_2.setText("X +");
final CLabel mLabel_3_1_2 = new CLabel(shell, SWT.NONE);
mLabel_3_1_2.setBounds(64, 151, 31, 19);
mLabel_3_1_2.setText("X +");
final CLabel ifsure = new CLabel(shell, SWT.NONE);
ifsure.setBounds(347, 194, 60, 19);
final CLabel label_1 = new CLabel(shell, SWT.NONE);
label_1.setBounds(265, 194, 78, 19);
label_1.setText("解的情况为:");
final CLabel rank = new CLabel(shell, SWT.NONE);
rank.setBounds(226, 194, 34, 19);
final Button done = new Button(shell, SWT.NONE);
done.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
//这样节省资源
String[][] str={{x1.getText(),y1.getText(),z1.getText(),m1.getText(),r1.getText()},
{x2.getText(),y2.getText(),z2.getText(),m2.getText(),r2.getText()},
{x3.getText(),y3.getText(),z3.getText(),m3.getText(),r3.getText()},
{x4.getText(),y4.getText(),z4.getText(),m4.getText(),r4.getText()}};
TestDo testdo=new TestDo();
//获取当前的数据
testdo.getstr(str);
if(!testdo.checkall()){
MessageBox mess=new MessageBox(shell,SWT.None);
mess.setMessage("您输入的有问题!请在每个空格填上合理的值再点运算,谢谢合作!");
mess.open();
// System.out.println("checkall is "+testdo.checkall());
}else{
//数据转换
testdo.StrToDou();
//计算秩
ifsure.setText(testdo.ifsure());
String rank1=String.valueOf(testdo.getrank());
rank.setText(rank1);
if(testdo.ifsure().equals("有唯一解")){
double[] dou=testdo.doneit();
rs1.setText(String.valueOf(dou[0]));
rs2.setText(String.valueOf(dou[1]));
rs3.setText(String.valueOf(dou[2]));
rs4.setText(String.valueOf(dou[3]));
}
}
}
});
done.setImage(SWTResourceManager.getImage(MatTest.class, "/org/eclipse/jface/dialogs/images/message_warning.gif"));
done.setText("运算");
done.setBounds(224, 331, 60, 23);
final Button none = new Button(shell, SWT.NONE);
none.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
rs1.setText("");rs2.setText("");
rs3.setText("");rs4.setText("");
x1.setText("");y1.setText("");
z1.setText("");m1.setText("");
r1.setText("");x2.setText("");
y2.setText("");z2.setText("");
m2.setText("");r2.setText("");
x3.setText("");y3.setText("");
z3.setText("");m3.setText("");
x4.setText("");y4.setText("");
z4.setText("");m4.setText("");
rank.setText("");ifsure.setText("");
}
});
none.setImage(SWTResourceManager.getImage(MatTest.class, "/org/eclipse/jface/dialogs/images/message_error.gif"));
none.setText("取消");
none.setBounds(290, 331, 57, 23);
final Button rxit = new Button(shell, SWT.NONE);
rxit.setImage(SWTResourceManager.getImage(MatTest.class, "/org/eclipse/jface/dialogs/images/message_info.gif"));
rxit.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
shell.close();
}
});
rxit.setText("退出");
rxit.setBounds(353, 331, 57, 23);
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import com.swtdesigner.SWTResourceManager;
import org.eclipse.swt.widgets.MessageBox;
/**/ /*
* 主程序
*
* */
public class MatTest {
private static StyledText r4;
private static StyledText r3;
private static StyledText r2;
private static StyledText r1;
private static StyledText m4;
private static StyledText m3;
private static StyledText m2;
private static StyledText m1;
private static StyledText z4;
private static StyledText z3;
private static StyledText z2;
private static StyledText z1;
private static StyledText y4;
private static StyledText y3;
private static StyledText y2;
private static StyledText y1;
private static StyledText x4;
private static StyledText x3;
private static StyledText x2;
private static StyledText x1;
public static void main(String[] args) {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setImage(SWTResourceManager.getImage(MatTest.class, "/com/sun/java/swing/plaf/windows/icons/JavaCup32.png"));
shell.setForeground(SWTResourceManager.getColor(255, 255, 255));
shell.setSize(428, 393);
shell.setText("4元一次方程");
//
shell.open();
final CLabel label = new CLabel(shell, SWT.NONE);
label.setText("运行结果:该方程组对应矩阵的秩为:");
label.setBounds(10, 194, 210, 19);
final CLabel xLabel = new CLabel(shell, SWT.NONE);
xLabel.setText("X=");
xLabel.setBounds(64, 219, 20, 19);
final CLabel rs1 = new CLabel(shell, SWT.NONE);
rs1.setBounds(115, 219, 269, 19);
final CLabel xLabel_1 = new CLabel(shell, SWT.NONE);
xLabel_1.setBounds(64, 244, 20, 19);
xLabel_1.setText("Y=");
final CLabel rs2 = new CLabel(shell, SWT.NONE);
rs2.setBounds(115, 244, 269, 19);
final CLabel xLabel_2 = new CLabel(shell, SWT.NONE);
xLabel_2.setBounds(64, 269, 20, 19);
xLabel_2.setText("Z=");
final CLabel rs3 = new CLabel(shell, SWT.NONE);
rs3.setBounds(115, 269, 269, 19);
final CLabel xLabel_3 = new CLabel(shell, SWT.NONE);
xLabel_3.setBounds(64, 294, 20, 19);
xLabel_3.setText("M=");
final CLabel rs4 = new CLabel(shell, SWT.NONE);
rs4.setBounds(115, 294, 269, 19);
x1 = new StyledText(shell, SWT.BORDER);
x1.setBackground(SWTResourceManager.getColor(241, 225, 216));
x1.setBounds(10, 10, 48, 19);
x2 = new StyledText(shell, SWT.BORDER);
x2.setBackground(SWTResourceManager.getColor(241, 225, 216));
x2.setBounds(10, 55, 48, 19);
x3 = new StyledText(shell, SWT.BORDER);
x3.setBackground(SWTResourceManager.getColor(241, 225, 216));
x3.setBounds(10, 101, 48, 19);
x4 = new StyledText(shell, SWT.BORDER);
x4.setBackground(SWTResourceManager.getColor(241, 225, 216));
x4.setBounds(10, 151, 48, 19);
y1 = new StyledText(shell, SWT.BORDER);
y1.setBackground(SWTResourceManager.getColor(241, 225, 216));
y1.setBounds(92, 10, 48, 19);
y2 = new StyledText(shell, SWT.BORDER);
y2.setBackground(SWTResourceManager.getColor(241, 225, 216));
y2.setBounds(92, 55, 48, 19);
y3 = new StyledText(shell, SWT.BORDER);
y3.setBackground(SWTResourceManager.getColor(241, 225, 216));
y3.setBounds(92, 101, 48, 19);
y4 = new StyledText(shell, SWT.BORDER);
y4.setBackground(SWTResourceManager.getColor(241, 225, 216));
y4.setBounds(92, 151, 48, 19);
z1 = new StyledText(shell, SWT.BORDER);
z1.setBackground(SWTResourceManager.getColor(241, 225, 216));
z1.setBounds(183, 10, 48, 19);
z2 = new StyledText(shell, SWT.BORDER);
z2.setBackground(SWTResourceManager.getColor(241, 225, 216));
z2.setBounds(183, 55, 48, 19);
z3 = new StyledText(shell, SWT.BORDER);
z3.setBackground(SWTResourceManager.getColor(241, 225, 216));
z3.setBounds(183, 101, 48, 19);
z4 = new StyledText(shell, SWT.BORDER);
z4.setBackground(SWTResourceManager.getColor(241, 225, 216));
z4.setBounds(183, 151, 48, 19);
m1 = new StyledText(shell, SWT.BORDER);
m1.setBackground(SWTResourceManager.getColor(241, 225, 216));
m1.setBounds(274, 10, 48, 19);
m2 = new StyledText(shell, SWT.BORDER);
m2.setBackground(SWTResourceManager.getColor(241, 225, 216));
m2.setBounds(274, 55, 48, 19);
m3 = new StyledText(shell, SWT.BORDER);
m3.setBackground(SWTResourceManager.getColor(241, 225, 216));
m3.setBounds(274, 101, 48, 19);
m4 = new StyledText(shell, SWT.BORDER);
m4.setBackground(SWTResourceManager.getColor(241, 225, 216));
m4.setBounds(274, 151, 48, 19);
r1 = new StyledText(shell, SWT.BORDER);
r1.setBackground(SWTResourceManager.getColor(241, 225, 216));
r1.setBounds(362, 10, 48, 19);
r2 = new StyledText(shell, SWT.BORDER);
r2.setBackground(SWTResourceManager.getColor(241, 225, 216));
r2.setBounds(362, 55, 48, 19);
r3 = new StyledText(shell, SWT.BORDER);
r3.setBackground(SWTResourceManager.getColor(241, 225, 216));
r3.setBounds(362, 101, 48, 19);
r4 = new StyledText(shell, SWT.BORDER);
r4.setBackground(SWTResourceManager.getColor(241, 225, 216));
r4.setBounds(362, 151, 48, 19);
final CLabel mLabel = new CLabel(shell, SWT.NONE);
mLabel.setText("M =");
mLabel.setBounds(328, 10, 40, 19);
final CLabel mLabel_1 = new CLabel(shell, SWT.NONE);
mLabel_1.setBounds(328, 55, 40, 19);
mLabel_1.setText("M =");
final CLabel mLabel_2 = new CLabel(shell, SWT.NONE);
mLabel_2.setBounds(328, 101, 40, 19);
mLabel_2.setText("M =");
final CLabel mLabel_3 = new CLabel(shell, SWT.NONE);
mLabel_3.setBounds(328, 151, 40, 19);
mLabel_3.setText("M =");
final CLabel mLabel_4 = new CLabel(shell, SWT.NONE);
mLabel_4.setBounds(237, 10, 31, 19);
mLabel_4.setText("Z +");
final CLabel mLabel_1_1 = new CLabel(shell, SWT.NONE);
mLabel_1_1.setBounds(237, 55, 31, 19);
mLabel_1_1.setText("Z +");
final CLabel mLabel_2_1 = new CLabel(shell, SWT.NONE);
mLabel_2_1.setBounds(237, 101, 31, 19);
mLabel_2_1.setText("Z +");
final CLabel mLabel_3_1 = new CLabel(shell, SWT.NONE);
mLabel_3_1.setBounds(237, 151, 31, 19);
mLabel_3_1.setText("Z +");
final CLabel mLabel_4_1 = new CLabel(shell, SWT.NONE);
mLabel_4_1.setBounds(146, 10, 31, 19);
mLabel_4_1.setText("Y +");
final CLabel mLabel_1_1_1 = new CLabel(shell, SWT.NONE);
mLabel_1_1_1.setBounds(146, 55, 31, 19);
mLabel_1_1_1.setText("Y +");
final CLabel mLabel_2_1_1 = new CLabel(shell, SWT.NONE);
mLabel_2_1_1.setBounds(146, 101, 31, 19);
mLabel_2_1_1.setText("Y +");
final CLabel mLabel_3_1_1 = new CLabel(shell, SWT.NONE);
mLabel_3_1_1.setBounds(146, 151, 31, 19);
mLabel_3_1_1.setText("Y +");
final CLabel mLabel_4_2 = new CLabel(shell, SWT.NONE);
mLabel_4_2.setBounds(64, 10, 31, 19);
mLabel_4_2.setText("X +");
final CLabel mLabel_1_1_2 = new CLabel(shell, SWT.NONE);
mLabel_1_1_2.setBounds(64, 55, 31, 19);
mLabel_1_1_2.setText("X +");
final CLabel mLabel_2_1_2 = new CLabel(shell, SWT.NONE);
mLabel_2_1_2.setBounds(64, 101, 31, 19);
mLabel_2_1_2.setText("X +");
final CLabel mLabel_3_1_2 = new CLabel(shell, SWT.NONE);
mLabel_3_1_2.setBounds(64, 151, 31, 19);
mLabel_3_1_2.setText("X +");
final CLabel ifsure = new CLabel(shell, SWT.NONE);
ifsure.setBounds(347, 194, 60, 19);
final CLabel label_1 = new CLabel(shell, SWT.NONE);
label_1.setBounds(265, 194, 78, 19);
label_1.setText("解的情况为:");
final CLabel rank = new CLabel(shell, SWT.NONE);
rank.setBounds(226, 194, 34, 19);
final Button done = new Button(shell, SWT.NONE);
done.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
//这样节省资源
String[][] str={{x1.getText(),y1.getText(),z1.getText(),m1.getText(),r1.getText()},
{x2.getText(),y2.getText(),z2.getText(),m2.getText(),r2.getText()},
{x3.getText(),y3.getText(),z3.getText(),m3.getText(),r3.getText()},
{x4.getText(),y4.getText(),z4.getText(),m4.getText(),r4.getText()}};
TestDo testdo=new TestDo();
//获取当前的数据
testdo.getstr(str);
if(!testdo.checkall()){
MessageBox mess=new MessageBox(shell,SWT.None);
mess.setMessage("您输入的有问题!请在每个空格填上合理的值再点运算,谢谢合作!");
mess.open();
// System.out.println("checkall is "+testdo.checkall());
}else{
//数据转换
testdo.StrToDou();
//计算秩
ifsure.setText(testdo.ifsure());
String rank1=String.valueOf(testdo.getrank());
rank.setText(rank1);
if(testdo.ifsure().equals("有唯一解")){
double[] dou=testdo.doneit();
rs1.setText(String.valueOf(dou[0]));
rs2.setText(String.valueOf(dou[1]));
rs3.setText(String.valueOf(dou[2]));
rs4.setText(String.valueOf(dou[3]));
}
}
}
});
done.setImage(SWTResourceManager.getImage(MatTest.class, "/org/eclipse/jface/dialogs/images/message_warning.gif"));
done.setText("运算");
done.setBounds(224, 331, 60, 23);
final Button none = new Button(shell, SWT.NONE);
none.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
rs1.setText("");rs2.setText("");
rs3.setText("");rs4.setText("");
x1.setText("");y1.setText("");
z1.setText("");m1.setText("");
r1.setText("");x2.setText("");
y2.setText("");z2.setText("");
m2.setText("");r2.setText("");
x3.setText("");y3.setText("");
z3.setText("");m3.setText("");
x4.setText("");y4.setText("");
z4.setText("");m4.setText("");
rank.setText("");ifsure.setText("");
}
});
none.setImage(SWTResourceManager.getImage(MatTest.class, "/org/eclipse/jface/dialogs/images/message_error.gif"));
none.setText("取消");
none.setBounds(290, 331, 57, 23);
final Button rxit = new Button(shell, SWT.NONE);
rxit.setImage(SWTResourceManager.getImage(MatTest.class, "/org/eclipse/jface/dialogs/images/message_info.gif"));
rxit.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
shell.close();
}
});
rxit.setText("退出");
rxit.setBounds(353, 331, 57, 23);
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
package
com.swtdesigner;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import org.eclipse.jface.resource.CompositeImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics. * ;
import org.eclipse.swt.widgets. * ;
/** */ /**
* Utility class for managing OS resources associated with SWT controls such as
* colors, fonts, images, etc.
*
* !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code>
* method to release the operating system resources managed by cached objects
* when those objects and OS resources are no longer needed (e.g. on
* application shutdown)
*
* This class may be freely distributed as part of any application or plugin.
* <p>
* Copyright (c) 2003 - 2005, Instantiations, Inc. <br>All Rights Reserved
*
* @author scheglov_ke
* @author Dan Rubel
*/
public class SWTResourceManager {
/** *//**
* Dispose of cached objects and their underlying OS resources. This should
* only be called when the cached objects are no longer needed (e.g. on
* application shutdown)
*/
public static void dispose() {
disposeColors();
disposeFonts();
disposeImages();
disposeCursors();
}
//////////////////////////////
// Color support
//////////////////////////////
/** *//**
* Maps RGB values to colors
*/
private static HashMap m_ColorMap = new HashMap();
/** *//**
* Returns the system color matching the specific ID
* @param systemColorID int The ID value for the color
* @return Color The system color matching the specific ID
*/
public static Color getColor(int systemColorID) {
Display display = Display.getCurrent();
return display.getSystemColor(systemColorID);
}
/** *//**
* Returns a color given its red, green and blue component values
* @param r int The red component of the color
* @param g int The green component of the color
* @param b int The blue component of the color
* @return Color The color matching the given red, green and blue componet values
*/
public static Color getColor(int r, int g, int b) {
return getColor(new RGB(r, g, b));
}
/** *//**
* Returns a color given its RGB value
* @param rgb RGB The RGB value of the color
* @return Color The color matching the RGB value
*/
public static Color getColor(RGB rgb) {
Color color = (Color) m_ColorMap.get(rgb);
if (color == null) {
Display display = Display.getCurrent();
color = new Color(display, rgb);
m_ColorMap.put(rgb, color);
}
return color;
}
/** *//**
* Dispose of all the cached colors
*/
public static void disposeColors() {
for (Iterator iter = m_ColorMap.values().iterator(); iter.hasNext();)
((Color) iter.next()).dispose();
m_ColorMap.clear();
}
//////////////////////////////
// Image support
//////////////////////////////
/** *//**
* Maps image names to images
*/
private static HashMap m_ClassImageMap = new HashMap();
/** *//**
* Maps images to image decorators
*/
private static HashMap m_ImageToDecoratorMap = new HashMap();
/** *//**
* Returns an image encoded by the specified input stream
* @param is InputStream The input stream encoding the image data
* @return Image The image encoded by the specified input stream
*/
protected static Image getImage(InputStream is) {
Display display = Display.getCurrent();
ImageData data = new ImageData(is);
if (data.transparentPixel > 0)
return new Image(display, data, data.getTransparencyMask());
return new Image(display, data);
}
/** *//**
* Returns an image stored in the file at the specified path
* @param path String The path to the image file
* @return Image The image stored in the file at the specified path
*/
public static Image getImage(String path) {
return getImage("default", path); //$NON-NLS-1$
}
/** *//**
* Returns an image stored in the file at the specified path
* @param section The section to which belongs specified image
* @param path String The path to the image file
* @return Image The image stored in the file at the specified path
*/
public static Image getImage(String section, String path) {
String key = section + '|' + SWTResourceManager.class.getName() + '|' + path;
Image image = (Image) m_ClassImageMap.get(key);
if (image == null) {
try {
FileInputStream fis = new FileInputStream(path);
image = getImage(fis);
m_ClassImageMap.put(key, image);
fis.close();
} catch (Exception e) {
image = getMissingImage();
m_ClassImageMap.put(key, image);
}
}
return image;
}
/** *//**
* Returns an image stored in the file at the specified path relative to the specified class
* @param clazz Class The class relative to which to find the image
* @param path String The path to the image file
* @return Image The image stored in the file at the specified path
*/
public static Image getImage(Class clazz, String path) {
String key = clazz.getName() + '|' + path;
Image image = (Image) m_ClassImageMap.get(key);
if (image == null) {
try {
if (path.length() > 0 && path.charAt(0) == '/') {
String newPath = path.substring(1, path.length());
image = getImage(new BufferedInputStream(clazz.getClassLoader().getResourceAsStream(newPath)));
} else {
image = getImage(clazz.getResourceAsStream(path));
}
m_ClassImageMap.put(key, image);
} catch (Exception e) {
image = getMissingImage();
m_ClassImageMap.put(key, image);
}
}
return image;
}
private static final int MISSING_IMAGE_SIZE = 10;
private static Image getMissingImage() {
Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
//
GC gc = new GC(image);
gc.setBackground(getColor(SWT.COLOR_RED));
gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
gc.dispose();
//
return image;
}
/** *//**
* Style constant for placing decorator image in top left corner of base image.
*/
public static final int TOP_LEFT = 1;
/** *//**
* Style constant for placing decorator image in top right corner of base image.
*/
public static final int TOP_RIGHT = 2;
/** *//**
* Style constant for placing decorator image in bottom left corner of base image.
*/
public static final int BOTTOM_LEFT = 3;
/** *//**
* Style constant for placing decorator image in bottom right corner of base image.
*/
public static final int BOTTOM_RIGHT = 4;
/** *//**
* Returns an image composed of a base image decorated by another image
* @param baseImage Image The base image that should be decorated
* @param decorator Image The image to decorate the base image
* @return Image The resulting decorated image
*/
public static Image decorateImage(Image baseImage, Image decorator) {
return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
}
/** *//**
* Returns an image composed of a base image decorated by another image
* @param baseImage Image The base image that should be decorated
* @param decorator Image The image to decorate the base image
* @param corner The corner to place decorator image
* @return Image The resulting decorated image
*/
public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {
HashMap decoratedMap = (HashMap) m_ImageToDecoratorMap.get(baseImage);
if (decoratedMap == null) {
decoratedMap = new HashMap();
m_ImageToDecoratorMap.put(baseImage, decoratedMap);
}
Image result = (Image) decoratedMap.get(decorator);
if (result == null) {
final Rectangle bid = baseImage.getBounds();
final Rectangle did = decorator.getBounds();
final Point baseImageSize = new Point(bid.width, bid.height);
CompositeImageDescriptor compositImageDesc = new CompositeImageDescriptor() {
protected void drawCompositeImage(int width, int height) {
drawImage(baseImage.getImageData(), 0, 0);
if (corner == TOP_LEFT) {
drawImage(decorator.getImageData(), 0, 0);
} else if (corner == TOP_RIGHT) {
drawImage(decorator.getImageData(), bid.width - did.width - 1, 0);
} else if (corner == BOTTOM_LEFT) {
drawImage(decorator.getImageData(), 0, bid.height - did.height - 1);
} else if (corner == BOTTOM_RIGHT) {
drawImage(decorator.getImageData(), bid.width - did.width - 1, bid.height - did.height - 1);
}
}
protected Point getSize() {
return baseImageSize;
}
};
result = compositImageDesc.createImage();
decoratedMap.put(decorator, result);
}
return result;
}
/** *//**
* Dispose all of the cached images
*/
public static void disposeImages() {
for (Iterator I = m_ClassImageMap.values().iterator(); I.hasNext();)
((Image) I.next()).dispose();
m_ClassImageMap.clear();
//
for (Iterator I = m_ImageToDecoratorMap.values().iterator(); I.hasNext();) {
HashMap decoratedMap = (HashMap) I.next();
for (Iterator J = decoratedMap.values().iterator(); J.hasNext();) {
Image image = (Image) J.next();
image.dispose();
}
}
}
/** *//**
* Dispose cached images in specified section
* @param section the section do dispose
*/
public static void disposeImages(String section) {
for (Iterator I = m_ClassImageMap.keySet().iterator(); I.hasNext();) {
String key = (String) I.next();
if (!key.startsWith(section + '|'))
continue;
Image image = (Image) m_ClassImageMap.get(key);
image.dispose();
I.remove();
}
}
//////////////////////////////
// Font support
//////////////////////////////
/** *//**
* Maps font names to fonts
*/
private static HashMap m_FontMap = new HashMap();
/** *//**
* Maps fonts to their bold versions
*/
private static HashMap m_FontToBoldFontMap = new HashMap();
/** *//**
* Returns a font based on its name, height and style
* @param name String The name of the font
* @param height int The height of the font
* @param style int The style of the font
* @return Font The font matching the name, height and style
*/
public static Font getFont(String name, int height, int style) {
return getFont(name, height, style, false, false);
}
/** *//**
* Returns a font based on its name, height and style.
* Windows-specific strikeout and underline flags are also supported.
* @param name String The name of the font
* @param size int The size of the font
* @param style int The style of the font
* @param strikeout boolean The strikeout flag (warning: Windows only)
* @param underline boolean The underline flag (warning: Windows only)
* @return Font The font matching the name, height, style, strikeout and underline
*/
public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) {
String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
Font font = (Font) m_FontMap.get(fontName);
if (font == null) {
FontData fontData = new FontData(name, size, style);
if (strikeout || underline) {
try {
Class logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$
Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$
if (logFont != null && logFontClass != null) {
if (strikeout) {
logFontClass.getField("lfStrikeOut").set(logFont, new Byte((byte) 1)); //$NON-NLS-1$
}
if (underline) {
logFontClass.getField("lfUnderline").set(logFont, new Byte((byte) 1)); //$NON-NLS-1$
}
}
} catch (Throwable e) {
System.err.println(
"Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
font = new Font(Display.getCurrent(), fontData);
m_FontMap.put(fontName, font);
}
return font;
}
/** *//**
* Return a bold version of the give font
* @param baseFont Font The font for whoch a bold version is desired
* @return Font The bold version of the give font
*/
public static Font getBoldFont(Font baseFont) {
Font font = (Font) m_FontToBoldFontMap.get(baseFont);
if (font == null) {
FontData fontDatas[] = baseFont.getFontData();
FontData data = fontDatas[0];
font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
m_FontToBoldFontMap.put(baseFont, font);
}
return font;
}
/** *//**
* Dispose all of the cached fonts
*/
public static void disposeFonts() {
for (Iterator iter = m_FontMap.values().iterator(); iter.hasNext();)
((Font) iter.next()).dispose();
m_FontMap.clear();
}
//////////////////////////////
// CoolBar support
//////////////////////////////
/** *//**
* Fix the layout of the specified CoolBar
* @param bar CoolBar The CoolBar that shgoud be fixed
*/
public static void fixCoolBarSize(CoolBar bar) {
CoolItem[] items = bar.getItems();
// ensure that each item has control (at least empty one)
for (int i = 0; i < items.length; i++) {
CoolItem item = items[i];
if (item.getControl() == null)
item.setControl(new Canvas(bar, SWT.NONE) {
public Point computeSize(int wHint, int hHint, boolean changed) {
return new Point(20, 20);
}
});
}
// compute size for each item
for (int i = 0; i < items.length; i++) {
CoolItem item = items[i];
Control control = item.getControl();
control.pack();
Point size = control.getSize();
item.setSize(item.computeSize(size.x, size.y));
}
}
//////////////////////////////
// Cursor support
//////////////////////////////
/** *//**
* Maps IDs to cursors
*/
private static HashMap m_IdToCursorMap = new HashMap();
/** *//**
* Returns the system cursor matching the specific ID
* @param id int The ID value for the cursor
* @return Cursor The system cursor matching the specific ID
*/
public static Cursor getCursor(int id) {
Integer key = new Integer(id);
Cursor cursor = (Cursor) m_IdToCursorMap.get(key);
if (cursor == null) {
cursor = new Cursor(Display.getDefault(), id);
m_IdToCursorMap.put(key, cursor);
}
return cursor;
}
/** *//**
* Dispose all of the cached cursors
*/
public static void disposeCursors() {
for (Iterator iter = m_IdToCursorMap.values().iterator(); iter.hasNext();)
((Cursor) iter.next()).dispose();
m_IdToCursorMap.clear();
}
}
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import org.eclipse.jface.resource.CompositeImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics. * ;
import org.eclipse.swt.widgets. * ;
/** */ /**
* Utility class for managing OS resources associated with SWT controls such as
* colors, fonts, images, etc.
*
* !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code>
* method to release the operating system resources managed by cached objects
* when those objects and OS resources are no longer needed (e.g. on
* application shutdown)
*
* This class may be freely distributed as part of any application or plugin.
* <p>
* Copyright (c) 2003 - 2005, Instantiations, Inc. <br>All Rights Reserved
*
* @author scheglov_ke
* @author Dan Rubel
*/
public class SWTResourceManager {
/** *//**
* Dispose of cached objects and their underlying OS resources. This should
* only be called when the cached objects are no longer needed (e.g. on
* application shutdown)
*/
public static void dispose() {
disposeColors();
disposeFonts();
disposeImages();
disposeCursors();
}
//////////////////////////////
// Color support
//////////////////////////////
/** *//**
* Maps RGB values to colors
*/
private static HashMap m_ColorMap = new HashMap();
/** *//**
* Returns the system color matching the specific ID
* @param systemColorID int The ID value for the color
* @return Color The system color matching the specific ID
*/
public static Color getColor(int systemColorID) {
Display display = Display.getCurrent();
return display.getSystemColor(systemColorID);
}
/** *//**
* Returns a color given its red, green and blue component values
* @param r int The red component of the color
* @param g int The green component of the color
* @param b int The blue component of the color
* @return Color The color matching the given red, green and blue componet values
*/
public static Color getColor(int r, int g, int b) {
return getColor(new RGB(r, g, b));
}
/** *//**
* Returns a color given its RGB value
* @param rgb RGB The RGB value of the color
* @return Color The color matching the RGB value
*/
public static Color getColor(RGB rgb) {
Color color = (Color) m_ColorMap.get(rgb);
if (color == null) {
Display display = Display.getCurrent();
color = new Color(display, rgb);
m_ColorMap.put(rgb, color);
}
return color;
}
/** *//**
* Dispose of all the cached colors
*/
public static void disposeColors() {
for (Iterator iter = m_ColorMap.values().iterator(); iter.hasNext();)
((Color) iter.next()).dispose();
m_ColorMap.clear();
}
//////////////////////////////
// Image support
//////////////////////////////
/** *//**
* Maps image names to images
*/
private static HashMap m_ClassImageMap = new HashMap();
/** *//**
* Maps images to image decorators
*/
private static HashMap m_ImageToDecoratorMap = new HashMap();
/** *//**
* Returns an image encoded by the specified input stream
* @param is InputStream The input stream encoding the image data
* @return Image The image encoded by the specified input stream
*/
protected static Image getImage(InputStream is) {
Display display = Display.getCurrent();
ImageData data = new ImageData(is);
if (data.transparentPixel > 0)
return new Image(display, data, data.getTransparencyMask());
return new Image(display, data);
}
/** *//**
* Returns an image stored in the file at the specified path
* @param path String The path to the image file
* @return Image The image stored in the file at the specified path
*/
public static Image getImage(String path) {
return getImage("default", path); //$NON-NLS-1$
}
/** *//**
* Returns an image stored in the file at the specified path
* @param section The section to which belongs specified image
* @param path String The path to the image file
* @return Image The image stored in the file at the specified path
*/
public static Image getImage(String section, String path) {
String key = section + '|' + SWTResourceManager.class.getName() + '|' + path;
Image image = (Image) m_ClassImageMap.get(key);
if (image == null) {
try {
FileInputStream fis = new FileInputStream(path);
image = getImage(fis);
m_ClassImageMap.put(key, image);
fis.close();
} catch (Exception e) {
image = getMissingImage();
m_ClassImageMap.put(key, image);
}
}
return image;
}
/** *//**
* Returns an image stored in the file at the specified path relative to the specified class
* @param clazz Class The class relative to which to find the image
* @param path String The path to the image file
* @return Image The image stored in the file at the specified path
*/
public static Image getImage(Class clazz, String path) {
String key = clazz.getName() + '|' + path;
Image image = (Image) m_ClassImageMap.get(key);
if (image == null) {
try {
if (path.length() > 0 && path.charAt(0) == '/') {
String newPath = path.substring(1, path.length());
image = getImage(new BufferedInputStream(clazz.getClassLoader().getResourceAsStream(newPath)));
} else {
image = getImage(clazz.getResourceAsStream(path));
}
m_ClassImageMap.put(key, image);
} catch (Exception e) {
image = getMissingImage();
m_ClassImageMap.put(key, image);
}
}
return image;
}
private static final int MISSING_IMAGE_SIZE = 10;
private static Image getMissingImage() {
Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
//
GC gc = new GC(image);
gc.setBackground(getColor(SWT.COLOR_RED));
gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
gc.dispose();
//
return image;
}
/** *//**
* Style constant for placing decorator image in top left corner of base image.
*/
public static final int TOP_LEFT = 1;
/** *//**
* Style constant for placing decorator image in top right corner of base image.
*/
public static final int TOP_RIGHT = 2;
/** *//**
* Style constant for placing decorator image in bottom left corner of base image.
*/
public static final int BOTTOM_LEFT = 3;
/** *//**
* Style constant for placing decorator image in bottom right corner of base image.
*/
public static final int BOTTOM_RIGHT = 4;
/** *//**
* Returns an image composed of a base image decorated by another image
* @param baseImage Image The base image that should be decorated
* @param decorator Image The image to decorate the base image
* @return Image The resulting decorated image
*/
public static Image decorateImage(Image baseImage, Image decorator) {
return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
}
/** *//**
* Returns an image composed of a base image decorated by another image
* @param baseImage Image The base image that should be decorated
* @param decorator Image The image to decorate the base image
* @param corner The corner to place decorator image
* @return Image The resulting decorated image
*/
public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {
HashMap decoratedMap = (HashMap) m_ImageToDecoratorMap.get(baseImage);
if (decoratedMap == null) {
decoratedMap = new HashMap();
m_ImageToDecoratorMap.put(baseImage, decoratedMap);
}
Image result = (Image) decoratedMap.get(decorator);
if (result == null) {
final Rectangle bid = baseImage.getBounds();
final Rectangle did = decorator.getBounds();
final Point baseImageSize = new Point(bid.width, bid.height);
CompositeImageDescriptor compositImageDesc = new CompositeImageDescriptor() {
protected void drawCompositeImage(int width, int height) {
drawImage(baseImage.getImageData(), 0, 0);
if (corner == TOP_LEFT) {
drawImage(decorator.getImageData(), 0, 0);
} else if (corner == TOP_RIGHT) {
drawImage(decorator.getImageData(), bid.width - did.width - 1, 0);
} else if (corner == BOTTOM_LEFT) {
drawImage(decorator.getImageData(), 0, bid.height - did.height - 1);
} else if (corner == BOTTOM_RIGHT) {
drawImage(decorator.getImageData(), bid.width - did.width - 1, bid.height - did.height - 1);
}
}
protected Point getSize() {
return baseImageSize;
}
};
result = compositImageDesc.createImage();
decoratedMap.put(decorator, result);
}
return result;
}
/** *//**
* Dispose all of the cached images
*/
public static void disposeImages() {
for (Iterator I = m_ClassImageMap.values().iterator(); I.hasNext();)
((Image) I.next()).dispose();
m_ClassImageMap.clear();
//
for (Iterator I = m_ImageToDecoratorMap.values().iterator(); I.hasNext();) {
HashMap decoratedMap = (HashMap) I.next();
for (Iterator J = decoratedMap.values().iterator(); J.hasNext();) {
Image image = (Image) J.next();
image.dispose();
}
}
}
/** *//**
* Dispose cached images in specified section
* @param section the section do dispose
*/
public static void disposeImages(String section) {
for (Iterator I = m_ClassImageMap.keySet().iterator(); I.hasNext();) {
String key = (String) I.next();
if (!key.startsWith(section + '|'))
continue;
Image image = (Image) m_ClassImageMap.get(key);
image.dispose();
I.remove();
}
}
//////////////////////////////
// Font support
//////////////////////////////
/** *//**
* Maps font names to fonts
*/
private static HashMap m_FontMap = new HashMap();
/** *//**
* Maps fonts to their bold versions
*/
private static HashMap m_FontToBoldFontMap = new HashMap();
/** *//**
* Returns a font based on its name, height and style
* @param name String The name of the font
* @param height int The height of the font
* @param style int The style of the font
* @return Font The font matching the name, height and style
*/
public static Font getFont(String name, int height, int style) {
return getFont(name, height, style, false, false);
}
/** *//**
* Returns a font based on its name, height and style.
* Windows-specific strikeout and underline flags are also supported.
* @param name String The name of the font
* @param size int The size of the font
* @param style int The style of the font
* @param strikeout boolean The strikeout flag (warning: Windows only)
* @param underline boolean The underline flag (warning: Windows only)
* @return Font The font matching the name, height, style, strikeout and underline
*/
public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) {
String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
Font font = (Font) m_FontMap.get(fontName);
if (font == null) {
FontData fontData = new FontData(name, size, style);
if (strikeout || underline) {
try {
Class logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$
Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$
if (logFont != null && logFontClass != null) {
if (strikeout) {
logFontClass.getField("lfStrikeOut").set(logFont, new Byte((byte) 1)); //$NON-NLS-1$
}
if (underline) {
logFontClass.getField("lfUnderline").set(logFont, new Byte((byte) 1)); //$NON-NLS-1$
}
}
} catch (Throwable e) {
System.err.println(
"Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
font = new Font(Display.getCurrent(), fontData);
m_FontMap.put(fontName, font);
}
return font;
}
/** *//**
* Return a bold version of the give font
* @param baseFont Font The font for whoch a bold version is desired
* @return Font The bold version of the give font
*/
public static Font getBoldFont(Font baseFont) {
Font font = (Font) m_FontToBoldFontMap.get(baseFont);
if (font == null) {
FontData fontDatas[] = baseFont.getFontData();
FontData data = fontDatas[0];
font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
m_FontToBoldFontMap.put(baseFont, font);
}
return font;
}
/** *//**
* Dispose all of the cached fonts
*/
public static void disposeFonts() {
for (Iterator iter = m_FontMap.values().iterator(); iter.hasNext();)
((Font) iter.next()).dispose();
m_FontMap.clear();
}
//////////////////////////////
// CoolBar support
//////////////////////////////
/** *//**
* Fix the layout of the specified CoolBar
* @param bar CoolBar The CoolBar that shgoud be fixed
*/
public static void fixCoolBarSize(CoolBar bar) {
CoolItem[] items = bar.getItems();
// ensure that each item has control (at least empty one)
for (int i = 0; i < items.length; i++) {
CoolItem item = items[i];
if (item.getControl() == null)
item.setControl(new Canvas(bar, SWT.NONE) {
public Point computeSize(int wHint, int hHint, boolean changed) {
return new Point(20, 20);
}
});
}
// compute size for each item
for (int i = 0; i < items.length; i++) {
CoolItem item = items[i];
Control control = item.getControl();
control.pack();
Point size = control.getSize();
item.setSize(item.computeSize(size.x, size.y));
}
}
//////////////////////////////
// Cursor support
//////////////////////////////
/** *//**
* Maps IDs to cursors
*/
private static HashMap m_IdToCursorMap = new HashMap();
/** *//**
* Returns the system cursor matching the specific ID
* @param id int The ID value for the cursor
* @return Cursor The system cursor matching the specific ID
*/
public static Cursor getCursor(int id) {
Integer key = new Integer(id);
Cursor cursor = (Cursor) m_IdToCursorMap.get(key);
if (cursor == null) {
cursor = new Cursor(Display.getDefault(), id);
m_IdToCursorMap.put(key, cursor);
}
return cursor;
}
/** *//**
* Dispose all of the cached cursors
*/
public static void disposeCursors() {
for (Iterator iter = m_IdToCursorMap.values().iterator(); iter.hasNext();)
((Cursor) iter.next()).dispose();
m_IdToCursorMap.clear();
}
}
处理类:
import
java.util.regex.Matcher;
// 应用到的包
import Jama.Matrix;
/**/ /*
* 后台数据处理
* */
public class TestDo {
//用来获取文本框中的内容
String[][] str;
//增广矩阵
double[][] no=new double[4][5];
//左边四列的值
double[][] noo=new double[4][4];
//最右边一列的值
double[][] nooo=new double[4][4];
//判断输入的数据是否有效
boolean bool;
//获取文本框里的值
public void getstr(String[][] str){
this.str=str;
}
//判断,返回给MatTest一个boolean值
public boolean checkall(){
for(int i=0;i<4;i++){
for(int j=0;j<5;j++){
if(str[i][j].equals("")){
bool=false;
break;
// System.out.println("It's null");
}else{
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(str[i][j]);
if(isNum.matches())
{
bool=true;
}
}
}
}
return bool;
}
//这个是转换的函数将String[][]转换成double[][]数据集
public void StrToDou(){
try{
//获取增广矩阵
for(int i=0;i<4;i++){
for(int j=0;j<5;j++){
no[i][j]=Double.valueOf(str[i][j]).doubleValue();
System.out.print(no[i][j]+" ");
}
System.out.println();
}
System.out.println();
//获取矩阵
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
noo[i][j]=Double.valueOf(str[i][j]).doubleValue();
System.out.print(noo[i][j]+" ");
}
System.out.println();
}
System.out.println();
for(int j=0;j<4;j++){
nooo[j][0]=Double.valueOf(str[j][4]).doubleValue();
System.out.print(nooo[j][0]+" ");
}
}catch(Exception e){
//return false;
System.out.println("StrToDou "+e);
}
}
//计算知道矩阵是否有解
public String ifsure(){
Matrix mat=new Matrix(no);
Matrix mat1=new Matrix(noo);
String ifs="";
//System.out.println("增广矩阵的秩是: "+mat.rank());
//System.out.println(" 矩阵的秩是: "+mat1.rank());
if(mat.rank()==mat1.rank()&&mat.rank()==4){
ifs="有唯一解";
}else if(mat.rank()<4){
ifs="无穷解";
}else{
ifs="无解";
}
return ifs;
}
//获取增广矩阵的秩
public int getrank(){
Matrix mat=new Matrix(no);
int rank=mat.rank();
return rank;
}
//计算得到结果
public double[] doneit(){
//将double[][]型数据集合化成矩阵
Matrix mat=new Matrix(noo);
//同上
Matrix mat2=new Matrix(nooo);
double[] dou=new double[4];
Matrix rs=mat.solve(mat2);//解方程的函数
/**//*测试代码
System.out.println("结果是:");
System.out.println(rs.getArray()[0][0]);
System.out.println(rs.getArray()[1][0]);
System.out.println(rs.getArray()[2][0]);
System.out.println(rs.getArray()[3][0]);
*/
for(int i=0;i<4;i++){
//将解的值取出在一个double[]数据集合里,返回给MatTest
dou[i]=rs.getArray()[i][0];
}
return dou;
}
}
// 应用到的包
import Jama.Matrix;
/**/ /*
* 后台数据处理
* */
public class TestDo {
//用来获取文本框中的内容
String[][] str;
//增广矩阵
double[][] no=new double[4][5];
//左边四列的值
double[][] noo=new double[4][4];
//最右边一列的值
double[][] nooo=new double[4][4];
//判断输入的数据是否有效
boolean bool;
//获取文本框里的值
public void getstr(String[][] str){
this.str=str;
}
//判断,返回给MatTest一个boolean值
public boolean checkall(){
for(int i=0;i<4;i++){
for(int j=0;j<5;j++){
if(str[i][j].equals("")){
bool=false;
break;
// System.out.println("It's null");
}else{
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(str[i][j]);
if(isNum.matches())
{
bool=true;
}
}
}
}
return bool;
}
//这个是转换的函数将String[][]转换成double[][]数据集
public void StrToDou(){
try{
//获取增广矩阵
for(int i=0;i<4;i++){
for(int j=0;j<5;j++){
no[i][j]=Double.valueOf(str[i][j]).doubleValue();
System.out.print(no[i][j]+" ");
}
System.out.println();
}
System.out.println();
//获取矩阵
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
noo[i][j]=Double.valueOf(str[i][j]).doubleValue();
System.out.print(noo[i][j]+" ");
}
System.out.println();
}
System.out.println();
for(int j=0;j<4;j++){
nooo[j][0]=Double.valueOf(str[j][4]).doubleValue();
System.out.print(nooo[j][0]+" ");
}
}catch(Exception e){
//return false;
System.out.println("StrToDou "+e);
}
}
//计算知道矩阵是否有解
public String ifsure(){
Matrix mat=new Matrix(no);
Matrix mat1=new Matrix(noo);
String ifs="";
//System.out.println("增广矩阵的秩是: "+mat.rank());
//System.out.println(" 矩阵的秩是: "+mat1.rank());
if(mat.rank()==mat1.rank()&&mat.rank()==4){
ifs="有唯一解";
}else if(mat.rank()<4){
ifs="无穷解";
}else{
ifs="无解";
}
return ifs;
}
//获取增广矩阵的秩
public int getrank(){
Matrix mat=new Matrix(no);
int rank=mat.rank();
return rank;
}
//计算得到结果
public double[] doneit(){
//将double[][]型数据集合化成矩阵
Matrix mat=new Matrix(noo);
//同上
Matrix mat2=new Matrix(nooo);
double[] dou=new double[4];
Matrix rs=mat.solve(mat2);//解方程的函数
/**//*测试代码
System.out.println("结果是:");
System.out.println(rs.getArray()[0][0]);
System.out.println(rs.getArray()[1][0]);
System.out.println(rs.getArray()[2][0]);
System.out.println(rs.getArray()[3][0]);
*/
for(int i=0;i<4;i++){
//将解的值取出在一个double[]数据集合里,返回给MatTest
dou[i]=rs.getArray()[i][0];
}
return dou;
}
}
地震让大伙知道:居安思危,才是生存之道。