📄 theme.java
字号:
package util;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
public class Theme{
private List<String> themes;
private Map<String,String> incompatibilites;
public Theme(){
themes=new ArrayList<String>();
incompatibilites=new HashMap<String, String>();
handleThemeXML();
}
public List<String> getThemes() {
return themes;
}
public void setThemes(List<String> themes) {
this.themes = themes;
}
public Map<String, String> getIncompatibilites() {
return incompatibilites;
}
public void setIncompatibilites(Map<String, String> incompatibilites) {
this.incompatibilites = incompatibilites;
}
public boolean isCompatible(String gouche,String droite){
if(gouche.equals(droite)){
return false;
}
String exceptedGouche=incompatibilites.get(gouche);
if(exceptedGouche!=null&&exceptedGouche.equals(droite)){
return false;
}
String exceptedDroite=incompatibilites.get(droite);
if(exceptedDroite!=null&&exceptedDroite.equals(gouche)){
return false;
}
return true;
}
public void handleThemeXML(){
SAXParserFactory factory=SAXParserFactory.newInstance();
factory.setValidating(true);
SAXParser parser;
try {
parser = factory.newSAXParser();
parser.parse("themes.xml", new DefaultHandler(){
@Override
public void startElement(String uri, String localName, String name,
Attributes attributes) throws SAXException {
if(name.equals("theme")){
themes.add(attributes.getValue("nom"));
}else{
String droite=attributes.getValue("droit");
String gouche=attributes.getValue("gauche");
incompatibilites.put(gouche, droite);
}
}
});
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -