コード例 #1
0
ファイル: ExtensionOption.java プロジェクト: igorhvr/zaproxy
 private JCheckBoxMenuItem getMenuViewImage() {
   if (menuViewImage == null) {
     menuViewImage = new JCheckBoxMenuItem();
     menuViewImage.setText(Constant.messages.getString("menu.view.enableImage")); // ZAP: i18n
     menuViewImage.addItemListener(
         new java.awt.event.ItemListener() {
           @Override
           public void itemStateChanged(java.awt.event.ItemEvent e) {
             getModel()
                 .getOptionsParam()
                 .getViewParam()
                 .setProcessImages(getMenuViewImage().getState() ? 1 : 0);
           }
         });
   }
   return menuViewImage;
 }
コード例 #2
0
ファイル: AlgorithmsPanel.java プロジェクト: Yaqiang/sextante
  private void init() {

    m_iExecuteIterativeMenuCount = 0;
    this.setPreferredSize(new java.awt.Dimension(350, 380));
    this.setSize(new java.awt.Dimension(350, 380));
    final BorderLayout thisLayout = new BorderLayout();
    this.setLayout(thisLayout);
    jTree = new JTree();
    jTree.setOpaque(false);
    jTree.setCellRenderer(new AlgorithmTreeCellRenderer());
    final MouseListener ml =
        new MouseAdapter() {
          @Override
          public void mousePressed(MouseEvent e) {
            m_Alg = null;
            m_Action = null;
            menuItemExecute.setVisible(false);
            menuItemExecuteAsBatch.setVisible(false);
            for (int i = 0; i < EXECUTE_ITERATIVE_MENU_COUNT; i++) {
              menuItemExecuteIterative[i].setVisible(false);
            }
            for (int j = 0; j < menuItemToolboxAction.length; j++) {
              menuItemToolboxAction[j].setVisible(false);
            }
            menuItemExecuteAsBatchFromGIS.setVisible(false);
            menuItemShowHelp.setVisible(false);
            m_Path = jTree.getPathForLocation(e.getX(), e.getY());
            updateSelectedAlgorithm();

            // Create again DataObjects here to get feature selections changes (if there are)
            SextanteGUI.getInputFactory().createDataObjects();

            if (e.getButton() == MouseEvent.BUTTON1) {
              if (e.getClickCount() == 2) {
                executeSelectedAlgorithm();
              }
            } else if (e.getButton() == MouseEvent.BUTTON3) {
              showPopupMenu(e);
            }
          }
        };
    jTree.addMouseListener(ml);
    jTree.addKeyListener(
        new KeyListener() {
          public void keyPressed(final KeyEvent e) {}

          public void keyReleased(final KeyEvent e) {}

          public void keyTyped(final KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
              executeSelectedAlgorithm();
            }

            if (e.getKeyChar() == KeyEvent.VK_SPACE) {
              showPopupMenu(e);
            }
          }
        });

    jTree.addTreeSelectionListener(
        new TreeSelectionListener() {

          public void valueChanged(final TreeSelectionEvent e) {
            m_Path = e.getPath();
            updateSelectedAlgorithm();
          }
        });

    jScrollPane = new TransparentScrollPane(jTree);
    jScrollPane.setSize(new java.awt.Dimension(350, 380));
    if (m_BackgroundImg != null) {
      jScrollPane.setBackgroundImage(m_BackgroundImg);
    }
    this.add(jScrollPane, BorderLayout.CENTER);

    popupMenu = new JPopupMenu("Menu");

    menuItemExecute = new JMenuItem(Sextante.getText("Run"));
    menuItemExecute.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            executeSelectedAlgorithm();
          }
        });
    popupMenu.add(menuItemExecute);

    menuItemExecuteIterative = new JMenuItem[EXECUTE_ITERATIVE_MENU_COUNT];
    for (int i = 0; i < menuItemExecuteIterative.length; i++) {
      final int iParameter = i;
      menuItemExecuteIterative[i] = new JMenuItem();
      menuItemExecuteIterative[i].addActionListener(
          new ActionListener() {
            public void actionPerformed(final ActionEvent evt) {
              executeSelectedAlgorithmIteratively(iParameter);
            }
          });
      popupMenu.add(menuItemExecuteIterative[i]);
    }

    final IToolboxRightButtonAction[] actions = SextanteGUI.getToolboxRightButtonActions();
    menuItemToolboxAction = new JMenuItem[actions.length];
    for (int i = 0; i < actions.length; i++) {
      final IToolboxRightButtonAction action = actions[i];
      menuItemToolboxAction[i] = new JMenuItem();
      menuItemToolboxAction[i].setText(action.getDescription());
      menuItemToolboxAction[i].addActionListener(
          new ActionListener() {
            public void actionPerformed(final ActionEvent evt) {
              action.execute(m_Alg);
            }
          });
      popupMenu.add(menuItemToolboxAction[i]);
    }

    menuItemExecuteAsBatch = new JMenuItem(Sextante.getText("Execute_as_batch_process"));
    menuItemExecuteAsBatch.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            executeAsBatch();
          }
        });
    popupMenu.add(menuItemExecuteAsBatch);

    menuItemExecuteAsBatchFromGIS =
        new JMenuItem(Sextante.getText("Execute_as_batch_process__using_layers_from_GIS_app"));
    menuItemExecuteAsBatchFromGIS.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            executeAsBatchInGIS();
          }
        });
    popupMenu.add(menuItemExecuteAsBatchFromGIS);
    popupMenu.addSeparator();

    menuItemSetOutputRendering = new JMenuItem(Sextante.getText("set_output_rendering"));
    menuItemSetOutputRendering.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            setOutputRendering();
          }
        });
    popupMenu.add(menuItemSetOutputRendering);
    popupMenu.addSeparator();

    final JMenuItem menuItemExpand = new JMenuItem(Sextante.getText("Expand_all"));
    menuItemExpand.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            expandAll();
          }
        });
    popupMenu.add(menuItemExpand);

    final JMenuItem menuItemCollapse = new JMenuItem(Sextante.getText("Collapse_all"));
    menuItemCollapse.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            collapseAll();
          }
        });
    popupMenu.add(menuItemCollapse);

    menuItemShowOnlyActive = new JCheckBoxMenuItem(Sextante.getText("Show_active_only"));
    menuItemShowOnlyActive.addItemListener(
        new ItemListener() {
          public void itemStateChanged(final ItemEvent e) {
            SextanteGUI.setShowOnlyActiveAlgorithms(e.getStateChange() == ItemEvent.SELECTED);
            fillTree(m_sLastSearchString, m_bLastSearchIncludedHelpFiles);
            collapseAll();
          }
        });
    menuItemShowOnlyActive.setSelected(SextanteGUI.getShowOnlyActiveAlgorithms());
    popupMenu.add(menuItemShowOnlyActive);

    popupMenu.addSeparator();

    menuItemShowHelp = new JMenuItem(Sextante.getText("Show_help"));
    menuItemShowHelp.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent evt) {
            showHelp();
          }
        });
    popupMenu.add(menuItemShowHelp);
  }
