![]() |
ENSDF++ 1.1
An easy, fast and simple way to run querys towards the ENSDF database, written in C++.
|
00001 import java.util.ArrayList; 00002 import java.io.*; 00003 import java.awt.*; 00004 import java.awt.geom.*; 00005 import java.text.*; 00006 import java.awt.image.*; 00007 import java.awt.font.*; 00008 import javax.imageio.*; 00009 import javax.swing.ImageIcon; 00010 import javax.swing.*; 00011 import java.util.List; 00012 import java.util.Arrays; 00013 00014 00027 public class EPSCreator extends JFrame 00028 { 00029 static private ArrayList<JIsotope> isotopeList; // lists of isotopes, where the innermost list contains the name of the list and color codein 00030 // each list is drawn with a different color 00031 static private ArrayList<RGBVector> rgbVectorList; 00032 private int bottomLeftZ, bottomLeftA, upperRightZ, upperRightA; // contains information on which part of the nuclide chart to draw 00033 private int bottomLeftN, upperRightN; // number of neutrons in the bottom left and upper right isotopes 00034 private int width, height; // holds the width and height of the epsdocument 00035 int isotopeWidth, isotopeHeight; 00036 Graphics2D graphics; // EpsGraphics2D object that creates the eps document 00037 int preferredSizeOutside = 10; 00038 List<Integer> MagicNumbers; 00039 00041 int findMinN(int Z ) 00042 { 00043 int found = 10000; 00044 for(JIsotope i:isotopeList) 00045 { 00046 if(i.getZ()==Z) 00047 { 00048 if(i.getN()<found) 00049 found=i.getN(); 00050 } 00051 } 00052 if(found<bottomLeftN) 00053 return bottomLeftN; 00054 return found; 00055 } 00056 00057 int findMaxN(int Z) 00058 { 00059 int found = -10000; 00060 for(JIsotope i:isotopeList) 00061 { 00062 if(i.getZ()==Z) 00063 { 00064 if(i.getN()>found) 00065 found=i.getN(); 00066 } 00067 } 00068 if(found>upperRightN) 00069 return upperRightN; 00070 return found; 00071 } 00072 00073 int findMinZ(int N) 00074 { 00075 int found = 10000; 00076 for(JIsotope i:isotopeList) 00077 { 00078 if(i.getN()==N) 00079 { 00080 if(i.getZ()<found) 00081 found=i.getZ(); 00082 } 00083 } 00084 if(found<bottomLeftZ) 00085 return bottomLeftZ; 00086 return found; 00087 } 00088 00089 int findMaxZ(int N) 00090 { 00091 int found = -10000; 00092 for(JIsotope i:isotopeList) 00093 { 00094 if(i.getN()==N) 00095 { 00096 if(i.getZ()>found) 00097 found=i.getZ(); 00098 } 00099 } 00100 if(found>upperRightZ) 00101 return upperRightZ; 00102 return found; 00103 } 00104 00109 public EPSCreator(ArrayList<JIsotope> list, int blZ, int blA, int urZ, int urA) 00110 { 00111 isotopeList = new ArrayList<JIsotope>(); 00112 //isotopeList = new ArrayList<JIsotope>(); 00113 isotopeList = list; 00114 //rgbVectorList = rgbList; 00115 graphics = new EpsGraphics2D("epsdocument"); 00116 setViewingArea(blZ, blA, urZ, urA); 00117 MagicNumbers = Arrays.asList(2, 8, 20, 28, 50, 82, 126, 152); 00118 } 00119 00123 public EPSCreator(ArrayList<JIsotope> lists) 00124 { 00125 this(lists, 0, 0, 118, 293); 00126 } 00127 00129 private void setViewingArea(int blZ, int blA, int urZ, int urA) 00130 { 00131 bottomLeftZ = blZ; 00132 bottomLeftA = blA; 00133 upperRightZ = urZ; 00134 upperRightA = urA; 00135 upperRightN = upperRightA-upperRightZ; 00136 bottomLeftN = bottomLeftA-bottomLeftZ; 00137 } 00139 private void drawLine(double x1, double x2, double y1, double y2) 00140 { 00141 Line2D lineToDraw = new Line2D.Double(x1,y1,x2,y2); 00142 graphics.draw(lineToDraw); 00143 } 00144 00146 private void drawNuclideChart() 00147 { 00148 for (int i=0; i < isotopeList.size(); i++) 00149 { 00150 drawJIsotope(isotopeList.get(i), (Graphics)graphics); 00151 } 00152 00153 //Stroke drawingStroke = new BasicStroke(3, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{30}, 0); 00154 graphics.setStroke(new BasicStroke(3)); 00155 graphics.setColor(new Color(72, 61, 139)); 00156 00157 //drawMagicLines(); 00158 drawNewMagicLines(); 00159 } 00161 private double widthBoundaryCheck(double toCheck) 00162 { 00163 if(toCheck<0) 00164 return 0; 00165 if(toCheck>width) 00166 return width; 00167 return toCheck; 00168 } 00170 private double heightBoundaryCheck(double toCheck) 00171 { 00172 if(toCheck<0) 00173 return 0; 00174 if(toCheck>height) 00175 return height; 00176 return toCheck; 00177 } 00178 00180 private void drawNewMagicLines() 00181 { 00182 for(Integer i:MagicNumbers) 00183 { 00184 for(int k = 0; k<2; ++k) 00185 { 00186 //first fix A on magic number. -> vertical line 00187 if(bottomLeftN <= i+k && upperRightN+1 >=i+k) //OK to draw line 00188 { 00189 drawLine(widthBoundaryCheck(isotopeWidth*(i+k-bottomLeftN)), 00190 widthBoundaryCheck(isotopeWidth*(i+k-bottomLeftN)), 00191 heightBoundaryCheck(height-isotopeHeight*(- bottomLeftZ +preferredSizeOutside + findMaxZ(i)+1)), 00192 heightBoundaryCheck(height-isotopeHeight*(- bottomLeftZ-preferredSizeOutside + findMinZ(i)))); 00193 } 00194 //fix Z on magic number -> horizontal line. 00195 if(bottomLeftZ <= i+k && upperRightZ+1 >=i+k) //OK to draw line. 00196 { 00197 drawLine(widthBoundaryCheck(isotopeWidth*(-bottomLeftN + findMinN(i)-preferredSizeOutside)), 00198 widthBoundaryCheck(isotopeWidth*(- bottomLeftN + findMaxN(i)+preferredSizeOutside)), 00199 heightBoundaryCheck(height-isotopeHeight*(i+k-bottomLeftZ)), 00200 heightBoundaryCheck(height-isotopeHeight*(i+k-bottomLeftZ))); 00201 } 00202 } 00203 } 00204 } 00205 00207 private void drawJIsotope(JIsotope iso, Graphics g) 00208 { 00209 // don't draw anything if the isotope is outside of the viewing area 00210 if (iso.getZ() < bottomLeftZ || iso.getZ() > upperRightZ || iso.getN() < bottomLeftN || iso.getN() > upperRightN) 00211 return; 00212 00213 //defining constants. 00214 int liningThickness = 10; 00215 int massXIndent = 15; 00216 int massYIndent = 20; 00217 int nameXIndent = 16; 00218 int nameYIndent = 29; 00219 00220 //Screen coordinates of upper left corner of isotope. 00221 int x = (iso.getN()-bottomLeftN)*isotopeWidth; 00222 int y = height-(iso.getZ()-bottomLeftZ+1)*isotopeHeight; 00223 00224 Font font = new Font("Arial", Font.PLAIN, 10); 00225 g.setFont(font); 00226 String isotopeName = iso.getName().substring(0,1) + iso.getName().substring(1).toLowerCase(); 00227 Boolean oneUsed = false; 00228 if(iso.getColorList().size()>1) 00229 if(iso.getColorList().get(1).getR() == 0 && iso.getColorList().get(1).getG() == 0 && iso.getColorList().get(1).getB() == 0) 00230 { 00231 00232 g.setColor(Color.black); 00233 g.fillRect(x, y, isotopeWidth, isotopeHeight); 00234 oneUsed = true; 00235 } 00236 00237 switch(iso.getColorList().size()) 00238 { 00239 case 1: 00240 g.setColor(new Color(iso.getColorList().get(0).getR(), iso.getColorList().get(0).getG(), iso.getColorList().get(0).getB())); 00241 g.fillRect(x, y, isotopeWidth, isotopeHeight); 00242 break; 00243 case 2: 00244 int switcha = 1; 00245 if(oneUsed) switcha=0; 00246 g.setColor(new Color(iso.getColorList().get(switcha).getR(), iso.getColorList().get(switcha).getG(), iso.getColorList().get(switcha).getB())); 00247 if(oneUsed) 00248 g.fillRect(x+liningThickness, y+liningThickness, isotopeWidth-2*liningThickness, isotopeHeight-2*liningThickness); 00249 else 00250 g.fillRect(x,y,isotopeWidth, isotopeHeight); 00251 break; 00252 case 3: 00253 if(oneUsed) 00254 { 00255 g.setColor(new Color(iso.getColorList().get(2).getR(), iso.getColorList().get(2).getG(), iso.getColorList().get(2).getB())); 00256 g.fillRect(x+liningThickness, y+liningThickness, isotopeWidth-2*liningThickness, isotopeHeight-2*liningThickness); 00257 } 00258 else 00259 { 00260 g.setColor(new Color(iso.getColorList().get(1).getR(), iso.getColorList().get(1).getG(), iso.getColorList().get(1).getB())); 00261 int xpoints0[] = {x, x, x + isotopeWidth}; 00262 int ypoints0[] = {y, y + isotopeHeight, y + isotopeHeight}; 00263 g.fillPolygon(xpoints0, ypoints0, 3); 00264 00265 00266 g.setColor(new Color(iso.getColorList().get(2).getR(), iso.getColorList().get(2).getG(), iso.getColorList().get(2).getB())); 00267 int xpoints1[] = {x, x + isotopeWidth, x + isotopeWidth}; 00268 int ypoints1[] = {y, y, y + isotopeHeight}; 00269 g.fillPolygon(xpoints1, ypoints1, 3); 00270 00271 } 00272 break; 00273 case 4: 00274 if(oneUsed) 00275 { 00276 g.setColor(new Color(iso.getColorList().get(1).getR(), iso.getColorList().get(1).getG(), iso.getColorList().get(1).getB())); 00277 int xpoints0[] = {x+liningThickness, x+liningThickness, x + isotopeWidth-liningThickness}; 00278 int ypoints0[] = {y+liningThickness, y + isotopeHeight-liningThickness, y + isotopeHeight-liningThickness}; 00279 g.fillPolygon(xpoints0, ypoints0, 3); 00280 00281 g.setColor(new Color(iso.getColorList().get(2).getR(), iso.getColorList().get(2).getG(), iso.getColorList().get(2).getB())); 00282 int xpoints1[] = {x+liningThickness, x + isotopeWidth-liningThickness, x + isotopeWidth-liningThickness}; 00283 int ypoints1[] = {y+liningThickness, y+liningThickness, y + isotopeHeight-liningThickness}; 00284 g.fillPolygon(xpoints1, ypoints1, 3); 00285 } 00286 else 00287 { 00288 g.setColor(new Color(iso.getColorList().get(1).getR(), iso.getColorList().get(1).getG(), iso.getColorList().get(1).getB())); 00289 int[] xpoints0 = {x, x, x + isotopeWidth}; 00290 int[] ypoints0 = {y, y + isotopeHeight, y + isotopeHeight}; 00291 g.fillPolygon(xpoints0, ypoints0, 3); 00292 00293 g.setColor(new Color(iso.getColorList().get(2).getR(), iso.getColorList().get(2).getG(), iso.getColorList().get(2).getB())); 00294 int[] xpoints1 = {x, x + isotopeWidth, x + isotopeWidth/2}; 00295 int[] ypoints1 = {y, y, y + isotopeHeight/2}; 00296 g.fillPolygon(xpoints1, ypoints1, 3); 00297 00298 g.setColor(new Color(iso.getColorList().get(3).getR(), iso.getColorList().get(3).getG(), iso.getColorList().get(3).getB())); 00299 int[] xpoints2 = {x + isotopeWidth, x + isotopeWidth, x + isotopeWidth/2}; 00300 int[] ypoints2 = {y + isotopeHeight, y, y + isotopeHeight/2}; 00301 g.fillPolygon(xpoints2, ypoints2, 3); 00302 00303 00304 } 00305 break; 00306 case 5: 00307 if(oneUsed) 00308 { 00309 g.setColor(new Color(iso.getColorList().get(2).getR(), iso.getColorList().get(2).getG(), iso.getColorList().get(2).getB())); 00310 int[] xpoints0 = {x, x, x + isotopeWidth}; 00311 int[] ypoints0 = {y, y + isotopeHeight, y + isotopeHeight}; 00312 g.fillPolygon(xpoints0, ypoints0, 3); 00313 00314 g.setColor(new Color(iso.getColorList().get(3).getR(), iso.getColorList().get(3).getG(), iso.getColorList().get(3).getB())); 00315 int[] xpoints1 = {x, x + isotopeWidth, x + isotopeWidth/2}; 00316 int[] ypoints1 = {y, y, y + isotopeHeight/2}; 00317 g.fillPolygon(xpoints1, ypoints1, 3); 00318 00319 g.setColor(new Color(iso.getColorList().get(4).getR(), iso.getColorList().get(4).getG(), iso.getColorList().get(4).getB())); 00320 int[] xpoints2 = {x + isotopeWidth, x + isotopeWidth, x + isotopeWidth/2}; 00321 int[] ypoints2 = {y + isotopeHeight, y, y + isotopeHeight/2}; 00322 g.fillPolygon(xpoints2, ypoints2, 3); 00323 00324 } 00325 00326 else 00327 { 00328 g.setColor(new Color(iso.getColorList().get(1).getR(), iso.getColorList().get(1).getG(), iso.getColorList().get(1).getB())); 00329 int[] xpoints0 = {x, x, x + isotopeWidth/2}; 00330 int[] ypoints0 = {y, y + isotopeHeight, y + isotopeHeight/2}; 00331 g.fillPolygon(xpoints0, ypoints0, 3); 00332 00333 g.setColor(new Color(iso.getColorList().get(2).getR(), iso.getColorList().get(2).getG(), iso.getColorList().get(2).getB())); 00334 int[] xpoints1 = {x, x + isotopeWidth, x + isotopeWidth/2}; 00335 int[] ypoints1 = {y, y, y + isotopeHeight/2}; 00336 g.fillPolygon(xpoints1, ypoints1, 3); 00337 00338 g.setColor(new Color(iso.getColorList().get(3).getR(), iso.getColorList().get(3).getG(), iso.getColorList().get(3).getB())); 00339 int[] xpoints2 = {x + isotopeWidth, x + isotopeWidth, x + isotopeWidth/2}; 00340 int[] ypoints2 = {y+isotopeHeight, y, y + isotopeHeight/2}; 00341 g.fillPolygon(xpoints2, ypoints2, 3); 00342 00343 g.setColor(new Color(iso.getColorList().get(4).getR(), iso.getColorList().get(4).getG(), iso.getColorList().get(4).getB())); 00344 int[] xpoints3 = {x, x + isotopeWidth/2, x + isotopeWidth}; 00345 int[] ypoints3 = {y + isotopeHeight, y + isotopeHeight/2, y + isotopeHeight}; 00346 g.fillPolygon(xpoints3, ypoints3, 3); 00347 00348 } 00349 break; 00350 default: 00351 System.out.println("Too many color lists."); 00352 } 00353 00354 g.setColor(Color.black); 00355 g.drawRect(x, y, isotopeWidth, isotopeHeight); 00356 g.drawString(iso.getA()+"", x+massXIndent, y+massYIndent); 00357 g.drawString(isotopeName, x+nameXIndent, y+nameYIndent); 00358 00359 } 00360 00362 public void createEPSDocument(String filename) 00363 { 00364 isotopeWidth = 50; 00365 isotopeHeight = 50; 00366 00367 width = isotopeWidth*(upperRightN-bottomLeftN+1); 00368 height = isotopeHeight*(upperRightZ-bottomLeftZ+1); 00369 00370 drawNuclideChart(); 00371 00372 try 00373 { 00374 BufferedWriter out = new BufferedWriter(new FileWriter(filename, false)); 00375 out.write(graphics.toString()); 00376 out.close(); 00377 } 00378 catch(IOException e) 00379 { 00380 System.out.println("Error creating EPS document!"); 00381 } 00382 } 00383 }