protected final void fireActionEvent(String command) {

    ActionEvent event = new ActionEvent(this, 0, command);

    for (ActionListener listener : listeners) {
      listener.actionPerformed(event);
    }
  }
	/**
	 * Executes the specified action, repeating and recording it as
	 * necessary.
	 * @param listener The action listener
	 * @param source The event source
	 * @param actionCommand The action command
	 */
	public void executeAction(ActionListener listener, Object source,
		String actionCommand)
	{
		// create event
		ActionEvent evt = new ActionEvent(source,
			ActionEvent.ACTION_PERFORMED,
			actionCommand);

		// don't do anything if the action is a wrapper
		// (like EditAction.Wrapper)
		if(listener instanceof Wrapper)
		{
			listener.actionPerformed(evt);
			return;
		}

		// remember old values, in case action changes them
		boolean _repeat = repeat;
		int _repeatCount = getRepeatCount();

		// execute the action
		if(listener instanceof InputHandler.NonRepeatable)
			listener.actionPerformed(evt);
		else
		{
			for(int i = 0; i < Math.max(1,repeatCount); i++)
				listener.actionPerformed(evt);
		}

		// do recording. Notice that we do no recording whatsoever
		// for actions that grab keys
		if(grabAction == null)
		{
			if(recorder != null)
			{
				if(!(listener instanceof InputHandler.NonRecordable))
				{
					if(_repeatCount != 1)
						recorder.actionPerformed(REPEAT,String.valueOf(_repeatCount));

					recorder.actionPerformed(listener,actionCommand);
				}
			}

			// If repeat was true originally, clear it
			// Otherwise it might have been set by the action, etc
			if(_repeat)
			{
				repeat = false;
				repeatCount = 0;
			}
		}
	}
 /**
  * ** Invokes all listeners with an assciated command ** @param r a string that may specify a
  * command (possibly one ** of several) associated with the event
  */
 protected void invokeListeners(String r) {
   if (this.actionListeners != null) {
     for (Iterator i = this.actionListeners.iterator(); i.hasNext(); ) {
       ActionListener al = (ActionListener) i.next();
       ActionEvent ae = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, r);
       try {
         al.actionPerformed(ae);
       } catch (Throwable t) {
         Print.logError("Exception: " + t.getMessage());
       }
     }
   }
 }
Exemple #4
0
  @Override
  public void mouseDragged(final MouseEvent e) {
    final double prop = (max - min) * (mouseX - e.getX()) / (getWidth() - SLIDERW);

    final int old = value;
    value = Math.max(min, Math.min(max, (int) (oldValue - prop)));

    if (value != old) {
      if (dialog != null) dialog.action(null);
      for (final ActionListener al : listenerList.getListeners(ActionListener.class)) {
        al.actionPerformed(null);
      }
      repaint();
    }
  }
