Make first real commit: copy of CaRMetal 4.2.8

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

BIN
rene/.DS_Store vendored Normal file

Binary file not shown.

View file

@ -0,0 +1,161 @@
/*
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.dialogs;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Scrollbar;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import eric.JEricPanel;
import rene.gui.ButtonAction;
import rene.gui.CloseDialog;
import rene.gui.DoActionListener;
import rene.gui.Global;
import rene.gui.IntField;
import rene.gui.MyLabel;
import rene.gui.MyPanel;
import rene.gui.Panel3D;
class ColorScrollbar extends JEricPanel implements AdjustmentListener,
DoActionListener, FocusListener {
/**
*
*/
private static final long serialVersionUID = 1L;
public int Value;
ColorEditor CE;
Scrollbar SB;
IntField L;
public ColorScrollbar(final ColorEditor ce, final String s, final int value) {
CE = ce;
setLayout(new GridLayout(1, 0));
Value = value;
final JEricPanel p = new MyPanel();
p.setLayout(new GridLayout(1, 0));
p.add(new MyLabel(s));
p.add(L = new IntField(this, "L", Value, 4));
add(p);
add(SB = new Scrollbar(Scrollbar.HORIZONTAL, value, 40, 0, 295));
SB.addAdjustmentListener(this);
L.addFocusListener(this);
}
public void focusLost(final FocusEvent e) {
doAction("L");
}
public void focusGained(final FocusEvent e) {
doAction("L");
}
public void doAction(final String o) {
if ("L".equals(o)) {
Value = L.value(0, 255);
SB.setValue(Value);
CE.setcolor();
}
}
public void itemAction(final String o, final boolean flag) {
}
public void adjustmentValueChanged(final AdjustmentEvent e) {
Value = SB.getValue();
L.set(Value);
SB.setValue(Value);
CE.setcolor();
}
public int value() {
return L.value(0, 255);
}
}
/**
* A dialog to edit a color. The result is stored in the Global parameters under
* the specified name string.
*
* @see rene.gui.Global
*/
public class ColorEditor extends CloseDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
ColorScrollbar Red, Green, Blue;
Label RedLabel, GreenLabel, BlueLabel;
Color C;
JEricPanel CP;
String Name;
public ColorEditor(final Frame F, final String s, final Color c) {
super(F, Global.name("coloreditor.title"), true);
Name = s;
C = Global.getParameter(s, c);
if (C == null)
C = new Color(255, 255, 255);
final JEricPanel p = new MyPanel();
p.setLayout(new GridLayout(0, 1));
p.add(Red = new ColorScrollbar(this, Global.name("coloreditor.red"), C
.getRed()));
p.add(Green = new ColorScrollbar(this,
Global.name("coloreditor.green"), C.getGreen()));
p.add(Blue = new ColorScrollbar(this, Global.name("coloreditor.blue"),
C.getBlue()));
add("Center", new Panel3D(p));
final JEricPanel pb = new MyPanel();
pb.add(new ButtonAction(this, Global.name("OK"), "OK"));
pb.add(new ButtonAction(this, Global.name("abort"), "Close"));
add("South", new Panel3D(pb));
CP = new MyPanel();
CP.add(new MyLabel(Global.name("coloreditor.color")));
CP.setBackground(C);
add("North", new Panel3D(CP));
pack();
}
@Override
public void doAction(final String o) {
if ("Close".equals(o)) {
doclose();
} else if ("OK".equals(o)) {
setcolor();
Global.setParameter(Name, C);
doclose();
}
}
public void setcolor() {
C = new Color(Red.value(), Green.value(), Blue.value());
CP.setBackground(C);
CP.repaint();
}
}

View file

@ -0,0 +1,174 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.5" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,-15,0,0,2,35"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Component class="javax.swing.JFileChooser" name="jFileChooser1">
<Properties>
<Property name="dialogType" type="int" value="1"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="-1" gridY="-1" gridWidth="4" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="0" insetsBottom="0" insetsRight="0" anchor="11" weightX="0.5" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Container class="javax.swing.JPanel" name="jPanelOption">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
<TitledBorder title="Export options"/>
</Border>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="1" gridWidth="4" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="4" insetsBottom="4" insetsRight="4" anchor="10" weightX="0.5" weightY="0.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="Scale:"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="10" insetsBottom="5" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JSlider" name="jSliderScale">
<Properties>
<Property name="maximum" type="int" value="300"/>
</Properties>
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="jSliderScaleStateChanged"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="1" gridWidth="8" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="0" insetsBottom="5" insetsRight="0" anchor="10" weightX="0.5" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JSpinner" name="jSpinnerScale">
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="jSpinnerScaleStateChanged"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="9" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="18" ipadY="0" insetsTop="5" insetsLeft="0" insetsBottom="5" insetsRight="0" anchor="12" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel3">
<Properties>
<Property name="text" type="java.lang.String" value="Originale size:"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="10" insetsBottom="5" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel4">
<Properties>
<Property name="text" type="java.lang.String" value="Scaled size:"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="3" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="10" insetsBottom="5" insetsRight="0" anchor="17" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JTextField" name="jTextFieldOriginalWidth">
<Properties>
<Property name="editable" type="boolean" value="false"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="2" gridWidth="2" gridHeight="1" fill="2" ipadX="50" ipadY="0" insetsTop="0" insetsLeft="5" insetsBottom="5" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel5">
<Properties>
<Property name="text" type="java.lang.String" value="X"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="3" gridY="2" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="5" insetsBottom="5" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JTextField" name="jTextFieldOriginalHeight">
<Properties>
<Property name="editable" type="boolean" value="false"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="4" gridY="2" gridWidth="2" gridHeight="1" fill="2" ipadX="50" ipadY="0" insetsTop="0" insetsLeft="5" insetsBottom="5" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JTextField" name="jTextFieldScaledWidth">
<Properties>
<Property name="editable" type="boolean" value="false"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="3" gridWidth="2" gridHeight="1" fill="2" ipadX="50" ipadY="0" insetsTop="0" insetsLeft="5" insetsBottom="5" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel6">
<Properties>
<Property name="text" type="java.lang.String" value="X"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="3" gridY="3" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="5" insetsBottom="5" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JTextField" name="jTextFieldScaledHeight">
<Properties>
<Property name="editable" type="boolean" value="false"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="4" gridY="3" gridWidth="2" gridHeight="1" fill="2" ipadX="50" ipadY="0" insetsTop="0" insetsLeft="5" insetsBottom="5" insetsRight="0" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="jLabel7">
<Properties>
<Property name="text" type="java.lang.String" value="%"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="10" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="5" insetsLeft="4" insetsBottom="5" insetsRight="0" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View file

