// --------------------------------actionConnect------------------------------ private void actionConnect() { if (oParty == null) { JOptionPane.showMessageDialog(frame, "Make a party before trying to connect."); return; } String[] oResults = (String[]) DialogManager.show(DialogManager.CONNECT, frame); if (oResults[DialogManager.RETURN_IP].equals("cancel")) return; lblStatus3.setText("Connecting..."); try { oConn.connect( oResults[DialogManager.RETURN_IP], Integer.parseInt(oResults[DialogManager.RETURN_PORT])); } catch (UnknownHostException e) { JOptionPane.showMessageDialog( frame, "The IP of the host cannot be determined.", "Unknown Host Exception", JOptionPane.ERROR_MESSAGE); frame.repaint(); return; } catch (IOException e) { JOptionPane.showMessageDialog( frame, e.getMessage(), "Input/Output Exception", JOptionPane.ERROR_MESSAGE); frame.repaint(); return; } echo("Connected to opponent!"); tConn = new Thread(oConn, "conn"); tConn.start(); tMain = new Thread(this, "main"); tMain.start(); }
// --------------------------------actionHost--------------------------------- private void actionHost() { if (oParty == null) { JOptionPane.showMessageDialog(frame, "Make a party before trying to connect."); return; } JFileChooser oFC = new JFileChooser(DEFAULT_MAP_DIRECTORY); int nReturn = oFC.showOpenDialog(frame); if (nReturn == JFileChooser.CANCEL_OPTION) { return; } int nPort = Integer.parseInt((String) (DialogManager.show(DialogManager.HOST, frame))); JDialog dlgBox = (JDialog) (DialogManager.show(DialogManager.WAITING_FOR_CONN, frame)); dlgBox.pack(); try { oConn.host(nPort); } catch (IOException e) { JOptionPane.showMessageDialog(frame, e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE); frame.repaint(); return; } dlgBox.setVisible(false); echo("Connected to opponent!"); tConn = new Thread(oConn, "conn"); tConn.start(); tMain = new Thread(this, "main"); tMain.start(); try { oMap.loadMap(oFC.getSelectedFile()); oConn.send("loadmap", oFC.getName(oFC.getSelectedFile())); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } }
public void setupDialogHandlers(DialogManager dialogManager) { dialogManager.registerHandler( ADD_RELATED_RECIPE_DIALOG, new DialogHandler() { public Dialog createDialog(Bundle bundle) { return new RelatedRecipeDialog(context, recipe, RelatedRecipeListWidget.this); } public void prepareDialog(Dialog d, Bundle bundle) { ((RelatedRecipeDialog) d).prepareNew(); } }); dialogManager.registerHandler( REMOVE_RELATED_RECIPE_DIALOG, new DialogHandler() { public Dialog createDialog(Bundle bundle) { return new RelatedRecipeDialog(context, recipe, RelatedRecipeListWidget.this); } public void prepareDialog(Dialog d, Bundle bundle) { long rid = bundle.getLong("id", -1); ((RelatedRecipeDialog) d).prepareDelete(util.getRecipeById(rid)); } }); }
public void eventDispatched(AWTEvent event) { if (!isAssertTrigger(event)) { return; } MouseEvent mouse = (MouseEvent) event; GuiComponent guiComponent = factory.find(mouse); if (guiComponent == null) { return; } assertContext.setGuiComponent(guiComponent); assertContext.setPoint(mouse.getPoint()); JPopupMenu menu = dialogManager.newPopupMenu(); for (Iterator iterator = actionManager.actions(); iterator.hasNext(); ) { AbstractAssert assertAction = (AbstractAssert) iterator.next(); String actionId = (String) assertAction.getValue(AbstractAssert.ACTION_ID); ActionViewUtil.connectActionTo(assertAction, menu.add(actionId)); assertAction.update(); if (!guiComponent.isFindable() && AbstractAssert.COMPONENT_ASSERT == assertAction.getAssertType()) { assertAction.setEnabled(false); } } menu.setBorder(BorderFactory.createLineBorder(Color.blue, 5)); menu.show(guiComponent.getSwingComponent(), mouse.getX(), mouse.getY()); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test_gcm); cd = new ConnectionDetector(getApplicationContext()); // Check if Internet present if (!cd.isConnectingToInternet()) { // Internet Connection is not present alert.showDialog( TestGCMActivity.this, "Internet Connection Error", "Please connect to working Internet connection", false); // stop executing code by return return; } // Getting name, email from intent Intent i = getIntent(); name = i.getStringExtra("name"); email = i.getStringExtra("email"); GCMRegistrar.checkDevice(this); // GCMRegistrar.checkManifest(this); // lblMessage = (TextView) findViewById(R.id.lblMessage); registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION)); // Get GCM registration id final String regId = GCMRegistrar.getRegistrationId(this); // Check if regid already presents if (regId.equals("")) { // Registration is not present, register now with GCM GCMRegistrar.register(this, SENDER_ID); } else { // Device is already registered on GCM if (GCMRegistrar.isRegisteredOnServer(this)) { // Skips registration. Toast.makeText(getApplicationContext(), "Already registered with GCM", Toast.LENGTH_LONG) .show(); } else { // Try to register again, but not in the UI thread. // It's also necessary to cancel the thread onDestroy(), // hence the use of AsyncTask instead of a raw thread. final Context context = this; mRegisterTask = new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { // Register on our server // On server creates a new user ServerUtilities.register(context, name, email, regId); return null; } @Override protected void onPostExecute(Void result) { mRegisterTask = null; } }; mRegisterTask.execute(null, null, null); } } }
@Override public void endEvent() { DialogManager.endDialog(); }
@Override public void progressEvent() { DialogManager.progressDialog(); }