Exemple #5
0
  public void _sendString(String text) {
    if (writeCommand == null) return;

    /* intercept sessions -i and deliver it to a listener within armitage */
    if (sessionListener != null) {
      Matcher m = interact.matcher(text);
      if (m.matches()) {
        sessionListener.actionPerformed(new ActionEvent(this, 0, m.group(1)));
        return;
      }
    }

    Map read = null;

    try {
      synchronized (this) {
        if (window != null && echo) {
          window.append(window.getPromptText() + text);
        }
      }

      if ("armitage.push".equals(writeCommand)) {
        read = (Map) connection.execute(writeCommand, new Object[] {session, text});
      } else {
        connection.execute(writeCommand, new Object[] {session, text});
        read = readResponse();
      }
      processRead(read);

      fireSessionWroteEvent(text);
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
 void performOnPrimary(
     int primaryShardId,
     boolean fromDiscoveryListener,
     final ShardRouting shard,
     ClusterState clusterState) {
   try {
     PrimaryResponse<Response, ReplicaRequest> response =
         shardOperationOnPrimary(
             clusterState, new PrimaryOperationRequest(primaryShardId, request));
     performReplicas(response);
   } catch (Exception e) {
     // shard has not been allocated yet, retry it here
     if (retryPrimaryException(e)) {
       primaryOperationStarted.set(false);
       retry(fromDiscoveryListener, null);
       return;
     }
     if (e instanceof ElasticSearchException
         && ((ElasticSearchException) e).status() == RestStatus.CONFLICT) {
       if (logger.isTraceEnabled()) {
         logger.trace(shard.shortSummary() + ": Failed to execute [" + request + "]", e);
       }
     } else {
       if (logger.isDebugEnabled()) {
         logger.debug(shard.shortSummary() + ": Failed to execute [" + request + "]", e);
       }
     }
     listener.onFailure(e);
   }
 }
Exemple #7
0
  private void invokeAnalogsAndActions(int hash, float value, boolean applyTpf) {
    if (value < axisDeadZone) {
      invokeAnalogs(hash, value, !applyTpf);
      return;
    }

    ArrayList<Mapping> maps = bindings.get(hash);
    if (maps == null) {
      return;
    }

    boolean valueChanged = !axisValues.containsKey(hash);
    if (applyTpf) {
      value *= frameTPF;
    }

    int size = maps.size();
    for (int i = size - 1; i >= 0; i--) {
      Mapping mapping = maps.get(i);
      ArrayList<InputListener> listeners = mapping.listeners;
      int listenerSize = listeners.size();
      for (int j = listenerSize - 1; j >= 0; j--) {
        InputListener listener = listeners.get(j);

        if (listener instanceof ActionListener && valueChanged) {
          ((ActionListener) listener).onAction(mapping.name, true, frameTPF);
        }

        if (listener instanceof AnalogListener) {
          ((AnalogListener) listener).onAnalog(mapping.name, value, frameTPF);
        }
      }
    }
  }
Exemple #8
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mTracker = AnalyticsTrackers.getInstance().get(AnalyticsTrackers.Target.APP);
    // Load an ad into the AdMob banner view.
    AdView adView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest =
        new AdRequest.Builder().setRequestAgent("android_studio:ad_template").build();
    adView.loadAd(adRequest);

    // Toasts the test ad message on the screen. Remove this after defining your own ad unit ID.
    Toast.makeText(this, TOAST_TEXT, Toast.LENGTH_LONG).show();
    mText = (EditText) findViewById(R.id.partno);
    mStart = findViewById(R.id.imageView1);

    mText.setOnEditorActionListener(ActionListener.newInstance(this));
    mStart.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            if (!TextUtils.isEmpty(mText.getText())) {
              String s = mText.getText().toString();
              Intent i = new Intent(getBaseContext(), Game.class);
              i.putExtra("number", s);
              startActivity(i);
              finish();
            } else {
              Toast.makeText(MainActivity.this, TOAST_TEXT, Toast.LENGTH_LONG).show();
            }
          }
        });
  }
  /** Removes the navigational data from another NavigatorView. */
  public void remove(NavigatorView view) {
    debug("removing " + view);

    // redo the search if necessary
    if (searchparams.getText() != null) {
      searchAction.actionPerformed(new ActionEvent(searchparams, ActionEvent.ACTION_PERFORMED, ""));
    }
  }
 @Override
 public void executeAction(String command, String value, String valueParameter)
     throws NotValidValueException {
   if (isValidValue(value)) {
     T extractedValue = convertValue(value);
     listener.onAction(new ActionEvent(value, extractedValue, valueParameter));
   }
 }
 protected void onCompletion() {
   Response response = null;
   try {
     response =
         newResponse(request, responses, unavailableShardExceptions, nodeIds, clusterState);
   } catch (Throwable t) {
     logger.debug("failed to combine responses from nodes", t);
     listener.onFailure(t);
   }
   if (response != null) {
     try {
       listener.onResponse(response);
     } catch (Throwable t) {
       listener.onFailure(t);
     }
   }
 }
  /** @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) */
  public void mouseClicked(final MouseEvent e) {
    hasBeenClicked = true;

    // If the action is not null, perform the action
    if (action != null) {
      action.actionPerformed(new ActionEvent(this, 0, getText()));
    }
  }
  /** Merges in the navigational data from another NavigatorView. */
  public void merge(NavigatorView view) {
    debug("merging " + view);

    // redo the search if necessary
    String text = searchparams.getText();
    if (text != null && text.length() != 0) {
      searchAction.actionPerformed(new ActionEvent(searchparams, ActionEvent.ACTION_PERFORMED, ""));
    }
  }