@ -0,0 +1,381 @@
/*
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.dialogs;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.border.TitledBorder;
import javax.swing.filechooser.FileSystemView;
import rene.gui.Global;
/**
*
* @author thecat
*/
public class ExportPictureDlg extends javax.swing.JDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
/** Creates new form ExportPictureDlg */
public ExportPictureDlg(final java.awt.Frame parent) {
super(parent, true);
initComponents();
final TitledBorder tb = (TitledBorder) jPanelOption.getBorder();
tb.setTitle(Global.Loc("pngdialog.options"));
jLabel2.setText(Global.Loc("pngdialog.scale"));
jLabel3.setText(Global.Loc("pngdialog.originsize"));
jLabel4.setText(Global.Loc("pngdialog.scaledsize"));
setPercentScale(100);
pictureHeight = 0;
pictureScaledWidth = 0;
final FileSystemView vueSysteme = FileSystemView.getFileSystemView();
final File def = vueSysteme.getHomeDirectory();
final File desk = vueSysteme.getChild(def, "Desktop");
final File choice = (desk == null) ? def : desk;
jFileChooser1.setCurrentDirectory(choice);
jFileChooser1.setAcceptAllFileFilterUsed(false);
jFileChooser1.addChoosableFileFilter(new ImageFilter());
jFileChooser1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(final java.awt.event.ActionEvent evt) {
if (evt.getActionCommand()
.equals(JFileChooser.CANCEL_SELECTION)) {
cancel();
} else if (evt.getActionCommand().equals(
JFileChooser.APPROVE_SELECTION)) {
ok();
}
}
});
setLocationRelativeTo(parent);
}
public boolean select() {
this.setVisible(true);
return finalResult;
}
private boolean finalResult = false;
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed"
// desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
jFileChooser1 = new javax.swing.JFileChooser();
jPanelOption = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jSliderScale = new javax.swing.JSlider();
jSpinnerScale = new javax.swing.JSpinner();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jTextFieldOriginalWidth = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jTextFieldOriginalHeight = new javax.swing.JTextField();
jTextFieldScaledWidth = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jTextFieldScaledHeight = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
getContentPane().setLayout(new java.awt.GridBagLayout());
jFileChooser1.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = 4;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
gridBagConstraints.weightx = 0.5;
getContentPane().add(jFileChooser1, gridBagConstraints);
jPanelOption.setBorder(javax.swing.BorderFactory
.createTitledBorder("Export options"));
jPanelOption.setLayout(new java.awt.GridBagLayout());
jLabel2.setText("Scale:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 0);
jPanelOption.add(jLabel2, gridBagConstraints);
jSliderScale.setMaximum(300);
jSliderScale.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(final javax.swing.event.ChangeEvent evt) {
jSliderScaleStateChanged(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 8;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 0.5;
gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 0);
jPanelOption.add(jSliderScale, gridBagConstraints);
jSpinnerScale.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(final javax.swing.event.ChangeEvent evt) {
jSpinnerScaleStateChanged(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 9;
gridBagConstraints.gridy = 1;
gridBagConstraints.ipadx = 18;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 0);
jPanelOption.add(jSpinnerScale, gridBagConstraints);
jLabel3.setText("Originale size:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 10, 5, 0);
jPanelOption.add(jLabel3, gridBagConstraints);
jLabel4.setText("Scaled size:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 10, 5, 0);
jPanelOption.add(jLabel4, gridBagConstraints);
jTextFieldOriginalWidth.setEditable(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.ipadx = 50;
gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
jPanelOption.add(jTextFieldOriginalWidth, gridBagConstraints);
jLabel5.setText("X");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 2;
gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
jPanelOption.add(jLabel5, gridBagConstraints);
jTextFieldOriginalHeight.setEditable(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.ipadx = 50;
gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
jPanelOption.add(jTextFieldOriginalHeight, gridBagConstraints);
jTextFieldScaledWidth.setEditable(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 3;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.ipadx = 50;
gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
jPanelOption.add(jTextFieldScaledWidth, gridBagConstraints);
jLabel6.setText("X");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 3;
gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
jPanelOption.add(jLabel6, gridBagConstraints);
jTextFieldScaledHeight.setEditable(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 3;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.ipadx = 50;
gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
jPanelOption.add(jTextFieldScaledHeight, gridBagConstraints);
jLabel7.setText("%");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 10;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(5, 4, 5, 0);
jPanelOption.add(jLabel7, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridwidth = 4;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.weightx = 0.5;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
getContentPane().add(jPanelOption, gridBagConstraints);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jSpinnerScaleStateChanged(
final javax.swing.event.ChangeEvent evt) {// GEN-FIRST:event_jSpinnerScaleStateChanged
final int value = ((Integer) jSpinnerScale.getValue()).intValue();
setPercentScale(value);
}// GEN-LAST:event_jSpinnerScaleStateChanged
private void jSliderScaleStateChanged(
final javax.swing.event.ChangeEvent evt) {// GEN-FIRST:event_jSliderScaleStateChanged
final int value = jSliderScale.getValue();
setPercentScale(value);
}// GEN-LAST:event_jSliderScaleStateChanged
public void ok() {
finalResult = true;
setVisible(false);
}
public void cancel() {
setVisible(false);
}
private int pictureHeight;
private int pictureWidth;
private int pictureScaledHeight;
private int pictureScaledWidth;
private int percentScale;
public int getPercentScale() {
return percentScale;
}
public void setPercentScale(final int percentScale) {
final int oldValue = this.percentScale;
this.percentScale = percentScale;
jSpinnerScale.setValue(new Integer(percentScale));
jSliderScale.setValue(percentScale);
final double scale = (double) percentScale / 100.0;
setPictureScaledWidth((int) (pictureWidth * scale));
setPictureScaledHeight((int) (pictureHeight * scale));
firePropertyChange("percentScale", oldValue, percentScale);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JFileChooser jFileChooser1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JPanel jPanelOption;
private javax.swing.JSlider jSliderScale;
private javax.swing.JSpinner jSpinnerScale;
private javax.swing.JTextField jTextFieldOriginalHeight;
private javax.swing.JTextField jTextFieldOriginalWidth;
private javax.swing.JTextField jTextFieldScaledHeight;
private javax.swing.JTextField jTextFieldScaledWidth;
// End of variables declaration//GEN-END:variables
public int getPictureHeight() {
return pictureHeight;
}
public void setPictureHeight(final int pictureHeight) {
final int oldValue = this.pictureHeight;
this.pictureHeight = pictureHeight;
jTextFieldOriginalHeight.setText(new Integer(getPictureHeight())
.toString());
firePropertyChange("pictureHeight", oldValue, pictureHeight);
}
public int getPictureWidth() {
return pictureWidth;
}
public int getPictureScaledHeight() {
return pictureScaledHeight;
}
public int getPictureScaledWidth() {
return pictureScaledWidth;
}
public void setPictureScaledWidth(final int pictureScaledWidth) {
final int oldValue = this.pictureScaledWidth;
this.pictureScaledWidth = pictureScaledWidth;
jTextFieldScaledWidth.setText(new Integer(getPictureScaledWidth())
.toString());
firePropertyChange("pictureScaledWidth", oldValue, pictureScaledWidth);
}
public void setPictureWidth(final int pictureWidth) {
final int oldValue = this.pictureWidth;
this.pictureWidth = pictureWidth;
jTextFieldOriginalWidth.setText(new Integer(getPictureWidth())
.toString());
firePropertyChange("pictureWidth", oldValue, pictureWidth);
}
public void setPictureScaledHeight(final int pictureScaledHeight) {
final int oldValue = this.pictureScaledHeight;
this.pictureScaledHeight = pictureScaledHeight;
jTextFieldScaledHeight.setText(new Integer(getPictureScaledHeight())
.toString());
firePropertyChange("pictureScaledHeight", oldValue, pictureScaledHeight);
}
public String getFileName() {
String result = "";
try {
final File outputfile = jFileChooser1.getSelectedFile();
final String strFilename = outputfile.getAbsolutePath();
final String ext = (outputfile.getAbsolutePath().endsWith(".png")) ? ""
: ".png";
result = strFilename + ext;
} catch (final Exception e) {
// warning(e.toString());
}
return result;
}
}

View file

@ -0,0 +1,208 @@
/*
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.dialogs;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.awt.TextField;
import eric.JEricPanel;
import rene.gui.ButtonAction;
import rene.gui.CheckboxAction;
import rene.gui.ChoiceAction;
import rene.gui.CloseDialog;
import rene.gui.Global;
import rene.gui.IntField;
import rene.gui.MyLabel;
import rene.gui.MyPanel;
import rene.gui.Panel3D;
import rene.gui.TextFieldAction;
/**
* A canvas to display a sample of the chosen font. The samples is drawn from
* the GetFontSize dialog.
*/
class ExampleCanvas extends Canvas {
/**
*
*/
private static final long serialVersionUID = 1L;
FontEditor GFS;
public ExampleCanvas(final FontEditor gfs) {
GFS = gfs;
}
@Override
public void paint(final Graphics g) {
GFS.example(g, getSize().width, getSize().height);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(200, 100);
}
}
/**
* A dialog to get the font size of the fixed font and its name. Both items are
* stored as a Global Parameter.
*/
public class FontEditor extends CloseDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
String FontTag;
TextField FontName;
IntField FontSize, FontSpacing;
Choice Fonts, Mode;
Canvas Example;
String E = Global.name("fonteditor.sample");
Checkbox Smooth;
/**
* @param fonttag
* ,fontdef the font name resource tag and its default value
* @param sizetag
* ,sizedef the font size resource tag and its default value
*/
public FontEditor(final Frame f, final String fonttag,
final String fontdef, final int sizedef) {
super(f, Global.name("fonteditor.title"), true);
FontTag = fonttag;
setLayout(new BorderLayout());
final JEricPanel p = new MyPanel();
p.setLayout(new GridLayout(0, 2));
p.add(new MyLabel(Global.name("fonteditor.name")));
p.add(FontName = new TextFieldAction(this, "FontName"));
FontName.setText(Global.getParameter(fonttag + ".name", fontdef));
p.add(new MyLabel(Global.name("fonteditor.available")));
// p.add(Fonts = new ChoiceAction(this, "Fonts"));
final String[] fonts = GraphicsEnvironment
.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
// String[] fonts=Toolkit.getDefaultToolkit().getFontList();
if (fonts != null) {
for (final String font2 : fonts) {
Fonts.add(font2);
}
} else {
Fonts.add("Dialog");
Fonts.add("SansSerif");
Fonts.add("Serif");
Fonts.add("Monospaced");
Fonts.add("DialogInput");
}
Fonts.add("Courier");
Fonts.add("TimesRoman");
Fonts.add("Helvetica");
Fonts.select(FontName.getText());
p.add(new MyLabel(Global.name("fonteditor.mode")));
// p.add(Mode = new ChoiceAction(this, "Mode"));
Mode.add(Global.name("fonteditor.plain"));
Mode.add(Global.name("fonteditor.bold"));
Mode.add(Global.name("fonteditor.italic"));
final String name = Global.getParameter(fonttag + ".mode", "plain");
if (name.startsWith("bold"))
Mode.select(1);
else if (name.startsWith("italic"))
Mode.select(2);
else
Mode.select(0);
p.add(new MyLabel(Global.name("fonteditor.size")));
p.add(FontSize = new IntField(this, "FontSize", Global.getParameter(
fonttag + ".size", sizedef)));
p.add(new MyLabel(Global.name("fonteditor.spacing")));
p.add(FontSpacing = new IntField(this, "FontSpacing", Global
.getParameter(fonttag + ".spacing", 0)));
p.add(new MyLabel(Global.name("fonteditor.antialias")));
p.add(Smooth = new CheckboxAction(this, "", "Smooth"));
Smooth.setState(Global.getParameter("font.smooth", true));
add("North", new Panel3D(p));
Example = new ExampleCanvas(this);
add("Center", new Panel3D(Example));
final JEricPanel bp = new MyPanel();
bp.add(new ButtonAction(this, Global.name("OK"), "OK"));
bp.add(new ButtonAction(this, Global.name("close"), "Close"));
add("South", new Panel3D(bp));
pack();
}
@Override
public void doAction(final String o) {
if ("OK".equals(o)) {
Global.setParameter(FontTag + ".name", FontName.getText());
String s = "plain";
if (mode() == Font.BOLD)
s = "bold";
else if (mode() == Font.ITALIC)
s = "Italic";
Global.setParameter(FontTag + ".mode", s);
Global.setParameter(FontTag + ".size", FontSize.value(3, 50));
Global.setParameter(FontTag + ".spacing", FontSpacing
.value(-10, 10));
Global.setParameter("font.smooth", Smooth.getState());
doclose();
} else
super.doAction(o);
Example.repaint();
}
@Override
public void itemAction(final String s, final boolean flag) {
FontName.setText(Fonts.getSelectedItem());
Example.repaint();
}
int mode() {
if (Mode.getSelectedItem().equals(Global.name("fonteditor.bold")))
return Font.BOLD;
else if (Mode.getSelectedItem()
.equals(Global.name("fonteditor.italic")))
return Font.ITALIC;
else
return Font.PLAIN;
}
public void example(final Graphics g, final int w, final int h) {
final Font f = new Font(FontName.getText(), mode(), FontSize.value(3,
50));
g.setFont(f);
final FontMetrics fm = g.getFontMetrics();
final int d = FontSpacing.value(-10, 10);
for (int i = 1; i <= 4; i++)
g.drawString(E, 5, 5 + d + i * d + fm.getLeading() + fm.getAscent()
+ i * fm.getHeight());
}
}

View file

@ -0,0 +1,118 @@
/*
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.dialogs;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import eric.JEricPanel;
import rene.gui.ButtonAction;
import rene.gui.CloseDialog;
import rene.gui.Global;
import rene.gui.HistoryTextField;
import rene.gui.MyLabel;
import rene.gui.MyPanel;
import rene.gui.Panel3D;
/**
* A simple dialog to scan for a parameter.
*/
public class GetParameter extends CloseDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
HistoryTextField Input;
static public int InputLength;
String Result = "";
boolean Aborted = true;
public GetParameter(final Frame f, final String title, final String prompt,
final String action) {
this(f, title, prompt, action, false);
}
public GetParameter(final Frame f, final String title, final String prompt,
final String action, final String subject) {
super(f, title, true);
Subject = subject;
Input = new HistoryTextField(this, "Action", InputLength);
Input.addKeyListener(this);
init(f, title, prompt, action, true);
}
public GetParameter(final Frame f, final String title, final String prompt,
final String action, final boolean help) {
super(f, title, true);
Input = new HistoryTextField(this, "Action", InputLength);
Input.addKeyListener(this);
init(f, title, prompt, action, help);
}
void init(final Frame f, final String title, final String prompt,
final String action, final boolean help) {
setLayout(new BorderLayout());
final JEricPanel center = new MyPanel();
center.setLayout(new GridLayout(0, 1));
center.add(new MyLabel(prompt));
center.add(Input);
add("Center", new Panel3D(center));
final JEricPanel south = new MyPanel();
south.setLayout(new FlowLayout(FlowLayout.RIGHT));
south.add(new ButtonAction(this, action, "Action"));
south.add(new ButtonAction(this, Global.name("abort"), "Abort"));
if (help)
south.add(new ButtonAction(this, Global.name("help", "Help"),
"Help"));
add("South", new Panel3D(south));
pack();
}
@Override
public void doAction(final String o) {
if (o.equals("Abort")) {
doclose();
} else if (o.equals("Action")) {
Result = Input.getText();
doclose();
Aborted = false;
} else
super.doAction(o);
}
public void set(final String s) {
Input.setText(s);
}
public String getResult() {
return Result;
}
public boolean aborted() {
return Aborted;
}
}

View file

@ -0,0 +1,65 @@
/*
Copyright 2006 Eric Hakenholz
This file is part of C.a.R. software.
C.a.R. is a free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
C.a.R. is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package rene.dialogs;
import java.io.File;
import javax.swing.filechooser.FileFilter;
public class ImageFilter extends FileFilter {
@Override
public boolean accept(final File f) {
if (f.isDirectory()) {
return true;
}
final String extension = this.getExtension(f);
if (extension != null) {
if (extension.equals("tiff") || extension.equals("tif")
|| extension.equals("svg") || extension.equals("gif")
|| extension.equals("jpeg") || extension.equals("jpg")
|| extension.equals("eps") || extension.equals("png")) {
return true;
} else {
return false;
}
}
return false;
}
@Override
public String getDescription() {
return "Images";
}
public String getExtension(final File f) {
String ext = null;
final String s = f.getName();
final int i = s.lastIndexOf('.');
if (i > 0 && i < s.length() - 1) {
ext = s.substring(i + 1).toLowerCase();
}
return ext;
}
}

View file

@ -0,0 +1,375 @@
/*
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.dialogs;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Vector;
import eric.JEricPanel;
import rene.gui.ButtonAction;
import rene.gui.CloseDialog;
import rene.gui.Global;
import rene.gui.MyLabel;
import rene.gui.MyList;
import rene.gui.MyPanel;
import rene.gui.Panel3D;
/**
* This is a general class to one in a list of items (like makros, plugins or
* tools in the JE editor).
*/
public class ItemEditor extends CloseDialog implements ItemListener {
/**
*
*/
private static final long serialVersionUID = 1L;
Frame F;
/** An AWT list at the left */
MyList L;
/** Aborted? */
boolean Aborted = true;
/** A vector of ItemEditorElement objects */
Vector V;
/** A panel to display the element settings */
ItemPanel P;
/** The name of this editor */
String Name;
/** The displayed item */
int Displayed = -1;
/** possible actions */
public final static int NONE = 0, SAVE = 1, LOAD = 2;
/** save or load action */
int Action = NONE;
/**
* @param p
* The item editor panel
* @param v
* The vector of item editor elements
* @param prompt
* The prompt, displayed in the north
*/
public ItemEditor(final Frame f, final ItemPanel p, final Vector v,
final String name, final String prompt) {
this(f, p, v, name, prompt, true, true, false, "");
}
public ItemEditor(final Frame f, final ItemPanel p, final Vector v,
final String name, final String prompt, final boolean allowChanges,
final boolean allowReorder, final boolean allowSave,
final String extraButton) {
super(f, Global.name(name + ".title"), true);
Name = name;
F = f;
P = p;
setLayout(new BorderLayout());
// Title String:
final JEricPanel title = new MyPanel();
title.add(new MyLabel(prompt));
add("North", title);
// Center panel:
final JEricPanel center = new MyPanel();
center.setLayout(new BorderLayout(5, 5));
// Element List:
center.add("West", L = new MyList(10));
L.addItemListener(this);
// Editor JPanel:
final JEricPanel cp = new MyPanel();
cp.setLayout(new BorderLayout());
cp.add("North", P);
cp.add("Center", new MyPanel());
center.add("Center", cp);
add("Center", new Panel3D(center));
// Buttons:
final JEricPanel buttons = new MyPanel();
buttons.setLayout(new GridLayout(0, 1));
if (allowChanges) {
final JEricPanel buttons1 = new MyPanel();
buttons1.add(new ButtonAction(this, Global
.name("itemeditor.insert"), "Insert"));
buttons1.add(new ButtonAction(this, Global.name("itemeditor.new"),
"New"));
buttons1.add(new ButtonAction(this, Global
.name("itemeditor.delete"), "Delete"));
buttons.add(buttons1);
}
if (allowReorder) {
final JEricPanel buttons2 = new MyPanel();
buttons2.add(new ButtonAction(this, Global.name("itemeditor.down"),
"Down"));
buttons2.add(new ButtonAction(this, Global.name("itemeditor.up"),
"Up"));
buttons.add(buttons2);
}
final JEricPanel buttons3 = new MyPanel();
buttons3.setLayout(new FlowLayout(FlowLayout.RIGHT));
buttons3.add(new ButtonAction(this, Global.name("OK"), "OK"));
buttons3.add(new ButtonAction(this, Global.name("abort"), "Close"));
buttons.add(buttons3);
if (allowSave) {
final JEricPanel buttons4 = new MyPanel();
buttons4.setLayout(new FlowLayout(FlowLayout.RIGHT));
buttons4.add(new ButtonAction(this, Global.name("save"), "Save"));
buttons4.add(new ButtonAction(this, Global.name("load"), "Load"));
if (!extraButton.equals("")) {
buttons4.add(new ButtonAction(this, extraButton, "Extra"));
}
buttons.add(buttons4);
}
add("South", new Panel3D(buttons));
V = new Vector();
for (int i = 0; i < v.size(); i++)
V.addElement(v.elementAt(i));
init();
pack();
}
/**
* @param v
* A vector of item editor elements.
*/
public void init() {
for (int i = 0; i < V.size(); i++) {
final ItemEditorElement e = (ItemEditorElement) V.elementAt(i);
L.add(e.getName());
}
if (V.size() > 0) {
L.select(0);
select();
}
}
/**
* React on Item changes.
*/
public void itemStateChanged(final ItemEvent e) {
if (e.getSource() == L) {
if (Displayed >= 0)
define(Displayed);
select();
}
}
/**
* Show the currently selected item on the item panel.
*/
public void select() {
final int i = L.getSelectedIndex();
if (i < 0)
return;
P.display((ItemEditorElement) V.elementAt(i));
Displayed = i;
}
@Override
public void doAction(final String o) {
if (o.equals("Delete")) {
delete();
} else if (o.equals("Insert")) {
insert();
} else if (o.equals("New")) {
P.newElement();
} else if (o.equals("Up")) {
up();
} else if (o.equals("Down")) {
down();
} else if (o.equals("OK")) {
noteSize(Name);
define();
Aborted = false;
doclose();
} else if (o.equals("Help")) {
P.help();
} else if (o.equals("Save")) {
define();
Action = SAVE;
Aborted = false;
doclose();
} else if (o.equals("Load")) {
define();
Action = LOAD;
Aborted = false;
doclose();
} else if (o.equals("Extra")) {
if (P.extra(V)) {
Aborted = false;
doclose();
}
} else
super.doAction(o);
}
/**
* Insert the current element, renaming if necessary.
*/
void insert() {
String name = P.getName();
int Selected = L.getSelectedIndex();
if (Selected < 0)
Selected = 0;
while (find(name))
name = name + "*";
P.setName(name);
final ItemEditorElement e = P.getElement();
L.add(e.getName(), Selected);
L.select(Selected);
V.insertElementAt(e, Selected);
}
/**
* Changes an item.
*/
void define(final int Selected) {
final String name = P.getName();
if (name.equals(""))
return;
if (!L.getItem(Selected).equals(name))
L.replaceItem(name, Selected);
V.setElementAt(P.getElement(), Selected);
P.notifyChange(V, Selected);
}
/**
* Changes the currently selected item.
*/
void define() {
final int Selected = L.getSelectedIndex();
if (Selected < 0)
return;
define(Selected);
L.select(Selected);
}
/**
* Find a plugin by name.
*
* @return true, if it exists.
*/
boolean find(final String name) {
int i;
for (i = 0; i < V.size(); i++) {
final ItemEditorElement t = ((ItemEditorElement) V.elementAt(i));
if (t.getName().equals(name))
return true;
}
return false;
}
/**
* Delete the current selected item.
*/
void delete() {
int Selected = L.getSelectedIndex();
if (Selected < 0)
return;
V.removeElementAt(Selected);
L.remove(Selected);
if (L.getItemCount() == 0)
return;
if (Selected >= L.getItemCount())
Selected--;
L.select(Selected);
select();
}
/**
* Push the selected item one down.
*/
void down() {
define();
int Selected = L.getSelectedIndex();
if (Selected < 0 || Selected + 1 >= V.size())
return;
final ItemEditorElement now = (ItemEditorElement) V.elementAt(Selected), next = (ItemEditorElement) V
.elementAt(Selected + 1);
V.setElementAt(next, Selected);
V.setElementAt(now, Selected + 1);
L.replaceItem(next.getName(), Selected);
L.replaceItem(now.getName(), Selected + 1);
Selected = Selected + 1;
L.select(Selected);
select();
}
/**
* Push the selected item one up.
*/
void up() {
define();
int Selected = L.getSelectedIndex();
if (Selected <= 0)
return;
final ItemEditorElement now = (ItemEditorElement) V.elementAt(Selected), prev = (ItemEditorElement) V
.elementAt(Selected - 1);
V.setElementAt(prev, Selected);
V.setElementAt(now, Selected - 1);
L.replaceItem(prev.getName(), Selected);
L.replaceItem(now.getName(), Selected - 1);
Selected = Selected - 1;
L.select(Selected);
select();
}
/**
* @return If aborted.
*/
@Override
public boolean isAborted() {
return Aborted;
}
/**
* @return The list of item elements.
*/
public Vector getElements() {
return V;
}
/**
* Return the action, if there is one
*
* @return NONE,LOAD,SAVE
*/
public int getAction() {
return Action;
}
}

View 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.dialogs;
public interface ItemEditorElement {
public String getName();
}

View file

@ -0,0 +1,84 @@
/*
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.dialogs;
import java.util.Vector;
import eric.JEricPanel;
import rene.gui.DoActionListener;
public class ItemPanel extends JEricPanel implements DoActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
public void display(final ItemEditorElement e) {
}
@Override
public String getName() {
return "";
}
@Override
public void setName(final String name) {
}
public ItemEditorElement getElement() {
return null;
}
public void newElement() {
}
public void help() {
}
public void doAction(final String o) {
}
public void itemAction(final String o, final boolean flag) {
}
/**
* Called, whenever an item is redefined.
*
* @param v
* The vector of KeyboardItem.
* @param item
* The currently changed item number.
*/
public void notifyChange(final Vector v, final int item) {
}
/**
* Called, when the extra Button was pressed.
*
* @v The vector of KeyboardItem.
* @return If the panel should be closed immediately.
*/
public boolean extra(final Vector v) {
return false;
}
}

View file

@ -0,0 +1,667 @@
/*
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.dialogs;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Component;
import java.awt.FileDialog;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;
import java.io.FilenameFilter;
import java.util.Enumeration;
import eric.JEricPanel;
import rene.gui.ButtonAction;
import rene.gui.CloseDialog;
import rene.gui.CloseFrame;
import rene.gui.DoActionListener;
import rene.gui.Global;
import rene.gui.HistoryTextField;
import rene.gui.HistoryTextFieldChoice;
import rene.gui.MyLabel;
import rene.gui.MyPanel;
import rene.gui.Panel3D;
import rene.gui.TextFieldAction;
import rene.lister.Lister;
import rene.lister.ListerMouseEvent;
import rene.util.FileList;
import rene.util.FileName;
import rene.util.MyVector;
class DirFieldListener implements DoActionListener {
MyFileDialog T;
public DirFieldListener(final MyFileDialog t) {
T = t;
}
public void doAction(final String o) {
T.setFile(o);
}
public void itemAction(final String o, final boolean flag) {
}
}
/**
* This is a file dialog. It is easy to handle, remembers its position and size,
* and performs pattern matching. The calls needs the rene.viewer.* class,
* unless you replace Lister with List everywhere. Moreover it needs the
* rene.gui.Global class to store field histories and determine the background
* color. Finally, it uses the FileList class to get the list of files.
* <p>
* The dialog does never check for files to exists. This must be done by the
* application.
* <p>
* There is a static main method, which demonstrates everything.
*/
public class MyFileDialog extends CloseDialog implements ItemListener,
FilenameFilter, MouseListener { // java.awt.List Dirs,Files;
/**
*
*/
private static final long serialVersionUID = 1L;
Lister Dirs, Files;
HistoryTextField DirField, FileField, PatternField;
HistoryTextFieldChoice DirHistory, FileHistory;
TextField Chosen;
String CurrentDir = ".";
boolean Aborted = true;
String DirAppend = "", PatternAppend = "", FileAppend = "";
Button Home;
Frame F;
/**
* @param title
* The dialog title.
* @param action
* The button string for the main action (e.g. Load)
* @param saving
* True, if this is a saving dialog.
*/
public MyFileDialog(final Frame f, final String title, final String action,
final boolean saving, final boolean help) {
super(f, title, true);
F = f;
setLayout(new BorderLayout());
// title prompt
add("North", new Panel3D(Chosen = new TextFieldAction(this, "")));
Chosen.setEditable(false);
// center panels
final JEricPanel center = new MyPanel();
center.setLayout(new GridLayout(1, 2, 5, 0));
Dirs = new Lister();
if (Global.NormalFont != null)
Dirs.setFont(Global.NormalFont);
Dirs.addActionListener(this);
Dirs.setMode(false, false, false, false);
center.add(Dirs);
Files = new Lister();
if (Global.NormalFont != null)
Files.setFont(Global.NormalFont);
Files.addActionListener(this);
Files.setMode(false, false, true, false);
center.add(Files);
add("Center", new Panel3D(center));
// south panel
final JEricPanel south = new MyPanel();
south.setLayout(new BorderLayout());
final JEricPanel px = new MyPanel();
px.setLayout(new BorderLayout());
final JEricPanel p0 = new MyPanel();
p0.setLayout(new GridLayout(0, 1));
final JEricPanel p1 = new MyPanel();
p1.setLayout(new BorderLayout());
p1.add("North", linePanel(new MyLabel(Global.name("myfiledialog.dir")),
DirField = new HistoryTextField(this, "Dir", 32) {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public boolean filterHistory(final String name)
// avoid a Windows bug with C: instead of c:
{
if (name.length() < 2)
return true;
if (name.charAt(1) == ':'
&& Character.isUpperCase(name.charAt(0)))
return false;
return true;
}
}));
DirField.setText(".");
p1.add("South", linePanel(new MyLabel(Global.name(
"myfiledialog.olddirs", "")),
DirHistory = new HistoryTextFieldChoice(DirField)));
p0.add(new Panel3D(p1));
final JEricPanel p2 = new MyPanel();
p2.setLayout(new BorderLayout());
p2.add("North", linePanel(
new MyLabel(Global.name("myfiledialog.file")),
FileField = new HistoryTextField(this, "File")));
p2.add("South", linePanel(new MyLabel(Global.name(
"myfiledialog.oldfiles", "")),
FileHistory = new HistoryTextFieldChoice(FileField)));
p0.add(new Panel3D(p2));
px.add("Center", p0);
px.add("South", new Panel3D(linePanel(new MyLabel(Global
.name("myfiledialog.pattern")),
PatternField = new HistoryTextField(this, "Pattern"))));
PatternField.setText("*");
south.add("Center", px);
final JEricPanel buttons = new MyPanel();
buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
// buttons.add(Home = new ButtonAction(this, Global.name(
// "myfiledialog.home", "Home"), "Home"));
buttons.add(new ButtonAction(this, Global.name("myfiledialog.mkdir",
"Create Directory"), "Create"));
buttons.add(new ButtonAction(this, Global.name("myfiledialog.back",
"Back"), "Back"));
buttons.add(new MyLabel(""));
buttons.add(new ButtonAction(this, action, "Action"));
buttons.add(new ButtonAction(this, Global.name("abort"), "Close"));
if (help) {
addHelp(buttons, "filedialog");
}
south.add("South", buttons);
add("South", new Panel3D(south));
// set sizes
pack();
setSize("myfiledialog");
addKeyListener(this);
DirField.addKeyListener(this);
DirField.setTrigger(true);
FileHistory.setDoActionListener(new DirFieldListener(this));
PatternField.addKeyListener(this);
PatternField.setTrigger(true);
FileField.addKeyListener(this);
FileField.setTrigger(true);
Home.addMouseListener(this);
}
JEricPanel linePanel(final Component x, final Component y) {
final JEricPanel p = new MyPanel();
p.setLayout(new GridLayout(1, 0));
p.add(x);
p.add(y);
return p;
}
public MyFileDialog(final Frame f, final String title, final String action,
final boolean saving) {
this(f, title, action, saving, false);
}
FileDialog FD;
public MyFileDialog(final Frame f, final String title, final boolean saving) {
super(f, "", true);
FD = new FileDialog(f, title, saving ? FileDialog.SAVE
: FileDialog.LOAD);
}
boolean HomeShiftControl = false;
public void mousePressed(final MouseEvent e) {
HomeShiftControl = e.isShiftDown() && e.isControlDown();
}
public void mouseReleased(final MouseEvent e) {
}
public void mouseClicked(final MouseEvent e) {
}
public void mouseEntered(final MouseEvent e) {
}
public void mouseExited(final MouseEvent e) {
}
@Override
public void doAction(final String o) {
if (o.equals("Dir") || o.equals("Pattern")) {
if (updateDir())
updateFiles();
PatternField.remember(PatternField.getText());
} else if (o.equals("File") || o.equals("Action")) {
if (FileField.getText().equals(""))
return;
leave();
} else if (o.equals("Home")) {
if (HomeShiftControl) {
final String s = Global.getParameter("myfiledialog.homdir", "");
if (s.equals(""))
Global.setParameter("myfiledialog.homdir", DirField
.getText());
else
Global.setParameter("myfiledialog.homdir", "");
}
try {
final String s = Global.getParameter("myfiledialog.homdir", "");
if (s.equals("")) {
final String s1 = System.getProperty("user.home");
final String s2 = Global.name("myfiledialog.windowshome",
"");
final String s3 = Global.name("myfiledialog.homedir", "");
final String sep = System.getProperty("file.separator");
if (new File(s1 + sep + s2 + sep + s3).exists())
DirField.setText(s1 + sep + s2 + sep + s3);
else if (new File(s1 + sep + s2).exists())
DirField.setText(s1 + sep + s2);
else
DirField.setText(s1);
} else
DirField.setText(s);
updateDir();
updateFiles();
} catch (final Exception e) {
}
} else if (o.equals("Create")) {
try {
final File f = new File(DirField.getText());
if (!f.exists()) {
f.mkdir();
}
updateDir();
updateFiles();
} catch (final Exception e) {
}
} else if (o.equals("Back")) {
final String dir = getUndo();
if (!dir.equals("")) {
DirField.setText(dir);
updateDir();
updateFiles();
}
} else
super.doAction(o);
}
@Override
public void actionPerformed(final ActionEvent e) {
if (e.getSource() == Dirs) {
final String s = Dirs.getSelectedItem();
if (s == null)
return;
if (s.equals(".."))
dirup();
else
dirdown(s);
}
if (e.getSource() == Files) {
if (e instanceof ListerMouseEvent) {
final ListerMouseEvent em = (ListerMouseEvent) e;
if (em.clickCount() >= 2)
leave();
else {
final String s = Files.getSelectedItem();
if (s != null)
FileField.setText(s);
}
}
} else
super.actionPerformed(e);
}
public void setFile(final String s) {
DirField.setText(FileName.path(s));
FileField.setText(FileName.filename(s));
// System.out.println(s);
update(false);
}
public void dirup() {
DirField.setText(FileName.path(CurrentDir));
if (DirField.getText().equals(""))
DirField.setText("" + File.separatorChar);
if (updateDir())
updateFiles();
}
public void dirdown(final String subdir) {
DirField.setText(CurrentDir + File.separatorChar + subdir);
if (updateDir())
updateFiles();
}
/**
* Leave the dialog and remember settings.
*/
void leave() {
if (FD != null)
return;
if (!FileField.getText().equals(""))
Aborted = false;
if (!Aborted) {
noteSize("myfiledialog");
DirField.remember(DirField.getText());
DirField.saveHistory("myfiledialog.dir.history" + DirAppend);
PatternField.saveHistory("myfiledialog.pattern.history"
+ PatternAppend);
FileField.remember(getFilePath());
FileField.saveHistory("myfiledialog.file.history" + FileAppend);
}
doclose();
}
/**
* Update the directory list.
*
* @return if the current content of DirField is indeed a directory.
*/
public boolean updateDir() {
if (FD != null)
return true;
final File dir = new File(DirField.getText() + File.separatorChar);
if (!dir.isDirectory())
return false;
try {
final String s = FileName.canonical(dir.getCanonicalPath());
addUndo(s);
DirField.setText(s);
Chosen.setText(FileName.chop(16, DirField.getText()
+ File.separatorChar + PatternField.getText(), 48));
} catch (final Exception e) {
return false;
}
return true;
}
MyVector Undo = new MyVector();
/**
* Note the directory in a history list.
*/
public void addUndo(final String dir) {
if (Undo.size() > 0
&& ((String) Undo.elementAt(Undo.size() - 1)).equals(dir))
return;
Undo.addElement(dir);
}
/**
* Get the undo directory and remove it.
*/
public String getUndo() {
if (Undo.size() < 2)
return "";
final String s = (String) Undo.elementAt(Undo.size() - 2);
Undo.truncate(Undo.size() - 1);
return s;
}
/**
* Update the file list.
*/
public void updateFiles() {
if (FD != null)
return;
final File dir = new File(DirField.getText());
if (!dir.isDirectory())
return;
CurrentDir = DirField.getText();
if (PatternField.getText().equals(""))
PatternField.setText("*");
try {
Files.clear();
Dirs.clear();
final FileList l = new FileList(DirField.getText(), PatternField
.getText(), false);
l.setCase(Global.getParameter("filedialog.usecaps", false));
l.search();
l.sort();
Enumeration e = l.files();
while (e.hasMoreElements()) {
final File f = (File) e.nextElement();
Files.addElement(FileName.filename(f.getCanonicalPath()));
}
Dirs.addElement("..");
e = l.dirs();
while (e.hasMoreElements()) {
final File f = (File) e.nextElement();
Dirs.addElement(FileName.filename(f.getCanonicalPath()));
}
} catch (final Exception e) {
}
Dirs.updateDisplay();
Files.updateDisplay();
Files.requestFocus();
}
public void setDirectory(final String dir) {
if (FD != null)
FD.setDirectory(dir);
else
DirField.setText(dir);
}
public void setPattern(final String pattern) {
if (FD != null) {
FD.setFilenameFilter(this); // does not work
final String s = pattern.replace(' ', ';');
FD.setFile(s);
} else
PatternField.setText(pattern);
}
public void setFilePath(final String file) {
if (FD != null) {
FD.setFile(file);
return;
}
final String dir = FileName.path(file);
if (!dir.equals("")) {
DirField.setText(dir);
FileField.setText(FileName.filename(file));
} else
FileField.setText(file);
}
/**
* Check, if the dialog was aborted.
*/
@Override
public boolean isAborted() {
if (FD != null)
return FD.getFile() == null || FD.getFile().equals("");
else
return Aborted;
}
/**
* @return The file plus its path.
*/
public String getFilePath() {
if (FD != null) {
if (FD.getFile() != null)
return FD.getDirectory() + FD.getFile();
else
return "";
}
final String file = FileField.getText();
if (!FileName.path(file).equals(""))
return file;
else
return CurrentDir + File.separatorChar + FileField.getText();
}
/**
* This should be called at the start.
*/
public void update(final boolean recent) {
if (FD != null)
return;
loadHistories(recent);
setFilePath(FileField.getText());
if (updateDir())
updateFiles();
Aborted = true;
}
public void update() {
update(true);
}
@Override
public void setVisible(final boolean flag) {
if (FD != null)
FD.setVisible(flag);
else
super.setVisible(flag);
}
@Override
public void center(final Frame f) {
if (FD != null)
CloseDialog.center(f, FD);
else
super.center(f);
}
public static void main(final String args[]) {
final Frame f = new CloseFrame() {
/**
*
*/
private static final long serialVersionUID = 1L;
@Override
public void doclose() {
System.exit(0);
}
};
f.setSize(500, 500);
f.setLocation(400, 400);
f.setVisible(true);
final MyFileDialog d = new MyFileDialog(f, "Title", "Save", false);
d.center(f);
d.update();
d.setVisible(true);
}
@Override
public void focusGained(final FocusEvent e) {
FileField.requestFocus();
}
/**
* Can be overwritten by instances to accept only some files.
*/
public boolean accept(final File dir, final String file) {
return true;
}
public void loadHistories(final boolean recent) {
if (FD != null)
return;
DirField.loadHistory("myfiledialog.dir.history" + DirAppend);
DirHistory.update();
if (recent)
setDirectory(DirHistory.getRecent());
if (updateDir())
updateFiles();
PatternField
.loadHistory("myfiledialog.pattern.history" + PatternAppend);
FileField.loadHistory("myfiledialog.file.history" + FileAppend);
FileHistory.update();
}
public void loadHistories() {
loadHistories(true);
}
/**
* Loads the histories from the configuration file. If you want a unique
* history for your instance, you need to give a string unique for your
* instance. There are three types of histories.
*
* @param dir
* @param pattern
* @param file
* @see loadHistories
*/
public void loadHistories(final String dir, final String pattern,
final String file) {
setAppend(dir, pattern, file);
loadHistories();
}
/**
* Histories are used for the directories, the files and the patterns. The
* dialog can use different histories for each instance of this class. If
* you want that, you need to determine the history for the instance with a
* string, unique for the instance. If a string is empty, "default" is used.
*
* @param dir
* @param pattern
* @param file
*/
public void setAppend(final String dir, final String pattern,
final String file) {
if (FD != null)
return;
if (!dir.equals(""))
DirAppend = "." + dir;
else
DirAppend = ".default";
if (!pattern.equals(""))
PatternAppend = "." + pattern;
else
PatternAppend = ".default";
if (!file.equals(""))
FileAppend = "." + file;
else
FileAppend = ".default";
}
public void itemStateChanged(final ItemEvent e) {
}
}

120
rene/dialogs/Question.java Normal file
View file

@ -0,0 +1,120 @@
/*
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.dialogs;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.event.ActionListener;
import eric.JEricPanel;
import rene.gui.ButtonAction;
import rene.gui.CloseDialog;
import rene.gui.Global;
import rene.gui.MyLabel;
import rene.gui.MyPanel;
/**
* This is a simple yes/no question. May be used as modal or non-modal dialog.
* Modal Question dialogs must be overriden to do something sensible with the
* tell method. In any case setVible(true) must be called in the calling
* program.
* <p>
* The static YesString and NoString may be overriden for foreign languages.
*/
public class Question extends CloseDialog implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
public int Result;
Object O;
Frame F;
public static int NO = 0, YES = 1, ABORT = -1;
public Question(final Frame f, final String c, final String title,
final Object o, final boolean abort, final boolean flag) {
super(f, title, flag);
F = f;
final JEricPanel pc = new MyPanel();
final FlowLayout fl = new FlowLayout();
pc.setLayout(fl);
fl.setAlignment(FlowLayout.CENTER);
pc.add(new MyLabel(" " + c + " "));
getContentPane().add("Center", pc);
final JEricPanel p = new MyPanel();
p.setLayout(new FlowLayout(FlowLayout.RIGHT));
p.add(new ButtonAction(this, Global.name("yes"), "Yes"));
p.add(new ButtonAction(this, Global.name("no"), "No"));
if (abort)
p.add(new ButtonAction(this, Global.name("abort"), "Abort"));
getContentPane().add("South", p);
O = o;
pack();
}
public Question(final Frame f, final String c, final String title,
final Object o, final boolean flag) {
this(f, c, title, o, true, flag);
}
public Question(final Frame f, final String c, final String title) {
this(f, c, title, null, true, true);
}
public Question(final Frame f, final String c, final String title,
final boolean abort) {
this(f, c, title, null, abort, true);
}
@Override
public void doAction(final String o) {
if (o.equals("Yes")) {
tell(this, O, YES);
} else if (o.equals("No")) {
tell(this, O, NO);
} else if (o.equals("Abort")) {
tell(this, O, ABORT);
Aborted = true;
}
}
/**
* Needs to be overriden for modal usage. Should dispose the dialog.
*/
public void tell(final Question q, final Object o, final int f) {
Result = f;
doclose();
}
/**
* @return if the user pressed yes.
*/
public boolean yes() {
return Result == YES;
}
public int getResult() {
return Result;
}
}

View file

@ -0,0 +1,349 @@
/*
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.dialogs;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent;
import java.io.File;
import java.util.Enumeration;
import eric.JEricPanel;
import rene.gui.ButtonAction;
import rene.gui.CheckboxAction;
import rene.gui.CloseDialog;
import rene.gui.Global;
import rene.gui.HistoryTextField;
import rene.gui.MyLabel;
import rene.gui.MyList;
import rene.gui.MyPanel;
import rene.gui.Panel3D;
import rene.util.FileList;
class FileListFinder extends FileList {
String Res;
public FileListFinder(final String dir, final String pattern,
final boolean recurse) {
super(dir, pattern, recurse);
}
@Override
public boolean file(final File file) {
try {
Res = file.getCanonicalPath();
} catch (final Exception e) {
}
return false;
}
public String getResult() {
return Res;
}
}
class SearchFileThread extends Thread {
SearchFileDialog D;
MyList L;
String Dir, Pattern;
boolean Recurse;
public SearchFileThread(final SearchFileDialog dialog, final MyList l,
final String d, final String p, final boolean r) {
D = dialog;
L = l;
Dir = d;
Pattern = p;
Recurse = r;
}
@Override
public void run() {
D.enableButtons(false);
L.removeAll();
L.setEnabled(false);
final FileList f = new FileList(Dir, Pattern, Recurse);
D.F = f;
f.search();
f.sort();
final Enumeration e = f.files();
while (e.hasMoreElements()) {
try {
L.add(((File) e.nextElement()).getCanonicalPath());
} catch (final Exception ex) {
}
}
L.setEnabled(true);
D.enableButtons(true);
}
}
/**
* This is a dialog to search a subtree for a specific file. The user can enter
* a directory and a file pattern containing * and ?. He can choose between
* immediate search and open, or search/select/open. Abort will result in an
* empty string. The calling routine checks the result file name with
* getResult().
* <p>
* You need to specify the following properties
*
* <pre>
* searchfile.title=Search File
* searchfile.directory=Directory
* searchfile.pattern=Pattern
* searchfile.search=Search
* searchfile.searchrek=Search Subdirectories
* </pre>
*/
public class SearchFileDialog extends CloseDialog implements Runnable,
Enumeration {
/**
*
*/
private static final long serialVersionUID = 1L;
HistoryTextField Dir, Pattern;
MyList L;
static public int ListNumber = Global.getParameter("searchfile.number", 10);
String Result = null;
Button ActionButton, CloseButton, SearchButton, SearchrekButton;
public FileList F = null;
public boolean Abort = true;
Checkbox Mod;
public SearchFileDialog(final Frame f, final String action,
final String modify, final boolean modifystate) {
super(f, Global.name("searchfile.title"), true);
setLayout(new BorderLayout());
final JEricPanel north = new MyPanel();
north.setLayout(new BorderLayout());
final JEricPanel northa = new MyPanel();
northa.setLayout(new BorderLayout());
final JEricPanel north1 = new MyPanel();
north1.setLayout(new GridLayout(0, 2));
north1.add(new MyLabel(Global.name("searchfile.directory")));
north1.add(Dir = new HistoryTextField(this, "Dir", 20));
Dir.setText(".");
north1.add(new MyLabel(Global.name("searchfile.pattern")));
north1.add(Pattern = new HistoryTextField(this, "TextAction", 20));
northa.add("Center", north1);
final JEricPanel north2 = new MyPanel();
// north2.add(SearchButton = new ButtonAction(this, Global
// .name("searchfile.search"), "Search"));
// north2.add(SearchrekButton = new ButtonAction(this, Global
// .name("searchfile.searchrek"), "SearchRek"));
northa.add("South", north2);
north.add("North", northa);
add("North", new Panel3D(north));
add("Center", new Panel3D(L = new MyList(ListNumber)));
L.addActionListener(this);
L.setMultipleMode(true);
final JEricPanel south = new MyPanel();
south.setLayout(new FlowLayout(FlowLayout.RIGHT));
if (!modify.equals("")) {
south.add(Mod = new CheckboxAction(this, modify, ""));
Mod.setState(modifystate);
}
// south.add(ActionButton = new ButtonAction(this, action, "Action"));
// south.add(CloseButton = new ButtonAction(this, Global.name("abort"),
// "Close"));
add("South", new Panel3D(south));
pack();
Dir.loadHistory("searchfile.dir");
Pattern.loadHistory("searchfile.pattern");
// size
setSize("searchfiledialog");
addKeyListener(this);
Dir.addKeyListener(this);
Pattern.addKeyListener(this);
}
public SearchFileDialog(final Frame f, final String action) {
this(f, action, "", false);
}
@Override
public void actionPerformed(final ActionEvent e) {
if (e.getSource() == L) {
action();
} else
super.actionPerformed(e);
}
@Override
public void doAction(final String o) {
Result = null;
if (o.equals("SearchRek"))
search(true);
else if (o.equals("Search"))
search(false);
else if (o.equals("TextAction")) {
L.removeAll();
action();
} else if (o.equals("Action"))
action();
else if (o.equals("Help"))
help();
else if (o.equals("Close")) {
Abort = true;
doclose();
}
}
public void help() {
}
Thread Run;
public void search(final boolean recurse) {
saveHistory();
if (Run != null && Run.isAlive())
return;
Run = new SearchFileThread(this, L, Dir.getText(), Pattern.getText(),
recurse);
Run.start();
}
public void action() {
saveHistory();
if (Run != null && Run.isAlive())
return;
Run = new Thread(this);
Run.start();
}
public void enableButtons(final boolean f) {
Pattern.setEnabled(f);
SearchButton.setEnabled(f);
SearchrekButton.setEnabled(f);
ActionButton.setEnabled(f);
}
public void run() {
Result = null;
enableButtons(false);
if (L.getItemCount() > 0) {
final int i = L.getSelectedIndex();
if (i > 0)
Result = L.getItem(i);
else
Result = L.getItem(0);
} else {
final FileListFinder f = new FileListFinder(Dir.getText(), Pattern
.getText(), true);
F = f;
f.search();
Result = f.getResult();
}
enableButtons(true);
Abort = false;
doclose();
}
public String getResult() {
return Result;
}
@Override
public void focusGained(final FocusEvent e) {
Pattern.requestFocus();
}
@Override
public void setVisible(final boolean flag) {
if (flag)
enableButtons(true);
super.setVisible(flag);
}
@Override
public boolean close() {
Abort = true;
return true;
}
@Override
public void doclose() {
if (F != null)
F.stopIt();
Dir.saveHistory("searchfile.dir");
Pattern.saveHistory("searchfile.pattern");
noteSize("searchfiledialog");
super.doclose();
}
public void saveHistory() {
Dir.remember();
Pattern.remember();
}
public void setPattern(final String s) {
Pattern.setText(s);
}
String S[];
int Sn;
/**
* Get an enumeration of selected files. Should check for an aborted dialog
* before.
*/
public Enumeration getFiles() {
S = L.getSelectedItems();
Sn = 0;
return this;
}
public boolean hasMoreElements() {
return Sn < S.length;
}
public Object nextElement() {
if (Sn >= S.length)
return null;
final String s = S[Sn];
Sn++;
return s;
}
@Override
public boolean isAborted() {
return Abort;
}
public void deselectAll() {
for (int i = L.getItemCount() - 1; i >= 0; i--) {
L.deselect(i);
}
}
public boolean isModified() {
return Mod.getState();
}
}

102
rene/dialogs/Warning.java Normal file
View file

@ -0,0 +1,102 @@
/*
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.dialogs;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionListener;
import eric.JEricPanel;
import rene.gui.ButtonAction;
import rene.gui.CloseDialog;
import rene.gui.Global;
import rene.gui.MyLabel;
import rene.gui.MyPanel;
/**
* This is a simple warning dialog. May be used as modal or non-modal dialog.
*/
public class Warning extends CloseDialog implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
public boolean Result;
Frame F;
public Warning(final Frame f, final String c, final String title,
final boolean flag, final String help) {
super(f, title, flag);
F = f;
final JEricPanel pc = new MyPanel();
final FlowLayout fl = new FlowLayout();
pc.setLayout(fl);
fl.setAlignment(FlowLayout.CENTER);
pc.add(new MyLabel(" " + c + " "));
add("Center", pc);
final JEricPanel p = new MyPanel();
p.add(new ButtonAction(this, Global.name("close"), "Close"));
if (help != null && !help.equals(""))
addHelp(p, help);
add("South", p);
pack();
}
public Warning(final Frame f, final String c, final String title,
final boolean flag) {
this(f, c, title, flag, "");
}
public Warning(final Frame f, final String c, final String title) {
this(f, c, title, true, "");
}
public Warning(final Frame f, final String c1, final String c2,
final String title, final boolean flag, final String help) {
super(f, title, flag);
F = f;
final JEricPanel pc = new MyPanel();
pc.setLayout(new GridLayout(0, 1));
pc.add(new MyLabel(" " + c1 + " "));
pc.add(new MyLabel(" " + c2 + " "));
add("Center", pc);
final JEricPanel p = new MyPanel();
p.add(new ButtonAction(this, Global.name("close"), "Close"));
if (help != null && !help.equals(""))
addHelp(p, help);
add("South", p);
pack();
}
public Warning(final Frame f, final String c1, final String c2,
final String title, final boolean flag) {
this(f, c1, c2, title, flag, "");
}
public Warning(final Frame f, final String c1, final String c2,
final String title) {
this(f, c1, c2, title, true, "");
}
}

View 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);
}
}

View 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;
// }
}

View 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));
}
}