コード例 #3
0
ファイル: MenuDemo.java プロジェクト: fanhongtao/java.old
  public JMenuBar createMenuBar() {
    JMenuBar menuBar;
    JMenu menu, submenu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMenuItem;
    JCheckBoxMenuItem cbMenuItem;

    // Create the menu bar.
    menuBar = new JMenuBar();

    // Build the first menu.
    menu = new JMenu("A Menu");
    menu.setMnemonic(KeyEvent.VK_A);
    menu.getAccessibleContext()
        .setAccessibleDescription("The only menu in this program that has menu items");
    menuBar.add(menu);

    // a group of JMenuItems
    menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T);
    // menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    ImageIcon icon = createImageIcon("images/middle.gif");
    menuItem = new JMenuItem("Both text and icon", icon);
    menuItem.setMnemonic(KeyEvent.VK_B);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem(icon);
    menuItem.setMnemonic(KeyEvent.VK_D);
    menuItem.addActionListener(this);
    menu.add(menuItem);

    // a group of radio button menu items
    menu.addSeparator();
    ButtonGroup group = new ButtonGroup();

    rbMenuItem = new JRadioButtonMenuItem("A radio button menu item");
    rbMenuItem.setSelected(true);
    rbMenuItem.setMnemonic(KeyEvent.VK_R);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    rbMenuItem = new JRadioButtonMenuItem("Another one");
    rbMenuItem.setMnemonic(KeyEvent.VK_O);
    group.add(rbMenuItem);
    rbMenuItem.addActionListener(this);
    menu.add(rbMenuItem);

    // a group of check box menu items
    menu.addSeparator();
    cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
    cbMenuItem.setMnemonic(KeyEvent.VK_C);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    cbMenuItem = new JCheckBoxMenuItem("Another one");
    cbMenuItem.setMnemonic(KeyEvent.VK_H);
    cbMenuItem.addItemListener(this);
    menu.add(cbMenuItem);

    // a submenu
    menu.addSeparator();
    submenu = new JMenu("A submenu");
    submenu.setMnemonic(KeyEvent.VK_S);

    menuItem = new JMenuItem("An item in the submenu");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK));
    menuItem.addActionListener(this);
    submenu.add(menuItem);

    menuItem = new JMenuItem("Another item");
    menuItem.addActionListener(this);
    submenu.add(menuItem);
    menu.add(submenu);

    // Build second menu in the menu bar.
    menu = new JMenu("Another Menu");
    menu.setMnemonic(KeyEvent.VK_N);
    menu.getAccessibleContext().setAccessibleDescription("This menu does nothing");
    menuBar.add(menu);

    return menuBar;
  }
