List of usage examples for java.net UnknownHostException printStackTrace
public void printStackTrace()
From source file:com.mobilyzer.util.PhoneUtils.java
public String getWifiIpAddress() { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if (wifiInfo != null) { int ip = wifiInfo.getIpAddress(); if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { ip = Integer.reverseBytes(ip); }/*from w w w . j av a 2s . c o m*/ byte[] bytes = BigInteger.valueOf(ip).toByteArray(); String address; try { address = InetAddress.getByAddress(bytes).getHostAddress(); return address; } catch (UnknownHostException e) { e.printStackTrace(); } } return null; }
From source file:com.thousandthoughts.tutorials.SensorFusionActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*from ww w .j a va 2 s . co m*/ layout = (RelativeLayout) findViewById(R.id.mainlayout); IP1 = ""; IP2 = ""; angle1 = 0.0f; angle2 = 0.0f; gyroOrientation[0] = 0.0f; gyroOrientation[1] = 0.0f; gyroOrientation[2] = 0.0f; // initialise gyroMatrix with identity matrix gyroMatrix[0] = 1.0f; gyroMatrix[1] = 0.0f; gyroMatrix[2] = 0.0f; gyroMatrix[3] = 0.0f; gyroMatrix[4] = 1.0f; gyroMatrix[5] = 0.0f; gyroMatrix[6] = 0.0f; gyroMatrix[7] = 0.0f; gyroMatrix[8] = 1.0f; // get sensorManager and initialise sensor listeners mSensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE); initListeners(); // wait for one second until gyroscope and magnetometer/accelerometer // data is initialised then scedule the complementary filter task fuseTimer.scheduleAtFixedRate(new calculateFusedOrientationTask(), 1000, TIME_CONSTANT); // GUI stuff try { client1 = new MyCoapClient(this.IP1); client2 = new MyCoapClient(this.IP2); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } json = new JSONObject(); mHandler = new Handler(); radioSelection = 0; d.setRoundingMode(RoundingMode.HALF_UP); d.setMaximumFractionDigits(3); d.setMinimumFractionDigits(3); /// Application layout here only RelativeLayout.LayoutParams left = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams right = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams up = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams down = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams button1 = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams button2 = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams text1 = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); RelativeLayout.LayoutParams text2 = new RelativeLayout.LayoutParams( android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT); ImageView img_left = new ImageView(this); ImageView img_right = new ImageView(this); ImageView img_up = new ImageView(this); ImageView img_down = new ImageView(this); ImageView img_button1 = new ImageView(this); ImageView img_button2 = new ImageView(this); final EditText edittext1 = new EditText(this); final EditText edittext2 = new EditText(this); img_left.setImageResource(R.drawable.left_button); img_right.setImageResource(R.drawable.right_button); img_up.setImageResource(R.drawable.up); img_down.setImageResource(R.drawable.down); img_button1.setImageResource(R.drawable.button); img_button2.setImageResource(R.drawable.button); left.setMargins(0, 66, 0, 0); right.setMargins(360, 66, 0, 0); up.setMargins(240, 90, 0, 0); down.setMargins(240, 240, 0, 0); button1.setMargins(440, 800, 0, 0); button2.setMargins(440, 900, 0, 0); text1.setMargins(5, 800, 0, 0); text2.setMargins(5, 900, 0, 0); layout.addView(img_left, left); layout.addView(img_right, right); layout.addView(img_up, up); layout.addView(img_down, down); layout.addView(img_button1, button1); layout.addView(edittext1, text1); layout.addView(img_button2, button2); layout.addView(edittext2, text2); img_left.getLayoutParams().height = 560; img_left.getLayoutParams().width = 280; img_right.getLayoutParams().height = 560; img_right.getLayoutParams().width = 280; img_up.getLayoutParams().height = 150; img_up.getLayoutParams().width = 150; img_down.getLayoutParams().height = 150; img_down.getLayoutParams().width = 150; img_button1.getLayoutParams().height = 100; img_button1.getLayoutParams().width = 200; edittext1.getLayoutParams().width = 400; edittext1.setText("84.248.76.84"); edittext2.setText("84.248.76.84"); img_button2.getLayoutParams().height = 100; img_button2.getLayoutParams().width = 200; edittext2.getLayoutParams().width = 400; /////////// Define and Remember Position for EACH PHYSICAL OBJECTS (LAPTOPS) ///////////////////// img_button1.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // POSITION OF LAPTOP 1 IS REMEMBERED angle1 = fusedOrientation[0]; IP1 = edittext1.getText().toString(); try { // CREATE CLIENT CONNECT TO FIRST LAPTOP client1 = new MyCoapClient(IP1); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: //view.setImageResource(R.drawable.left_button); break; } return true; } }); img_button2.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // POSITION OF LAPTOP 2 IS REMEMBERED angle2 = fusedOrientation[0]; IP2 = edittext2.getText().toString(); try { // CREATE CLIENT CONNECT TO SECOND LAPTOP client2 = new MyCoapClient(IP2); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: break; } return true; } }); img_left.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: view.setImageResource(R.drawable.left_button_press); ///////////////////// PERFORM CLICK ACTION BASED ON POSITION OF 2 PHYSICAL OBJECTS (LAPTOPs) HERE///////////////////////// // PHONE's ANGLE WITHIN FIRST LAPTOP// if (angle1 != 0.0f) { if (angle1 * 180 / Math.PI - 40.0 < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0) { client1.runClient("left pressed"); } } //PHONE's ANGLE WITHIN SECOND LAPTOP// if (angle2 != 0.0f) { if (angle2 * 180 / Math.PI - 40.0 < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0) { client2.runClient("left pressed"); } } break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: view.setImageResource(R.drawable.left_button); // PHONE's ANGLE WITHIN FIRST LAPTOP// if (angle1 != 0.0f) { if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) { client1.runClient("left released"); } } //PHONE's ANGLE WITHIN SECOND LAPTOP// if (angle2 != 0.0f) { if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) { client2.runClient("left released"); } } break; } return true; } }); img_right.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: view.setImageResource(R.drawable.right_button_press); // PHONE's ANGLE WITHIN FIRST LAPTOP// if (angle1 != 0.0f) { if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) { client1.runClient("right pressed"); } } //PHONE's ANGLE WITHIN SECOND LAPTOP// if (angle2 != 0.0f) { if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) { client2.runClient("right pressed"); } } break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: view.setImageResource(R.drawable.right_button); break; } return true; } }); img_up.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: view.setImageResource(R.drawable.up_press); // PHONE's ANGLE WITHIN FIRST LAPTOP// if (angle1 != 0.0f) { if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) { client1.runClient("up pressed"); } } //PHONE's ANGLE WITHIN SECOND LAPTOP// if (angle2 != 0.0f) { if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) { client2.runClient("up pressed"); } } break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: view.setImageResource(R.drawable.up); break; } return true; } }); img_down.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction()) { case MotionEvent.ACTION_DOWN: view.setImageResource(R.drawable.down_press); // PHONE's ANGLE WITHIN FIRST LAPTOP// if (angle1 != 0.0f) { if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) { client1.runClient("down pressed"); } } //PHONE's ANGLE WITHIN SECOND LAPTOP// if (angle2 != 0.0f) { if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) { client2.runClient("down pressed"); } } break; case MotionEvent.ACTION_MOVE: break; case MotionEvent.ACTION_UP: view.setImageResource(R.drawable.down); break; } return true; } }); }
From source file:edu.ku.brc.specify.toycode.RegPivot.java
/** * @param newTblName/*from ww w. j av a2 s . c o m*/ * @param tblName * @param keyName */ private void process(final String newTblName, final String tblName, final String keyName, final String defSQL, final String fillSQL, final boolean isRegBuild) { String sql = String.format("SELECT DISTINCT Name FROM %s", tblName); String sql2 = "SELECT MAX(LENGTH(Value)) FROM " + tblName + " WHERE Name = '%s'"; int instCnt = 0; Statement stmt = null; try { stmt = connection.createStatement(); BasicSQLUtils.setDBConnection(connection); boolean doBuild = true; if (doBuild) { StringBuilder tblSQL = new StringBuilder(String .format("CREATE TABLE %s (`%s` INT(11) NOT NULL AUTO_INCREMENT, \n", newTblName, keyName)); Vector<String> dbFieldNames = new Vector<String>(); Vector<Integer> dbFieldTypes = new Vector<Integer>(); if (defSQL != null) { ResultSet rs = stmt.executeQuery(defSQL); ResultSetMetaData rsmd = rs.getMetaData(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { if (i > 1) tblSQL.append(",\n "); String name = rsmd.getColumnName(i); dbFieldNames.add(rsmd.getColumnName(i)); dbFieldTypes.add(rsmd.getColumnType(i)); switch (rsmd.getColumnType(i)) { case java.sql.Types.INTEGER: tblSQL.append(String.format("`%s` INT(11) DEFAULT NULL", name)); break; case java.sql.Types.VARCHAR: tblSQL.append(String.format("`%s` VARCHAR(%s) DEFAULT NULL", name, 64)); break; case java.sql.Types.TIMESTAMP: tblSQL.append(String.format("`%s` DATETIME DEFAULT NULL", name)); break; default: System.err.println(String.format("No case for %s %d", name, rsmd.getColumnType(i))); break; } } rs.close(); } int secInx = dbFieldNames.size() + 1; System.out.println("secInx: " + secInx + " " + tblSQL.toString()); HashSet<String> nameSet = new HashSet<String>(); int cnt = 0; for (Object nmObj : BasicSQLUtils.querySingleCol(connection, sql)) { String name = nmObj.toString(); if (name.endsWith("ID")) { continue; } name = StringUtils.replace(name, "(", "_"); name = StringUtils.replace(name, ")", "_"); if (nameSet.contains(name)) continue; nameSet.add(name); tblSQL.append(",\n "); if (name.startsWith("num_") || name.startsWith("Usage_")) { tblSQL.append(String.format("`%s` INT(11) DEFAULT NULL", name)); dbFieldNames.add(name); dbFieldTypes.add(java.sql.Types.INTEGER); } else if (name.endsWith("_number")) { tblSQL.append(String.format("`%s` VARCHAR(16) DEFAULT NULL", name)); dbFieldNames.add(name); dbFieldTypes.add(java.sql.Types.VARCHAR); } else { int maxLen = BasicSQLUtils.getCountAsInt(connection, String.format(sql2, name)); tblSQL.append(String.format("`%s` VARCHAR(%s) DEFAULT NULL", name, maxLen + 1)); dbFieldNames.add(name); dbFieldTypes.add(java.sql.Types.VARCHAR); } cnt++; } if (isRegBuild) { tblSQL.append(String.format(",\n`RecordType`INT(11) DEFAULT NULL")); } tblSQL.append(String.format(",\n PRIMARY KEY (`%s`)) ENGINE=InnoDB DEFAULT CHARSET=UTF8", keyName)); System.out.println(tblSQL.toString()); DBMSUserMgr dbMgr = DBMSUserMgr.getInstance(); dbMgr.setConnection(connection); if (dbMgr.doesDBHaveTable(newTblName)) { BasicSQLUtils.update(connection, "DROP TABLE " + newTblName); } BasicSQLUtils.update(connection, tblSQL.toString()); HashMap<Integer, String> inxToName = new HashMap<Integer, String>(); StringBuilder fields = new StringBuilder(); StringBuilder vals = new StringBuilder(); int inx = 0; for (String nm : dbFieldNames) { if (fields.length() > 0) fields.append(","); fields.append(nm); if (vals.length() > 0) vals.append(","); vals.append('?'); inxToName.put(inx, nm); inx++; } if (isRegBuild) { if (fields.length() > 0) fields.append(","); fields.append("RecordType"); if (vals.length() > 0) vals.append(","); vals.append('?'); } String insertSQL = String.format("INSERT INTO %s (%s) VALUES(%s)", newTblName, fields.toString(), vals.toString()); System.out.println(insertSQL); PreparedStatement pStmt = connection.prepareStatement(insertSQL); if (isRegBuild) { fillRegisterTable(newTblName, stmt, pStmt, fillSQL, secInx, dbFieldTypes, dbFieldNames, inxToName); } else { fillTrackTable(newTblName, stmt, pStmt, fillSQL, secInx, dbFieldTypes, dbFieldNames, inxToName); } System.out.println("InstCnt: " + instCnt); pStmt.close(); } boolean doIP = false; if (doIP) { HTTPGetter httpGetter = new HTTPGetter(); sql = "SELECT RegID, IP from reg"; PreparedStatement pStmt = connection.prepareStatement(String .format("UPDATE %s SET lookup=?, Country=?, City=? WHERE %s = ?", newTblName, keyName)); HashMap<String, String> ipHash = new HashMap<String, String>(); HashMap<String, Pair<String, String>> ccHash = new HashMap<String, Pair<String, String>>(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { int regId = rs.getInt(1); String ip = rs.getString(2); String hostName = ipHash.get(ip); String country = null; String city = null; if (hostName == null) { String rvStr = new String( httpGetter.doHTTPRequest("http://api.hostip.info/get_html.php?ip=" + ip)); country = parse(rvStr, "Country:"); city = parse(rvStr, "City:"); System.out.println(rvStr + "[" + country + "][" + city + "]"); try { InetAddress addr = InetAddress.getByName(ip); hostName = addr.getHostName(); ipHash.put(ip, hostName); ccHash.put(ip, new Pair<String, String>(country, city)); } catch (UnknownHostException e) { e.printStackTrace(); } } else { Pair<String, String> p = ccHash.get(ip); if (p != null) { country = p.first; city = p.second; } } pStmt.setString(1, hostName); pStmt.setString(2, country); pStmt.setString(3, city); pStmt.setInt(4, regId); pStmt.executeUpdate(); } pStmt.close(); } stmt.close(); colDBConn.close(); } catch (Exception ex) { ex.printStackTrace(); } System.out.println("Done."); }
From source file:ch.fork.AdHocRailway.ui.AdHocRailway.java
private void setUpLogging() { PropertyConfigurator.configure(ClassLoader.getSystemResource("log4j.properties")); final FileAppender appender = new FileAppender(); appender.setName("MyFileAppender"); appender.setLayout(new PatternLayout("%d [%t] %-5p %c{1} - %m%n")); String localhostname = ""; try {//from www. j av a2 s .co m localhostname = java.net.InetAddress.getLocalHost().getHostName(); } catch (final UnknownHostException e) { e.printStackTrace(); } final String userName = System.getProperty("user.name"); appender.setFile("./logs/" + localhostname + "_" + userName + ".log"); appender.setAppend(true); appender.setThreshold(Level.DEBUG); appender.activateOptions(); Logger.getRootLogger().addAppender(appender); }
From source file:edu.umass.cs.reconfiguration.ActiveReplica.java
private Request getRequest(JSONObject jsonObject) throws RequestParseException, JSONException { long t = System.nanoTime(); if (jsonObject instanceof JSONMessenger.JSONObjectWrapper) try {//from www . j av a 2 s .c o m byte[] bytes = (byte[]) ((JSONMessenger.JSONObjectWrapper) jsonObject).getObj(); Request request = this.appCoordinator.getRequest( Arrays.copyOfRange(bytes, NIOHeader.BYTES, bytes.length), NIOHeader.getNIOHeader(bytes)); instrumentNanoApp(Instrument.getRequest, t); return request; } catch (UnknownHostException e) { e.printStackTrace(); } // else slow path String stringified = STAMP_SENDER_ADDRESS_JSON || !jsonObject.has(MessageExtractor.STRINGIFIED) ? jsonObject.toString() : jsonObject.getString(MessageExtractor.STRINGIFIED); instrumentNano(Instrument.restringification, t); Request request = this.appCoordinator.getRequest(stringified); instrumentNanoApp(Instrument.getRequest, t); return request; }
From source file:com.mitre.holdshort.AlertLogger.java
private void endAlert(Location loc, AlertEndType endType) { currentAlert.setStopTime(System.currentTimeMillis()); currentAlert.setStopLatLon(String.valueOf(loc.getLatitude()), String.valueOf(loc.getLongitude())); currentAlert.setStopHeading(loc.getBearing()); currentAlert.setStopSpeed((float) (loc.getSpeed() * MainActivity.MS_TO_KNOTS)); currentAlert.setStopAltitude(loc.getAltitude() * MainActivity.M_TO_FEET); currentAlert.setEndType(endType);//from w ww . j a v a 2s . c om try { alertFTPClient.connect(this.ftpHost, 21); if (alertFTPClient.login(this.ftpUser, this.ftpPassword)) { alertFTPClient.enterLocalPassiveMode(); writeDataToFtpServer(currentAlert); currentAlert = null; } } catch (UnknownHostException e) { System.err.println("No Connection For FTP Client"); // No write that stuff to oldAlerts.dat File oldAlerts = new File(ctx.getFilesDir() + "/oldAlerts.dat"); FileWriter logWriter = null; try { logWriter = new FileWriter(oldAlerts, true); BufferedWriter outer = new BufferedWriter(logWriter); outer.append(currentAlert.getAlertString()); outer.newLine(); outer.close(); System.out.println(String.valueOf(oldAlerts.length())); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { System.err.println("No Connection For FTP Client"); // No write that stuff to oldAlerts.dat File oldAlerts = new File(ctx.getFilesDir() + "/oldAlerts.dat"); FileWriter logWriter = null; try { logWriter = new FileWriter(oldAlerts, true); BufferedWriter outer = new BufferedWriter(logWriter); outer.append(currentAlert.getAlertString()); outer.newLine(); outer.close(); System.out.println(String.valueOf(oldAlerts.length())); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }
From source file:org.squidy.nodes.Tracking.java
/** * //from ww w . ja v a2 s . com */ private void startMulticastServer() throws ProcessException { InetAddress multicastGroup; try { multicastGroup = InetAddress.getByName(multicastGroupAddress); } catch (UnknownHostException e) { throw new ProcessException(e.getMessage(), e); } server = new MulticastServer(multicastGroup, port); server.addMulticastListener(new MulticastAdapter() { /* (non-Javadoc) * @see org.squidy.manager.protocol.udp.UDPListener#parseData(byte[]) */ public void parseData(byte[] data) { // TODO [SF]: Do your parsing stuff here!!! ByteArrayInputStream bais = new ByteArrayInputStream(data); DataInputStream instream = new DataInputStream(bais); try { System.out.println("short: " + instream.readUnsignedShort() + " | " + instream.readUnsignedShort() + " | " + (instream.readInt() & 0x7F)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // // String s = new String(data); // System.out.println(s); /* * Data is coded with a started MessageID = 7 lastFrameCounter = <FrameId>; if (<singleMarker == true>){ trackedBodies = <numTrackedSingleMarker>; bodyId = 0; //Read x,y,z and convert to mm x = <x>*100; y = <y>*100; z = <z>*100; publish(new DataPosition3D(Tracking.class, bodyID, x, y, z, width, height, depth, lastFrameCounter, trackedBodies)); // only publish single marker positions, not the ones belonging to a rigit body } if (<rigitBody == true>){ trackedBodies = <numTrackedRigitBodies>; bodyId = <rigitBodyId>; //Read x,y,z and convert to mm x = <x>*100; y = <y>*100; z = <z>*100; //Read quatrions qx = <qx>; qy = <qy>; qz = <qz>; qw = <qw>; //Transform to rotation matrix //Spalte 1: rxx = 2*(qx*qx + qw*qw)-1; ryx = 2*(qx*qy + qz*qw); rzx = 2*(qx*qz - qy*qw); Spalte 2: rxy = 2*(qx*qy - qz*qw); ryy = 2*(qy*qy + qq*qw)-1; rzy = 2*(qy*qz + qx*qw); Spalte 3: rxz = 2*(qx*qz + qy*qw); ryz = 2*(qy*qz - qx*qw); rzz = 2*(qz*qz + qw*qw)-1; //quadToMatrix: ? //m[0] = 1-2*q[1]*q[1]-2*q[2]*q[2]; m[1] = 2*q[0]*q[1]-2*q[3]*q[2]; m[2] = 2*q[0]*q[2]+2*q[3]*q[1]; //m[3] = 2*q[0]*q[1]+2*q[3]*q[2]; m[4] = 1-2*q[0]*q[0]-2*q[2]*q[2]; m[5] = 2*q[1]*q[2]-2*q[3]*q[0]; //m[6] = 2*q[0]*q[2]-2*q[3]*q[1]; m[7] = 2*q[1]*q[2]+2*q[3]*q[0]; m[8] = 1-2*q[0]*q[0]-2*q[1]*q[1]; publish(new DataPosition6D(arTracking.getClass(), bodyID, x, y, z, width, height, depth, rxx, ryx, rzx, rxy, ryy, rzy, rxz, ryz, rzz, lastFrameCounter, trackedBodies)); } */ // // ... } }); }
From source file:ui.FtpDialog.java
private void loginBtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginBtActionPerformed String host = hostAddressField.getText(); int port = (int) portNumberSp.getValue(); String user = userNameField.getText(); char[] password = passField.getPassword(); String pass = new String(password); String hostIP = null;/*from ww w .j av a2 s . co m*/ Trace.connectionFtp = true; InetAddress address = null; if (!connected) { try { address = InetAddress.getByName(host); ; hostIP = StringUtils.substringAfter(address.toString(), "/"); if (hostIP == null || hostIP.equals("127.0.0.1")) { JOptionPane.showMessageDialog(rootFrame, "Host name not set", "Error", JOptionPane.ERROR_MESSAGE); return; } if (port == 0) { JOptionPane.showMessageDialog(rootFrame, "Invalid port number", "Error", JOptionPane.ERROR_MESSAGE); } if (Trace.connectionFtp) { Trace.trc("Host IP address: " + hostIP); } } catch (UnknownHostException e) { JOptionPane.showMessageDialog(rootFrame, "Cannot resolve host address", "Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } try { if (address != null && port != 0 && user != null && pass != null) { connected = ftpHandler.doConnect(hostIP, port, user, pass); Arrays.fill(password, '0'); if (!connected) { JOptionPane.showMessageDialog(rootFrame, "Problem iniating connection to the FTP server, please check your login credentials", "Error", JOptionPane.ERROR_MESSAGE); return; } } } catch (IOException e) { e.printStackTrace(); } if (connected) { try { if (Trace.connectionFtp) { Trace.trc("Attempting to list the remote directory..."); } String dirList = ftpHandler.list(); lastKnownDir = ftpHandler.pwd(); outputTextArea.setText(dirList); remoteSiteText.setText(ftpHandler.pwd()); } catch (IOException e) { e.printStackTrace(); } } } else { JOptionPane.showMessageDialog(rootFrame, "Already connected to a FTP server, cannot reconnect!", "Error", JOptionPane.ERROR_MESSAGE); } }
From source file:edu.umich.robot.GuiApplication.java
/** * Entry point.//ww w . ja v a2s . c o m * * @param args Args from command line. */ public GuiApplication(Config config) { // Heavyweight is not desirable but it is the only thing that will // render in front of the Viewer on all platforms. Blame OpenGL JPopupMenu.setDefaultLightWeightPopupEnabled(false); ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false); // must have config //Config config = (args.length > 0) ? ConfigUtil.getDefaultConfig(args) : promptForConfig(frame); if (config == null) System.exit(1); // Add more stuff to the config file that doesn't change between runs. Application.setupSimulatorConfig(config); setupViewerConfig(config); Configs.toLog(logger, config); controller = new Controller(config, new Gamepad()); controller.initializeGamepad(); viewer = new Viewer(config, frame); // This puts us in full 3d mode by default. The Viewer GUI doesn't // reflect this in its right click drop-down, a bug. viewer.getVisCanvas().getViewManager().setInterfaceMode(3); controller.addListener(RobotAddedEvent.class, listener); controller.addListener(RobotRemovedEvent.class, listener); controller.addListener(AfterResetEvent.class, listener); controller.addListener(ControllerActivatedEvent.class, listener); controller.addListener(ControllerDeactivatedEvent.class, listener); actionManager = new ActionManager(this); initActions(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { controller.shutdown(); System.exit(0); } }); frame.setLayout(new BorderLayout()); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.add(actionManager.getAction(CreateSplinterRobotAction.class)); fileMenu.add(actionManager.getAction(CreateSuperdroidRobotAction.class)); fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(ConnectSuperdroidAction.class)); fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(ResetPreferencesAction.class)); /* fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(TextMessageAction.class)); */ fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(SaveMapAction.class)); fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(ExitAction.class)); menuBar.add(fileMenu); JMenu cameraMenu = new JMenu("Camera"); cameraMenu.add(actionManager.getAction(DisableFollowAction.class)); cameraMenu.add(actionManager.getAction(FollowPositionAction.class)); cameraMenu.add(actionManager.getAction(FollowPositionAndThetaAction.class)); cameraMenu.add(new JSeparator()); cameraMenu.add(actionManager.getAction(MoveCameraBehindAction.class)); cameraMenu.add(actionManager.getAction(MoveCameraAboveAction.class)); menuBar.add(cameraMenu); JMenu objectMenu = new JMenu("Objects"); boolean added = false; for (String objectName : controller.getObjectNames()) { added = true; objectMenu.add(new AddObjectAction(this, objectName)); } if (!added) objectMenu.add(new JLabel("No objects available")); menuBar.add(objectMenu); menuBar.revalidate(); frame.setJMenuBar(menuBar); JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false); toolBar.setRollover(true); toolBar.add(actionManager.getAction(SoarParametersAction.class)); toolBar.add(actionManager.getAction(SoarDataAction.class)); toolBar.add(actionManager.getAction(ResetAction.class)); toolBar.add(actionManager.getAction(SoarToggleAction.class)); toolBar.add(actionManager.getAction(SoarStepAction.class)); toolBar.add(actionManager.getAction(SimSpeedAction.class)); frame.add(toolBar, BorderLayout.PAGE_START); viewerView = new ViewerView(viewer.getVisCanvas()); robotsView = new RobotsView(this, actionManager); final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, viewerView, robotsView); splitPane.setDividerLocation(0.75); // TODO SoarApril /* viewer.addRobotSelectionChangedListener(robotsView); viewer.getVisCanvas().setDrawGround(true); */ viewer.getVisCanvas().addEventHandler(new VisCanvasEventAdapter() { public String getName() { return "Place Object"; } @Override public boolean mouseClicked(VisCanvas vc, GRay3D ray, MouseEvent e) { boolean ret = false; synchronized (GuiApplication.this) { if (objectToAdd != null && controller != null) { controller.addObject(objectToAdd, ray.intersectPlaneXY()); objectToAdd = null; ret = true; } else { double[] click = ray.intersectPlaneXY(); chatView.setClick(new Point2D.Double(click[0], click[1])); } } status.setMessage( String.format("%3.1f,%3.1f", ray.intersectPlaneXY()[0], ray.intersectPlaneXY()[1])); return ret; } }); consoleView = new ConsoleView(); chatView = new ChatView(this); controller.getRadio().addRadioHandler(chatView); final JSplitPane bottomPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, consoleView, chatView); bottomPane.setDividerLocation(200); final JSplitPane splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, splitPane, bottomPane); splitPane2.setDividerLocation(0.75); frame.add(splitPane2, BorderLayout.CENTER); status = new StatusBar(); frame.add(status, BorderLayout.SOUTH); /* frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { final Preferences windowPrefs = getWindowPreferences(); final Rectangle r = frame.getBounds(); if(frame.getExtendedState() == JFrame.NORMAL) { windowPrefs.putInt("x", r.x); windowPrefs.putInt("y", r.y); windowPrefs.putInt("width", r.width); windowPrefs.putInt("height", r.height); windowPrefs.putInt("divider", splitPane.getDividerLocation()); } exit(); }}); Preferences windowPrefs = getWindowPreferences(); if (windowPrefs.get("x", null) != null) { frame.setBounds( windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0), windowPrefs.getInt("width", 1200), windowPrefs.getInt("height", 900)); splitPane.setDividerLocation(windowPrefs.getInt("divider", 500)); } else { frame.setBounds( windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0), windowPrefs.getInt("width", 1200), windowPrefs.getInt("height", 900)); splitPane.setDividerLocation(0.75); frame.setLocationRelativeTo(null); // center } */ frame.getRootPane().setBounds(0, 0, 1600, 1200); frame.getRootPane().registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.dispose(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); frame.pack(); frame.setVisible(true); for (String s : config.getStrings("splinters", new String[0])) { double[] pos = config.getDoubles(s + ".position"); if (pos == null) { logger.error("Splinter indexed in config file but no position defined: " + s); continue; } Pose pose = new Pose(pos); String prods = config.getString(s + ".productions"); boolean collisions = config.getBoolean(s + ".wallCollisions", true); controller.createSplinterRobot(s, pose, collisions); boolean simulated = config.getBoolean(s + ".simulated", true); if (simulated) controller.createSimSplinter(s); else controller.createRealSplinter(s); controller.createSimLaser(s); if (prods != null) { controller.createSoarController(s, s, prods, config.getChild(s + ".properties")); PREFERENCES.put("lastProductions", prods); } } for (String s : config.getStrings("superdroids", new String[0])) { double[] pos = config.getDoubles(s + ".position"); if (pos == null) { logger.error("Superdroid indexed in config file but no position defined: " + s); continue; } Pose pose = new Pose(pos); String prods = config.getString(s + ".productions"); boolean collisions = config.getBoolean(s + ".wallCollisions", true); controller.createSuperdroidRobot(s, pose, collisions); boolean simulated = config.getBoolean(s + ".simulated", true); if (simulated) controller.createSimSuperdroid(s); else { try { controller.createRealSuperdroid(s, "192.168.1.165", 3192); } catch (UnknownHostException e1) { e1.printStackTrace(); } catch (SocketException e1) { e1.printStackTrace(); } } controller.createSimLaser(s); if (prods != null) { // wait a sec try { Thread.sleep(1000); } catch (InterruptedException ex) { } controller.createSoarController(s, s, prods, config.getChild(s + ".properties")); PREFERENCES.put("lastProductions", prods); } } }
From source file:com.sonyericsson.jenkins.plugins.bfa.db.MongoDBKnowledgeBase.java
@Override public List<FailureCauseTimeInterval> getFailureCausesPerTime(int intervalSize, GraphFilterBuilder filter, boolean byCategories) { List<FailureCauseTimeInterval> failureCauseIntervals = new ArrayList<FailureCauseTimeInterval>(); Map<MultiKey, FailureCauseTimeInterval> categoryTable = new HashMap<MultiKey, FailureCauseTimeInterval>(); DBObject matchFields = generateMatchFields(filter); DBObject match = new BasicDBObject("$match", matchFields); DBObject unwind = new BasicDBObject("$unwind", "$failureCauses"); DBObject idFields = generateTimeGrouping(intervalSize); idFields.put("failureCause", "$failureCauses.failureCause"); DBObject groupFields = new BasicDBObject(); groupFields.put("_id", idFields); groupFields.put("number", new BasicDBObject("$sum", 1)); DBObject group = new BasicDBObject("$group", groupFields); AggregationOutput output;/*from ww w. jav a2 s . com*/ try { output = getStatisticsCollection().aggregate(match, unwind, group); for (DBObject result : output.results()) { int number = (Integer) result.get("number"); TimePeriod period = generateTimePeriodFromResult(result, intervalSize); BasicDBObject groupedAttrs = (BasicDBObject) result.get("_id"); DBRef failureRef = (DBRef) groupedAttrs.get("failureCause"); String id = failureRef.getId().toString(); FailureCause failureCause = getCause(id); if (byCategories) { if (failureCause.getCategories() != null) { for (String category : failureCause.getCategories()) { MultiKey multiKey = new MultiKey(category, period); FailureCauseTimeInterval interval = categoryTable.get(multiKey); if (interval == null) { interval = new FailureCauseTimeInterval(period, category, number); categoryTable.put(multiKey, interval); failureCauseIntervals.add(interval); } else { interval.addNumber(number); } } } } else { FailureCauseTimeInterval timeInterval = new FailureCauseTimeInterval(period, failureCause.getName(), failureCause.getId(), number); failureCauseIntervals.add(timeInterval); } } } catch (UnknownHostException e) { logger.fine("Unable to get failure causes by time"); e.printStackTrace(); } catch (AuthenticationException e) { logger.fine("Unable to get failure causes by time"); e.printStackTrace(); } return failureCauseIntervals; }