View 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);
}
}
}

View 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);
}
}

View 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
View 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
View 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);
}
}

View 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();
}

View 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);
}

View 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

File diff suppressed because it is too large Load diff

View 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);
}
}

View 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

File diff suppressed because it is too large Load diff

View 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);
}

View 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
View 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;
}
}

View 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
View 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();
}
}

View 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;
}
}

View 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
View 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
View 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
View 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);
}
}

View 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;
}
}

View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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
View 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;
}
}

View 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());
}
}

View 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);
}
}

32
rene/lister/Element.java Normal file
View file

@ -0,0 +1,32 @@
/*
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.lister;
import java.awt.Color;
public interface Element {
public String getElementString(int state);
public String getElementString();
public Color getElementColor();
}

177
rene/lister/Lister.java Normal file
View file

@ -0,0 +1,177 @@
/*
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.lister;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.io.PrintWriter;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
public class Lister extends JScrollPane {
/**
*
*/
public ListerPanel L;
/**
* Initialize the display of vertical scrollbar
*
*/
public Lister() {
L=new ListerPanel(this);
setViewportView(L);
setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
setBorder(javax.swing.BorderFactory.createEmptyBorder());
setWheelScrollingEnabled(true);
getVerticalScrollBar().setUnitIncrement(16);
}
/**
* Return the lister for external use.
*
* @return lister panel
*/
public ListerPanel getLister() {
return L;
}
public void addActionListener(final ActionListener al) {
L.addActionListener(al);
}
public void updateDisplay() {
L.repaint();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
L.fixsize();
}
});
}
public void removeActionListener(final ActionListener al) {
L.removeActionListener(al);
}
public void clear() {
L.clear();
}
public void addElement(final Element el) {
L.add(el);
}
/**
* Get the first selected index.
*
* @return index or -1
*/
public int getSelectedIndex() {
if (L.Selected.size()>0) {
return ((Integer) L.Selected.elementAt(0)).intValue();
} else {
return -1;
}
}
public String getSelectedItem() {
final int n=getSelectedIndex();
if (n<0) {
return null;
}
return L.getElementAt(n).getElementString();
}
/**
* Get a vector of all selected indices.
*
* @return vector of indices
*/
public int[] getSelectedIndices() {
final int k[]=new int[L.Selected.size()];
for (int i=0; i<k.length; i++) {
k[i]=((Integer) L.Selected.elementAt(i)).intValue();
}
return k;
}
/**
* Make sure, the lister shows the last element.
*/
public void showLast() {
L.showLast();
}
/**
* Set the operations mode.
*
* @param multiple
* allows multiple clicks
* @param easymultiple
* multiple selection without control
* @param singleclick
* report single click events
* @param rightmouse
* report right mouse clicks
*/
public void setMode(final boolean multiple, final boolean easymultiple,
final boolean singleclick, final boolean rightmouse) {
L.MultipleSelection=multiple;
L.EasyMultipleSelection=easymultiple;
L.ReportSingleClick=singleclick;
L.RightMouseClick=rightmouse;
}
/**
* Print the lines to the printwriter o.
*
* @param o
*/
public void save(final PrintWriter o) {
L.save(o);
}
public void select(final int sel) {
}
/**
* Shortcut to add a string with a specific color.
*
* @param name
* @param col
*/
public void addElement(final String name, final Color col) {
addElement(new StringElement(name, col));
}
public void addElement(final String name) {
addElement(new StringElement(name));
}
public void setState(final int s) {
L.setState(s);
}
public void setListingBackground(final Color c) {
L.setListingBackground(c);
}
}

View file

@ -0,0 +1,56 @@
/*
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.lister;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
public class ListerMouseEvent extends ActionEvent {
/**
*
*/
private static final long serialVersionUID = 1L;
static int ID = 0;
MouseEvent E;
public ListerMouseEvent(final Object o, final String name,
final MouseEvent e) {
super(o, ID++, name);
E = e;
}
public MouseEvent getEvent() {
return E;
}
public String getName() {
return E.paramString();
}
public boolean rightMouse() {
return E.isMetaDown();
}
public int clickCount() {
return E.getClickCount();
}
}

View file

@ -0,0 +1,454 @@
/*
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.lister;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.font.FontRenderContext;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Vector;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import eric.JEricPanel;
import rene.gui.Global;
import rene.util.MyVector;
public class ListerPanel extends JEricPanel {
/**
*
*/
private static final long serialVersionUID=1L;
private final MyVector V; // Vector of listed Elements
int Top; // Top Element
Image I; // Buffer Image
int W, H; // width and height of current image
int panelHeight;
Graphics IG; // Graphics for the image
Font F; // current font
FontMetrics FM; // current font metrics
int Leading, Height, Ascent, Descent; // font stuff
int PageSize; // numbers of lines per page
int HOffset; // horizontal offset of display
boolean ShowLast; // Show last on next redraw
Lister LD;
String Name;
public Color ListingBackground=null;
public boolean MultipleSelection=true; // Allow multiple selection
public boolean EasyMultipleSelection=false; // Multiple select without
// right mouse
public boolean ReportSingleClick=false; // Report single clicks also
public boolean RightMouseClick=false; // Report right mouse clicks also
public ListerPanel(final Lister ld, final String name) {
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
LD=ld;
Name=name;
V=new MyVector();
Top=0;
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
clicked(e);
}
});
init();
}
public ListerPanel(final Lister ld) {
this(ld, "");
}
/**
* Paint routine. Simply sets up the buffer image, calls dopaint and paints
* the image to the screen.
*/
// @Override
@Override
public void paintComponent(final Graphics g) {
W=getSize().width;
H=getHeight();
I=createImage(W, H);
if (I==null) {
return;
}
IG=I.getGraphics();
init();
dopaint(IG);
g.drawImage(I, 0, 0, W, H, this);
double vp, vs, hp, hs;
if (V.size()>1) {
vp=(double) Top/V.size();
} else {
vp=0;
}
if (V.size()>2*PageSize) {
vs=(double) PageSize/V.size();
} else {
vs=0.5;
}
if (HOffset<10*W) {
hp=(double) HOffset/(10*W);
} else {
hp=0.9;
}
hs=0.1;
}
/**
* Initialize the font stuff and set the background of the panel.
*/
void init() {
F=new Font("Monospaced", 1, 14);
setFont(F);
FM=getFontMetrics(F);
Leading=FM.getLeading()
+Global.getParameter("fixedfont.spacing", -1);
Height=FM.getHeight()+3;
Ascent=FM.getAscent();
Descent=FM.getDescent();
// if (Global.Background!=null) setBackground(Global.Background);
if (Height+Leading>0) {
PageSize=H/(Height+Leading);
} else {
PageSize=10;
}
Top=0;
}
/**
* Paint the current text lines on the image.
*
* @param g
*/
public synchronized void dopaint(final Graphics g) {
Graphics2D g2=(Graphics2D) g;
g2.setColor(Color.white);
g2.fillRect(0, 0, W, H);
g2.setFont(F);
g2.setColor(Color.black);
int h=Leading+Ascent;
int line=Top;
if (line<0) {
return;
}
while (line-Top<PageSize&&line<V.size()) {
final Element el=(Element) V.elementAt(line);
if (isSelected(line)) {
g2.setColor(getBackground().darker());
g2.fillRect(0, h-Ascent, W, Height);
g2.setColor(Color.black);
}
final Color col=el.getElementColor();
if (col!=null) {
g2.setColor(col);
} else {
g2.setColor(Color.black);
}
g2.drawString(el.getElementString(State), 2-HOffset, h+1);
h+=Leading+Height;
line++;
}
}
public int getHeight() {
return (V.size()*(Leading+Height));
}
public void fixsize() {
fixsize(this, W, getHeight());
}
private static void fixsize(final JComponent cp, final int w, final int h) {
final Dimension d=new Dimension(w, h);
cp.setMaximumSize(d);
cp.setMinimumSize(d);
cp.setPreferredSize(d);
cp.setSize(d);
}
int State=0;
public void setState(final int s) {
State=s;
}
/**
* Add a new line of type rene.lister.Element
*
* @param e
*/
public synchronized void add(final Element e) {
V.addElement(e);
}
// Used by the mouse wheel or external programs:
public synchronized void up(final int n) {
Top+=n;
if (Top>=V.size()) {
Top=V.size()-1;
}
if (Top<0) {
Top=0;
}
repaint();
}
public synchronized void down(final int n) {
Top-=n;
if (Top<0) {
Top=0;
}
repaint();
}
public synchronized void pageUp() {
up(PageSize-1);
repaint();
}
public synchronized void pageDown() {
down(PageSize-1);
repaint();
}
/**
* Set the vertical position. Used by the scrollbars in the Lister.
*
* @param x
* percentage of text
*/
public synchronized void setVerticalPos(final double x) {
Top=(int) (x*V.size());
if (Top>=V.size()) {
Top=V.size()-1;
}
repaint();
}
/**
* Set the horizontal offset.
*
* @param x
* ofset in percent of 10 times the screen width
*/
public synchronized void setHorizontalPos(final double x) {
HOffset=(int) (x*10*W);
repaint();
}
/**
* Delete all items from the panel.
*/
public synchronized void clear() {
Selected.removeAllElements();
V.removeAllElements();
Top=0;
}
/**
* Make sure, the last element displays.
*/
public synchronized void showLast() {
ShowLast=true;
LD.getVerticalScrollBar().setValue(LD.getVerticalScrollBar().getMaximum());
}
// Mouse routines:
Vector VAL=new Vector(); // Vector of action listener
MyVector Selected=new MyVector(); // currently selected items
/**
* Determine if line sel is selected
*
* @param sel
* @return selected or not
*/
public synchronized boolean isSelected(final int sel) {
final Enumeration e=Selected.elements();
while (e.hasMoreElements()) {
final int n=((Integer) e.nextElement()).intValue();
if (n==sel) {
return true;
}
}
return false;
}
/**
* Toggle the line sel to be selected or not.
*
* @param sel
*/
public synchronized void toggleSelect(final int sel) {
final Enumeration e=Selected.elements();
while (e.hasMoreElements()) {
final Integer i=(Integer) e.nextElement();
if (i.intValue()==sel) {
Selected.removeElement(i);
return;
}
}
Selected.addElement(new Integer(sel));
}
/**
* Expand the selection to include sel and all elements in between.
*
* @param sel
*/
public synchronized void expandSelect(final int sel) { // compute maximal
// selected index
// below sel.
int max=-1;
Enumeration e=Selected.elements();
while (e.hasMoreElements()) {
final int i=((Integer) e.nextElement()).intValue();
if (i>max&&i<sel) {
max=i;
}
}
if (max>=0) {
for (int i=max+1; i<=sel; i++) {
select(i);
}
return;
}
int min=V.size();
e=Selected.elements();
while (e.hasMoreElements()) {
final int i=((Integer) e.nextElement()).intValue();
if (i<min&&i>sel) {
min=i;
}
}
if (min<V.size()) {
for (int i=sel; i<=min; i++) {
select(i);
}
}
}
/**
* Selecte an item by number sel.
*
* @param sel
*/
public synchronized void select(final int sel) {
if (!isSelected(sel)) {
Selected.addElement(new Integer(sel));
}
}
/**
* Add an action listener for all actions of this panel.
*
* @param al
*/
public void addActionListener(final ActionListener al) {
VAL.addElement(al);
}
/**
* Remove an action listener
*
* @param al
*/
public void removeActionListener(final ActionListener al) {
VAL.removeElement(al);
}
/**
* React on mouse clicks (single or double, or right click). single: select
* the item (according multiple mode) cause change action. double: select
* only this item and cause action. right: popup menu, if possible. In any
* case, report the result to the action listeners.
*
* @param e
*/
public void clicked(final MouseEvent e) {
final int n=e.getY()/(Leading+Height);
if (e.isMetaDown()&&RightMouseClick) {
final Enumeration en=VAL.elements();
while (en.hasMoreElements()) {
((ActionListener) (en.nextElement())).actionPerformed(new ListerMouseEvent(LD, Name, e));
}
} else {
if (Top+n>=V.size()) {
return;
}
final int sel=n+Top;
if (e.getClickCount()>=2) {
if (!MultipleSelection) {
Selected.removeAllElements();
}
select(sel);
} else if (MultipleSelection
&&(e.isControlDown()||EasyMultipleSelection||e.isShiftDown())) {
if (e.isControlDown()||EasyMultipleSelection) {
toggleSelect(sel);
} else if (e.isShiftDown()) {
expandSelect(sel);
}
} else {
Selected.removeAllElements();
Selected.addElement(new Integer(sel));
}
final Graphics g=getGraphics();
paint(g);
g.dispose();
if (e.getClickCount()>=2||ReportSingleClick) {
final Enumeration en=VAL.elements();
while (en.hasMoreElements()) {
((ActionListener) (en.nextElement())).actionPerformed(new ListerMouseEvent(LD, Name, e));
}
}
}
}
// @Override
// public Dimension getPreferredSize() {
// return new Dimension(200, 300);
// }
public synchronized Element getElementAt(final int n) {
return (Element) V.elementAt(n);
}
public synchronized void save(final PrintWriter o) {
final Enumeration e=V.elements();
while (e.hasMoreElements()) {
final Element el=(Element) e.nextElement();
o.println(el.getElementString());
}
}
public void setListingBackground(final Color c) {
ListingBackground=c;
}
}