コード例 #4
0
  // Method builds menu action listeners.
  private void buildMenuActionListeners() {
    /*
    || Section adds action listeners to window frame menus:
    || ===================================================
    ||  - Menu file:
    ||    ---------
    ||    - menuItemSend
    ||    - menuItemReceive
    ||    - menuItemExit
    ||
    ||  - Menu edit:
    ||    ---------
    ||    - menuItemHelp
    */

    // ---------------------------------/
    // Menu item listeners to file menu.
    // ---------------------------------/

    menuItemNew.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // New file.
            newFile();
          } // End of actionPerformed method.
        }); // End of menuItemNew action listener.

    menuItemOpen.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Open file.
            openFile();
          } // End of actionPerformed method.
        }); // End of menuItemOpen action listener.

    menuItemClose.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Close file.
            closeFile();
          } // End of actionPerformed method.
        }); // End of menuItemClose action listener.

    menuItemSave.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Save current sender JTextAreaPanel String as current file.
            saveFile();
          } // End of actionPerformed method.
        }); // End of menuItemSave action listener.

    menuItemSaveAs.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Save current sender JTextAreaPanel String as new file.
            saveAsFile();
          } // End of actionPerformed method.
        }); // End of menuItemSaveAs action listener.

    menuItemExit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Exit the system on menu exit.
            System.exit(0);
          } // End of actionPerformed() method.
        }); // End of menuItemExit action listener.

    menuItemSend.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Send message.
            setMessage(sender, receiver);
          } // End of actionPerformed() method.
        }); // End of menuItemSend action listener.

    menuItemReceive.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Receive message.
            getMessage(receiver);
          } // End of actionPerformed() method.
        }); // End of menuItemReceive action listener.

    menuItemConnect.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Functionality to be implemented.
            System.out.println("This is future functionality to Connect to DB.");
          } // End of actionPerformed() method.
        }); // End of menuItemConnect action listener.

    menuItemSubmit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Functionality to be implemented.
            System.out.println("This is future functionality to Submit SQL.");
          } // End of actionPerformed() method.
        }); // End of menuItemSubmit action listener.

    // ---------------------------------/
    // Menu item listeners to help menu.
    // ---------------------------------/

    // Add menu item listeners for debug check box menu item.
    menuCheckBoxItemDebug.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            // Set stack trace enablement to opposite state.
            setDebugEnabled(!getDebugEnabled());
          } // End of actionPerformed method.
        }); // End of menuCheckBoxItemDebug item listener.

    // Add menu item action listener for help menu.
    menuItemHelp.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // Call inner class help handler.
            new HelpHandler(JMessagingFrame.this, true);
          } // End of actionPerformed() method.
        }); // End of menuItemHelp action listener.
  } // End of buildMenuActionListeners() method.
