/*
Copyright 2006 Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a 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, version 3 of the License.
C.a.R. 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 .
*/
package eric.JSprogram;
import java.awt.Dimension;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JComponent;
import eric.JEricPanel;
import javax.swing.JTextPane;
import javax.swing.plaf.metal.MetalComboBoxUI;
public class JSIcon extends JSButton {
/**
*
*/
String NAME;
String CODE;
ArrayList PATTERNS=new ArrayList();
ArrayList STRS=new ArrayList();
ArrayList VARS=new ArrayList();
ArrayList CONST=new ArrayList();
ArrayList EXEMPLES=new ArrayList();
JSEditor JSC;
private static final String REGEX_NUMERIC="(((?<=[-+*/(])|(?<=^))-)?\\d+(\\.\\d+)?";
private static final String REGEX_VARIABLE="\\$[a-zA-Z][a-zA-Z0-9]*";
public static final String REGEX_OPERATION="[a-zA-Z][a-zA-Z0-9]+|[-*/+|?:@&^<>'`=%#]";
private static final String REGEX_PARANTHESIS="[()]";
// private JPanel JPN=new JPanel();
private void fixsize(final int sze) {
final Dimension d=new Dimension(sze, sze);
this.setMaximumSize(d);
this.setMinimumSize(d);
this.setPreferredSize(d);
this.setSize(d);
}
// Create an Icon wich belongs to group (if not null) :
// public JSIcon(final JSConsole jsc, final String nm, String[] codes) {
public JSIcon(JSEditor jsc, String name, String code) {
super(name, 24, !code.equals(""));
JSC=jsc;
NAME=name;
CODE=code;
this.addMouseListener(new MouseAdapter() {
public void mousePressed(final MouseEvent e) {
if (!isDisabled) {
JSC.clearStatusBar();
if (e.getButton()!=MouseEvent.BUTTON3) {
ClicOnMe();
}
JSC.NoTypeNoClic();
}
}
});
interpret();
}
@Override
public String getName() {
return NAME;
}
private int[] t;
private int[] T;
private void interpret() {
// exemple : =Point(,,);
StringBuffer sb=new StringBuffer();
Pattern p=Pattern.compile("<(\\w+[,\\w]*)>", Pattern.CASE_INSENSITIVE);
Matcher m=p.matcher(CODE);
while (m.find()) {
VARS.add(m.group(1).split(","));
m.appendReplacement(sb, "@@@@");
}
m.appendTail(sb);
m.reset();
String result=" "+sb.toString()+" ";
String[] c=result.split("@@@@");
for (int i=0; i", Pattern.CASE_INSENSITIVE);
Matcher m=p.matcher((String) EXEMPLES.get(i));
if (m.find()) {
String[] c=m.group(1).split(",");
m.appendReplacement(sb, "@@@@");
m.appendTail(sb);
String myex=sb.toString();
for (int k=0; k0)) {
T[i]=0;
i=i-1;
}
if (T[i]1) {
// st=(String) EXEMPLES.get(0);
// }
JSC.addToScript(exemple(0));
// String st="";
//
//
//
// for (int i=0; i