📄 svgresource.java
字号:
if(root!=null){ String res="<?xml version=\"1.0\" ?>"; res=printChild(root, res); byte[] result=new byte[0]; try{result=res.getBytes("UTF-8");}catch (Exception e) {} //writes the string OutputStream writer=null; try{ writer=new BufferedOutputStream(new FileOutputStream(new URI(getPath("xml/".concat(path))).getPath())); }catch (Exception ex){writer=null;} if(writer!=null){ try{ writer.write(result, 0, result.length); writer.flush(); writer.close(); }catch (Exception ex){} } } } } /** * the recursive function allowing to concat the string representation of the given node * @param node a node * @param str a string * @return the string representation of the subtree of the given node */ protected String printChild(Node node, String str){ String res=new String(str); if(node instanceof Element){ //writes the node name res=res.concat("<"+node.getNodeName()+" "); //writes the attributes NamedNodeMap att=node.getAttributes(); Node at=null; for(int i=0;i<att.getLength();i++){ at=att.item(i); if(at!=null){ res=res.concat(at.getNodeName()+"=\""+at.getNodeValue()+"\" "); } } //writes the children Node cur=null; if(node.hasChildNodes()){ res=res.concat(">"); cur=node.getFirstChild(); }else{ res=res.concat("/>"); } while(cur!=null){ res=printChild(cur, res); cur=cur.getNextSibling(); } if(node.hasChildNodes()){ res=res.concat("</"+node.getNodeName()+">"); } } return res; } /** * @return the collection of the recently opened files */ public Collection<String> getRecentFiles(){ return new LinkedList<String>(recentFiles); } /** * adds a new file to the list of the recent files * @param fileName the name of the file */ public void addRecentFile(String fileName){ if(recentFiles!=null && fileName!=null && ! fileName.equals("")){ if(recentFiles.contains(fileName)){ //if the file name is already contained in the list, it is removed recentFiles.remove(fileName); }else if(recentFiles.size()>5){ recentFiles.removeLast(); } recentFiles.addFirst(fileName); } saveRecentFiles(); } /** * removes a the file that has the given name from the list of the recent files * @param fileName the name of the file */ public void removeRecentFile(String fileName){ if(recentFiles!=null && fileName!=null && ! fileName.equals("") && recentFiles.contains(fileName)){ recentFiles.remove(fileName); } saveRecentFiles(); } /** * saves the list of the recent files into a file */ protected void saveRecentFiles(){ if(preferences!=null && recentFiles!=null){ //removing all the child nodes from the preference node String[] keys=null; try{keys=preferences.keys();}catch (Exception ex){} if(keys!=null){ //filling the list of the recent files for(int i=0; i<keys.length; i++){ preferences.remove(keys[i]); } } if(recentFiles.size()>0){ String rf=""; int n=0; for(Iterator it=recentFiles.iterator(); it.hasNext();){ try{rf=(String)it.next();}catch (Exception ex){} if(rf!=null && ! rf.equals("")){ preferences.put(n+"", rf); n++; } } try{preferences.flush();}catch (Exception ex){} } } } /** * @return the list of the style properties found in the properties.xml file */ public HashSet<String> getAttributesToTranslate(){ if(styleProperties.size()<=0){ Document doc=null; if(xmlProperties!=null){ doc=xmlProperties; }else{ doc=getXMLDocument("properties.xml"); } if(doc!=null){ Node root=doc.getDocumentElement(); if(root!=null){ //the node iterator Node node=null; String str=""; //for each property npde for(NodeIterator it=new NodeIterator(root); it.hasNext();){ try{node=it.next();}catch (Exception ex){node=null;} if(node!=null && node instanceof Element && node.getNodeName().equals("property")){ //tests if the node is a style property if(((Element)node).getAttribute("type")!=null && ((Element)node).getAttribute("type").equals("style")){ str=((Element)node).getAttribute("name"); //gets the name of the stye property if(str!=null && !str.equals("")){ str=str.substring(9, str.length()); styleProperties.add(str); } } } } } } } return styleProperties; } /** * adds a runnable to the list of the runnables that will be run when the editor is exited * @param runnable a runnable */ public void addExitRunnable(Runnable runnable){ synchronized(this){exitRunnables.add(runnable);} } /** * saves the editor's current state before it is exited */ public void saveEditorsCurrentState(){ //saves the current files list saveRecentFiles(); //runs the list of the runnables LinkedList<Runnable> exitRun=new LinkedList<Runnable>(exitRunnables); for(Runnable runnable : exitRun){ if(runnable!=null){ runnable.run(); } } } /** * the comparator for the colors * * @author Jordi SUC */ protected class ColorComparator implements Comparator{ private static final int GREY_TYPE=0; private static final int BLUE_TYPE=1; private static final int MAGENTA_TYPE=2; private static final int RED_TYPE=3; private static final int YELLOW_TYPE=4; private static final int GREEN_TYPE=5; private static final int CYAN_TYPE=6; /** * returns the type of the color * @param color a color * @return the type of the color */ protected int getType(Color color){ int type=-2; if(color!=null){ int r=color.getRed(), g=color.getGreen(), b=color.getBlue(); if(r==g && g==b){ type=GREY_TYPE; }else if(b>g && b>r){ type=BLUE_TYPE; }else if(b==r && r>g){ type=MAGENTA_TYPE; }else if(r>g && r>g){ type=RED_TYPE; }else if(r==g && r>b){ type=YELLOW_TYPE; }else if(g>r && g>b){ type=GREEN_TYPE; }else if(g==b && g>r){ type=CYAN_TYPE; } } return type; } /** * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) */ public int compare(Object arg0, Object arg1) { if(arg0!=null && arg1!=null && arg0 instanceof Color && arg1 instanceof Color){ Color color0=(Color)arg0, color1=(Color)arg1; int r0=color0.getRed(), g0=color0.getGreen(), b0=color0.getRed(), r1=color1.getRed(), g1=color1.getGreen(), b1=color1.getBlue(); float[] hsbVal0=new float[3], hsbVal1=new float[3]; hsbVal0=Color.RGBtoHSB(r0, g0, b0, hsbVal0); hsbVal1=Color.RGBtoHSB(r1, g1, b1, hsbVal1); float hue0=hsbVal0[0], hue1=hsbVal1[0]; float sat0=hsbVal0[1], sat1=hsbVal1[1]; float br0=hsbVal0[2], br1=hsbVal1[2]; if(Math.abs(hue1-hue0)>=0.5){ if(hue1>hue0){ return -1; }else if(hue1<hue0){ return 1; }else{ return 0; } } if(Math.abs(sat1-sat0)>=0.5){ if(sat1>sat0){ return 1; } if(sat1<sat0){ return -1; } return 0; } if(br1>br0){ return 1; }else if(br1<br0){ return -1; }else{ return 0; } /*if(hue0<hue1){ return 1; }else if(hue0>hue1){ return -1; }else if(hue0!=type1){ if(type0<type1){ return -1; }else if(type0>type1){ return 1; }else{ return 0; } }else{ if(lum0<lum1){ return 1; }else if(lum0>lum1){ return -1; }else{ return 0; } }*/ } return 0; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -