Hallo,
ich habe hier ein fehlerhaftes SCCEE für einen Filechooser. Die Buttons werden leider nicht dargestellt und man muss erst mit Alt-F4 den Ok-Dialog schließen um zum Filechooser zu kommen. Daher meine erst Frage: Wie werden die Buttons dargestellt und haben eine Funktion?
Und zu meiner eigentlichen Frage: Wie wird der Filechooser komplett in grün/schwarz dargestellt? Dafür die folgenden Fragen:
- Wie werden die kleinen Buttons, der Scrollbars mit den grünen Dreiecken ausgestattet? Dies betrifft sowohl den Directory-/File-Panel als auch die JComboboxes.
- Wie werden in den JComboboxes die List und das Dreieck durch einen senkrechten, dünnen grünen Strich getrennt?
Danke!
import javax.swing.UIManager;
public class ShockCfg
{
public static void main(final String args[])
{
UIManager.put("Button.focus",new javax.swing.plaf.ColorUIResource(Color.GREEN));
UIManager.put("CheckBox.focus",new javax.swing.plaf.ColorUIResource(Color.GREEN));
UIManager.put("RadioButton.focus",new javax.swing.plaf.ColorUIResource(Color.GREEN));
new ReadCfg();
}
}
public class ReadCfg
{
private String readpath; //Path to System Shock 2.
private String IniLanguage = "DE"; //Language of ShockCfg
public String getreadpath()
{
return readpath;
}
public void setreadpath(String readpath)
{
this.readpath = readpath;
}
public String getIniLanguage()
{
return IniLanguage;
}
public ReadCfg()
{
try
{
BufferedReader buffer = new BufferedReader( new FileReader("ShockCfg.ini"));
readpath = buffer.readLine();
IniLanguage = buffer.readLine();
buffer.close();
}
catch (IOException e)
{
//if shockcfg.cfg don't exists, open filechooser.
new WriteCfg(this);
}
}
}
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.metal.MetalComboBoxButton;
import javax.swing.plaf.metal.MetalComboBoxIcon;
import java.util.ArrayList;
import java.util.Locale;
public class WriteCfg
{
private final JFileChooser dir;
private int returnval;
private File shock2exe;
private BufferedWriter bufferwrite;
private ReadCfg readcfg;
public WriteCfg(ReadCfg readcfg)
{
this.setReadcfg(readcfg);
UIManager.put("OptionPane.questionDialog.border.background", new javax.swing.plaf.ColorUIResource(Color.GREEN));
UIManager.put("activeCaption", new javax.swing.plaf.ColorUIResource(Color.black));
UIManager.put("OptionPane.questionDialog.titlePane.background", new javax.swing.plaf.ColorUIResource(Color.BLACK));
UIManager.put("OptionPane.questionDialog.titlePane.foreground", new javax.swing.plaf.ColorUIResource(Color.GREEN));
UIManager.put("activeCaptionText", new javax.swing.plaf.ColorUIResource(Color.green));
UIManager.put("OptionPane.questionDialog.titlePane.shadow", new javax.swing.plaf.ColorUIResource(Color.GREEN));
javax.swing.plaf.metal.MetalLookAndFeel.setCurrentTheme(new NoBumpsTheme());
JDialog.setDefaultLookAndFeelDecorated(true);
//Inverting Colors for pressed Buttons
try {
UIManager.setLookAndFeel( new MyLookAndFeel() );
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
JOptionPane optPane = new JOptionPane("Select directory of SS2");
optPane.setOptionType(JOptionPane.DEFAULT_OPTION);
JDialog dia = optPane.createDialog(null, "Select directory of SS2");
dia.getRootPane().setBorder(BorderFactory.createLineBorder(Color.green, 3));
changeColor(dia.getComponents());
dia.setModal(true);
dia.setVisible(true);
//Inverting Colors
UIManager.put("Button.select", Color.green);
//Filechooser opening
dir = new JFileChooser()
{
/**
*
*/
private static final long serialVersionUID = 1L;
public JDialog createDialog(Component parent)
{
JDialog d = super.createDialog(parent);
d.getContentPane().setBackground(Color.black);
return d;
}
};
changeColor(new Component[]{dir});
colorChooser(dir);
dir.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
returnval = dir.showDialog(null, "Choose");
if (returnval == JFileChooser.APPROVE_OPTION)
{
shock2exe = dir.getSelectedFile();
try
{
//make shockcfg.cfg
bufferwrite = new BufferedWriter( new FileWriter("ShockCfg.ini"));
readcfg.setreadpath(shock2exe.getPath());
bufferwrite.write(readcfg.getreadpath());
//thx to Al_B
bufferwrite.write("
");
Locale w = Locale.getDefault();
if(w.getLanguage().equalsIgnoreCase("de_DE"))
{
bufferwrite.write("de_DE");
}
else
{
bufferwrite.write("en_EN");
}
bufferwrite.write("
");
bufferwrite.close();
}
catch (IOException ex)
{
System.out.println("Can not write file");
System.out.println(ex);
System.exit(0);
}
}
else
{
System.exit(0);
}
}
public void colorChooser(JFileChooser chooser){
@SuppressWarnings("rawtypes")
java.util.List<JComboBox> boxes = getComponents(chooser, JComboBox.class);
for(@SuppressWarnings("rawtypes")
JComboBox box : boxes)
{
java.util.List<JButton> buttons = getComponents(box, JButton.class);
for(JButton button : buttons)
{
MetalComboBoxButton b = (MetalComboBoxButton)button;
b.setComboIcon(new MyIcon());
}
box.setForeground(Color.GREEN);
box.setBackground(Color.BLACK);
box.setBorder(BorderFactory.createLineBorder(Color.green));
}
}
public void changeColor(Component[] comp)
{
for(int x=0; x<comp.length; x++)
{
try
{
comp[x].setBackground(Color.black);
comp[x].setForeground(Color.green);
}
catch(Exception e) {}
if(comp[x] instanceof Container)
changeColor(((Container)comp[x]).getComponents());
}
}
public class MyIcon extends MetalComboBoxIcon
{
private static final long serialVersionUID = -6616394682227867147L;
public void paintIcon(Component c, Graphics g, int x, int y)
{
int iconWidth = getIconWidth();
g.translate( x, y );
g.setColor(Color.GREEN);
g.drawLine( 0, 0, iconWidth - 1, 0 );
g.drawLine( 1, 1, 1 + (iconWidth - 3), 1 );
g.drawLine( 2, 2, 2 + (iconWidth - 5), 2 );
g.drawLine( 3, 3, 3 + (iconWidth - 7), 3 );
g.drawLine( 4, 4, 4 + (iconWidth - 9), 4 );
g.translate( -x, -y );
}
}
public static <T> java.util.List<T> getComponents(Component component, Class<T> clazz)
{
java.util.List<T> comps = new ArrayList<T>();
if(clazz.isInstance(component))
{
comps.add(clazz.cast(component));
}
else if(component instanceof Container)
{
for(Component c : ((Container)component).getComponents())
{
comps.addAll(getComponents(c, clazz));
}
}
return comps;
}
public ReadCfg getReadcfg() {
return readcfg;
}
public void setReadcfg(ReadCfg readcfg) {
this.readcfg = readcfg;
}
}
class NoBumpsTheme extends javax.swing.plaf.metal.DefaultMetalTheme
{
public javax.swing.plaf.ColorUIResource getControl(){
return new javax.swing.plaf.ColorUIResource(Color.BLACK);
}
public javax.swing.plaf.ColorUIResource getWhite(){
return new javax.swing.plaf.ColorUIResource(Color.GREEN);
}
public javax.swing.plaf.ColorUIResource getWindowBackground(){
return new javax.swing.plaf.ColorUIResource(Color.BLACK);
}
public javax.swing.plaf.ColorUIResource getPrimaryControlHighlight(){
return new javax.swing.plaf.ColorUIResource(Color.GREEN);
}
public javax.swing.plaf.ColorUIResource getPrimaryControlDarkShadow(){
return new javax.swing.plaf.ColorUIResource(Color.BLACK);
}
public javax.swing.plaf.ColorUIResource getPrimaryControlShadow(){
return new javax.swing.plaf.ColorUIResource(Color.GREEN);
}
public javax.swing.plaf.ColorUIResource getPrimaryControl(){
return new javax.swing.plaf.ColorUIResource(Color.GREEN);
}
public javax.swing.plaf.ColorUIResource getSecondary1() {
return new javax.swing.plaf.ColorUIResource(Color.GREEN);
}
public javax.swing.plaf.ColorUIResource getControlDarkShadow() {
return new javax.swing.plaf.ColorUIResource(Color.GREEN);
}
public javax.swing.plaf.ColorUIResource getControlShadow() {
return new javax.swing.plaf.ColorUIResource(Color.GREEN);
}
public javax.swing.plaf.ColorUIResource getControlHighlight() {
return new javax.swing.plaf.ColorUIResource(Color.GREEN);
}
public javax.swing.plaf.ColorUIResource getTextHighlightColor() {
return new javax.swing.plaf.ColorUIResource(Color.GREEN);
}
public javax.swing.plaf.ColorUIResource getHighlightedTextColor() {
return new javax.swing.plaf.ColorUIResource(Color.BLACK);
}
public javax.swing.plaf.ColorUIResource getSecondary3() {
return new javax.swing.plaf.ColorUIResource(Color.GREEN);
}
public javax.swing.plaf.ColorUIResource getPrimary2() {
return new javax.swing.plaf.ColorUIResource(Color.GREEN);
}
public javax.swing.plaf.ColorUIResource getControlInfo() {
return new javax.swing.plaf.ColorUIResource(Color.BLACK);
}
}
import javax.swing.plaf.metal.MetalLookAndFeel;
@SuppressWarnings("serial")
public class MyLookAndFeel extends MetalLookAndFeel {
protected void initClassDefaults(UIDefaults table)
{
super.initClassDefaults(table);
table.put( "ButtonUI", "test.ButtonUI" );
}
}