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.eclipse.jface.dialogs.IDialogConstants;
20 import org.simantics.utils.strings.format.MetricsFormat;
22 public class AWTStyleDialog extends JDialog {
24 private static final long serialVersionUID = 6836378345175793069L;
26 private FontChooser fontChooser;
27 private JColorChooser colorChooser;
28 private MetricsEditor metricsEditor;
30 private boolean cancelled = true;
32 private boolean useFont = true;
33 private boolean useColor = true;
34 private boolean useFormat = true;
36 public AWTStyleDialog(Frame owner,boolean useFont, boolean useColor, boolean useFormat) {
37 super(owner,Messages.AWTStyleDialog_Style,true);
38 this.useFont = useFont;
39 this.useColor = useColor;
40 this.useFormat = useFormat;
44 public AWTStyleDialog(boolean useFont, boolean useColor, boolean useFormat) {
46 setTitle(Messages.AWTStyleDialog_Style);
48 this.useFont = useFont;
49 this.useColor = useColor;
50 this.useFormat = useFormat;
54 public void setStartFont(Font font) {
56 throw new RuntimeException("Dialog is not configured with font support"); //$NON-NLS-1$
57 fontChooser.setCurrentFont(font);
60 public void setStartColor(Color color) {
62 throw new RuntimeException("Dialog is not configured with color support"); //$NON-NLS-1$
63 colorChooser.setColor(color);
66 public void setStartFormat(MetricsFormat format) {
68 throw new RuntimeException("Dialog is not configured with format support"); //$NON-NLS-1$
69 metricsEditor.setMetricsFormat(format);
72 private void createContents() {
74 JTabbedPane tabbedPane = new JTabbedPane();
75 getContentPane().add(tabbedPane, BorderLayout.CENTER);
77 tabbedPane.addTab(Messages.AWTStyleDialog_Font,
78 fontChooser = new FontChooser(Messages.AWTStyleDialog_SampleText));
80 tabbedPane.addTab(Messages.AWTStyleDialog_Color, colorChooser = new JColorChooser(new Color(0, 0, 0)));
82 tabbedPane.addTab(Messages.AWTStyleDialog_Metrics, metricsEditor = new MetricsEditor());
84 JPanel controlPanel = new JPanel();
85 getContentPane().add(controlPanel, BorderLayout.SOUTH);
86 controlPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
88 JButton okButton = new JButton(IDialogConstants.OK_LABEL);
89 controlPanel.add(okButton);
90 okButton.addActionListener(new ActionListener() {
93 public void actionPerformed(ActionEvent e) {
95 AWTStyleDialog.this.setVisible(false);
96 AWTStyleDialog.this.dispose();
100 JButton cancelButton = new JButton(IDialogConstants.CANCEL_LABEL);
101 controlPanel.add(cancelButton);
102 cancelButton.addActionListener(new ActionListener() {
105 public void actionPerformed(ActionEvent e) {
106 AWTStyleDialog.this.setVisible(false);
107 AWTStyleDialog.this.dispose();
111 this.addWindowListener(new WindowListener() {
114 public void windowOpened(WindowEvent arg0) {}
117 public void windowIconified(WindowEvent arg0) {}
120 public void windowDeiconified(WindowEvent arg0) {}
123 public void windowDeactivated(WindowEvent arg0) {}
126 public void windowClosing(WindowEvent arg0) {
127 if (metricsEditor != null)
128 metricsEditor.dispose();
132 public void windowClosed(WindowEvent arg0) {}
135 public void windowActivated(WindowEvent arg0) {}
139 public boolean isCancelled() {
143 public Font getFont() {
144 if (fontChooser != null)
145 return fontChooser.getFont();
149 public Color getColor() {
150 if (colorChooser != null)
151 return colorChooser.getColor();
155 public MetricsFormat getFormat() {
156 return metricsEditor != null ? metricsEditor.getFormat() : null;