コード例 #1
0
  private static JPanel newPanel(List<NarseseTemplate> templates) {
    JPanel p = new JPanel(new BorderLayout());

    JPanel menu = new JPanel(new BorderLayout());
    DefaultMutableTreeNode tree = new DefaultMutableTreeNode();

    for (NarseseTemplate n : templates) {
      DefaultMutableTreeNode nt = new DefaultMutableTreeNode(n);
      tree.add(nt);
    }
    JTree t = new JTree(tree);
    menu.add(t, BorderLayout.CENTER);

    final JComboBox formSelect = new JComboBox();
    formSelect.addItem("en");
    formSelect.addItem("narsese");
    menu.add(formSelect, BorderLayout.NORTH);

    p.add(menu, BorderLayout.WEST);

    ActionListener change =
        new ActionListener() {
          JPanel r = null;

          @Override
          public void actionPerformed(ActionEvent e) {
            if (t.getSelectionModel().isSelectionEmpty()) return;
            Object o =
                ((DefaultMutableTreeNode)
                        t.getSelectionModel().getSelectionPath().getLastPathComponent())
                    .getUserObject();

            if (!(o instanceof NarseseTemplate)) return;

            if (r != null) {
              p.remove(r);
            }

            r = newPanel((NarseseTemplate) o, formSelect.getSelectedItem().toString());

            p.add(r, BorderLayout.CENTER);
            p.validate();
          }
        };

    formSelect.addActionListener(change);
    t.getSelectionModel()
        .addTreeSelectionListener(
            new TreeSelectionListener() {

              @Override
              public void valueChanged(TreeSelectionEvent e) {
                change.actionPerformed(null);
              }
            });

    change.actionPerformed(null);

    return p;
  }
コード例 #2
0
ファイル: WizExtendedList.java プロジェクト: fennstef/math4u2
 private void fireActionEvent() {
   for (Iterator iter = actionListeners.iterator(); iter.hasNext(); ) {
     ActionListener listener = (ActionListener) iter.next();
     ActionEvent ae = new ActionEvent(this, -1, null);
     listener.actionPerformed(ae);
   } // for iter
 } // fireActionEvent
コード例 #3
0
  public static JPanel newPanel(final NarseseTemplate t) {
    final JPanel p = new JPanel(new BorderLayout());

    final JComboBox formSelect = new JComboBox();
    p.add(formSelect, BorderLayout.WEST);

    for (String f : t.forms.keySet()) formSelect.addItem(f);

    ActionListener change =
        new ActionListener() {
          JPanel r = null;

          @Override
          public void actionPerformed(ActionEvent e) {
            if (r != null) {
              p.remove(r);
            }

            r = newPanel(t, formSelect.getSelectedItem().toString());

            p.add(r, BorderLayout.CENTER);
            p.validate();
          }
        };

    formSelect.addActionListener(change);

    change.actionPerformed(null);

    return p;
  }
コード例 #4
0
  /**
   * Handles the various button clicking type activities.
   *
   * @param e a value of type 'ActionEvent'
   */
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() == m_ConfigureBut) {
      selectProperty();
    } else if (e.getSource() == m_StatusBox) {
      // notify any listeners
      for (int i = 0; i < m_Listeners.size(); i++) {
        ActionListener temp = ((ActionListener) m_Listeners.elementAt(i));
        temp.actionPerformed(
            new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Editor status change"));
      }

      // Toggles whether the custom property is used
      if (m_StatusBox.getSelectedIndex() == 0) {
        m_Exp.setUsePropertyIterator(false);
        m_ConfigureBut.setEnabled(false);
        m_ArrayEditor.setEnabled(false);
        m_ArrayEditor.setValue(null);
        validate();
      } else {
        if (m_Exp.getPropertyArray() == null) {
          selectProperty();
        }
        if (m_Exp.getPropertyArray() == null) {
          m_StatusBox.setSelectedIndex(0);
        } else {
          m_Exp.setUsePropertyIterator(true);
          m_ConfigureBut.setEnabled(true);
          m_ArrayEditor.setEnabled(true);
        }
        validate();
      }
    }
  }