View file

@ -0,0 +1,50 @@
/*
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.lister;
import java.awt.Color;
public class StringElement implements Element {
public String S;
public Color C;
public StringElement(final String s, final Color c) {
S = s;
C = c;
}
public StringElement(final String s) {
this(s, null);
}
public String getElementString() {
return S;
}
public String getElementString(final int state) {
return S;
}
public Color getElementColor() {
return C;
}
}

48
rene/lister/Wheel.java Normal file
View 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.lister;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
class Wheel implements MouseWheelListener {
WheelListener V;
public Wheel(final WheelListener v) {
V = v;
}
public void mouseWheelMoved(final MouseWheelEvent e) {
if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
if (e.getWheelRotation() > 0)
V.pageUp();
else
V.pageDown();
} else {
final int n = e.getScrollAmount();
if (e.getWheelRotation() > 0)
V.up(n);
else
V.down(n);
}
}
}

View file

@ -0,0 +1,32 @@
/*
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.lister;
public interface WheelListener {
void up(int n);
void down(int n);
void pageUp();
void pageDown();
}

281
rene/util/FileList.java Normal file
View file

@ -0,0 +1,281 @@
/*
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.util;
import java.io.File;
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.Vector;
import rene.util.sort.SortObject;
import rene.util.sort.Sorter;
class SortFile extends File implements SortObject {
/**
*
*/
private static final long serialVersionUID = 1L;
String S;
static int SortBy = 0;
final public static int NAME = 0, DATE = 1;
public SortFile(final File dir, final String name) {
super(dir, name);
try {
S = getCanonicalPath().toUpperCase();
} catch (final Exception e) {
S = "";
}
}
public int compare(final SortObject o) {
final SortFile f = (SortFile) o;
if (SortBy == DATE) {
final long n = f.lastModified();
final long m = lastModified();
if (n < m)
return -1;
if (n > m)
return 1;
return 0;
}
return -f.S.compareTo(S);
}
}
class FileFilter {
char F[][];
public FileFilter(final String s) {
final StringTokenizer t = new StringTokenizer(s);
final int n = t.countTokens();
F = new char[n][];
for (int i = 0; i < n; i++) {
F[i] = t.nextToken().toCharArray();
}
}
public char[] filter(final int i) {
return F[i];
}
public int filterCount() {
return F.length;
}
}
/**
* This class parses a subtree for files that match a pattern. The pattern may
* contain one or more * and ? as usual. The class delivers an enumerator for
* the files, or may be subclassed to handle the files directly. The routines
* directory and file can be used to return, if more scanning is necessary.
*/
public class FileList {
Vector V = new Vector(), Vdir = new Vector();
boolean Stop;
boolean Recurse;
String Dir, Filter;
boolean UseCase = false;
public FileList(final String dir, final String filter, final boolean recurse) {
Stop = false;
Recurse = recurse;
Dir = dir;
Filter = filter;
if (Dir.equals("-")) {
Dir = ".";
Recurse = false;
} else if (Dir.startsWith("-")) {
Dir = Dir.substring(1);
Recurse = false;
}
}
public FileList(final String dir, final String filter) {
this(dir, filter, true);
}
public FileList(final String dir) {
this(dir, "*", true);
}
public void setCase(final boolean usecase) {
UseCase = usecase;
}
public void search() {
Stop = false;
final File file = new File(Dir);
if (!UseCase)
Filter = Filter.toLowerCase();
if (file.isDirectory())
find(file, new FileFilter(Filter));
}
void find(final File dir, final FileFilter filter) {
if (!directory(dir))
return;
final String list[] = dir.list();
loop: for (int i = 0; i < list.length; i++) {
final SortFile file = new SortFile(dir, list[i]);
if (file.isDirectory()) {
Vdir.addElement(file);
if (Recurse)
find(file, filter);
} else {
String filename = file.getName();
if (!UseCase)
filename = filename.toLowerCase();
final char fn[] = filename.toCharArray();
for (int j = 0; j < filter.filterCount(); j++) {
if (match(fn, 0, filter.filter(j), 0)) {
Stop = !file(file);
if (Stop)
break loop;
V.addElement(file);
}
}
}
if (Stop)
break;
}
parsed(dir);
}
boolean match(final char filename[], final int n, final char filter[],
final int m) {
if (filter == null)
return true;
if (m >= filter.length)
return n >= filename.length;
if (n >= filename.length)
return m == filter.length - 1 && filter[m] == '*';
if (filter[m] == '?') {
return match(filename, n + 1, filter, m + 1);
}
if (filter[m] == '*') {
if (m == filter.length - 1)
return true;
for (int i = n; i < filename.length; i++) {
if (match(filename, i, filter, m + 1))
return true;
}
return false;
}
if (filter[m] == filename[n])
return match(filename, n + 1, filter, m + 1);
return false;
}
/**
* Return an Enumeration with the files.
*/
public Enumeration files() {
return V.elements();
}
/**
* Return an Enumeration with the directories.
*/
public Enumeration dirs() {
return Vdir.elements();
}
/**
* @return The number of files found.
*/
public int size() {
return V.size();
}
/**
* Sort the result.
*/
public void sort() {
int i, n = V.size();
SortObject v[] = new SortObject[n];
for (i = 0; i < n; i++)
v[i] = (SortFile) V.elementAt(i);
Sorter.sort(v);
for (i = 0; i < n; i++)
V.setElementAt(v[i], i);
n = Vdir.size();
v = new SortObject[n];
for (i = 0; i < n; i++)
v[i] = (SortFile) Vdir.elementAt(i);
Sorter.sort(v);
for (i = 0; i < n; i++)
Vdir.setElementAt(v[i], i);
}
public void sort(final int type) {
SortFile.SortBy = type;
sort();
SortFile.SortBy = SortFile.NAME;
}
/**
* @param file
* The directory that has been found.
* @return false if recursion should stop here. (i.e. that directory needs
* not be parsed).
*/
protected boolean directory(final File dir) {
return true;
}
/**
* @param file
* The file that has been found.
* @return false if you need no more file at all.
*/
protected boolean file(final File file) {
return true;
}
/**
* @param parsed
* The directory that has been parsed.
*/
protected void parsed(final File dir) {
}
/**
* This stops the search from other threads.
*/
public void stopIt() {
Stop = true;
}
/**
* Returns a canonical version of the directory
*/
public String getDir() {
final File dir = new File(Dir);
try {
return (dir.getCanonicalPath());
} catch (final Exception e) {
return "Dir does not exist!";
}
}
}

206
rene/util/FileName.java Normal file
View 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.util;
import java.io.File;
/**
* This is a static class to determine extensions etc. from a file name.
*/
public class FileName {
static public int ChopLength = 48;
static public String purefilename(final String filename) {
final char a[] = filename.toCharArray();
int i = a.length - 1;
final char fs = File.separatorChar;
while (i >= 0) {
if (a[i] == fs || a[i] == '/' || i == 0) {
if (i == 0)
i = -1;
if (i < a.length - 1) {
int j = a.length - 1;
while (j > i && a[j] != '.')
j--;
if (j > i + 1)
return new String(a, i + 1, j - i - 1);
else
return "";
} else
return "";
}
i--;
}
return filename;
}
static public String path(final String filename) {
final char a[] = filename.toCharArray();
int i = a.length - 1;
final char fs = File.separatorChar;
while (i > 0) {
if (a[i] == fs || a[i] == '/') {
return new String(a, 0, i);
}
i--;
}
return "";
}
static public String pathAndSeparator(final String filename) {
final char a[] = filename.toCharArray();
int i = a.length - 1;
final char fs = File.separatorChar;
while (i > 0) {
if (a[i] == fs || a[i] == '/') {
return new String(a, 0, i + 1);
}
i--;
}
return "";
}
static public String filename(final String filename) {
final char a[] = filename.toCharArray();
int i = a.length - 1;
final char fs = File.separatorChar;
while (i > 0) {
if (a[i] == fs || a[i] == '/') {
if (i + 1 < a.length)
return new String(a, i + 1, a.length - i - 1);
else
return "";
}
i--;
}
return filename;
}
static public String extension(final String filename) {
final char a[] = filename.toCharArray();
int i = a.length - 1;
final char fs = File.separatorChar;
while (i > 0) {
if (a[i] == '.') {
if (i + 1 < a.length)
return new String(a, i + 1, a.length - i - 1);
else
return "";
}
if (a[i] == fs || a[i] == '/')
break;
i--;
}
return "";
}
static public String chop(String filename, final int chop)
// chop the filename to 32 characters
{
if (filename.length() > chop) {
filename = "... " + filename.substring(filename.length() - chop);
}
return filename;
}
static public String chop(final String filename) {
return chop(filename, ChopLength);
}
static public String chop(final int start, String filename, final int chop)
// chop the filename.substring(start) to 32 characters
{
if (filename.length() > start + chop) {
filename = filename.substring(0, start) + " ... "
+ filename.substring(filename.length() - chop);
}
return filename;
}
static public String chop(final int start, final String filename) {
return chop(start, filename, ChopLength);
}
static public String relative(String dir, final String filename) {
dir = dir + System.getProperty("file.separator");
if (filename.startsWith(dir)) {
return filename.substring(dir.length());
} else
return filename;
}
static public String canonical(final String filename) {
final File f = new File(filename);
try {
String s = f.getCanonicalPath();
if (s.length() > 2 && s.charAt(1) == ':')
s = s.substring(0, 2).toLowerCase() + s.substring(2);
return s;
} catch (final Exception e) {
return f.getAbsolutePath();
}
}
static public String toURL(final String filename) {
final int n = filename.indexOf(' ');
if (n >= 0)
return filename.substring(0, n) + "%20"
+ toURL(filename.substring(n + 1));
else
return filename;
}
static boolean match(final char filename[], final int n,
final char filter[], final int m) {
if (filter == null)
return true;
if (m >= filter.length)
return n >= filename.length;
if (n >= filename.length)
return m == filter.length - 1 && filter[m] == '*';
if (filter[m] == '?') {
return match(filename, n + 1, filter, m + 1);
}
if (filter[m] == '*') {
if (m == filter.length - 1)
return true;
for (int i = n; i < filename.length; i++) {
if (match(filename, i, filter, m + 1))
return true;
}
return false;
}
if (filter[m] == filename[n])
return match(filename, n + 1, filter, m + 1);
return false;
}
public static boolean match(final String filename, final String filter) {
final char fn[] = filename.toCharArray(), f[] = filter.toCharArray();
return match(fn, 0, f, 0);
}
public static void main(final String args[]) {
System.out.println("-" + toURL(" test test test ") + "-");
}
}

View file

@ -0,0 +1,61 @@
/*
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.util;
import java.awt.Image;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
/**
* @author unknown Class to hold an image for the clipboad, implements the
* Transferable class properly.
*/
public class ImageSelection implements Transferable {
// the Image object which will be housed by the ImageSelection
private final Image image;
public ImageSelection(final Image image) {
this.image = image;
}
// Returns the supported flavors of our implementation
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { DataFlavor.imageFlavor };
}
// Returns true if flavor is supported
public boolean isDataFlavorSupported(final DataFlavor flavor) {
return DataFlavor.imageFlavor.equals(flavor);
}
// Returns Image object housed by Transferable object
public Object getTransferData(final DataFlavor flavor)
throws UnsupportedFlavorException, IOException {
if (!DataFlavor.imageFlavor.equals(flavor)) {
throw new UnsupportedFlavorException(flavor);
}
// else return the payload
return image;
}
}

325
rene/util/MyVector.java Normal file
View file

@ -0,0 +1,325 @@
/*
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.util;
import java.util.Enumeration;
/**
* This is a more effective replacement of the Vector class. It is based on a
* growing array. If an object is removed, it is replaced by null. The class
* knows about the first null object (the gap). Searching for elements or other
* operations automatically compress the array by copying the elements upwards,
* but only as far as they need to go anyway.
*
* Accessing an element is very effective, at least the second time. If you want
* to make sure, it is always effective, compress first. The most effective way
* is to get the object array itself.
*
* The objects can be enumerated. The object returned by nextElement() is found
* very rapidly. E.g. it can be deleted at once.
*
* Enumeration is not reentrant. Do it only once each time.
*
* Nothing in this class is synchronized!
**/
public class MyVector implements Enumeration {
Object O[];
int OSize, ON, OLast, Gap;
int EN = 0;
public MyVector(final int initsize) {
O = new Object[initsize];
OSize = initsize;
OLast = ON = 0;
Gap = -1;
}
public MyVector() {
this(8);
}
/**
* Add an element. Extend the array, if necessary.
*/
public void addElement(final Object o) {
if (OLast >= OSize)
extend();
O[OLast++] = o;
ON++;
}
/**
* Extend the array, or get space by compressing it.
*/
public void extend() {
if (ON < OLast / 2) {
compress();
return;
}
final Object o[] = new Object[2 * OSize];
System.arraycopy(O, 0, o, 0, OLast);
OSize *= 2;
O = o;
}
/**
* Compress the array.
*/
public void compress() {
if (Gap < 0)
return;
int k = Gap;
for (int i = Gap; i < OLast; i++) {
if (O[i] == null)
continue;
O[k++] = O[i];
}
ON = k;
for (int i = k; i < OLast; i++)
O[i] = null;
Gap = -1;
OLast = ON;
}
/**
* Get an enumeration of this array.
*/
public Enumeration elements() {
compress();
EN = 0;
return this;
}
/**
* Method for Enumeration.
*/
public boolean hasMoreElements() {
while (EN < OLast && O[EN] == null)
EN++;
return EN < OLast;
}
/**
* Method for Enumeration.
*/
public Object nextElement() {
if (!hasMoreElements())
throw new ArrayIndexOutOfBoundsException(OLast);
return O[EN++];
}
/**
* Clear this array, but keep its memory!
*/
public void removeAllElements() {
for (int i = 0; i < OLast; i++)
O[i] = null;
ON = OLast = 0;
Gap = -1;
}
/**
* Remove a single element. This will also compress the part below the
* element, or all, if it is not found.
*/
public void removeElement(final Object o) {
final int i = indexOf(o);
if (i < 0)
return;
O[i] = null;
ON--;
if (Gap < 0 || Gap > i)
Gap = i;
if (i == OLast - 1)
OLast--;
while (OLast > 0 && O[OLast - 1] == null)
OLast--;
if (Gap >= OLast)
Gap = -1;
}
/**
* Find an element. Compress on the way. Check for the last element,
* returned by nextElement() first. Equality is checked with the equal()
* function.
*
* @return -1, if not found.
*/
public int indexOf(final Object o) {
if (EN > 0 && EN <= OLast && O[EN - 1].equals(o))
return EN - 1;
if (Gap < 0) {
for (int i = 0; i < OLast; i++) {
if (O[i].equals(o))
return i;
}
return -1;
}
for (int i = 0; i < Gap; i++) {
if (O[i].equals(o))
return i;
}
int k = Gap;
for (int i = Gap; i < OLast; i++) {
if (O[i] == null)
continue;
if (O[i].equals(o)) {
Gap = k;
return i;
}
O[k++] = O[i];
O[i] = null;
}
ON = k;
for (int i = k; i < OLast; i++)
O[i] = null;
Gap = -1;
OLast = ON;
return -1;
}
/**
* @return the number of objects in the vector.
*/
public int size() {
return ON;
}
/**
* Get the element at a given position. Second access will always be
* effective. First access compresses. Throws an exception, if the index is
* invalid.
*/
public Object elementAt(final int n) {
if (n < 0 || n >= ON)
throw new ArrayIndexOutOfBoundsException(n);
if (Gap < 0 || n < Gap)
return O[n];
int k = Gap;
for (int i = Gap; i < OLast; i++) {
if (O[i] == null)
continue;
O[k] = O[i];
O[i] = null;
if (k == n) {
final Object ret = O[k];
k++;
Gap = k;
if (Gap >= ON) {
for (int j = Gap; j < OLast; j++)
O[j] = null;
OLast = ON;
Gap = -1;
}
return ret;
}
k++;
}
// never happens
throw new ArrayIndexOutOfBoundsException(n);
}
/**
* Get the array itself (compressed). Make sure, you also use size() to
* determine the true length of the array. Do not change objects beyond the
* size! Do not set objects to null!
*/
public Object[] getArray() {
compress();
return O;
}
/**
* Copy the array into an object array of at least the same size.
*/
public void copyInto(final Object o[]) {
compress();
System.arraycopy(O, 0, o, 0, ON);
}
/**
* Test for equality with another vector, using equals.
*/
public boolean equals(final MyVector V) {
if (V.ON != ON)
return false;
V.compress();
compress();
for (int i = 0; i < ON; i++) {
if (!V.O[i].equals(O[i]))
return false;
}
return true;
}
/**
* Test for equality with another vector, using object equality.
*/
public boolean equalsIdentical(final MyVector V) {
if (V.ON != ON)
return false;
V.compress();
compress();
for (int i = 0; i < ON; i++) {
if (V.O[i] != O[i])
return false;
}
return true;
}
/**
* Trancate the vector to n elements, if it has more.
*/
public void truncate(final int n) {
if (n >= ON)
return;
compress();
for (int i = n; i < OLast; i++)
O[i] = null;
OLast = ON = n;
}
public static void main(final String args[]) {
final MyVector V = new MyVector();
for (int i = 1; i <= 10; i++)
V.addElement("Element " + i);
for (int i = 4; i <= 9; i++)
V.removeElement("Element " + i);
System.out.println("--> " + V.elementAt(3));
System.out.println(V.ON + " elements, " + V.OLast + " used, " + V.Gap
+ " gap.");
System.out.println("--> " + V.elementAt(3));
System.out.println(V.ON + " elements, " + V.OLast + " used, " + V.Gap
+ " gap.");
for (int i = 11; i <= 20; i++)
V.addElement("Element " + i);
System.out.println(V.ON + " elements, " + V.OLast + " used ," + V.Gap
+ " gap.");
final Enumeration E = V.elements();
while (E.hasMoreElements()) {
System.out.println((String) E.nextElement());
}
System.out.println(V.ON + " elements, " + V.OLast + " used, " + V.Gap
+ " gap.");
}
}

647
rene/util/PngEncoder.java Normal file
View file

