OptionsDialog.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package view;
  2. import java.awt.GridLayout;
  3. import java.awt.Toolkit;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import java.util.ArrayList;
  7. import javax.swing.JButton;
  8. import javax.swing.JComboBox;
  9. import javax.swing.JDialog;
  10. import javax.swing.JLabel;
  11. import javax.swing.JTextField;
  12. public class OptionsDialog extends JDialog {
  13. private static final long serialVersionUID = 1L;
  14. private ArrayList< ActionListener > listeners;
  15. private JComboBox<String> display;
  16. private JButton speichern;
  17. private JComboBox<String> run;
  18. private JTextField fSize;
  19. private int tempFSize = 12;
  20. private static class Options
  21. {
  22. public int layoutDisplaySelection = 0;
  23. public int runStepsSelection = 0;
  24. public int fontSize = 12;
  25. }
  26. private Options options;
  27. OptionsDialog()
  28. {
  29. setTitle( "Preferences" );
  30. setLayout( new GridLayout( 4, 2 ) );
  31. add( new JLabel( "Display layouts:" ) );
  32. String[] displayValues = { "All", "Only current" };
  33. display = new JComboBox<String>( displayValues );
  34. add( display );
  35. add( new JLabel( "Run steps:" ) );
  36. String[] runValues = { "All", "Only expanded" };
  37. run = new JComboBox<String>( runValues );
  38. add( run );
  39. add( new JLabel( "Font size:" ) );
  40. fSize = new JTextField( "12" );
  41. add( fSize );
  42. fSize.getDocument().addDocumentListener( new NumberDocumentListener( new NumberDocumentListener.Action() {
  43. @Override
  44. public void action(int val) {
  45. tempFSize = val;
  46. }
  47. }, fSize ) );
  48. add( new JLabel() );
  49. speichern = new JButton( "Ok" );
  50. speichern.addActionListener( new ActionListener() {
  51. @Override
  52. public void actionPerformed(ActionEvent e) {
  53. try {
  54. boolean change = options.layoutDisplaySelection != display.getSelectedIndex() ||
  55. options.runStepsSelection != run.getSelectedIndex() ||
  56. tempFSize != options.fontSize;
  57. options.layoutDisplaySelection = display.getSelectedIndex();
  58. options.runStepsSelection = run.getSelectedIndex();
  59. options.fontSize = tempFSize;
  60. if( change )
  61. {
  62. for( ActionListener l : listeners )
  63. {
  64. l.actionPerformed( new ActionEvent(this, 0, "Options changed" ) );
  65. }
  66. }
  67. setVisible( false );
  68. } catch( Exception e1 )
  69. {
  70. e1.printStackTrace();
  71. }
  72. }
  73. });
  74. add( speichern );
  75. setSize( 250, 150 );
  76. listeners = new ArrayList<ActionListener>();
  77. options = new Options();
  78. setLocation( Toolkit.getDefaultToolkit().getScreenSize().width / 2 - getWidth() / 2, Toolkit.getDefaultToolkit().getScreenSize().height / 2 - getHeight() / 2 );
  79. }
  80. public int getLayerDisplayOption()
  81. {
  82. return options.layoutDisplaySelection;
  83. }
  84. public int getRunStepsOption()
  85. {
  86. return options.runStepsSelection;
  87. }
  88. public int getFontSize()
  89. {
  90. return options.fontSize;
  91. }
  92. public void addActionListener( ActionListener al )
  93. {
  94. listeners.add( al );
  95. }
  96. }