X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.ui%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Fui%2Factions%2Fstyle%2FAWTStyleDialog.java;h=5245089190e8434b118021f2d0f783a39d9eec59;hb=e88be95edf1f80781646cfdf717ec1b663264179;hp=86b1aa316e3036f042c54094bf378fec762468bb;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/style/AWTStyleDialog.java b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/style/AWTStyleDialog.java index 86b1aa316..524508919 100644 --- a/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/style/AWTStyleDialog.java +++ b/bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/actions/style/AWTStyleDialog.java @@ -1,158 +1,158 @@ -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; - } -} - +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; + } +} +