Exemple #14
0
 public void setStartAddress(int addr) {
   if (addr < 0) return;
   int endAddress = addr + fullRows() * 16 - 1;
   if (endAddress > SICXE.MAX_ADDR + 15 && addr > startAddress) return;
   int diff = addr - startAddress;
   startAddress = addr;
   cursorAddress += diff;
   repaint();
   if (onAddressChange != null) onAddressChange.actionPerformed(null);
 }
 @Override
 public <
         Request extends ActionRequest,
         Response extends ActionResponse,
         RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder, Client>>
     void execute(
         Action<Request, Response, RequestBuilder, Client> action,
         Request request,
         ActionListener<Response> listener) {
   listener.onResponse(null);
 }
Exemple #16
0
 public void setCursorAddress(int addr) {
   if (addr < 0 || addr > SICXE.MAX_ADDR) return;
   if (addr < startAddress) moveStartAddress(-1);
   if (addr > getEndAddress()) moveStartAddress(1);
   cursorAddress = addr;
   repaint();
   // if cursor was hidden due to window resize
   int col = cursorAddress % 16;
   if (cursorAddress > getEndAddress()) cursorAddress = getEndAddress() - 15 + col;
   if (onAddressChange != null) onAddressChange.actionPerformed(null);
 }
Exemple #17
0
 @Override
 public void keyPressed(final KeyEvent e) {
   final int old = value;
   if (PREVCHAR.is(e) || PREVLINE.is(e)) {
     value = Math.max(min, value - 1);
   } else if (NEXTCHAR.is(e) || NEXTLINE.is(e)) {
     value = Math.min(max, value + 1);
   } else if (NEXTPAGE.is(e)) {
     value = Math.max(min, value + 10);
   } else if (PREVPAGE.is(e)) {
     value = Math.min(max, value - 10);
   } else if (LINESTART.is(e)) {
     value = min;
   } else if (LINEEND.is(e)) {
     value = max;
   }
   if (value != old) {
     if (dialog != null) dialog.action(null);
     for (final ActionListener al : listenerList.getListeners(ActionListener.class)) {
       al.actionPerformed(null);
     }
     repaint();
   }
 }
 public void start() {
   if (nodeIds.size() == 0) {
     try {
       onCompletion();
     } catch (Throwable e) {
       listener.onFailure(e);
     }
   } else {
     int nodeIndex = -1;
     for (Map.Entry<String, List<ShardRouting>> entry : nodeIds.entrySet()) {
       nodeIndex++;
       DiscoveryNode node = nodes.get(entry.getKey());
       sendNodeRequest(node, entry.getValue(), nodeIndex);
     }
   }
 }
Exemple #19
0
 public void run() {
   while (true) {
     try {
       sleep(m_fast ? 30 : m_delay);
     } catch (Exception e) {
     }
     if (m_paused) {
       try {
         synchronized (this) {
           this.wait();
         }
       } catch (InterruptedException ie) {
       }
     }
     synchronized (this) {
       m_cb.actionPerformed(null);
     }
   }
 }
Exemple #20
0
  private void invokeActions(int hash, boolean pressed) {
    ArrayList<Mapping> maps = bindings.get(hash);
    if (maps == null) {
      return;
    }

    int size = maps.size();
    for (int i = size - 1; i >= 0; i--) {
      Mapping mapping = maps.get(i);
      ArrayList<InputListener> listeners = mapping.listeners;
      int listenerSize = listeners.size();
      for (int j = listenerSize - 1; j >= 0; j--) {
        InputListener listener = listeners.get(j);
        if (listener instanceof ActionListener) {
          ((ActionListener) listener).onAction(mapping.name, pressed, frameTPF);
        }
      }
    }
  }
  public void mouseReleased(MouseEvent e) {
    if (mMouseOverButton && mPressedButton != -1) {
      boolean needsUpdate = false;
      if (mColorListMode == VisualizationColor.cColorListModeCategories) {
        Color newColor =
            JColorChooser.showDialog(
                mOwner, "Select category color", mCategoryColorList[mPressedButton]);
        if (newColor != null) {
          mCategoryColorList[mPressedButton] = newColor;
          needsUpdate = true;
        }
      } else {
        if (mPressedButton == cColorWedgeButton) {
          if (++mColorListMode > VisualizationColor.cColorListModeStraight)
            mColorListMode = VisualizationColor.cColorListModeHSBShort;
          updateColorList(-1);
          needsUpdate = true;
        } else {
          int index = mPressedButton * (mWedgeColorList.length - 1);
          Color newColor =
              JColorChooser.showDialog(
                  mOwner, "Select color for min/max value", mWedgeColorList[index]);
          if (newColor != null) {
            mWedgeColorList[index] = newColor;
            updateColorList(-1);
            needsUpdate = true;
          }
        }
      }

      mPressedButton = -1;
      mMouseOverButton = false;

      if (needsUpdate) {
        mListener.actionPerformed(
            new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "colorChanged"));
        repaint();
      }
    }
  }
  public void execute(
      DiscoveryNode node, final Request request, final ActionListener<Response> listener) {
    ActionRequestValidationException validationException = request.validate();
    if (validationException != null) {
      listener.onFailure(validationException);
      return;
    }
    transportService.sendRequest(
        node,
        action.name(),
        request,
        transportOptions,
        new BaseTransportResponseHandler<Response>() {
          @Override
          public Response newInstance() {
            return action.newResponse();
          }

          @Override
          public String executor() {
            if (request.listenerThreaded()) {
              return ThreadPool.Names.GENERIC;
            }
            return ThreadPool.Names.SAME;
          }

          @Override
          public void handleResponse(Response response) {
            listener.onResponse(response);
          }

          @Override
          public void handleException(TransportException exp) {
            listener.onFailure(exp);
          }
        });
  }