コード例 #5
0
ファイル: NMenu.java プロジェクト: BackupTheBerlios/nv2d-svn
  private void initComponents() {
    _legend = new JMenu("Legend");
    _legendDefaultColoring = new JMenuItem("Normal Color Scheme");
    _legendDefaultColoring.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _legendDefaultColoringActionPerformed(e);
          }
        });
    _legend.add(_legendDefaultColoring);
    _legend.add(new JSeparator());

    // initialize the modules menu
    _mods = new JMenu("Import");
    _modsClear = new JMenuItem("Clear Graph");

    // NOTE: done in resetImporterMenu() now -bs
    // _mods.add(_modsClear);
    // _mods.add(_separatorImporter);
    _modsClear.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _modsClearActionPerformed(e);
          }
        });

    // initialize the plugins menu
    _plugin = new JMenu("Plugins");
    _pluginLoad = new JMenuItem("Plugin Manager");

    // NOTE: done in resetPluginMenu() now -bs
    // _plugin.add(_pluginLoad);
    // _plugin.add(_separatorPlugin);
    _pluginLoad.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _pluginLoadActionPerformed(e);
          }
        });

    // initialize the optimization menu
    _optimize = new JMenu("Optimization");
    _optimizeStart = new JMenuItem("Start");
    _optimizeStop = new JMenuItem("Stop");
    _optimizeCenter = new JMenuItem("Center");
    _optimizeReset = new JMenuItem("Reset");

    _optimize.add(_optimizeStart);
    _optimize.add(_optimizeStop);
    _optimize.add(_optimizeCenter);
    _optimize.add(_optimizeReset);

    _optimizeStart.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _optimizeStartActionPerformed(e);
          }
        });
    _optimizeStop.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _optimizeStopActionPerformed(e);
          }
        });
    _optimizeCenter.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _optimizeCenterActionPerformed(e);
          }
        });
    _optimizeReset.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _optimizeResetActionPerformed(e);
          }
        });

    _view = new JMenu("View");
    _viewVLabel =
        new JCheckBoxMenuItem(
            "Labels", _renderbox.getRenderSettings().getBoolean(RenderSettings.SHOW_LABELS));
    _viewStress =
        new JCheckBoxMenuItem(
            "Stress", _renderbox.getRenderSettings().getBoolean(RenderSettings.SHOW_STRESS));
    _viewLength =
        new JCheckBoxMenuItem(
            "Length", _renderbox.getRenderSettings().getBoolean(RenderSettings.SHOW_LENGTH));
    _viewVis = new JMenu("Visualization");
    _viewFilter = new JMenu("Graph Filters");
    _viewFilterDegree = new JMenuItem("Degree Filter");
    _viewSidePanel = new JMenuItem("Side Panel");
    _viewSouthPanel = new JMenuItem("Bottom Panel");
    _viewErrTxt = new JMenuItem("Error Messages");
    _viewOutTxt = new JMenuItem("Program Output");
    _viewRenderBox = new JMenuItem("Graph Visualization");
    _viewSaveImage = new JMenuItem("Save Image...");

    _view.add(_viewSouthPanel);
    _view.add(_viewSidePanel);
    _view.add(_viewRenderBox);
    _view.add(_viewOutTxt);
    _view.add(_viewErrTxt);
    _view.add(new JSeparator());
    _view.add(_viewVis);
    _view.add(_viewFilter);
    // visualization submenu
    _viewVis.add(_viewVLabel);
    // _viewVis.add(_viewStress); // TODO: not added b/c it doesn't do anything now
    _viewVis.add(_viewLength);
    // filter submenu
    _viewFilter.add(_viewFilterDegree);
    // save image option
    _view.add(new JSeparator());
    _view.add(_viewSaveImage);
    _viewFilterDegree.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _viewFilterDegreeActionPerformed(e);
          }
        });
    _viewSouthPanel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _viewBottomPanelActionPerformed(e);
          }
        });
    _viewSidePanel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _viewSidePanelActionPerformed(e);
          }
        });
    _viewVLabel.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            _viewVLabelItemStateChanged(e);
          }
        });
    _viewStress.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            _viewStressItemStateChanged(e);
          }
        });
    _viewLength.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            _viewLengthItemStateChanged(e);
          }
        });
    _viewErrTxt.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _viewErrTxtActionPerformed(e);
          }
        });
    _viewOutTxt.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _viewOutTxtActionPerformed(e);
          }
        });
    _viewRenderBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _viewRenderBoxActionPerformed(e);
          }
        });
    _viewSaveImage.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            _viewSaveImageActionPerformed(e);
          }
        });

    // initialize settings menu
    _settings = new JMenu("Settings");
    _settingsAntialias =
        new JCheckBoxMenuItem(
            "Antialias", _renderbox.getRenderSettings().getBoolean(RenderSettings.ANTIALIAS));

    _settings.add(_settingsAntialias);
    _settingsAntialias.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            _settingsAntialiasItemStateChanged(e);
          }
        });
  }
