2
GeoGebra - Dynamic Mathematics for Everyone
3
http://www.geogebra.org
5
This file is part of GeoGebra.
7
This program is free software; you can redistribute it and/or modify it
8
under the terms of the GNU General Public License as published by
9
the Free Software Foundation.
13
package geogebra.gui.view.spreadsheet;
15
import geogebra.gui.InputDialog;
16
import geogebra.gui.inputfield.MyTextField;
17
import geogebra.gui.util.GeoGebraIcon;
18
import geogebra.gui.util.PopupMenuButton;
19
import geogebra.gui.util.SelectionTable;
20
import geogebra.kernel.Construction;
21
import geogebra.kernel.GeoElement;
22
import geogebra.kernel.GeoList;
23
import geogebra.kernel.GeoPoint;
24
import geogebra.kernel.GeoPolygon;
25
import geogebra.kernel.GeoText;
26
import geogebra.kernel.Kernel;
27
import geogebra.kernel.View;
28
import geogebra.kernel.arithmetic.NumberValue;
29
import geogebra.kernel.kernelND.GeoPointND;
30
import geogebra.main.Application;
32
import java.awt.BorderLayout;
33
import java.awt.Color;
34
import java.awt.Component;
35
import java.awt.Container;
36
import java.awt.Dimension;
37
import java.awt.FlowLayout;
38
import java.awt.event.ActionEvent;
39
import java.awt.event.ActionListener;
40
import java.awt.event.KeyEvent;
41
import java.awt.event.KeyListener;
42
import java.awt.event.MouseEvent;
43
import java.awt.event.MouseListener;
44
import java.util.ArrayList;
46
import javax.swing.BorderFactory;
47
import javax.swing.BoxLayout;
48
import javax.swing.JButton;
49
import javax.swing.JCheckBox;
50
import javax.swing.JCheckBoxMenuItem;
51
import javax.swing.JComboBox;
52
import javax.swing.JLabel;
53
import javax.swing.JPanel;
54
import javax.swing.JScrollPane;
55
import javax.swing.JTable;
56
import javax.swing.JTextField;
57
import javax.swing.JViewport;
58
import javax.swing.event.ListSelectionEvent;
59
import javax.swing.event.ListSelectionListener;
60
import javax.swing.table.DefaultTableCellRenderer;
61
import javax.swing.table.DefaultTableModel;
62
import javax.swing.table.TableCellRenderer;
63
import javax.swing.table.TableColumn;
67
* View for inspecting selected GeoElements
69
* @author G. Sturr, 2011-2-12
73
public class InspectorView extends InputDialog implements View, MouseListener, ListSelectionListener, KeyListener, ActionListener{
75
private static final Color EVEN_ROW_COLOR = new Color(241, 245, 250);
76
private static final Color TABLE_GRID_COLOR = new Color(0xd9d9d9);
77
private static final int minRows = 10;
80
private static final int COL_DERIVATIVE = 0;
81
private static final int COL_DERIVATIVE2 = 1;
82
private static final int COL_DIFFERENCE = 2;
83
private static final int COL_CURVATURE = 3;
87
private Kernel kernel;
88
private Construction cons;
92
private DefaultTableModel model;
93
private ArrayList<Integer> extraColumnList;
96
private JLabel lblGeoName, lblStart, lblStep;
97
private MyTextField fldStart, fldStep;
98
private JPanel controlPanel;
99
private JCheckBox ckShowTangent, ckShowOscCircle, ckShowX, ckShowY, ckShowAutoTable;
100
private JComboBox cbShow, cbAdd;
101
private JButton btnAdd, btnRemove;
102
private String[] columnNames;
106
private GeoElement selectedGeo, tangentLine, oscCircle, xSegment, ySegment;
107
private GeoElement derivative, derivative2;
108
private GeoPoint testPoint;
110
private double start =-1;
111
private double step = 0.1;
112
private JLabel lblShow;
113
private ArrayList<GeoElement> geoList;
114
private PopupMenuButton btnAddColumn;
115
private ArrayList<GeoElement> showGeo;
116
private ArrayList<String> showName;
117
private PopupMenuButton btnShow;
122
public InspectorView(Application app) {
124
super(app.getFrame(), false);
126
kernel = app.getKernel();
127
cons = kernel.getConstruction();
128
boolean showApply = false;
130
// setup InputDialog GUI
131
String title = app.getMenu("FunctionInspector");
132
createGUI(title, "", false, 16, 1, false, false, false, false, false, showApply, false);
133
this.btOK.setVisible(false);
134
this.btCancel.setVisible(false);
137
// create Table and additional GUI elements
138
geoList = new ArrayList<GeoElement>();
143
// put additional GUI together
144
JPanel cp1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
149
cp1.add(btnAddColumn);
152
JPanel cp2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
154
cp2.add(ckShowTangent);
157
cp2.add(ckShowOscCircle);
163
controlPanel = new JPanel();
164
controlPanel.setLayout(new BoxLayout(controlPanel,BoxLayout.Y_AXIS));
165
controlPanel.add(cp1);
166
controlPanel.add(cp2);
167
//controlPanel.add(cp3);
168
controlPanel.setVisible(false);
170
JPanel southPanel = new JPanel(new BorderLayout());
171
southPanel.add(controlPanel,BorderLayout.SOUTH);
172
southPanel.setMinimumSize(controlPanel.getPreferredSize());
174
//System.out.println();
176
JScrollPane scroller = new JScrollPane(table);
177
scroller.setPreferredSize(table.getPreferredSize());
179
JPanel headerPanel = new JPanel(new BorderLayout());
180
headerPanel.add(lblGeoName, BorderLayout.CENTER);
181
headerPanel.setBorder(BorderFactory.createEmptyBorder(2,5,2,2));
183
JPanel centerPanel = new JPanel(new BorderLayout(5,5));
184
centerPanel.add(headerPanel,BorderLayout.NORTH);
185
centerPanel.add(scroller,BorderLayout.CENTER);
186
centerPanel.add(southPanel,BorderLayout.SOUTH);
188
getContentPane().add(centerPanel,BorderLayout.CENTER);
194
app.getKernel().attach(this);
199
// Create GUI elements
200
// =====================================
202
private void createGUIElements(){
204
columnNames = new String[4];
205
columnNames[COL_DERIVATIVE] = app.getPlain("fncInspector.Derivative");
206
columnNames[COL_DERIVATIVE2] = app.getPlain("fncInspector.Derivative2");
207
columnNames[COL_CURVATURE] = app.getPlain("fncInspector.Curvature");
208
columnNames[COL_DIFFERENCE] = app.getPlain("fncInspector.Difference");
210
lblGeoName = new JLabel(getTitleString());
211
lblGeoName.setFont(app.getBoldFont());
213
lblStep = new JLabel(app.getMenu("Step") + ":");
214
lblStart = new JLabel(app.getMenu("Start") + ":");
215
lblShow = new JLabel(app.getMenu("Show") + ":");
216
fldStep = new MyTextField(app);
217
fldStep.addActionListener(this);
218
fldStep.setColumns(6);
220
fldStart = new MyTextField(app);
221
fldStart.addActionListener(this);
222
fldStart.setColumns(6);
224
ckShowTangent = new JCheckBox(app.getMenu("Tangent"));
225
ckShowOscCircle = new JCheckBox(app.getMenu("OsculatingCircle"));
226
ckShowX = new JCheckBox(app.getMenu("Xseg"));
227
ckShowY = new JCheckBox(app.getMenu("Yseg"));
228
ckShowX.setSelected(true);
229
ckShowY.setSelected(true);
232
ckShowTangent.addActionListener(this);
233
ckShowOscCircle.addActionListener(this);
234
ckShowX.addActionListener(this);
235
ckShowY.addActionListener(this);
238
btnAdd = new JButton("\u271A");
239
btnAdd.addActionListener(this);
241
btnRemove = new JButton("\u2718");
242
btnRemove.addActionListener(this);
246
btnAddColumn = new PopupMenuButton(app, columnNames, -1, 1,
247
new Dimension(0, 12), SelectionTable.MODE_TEXT);
249
btnAddColumn.setKeepVisible(false);
250
btnAddColumn.setStandardButton(true);
251
btnAddColumn.setFixedIcon(GeoGebraIcon.createDownTriangleIcon(10));
252
btnAddColumn.setText("Add Column");
253
btnAddColumn.addActionListener(this);
261
* Builds popup button with checkbox menu items to hide/show display geos
263
private void buildShowButton(){
265
btnShow = new PopupMenuButton(app);
266
btnShow.setKeepVisible(true);
267
btnShow.setStandardButton(true);
268
btnShow.setFixedIcon(GeoGebraIcon.createDownTriangleIcon(10));
269
btnShow.setText("Show" + "...");
271
JCheckBoxMenuItem menuItem;
272
menuItem = new JCheckBoxMenuItem(app.getMenu("XLine"));
273
menuItem.addActionListener(new ActionListener(){
274
public void actionPerformed(ActionEvent e) {
275
xSegment.setEuclidianVisible(!xSegment.isEuclidianVisible());
278
btnShow.addPopupMenuItem(menuItem);
280
menuItem = new JCheckBoxMenuItem(app.getMenu("YLine"));
281
menuItem.addActionListener(new ActionListener(){
282
public void actionPerformed(ActionEvent e) {
283
ySegment.setEuclidianVisible(!ySegment.isEuclidianVisible());
286
btnShow.addPopupMenuItem(menuItem);
288
menuItem = new JCheckBoxMenuItem(app.getMenu("Tangent"));
289
menuItem.addActionListener(new ActionListener(){
290
public void actionPerformed(ActionEvent e) {
291
tangentLine.setEuclidianVisible(!tangentLine.isEuclidianVisible());
294
btnShow.addPopupMenuItem(menuItem);
296
menuItem = new JCheckBoxMenuItem(app.getMenu("OsculatingCircle"));
297
menuItem.addActionListener(new ActionListener(){
298
public void actionPerformed(ActionEvent e) {
299
tangentLine.setEuclidianVisible(!tangentLine.isEuclidianVisible());
302
btnShow.addPopupMenuItem(menuItem);
309
// Create/Setup Table
310
// =====================================
312
private void createTable(){
314
table = new JTable(minRows,2){
316
// disable cell editing
318
public boolean isCellEditable(int rowIndex, int colIndex) {
322
// fill empty scroll pane space with table background color
324
protected void configureEnclosingScrollPane() {
325
super.configureEnclosingScrollPane();
326
Container p = getParent();
327
if (p instanceof JViewport) {
328
((JViewport) p).setBackground(getBackground());
332
// shade alternate rows
333
private Color rowColor(int row){
338
c = this.getBackground();
343
public Component prepareRenderer(TableCellRenderer renderer,int row, int column) {
344
Component c = super.prepareRenderer(renderer, row, column);
346
if (isCellSelected(row, column)) {
347
c.setBackground(getSelectionBackground());
348
c.setForeground(getSelectionForeground());
350
c.setBackground(rowColor(row));
351
c.setForeground(getForeground());
353
setFont(app.getPlainFont());
359
TableColumn col = table.getColumnModel().getColumn(vColIndex);
360
col.setCellRenderer(new MyCellRenderer());
362
table.setShowGrid(true);
363
table.setGridColor(TABLE_GRID_COLOR);
364
//table.setAutoCreateColumnsFromModel(false);
365
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
366
//table.setPreferredScrollableViewportSize(table.getPreferredSize());
367
table.setBorder(null);
368
table.getSelectionModel().addListSelectionListener(this);
369
table.addKeyListener(this);
371
// create list to store column types of dynamically appended columns
372
extraColumnList = new ArrayList<Integer>();
376
public class MyCellRenderer extends DefaultTableCellRenderer {
378
public Component getTableCellRendererComponent(JTable table, Object value,
379
boolean isSelected, boolean hasFocus, final int row, int column) {
381
setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
382
setText((String) value);
392
// =====================================
394
private void populateTableModel(){
396
String lbl = selectedGeo.getLabel();
397
ArrayList<String> property = new ArrayList<String>();
398
ArrayList<String> value = new ArrayList<String>();
401
switch (selectedGeo.getGeoClassType()){
403
case GeoElement.GEO_CLASS_POINT:
405
property.add(app.getCommand("Angle"));
406
value.add("Angle[" + lbl + "]");
409
case GeoElement.GEO_CLASS_POLYGON:
411
GeoPointND[] pts = ((GeoPolygon)selectedGeo).getPoints();
412
for(int i=0; i<pts.length; i++){
413
property.add(pts[i].getLabel());
414
value.add(((GeoElement) pts[i]).toDefinedValueString());
417
property.add(app.getCommand("Area"));
418
value.add("Area[" + lbl + "]");
420
property.add(app.getCommand("Perimeter"));
421
value.add("Perimeter[" + lbl + "]");
425
case GeoElement.GEO_CLASS_LIST:
427
GeoList g = (GeoList) selectedGeo;
428
if(((GeoElement)g).getGeoElementForPropertiesDialog().isNumberValue()){
430
property.add(app.getCommand("Mean"));
431
value.add("Mean[" + lbl + "]");
433
property.add(app.getCommand("SD"));
434
value.add("SD[" + lbl + "]");
436
property.add(app.getCommand("Min"));
437
value.add("Min[" + lbl + "]");
439
property.add(app.getCommand("Q1"));
440
value.add("Q1[" + lbl + "]");
442
property.add(app.getCommand("Median"));
443
value.add("Median[" + lbl + "]");
445
property.add(app.getCommand("Q3"));
446
value.add("Q3[" + lbl + "]");
448
property.add(app.getCommand("Max"));
449
value.add("Max[" + lbl + "]");
455
case GeoElement.GEO_CLASS_CONIC:
457
property.add(app.getCommand("Center"));
458
value.add("Center[" + lbl + "]");
460
property.add(app.getCommand("Radius"));
461
value.add("Radius[" + lbl + "]");
463
property.add(app.getCommand("Area"));
464
value.add("Area[" + lbl + "]");
466
property.add(app.getCommand("Circumference"));
467
value.add("Circumference[" + lbl + "]");
469
property.add(app.getCommand("Eccentricity"));
470
value.add("Eccentricity[" + lbl + "]");
474
case GeoElement.GEO_CLASS_FUNCTION:
477
for(int i = 0; i < 10; i++){
478
property.add("" + x);
479
value.add( lbl + "(" + x + ")");
487
boolean isFunction = selectedGeo.getGeoClassType() == GeoElement.GEO_CLASS_FUNCTION;
489
int rowCount = Math.max(minRows, property.size());
490
int columnCount = isFunction ? 2 + extraColumnList.size() : 2;
492
model = new DefaultTableModel(rowCount, columnCount);
494
for(int i=0; i < property.size(); i++){
495
model.setValueAt(property.get(i),i,0);
496
model.setValueAt(evaluateToText("\"\"" + value.get(i)),i,1);
500
updateExtraColumns();
503
table.setModel(model);
508
table.getColumnModel().getColumn(0).setHeaderValue("x");
509
table.getColumnModel().getColumn(1).setHeaderValue("y");
510
for(int i = 0; i < extraColumnList.size() ; i++){
511
table.getColumnModel().getColumn(i+2).setHeaderValue(columnNames[extraColumnList.get(i)]);
514
controlPanel.setVisible(true);
517
table.getColumnModel().getColumn(0).setHeaderValue(app.getPlain("Property"));
518
table.getColumnModel().getColumn(1).setHeaderValue(app.getPlain("Value"));
520
controlPanel.setVisible(false);
529
private void addColumn(int columnType){
530
extraColumnList.add(columnType);
531
populateTableModel();
534
private void removeColumn(){
535
int count = table.getColumnCount();
536
if(count <= 2) return;
537
extraColumnList.remove(extraColumnList.size()-1);
538
populateTableModel();
543
private void updateExtraColumns(){
545
if(extraColumnList.size()==0) return;
549
for(int column = 2; column < extraColumnList.size() + 2; column ++ ){
551
int columnType = extraColumnList.get(column-2);
556
for(int row=0; row < table.getRowCount(); row++){
557
double x = Double.parseDouble((String) model.getValueAt(row, 0));
558
expr = derivative.getLabel() + "(" + x + ")";
559
model.setValueAt(evaluateToText("\"\"" + expr),row,column);
563
case COL_DERIVATIVE2:
565
for(int row=0; row < table.getRowCount(); row++){
566
double x = Double.parseDouble((String) model.getValueAt(row, 0));
567
expr = derivative2.getLabel() + "(" + x + ")";
568
model.setValueAt(evaluateToText("\"\"" + expr),row,column);
574
for(int row=0; row < table.getRowCount(); row++){
575
double x = Double.parseDouble((String) model.getValueAt(row, 0));
576
double y = Double.parseDouble((String) model.getValueAt(row, 1));
577
double c = this.evaluateExpression(
578
"Curvature[ (" + x + "," + y + ")," + selectedGeo.getLabel() + "]");
579
model.setValueAt("" + c,row,column);
585
for(int row=1; row < table.getRowCount(); row++){
586
if(model.getValueAt(row-1, column -1) != null){
587
double prev = Double.parseDouble((String) model.getValueAt(row-1, column -1));
588
double x = Double.parseDouble((String) model.getValueAt(row, column-1));
589
model.setValueAt("" + (x - prev),row,column);
591
model.setValueAt(null,row,column);
604
private String getTitleString(){
608
if(selectedGeo == null){
609
title = app.getMenu("SelectObject");
612
// title = selectedGeo.getLongDescriptionHTML(false, true);
613
// if (title.length() > 80)
614
title = selectedGeo.getNameDescriptionHTML(false, true);
621
private void setColumnWidths(){
624
for (int i = 0; i < table.getColumnCount(); ++ i) {
625
w = getMaxColumnWidth(table,i) + 5;
626
table.getColumnModel().getColumn(i).setPreferredWidth(w);
629
int gap = table.getParent().getPreferredSize().width - table.getPreferredSize().width;
630
//System.out.println(table.getParent().getPreferredSize().width);
632
w = table.getColumnCount() - 1;
633
int newWidth = gap + table.getColumnModel().getColumn(table.getColumnCount() - 1).getWidth() ;
634
table.getColumnModel().getColumn(w).setPreferredWidth(newWidth);
640
* Finds the maximum preferred width of a column.
642
public int getMaxColumnWidth(JTable table, int column){
644
TableColumn tableColumn = table.getColumnModel().getColumn(column);
646
// iterate through the rows and find the preferred width
647
int maxPrefWidth = tableColumn.getPreferredWidth();
648
int colPrefWidth = 0;
649
for (int row = 0; row < table.getRowCount(); row++) {
650
if(table.getValueAt(row, column)!=null){
651
colPrefWidth = (int) table.getCellRenderer(row, column)
652
.getTableCellRendererComponent(table,
653
table.getValueAt(row, column), false, false,
654
row, column).getPreferredSize().getWidth();
655
maxPrefWidth = Math.max(maxPrefWidth, colPrefWidth);
659
return maxPrefWidth + table.getIntercellSpacing().width;
666
// Action and Other Event Handlers
667
// =====================================
669
public void actionPerformed(ActionEvent e) {
670
Object source = e.getSource();
672
if (source instanceof JTextField) {
673
doTextFieldActionPerformed((JTextField)source);
677
else if (source == btnAddColumn) {
678
//System.out.println(btnAddColumn.getSelectedIndex() + "=============");
679
addColumn(btnAddColumn.getSelectedIndex());
683
else if (source == btnAdd) {
684
addColumn(cbAdd.getSelectedIndex());
687
else if (source == btnRemove) {
691
else if (source == ckShowTangent) {
692
tangentLine.setEuclidianVisible(ckShowTangent.isSelected());
693
tangentLine.updateRepaint();
696
else if (source == ckShowOscCircle) {
697
oscCircle.setEuclidianVisible(ckShowOscCircle.isSelected());
698
oscCircle.updateRepaint();
701
else if (source == ckShowX) {
702
xSegment.setEuclidianVisible(ckShowX.isSelected());
703
xSegment.updateRepaint();
706
else if (source == ckShowY) {
707
ySegment.setEuclidianVisible(ckShowY.isSelected());
708
ySegment.updateRepaint();
717
private void doTextFieldActionPerformed(JTextField source) {
719
String inputText = source.getText().trim();
720
Double value = Double.parseDouble(source.getText());
723
if (source == fldStep)
725
if (source == fldStart)
727
this.populateTableModel();
729
} catch (NumberFormatException e) {
737
public void setVisible(boolean isVisible) {
738
super.setVisible(isVisible);
741
app.getKernel().attach(this);
743
app.getKernel().detach(this);
750
// View Implementation
751
// =====================================
753
public void update(GeoElement geo) {
754
if(selectedGeo == null) return;
755
if(selectedGeo.equals(geo)){
756
lblGeoName.setText(selectedGeo.toString());
757
populateTableModel();
762
public void add(GeoElement geo) {}
763
public void remove(GeoElement geo) {}
764
public void rename(GeoElement geo) {}
765
public void updateAuxiliaryObject(GeoElement geo) {}
766
public void repaintView() {}
767
public void reset() {}
768
public void clearView() {}
769
public void setMode(int mode) {}
773
// Table Selection Listener
774
// =====================================
776
public void valueChanged(ListSelectionEvent e) {
778
if (e.getValueIsAdjusting()) return;
780
table.getSelectionModel().removeListSelectionListener(this);
781
if (e.getSource() == table.getSelectionModel() && table.getRowSelectionAllowed()) {
782
// row selection changed
785
table.getSelectionModel().addListSelectionListener(this);
790
// Geo Selection Listener
791
// =====================================
793
public void geoElementSelected(GeoElement geo, boolean addToSelection) {
794
// TODO: not working directly yet, currently the listener
795
// is in InputDialog, so an overridden insertGeoElement() is used instead
797
public void insertGeoElement(GeoElement geo) {
799
lblGeoName.setText(getTitleString());
801
if(selectedGeo.getGeoClassType() == GeoElement.GEO_CLASS_FUNCTION){
803
start = 0.5* (kernel.getApplication().getEuclidianView().getXmin()-
804
kernel.getApplication().getEuclidianView().getXmin());
805
step = 0.25 * kernel.getApplication().getEuclidianView().getGridDistances()[0];
806
fldStart.removeActionListener(this);
807
fldStep.removeActionListener(this);
808
fldStart.setText("" + start);
809
fldStep.setText("" + step);
810
fldStart.addActionListener(this);
811
fldStep.addActionListener(this);
816
populateTableModel();
818
//table.changeSelection(0,0, false, false);
827
//=========================================
829
public void keyPressed(KeyEvent e) {
831
int key = e.getKeyCode();
833
table.getSelectionModel().removeListSelectionListener(this);
836
if(table.getSelectedRow()==0){
838
populateTableModel();
843
case KeyEvent.VK_DOWN:
844
if(table.getSelectedRow()==table.getRowCount()-1){
846
populateTableModel();
847
table.changeSelection(table.getRowCount()-1, 0, false, false);
853
table.getSelectionModel().addListSelectionListener(this);
857
public void keyReleased(KeyEvent arg0) {}
858
public void keyTyped(KeyEvent arg0) {}
864
//=========================================
866
public void mouseClicked(MouseEvent arg0) { }
867
public void mouseEntered(MouseEvent arg0) { }
868
public void mouseExited(MouseEvent arg0) { }
869
public void mousePressed(MouseEvent arg0) { }
870
public void mouseReleased(MouseEvent arg0) { }
876
// Update/Create Display Geos
877
//=========================================
879
private void defineDisplayGeos(){
882
if(testPoint != null)
884
String expr = "Point[" + selectedGeo.getLabel() + "]";
885
testPoint = (GeoPoint) createGeoFromString(expr, null, true);
886
testPoint.setObjColor(Color.red);
887
testPoint.setPointSize(4);
888
testPoint.setLabel("testPoint");
894
expr = "Segment[" + testPoint.getLabel() + ", (x(" + testPoint.getLabel() + "),0) ]";
895
//Application.debug(expr);
896
xSegment = createGeoFromString(expr, null, true);
897
xSegment.setEuclidianVisible(true);
898
xSegment.setObjColor(Color.red);
899
xSegment.setLabel("xSegment");
905
expr = "Segment[" + testPoint.getLabel() + ", (0, y(" + testPoint.getLabel() + ")) ]";
906
//Application.debug(expr);
907
ySegment = createGeoFromString(expr, null, true);
908
ySegment.setObjColor(Color.red);
909
ySegment.setEuclidianVisible(true);
910
ySegment.setLabel("ySegment");
914
if(tangentLine != null)
915
tangentLine.remove();
917
expr = "Tangent[" + selectedGeo.getLabel() + "," + testPoint.getLabel() + "]";
918
//Application.debug(expr);
919
tangentLine = createGeoFromString(expr, null, true);
920
tangentLine.setObjColor(Color.red);
921
tangentLine.setEuclidianVisible(false);
922
tangentLine.setLabel("tangentLine");
926
if( oscCircle != null)
929
expr = "OsculatingCircle[" + testPoint.getLabel() + "," + selectedGeo.getLabel() + "]";
930
//Application.debug(expr);
931
oscCircle = createGeoFromString(expr, null, true);
932
oscCircle.setObjColor(Color.red);
933
oscCircle.setEuclidianVisible(false);
934
oscCircle.setLabel("oscCircle");
938
if( derivative != null)
941
expr = "Derivative[" + selectedGeo.getLabel() + "]";
942
//Application.debug(expr);
943
derivative = createGeoFromString(expr, null, true);
944
derivative.setEuclidianVisible(false);
945
derivative.setLabel("derivative");
948
if( derivative2 != null)
949
derivative2.remove();
951
expr = "Derivative[" + selectedGeo.getLabel() + " , 2 ]";
952
//Application.debug(expr);
953
derivative2 = createGeoFromString(expr, null, true);
954
derivative2.setEuclidianVisible(false);
955
derivative2.setLabel("derivative2");
963
private void updateTestPoint(){
965
if(testPoint != null){
966
int row = table.getSelectedRow();
968
double x = Double.parseDouble((String) model.getValueAt(row, 0));
969
double y = Double.parseDouble((String) model.getValueAt(row, 1));
970
testPoint.setCoords(x, y, 1);
971
testPoint.updateRepaint();
980
// Geo Creation and Evaluation Methods
981
//=========================================
983
private double evaluateExpression(String expr){
985
nv = kernel.getAlgebraProcessor().evaluateToNumeric(expr, false);
986
return nv.getDouble();
990
private String evaluateToText(String expr){
991
GeoText text = kernel.getAlgebraProcessor().evaluateToText(expr, false);
992
return text.getTextString();
996
public GeoElement createGeoFromString(String text, String label, boolean suppressLabelCreation ){
1000
boolean oldSuppressLabelMode = cons.isSuppressLabelsActive();
1002
if(suppressLabelCreation)
1003
cons.setSuppressLabelCreation(true);
1004
//Application.debug(text);
1005
GeoElement[] geos = kernel.getAlgebraProcessor()
1006
.processAlgebraCommandNoExceptions(text, false);
1009
geos[0].setLabel(label);
1012
geos[0].setEuclidianVisible(true);
1013
geos[0].setAuxiliaryObject(true);
1014
geos[0].setLabelVisible(false);
1016
if(suppressLabelCreation)
1017
cons.setSuppressLabelCreation(oldSuppressLabelMode);
1019
geoList.add(geos[0]);
1022
} catch (Exception e) {
1023
e.printStackTrace();
1030
private void clearGeoList(){
1031
for(GeoElement geo : geoList){
1038
public void updateFont(){
1039
this.setFont(app.getPlainFont());
1044
public int getViewID() {
1045
return Application.VIEW_INSPECTOR;