Make first real commit: copy of CaRMetal 4.2.8
This commit is contained in:
parent
002acfc88e
commit
c312811084
1120 changed files with 226843 additions and 1 deletions
49
rene/gui/ActionTranslator.java
Normal file
49
rene/gui/ActionTranslator.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* A translator for Actions.
|
||||
*/
|
||||
|
||||
public class ActionTranslator implements ActionListener {
|
||||
String Name;
|
||||
DoActionListener C;
|
||||
ActionEvent E;
|
||||
|
||||
public ActionTranslator(final DoActionListener c, final String name) {
|
||||
Name = name;
|
||||
C = c;
|
||||
}
|
||||
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
E = e;
|
||||
C.doAction(Name);
|
||||
}
|
||||
|
||||
public void trigger() {
|
||||
C.doAction(Name);
|
||||
}
|
||||
}
|
62
rene/gui/ButtonAction.java
Normal file
62
rene/gui/ButtonAction.java
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JButton;
|
||||
|
||||
/**
|
||||
* A text Button with a midifyable Font. The button may also be triggered by a
|
||||
* keyboard return.
|
||||
* <P>
|
||||
* This button class is used in DoActionListener interfaces.
|
||||
*/
|
||||
|
||||
public class ButtonAction extends JButton {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
DoActionListener C;
|
||||
String Name;
|
||||
ActionTranslator AT;
|
||||
|
||||
public ButtonAction(final DoActionListener c, final String s,
|
||||
final String name) {
|
||||
super(s);
|
||||
C = c;
|
||||
Name = name;
|
||||
addActionListener(AT = new ActionTranslator(c, name));
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
}
|
||||
|
||||
public ButtonAction(final DoActionListener c, final String s) {
|
||||
this(c, s, s);
|
||||
}
|
||||
|
||||
|
||||
// public ActionEvent getAction() {
|
||||
// return AT.E;
|
||||
// }
|
||||
}
|
71
rene/gui/CheckboxAction.java
Normal file
71
rene/gui/CheckboxAction.java
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.Checkbox;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
class CheckboxActionTranslator implements ItemListener {
|
||||
DoActionListener C;
|
||||
String S;
|
||||
public Checkbox CB;
|
||||
|
||||
public CheckboxActionTranslator(final Checkbox cb,
|
||||
final DoActionListener c, final String s) {
|
||||
C = c;
|
||||
S = s;
|
||||
CB = cb;
|
||||
}
|
||||
|
||||
public void itemStateChanged(final ItemEvent e) {
|
||||
C.itemAction(S, CB.getState());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A Checkbox with modifyable font.
|
||||
* <p>
|
||||
* To be used in DoActionListener interfaces.
|
||||
*/
|
||||
|
||||
public class CheckboxAction extends Checkbox {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CheckboxAction(final DoActionListener c, final String s) {
|
||||
super(s);
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
addItemListener(new CheckboxActionTranslator(this, c, s));
|
||||
}
|
||||
|
||||
public CheckboxAction(final DoActionListener c, final String s,
|
||||
final String h) {
|
||||
super(s);
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
addItemListener(new CheckboxActionTranslator(this, c, h));
|
||||
}
|
||||
}
|
58
rene/gui/CheckboxMenu.java
Normal file
58
rene/gui/CheckboxMenu.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.CheckboxMenuItem;
|
||||
import java.util.Vector;
|
||||
|
||||
class CheckboxMenuElement {
|
||||
public String Tag;
|
||||
public CheckboxMenuItem Item;
|
||||
|
||||
public CheckboxMenuElement(final CheckboxMenuItem i, final String tag) {
|
||||
Item = i;
|
||||
Tag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
public class CheckboxMenu {
|
||||
Vector V;
|
||||
|
||||
public CheckboxMenu() {
|
||||
V = new Vector();
|
||||
}
|
||||
|
||||
public void add(final CheckboxMenuItem i, final String tag) {
|
||||
V.addElement(new CheckboxMenuElement(i, tag));
|
||||
}
|
||||
|
||||
public void set(final String tag) {
|
||||
int i;
|
||||
for (i = 0; i < V.size(); i++) {
|
||||
final CheckboxMenuElement e = (CheckboxMenuElement) V.elementAt(i);
|
||||
if (tag.equals(e.Tag))
|
||||
e.Item.setState(true);
|
||||
else
|
||||
e.Item.setState(false);
|
||||
}
|
||||
}
|
||||
}
|
68
rene/gui/CheckboxMenuItemAction.java
Normal file
68
rene/gui/CheckboxMenuItemAction.java
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.CheckboxMenuItem;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
class CheckboxTranslator implements ItemListener {
|
||||
DoActionListener C;
|
||||
String S;
|
||||
public CheckboxMenuItem CB;
|
||||
|
||||
public CheckboxTranslator(final CheckboxMenuItem cb,
|
||||
final DoActionListener c, final String s) {
|
||||
C = c;
|
||||
S = s;
|
||||
CB = cb;
|
||||
}
|
||||
|
||||
public void itemStateChanged(final ItemEvent e) {
|
||||
C.itemAction(S, CB.getState());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A CheckboxMenuItem with modifyable font.
|
||||
* <p>
|
||||
* This is to be used in DoActionListener interfaces.
|
||||
*/
|
||||
|
||||
public class CheckboxMenuItemAction extends CheckboxMenuItem {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CheckboxMenuItemAction(final DoActionListener c, final String s,
|
||||
final String st) {
|
||||
super(s);
|
||||
addItemListener(new CheckboxTranslator(this, c, st));
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
}
|
||||
|
||||
public CheckboxMenuItemAction(final DoActionListener c, final String s) {
|
||||
this(c, s, s);
|
||||
}
|
||||
}
|
68
rene/gui/ChoiceAction.java
Normal file
68
rene/gui/ChoiceAction.java
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import javax.swing.JComboBox;
|
||||
|
||||
class ChoiceTranslator implements ItemListener {
|
||||
DoActionListener C;
|
||||
String S;
|
||||
public JComboBox Ch;
|
||||
|
||||
public ChoiceTranslator(final JComboBox ch, final DoActionListener c,
|
||||
final String s) {
|
||||
C = c;
|
||||
S = s;
|
||||
Ch = ch;
|
||||
}
|
||||
|
||||
public void itemStateChanged(final ItemEvent e) {
|
||||
C.itemAction(S, e.getStateChange() == ItemEvent.SELECTED);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a choice item, which sets a specified font and translates events into
|
||||
* strings, which are passed to the doAction method of the DoActionListener.
|
||||
*
|
||||
* @see jagoclient.gui.CloseFrame#doAction
|
||||
* @see jagoclient.gui.CloseDialog#doAction
|
||||
*/
|
||||
|
||||
public class ChoiceAction extends JComboBox {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
|
||||
public ChoiceAction(final DoActionListener c, final String s) {
|
||||
addItemListener(new ChoiceTranslator(this, c, s));
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
setBackground(Color.white);
|
||||
}
|
||||
}
|
313
rene/gui/CloseDialog.java
Normal file
313
rene/gui/CloseDialog.java
Normal file
|
@ -0,0 +1,313 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import eric.GUI.pipe_tools;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
|
||||
import eric.JEricPanel;
|
||||
|
||||
/**
|
||||
* A dialog, which can be closed by clicking on the close window field (a cross
|
||||
* on the top right corner in Windows 95), or by pressing the escape key.
|
||||
* <p>
|
||||
* Moreover, the dialog is a DoActionListener, which makes it possible to use
|
||||
* the simplified TextFieldAction etc.
|
||||
*/
|
||||
|
||||
public class CloseDialog extends javax.swing.JDialog implements WindowListener,
|
||||
ActionListener, DoActionListener, KeyListener, FocusListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
boolean Dispose = true;
|
||||
public boolean Aborted = false;
|
||||
Frame F;
|
||||
public String Subject = "";
|
||||
|
||||
public CloseDialog(final Frame f, final String s, final boolean modal) {
|
||||
super(f, s, modal);
|
||||
F = f;
|
||||
addWindowListener(this);
|
||||
addKeyListener(this);
|
||||
addFocusListener(this);
|
||||
}
|
||||
|
||||
public void windowActivated(final WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowClosed(final WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowClosing(final WindowEvent e) {
|
||||
if (close())
|
||||
doclose();
|
||||
}
|
||||
|
||||
public void windowDeactivated(final WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowDeiconified(final WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowIconified(final WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowOpened(final WindowEvent e) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the dialog is closed.
|
||||
*/
|
||||
public boolean close() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls close(), when the escape key is pressed.
|
||||
*
|
||||
* @return true if the dialog may close.
|
||||
*/
|
||||
public boolean escape() {
|
||||
return close();
|
||||
}
|
||||
|
||||
public ActionEvent E;
|
||||
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
E = e;
|
||||
doAction(e.getActionCommand());
|
||||
}
|
||||
|
||||
public void doAction(final String o) {
|
||||
if ("Close".equals(o) && close()) {
|
||||
Aborted = true;
|
||||
doclose();
|
||||
} else if (o.equals("Help")) {
|
||||
showHelp();
|
||||
}
|
||||
}
|
||||
|
||||
public void showHelp() {
|
||||
// InfoDialog.Subject=Subject;
|
||||
// InfoDialog id=new InfoDialog(F);
|
||||
}
|
||||
|
||||
public void itemAction(final String o, final boolean flag) {
|
||||
}
|
||||
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ESCAPE && escape())
|
||||
doclose();
|
||||
}
|
||||
|
||||
public void keyReleased(final KeyEvent e) {
|
||||
}
|
||||
|
||||
public void keyTyped(final KeyEvent e) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the dialog. This may be used in subclasses to do some action. Then
|
||||
* call super.doclose()
|
||||
*/
|
||||
public void doclose() {
|
||||
setVisible(false);
|
||||
// Because of a bug in Linux Java 1.4.2 etc.
|
||||
// dispose in a separate thread.
|
||||
final Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (Dispose)
|
||||
dispose();
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void center(final Frame g) {
|
||||
JEricPanel panel=pipe_tools.getCanvasPanel();
|
||||
final Dimension si = panel.getSize(), d = getSize(), dscreen = getToolkit()
|
||||
.getScreenSize();
|
||||
final Point lo = panel.getLocationOnScreen();
|
||||
int x = lo.x + si.width / 2 - d.width / 2;
|
||||
int y = lo.y + si.height / 2 - d.height / 2;
|
||||
if (x + d.width > dscreen.width)
|
||||
x = dscreen.width - d.width - 10;
|
||||
if (x < 10)
|
||||
x = 10;
|
||||
if (y + d.height > dscreen.height)
|
||||
y = dscreen.height - d.height - 10;
|
||||
if (y < 10)
|
||||
y = 10;
|
||||
setLocation(x, y);
|
||||
}
|
||||
|
||||
static public void center(final Frame f, final Dialog dialog) {
|
||||
final Dimension si = f.getSize(), d = dialog.getSize(), dscreen = f
|
||||
.getToolkit().getScreenSize();
|
||||
final Point lo = f.getLocation();
|
||||
int x = lo.x + si.width / 2 - d.width / 2;
|
||||
int y = lo.y + si.height / 2 - d.height / 2;
|
||||
if (x + d.width > dscreen.width)
|
||||
x = dscreen.width - d.width - 10;
|
||||
if (x < 10)
|
||||
x = 10;
|
||||
if (y + d.height > dscreen.height)
|
||||
y = dscreen.height - d.height - 10;
|
||||
if (y < 10)
|
||||
y = 10;
|
||||
dialog.setLocation(x, y);
|
||||
}
|
||||
|
||||
public void centerOut(final Frame f) {
|
||||
final Dimension si = f.getSize(), d = getSize(), dscreen = getToolkit()
|
||||
.getScreenSize();
|
||||
final Point lo = f.getLocation();
|
||||
int x = lo.x + si.width - getSize().width + 20;
|
||||
int y = lo.y + si.height / 2 + 40;
|
||||
if (x + d.width > dscreen.width)
|
||||
x = dscreen.width - d.width - 10;
|
||||
if (x < 10)
|
||||
x = 10;
|
||||
if (y + d.height > dscreen.height)
|
||||
y = dscreen.height - d.height - 10;
|
||||
if (y < 10)
|
||||
y = 10;
|
||||
setLocation(x, y);
|
||||
}
|
||||
|
||||
public void center() {
|
||||
final Dimension d = getSize(), dscreen = getToolkit().getScreenSize();
|
||||
setLocation((dscreen.width - d.width) / 2,
|
||||
(dscreen.height - d.height) / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Note window position in Global.
|
||||
*/
|
||||
public void notePosition(final String name) {
|
||||
final Point l = getLocation();
|
||||
final Dimension d = getSize();
|
||||
Global.setParameter(name + ".x", l.x);
|
||||
Global.setParameter(name + ".y", l.y);
|
||||
Global.setParameter(name + ".w", d.width);
|
||||
if (d.height - Global.getParameter(name + ".h", 0) != 19)
|
||||
// works around a bug in Windows
|
||||
Global.setParameter(name + ".h", d.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set window position and size.
|
||||
*/
|
||||
public void setPosition(final String name) {
|
||||
final Point l = getLocation();
|
||||
final Dimension d = getSize();
|
||||
final Dimension dscreen = getToolkit().getScreenSize();
|
||||
int x = Global.getParameter(name + ".x", l.x);
|
||||
int y = Global.getParameter(name + ".y", l.y);
|
||||
int w = Global.getParameter(name + ".w", d.width);
|
||||
int h = Global.getParameter(name + ".h", d.height);
|
||||
if (w > dscreen.width)
|
||||
w = dscreen.width;
|
||||
if (h > dscreen.height)
|
||||
h = dscreen.height;
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
if (x + w > dscreen.width)
|
||||
x = dscreen.width - w;
|
||||
if (y < 0)
|
||||
y = 0;
|
||||
if (y + h > dscreen.height)
|
||||
y = dscreen.height - h;
|
||||
setLocation(x, y);
|
||||
setSize(w, h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to set the focus somewhere.
|
||||
*/
|
||||
public void focusGained(final FocusEvent e) {
|
||||
}
|
||||
|
||||
public void focusLost(final FocusEvent e) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Note window size in Global.
|
||||
*/
|
||||
public void noteSize(final String name) {
|
||||
final Dimension d = getSize();
|
||||
Global.setParameter(name + ".w", d.width);
|
||||
Global.setParameter(name + ".h", d.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set window size.
|
||||
*/
|
||||
public void setSize(final String name) {
|
||||
if (!Global.haveParameter(name + ".w"))
|
||||
pack();
|
||||
else {
|
||||
final Dimension d = getSize();
|
||||
final int w = Global.getParameter(name + ".w", d.width);
|
||||
final int h = Global.getParameter(name + ".h", d.height);
|
||||
setSize(w, h);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This inihibits dispose(), when the dialog is closed.
|
||||
*/
|
||||
public void setDispose(final boolean flag) {
|
||||
Dispose = flag;
|
||||
}
|
||||
|
||||
public boolean isAborted() {
|
||||
return Aborted;
|
||||
}
|
||||
|
||||
/**
|
||||
* To add a help button to children.
|
||||
*
|
||||
* @param p
|
||||
* @param subject
|
||||
*/
|
||||
public void addHelp(final JEricPanel p, final String subject) {
|
||||
p.add(new MyLabel(""));
|
||||
p.add(new ButtonAction(this, Global.name("help"), "Help"));
|
||||
Subject = subject;
|
||||
}
|
||||
|
||||
}
|
269
rene/gui/CloseFrame.java
Normal file
269
rene/gui/CloseFrame.java
Normal file
|
@ -0,0 +1,269 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Image;
|
||||
import java.awt.MediaTracker;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
import java.io.InputStream;
|
||||
import java.util.Hashtable;
|
||||
|
||||
class ToFrontDelay extends Thread {
|
||||
CloseFrame F;
|
||||
final int Delay = 500;
|
||||
|
||||
public ToFrontDelay(final CloseFrame f) {
|
||||
F = f;
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
sleep(Delay);
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
F.toFront();
|
||||
F.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A Frame, which can be closed with the close button in the window frame.
|
||||
* <p>
|
||||
* This frame may set an icon. The icon file must be a GIF with 16x16 dots in
|
||||
* 256 colors. We use the simple method, which does not work in the Netscape
|
||||
* browser.
|
||||
* <p>
|
||||
* This Frame is a DoActionListener. Thus it is possible to use TextFieldAction
|
||||
* etc. in it. Override doAction(String) and itemAction(String,boolean) to react
|
||||
* on events.
|
||||
* <p>
|
||||
* Sometimes the Frame wants to set the focus to a certain text field. To
|
||||
* support this, override focusGained().
|
||||
*/
|
||||
|
||||
public class CloseFrame extends javax.swing.JFrame implements WindowListener,
|
||||
ActionListener, DoActionListener, FocusListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public CloseFrame(final String s) {
|
||||
super(s);
|
||||
addWindowListener(this);
|
||||
addFocusListener(this);
|
||||
}
|
||||
|
||||
public CloseFrame() {
|
||||
addWindowListener(this);
|
||||
addFocusListener(this);
|
||||
}
|
||||
|
||||
public void windowActivated(final WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowClosed(final WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowClosing(final WindowEvent e) {
|
||||
if (close())
|
||||
doclose();
|
||||
}
|
||||
|
||||
public void windowDeactivated(final WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowDeiconified(final WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowIconified(final WindowEvent e) {
|
||||
}
|
||||
|
||||
public void windowOpened(final WindowEvent e) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the frame should close now.
|
||||
*/
|
||||
public boolean close() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
doAction(e.getActionCommand());
|
||||
}
|
||||
|
||||
public void doAction(final String o) {
|
||||
if ("Close".equals(o) && close())
|
||||
doclose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the frame. Override, if necessary, and call super.doclose().
|
||||
*/
|
||||
public void doclose() {
|
||||
setMenuBar(null); // for Linux ?!
|
||||
setVisible(false);
|
||||
// Because of a bug in Linux Java 1.4.2 etc.
|
||||
// dispose in a separate thread.
|
||||
final Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Global.disposeCurrentJZF();
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void itemAction(final String o, final boolean flag) {
|
||||
}
|
||||
|
||||
// the icon things
|
||||
static Hashtable Icons = new Hashtable();
|
||||
|
||||
public void seticon(final String file) {
|
||||
try {
|
||||
final Object o = Icons.get(file);
|
||||
if (o == null) {
|
||||
Image i;
|
||||
final InputStream in = getClass().getResourceAsStream(
|
||||
"/" + file);
|
||||
int pos = 0;
|
||||
int n = in.available();
|
||||
final byte b[] = new byte[20000];
|
||||
while (n > 0) {
|
||||
final int k = in.read(b, pos, n);
|
||||
if (k < 0)
|
||||
break;
|
||||
pos += k;
|
||||
n = in.available();
|
||||
}
|
||||
i = Toolkit.getDefaultToolkit().createImage(b, 0, pos);
|
||||
final MediaTracker T = new MediaTracker(this);
|
||||
T.addImage(i, 0);
|
||||
T.waitForAll();
|
||||
Icons.put(file, i);
|
||||
setIconImage(i);
|
||||
} else {
|
||||
setIconImage((Image) o);
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to set the focus somewhere.
|
||||
*/
|
||||
public void focusGained(final FocusEvent e) {
|
||||
}
|
||||
|
||||
public void focusLost(final FocusEvent e) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Note window position in Global.
|
||||
*/
|
||||
public void notePosition(final String name) {
|
||||
final Point l = getLocation();
|
||||
final Dimension d = getSize();
|
||||
Global.setParameter(name + ".x", l.x);
|
||||
Global.setParameter(name + ".y", l.y);
|
||||
Global.setParameter(name + ".w", d.width);
|
||||
if (d.height - Global.getParameter(name + ".h", 0) != 19)
|
||||
// works around a bug in Windows
|
||||
Global.setParameter(name + ".h", d.height);
|
||||
if ((getExtendedState() & Frame.MAXIMIZED_BOTH) != 0)
|
||||
Global.setParameter(name + ".maximized", true);
|
||||
else
|
||||
Global.removeParameter(name + ".maximized");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set window position and size.
|
||||
*/
|
||||
public void setPosition(final String name) {
|
||||
if (Global.getParameter(name + ".maximized", false)) {
|
||||
setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
return;
|
||||
}
|
||||
final Point l = getLocation();
|
||||
final Dimension d = getSize();
|
||||
final Dimension dscreen = getToolkit().getScreenSize();
|
||||
int x = Global.getParameter(name + ".x", l.x);
|
||||
int y = Global.getParameter(name + ".y", l.y);
|
||||
int w = Global.getParameter(name + ".w", d.width);
|
||||
int h = Global.getParameter(name + ".h", d.height);
|
||||
if (w > dscreen.width)
|
||||
w = dscreen.width;
|
||||
if (h > dscreen.height)
|
||||
h = dscreen.height;
|
||||
if (x < 0)
|
||||
x = 0;
|
||||
if (x + w > dscreen.width)
|
||||
x = dscreen.width - w;
|
||||
if (y < 0)
|
||||
y = 0;
|
||||
if (y + h > dscreen.height)
|
||||
y = dscreen.height - h;
|
||||
setLocation(x, y);
|
||||
setSize(w, h);
|
||||
}
|
||||
|
||||
public void front() {
|
||||
new ToFrontDelay(this);
|
||||
}
|
||||
|
||||
public void center() {
|
||||
final Dimension dscreen = getToolkit().getScreenSize();
|
||||
final Dimension d = getSize();
|
||||
setLocation((dscreen.width - d.width) / 2,
|
||||
(dscreen.height - d.height) / 2);
|
||||
}
|
||||
|
||||
public void centerOut(final Frame f) {
|
||||
final Dimension si = f.getSize(), d = getSize(), dscreen = getToolkit()
|
||||
.getScreenSize();
|
||||
final Point lo = f.getLocation();
|
||||
int x = lo.x + si.width - getSize().width + 20;
|
||||
int y = lo.y + si.height / 2 + 40;
|
||||
if (x + d.width > dscreen.width)
|
||||
x = dscreen.width - d.width - 10;
|
||||
if (x < 10)
|
||||
x = 10;
|
||||
if (y + d.height > dscreen.height)
|
||||
y = dscreen.height - d.height - 10;
|
||||
if (y < 10)
|
||||
y = 10;
|
||||
setLocation(x, y);
|
||||
}
|
||||
}
|
26
rene/gui/CloseListener.java
Normal file
26
rene/gui/CloseListener.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
public interface CloseListener {
|
||||
public void closed();
|
||||
}
|
28
rene/gui/DoActionListener.java
Normal file
28
rene/gui/DoActionListener.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
public interface DoActionListener {
|
||||
void doAction(String o);
|
||||
|
||||
void itemAction(String o, boolean flag);
|
||||
}
|
48
rene/gui/FormTextField.java
Normal file
48
rene/gui/FormTextField.java
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
/**
|
||||
* A text field, which can transfer focus to the next text field, when return is
|
||||
* pressed.
|
||||
*/
|
||||
|
||||
public class FormTextField extends MyTextField implements DoActionListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public FormTextField(final String s) {
|
||||
super();
|
||||
final TextFieldActionListener T = new TextFieldActionListener(this, "");
|
||||
addActionListener(T);
|
||||
setText(s);
|
||||
}
|
||||
|
||||
public void doAction(final String o) {
|
||||
transferFocus();
|
||||
}
|
||||
|
||||
public void itemAction(final String o, final boolean flag) {
|
||||
}
|
||||
}
|
1106
rene/gui/Global.java
Normal file
1106
rene/gui/Global.java
Normal file
File diff suppressed because it is too large
Load diff
196
rene/gui/HistoryTextField.java
Normal file
196
rene/gui/HistoryTextField.java
Normal file
|
@ -0,0 +1,196 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.MenuItem;
|
||||
import java.awt.PopupMenu;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
|
||||
import rene.util.FileName;
|
||||
import rene.util.list.ListClass;
|
||||
import rene.util.list.ListElement;
|
||||
|
||||
/**
|
||||
* A TextField, which display the old input, when cursor up is pressed. The old
|
||||
* input is stored in a list. The class is derived from TextFieldAction.
|
||||
*
|
||||
* @see TextFieldAction
|
||||
*/
|
||||
|
||||
public class HistoryTextField extends TextFieldAction implements KeyListener,
|
||||
DoActionListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
ListClass H;
|
||||
PopupMenu M = null;
|
||||
boolean Trigger = false;
|
||||
public int MaxLength = 48;
|
||||
|
||||
public HistoryTextField(final DoActionListener l, final String name) {
|
||||
super(l, name);
|
||||
H = new ListClass();
|
||||
H.append(new ListElement(""));
|
||||
addKeyListener(this);
|
||||
}
|
||||
|
||||
public HistoryTextField(final DoActionListener l, final String name,
|
||||
final int s) {
|
||||
super(l, name, s);
|
||||
H = new ListClass();
|
||||
H.append(new ListElement(""));
|
||||
addKeyListener(this);
|
||||
}
|
||||
|
||||
public void keyPressed(final KeyEvent ev) {
|
||||
switch (ev.getKeyCode()) {
|
||||
case KeyEvent.VK_UP:
|
||||
case KeyEvent.VK_DOWN:
|
||||
if (M == null) {
|
||||
M = new PopupMenu();
|
||||
ListElement e = H.last();
|
||||
int i = 0;
|
||||
final int n = Global.getParameter("history.length", 10);
|
||||
while (e != null && i < n) {
|
||||
final String t = (String) e.content();
|
||||
if (!t.equals("")) {
|
||||
final MenuItem item = new MenuItemAction(this, FileName
|
||||
.chop(t, MaxLength), t);
|
||||
M.add(item);
|
||||
}
|
||||
e = e.previous();
|
||||
i++;
|
||||
}
|
||||
add(M);
|
||||
}
|
||||
M.show(this, 10, 10);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void keyReleased(final KeyEvent e) {
|
||||
}
|
||||
|
||||
public void keyTyped(final KeyEvent e) {
|
||||
}
|
||||
|
||||
String Last = "";
|
||||
|
||||
public void remember(final String s) {
|
||||
if (s.equals(Last))
|
||||
return;
|
||||
deleteFromHistory(s);
|
||||
Last = s;
|
||||
H.last().content(s);
|
||||
H.append(new ListElement(""));
|
||||
M = null;
|
||||
}
|
||||
|
||||
public void deleteFromHistory(final String s) {
|
||||
ListElement e = H.first();
|
||||
while (e != null) {
|
||||
final String t = (String) e.content();
|
||||
final ListElement next = e.next();
|
||||
if (t.equals(s)) {
|
||||
H.remove(e);
|
||||
if (H.first() == null)
|
||||
H.append(new ListElement(""));
|
||||
}
|
||||
e = next;
|
||||
}
|
||||
}
|
||||
|
||||
public void remember() {
|
||||
remember(getText());
|
||||
}
|
||||
|
||||
public void saveHistory(final String name) {
|
||||
int i;
|
||||
final int n = Global.getParameter("history.length", 10);
|
||||
Global.removeAllParameters("history." + name);
|
||||
ListElement e = H.last();
|
||||
if (e == null)
|
||||
return;
|
||||
for (i = 0; i < n && e != null; e = e.previous()) {
|
||||
final String s = (String) e.content();
|
||||
if (!s.equals("")) {
|
||||
i++;
|
||||
Global.setParameter("history." + name + "." + i, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadHistory(final String name) {
|
||||
int i = 1;
|
||||
H = new ListClass();
|
||||
H.append(new ListElement(""));
|
||||
while (Global.haveParameter("history." + name + "." + i)) {
|
||||
final String s = Global.getParameter("history." + name + "." + i,
|
||||
"");
|
||||
if (!s.equals("") && filterHistory(s))
|
||||
H.prepend(new ListElement(s));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean filterHistory(final String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public ListClass getHistory() {
|
||||
return H;
|
||||
}
|
||||
|
||||
public void setTrigger(final boolean f) {
|
||||
Trigger = f;
|
||||
}
|
||||
|
||||
public void doAction(final String o) {
|
||||
if (!o.equals("")) {
|
||||
setText(o);
|
||||
if (Trigger)
|
||||
triggerAction();
|
||||
}
|
||||
}
|
||||
|
||||
public void itemAction(final String o, final boolean flag) {
|
||||
}
|
||||
|
||||
public static void main(final String args[]) {
|
||||
final CloseFrame f = new CloseFrame("test");
|
||||
final HistoryTextField t = new HistoryTextField(f, "Test", 30);
|
||||
t.remember("AAAA");
|
||||
t.remember("BBBB");
|
||||
t.remember("CCCC");
|
||||
t.remember("DDDD");
|
||||
f.setLayout(new BorderLayout());
|
||||
f.add("Center", t);
|
||||
f.add("South", new HistoryTextFieldChoice(t));
|
||||
f.pack();
|
||||
f.setVisible(true);
|
||||
}
|
||||
}
|
87
rene/gui/HistoryTextFieldChoice.java
Normal file
87
rene/gui/HistoryTextFieldChoice.java
Normal file
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
import rene.util.FileName;
|
||||
import rene.util.MyVector;
|
||||
import rene.util.list.ListClass;
|
||||
import rene.util.list.ListElement;
|
||||
|
||||
public class HistoryTextFieldChoice extends MyChoice implements ItemListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
HistoryTextField T;
|
||||
DoActionListener AL;
|
||||
MyVector V = new MyVector();
|
||||
public int MaxLength = 32;
|
||||
|
||||
public HistoryTextFieldChoice(final HistoryTextField t) {
|
||||
T = t;
|
||||
addItemListener(this);
|
||||
}
|
||||
|
||||
public void setDoActionListener(final DoActionListener al) {
|
||||
AL = al;
|
||||
}
|
||||
|
||||
public void itemStateChanged(final ItemEvent e) {
|
||||
final int n = getSelectedIndex();
|
||||
final String s = (String) V.elementAt(n);
|
||||
if (s.equals(" "))
|
||||
return;
|
||||
if (AL != null)
|
||||
AL.doAction(s);
|
||||
else
|
||||
T.doAction(s);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
removeAll();
|
||||
V.removeAllElements();
|
||||
final ListClass l = T.getHistory();
|
||||
ListElement e = l.last();
|
||||
if (e == null || ((String) e.content()).equals("")) {
|
||||
V.addElement(" ");
|
||||
add(" ");
|
||||
}
|
||||
while (e != null) {
|
||||
final String s = (String) e.content();
|
||||
if (!s.equals("")) {
|
||||
V.addElement(s);
|
||||
add(FileName.chop(s, MaxLength));
|
||||
}
|
||||
e = e.previous();
|
||||
}
|
||||
}
|
||||
|
||||
public String getRecent() {
|
||||
if (V.size() > 1)
|
||||
return (String) V.elementAt(1);
|
||||
else
|
||||
return "";
|
||||
}
|
||||
}
|
1795
rene/gui/IconBar.java
Normal file
1795
rene/gui/IconBar.java
Normal file
File diff suppressed because it is too large
Load diff
26
rene/gui/IconBarListener.java
Normal file
26
rene/gui/IconBarListener.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
public interface IconBarListener {
|
||||
void iconPressed(String name);
|
||||
}
|
71
rene/gui/IconBarPanel.java
Normal file
71
rene/gui/IconBarPanel.java
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
|
||||
/**
|
||||
* @author Rene A panel for two components. The left one uses its width.
|
||||
*
|
||||
*/
|
||||
public class IconBarPanel extends MyPanel {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
Component C1, C2;
|
||||
int IX = 0, IY = 0;
|
||||
|
||||
public IconBarPanel(final Component c1, final Component c2) {
|
||||
C1 = c1;
|
||||
C2 = c2;
|
||||
add(C1);
|
||||
add(C2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doLayout() {
|
||||
final int w = C1.getPreferredSize().width;
|
||||
C1.setSize(w, getSize().height - 2 * IY);
|
||||
C1.setLocation(IX, IY);
|
||||
C2.setSize(getSize().width - 3 * IX - w, getSize().height - 2 * IX);
|
||||
C2.setLocation(w + 2 * IX, IY);
|
||||
C1.doLayout();
|
||||
C2.doLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
final Dimension d1 = C1.getPreferredSize(), d2 = C2.getPreferredSize();
|
||||
return new Dimension(d1.width + d2.width, Math
|
||||
.max(d1.height, d2.height));
|
||||
}
|
||||
|
||||
public void setInsets(final int x, final int y) {
|
||||
IX = x;
|
||||
IY = y;
|
||||
}
|
||||
|
||||
public static void main(final String[] args) {
|
||||
}
|
||||
}
|
83
rene/gui/IntField.java
Normal file
83
rene/gui/IntField.java
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
/**
|
||||
* A TextField, which holds an integer number with minimal and maximal range.
|
||||
*/
|
||||
|
||||
public class IntField extends TextFieldAction {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public IntField(final DoActionListener l, final String name, final int v) {
|
||||
super(l, name, "" + v);
|
||||
}
|
||||
|
||||
public IntField(final DoActionListener l, final String name, final int v,
|
||||
final int cols) {
|
||||
super(l, name, "" + v, cols);
|
||||
}
|
||||
|
||||
public int value() {
|
||||
try {
|
||||
return Integer.parseInt(getText());
|
||||
} catch (final NumberFormatException e) {
|
||||
setText("" + 0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int value(final int min, final int max) {
|
||||
int n;
|
||||
try {
|
||||
n = Integer.parseInt(getText());
|
||||
} catch (final NumberFormatException e) {
|
||||
setText("" + min);
|
||||
return min;
|
||||
}
|
||||
if (n < min) {
|
||||
n = min;
|
||||
setText("" + min);
|
||||
}
|
||||
if (n > max) {
|
||||
n = max;
|
||||
setText("" + max);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public void set(final int v) {
|
||||
setText("" + v);
|
||||
}
|
||||
|
||||
public boolean valid() {
|
||||
try {
|
||||
Integer.parseInt(getText());
|
||||
} catch (final NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
76
rene/gui/KeyDictionary.java
Normal file
76
rene/gui/KeyDictionary.java
Normal file
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* This servers as a dictionary to make sure that the key translation will work
|
||||
* on localized systems too. The key recognition depends on the text translation
|
||||
* in KeyEvent. For user defined keyboards this will not matter, but this class
|
||||
* makes sure that it does not matter for the default keyboard.
|
||||
*/
|
||||
|
||||
class KeyDictionary {
|
||||
static Hashtable H;
|
||||
static {
|
||||
H = new Hashtable(100);
|
||||
put(KeyEvent.VK_F1, "f1");
|
||||
put(KeyEvent.VK_F2, "f2");
|
||||
put(KeyEvent.VK_F3, "f3");
|
||||
put(KeyEvent.VK_F4, "f4");
|
||||
put(KeyEvent.VK_F5, "f5");
|
||||
put(KeyEvent.VK_F6, "f6");
|
||||
put(KeyEvent.VK_F7, "f7");
|
||||
put(KeyEvent.VK_F8, "f8");
|
||||
put(KeyEvent.VK_F9, "f9");
|
||||
put(KeyEvent.VK_F10, "f10");
|
||||
put(KeyEvent.VK_F11, "f11");
|
||||
put(KeyEvent.VK_F12, "f12");
|
||||
put(KeyEvent.VK_LEFT, "left");
|
||||
put(KeyEvent.VK_RIGHT, "right");
|
||||
put(KeyEvent.VK_DOWN, "down");
|
||||
put(KeyEvent.VK_UP, "up");
|
||||
put(KeyEvent.VK_PAGE_DOWN, "page down");
|
||||
put(KeyEvent.VK_PAGE_UP, "page up");
|
||||
put(KeyEvent.VK_DELETE, "delete");
|
||||
put(KeyEvent.VK_BACK_SPACE, "backspace");
|
||||
put(KeyEvent.VK_INSERT, "insert");
|
||||
put(KeyEvent.VK_HOME, "home");
|
||||
put(KeyEvent.VK_END, "end");
|
||||
put(KeyEvent.VK_ESCAPE, "escape");
|
||||
put(KeyEvent.VK_TAB, "tab");
|
||||
put(KeyEvent.VK_ENTER, "enter");
|
||||
}
|
||||
|
||||
static void put(final int code, final String name) {
|
||||
H.put(new Integer(code), name);
|
||||
}
|
||||
|
||||
static String translate(final int code) {
|
||||
final Object o = H.get(new Integer(code));
|
||||
if (o != null)
|
||||
return (String) o;
|
||||
return KeyEvent.getKeyText(code);
|
||||
}
|
||||
}
|
287
rene/gui/Keyboard.java
Normal file
287
rene/gui/Keyboard.java
Normal file
|
@ -0,0 +1,287 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
/*
|
||||
This file contains a keyboard translater. It translates key strokes
|
||||
into text strings. The strings are menu descriptions and key
|
||||
descriptions. Menu descriptions are used to call menu entries in
|
||||
EditorFrame, and key descriptions are used in TextDisplay.
|
||||
<p>
|
||||
JE supports up to 5 command keys, which may be prepended to other
|
||||
keys. Those keys are mapped to command.X, where X is from 1 to 5.
|
||||
There is also a special escape command key, mapped to command.escape.
|
||||
<p>
|
||||
Some strings are contained in the properties, others may be defined by
|
||||
the user, and are contained in the parameter file "je.cfg". There is
|
||||
also an editor for the keystrokes, which uses the ItemEditor dialog.
|
||||
*/
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
|
||||
import rene.dialogs.ItemEditor;
|
||||
import rene.dialogs.MyFileDialog;
|
||||
import rene.util.sort.Sorter;
|
||||
|
||||
/**
|
||||
* A static class, which contains tranlations for key events. It keeps the
|
||||
* translations in a vector of KeyboardItem.
|
||||
* <p>
|
||||
* The class will statically generate the list of translations from the default
|
||||
* local properties and the JE configuration.
|
||||
*/
|
||||
|
||||
public class Keyboard {
|
||||
static Vector V;
|
||||
static Hashtable Hmenu, Hcharkey;
|
||||
|
||||
static {
|
||||
makeKeys();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the keys from the Global names and parameters, and put into a vector
|
||||
* and two hash tables for easy access.
|
||||
*/
|
||||
public static void makeKeys() {
|
||||
V = new Vector();
|
||||
Hmenu = new Hashtable();
|
||||
Hcharkey = new Hashtable();
|
||||
// collect all predefined keys
|
||||
Enumeration e = Global.names();
|
||||
if (e == null)
|
||||
return;
|
||||
while (e.hasMoreElements()) {
|
||||
final String key = (String) e.nextElement();
|
||||
if (key.startsWith("key.")) {
|
||||
final String menu = key.substring(4);
|
||||
String charkey = Global.getParameter(key, "default");
|
||||
final String normalcharkey = Global.name(key);
|
||||
if (charkey.equals("default"))
|
||||
charkey = normalcharkey;
|
||||
final KeyboardItem k = new KeyboardItem(menu, charkey);
|
||||
V.addElement(k);
|
||||
Hmenu.put(menu, k);
|
||||
Hcharkey.put(charkey, k);
|
||||
}
|
||||
}
|
||||
// collect all user defined (double defined) keys
|
||||
e = Global.properties();
|
||||
while (e.hasMoreElements()) {
|
||||
final String key = (String) e.nextElement();
|
||||
if (key.startsWith("key.")) {
|
||||
final String menu = key.substring(4);
|
||||
if (findMenu(menu) != null)
|
||||
continue;
|
||||
final String charkey = Global.getParameter(key, "default");
|
||||
if (charkey.equals("default"))
|
||||
continue;
|
||||
final KeyboardItem k = new KeyboardItem(menu, charkey);
|
||||
V.addElement(k);
|
||||
Hmenu.put(menu, k);
|
||||
Hcharkey.put(charkey, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a menu string in the key definitions
|
||||
*/
|
||||
public static KeyboardItem findMenu(final String menu) {
|
||||
final Object o = Hmenu.get(menu);
|
||||
if (o == null)
|
||||
return null;
|
||||
else
|
||||
return (KeyboardItem) o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a shortcut for the menu item.
|
||||
*/
|
||||
public static String shortcut(final String tag) {
|
||||
final Enumeration e = V.elements();
|
||||
while (e.hasMoreElements()) {
|
||||
final KeyboardItem item = (KeyboardItem) e.nextElement();
|
||||
if (item.getMenuString().equals(tag)) {
|
||||
String shortcut = item.shortcut();
|
||||
if (!shortcut.equals(""))
|
||||
shortcut = " (" + shortcut + ")";
|
||||
return shortcut;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* See, if the key event matches any of my translations, and get the menu
|
||||
* entry.
|
||||
*/
|
||||
public static String findKey(final KeyEvent event, final int type) {
|
||||
final Object o = Hcharkey.get(toCharKey(event, type));
|
||||
if (o == null)
|
||||
return "";
|
||||
String s = ((KeyboardItem) o).getMenuString();
|
||||
while (s.endsWith("*"))
|
||||
s = s.substring(0, s.length() - 1);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a keychar string from the event.
|
||||
*/
|
||||
public static String toCharKey(final KeyEvent e, final int type) {
|
||||
String s = "";
|
||||
if (type > 0)
|
||||
s = s + "esc" + type + ".";
|
||||
if (e.isShiftDown())
|
||||
s = s + "shift.";
|
||||
if (e.isControlDown())
|
||||
s = s + "control.";
|
||||
if (e.isAltDown())
|
||||
s = s + "alt.";
|
||||
return s + KeyDictionary.translate(e.getKeyCode()).toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit the translations.
|
||||
*/
|
||||
public static void edit(final Frame f) {
|
||||
final KeyboardItem keys[] = new KeyboardItem[V.size()];
|
||||
V.copyInto(keys);
|
||||
Sorter.sort(keys);
|
||||
final Vector v = new Vector();
|
||||
for (final KeyboardItem key2 : keys)
|
||||
v.addElement(key2);
|
||||
final KeyboardPanel p = new KeyboardPanel();
|
||||
final ItemEditor d = new ItemEditor(f, p, v, "keyeditor", Global
|
||||
.name("keyeditor.prompt"), true, false, true, Global
|
||||
.name("keyeditor.clearall"));
|
||||
p.setItemEditor(d);
|
||||
p.makeCommandChoice();
|
||||
d.center(f);
|
||||
d.setVisible(true);
|
||||
if (d.isAborted())
|
||||
return;
|
||||
Global.removeAllParameters("key.");
|
||||
V = d.getElements();
|
||||
Enumeration e = V.elements();
|
||||
while (e.hasMoreElements()) {
|
||||
final KeyboardItem k = (KeyboardItem) e.nextElement();
|
||||
if (!k.getCharKey().equals("default")) {
|
||||
final String keytag = "key." + k.getMenuString();
|
||||
final String description = k.keyDescription();
|
||||
if (!Global.name(keytag).toLowerCase().equals(description)) {
|
||||
Global.setParameter(keytag, description);
|
||||
}
|
||||
}
|
||||
}
|
||||
makeKeys();
|
||||
if (d.getAction() == ItemEditor.SAVE) {
|
||||
final Properties parameters = new Properties();
|
||||
e = Global.properties();
|
||||
while (e.hasMoreElements()) {
|
||||
final String key = (String) e.nextElement();
|
||||
if (key.startsWith("key."))
|
||||
parameters.put(key, Global.getParameter(key, "default"));
|
||||
}
|
||||
final MyFileDialog save = new MyFileDialog(f, Global.name("save"),
|
||||
Global.name("save"), true);
|
||||
save.setPattern("*.keys");
|
||||
save.center(f);
|
||||
save.update();
|
||||
save.setVisible(true);
|
||||
if (save.isAborted())
|
||||
return;
|
||||
final String filename = save.getFilePath();
|
||||
if (filename.equals(""))
|
||||
return; // aborted dialog!
|
||||
try {
|
||||
final FileOutputStream o = new FileOutputStream(filename);
|
||||
parameters.store(o, "JE Keyboard Definition");
|
||||
// parameters.save(o,"JE Keyboard Definition");
|
||||
} catch (final Exception ex) {
|
||||
}
|
||||
} else if (d.getAction() == ItemEditor.LOAD) {
|
||||
final Properties parameters = new Properties();
|
||||
final MyFileDialog load = new MyFileDialog(f, Global.name("load"),
|
||||
Global.name("load"), true);
|
||||
load.setPattern("*.keys");
|
||||
load.center(f);
|
||||
load.update();
|
||||
load.setVisible(true);
|
||||
if (load.isAborted())
|
||||
return;
|
||||
final String filename = load.getFilePath();
|
||||
if (filename.equals(""))
|
||||
return; // aborted dialog!
|
||||
try {
|
||||
final FileInputStream in = new FileInputStream(filename);
|
||||
parameters.load(in);
|
||||
} catch (final Exception ex) {
|
||||
}
|
||||
Global.removeAllParameters("key.");
|
||||
e = parameters.keys();
|
||||
while (e.hasMoreElements()) {
|
||||
final String key = (String) e.nextElement();
|
||||
Global.setParameter(key, (String) parameters.get(key));
|
||||
}
|
||||
makeKeys();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Append a list of keyboard shortcuts to a text area.
|
||||
*/
|
||||
public static Vector getKeys() {
|
||||
final Vector keys = new Vector();
|
||||
Sorter.sort(V);
|
||||
final Enumeration e = V.elements();
|
||||
while (e.hasMoreElements()) {
|
||||
final KeyboardItem k = (KeyboardItem) e.nextElement();
|
||||
if (!k.getCharKey().equals("none")) {
|
||||
String shortcut = k.shortcut();
|
||||
final int n = shortcut.length();
|
||||
for (int i = 0; i < 30 - n; i++)
|
||||
shortcut = shortcut + " ";
|
||||
keys.addElement(shortcut + " = " + k.getActionName());
|
||||
}
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a shortcut for the command.
|
||||
*/
|
||||
public static String commandShortcut(final int type) {
|
||||
final Object o = Hmenu.get("command." + type);
|
||||
if (o == null)
|
||||
return "";
|
||||
return ((KeyboardItem) o).shortcut();
|
||||
}
|
||||
}
|
158
rene/gui/KeyboardController.java
Normal file
158
rene/gui/KeyboardController.java
Normal file
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
|
||||
public class KeyboardController implements KeyListener {
|
||||
/** Macro and programs key pressed */
|
||||
boolean Escape = false;
|
||||
/** Note, if the next entry should be ignored or not */
|
||||
boolean IgnoreTyped = false;
|
||||
/** The type of the recent command key (1..5) */
|
||||
int CommandType = 0;
|
||||
/** The component, which we are listening to. */
|
||||
Component C = null;
|
||||
/** The primary and secondary KeyboardInterface */
|
||||
KeyboardInterface Primary = null, Secondary = null;
|
||||
|
||||
public synchronized void keyPressed(final KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_SHIFT)
|
||||
return;
|
||||
if (e.getKeyCode() == KeyEvent.VK_CONTROL)
|
||||
return;
|
||||
if (e.getKeyCode() == KeyEvent.VK_ALT)
|
||||
return;
|
||||
if (old(e))
|
||||
return;
|
||||
final String s = Keyboard.findKey(e, CommandType);
|
||||
// System.out.println(Escape+" "+CommandType+" "+s);
|
||||
IgnoreTyped = false;
|
||||
if (s.startsWith("command.")) {
|
||||
if (s.equals("command.escape")) {
|
||||
Escape = !Escape;
|
||||
} else
|
||||
try {
|
||||
CommandType = Integer.parseInt(s.substring(8));
|
||||
Escape = false;
|
||||
} catch (final Exception ex) {
|
||||
CommandType = 0;
|
||||
}
|
||||
IgnoreTyped = true;
|
||||
} else if (s.startsWith("charkey.")) {
|
||||
keyboardCommand(e, s);
|
||||
IgnoreTyped = true;
|
||||
Escape = false;
|
||||
CommandType = 0;
|
||||
} else if (Escape) {
|
||||
final char c = e.getKeyChar();
|
||||
IgnoreTyped = true;
|
||||
keyboardEscape(e, c);
|
||||
Escape = false;
|
||||
} else if (!s.equals("")) {
|
||||
keyboardCommand(e, s);
|
||||
IgnoreTyped = false;
|
||||
Escape = false;
|
||||
CommandType = 0;
|
||||
} else if (!e.isActionKey()) {
|
||||
if (!Global.getParameter("keyboard.compose", true)) {
|
||||
keyboardChar(e, e.getKeyChar());
|
||||
Escape = false;
|
||||
CommandType = 0;
|
||||
} else {
|
||||
Escape = false;
|
||||
CommandType = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void keyTyped(final KeyEvent e) {
|
||||
if (!Global.getParameter("keyboard.compose", true))
|
||||
return;
|
||||
// System.out.println("key typed "+IgnoreTyped+" "+e);
|
||||
if (IgnoreTyped)
|
||||
return;
|
||||
IgnoreTyped = false;
|
||||
keyboardChar(e, e.getKeyChar());
|
||||
Escape = false;
|
||||
CommandType = 0;
|
||||
}
|
||||
|
||||
public void keyReleased(final KeyEvent e) {
|
||||
}
|
||||
|
||||
public void keyboardCommand(final KeyEvent e, final String command) { // System.out.println(command);
|
||||
if (Primary == null || !Primary.keyboardCommand(e, command))
|
||||
if (Secondary != null)
|
||||
Secondary.keyboardCommand(e, command);
|
||||
}
|
||||
|
||||
public void keyboardEscape(final KeyEvent e, final char c) { // System.out.println("escape "+c);
|
||||
if (Primary == null || !Primary.keyboardEscape(e, c))
|
||||
if (Secondary != null)
|
||||
Secondary.keyboardEscape(e, c);
|
||||
}
|
||||
|
||||
public void keyboardChar(final KeyEvent e, final char c) { // System.out.println(""+c);
|
||||
if (Primary == null || !Primary.keyboardChar(e, c))
|
||||
if (Secondary != null)
|
||||
Secondary.keyboardChar(e, c);
|
||||
}
|
||||
|
||||
boolean scaled = false; // scaled already
|
||||
long scale; // the scaling in milliseconds
|
||||
|
||||
/**
|
||||
* Test for old keys. This algorithm uses the difference between event time
|
||||
* and system time. However, one needs to scale this first, since in Linux
|
||||
* both timers do not agree.
|
||||
*/
|
||||
boolean old(final KeyEvent e) {
|
||||
if (!scaled) {
|
||||
scaled = true;
|
||||
scale = System.currentTimeMillis() - e.getWhen();
|
||||
return false;
|
||||
}
|
||||
final long delay = System.currentTimeMillis() - e.getWhen() - scale;
|
||||
if (delay > 10000)
|
||||
return false; // function does not work!
|
||||
return (delay > 200);
|
||||
}
|
||||
|
||||
public void listenTo(final Component c) {
|
||||
if (C != null)
|
||||
C.removeKeyListener(this);
|
||||
C = c;
|
||||
if (C != null)
|
||||
C.addKeyListener(this);
|
||||
}
|
||||
|
||||
public void setPrimary(final KeyboardInterface i) {
|
||||
Primary = i;
|
||||
}
|
||||
|
||||
public void setSecondary(final KeyboardInterface i) {
|
||||
Secondary = i;
|
||||
}
|
||||
}
|
44
rene/gui/KeyboardInterface.java
Normal file
44
rene/gui/KeyboardInterface.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public interface KeyboardInterface {
|
||||
/**
|
||||
* Got a command string.
|
||||
*
|
||||
* @return Could handle command or not.
|
||||
*/
|
||||
public boolean keyboardCommand(KeyEvent e, String o);
|
||||
|
||||
/**
|
||||
* Got an escaped character. Escape works as macro key or call of external
|
||||
* programs in JE.
|
||||
*/
|
||||
public boolean keyboardEscape(KeyEvent e, char c);
|
||||
|
||||
/**
|
||||
* Got a character input.
|
||||
*/
|
||||
public boolean keyboardChar(KeyEvent e, char c);
|
||||
}
|
206
rene/gui/KeyboardItem.java
Normal file
206
rene/gui/KeyboardItem.java
Normal file
|
@ -0,0 +1,206 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import rene.dialogs.ItemEditorElement;
|
||||
import rene.util.sort.SortObject;
|
||||
|
||||
/**
|
||||
* A keyboard item. Can be constructed from a menu string (like
|
||||
* editor.file.open) and a key string (like control.o). Can test a key event, if
|
||||
* it fits.
|
||||
*/
|
||||
|
||||
public class KeyboardItem implements ItemEditorElement, SortObject {
|
||||
boolean Shift, Control, Alt;
|
||||
String CharKey;
|
||||
String MenuString, ActionName;
|
||||
int CommandType = 0;
|
||||
|
||||
/**
|
||||
* Copy constructor, for use in editing (clone).
|
||||
*/
|
||||
public KeyboardItem(final KeyboardItem item) {
|
||||
Shift = item.Shift;
|
||||
Control = item.Control;
|
||||
Alt = item.Alt;
|
||||
CharKey = item.CharKey;
|
||||
MenuString = item.MenuString;
|
||||
ActionName = item.ActionName;
|
||||
CommandType = item.CommandType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param charkey
|
||||
* The keyboard descriptive character (like "page down")
|
||||
* @param menustring
|
||||
* The menu item (may have some *s added)
|
||||
* @param actionname
|
||||
* The description of the menu item.
|
||||
* @param shift
|
||||
* ,control,alt Modifier flags.
|
||||
* @param commandtype
|
||||
* The command key, that is needed (0 is none).
|
||||
*/
|
||||
public KeyboardItem(final String charkey, final String menustring,
|
||||
final String actionname, final boolean shift,
|
||||
final boolean control, final boolean alt, final int commandtype) {
|
||||
Shift = shift;
|
||||
Control = control;
|
||||
Alt = alt;
|
||||
CharKey = charkey.toLowerCase();
|
||||
MenuString = menustring;
|
||||
ActionName = actionname;
|
||||
CommandType = commandtype;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param menu
|
||||
* The menu string.
|
||||
* @param key
|
||||
* The key descripion a la "esc1.shift.control.e"
|
||||
*/
|
||||
public KeyboardItem(final String menu, final String key) {
|
||||
MenuString = menu;
|
||||
Shift = Control = Alt = false;
|
||||
CommandType = 0;
|
||||
CharKey = "";
|
||||
final StringTokenizer t = new StringTokenizer(key, ".");
|
||||
while (t.hasMoreTokens()) {
|
||||
final String token = (String) t.nextToken();
|
||||
if (t.hasMoreTokens()) {
|
||||
if (token.equals("control"))
|
||||
Control = true;
|
||||
else if (token.equals("shift"))
|
||||
Shift = true;
|
||||
else if (token.equals("alt"))
|
||||
Alt = true;
|
||||
else if (token.startsWith("esc"))
|
||||
// esc should be followed by a number
|
||||
{
|
||||
try {
|
||||
CommandType = Integer.parseInt(token.substring(3));
|
||||
} catch (final Exception e) {
|
||||
}
|
||||
} else
|
||||
return;
|
||||
} else {
|
||||
if (key.equals(""))
|
||||
return;
|
||||
CharKey = token.toLowerCase();
|
||||
}
|
||||
}
|
||||
ActionName = Global.name(getStrippedMenuString());
|
||||
}
|
||||
|
||||
public String getMenuString() {
|
||||
return MenuString;
|
||||
}
|
||||
|
||||
public String getActionName() {
|
||||
return ActionName;
|
||||
}
|
||||
|
||||
public String getCharKey() {
|
||||
return CharKey;
|
||||
}
|
||||
|
||||
public boolean isShift() {
|
||||
return Shift;
|
||||
}
|
||||
|
||||
public boolean isControl() {
|
||||
return Control;
|
||||
}
|
||||
|
||||
public boolean isAlt() {
|
||||
return Alt;
|
||||
}
|
||||
|
||||
public int getCommandType() {
|
||||
return CommandType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a menu string, which is stripped from stars.
|
||||
*/
|
||||
public String getStrippedMenuString() {
|
||||
String s = MenuString;
|
||||
while (s.endsWith("*"))
|
||||
s = s.substring(0, s.length() - 1);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute a visible shortcut to append after the menu items (like
|
||||
* "(Ctr O)". The modifiers depend on the language.
|
||||
*/
|
||||
public String shortcut() {
|
||||
if (CharKey.equals("none"))
|
||||
return "";
|
||||
String s = CharKey.toUpperCase();
|
||||
if (Alt)
|
||||
s = Global.name("shortcut.alt") + " " + s;
|
||||
if (Control)
|
||||
s = Global.name("shortcut.control") + " " + s;
|
||||
if (Shift)
|
||||
s = Global.name("shortcut.shift") + " " + s;
|
||||
if (CommandType > 0)
|
||||
s = Keyboard.commandShortcut(CommandType) + " " + s;
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of this KeyboardItem element.
|
||||
*/
|
||||
public String getName() {
|
||||
return MenuString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method of SortObject, necessary to sort the keys by name.
|
||||
*/
|
||||
public int compare(final SortObject o) {
|
||||
return getName().compareTo(((KeyboardItem) o).getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a key description for this item (to save as parameter). This
|
||||
* should be the same as the key parameter in the constructor.
|
||||
*/
|
||||
public String keyDescription() {
|
||||
String s = CharKey.toLowerCase();
|
||||
if (s.equals("none") || s.equals("default"))
|
||||
return s;
|
||||
if (Alt)
|
||||
s = "alt." + s;
|
||||
if (Control)
|
||||
s = "control." + s;
|
||||
if (Shift)
|
||||
s = "shift." + s;
|
||||
if (CommandType > 0)
|
||||
s = "esc" + CommandType + "." + s;
|
||||
return s;
|
||||
}
|
||||
}
|
238
rene/gui/KeyboardPanel.java
Normal file
238
rene/gui/KeyboardPanel.java
Normal file
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Checkbox;
|
||||
import java.awt.Choice;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.TextField;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
import eric.JEricPanel;
|
||||
|
||||
import rene.dialogs.ItemEditor;
|
||||
import rene.dialogs.ItemEditorElement;
|
||||
import rene.dialogs.ItemPanel;
|
||||
|
||||
/**
|
||||
* This is used as the display panel for the keyboard editor. It displays
|
||||
* information about the selected keyboard item.
|
||||
*/
|
||||
|
||||
public class KeyboardPanel extends ItemPanel implements KeyListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
TextField MenuString, ActionName, CharKey;
|
||||
Checkbox Shift, Control, Alt;
|
||||
String Name = "";
|
||||
Choice C;
|
||||
ItemEditor E;
|
||||
|
||||
public KeyboardPanel() {
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
final JEricPanel center = new JEricPanel();
|
||||
center.setLayout(new GridLayout(0, 1));
|
||||
// the menu item
|
||||
center.add(MenuString = new MyTextField("", 30));
|
||||
MenuString.setEditable(false);
|
||||
// the description
|
||||
center.add(ActionName = new MyTextField());
|
||||
ActionName.setEditable(false);
|
||||
// the key
|
||||
center.add(CharKey = new MyTextField());
|
||||
CharKey.setEditable(false);
|
||||
CharKey.addKeyListener(this);
|
||||
// modifiers
|
||||
center.add(Shift = new Checkbox(Global.name("keyeditor.shift")));
|
||||
center.add(Control = new Checkbox(Global.name("keyeditor.control")));
|
||||
center.add(Alt = new Checkbox(Global.name("keyeditor.alt")));
|
||||
add("Center", center);
|
||||
|
||||
final JEricPanel south = new JEricPanel();
|
||||
south.setLayout(new BorderLayout());
|
||||
final JEricPanel c = new JEricPanel();
|
||||
// the choice of command keys
|
||||
C = new Choice();
|
||||
if (Global.NormalFont != null)
|
||||
C.setFont(Global.NormalFont);
|
||||
c.add(C);
|
||||
C.add("-------------");
|
||||
south.add("Center", c);
|
||||
// default and undefine buttons
|
||||
final JEricPanel buttons = new JEricPanel();
|
||||
buttons.add(new ButtonAction(this, Global.name("keyeditor.default"),
|
||||
"Default"));
|
||||
buttons.add(new ButtonAction(this, Global.name("keyeditor.none"),
|
||||
"None"));
|
||||
south.add("South", buttons);
|
||||
add("South", south);
|
||||
}
|
||||
|
||||
public void setItemEditor(final ItemEditor e) {
|
||||
E = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a list of available command keys.
|
||||
*/
|
||||
public void makeCommandChoice() {
|
||||
C.removeAll();
|
||||
C.add("");
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
final String s = commandShortcut(i);
|
||||
C.add(i + ": " + s);
|
||||
}
|
||||
C.select(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* The the command shortcut number i.
|
||||
*/
|
||||
public String commandShortcut(final int i) {
|
||||
final String s = "command." + i;
|
||||
final Enumeration e = E.getElements().elements();
|
||||
while (e.hasMoreElements()) {
|
||||
final KeyboardItem k = (KeyboardItem) e.nextElement();
|
||||
if (k.getMenuString().equals(s)) {
|
||||
return k.shortcut();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the key, if one is pressed inside the CharKey textfield.
|
||||
*/
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
Shift.setState(e.isShiftDown());
|
||||
Control.setState(e.isControlDown());
|
||||
Alt.setState(e.isAltDown());
|
||||
CharKey.setText(KeyDictionary.translate(e.getKeyCode()).toLowerCase());
|
||||
C.select(0);
|
||||
}
|
||||
|
||||
public void keyTyped(final KeyEvent e) {
|
||||
}
|
||||
|
||||
public void keyReleased(final KeyEvent e) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Override methods of ItemPanel
|
||||
*/
|
||||
|
||||
/**
|
||||
* Display this element on the panel.
|
||||
*/
|
||||
@Override
|
||||
public void display(final ItemEditorElement e) {
|
||||
final KeyboardItem k = (KeyboardItem) e;
|
||||
Name = k.getName();
|
||||
MenuString.setText(k.getMenuString());
|
||||
ActionName.setText(k.getActionName());
|
||||
CharKey.setText(k.getCharKey());
|
||||
MenuString.setText(k.getMenuString());
|
||||
Shift.setState(k.isShift());
|
||||
Control.setState(k.isControl());
|
||||
Alt.setState(k.isAlt());
|
||||
C.select(k.getCommandType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new keyboard element from the panel entries.
|
||||
*/
|
||||
@Override
|
||||
public ItemEditorElement getElement() {
|
||||
final int type = C.getSelectedIndex();
|
||||
return new KeyboardItem(CharKey.getText(), MenuString.getText(),
|
||||
ActionName.getText(), Shift.getState(), Control.getState(), Alt
|
||||
.getState(), type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(final String s) {
|
||||
Name = s;
|
||||
MenuString.setText(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test on doublicate keys, and undefine them.
|
||||
*/
|
||||
@Override
|
||||
public void notifyChange(final Vector v, final int item) {
|
||||
final KeyboardItem changed = (KeyboardItem) v.elementAt(item);
|
||||
final String descr = changed.keyDescription();
|
||||
for (int i = 0; i < v.size(); i++) {
|
||||
if (i == item)
|
||||
continue;
|
||||
final KeyboardItem k = (KeyboardItem) v.elementAt(i);
|
||||
if (k.keyDescription().equals(descr)) {
|
||||
v.setElementAt(new KeyboardItem(k.getMenuString(), "none"), i);
|
||||
}
|
||||
}
|
||||
if (changed.getMenuString().startsWith("command.")) {
|
||||
makeCommandChoice();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* React on the Default and None buttons.
|
||||
*/
|
||||
@Override
|
||||
public void doAction(final String o) {
|
||||
if (o.equals("Default")) {
|
||||
final String s = MenuString.getText();
|
||||
final KeyboardItem k = new KeyboardItem(s, Global.name("key." + s));
|
||||
CharKey.setText(k.getCharKey());
|
||||
Shift.setState(k.isShift());
|
||||
Control.setState(k.isControl());
|
||||
Alt.setState(k.isAlt());
|
||||
} else if (o.equals("None")) {
|
||||
CharKey.setText("none");
|
||||
Shift.setState(false);
|
||||
Control.setState(false);
|
||||
Alt.setState(false);
|
||||
} else
|
||||
super.doAction(o);
|
||||
}
|
||||
|
||||
/**
|
||||
* User wishes to clear all keyboard definitions.
|
||||
*/
|
||||
@Override
|
||||
public boolean extra(final Vector v) {
|
||||
v.removeAllElements();
|
||||
return true;
|
||||
}
|
||||
}
|
49
rene/gui/ListAction.java
Normal file
49
rene/gui/ListAction.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.List;
|
||||
|
||||
/**
|
||||
* A List class with a specified font and background. Designed for
|
||||
* DoActionListener objects.
|
||||
*/
|
||||
|
||||
public class ListAction extends List {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ListAction(final DoActionListener c, final String name) {
|
||||
addActionListener(new ActionTranslator(c, name));
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
}
|
||||
|
||||
public ListAction(final DoActionListener c, final String name, final int n) {
|
||||
super(n);
|
||||
addActionListener(new ActionTranslator(c, name));
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
}
|
||||
}
|
67
rene/gui/MenuItemAction.java
Normal file
67
rene/gui/MenuItemAction.java
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* A MenuItem with modifyable font.
|
||||
* <p>
|
||||
* This it to be used in DoActionListener interfaces.
|
||||
*/
|
||||
|
||||
class MenuItemActionTranslator implements ActionListener {
|
||||
String S;
|
||||
DoActionListener C;
|
||||
|
||||
public MenuItemActionTranslator(final DoActionListener c, final String s) {
|
||||
S = s;
|
||||
C = c;
|
||||
}
|
||||
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
C.doAction(S);
|
||||
}
|
||||
}
|
||||
|
||||
public class MenuItemAction extends MyMenuItem {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
MenuItemActionTranslator MIT;
|
||||
|
||||
public MenuItemAction(final DoActionListener c, final String s,
|
||||
final String st) {
|
||||
super(s);
|
||||
addActionListener(MIT = new MenuItemActionTranslator(c, st));
|
||||
}
|
||||
|
||||
public MenuItemAction(final DoActionListener c, final String s) {
|
||||
this(c, s, s);
|
||||
}
|
||||
|
||||
public void setString(final String s) {
|
||||
MIT.S = s;
|
||||
}
|
||||
}
|
37
rene/gui/MyCheckboxMenuItem.java
Normal file
37
rene/gui/MyCheckboxMenuItem.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.CheckboxMenuItem;
|
||||
|
||||
public class MyCheckboxMenuItem extends CheckboxMenuItem {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MyCheckboxMenuItem(final String s) {
|
||||
super(s);
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
}
|
||||
}
|
36
rene/gui/MyChoice.java
Normal file
36
rene/gui/MyChoice.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.Choice;
|
||||
|
||||
public class MyChoice extends Choice {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MyChoice() {
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
}
|
||||
}
|
66
rene/gui/MyLabel.java
Normal file
66
rene/gui/MyLabel.java
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.Container;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Label;
|
||||
|
||||
/**
|
||||
* A Label with a midifyable Font.
|
||||
*/
|
||||
|
||||
public class MyLabel extends javax.swing.JLabel {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MyLabel(final String s) {
|
||||
super(s);
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
}
|
||||
|
||||
public MyLabel(final String s, final int allign) {
|
||||
super(s, allign);
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is for Java 1.2 on Windows.
|
||||
*/
|
||||
@Override
|
||||
public void paint(final Graphics g) {
|
||||
final Container c = getParent();
|
||||
if (c != null)
|
||||
setBackground(c.getBackground());
|
||||
super.paint(g);
|
||||
}
|
||||
|
||||
public void setAlignment(final int align) {
|
||||
if (align == Label.CENTER) {
|
||||
this.setAlignmentX(0.5F);
|
||||
}
|
||||
}
|
||||
}
|
53
rene/gui/MyList.java
Normal file
53
rene/gui/MyList.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
|
||||
public class MyList extends java.awt.List implements KeyListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MyList(final int n) {
|
||||
super(n);
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
addKeyListener(this);
|
||||
}
|
||||
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
}
|
||||
|
||||
public void keyReleased(final KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||
processActionEvent(new ActionEvent(this,
|
||||
ActionEvent.ACTION_PERFORMED, ""));
|
||||
}
|
||||
}
|
||||
|
||||
public void keyTyped(final KeyEvent e) {
|
||||
}
|
||||
}
|
37
rene/gui/MyMenu.java
Normal file
37
rene/gui/MyMenu.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.Menu;
|
||||
|
||||
public class MyMenu extends Menu {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MyMenu(final String s) {
|
||||
super(s);
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
}
|
||||
}
|
37
rene/gui/MyMenuItem.java
Normal file
37
rene/gui/MyMenuItem.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.MenuItem;
|
||||
|
||||
public class MyMenuItem extends MenuItem {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MyMenuItem(final String s) {
|
||||
super(s);
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
}
|
||||
}
|
43
rene/gui/MyPanel.java
Normal file
43
rene/gui/MyPanel.java
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.Graphics;
|
||||
|
||||
import eric.JEricPanel;
|
||||
|
||||
public class MyPanel extends JEricPanel {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MyPanel() {
|
||||
repaint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(final Graphics g) {
|
||||
super.paint(g);
|
||||
getToolkit().sync();
|
||||
}
|
||||
}
|
37
rene/gui/MyPopupMenu.java
Normal file
37
rene/gui/MyPopupMenu.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.awt.Window;
|
||||
|
||||
public class MyPopupMenu extends Window {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MyPopupMenu() {
|
||||
super(new Frame());
|
||||
setSize(200, 200);
|
||||
}
|
||||
}
|
66
rene/gui/MyTextField.java
Normal file
66
rene/gui/MyTextField.java
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.TextField;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
|
||||
/**
|
||||
* A TextField with a modifyable background and font.
|
||||
*/
|
||||
|
||||
public class MyTextField extends TextField implements FocusListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MyTextField(final String s, final int n) {
|
||||
super(s, n);
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
addFocusListener(this);
|
||||
}
|
||||
|
||||
public MyTextField(final String s) {
|
||||
super(s);
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
addFocusListener(this);
|
||||
}
|
||||
|
||||
public MyTextField() {
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
addFocusListener(this);
|
||||
}
|
||||
|
||||
public void focusGained(final FocusEvent e) {
|
||||
setSelectionStart(0);
|
||||
}
|
||||
|
||||
public void focusLost(final FocusEvent e) {
|
||||
setSelectionStart(0);
|
||||
setSelectionEnd(0);
|
||||
}
|
||||
}
|
98
rene/gui/Panel3D.java
Normal file
98
rene/gui/Panel3D.java
Normal file
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.LayoutManager;
|
||||
|
||||
import eric.JEricPanel;
|
||||
|
||||
/**
|
||||
* Panel3D extends the JPanel class with a 3D look.
|
||||
*/
|
||||
|
||||
public class Panel3D extends JEricPanel implements LayoutManager {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
Component C;
|
||||
|
||||
/**
|
||||
* Adds the component to the panel. This component is resized to leave 5
|
||||
* pixel on each side.
|
||||
*/
|
||||
public Panel3D(final Component c) {
|
||||
C = c;
|
||||
setLayout(this);
|
||||
add(C);
|
||||
setBackground(C.getBackground());
|
||||
}
|
||||
|
||||
public Panel3D(final Component c, final Color background) {
|
||||
C = c;
|
||||
setLayout(this);
|
||||
add(C);
|
||||
setBackground(background);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void paintComponent(final Graphics g) {
|
||||
// g.setColor(getBackground());
|
||||
// if (getSize().width > 0 && getSize().height > 0)
|
||||
// g.fill3DRect(0, 0, getSize().width, getSize().height, true);
|
||||
// // C.repaint(); // probably not necessary, but Mac OSX bug ?!?
|
||||
// }
|
||||
|
||||
public void addLayoutComponent(final String arg0, final Component arg1) {
|
||||
C = arg1;
|
||||
}
|
||||
|
||||
public void removeLayoutComponent(final Component arg0) {
|
||||
C = null;
|
||||
}
|
||||
|
||||
public Dimension preferredLayoutSize(final Container arg0) {
|
||||
if (C != null)
|
||||
return new Dimension(C.getPreferredSize().width + 10, C
|
||||
.getPreferredSize().height + 10);
|
||||
return new Dimension(10, 10);
|
||||
}
|
||||
|
||||
public Dimension minimumLayoutSize(final Container arg0) {
|
||||
if (C != null)
|
||||
return new Dimension(C.getMinimumSize().width + 10, C
|
||||
.getMinimumSize().height + 10);
|
||||
return new Dimension(10, 10);
|
||||
}
|
||||
|
||||
public void layoutContainer(final Container arg0) {
|
||||
if (C == null)
|
||||
return;
|
||||
C.setLocation(5, 5);
|
||||
C.setSize(getSize().width - 10, getSize().height - 10);
|
||||
}
|
||||
}
|
72
rene/gui/SimplePanel.java
Normal file
72
rene/gui/SimplePanel.java
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
|
||||
/**
|
||||
* A panel with two components side by side. The size of the components is
|
||||
* determined by the weights.
|
||||
*/
|
||||
|
||||
public class SimplePanel extends MyPanel {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
Component C1, C2;
|
||||
double W;
|
||||
int IX = 0, IY = 0;
|
||||
|
||||
public SimplePanel(final Component c1, final double w1, final Component c2,
|
||||
final double w2) {
|
||||
C1 = c1;
|
||||
C2 = c2;
|
||||
W = w1 / (w1 + w2);
|
||||
add(C1);
|
||||
add(C2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doLayout() {
|
||||
final int w = (int) (getSize().width * W - 3 * IX);
|
||||
C1.setSize(w, getSize().height - 2 * IY);
|
||||
C1.setLocation(IX, IY);
|
||||
C2.setSize(getSize().width - 3 * IX - w, getSize().height - 2 * IX);
|
||||
C2.setLocation(w + 2 * IX, IY);
|
||||
C1.doLayout();
|
||||
C2.doLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
final Dimension d1 = C1.getPreferredSize(), d2 = C2.getPreferredSize();
|
||||
return new Dimension(d1.width + d2.width, Math
|
||||
.max(d1.height, d2.height));
|
||||
}
|
||||
|
||||
public void setInsets(final int x, final int y) {
|
||||
IX = x;
|
||||
IY = y;
|
||||
}
|
||||
}
|
107
rene/gui/TextFieldAction.java
Normal file
107
rene/gui/TextFieldAction.java
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.TextField;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
|
||||
/**
|
||||
* A TextField with a modifyable background and font. This is used in
|
||||
* DoActionListener interfaces.
|
||||
*/
|
||||
|
||||
public class TextFieldAction extends TextField implements FocusListener {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
protected ActionTranslator T;
|
||||
String S;
|
||||
|
||||
public TextFieldAction(final DoActionListener t, final String name,
|
||||
final String s) {
|
||||
super(s);
|
||||
S = s;
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
T = new ActionTranslator(t, name);
|
||||
addActionListener(T);
|
||||
addFocusListener(this);
|
||||
}
|
||||
|
||||
public TextFieldAction(final DoActionListener t, final String name) {
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
T = new ActionTranslator(t, name);
|
||||
addActionListener(T);
|
||||
addFocusListener(this);
|
||||
}
|
||||
|
||||
public TextFieldAction(final DoActionListener t, final String name,
|
||||
final int n) {
|
||||
super(n);
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
T = new ActionTranslator(t, name);
|
||||
addActionListener(T);
|
||||
addFocusListener(this);
|
||||
}
|
||||
|
||||
public TextFieldAction(final DoActionListener t, final String name,
|
||||
final String s, final int n) {
|
||||
super(s, n);
|
||||
S = s;
|
||||
if (Global.NormalFont != null)
|
||||
setFont(Global.NormalFont);
|
||||
T = new ActionTranslator(t, name);
|
||||
addActionListener(T);
|
||||
addFocusListener(this);
|
||||
}
|
||||
|
||||
public void triggerAction() {
|
||||
T.trigger();
|
||||
}
|
||||
|
||||
public void focusGained(final FocusEvent e) {
|
||||
setSelectionStart(0);
|
||||
}
|
||||
|
||||
public void focusLost(final FocusEvent e) {
|
||||
setSelectionStart(0);
|
||||
setSelectionEnd(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(final String s) {
|
||||
super.setText(s);
|
||||
S = s;
|
||||
}
|
||||
|
||||
public String getOldText() {
|
||||
return S;
|
||||
}
|
||||
|
||||
public boolean isChanged() {
|
||||
return !S.equals(getText());
|
||||
}
|
||||
}
|
39
rene/gui/TextFieldActionListener.java
Normal file
39
rene/gui/TextFieldActionListener.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
|
||||
Copyright 2006 Rene Grothmann, modified by 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 rene.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
class TextFieldActionListener implements ActionListener {
|
||||
DoActionListener C;
|
||||
String Name;
|
||||
|
||||
public TextFieldActionListener(final DoActionListener c, final String name) {
|
||||
C = c;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
C.doAction(Name);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue