Package javax.swing

Examples of javax.swing.Action


    }
    public void showDialog(Component content, Action[] buttonActions, String title) {
        JDialog result = new JDialog(myMainFrame, true);
        result.setTitle(title);
        final Commiter commiter = new Commiter();
        Action okAction = null;
        Action cancelAction = null;
        Box buttonBox = Box.createHorizontalBox();
        for (int i = 0; i < buttonActions.length; i++) {
            Action nextAction = buttonActions[i];
            JButton nextButton = null;
            if (nextAction instanceof OkAction) {
                nextAction = createOkAction(nextAction, result, commiter);
                okAction = nextAction;
                nextButton = new JButton(nextAction);
                result.getRootPane().setDefaultButton(nextButton);
            }
            if (nextAction instanceof CancelAction) {
                nextAction = createCancelAction(nextAction, result, commiter);
                cancelAction = nextAction;
                result.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
                        KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
                        nextAction.getValue(Action.NAME));
                result.getRootPane().getActionMap().put(
                        nextAction.getValue(Action.NAME), nextAction);
            }
            if (nextButton == null) {
                nextButton = new JButton(nextAction);
            }
            buttonBox.add(nextButton);
            if (i < buttonActions.length - 1) {
                buttonBox.add(Box.createHorizontalStrut(5));
            }
        }
        result.getContentPane().setLayout(new BorderLayout());
        result.getContentPane().add(content, BorderLayout.CENTER);
        //
        JPanel buttonPanel = new JPanel(new BorderLayout());
        buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 5));
        buttonPanel.add(buttonBox, BorderLayout.EAST);
        result.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
        //
        result.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        final Action localOkAction = okAction;
        final Action localCancelAction = cancelAction;
        result.addWindowListener(new WindowAdapter() {
            public void windowClosed(WindowEvent e) {
                if (localCancelAction != null && !commiter.isCommited()) {
                    localCancelAction.actionPerformed(null);
                }
            }
        });
        result.pack();
        // setSize(300, 300);