@ -0,0 +1,647 @@
/*
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.util;
/**
* PngEncoder takes a Java Image object and creates a byte string which can be saved as a PNG file.
* The Image is presumed to use the DirectColorModel.
*
* Thanks to Jay Denny at KeyPoint Software
* http://www.keypoint.com/
* who let me develop this code on company time.
*
* You may contact me with (probably very-much-needed) improvements,
* comments, and bug fixes at:
*
* david@catcode.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* A copy of the GNU LGPL may be found at
* http://www.gnu.org/copyleft/lesser.html,
*
* @author J. David Eisenberg
* @version 1.4, 31 March 2000
*/
import java.awt.Image;
import java.awt.image.ImageObserver;
import java.awt.image.PixelGrabber;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.CRC32;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
public class PngEncoder extends Object {
/** Constant specifying that alpha channel should be encoded. */
public static final boolean ENCODE_ALPHA = true;
/** Constant specifying that alpha channel should not be encoded. */
public static final boolean NO_ALPHA = false;
/** Constants for filters */
public static final int FILTER_NONE = 0;
public static final int FILTER_SUB = 1;
public static final int FILTER_UP = 2;
public static final int FILTER_LAST = 2;
protected byte[] pngBytes;
protected byte[] priorRow;
protected byte[] leftBytes;
protected Image image;
protected int width, height;
protected int bytePos, maxPos;
protected int hdrPos, dataPos, endPos;
protected CRC32 crc = new CRC32();
protected long crcValue;
protected boolean encodeAlpha;
protected int filter;
protected int bytesPerPixel;
protected int compressionLevel;
protected double DPI = 300;
/**
* Class constructor
*
*/
public PngEncoder() {
this(null, false, FILTER_NONE, 0);
}
/**
* Class constructor specifying Image to encode, with no alpha channel
* encoding.
*
* @param image
* A Java Image object which uses the DirectColorModel
* @see java.awt.Image
*/
public PngEncoder(final Image image) {
this(image, false, FILTER_NONE, 0);
}
/**
* Class constructor specifying Image to encode, and whether to encode
* alpha.
*
* @param image
* A Java Image object which uses the DirectColorModel
* @param encodeAlpha
* Encode the alpha channel? false=no; true=yes
* @see java.awt.Image
*/
public PngEncoder(final Image image, final boolean encodeAlpha) {
this(image, encodeAlpha, FILTER_NONE, 0);
}
/**
* Class constructor specifying Image to encode, whether to encode alpha,
* and filter to use.
*
* @param image
* A Java Image object which uses the DirectColorModel
* @param encodeAlpha
* Encode the alpha channel? false=no; true=yes
* @param whichFilter
* 0=none, 1=sub, 2=up
* @see java.awt.Image
*/
public PngEncoder(final Image image, final boolean encodeAlpha,
final int whichFilter) {
this(image, encodeAlpha, whichFilter, 0);
}
/**
* Class constructor specifying Image source to encode, whether to encode
* alpha, filter to use, and compression level.
*
* @param image
* A Java Image object
* @param encodeAlpha
* Encode the alpha channel? false=no; true=yes
* @param whichFilter
* 0=none, 1=sub, 2=up
* @param compLevel
* 0..9
* @see java.awt.Image
*/
public PngEncoder(final Image image, final boolean encodeAlpha,
final int whichFilter, final int compLevel) {
this.image = image;
this.encodeAlpha = encodeAlpha;
setFilter(whichFilter);
if (compLevel >= 0 && compLevel <= 9) {
this.compressionLevel = compLevel;
}
}
/**
* Set the image to be encoded
*
* @param image
* A Java Image object which uses the DirectColorModel
* @see java.awt.Image
* @see java.awt.image.DirectColorModel
*/
public void setImage(final Image image) {
this.image = image;
pngBytes = null;
}
public void setDPI(final double dpi) {
DPI = dpi;
}
/**
* Creates an array of bytes that is the PNG equivalent of the current
* image, specifying whether to encode alpha or not.
*
* @param encodeAlpha
* boolean false=no alpha, true=encode alpha
* @return an array of bytes, or null if there was a problem
*/
public byte[] pngEncode(final boolean encodeAlpha) {
final byte[] pngIdBytes = { -119, 80, 78, 71, 13, 10, 26, 10 };
if (image == null) {
return null;
}
width = image.getWidth(null);
height = image.getHeight(null);
/*
* start with an array that is big enough to hold all the pixels (plus
* filter bytes), and an extra 200 bytes for header info
*/
pngBytes = new byte[((width + 1) * height * 3) + 200];
/*
* keep track of largest byte written to the array
*/
maxPos = 0;
bytePos = writeBytes(pngIdBytes, 0);
hdrPos = bytePos;
writeHeader();
writePhys();
dataPos = bytePos;
if (writeImageData()) {
writeEnd();
pngBytes = resizeByteArray(pngBytes, maxPos);
} else {
pngBytes = null;
}
return pngBytes;
}
/**
* Creates an array of bytes that is the PNG equivalent of the current
* image. Alpha encoding is determined by its setting in the constructor.
*
* @return an array of bytes, or null if there was a problem
*/
public byte[] pngEncode() {
return pngEncode(encodeAlpha);
}
/**
* Set the alpha encoding on or off.
*
* @param encodeAlpha
* false=no, true=yes
*/
public void setEncodeAlpha(final boolean encodeAlpha) {
this.encodeAlpha = encodeAlpha;
}
/**
* Retrieve alpha encoding status.
*
* @return boolean false=no, true=yes
*/
public boolean getEncodeAlpha() {
return encodeAlpha;
}
/**
* Set the filter to use
*
* @param whichFilter
* from constant list
*/
public void setFilter(final int whichFilter) {
this.filter = FILTER_NONE;
if (whichFilter <= FILTER_LAST) {
this.filter = whichFilter;
}
}
/**
* Retrieve filtering scheme
*
* @return int (see constant list)
*/
public int getFilter() {
return filter;
}
/**
* Set the compression level to use
*
* @param level
* 0 through 9
*/
public void setCompressionLevel(final int level) {
if (level >= 0 && level <= 9) {
this.compressionLevel = level;
}
}
/**
* Retrieve compression level
*
* @return int in range 0-9
*/
public int getCompressionLevel() {
return compressionLevel;
}
/**
* Increase or decrease the length of a byte array.
*
* @param array
* The original array.
* @param newLength
* The length you wish the new array to have.
* @return Array of newly desired length. If shorter than the original, the
* trailing elements are truncated.
*/
protected byte[] resizeByteArray(final byte[] array, final int newLength) {
final byte[] newArray = new byte[newLength];
final int oldLength = array.length;
System.arraycopy(array, 0, newArray, 0, Math.min(oldLength, newLength));
return newArray;
}
/**
* Write an array of bytes into the pngBytes array. Note: This routine has
* the side effect of updating maxPos, the largest element written in the
* array. The array is resized by 1000 bytes or the length of the data to be
* written, whichever is larger.
*
* @param data
* The data to be written into pngBytes.
* @param offset
* The starting point to write to.
* @return The next place to be written to in the pngBytes array.
*/
protected int writeBytes(final byte[] data, final int offset) {
maxPos = Math.max(maxPos, offset + data.length);
if (data.length + offset > pngBytes.length) {
pngBytes = resizeByteArray(pngBytes, pngBytes.length
+ Math.max(1000, data.length));
}
System.arraycopy(data, 0, pngBytes, offset, data.length);
return offset + data.length;
}
/**
* Write an array of bytes into the pngBytes array, specifying number of
* bytes to write. Note: This routine has the side effect of updating
* maxPos, the largest element written in the array. The array is resized by
* 1000 bytes or the length of the data to be written, whichever is larger.
*
* @param data
* The data to be written into pngBytes.
* @param nBytes
* The number of bytes to be written.
* @param offset
* The starting point to write to.
* @return The next place to be written to in the pngBytes array.
*/
protected int writeBytes(final byte[] data, final int nBytes,
final int offset) {
maxPos = Math.max(maxPos, offset + nBytes);
if (nBytes + offset > pngBytes.length) {
pngBytes = resizeByteArray(pngBytes, pngBytes.length
+ Math.max(1000, nBytes));
}
System.arraycopy(data, 0, pngBytes, offset, nBytes);
return offset + nBytes;
}
/**
* Write a two-byte integer into the pngBytes array at a given position.
*
* @param n
* The integer to be written into pngBytes.
* @param offset
* The starting point to write to.
* @return The next place to be written to in the pngBytes array.
*/
protected int writeInt2(final int n, final int offset) {
final byte[] temp = { (byte) ((n >> 8) & 0xff), (byte) (n & 0xff) };
return writeBytes(temp, offset);
}
/**
* Write a four-byte integer into the pngBytes array at a given position.
*
* @param n
* The integer to be written into pngBytes.
* @param offset
* The starting point to write to.
* @return The next place to be written to in the pngBytes array.
*/
protected int writeInt4(final int n, final int offset) {
final byte[] temp = { (byte) ((n >> 24) & 0xff),
(byte) ((n >> 16) & 0xff), (byte) ((n >> 8) & 0xff),
(byte) (n & 0xff) };
return writeBytes(temp, offset);
}
/**
* Write a single byte into the pngBytes array at a given position.
*
* @param n
* The integer to be written into pngBytes.
* @param offset
* The starting point to write to.
* @return The next place to be written to in the pngBytes array.
*/
protected int writeByte(final int b, final int offset) {
final byte[] temp = { (byte) b };
return writeBytes(temp, offset);
}
/**
* Write a string into the pngBytes array at a given position. This uses the
* getBytes method, so the encoding used will be its default.
*
* @param n
* The integer to be written into pngBytes.
* @param offset
* The starting point to write to.
* @return The next place to be written to in the pngBytes array.
* @see java.lang.String#getBytes()
*/
protected int writeString(final String s, final int offset) {
return writeBytes(s.getBytes(), offset);
}
/**
* Write a PNG "IHDR" chunk into the pngBytes array.
*/
protected void writeHeader() {
int startPos;
startPos = bytePos = writeInt4(13, bytePos);
bytePos = writeString("IHDR", bytePos);
width = image.getWidth(null);
height = image.getHeight(null);
bytePos = writeInt4(width, bytePos);
bytePos = writeInt4(height, bytePos);
bytePos = writeByte(8, bytePos); // bit depth
bytePos = writeByte((encodeAlpha) ? 6 : 2, bytePos); // direct model
bytePos = writeByte(0, bytePos); // compression method
bytePos = writeByte(0, bytePos); // filter method
bytePos = writeByte(0, bytePos); // no interlace
crc.reset();
crc.update(pngBytes, startPos, bytePos - startPos);
crcValue = crc.getValue();
bytePos = writeInt4((int) crcValue, bytePos);
}
/**
* Write a PNG "pHYs" chunk into the pngBytes array.
*/
protected void writePhys() {
int startPos;
startPos = bytePos = writeInt4(9, bytePos);
bytePos = writeString("pHYs", bytePos);
final int dots = (int) (DPI * 39.37);
bytePos = writeInt4(dots, bytePos);
bytePos = writeInt4(dots, bytePos);
bytePos = writeByte(1, bytePos); // bit depth
crc.reset();
crc.update(pngBytes, startPos, bytePos - startPos);
crcValue = crc.getValue();
bytePos = writeInt4((int) crcValue, bytePos);
}
/**
* Perform "sub" filtering on the given row. Uses temporary array leftBytes
* to store the original values of the previous pixels. The array is 16
* bytes long, which will easily hold two-byte samples plus two-byte alpha.
*
* @param pixels
* The array holding the scan lines being built
* @param startPos
* Starting position within pixels of bytes to be filtered.
* @param width
* Width of a scanline in pixels.
*/
protected void filterSub(final byte[] pixels, final int startPos,
final int width) {
int i;
final int offset = bytesPerPixel;
final int actualStart = startPos + offset;
final int nBytes = width * bytesPerPixel;
int leftInsert = offset;
int leftExtract = 0;
for (i = actualStart; i < startPos + nBytes; i++) {
leftBytes[leftInsert] = pixels[i];
pixels[i] = (byte) ((pixels[i] - leftBytes[leftExtract]) % 256);
leftInsert = (leftInsert + 1) % 0x0f;
leftExtract = (leftExtract + 1) % 0x0f;
}
}
/**
* Perform "up" filtering on the given row. Side effect: refills the prior
* row with current row
*
* @param pixels
* The array holding the scan lines being built
* @param startPos
* Starting position within pixels of bytes to be filtered.
* @param width
* Width of a scanline in pixels.
*/
protected void filterUp(final byte[] pixels, final int startPos,
final int width) {
int i, nBytes;
byte current_byte;
nBytes = width * bytesPerPixel;
for (i = 0; i < nBytes; i++) {
current_byte = pixels[startPos + i];
pixels[startPos + i] = (byte) ((pixels[startPos + i] - priorRow[i]) % 256);
priorRow[i] = current_byte;
}
}
/**
* Write the image data into the pngBytes array. This will write one or more
* PNG "IDAT" chunks. In order to conserve memory, this method grabs as many
* rows as will fit into 32K bytes, or the whole image; whichever is less.
*
*
* @return true if no errors; false if error grabbing pixels
*/
protected boolean writeImageData() {
int rowsLeft = height; // number of rows remaining to write
int startRow = 0; // starting row to process this time through
int nRows; // how many rows to grab at a time
byte[] scanLines; // the scan lines to be compressed
int scanPos; // where we are in the scan lines
int startPos; // where this line's actual pixels start (used for
// filtering)
byte[] compressedLines; // the resultant compressed lines
int nCompressed; // how big is the compressed area?
PixelGrabber pg;
bytesPerPixel = (encodeAlpha) ? 4 : 3;
final Deflater scrunch = new Deflater(compressionLevel);
final ByteArrayOutputStream outBytes = new ByteArrayOutputStream(1024);
final DeflaterOutputStream compBytes = new DeflaterOutputStream(
outBytes, scrunch);
try {
nRows = (64 * 32768 - 1) / (width * (bytesPerPixel + 1));
final int[] pixels = new int[width * nRows];
while (rowsLeft > 0) {
if (nRows >= rowsLeft)
nRows = rowsLeft;
pg = new PixelGrabber(image, 0, startRow, width, nRows, pixels,
0, width);
try {
pg.grabPixels();
} catch (final Exception e) {
System.err.println("interrupted waiting for pixels!");
return false;
}
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or errored");
return false;
}
/*
* Create a data chunk. scanLines adds "nRows" for the filter
* bytes.
*/
scanLines = new byte[width * nRows * bytesPerPixel + nRows];
if (filter == FILTER_SUB) {
leftBytes = new byte[16];
}
if (filter == FILTER_UP) {
priorRow = new byte[width * bytesPerPixel];
}
scanPos = 0;
startPos = 1;
for (int i = 0; i < width * nRows; i++) {
if (i % width == 0) {
scanLines[scanPos++] = (byte) filter;
startPos = scanPos;
}
scanLines[scanPos++] = (byte) ((pixels[i] >> 16) & 0xff);
scanLines[scanPos++] = (byte) ((pixels[i] >> 8) & 0xff);
scanLines[scanPos++] = (byte) ((pixels[i]) & 0xff);
if (encodeAlpha) {
scanLines[scanPos++] = (byte) ((pixels[i] >> 24) & 0xff);
}
if ((i % width == width - 1) && (filter != FILTER_NONE)) {
if (filter == FILTER_SUB) {
filterSub(scanLines, startPos, width);
}
if (filter == FILTER_UP) {
filterUp(scanLines, startPos, width);
}
}
}
/*
* Write these lines to the output area
*/
compBytes.write(scanLines, 0, scanPos);
startRow += nRows;
rowsLeft -= nRows;
}
compBytes.close();
/*
* Write the compressed bytes
*/
compressedLines = outBytes.toByteArray();
nCompressed = compressedLines.length;
crc.reset();
bytePos = writeInt4(nCompressed, bytePos);
bytePos = writeString("IDAT", bytePos);
crc.update("IDAT".getBytes());
bytePos = writeBytes(compressedLines, nCompressed, bytePos);
crc.update(compressedLines, 0, nCompressed);
crcValue = crc.getValue();
bytePos = writeInt4((int) crcValue, bytePos);
scrunch.finish();
return true;
} catch (final IOException e) {
System.err.println(e.toString());
return false;
}
}
/**
* Write a PNG "IEND" chunk into the pngBytes array.
*/
protected void writeEnd() {
bytePos = writeInt4(0, bytePos);
bytePos = writeString("IEND", bytePos);
crc.reset();
crc.update("IEND".getBytes());
crcValue = crc.getValue();
bytePos = writeInt4((int) crcValue, bytePos);
}
}

View 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.util;
public class SimpleByteBuffer {
private int Size, N;
private byte Buf[];
public SimpleByteBuffer(final int size) {
Size = size;
Buf = new byte[size];
N = 0;
}
public SimpleByteBuffer(final byte b[]) {
Size = b.length;
Buf = b;
N = 0;
}
public void append(final byte c) {
if (N < Size)
Buf[N++] = c;
else {
Size = 2 * Size;
final byte NewBuf[] = new byte[Size];
for (int i = 0; i < N; i++)
NewBuf[i] = Buf[i];
Buf = NewBuf;
Buf[N++] = c;
}
}
public void clear() {
N = 0;
}
public byte[] getBuffer() {
return Buf;
}
public byte[] getByteArray() {
final byte b[] = new byte[N];
for (int i = 0; i < N; i++)
b[i] = Buf[i];
return b;
}
public int size() {
return N;
}
}

View file

