Use a single static JColorChooser instance to keep recent colors populated.
This commit is contained in:
parent
0cd27951e1
commit
40cac0f8fd
@ -13,6 +13,7 @@ import javax.swing.JButton;
|
|||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import javax.swing.JColorChooser;
|
import javax.swing.JColorChooser;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JDialog;
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
@ -50,6 +51,8 @@ public class AppearancePanel extends JPanel {
|
|||||||
|
|
||||||
private static File lastImageDir = null;
|
private static File lastImageDir = null;
|
||||||
|
|
||||||
|
private static final JColorChooser colorChooser = new JColorChooser();
|
||||||
|
|
||||||
private class ColorActionListener implements ActionListener {
|
private class ColorActionListener implements ActionListener {
|
||||||
private final String valueName;
|
private final String valueName;
|
||||||
private final Object o;
|
private final Object o;
|
||||||
@ -60,26 +63,32 @@ public class AppearancePanel extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent colorClickEvent) {
|
||||||
try {
|
try {
|
||||||
Method getMethod = o.getClass().getMethod("get" + valueName);
|
final Method getMethod = o.getClass().getMethod("get" + valueName);
|
||||||
Method setMethod = o.getClass().getMethod("set" + valueName, net.sf.openrocket.util.Color.class);
|
final Method setMethod = o.getClass().getMethod("set" + valueName, net.sf.openrocket.util.Color.class);
|
||||||
net.sf.openrocket.util.Color c = (net.sf.openrocket.util.Color) getMethod.invoke(o);
|
net.sf.openrocket.util.Color c = (net.sf.openrocket.util.Color) getMethod.invoke(o);
|
||||||
Color awtColor = ColorConversion.toAwtColor(c);
|
Color awtColor = ColorConversion.toAwtColor(c);
|
||||||
awtColor = JColorChooser.showDialog( //
|
colorChooser.setColor(awtColor);
|
||||||
AppearancePanel.this, //
|
JDialog d = JColorChooser.createDialog(AppearancePanel.this,
|
||||||
trans.get("RocketCompCfg.lbl.Choosecolor"), //
|
trans.get("RocketCompCfg.lbl.Choosecolor"), true, colorChooser, new ActionListener() {
|
||||||
awtColor);
|
@Override
|
||||||
if (awtColor == null)
|
public void actionPerformed(ActionEvent okEvent) {
|
||||||
return;
|
Color selected = colorChooser.getColor();
|
||||||
setMethod.invoke(o, ColorConversion.fromAwtColor(awtColor));
|
if (selected == null)
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
setMethod.invoke(o, ColorConversion.fromAwtColor(selected));
|
||||||
|
} catch (Throwable e1) {
|
||||||
|
Application.getExceptionHandler().handleErrorCondition(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
d.setVisible(true);
|
||||||
} catch (Throwable e1) {
|
} catch (Throwable e1) {
|
||||||
// TODO Auto-generated catch block
|
Application.getExceptionHandler().handleErrorCondition(e1);
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AppearancePanel(final RocketComponent c) {
|
public AppearancePanel(final RocketComponent c) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user