View Full Code Here


      }                 
        };
        buttonBar.add(downButton);
        //
        buttonBar.add(Box.createHorizontalStrut(8));
        Action linkAction = new LinkTasksAction(myProject.getTaskManager(), Mediator.getTaskSelectionManager(), myWorkbenchFacade);
        myTreeFacade.setLinkTasksAction(linkAction);
        TestGanttRolloverButton linkButton = new TestGanttRolloverButton(linkAction) {
      public String getText() {
        return null;
      }                 
        };
        buttonBar.add(linkButton);
        //
        Action unlinkAction = new UnlinkTasksAction(myProject.getTaskManager(), Mediator.getTaskSelectionManager(), myWorkbenchFacade);
        myTreeFacade.setUnlinkTasksAction(unlinkAction);
        TestGanttRolloverButton unlinkButton = new TestGanttRolloverButton(unlinkAction) {
      public String getText() {
        return null;
      }                 
View Full Code Here

        for (int i = 0; i < myExporters.length; i++) {
            final Exporter nextExporter = myExporters[i];
            if (nextExporter==myState.getExporter()) {
                selectedGroupIndex = i;
            }
            Action nextAction = new AbstractAction(nextExporter
                    .getFileTypeDescription()) {
                public void actionPerformed(ActionEvent e) {
                    ExporterChooserPage.this.myState.setExporter(nextExporter);
                }
            };
View Full Code Here

            myEndDateButton.setToolTipText(GanttProject.getToolTip(GanttProject
                    .correctLabel(language.getText("setEndDate"))));
                    */
            //GanttProject gp = Mediator.getGanttProjectSingleton();
            final ZoomManager zoomManager = myUIfacade.getZoomManager();
            final Action zoomOut = new ZoomOutAction(zoomManager, "16");
            final Action zoomIn = new ZoomInAction(zoomManager, "16");
            bZoomOut = new JButton((Icon) zoomOut.getValue(Action.SMALL_ICON));
            bZoomIn = new JButton((Icon) zoomIn.getValue(Action.SMALL_ICON));

            bZoomOut.setHorizontalTextPosition(SwingConstants.RIGHT);
            bZoomOut.setText(language.getText("narrowChart"));
            bZoomOut.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                    run(new Runnable() {
                        public void run() {
                            zoomOut.actionPerformed(null);
                            updateSourceImage();
                            bZoomOut.setEnabled(zoomManager.canZoomOut());
                            bZoomIn.setEnabled(zoomManager.canZoomIn());
                        }
                    });
                }
            });

            bZoomIn.setHorizontalTextPosition(SwingConstants.RIGHT);
            bZoomIn.setText(language.getText("widenChart"));
            bZoomIn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent arg0) {
                    run(new Runnable() {
                        public void run() {
                            zoomIn.actionPerformed(null);
                            updateSourceImage();
                            bZoomOut.setEnabled(zoomManager.canZoomOut());
                            bZoomIn.setEnabled(zoomManager.canZoomIn());
                        }
                    });
View Full Code Here

  /**
   * Adds to tool bar the button matching the given <code>actionType</code>.
   */
  private void addActionToToolBar(ActionType actionType,
                                  JToolBar toolBar) {
    Action action = getActionMap().get(actionType);
    if (action!= null && action.getValue(Action.NAME) != null) {
      toolBar.add(new ResourceAction.ToolBarAction(action));
    }
  }
View Full Code Here

  /**
   * Enables or disables the action matching <code>actionType</code>.
   */
  public void setEnabled(ActionType actionType,
                         boolean enabled) {
    Action action = getActionMap().get(actionType);
    if (action != null) {
      action.setEnabled(enabled);
    }
  }
View Full Code Here

   * Sets the <code>NAME</code> and <code>SHORT_DESCRIPTION</code> properties value
   * matching <code>actionType</code>. If <code>name</code> is null,
   * the properties will be reset to their initial values.
   */
  private void setNameAndShortDescription(ActionType actionType, String name) {
    Action action = getActionMap().get(actionType);
    if (action != null) {
      if (name == null) {
        name = (String)action.getValue(Action.DEFAULT);
      }
      action.putValue(Action.NAME, name);
      action.putValue(Action.SHORT_DESCRIPTION, name);
    }
  }
View Full Code Here

    // Remove menu bar
    homeView.setJMenuBar(null);
   
    // As the applet has no menu, activate accelerators directly on home view
    for (HomeView.ActionType actionType : HomeView.ActionType.values()) {
      Action action = homeView.getActionMap().get(actionType);
      if (action != null) {
        ResourceAction.MenuItemAction menuAction = new ResourceAction.MenuItemAction(action);
        KeyStroke accelerator = (KeyStroke)menuAction.getValue(Action.ACCELERATOR_KEY);
        if (accelerator != null) {
          homeView.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(accelerator, actionType);
        }
      }
    }
   
    // Change default buttons in toolbar
    JToolBar toolBar = (JToolBar)homeView.getContentPane().getComponent(0);
    toolBar.setFloatable(false);   
    // Retrieve all buttons that are plug-in actions
    List<JComponent> pluginButtons = new ArrayList<JComponent>();
    for (int i = 0; i < toolBar.getComponentCount(); i++) {
      JComponent component = (JComponent)toolBar.getComponent(i);
      if (component instanceof AbstractButton
          && ((AbstractButton)component).getAction().
                getValue(PluginAction.Property.TOOL_BAR.name()) == Boolean.TRUE) {
        pluginButtons.add(component);
      }
    }
    toolBar.removeAll();
    // Add New, Open, Save, Save as buttons if they are enabled
    Action newHomeAction = getToolBarAction(homeView, HomeView.ActionType.NEW_HOME);
    if (newHomeAction != null && newHomeAction.isEnabled()) {
      toolBar.add(newHomeAction);
    }
    Action openAction = getToolBarAction(homeView, HomeView.ActionType.OPEN);
    if (openAction != null && openAction.isEnabled()) {
      toolBar.add(openAction);
    }
    Action saveAction = getToolBarAction(homeView, HomeView.ActionType.SAVE);
    if (saveAction != null && saveAction.isEnabled()) {
      toolBar.add(saveAction);
    }
    Action saveAsAction = getToolBarAction(homeView, HomeView.ActionType.SAVE_AS);
    if (saveAsAction != null && saveAsAction.isEnabled()) {
      toolBar.add(saveAsAction);
    }
   
    if (getAppletBooleanParameter(this.applet, ENABLE_EXPORT_TO_SH3D)) {
      try {
        // Add export to SH3D action
        Action exportToSH3DAction = new ControllerAction(getUserPreferences(),
            AppletApplication.class, "EXPORT_TO_SH3D", controller, "exportToSH3D");
        exportToSH3DAction.setEnabled(true);
        toolBar.add(new ResourceAction.ToolBarAction(exportToSH3DAction));
      } catch (NoSuchMethodException ex) {
        ex.printStackTrace();
      }
    }
   
    if (toolBar.getComponentCount() > 0) {
      toolBar.add(Box.createRigidArea(new Dimension(2, 2)));
    }
    addToolBarAction(homeView, HomeView.ActionType.PAGE_SETUP, toolBar);
    addToolBarAction(homeView, HomeView.ActionType.PRINT, toolBar);
    Action printToPdfAction = getToolBarAction(homeView, HomeView.ActionType.PRINT_TO_PDF);
    if (printToPdfAction != null
        && getAppletBooleanParameter(this.applet, ENABLE_PRINT_TO_PDF)
        && !OperatingSystem.isMacOSX()) {
      controller.getView().setEnabled(HomeView.ActionType.PRINT_TO_PDF, true);
      toolBar.add(printToPdfAction);
    }
    Action preferencesAction = getToolBarAction(homeView, HomeView.ActionType.PREFERENCES);
    if (preferencesAction != null) {
      toolBar.add(Box.createRigidArea(new Dimension(2, 2)));
      toolBar.add(preferencesAction);
    }
    toolBar.addSeparator();

    addToolBarAction(homeView, HomeView.ActionType.UNDO, toolBar);
    addToolBarAction(homeView, HomeView.ActionType.REDO, toolBar);
    toolBar.add(Box.createRigidArea(new Dimension(2, 2)));
    addToolBarAction(homeView, HomeView.ActionType.CUT, toolBar);
    addToolBarAction(homeView, HomeView.ActionType.COPY, toolBar);
    addToolBarAction(homeView, HomeView.ActionType.PASTE, toolBar);
    toolBar.add(Box.createRigidArea(new Dimension(2, 2)));
    addToolBarAction(homeView, HomeView.ActionType.DELETE, toolBar);
    toolBar.addSeparator();

    Action addHomeFurnitureAction = getToolBarAction(homeView, HomeView.ActionType.ADD_HOME_FURNITURE);
    if (addHomeFurnitureAction != null) {
      toolBar.add(addHomeFurnitureAction);
      toolBar.addSeparator();
    }
   
    final JToggleButton selectToggleButton =
        new JToggleButton(getToolBarAction(homeView, HomeView.ActionType.SELECT));
    selectToggleButton.setSelected(true);
    toolBar.add(selectToggleButton);
    final JToggleButton panToggleButton =
        new JToggleButton(getToolBarAction(homeView, HomeView.ActionType.PAN));
    toolBar.add(panToggleButton);
    final JToggleButton createWallsToggleButton =
        new JToggleButton(getToolBarAction(homeView, HomeView.ActionType.CREATE_WALLS));
    toolBar.add(createWallsToggleButton);
    final JToggleButton createRoomsToggleButton =
        new JToggleButton(getToolBarAction(homeView, HomeView.ActionType.CREATE_ROOMS));
    toolBar.add(createRoomsToggleButton);
    final JToggleButton createDimensionLinesToggleButton =
        new JToggleButton(getToolBarAction(homeView, HomeView.ActionType.CREATE_DIMENSION_LINES));
    toolBar.add(createDimensionLinesToggleButton);
    final JToggleButton createLabelsToggleButton =
        new JToggleButton(getToolBarAction(homeView, HomeView.ActionType.CREATE_LABELS));
    toolBar.add(createLabelsToggleButton);
    // Add Select, Create Walls and Create dimensions buttons to radio group
    ButtonGroup group = new ButtonGroup();
    group.add(selectToggleButton);
    group.add(panToggleButton);
    group.add(createWallsToggleButton);
    group.add(createRoomsToggleButton);
    group.add(createDimensionLinesToggleButton);
    group.add(createLabelsToggleButton);
    controller.getPlanController().addPropertyChangeListener(PlanController.Property.MODE,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            PlanController.Mode mode = controller.getPlanController().getMode();
            selectToggleButton.setSelected(mode == PlanController.Mode.SELECTION);
            panToggleButton.setSelected(mode == PlanController.Mode.PANNING);
            createWallsToggleButton.setSelected(mode == PlanController.Mode.WALL_CREATION);
            createRoomsToggleButton.setSelected(mode == PlanController.Mode.ROOM_CREATION);
            createDimensionLinesToggleButton.setSelected(mode == PlanController.Mode.DIMENSION_LINE_CREATION);
            createLabelsToggleButton.setSelected(mode == PlanController.Mode.LABEL_CREATION);
          }
        });
    toolBar.add(Box.createRigidArea(new Dimension(2, 2)));
   
    addToolBarAction(homeView, HomeView.ActionType.ZOOM_OUT, toolBar);
    addToolBarAction(homeView, HomeView.ActionType.ZOOM_IN, toolBar);

    Action createPhotoAction = getToolBarAction(homeView, HomeView.ActionType.CREATE_PHOTO);
    if (createPhotoAction != null) {
      boolean enableCreatePhoto = getAppletBooleanParameter(this.applet, ENABLE_CREATE_PHOTO);
      controller.getView().setEnabled(HomeView.ActionType.CREATE_PHOTO, enableCreatePhoto);
      if (enableCreatePhoto) {
        toolBar.addSeparator();
        toolBar.add(createPhotoAction);
      }
    }

    // Add plug-in buttons
    if (pluginButtons.size() > 0) {
      toolBar.addSeparator();
      for (JComponent pluginButton : pluginButtons) {
        toolBar.add(pluginButton);
      }
    }
   
    Action aboutAction = getToolBarAction(homeView, HomeView.ActionType.ABOUT);
    if (aboutAction != null) {
      toolBar.addSeparator();
      toolBar.add(aboutAction);
    }
   
View Full Code Here

 
  /**
   * Adds the action matching the given <code>actionType</code> to the tool bar if it exists.
   */
  private void addToolBarAction(JComponent homeView, HomeView.ActionType actionType, JToolBar toolBar) {
    Action action = getToolBarAction(homeView, actionType);
    if (action != null) {
      toolBar.add(action);
    }
  }
View Full Code Here

  /**
   * Returns an action decorated for tool bar buttons.
   */
  private Action getToolBarAction(JComponent homeView, HomeView.ActionType actionType) {
    Action action = homeView.getActionMap().get(actionType);   
    return action != null
        ? new ResourceAction.ToolBarAction(action)
        : null;
  }
View Full Code Here

TOP

Related Classes of javax.swing.Action

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.