/** Invoked when an action occurs. */ public static BoxItem createNewElement(String className, int posX, int posY) { BoxItem ret = null; Element elem = null; try { if (debug) System.out.println("Creating new element '" + className + "'"); elem = Element.newInstance(className); if (elem == null) { if (debug) System.out.println("Element '" + className + "' not found"); return null; } ret = elem.getDesignerBox(); ret.setBounds( (posX / DesignEventHandler.ELEM_STEP) * DesignEventHandler.ELEM_STEP, (posY / DesignEventHandler.ELEM_STEP) * DesignEventHandler.ELEM_STEP, ConfigurableSystemSettings.getDesignerElementWidth(), ConfigurableSystemSettings.getDesignerElementHeight()); Main.app.designFrame.addElement(ret); Item.highlighted.clear(); Item.highlighted.add(ret); Main.app.processor.add(elem); // elem.setActive(false); Main.app.designFrame.panel.repaint(); if (elem instanceof Display) { Chart chart = ((Display) elem).newChart(); ((Display) elem).setChart(chart); chart.setAtTopLayer(); // System.out.println("c1 " + chart.getBounds()); Main.app.runtimeFrame.addChart(chart); // Main.app.runtimeFrame.show(); Main.app.runtimeFrame.setVisible(); // Main.app.runtimeFrame.repaint(); // Change runtime to edit mode if not now if (!Main.app.runtimeFrame.framedCharts) { Main.app.runtimeFrame.framedCharts = true; try { Main.app.runtimeFrame.reload(); } catch (Exception ex) { ex.printStackTrace(); } } } elem.reinit(); } catch (Exception e) { if (elem != null) elem.disactivate(e); System.out.println("New element error: " + e); // e.printStackTrace(); } catch (Throwable e) { System.out.println("Critical error occurred while creating new element: " + e); e.printStackTrace(); } return ret; }
/** EdiDialog constructor comment. */ public static void main(String args[]) throws Exception { try { System.out.println("started"); DialogNewElement.test(); System.out.println("Finished"); } catch (Exception e) { e.printStackTrace(); } }
/** LinesPanel constructor comment. */ public void deleteElement(Item elem) { if (elem instanceof BoxItem) { Element element = ((BoxItem) elem).element; if (element instanceof Display) { // Remove also from runtime JChart chart = ((JDisplay) element).getChart(); // System.out.println("c1 " + chart.getBounds()); Main.app.runtimeFrame.removeChart(chart); // Main.app.runtimeFrame.show(); Main.app.runtimeFrame.setVisible(); } boxes.delete(elem); // Delete all connections to this element connections.deleteConnectedTo(elem); // Delete from runtime processor try { Main.app.processor.remove(element); } catch (Exception ex) { ex.printStackTrace(); } } else if (elem instanceof TieItem) { TieItem t = (TieItem) connections.delete(elem); if (t != null) { if (t.destPin.input) { Element e1 = t.src.element; Element e2 = t.dest.element; // Pipe p1 = e1.getOutputByName(t.srcPin.pipe.getName()); // Pipe p2 = e2.getInputByName(t.destPin.pipe.getName()); Pipe p1 = t.srcPin.pipe; Pipe p2 = t.destPin.pipe; // System.out.println("p1=" + p1); // System.out.println("p2=" + p2); if (p1 instanceof PipeDistributor) { boolean ret = ((PipeDistributor) p1).unregister(p2); // System.out.println("Unregistered tie " + ret); // System.out.println("All elements:\n" + // bioera.runtime.RuntimeManager.runtimeManager.printAllElements()); } else { System.out.println("Error: Source is not a distributor"); } } else { System.out.println("Error: Source is not an output"); } } } }