Exemple #23
0
 /** Mouse action event handler. */
 protected void processActionEvent(ActionEvent e) {
   if (isEnabled() && actionListener != null && e != null) {
     actionListener.actionPerformed(e);
   }
 }
 private void signalAll(ActionEvent e) {
   for (ActionListener a : listeners) {
     a.actionPerformed(e);
   }
 }
 private void fireActionEvent(ActionEvent evt) {
   for (ActionListener l : actionListeners) {
     l.actionPerformed(evt);
   }
 }
 private void processEvent(ActionEvent e) {
   // Hieronder gebruiken we het nieuwe Java "foreach" statement.
   // Lees het als: "for each ActionListener in actionListenerList do ..."
   // Je kunt ook een for-lus of een iterator gebruiken, maar foreach is het elegantste.
   for (ActionListener l : inputListenerList) l.actionPerformed(e);
 }
 /**
  * Processes action events occurring on this text field by dispatching them to any registered
  * <code>ActionListener</code> objects.
  *
  * <p>This method is not called unless action events are enabled for this component. Action events
  * are enabled when one of the following occurs:
  *
  * <p>
  *
  * <ul>
  *   <li>An <code>ActionListener</code> object is registered via <code>addActionListener</code>.
  *   <li>Action events are enabled via <code>enableEvents</code>.
  * </ul>
  *
  * <p>Note that if the event parameter is <code>null</code> the behavior is unspecified and may
  * result in an exception.
  *
  * @param e the action event
  * @see java.awt.event.ActionListener
  * @see java.awt.TextField#addActionListener
  * @see java.awt.Component#enableEvents
  * @since JDK1.1
  */
 protected void processActionEvent(ActionEvent e) {
   ActionListener listener = actionListener;
   if (listener != null) {
     listener.actionPerformed(e);
   }
 }
 /**
  * Handles the actionPerformed event by invoking the actionPerformed methods on listener-a and
  * listener-b.
  *
  * @param e the action event
  */
 public void actionPerformed(ActionEvent e) {
   ((ActionListener) a).actionPerformed(e);
   ((ActionListener) b).actionPerformed(e);
 }