コード例 #5
0
  /**
   * Checks state of the {@code checked} checkbox and if state is {@code checkedState} than to
   * disable {@code changed} text field and clean it. When the {@code checked} checkbox changes
   * states to other state, than enable {@code changed} and restore its state. Note that the each
   * text field should be implied by only one other checkbox.
   *
   * @param checked the checkbox to monitor
   * @param checkedState the state that triggers disabling changed state
   * @param changed the checkbox to change
   */
  public static void implyDisabled(
      final JCheckBox checked, final boolean checkedState, final JTextField changed) {
    ActionListener l =
        new ActionListener() {
          String previousState;

          public void actionPerformed(ActionEvent e) {
            if (checked.isSelected() == checkedState) {
              if (previousState == null) {
                previousState = changed.getText();
              }
              changed.setEnabled(false);
              changed.setText("");
            } else {
              changed.setEnabled(true);
              if (previousState != null) {
                changed.setText(previousState);
                previousState = null;
              }
            }
          }
        };
    checked.addActionListener(l);
    l.actionPerformed(null);
  }
コード例 #6
0
 /**
  * Setup root chooser with specified elements and link selection to the current branch label.
  *
  * @param project a context project
  * @param roots git roots for the project
  * @param defaultRoot a default root
  * @param gitRootChooser git root selector
  * @param currentBranchLabel current branch label (might be null)
  */
 public static void setupRootChooser(
     @NotNull final Project project,
     @NotNull final List<VirtualFile> roots,
     @Nullable final VirtualFile defaultRoot,
     @NotNull final JComboBox gitRootChooser,
     @Nullable final JLabel currentBranchLabel) {
   for (VirtualFile root : roots) {
     gitRootChooser.addItem(root);
   }
   gitRootChooser.setRenderer(getVirtualFileListCellRenderer(gitRootChooser.getRenderer()));
   gitRootChooser.setSelectedItem(defaultRoot != null ? defaultRoot : roots.get(0));
   if (currentBranchLabel != null) {
     final ActionListener listener =
         new ActionListener() {
           public void actionPerformed(final ActionEvent e) {
             VirtualFile root = (VirtualFile) gitRootChooser.getSelectedItem();
             assert root != null : "The root must not be null";
             GitRepository repo =
                 GitRepositoryManager.getInstance(project).getRepositoryForRoot(root);
             assert repo != null : "The repository must not be null";
             GitBranch current = repo.getCurrentBranch();
             if (current == null) {
               currentBranchLabel.setText(NO_CURRENT_BRANCH);
             } else {
               currentBranchLabel.setText(current.getName());
             }
           }
         };
     listener.actionPerformed(null);
     gitRootChooser.addActionListener(listener);
   }
 }
コード例 #7
0
ファイル: ProductDisplay.java プロジェクト: lindskogen/iMat
 @Override
 public void actionPerformed(ActionEvent evt) {
   if (evt.getActionCommand().equals("buy")) {
     evt.setSource(getItem());
     listener.actionPerformed(evt);
   } else if (evt.getActionCommand().equals("fav")) {
     if (IDH.isFavorite(product)) {
       IDH.removeFavorite(product);
       if (list) {
         favButton.setIcon(
             new ImageIcon(ProductDisplay.class.getResource("/imat/resources/unfavmini.PNG")));
       } else {
         favButton.setIcon(
             new ImageIcon(ProductDisplay.class.getResource("/imat/resources/unfav.PNG")));
       }
       favButton.setToolTipText("Lägg till som favorit");
       listener.actionPerformed(evt);
     } else {
       IDH.addFavorite(product);
       if (list) {
         favButton.setIcon(
             new ImageIcon(ProductDisplay.class.getResource("/imat/resources/favmini.PNG")));
       } else {
         favButton.setIcon(
             new ImageIcon(ProductDisplay.class.getResource("/imat/resources/fav.PNG")));
       }
       listener.actionPerformed(evt);
       favButton.setToolTipText("Ta bort som favorit");
     }
     listener.actionPerformed(evt);
   }
 }
