aboutsummaryrefslogtreecommitdiff
path: root/src/EquationDialog.java
blob: 76c7bd3e10c1add5e14847d30bea25e9813002e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*     */ import java.awt.Dimension;
/*     */ import java.awt.FlowLayout;
/*     */ import java.awt.Frame;
/*     */ import java.awt.GridBagLayout;
/*     */ import java.awt.GridLayout;
/*     */ import java.awt.event.ActionEvent;
/*     */ import java.awt.event.ActionListener;
/*     */ import java.util.ArrayList;
/*     */ import javax.swing.BoxLayout;
/*     */ import javax.swing.JButton;
/*     */ import javax.swing.JDialog;
/*     */ import javax.swing.JLabel;
/*     */ import javax.swing.JPanel;
/*     */ import javax.swing.JScrollPane;
/*     */ import javax.swing.JTextField;
/*     */ import javax.swing.JViewport;
/*     */ 
/*     */ public class EquationDialog extends JDialog
/*     */   implements GraphTypeStateChangedListener, ActionListener
/*     */ {
/*     */   private JScrollPane scroll;
/*     */   private JTextField[] equations;
/*     */   private JLabel[] equationNames;
/*     */   private JPanel[] packages;
/*     */   private JPanel holder;
/*     */   private JPanel fullPanel;
/*     */   private JButton ok;
/*     */   private JButton cancel;
/*     */   private JPanel okButtons;
/*     */   private Graph2D graph;
/*     */ 
/*     */   public EquationDialog(Frame parent, Graph2D graph)
/*     */   {
/*  25 */     super(parent, true);
/*  26 */     this.graph = graph;
/*  27 */     setLayout(new GridBagLayout());
/*  28 */     this.ok = new JButton("Apply");
/*  29 */     this.cancel = new JButton("Cancel");
/*  30 */     this.okButtons = new JPanel(new FlowLayout());
/*  31 */     this.okButtons.add(this.ok);
/*  32 */     this.okButtons.add(this.cancel);
/*  33 */     this.ok.addActionListener(this);
/*  34 */     this.cancel.addActionListener(this);
/*  35 */     this.holder = new JPanel();
/*     */ 
/*  37 */     this.equations = new JTextField[10];
/*  38 */     this.equationNames = new JLabel[10];
/*  39 */     this.scroll = new JScrollPane();
/*  40 */     this.holder.setLayout(new GridLayout(this.equations.length, 1));
/*  41 */     this.scroll.setPreferredSize(new Dimension(200, 200));
/*  42 */     this.packages = new JPanel[10];
/*  43 */     for (int i = 0; i < this.equations.length; i++) {
/*  44 */       this.equations[i] = new JTextField("", 10);
/*  45 */       this.equations[i].setFocusable(true);
/*  46 */       this.equationNames[i] = new JLabel("<html><a style='font-family:Times New Roman'>y<sub>" + i + "</sub>(x)</a>=<html>");
/*  47 */       this.packages[i] = new JPanel(new FlowLayout());
/*  48 */       this.packages[i].add(this.equationNames[i]);
/*  49 */       this.packages[i].add(this.equations[i]);
/*  50 */       this.packages[i].setPreferredSize(new Dimension(150, 65));
/*  51 */       this.holder.add(this.packages[i]);
/*     */     }
/*  53 */     this.scroll.getViewport().add(this.holder);
/*  54 */     this.fullPanel = new JPanel();
/*  55 */     this.fullPanel.setLayout(new BoxLayout(this.fullPanel, 1));
/*  56 */     this.fullPanel.add(this.scroll);
/*  57 */     this.fullPanel.add(this.okButtons);
/*  58 */     add(this.fullPanel);
/*     */ 
/*  60 */     pack();
/*     */   }
/*     */ 
/*     */   public void setEquations(String[] args) {
/*  64 */     for (int i = 0; (i < args.length) && (i < this.equations.length); i++)
/*  65 */       this.equations[i].setText(args[i].replaceAll("<ivar>", GraphTypeHolder.getInstance().getGraphPointMaker().getIndependentVariable()));
/*     */   }
/*     */ 
/*     */   public void setVisible(boolean visible) {
/*  69 */     if (visible) {
/*  70 */       setEquations(this.graph.getEquations());
/*     */     }
/*  72 */     super.setVisible(visible);
/*     */   }
/*     */   public void applyEquations() {
/*  75 */     this.graph.setEquations(getEquations());
/*  76 */     ModulusThreads.addThread("Remaking Points", this.graph.getThread());
/*     */   }
/*     */   public String[] getEquations() {
/*  79 */     ArrayList strs = new ArrayList();
/*  80 */     for (JTextField jtf : this.equations) {
/*  81 */       if (jtf.getText().length() != 0)
/*  82 */         strs.add(parseEquation(jtf.getText()));
/*     */     }
/*  84 */     String[] ret = new String[strs.size()];
/*  85 */     for (int i = 0; i < strs.size(); i++) ret[i] = ((String)strs.get(i));
/*  86 */     return ret;
/*     */   }
/*     */   public static String parseEquation(String equation) {
/*  89 */     if (equation.equals("")) return "";
/*  90 */     if (equation.length() == 1) return equation.charAt(0) == GraphTypeHolder.getInstance().getGraphPointMaker().getIndependentVariable() ? "<ivar>" : equation;
/*  91 */     Point2DMaker maker = GraphTypeHolder.getInstance().getGraphPointMaker();
/*  92 */     String ret = "";
/*  93 */     for (int i = 0; i < equation.length(); i++) {
/*  94 */       char next = equation.charAt(i);
/*  95 */       if (next == maker.getIndependentVariable()) {
/*  96 */         if (i == 0) {
/*  97 */           if (!Character.isLowerCase(equation.charAt(i + 1))) {
/*  98 */             ret = ret + "<ivar>";
/*  99 */             continue;
/*     */           }
/*     */         }
/* 102 */         else if (i == equation.length() - 1) {
/* 103 */           if (!Character.isLowerCase(equation.charAt(i - 1))) {
/* 104 */             ret = ret + "<ivar>";
/* 105 */             continue;
/*     */           }
/*     */         }
/* 108 */         else if ((!Character.isLowerCase(equation.charAt(i - 1))) && (!Character.isLowerCase(equation.charAt(i + 1)))) {
/* 109 */           ret = ret + "<ivar>";
/* 110 */           continue;
/*     */         }
/*     */       }
/* 113 */       ret = ret + equation.charAt(i);
/*     */     }
/* 115 */     return ret;
/*     */   }
/*     */   public void graphTypeChanged(Point2DMaker maker) {
/* 118 */     for (int i = 0; i < this.equationNames.length; i++)
/* 119 */       this.equationNames[i].setText("<html><a style='font-family:Times New Roman'>" + maker.getDependentVariable() + "<sub>" + i + "</sub>(" + GraphTypeHolder.getInstance().getGraphPointMaker().getIndependentVariable() + ")</a> =<html>");
/*     */   }
/*     */ 
/*     */   public void actionPerformed(ActionEvent e)
/*     */   {
/* 124 */     setVisible(false);
/* 125 */     if (e.getSource() == this.ok)
/* 126 */       applyEquations();
/*     */   }
/*     */ }

/* Location:           Modulus.jar
 * Qualified Name:     EquationDialog
 * JD-Core Version:    0.6.2
 */