Rev 7304 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7304 | Rev 7314 | ||
---|---|---|---|
Line 47... | Line 47... | ||
47 | public static int rotation; |
47 | public static int rotation; |
48 | public static boolean viewC; |
48 | public static boolean viewC; |
49 | public static boolean viewH; |
49 | public static boolean viewH; |
50 | public static boolean[] TOOL_SELECTION; |
50 | public static boolean[] TOOL_SELECTION; |
51 | public static boolean[] MENU_SELECTION; |
51 | public static boolean[] MENU_SELECTION; |
52 | public static boolean USER_SELECTION; |
52 | public static boolean USER_SELECTION = false; |
53 | public static int GLOBAL_ALPHA = 140; |
53 | public static int GLOBAL_ALPHA = 140; |
- | 54 | public static int ATOM_SELECT_HTML_COLOR; /* the default Atom click colour for user interaction when selecting atoms */ |
|
- | 55 | public static int BOND_SELECT_HTML_COLOR; /* the default bond click colour for user interaction when selecting atoms */ |
|
54 | public static Color ATOM_SELECT_COLOR; |
56 | public static Color ATOM_SELECT_COLOR;/* the colour for not-by-param-selected-atoms */ |
55 | public static Color BOND_SELECT_COLOR; |
57 | public static Color BOND_SELECT_COLOR;/* the colour for not-by-param-selected-bonds */ |
56 | public static int[] ExternalAtomSelection; |
58 | public static int[] ExternalAtomSelection; /* atom line numbers in MDLmol file */ |
57 | public static Color SelectedAtomColorArray[]; |
59 | public static Color SelectedAtomColorArray[];/* atom corresponding colours for line numbers in MDLmol file */ |
58 | public static int[] ExternalBondSelection; |
60 | public static int[] ExternalBondSelection;/* bonding line numbers in MDLmol file */ |
- | 61 | public static Color SelectedBondColorArray[];;/* corresponding bonding colours for line numbers in MDLmol file */ |
|
- | 62 | public static int SelectedAtomColorInt[]; /* int color numbers set by params used in svg export */ |
|
59 | public static |
63 | public static int SelectedBondColorInt[]; /* colors set by params used in svg export */ |
60 | public static boolean ATOM_BUTTONS = true; |
64 | public static boolean ATOM_BUTTONS = true; /* button row with atoms SOUTH */ |
- | 65 | public static boolean SUPERUSER_SELECTION = false; /* if true the exported SVG will be coloured according params */ |
|
- | 66 | ||
61 | public static String language; |
67 | public static String language; |
62 | public void init(){ |
68 | public void init(){ |
63 | ATOM_BUTTONS = getBool("atom_button_row",false); /* if set an extra row of buttons will be shown */ |
69 | ATOM_BUTTONS = getBool("atom_button_row",false); /* if set an extra row of buttons will be shown */ |
64 | USER_SELECTION = getBool("user_selection",false); |
70 | USER_SELECTION = getBool("user_selection",false); |
65 | if( USER_SELECTION ){ |
71 | if( USER_SELECTION ){ |
66 | GLOBAL_ALPHA = getInt("color_alpha",140); |
72 | GLOBAL_ALPHA = getInt("color_alpha",140); |
67 | /* some people forget the importance of alpha...this should be removed */ |
73 | /* some people forget the importance of alpha...this should be removed */ |
68 | if( GLOBAL_ALPHA > 250 ){GLOBAL_ALPHA = 140;} |
74 | if( GLOBAL_ALPHA > 250 ){GLOBAL_ALPHA = 140;} |
69 | ATOM_SELECT_COLOR = getColor("default_atom_select_color",GLOBAL_ALPHA,255,0,0);/* RGB */ |
75 | ATOM_SELECT_COLOR = getColor("default_atom_select_color",GLOBAL_ALPHA,255,0,0);/* RGB */ |
70 | BOND_SELECT_COLOR = getColor("default_bond_select_color",GLOBAL_ALPHA,0,0,255);/* RGB */ |
76 | BOND_SELECT_COLOR = getColor("default_bond_select_color",GLOBAL_ALPHA,0,0,255);/* RGB */ |
- | 77 | ATOM_SELECT_HTML_COLOR = RGB2int("default_atom_select_color",0x0000ff);/* int for svg */ |
|
- | 78 | BOND_SELECT_HTML_COLOR = RGB2int("default_bond_select_color",0x00ff00);/* int for svg */ |
|
71 | } |
79 | } |
72 | zoom_js = ""; |
80 | zoom_js = ""; |
73 | language = getLanguage(); |
81 | language = getLanguage(); |
74 | TOOL_SELECTION = getTools(); |
82 | TOOL_SELECTION = getTools(); |
75 | MENU_SELECTION = getMenus(); |
83 | MENU_SELECTION = getMenus(); |
Line 114... | Line 122... | ||
114 | return true; |
122 | return true; |
115 | } catch (IOException e) { System.out.println("problems parsing:\n"+Source.toString()+"\n"+e);} |
123 | } catch (IOException e) { System.out.println("problems parsing:\n"+Source.toString()+"\n"+e);} |
116 | return false; |
124 | return false; |
117 | } |
125 | } |
118 | public boolean SetMolecule(String Source, boolean is_molfile) |
126 | public boolean SetMolecule(String Source, boolean is_molfile) |
119 | { |
127 | { |
120 | try |
128 | try |
121 | { |
129 | { |
122 | Molecule mol; |
130 | Molecule mol; |
123 | if(is_molfile){ |
131 | if(is_molfile){ |
124 | mol = MoleculeStream.readMDLMOL(new BufferedReader(new StringReader(Source.toString()))); |
132 | mol = MoleculeStream.readMDLMOL(new BufferedReader(new StringReader(Source.toString()))); |
125 | } |
133 | } |
126 | else |
134 | else |
127 | { |
135 | { |
128 | mol = MoleculeStream.readUnknown(new BufferedReader(new StringReader(Source.toString()))); |
136 | mol = MoleculeStream.readUnknown(new BufferedReader(new StringReader(Source.toString()))); |
Line 157... | Line 165... | ||
157 | return true; |
165 | return true; |
158 | } |
166 | } |
159 | catch (IOException e) { System.out.println("error in applet : appendMolelcule( String Source ) : "+e.toString());} |
167 | catch (IOException e) { System.out.println("error in applet : appendMolelcule( String Source ) : "+e.toString());} |
160 | 168 | ||
161 | return false; |
169 | return false; |
162 | } |
170 | } |
163 | 171 | ||
164 | /* |
172 | /* |
165 | return the string representation of the molecule, in WIMSchem native format |
173 | return the string representation of the molecule, in WIMSchem native format |
166 | */ |
174 | */ |
167 | public String GetMoleculeNative() |
175 | public String GetMoleculeNative() |
168 | { |
176 | { |
169 | try |
177 | try |
Line 192... | Line 200... | ||
192 | } |
200 | } |
193 | catch (IOException e) {} |
201 | catch (IOException e) {} |
194 | 202 | ||
195 | return "error getting MDLMol file from applet"; |
203 | return "error getting MDLMol file from applet"; |
196 | } |
204 | } |
197 | - | ||
198 | public |
205 | public int RGB2int(String p, int d){ /* convert 255,0,255 -> ff00ff*/ |
- | 206 | String param = getParameter(p); |
|
- | 207 | if( param != null && param.length()>0 ){ |
|
199 |
|
208 | int k = 0;String hex = "";String tmp=""; |
- | 209 | StringTokenizer q = new StringTokenizer(param, ","); |
|
- | 210 | int c = q.countTokens(); |
|
- | 211 | if( c != 3){System.out.println("use R,G,B for colours ; use param color_alpha for transparency"); return d;} |
|
- | 212 | for( int a = 0; a < 3 ; a++){ |
|
- | 213 | k = Integer.parseInt(q.nextToken(), 10); |
|
- | 214 | tmp = Integer.toHexString(k); |
|
- | 215 | while (tmp.length()<2) tmp="0"+tmp; |
|
- | 216 | hex = hex+""+tmp; |
|
- | 217 | } |
|
200 |
|
218 | return Integer.parseInt(hex,16); |
- | 219 | } |
|
201 |
|
220 | else |
- | 221 | { |
|
- | 222 | return d; |
|
- | 223 | } |
|
202 | } |
224 | } |
- | 225 | ||
- | 226 | public void componentHidden(ComponentEvent e){} |
|
- | 227 | public void componentMoved(ComponentEvent e){} |
|
- | 228 | public void componentResized(ComponentEvent e){} |
|
203 | public void componentShown(ComponentEvent e) |
229 | public void componentShown(ComponentEvent e){ |
204 | { |
- | |
205 | mainPanel.scaleToFit(); |
230 | mainPanel.scaleToFit(); |
206 | mainPanel.repaint(); |
231 | mainPanel.repaint(); |
207 | } |
232 | } |
208 | /* |
233 | /* |
209 | jm.evers additions to configuring applet |
234 | jm.evers additions to configuring applet |
Line 216... | Line 241... | ||
216 | if( (mainPanel.editor).selected[n-1] ){ reply = reply+mol.atomElement(n-1)+"\n";} |
241 | if( (mainPanel.editor).selected[n-1] ){ reply = reply+mol.atomElement(n-1)+"\n";} |
217 | } |
242 | } |
218 | return reply; |
243 | return reply; |
219 | } |
244 | } |
220 | 245 | ||
221 | public String getSVG(String type){ |
246 | public String getSVG(String type){ |
222 | SVGMolecule svgmol; |
247 | SVGMolecule svgmol; |
223 | if( type.equals("1") ){ /* get the student reply*/ |
248 | if( type.equals("1") ){ /* get the student reply*/ |
224 | try{ |
249 | try{ |
- | 250 | System.out.println("ok : exporting user drawing to SVG"); |
|
225 | svgmol = new SVGMolecule((mainPanel.editor).molData()); |
251 | svgmol = new SVGMolecule((mainPanel.editor).molData()); |
226 | }catch(Exception e){return e.toString();} |
252 | }catch(Exception e){return e.toString();} |
227 | } |
253 | } |
228 | else |
254 | else |
229 | { |
255 | { |
- | 256 | /* |
|
- | 257 | check if we have a param 'name=file2' : reserved for the correctmolecule in mdlmol --> svg |
|
- | 258 | using javascript:getSVG(2) |
|
230 |
|
259 | */ |
231 |
|
260 | type = getString("file2"); |
- | 261 | USER_SELECTION = false; /* disable colours of studentreply in correct answer svg ! */ |
|
- | 262 | SUPERUSER_SELECTION = true; /* if appropriate set html colours to applet colours */ |
|
232 |
|
263 | if( type != null ){ /* ok found param file2 */ |
- | 264 | try{ |
|
233 | String correct_answer = loadAny(type); |
265 | String correct_answer = loadAny(type); |
234 | Molecule answer_mol = MoleculeStream.readMDLMOL(new BufferedReader(new StringReader(correct_answer.toString()))); |
266 | Molecule answer_mol = MoleculeStream.readMDLMOL(new BufferedReader(new StringReader(correct_answer.toString()))); |
235 | svgmol = new SVGMolecule(answer_mol); |
267 | svgmol = new SVGMolecule(answer_mol); |
- | 268 | System.out.println("ok : exporting file2 to SVG"); |
|
- | 269 | }catch(Exception e){return e.toString();} |
|
- | 270 | } |
|
- | 271 | else |
|
- | 272 | { |
|
- | 273 | /* use the drawing in the applet for export to svg*/ |
|
- | 274 | try{ |
|
- | 275 | svgmol = new SVGMolecule((mainPanel.editor).molData()); |
|
- | 276 | System.out.println("ok : exporting molecule in applet window to SVG\npossibly colouring atoms and bonds\naccording to color params"); |
|
236 | }catch(Exception e){return e.toString();} |
277 | }catch(Exception e){return e.toString();} |
237 | } |
278 | } |
- | 279 | } |
|
238 | double zoom_factor = getDouble("zoomfactor",1.00); |
280 | double zoom_factor = getDouble("zoomfactor",1.00); |
239 | if( zoom_factor != 1.00 ){ /* simple static in/out zoom, no pan */ |
281 | if( zoom_factor != 1.00 ){ /* simple static in/out zoom, no pan */ |
240 | id = System.currentTimeMillis(); |
282 | id = System.currentTimeMillis(); |
241 | g_id = ("g_SVG_"+id).toString(); |
283 | g_id = ("g_SVG_"+id).toString(); |
242 | svg_id = ("SVG_"+id).toString(); |
284 | svg_id = ("SVG_"+id).toString(); |
Line 594... | Line 636... | ||
594 | param=param.replaceAll(";",",");param=param.replaceAll(":",","); |
636 | param=param.replaceAll(";",",");param=param.replaceAll(":",","); |
595 | StringTokenizer i = new StringTokenizer(param, ","); |
637 | StringTokenizer i = new StringTokenizer(param, ","); |
596 | int max=i.countTokens(); |
638 | int max=i.countTokens(); |
597 | ExternalAtomSelection = new int[max]; |
639 | ExternalAtomSelection = new int[max]; |
598 | SelectedAtomColorArray = new Color[max]; |
640 | SelectedAtomColorArray = new Color[max]; |
- | 641 | SelectedAtomColorInt = new int[max]; |
|
599 | String ColorParam; |
642 | String ColorParam; |
600 | for(int p=0;p<max;p++){ |
643 | for(int p=0;p<max;p++){ |
601 | ExternalAtomSelection[p] = Integer.parseInt(i.nextToken()); |
644 | ExternalAtomSelection[p] = Integer.parseInt(i.nextToken()); |
602 | // now try to find the color belonging to this selected atom |
645 | // now try to find the color belonging to this selected atom |
- | 646 | SelectedAtomColorInt[p] = RGB2int("select_atom_color"+ExternalAtomSelection[p]+"",0x00ff00); |
|
603 | ColorParam=getParameter("select_atom_color"+ExternalAtomSelection[p]); |
647 | ColorParam=getParameter("select_atom_color"+ExternalAtomSelection[p]); |
604 | if(ColorParam != null && ColorParam.length()>0){ |
648 | if(ColorParam != null && ColorParam.length()>0){ |
605 | ColorParam=ColorParam.replaceAll(":",",");ColorParam=ColorParam.replace(";",","); |
649 | ColorParam=ColorParam.replaceAll(":",",");ColorParam=ColorParam.replace(";",","); |
606 | StringTokenizer q = new StringTokenizer(ColorParam, ","); |
650 | StringTokenizer q = new StringTokenizer(ColorParam, ","); |
607 | for( int a=0; a<3 ; a++){ |
651 | for( int a=0; a<3 ; a++){ |
Line 620... | Line 664... | ||
620 | else |
664 | else |
621 | { |
665 | { |
622 | SelectedAtomColorArray[p] = ATOM_SELECT_COLOR; |
666 | SelectedAtomColorArray[p] = ATOM_SELECT_COLOR; |
623 | } |
667 | } |
624 | } |
668 | } |
- | 669 | SUPERUSER_SELECTION = true; |
|
625 | }else{ ExternalAtomSelection = null;} |
670 | }else{ ExternalAtomSelection = null;} |
626 | return ExternalAtomSelection; |
671 | return ExternalAtomSelection; |
627 | } |
672 | } |
628 | 673 | ||
629 | /* |
674 | /* |
Line 636... | Line 681... | ||
636 | param=param.replaceAll(";",",");param=param.replaceAll(":",","); |
681 | param=param.replaceAll(";",",");param=param.replaceAll(":",","); |
637 | StringTokenizer i = new StringTokenizer(param, ","); |
682 | StringTokenizer i = new StringTokenizer(param, ","); |
638 | int max=i.countTokens(); |
683 | int max=i.countTokens(); |
639 | ExternalBondSelection = new int[max]; |
684 | ExternalBondSelection = new int[max]; |
640 | SelectedBondColorArray = new Color[max]; |
685 | SelectedBondColorArray = new Color[max]; |
- | 686 | SelectedBondColorInt = new int[max]; |
|
641 | for(int p=0;p<max;p++){ |
687 | for(int p=0;p<max;p++){ |
642 | ExternalBondSelection[p] = Integer.parseInt(i.nextToken()); |
688 | ExternalBondSelection[p] = Integer.parseInt(i.nextToken()); |
643 | // now try to find the color belonging to this selected bond |
689 | // now try to find the color belonging to this selected bond |
- | 690 | SelectedBondColorInt[p] = RGB2int("select_bond_color"+ExternalBondSelection[p]+"",0x0000ff); |
|
644 | ColorParam=getParameter("select_bond_color"+ExternalBondSelection[p]); |
691 | ColorParam=getParameter("select_bond_color"+ExternalBondSelection[p]); |
645 | if(ColorParam != null && ColorParam.length()>0){ |
692 | if(ColorParam != null && ColorParam.length()>0){ |
646 | ColorParam=ColorParam.replaceAll(":",",");ColorParam=ColorParam.replace(";",","); |
693 | ColorParam=ColorParam.replaceAll(":",",");ColorParam=ColorParam.replace(";",","); |
647 | StringTokenizer q = new StringTokenizer(ColorParam, ","); |
694 | StringTokenizer q = new StringTokenizer(ColorParam, ","); |
648 | for( int a=0; a<3 ; a++){ |
695 | for( int a=0; a<3 ; a++){ |
Line 661... | Line 708... | ||
661 | else |
708 | else |
662 | { |
709 | { |
663 | SelectedBondColorArray[p] = BOND_SELECT_COLOR; |
710 | SelectedBondColorArray[p] = BOND_SELECT_COLOR; |
664 | } |
711 | } |
665 | } |
712 | } |
- | 713 | SUPERUSER_SELECTION = true; |
|
666 | }else{ ExternalBondSelection = null;} |
714 | }else{ ExternalBondSelection = null;} |
667 | return ExternalBondSelection; |
715 | return ExternalBondSelection; |
668 | } |
716 | } |
669 | 717 | ||
670 | /* |
718 | /* |