コード例 #6
0
ファイル: DetailsFrame.java プロジェクト: ncweiler/fiji
  public void setListeners() {

    addWindowFocusListener(
        new WindowFocusListener() {
          public void windowGainedFocus(WindowEvent e) {
            updateTreeAndLabels();
          }

          public void windowLostFocus(WindowEvent e) {}
        });

    dumpButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dumpData();
          }
        });

    xmlButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dumpXmlData();
          }
        });

    expandAllItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            expandAll();
          }
        });

    collapseAllItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            collapseAll();
          }
        });

    detailsTree.addMouseListener(
        new MouseAdapter() {
          public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
              detailsTreePopupMenu.show((JComponent) e.getSource(), e.getX(), e.getY());
            }
          }
        });

    exitButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });

    filterCBItem.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            filterButton.setSelected(filterCBItem.isSelected());
            updateTreeAndLabels();
          }
        });

    filterButton.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            filterCBItem.setSelected(filterButton.isSelected());
            updateTreeAndLabels();
          }
        });

    searchButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (!searchTF.getText().equals("")) {
              lastNodeResult =
                  findNode(
                      searchTF.getText(),
                      ((DefaultMutableTreeNode) detailsTree.getModel().getRoot())
                          .breadthFirstEnumeration(),
                      lastNodeResult);
              if (lastNodeResult != null) {
                TreePath tp = new TreePath(lastNodeResult.getPath());
                detailsTree.setSelectionPath(tp);
                detailsTree.scrollPathToVisible(tp);
                if (lastNodeResult instanceof InfoNode && searchCoordinates != null) {

                  table.changeSelection(searchCoordinates.x, searchCoordinates.y, false, false);
                }
              }
            }
          }
        });

    detailsTree.addTreeSelectionListener(
        new TreeSelectionListener() {
          public void valueChanged(TreeSelectionEvent e) {
            if (detailsTree.getLastSelectedPathComponent() instanceof InfoNode) {
              InfoNode node = (InfoNode) detailsTree.getLastSelectedPathComponent();
              if (node == null) return;
              Object nodeInfo = node.getUserObject();
              if (nodeInfo == null) return;
              if (nodeInfo instanceof LinkedHashMap) {
                LinkedHashMap<String, Object> info = (LinkedHashMap<String, Object>) nodeInfo;
                ((TreeTableModel) table.getModel()).setData(info);
              }
            } else ((TreeTableModel) table.getModel()).setData(null);
          }
        });

    updateTreeAndLabels();
  }
