[Webfunds-commits] java/webfunds/client/contracts/wizard Wizard.java
Ian Grigg
iang@cypherpunks.ai
Mon, 14 Aug 2000 17:59:02 -0400 (AST)
iang 00/08/14 17:59:02
Modified: webfunds/client/contracts/wizard Wizard.java
Log:
removed ^M at end of line only
Revision Changes Path
1.2 +370 -370 java/webfunds/client/contracts/wizard/Wizard.java
Index: Wizard.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/client/contracts/wizard/Wizard.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Wizard.java 2000/08/08 14:56:52 1.1
+++ Wizard.java 2000/08/14 21:59:02 1.2
@@ -1,370 +1,370 @@
-/*
- * $Id: Wizard.java,v 1.1 2000/08/08 14:56:52 edwin Exp $
- *
- * Copyright (c) Systemics Inc 2000 on behalf of
- * the WebFunds Development Team. All Rights Reserved.
- */
-
-package webfunds.client.contracts.wizard;
-
-
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-import javax.swing.border.*;
-import javax.swing.event.*;
-import javax.swing.tree.*;
-
-
-/**
- * Main class for the wizard
- *
- * @author Edwin Woudt <edwin@webfunds.org>
- * @version $Revision: 1.1 $
- */
-
-public class Wizard extends JPanel
- implements TreeWillExpandListener, ActionListener {
-
-
- final WizardData data = new WizardData();
-
- ImageIcon iconNot = new ImageIcon("iconnot.gif");
- ImageIcon iconYes = new ImageIcon("iconyes.gif");
-
- WizardPanel contractFile = new ContractFile(data);
- WizardPanel contractEdit = new ContractEdit(data);
- WizardPanel keyTop = new KeyTop(data);
- WizardPanel keyContract = new KeyContract(data);
- WizardPanel keyServer = new KeyServer(data);
- WizardPanel finishSig = new FinishSig(data);
- WizardPanel finishEnd = new FinishEnd(data);
-
- WizardPanel[] wizardPanels = { null, contractFile, contractEdit,
- null, keyTop, keyContract, keyServer,
- null, finishSig, finishEnd };
- int wizardActive = -1;
- int wizardPrevAct = -1;
-
- boolean usedNext = false;
-
- JTree tree;
-
-
- public Wizard() {
-
- // GridBagLayout is the most flexible (also the most difficult
- // to use) LayoutManager.
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints c = new GridBagConstraints();
-
- setLayout(gridbag);
-
- // The content pane that contains the panels from all the steps.
- JPanel content = new JPanel();
- OverlayLayout layout = new OverlayLayout(content);
- content.setLayout(layout);
-
- boolean first = true;
- for (int i=0; i<wizardPanels.length; i++) {
- if (wizardPanels[i] != null) {
- if (first) {
- wizardPanels[i].setVisible(true);
- first = false;
- } else {
- wizardPanels[i].setVisible(false);
- }
- content.add(wizardPanels[i]);
- }
- }
-
-
- // Ok, this is where the real dirty work starts. Do not attempt
- // to change it, unless you understand the GridBagLayout and
- // GridBagConstraints, because in case you don't the result
- // will probably be a real f*ck up of the layout.
-
- c.gridheight = 3; c.gridwidth = 1;
- c.gridy = 0; c.gridx = 0;
- c.weighty = 1; c.weightx = 1;
- c.fill = GridBagConstraints.BOTH;
- c.anchor = GridBagConstraints.CENTER;
- c.insets = new Insets(8, 8, 8, 8);
- tree = createTree();
- tree.setBorder(BorderFactory.createEtchedBorder());
- gridbag.setConstraints(tree,c); add(tree);
-
- c.gridheight = 1; c.gridwidth = 4;
- c.gridy = 0; c.gridx = 1;
- c.weighty = 1; c.weightx = 1;
- c.fill = GridBagConstraints.BOTH;
- c.anchor = GridBagConstraints.CENTER;
- c.insets = new Insets(8, 8, 8, 8);
- gridbag.setConstraints(content,c); add(content);
-
- c.gridheight = 1; c.gridwidth = 4;
- c.gridy = 1; c.gridx = 1;
- c.weighty = 0; c.weightx = 1;
- c.fill = GridBagConstraints.BOTH;
- c.anchor = GridBagConstraints.CENTER;
- c.insets = new Insets(8, 8, 4, 8);
- JPanel pane = new JPanel();
- Color color = UIManager.getColor("Label.foreground");
- Border border = BorderFactory.createMatteBorder(0,0,1,0,color);
- pane.setBorder(border);
- gridbag.setConstraints(pane,c); add(pane);
-
- c.gridheight = 1; c.gridwidth = 1;
- c.gridy = 2; c.gridx = 1;
- c.weighty = 0; c.weightx = 0;
- c.fill = GridBagConstraints.NONE;
- c.anchor = GridBagConstraints.WEST;
- c.insets = new Insets(8, 8, 8, 8);
- JButton canc = new JButton("Cancel");
- gridbag.setConstraints(canc,c); add(canc);
-
- // Filler
- c.gridheight = 1; c.gridwidth = 1;
- c.gridy = 2; c.gridx = 2;
- c.weighty = 0; c.weightx = 1;
- c.fill = GridBagConstraints.NONE;
- c.anchor = GridBagConstraints.CENTER;
- c.insets = new Insets(8, 8, 8, 8);
- JLabel lab = new JLabel("");
- gridbag.setConstraints(lab,c); add(lab);
-
- c.gridheight = 1; c.gridwidth = 1;
- c.gridy = 2; c.gridx = 3;
- c.weighty = 0; c.weightx = 0;
- c.fill = GridBagConstraints.NONE;
- c.anchor = GridBagConstraints.EAST;
- c.insets = new Insets(8, 8, 8, 4);
- JButton prev = new JButton("Previous");
- gridbag.setConstraints(prev,c); add(prev);
-
- c.gridheight = 1; c.gridwidth = 1;
- c.gridy = 2; c.gridx = 4;
- c.weighty = 0; c.weightx = 0;
- c.fill = GridBagConstraints.NONE;
- c.anchor = GridBagConstraints.EAST;
- c.insets = new Insets(8, 4, 8, 8);
- JButton next = new JButton("Next");
- gridbag.setConstraints(next,c); add(next);
-
-
- // Ensure that all three buttons have the same size
- Dimension dim1 = canc.getPreferredSize();
- Dimension dim2 = prev.getPreferredSize();
- Dimension dim3 = next.getPreferredSize();
-
- int max = dim1.width;
- if (dim2.width > max) max = dim2.width;
- if (dim3.width > max) max = dim3.width;
-
- dim1.width = max;
- dim2.width = max;
- dim3.width = max;
-
- canc.setMinimumSize(dim1);
- prev.setMinimumSize(dim2);
- next.setMinimumSize(dim3);
-
- // Get this class to listen for events
- canc.addActionListener(this);
- prev.addActionListener(this);
- next.addActionListener(this);
-
- }
-
-
- private JTree createTree(){
-
- DefaultMutableTreeNode root, lev1, lev2;
-
- root = new DefaultMutableTreeNode("Wizard");
-
- lev1 = new DefaultMutableTreeNode("Contract");
- root.add(lev1);
- lev2 = new DefaultMutableTreeNode("Read File");
- lev1.add(lev2);
- lev2 = new DefaultMutableTreeNode("Edit");
- lev1.add(lev2);
-
- lev1 = new DefaultMutableTreeNode("Keys");
- root.add(lev1);
- lev2 = new DefaultMutableTreeNode("Toplevel");
- lev1.add(lev2);
- lev2 = new DefaultMutableTreeNode("Contract");
- lev1.add(lev2);
- lev2 = new DefaultMutableTreeNode("Server");
- lev1.add(lev2);
-
- lev1 = new DefaultMutableTreeNode("Finish");
- root.add(lev1);
- lev2 = new DefaultMutableTreeNode("Signature");
- lev1.add(lev2);
- lev2 = new DefaultMutableTreeNode("Info");
- lev1.add(lev2);
-
- JTree tree = new JTree(root);
-
- // Tweak the display to remove the root object
- tree.setRootVisible(false);
- tree.setShowsRootHandles(false);
-
- // Show lines from the parents to the children
- tree.putClientProperty("JTree.lineStyle", "Angled");
-
- // Expand all rows. Doing this backwards is much more easy.
- tree.expandRow(2);
- tree.expandRow(1);
- tree.expandRow(0);
-
- // Prevent expand/collapse of nodes
- tree.addTreeWillExpandListener(this);
-
- // Fiddle in our own renderer which can show disabled nodes
- tree.setCellRenderer(new MyRenderer());
-
- // New Selectionmodel that does not allow invalid nodes to be
- // selected
- tree.setSelectionModel(new MySelectionModel());
-
- // Initial selection
- tree.setSelectionRow(1);
-
- return tree;
-
- }
-
-
- public void actionPerformed(ActionEvent e) {
-
- if (e.getActionCommand().equals("Next")) {
-
- if (wizardActive < wizardPanels.length-1) {
- data.setCompleted(wizardActive, true);
- int tmp = wizardActive + 1;
- if (wizardPanels[tmp] == null) tmp++;
- usedNext = true;
- tree.setSelectionRow(tmp);
- }
-
-
- } else if (e.getActionCommand().equals("Previous")) {
-
- if (wizardActive > 1) {
- int tmp = wizardActive - 1;
- if (wizardPanels[tmp] == null) tmp--;
- tree.setSelectionRow(tmp);
- }
-
- }
-
- }
-
- public void treeWillExpand(TreeExpansionEvent e)
- throws ExpandVetoException {
- // No way dude, expanding/collapsing of nodes is disabled.
- throw new ExpandVetoException(e);
- }
-
- public void treeWillCollapse(TreeExpansionEvent e)
- throws ExpandVetoException {
- // No way dude, expanding/collapsing of nodes is disabled.
- throw new ExpandVetoException(e);
- }
-
- private class MyRenderer extends DefaultTreeCellRenderer {
-
-
- public Component getTreeCellRendererComponent(
- JTree tree,
- Object value,
- boolean sel,
- boolean expanded,
- boolean leaf,
- int row,
- boolean hasFocus) {
-
- super.getTreeCellRendererComponent(
- tree, value, sel,
- expanded, leaf, row,
- hasFocus);
-
- if (leaf) {
- if (data.getCompleted(row)) {
- setIcon(iconYes);
- } else {
- setIcon(iconNot);
- }
- if (data.getInvalid(row)) {
- this.setEnabled(false);
- setDisabledIcon(getIcon());
- }
- } else {
- }
-
- return this;
- }
-
- }
-
- private class MySelectionModel extends DefaultTreeSelectionModel {
-
-
- public MySelectionModel() {
-
- setSelectionMode(SINGLE_TREE_SELECTION);
-
- }
-
-
- public void setSelectionPaths(TreePath[] pPaths) {
-
- TreePath path = pPaths[0];
-
- if (((TreeNode)path.getLastPathComponent()).isLeaf()) {
-
- RowMapper mapper = getRowMapper();
- TreePath[] ps = {path};
- int[] rows = mapper.getRowsForPaths(ps);
-
- if (!data.getInvalid(rows[0])) {
- super.setSelectionPaths(ps);
- wizardPrevAct = wizardActive;
- wizardActive = rows[0];
- if (wizardPrevAct != -1) {
- wizardPanels[wizardPrevAct].setVisible(false);
- if (usedNext) {
- wizardPanels[wizardPrevAct].next();
- usedNext = false;
- } else {
- wizardPanels[wizardPrevAct].leave();
- }
- }
- wizardPanels[wizardActive].setVisible(true);
- wizardPanels[wizardActive].enter();
- }
-
- }
-
- }
-
-
- }
-
-
- public static void main(String[] arg) {
-
- JFrame frame = new JFrame();
- frame.getContentPane().add(new Wizard());
-
- frame.setSize(640,450);
- frame.show();
-
- }
-
-
-
-}
\ No newline at end of file
+/*
+ * $Id: Wizard.java,v 1.2 2000/08/14 21:59:02 iang Exp $
+ *
+ * Copyright (c) Systemics Inc 2000 on behalf of
+ * the WebFunds Development Team. All Rights Reserved.
+ */
+
+package webfunds.client.contracts.wizard;
+
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.border.*;
+import javax.swing.event.*;
+import javax.swing.tree.*;
+
+
+/**
+ * Main class for the wizard
+ *
+ * @author Edwin Woudt <edwin@webfunds.org>
+ * @version $Revision: 1.2 $
+ */
+
+public class Wizard extends JPanel
+ implements TreeWillExpandListener, ActionListener {
+
+
+ final WizardData data = new WizardData();
+
+ ImageIcon iconNot = new ImageIcon("iconnot.gif");
+ ImageIcon iconYes = new ImageIcon("iconyes.gif");
+
+ WizardPanel contractFile = new ContractFile(data);
+ WizardPanel contractEdit = new ContractEdit(data);
+ WizardPanel keyTop = new KeyTop(data);
+ WizardPanel keyContract = new KeyContract(data);
+ WizardPanel keyServer = new KeyServer(data);
+ WizardPanel finishSig = new FinishSig(data);
+ WizardPanel finishEnd = new FinishEnd(data);
+
+ WizardPanel[] wizardPanels = { null, contractFile, contractEdit,
+ null, keyTop, keyContract, keyServer,
+ null, finishSig, finishEnd };
+ int wizardActive = -1;
+ int wizardPrevAct = -1;
+
+ boolean usedNext = false;
+
+ JTree tree;
+
+
+ public Wizard() {
+
+ // GridBagLayout is the most flexible (also the most difficult
+ // to use) LayoutManager.
+ GridBagLayout gridbag = new GridBagLayout();
+ GridBagConstraints c = new GridBagConstraints();
+
+ setLayout(gridbag);
+
+ // The content pane that contains the panels from all the steps.
+ JPanel content = new JPanel();
+ OverlayLayout layout = new OverlayLayout(content);
+ content.setLayout(layout);
+
+ boolean first = true;
+ for (int i=0; i<wizardPanels.length; i++) {
+ if (wizardPanels[i] != null) {
+ if (first) {
+ wizardPanels[i].setVisible(true);
+ first = false;
+ } else {
+ wizardPanels[i].setVisible(false);
+ }
+ content.add(wizardPanels[i]);
+ }
+ }
+
+
+ // Ok, this is where the real dirty work starts. Do not attempt
+ // to change it, unless you understand the GridBagLayout and
+ // GridBagConstraints, because in case you don't the result
+ // will probably be a real f*ck up of the layout.
+
+ c.gridheight = 3; c.gridwidth = 1;
+ c.gridy = 0; c.gridx = 0;
+ c.weighty = 1; c.weightx = 1;
+ c.fill = GridBagConstraints.BOTH;
+ c.anchor = GridBagConstraints.CENTER;
+ c.insets = new Insets(8, 8, 8, 8);
+ tree = createTree();
+ tree.setBorder(BorderFactory.createEtchedBorder());
+ gridbag.setConstraints(tree,c); add(tree);
+
+ c.gridheight = 1; c.gridwidth = 4;
+ c.gridy = 0; c.gridx = 1;
+ c.weighty = 1; c.weightx = 1;
+ c.fill = GridBagConstraints.BOTH;
+ c.anchor = GridBagConstraints.CENTER;
+ c.insets = new Insets(8, 8, 8, 8);
+ gridbag.setConstraints(content,c); add(content);
+
+ c.gridheight = 1; c.gridwidth = 4;
+ c.gridy = 1; c.gridx = 1;
+ c.weighty = 0; c.weightx = 1;
+ c.fill = GridBagConstraints.BOTH;
+ c.anchor = GridBagConstraints.CENTER;
+ c.insets = new Insets(8, 8, 4, 8);
+ JPanel pane = new JPanel();
+ Color color = UIManager.getColor("Label.foreground");
+ Border border = BorderFactory.createMatteBorder(0,0,1,0,color);
+ pane.setBorder(border);
+ gridbag.setConstraints(pane,c); add(pane);
+
+ c.gridheight = 1; c.gridwidth = 1;
+ c.gridy = 2; c.gridx = 1;
+ c.weighty = 0; c.weightx = 0;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.WEST;
+ c.insets = new Insets(8, 8, 8, 8);
+ JButton canc = new JButton("Cancel");
+ gridbag.setConstraints(canc,c); add(canc);
+
+ // Filler
+ c.gridheight = 1; c.gridwidth = 1;
+ c.gridy = 2; c.gridx = 2;
+ c.weighty = 0; c.weightx = 1;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.CENTER;
+ c.insets = new Insets(8, 8, 8, 8);
+ JLabel lab = new JLabel("");
+ gridbag.setConstraints(lab,c); add(lab);
+
+ c.gridheight = 1; c.gridwidth = 1;
+ c.gridy = 2; c.gridx = 3;
+ c.weighty = 0; c.weightx = 0;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.EAST;
+ c.insets = new Insets(8, 8, 8, 4);
+ JButton prev = new JButton("Previous");
+ gridbag.setConstraints(prev,c); add(prev);
+
+ c.gridheight = 1; c.gridwidth = 1;
+ c.gridy = 2; c.gridx = 4;
+ c.weighty = 0; c.weightx = 0;
+ c.fill = GridBagConstraints.NONE;
+ c.anchor = GridBagConstraints.EAST;
+ c.insets = new Insets(8, 4, 8, 8);
+ JButton next = new JButton("Next");
+ gridbag.setConstraints(next,c); add(next);
+
+
+ // Ensure that all three buttons have the same size
+ Dimension dim1 = canc.getPreferredSize();
+ Dimension dim2 = prev.getPreferredSize();
+ Dimension dim3 = next.getPreferredSize();
+
+ int max = dim1.width;
+ if (dim2.width > max) max = dim2.width;
+ if (dim3.width > max) max = dim3.width;
+
+ dim1.width = max;
+ dim2.width = max;
+ dim3.width = max;
+
+ canc.setMinimumSize(dim1);
+ prev.setMinimumSize(dim2);
+ next.setMinimumSize(dim3);
+
+ // Get this class to listen for events
+ canc.addActionListener(this);
+ prev.addActionListener(this);
+ next.addActionListener(this);
+
+ }
+
+
+ private JTree createTree(){
+
+ DefaultMutableTreeNode root, lev1, lev2;
+
+ root = new DefaultMutableTreeNode("Wizard");
+
+ lev1 = new DefaultMutableTreeNode("Contract");
+ root.add(lev1);
+ lev2 = new DefaultMutableTreeNode("Read File");
+ lev1.add(lev2);
+ lev2 = new DefaultMutableTreeNode("Edit");
+ lev1.add(lev2);
+
+ lev1 = new DefaultMutableTreeNode("Keys");
+ root.add(lev1);
+ lev2 = new DefaultMutableTreeNode("Toplevel");
+ lev1.add(lev2);
+ lev2 = new DefaultMutableTreeNode("Contract");
+ lev1.add(lev2);
+ lev2 = new DefaultMutableTreeNode("Server");
+ lev1.add(lev2);
+
+ lev1 = new DefaultMutableTreeNode("Finish");
+ root.add(lev1);
+ lev2 = new DefaultMutableTreeNode("Signature");
+ lev1.add(lev2);
+ lev2 = new DefaultMutableTreeNode("Info");
+ lev1.add(lev2);
+
+ JTree tree = new JTree(root);
+
+ // Tweak the display to remove the root object
+ tree.setRootVisible(false);
+ tree.setShowsRootHandles(false);
+
+ // Show lines from the parents to the children
+ tree.putClientProperty("JTree.lineStyle", "Angled");
+
+ // Expand all rows. Doing this backwards is much more easy.
+ tree.expandRow(2);
+ tree.expandRow(1);
+ tree.expandRow(0);
+
+ // Prevent expand/collapse of nodes
+ tree.addTreeWillExpandListener(this);
+
+ // Fiddle in our own renderer which can show disabled nodes
+ tree.setCellRenderer(new MyRenderer());
+
+ // New Selectionmodel that does not allow invalid nodes to be
+ // selected
+ tree.setSelectionModel(new MySelectionModel());
+
+ // Initial selection
+ tree.setSelectionRow(1);
+
+ return tree;
+
+ }
+
+
+ public void actionPerformed(ActionEvent e) {
+
+ if (e.getActionCommand().equals("Next")) {
+
+ if (wizardActive < wizardPanels.length-1) {
+ data.setCompleted(wizardActive, true);
+ int tmp = wizardActive + 1;
+ if (wizardPanels[tmp] == null) tmp++;
+ usedNext = true;
+ tree.setSelectionRow(tmp);
+ }
+
+
+ } else if (e.getActionCommand().equals("Previous")) {
+
+ if (wizardActive > 1) {
+ int tmp = wizardActive - 1;
+ if (wizardPanels[tmp] == null) tmp--;
+ tree.setSelectionRow(tmp);
+ }
+
+ }
+
+ }
+
+ public void treeWillExpand(TreeExpansionEvent e)
+ throws ExpandVetoException {
+ // No way dude, expanding/collapsing of nodes is disabled.
+ throw new ExpandVetoException(e);
+ }
+
+ public void treeWillCollapse(TreeExpansionEvent e)
+ throws ExpandVetoException {
+ // No way dude, expanding/collapsing of nodes is disabled.
+ throw new ExpandVetoException(e);
+ }
+
+ private class MyRenderer extends DefaultTreeCellRenderer {
+
+
+ public Component getTreeCellRendererComponent(
+ JTree tree,
+ Object value,
+ boolean sel,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus) {
+
+ super.getTreeCellRendererComponent(
+ tree, value, sel,
+ expanded, leaf, row,
+ hasFocus);
+
+ if (leaf) {
+ if (data.getCompleted(row)) {
+ setIcon(iconYes);
+ } else {
+ setIcon(iconNot);
+ }
+ if (data.getInvalid(row)) {
+ this.setEnabled(false);
+ setDisabledIcon(getIcon());
+ }
+ } else {
+ }
+
+ return this;
+ }
+
+ }
+
+ private class MySelectionModel extends DefaultTreeSelectionModel {
+
+
+ public MySelectionModel() {
+
+ setSelectionMode(SINGLE_TREE_SELECTION);
+
+ }
+
+
+ public void setSelectionPaths(TreePath[] pPaths) {
+
+ TreePath path = pPaths[0];
+
+ if (((TreeNode)path.getLastPathComponent()).isLeaf()) {
+
+ RowMapper mapper = getRowMapper();
+ TreePath[] ps = {path};
+ int[] rows = mapper.getRowsForPaths(ps);
+
+ if (!data.getInvalid(rows[0])) {
+ super.setSelectionPaths(ps);
+ wizardPrevAct = wizardActive;
+ wizardActive = rows[0];
+ if (wizardPrevAct != -1) {
+ wizardPanels[wizardPrevAct].setVisible(false);
+ if (usedNext) {
+ wizardPanels[wizardPrevAct].next();
+ usedNext = false;
+ } else {
+ wizardPanels[wizardPrevAct].leave();
+ }
+ }
+ wizardPanels[wizardActive].setVisible(true);
+ wizardPanels[wizardActive].enter();
+ }
+
+ }
+
+ }
+
+
+ }
+
+
+ public static void main(String[] arg) {
+
+ JFrame frame = new JFrame();
+ frame.getContentPane().add(new Wizard());
+
+ frame.setSize(640,450);
+ frame.show();
+
+ }
+
+
+
+}