Report problems to ATLAS LXR Team (with time and IP address indicated)

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: linux ]
Version: head ] [ nightly ] [ GaudiDev ]
  Links to LXR source navigation pages for stable releases [ 12.*.* ]   [ 13.*.* ]   [ 14.*.* ] 

001 package atlantis.gui;
002 
003 
004 import java.io.File;
005 import java.io.InputStream;
006 import java.awt.Color;
007 import javax.xml.parsers.DocumentBuilder;
008 import javax.xml.parsers.DocumentBuilderFactory;
009 
010 import org.w3c.dom.Node;
011 import org.w3c.dom.NodeList;
012 import org.w3c.dom.NamedNodeMap;
013 
014 import atlantis.Atlantis;
015 import atlantis.graphics.colormap.MappedColor;
016 import atlantis.parameters.APar;
017 import atlantis.utils.ALogPane;
018 import atlantis.utils.AOutput;
019 import atlantis.utils.AMath;
020 import atlantis.utils.AUtilities;
021 import atlantis.utils.ALogger;
022 import atlantis.utils.xml.AXMLErrorHandler;
023 
024 
025 public final class AColorMap
026 {
027     private static ALogger logger = ALogger.getLogger(AColorMap.class);
028     
029     private static final boolean VALIDATION = true;
030     final public static int NO_COLOR = -1;
031     final public static int INVISIBLE = -2;
032     static final public int BG = 8;   //background
033     static final public int WH = 0;   //white
034     static final public int GY = 14;  //grey
035     static final public int RD = 20;  //red
036     static final public int GN = 21;  //green
037     static final public int BL = 22;  //blue
038     static final public int YE = 23;  //yellow
039     static final public int MA = 24;  //magenta
040     static final public int CY = 25;  //cyan
041     static final public int BK = 26;  //black
042     static final public int OR = 27;  //orange
043     static final public int CB = 28;  //cornflower blue
044     private static final String[] mapNames = {"Default(1)", "Default(2)", "M4+M5", "GrayDet", 
045                                              "Original", "Gray", "B/W", "HitCol", "GrayHitCol"};
046     private static final String[] mapNamesPS = {"default1","default2","m4m5", "graydet", 
047                                              "original", "gray",  "bw", "hitcol", "grayhitcol"};
048     protected static MappedColor[][] maps;
049     private static int numColors;
050     private static int numMaps;
051 
052     // Color map indices.
053     public static final int COLOR_MAP_DEFAULT1 = 0;
054     public static final int COLOR_MAP_DEFAULT2 = 1;
055     public static final int COLOR_MAP_M4M5 = 2;
056     public static final int COLOR_MAP_GRAYDET = 3;
057     public static final int COLOR_MAP_ORIGINAL = 4;
058     public static final int COLOR_MAP_GRAY = 5;
059     public static final int COLOR_MAP_BW = 6;
060     public static final int COLOR_MAP_HITCOL = 7;
061     public static final int COLOR_MAP_GRAY_HITCOL = 8;
062 
063     //color map used if wrong value in config file 
064     static int currentMap = COLOR_MAP_DEFAULT1;
065 
066 
067     public static void readColorMap(String name)
068     {
069         String fileName = null;
070 
071         if(name != null && new File(name).canRead())
072         {
073             // color map file specified as command line argument
074             fileName = name;
075         }
076         else
077         {
078             if(name != null)
079             {
080                 logger.warn("Can't read color map file: " + name);
081             }
082             // color map file wasn't specified as command line argument
083             fileName = ".Atlantis-colormap.xml"; // default name
084             String fileNameFull = Atlantis.userHome + Atlantis.fileSep + fileName;
085             if(new File(fileNameFull).canRead())
086             {
087                 // use existing user's color map file
088                 fileName = fileNameFull;
089             }
090             else
091             {
092                 // use default color map file from Atlantis distribution
093                 fileName = Atlantis.getHomeDirectory() + "configuration" +
094                            Atlantis.fileSep + "colormap.xml";
095             }
096         }
097 
098         logger.info("Using color map file: " + fileName);
099         try
100         {
101             InputStream isColorMap = AUtilities.getFileAsStream(fileName);
102             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
103             factory.setValidating(VALIDATION);
104             DocumentBuilder parser = factory.newDocumentBuilder();
105             parser.setErrorHandler(new AXMLErrorHandler());
106             Node colormap = parser.parse(isColorMap).getDocumentElement();
107             NamedNodeMap cm = colormap.getAttributes();
108             numMaps = Integer.parseInt(cm.getNamedItem("numMaps").getNodeValue().
109                                        trim());
110             numColors = Integer.parseInt(cm.getNamedItem("numColors").
111                                          getNodeValue().trim());
112             maps = new MappedColor[numMaps][numColors];
113             NodeList list = colormap.getChildNodes();
114             int count = list.getLength();
115             for(int i = 0; i < count; i++)
116             {
117                 Node mapping = list.item(i);
118                 if(mapping.getNodeType() == Node.ELEMENT_NODE)
119                 {
120                     NamedNodeMap atts = mapping.getAttributes();
121                     try
122                     {
123                         int map = Integer.parseInt(atts.getNamedItem("map").
124                             getNodeValue().trim());
125                         int index = Integer.parseInt(atts.getNamedItem("index").
126                             getNodeValue().trim());
127                         int r = Integer.parseInt(atts.getNamedItem("r").
128                                                  getNodeValue().trim());
129                         int g = Integer.parseInt(atts.getNamedItem("g").
130                                                  getNodeValue().trim());
131                         int b = Integer.parseInt(atts.getNamedItem("b").
132                                                  getNodeValue().trim());
133                         if(map < maps.length)
134                         {
135                             if(index < maps[map].length)
136                             {
137                                 maps[map][index] = new MappedColor(r, g, b,
138                                     index);
139                             }
140                         }
141                     }
142                     catch(NumberFormatException e)
143                     {
144                         AExceptionHandler.processException("Colour map error:\n" +
145                             mapping, e);
146                     }
147                 } // if
148             } // for
149         }
150         catch(Exception e)
151         {
152             AExceptionHandler.processException("Error while reading colour map:\n" +
153                                                fileName, e);
154         }
155         for(int i = 0; i < maps.length; i++)
156         {
157             for(int j = 0; j < maps[i].length; j++)
158             {
159                 if(maps[i][j] == null)
160                 {
161                     AOutput.append("\nColorMap (" + i + "," + j +
162                                    ") is not present",
163                                    ALogPane.BAD_COMMAND);
164                 }
165             }
166         }
167 
168     } // readColorMap() -----------------------------------------------------
169 
170 
171 
172     public static int getNumMaps()
173     {
174         return numMaps;
175     }
176 
177 
178     public static int getNumColors()
179     {
180         return numColors;
181     }
182 
183 
184     /**
185      * Returns color map in the XML format.
186      * [Former method writeColorMap() was writing the XML data directly into
187      * the file.]
188      * @return String
189      */
190     public static String getColorMapXML()
191     {
192         StringBuffer buffer = new StringBuffer();
193         // color map DTD
194         buffer.append(
195             "<?xml version=\"1.0\"?>\n" +
196             "<!DOCTYPE colormap  [\n" +
197             " <!ELEMENT colormap (Mapping*)>" +
198             " <!ATTLIST colormap\n" +
199             "   numMaps   CDATA #REQUIRED\n" +
200             "   numColors CDATA #REQUIRED>\n" +
201             " <!ELEMENT Mapping EMPTY>\n" +
202             " <!ATTLIST Mapping\n" +
203             "   map   CDATA #REQUIRED\n" +
204             "   index CDATA #REQUIRED\n" +
205             "   r     CDATA #REQUIRED\n" +
206             "   g     CDATA #REQUIRED\n" +
207             "   b     CDATA #REQUIRED>\n" +
208             "]>\n\n\n");
209         buffer.append("<colormap numMaps=\"" + maps.length +
210                       "\" numColors=\"" + maps[0].length + "\" >\n");
211         for(int i = 0; i < maps.length; i++)
212         {
213             for(int j = 0; j < maps[i].length; j++)
214             {
215                 int r = maps[i][j].getRed();
216                 int g = maps[i][j].getGreen();
217                 int b = maps[i][j].getBlue();
218                 buffer.append("  <Mapping  map=\"" + i + "\" index=\"" + j +
219                               "\"  r=\"" + r + "\" g=\"" + g + "\" b=\"" +
220                               b + "\"/>\n");
221             }
222         }
223         buffer.append("</colormap>\n");
224         return buffer.toString();
225 
226     } // getColorMapXML() ---------------------------------------------------
227 
228 
229 
230     public static String getPSPrologColorMap()
231     {
232         StringBuffer s = new StringBuffer();
233         String newLine = System.getProperty("line.separator");
234         s.append(newLine);
235         for(int i = 0; i < maps.length; ++i)
236         {
237             s.append("/" + mapNamesPS[i] + "ColorMap" + newLine);
238             s.append("<<" + newLine);
239             for(int j = 0; j < maps[i].length; ++j)
240                 s.append(" /C" + j + " [" +
241                          AMath.d2s(maps[i][j].getRed() / 255., 3) + " "
242                          + AMath.d2s(maps[i][j].getGreen() / 255., 3) + " " +
243                          AMath.d2s(maps[i][j].getBlue() / 255., 3)
244                          + "]" + newLine);
245             s.append(">> def" + newLine);
246             s.append(newLine);
247         }
248         return s.toString();
249 
250     } // getPSPrologColorMap() ----------------------------------------------
251 
252 
253 
254     public static Color[] getColors(int map)
255     {
256         Color[] col = new Color[maps[map].length];
257         for(int i = 0; i < col.length; ++i)
258             col[i] = (Color) maps[map][i];
259         return col;
260     }
261 
262     //From hot (red), index 255, to cold (blue), index 0
263     public static Color[] getShades(int num)
264     {
265         assert (num>=2);
266         Color[] col = new Color[num];
267         col[0]=new Color(170,170,170);//grey for "other"
268         for(int i = 1; i < num-1; ++i)
269             col[i] = new Color(((255*i)/num),80,255-((255*i)/num));
270         return col;
271     }
272 
273     public static Color[] getColors()
274     {
275         return getColors(currentMap);
276     }
277 
278 
279     public static void setColorMap(int map)
280     {
281         if(map >= 0 && map < maps.length)
282         {
283             currentMap = map;
284             APar.get("Prefs","ColorMap").setI(map);
285         }
286     }
287 
288 
289     public static void setColorMap(String mapName)
290     {
291         for(int i = 0; i < mapNames.length; i++)
292             if(mapNames[i].equals(mapName))
293                 setColorMap(i);
294     }
295 
296 
297     public static int getColorMap()
298     {
299         return currentMap;
300     }
301 
302     public static boolean drawFrames()
303     {
304         if(currentMap==COLOR_MAP_GRAY  || currentMap==COLOR_MAP_BW)
305             return true;
306         else
307             return false;
308     }
309     
310     public static String getPSColorMapName()
311     {
312         return mapNamesPS[getColorMap()];
313 
314     } // getPSColorMapName() ------------------------------------------------
315 
316 
317     public MappedColor getMappedColor(int colorIndex)
318     {
319         if(colorIndex < 0 && colorIndex >= maps[currentMap].length)
320         {
321             return null;
322         }
323         else
324         {
325             return maps[currentMap][colorIndex];
326         }
327     }
328 
329 
330     public Color getColor(int colorIndex)
331     {
332         if(colorIndex < 0 && colorIndex >= maps[currentMap].length)
333         {
334             return null;
335         }
336         else
337         {
338             return(Color) maps[currentMap][colorIndex];
339         }
340     }
341 
342 
343     public static String getTag(int colorIndex)
344     {
345         if(colorIndex < 0 && colorIndex >= maps[0].length)
346         {
347             return null;
348         }
349         else
350         {
351             return "C" + colorIndex;
352         }
353     }
354 
355 
356     public static String[] getMapNames()
357     {
358         return(String[]) mapNames.clone();
359     }
360 
361 
362 } // class AColorMap ========================================================
363 

source navigation ] diff markup ] identifier search ] general search ]

Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems
This page was automatically generated by the LXR engine. Valid HTML 4.01!