Make first real commit: copy of CaRMetal 4.2.8

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

View file

@ -0,0 +1,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, "");
}
}