@ -0,0 +1,69 @@
/*
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.util;
public class SimpleStringBuffer {
private int Size, N;
private char Buf[];
public SimpleStringBuffer(final int size) {
Size = size;
Buf = new char[size];
N = 0;
}
public SimpleStringBuffer(final char b[]) {
Size = b.length;
Buf = b;
N = 0;
}
public void append(final char c) {
if (N < Size)
Buf[N++] = c;
else {
Size = 2 * Size;
final char NewBuf[] = new char[Size];
for (int i = 0; i < N; i++)
NewBuf[i] = Buf[i];
Buf = NewBuf;
Buf[N++] = c;
}
}
public void append(final String s) {
final int n = s.length();
for (int i = 0; i < n; i++)
append(s.charAt(i));
}
public void clear() {
N = 0;
}
@Override
public String toString() {
if (N == 0)
return "";
return new String(Buf, 0, N);
}
}

302
rene/util/TestEncoder.java Normal file
View file

@ -0,0 +1,302 @@
/*
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.util;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.ImageObserver;
import java.awt.image.MemoryImageSource;
import java.awt.image.PixelGrabber;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;
/**
* TestEncoder creates a PNG file that shows an analog clock displaying the
* current time of day, optionally with an alpha channel, and with the specified
* filter.
*
* The file name is in the format:
*
* clockHHMM_fNC alphaclockDHHMM_fNC
*
* HH = hours (24-hour clock), MM = minutes,
*
* N = filter level (0, 1, or 2) C = compression level (0 to 9)
*
* "alpha" is prefixed to the name if alpha encoding was used.
*
* This test program was written in a burning hurry, so it is not a model of
* efficient, or even good, code. Comments and bug fixes should be directed to:
*
* david@catcode.com
*
* @author J. David Eisenberg
* @version 1.3, 6 April 2000
*/
public class TestEncoder extends Frame {
/**
*
*/
private static final long serialVersionUID = 1L;
String message;
String timeStr;
Image clockImage = null;
int hour, minute;
boolean encodeAlpha;
int filter;
int compressionLevel;
int pixelDepth;
String filename;
boolean fileSaved = false;
public TestEncoder(final String s) {
super(s);
setSize(200, 200);
}
public void drawClockImage(int hour, final int minute) {
// variables used for drawing hands of clock
Graphics g;
final Font smallFont = new Font("Helvetica", Font.PLAIN, 9);
FontMetrics fm;
int x0, y0, x1, y1;
double angle;
g = clockImage.getGraphics();
g.setFont(smallFont);
fm = g.getFontMetrics();
// draw the clock face; yellow for AM, blue for PM
if (hour < 12) {
g.setColor(new Color(255, 255, 192));
} else {
g.setColor(new Color(192, 192, 255));
}
g.fillOval(10, 10, 80, 80);
g.setColor(Color.black);
g.drawOval(10, 10, 80, 80);
g.drawOval(48, 48, 4, 4);
/* draw the 12 / 3 / 6/ 9 numerals */
g.setFont(smallFont);
g.drawString("12", 50 - fm.stringWidth("12") / 2, 11 + fm.getAscent());
g.drawString("3", 88 - fm.stringWidth("3"), 50 + fm.getAscent() / 2);
g.drawString("6", 50 - fm.stringWidth("6") / 2, 88);
g.drawString("9", 12, 50 + fm.getAscent() / 2);
x0 = 50;
y0 = 50;
/* draw the hour hand */
hour %= 12;
angle = -(hour * 30 + minute / 2) + 90;
angle = angle * (Math.PI / 180.0);
x1 = (int) (x0 + 28 * (Math.cos(angle)));
y1 = (int) (y0 - 28 * (Math.sin(angle)));
g.drawLine(x0, y0, x1, y1);
/* and the minute hand */
angle = -(minute * 6) + 90;
angle = angle * Math.PI / 180.0;
x1 = (int) (x0 + 35 * (Math.cos(angle)));
y1 = (int) (y0 - 35 * (Math.sin(angle)));
g.drawLine(x0, y0, x1, y1);
}
public void addAlphaToImage() {
final int width = 100;
final int height = 100;
int alphaMask = 0;
final int[] pixels = new int[width * height];
final PixelGrabber pg = new PixelGrabber(clockImage, 0, 0, width,
height, pixels, 0, width);
try {
pg.grabPixels();
} catch (final InterruptedException e) {
System.err.println("interrupted waiting for pixels!");
return;
}
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or errored");
return;
}
for (int i = 0; i < width * height; i++) {
if ((i % width) == 0) {
alphaMask = (alphaMask >> 24) & 0xff;
alphaMask += 2;
if (alphaMask > 255) {
alphaMask = 255;
}
alphaMask = (alphaMask << 24) & 0xff000000;
}
pixels[i] = (pixels[i] & 0xffffff) | alphaMask;
}
clockImage = createImage(new MemoryImageSource(width, height, pixels,
0, width));
}
@Override
public void paint(final Graphics g) {
if (clockImage == null) {
clockImage = createImage(100, 100);
}
if (clockImage != null) {
if (!fileSaved) {
drawClockImage(hour, minute);
if (encodeAlpha) {
addAlphaToImage();
}
saveClockImage();
fileSaved = true;
}
g.drawImage(clockImage, 50, 20, null);
}
if (message != null) {
g.drawString(message, 10, 140);
}
}
protected static void usage() {
System.out.print("Usage: TestEncoder -alpha -filter n -compress c");
System.out.println("-alpha means to use alpha encoding (default none)");
System.out.println("n is filter number 0=none (default), 1=sub, 2=up");
System.out.println("c is compression factor (0-9); 1 default");
System.exit(0);
}
public static void main(final String[] args) {
int i;
final TestEncoder te = new TestEncoder("Test PNG Alpha/Filter Encoder");
i = 0;
te.encodeAlpha = false;
te.filter = 0;
te.pixelDepth = 24;
te.compressionLevel = 1;
while (i < args.length) {
if (args[i].equals("-alpha")) {
te.encodeAlpha = true;
i++;
} else if (args[i].equals("-filter")) {
if (i != args.length - 1) {
try {
te.filter = Integer.parseInt(args[i + 1]);
} catch (final Exception e) {
usage();
break;
}
}
i += 2;
} else if (args[i].equals("-compress")) {
if (i != args.length - 1) {
try {
te.compressionLevel = Integer.parseInt(args[i + 1]);
} catch (final Exception e) {
usage();
break;
}
}
i += 2;
} else {
usage();
break;
}
}
if (te.pixelDepth == 8) {
te.encodeAlpha = false;
}
te.doYourThing();
}
public void doYourThing() {
final Calendar cal = Calendar.getInstance();
hour = cal.get(Calendar.HOUR);
if (cal.get(Calendar.AM_PM) == 1) {
hour += 12;
}
hour %= 24;
minute = cal.get(Calendar.MINUTE);
/*
* format the time to a string of the form hhmm for use in the filename
*/
timeStr = Integer.toString(minute);
if (minute < 10) {
timeStr = "0" + timeStr;
}
timeStr = Integer.toString(hour) + timeStr;
if (hour < 10) {
timeStr = "0" + timeStr;
}
filename = (encodeAlpha) ? "alphaclock" : "clock";
filename += timeStr + "_f" + filter + compressionLevel + ".png";
message = "File: " + filename;
final WindowListener l = new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent e) {
System.exit(0);
}
};
addWindowListener(l);
setVisible(true);
// show();
}
public void saveClockImage() {
byte[] pngbytes;
final PngEncoder png = new PngEncoder(clockImage,
(encodeAlpha) ? PngEncoder.ENCODE_ALPHA : PngEncoder.NO_ALPHA,
filter, compressionLevel);
try {
final FileOutputStream outfile = new FileOutputStream(filename);
pngbytes = png.pngEncode();
if (pngbytes == null) {
System.out.println("Null image");
} else {
outfile.write(pngbytes);
}
outfile.flush();
outfile.close();
} catch (final IOException e) {
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,166 @@
/*
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.util.list;
/**
* A class for a list of things. The list is forward and backward chained.
*
* @see rene.list.ListElement
*/
public class ListClass {
ListElement First, Last; // Pointer to start and end of list.
/**
* Generate an empty list.
*/
public ListClass() {
First = null;
Last = null;
}
/**
* Append a node to the list
*/
public void append(final ListElement l) {
if (Last == null)
init(l);
else {
Last.next(l);
l.previous(Last);
Last = l;
l.next(null);
l.list(this);
}
}
public void prepend(final ListElement l)
// prepend a node to the list
{
if (First == null)
init(l);
else {
First.previous(l);
l.next(First);
First = l;
l.previous(null);
l.list(this);
}
}
/*
* @param l ListElement to be inserted.
*
* @param after If null, it works like prepend.
*/
public void insert(final ListElement l, final ListElement after) {
if (after == Last)
append(l);
else if (after == null)
prepend(l);
else {
after.next().previous(l);
l.next(after.next());
after.next(l);
l.previous(after);
l.list(this);
}
}
/**
* initialize the list with a single element.
*/
public void init(final ListElement l) {
Last = First = l;
l.previous(null);
l.next(null);
l.list(this);
}
/**
* Remove a node from the list. The node really should be in the list, which
* is not checked.
*/
public void remove(final ListElement l) {
if (First == l) {
First = l.next();
if (First != null)
First.previous(null);
else
Last = null;
} else if (Last == l) {
Last = l.previous();
if (Last != null)
Last.next(null);
else
First = null;
} else {
l.previous().next(l.next());
l.next().previous(l.previous());
}
l.next(null);
l.previous(null);
l.list(null);
}
/**
* Empty the list.
*/
public void removeall() {
First = null;
Last = null;
}
/** remove everything after e */
public void removeAfter(final ListElement e) {
e.next(null);
Last = e;
}
/**
* @return First ListElement.
*/
public ListElement first() {
return First;
}
/**
* @return Last ListElement.
*/
public ListElement last() {
return Last;
}
/**
* Prints the class
*/
@Override
public String toString() {
ListElement e = First;
String s = "";
while (e != null) {
s = s + e.content().toString() + ", ";
e = e.next();
}
return s;
}
}

View file

@ -0,0 +1,79 @@
/*
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.util.list;
/**
* The nodes of a list.
*
* @see rene.list.ListClass
*/
public class ListElement
// A list node with pointers to previous and next element
// and with a content of type Object.
{
ListElement Next, Previous; // the chain pointers
Object Content; // the content of the node
ListClass L; // Belongs to this list
public ListElement(final Object content)
// get a new Element with the content and null pointers
{
Content = content;
Next = Previous = null;
L = null;
}
// access methods:
public Object content() {
return Content;
}
public ListElement next() {
return Next;
}
public ListElement previous() {
return Previous;
}
public void list(final ListClass l) {
L = l;
}
// modifying methods:
public void content(final Object o) {
Content = o;
}
public void next(final ListElement o) {
Next = o;
}
public void previous(final ListElement o) {
Previous = o;
}
public ListClass list() {
return L;
}
}

118
rene/util/list/Tree.java Normal file
View file

@ -0,0 +1,118 @@
/*
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.util.list;
/**
* A node with a list of children trees.
*/
public class Tree {
ListClass Children; // list of children, each with Tree as content
Object Content; // content
ListElement Le; // the listelement containing the tree
Tree Parent; // the parent tree
/** initialize with an object and no children */
public Tree(final Object o) {
Content = o;
Children = new ListClass();
Le = null;
Parent = null;
}
/** add a child tree */
public void addchild(final Tree t) {
final ListElement p = new ListElement(t);
Children.append(p);
t.Le = p;
t.Parent = this;
}
/** insert a child tree */
public void insertchild(final Tree t) {
if (!haschildren()) // simple case
{
addchild(t);
return;
}
// give t my children
t.Children = Children;
// make t my only child
Children = new ListClass();
final ListElement p = new ListElement(t);
Children.append(p);
t.Le = p;
t.Parent = this;
// fix the parents of all grandchildren
ListElement le = t.Children.first();
while (le != null) {
final Tree h = (Tree) (le.content());
h.Parent = t;
le = le.next();
}
}
/** remove the specific child tree (must be in the tree!!!) */
public void remove(final Tree t) {
if (t.parent() != this)
return;
Children.remove(t.Le);
}
/** remove all children */
public void removeall() {
Children.removeall();
}
// Access Methods:
public boolean haschildren() {
return Children.first() != null;
}
public Tree firstchild() {
return (Tree) Children.first().content();
}
public Tree lastchild() {
return (Tree) Children.last().content();
}
public Tree parent() {
return Parent;
}
public ListClass children() {
return Children;
}
public Object content() {
return Content;
}
public void content(final Object o) {
Content = o;
}
public ListElement listelement() {
return Le;
}
}

View file

@ -0,0 +1,372 @@
/*
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.util.parser;
import java.util.Vector;
/**
* This is a string simple parser.
*/
public class StringParser {
char C[];
int N, L;
boolean Error;
/**
* @param S
* the string to be parsed.
*/
public StringParser(final String S) {
C = S.toCharArray();
N = 0;
L = C.length;
Error = (N >= L);
}
/**
* @return next character is white?
*/
public boolean blank() {
return (C[N] == ' ' || C[N] == '\t' || C[N] == '\n' || C[N] == '\r');
}
/**
* @return next character is white or c?
*/
public boolean blank(final char c) {
return (C[N] == ' ' || C[N] == '\t' || C[N] == '\n' || C[N] == '\r' || C[N] == c);
}
/**
* Cut off the String upto a character c.
*/
public String upto(final char c) {
if (Error)
return "";
int n = N;
while (n < L && C[n] != c)
n++;
if (n >= L)
Error = true;
final String s = new String(C, N, n - N);
N = n;
return s;
}
/**
* Advance one character.
*
* @return String is not empty.
*/
public boolean advance() {
if (N < L)
N++;
if (N >= L)
Error = true;
return !Error;
}
/**
* Parse a word up to a blank.
*/
public String parseword() {
if (Error)
return "";
while (blank()) {
if (!advance())
return "";
}
final int n = N;
while (!Error && !blank())
advance();
return new String(C, n, N - n);
}
/**
* Parse digits upto the character c or blank.
*/
public String parsedigits(final char c) {
if (Error)
return "";
while (blank()) {
if (!advance())
return "";
}
final int n = N;
while (!Error && !blank()) {
if (N > L || C[N] < '0' || C[N] > '9' || C[N] == c)
break;
advance();
}
return new String(C, n, N - n);
}
/**
* Parse digits upto a blank.
*/
public String parsedigits() {
if (Error)
return "";
while (blank()) {
if (!advance())
return "";
}
final int n = N;
while (!Error && !blank()) {
if (N > L || C[N] < '0' || C[N] > '9')
break;
advance();
}
return new String(C, n, N - n);
}
/**
* Parse a word upto the character c or blank.
*/
public String parseword(final char c) {
if (Error)
return "";
while (blank()) {
if (!advance())
return "";
}
final int n = N;
while (!Error && !blank(c))
advance();
return new String(C, n, N - n);
}
/**
* @return next character is a digit?
*/
public boolean isint() {
if (Error)
return false;
return (C[N] >= '0' && C[N] <= '9');
}
/**
* Parse an int upto a blank. The int may be negative.
*
* @return the int
*/
public int parseint() {
int sig = 1;
try {
skipblanks();
if (Error)
return 0;
if (C[N] == '-') {
sig = -1;
N++;
if (N > L) {
Error = true;
return 0;
}
}
return sig * Integer.parseInt(parsedigits(), 10);
} catch (final NumberFormatException e) {
return 0;
}
}
/**
* Parse an int upto a blank or c. The int may be negative.
*
* @return the int
*/
public int parseint(final char c) {
int sig = 1;
try {
skipblanks();
if (Error)
return 0;
if (C[N] == '-') {
sig = -1;
N++;
if (N > L) {
Error = true;
return 0;
}
}
return sig * Integer.parseInt(parsedigits(c), 10);
} catch (final NumberFormatException e) {
return 0;
}
}
/**
* Skip all white characters.
*/
public void skipblanks() {
if (Error)
return;
while (blank())
if (!advance())
break;
}
/**
* Skip everything to the string s.
*
* @return String was found
*/
public boolean skip(final String s) {
if (Error)
return false;
final int l = s.length();
if (N + l > L)
return false;
if (!new String(C, N, l).equals(s))
return false;
N += l;
if (N >= L)
Error = true;
return true;
}
/**
* Get the next character.
*/
public char next() {
if (Error)
return ' ';
else {
N++;
if (N >= L) {
Error = true;
}
return C[N - 1];
}
}
/**
* Return a String, which is parsed from words with limited length.
*
* @param columns
* the maximal length of the string
*/
public String wrapline(final int columns) {
int n = N, good = N;
String s = "";
while (n < L) {
if (C[n] == '\n') {
if (n > N)
s = new String(C, N, n - N);
N = n + 1;
break;
}
if (C[n] == ' ' || C[n] == '\t' || C[n] == '\n') {
good = n;
}
n++;
if (n - N >= columns && good > N) {
s = new String(C, N, good - N);
N = good + 1;
break;
}
if (n >= L) {
if (n > N)
s = new String(C, N, n - N);
N = n;
break;
}
}
if (N >= L)
Error = true;
return s;
}
/**
* Parse the string into lines.
*
* @param columns
* the maximal length of each line
* @return a Vector with lines
*/
public Vector wraplines(final int columns) {
final Vector v = new Vector(10, 10);
String s;
while (!Error) {
s = wrapline(columns);
v.addElement(s);
}
return v;
}
public String wraplineword(final int columns) {
int n = N;
final int good = N;
String s = "";
while (n < L) {
if (C[n] == '\n') {
s = new String(C, N, n - N);
N = n + 1;
break;
}
n++;
if (n >= L) {
if (n > N)
s = new String(C, N, n - N);
N = n;
break;
}
if (n - N >= columns && good > N) {
s = new String(C, N, good - N);
N = good + 1;
if (N < L && C[N] != '\n')
s = s + "\\";
break;
}
}
if (N >= L)
Error = true;
return s;
}
public Vector wrapwords(final int columns) {
final Vector v = new Vector(10, 10);
String s;
while (!Error) {
s = wraplineword(columns);
v.addElement(s);
}
return v;
}
/**
* Replace c1 by c2
*/
public void replace(final char c1, final char c2) {
for (int i = 0; i < L; i++)
if (C[i] == c1)
C[i] = c2;
}
/**
* @return if an error has occured during the parsing.
*/
public boolean error() {
return Error;
}
}

View 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.util.sort;
public interface SortObject {
public int compare(SortObject o);
}

View file

@ -0,0 +1,40 @@
/*
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.util.sort;
public class SortString implements SortObject {
String S;
public SortString(final String s) {
S = s;
}
public int compare(final SortObject o) {
final SortString s = (SortString) o;
return S.compareTo(s.S);
}
@Override
public String toString() {
return S;
}
}

View 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.util.sort;
public class SortStringNoCase extends SortString {
String Orig;
public SortStringNoCase(final String s) {
super(s.toLowerCase());
Orig = s;
}
@Override
public String toString() {
return Orig;
}
}

140
rene/util/sort/Sorter.java Normal file
View file

@ -0,0 +1,140 @@
/*
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.util.sort;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Enumeration;
import java.util.Vector;
/**
* Quick sort implementation. Sorts an array or a vector of SortObject.
*/
public class Sorter {
static public void sort(final SortObject v[]) {
QuickSort(v, 0, v.length - 1);
}
static public void sort(final SortObject v[], final int n) {
QuickSort(v, 0, n - 1);
}
static public void sort(final Vector v) {
final SortObject o[] = new SortObject[v.size()];
v.copyInto(o);
sort(o);
for (int i = 0; i < o.length; i++)
v.setElementAt(o[i], i);
}
static public void QuickSort(final SortObject a[], final int lo0,
final int hi0) {
int lo = lo0;
int hi = hi0;
SortObject mid;
if (hi0 > lo0) {
mid = a[(lo0 + hi0) / 2];
while (lo <= hi) {
while ((lo < hi0) && (a[lo].compare(mid) < 0))
++lo;
while ((hi > lo0) && (a[hi].compare(mid) > 0))
--hi;
if (lo <= hi) {
swap(a, lo, hi);
++lo;
--hi;
}
}
if (lo0 < hi)
QuickSort(a, lo0, hi);
if (lo < hi0)
QuickSort(a, lo, hi0);
}
}
static private void swap(final SortObject a[], final int i, final int j) {
SortObject T;
T = a[i];
a[i] = a[j];
a[j] = T;
}
static public void QuickSort(final Object a[], final int lo0, final int hi0) {
int lo = lo0;
int hi = hi0;
SortObject mid;
if (hi0 > lo0) {
mid = (SortObject) a[(lo0 + hi0) / 2];
while (lo <= hi) {
while ((lo < hi0) && (((SortObject) a[lo]).compare(mid) < 0))
++lo;
while ((hi > lo0) && (((SortObject) a[hi]).compare(mid) > 0))
--hi;
if (lo <= hi) {
swap(a, lo, hi);
++lo;
--hi;
}
}
if (lo0 < hi)
QuickSort(a, lo0, hi);
if (lo < hi0)
QuickSort(a, lo, hi0);
}
}
static private void swap(final Object a[], final int i, final int j) {
Object T;
T = a[i];
a[i] = a[j];
a[j] = T;
}
public static void main(final String args[]) throws IOException
// Sort the incoming lines and remove doublicates
{
final BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
final Vector v = new Vector();
while (true) {
final String line = in.readLine();
if (line == null)
break;
v.addElement(new SortString(line));
}
in.close();
sort(v);
final Enumeration e = v.elements();
String last = null;
while (e.hasMoreElements()) {
final String s = ((SortString) e.nextElement()).toString();
if (last == null || !s.equals(last)) {
System.out.println(s);
last = s;
}
}
}
}

View file

@ -0,0 +1,86 @@
/*
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.util.xml;
import java.io.FileOutputStream;
import java.io.PrintWriter;
public class SVGWriter extends XmlWriter {
int W, H;
public SVGWriter(final PrintWriter o, final String enc, final int w,
final int h) {
super(o);
printEncoding(enc);
W = w;
H = h;
startTagStart("svg");
printArg("width", "" + w);
printArg("height", "" + h);
startTagEndNewLine();
}
public SVGWriter(final PrintWriter o) {
super(o);
}
public void startSVG(final int w, final int h) {
printEncoding("utf-8");
Out.println("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"");
Out.println("\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">");
startTagStart("svg");
printArg("xmlns", "http://www.w3.org/2000/svg");
printArg("width", "" + w);
printArg("height", "" + h);
startTagEndNewLine();
}
@Override
public void close() {
endTag("svg");
super.close();
}
public void coord(final int x, final int y) {
printArg("x", "" + x);
printArg("y", "" + y);
}
public void text(final String text, final int x, final int y) {
startTagStart("text");
coord(x, y);
startTagEnd();
print(text);
endTagNewLine("text");
}
public static void main(final String args[]) throws Exception {
final SVGWriter out = new SVGWriter(new PrintWriter(
new FileOutputStream("test.svg")), "", 300, 300);
out.text("Hallo Welt", 10, 95);
out.startTagStart("path");
out.printArg("d", "M 150 150 A 50 50 0 1 0 100 200");
out.printArg("style", "fill:none;stroke-width:1;stroke:black");
out.finishTagNewLine();
out.close();
}
}

View file

@ -0,0 +1,505 @@
/*
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.util.xml;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import rene.util.SimpleByteBuffer;
import rene.util.SimpleStringBuffer;
import rene.util.list.ListElement;
public class XmlReader {
BufferedReader In;
SimpleStringBuffer buf = new SimpleStringBuffer(10000);
public XmlReader() {
In = null;
}
public XmlReader(final BufferedReader in) {
In = in;
}
public XmlReader(final InputStream in) throws XmlReaderException {
try { // read the file into a buffer
final BufferedInputStream rin = new BufferedInputStream(in);
final SimpleByteBuffer bb = new SimpleByteBuffer(10000);
while (true) {
final int k = rin.read();
if (k < 0)
break;
bb.append((byte) k);
}
rin.close();
final byte b[] = bb.getByteArray();
// Try to open an ASCII stream, or a default stream
ByteArrayInputStream bin = new ByteArrayInputStream(b);
XmlReader R = null;
try {
R = new XmlReader(new BufferedReader(new InputStreamReader(bin,
"ASCII")));
} catch (final UnsupportedEncodingException ex) {
R = new XmlReader(
new BufferedReader(new InputStreamReader(bin)));
}
// Determine the encoding
String Encoding = null;
while (true) {
while (true) {
final int c = R.read();
if (c == -1)
throw new Exception("<?xml> tag not found");
if (c == '<')
break;
}
if (R.found("?xml")) {
String s = R.scanFor("?>");
if (s == null)
throw new Exception("<?xml> tag error");
int n = s.indexOf("encoding=\"");
if (n >= 0) {
n += "encoding=\"".length();
s = s.substring(n);
final int m = s.indexOf('\"');
if (m < 0)
throw new Exception("Closing bracket missing");
Encoding = s.substring(0, m).toUpperCase();
if (Encoding.equals("UTF-8"))
Encoding = "UTF8";
// for IE5 !
break;
}
break;
}
}
// Open a stream with this encoding
bin = new ByteArrayInputStream(b);
if (Encoding == null)
In = new BufferedReader(new InputStreamReader(bin));
else
try {
In = new BufferedReader(
new InputStreamReader(bin, Encoding));
} catch (final UnsupportedEncodingException e) {
try {
In = new BufferedReader(new InputStreamReader(bin,
"ASCII"));
} catch (final UnsupportedEncodingException ex) {
In = new BufferedReader(new InputStreamReader(bin));
}
}
} catch (final Exception e) {
throw new XmlReaderException(e.toString());
}
}
public void init(final InputStream in) throws XmlReaderException {
try { // read the file into a buffer
final BufferedInputStream rin = new BufferedInputStream(in);
final SimpleByteBuffer bb = new SimpleByteBuffer(10000);
while (true) {
final int k = rin.read();
if (k < 0)
break;
bb.append((byte) k);
}
rin.close();
final byte b[] = bb.getByteArray();
// Try to open an ASCII stream, or a default stream
ByteArrayInputStream bin = new ByteArrayInputStream(b);
XmlReader R = null;
try {
R = new XmlReader(new BufferedReader(new InputStreamReader(bin,
"ASCII")));
} catch (final UnsupportedEncodingException ex) {
R = new XmlReader(
new BufferedReader(new InputStreamReader(bin)));
}
// Determine the encoding
String Encoding = null;
while (true) {
while (true) {
final int c = R.read();
if (c == -1)
throw new Exception("<?xml> tag not found");
if (c == '<')
break;
}
if (R.found("?xml")) {
String s = R.scanFor("?>");
if (s == null)
throw new Exception("<?xml> tag error");
int n = s.indexOf("encoding=\"");
if (n >= 0) {
n += "encoding=\"".length();
s = s.substring(n);
final int m = s.indexOf('\"');
if (m < 0)
throw new Exception("Closing bracket missing");
Encoding = s.substring(0, m).toUpperCase();
if (Encoding.equals("UTF-8"))
Encoding = "UTF8";
// for IE5 !
break;
}
break;
}
}
// Open a stream with this encoding
bin = new ByteArrayInputStream(b);
if (Encoding == null)
In = new BufferedReader(new InputStreamReader(bin));
else
try {
In = new BufferedReader(
new InputStreamReader(bin, Encoding));
} catch (final UnsupportedEncodingException e) {
try {
In = new BufferedReader(new InputStreamReader(bin,
"ASCII"));
} catch (final UnsupportedEncodingException ex) {
In = new BufferedReader(new InputStreamReader(bin));
}
}
} catch (final Exception e) {
throw new XmlReaderException(e.toString());
}
}
/**
* Scan an xml file. This function reads, until <?xml is found. then it
* skips this declaration and scans the rest of the items.
*/
public XmlTree scan() throws XmlReaderException {
while (true) {
while (true) {
final int c = read();
if (c == -1)
return null;
if (c == '<')
break;
}
if (found("?xml")) {
final String s = scanFor("?>");
if (s == null)
return null;
final XmlTree t = new XmlTree(new XmlTagRoot());
t.addchild(new XmlTree(new XmlTagPI(s)));
scanContent(t);
return t;
}
}
}
public void scanContent(final XmlTree t) throws XmlReaderException { // System.out.println("Sanning for "+t.getTag().name()+" ("+
// t.getTag().countParams()+")");
while (true) {
String s = scanFor('<');
if (s == null) {
if (t.getTag() instanceof XmlTagRoot)
return;
exception("File ended surprisingly");
}
if (!empty(s)) {
t
.addchild(new XmlTree(new XmlTagText(XmlTranslator
.toText(s))));
}
if (found("!--")) {
s = scanFor("-->");
continue;
}
if (found("!")) {
s = scanTagFor('>');
continue;
}
if (found("?")) {
s = scanTagFor("?>");
t.addchild(new XmlTree(new XmlTagPI(s)));
continue;
}
s = scanTagFor('>');
if (s == null)
exception("> missing");
if (s.startsWith("/")) {
if (s.substring(1).equals(t.getTag().name()))
return;
else
exception("End tag without start tag");
}
if (s.endsWith("/")) {
t.addchild(new XmlTree(new XmlTag(s
.substring(0, s.length() - 1))));
} else {
final XmlTree t0 = new XmlTree(new XmlTag(s));
scanContent(t0);
t.addchild(t0);
}
}
}
public boolean empty(final String s) {
final int n = s.length();
for (int i = 0; i < n; i++) {
final char c = s.charAt(i);
if (c != ' ' && c != '\n' && c != '\t')
return false;
}
return true;
}
/**
* Skip Blanks.
*
* @return Non-blank character or -1 for EOF.
*/
public int skipBlanks() throws XmlReaderException {
while (true) {
final int c = read();
if (c == ' ' || c == '\t' || c == '\n')
continue;
else
return c;
}
}
/**
* Scan for an end character.
*
* @return String between the current position and the end character, or
* null.
*/
public String scanFor(final char end) throws XmlReaderException {
buf.clear();
int c = read();
while (c != end) {
buf.append((char) c);
c = read();
if (c < 0)
return null;
}
return buf.toString();
}
/**
* Scan for a specific string.
*
* @return String between the current position and the string.
*/
public String scanFor(final String s) throws XmlReaderException {
buf.clear();
while (!found(s)) {
final int c = read();
if (c < 0)
return null;
buf.append((char) c);
}
for (int i = 0; i < s.length(); i++)
read();
return buf.toString();
}
/**
* Scan tag for an end character (interpreting " and ')
*
* @return String between the current position and the end character, or
* null.
*/
public String scanTagFor(final char end) throws XmlReaderException {
buf.clear();
int c = read();
while (c != end) {
if (c == '\"') {
buf.append((char) c);
while (true) {
c = read();
if (c < 0)
return null;
if (c == '\"')
break;
buf.append((char) c);
}
buf.append((char) c);
} else if (c == '\'') {
buf.append((char) c);
while (true) {
c = read();
if (c < 0)
return null;
if (c == '\'')
break;
buf.append((char) c);
}
buf.append((char) c);
} else
buf.append((char) c);
c = read();
if (c < 0)
return null;
}
return buf.toString();
}
/**
* Scan tag for a specific string (interpreting " and ')
*
* @return String between the current position and the string.
*/
public String scanTagFor(final String s) throws XmlReaderException {
buf.clear();
while (!found(s)) {
int c = read();
if (c < 0)
return null;
if (c == '\"') {
buf.append((char) c);
while (true) {
c = read();
if (c < 0)
return null;
if (c == '\"')
break;
buf.append((char) c);
}
buf.append((char) c);
} else if (c == '\'') {
buf.append((char) c);
while (true) {
c = read();
if (c < 0)
return null;
if (c == '\'')
break;
buf.append((char) c);
}
buf.append((char) c);
} else
buf.append((char) c);
}
for (int i = 0; i < s.length(); i++)
read();
return buf.toString();
}
String Line = null;
int LinePos;
public int read() throws XmlReaderException {
try {
if (Line == null) {
Line = In.readLine();
LinePos = 0;
// System.out.println("Read --> "+Line);
}
if (Line == null)
return -1;
if (LinePos >= Line.length()) {
Line = null;
return '\n';
}
return Line.charAt(LinePos++);
} catch (final Exception e) {
return -1;
}
}
/**
* @return If the string is at the current line position.
*/
public boolean found(final String s) {
final int n = s.length();
if (LinePos + n > Line.length())
return false;
for (int i = 0; i < n; i++)
if (s.charAt(i) != Line.charAt(LinePos + i))
return false;
return true;
}
public void exception(final String s) throws XmlReaderException {
throw new XmlReaderException(s, Line, LinePos);
}
/**
* A test program.
*/
public static void main(final String args[]) {
try {
final BufferedReader in = new BufferedReader(new InputStreamReader(
new FileInputStream("rene\\util\\xml\\test.xml"), "UTF8"));
final XmlReader reader = new XmlReader(in);
final XmlTree tree = reader.scan();
in.close();
print(tree);
} catch (final XmlReaderException e) {
System.out.println(e.toString() + "\n" + e.getLine() + "\n"
+ "Position : " + e.getPos());
} catch (final IOException e) {
System.out.println(e);
}
}
public static void print(final XmlTree t) {
final XmlTag tag = t.getTag();
System.out.print("<" + tag.name());
for (int i = 0; i < tag.countParams(); i++) {
System.out.print(" " + tag.getParam(i) + "=\"" + tag.getValue(i)
+ "\"");
}
System.out.println(">");
ListElement el = t.children().first();
while (el != null) {
print((XmlTree) (el.content()));
el = el.next();
}
System.out.println("</" + tag.name() + ">");
}
public static boolean testXml(final String s) {
int i = 0;
while (i < s.length()) {
final char c = s.charAt(i);
if (c == '<')
break;
i++;
}
if (i >= s.length())
return false;
if (s.substring(i).startsWith("<?xml"))
return true;
return false;
}
}

View file

@ -0,0 +1,55 @@
/*
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.util.xml;
public class XmlReaderException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
String Line;
int Pos;
String S;
public XmlReaderException(final String s, final String line, final int pos) {
super(s);
S = s;
Line = line;
Pos = pos;
}
public XmlReaderException(final String s) {
this(s, "", 0);
}
public String getLine() {
return Line;
}
public int getPos() {
return Pos;
}
public String getText() {
return S;
}
}

149
rene/util/xml/XmlTag.java Normal file
View file

@ -0,0 +1,149 @@
/*
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.util.xml;
public class XmlTag {
protected String Tag = "";
String Param[];
String Value[];
int N = 0;
public XmlTag(final String s) {
int n = 0;
int k = 0;
n = skipBlanks(s, n);
while (n < s.length()) {
n = endItem(s, n);
k++;
n = skipBlanks(s, n);
}
if (k == 0)
return;
n = 0;
n = skipBlanks(s, n);
int m = endItem(s, n);
Tag = s.substring(n, m);
n = m;
N = k - 1;
Param = new String[N];
Value = new String[N];
for (int i = 0; i < N; i++) {
n = skipBlanks(s, n);
m = endItem(s, n);
final String p = s.substring(n, m);
n = m;
final int kp = p.indexOf('=');
if (kp >= 0) {
Param[i] = p.substring(0, kp);
Value[i] = XmlTranslator.toText(p.substring(kp + 1));
if (Value[i].startsWith("\"") && Value[i].endsWith("\"")) {
Value[i] = Value[i].substring(1, Value[i].length() - 1);
} else if (Value[i].startsWith("\'") && Value[i].endsWith("\'")) {
Value[i] = Value[i].substring(1, Value[i].length() - 1);
}
} else {
Param[i] = p;
Value[i] = "";
}
}
}
int skipBlanks(final String s, int n) {
while (n < s.length()) {
final char c = s.charAt(n);
if (c == ' ' || c == '\t' || c == '\n')
n++;
else
break;
}
return n;
}
int endItem(final String s, int n) {
while (n < s.length()) {
final char c = s.charAt(n);
if (c == ' ' || c == '\t' || c == '\n')
break;
if (c == '\"') {
n++;
while (true) {
if (n >= s.length())
return n;
if (s.charAt(n) == '\"')
break;
n++;
}
} else if (c == '\'') {
n++;
while (true) {
if (n >= s.length())
return n;
if (s.charAt(n) == '\'')
break;
n++;
}
}
n++;
}
return n;
}
public String name() {
return Tag;
}
public int countParams() {
return N;
}
public String getParam(final int i) {
return Param[i];
}
public String getValue(final int i) {
return Value[i];
}
public boolean hasParam(final String param) {
for (int i = 0; i < N; i++)
if (Param[i].equals(param))
return true;
return false;
}
public boolean hasTrueParam(final String param) {
for (int i = 0; i < N; i++)
if (Param[i].equals(param)) {
if (Value[i].equals("true"))
return true;
return false;
}
return false;
}
public String getValue(final String param) {
for (int i = 0; i < N; i++)
if (Param[i].equals(param))
return Value[i];
return null;
}
}

View file

@ -0,0 +1,30 @@
/*
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.util.xml;
public class XmlTagPI extends XmlTag {
String Content;
public XmlTagPI(final String s) {
super(s);
}
}

View file

@ -0,0 +1,30 @@
/*
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.util.xml;
public class XmlTagRoot extends XmlTag {
String Content;
public XmlTagRoot() {
super("#ROOT");
}
}

View file

@ -0,0 +1,35 @@
/*
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.util.xml;
public class XmlTagText extends XmlTag {
String Content;
public XmlTagText(final String s) {
super("#PCDATA");
Content = s;
}
public String getContent() {
return Content;
}
}

View file

@ -0,0 +1,104 @@
/*
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.util.xml;
import rene.util.SimpleStringBuffer;
public class XmlTranslator {
static SimpleStringBuffer H = new SimpleStringBuffer(10000);
static String toXml(final String s) {
final int m = s.length();
H.clear();
for (int i = 0; i < m; i++) {
final char c = s.charAt(i);
switch (c) {
case '<':
toH("&lt;");
break;
case '>':
toH("&gt;");
break;
case '&':
toH("&amp;");
break;
case '\'':
toH("&apos;");
break;
case '\"':
toH("&quot;");
break;
default:
H.append(c);
}
}
return H.toString();
}
static void toH(final String s) {
final int m = s.length();
for (int i = 0; i < m; i++) {
H.append(s.charAt(i));
}
}
static String toText(final String s) {
final int m = s.length();
H.clear();
for (int i = 0; i < m; i++) {
final char c = s.charAt(i);
if (c == '&') {
if (find(s, i, "&lt;")) {
H.append('<');
i += 3;
} else if (find(s, i, "&gt;")) {
H.append('>');
i += 3;
} else if (find(s, i, "&quot;")) {
H.append('\"');
i += 5;
} else if (find(s, i, "&apos;")) {
H.append('\'');
i += 5;
} else if (find(s, i, "&amp;")) {
H.append('&');
i += 4;
} else
H.append(c);
} else
H.append(c);
}
return H.toString();
}
static boolean find(final String s, final int pos, final String t) {
try {
for (int i = 0; i < t.length(); i++) {
if (s.charAt(pos + i) != t.charAt(i))
return false;
}
return true;
} catch (final Exception e) {
return false;
}
}
}

119
rene/util/xml/XmlTree.java Normal file
View file

@ -0,0 +1,119 @@
/*
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.util.xml;
import java.util.Enumeration;
import java.util.Vector;
import rene.util.list.ListElement;
import rene.util.list.Tree;
import rene.util.parser.StringParser;
public class XmlTree extends Tree implements Enumeration {
public XmlTree(final XmlTag t) {
super(t);
}
public XmlTag getTag() {
return (XmlTag) content();
}
public XmlTree xmlFirstContent() {
if (firstchild() != null)
return (XmlTree) firstchild();
else
return null;
}
public boolean isText() {
if (!haschildren())
return true;
if (firstchild() != lastchild())
return false;
final XmlTree t = (XmlTree) firstchild();
final XmlTag tag = t.getTag();
if (!(tag instanceof XmlTagText))
return false;
return true;
}
public String getText() {
if (!haschildren())
return "";
final XmlTree t = (XmlTree) firstchild();
final XmlTag tag = t.getTag();
return ((XmlTagText) tag).getContent();
}
ListElement Current;
public Enumeration getContent() {
Current = children().first();
return this;
}
public boolean hasMoreElements() {
return Current != null;
}
public Object nextElement() {
if (Current == null)
return null;
final XmlTree c = (XmlTree) (Current.content());
Current = Current.next();
return c;
}
public String parseComment() throws XmlReaderException {
final StringBuffer s = new StringBuffer();
final Enumeration e = getContent();
while (e.hasMoreElements()) {
final XmlTree tree = (XmlTree) e.nextElement();
final XmlTag tag = tree.getTag();
if (tag.name().equals("P")) {
if (!tree.haschildren())
s.append("\n");
else {
final XmlTree h = tree.xmlFirstContent();
String k = ((XmlTagText) h.getTag()).getContent();
k = k.replace('\n', ' ');
final StringParser p = new StringParser(k);
final Vector v = p.wraplines(1000);
for (int i = 0; i < v.size(); i++) {
s.append((String) v.elementAt(i));
s.append("\n");
}
}
} else if (tag instanceof XmlTagText) {
final String k = ((XmlTagText) tag).getContent();
final StringParser p = new StringParser(k);
final Vector v = p.wraplines(1000);
for (int i = 0; i < v.size(); i++) {
s.append((String) v.elementAt(i));
s.append("\n");
}
} else
throw new XmlReaderException("<" + tag.name()
+ "> not proper here.");
}
return s.toString();
}
}

View file

@ -0,0 +1,203 @@
/*
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.util.xml;
import java.io.PrintWriter;
import java.util.Vector;
import rene.util.parser.StringParser;
public class XmlWriter {
PrintWriter Out;
public XmlWriter(final PrintWriter o) {
Out = o;
}
public void printTag(final String tag, final String content) {
startTag(tag);
print(content);
endTag(tag);
}
public void printTagNewLine(final String tag, final String content) {
printTag(tag, content);
Out.println();
}
public void printTag(final String tag, final String arg,
final String value, final String content) {
startTag(tag, arg, value);
print(content);
endTag(tag);
}
public void printTagNewLine(final String tag, final String arg,
final String value, final String content) {
printTag(tag, arg, value, content);
Out.println();
}
public void startTag(final String tag) {
Out.print("<");
Out.print(tag);
Out.print(">");
}
public void startTag(final String tag, final String arg, final String value) {
Out.print("<");
Out.print(tag);
printArg(arg, value);
Out.print(">");
}
public void finishTag(final String tag, final String arg, final String value) {
Out.print("<");
Out.print(tag);
printArg(arg, value);
Out.println("/>");
}
public void finishTag(final String tag) {
Out.print("<");
Out.print(tag);
Out.print("/>");
}
public void finishTagNewLine(final String tag) {
Out.print("<");
Out.print(tag);
Out.println("/>");
}
public void startTagStart(final String tag) {
Out.print("<");
Out.print(tag);
}
public void startTagEnd() {
Out.print(">");
}
public void finishTag() {
Out.print("/>");
}
public void finishTagNewLine() {
Out.println("/>");
}
public void startTagEndNewLine() {
Out.println(">");
}
public void printArg(final String arg, final String value) {
Out.print(" ");
print(arg);
Out.print("=\"");
print(value);
Out.print("\"");
}
public void startTagNewLine(final String tag, final String arg,
final String value) {
startTag(tag, arg, value);
Out.println();
}
public void startTagNewLine(final String tag) {
startTag(tag);
Out.println();
}
public void endTag(final String tag) {
Out.print("</");
Out.print(tag);
Out.print(">");
}
public void endTagNewLine(final String tag) {
endTag(tag);
Out.println();
}
public void println() {
Out.println();
}
public void print(final String s) {
Out.print(XmlTranslator.toXml(s));
}
public void println(final String s) {
Out.println(XmlTranslator.toXml(s));
}
public void printEncoding(final String s) {
if (s.equals(""))
Out.println("<?xml version=\"1.0\"?>");
else
Out.println("<?xml version=\"1.0\" encoding=\"" + s + "\"?>");
}
public void printXml() {
printEncoding("");
}
public void printEncoding() {
printEncoding("utf-8");
}
public void printXls(final String s) {
Out.println("<?xml-stylesheet href=\"" + s + "\" type=\"text/xsl\"?>");
}
public void printParagraphs(String s, final int linelength) {
final StringParser p = new StringParser(s);
final Vector v = p.wrapwords(linelength);
for (int i = 0; i < v.size(); i++) {
startTag("P");
s = (String) v.elementAt(i);
final StringParser q = new StringParser(s);
final Vector w = q.wraplines(linelength);
for (int j = 0; j < w.size(); j++) {
if (j > 0)
println();
s = (String) w.elementAt(j);
print(s);
}
endTagNewLine("P");
}
}
public void printDoctype(final String top, final String dtd) {
Out.print("<!DOCTYPE ");
Out.print(top);
Out.print(" SYSTEM \"");
Out.print(dtd);
Out.println("\">");
}
public void close() {
Out.close();
}
}

View file

@ -0,0 +1,423 @@
/*
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.viewer;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.Scrollbar;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.io.PrintWriter;
import java.util.Enumeration;
import eric.JEricPanel;
import rene.gui.Global;
import rene.gui.Panel3D;
import rene.util.MyVector;
/**
* An extended Version of the Viewer. It is able to reformat lines, when the
* area is resized. It has no vertical scrollbar. Text is stored into a separate
* string buffer, and will be formatted on repaint.
*/
public class ExtendedViewer extends Viewer implements AdjustmentListener,
MouseListener, MouseMotionListener, ActionListener, KeyListener,
WheelListener {
/**
*
*/
private static final long serialVersionUID = 1L;
TextDisplay TD;
Scrollbar Vertical;
TextPosition Start, End;
PopupMenu PM;
int X, Y;
JEricPanel P3D;
MyVector V; // Vector of lines
StringBuffer B; // Buffer for last line
boolean Changed = false;
public ExtendedViewer() {
TD = new TextDisplay(this);
setLayout(new BorderLayout());
add("Center", P3D = new Panel3D(TD));
add("East", Vertical = new Scrollbar(Scrollbar.VERTICAL, 0, 100, 0,
1100));
Vertical.addAdjustmentListener(this);
TD.addMouseListener(this);
TD.addMouseMotionListener(this);
Start = End = null;
PM = new PopupMenu();
MenuItem mi = new MenuItem(Global.name("block.copy", "Copy"));
mi.addActionListener(this);
PM.add(mi);
PM.addSeparator();
mi = new MenuItem(Global.name("block.begin", "Begin Block"));
mi.addActionListener(this);
PM.add(mi);
mi = new MenuItem(Global.name("block.end", "End Block"));
mi.addActionListener(this);
PM.add(mi);
add(PM);
final Wheel W = new Wheel(this);
addMouseWheelListener(W);
V = new MyVector();
B = new StringBuffer();
}
@Override
public void setFont(final Font f) {
TD.init(f);
}
@Override
public void appendLine(final String s) {
B.append(s);
V.addElement(B.toString());
B.setLength(0);
Changed = true;
}
public void newLine() {
V.addElement(B.toString());
B.setLength(0);
Changed = true;
}
@Override
public void appendLine(final String s, final Color c) {
appendLine(s);
}
@Override
public void append(final String s) {
B.append(s);
}
@Override
public void append(final String s, final Color c) {
append(s);
}
@Override
public void doUpdate(final boolean showlast) {
}
public void update() {
resized();
showFirst();
}
@Override
public void adjustmentValueChanged(final AdjustmentEvent e) {
if (e.getSource() == Vertical) {
switch (e.getAdjustmentType()) {
case AdjustmentEvent.UNIT_INCREMENT:
TD.verticalUp();
break;
case AdjustmentEvent.UNIT_DECREMENT:
TD.verticalDown();
break;
case AdjustmentEvent.BLOCK_INCREMENT:
TD.verticalPageUp();
break;
case AdjustmentEvent.BLOCK_DECREMENT:
TD.verticalPageDown();
break;
default:
final int v = Vertical.getValue();
Vertical.setValue(v);
TD.setVertical(v);
return;
}
setVerticalScrollbar();
}
}
@Override
public void setVerticalScrollbar() {
if (Vertical == null)
return;
final int h = TD.computeVerticalSize();
Vertical.setValues(TD.computeVertical(), h, 0, 1000 + h);
}
@Override
public void setText(final String S) {
TD.unmark();
Start = End = null;
TD.setText(S);
V.removeAllElements();
B.setLength(0);
setVerticalScrollbar();
}
@Override
public void save(final PrintWriter fo) {
TD.save(fo);
}
@Override
public void appendLine0(final String s) {
appendLine(s);
}
@Override
public void appendLine0(final String s, final Color c) {
appendLine(s);
}
boolean Dragging = false;
@Override
public void mouseClicked(final MouseEvent e) {
}
@Override
public void mousePressed(final MouseEvent e) {
if (e.isPopupTrigger() || e.isMetaDown()) {
PM.show(e.getComponent(), e.getX(), e.getY());
X = e.getX();
Y = e.getY();
} else {
TD.unmark(Start, End);
Start = TD.getposition(e.getX(), e.getY());
Start.oneleft();
End = null;
}
}
@Override
public Dimension getPreferredSize() {
return new Dimension(150, 200);
}
@Override
public Dimension getMinimumSize() {
return new Dimension(150, 200);
}
@Override
public void mouseReleased(final MouseEvent e) {
Dragging = false;
}
@Override
public void mouseEntered(final MouseEvent e) {
}
@Override
public void mouseExited(final MouseEvent e) {
}
@Override
public void mouseMoved(final MouseEvent e) {
}
@Override
public void mouseDragged(final MouseEvent e) {
TD.unmark(Start, End);
final TextPosition h = TD.getposition(e.getX(), e.getY());
if (h != null)
End = h;
TD.mark(Start, End);
}
@Override
public void actionPerformed(final ActionEvent e) {
final String o = e.getActionCommand();
if (o.equals(Global.name("block.copy", "Copy")))
TD.copy(Start, End);
else if (o.equals(Global.name("block.begin", "Begin Block"))) {
TD.unmark(Start, End);
Start = TD.getposition(X, Y);
Start.oneleft();
if (End == null && TD.L.last() != null) {
End = TD.lastpos();
}
TD.mark(Start, End);
} else if (o.equals(Global.name("block.end", "End Block"))) {
TD.unmark(Start, End);
End = TD.getposition(X, Y);
if (Start == null && TD.L.first() != null) {
Start = new TextPosition(TD.L.first(), 0, 0);
}
TD.mark(Start, End);
}
}
@Override
public void keyPressed(final KeyEvent e) {
}
@Override
public void keyReleased(final KeyEvent e) {
if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_C
&& Start != null && End != null) {
TD.copy(Start, End);
}
}
@Override
public void keyTyped(final KeyEvent e) {
}
@Override
public void setTabWidth(final int t) {
TD.setTabWidth(t);
}
@Override
public void showFirst() {
TD.showFirst();
setVerticalScrollbar();
TD.repaint();
}
@Override
public void showLast() {
TD.showlast();
setVerticalScrollbar();
TD.repaint();
}
@Override
public boolean hasFocus() {
return false;
}
@Override
public void setBackground(final Color c) {
TD.setBackground(c);
P3D.setBackground(c);
super.setBackground(c);
}
@Override
public void up(final int n) {
for (int i = 0; i < n; i++)
TD.verticalUp();
setVerticalScrollbar();
}
@Override
public void down(final int n) {
for (int i = 0; i < n; i++)
TD.verticalDown();
setVerticalScrollbar();
}
@Override
public void pageUp() {
TD.verticalPageUp();
setVerticalScrollbar();
}
@Override
public void pageDown() {
TD.verticalPageDown();
setVerticalScrollbar();
}
@Override
public void paint(final Graphics G) {
super.paint(G);
}
public void doAppend(final String s) {
final char a[] = s.toCharArray();
final int w[] = TD.getwidth(a);
int start = 0, end = 0;
final int W = TD.getSize().width;
int goodbreak;
while (start < a.length && a[start] == ' ')
start++;
if (start >= a.length) {
TD.appendLine("");
return;
}
int blanks = 0;
String sblanks = "";
int offset = 0;
if (start > 0) {
blanks = start;
sblanks = new String(a, 0, blanks);
offset = blanks + w[0];
}
while (start < a.length) {
int tw = TD.Offset + offset;
end = start;
goodbreak = start;
while (end < a.length && tw < W) {
tw += w[end];
if (a[end] == ' ')
goodbreak = end;
end++;
}
if (tw < W)
goodbreak = end;
if (goodbreak == start)
goodbreak = end;
if (blanks > 0)
TD
.appendLine(sblanks
+ new String(a, start, goodbreak - start));
else
TD.appendLine(new String(a, start, goodbreak - start));
start = goodbreak;
while (start < a.length && a[start] == ' ')
start++;
}
}
@Override
public synchronized void resized() {
if (TD.getSize().width <= 0)
return;
TD.setText("");
final Enumeration e = V.elements();
while (e.hasMoreElements()) {
final String s = (String) e.nextElement();
doAppend(s);
}
TD.repaint();
}
public void mouseWheelMoved(final MouseWheelEvent arg0) {
}
}

