forked from geogebra/geogebra
/
Application.java
4831 lines (3911 loc) · 120 KB
/
Application.java
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
GeoGebra - Dynamic Mathematics for Everyone
http://www.geogebra.org
This file is part of GeoGebra.
This program is 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.
*/
/**
* GeoGebra Application
*
* @author Markus Hohenwarter
*/
package geogebra.main;
import geogebra.CommandLineArguments;
import geogebra.GeoGebra;
import geogebra.common.GeoGebraConstants;
import geogebra.common.euclidian.AbstractEuclidianView;
import geogebra.common.euclidian.EuclidianConstants;
import geogebra.common.euclidian.event.AbstractEvent;
import geogebra.common.gui.view.spreadsheet.AbstractSpreadsheetTableModel;
import geogebra.common.io.MyXMLHandler;
import geogebra.common.io.layout.DockPanelData;
import geogebra.common.io.layout.Perspective;
import geogebra.common.kernel.AbstractAnimationManager;
import geogebra.common.kernel.Construction;
import geogebra.common.kernel.ConstructionDefaults;
import geogebra.common.kernel.Kernel;
import geogebra.common.kernel.Macro;
import geogebra.common.kernel.MacroInterface;
import geogebra.common.kernel.Relation;
import geogebra.common.kernel.View;
import geogebra.common.kernel.algos.AlgoElement;
import geogebra.common.kernel.cas.GeoGebraCasInterface;
import geogebra.common.kernel.commands.CommandProcessor;
import geogebra.common.kernel.geos.GeoAngle;
import geogebra.common.kernel.geos.GeoBoolean;
import geogebra.common.kernel.geos.GeoElement;
import geogebra.common.kernel.geos.GeoElementGraphicsAdapter;
import geogebra.common.kernel.geos.GeoList;
import geogebra.common.kernel.kernelND.GeoPointND;
import geogebra.common.main.AbstractApplication;
import geogebra.common.main.GeoElementSelectionListener;
import geogebra.common.main.MyError;
import geogebra.common.main.settings.ConstructionProtocolSettings;
import geogebra.common.main.settings.Settings;
import geogebra.common.plugin.EuclidianStyleConstants;
import geogebra.common.util.StringUtil;
import geogebra.common.util.Unicode;
import geogebra.euclidian.DrawEquation;
import geogebra.euclidian.EuclidianController;
import geogebra.euclidian.EuclidianStatic;
import geogebra.euclidian.EuclidianView;
import geogebra.euclidian.EuclidianViewInterface;
import geogebra.export.GraphicExportDialog;
import geogebra.export.WorksheetExportDialog;
import geogebra.gui.GuiManager;
import geogebra.gui.app.GeoGebraFrame;
import geogebra.gui.inputbar.AlgebraInput;
import geogebra.gui.layout.DockBar;
import geogebra.gui.util.ImageSelection;
import geogebra.gui.view.algebra.AlgebraView;
import geogebra.gui.view.spreadsheet.SpreadsheetTableModel;
import geogebra.gui.view.spreadsheet.SpreadsheetTraceManager;
import geogebra.io.MyXMLio;
import geogebra.kernel.AnimationManager;
import geogebra.kernel.UndoManager;
import geogebra.kernel.commands.CmdBarCode;
import geogebra.kernel.geos.GeoElementGraphicsAdapterDesktop;
import geogebra.plugin.CallJavaScript;
import geogebra.plugin.GgbAPI;
import geogebra.plugin.PluginManager;
import geogebra.plugin.ScriptManager;
import geogebra.plugin.jython.PythonBridge;
import geogebra.sound.SoundManager;
import geogebra.util.DebugPrinterDesktop;
import geogebra.util.DownloadManager;
import geogebra.util.ImageManager;
import geogebra.util.Util;
import java.awt.AWTKeyStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.KeyEventDispatcher;
import java.awt.KeyboardFocusManager;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.SystemColor;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.image.BufferedImage;
import java.awt.image.MemoryImageSource;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.URL;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.TreeSet;
import java.util.UUID;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import javax.imageio.ImageIO;
import javax.naming.OperationNotSupportedException;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.SwingUtilities;
import javax.swing.ToolTipManager;
import javax.swing.WindowConstants;
public class Application extends AbstractApplication implements
KeyEventDispatcher {
// license file
public static final String LICENSE_FILE = "/geogebra/gui/_license.txt";
// jar file names
public final static String CAS_JAR_NAME = "geogebra_cas.jar";
public final static String JAVASCRIPT_JAR_NAME = "geogebra_javascript.jar";
public static final String[] JAR_FILES = { "geogebra.jar",
"geogebra_main.jar", "geogebra_gui.jar", CAS_JAR_NAME,
"geogebra_algos.jar", "geogebra_export.jar", JAVASCRIPT_JAR_NAME, // don't
// put
// at
// end
// (sometimes
// omitted,
// see
// WorksheetExportDialog)
"jlatexmath.jar", // LaTeX
"jlm_greek.jar", // Greek Unicode codeblock (for LaTeX texts)
"jlm_cyrillic.jar", // Cyrillic Unicode codeblock (for LaTeX texts)
"geogebra_properties.jar" };
// supported GUI languages (from properties files)
public static ArrayList<Locale> supportedLocales = new ArrayList<Locale>();
static {
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("sq")); // Albanian
}
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("hy")); // Armenian
}
supportedLocales.add(new Locale("ar")); // Arabic
supportedLocales.add(new Locale("eu")); // Basque
supportedLocales.add(new Locale("bs")); // Bosnian
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("bg")); // Bulgarian
}
supportedLocales.add(new Locale("ca")); // Catalan
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("zh", "CN")); // Chinese
}
// (Simplified)
supportedLocales.add(new Locale("zh", "TW")); // Chinese (Traditional)
supportedLocales.add(new Locale("hr")); // Croatian
supportedLocales.add(new Locale("cs")); // Czech
supportedLocales.add(new Locale("da")); // Danish
supportedLocales.add(new Locale("nl")); // Dutch
supportedLocales.add(new Locale("en")); // English
supportedLocales.add(new Locale("en", "GB")); // English (UK)
supportedLocales.add(new Locale("en", "AU")); // English (Australia)
supportedLocales.add(new Locale("et")); // Estonian
supportedLocales.add(new Locale("fi")); // Finnish
supportedLocales.add(new Locale("fr")); // French
supportedLocales.add(new Locale("gl")); // Galician
supportedLocales.add(new Locale("ka")); // Georgian
supportedLocales.add(new Locale("de")); // German
supportedLocales.add(new Locale("de", "AT")); // German (Austria)
supportedLocales.add(new Locale("el")); // Greek
// supportedLocales.add(new Locale("gu")); // Gujarati
supportedLocales.add(new Locale("iw")); // Hebrew
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("hi")); // Hindi
}
supportedLocales.add(new Locale("hu")); // Hungarian
supportedLocales.add(new Locale("is")); // Icelandic
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("in")); // Indonesian
}
supportedLocales.add(new Locale("it")); // Italian
supportedLocales.add(new Locale("ja")); // Japanese
supportedLocales.add(new Locale("kk")); // Kazakh
supportedLocales.add(new Locale("ko")); // Korean
supportedLocales.add(new Locale("lt")); // Lithuanian
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("ml")); // Malayalam
}
supportedLocales.add(new Locale("mk")); // Macedonian
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("mr")); // Marathi
}
supportedLocales.add(new Locale("ms")); // Malay
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("ne")); // Nepalese
}
supportedLocales.add(new Locale("no", "NO")); // Norwegian (Bokmal)
supportedLocales.add(new Locale("no", "NO", "NY")); // Norwegian(Nynorsk)
// supportedLocales.add(new Locale("oc")); // Occitan
supportedLocales.add(new Locale("fa")); // Persian
supportedLocales.add(new Locale("pl")); // Polish
supportedLocales.add(new Locale("pt")); // Portugese (Brazil)
supportedLocales.add(new Locale("pt", "PT")); // Portuguese (Portugal)
// supportedLocales.add(new Locale("pa")); // Punjabi
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("ro")); // Romanian
}
supportedLocales.add(new Locale("ru")); // Russian
supportedLocales.add(new Locale("sr")); // Serbian
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("si")); // Sinhala (Sri Lanka)
}
supportedLocales.add(new Locale("sk")); // Slovakian
supportedLocales.add(new Locale("sl")); // Slovenian
supportedLocales.add(new Locale("es")); // Spanish
supportedLocales.add(new Locale("sv")); // Swedish
// supportedLocales.add(new Locale("ty")); // Tahitian
supportedLocales.add(new Locale("ta")); // Tamil
// supportedLocales.add(new Locale("te")); // Telugu
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("th")); // Thai
}
supportedLocales.add(new Locale("tr")); // Turkish
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("uk")); // Ukrainian
}
// supportedLocales.add(new Locale("ur")); // Urdu
supportedLocales.add(new Locale("vi")); // Vietnamese
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("cy")); // Welsh
}
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("ia")); // Interlingua
}
if (GeoGebraConstants.IS_PRE_RELEASE) {
supportedLocales.add(new Locale("ji")); // Yiddish
}
}
// made a little darker in ggb40
// (problem showing on some projectors)
public static final Color COLOR_SELECTION = new Color(210, 210, 225);
// Font settings
public static final int MIN_FONT_SIZE = 10;
// maximum number of files to (save &) show in File -> Recent submenu
public static final int MAX_RECENT_FILES = 8;
// file extension string
public static final String FILE_EXT_GEOGEBRA = "ggb";
// Added for Intergeo File Format (Yves Kreis) -->
public static final String FILE_EXT_INTERGEO = "i2g";
// <-- Added for Intergeo File Format (Yves Kreis)
public static final String FILE_EXT_GEOGEBRA_TOOL = "ggt";
public static final String FILE_EXT_PNG = "png";
public static final String FILE_EXT_EPS = "eps";
public static final String FILE_EXT_PDF = "pdf";
public static final String FILE_EXT_EMF = "emf";
public static final String FILE_EXT_SVG = "svg";
public static final String FILE_EXT_HTML = "html";
public static final String FILE_EXT_HTM = "htm";
public static final String FILE_EXT_TEX = "tex";
protected File currentPath, currentImagePath, currentFile = null;
// page margin in cm
public static final double PAGE_MARGIN_X = (1.8 * 72) / 2.54;
public static final double PAGE_MARGIN_Y = (1.8 * 72) / 2.54;
private static final String RB_MENU = "/geogebra/properties/menu";
private static final String RB_COMMAND = "/geogebra/properties/command";
private static final String RB_ERROR = "/geogebra/properties/error";
private static final String RB_PLAIN = "/geogebra/properties/plain";
private static final String RB_SYMBOL = "/geogebra/properties/symbols";
public static final String RB_JAVA_UI = "/geogebra/properties/javaui";
private static final String RB_COLORS = "/geogebra/properties/colors";
private static final String RB_SETTINGS = "/geogebra/export/settings";
//private static final String RB_ALGO2COMMAND = "/geogebra/kernel/algo2command";
// Added for Intergeo File Format (Yves Kreis) -->
//private static final String RB_ALGO2INTERGEO = "/geogebra/kernel/algo2intergeo";
// <-- Added for Intergeo File Format (Yves Kreis)
// private static Color COLOR_STATUS_BACKGROUND = new Color(240, 240, 240);
private boolean useFullGui = false;
/**
* The preferred size of this application. Used in case the frame size
* should be updated.
*/
private Dimension preferredSize = new Dimension();
public static final int DEFAULT_ICON_SIZE = 32;
private JFrame frame;
private static AppletImplementation appletImpl;
private final FontManager fontManager;
protected GuiManager guiManager;
private Component mainComp;
private boolean isApplet = false;
private final MyXMLio myXMLio;
private GlobalKeyDispatcher globalKeyDispatcher;
// For language specific settings
private Locale currentLocale;
private Locale tooltipLocale = null;
private ResourceBundle rbmenu, rbmenuTT, rbcommand, rbcommandTT,
rbcommandEnglish, rbcommandOld, rbcommandScripting, rberror,
rbcolors, rbplain, rbplainTT, rbmenuEnglish, rbsymbol, rbsettings;
protected ImageManager imageManager;
private int maxIconSize = DEFAULT_ICON_SIZE;
// Hashtable for translation of commands from
// local language to internal name
// key = local name, value = internal name
private boolean initing = false;
protected boolean showAlgebraView = true;
/*
* stored here rather than in algebra view so that it can be set without
* creating an AV (compatibility with 3.2)
*/
public boolean showAuxiliaryObjects = false;
private boolean showAlgebraInput = true;
private boolean showInputTop = false;
private boolean showInputHelpToggle = true;
protected boolean showToolBar = true;
private boolean showToolBarTop = true;
protected boolean showConsProtNavigation = false;
private boolean printScaleString = false;
private boolean allowToolTips = true;
private boolean rightClickEnabled = true;
private boolean chooserPopupsEnabled = true;
private boolean isErrorDialogsActive = true;
private boolean isErrorDialogShowing = false;
private static LinkedList<File> fileList = new LinkedList<File>();
private boolean isSaved = true;
// private int guiFontSize;
// private int axesFontSize;
// private int euclidianFontSize;
protected JPanel centerPanel, topPanel, bottomPanel;
private ArrayList<Perspective> tmpPerspectives = new ArrayList<Perspective>();
private GgbAPI ggbapi = null;
private PluginManager pluginmanager = null;
private ScriptManager scriptManager = null;
private PythonBridge pythonBridge = null;
// GUI elements to support a sidebar help panel for the input bar.
// The help panel slides open on a button press from the input bar.
private JSplitPane applicationSplitPane;
private DockBar dockBar;
public void openDockBar() {
if (dockBar != null) {
dockBar.openDockBar();
}
}
private SpreadsheetTableModel tableModel;
public Application(CommandLineArguments args, JFrame frame,
boolean undoActive) {
this(args, frame, null, null, undoActive);
}
public Application(CommandLineArguments args,
AppletImplementation appletImpl, boolean undoActive) {
this(args, null, appletImpl, null, undoActive);
}
public Application(CommandLineArguments args, Container comp,
boolean undoActive) {
this(args, null, null, comp, undoActive);
}
protected Application(CommandLineArguments args, JFrame frame,
AppletImplementation appletImpl, Container comp, boolean undoActive) {
AbstractApplication.dbg = new DebugPrinterDesktop();
setFileVersion(GeoGebraConstants.VERSION_STRING);
OS = System.getProperty("os.name").toLowerCase(
Locale.US);
if (args != null) {
handleHelpVersionArgs(args);
}
isApplet = appletImpl != null;
JApplet applet = null;
if (frame != null) {
mainComp = frame;
} else if (isApplet) {
applet = appletImpl.getJApplet();
mainComp = applet;
setApplet(appletImpl);
} else {
mainComp = comp;
}
useFullGui = !isApplet || appletImpl.needsGui();
// don't want to redirect System.out and System.err when running as
// Applet
// or eg from Eclipse
getCodeBase(); // initialize runningFromJar
if (!isApplet && runningFromJar) {
setUpLogging();
}
// needed for JavaScript getCommandName(), getValueString() to work
// (security problem running non-locally)
if (isApplet) {
preferredSize = appletImpl.getJApplet().getSize();
// needs command.properties in main.jar
// causes problems when not in English
// initCommandBundle();
} else {
preferredSize = new Dimension(800, 600);
}
fontManager = new FontManager();
initImageManager(mainComp);
// set locale
setLocale(mainComp.getLocale());
// init kernel
initFactories();
initKernel();
kernel.setPrintDecimals(Kernel.STANDARD_PRINT_DECIMALS);
// init settings
settings = new Settings();
// init euclidian view
initEuclidianViews();
// load file on startup and set fonts
// set flag to avoid multiple calls of setLabels() and
// updateContentPane()
initing = true;
setFontSize(12);
// This is needed because otherwise Exception might come and
// GeoGebra may exit. (dockPanel not entirely defined)
// This is needed before handleFileArg because
// we don't want to redefine the toolbar string from the file.
boolean ggtloading = isLoadingTool(args);
if (ggtloading) {
if (!isApplet) {
GeoGebraPreferences.getPref().loadXMLPreferences(this);
}
}
// init default preferences if necessary
if (!isApplet) {
GeoGebraPreferences.getPref().initDefaultXML(this);
}
// init xml io for construction loading
myXMLio = new MyXMLio((Kernel) kernel, kernel.getConstruction());
// open file given by startup parameter
handleOptionArgsEarly(args); // for --regressionFile=...
boolean fileLoaded = handleFileArg(args);
// initialize GUI
if (isUsingFullGui()) {
initGuiManager();
// set frame
if (!isApplet && (frame != null)) {
setFrame(frame);
}
}
if (!isApplet) {
// load XML preferences
currentPath = GeoGebraPreferences.getPref().getDefaultFilePath();
currentImagePath = GeoGebraPreferences.getPref()
.getDefaultImagePath();
if (!fileLoaded && !ggtloading) {
GeoGebraPreferences.getPref().loadXMLPreferences(this);
}
}
if (isUsingFullGui() && (tmpPerspectives != null) && !ggtloading) {
getGuiManager().getLayout().setPerspectives(tmpPerspectives);
}
setUndoActive(undoActive);
// applet/command line options
handleOptionArgs(args);
initing = false;
// for key listening
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addKeyEventDispatcher(this);
// init plugin manager for applications
if (!isApplet) {
pluginmanager = getPluginManager();
}
if (!isApplet()) {
getScriptManager().ggbOnInit();
}
isSaved = true;
if (getCASVersionString() == "") {
setCASVersionString(getPlain("CASInitializing"));
}
}
private void initFactories() {
geogebra.common.factories.AwtFactory.prototype = new geogebra.factories.AwtFactory();
geogebra.common.factories.FormatFactory.prototype = new geogebra.factories.FormatFactory();
geogebra.common.factories.LaTeXFactory.prototype = new geogebra.factories.LaTeXFactory();
geogebra.common.factories.CASFactory.prototype = new geogebra.factories.CASFactory();
geogebra.common.util.StringUtil.prototype = new geogebra.util.StringUtil();
// TODO: probably there is better way
geogebra.common.awt.Color.black = geogebra.awt.Color.black;
geogebra.common.awt.Color.white = geogebra.awt.Color.white;
geogebra.common.awt.Color.blue = geogebra.awt.Color.blue;
geogebra.common.awt.Color.gray = geogebra.awt.Color.gray;
geogebra.common.awt.Color.lightGray = geogebra.awt.Color.lightGray;
geogebra.common.awt.Color.darkGray = geogebra.awt.Color.darkGray;
geogebra.common.euclidian.HatchingHandler.prototype = new geogebra.euclidian.HatchingHandler();
geogebra.common.euclidian.EuclidianStatic.prototype = new geogebra.euclidian.EuclidianStatic();
geogebra.common.euclidian.clipping.DoubleArrayFactory.prototype = new geogebra.euclidian.clipping.DoubleArrayFactory();
}
private void handleHelpVersionArgs(CommandLineArguments args) {
if (args.containsArg("help")) {
// help message
System.out
.println("Usage: java -jar geogebra.jar [OPTION] [FILE]\n"
+ "Start GeoGebra with the specified OPTIONs and open the given FILE.\n"
+ " --help\t\tprint this message\n"
+ " --v\t\tprint version\n"
+ " --language=LANGUAGE_CODE\t\tset language using locale strings, e.g. en, de, de_AT, ...\n"
+ " --showAlgebraInput=BOOLEAN\tshow/hide algebra input field\n"
+ " --showAlgebraInputTop=BOOLEAN\tshow algebra input at top/bottom\n"
+ " --showAlgebraWindow=BOOLEAN\tshow/hide algebra window\n"
+ " --showSpreadsheet=BOOLEAN\tshow/hide spreadsheet\n"
+ (GeoGebraConstants.CAS_VIEW_ENABLED ? " --showCAS=BOOLEAN\tshow/hide CAS window\n"
: "")
+ " --showSplash=BOOLEAN\tenable/disable the splash screen\n"
+ " --enableUndo=BOOLEAN\tenable/disable Undo\n"
+ " --fontSize=NUMBER\tset default font size\n"
+ " --showAxes=BOOLEAN\tshow/hide coordinate axes\n"
+ " --showGrid=BOOLEAN\tshow/hide grid\n"
+ " --settingsFile=PATH|FILENAME\tload/save settings from/in a local file\n"
+ " --resetSettings\treset current settings\n"
+ " --antiAliasing=BOOLEAN\tturn anti-aliasing on/off\n"
+ " --regressionFile=FILENAME\texport textual representations of dependent objects, then exit\n");
System.exit(0);
}
// help debug applets
System.out.println("GeoGebra " + GeoGebraConstants.VERSION_STRING + " "
+ GeoGebraConstants.BUILD_DATE + " Java "
+ System.getProperty("java.version"));
if (args.containsArg("v")) {
System.exit(0);
}
}
@Override
protected EuclidianController newEuclidianController(Kernel kernel) {
return new EuclidianController(kernel);
}
@Override
protected AbstractEuclidianView newEuclidianView(boolean[] showAxes,
boolean showGrid) {
return new EuclidianView(euclidianController, showAxes, showGrid,
getSettings().getEuclidian(1));
}
/**
* init the ImageManager (and ImageManager3D for 3D)
*
* @param component
*/
protected void initImageManager(Component component) {
imageManager = new ImageManager(component);
}
/**
* @return True if the whole GUI is available, false if just the euclidian
* view is displayed.
*/
@Override
final public synchronized boolean isUsingFullGui() {
return useFullGui;
}
/**
* Initialize the gui manager.
*/
final protected void initGuiManager() {
setWaitCursor();
guiManager = newGuiManager();
guiManager.setLayout(new geogebra.gui.layout.Layout());
guiManager.initialize();
setDefaultCursor();
}
protected GuiManager newGuiManager() {
return new GuiManager(Application.this);
}
/**
* @return this application's GUI manager.
*/
@Override
final public synchronized GuiManager getGuiManager() {
return guiManager;
}
final public JApplet getJApplet() {
if (appletImpl == null) {
return null;
} else {
return appletImpl.getJApplet();
}
}
final public Font getBoldFont() {
return fontManager.getBoldFont();
}
final public Font getItalicFont() {
return fontManager.getItalicFont();
}
final public Font getPlainFont() {
return fontManager.getPlainFont();
}
@Override
final public geogebra.common.awt.Font getPlainFontCommon() {
return new geogebra.awt.Font(fontManager.getPlainFont());
}
final public Font getSerifFont() {
return fontManager.getSerifFont();
}
final public Font getSmallFont() {
return fontManager.getSmallFont();
}
final public Font getFont(boolean serif, int style, int size) {
return fontManager.getFont(serif, style, size);
}
/**
* @return the font manager to access fonts for different tasks
*/
final public FontManager getFontManager() {
return fontManager;
}
/**
* Sets state of application to "saved", so that no warning appears on
* close.
*
* @author Zbynek Konecny
* @version 2010-05-26
*/
public void setSaved() {
isSaved = true;
}
/**
* Sets application state to "unsaved" so that user is reminded on close.
*/
@Override
public void setUnsaved() {
isSaved = false;
}
@Override
public boolean isIniting() {
return initing;
}
public void fileNew() {
// clear all
clearConstruction();
// clear input bar
if (isUsingFullGui() && showAlgebraInput()) {
AlgebraInput ai = (AlgebraInput) (getGuiManager().getAlgebraInput());
ai.clear();
}
// reset spreadsheet columns, reset trace columns
if (isUsingFullGui()) {
getGuiManager().resetSpreadsheet();
}
getEuclidianView().resetMaxLayerUsed();
getEuclidianView().resetXYMinMaxObjects();
if (hasEuclidianView2EitherShowingOrNot()) {
getEuclidianView2().resetXYMinMaxObjects();
}
kernel.resetLibraryJavaScript();
kernel.resetLibraryPythonScript();
if (scriptManager != null) {
scriptManager.resetListeners();
}
resetUniqueId();
}
public boolean getAllowToolTips() {
return allowToolTips;
}
/**
* Sets allowToolTips flag and toggles tooltips for the application.
*/
public void setAllowToolTips(boolean allowToolTips) {
this.allowToolTips = allowToolTips;
ToolTipManager.sharedInstance().setEnabled(allowToolTips);
}
/**
* Updates the GUI of the main component.
*/
public void updateContentPane() {
updateContentPane(true);
}
/**
* Updates the GUI of the framd and its size.
*/
public void updateContentPaneAndSize() {
if (initing) {
return;
}
updateContentPane(false);
if ((frame != null) && frame.isShowing()) {
getGuiManager().updateFrameSize();
}
updateComponentTreeUI();
}
private void updateContentPane(boolean updateComponentTreeUI) {
if (initing) {
return;
}
Container cp;
if (isApplet) {
cp = appletImpl.getJApplet().getContentPane();
} else if (frame != null) {
cp = frame.getContentPane();
} else {
cp = (Container) mainComp;
}
addMacroCommands();
cp.removeAll();
cp.add(buildApplicationPanel());
fontManager.setFontSize(getGUIFontSize());
// update sizes
euclidianView.updateSize();
// update layout
if (updateComponentTreeUI) {
updateComponentTreeUI();
}
// reset mode and focus
setMoveMode();
if (mainComp.isShowing()) {
euclidianView.requestFocusInWindow();
}
System.gc();
}
protected void updateComponentTreeUI() {
if (isApplet()) {
SwingUtilities.updateComponentTreeUI(appletImpl.getJApplet());
} else if (frame != null) {
SwingUtilities.updateComponentTreeUI(frame);
} else if (mainComp != null) {
SwingUtilities.updateComponentTreeUI(mainComp);
}
}
/**
* Builds a panel with all components that should be shown on screen (like
* toolbar, input field, algebra view).
*/
public JPanel buildApplicationPanel() {
JPanel panel = new JPanel(new BorderLayout());
// remove existing elements
if (centerPanel != null) {
centerPanel.removeAll();
} else {
centerPanel = new JPanel(new BorderLayout());
}
centerPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0,
SystemColor.controlShadow));
updateCenterPanel(true);
// full GUI => use layout manager, add other GUI elements as requested
if (isUsingFullGui()) {
topPanel = new JPanel(new BorderLayout());
bottomPanel = new JPanel(new BorderLayout());
updateTopBottomPanels();
// ==================
// G.Sturr 2010-11-14
// Create a help panel for the input bar and a JSplitPane to contain
// it.
// The splitPane defaults with the application on the left and null
// on the right.
// Our help panel will be added/removed as needed by the input bar.
if (applicationSplitPane == null) {
applicationSplitPane = new JSplitPane(
JSplitPane.HORIZONTAL_SPLIT, centerPanel, null);
applicationSplitPane.setBorder(BorderFactory
.createEmptyBorder());
// help panel is on the right, so set all resize weight to the
// left pane
applicationSplitPane.setResizeWeight(1.0);
applicationSplitPane.setDividerSize(0);
}
if (dockBar == null) {
dockBar = new DockBar(this);
}
JPanel subPanel = new JPanel(new BorderLayout());
subPanel.add(topPanel, BorderLayout.NORTH);
subPanel.add(applicationSplitPane, BorderLayout.CENTER);
subPanel.add(bottomPanel, BorderLayout.SOUTH);
panel.add(subPanel, BorderLayout.CENTER);
panel.add(dockBar, BorderLayout.WEST);
// init labels
setLabels();
// Menubar; if the main component is a JPanel, we need to add the
// menubar manually to the north
if (showMenuBar() && (mainComp instanceof JPanel)) {
JPanel menuBarPanel = new JPanel(new BorderLayout());
menuBarPanel.add(getGuiManager().getMenuBar(),
BorderLayout.NORTH);
menuBarPanel.add(panel, BorderLayout.CENTER);
return menuBarPanel;
} else {
// standard case: return
return panel;
}
}
// minimal applet => just display EV
panel.add(((EuclidianView) euclidianView).getJPanel(), BorderLayout.CENTER);
centerPanel.add(panel, BorderLayout.CENTER);
return panel;
}
/**
* Open/close the sidebar help panel for the input bar
*/
public void setShowInputHelpPanel(boolean isVisible) {
if (isVisible) {
applicationSplitPane.setRightComponent(getGuiManager()
.getInputHelpPanel());
if (applicationSplitPane.getLastDividerLocation() <= 0) {
applicationSplitPane
.setLastDividerLocation(applicationSplitPane.getWidth()
- getGuiManager().getInputHelpPanel()