Exemple #29
0
 protected void notifyOk() {
   listener.onOk();
 }
  /**
   * Process data from the connect action
   *
   * @param data the {@link Bundle} returned by the {@link NewConnection} Acitivty
   */
  private void connectAction(Bundle data) {
    MqttConnectOptions conOpt = new MqttConnectOptions();
    /*
     * Mutal Auth connections could do something like this
     *
     *
     * SSLContext context = SSLContext.getDefault();
     * context.init({new CustomX509KeyManager()},null,null); //where CustomX509KeyManager proxies calls to keychain api
     * SSLSocketFactory factory = context.getSSLSocketFactory();
     *
     * MqttConnectOptions options = new MqttConnectOptions();
     * options.setSocketFactory(factory);
     *
     * client.connect(options);
     *
     */

    //    public Properties getSSLSettings() {
    //        final Properties properties = new Properties();
    //        properties.setProperty("com.ibm.ssl.keyStore",
    //            "C:/BKSKeystore/mqttclientkeystore.keystore");
    //        properties.setProperty("com.ibm.ssl.keyStoreType", "BKS");
    //        properties.setProperty("com.ibm.ssl.keyStorePassword", "passphrase");
    //        properties.setProperty("com.ibm.ssl.trustStore",
    //            "C:/BKSKeystore/mqttclienttrust.keystore");
    //        properties.setProperty("com.ibm.ssl.trustStoreType", "BKS");
    //        properties.setProperty("com.ibm.ssl.trustStorePassword", "passphrase ");
    //
    //        return properties;
    //    }

    try {

      SSLContext context;
      KeyStore ts = KeyStore.getInstance("BKS");
      ts.load(getResources().openRawResource(R.raw.test), "123456".toCharArray());
      TrustManagerFactory tmf = TrustManagerFactory.getInstance("X509");
      tmf.init(ts);
      TrustManager[] tm = tmf.getTrustManagers();
      context = SSLContext.getInstance("TLS");
      context.init(null, tm, null);

      // SocketFactory factory= SSLSocketFactory.getDefault();
      // Socket socket =factory.createSocket("localhost", 10000);
      SocketFactory factory = context.getSocketFactory();
      conOpt.setSocketFactory(factory);

    } catch (Exception e) {
      // TODO: handle exception
    }

    // The basic client information
    String server = (String) data.get(ActivityConstants.server);
    String clientId = (String) data.get(ActivityConstants.clientId);
    int port = Integer.parseInt((String) data.get(ActivityConstants.port));
    boolean cleanSession = (Boolean) data.get(ActivityConstants.cleanSession);

    boolean ssl = (Boolean) data.get(ActivityConstants.ssl);
    String uri = null;
    if (ssl) {
      Log.e("SSLConnection", "Doing an SSL Connect");
      uri = "ssl://";

    } else {
      uri = "tcp://";
    }

    uri = uri + server + ":" + port;

    MqttClientAndroidService client;
    client = Connections.getInstance(this).createClient(this, uri, clientId);
    // create a client handle
    String clientHandle = uri + clientId;

    // last will message
    String message = (String) data.get(ActivityConstants.message);
    String topic = (String) data.get(ActivityConstants.topic);
    Integer qos = (Integer) data.get(ActivityConstants.qos);
    Boolean retained = (Boolean) data.get(ActivityConstants.retained);

    // connection options

    String username = (String) data.get(ActivityConstants.username);

    String password = (String) data.get(ActivityConstants.password);

    int timeout = (Integer) data.get(ActivityConstants.timeout);
    int keepalive = (Integer) data.get(ActivityConstants.keepalive);

    Connection connection = new Connection(clientHandle, clientId, server, port, this, client, ssl);
    arrayAdapter.add(connection);

    connection.registerChangeListener(changeListener);
    // connect client

    String[] actionArgs = new String[1];
    actionArgs[0] = clientId;
    connection.changeConnectionStatus(ConnectionStatus.CONNECTING);

    conOpt.setCleanSession(cleanSession);
    conOpt.setConnectionTimeout(timeout);
    conOpt.setKeepAliveInterval(keepalive);
    if (!username.equals(ActivityConstants.empty)) {
      conOpt.setUserName(username);
    }
    if (!password.equals(ActivityConstants.empty)) {
      conOpt.setPassword(password.toCharArray());
    }

    final ActionListener callback =
        new ActionListener(this, ActionListener.Action.CONNECT, clientHandle, actionArgs);

    boolean doConnect = true;

    if ((!message.equals(ActivityConstants.empty)) || (!topic.equals(ActivityConstants.empty))) {
      // need to make a message since last will is set
      try {
        conOpt.setWill(topic, message.getBytes(), qos.intValue(), retained.booleanValue());
      } catch (Exception e) {
        doConnect = false;
        callback.onFailure(null, e);
      }
    }
    client.setCallback(new MqttCallbackHandler(this, clientHandle));
    connection.addConnectionOptions(conOpt);
    Connections.getInstance(this).addConnection(connection);
    if (doConnect) {
      try {
        client.connect(conOpt, null, callback);
      } catch (MqttException e) {
        Log.e(this.getClass().getCanonicalName(), "MqttException Occured", e);
      }
    }
  }