リストの続き
// <Color>メニュー用ActionListenerクラス
class ColorMenuAction implements ActionListener {
public void actionPerformed(ActionEvent ev) {
String cmd = ev.getActionCommand();
MutableAttributeSet attr = new SimpleAttributeSet();
attr = setStyles(attr);
Color c = null;
try {
Class cobj = ClassLoader.getSystemClassLoader().
loadClass("java.awt.Color");
Field field = cobj.getField(cmd);
c = (Color)field.get(cobj);
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
StyleConstants.setForeground(attr,c);
StyledDocument doc = textpane.getStyledDocument();
doc.setCharacterAttributes(selstart,selend - selstart,attr,true);
textpane.select(selstart,selend);
}
}
}
// JFileChooser用FileFilterクラス
class MyRTFFilter extends FileFilter {
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
String fname = f.getName();
int n = fname.lastIndexOf(".");
String ext = fname.substring(n);
ext = ext.toLowerCase();
if (ext != null) {
if (ext.equals(".rtf")){
return true;
} else {
return false;
}
}
return false;
}
public String getDescription() {
return "RTF";
}
}