224
rene/viewer/Line.java Normal file
View file

@ -0,0 +1,224 @@
/*
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.viewer;
import java.awt.Color;
import java.awt.Graphics;
public class Line {
TextDisplay TD;
boolean Chosen;
int Pos, Posend;
int Block; // block state
static final int NONE = 0, START = 1, END = 2, FULL = 4; // block states
// (logically
// or'ed)
Color C, IC; // Color of line and high key color of the line
char a[]; // Contains the characters of this line
public Line(final String s, final TextDisplay td) {
this(s, td, Color.black);
}
/**
* Generate a line containing s in the textdisplay td. Display color is c.
*
* @param s
* @param td
* @param c
*/
public Line(final String s, final TextDisplay td, final Color c) {
TD = td;
C = c;
// Create a color that is very bright, but resembles the line color
IC = new Color(C.getRed() / 4 + 192, C.getGreen() / 4 + 192, C
.getBlue() / 4 + 192);
Block = NONE;
a = s.toCharArray();
}
public void expandTabs(final int tabwidth) {
int pos = 0;
for (final char element : a) {
pos++;
if (element == '\t')
pos = (pos / tabwidth + 1) * tabwidth;
}
final char b[] = new char[pos];
pos = 0;
for (final char element : a) {
if (element == '\t') {
final int newpos = ((pos + 1) / tabwidth + 1) * tabwidth;
for (int k = pos; k < newpos; k++)
b[k] = ' ';
pos = newpos;
} else
b[pos++] = element;
}
a = b;
}
int length() {
return a.length;
}
int getpos(final int x, final int offset) {
final int l[] = TD.getwidth(a);
int h = offset - TD.Offset * TD.FM.charWidth(' ');
if (x < h)
return 0;
int i = 0;
while (x > h && i < a.length) {
h += l[i];
i++;
}
return i;
}
/**
* Draw a line. If the line is in a block, draw it white on black or on dark
* gray, depending on the focus. Drawing in blocks does not use antialias.
*
* @param g
* @param x
* @param y
*/
public void draw(final Graphics g, int x, final int y) {
x -= TD.Offset * TD.FM.charWidth(' ');
if (Chosen) // Complete line is chosen (in Lister)
{ // To see, if the display has the focus:
if (TD.hasFocus())
g.setColor(Color.darkGray);
else
g.setColor(Color.gray);
g.fillRect(0, y - TD.Ascent, TD.getSize().width, TD.Height);
g.setColor(IC); // draw in light color
TD.antialias(false);
g.drawChars(a, 0, a.length, x, y);
TD.antialias(true);
} else if ((Block & FULL) != 0) // Line in full block (in Viewer)
{
g.setColor(Color.darkGray);
g.fillRect(x, y - TD.Ascent, TD.FM.charsWidth(a, 0, a.length),
TD.Height);
g.setColor(Color.white);
TD.antialias(false);
g.drawChars(a, 0, a.length, x, y);
TD.antialias(true);
} else if ((Block & START) != 0) {
if (Pos > 0) // Draw text before block
{
g.setColor(C);
g.drawChars(a, 0, Pos, x, y);
x += TD.FM.charsWidth(a, 0, Pos);
}
if ((Block & END) != 0) // draw text in block
{
if (Posend > Pos) {
final int h = TD.FM.charsWidth(a, Pos, Posend - Pos);
g.setColor(Color.darkGray);
g.fillRect(x, y - TD.Ascent, h, TD.Height);
g.setColor(Color.white);
TD.antialias(false);
g.drawChars(a, Pos, Posend - Pos, x, y);
TD.antialias(true);
g.setColor(C);
x += h;
if (a.length > Posend) {
g.drawChars(a, Posend, a.length - Posend, x, y);
}
} else
g.drawChars(a, Pos, a.length - Pos, x, y);
} else // draw the rest of the line in block
{
final int h = TD.FM.charsWidth(a, Pos, a.length - Pos);
g.setColor(Color.darkGray);
g.fillRect(x, y - TD.Ascent, h, TD.Height);
g.setColor(Color.white);
TD.antialias(false);
g.drawChars(a, Pos, a.length - Pos, x, y);
TD.antialias(true);
}
} else if ((Block & END) != 0) {
final int h = TD.FM.charsWidth(a, 0, Posend);
g.setColor(Color.darkGray);
g.fillRect(x, y - TD.Ascent, h, TD.Height);
g.setColor(Color.white);
TD.antialias(false);
g.drawChars(a, 0, Posend, x, y);
TD.antialias(true);
g.setColor(C);
x += h;
if (a.length > Posend) {
g.drawChars(a, Posend, a.length - Posend, x, y);
}
} else {
g.setColor(C);
g.drawChars(a, 0, a.length, x, y);
}
}
void append(final String s) {
a = (new String(a) + s).toCharArray();
}
void chosen(final boolean f) {
Chosen = f;
}
public boolean chosen() {
return Chosen;
}
void block(final int pos, final int mode) {
switch (mode) {
case NONE:
Block = NONE;
break;
case FULL:
Block = FULL;
break;
case START:
Block |= START;
Pos = pos;
break;
case END:
Block |= END;
Posend = pos;
break;
}
}
String getblock() {
if (Block == FULL) {
return new String(a, 0, a.length);
} else if ((Block & START) != 0) {
if ((Block & END) != 0) {
return new String(a, Pos, Posend - Pos);
} else
return new String(a, Pos, a.length - Pos);
} else if ((Block & END) != 0)
return new String(a, 0, Posend);
else
return "";
}
}

