Make first real commit: copy of CaRMetal 4.2.8

This commit is contained in:
Glen Whitney 2018-09-04 22:51:42 -04:00
parent 002acfc88e
commit c312811084
1120 changed files with 226843 additions and 1 deletions

View file

@ -0,0 +1,104 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
package eric.textfieldpopup;
import javax.swing.JButton;
import javax.swing.JComponent;
import eric.JEricPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;
import javax.swing.text.JTextComponent;
/**
*
* @author erichake
*/
public class JFunctionsPanel extends JMenuPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
int Linemax = 3;
String funcs = "&& || ! < > <= >= == ~= $ "
+ "x() y() d(,) if(,,) a(,,) inside(,) $ "
+ "sqrt() exp() log() round() ceil() floor() abs() sign() random() min(,) max(,) $ "
+ "sin() cos() tan() rsin() rcos() rtan() "
+ "arcsin() arccos() arctan() rarcsin() rarccos() rarctan() "
+ "deg() rad() sinhyp() coshyp() angle180() angle360() "
+ "Argsinh() Argcosh() Argtanh() tanhyp() atan2(,) ratan2(,) $ "
+ "integrate(,,) zero(,,) diff(,) min(,,) max(,,) length() $ "
+ "windoww windowh windowcx windowcy pixel $ "
+ "div(,) mod(,) gcd(,) lcm(,)";
public JFunctionsPanel(final JPopupMenu men, final JComponent jtf) {
super(men);
JTF = jtf;
iconwidth = 75;
iconheight = 20;
final String[] f = funcs.split(" ");
JEricPanel line = null;
int j = 0;
for (final String element : f) {
if ((j % Linemax) == 0) {
add(line = getnewline());
}
if (element.equals("$")) {
add(new JSeparator());
j = 0;
} else {
line.add(getJButton(element));
j++;
}
}
}
@Override
public void doAction(final JButton mybtn) {
final String s = mybtn.getText();
mybtn.setOpaque(false);
mybtn.setContentAreaFilled(false);
if (JTF != null) {
final JTextComponent jt = (JTextComponent) JTF;
if ((s.endsWith(")")) && (jt.getSelectedText() != null)) {
String mytxt = jt.getText()
.substring(0, jt.getSelectionStart());
mytxt += s.substring(0, s.length() - 1);
mytxt += jt.getSelectedText() + ")";
final int car = mytxt.length();
mytxt += jt.getText().substring(jt.getSelectionEnd());
jt.setText(mytxt);
jt.setCaretPosition(car);
} else {
String mytxt = jt.getText()
.substring(0, jt.getSelectionStart());
mytxt += (s.endsWith(")")) ? s.substring(0, s.length() - 1) : s;
final int car = mytxt.length();
mytxt += jt.getText().substring(jt.getSelectionEnd());
jt.setText(mytxt);
jt.setCaretPosition(car);
}
MEN.setVisible(false);
}
}
}

View file

