1 package org.simantics.modeling.ui.actions.style;
3 import java.awt.BorderLayout;
5 import java.awt.FlowLayout;
8 import java.awt.event.ActionEvent;
9 import java.awt.event.ActionListener;
10 import java.awt.event.WindowEvent;
11 import java.awt.event.WindowListener;
13 import javax.swing.JButton;
14 import javax.swing.JColorChooser;
15 import javax.swing.JDialog;
16 import javax.swing.JPanel;
17 import javax.swing.JTabbedPane;
19 import org.simantics.utils.strings.format.MetricsFormat;
21 public class AWTStyleDialog extends JDialog {
23 private static final long serialVersionUID = 6836378345175793069L;
25 private FontChooser fontChooser;
26 private JColorChooser colorChooser;
27 private MetricsEditor metricsEditor;
29 private boolean cancelled = true;
31 private boolean useFont = true;
32 private boolean useColor = true;
33 private boolean useFormat = true;
35 public AWTStyleDialog(Frame owner,boolean useFont, boolean useColor, boolean useFormat) {
36 super(owner,"Style",true);
37 this.useFont = useFont;
38 this.useColor = useColor;
39 this.useFormat = useFormat;
43 public AWTStyleDialog(boolean useFont, boolean useColor, boolean useFormat) {
47 this.useFont = useFont;
48 this.useColor = useColor;
49 this.useFormat = useFormat;
53 public void setStartFont(Font font) {
55 throw new RuntimeException("Dialog is not configured with font support");
56 fontChooser.setCurrentFont(font);
59 public void setStartColor(Color color) {
61 throw new RuntimeException("Dialog is not configured with color support");
62 colorChooser.setColor(color);
65 public void setStartFormat(MetricsFormat format) {
67 throw new RuntimeException("Dialog is not configured with format support");
68 metricsEditor.setMetricsFormat(format);
71 private void createContents() {
73 JTabbedPane tabbedPane = new JTabbedPane();
74 getContentPane().add(tabbedPane,BorderLayout.CENTER);
76 tabbedPane.addTab("Font", fontChooser = new FontChooser("Sample text"));
78 tabbedPane.addTab("Color",colorChooser = new JColorChooser(new Color(0, 0, 0)));
80 tabbedPane.addTab("Metrics",metricsEditor = new MetricsEditor());
82 JPanel controlPanel = new JPanel();
83 getContentPane().add(controlPanel,BorderLayout.SOUTH);
84 controlPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
86 JButton okButton = new JButton("OK");
87 controlPanel.add(okButton);
88 okButton.addActionListener(new ActionListener() {
91 public void actionPerformed(ActionEvent e) {
93 AWTStyleDialog.this.setVisible(false);
94 AWTStyleDialog.this.dispose();
98 JButton cancelButton = new JButton("Cancel");
99 controlPanel.add(cancelButton);
100 cancelButton.addActionListener(new ActionListener() {
103 public void actionPerformed(ActionEvent e) {
104 AWTStyleDialog.this.setVisible(false);
105 AWTStyleDialog.this.dispose();
110 this.addWindowListener(new WindowListener() {
113 public void windowOpened(WindowEvent arg0) {}
116 public void windowIconified(WindowEvent arg0) {}
119 public void windowDeiconified(WindowEvent arg0) {}
122 public void windowDeactivated(WindowEvent arg0) {}
125 public void windowClosing(WindowEvent arg0) {
126 if (metricsEditor != null)
127 metricsEditor.dispose();
131 public void windowClosed(WindowEvent arg0) {}
134 public void windowActivated(WindowEvent arg0) {}
138 public boolean isCancelled() {
142 public Font getFont() {
143 if (fontChooser != null)
144 return fontChooser.getFont();
148 public Color getColor() {
149 if (colorChooser != null)
150 return colorChooser.getColor();
154 public MetricsFormat getFormat() {
155 return metricsEditor != null ? metricsEditor.getFormat() : null;