-package org.simantics.modeling.ui.actions.style;\r
-\r
-import java.awt.BorderLayout;\r
-import java.awt.Color;\r
-import java.awt.FlowLayout;\r
-import java.awt.Font;\r
-import java.awt.Frame;\r
-import java.awt.event.ActionEvent;\r
-import java.awt.event.ActionListener;\r
-import java.awt.event.WindowEvent;\r
-import java.awt.event.WindowListener;\r
-\r
-import javax.swing.JButton;\r
-import javax.swing.JColorChooser;\r
-import javax.swing.JDialog;\r
-import javax.swing.JPanel;\r
-import javax.swing.JTabbedPane;\r
-\r
-import org.simantics.utils.strings.format.MetricsFormat;\r
-\r
-public class AWTStyleDialog extends JDialog {\r
-\r
- private static final long serialVersionUID = 6836378345175793069L;\r
- \r
- private FontChooser fontChooser;\r
- private JColorChooser colorChooser;\r
- private MetricsEditor metricsEditor;\r
- \r
- private boolean cancelled = true;\r
- \r
- private boolean useFont = true;\r
- private boolean useColor = true;\r
- private boolean useFormat = true;\r
- \r
- public AWTStyleDialog(Frame owner,boolean useFont, boolean useColor, boolean useFormat) {\r
- super(owner,"Style",true);\r
- this.useFont = useFont;\r
- this.useColor = useColor;\r
- this.useFormat = useFormat;\r
- createContents();\r
- }\r
- \r
- public AWTStyleDialog(boolean useFont, boolean useColor, boolean useFormat) {\r
- super();\r
- setTitle("Style");\r
- setModal(true);\r
- this.useFont = useFont;\r
- this.useColor = useColor;\r
- this.useFormat = useFormat;\r
- createContents();\r
- }\r
- \r
- public void setStartFont(Font font) {\r
- if (!useFont)\r
- throw new RuntimeException("Dialog is not configured with font support");\r
- fontChooser.setCurrentFont(font);\r
- }\r
- \r
- public void setStartColor(Color color) {\r
- if (!useColor)\r
- throw new RuntimeException("Dialog is not configured with color support");\r
- colorChooser.setColor(color);\r
- }\r
- \r
- public void setStartFormat(MetricsFormat format) {\r
- if (!useFormat)\r
- throw new RuntimeException("Dialog is not configured with format support");\r
- metricsEditor.setMetricsFormat(format);\r
- }\r
- \r
- private void createContents() {\r
- \r
- JTabbedPane tabbedPane = new JTabbedPane();\r
- getContentPane().add(tabbedPane,BorderLayout.CENTER);\r
- if (useFont)\r
- tabbedPane.addTab("Font", fontChooser = new FontChooser("Sample text"));\r
- if (useColor)\r
- tabbedPane.addTab("Color",colorChooser = new JColorChooser(new Color(0, 0, 0)));\r
- if (useFormat)\r
- tabbedPane.addTab("Metrics",metricsEditor = new MetricsEditor());\r
- \r
- JPanel controlPanel = new JPanel();\r
- getContentPane().add(controlPanel,BorderLayout.SOUTH);\r
- controlPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));\r
- \r
- JButton okButton = new JButton("OK");\r
- controlPanel.add(okButton);\r
- okButton.addActionListener(new ActionListener() {\r
- \r
- @Override\r
- public void actionPerformed(ActionEvent e) {\r
- cancelled = false;\r
- AWTStyleDialog.this.setVisible(false);\r
- AWTStyleDialog.this.dispose();\r
- }\r
- });\r
- \r
- JButton cancelButton = new JButton("Cancel");\r
- controlPanel.add(cancelButton);\r
- cancelButton.addActionListener(new ActionListener() {\r
- \r
- @Override\r
- public void actionPerformed(ActionEvent e) {\r
- AWTStyleDialog.this.setVisible(false);\r
- AWTStyleDialog.this.dispose();\r
- }\r
- });\r
- \r
- \r
- this.addWindowListener(new WindowListener() {\r
- \r
- @Override\r
- public void windowOpened(WindowEvent arg0) {}\r
- \r
- @Override\r
- public void windowIconified(WindowEvent arg0) {}\r
- \r
- @Override\r
- public void windowDeiconified(WindowEvent arg0) {}\r
- \r
- @Override\r
- public void windowDeactivated(WindowEvent arg0) {}\r
- \r
- @Override\r
- public void windowClosing(WindowEvent arg0) {\r
- if (metricsEditor != null)\r
- metricsEditor.dispose();\r
- }\r
- \r
- @Override\r
- public void windowClosed(WindowEvent arg0) {}\r
- \r
- @Override\r
- public void windowActivated(WindowEvent arg0) {}\r
- });\r
- }\r
- \r
- public boolean isCancelled() {\r
- return cancelled;\r
- }\r
- \r
- public Font getFont() {\r
- if (fontChooser != null)\r
- return fontChooser.getFont();\r
- return null;\r
- }\r
- \r
- public Color getColor() {\r
- if (colorChooser != null)\r
- return colorChooser.getColor();\r
- return null;\r
- }\r
- \r
- public MetricsFormat getFormat() {\r
- return metricsEditor != null ? metricsEditor.getFormat() : null;\r
- }\r
-}\r
-\r
+package org.simantics.modeling.ui.actions.style;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+
+import javax.swing.JButton;
+import javax.swing.JColorChooser;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+
+import org.simantics.utils.strings.format.MetricsFormat;
+
+public class AWTStyleDialog extends JDialog {
+
+ private static final long serialVersionUID = 6836378345175793069L;
+
+ private FontChooser fontChooser;
+ private JColorChooser colorChooser;
+ private MetricsEditor metricsEditor;
+
+ private boolean cancelled = true;
+
+ private boolean useFont = true;
+ private boolean useColor = true;
+ private boolean useFormat = true;
+
+ public AWTStyleDialog(Frame owner,boolean useFont, boolean useColor, boolean useFormat) {
+ super(owner,"Style",true);
+ this.useFont = useFont;
+ this.useColor = useColor;
+ this.useFormat = useFormat;
+ createContents();
+ }
+
+ public AWTStyleDialog(boolean useFont, boolean useColor, boolean useFormat) {
+ super();
+ setTitle("Style");
+ setModal(true);
+ this.useFont = useFont;
+ this.useColor = useColor;
+ this.useFormat = useFormat;
+ createContents();
+ }
+
+ public void setStartFont(Font font) {
+ if (!useFont)
+ throw new RuntimeException("Dialog is not configured with font support");
+ fontChooser.setCurrentFont(font);
+ }
+
+ public void setStartColor(Color color) {
+ if (!useColor)
+ throw new RuntimeException("Dialog is not configured with color support");
+ colorChooser.setColor(color);
+ }
+
+ public void setStartFormat(MetricsFormat format) {
+ if (!useFormat)
+ throw new RuntimeException("Dialog is not configured with format support");
+ metricsEditor.setMetricsFormat(format);
+ }
+
+ private void createContents() {
+
+ JTabbedPane tabbedPane = new JTabbedPane();
+ getContentPane().add(tabbedPane,BorderLayout.CENTER);
+ if (useFont)
+ tabbedPane.addTab("Font", fontChooser = new FontChooser("Sample text"));
+ if (useColor)
+ tabbedPane.addTab("Color",colorChooser = new JColorChooser(new Color(0, 0, 0)));
+ if (useFormat)
+ tabbedPane.addTab("Metrics",metricsEditor = new MetricsEditor());
+
+ JPanel controlPanel = new JPanel();
+ getContentPane().add(controlPanel,BorderLayout.SOUTH);
+ controlPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
+
+ JButton okButton = new JButton("OK");
+ controlPanel.add(okButton);
+ okButton.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ cancelled = false;
+ AWTStyleDialog.this.setVisible(false);
+ AWTStyleDialog.this.dispose();
+ }
+ });
+
+ JButton cancelButton = new JButton("Cancel");
+ controlPanel.add(cancelButton);
+ cancelButton.addActionListener(new ActionListener() {
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ AWTStyleDialog.this.setVisible(false);
+ AWTStyleDialog.this.dispose();
+ }
+ });
+
+
+ this.addWindowListener(new WindowListener() {
+
+ @Override
+ public void windowOpened(WindowEvent arg0) {}
+
+ @Override
+ public void windowIconified(WindowEvent arg0) {}
+
+ @Override
+ public void windowDeiconified(WindowEvent arg0) {}
+
+ @Override
+ public void windowDeactivated(WindowEvent arg0) {}
+
+ @Override
+ public void windowClosing(WindowEvent arg0) {
+ if (metricsEditor != null)
+ metricsEditor.dispose();
+ }
+
+ @Override
+ public void windowClosed(WindowEvent arg0) {}
+
+ @Override
+ public void windowActivated(WindowEvent arg0) {}
+ });
+ }
+
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ public Font getFont() {
+ if (fontChooser != null)
+ return fontChooser.getFont();
+ return null;
+ }
+
+ public Color getColor() {
+ if (colorChooser != null)
+ return colorChooser.getColor();
+ return null;
+ }
+
+ public MetricsFormat getFormat() {
+ return metricsEditor != null ? metricsEditor.getFormat() : null;
+ }
+}
+