@ -0,0 +1,152 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
package eric.textfieldpopup;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import eric.JEricPanel;
import javax.swing.JPopupMenu;
import javax.swing.text.JTextComponent;
import rene.gui.Global;
/**
*
* @author erichake
*/
public class JMenuPanel extends JEricPanel implements MouseListener {
/**
*
*/
private static final long serialVersionUID = 1L;
JPopupMenu MEN = null;
int iconwidth = 20;
int iconheight = 20;
JComponent JTF;
public JMenuPanel(final JPopupMenu men) {
MEN = men;
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
setAlignmentY(0f);
setOpaque(true);
setFocusable(false);
setBackground(new Color(250, 250, 250));
}
static void fixsize(final JComponent cp, final int w, final int h) {
final Dimension d = new Dimension(w, h);
cp.setMaximumSize(d);
cp.setMinimumSize(d);
cp.setPreferredSize(d);
cp.setSize(d);
}
public JButton getJButton(final String s) {
final JButton mybtn = new JButton(s);
mybtn.setBorder(BorderFactory.createEmptyBorder());
mybtn.setBorderPainted(false);
mybtn.setFocusPainted(false);
mybtn.setFocusable(false);
mybtn.setBackground(new Color(228, 222, 255));
mybtn.setOpaque(false);
mybtn.setContentAreaFilled(false);
mybtn.addMouseListener(this);
mybtn.setFont(new java.awt.Font(Global.GlobalFont, 1, 11));
mybtn.setForeground(new Color(20, 20, 20));
fixsize(mybtn, iconwidth, iconheight);
return mybtn;
}
JEricPanel getnewline() {
final JEricPanel line = new JEricPanel();
line.setLayout(new BoxLayout(line, BoxLayout.X_AXIS));
line.setAlignmentX(0f);
line.setOpaque(false);
return line;
}
JEricPanel getnewcol() {
final JEricPanel col = new JEricPanel();
col.setLayout(new BoxLayout(col, BoxLayout.Y_AXIS));
col.setAlignmentY(0f);
col.setOpaque(true);
col.setBackground(new Color(250, 250, 250));
return col;
}
public void doAction(final JButton mybtn) {
final String s = mybtn.getText();
mybtn.setOpaque(false);
mybtn.setContentAreaFilled(false);
if (JTF != null) {
final JTextComponent jt = (JTextComponent) JTF;
String mytxt = jt.getText().substring(0, jt.getSelectionStart());
mytxt += s;
final int car = mytxt.length();
mytxt += jt.getText().substring(jt.getSelectionEnd());
jt.setText(mytxt);
jt.setCaretPosition(car);
MEN.setVisible(false);
}
}
public void mouseClicked(final MouseEvent e) {
final JButton mybtn = (JButton) e.getComponent();
doAction(mybtn);
}
public void mousePressed(final MouseEvent e) {
}
public void mouseReleased(final MouseEvent e) {
}
public void mouseEntered(final MouseEvent e) {
if (e.getSource() != null) {
final JButton btn = (JButton) e.getSource();
btn.setBackground(new Color(171, 191, 231));
btn.setOpaque(true);
btn.setContentAreaFilled(true);
}
}
public void mouseExited(final MouseEvent e) {
if (e.getSource() != null) {
final JButton btn = (JButton) e.getSource();
btn.setOpaque(false);
btn.setContentAreaFilled(false);
}
}
}

View file

@ -0,0 +1,66 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
package eric.textfieldpopup;
import javax.swing.JComponent;
import eric.JEricPanel;
import javax.swing.JPopupMenu;
import javax.swing.JSeparator;
/**
*
* @author erichake
*/
public class JSpecialCarsPanel extends JMenuPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
int Linemax = 10;
private final String greekmajLettersSet = "\u0391\u0392\u0393\u0394\u0395\u0396"
+ "\u0397\u0398\u0399\u039A\u039B\u039C\u039D\u039E\u039F\u03A0\u03A1\u03A3"
+ "\u03A4\u03A5\u03A6\u03A7\u03A8\u03A9";
private final String greekminLettersSet = "\u03B1\u03B2\u03B3\u03B4\u03B5\u03B6\u03B7\u03B8\u03B9"
+ "\u03BA\u03BB\u03BC\u03BD\u03BE\u03BF\u03C0\u03C1\u03C3\u03C4\u03C5\u03C6"
+ "\u03C7\u03C8\u03C9";
public JSpecialCarsPanel(final JPopupMenu men, final JComponent jtf) {
super(men);
JTF = jtf;
JEricPanel line = null;
for (int i = 0; i < greekminLettersSet.length(); i++) {
if ((i % Linemax) == 0) {
add(line = getnewline());
}
line.add(getJButton(greekminLettersSet.substring(i, i + 1)));
}
add(new JSeparator());
for (int i = 0; i < greekmajLettersSet.length(); i++) {
if ((i % Linemax) == 0) {
add(line = getnewline());
}
line.add(getJButton(greekmajLettersSet.substring(i, i + 1)));
}
}
}

View file