コード例 #7
0
    /** Create the UI for this editor */
    void makeUI() {

      JPanel mainPanel = new JPanel(new BorderLayout());
      mainPanel.setBorder(new LineBorder(Color.blue));
      getContentPane().add(mainPanel, BorderLayout.CENTER);

      // the map and associated toolbar
      npEditControl = new NPController();
      mapEditPanel = npEditControl.getNavigatedPanel(); // here's where the map will be drawn
      mapEditPanel.setPreferredSize(new Dimension(250, 250));
      mapEditPanel.setSelectRegionMode(true);
      JToolBar navToolbar = mapEditPanel.getNavToolBar();
      navToolbar.setFloatable(false);
      JToolBar moveToolbar = mapEditPanel.getMoveToolBar();
      moveToolbar.setFloatable(false);
      // toolbar.remove("setReference");

      JPanel toolbar = new JPanel();
      List localMaps = maps;
      if (localMaps == null) {
        localMaps = getDefaultMaps();
      }
      JMenu mapMenu = new JMenu("Maps");
      JMenuBar menuHolder = new JMenuBar();
      menuHolder.setBorder(null);
      menuHolder.add(mapMenu);
      toolbar.add(menuHolder);
      for (int mapIdx = 0; mapIdx < localMaps.size(); mapIdx++) {
        final MapData mapData = (MapData) localMaps.get(mapIdx);
        final JCheckBoxMenuItem cbx =
            new JCheckBoxMenuItem(mapData.getDescription(), mapData.getVisible());
        if (mapData.getVisible()) {
          toggleMap(mapData, true);
        }
        mapMenu.add(cbx);
        cbx.addItemListener(
            new ItemListener() {
              public void itemStateChanged(ItemEvent event) {
                toggleMap(mapData, cbx.isSelected());
              }
            });
      }
      GuiUtils.limitMenuSize(mapMenu, "Maps ", 20);

      toolbar.add(navToolbar);
      toolbar.add(moveToolbar);

      JPanel mapSide = new JPanel();
      mapSide.setLayout(new BorderLayout());
      TitledBorder mapBorder =
          new TitledBorder(
              standardBorder, "Edit Projection", TitledBorder.ABOVE_TOP, TitledBorder.CENTER);
      mapSide.setBorder(mapBorder);
      mapSide.add(toolbar, BorderLayout.NORTH);
      mapSide.add(mapEditPanel, BorderLayout.CENTER);
      mainPanel.add(mapSide, BorderLayout.WEST);

      // the projection parameters

      // the Projection name
      JLabel nameLabel = GuiUtils.rLabel("Name: ");
      nameTF = new JTextField(20);

      // the list of Projection classes is kept in a comboBox
      typeLabel = GuiUtils.rLabel("Type: ");
      projClassCB = new JComboBox();
      // standard list of projection classes
      List classNames = getDefaultProjections();
      for (int i = 0; i < classNames.size(); i++) {
        String className = (String) classNames.get(i);
        try {
          projClassCB.addItem(new ProjectionClass(className));
        } catch (ClassNotFoundException ee) {
          System.err.println("ProjectionManager failed on " + className + " " + ee);
        } catch (IntrospectionException ee) {
          System.err.println("ProjectionManager failed on " + className + " " + ee);
        }
      }
      GuiUtils.tmpInsets = new Insets(4, 4, 4, 4);
      JPanel topPanel =
          GuiUtils.doLayout(
              new Component[] {nameLabel, nameTF, typeLabel, projClassCB},
              2,
              GuiUtils.WT_N,
              GuiUtils.WT_N);

      // the Projection parameter area
      paramPanel = new JPanel();
      paramPanel.setLayout(new BorderLayout());
      paramPanel.setBorder(
          new TitledBorder(
              standardBorder,
              "Projection Parameters",
              TitledBorder.ABOVE_TOP,
              TitledBorder.CENTER));

      // the bottom button panel
      JPanel buttPanel = new JPanel();
      JButton acceptButton = new JButton("Save");
      JButton previewButton = new JButton("Preview");
      JButton cancelButton = new JButton("Cancel");
      buttPanel.add(acceptButton, null);
      buttPanel.add(previewButton, null);
      buttPanel.add(cancelButton, null);

      JPanel mainBox = GuiUtils.topCenterBottom(topPanel, paramPanel, buttPanel);
      mainPanel.add(mainBox, BorderLayout.CENTER);
      pack();

      // enable event listeners when we're done constructing the UI
      projClassCB.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              ProjectionClass selectClass = (ProjectionClass) projClassCB.getSelectedItem();
              setProjection(selectClass.makeDefaultProjection());
            }
          });

      acceptButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              accept();
            }
          });
      previewButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              ProjectionClass projClass = findProjectionClass(editProjection);
              if (null != projClass) {
                setProjFromDialog(projClass, editProjection);
                setProjection(editProjection);
              }
            }
          });
      cancelButton.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
              NewProjectionDialog.this.setVisible(false);
            }
          });
    }
