Package historyPlugin

Source Code of historyPlugin.HistoryPlugin

package historyPlugin;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import lipstone.joshua.parser.Parser;
import lipstone.joshua.parser.plugin.ParserPlugin;
import lipstone.joshua.parser.plugin.settings.ParserSettingsCheckBox;
import lipstone.joshua.parser.plugin.settings.ParserSettingsList;
import lipstone.joshua.parser.plugin.types.SettingsPlugin;
import lipstone.joshua.parser.util.Equation;

public class HistoryPlugin extends ParserPlugin implements SettingsPlugin {
 
  @Override
  public void loadSettings() {
    settingsPanel.setName("History");
    final ParserSettingsList<Equation> history = new ParserSettingsList<Equation>("History", this, parser.getHistory().getList());
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = 6;
    c.gridheight = 16;
    addSettingsItem(history, c, new Dimension(600, 400));
    c.gridwidth = 1;
    c.gridheight = 1;
    JButton remove = new JButton("Remove"), clear = new JButton("Clear");
    remove.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        parser.getHistory().removeEquation(history.getGUIItem().getSelectedIndices());
      }
    });
    clear.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        parser.getHistory().clearHistory();
      }
    });
    final ParserSettingsCheckBox save = new ParserSettingsCheckBox("Save", this, "Save History") {
      @Override
      public void onEnter() {
        super.onEnter();
        parser.setSaveHistory(this.getGUIItem().isSelected());
      }
    };
    save.getGUIItem().setSelected(parser.isSavingHistory());
    parser.addPropertyListener(new PropertyChangeListener() {
     
      @Override
      public void propertyChange(PropertyChangeEvent evt) {
        save.getGUIItem().setSelected((boolean) evt.getNewValue());
      }
    }, Parser.SaveHistory);
    c.gridy = 17;
    settingsPanel.add(remove, c);
    c.gridx = 2;
    JPanel spacer1 = new JPanel();
    spacer1.setOpaque(false);
    spacer1.setPreferredSize(new Dimension(149, 25));
    settingsPanel.add(spacer1, c);
    c.gridx = 3;
    //23, 110
    save.getGUIItem().setOpaque(false);
    addSettingsItem(save, c);
    c.gridx = 4;
    JPanel spacer2 = new JPanel();
    spacer2.setOpaque(false);
    spacer2.setPreferredSize(new Dimension(149, 25));
    settingsPanel.add(spacer2, c);
    c.gridwidth = 1;
    c.gridx = 5;
    settingsPanel.add(clear, c);
  }
 
  @Override
  public void unloadSettings() {}
 
}
TOP

Related Classes of historyPlugin.HistoryPlugin

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.