@BeforeClass public static void setupCas() { app = new AppD(new CommandLineArguments(new String[] {"--giac"}), new JFrame(), false); // Set language to something else than English to test automatic translation. app.setLanguage(Locale.GERMANY); // app.fillCasCommandDict(); kernel = app.getKernel(); cas = kernel.getGeoGebraCAS(); logger = new CASTestLogger(); // Setting the general timeout to 13 seconds. Feel free to change this. kernel.getApplication().getSettings().getCasSettings().setTimeoutMilliseconds(13000); try { Log.debug("CAS: loading testcases"); String json = readFileAsString("../web/war/__giac.js"); Log.debug("CAS: parsing testcases"); Log.debug("CAS: testcases parsed"); JSONArray testsJSON = new JSONArray(json.substring("var __giac = ".length())); Assert.assertNotSame(0, testsJSON.length()); int i = 1; while (i < testsJSON.length()) { JSONObject test = testsJSON.getJSONObject(i); i++; String cat = "general"; if (test.has("cat")) { cat = test.getString("cat"); } if (!testcases.containsKey(cat)) { /*System.out.println("@Test"); System.out.println("public void test"+cat+"(){"); System.out.println(" testCat(\""+cat+"\");"); System.out.println("}\n");*/ testcases.put(cat, new HashMap<String, String>()); } if (test.has("round")) { testcases.get(cat).put(test.getString("cmd"), test.getString("round")); } else { testcases.get(cat).put(test.getString("cmd"), test.getString("result")); } } } catch (Throwable e) { e.printStackTrace(); } }
private void doTextFieldActionPerformed(JTextField source) { if (isUpdating) return; try { String inputText = source.getText().trim(); NumberValue nv; nv = app.getKernel().getAlgebraProcessor().evaluateToNumeric(inputText, false); double value = nv.getDouble(); // TODO better validation if (source == fldXMin) { settings.xMin = value; firePropertyChange("settings", true, false); } else if (source == fldXMax) { settings.xMax = value; firePropertyChange("settings", true, false); } else if (source == fldYMax) { settings.yMax = value; firePropertyChange("settings", true, false); } else if (source == fldYMin) { settings.yMin = value; firePropertyChange("settings", true, false); } else if (source == fldXInterval && value >= 0) { settings.xAxesInterval = value; firePropertyChange("settings", true, false); } else if (source == fldYInterval && value >= 0) { settings.yAxesInterval = value; firePropertyChange("settings", true, false); } else if (source == fldBarWidth && value >= 0) { settings.setBarWidth(value); firePropertyChange("settings", true, false); } updateGUI(); } catch (NumberFormatException e) { e.printStackTrace(); } }
private void doTextFieldActionPerformed(JTextField source) { if (isIniting) return; if (source == fldInputX) { try { String inputText = source.getText().trim(); if (inputText == null || inputText.length() == 0) return; NumberValue nv; nv = app.getKernel().getAlgebraProcessor().evaluateToNumeric(inputText, true); double value = nv.getDouble(); double output = ((GeoFunctionable) statDialog.getRegressionModel()).getGeoFunction().evaluate(value); fldOutputY.setText(statDialog.format(output)); } catch (NumberFormatException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } }
/** add the buttons */ protected void addButtons() { // "columns" button btnColumns = new PopupMenuButtonD(app) { private static final long serialVersionUID = 1L; @Override public boolean prepareToShowPopup() { JCheckBoxMenuItem item; removeAllMenuItems(); for (int k = 1; k < cpView.getTableColumns().length; k++) { item = new JCheckBoxMenuItem(cpView.getData().getColumns()[k].getTranslatedTitle()); TableColumn column = cpView.getTableColumns()[k]; item.setSelected(cpView.isColumnInModel(column)); ColumnKeeper colKeeper = cpView.new ColumnKeeper(column, cpView.getData().columns[k]); item.addActionListener(colKeeper); btnColumns.addPopupMenuItem(item); } return true; } }; btnColumns.setKeepVisible(true); btnColumns.setStandardButton(true); // mouse clicks over total button // region btnColumns.setIcon(app.getScaledIcon(GuiResourcesD.COLUMN_HEADER)); add(btnColumns); addSeparator(); // options button // PopupMenuButton without selection table, add JMenuItems directly. btnOptions = new PopupMenuButtonD(app) { private static final long serialVersionUID = 1L; @Override public boolean prepareToShowPopup() { miShowOnlyBreakpoints.setSelected( app.getKernel().getConstruction().showOnlyBreakpoints()); miColorfulConstructionProtocol.setSelected(cpView.getUseColors()); return true; } }; btnOptions.setKeepVisible(true); btnOptions.setStandardButton(true); // mouse clicks over total button // region btnOptions.setIcon(app.getScaledIcon(GuiResourcesD.DOCUMENT_PROPERTIES)); miShowOnlyBreakpoints = new JCheckBoxMenuItem(loc.getPlain("ShowOnlyBreakpoints")); miShowOnlyBreakpoints.setSelected(app.getKernel().getConstruction().showOnlyBreakpoints()); miShowOnlyBreakpoints.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { cpView.showOnlyBreakpointsAction(); } }); btnOptions.addPopupMenuItem(miShowOnlyBreakpoints); miColorfulConstructionProtocol = new JCheckBoxMenuItem(loc.getPlain("ColorfulConstructionProtocol")); miColorfulConstructionProtocol.setSelected(cpView.getUseColors()); miColorfulConstructionProtocol.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { cpView.setUseColors(!cpView.getUseColors()); } }); btnOptions.addPopupMenuItem(miColorfulConstructionProtocol); add(btnOptions); addSeparator(); // export button btnExport = new JButton(app.getScaledIcon(GuiResourcesD.TEXT_HTML)); btnExport.setToolTipText(loc.getPlainTooltip("ExportAsWebpage")); btnExport.addActionListener(this); add(btnExport); addSeparator(); // print button btnPrint = new JButton(app.getScaledIcon(GuiResourcesD.DOCUMENT_PRINT_PREVIEW)); btnPrint.setToolTipText(loc.getPlainTooltip("Print")); btnPrint.addActionListener(this); add(btnPrint); addSeparator(); // Help button btnHelp = new JButton(app.getScaledIcon(GuiResourcesD.HELP)); // btnHelp.setToolTipText(loc.getPlainTooltip("FastHelp")); btnHelp.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Thread runner = new Thread() { @Override public void run() { app.getGuiManager().openHelp("Construction_Protocol"); } }; runner.start(); } }); add(btnHelp); setLabels(); }
public ConstructionProtocolViewD(final AppD app) { // cpPanel = new JPanel(new BorderLayout()); this.app = app; kernel = app.getKernel(); data = new ConstructionTableData(this); useColors = true; addIcons = false; table = new JTable(); table.setAutoCreateColumnsFromModel(false); table.setModel(((GAbstractTableModelD) data.getImpl()).getImpl()); table.setRowSelectionAllowed(true); table.setGridColor(Color.lightGray); table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); // header JTableHeader header = table.getTableHeader(); // header.setUpdateTableInRealTime(true); header.setReorderingAllowed(false); // init model ConstructionTableCellRenderer renderer; HeaderRenderer headerRend = new HeaderRenderer(); tableColumns = new TableColumn[data.columns.length]; for (int k = 0; k < data.columns.length; k++) { renderer = new ConstructionTableCellRenderer(); renderer.setHorizontalAlignment(data.columns[k].getAlignment()); tableColumns[k] = new TableColumn(k, data.columns[k].getPreferredWidth(), renderer, null); tableColumns[k].setMinWidth(data.columns[k].getMinWidth()); tableColumns[k].setHeaderRenderer(headerRend); if (data.columns[k].getInitShow()) table.addColumn(tableColumns[k]); if (data.columns[k].getTitle() == "Caption") { tableColumns[k].setCellEditor(new ConstructionTableCellEditor()); } } // first column "No." should have fixed width tableColumns[0].setMaxWidth(tableColumns[0].getMinWidth()); table .getColumnModel() .addColumnModelListener(((ConstructionTableData) data).new ColumnMovementListener()); scrollPane = new JScrollPane(table); scrollPane.getViewport().setBackground(Color.white); // cpPanel.add(scrollPane, BorderLayout.CENTER); // clicking ConstructionMouseListener ml = new ConstructionMouseListener(); table.addMouseListener(ml); table.addMouseMotionListener(ml); header.addMouseListener(ml); // double clicking, right-click menu scrollPane.addMouseListener(ml); // right-click menu // keys ConstructionKeyListener keyListener = new ConstructionKeyListener(); table.addKeyListener(keyListener); app.getGuiManager().registerConstructionProtocolView(this); // navigation bar // protNavBar = new ConstructionProtocolNavigationD(app); // protNavBar.register(this); // protNavBar.setPlayButtonVisible(false); // protNavBar.setConsProtButtonVisible(false); // this.cpPanel.add(protNavBar.getImpl(), BorderLayout.SOUTH); // org.geogebra.desktop.util.Util.addKeyListenerToAll(protNavBar.getImpl(), // keyListener); initGUI(); initActions(); ConstructionProtocolSettings cps = app.getSettings().getConstructionProtocol(); settingsChanged(cps); cps.addListener(this); }