View 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.viewer;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.TextArea;
import java.io.PrintWriter;
public class SystemViewer extends Viewer {
/**
*
*/
private static final long serialVersionUID = 1L;
TextArea T;
public SystemViewer() {
super("dummy");
setLayout(new BorderLayout());
add("Center", T = new TextArea());
}
@Override
public void appendLine(final String s) {
T.append(s + "\n");
}
@Override
public void appendLine(final String s, final Color c) {
appendLine(s);
}
@Override
public void append(final String s) {
T.append(s);
}
@Override
public void append(final String s, final Color c) {
append(s);
}
@Override
public void setText(final String s) {
T.setText(s);
}
@Override
public void doUpdate(final boolean showlast) {
T.repaint();
}
@Override
public void setFont(final Font s) {
T.setFont(s);
}
@Override
public void save(final PrintWriter fo) {
fo.print(T.getText());
fo.flush();
}
}

View file

@ -0,0 +1,575 @@
/*
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.viewer;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.SystemColor;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.io.PrintWriter;
import rene.gui.Global;
import rene.util.list.ListClass;
import rene.util.list.ListElement;
class ClipboardCopy extends Thread {
String S;
ClipboardOwner C;
Canvas Cv;
public ClipboardCopy(final ClipboardOwner c, final Canvas cv, final String s) {
S = s;
C = c;
Cv = cv;
start();
}
@Override
public void run() {
final Clipboard clip = Cv.getToolkit().getSystemClipboard();
final StringSelection cont = new StringSelection(S);
clip.setContents(cont, C);
}
}
public class TextDisplay extends Canvas implements ClipboardOwner,
ComponentListener {
/**
*
*/
private static final long serialVersionUID = 1L;
ListClass L;
Font F = null;
FontMetrics FM;
Viewer V;
int Leading, Height, Ascent, Descent;
int LineCount, TopLineCount;
int PageSize;
ListElement TopLine;
Image I;
Graphics IG;
int W, H;
public int Tabsize = 4;
public int Offset;
boolean LineFinished = true;
int Widths[], HW[];
long LastScrollTime;
Color Background;
int TabWidth = 0;
public TextDisplay(final Viewer v) {
L = new ListClass();
F = null;
V = v;
LineCount = 0;
TopLineCount = 0;
TopLine = null;
I = null;
W = H = 0;
PageSize = 10;
HW = new int[1024];
addKeyListener(v);
addComponentListener(this);
}
void init(final Font f) {
F = f;
FM = getFontMetrics(F);
Leading = FM.getLeading()
+ Global.getParameter("fixedfont.spacing", -1);
Height = FM.getHeight();
Ascent = FM.getAscent();
Descent = FM.getDescent();
Widths = FM.getWidths();
}
@Override
public Color getBackground() {
return SystemColor.window;
}
int[] getwidth(final char a[]) {
try {
for (int i = 0; i < a.length; i++) {
if (a[i] < 256)
HW[i] = Widths[a[i]];
else
HW[i] = FM.charWidth(a[i]);
}
} catch (final Exception e) {
return HW;
}
return HW;
}
public synchronized void appendLine0(final String S) {
appendLine0(S, Color.black);
}
public synchronized void appendLine0(final String S, final Color c) {
Line l;
L.append(new ListElement(l = new Line(S, this, c)));
LineCount++;
if (LineCount == 1)
TopLine = L.first();
LineFinished = true;
if (TabWidth > 0)
l.expandTabs(TabWidth);
}
public synchronized void appendLine(final String s) {
appendLine0(s);
V.setVerticalScrollbar();
}
public void append(final String S, final Color c) {
append(S, c, true);
}
public void append(String S, final Color c, final boolean suddenupdate) {
while (true) {
final int p = S.indexOf('\n');
if (p < 0) {
appendlast(S, c);
LineFinished = false;
break;
}
appendlast(S.substring(0, p), c);
LineFinished = true;
S = S.substring(p + 1);
if (S.equals("")) {
break;
}
}
if (suddenupdate)
doUpdate(true);
repaint();
}
public void doUpdate(final boolean showlast) {
if (showlast) {
final long m = System.currentTimeMillis();
if (m - LastScrollTime > 10000)
showlast();
}
repaint();
V.setVerticalScrollbar();
}
public void setText(final String s) {
TopLine = null;
TopLineCount = 0;
LineCount = 0;
L = new ListClass();
if (!s.equals(""))
append(s, Color.black);
repaint();
}
public synchronized void appendlast(final String s, final Color c) {
if (LineFinished || L.last() == null) {
Line l;
L.append(new ListElement(l = new Line(s, this, c)));
LineCount++;
if (LineCount == 1)
TopLine = L.first();
if (TabWidth > 0)
l.expandTabs(TabWidth);
} else {
((Line) L.last().content()).append(s);
}
}
public void showlast() {
ListElement e = L.last();
if (e == null)
return;
TopLineCount = LineCount;
for (int i = 0; i < PageSize - 1; i++) {
if (e.previous() == null)
break;
e = e.previous();
TopLineCount--;
}
TopLine = e;
repaint();
}
public void makeimage() {
final Dimension D = getSize();
if (I == null || D.width != W || D.height != H) {
try {
I = createImage(W = D.width, H = D.height);
IG = I.getGraphics();
} catch (final Exception e) {
}
}
IG.setColor(Color.black);
IG.clearRect(0, 0, W, H);
IG.setFont(F);
try {
PageSize = H / (Height + Leading);
} catch (final Exception e) {
}
}
@Override
public synchronized void paint(final Graphics g) {
if (F == null)
init(getFont());
makeimage();
ListElement e = TopLine;
antialias(true);
int h = Leading + Ascent;
if (Background == null)
Background = getBackground();
IG.setColor(Background);
IG.fillRect(0, 0, W, H);
int lines = 0;
while (lines < PageSize && e != null) {
final Line l = (Line) e.content();
l.draw(IG, 2, h);
h += Leading + Height;
e = e.next();
lines++;
}
g.drawImage(I, 0, 0, this);
}
/**
* Set Anti-Aliasing on or off, if in Java 1.2 or better and the Parameter
* "font.smooth" is switched on.
*
* @param flag
*/
public void antialias(final boolean flag) {
if (Global.getParameter("font.smooth", true)) {
IG = (Graphics2D) IG;
((Graphics2D) IG).setRenderingHint(
RenderingHints.KEY_TEXT_ANTIALIASING,
flag ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON
: RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
}
}
public void showLine(final ListElement line) {
ListElement e = TopLine;
int h = Leading + Ascent;
if (Background == null)
Background = getBackground();
int lines = 0;
while (lines < PageSize && e != null) {
if (e == line)
return;
h += Leading + Height;
e = e.next();
lines++;
}
if (e == line && TopLine.next() != null)
TopLine = TopLine.next();
else
TopLine = line;
}
public ListElement getline(final int y) {
if (TopLine == null)
return null;
ListElement e = TopLine;
int h = Leading + Height;
if (h == 0)
return null;
h = y / h;
for (int i = 0; i < h; i++) {
if (e.next() == null)
return e;
e = e.next();
}
return e;
}
@Override
public void update(final Graphics g) {
paint(g);
}
int computeVertical() {
if (LineCount > 0)
return TopLineCount * 1000 / LineCount;
else
return 0;
}
public int setVertical(final int v) {
if (TopLine == null)
return 0;
final int NewTop = LineCount * v / 1000;
if (NewTop > TopLineCount) {
for (int i = TopLineCount; i < NewTop; i++) {
if (TopLine.next() == null)
break;
TopLine = TopLine.next();
TopLineCount++;
}
repaint();
} else if (NewTop < TopLineCount) {
for (int i = TopLineCount; i > NewTop; i--) {
if (TopLine.previous() == null)
break;
TopLine = TopLine.previous();
TopLineCount--;
}
repaint();
}
LastScrollTime = System.currentTimeMillis();
return v;
}
public void verticalUp() {
if (TopLine == null)
return;
if (TopLine.next() == null)
return;
TopLine = TopLine.next();
TopLineCount++;
repaint();
LastScrollTime = System.currentTimeMillis();
}
public void verticalDown() {
if (TopLine == null)
return;
if (TopLine.previous() == null)
return;
TopLine = TopLine.previous();
TopLineCount--;
repaint();
LastScrollTime = System.currentTimeMillis();
}
public void verticalPageUp() {
if (TopLine == null)
return;
for (int i = 0; i < PageSize - 1; i++) {
if (TopLine.next() == null)
break;
TopLine = TopLine.next();
TopLineCount++;
}
repaint();
LastScrollTime = System.currentTimeMillis();
}
public void verticalPageDown() {
if (TopLine == null)
return;
for (int i = 0; i < PageSize - 1; i++) {
if (TopLine.previous() == null)
break;
TopLine = TopLine.previous();
TopLineCount--;
}
repaint();
LastScrollTime = System.currentTimeMillis();
}
int computeVerticalSize() {
if (LineCount == 0)
return 100;
int h = PageSize * 2000 / LineCount;
if (h < 10)
h = 10;
return h;
}
public int setHorizontal(final int v) {
Offset = v / 5;
repaint();
return v;
}
public void save(final PrintWriter fo) {
ListElement e = L.first();
while (e != null) {
fo.println(new String(((Line) e.content()).a));
e = e.next();
}
}
public TextPosition getposition(final int x, final int y) {
if (L.first() == null)
return null;
if (y < 0)
return new TextPosition(TopLine, TopLineCount, 0);
if (TopLine == null)
return null;
ListElement e = TopLine;
int h = Leading + Height;
if (h == 0)
return null;
h = y / h;
int i;
for (i = 0; i < h; i++) {
if (e.next() == null || i == PageSize - 1)
return new TextPosition(e, TopLineCount + i, ((Line) e
.content()).length());
e = e.next();
}
return new TextPosition(e, TopLineCount + i, ((Line) e.content())
.getpos(x, 2));
}
public void unmark() {
ListElement e = L.first();
while (e != null) {
((Line) e.content()).block(0, Line.NONE);
e = e.next();
}
repaint();
}
public void unmark(final TextPosition Start, final TextPosition End) {
if (Start == null || End == null)
return;
TextPosition P1, P2;
if (Start.before(End)) {
P1 = Start;
P2 = End;
} else if (End.before(Start)) {
P1 = End;
P2 = Start;
} else
return;
ListElement e = P1.L;
while (e != null && e != P2.L) {
((Line) e.content()).block(0, Line.NONE);
e = e.next();
}
if (e != null)
((Line) e.content()).block(0, Line.NONE);
repaint();
}
public void mark(final TextPosition Start, final TextPosition End) {
if (Start == null || End == null)
return;
TextPosition P1, P2;
if (Start.before(End)) {
P1 = Start;
P2 = End;
} else if (End.before(Start)) {
P1 = End;
P2 = Start;
} else
return;
ListElement e = P1.L;
((Line) e.content()).block(P1.LPos, Line.START);
if (e != P2.L)
e = e.next();
while (e != null && e != P2.L) {
((Line) e.content()).block(0, Line.FULL);
e = e.next();
}
if (e != null)
((Line) e.content()).block(P2.LPos, Line.END);
repaint();
requestFocus();
}
void copy(final TextPosition Start, final TextPosition End) {
if (Start == null || End == null)
return;
TextPosition P1, P2;
if (Start.before(End)) {
P1 = Start;
P2 = End;
} else if (End.before(Start)) {
P1 = End;
P2 = Start;
} else
return;
String s = "";
ListElement e = P1.L;
while (e != null && e != P2.L) {
s = s + ((Line) e.content()).getblock() + "\n";
e = e.next();
}
if (e != null)
s = s + ((Line) e.content()).getblock();
new ClipboardCopy(this, this, s);
}
public void showFirst() {
TopLine = L.first();
}
public void lostOwnership(final Clipboard clip, final Transferable cont) {
}
TextPosition lastpos() {
final ListElement e = L.last();
if (e == null)
return null;
final Line l = (Line) e.content();
return new TextPosition(e, LineCount, l.length());
}
public void setTabWidth(final int t) {
TabWidth = t;
}
@Override
public boolean hasFocus() {
return V.hasFocus();
}
@Override
public void setBackground(final Color c) {
Background = c;
super.setBackground(c);
}
public void componentHidden(final ComponentEvent e) {
}
public void componentMoved(final ComponentEvent e) {
}
public void componentResized(final ComponentEvent e) {
V.resized();
}
public void componentShown(final ComponentEvent e) {
}
}

View 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.viewer;
import rene.util.list.ListElement;
class TextPosition {
ListElement L;
int LCount;
int LPos;
public TextPosition(final ListElement l, final int lcount, final int lpos) {
L = l;
LCount = lcount;
LPos = lpos;
}
boolean equal(final TextPosition p) {
return p.LCount == LCount && p.LPos == LPos;
}
boolean before(final TextPosition p) {
return p.LCount > LCount || (p.LCount == LCount && p.LPos > LPos);
}
void oneleft() {
if (LPos > 0)
LPos--;
}
}

339
rene/viewer/Viewer.java Normal file
View file

@ -0,0 +1,339 @@
/*
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.viewer;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.Scrollbar;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.PrintWriter;
import eric.JEricPanel;
import rene.gui.Global;
import rene.gui.Panel3D;
/**
* This is a read-only TextArea, removing the memory restriction in some OS's.
* Component usage is like a JPanel. Use appendLine to append a line of text.
* You can give each line a different color. Moreover, you can save the file to
* a PrintWriter. You can mark blocks with the right mouse button. Dragging and
* scrolling is not supported in this version.
*/
public class Viewer extends JEricPanel implements AdjustmentListener,
MouseListener, MouseMotionListener, ActionListener, KeyListener,
WheelListener {
/**
*
*/
private static final long serialVersionUID = 1L;
TextDisplay TD;
Scrollbar Vertical, Horizontal;
TextPosition Start, End;
PopupMenu PM;
int X, Y;
JEricPanel P3D;
public Viewer(final boolean vs, final boolean hs) {
TD = new TextDisplay(this);
setLayout(new BorderLayout());
add("Center", P3D = new Panel3D(TD));
if (vs) {
add("East", Vertical = new Scrollbar(Scrollbar.VERTICAL, 0, 100, 0,
1100));
Vertical.addAdjustmentListener(this);
}
if (hs) {
add("South", Horizontal = new Scrollbar(Scrollbar.HORIZONTAL, 0,
100, 0, 1100));
Horizontal.addAdjustmentListener(this);
}
TD.addMouseListener(this);
TD.addMouseMotionListener(this);
Start = End = null;
PM = new PopupMenu();
MenuItem mi = new MenuItem(Global.name("block.copy", "Copy"));
mi.addActionListener(this);
PM.add(mi);
PM.addSeparator();
mi = new MenuItem(Global.name("block.begin", "Begin Block"));
mi.addActionListener(this);
PM.add(mi);
mi = new MenuItem(Global.name("block.end", "End Block"));
mi.addActionListener(this);
PM.add(mi);
add(PM);
final Wheel W = new Wheel(this);
addMouseWheelListener(W);
}
public Viewer() {
this(true, true);
}
public Viewer(final String dummy) {
}
@Override
public void setFont(final Font f) {
TD.init(f);
}
public void appendLine(final String s) {
TD.appendLine0(s);
}
public void appendLine(final String s, final Color c) {
TD.appendLine0(s, c);
}
public void append(final String s) {
append(s, Color.black);
}
public void append(final String s, final Color c) {
TD.append(s, c);
}
public void doUpdate(final boolean showlast) {
TD.doUpdate(showlast);
setVerticalScrollbar();
}
public void adjustmentValueChanged(final AdjustmentEvent e) {
if (e.getSource() == Vertical) {
switch (e.getAdjustmentType()) {
case AdjustmentEvent.UNIT_INCREMENT:
TD.verticalUp();
break;
case AdjustmentEvent.UNIT_DECREMENT:
TD.verticalDown();
break;
case AdjustmentEvent.BLOCK_INCREMENT:
TD.verticalPageUp();
break;
case AdjustmentEvent.BLOCK_DECREMENT:
TD.verticalPageDown();
break;
default:
final int v = Vertical.getValue();
Vertical.setValue(v);
TD.setVertical(v);
return;
}
setVerticalScrollbar();
} else if (e.getSource() == Horizontal) {
Horizontal.setValue(TD.setHorizontal(Horizontal.getValue()));
}
}
public void setVerticalScrollbar() {
if (Vertical == null)
return;
final int h = TD.computeVerticalSize();
Vertical.setValues(TD.computeVertical(), h, 0, 1000 + h);
}
public void setText(final String S) {
TD.unmark();
Start = End = null;
TD.setText(S);
setVerticalScrollbar();
}
public void save(final PrintWriter fo) {
TD.save(fo);
}
public void appendLine0(final String s) {
TD.appendLine0(s);
}
public void appendLine0(final String s, final Color c) {
TD.appendLine0(s, c);
}
boolean Dragging = false;
public void mouseClicked(final MouseEvent e) {
}
public void mousePressed(final MouseEvent e) {
if (e.isPopupTrigger() || e.isMetaDown()) {
PM.show(e.getComponent(), e.getX(), e.getY());
X = e.getX();
Y = e.getY();
} else {
TD.unmark(Start, End);
Start = TD.getposition(e.getX(), e.getY());
Start.oneleft();
End = null;
}
}
@Override
public Dimension getPreferredSize() {
return new Dimension(150, 200);
}
@Override
public Dimension getMinimumSize() {
return new Dimension(150, 200);
}
public void mouseReleased(final MouseEvent e) {
Dragging = false;
}
public void mouseEntered(final MouseEvent e) {
}
public void mouseExited(final MouseEvent e) {
}
public void mouseMoved(final MouseEvent e) {
}
public void mouseDragged(final MouseEvent e) {
TD.unmark(Start, End);
final TextPosition h = TD.getposition(e.getX(), e.getY());
if (h != null)
End = h;
TD.mark(Start, End);
}
public void actionPerformed(final ActionEvent e) {
final String o = e.getActionCommand();
if (o.equals(Global.name("block.copy", "Copy")))
TD.copy(Start, End);
else if (o.equals(Global.name("block.begin", "Begin Block"))) {
TD.unmark(Start, End);
Start = TD.getposition(X, Y);
Start.oneleft();
if (End == null && TD.L.last() != null) {
End = TD.lastpos();
}
TD.mark(Start, End);
} else if (o.equals(Global.name("block.end", "End Block"))) {
TD.unmark(Start, End);
End = TD.getposition(X, Y);
if (Start == null && TD.L.first() != null) {
Start = new TextPosition(TD.L.first(), 0, 0);
}
TD.mark(Start, End);
}
}
public void keyPressed(final KeyEvent e) {
}
public void keyReleased(final KeyEvent e) {
if (e.isControlDown() && e.getKeyCode() == KeyEvent.VK_C
&& Start != null && End != null) {
TD.copy(Start, End);
}
}
public void keyTyped(final KeyEvent e) {
}
public void setTabWidth(final int t) {
TD.setTabWidth(t);
}
public void showFirst() {
TD.showFirst();
setVerticalScrollbar();
TD.repaint();
}
public void showLast() {
TD.showlast();
setVerticalScrollbar();
TD.repaint();
}
@Override
public boolean hasFocus() {
return false;
}
@Override
public void setBackground(final Color c) {
TD.setBackground(c);
P3D.setBackground(c);
super.setBackground(c);
}
public void up(final int n) {
for (int i = 0; i < n; i++)
TD.verticalUp();
setVerticalScrollbar();
}
public void down(final int n) {
for (int i = 0; i < n; i++)
TD.verticalDown();
setVerticalScrollbar();
}
public void pageUp() {
TD.verticalPageUp();
setVerticalScrollbar();
}
public void pageDown() {
TD.verticalPageDown();
setVerticalScrollbar();
}
public void resized() {
}
public static void main(final String args[]) {
final Frame f = new Frame();
f.setLayout(new BorderLayout());
final Viewer v = new Viewer(true, false);
f.add("Center", v);
f.setSize(300, 300);
f.setVisible(true);
v.append("test test test test test test test");
v.appendLine("test test test test test test test");
v.appendLine("test test test test test test test");
v.appendLine("test test test test test test test");
}
}

48
rene/viewer/Wheel.java Normal file
View 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.viewer;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
class Wheel implements MouseWheelListener {
WheelListener V;
public Wheel(final WheelListener v) {
V = v;
}
public void mouseWheelMoved(final MouseWheelEvent e) {
if (e.getScrollType() == MouseWheelEvent.WHEEL_BLOCK_SCROLL) {
if (e.getWheelRotation() > 0)
V.pageUp();
else
V.pageDown();
} else {
final int n = e.getScrollAmount();
if (e.getWheelRotation() > 0)
V.up(n);
else
V.down(n);
}
}
}

View file

@ -0,0 +1,32 @@
/*
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.viewer;
public interface WheelListener {
void up(int n);
void down(int n);
void pageUp();
void pageDown();
}

0
rene/zirkel/.#Zirkel.java.1.6 Executable file
View file

File diff suppressed because it is too large Load diff

BIN
rene/zirkel/.DS_Store vendored Normal file

Binary file not shown.

View 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.zirkel;
import java.awt.event.MouseEvent;
/**
* @author Rene A thread for reporting drags to the main program, avoiding to
* many drag messages, so that the program seems to hang.
*/
class DragThread extends Thread {
MouseEvent EWaiting = null;
ZirkelCanvas ZC;
Object Ready = new Object();
boolean Working = false;
public DragThread(final ZirkelCanvas zc) {
ZC = zc;
start();
}
@Override
public void run() {
MouseEvent e;
while (true) {
if (EWaiting == null) {
try {
synchronized (this) {
wait();
}
} catch (final Exception ex) {
}
}
if (EWaiting != null) {
synchronized (this) {
e = EWaiting;
EWaiting = null;
}
Working = true;
ZC.doMouseDragged(e);
try {
sleep(0);
} catch (final Exception ex) {
}
Working = false;
synchronized (Ready) {
Ready.notify();
}
}
}
}
public synchronized void mouseDragged(final MouseEvent e) {
EWaiting = e;
notify();
}
public void waitReady() {
if (!Working)
return;
synchronized (Ready) {
try {
Thread.currentThread().wait(1000);
} catch (final Exception ex) {
}
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,38 @@
/*
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.zirkel;
import java.awt.Image;
import rene.zirkel.macro.Macro;
public interface ZirkelCanvasInterface {
public void replayChosen();
public void runMacro(Macro m);
public boolean enabled(String tool);
public String loadImage();
public Image doLoadImage(String filename);
}

Some files were not shown because too many files have changed in this diff Show more