Package ketUI

Source Code of ketUI.FunctionList

/*
* Copyright (C) 2011  Alasdair C. Hamilton
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>
*/

package ketUI;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.*;

import ketUI.modes.DocumentState;
import ket.Selection;
import ket.math.*;
import static ket.math.Type.STRICT_INVERSES; // This is accessible statically but not by regular import - why?

/**
* A list of functions.
*/

public class FunctionList extends PurposeList {

  boolean updatePurpose;

  public FunctionList(Document document, JComponent source) {
    super(document, source);
    // TODO: Convert to a static final enum set field in DocumentState.
    DocumentState ds = document.getModes().getDocumentState();
    updatePurpose = ds==DocumentState.APPEND_PURPOSE || ds==DocumentState.PREPEND_PURPOSE || ds==DocumentState.QUICK_RENAME;
  }

  @Override
  protected void populate(Vector<String> all) {
    for (Purpose p : Function.OPERATORS) {
      if (STRICT_INVERSES.contains(p)) continue;
      all.add(p.getName());
    }
  }

  @Override
  protected Purpose seek(String text) {
    if (text==null) return null;
    for (Purpose p : Function.OPERATORS) {
      if (text.equals(p.getName())) {
        return p;
      }
    }
    return null;
  }

  @Override
  protected void insert(Purpose purpose) {
    Document d = getDocument();
    Selection s = d.getSelection();
    Argument current = s.getCurrent();
    if (current.isBranch() && updatePurpose) {
      current.asBranch().setFunction((Function) purpose);
    } else {
      s.addIntermediaryParent((Function) purpose);
    }
  }

  @Override
  protected Purpose create(String name) {
    return getDocument().getModes().getKnownArguments().recordUniqueFunction(name);
  }

}
TOP

Related Classes of ketUI.FunctionList

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.