/** * Resets the player to a checkpoint with the given CheckPointInfo * * @param info */ public void resetCheckpoint(CheckPointInfo info) { state = info.getState(); velocity = Vector2.Zero; health = info.getHealth(); mana = info.getMana(); heading = info.getHeading(); stats = info.getStats(); screenPosition = info.getPosition(); collisionRect = info.getRectangle(); statusbar.setHealth(health); statusbar.setMana(mana); }
public Container CreateContentPane() { // Create the content-pane-to-be. JPanel contentPane = new JPanel(new BorderLayout()); contentPane.setOpaque(true); // the log panel log = new JTextPane(); log.setEditable(false); log.setBackground(Color.BLACK); logPane = new JScrollPane(log); kit = new HTMLEditorKit(); doc = new HTMLDocument(); log.setEditorKit(kit); log.setDocument(doc); DefaultCaret c = (DefaultCaret) log.getCaret(); c.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); ClearLog(); // the preview panel previewPane = new DrawPanel(); previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right); // status bar statusBar = new StatusBar(); Font f = statusBar.getFont(); statusBar.setFont(f.deriveFont(Font.BOLD, 15)); Dimension d = statusBar.getMinimumSize(); d.setSize(d.getWidth(), d.getHeight() + 30); statusBar.setMinimumSize(d); // layout Splitter split = new Splitter(JSplitPane.VERTICAL_SPLIT); split.add(previewPane); split.add(logPane); split.setDividerSize(8); contentPane.add(statusBar, BorderLayout.SOUTH); contentPane.add(split, BorderLayout.CENTER); // open the file if (recentFiles[0].length() > 0) { OpenFileOnDemand(recentFiles[0]); } // connect to the last port ListSerialPorts(); if (Arrays.asList(portsDetected).contains(recentPort)) { OpenPort(recentPort); } return contentPane; }
public WWPanel(Dimension size) { this.wwd = new WorldWindowGLCanvas(); this.wwd.setSize(size); this.wwd.setModel((Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME)); this.setLayout(new BorderLayout(5, 5)); this.add(this.wwd, BorderLayout.CENTER); StatusBar statusBar = new StatusBar(); statusBar.setEventSource(wwd); this.add(statusBar, BorderLayout.SOUTH); }
// User has asked that a file be opened. public void OpenFileOnDemand(String filename) { Log("<font color='green'>Opening file " + recentFiles[0] + "...</font>\n"); String ext = filename.substring(filename.lastIndexOf('.')); if (!ext.equalsIgnoreCase(".ngc")) { LoadImage(filename); } else { LoadGCode(filename); } statusBar.Clear(); }
@SuppressWarnings("incomplete-switch") @Override public void draw(Graphics2D graphics) { ElementalShield cs = spellManager.getCurrentShield(); if (cs != null) { Color[] c = new Color[3]; c[0] = new Color(0, 0, 0, 0); c[1] = new Color(0, 0, 0, 0); ElementType type = cs.getElementType(); switch (type) { case Earth: c[2] = new Color(0.45f, 0.4f, 0.15f, 0.85f); break; case Fire: c[2] = new Color(1.0f, 0.0f, 0.0f, 0.7f); break; case Water: c[2] = new Color(0.3f, 0.3f, 0.8f, 0.7f); break; } float[] dist = {0.0f, 0.25f, 1f}; RadialGradientPaint rgp = new RadialGradientPaint( new Point2D.Float((int) screenPosition.x + 16, (int) screenPosition.y + 16), 20, dist, c); graphics.setPaint(rgp); graphics.fillOval((int) screenPosition.x - 4, (int) screenPosition.y - 4, 40, 40); } graphics.drawImage(getTexture(), (int) screenPosition.x, (int) screenPosition.y, null); if (controlled) { spellManager.draw(graphics); statusbar.draw(graphics); } if (isInNetwork && controllerActive) { if (controller.isPressed(KeyEvent.VK_T)) DeathMatchStatistics.getInstance().draw(graphics); } }
// Take the next line from the file and send it to the robot, if permitted. public void SendFileCommand() { if (running == false || paused == true || fileOpened == false || portConfirmed == false || linesProcessed >= linesTotal) return; String line; do { // are there any more commands? line = gcode.get((int) linesProcessed++).trim(); previewPane.setLinesProcessed(linesProcessed); statusBar.SetProgress(linesProcessed, linesTotal); // loop until we find a line that gets sent to the robot, at which point we'll // pause for the robot to respond. Also stop at end of file. } while (ProcessLine(line) && linesProcessed < linesTotal); if (linesProcessed == linesTotal) { // end of file Halt(); } }
public MainFrame() { super("Cacophony"); setFocusTraversalKeysEnabled(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setExtendedState(JFrame.MAXIMIZED_BOTH); final Synthesizer syn = system.getSynthesizer(); instruments = new DefaultMidiInstruments(syn); grates.register(GrateModes.KEYS, new DefaultKeyGrate()); grates.register(GrateModes.COMMAND, new DefaultCommandGrate(instruments, status)); final JPanel mainView = new JPanel(); add(mainView, BorderLayout.CENTER); add(status.view(), BorderLayout.SOUTH); final SwitchableView[] switchableViews = ocelot.views(); mainView.setLayout(new GridLayout(switchableViews.length + 1, 1)); final List<Toridor> views = meerkat.views( reader.read( new StringReader( "Vibraphone\n" + "50,51,52_16|54_32|53_16|56_16|55_16|58_16|55_16|56_16|58_16|53_16|68_16|70_16|68_16|70_16|68_16|70_16|67_16\n" + "String Ensemble 1\n" + "70_64|70_16|61,62_16|64_32|53_16|56_16|55_16|58_16|55_16|56_16|58_16|53_16|68_16|70_16|68_16|70_16|68_16|70_16|67_16\n" + "Flute\n" + "70_64|61,62_16|64_32|53_16|56_16|55_64\n" + // "Lead 8 (bass + lead)\n" + // "70_64|61,62_16\n" + "Seashore\n" + "70_64|61,62_16|64_32|53_16|56_16|55_16|58_16|70_16|68_16|70_16|67_16\n" + "Gunshot\n" + "70_64|61,62_16|64_32|53_16|56_16|55_16|58_16|55_16|56_16|58_16|53_16|68_16|70_16|68_16|70_16|68_16|70_16|67_16")), instruments); for (final SwitchableView switchableView : switchableViews) { mainView.add(switchableView.view()); } for (int i = 0; i < views.size(); i++) { final Toridor toridor = views.get(i); if (i < switchableViews.length) switchableViews[i].show(toridor); } ocelot.setCandidates(views); manager = new DefaultToridorManager(views); mainView.add(infoPanel.view()); infoPanel.refresh(); addKeyListener( new KeyAdapter() { public void keyPressed(final KeyEvent e) { final Operation operation = grates.handle(e); status.clearMessage(); operation.fold( new ChannelOp() { public boolean op(final H<Ocelot, Control, Boolean> h) { return h.h(ocelot, control); } }, new ControlOp() { public boolean op(final G<Control, Boolean> g) { g.g(control); updateInfo(); return true; } }, new SystemOp() { public boolean op(final H<SoundSystem, ToridorManager, Boolean> h) { return h.h(system, manager); } }, new UiOp() { public boolean op(final G<Grates, Boolean> g) { g.g(grates); updateInfo(); return true; } }, new NoOp() { public boolean op() { // FIX 17/03/12 This may be a bit verbose as it picks up when a meta key is // pressed. return true; } }); } }); }
// The user has done something. respond to it. public void actionPerformed(ActionEvent e) { Object subject = e.getSource(); if (subject == buttonZoomIn) { previewPane.ZoomIn(); return; } if (subject == buttonZoomOut) { previewPane.ZoomOut(); return; } if (subject == buttonOpenFile) { OpenFileDialog(); return; } if (subject == buttonStart) { if (fileOpened) { paused = false; running = true; UpdateMenuBar(); linesProcessed = 0; previewPane.setRunning(running); previewPane.setLinesProcessed(linesProcessed); statusBar.Start(); SendFileCommand(); } return; } if (subject == buttonPause) { if (running) { if (paused == true) { buttonPause.setText("Pause"); paused = false; // @TODO: if the robot is not ready to unpause, this might fail and the program would // appear to hang. SendFileCommand(); } else { buttonPause.setText("Unpause"); paused = true; } } return; } if (subject == buttonDrive) { Drive(); return; } if (subject == buttonHalt) { Halt(); return; } if (subject == buttonRescan) { ListSerialPorts(); UpdateMenuBar(); return; } if (subject == buttonConfig) { UpdateConfig(); return; } if (subject == buttonJogMotors) { JogMotors(); return; } if (subject == buttonAbout) { JOptionPane.showMessageDialog( null, "Created by Dan Royer ([email protected]).\n\n" + "Find out more at http://www.marginallyclever.com/\n" + "Get the latest version and read the documentation online @ http://github.com/i-make-robots/DrawBot/"); return; } if (subject == buttonCheckForUpdate) { CheckForUpdate(); return; } if (subject == buttonExit) { System.exit(0); // @TODO: be more graceful? return; } int i; for (i = 0; i < 10; ++i) { if (subject == buttonRecent[i]) { OpenFileOnDemand(recentFiles[i]); return; } } for (i = 0; i < portsDetected.length; ++i) { if (subject == buttonPorts[i]) { OpenPort(portsDetected[i]); return; } } }
void EstimateDrawTime() { int i, j; float drawScale = 1.0f; double px = 0, py = 0, pz = 0; float feed_rate = 1.0f; estimated_time = 0; float estimated_length = 0; int estimate_count = 0; for (i = 0; i < gcode.size(); ++i) { String line = gcode.get(i); String[] pieces = line.split(";"); if (pieces.length == 0) continue; String[] tokens = pieces[0].split("\\s"); if (tokens.length == 0) continue; for (j = 0; j < tokens.length; ++j) { if (tokens[j].equals("G20")) drawScale = 0.393700787f; if (tokens[j].equals("G21")) drawScale = 0.1f; if (tokens[j].startsWith("F")) { feed_rate = Float.valueOf(tokens[j].substring(1)) * drawScale; Log("<span style='color:green'>feed rate=" + feed_rate + "</span>\n"); feed_rate *= 1; } } double x = px; double y = py; double z = pz; double ai = px; double aj = py; for (j = 1; j < tokens.length; ++j) { if (tokens[j].startsWith("X")) x = Float.valueOf(tokens[j].substring(1)) * drawScale; if (tokens[j].startsWith("Y")) y = Float.valueOf(tokens[j].substring(1)) * drawScale; if (tokens[j].startsWith("Z")) z = Float.valueOf(tokens[j].substring(1)) * drawScale; if (tokens[j].startsWith("I")) ai = px + Float.valueOf(tokens[j].substring(1)) * drawScale; if (tokens[j].startsWith("J")) aj = py + Float.valueOf(tokens[j].substring(1)) * drawScale; } if (tokens[0].equals("G00") || tokens[0].equals("G0") || tokens[0].equals("G01") || tokens[0].equals("G1")) { // draw a line double ddx = x - px; double ddy = y - py; double dd = Math.sqrt(ddx * ddx + ddy * ddy); estimated_time += dd / feed_rate; estimated_length += dd; ++estimate_count; px = x; py = y; pz = z; } else if (tokens[0].equals("G02") || tokens[0].equals("G2") || tokens[0].equals("G03") || tokens[0].equals("G3")) { // draw an arc int dir = (tokens[0].equals("G02") || tokens[0].equals("G2")) ? -1 : 1; double dx = px - ai; double dy = py - aj; double radius = Math.sqrt(dx * dx + dy * dy); // find angle of arc (sweep) double angle1 = atan3(dy, dx); double angle2 = atan3(y - aj, x - ai); double theta = angle2 - angle1; if (dir > 0 && theta < 0) angle2 += 2.0 * Math.PI; else if (dir < 0 && theta > 0) angle1 += 2.0 * Math.PI; theta = Math.abs(angle2 - angle1); // Draw the arc from a lot of little line segments. for (int k = 0; k <= theta * DrawPanel.STEPS_PER_DEGREE; ++k) { double angle3 = (angle2 - angle1) * ((double) k / (theta * DrawPanel.STEPS_PER_DEGREE)) + angle1; float nx = (float) (ai + Math.cos(angle3) * radius); float ny = (float) (aj + Math.sin(angle3) * radius); double ddx = nx - px; double ddy = ny - py; double dd = Math.sqrt(ddx * ddx + ddy * ddy); estimated_time += dd / feed_rate; estimated_length += dd; ++estimate_count; px = nx; py = ny; } double ddx = x - px; double ddy = y - py; double dd = Math.sqrt(ddx * ddx + ddy * ddy); estimated_time += dd / feed_rate; estimated_length += dd; ++estimate_count; px = x; py = y; pz = z; } } // for ( each instruction ) estimated_time += estimate_count * 0.007617845117845f; Log( "<font color='green'>" + estimate_count + " line segments.\n" + estimated_length + "cm of line.\n" + "Estimated " + statusBar.formatTime((long) (estimated_time * 10000)) + "s to draw.</font>\n"); }
/** Dynamic Init. Table Layout, Visual, Listener */ private void dynInit() { ColumnInfo[] layout = new ColumnInfo[] { new ColumnInfo(Msg.translate(Env.getCtx(), "M_Product_ID"), ".", KeyNamePair.class), // 1 new ColumnInfo(Msg.translate(Env.getCtx(), "Name"), ".", String.class) // 2 }; xProductTable.prepareTable(layout, "", "", false, ""); xAssociateTable.prepareTable(layout, "", "", true, ""); xAssociateTable.setAutoResizeMode(3); xProductTable.setAutoResizeMode(3); // Visual CompiereColor.setBackground(this); // Listener xProductTable.getSelectionModel().addListSelectionListener(this); xAssociateTable.getModel().addTableModelListener(this); bDisassociate.addActionListener(this); bNewProduct.addActionListener(this); // pregunto si hay productos asociados para ver si cargo las tablas boolean ready = verify(); if (ready == false) { tableInit_option = 0; tableInit(); tableLoad(xProductTable); } else { tableInit_option = 1; tableInit(); tableLoad(xAssociateTable); bNewProduct.setEnabled(false); bDisassociate.setEnabled(true); } xProductTable.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int rowP = xProductTable.getSelectedRow(); if (!(rowP == -1)) { cmd_associate(); } } } }); // Init statusBar.setStatusLine(""); statusBar.setStatusDB(0); MOrder order = new MOrder(Env.getCtx(), LineRefProv.getC_Order_ID(), null); boolean block = false; String oS = order.getXX_OrderStatus(); String compS = order.getDocStatus(); if (oS.equals("AN") || compS.equals("CO")) { block = true; } if (order.isXX_OrderReadyStatus() && order.getXX_OrderType().equalsIgnoreCase("Nacional")) block = true; if (order.getXX_OrderType().equalsIgnoreCase("Importada") && order.get_ValueAsInt("XX_ImportingCompany_ID") != 0) { if (order.get_ValueAsInt("XX_ImportingCompany_ID") != Env.getCtx().getContextAsInt("#XX_L_VSI_CLIENTCENTROBECO_ID")) { block = true; } } if (order.getXX_StoreDistribution().equals("Y") || block) { xProductTable.setEnabled(false); xAssociateTable.setEnabled(false); bNewProduct.setEnabled(false); bDisassociate.setEnabled(false); } } // dynInit