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