123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- package view;
- import java.awt.GridLayout;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.ArrayList;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JDialog;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- /**
- * the "preferences" dialog
- * @author kolja
- *
- */
- public class OptionsDialog extends JDialog {
- private static final long serialVersionUID = 1L;
- private ArrayList< ActionListener > listeners;
- private JComboBox<String> display;
- private JButton speichern;
- private JComboBox<String> run;
- private JComboBox<String> collapse;
- private JTextField fSize;
- private int tempFSize = 12;
-
- private static class Options
- { // Speichert die Optionen wie sie zuletzt waren (um zu prüfen ob was geändert wurde)
- public int layoutDisplaySelection = 0;
- public int runStepsSelection = 0;
- public int autoCollapse = 0;
- public int fontSize = 12;
- }
-
- private Options options;
-
- OptionsDialog()
- {
- setTitle( "Preferences" );
- setLayout( new GridLayout( 5, 2 ) );
- add( new JLabel( "Display layouts:" ) );
- String[] displayValues = { "All", "Only current" };
- display = new JComboBox<String>( displayValues );
- add( display );
- // Run Option
- add( new JLabel( "Run steps:" ) );
- String[] runValues = { "All", "Only expanded" };
- run = new JComboBox<String>( runValues );
- add( run );
- // Automatically collapse option
- add( new JLabel( "Automatically collapse pseudocode:" ) );
- String[] collapseValues = { "No", "Yes" };
- collapse = new JComboBox<String>( collapseValues );
- add( collapse );
- // Font size Option
- add( new JLabel( "Font size:" ) );
- fSize = new JTextField( "12" );
- add( fSize );
- fSize.getDocument().addDocumentListener( new NumberDocumentListener( new NumberDocumentListener.Action() {
- @Override
- public void action(int val) {
- tempFSize = val;
- }
- }, fSize ) );
- add( new JLabel() );
- // save
- speichern = new JButton( "Ok" );
- speichern.addActionListener( new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
- // prüfe auf änderungen
- boolean change = options.layoutDisplaySelection != display.getSelectedIndex() ||
- options.runStepsSelection != run.getSelectedIndex() ||
- tempFSize != options.fontSize ||
- options.autoCollapse != collapse.getSelectedIndex();
- options.layoutDisplaySelection = display.getSelectedIndex();
- options.runStepsSelection = run.getSelectedIndex();
- options.fontSize = tempFSize;
- options.autoCollapse = collapse.getSelectedIndex();
- if( change )
- {
- for( ActionListener l : listeners )
- { // benachrichtige die Listener über die Änderungen
- l.actionPerformed( new ActionEvent(this, 0, "Options changed" ) );
- }
- }
- setVisible( false );
- } catch( Exception e1 )
- {
- e1.printStackTrace();
- }
- }
-
- });
- add( speichern );
- setSize( 250, 150 );
- listeners = new ArrayList<ActionListener>();
- options = new Options();
- setLocation( Toolkit.getDefaultToolkit().getScreenSize().width / 2 - getWidth() / 2, Toolkit.getDefaultToolkit().getScreenSize().height / 2 - getHeight() / 2 );
- }
-
- public int getAutoCollapseOption()
- {
- return options.autoCollapse;
- }
-
- public int getLayerDisplayOption()
- {
- return options.layoutDisplaySelection;
- }
-
- public int getRunStepsOption()
- {
- return options.runStepsSelection;
- }
-
- public int getFontSize()
- {
- return options.fontSize;
- }
-
- public void addActionListener( ActionListener al )
- {
- listeners.add( al );
- }
- }
|