コード例 #8
0
ファイル: CWNTPanel.java プロジェクト: tinevez/CWNS
  private void fireEvent(final ActionEvent event) {
    if (event == STEP1_PARAMETER_CHANGED
        || event == STEP2_PARAMETER_CHANGED
        || event == STEP3_PARAMETER_CHANGED
        || event == STEP4_PARAMETER_CHANGED
        || event == STEP5_PARAMETER_CHANGED) {
      collectMaskingParameters();
      try {
        thresholdFactor = Double.parseDouble(thresholdFactorText.getText());
      } catch (final NumberFormatException nfe) {
      }

      if (Arrays.equals(maskingParams, oldMaskingParams) && thresholdFactor == oldThresholdFactor) {
        // We do not fire event if params did not change
        return;
      }

      oldThresholdFactor = thresholdFactor;
      oldMaskingParams = Arrays.copyOf(maskingParams, maskingParams.length);
    }

    for (final ActionListener listener : actionListeners) {
      listener.actionPerformed(event);
    }
  }
コード例 #9
0
 /**
  * This method check DefaultExpandedSideMenuPanel.
  *
  * @param collapseIcon the collapse icon
  * @param pinIcon the pin icon
  */
 private void checkDefaultExpandedSideMenuPanel(Icon collapseIcon, Icon pinIcon) {
   assertEquals("sideMenuModel", sideMenuModel, target.getSideMenuModel());
   ActionListener buttonListener =
       (ActionListener)
           TestHelper.getPrivateField(
               DefaultExpandedSideMenuPanel.class, target, "buttonListener");
   // check buttonListener
   assertNotNull("buttonListener", buttonListener);
   // ((JToggleButton) target.getPinButton()).setSelected(true);
   // buttonListener.actionPerformed(new ActionEvent(target.getPinButton(), 1, "xxx"));
   // assertEquals("should be floating", true, sideMenuModel.isFloating());
   ((JToggleButton) target.getPinButton()).setSelected(false);
   buttonListener.actionPerformed(new ActionEvent(target.getPinButton(), 1, "xxx"));
   assertEquals("should not be floating", false, sideMenuModel.isFloating());
   buttonListener.actionPerformed(new ActionEvent(target.getCollapseButton(), 1, "xxx"));
   assertEquals("should not be expanded", false, sideMenuModel.isExpanded());
   // check other fields
   assertEquals("content", TestHelper.CONTENT, target.getContent());
   TestHelper.checkButton(target.getCollapseButton(), buttonListener, collapseIcon);
   TestHelper.checkButton(target.getPinButton(), buttonListener, pinIcon);
   assertEquals("Selected status", sideMenuModel.isFloating(), target.getPinButton().isSelected());
   JLabel textLabel =
       (JLabel)
           TestHelper.getPrivateField(DefaultExpandedSideMenuPanel.class, target, "textLabel");
   assertEquals("text of textLabel", sideMenuModel.getTitle(), textLabel.getText());
   assertEquals(
       "HorizontalAlignment of textLabel",
       SwingConstants.CENTER,
       textLabel.getHorizontalAlignment());
 }