コード例 #8
0
ファイル: EditorLite.java プロジェクト: adamdunson/EditorLite
  /** Creates the EditorLite object and displays the GUI with an empty editor pane. */
  public EditorLite() {
    /* Scrollable Text Panes */
    // create some text areas
    // these are dimensionless to let the layout handle it
    editor = new JTextArea();
    editor.setLineWrap(true);
    editor.setWrapStyleWord(true);
    editor.addKeyListener(this);
    side = new JTextArea();
    side.setLineWrap(true);
    side.setEditable(false);

    // create the scroll panes (to house the text areas)
    editorPane = new JScrollPane(editor);
    sidePane = new JScrollPane(side);

    centerPanel = new JPanel(new GridLayout(1, 2));
    centerPanel.add(editorPane);
    centerPanel.add(sidePane);

    /* Button Panel */
    // create the buttonPanel
    buttonPanel = new JPanel(new FlowLayout());

    // create the buttons
    fileChooserButton = new JButton("Open File");
    sideButton = new JButton("Copy to Side Pane");

    // add action listeners to the buttons
    fileChooserButton.addActionListener(this);
    sideButton.addActionListener(this);

    // add the buttons to the buttonPanel
    buttonPanel.add(fileChooserButton);
    buttonPanel.add(sideButton);

    /* Menu Bar */
    // create a menu bar
    menuBar = new JMenuBar();

    // create menus to add to the menu bar
    // also setup mnemonics for keyboard access
    fileMenu = new JMenu("File");
    editMenu = new JMenu("Edit");
    formatMenu = new JMenu("Format");
    viewMenu = new JMenu("View");
    helpMenu = new JMenu("Help");

    fileMenu.setMnemonic(KeyEvent.VK_F);
    editMenu.setMnemonic(KeyEvent.VK_E);
    formatMenu.setMnemonic(KeyEvent.VK_O);
    viewMenu.setMnemonic(KeyEvent.VK_V);
    helpMenu.setMnemonic(KeyEvent.VK_H);

    fileMenu.setDisplayedMnemonicIndex(0);
    editMenu.setDisplayedMnemonicIndex(0);
    formatMenu.setDisplayedMnemonicIndex(1);
    viewMenu.setDisplayedMnemonicIndex(0);
    helpMenu.setDisplayedMnemonicIndex(0);

    // create menu items to add to the menus
    // also setup mnemonics for keyboard access
    // note: \u2026 is a unicode ellipsis (ie, '...')
    newFile = new JMenuItem("New", KeyEvent.VK_N);
    open = new JMenuItem("Open\u2026", KeyEvent.VK_O);
    save = new JMenuItem("Save", KeyEvent.VK_S);
    saveAs = new JMenuItem("Save As\u2026", KeyEvent.VK_A);
    close = new JMenuItem("Exit", KeyEvent.VK_X);
    newFile.setDisplayedMnemonicIndex(0);
    open.setDisplayedMnemonicIndex(0);
    save.setDisplayedMnemonicIndex(0);
    saveAs.setDisplayedMnemonicIndex(5);
    close.setDisplayedMnemonicIndex(1);
    newFile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
    // disable the save JMenuItem by default
    save.setEnabled(false);

    cut = new JMenuItem("Cut", KeyEvent.VK_T);
    copy = new JMenuItem("Copy", KeyEvent.VK_C);
    paste = new JMenuItem("Paste", KeyEvent.VK_P);
    deleteSelected = new JMenuItem("Delete", KeyEvent.VK_L);
    cut.setDisplayedMnemonicIndex(2);
    copy.setDisplayedMnemonicIndex(0);
    paste.setDisplayedMnemonicIndex(0);
    deleteSelected.setDisplayedMnemonicIndex(2);
    cut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
    copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
    paste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
    deleteSelected.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));

    wordWrap = new JCheckBoxMenuItem("Word Wrap", true);
    wordWrap.setMnemonic(KeyEvent.VK_W);
    wordWrap.setDisplayedMnemonicIndex(7);

    toggleSide = new JCheckBoxMenuItem("Side Pane", true);
    toggleSide.setMnemonic(KeyEvent.VK_S);
    toggleSide.setDisplayedMnemonicIndex(7);

    about = new JMenuItem("About " + programName, KeyEvent.VK_A);
    about.setDisplayedMnemonicIndex(0);

    // add action listeners to the menu items
    newFile.addActionListener(this);
    open.addActionListener(this);
    save.addActionListener(this);
    saveAs.addActionListener(this);
    close.addActionListener(this);

    cut.addActionListener(this);
    copy.addActionListener(this);
    paste.addActionListener(this);
    deleteSelected.addActionListener(this);

    wordWrap.addItemListener(this);

    toggleSide.addItemListener(this);

    about.addActionListener(this);

    // add the menu items to the menus
    fileMenu.add(newFile);
    fileMenu.add(open);
    fileMenu.add(save);
    fileMenu.add(saveAs);
    fileMenu.add(close);

    editMenu.add(cut);
    editMenu.add(copy);
    editMenu.add(paste);
    editMenu.add(deleteSelected);

    formatMenu.add(wordWrap);

    viewMenu.add(toggleSide);

    helpMenu.add(about);

    // add the menus to the menu bar
    menuBar.add(fileMenu);
    menuBar.add(editMenu);
    menuBar.add(formatMenu);
    menuBar.add(viewMenu);
    menuBar.add(helpMenu);

    /* Main Frame */
    // initialize
    mainFrame = new JFrame("EditorLite");

    // add the listener for windowClosing event
    mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    mainFrame.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent winEvt) {
            if (isUnsavedFile()) {
              int choice = displayUnsavedWarning();
              if (choice == JOptionPane.YES_OPTION) {
                System.exit(0);
              }
            } else {
              System.exit(0);
            }
          }
        });

    // set up the layout
    mainFrame.setJMenuBar(menuBar);
    mainFrame.add(centerPanel, BorderLayout.CENTER);
    mainFrame.add(buttonPanel, BorderLayout.SOUTH);

    // pack and set a reasonable start size
    mainFrame.pack();
    mainFrame.setSize(600, 400);

    // center the window on the screen
    // basically, it gets the width of the screen, subtracts the width of the frame,
    // and then divides by 2 for the x coordinate
    int xCoord =
        (Toolkit.getDefaultToolkit().getScreenSize().width - mainFrame.getSize().width) / 2;
    // similarly, it gets the height of the screen, subtracts the height of the frame,
    // and then divides by 2 for the y coordinate
    int yCoord =
        (Toolkit.getDefaultToolkit().getScreenSize().height - mainFrame.getSize().height) / 2;
    mainFrame.setLocation(xCoord, yCoord);

    // finally, make it visible
    mainFrame.setVisible(true);
  }