@ -0,0 +1,145 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
package eric.textfieldpopup;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import eric.JEricPanel;
import javax.swing.JPopupMenu;
import javax.swing.text.JTextComponent;
import atp.sHotEqn;
import java.awt.Graphics2D;
import rene.gui.Global;
/**
*
* @author erichake
*/
public class JTexPanel extends JMenuPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
int Linemax = 4;
String funcs = "\\frac{a}{b} \\sqrt{a} \\sqrt[n]{a} \\vec{u} \\widehat{ABC} \\hat{a} a_1 a^2 "
+ "\\sum_{i=0}^{n} \\prod_{i=0}^{n} \\int_{a}^{b} \\oint_{a}^{b} \\bar{z} \\fbox{box}";
// +"\\left|\\begin{array}{cc}a_{11}&a_{12}\\\\\\\\a_{21}&a_{22}\\end{array}\\right| "
// +
// "\\left(\\begin{array}{cc}a_{11}&a_{12}\\\\\\\\a_{21}&a_{22}\\end{array}\\right) ";
public JTexPanel(final JPopupMenu men, final JComponent jtf) {
super(men);
JTF = jtf;
iconwidth = 50;
iconheight = 50;
final String[] f = funcs.split(" ");
JEricPanel line = null;
for (int i = 0; i < f.length; i++) {
if ((i % Linemax) == 0) {
add(line = getnewline());
}
line.add(getJButton(f[i]));
}
}
@Override
public void doAction(final JButton mybtn) {
String s = ((myJButton) mybtn).EQ;
final JTextComponent jt = (JTextComponent) JTF;
mybtn.setOpaque(false);
mybtn.setContentAreaFilled(false);
String mytxt = jt.getText().substring(0, jt.getSelectionStart());
final int nbDollars = mytxt.split("\\$").length - 1;
if (nbDollars % 2 == 0) {
s = "$" + s + "$";
}
if (jt.getSelectedText() != null) {
final Pattern p = Pattern.compile("\\{([^\\}]*)\\}",
Pattern.CASE_INSENSITIVE);
final Matcher m = p.matcher(s);
if (m.find()) {
s = m.replaceFirst("{" + jt.getSelectedText() + "}");
}
}
mytxt += s;
final int car = mytxt.length();
mytxt += jt.getText().substring(jt.getSelectionEnd());
jt.setText(mytxt);
jt.setCaretPosition(car);
MEN.setVisible(false);
}
@Override
public JButton getJButton(final String s) {
final myJButton mybtn = new myJButton(s);
mybtn.setBorder(BorderFactory.createEmptyBorder());
mybtn.setBorderPainted(false);
mybtn.setFocusPainted(false);
mybtn.setFocusable(false);
mybtn.setBackground(new Color(228, 222, 255));
mybtn.setOpaque(false);
mybtn.setContentAreaFilled(false);
mybtn.addMouseListener(this);
mybtn.setFont(new java.awt.Font(Global.GlobalFont, 1, 14));
mybtn.setForeground(new Color(20, 20, 20));
fixsize(mybtn, iconwidth, iconheight);
return mybtn;
}
class myJButton extends JButton {
/**
*
*/
private static final long serialVersionUID = 1L;
String EQ = null;
sHotEqn HE = null;
@Override
public void paintComponent(final Graphics g) {
super.paintComponent(g);
Graphics2D g2d=(Graphics2D) g;
final Dimension d = this.getSize();
final Dimension eq = HE.getSizeof(EQ, g2d);
HE.paint((d.width - eq.width) / 2, (d.height - eq.height) / 2, g2d);
}
public myJButton(final String s) {
super();
EQ = s;
HE = new sHotEqn(this);
HE.setHAlign("center");
HE.setEquation(s);
}
}
}

View file

@ -0,0 +1,90 @@
/*
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 <http://www.gnu.org/licenses/>.
*/
package eric.textfieldpopup;
import java.awt.event.MouseEvent;
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JPopupMenu;
import rene.gui.Global;
/**
*
* @author erichake
*/
public class JTextFieldPopup extends JPopupMenu {
/**
*
*/
private static final long serialVersionUID = 1L;
JComponent JTF;
// Numéro du menu :
static public int SPECIALCARMENU = 0, FUNCTIONMENU = 1, LATEXMENU = 2;
myJMenuItem m1, m2, m3;
public JTextFieldPopup(final JComponent jtf) {
JTF = jtf;
this.setFocusable(false);
m1 = new myJMenuItem(Global.Loc("props.popup.special"),
new JSpecialCarsPanel(this, JTF));
m2 = new myJMenuItem(Global.Loc("props.popup.functions"),
new JFunctionsPanel(this, JTF));
m3 = new myJMenuItem(Global.Loc("props.popup.latex"), new JTexPanel(
this, JTF));
this.add(m1);
this.add(m2);
this.add(m3);
}
public void setDisabled(final String dis) {
if (dis.contains("," + SPECIALCARMENU + ","))
this.getComponent(SPECIALCARMENU).setEnabled(false);
if (dis.contains("," + FUNCTIONMENU + ","))
this.getComponent(FUNCTIONMENU).setEnabled(false);
if (dis.contains("," + LATEXMENU + ","))
this.getComponent(LATEXMENU).setEnabled(false);
}
public void openMenu(final MouseEvent e) {
this.show(e.getComponent(), e.getX(), e.getY());
}
class myJMenuItem extends JMenu {
/**
*
*/
private static final long serialVersionUID = 1L;
JPopupMenu jp;
public myJMenuItem(final String name, final JMenuPanel jmp) {
super(name);
this.setFocusable(false);
this.add(jmp);
}
}
}