コード例 #10
0
 protected void editScript(boolean selectAll) {
   JEditorPane textEditor = new JEditorPane();
   textEditor.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
   final JRestrictedSizeScrollPane scrollPane = new JRestrictedSizeScrollPane(textEditor);
   scrollPane.setMinimumSize(minimumSize);
   textEditor.setContentType("text/groovy");
   textEditor.setText(script);
   if (selectAll) {
     textEditor.selectAll();
   }
   String title = TextUtils.getText("plugins/ScriptEditor/window.title");
   final JOptionPane optionPane =
       new JOptionPane(scrollPane, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
   final JDialog dialog = optionPane.createDialog(showEditorBtn, title);
   dialog.setResizable(true);
   if (bounds != null) dialog.setBounds(bounds);
   dialog.setVisible(true);
   bounds = dialog.getBounds();
   final Integer result = ((Integer) optionPane.getValue());
   if (result == null || result != JOptionPane.OK_OPTION) return;
   script = textEditor.getText();
   setButtonText();
   final ActionEvent actionEvent = new ActionEvent(this, 0, null);
   for (final ActionListener l : actionListeners) {
     l.actionPerformed(actionEvent);
   }
 }
コード例 #11
0
 private void notifyListners() {
   ActionEvent event = new ActionEvent(this, 0, loadPath);
   for (Iterator iter = listeners.iterator(); iter.hasNext(); ) {
     ActionListener element = (ActionListener) iter.next();
     element.actionPerformed(event);
   }
 }
コード例 #12
0
  /**
   * Checks state of the {@code checked} checkbox and if state is {@code checkedState} than to
   * disable {@code changed} checkbox and change its state to {@code impliedState}. When the {@code
   * checked} checkbox changes states to other state, than enable {@code changed} and restore its
   * state. Note that the each checkbox should be implied by only one other checkbox.
   *
   * @param checked the checkbox to monitor
   * @param checkedState the state that triggers disabling changed state
   * @param changed the checkbox to change
   * @param impliedState the implied state of checkbox
   */
  public static void imply(
      final JCheckBox checked,
      final boolean checkedState,
      final JCheckBox changed,
      final boolean impliedState) {
    ActionListener l =
        new ActionListener() {
          Boolean previousState;

          public void actionPerformed(ActionEvent e) {
            if (checked.isSelected() == checkedState) {
              if (previousState == null) {
                previousState = changed.isSelected();
              }
              changed.setEnabled(false);
              changed.setSelected(impliedState);
            } else {
              changed.setEnabled(true);
              if (previousState != null) {
                changed.setSelected(previousState);
                previousState = null;
              }
            }
          }
        };
    checked.addActionListener(l);
    l.actionPerformed(null);
  }
コード例 #13
0
 private void fireActionPerformed(DropTargetDropEvent dtde) {
   this.dropEvent = dtde;
   for (ActionListener l : listeners) {
     l.actionPerformed(new ActionEvent(this, 0, null));
   }
   this.dropEvent = null;
 }
コード例 #14
0
  private void fireActionEvent(ActionEvent evt) {
    ActionListener[] actionListeners = getActionListeners();

    for (ActionListener actionListener : actionListeners) {
      actionListener.actionPerformed(evt);
    }
  }
コード例 #15
0
 /**
  * This method adds a new field to the list, without any regard to validation. This method can be
  * useful for classes that overrides addField(s) to provide different validation.
  */
 protected void addFieldUncritically(String s) {
   listModel.addElement(s);
   changesMade = true;
   for (ActionListener additionListener : additionListeners) {
     additionListener.actionPerformed(new ActionEvent(this, 0, s));
   }
 }
コード例 #16
0
 private void play() {
   setSequenceParams();
   cs.play();
   play.setText("Pause");
   step.setEnabled(false);
   for (ActionListener a : playListeners) a.actionPerformed(null);
 }
コード例 #17
0
ファイル: Application.java プロジェクト: dpyryesk/ePad
 // Send a message to all listeners
 private static void notifyListeners(Object source, String message) {
   for (int i = 0; i < listeners.size(); i++) {
     ActionListener listener = listeners.get(i);
     if (listener != null)
       listener.actionPerformed(new ActionEvent(source, ActionEvent.ACTION_FIRST, message));
     else LOGGER.error("A listener is null: " + i);
   }
 }
コード例 #18
0
ファイル: ActionDialog.java プロジェクト: adbrown85/dalmatian
  protected final void fireActionEvent(String command) {

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

    for (ActionListener listener : listeners) {
      listener.actionPerformed(event);
    }
  }
コード例 #19
0
 public void setTreeActionState(Class<? extends TreeAction> action, boolean state) {
   final JCheckBox checkBox = myCheckBoxes.get(action);
   if (checkBox != null) {
     checkBox.setSelected(state);
     for (ActionListener listener : checkBox.getActionListeners()) {
       listener.actionPerformed(new ActionEvent(this, 1, ""));
     }
   }
 }
コード例 #20
0
ファイル: HUDButtonComponent.java プロジェクト: solimanm/OWL
 private void notifyListeners(ActionEvent event) {
   if (listeners != null) {
     Iterator<ActionListener> iter = actionListeners.iterator();
     while (iter.hasNext()) {
       ActionListener notifiee = iter.next();
       notifiee.actionPerformed(event);
     }
   }
 }
コード例 #21
0
 public void alert() {
   if (isUpnpDevice(uuid)
       && (monitor == null || !monitor.isAlive())
       && !"STOPPED".equals(data.get("TransportState"))) {
     monitor();
   }
   for (ActionListener l : listeners) {
     l.actionPerformed(event);
   }
 }
コード例 #22
0
        @Override
        public void mousePressed(MouseEvent e) {
          if (isEnabled()) {
            isSelected = !isSelected;
            repaint();

            ActionEvent evt = new ActionEvent(CompactCheckBox.this, 0, null);
            for (ActionListener l : listeners) l.actionPerformed(evt);
          }
        }
コード例 #23
0
 /**
  * fires an action event with a ClickEvent Id as its ID.
  *
  * @param ce the ce
  */
 public void fireActionPerformed(TapEvent ce) {
   ActionListener[] listeners = this.getActionListeners();
   synchronized (listeners) {
     for (int i = 0; i < listeners.length; i++) {
       ActionListener listener = (ActionListener) listeners[i];
       listener.actionPerformed(
           new ActionEvent(this, ce.getTapID(), "action performed on tangible button"));
     }
   }
 }
コード例 #24
0
 /**
  * Notifies all listeners that have registered interest for notification on this event type. The
  * event instance is lazily created using the <code>event</code> parameter.
  *
  * @param event the <code>ActionEvent</code> object
  * @see EventListenerList
  */
 protected void fireActionPerformed(ActionEvent event) {
   for (ActionListener listener : getActionListeners())
     listener.actionPerformed(
         new ActionEvent(
             this,
             ActionEvent.ACTION_PERFORMED,
             event.getActionCommand(),
             event.getWhen(),
             event.getModifiers()));
 }
コード例 #25
0
ファイル: JTarget.java プロジェクト: Tigraine/EvoPaint
    public void actionPerformed(ActionEvent e) {

      boolean containedCenter = false;
      if (directions.contains(RelativeCoordinate.CENTER)) {
        containedCenter = true;
      }

      List<RelativeCoordinate> allNeighbors =
          new ArrayList<RelativeCoordinate>() {
            {
              add(RelativeCoordinate.NORTH);
              add(RelativeCoordinate.NORTH_EAST);
              add(RelativeCoordinate.EAST);
              add(RelativeCoordinate.SOUTH_EAST);
              add(RelativeCoordinate.SOUTH);
              add(RelativeCoordinate.SOUTH_WEST);
              add(RelativeCoordinate.WEST);
              add(RelativeCoordinate.NORTH_WEST);
            }
          };

      if (directions.containsAll(allNeighbors)) {
        neighborsToggled = true;
      }

      directions.clear();

      if (containedCenter) {
        directions.add(RelativeCoordinate.CENTER);
      }

      if (neighborsToggled == false) {
        directions.addAll(allNeighbors);
      }

      for (JToggleButton b : buttonsDirections.keySet()) {
        if (buttonsDirections.get(b) == RelativeCoordinate.CENTER) {
          continue;
        }
        if (neighborsToggled == false && b.isSelected() == false) {
          b.setSelected(true);
          ActionEvent ae = new ActionEvent((Object) b, ActionEvent.ACTION_PERFORMED, "");
          for (ActionListener a : b.getActionListeners()) {
            a.actionPerformed(ae);
          }
        } else if (neighborsToggled && b.isSelected()) {
          b.setSelected(false);
          ActionEvent ae = new ActionEvent((Object) b, ActionEvent.ACTION_PERFORMED, "");
          for (ActionListener a : b.getActionListeners()) {
            a.actionPerformed(ae);
          }
        }
      }
      neighborsToggled = !neighborsToggled;
    }
コード例 #26
0
ファイル: InputHandler.java プロジェクト: ieugen/squirrel-sql
	/**
	 * 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;
			}
		}
	}
コード例 #27
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());
       }
     }
   }
 }
コード例 #28
0
ファイル: PenModel.java プロジェクト: KwokShing/Java
  private void processEvent(ActionEvent e) {
    ArrayList list;

    synchronized (this) {
      if (actionListenerList == null) return;
      list = (ArrayList) actionListenerList.clone();
    }

    for (int i = 0; i < list.size(); i++) {
      ActionListener listener = (ActionListener) list.get(i);
      listener.actionPerformed(e);
    }
  }
コード例 #29
0
 public void actionPerformed(ActionEvent event) {
   if (!listeners.isEmpty()) {
     ActionEvent e =
         new ActionEvent(
             menuItem,
             event.getID(),
             event.getActionCommand(),
             event.getWhen(),
             event.getModifiers());
     for (ActionListener l : listeners) {
       l.actionPerformed(e);
     }
   }
 }
コード例 #30
0
ファイル: BaseXSlider.java プロジェクト: dirkk/basex
  @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();
    }
  }