001//==JZcmd==
002//JZcmd main(){
003//JZcmd   if($1=="AWT") { java org.vishia.gral.test.GralColorShow.mainAWT();
004//JZcmd   } else { java org.vishia.gral.test.GralColorShow.main(); } 
005//JZcmd }
006//==endJZcmd==
007package org.vishia.gral.test;
008import java.io.BufferedInputStream;
009import java.io.BufferedReader;
010import java.io.File;
011import java.io.FileNotFoundException;
012import java.io.FileWriter;
013import java.io.IOException;
014import java.io.InputStream;
015import java.io.InputStreamReader;
016import java.io.Writer;
017import java.nio.charset.IllegalCharsetNameException;
018import java.nio.charset.UnsupportedCharsetException;
019import java.text.ParseException;
020import java.util.Map;
021import java.util.TreeMap;
022
023import org.vishia.gral.awt.AwtFactory;
024import org.vishia.gral.base.GralColorConv;
025import org.vishia.gral.base.GralGraphicTimeOrder;
026import org.vishia.gral.base.GralMng;
027import org.vishia.gral.base.GralMouseWidgetAction_ifc;
028import org.vishia.gral.base.GralPos;
029import org.vishia.gral.base.GralTextField;
030import org.vishia.gral.base.GralWindow;
031import org.vishia.gral.ifc.GralColor;
032import org.vishia.gral.ifc.GralFactory;
033import org.vishia.gral.ifc.GralUserAction;
034import org.vishia.gral.ifc.GralWidget_ifc;
035import org.vishia.gral.ifc._GralChgColor;
036import org.vishia.gral.swt.SwtFactory;
037import org.vishia.gral.widget.GralLabel;
038import org.vishia.math.CurveInterpolation;
039import org.vishia.msgDispatch.LogMessage;
040import org.vishia.msgDispatch.LogMessageStream;
041import org.vishia.util.Debugutil;
042import org.vishia.util.KeyCode;
043import org.vishia.util.StringPartFromFileLines;
044import org.vishia.util.StringPartScan;
045
046
047/*Test with jzcmd: call jzcmd with this java file with its full path:
048D:/vishia/Java/srcJava_vishiaGui/org/vishia/gral/test/GralColorShow.java
049==JZcmd==
050java org.vishia.gral.test.GralColorShow.main(null);                 
051==endJZcmd==
052 */
053
054/**This class opens a window with some colors sorted horizontal with saturation and vertical with color value.
055 * 
056 * @author Hartmut Schorrig
057 *
058 */
059public class GralColorShow
060{
061  
062  /**The version, history and license.
063   * <ul>
064   * <li>2015-09-12 Hartmut now generates some colors via HSB values.
065   * <li>2015-01-01 Hartmut created: .
066   * </ul>
067   * 
068   * <b>Copyright/Copyleft</b>:
069   * For this source the LGPL Lesser General Public License,
070   * published by the Free Software Foundation is valid.
071   * It means:
072   * <ol>
073   * <li> You can use this source without any restriction for any desired purpose.
074   * <li> You can redistribute copies of this source to everybody.
075   * <li> Every user of this source, also the user of redistribute copies
076   *    with or without payment, must accept this license for further using.
077   * <li> But the LPGL is not appropriate for a whole software product,
078   *    if this source is only a part of them. It means, the user
079   *    must publish this part of source,
080   *    but don't need to publish the whole source of the own product.
081   * <li> You can study and modify (improve) this source
082   *    for own using or for redistribution, but you have to license the
083   *    modified sources likewise under this LGPL Lesser General Public License.
084   *    You mustn't delete this Copyright/Copyleft inscription in this source file.
085   * </ol>
086   * If you are intent to use this sources without publishing its usage, you can get
087   * a second license subscribing a special contract with the author. 
088   * 
089   * @author Hartmut Schorrig = hartmut.schorrig@vishia.de
090   * 
091   * 
092   */
093  public static final String version = "2015-09-12";
094
095  
096  class Index {
097    int ixCol, ixLight;
098    //int ixColNext, ixColPrev;
099    //int ixLightNext, ixLightPrev;
100    
101  }
102  
103  
104  /**All attributes should be stored in a GralColor TODO.
105   */
106  class XXXColorValue {
107    GralColor color;
108    int rgb;
109    String shortname, name;
110    public XXXColorValue(int rgb, String shortname, String name)
111    { this.color = new GralColor(shortname, rgb);
112      this.rgb = rgb;
113      this.shortname = shortname;
114      this.name = name;
115    }
116  }
117  
118  
119  
120  
121  class ColorWithField {
122    GralColor co;
123    final Index index;
124    float[] hsb = new float[3];
125    float[] hls = new float[3];
126    final GralTextField wdgColor;
127    
128    /**True if a graphic is initialized and opened . */
129    boolean bActive;
130    
131    ColorWithField(GralColor co, String shortname, int ixCol, int ixBright, int colValue) {
132      this.co = co;
133      this.index = new Index();
134      this.index.ixCol = ixCol; index.ixLight = ixBright;
135      this.wdgColor = new GralTextField("" + ixCol + "," + ixBright); //, GralTextField.Type.editable);
136      this.wdgColor.setBackColor(co, 0);
137      this.wdgColor.setData(this);
138      //this.wdgColor.setActionFocused(actionFocusColor);
139      this.wdgColor.setActionChange(actionEditColor);
140      this.wdgColor.setActionMouse(null, GralMouseWidgetAction_ifc.mUserAll);
141      //this.wdgColor.setTextColor(colText);
142    }
143    
144    @Override public String toString(){ return co.name + ": [" + index.ixLight + ", " + index.ixCol + "]"; }
145  }
146  
147  GralMng gralMng = GralMng.get();
148  
149  GralFactory gralFactory;
150  
151  public static void main(String[] args){ main(); }
152
153    
154  public static void mainAWT(){
155    GralColorShow main = new GralColorShow();
156    main.gralFactory = new AwtFactory();
157    //main.execute();
158    main.execute1();
159  }
160  
161  public static void main(){
162    GralColorShow main = new GralColorShow();
163    main.gralFactory = new SwtFactory();
164    //main.execute();
165    main.execute1();
166  }
167  
168  private void execute(){
169    genColorFrame();
170    genDefaultConfig();
171    /*
172    try {
173      readConfig();
174    } catch (IOException e1) {
175      System.err.println("GralColor - config file error, " + e1.getMessage());
176    } catch(ParseException exc) {
177      System.err.println("GralColor - cannot read config, " + exc.getMessage());
178    }
179    */
180    LogMessage log = new LogMessageStream(System.out);
181    GralWindow wind = gralFactory.createWindow(log, "Show Colors", 'B', 150, 10,1000, 800);
182    gralMng = wind.gralMng();
183    gralMng.gralDevice.addDispatchOrder(initGraphicFullColors);
184    //initGraphic.awaitExecution(1, 0);
185    while(gralMng.gralDevice.isRunning()){
186      try{ Thread.sleep(100);} 
187      catch (InterruptedException e)
188      { //dialogZbnfConfigurator.terminate();
189      }
190    }
191      
192  }
193  
194  
195  
196  
197  private void execute1(){
198    genColorFrame();
199    try {
200      readConfig();
201    } catch (IOException e1) {
202      System.err.println("GralColor - config file error, " + e1.getMessage());
203    } catch(ParseException exc) {
204      System.err.println("GralColor - cannot read config, " + exc.getMessage());
205    }
206    GralFactory gralFactory = new SwtFactory();
207    LogMessage log = new LogMessageStream(System.out);
208    GralWindow wind = gralFactory.createWindow(log, "Show Colors", 'B', 150, 10,1000, 800);
209    gralMng = wind.gralMng();
210    gralMng.gralDevice.addDispatchOrder(initGraphicLessColors);
211    //initGraphic.awaitExecution(1, 0);
212    while(gralMng.gralDevice.isRunning()){
213      try{ Thread.sleep(100);} 
214      catch (InterruptedException e)
215      { //dialogZbnfConfigurator.terminate();
216      }
217    }
218      
219  }
220  
221  
222  
223  
224  class ColHue{
225    final String colorName;
226    final float colorValue;
227
228    public ColHue(String colorName, float colorValue)
229    { this.colorName = colorName;
230      this.colorValue = colorValue;
231    }
232  }
233  
234  
235  
236  ColHue[] colHue =   ////
237  { new ColHue("ma",  0.0f)  //pu
238  , new ColHue("pk",  2.0f) 
239  //)), new ColHue("rp",  2.5f) 
240  , new ColHue("rd",  4.0f)  //rd
241  , new ColHue("ro",  5.0f) 
242  , new ColHue("or",  6.0f) 
243  , new ColHue("yo",  7.0f) //or
244  , new ColHue("am",  7.5f) //am
245  , new ColHue("ye",  8.0f) //ye
246  , new ColHue("gy",  8.4f) 
247  , new ColHue("yg",  9.0f)                         
248  , new ColHue("ng", 10.0f) 
249  , new ColHue("gn", 12.0f)  //gn
250  //, new ColHue("gc", 13.5f) 
251  , new ColHue("sg", 14.0f)  //cy
252  , new ColHue("cy", 16.0f) //cy
253  , new ColHue("cb", 17.5f) 
254  , new ColHue("nb", 19.0f) 
255  , new ColHue("bl", 20.0f)   //bl
256  , new ColHue("vb", 21.0f)   //bl                   
257  , new ColHue("vi", 22.0f)   //vi
258  , new ColHue("vm", 23.0f)   //vi
259  };
260  
261  
262  
263  String[][] namesGray = 
264  { {"gr", "mg", "rg", "yg", "gg", "cg", "bg"}, {"g2", "gm", "gd", "gy", "ge", "gc", "gb"} };
265
266  
267  /**Class to store a color with light-value and saturation
268   * @author hartmut
269   *
270   */
271  class LightSat{
272    final String lName;
273    final float light;
274    final float sat, sat2;
275    
276    public LightSat(String lName, float light, float sat)
277    { this.lName = lName;
278      this.light = light;
279      this.sat = sat;
280      this.sat2 = sat;
281    }
282    
283    public LightSat(String lName, float light, float sat, float sat2)
284    { this.lName = lName;
285      this.light = light;
286      this.sat = sat;
287      this.sat2 = sat2;
288    }
289    
290  }
291  
292  
293  /**The 2 tables of gray colors. Saturation for table 1 and table 2*/
294  LightSat[] gray1Sat =  ////
295  { new LightSat("p1", 1.90f, 0.02f, 0.05f )
296  , new LightSat("p2", 1.80f, 0.03f, 0.07f )
297  , new LightSat("l1", 1.70f, 0.04f, 0.10f  )
298  , new LightSat("l2", 1.60f, 0.05f, 0.12f  )
299  , new LightSat("l3", 1.50f, 0.06f, 0.14f  )
300  , new LightSat("l4", 1.40f, 0.08f, 0.16f  )
301  , new LightSat("l5", 1.30f, 0.10f, 0.18f  )
302  , new LightSat("d1", 1.20f, 0.12f, 0.20f  )
303  , new LightSat("d2", 1.10f, 0.12f, 0.20f  )
304  , new LightSat("d3", 1.00f, 0.15f, 0.25f  )
305  , new LightSat("d4", 0.80f, 0.18f, 0.30f  )
306  , new LightSat("d5", 0.60f, 0.20f, 0.40f  )
307  , new LightSat("d6", 0.40f, 0.40f, 0.60f  )
308  , new LightSat("d7", 0.20f, 0.60f, 1.0f  )
309  };
310  
311  
312  /**Use this table to test the gray light in comparison with color lights
313   * 
314   */
315  LightSat[] gray1Sat_test =  ////
316  { new LightSat("p1", 1.90f, 1.0f, 0.5f )
317  , new LightSat("p2", 1.80f, 1.0f, 0.5f )
318  , new LightSat("l1", 1.70f, 1.0f, 0.5f  )
319  , new LightSat("l2", 1.60f, 1.0f, 0.5f  )
320  , new LightSat("l3", 1.50f, 1.0f, 0.5f  )
321  , new LightSat("l4", 1.40f, 1.0f, 0.5f  )
322  , new LightSat("l5", 1.30f, 1.0f, 0.5f  )
323  , new LightSat("d1", 1.20f, 1.0f, 0.5f  )
324  , new LightSat("d2", 1.10f, 1.0f, 0.5f  )
325  , new LightSat("d3", 1.00f, 1.0f, 0.5f  )
326  , new LightSat("d4", 0.80f, 1.0f, 0.5f  )
327  , new LightSat("d5", 0.60f, 1.0f, 0.5f  )
328  , new LightSat("d6", 0.40f, 1.0f, 0.5f  )
329  , new LightSat("d7", 0.20f, 1.0f, 0.5f  )
330  };
331  
332  
333  /**Table which determines the rows of the color table.
334   * It give light and saturation values.
335   */
336  LightSat[] lightSat_html =  ////
337  { new LightSat("p1", 1.95f, 1.00f )
338  , new LightSat("p2", 1.90f, 1.00f )
339  , new LightSat("p3", 1.85f, 1.00f )
340  , new LightSat("p4", 1.80f, 1.00f )
341  , new LightSat("p5", 1.80f, 0.80f )
342  , new LightSat("l1", 1.70f, 1.00f )
343  , new LightSat("l2", 1.60f, 1.00f )
344  , new LightSat("l3", 1.60f, 0.80f )
345  , new LightSat("l4", 1.50f, 1.00f )
346  , new LightSat("l5", 1.40f, 1.00f )
347  , new LightSat("s1", 1.30f, 1.00f )
348  , new LightSat("g1", 1.30f, 0.70f )
349  , new LightSat("g2", 1.30f, 0.40f )
350  , new LightSat("s2", 1.20f, 1.00f )
351  , new LightSat("s3", 1.10f, 1.00f )
352  , new LightSat("g3", 1.20f, 0.30f )                                                                 
353  , new LightSat("s4", 1.10f, 0.50f )                                                                 
354  , new LightSat("g4", 1.10f, 0.70f )                                                                 
355  , new LightSat("s5", 1.00f, 1.00f )
356  , new LightSat("s6", 0.90f, 1.00f )
357  , new LightSat("g5", 0.90f, 0.70f )
358  , new LightSat("g6", 0.90f, 0.50f )
359  , new LightSat("g7", 0.80f, 0.40f )
360  , new LightSat("g8", 0.80f, 0.60f )
361  , new LightSat("s7", 0.80f, 1.00f )
362  , new LightSat("d1", 0.65f, 1.00f )                        
363  , new LightSat("d2", 0.60f, 0.70f )
364  , new LightSat("g9", 0.60f, 0.50f )
365  , new LightSat("d3", 0.50f, 0.60f )
366  , new LightSat("d4", 0.45f, 1.00f )
367  , new LightSat("d5", 0.40f, 0.70f )
368  , new LightSat("d6", 0.30f, 1.00f )
369  };
370  
371  
372  LightSat[] lightSat_test =  //// test
373  { new LightSat("p1", 1.95f, 1.00f )
374  , new LightSat("p2", 1.90f, 1.00f )
375  , new LightSat("p3", 1.85f, 1.00f )
376  , new LightSat("p4", 1.80f, 1.00f )
377  , new LightSat("p5", 1.75f, 1.00f )
378  , new LightSat("l1", 1.70f, 1.00f )
379  , new LightSat("l2", 1.60f, 1.00f )
380  , new LightSat("l3", 1.50f, 1.00f )
381  , new LightSat("l4", 1.50f, 1.00f )
382  , new LightSat("l5", 1.50f, 1.00f )
383  , new LightSat("s1", 1.40f, 1.00f )
384  , new LightSat("g1", 1.30f, 1.00f )
385  , new LightSat("s2", 1.20f, 1.00f )
386  , new LightSat("s3", 1.10f, 1.00f )
387  , new LightSat("g2", 1.10f, 0.00f )                                                                 
388  , new LightSat("g3", 1.00f, 0.10f )                                                                 
389  , new LightSat("g4", 1.00f, 0.20f )                                                                 
390  , new LightSat("s4", 1.00f, 0.30f )
391  , new LightSat("s5", 1.00f, 0.40f )
392  , new LightSat("g5", 1.00f, 0.60f )
393  , new LightSat("g6", 1.00f, 0.8f )
394  , new LightSat("g7", 1.00f, 1.00f )
395  , new LightSat("g8", 0.90f, 1.00f )
396  , new LightSat("s6", 0.80f, 1.00f )
397  , new LightSat("d1", 0.70f, 1.00f )                        
398  , new LightSat("d2", 0.60f, 1.00f )
399  , new LightSat("g9", 0.50f, 1.00f )
400  , new LightSat("d3", 0.40f, 1.00f )
401  , new LightSat("d4", 0.30f, 1.00f )
402  , new LightSat("d5", 0.20f, 1.00f )
403  , new LightSat("d6", 0.10f, 1.00f )
404  };
405  
406  
407  LightSat[] lightSat_test2 =  //// test
408  { new LightSat("p1", 1.50f, 0.00f )
409  , new LightSat("p2", 1.50f, 0.10f )
410  , new LightSat("p3", 1.50f, 0.20f )
411  , new LightSat("p4", 1.50f, 0.30f )
412  , new LightSat("p5", 1.50f, 0.40f )
413  , new LightSat("l1", 1.50f, 0.60f )
414  , new LightSat("l2", 1.50f, 0.80f )
415  , new LightSat("l3", 1.50f, 0.90f )
416  , new LightSat("l4", 1.50f, 1.00f )
417  , new LightSat("l5", 1.00f, 0.00f )
418  , new LightSat("s1", 1.00f, 0.10f )
419  , new LightSat("g1", 1.00f, 0.20f )
420  , new LightSat("s2", 1.00f, 0.30f )
421  , new LightSat("s3", 1.00f, 0.40f )
422  , new LightSat("g2", 1.00f, 0.50f )                                                                 
423  , new LightSat("g3", 1.00f, 0.60f )                                                                 
424  , new LightSat("g4", 1.00f, 0.70f )                                                                 
425  , new LightSat("s4", 1.00f, 0.80f )
426  , new LightSat("s5", 1.00f, 0.90f )
427  , new LightSat("g5", 1.00f, 1.00f )
428  , new LightSat("g6", 0.65f, 0.00f )
429  , new LightSat("g7", 0.65f, 0.10f )
430  , new LightSat("g8", 0.65f, 0.20f )
431  , new LightSat("s6", 0.65f, 0.30f )
432  , new LightSat("d1", 0.65f, 0.40f )                        
433  , new LightSat("d2", 0.65f, 0.50f )
434  , new LightSat("g9", 0.65f, 0.60f )
435  , new LightSat("d3", 0.65f, 0.70f )
436  , new LightSat("d4", 0.65f, 0.80f )
437  , new LightSat("d5", 0.65f, 0.90f )
438  , new LightSat("d6", 0.65f, 1.00f )
439  };
440  
441  
442  
443  LightSat[] lightSat = lightSat_html;
444  
445  String[] valTest = {"", ""};
446  
447
448  String[][] colorsLess = 
449  { { "ma", ""}
450  , { "", ""}
451  };
452  
453  
454  String[][] colorsAll = 
455  { { "p1ma", "p1pk", "p1rd", "p1ro", "p1op", "p1yo", "p1am", "p1ye", "p1gy", "p1yg", "p1ng", "p1gn", "p1sg", "p1cy", "p1cb", "p1nb", "p1bl", "p1vb", "p1vi", "p1vm", "p1ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
456  , { "p2ma", "p2pk", "p2rd", "p2ro", "p2op", "p2yo", "p2am", "p2ye", "p2gy", "p2yg", "p2ng", "p2gn", "p2sg", "p2cy", "p2cb", "p2nb", "p2bl", "p2vb", "p2vi", "p2vm", "p2ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
457  , { "p3ma", "p3pk", "p3rd", "p3ro", "p3op", "p3yo", "p3am", "p3ye", "p3gy", "p3yg", "p3ng", "p3gn", "p3sg", "p3cy", "p3cb", "p3nb", "p3bl", "p3vb", "p3vi", "p3vm", "p3ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
458  , { "p4ma", "p4pk", "p4rd", "p4ro", "p4op", "p4yo", "p4am", "p4ye", "p4gy", "p4yg", "p4ng", "p4gn", "p4sg", "p4cy", "p4cb", "p4nb", "p4bl", "p4vb", "p4vi", "p4vm", "p4ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
459  , { "l1ma", "l1pk", "l1rd", "l1ro", "l1op", "l1yo", "l1am", "l1ye", "l1gy", "l1yg", "l1ng", "l1gn", "l1sg", "l1cy", "l1cb", "l1nb", "l1bl", "l1vb", "l1vi", "l1vm", "l1ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
460  , { "l2ma", "l2pk", "l2rd", "l2ro", "l2op", "l2yo", "l2am", "l2ye", "l2gy", "l2yg", "l2ng", "l2gn", "l2sg", "l2cy", "l2cb", "l2nb", "l2bl", "l2vb", "l2vi", "l2vm", "l2ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
461  , { "l3ma", "l3pk", "l3rd", "l3ro", "l3op", "l3yo", "l3am", "l3ye", "l3gy", "l3yg", "l3ng", "l3gn", "l3sg", "l3cy", "l3cb", "l3nb", "l3bl", "l3vb", "l3vi", "l3vm", "l3ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
462  , { "l4ma", "l4pk", "l4rd", "l4ro", "l4op", "l4yo", "l4am", "l4ye", "l4gy", "l4yg", "l4ng", "l4gn", "l4sg", "l4cy", "l4cb", "l4nb", "l4bl", "l4vb", "l4vi", "l4vm", "l4ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
463  , { "l5ma", "l5pk", "l5rd", "l5ro", "l5op", "l5yo", "l5am", "l5ye", "l5gy", "l5yg", "l5ng", "l5gn", "l5sg", "l5cy", "l5cb", "l5nb", "l5bl", "l5vb", "l5vi", "l5vm", "l5ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
464  , { "s1ma", "s1pk", "s1rd", "s1ro", "s1op", "s1yo", "s1am", "s1ye", "s1gy", "s1yg", "s1ng", "s1gn", "s1sg", "s1cy", "s1cb", "s1nb", "s1bl", "s1vb", "s1vi", "s1vm", "s1ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
465  , { "g1ma", "g1pk", "g1rd", "g1ro", "g1op", "g1yo", "g1am", "g1ye", "g1gy", "g1yg", "g1ng", "g1gn", "g1sg", "g1cy", "g1cb", "g1nb", "g1bl", "g1vb", "g1vi", "g1vm", "g1ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
466  , { "s2ma", "s2pk", "s2rd", "s2ro", "s2op", "s2yo", "s2am", "s2ye", "s2gy", "s2yg", "s2ng", "s2gn", "s2sg", "s2cy", "s2cb", "s2nb", "s2bl", "s2vb", "s2vi", "s2vm", "s2ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
467  , { "s3ma", "s3pk", "s3rd", "s3ro", "s3op", "s3yo", "s3am", "s3ye", "s3gy", "s3yg", "s3ng", "s3gn", "s3sg", "s3cy", "s3cb", "s3nb", "s3bl", "s3vb", "s3vi", "s3vm", "s3ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
468  , { "g2ma", "g2pk", "g2rd", "g2ro", "g2op", "g2yo", "g2am", "g2ye", "g2gy", "g2yg", "g2ng", "g2gn", "g2sg", "g2cy", "g2cb", "g2nb", "g2bl", "g2vb", "g2vi", "g2vm", "g2ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
469  , { "g3ma", "g3pk", "g3rd", "g3ro", "g3op", "g3yo", "g3am", "g3ye", "g3gy", "g3yg", "g3ng", "g3gn", "g3sg", "g3cy", "g3cb", "g3nb", "g3bl", "g3vb", "g3vi", "g3vm", "g3ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
470  , { "g4ma", "g4pk", "g4rd", "g4ro", "g4op", "g4yo", "g4am", "g4ye", "g4gy", "g4yg", "g4ng", "g4gn", "g4sg", "g4cy", "g4cb", "g4nb", "g4bl", "g4vb", "g4vi", "g4vm", "g4ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
471  , { "s4ma", "s4pk", "s4rd", "s4ro", "s4op", "s4yo", "s4am", "s4ye", "s4gy", "s4yg", "s4ng", "s4gn", "s4sg", "s4cy", "s4cb", "s4nb", "s4bl", "s4vb", "s4vi", "s4vm", "s4ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
472  , { "s5ma", "s5pk", "s5rd", "s5ro", "s5op", "s5yo", "s5am", "s5ye", "s5gy", "s5yg", "s5ng", "s5gn", "s5sg", "s5cy", "s5cb", "s5nb", "s5bl", "s5vb", "s5vi", "s5vm", "s5ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
473  , { "g5ma", "g5pk", "g5rd", "g5ro", "g5op", "g5yo", "g5am", "g5ye", "g5gy", "g5yg", "g5ng", "g5gn", "g5sg", "g5cy", "g5cb", "g5nb", "g5bl", "g5vb", "g5vi", "g5vm", "g5ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
474  , { "g6ma", "g6pk", "g6rd", "g6ro", "g6op", "g6yo", "g6am", "g6ye", "g6gy", "g6yg", "g6ng", "g6gn", "g6sg", "g6cy", "g6cb", "g6nb", "g6bl", "g6vb", "g6vi", "g6vm", "g6ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
475  , { "g7ma", "g7pk", "g7rd", "g7ro", "g7op", "g7yo", "g7am", "g7ye", "g7gy", "g7yg", "g7ng", "g7gn", "g7sg", "g7cy", "g7cb", "g7nb", "g7bl", "g7vb", "g7vi", "g7vm", "g7ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
476  , { "g8ma", "g8pk", "g8rd", "g8ro", "g8op", "g8yo", "g8am", "g8ye", "g8gy", "g8yg", "g8ng", "g8gn", "g8sg", "g8cy", "g8cb", "g8nb", "g8bl", "g8vb", "g8vi", "g8vm", "g8ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
477  , { "s6ma", "s6pk", "s6rd", "s6ro", "s6op", "s6yo", "s6am", "s6ye", "s6gy", "s6yg", "s6ng", "s6gn", "s6sg", "s6cy", "s6cb", "s6nb", "s6bl", "s6vb", "s6vi", "s6vm", "s6ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
478  , { "d1ma", "d1pk", "d1rd", "d1ro", "d1op", "d1yo", "d1am", "d1ye", "d1gy", "d1yg", "d1ng", "d1gn", "d1sg", "d1cy", "d1cb", "d1nb", "d1bl", "d1vb", "d1vi", "d1vm", "d1ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
479  , { "d2ma", "d2pk", "d2rd", "d2ro", "d2op", "d2yo", "d2am", "d2ye", "d2gy", "d2yg", "d2ng", "d2gn", "d2sg", "d2cy", "d2cb", "d2nb", "d2bl", "d2vb", "d2vi", "d2vm", "d2ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
480  , { "g9ma", "g9pk", "g9rd", "g9ro", "g9op", "g9yo", "g9am", "g9ye", "g9gy", "g9yg", "g9ng", "g9gn", "g9sg", "g9cy", "g9cb", "g9nb", "g9bl", "g9vb", "g9vi", "g9vm", "g9ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
481  , { "d3ma", "d3pk", "d3rd", "d3ro", "d3op", "d3yo", "d3am", "d3ye", "d3gy", "d3yg", "d3ng", "d3gn", "d3sg", "d3cy", "d3cb", "d3nb", "d3bl", "d3vb", "d3vi", "d3vm", "d3ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
482  , { "d4ma", "d4pk", "d4rd", "d4ro", "d4op", "d4yo", "d4am", "d4ye", "d4gy", "d4yg", "d4ng", "d4gn", "d4sg", "d4cy", "d4cb", "d4nb", "d4bl", "d4vb", "d4vi", "d4vm", "d4ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
483  , { "d5ma", "d5pk", "d5rd", "d5ro", "d5op", "d5yo", "d5am", "d5ye", "d5gy", "d5yg", "d5ng", "d5gn", "d5sg", "d5cy", "d5cb", "d5nb", "d5bl", "d5vb", "d5vi", "d5vm", "d5ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
484  , { "d6ma", "d6pk", "d6rd", "d6ro", "d6op", "d6yo", "d6am", "d6ye", "d6gy", "d6yg", "d6ng", "d6gn", "d6sg", "d6cy", "d6cb", "d6nb", "d6bl", "d6vb", "d6vi", "d6vm", "d6ma", "wh", "whma", "wh1r", "whye", "whgn", "whcy", "whbl"}
485  };
486  
487  
488  String[][] colors4 = 
489  { { "p1ma", "p1pk", "p1rd", "p1or", "p1yo", "p1ye", "p1yg", "p1gn", "p1sg", "p1cy", "p1bl", "p1vi", "p1w2" ,"p1mw" ,"p1rw", "whye", "p1gw", "p1cw", "whbl"}
490  , { "p3ma", "p3pk", "p3rd", "p3or", "p3yo", "p3ye", "p3yg", "p3gn", "p3sg", "p3cy", "p3bl", "p3vi", "p2w2" ,"p2mw" ,"p2rw", "p2yw", "p2gw", "p2cw", "p2bw" }
491  , { "l1ma", "l1pk", "l1rd", "l1or", "l1yo", "l1ye", "l1yg", "l1gn", "l1sg", "l1cy", "l1bl", "l1vi", "l1g2" ,"l1mg" ,"l1rg", "l1yg", "l1gg", "l1cg", "l1bg" }
492  , { "l3ma", "l3pk", "l3rd", "l3or", "l3yo", "l3ye", "l3yg", "l3gn", "l3sg", "l3cy", "l3bl", "l3vi", "l2g2" ,"l2mg" ,"l2rg", "l2yg", "l2gg", "l2cg", "l2bg" }
493  , { "l5ma", "l5pk", "l5rd", "l5or", "l5yo", "l5ye", "l5yg", "l5gn", "l5sg", "l5cy", "l5bl", "l5vi", "l3g2" ,"l3mg" ,"l3rg", "l3yg", "l3gg", "l3cg", "l3bg" }
494  , { "g1ma", "g1pk", "g1rd", "g1or", "g1yo", "g1ye", "g1yg", "g1gn", "g1sg", "g1cy", "g1bl", "g1vi", "l4g2" ,"l4mg" ,"l4rg", "l4yg", "l4gg", "l4cg", "l4bg" }
495  , { "s3ma", "s3pk", "s3rd", "s3or", "s3yo", "s3ye", "s3yg", "s3gn", "s3sg", "s3cy", "s3bl", "s3vi", "l5g2" ,"l5mg" ,"l5rg", "l5yg", "l5gg", "l5cg", "l5bg" }
496  , { "g3ma", "g3pk", "g3rd", "g3or", "g3yo", "g3ye", "g3yg", "g3gn", "g3sg", "g3cy", "g3bl", "g3vi", "d1g2" ,"d1mg" ,"d1rg", "d1yg", "d1gg", "d1cg", "d1bg" }
497  , { "s4ma", "s4pk", "s4rd", "s4or", "s4yo", "s4ye", "s4yg", "s4gn", "s4sg", "s4cy", "s4bl", "s4vi", "d2g2" ,"d2mg" ,"d2rg", "d2yg", "d2gg", "d2cg", "d2bg" }
498  , { "g5ma", "g5pk", "g5rd", "g5or", "g5yo", "g5ye", "g5yg", "g5gn", "g5sg", "g5cy", "g5bl", "g5vi", "d3g2" ,"d3mg" ,"d3rg", "d3yg", "d3gg", "d3cg", "d3bg" }
499  , { "g7ma", "g7pk", "g7rd", "g7or", "g7yo", "g7ye", "g7yg", "g7gn", "g7sg", "g7cy", "g7bl", "g7vi", "d4g2" ,"d4mg" ,"d4rg", "d4yg", "d4gg", "d4cg", "d4bg" }
500  , { "s6ma", "s6pk", "s6rd", "s6or", "s6yo", "s6ye", "s6yg", "s6gn", "s6sg", "s6cy", "s6bl", "s6vi", "d5g2" ,"d5mg" ,"d5rg", "d5yg", "d5gg", "d5cg", "d5bg" }
501  , { "d2ma", "d2pk", "d2rd", "d2or", "d2yo", "d2ye", "d2yg", "d2gn", "d2sg", "d2cy", "d2bl", "d2vi", "d6g2" ,"d6mg" ,"d6rg", "d6yg", "d6gg", "d6cg", "d6bg" }
502  , { "g9ma", "g9pk", "g9rd", "g9or", "g9yo", "g9ye", "g9yg", "g9gn", "g9sg", "g9cy", "g9bl", "g9vi", "d7g2" ,"d7mg" ,"d7rg", "d7yg", "d7gg", "d7cg", "d7bg" }
503  , { "d4ma", "d4pk", "d4rd", "d4or", "d4yo", "d4ye", "d4yg", "d4gn", "d4sg", "d4cy", "d4bl", "d4vi", "d8g2" ,"d8mg" ,"d8rg", "d8yg", "d8gg", "d8cg", "d8bg" }
504  , { "d6ma", "d6pk", "d6rd", "d6or", "d6yo", "d6ye", "d6yg", "d6gn", "d6sg", "d6cy", "d6bl", "d6vi"} //, "p1w2" ,"p1mw" ,"p1rw", "whye", "p1gw", "p1cw", "whbl"}
505  };
506  
507  
508  
509  
510
511  
512    
513  Map<String, GralColor> idxColorsByShortname = new TreeMap<String, GralColor>();
514  
515  
516  //GralTextField[][] wdgColorBack = new GralTextField[19][10];
517
518  //String[][] shortname = new String[19][10];
519  
520  //String[][] name = new String[19][10];
521  
522  ColorWithField[][] colorF;
523  
524  
525  //final GralColor[][] colorV = new GralColor[lightSat.length][colHue.length + 7];
526  final GralColor[][] colorV = new GralColor[lightSat.length][];
527  
528  ColorWithField colorFocus, colorFocus2;
529  
530  /**Shows in the right field, else in left. */
531  boolean bRightShow;
532  
533  /**Set for 1 time if the show field is switched till foucus. */
534  boolean bNewSwitchShow;
535  
536  GralTextField wdgTest, wdgTest1, wdgTest2;
537  
538  GralTextField wdgHexValue, wdgHue, wdgSat, wdgBright, wdgHue2, wdgSat2, wdgLight2, wdgShortname, wdgName;
539  
540  boolean testText, testLine;
541  
542  GralColor colWh = GralColor.getColor("wh");  
543  GralColor colBk = GralColor.getColor("bk");
544  //GralFont fontText = GralFont.fontMonospacedSansSerif;
545  
546  
547  /**If not null, edit mode, write possible. */
548  File pathConfig;
549  
550  
551
552
553  
554  int HSBtoRGB(float hue, float saturation, float brightness) {
555    float hue1 = (hue-4) / 24;
556    if(hue1 < 0 ){ hue1 += 1.0f; }
557    return java.awt.Color.HSBtoRGB(hue1, saturation, brightness);
558  }
559  
560  void RGBtoHSB(int col2, float[] hsb){
561    java.awt.Color.RGBtoHSB((col2>>16) & 0xff, (col2>>8) & 0xff, (col2) & 0xff, hsb);
562    hsb[0] = hsb[0] * 24 +4;
563    if(hsb[0] >= 24.0f){ hsb[0] -= 24.0f; }
564  }
565  
566  
567  ColorWithField createColorField(int ixSatB, int ixHue, GralColor colorV1 ){
568    ColorWithField colorF1 = new ColorWithField(colorV1, colorV1.name, ixHue, ixSatB, colorV1.rgb());
569    colorF[ixSatB][ixHue] = colorF1;
570    setColorHSB_HLSvalues(colorF1);
571    setColorT(colorF1);
572    return colorF1;
573  }
574  
575  void genColorFrame() { 
576    int colorVal;
577    for(int ixSatB = 0; ixSatB < lightSat.length; ++ixSatB){
578      int len = colHue.length;
579      if(ixSatB < gray1Sat.length || ixSatB >= gray1Sat.length+1 && ixSatB < gray1Sat.length+1 + gray1Sat.length){
580        len += 7;
581      }
582      colorV[ixSatB] = new GralColor[len];
583      for(int ixHue = 0; ixHue < colHue.length; ++ixHue){
584        String shname = lightSat[ixSatB].lName + colHue[ixHue].colorName;
585        GralColor colorV1 = new GralColor(shname, 0xfefefe);
586        colorV[ixSatB][ixHue] = colorV1;
587        idxColorsByShortname.put(shname, colorV1);
588      }
589    }
590    for(int ixGrayTable = 0; ixGrayTable < 2; ++ixGrayTable){
591      //float[][] clinesat = ixsat ==0 ? clineSatC1 : clineSatC2;
592      for(int ixHue=0; ixHue < 7; ++ixHue){
593        for(int ixSatB = 0; ixSatB < gray1Sat.length; ++ixSatB){
594          final String shname = gray1Sat[ixSatB].lName + namesGray[ixGrayTable][ixHue];
595          int ixline = ixSatB + gray1Sat.length * ixGrayTable + ixGrayTable;
596          GralColor colorV1 = new GralColor(shname, 0xffffff);
597          colorV[ixline][colHue.length + ixHue] = colorV1;
598          idxColorsByShortname.put(shname, colorV1);
599        }
600      }
601    }
602  }
603  
604  
605  
606  
607  /**
608   * 
609   */
610  void genDefaultConfig() {
611    int colorVal;
612    for(int ixSatB = 0; ixSatB < lightSat.length; ++ixSatB){
613      for(int ixHue = 0; ixHue < colHue.length; ++ixHue){
614      //StringBuilder line = new StringBuilder(1000);
615        float b = lightSat[ixSatB].light;
616        float s = lightSat[ixSatB].sat; // * colHue[ixHue][1];
617        //if(b > 1.0f){ s -= b -1.0f; b = 1.0f; }
618        //colorVal = HSBtoRGB(colHue[ixHue][0], s, b) & 0xffffff;
619        if(ixHue == 3 && ixSatB == 1)
620          Debugutil.stop();
621        GralColor color = colorV[ixSatB][ixHue];
622        if(color.name.equals("l3rd"))   ////
623          Debugutil.stop();
624        colorVal = GralColorConv.HLStoRGB(colHue[ixHue].colorValue, b, s) & 0xffffff;
625        //String shname = lightSat[ixSatB].lName + colHue[ixHue].colorName;
626        _GralChgColor.setColorValue(color, colorVal);
627        _GralChgColor.setColorUsualNames(color, null);
628      }
629    }
630    for(int ixGrayTable = 0; ixGrayTable < 2; ++ixGrayTable){
631      for(int ixHue=0; ixHue < 7; ++ixHue){
632        for(int ixSatB = 0; ixSatB < gray1Sat.length; ++ixSatB){
633          if(ixGrayTable == 0 && ixHue == 1 && ixSatB == 5)
634            Debugutil.stop();
635          int ixline = ixSatB + gray1Sat.length * ixGrayTable + ixGrayTable;
636          float color, sat; 
637          float light = gray1Sat[ixSatB].light; //(1.0f - ((float)ixSatB) / lightSat.length * 2);
638          if(ixHue == 0) {
639            color = 4; 
640            sat = 0;
641          } else {
642            color = 4*(ixHue-1);
643            if(ixHue == 5 && ixSatB == 10)
644              Debugutil.stop();
645            //sat = CurveInterpolation.linearInterpolation(light, color, clinesat, -1);
646            if(ixGrayTable == 0) {
647              sat = gray1Sat[ixSatB].sat;  //0.06f + 0.4f * (1-light);// * (1-light);
648            } else {
649              sat = gray1Sat[ixSatB].sat2;  // 0.02f + 0.25f * (1-light);// * (1-light);
650            }
651         }
652          colorVal = GralColorConv.HLStoRGB(color, light, sat) & 0xffffff;
653          _GralChgColor.setColorValue(colorV[ixline][colHue.length + ixHue], colorVal);
654          _GralChgColor.setColorUsualNames(colorV[ixline][colHue.length + ixHue], null);
655        }
656      }
657    }
658  }
659  
660  
661  
662  
663  
664  void readConfig() throws FileNotFoundException, IOException, ParseException
665  { 
666    InputStream ins = ClassLoader.getSystemClassLoader().getResourceAsStream("org/vishia/gral/colordef.txt");
667    //BufferedReader in = new BufferedReader(new InputStreamReader(ins));
668    if(ins == null) return;
669    StringPartFromFileLines spline = new StringPartFromFileLines(ins, "org/vishia/gral/colordef.txt", 100000, null, null);
670    ins.close();
671    spline.setIgnoreWhitespaces(true);
672    if(spline.scan("@").scanOk()){
673      //it is redirected to a file:
674      spline.len0end();
675      String path = spline.getCurrentPart().toString().trim();
676      spline.close();
677      File fileConfig = new File(path);
678      if(fileConfig.exists()){
679        this.pathConfig = fileConfig;
680      } else {
681        throw new FileNotFoundException("edit mode failed, " + fileConfig.getAbsolutePath());
682      }
683      spline = new StringPartFromFileLines(fileConfig);
684    }
685    //String[] val = valTest;
686    //String[] val = valOk;
687    
688    //int zLine = Math.min(val.length, lightSat.length);
689    //int ixBright = -1;
690    boolean cont = true;
691    do {
692      spline.setIgnoreWhitespaces(true);  //for the next line.
693      if(spline.scan("colorhex").scan("=").scanOk()){}
694      else if(spline.scan("color").scan("=").scanOk()){
695        boolean ok;
696        String shname = null;
697        int cvalue;
698        GralColor colorV1 = null;
699        ok = spline.scanIdentifier().scanOk();
700        if(ok){
701          shname = spline.getLastScannedString().toString();
702          ok = spline.scan(":").scan("#").scanHex(6).scanOk();
703        }
704        if(ok) {
705          cvalue = (int)spline.getLastScannedIntegerNumber();
706          colorV1 = idxColorsByShortname.get(shname);
707          if(colorV1 == null) {
708            System.err.println("GralColor: faulty colorname = " + shname);
709          } else {
710            if(cvalue >=0){
711              _GralChgColor.setColorValue(colorV1, cvalue);
712            }
713          }
714        }
715        int check = 0;
716        while(ok && spline.scan(",").scanIdentifier(null, "-").scanOk()){
717          String name = spline.getLastScannedString().toString();
718          if(++check == 1){
719            _GralChgColor.setColorUsualNames(colorV1, name);
720          }
721        }
722      }
723      else if( spline.scanHex(6).scanOk()) {
724        //for(int ixCol=0; ixCol<val.length; ++ixCol) {
725        GralColor colText;
726        //if(ixBright < 11){ colText = colBk; }
727        //else { colText = colWh; }
728        int col2;
729        spline.setIgnoreWhitespaces(true);
730        spline.scanOk();
731        try{ 
732          //spline.scanHex(6); 
733          col2 = (int) spline.getLastScannedIntegerNumber();
734        } catch(ParseException exc){ col2 = 0xffffff; }
735        GralColor col3 = GralColor.getColor(col2);
736        spline.setIgnoreWhitespaces(false);
737        spline.scanSkipSpace().scanOk();
738        final String shortname;
739        if(spline.scan(":").scanIdentifier().scanOk()){
740          shortname = spline.getLastScannedString().toString();   
741        } else {
742          spline.scan(":").scanOk();  //read ':'
743          shortname = "";
744        }
745        boolean marked = spline.scan("+").scanOk();
746        GralColor colorV1 = idxColorsByShortname.get(shortname);
747        if(colorV1 !=null) {
748          if(marked){
749            //marked.
750            _GralChgColor.setColorValue(colorV1,col2);
751          }
752        } else {
753          System.err.println("GralColor - color not found, " + shortname);
754        }
755        
756      }
757      else {
758        cont = false;
759      }
760    } while(cont);
761    spline.close();
762  }
763  
764 
765  
766  void refreshColorFields()
767  {
768    for(int ixLine = 0; ixLine < colorF.length; ++ixLine){
769      for(int col = 0; col < colorF[ixLine].length; ++col){
770        ColorWithField field = colorF[ixLine][col];
771        field.wdgColor.setBackColor(colorF[ixLine][col].co,0);
772        String text = "";
773        if(field.co.usualNames() !=null && field.co.usualNames().length() >0) {
774          text = "-";
775        }
776        field.wdgColor.setText(text);
777      }
778    }
779  }
780  
781  
782  
783  void outColors(){
784    if(pathConfig ==null) return;
785    try{ 
786      Writer out = new FileWriter(pathConfig);
787      for(int line=9990; line < colorF.length; ++line) {
788        String spaces = "            ";
789        out.append("colorhex = ");
790        for(int col = 0; col < colorF[line].length; ++col){
791          ColorWithField colorF1 = colorF[line][col];
792          //String sVal = colorF1.wdgColor.getText();
793          GralColor color = colorF1.wdgColor.getBackColor(0);
794          int colValue = color.getColorValue();
795          String sHex = String.format("%06X", colValue);
796          out.append(sHex).append(':').append(colorF1.co.name);
797          if(colorF1.co.usualNames() !=null && colorF1.co.usualNames().trim().length()>0){
798            out.append('+');
799          } else {
800            out.append(' ');
801          }
802          int zspaces = 5 - colorF1.co.name.length();
803          if(zspaces < 1){ zspaces = 1; }
804          out.append(spaces.substring(0, zspaces));
805        }
806        out.append("\"\n");
807      }
808      out.append("\n\n");
809    
810      for(int line=0; line<colorF.length; ++line) {
811        for(int col = 0; col < colorF[line].length; ++col){
812          String usualNames = colorF[line][col].co.usualNames();
813          if(usualNames !=null && usualNames.length()>0) {
814            GralColor color = colorF[line][col].wdgColor.getBackColor(0);
815            int colValue = color.getColorValue();
816            String sHex = String.format("%06X", colValue);
817            out.append("color = ")
818            .append(colorF[line][col].co.name)
819            .append(": #").append(sHex)
820            .append(", ")
821            .append(usualNames)
822            .append("\n");
823          }
824        }
825      }
826      out.close();
827    } catch(IOException exc){
828      System.err.println(exc.getMessage());
829    }
830  }
831
832
833  void setColorHSB_HLSvalues(ColorWithField colorF1){
834    int col2 = colorF1.co.rgb();
835    RGBtoHSB(col2, colorF1.hsb);
836    GralColorConv.RGBtoHLS(col2, colorF1.hls);
837    //colorF1.color = GralColor.getColor(colorF1.rgb);
838    //colorF1.wdgColor.setBackColor(colorF1.color, 0);
839  }
840        
841  
842  void processHSBinput() {
843    ColorWithField colorF2 = bRightShow ? colorFocus2 : colorFocus;
844    int rgb = colorF2.co.rgb();
845    int rgb2 = HSBtoRGB(colorF2.hsb[0], colorF2.hsb[1], colorF2.hsb[2]) & 0xffffff;
846    if(rgb != rgb2){
847      _GralChgColor.setColorValue(colorF2.co, rgb2);
848      setColorHSB_HLSvalues(colorF2);
849      setColorT(colorF2);
850      setColorEditFields(bRightShow ? 2 : 1);
851    }
852  }
853
854  
855  /**Sets the color of the cell with the given HSB values, maybe changed in the cell.
856   * @param colorF1 The cell.
857   */
858  void setColorFromHSB(ColorWithField colorF1) {
859    _GralChgColor.setColorValue(colorF1.co, HSBtoRGB(colorF1.hsb[0], colorF1.hsb[1], colorF1.hsb[2]) & 0xffffff);
860    GralColorConv.RGBtoHLS(colorF1.co.rgb(), colorF1.hls);
861    /*    String sHex = String.format("%06X", colorF1.rgb);
862    wdgHexValue.setText(sHex);
863    colorF1.color = GralColor.getColor(colorF1.rgb);
864    colorF1.wdgColor.setBackColor(colorF1.color, 0);
865*/  }
866
867
868  void setColorFromHSL(ColorWithField colorF1) {
869    _GralChgColor.setColorValue(colorF1.co, GralColorConv.HLStoRGB(colorF1.hls[0], colorF1.hls[1], colorF1.hls[1]) & 0xffffff);
870    RGBtoHSB(colorF1.co.rgb(), colorF1.hsb);
871    /*   String sHex = String.format("%06X", colorF1.rgb);
872    wdgHexValue.setText(sHex);
873    colorF1.color = GralColor.getColor(colorF1.rgb);
874    colorF1.wdgColor.setBackColor(colorF1.color, 0);
875 */ }
876
877  
878  
879  void setColorEditFields(int nr) {
880    ColorWithField colorF1 = nr == 2 ? colorFocus2 : colorFocus;
881    String sHex = String.format("%06X", colorF1.co.rgb());
882    wdgHexValue.setText(sHex); //Integer.toHexString(colValue));
883    wdgShortname.setText(colorF1.co.name);
884    String usualNames = colorF1.co.usualNames();
885    if(usualNames ==null) { usualNames = ""; }
886    wdgName.setText(usualNames);
887    if(colorF1.co.name.length()>0){
888      //colorF1.wdgColor.setText(colorF1.name);
889    }
890    float hue1 = colorF1.hsb[0]; //24 * colorF1.hsb[0] +4;
891    //if(hue1 >= 24.0f){ hue1 -= 24; }
892    wdgHue.setText(""+hue1);
893    wdgSat.setText(""+colorF1.hsb[1]);
894    wdgBright.setText(""+colorF1.hsb[2]);
895    float col2 = 24 * colorF1.hls[0] +4;
896    if(col2 >=24.0f) col2 -= 24.0f;
897    //wdgHue2.setText(""+colorF1.hls[0]);
898    
899    
900    //int l2 = (int)((colorF1.co.red + colorF1.co.green / 1.6f + colorF1.co.blue * 1.0f) /3);
901    int l2 = (int)((colorF1.co.red + colorF1.co.green * 1.5f + colorF1.co.blue / 1.2f) /3);
902    String sl2 = String.format("%02X", l2);
903    wdgHue2.setText(sl2);
904    
905    wdgSat2.setText(""+colorF1.hls[2]);
906    wdgLight2.setText(""+colorF1.hls[1]);
907    GralColor color = GralColor.getColor(colorF1.co.rgb());
908    if(nr == 1){ wdgTest = wdgTest1; }
909    else if(nr == 2){ wdgTest = wdgTest2; }
910    if(testText) {
911      wdgTest.setTextColor(color);
912      wdgTest.setLineColor(color, 0);
913    } else {
914      wdgTest.setBackColor(color,0);
915    }
916        
917  }      
918
919  
920  void setFocusColor(ColorWithField field)
921  { colorFocus.wdgColor.setBorderWidth(0);
922    colorFocus = field; 
923    colorFocus.wdgColor.setBorderWidth(3);
924    setColorHSB_HLSvalues(colorFocus);
925    setColorEditFields(1);
926 
927  }
928  
929  
930  void setFocusColor2(ColorWithField field)
931  { colorFocus2.wdgColor.setBorderWidth(0);
932    colorFocus2 = field; 
933    colorFocus2.wdgColor.setBorderWidth(3);
934    setColorHSB_HLSvalues(colorFocus2);
935    setColorEditFields(2);
936 
937  }
938  
939  
940  
941  void setColorT(ColorWithField colorF1) {
942    //colorF1.co.color = GralColor.getColor(colorF1.co.rgb());
943    
944    colorF1.wdgColor.setBackColor(colorF[0][0].co, 0);
945    colorF1.wdgColor.setBackColor(colorF1.co, 0);
946    String usualNames = colorF1.co.usualNames();
947    if(usualNames !=null && usualNames.length()>0) {
948      colorF1.wdgColor.setText("x");
949    } else {
950      colorF1.wdgColor.setText("");
951    }
952  }
953
954  GralGraphicTimeOrder initGraphicFullColors = new GralGraphicTimeOrder("GralArea9Window.initGraphic"){
955    @Override public void executeOrder()
956    {
957      //gralMng.addTextField();
958      //colorF = new ColorWithField[lightSat.length][colHue.length + 7];
959      colorF = new ColorWithField[lightSat.length][];
960      ColorWithField colorF1 = null;
961      for(int ixRow = 0; ixRow < lightSat.length; ++ixRow){ //cells in columns, vertical
962        LightSat ls = lightSat[ixRow];
963        String text = ls.lName; //String.format("%s %1.1f,%1.1f", ls.lName, ls.light, ls.sat);
964        gralMng.setPosition(6+3*ixRow, GralPos.size -2, 0, GralPos.size+2, 0, 'd', 0);
965        GralLabel label = new GralLabel(null, text,0);
966        label.createImplWidget_Gthread();
967      }
968      for(int ixCol=0; ixCol<colHue.length; ++ixCol) { //the column, for horizontal
969        String nameShow;
970        nameShow = colHue[ixCol].colorName;
971        gralMng.setPosition(2.5f, GralPos.size -2, 4*ixCol +3, GralPos.size+4, 0, 'd', 0);
972        GralLabel label = new GralLabel(null, nameShow,0);
973        label.createImplWidget_Gthread();
974      }
975      gralMng.setPosition(2.5f, GralPos.size -2, 4 + 4 * colHue.length, GralPos.size+4, 0, 'r', 0);
976      for(int ixCol=0; ixCol<namesGray[0].length; ++ixCol) { //the column, for horizontal
977        String nameShow;
978        nameShow = namesGray[0][ixCol];
979        GralLabel label = new GralLabel(null, nameShow,0);
980        label.createImplWidget_Gthread();
981      }
982      gralMng.setPosition(5.5f + 3* gray1Sat.length , GralPos.size -2, 4 + 4 * colHue.length, GralPos.size+4, 0, 'r', 0);
983      for(int ixCol=0; ixCol<namesGray[1].length; ++ixCol) { //the column, for horizontal
984        String nameShow;
985        nameShow = namesGray[1][ixCol];
986        GralLabel label = new GralLabel(null, nameShow,0);
987        label.createImplWidget_Gthread();
988      }
989      for(int ixRow = 0; ixRow < colorF.length; ++ixRow){ //cells in columns, vertical
990        
991        colorF[ixRow] = new ColorWithField[colorV[ixRow].length];
992        gralMng.setPosition(6 + 3 * ixRow, GralPos.size -3, 2, GralPos.size+4, 0, 'r', 0);
993        //gralMng.setPosition(3, GralPos.size -2, 9*col, GralPos.size+8, 0, 'd', 1);
994        //out.append(", \"");
995        //int pline = 0;
996        for(int ixCol=0; ixCol < colorF[ixRow].length; ++ixCol) { //the column, for horizontal
997          
998          GralColor colText;
999          if(ixRow < 11){ colText = colBk; }
1000          else { colText = colWh; }
1001          GralColor colorV2 = colorV[ixRow][ixCol];
1002          if(colorV2 !=null) {
1003            colorF1 = createColorField(ixRow, ixCol, colorV2);
1004            //colorF1 = colorF[ixRow][ixCol];
1005            if(colorF1 !=null) {
1006              colorF1.wdgColor.createImplWidget_Gthread();
1007              colorF1.bActive = true;
1008              colorF1.wdgColor.setTextColor(colText);
1009              if(colorF1.co.usualNames() !=null && colorF1.co.usualNames().length() >0) {
1010                colorF1.wdgColor.setText("x");
1011              }
1012            }
1013          }
1014        }
1015      }
1016      colorFocus = colorF[0][0];
1017      colorFocus2 = colorF[0][1];
1018      
1019      gralMng.setPosition(4 + 3 * colorV.length /*GralPos.refer+4*/, GralPos.size +10, 1, GralPos.size+15, 0, 'r');
1020      //
1021      wdgTest1 = new GralTextField("test1");
1022      wdgTest2 = new GralTextField("test2");
1023      wdgTest1.setEditable(true);
1024      wdgTest2.setEditable(true);
1025      wdgTest1.setActionFocused(actionFocusedTest);
1026      wdgTest2.setActionFocused(actionFocusedTest);
1027      wdgTest1.setToPanel(gralMng);
1028      wdgTest2.setToPanel(gralMng);
1029      wdgTest1.setText("ABC");
1030      wdgTest2.setText("XYZ");
1031      wdgTest = wdgTest1;
1032      
1033      gralMng.setPosition(GralPos.refer, GralPos.size +2, 40, GralPos.size+10, 0, 'r');
1034      wdgHexValue = new GralTextField("hex");
1035      wdgHexValue.setEditable(true);
1036      wdgHexValue.setActionChange(actionEnterHex);
1037      wdgHexValue.setToPanel(gralMng);
1038      wdgShortname = new GralTextField("sname");
1039      wdgShortname.setEditable(true);
1040      wdgShortname.setActionChange(actionEnterShortname);
1041      wdgShortname.setToPanel(gralMng);
1042      gralMng.setPosition(GralPos.refer +3, GralPos.size +2, 40, GralPos.size+20, 0, 'r');
1043      wdgName = new GralTextField("name");
1044      wdgName.setEditable(true);
1045      wdgName.setActionChange(actionEnterName);
1046      wdgName.setToPanel(gralMng);
1047      gralMng.setPosition(GralPos.refer +3, GralPos.size +2, 40, GralPos.size+12, 0, 'r',1);
1048      wdgHue = new GralTextField("name");
1049      wdgHue.setEditable(true);
1050      wdgHue.setActionChange(new ActionEnterHSB(0));
1051      wdgHue.setToPanel(gralMng);
1052      wdgBright = new GralTextField("name");
1053      wdgBright.setEditable(true);
1054      wdgBright.setActionChange(new ActionEnterHSB(2));
1055      wdgBright.setToPanel(gralMng);
1056      wdgSat = new GralTextField("name");
1057      wdgSat.setEditable(true);
1058      wdgSat.setActionChange(new ActionEnterHSB(1));
1059      wdgSat.setToPanel(gralMng);
1060      gralMng.setPosition(GralPos.refer +3, GralPos.size +2, 40, GralPos.size+12, 0, 'r',1);
1061      wdgHue2 = new GralTextField("name");
1062      wdgHue2.setEditable(true);
1063      wdgHue2.setActionChange(new ActionEnterHLS(0));
1064      wdgHue2.setToPanel(gralMng);
1065      wdgLight2 = new GralTextField("name");
1066      wdgLight2.setEditable(true);
1067      wdgLight2.setActionChange(new ActionEnterHLS(1));
1068      wdgLight2.setToPanel(gralMng);
1069      wdgSat2 = new GralTextField("name");
1070      wdgSat2.setEditable(true);
1071      wdgSat2.setActionChange(new ActionEnterHLS(2));
1072      wdgSat2.setToPanel(gralMng);
1073   } };
1074  
1075  
1076  
1077  GralGraphicTimeOrder initGraphicLessColors = new GralGraphicTimeOrder("initGraphicLessColors"){
1078    @Override public void executeOrder()
1079    {
1080      String[][] colors = colors4;
1081      colorF = new ColorWithField[colors.length][];
1082      gralMng.setPosition(4, -2, 2, -2, 0, 'd');
1083      for(int ixRow = 0; ixRow < colors.length; ++ixRow){ //fill cells of columns.
1084        colorF[ixRow] = new ColorWithField[colors[ixRow].length];
1085        gralMng.setPosition(4 + 3*ixRow, GralPos.size -3, 1, GralPos.size+4, 0, 'r', 0);
1086        //gralMng.setPosition(3, GralPos.size -2, 9*col, GralPos.size+8, 0, 'd', 1);
1087        ColorWithField colorF1 = null;
1088        for(int ixCol=0; ixCol<colors[ixRow].length; ++ixCol) { //create columns
1089          GralColor colText;
1090          String shname = colors[ixRow][ixCol];
1091          GralColor colorV1 = idxColorsByShortname.get(shname);
1092          if(colorV1 == null) { colorV1 = colorV[0][0]; }
1093          colorF1 = createColorField(ixRow, ixCol, colorV1);
1094          //colorF1 = colorF[ixRow][ixCol];
1095          if(colorF1 !=null) {
1096            colorF1.wdgColor.createImplWidget_Gthread();
1097            colorF1.bActive = true;
1098            if(colorF1.co.usualNames() !=null && colorF1.co.usualNames().length() >0) {
1099              colorF1.wdgColor.setText("x");
1100            }
1101          }
1102        }
1103      }
1104      colorFocus = colorF[0][0];
1105      colorFocus2 = colorF[0][1];
1106      
1107      gralMng.setPosition(GralPos.refer+4, GralPos.size +10, 1, GralPos.size+15, 0, 'r');
1108      //
1109      wdgTest1 = new GralTextField("test1");
1110      wdgTest2 = new GralTextField("test2");
1111      wdgTest1.setEditable(true);
1112      wdgTest2.setEditable(true);
1113      wdgTest1.setActionFocused(actionFocusedTest);
1114      wdgTest2.setActionFocused(actionFocusedTest);
1115      wdgTest1.setToPanel(gralMng);
1116      wdgTest2.setToPanel(gralMng);
1117      wdgTest1.setText("ABC");
1118      wdgTest2.setText("XYZ");
1119      wdgTest = wdgTest1;
1120      
1121      gralMng.setPosition(GralPos.refer, GralPos.size +2, 40, GralPos.size+10, 0, 'r');
1122      wdgHexValue = new GralTextField("hex");
1123      wdgHexValue.setEditable(true);
1124      wdgHexValue.setActionChange(actionEnterHex);
1125      wdgHexValue.setToPanel(gralMng);
1126      wdgShortname = new GralTextField("sname");
1127      wdgShortname.setEditable(true);
1128      wdgShortname.setActionChange(actionEnterShortname);
1129      wdgShortname.setToPanel(gralMng);
1130      gralMng.setPosition(GralPos.refer +3, GralPos.size +2, 40, GralPos.size+20, 0, 'r');
1131      wdgName = new GralTextField("name");
1132      wdgName.setEditable(true);
1133      wdgName.setActionChange(actionEnterName);
1134      wdgName.setToPanel(gralMng);
1135      gralMng.setPosition(GralPos.refer +3, GralPos.size +2, 40, GralPos.size+12, 0, 'r',1);
1136      wdgHue = new GralTextField("name");
1137      wdgHue.setEditable(true);
1138      wdgHue.setActionChange(new ActionEnterHSB(0));
1139      wdgHue.setToPanel(gralMng);
1140      wdgBright = new GralTextField("name");
1141      wdgBright.setEditable(true);
1142      wdgBright.setActionChange(new ActionEnterHSB(2));
1143      wdgBright.setToPanel(gralMng);
1144      wdgSat = new GralTextField("name");
1145      wdgSat.setEditable(true);
1146      wdgSat.setActionChange(new ActionEnterHSB(1));
1147      wdgSat.setToPanel(gralMng);
1148      gralMng.setPosition(GralPos.refer +3, GralPos.size +2, 40, GralPos.size+12, 0, 'r',1);
1149      wdgHue2 = new GralTextField("name");
1150      wdgHue2.setEditable(true);
1151      wdgHue2.setActionChange(new ActionEnterHLS(0));
1152      wdgHue2.setToPanel(gralMng);
1153      wdgLight2 = new GralTextField("name");
1154      wdgLight2.setEditable(true);
1155      wdgLight2.setActionChange(new ActionEnterHLS(1));
1156      wdgLight2.setToPanel(gralMng);
1157      wdgSat2 = new GralTextField("name");
1158      wdgSat2.setEditable(true);
1159      wdgSat2.setActionChange(new ActionEnterHLS(2));
1160      wdgSat2.setToPanel(gralMng);
1161   } };
1162  
1163  
1164  
1165  GralUserAction XXXactionFocusColor = new GralUserAction("focus color"){
1166    @Override public boolean exec(int key, GralWidget_ifc widgP, Object... params)
1167    {
1168      if(key == (KeyCode.focusGained)){
1169        GralTextField wdg = (GralTextField)widgP;
1170        if(colorFocus !=null) {
1171          //if(colorFocus != colorFocus1 || colorFocus != colorFocus2) {
1172          if(bNewSwitchShow){
1173            bNewSwitchShow = false; 
1174          } else { 
1175            colorFocus.wdgColor.setBorderWidth(0);
1176            colorFocus = (ColorWithField)widgP.getData();
1177            colorFocus.wdgColor.setBorderWidth(3);
1178            setColorHSB_HLSvalues(colorFocus);
1179            setColorEditFields(0);
1180          }
1181          System.out.println("focus");
1182        }
1183      }
1184      return true;
1185  } };
1186  
1187  
1188  
1189  GralUserAction XXXactionMouseColor = new GralUserAction("MouseColor"){
1190    @Override public boolean exec(int key, GralWidget_ifc widgP, Object... params)
1191    {
1192      if(key == (KeyCode.mouse2Up)){
1193        GralTextField wdg = (GralTextField)widgP;
1194        colorFocus.wdgColor.setBorderWidth(0);
1195        colorFocus = (ColorWithField)widgP.getData();
1196        colorFocus.wdgColor.setBorderWidth(3);
1197        //int colValue = color.getColorValue();
1198        setColorHSB_HLSvalues(colorFocus);
1199        setColorEditFields(0);
1200      }
1201      return true;
1202  } };
1203  
1204  
1205  
1206  GralUserAction actionEditColor = new GralUserAction("edit color"){
1207    @Override public boolean exec(int key, GralWidget_ifc widgP, Object... params)
1208    {
1209      ColorWithField colorFs = bRightShow ? colorFocus2 : colorFocus;
1210    
1211      GralTextField wdg = (GralTextField)widgP;
1212      if(key == KeyCode.right) {
1213        int ixRow = colorFocus.index.ixLight;
1214        int ixCol = colorFocus.index.ixCol;
1215        int ctw = 100;
1216        do { if(++ixCol >= colorF[ixRow].length){ ixCol = 0;}
1217        } while(--ctw >=0 && !colorF[ixRow][ixCol].bActive);
1218        ColorWithField newField = colorF[ixRow][ixCol];
1219        newField.wdgColor.setFocus();
1220        setFocusColor(newField);
1221      } else if(key == KeyCode.shift + KeyCode.right) {
1222        int ixRow = colorFocus2.index.ixLight;
1223        int ixCol = colorFocus2.index.ixCol;
1224        int ctw = 100;
1225        do { if(++ixCol >= colorF[0].length){ ixCol = 0;}
1226        } while(--ctw >=0 && !colorF[ixRow][ixCol].bActive);
1227        if(ixCol >= colorF[0].length) { ixCol = 0; } //first is active.
1228        ColorWithField newField = colorF[ixRow][ixCol];
1229        newField.wdgColor.setFocus();
1230        setFocusColor2(newField);
1231      } else if(key == KeyCode.left){ 
1232        int ixRow = colorFocus.index.ixLight;
1233        int ixCol = colorFocus.index.ixCol;
1234        int ctw = 100;
1235        if(--ixCol <0){  ixCol = colorF[ixRow].length -1; }
1236        //} while(--ctw >= 0 && !colorF[ixRow][ixCol].bActive);
1237        ColorWithField newField = colorF[ixRow][ixCol];
1238        newField.wdgColor.setFocus();
1239        setFocusColor(newField);
1240      } else if(key == KeyCode.shift + KeyCode.left){ 
1241        int ixRow = colorFocus2.index.ixLight;
1242        int ixCol = colorFocus2.index.ixCol;
1243        int ctw = 100;
1244        do { if(--ixCol <0){  ixCol = colorF[0].length -1; }
1245        } while(--ctw >= 0 && !colorF[ixRow][ixCol].bActive);
1246        ColorWithField newField = colorF[ixRow][ixCol];
1247        newField.wdgColor.setFocus();
1248        setFocusColor2(newField);
1249      } else if(key == KeyCode.up && colorFocus.index.ixLight > 0){ 
1250        int ixRow = colorFocus.index.ixLight;
1251        int ixCol = colorFocus.index.ixCol;
1252        ixRow -=1;
1253        if(ixCol >= colorF[ixRow].length) { ixRow -=1; } //skip over title on gray table
1254        ColorWithField newField = colorF[ixRow][ixCol];
1255        newField.wdgColor.setFocus();
1256        setFocusColor(newField);
1257      } else if(key == KeyCode.shift + KeyCode.up && colorFocus2.index.ixLight > 0){ 
1258        int ixRow = colorFocus2.index.ixLight;
1259        int ixCol = colorFocus2.index.ixCol;
1260        int ctw = 100;
1261        do { if(--ixRow <0){  ixRow = colorF.length -1; }
1262        } while(--ctw >= 0 && !colorF[ixRow][ixCol].bActive);
1263        ColorWithField newField = colorF[ixRow][ixCol];
1264        newField.wdgColor.setFocus();
1265        setFocusColor2(newField);
1266      } else if(key == KeyCode.dn && colorFocus.index.ixLight < colorF.length -1){ 
1267        int ixRow = colorFocus.index.ixLight;
1268        int ixCol = colorFocus.index.ixCol;
1269        ixRow +=1;
1270        while(ixRow < colorF.length && ixCol >= colorF[ixRow].length) { ixRow +=1; } //skip over title on gray table
1271        if(ixRow < colorF.length){ 
1272          ColorWithField newField = colorF[ixRow][ixCol];
1273          newField.wdgColor.setFocus();
1274          setFocusColor(newField);
1275        }
1276      } else if(key == KeyCode.shift + KeyCode.dn && colorFocus2.index.ixLight < colorF.length -1){ 
1277        int ixRow = colorFocus2.index.ixLight;
1278        int ixCol = colorFocus2.index.ixCol;
1279        int ctw = 100;
1280        do { if(++ixRow >=colorF.length){  ixRow = 0; }
1281        } while(--ctw >= 0 && !colorF[ixRow][ixCol].bActive);
1282        if(ctw >= 0){
1283          ColorWithField newField = colorF[ixRow][ixCol];
1284          newField.wdgColor.setFocus();
1285          setFocusColor2(newField);
1286        }
1287      } else if(key == KeyCode.mouse2Down) {
1288        ColorWithField colorF2 = (ColorWithField)widgP.getData();
1289        _GralChgColor.setColorValue(colorF2.co, colorFocus.co.rgb());  //copy from last focused.
1290        colorF2.wdgColor.setBackColor(colorFocus.wdgColor.getBackColor(0),0);
1291        setColorHSB_HLSvalues(colorF2);
1292        //setFocusColor(wdg);
1293      } else if(key == KeyCode.mouse1Down) {
1294        ColorWithField colorF2 = (ColorWithField)widgP.getData();
1295        setColorHSB_HLSvalues(colorF2);
1296        setColorT(colorFocus);
1297        setColorEditFields(1);
1298        bNewSwitchShow = true;
1299        System.out.println("mouse down");
1300        bRightShow = false;
1301        setFocusColor(colorF2);
1302      } else if(key == KeyCode.mouse1Down + KeyCode.shift) {
1303        ColorWithField colorF2 = (ColorWithField)widgP.getData();
1304        setColorHSB_HLSvalues(colorF2);
1305        setColorT(colorFocus);
1306        bNewSwitchShow = true;
1307        setColorEditFields(2);
1308        System.out.println("mouse sh down");
1309        bRightShow = true;
1310        setFocusColor2(colorF2);
1311      } else if(key == KeyCode.mouse1Down + KeyCode.shift + KeyCode.ctrl) {
1312        ColorWithField colorF2 = (ColorWithField)widgP.getData();
1313        int rgb2 = colorF2.co.rgb();
1314        String usualNames2 = colorF2.co.usualNames();
1315        String usualNames = colorFocus.co.usualNames();
1316        int rgb = colorFocus.co.rgb();
1317        _GralChgColor.setColorValue(colorF2.co, rgb);
1318        _GralChgColor.setColorUsualNames(colorF2.co, usualNames);
1319        _GralChgColor.setColorValue(colorFocus.co, rgb2);
1320        _GralChgColor.setColorUsualNames(colorFocus.co, usualNames2);
1321        setColorHSB_HLSvalues(colorF2);
1322        setColorT(colorF2);
1323        setColorHSB_HLSvalues(colorFocus);
1324        setColorT(colorFocus);
1325        bNewSwitchShow = true;
1326        setColorEditFields(2);
1327        bRightShow = true;
1328        setFocusColor2(colorF2);
1329      } else if(key == 'R'){
1330        int rd = (colorFocus.co.rgb() >>16) & 0xff;
1331        if(rd <255) rd +=1;
1332        _GralChgColor.setColorValue(colorFocus.co, (colorFocus.co.rgb() & 0x00ffff) | rd <<16);
1333        setColorHSB_HLSvalues(colorFocus);
1334        setColorT(colorFocus);
1335        setColorEditFields(0);
1336      } else if(key == ('r')){
1337        int rd = (colorFocus.co.rgb() >>16) & 0xff;
1338        if(rd >0) rd -=1;
1339        _GralChgColor.setColorValue(colorFocus.co, (colorFocus.co.rgb() & 0x00ffff) | rd <<16);
1340        setColorHSB_HLSvalues(colorFocus);
1341        setColorT(colorFocus);
1342        setColorEditFields(0);
1343      } else if(key == ('G')){
1344        int gn = (colorFocus.co.rgb() >>8) & 0xff;
1345        if(gn <255) gn +=1;
1346        _GralChgColor.setColorValue(colorFocus.co, (colorFocus.co.rgb() & 0xff00ff) | gn <<8);
1347        setColorHSB_HLSvalues(colorFocus);
1348        setColorT(colorFocus);
1349        setColorEditFields(0);
1350      } else if(key == ('g')){
1351        int gn = (colorFocus.co.rgb() >>8) & 0xff;
1352        if(gn >0) gn -=1;
1353        _GralChgColor.setColorValue(colorFocus.co, (colorFocus.co.rgb() & 0xff00ff) | gn <<8);
1354        setColorHSB_HLSvalues(colorFocus);
1355        setColorT(colorFocus);
1356        setColorEditFields(0);
1357      } else if(key == ('B')){  //key of a notebook: 
1358        int bl = (colorFocus.co.rgb()) & 0xff;
1359        if(bl <255) bl +=1;
1360        _GralChgColor.setColorValue(colorFocus.co, (colorFocus.co.rgb() & 0xffff00) | bl);
1361        setColorHSB_HLSvalues(colorFocus);
1362        setColorT(colorFocus);
1363        setColorEditFields(0);
1364      } else if(key == ('b')){
1365        int bl = (colorFocus.co.rgb()) & 0xff;
1366        if(bl >0) bl -=1;
1367        _GralChgColor.setColorValue(colorFocus.co, (colorFocus.co.rgb() & 0xffff00) | bl);
1368        setColorHSB_HLSvalues(colorFocus);
1369        setColorT(colorFocus);
1370        setColorEditFields(0);
1371      } else if(key == ('H')){
1372        float val = colorFs.hsb[0] + 0.125f;
1373        if(val >= 24){ val = 0.0f; }
1374        colorFs.hsb[0] = val;
1375        processHSBinput();
1376        colorFs.hsb[0] = val;
1377      } else if(key == ('h')){
1378        float val = colorFs.hsb[0] - 0.125f;
1379        if(val <0 ){ val += 24.0f; }
1380        colorFs.hsb[0] = val;
1381        processHSBinput();
1382        colorFs.hsb[0] = val;
1383      } else if(key == ('J')){
1384        float light = colorFs.hsb[2] + 0.005f;
1385        if(light > 1){ light = 1.0f; }
1386        colorFs.hsb[2] = light;
1387        processHSBinput();
1388      } else if(key == ('j')){
1389        float light = colorFs.hsb[2] - 0.005f;
1390        if(light < 0){ light = 0.0f; }
1391        colorFs.hsb[2] = light;
1392        processHSBinput();
1393      } else if(key == ('K')){
1394        float val = colorFs.hsb[1] + 0.005f;
1395        if(val > 1){ val = 1.0f; }
1396        colorFs.hsb[1] = val;
1397        processHSBinput();
1398        colorFs.hsb[1] = val;
1399      } else if(key == ('k')){
1400        float val = colorFs.hsb[1] - 0.005f;
1401        if(val > 1){ val = 1.0f; }
1402        colorFs.hsb[1] = val;
1403        processHSBinput();
1404        colorFs.hsb[1] = val;
1405      } else if(key == KeyCode.ctrl + ('x')){
1406        genDefaultConfig();
1407        refreshColorFields();
1408      } else if(key == KeyCode.ctrl +('y')){
1409        try {
1410          readConfig();
1411        } catch (IOException e1) {
1412          System.err.println("GralColor - config file error, " + e1.getMessage());
1413        } catch(ParseException exc) {
1414          System.err.println("GralColor - cannot read config, " + exc.getMessage());
1415        }
1416        refreshColorFields();
1417      } else if(key == KeyCode.enter){
1418        setColorHSB_HLSvalues(colorFocus);
1419      } else if(key == (KeyCode.focusGained)){ //only if it is an edit field
1420        //actionFocusColor.exec(key, widgP);
1421      } else if(key == (KeyCode.enter + KeyCode.ctrl) || key == ('s' + KeyCode.ctrl) || key == ('S' + KeyCode.ctrl)){
1422        outColors();
1423      }
1424      return true;
1425    }
1426  };
1427  
1428
1429  
1430  
1431  
1432    GralUserAction actionEnterHex = new GralUserAction("actionEnterHex"){
1433    @Override public boolean exec(int actionCode, GralWidget_ifc widg, Object... params) {
1434      if(actionCode == KeyCode.enter || actionCode == KeyCode.focusLost){
1435        GralTextField widgt = (GralTextField)widg;
1436        String text = widgt.getText();
1437        try{ 
1438          _GralChgColor.setColorValue(colorFocus.co, Integer.parseInt(text, 16));
1439          setColorHSB_HLSvalues(colorFocus);
1440          //GralColor colorBack = GralColor.getColor(colorFocus.co.rgb());
1441          //colorFocus.co.color = colorBack;
1442          colorFocus.wdgColor.setBackColor(colorFocus.co, 0); 
1443        } catch(NumberFormatException exc){
1444          System.out.println(exc.getMessage());
1445        }
1446      }
1447      return true;      
1448  } };
1449
1450  GralUserAction actionEnterShortname = new GralUserAction("actionEnterShortname"){
1451    @Override public boolean exec(int actionCode, GralWidget_ifc widg, Object... params) {
1452      if(actionCode == KeyCode.enter || actionCode == KeyCode.focusLost){
1453        GralTextField widgt = (GralTextField)widg;
1454        String text = widgt.getText().trim();
1455        if(!text.equals(colorFocus.co.name)) {
1456          GralColor oldColor = colorFocus.co;
1457          colorFocus.co = new GralColor(text, oldColor.rgb());
1458          idxColorsByShortname.remove(oldColor.name);
1459          String usualNames = oldColor.usualNames();
1460          _GralChgColor.setColorUsualNames(colorFocus.co, usualNames);
1461          if(usualNames!=null && usualNames.length() >0) {
1462            //remove given shortname 
1463            //idxColorsByShortname.remove(usualNames);
1464          }
1465          
1466          //_GralChgColor.setColorUsualNames(colorFocus.co, text.trim());
1467          idxColorsByShortname.put(colorFocus.co.name, colorFocus.co);
1468        }
1469      }
1470      return true;      
1471  } };
1472
1473  GralUserAction actionEnterName = new GralUserAction("actionEnterName"){
1474    @Override public boolean exec(int actionCode, GralWidget_ifc widg, Object... params) {
1475      if(actionCode == KeyCode.enter || actionCode == KeyCode.focusLost){
1476        GralTextField widgt = (GralTextField)widg;
1477        String text = widgt.getText();
1478        _GralChgColor.setColorUsualNames(colorFocus.co, text.trim());
1479      }
1480      return true;      
1481  } };
1482
1483  
1484  GralUserAction XXXactionEnterHue = new GralUserAction("actionEnterHue") {
1485    @Override public boolean exec(int actionCode, GralWidget_ifc widg, Object... params) {
1486      if(actionCode == KeyCode.enter || actionCode == KeyCode.focusLost){
1487        GralTextField widgt = (GralTextField)widg;
1488        String text = widgt.getText();
1489        float hue;
1490        try{
1491          hue = Float.parseFloat(text.trim());
1492          if(hue > 1.0f){ hue = 1.0f; }
1493          if(hue < 0.0f){ hue = 0.0f; }
1494        } catch(NumberFormatException exc){ hue = 0; }  //red
1495        colorFocus.hsb[0] = hue;
1496        setColorFromHSB(colorFocus);
1497      }
1498      return true;      
1499  } };
1500
1501  
1502  
1503  
1504  class ActionEnterHSB extends GralUserAction {
1505    final int indexHSB;
1506    ActionEnterHSB(int indexHSB){
1507      super("actionEnterHSB" + indexHSB);
1508      this.indexHSB = indexHSB;
1509    }
1510      
1511    @Override public boolean exec(int actionCode, GralWidget_ifc widg, Object... params) {
1512      if(actionCode == KeyCode.enter || actionCode == KeyCode.focusLost){
1513        GralTextField widgt = (GralTextField)widg;
1514        String text = widgt.getText();
1515        float value;
1516        try{
1517          value = Float.parseFloat(text.trim());
1518          if(indexHSB == 777){ value = (value -4) / 24; if(value < 0.0f){ value +=1.0f;} }
1519          //if(value > 1.0f){ value = 1.0f; }
1520          //if(value < 0.0f){ value = 0.0f; }
1521        } catch(NumberFormatException exc){ value = 0; }  //red
1522        colorFocus.hsb[indexHSB] = value;
1523        setColorFromHSB(colorFocus);
1524        setColorEditFields(0);
1525        setColorT(colorFocus);
1526      }
1527      return true;      
1528  } };
1529
1530  
1531  
1532  class ActionEnterHLS extends GralUserAction {
1533    final int indexHLS;
1534    ActionEnterHLS(int indexHSL){
1535      super("actionEnterHLS" + indexHSL);
1536      this.indexHLS = indexHSL;
1537    }
1538      
1539    @Override public boolean exec(int actionCode, GralWidget_ifc widg, Object... params) {
1540      if(actionCode == KeyCode.enter || actionCode == KeyCode.focusLost){
1541        GralTextField widgt = (GralTextField)widg;
1542        String text = widgt.getText();
1543        float value;
1544        try{
1545          value = Float.parseFloat(text.trim());
1546          if(value > 1.0f){ value = 1.0f; }
1547          if(value < 0.0f){ value = 0.0f; }
1548        } catch(NumberFormatException exc){ value = 0; }  //red
1549        colorFocus.hls[indexHLS] = value;
1550        setColorFromHSL(colorFocus);
1551        setColorEditFields(0);
1552        setColorT(colorFocus);
1553      }
1554      return true;      
1555  } };
1556
1557  
1558  
1559  
1560  GralUserAction actionFocusedTest = new GralUserAction("actionFocusedTest"){
1561    @Override public boolean exec(int actionCode, GralWidget_ifc widg, Object... params) {
1562      if(actionCode == KeyCode.focusLost){
1563        GralTextField widgt = (GralTextField)widg;
1564        wdgTest = widgt;
1565        String text = widgt.getText();
1566        int cursor = widgt.getCursorPos();
1567        testText =  cursor > 0 && cursor < text.length();
1568      }
1569      return true;      
1570  } };
1571
1572}