Example usage for java.awt.event InputEvent ALT_MASK

List of usage examples for java.awt.event InputEvent ALT_MASK

Introduction

In this page you can find the example usage for java.awt.event InputEvent ALT_MASK.

Prototype

int ALT_MASK

To view the source code for java.awt.event InputEvent ALT_MASK.

Click Source Link

Document

The Alt key modifier constant.

Usage

From source file:org.pmedv.core.provider.ApplicationMenuBarProviderImpl.java

@SuppressWarnings("unused")
public ApplicationMenuBarProviderImpl() {

    populateKeyTable();//from   ww  w  .  ja  v  a2 s  .c  o m

    menubar = new JMenuBar();

    try {
        JAXBContext c = JAXBContext.newInstance(ApplicationMenubar.class);

        Unmarshaller u = c.createUnmarshaller();

        ApplicationMenubar appMenuBar = (ApplicationMenubar) u
                .unmarshal(getClass().getClassLoader().getResourceAsStream("menus.xml"));

        for (ApplicationMenu currentMenu : appMenuBar.getMenus()) {

            JMenuWithId menu = new JMenuWithId(resources.getResourceByKey(currentMenu.getName()));

            menu.setMnemonic(resources.getResourceByKey(currentMenu.getName()).charAt(0));

            for (ApplicationMenuItem currentItem : currentMenu.getItems()) {

                try {

                    if (currentItem.getActionClass() != null) {

                        if (currentItem.getActionClass().equals("separator")) {
                            menu.addSeparator();
                            continue;
                        }

                        log.info("Mapping action class : " + currentItem.getActionClass());

                        try {

                            AbstractCommand command = null;
                            Class<?> clazz = Class.forName(currentItem.getActionClass());

                            if (currentItem.isBean()) {
                                command = (AbstractCommand) ctx.getBean(clazz);
                            } else {
                                command = (AbstractCommand) clazz.newInstance();
                            }

                            ImageIcon icon = null;
                            String mnemonic = null;
                            String toolTipText = null;

                            if (currentItem.getImageIcon() != null) {

                                InputStream is = getClass().getClassLoader()
                                        .getResourceAsStream(currentItem.getImageIcon());

                                if (is == null) {
                                    is = getClass().getClassLoader()
                                            .getResourceAsStream("icons/noresource_16x16.png");
                                }

                                icon = new ImageIcon(ImageIO.read(is));

                            }
                            if (currentItem.getMnemonic() != null) {
                                mnemonic = currentItem.getMnemonic();
                            }
                            if (currentItem.getToolTipText() != null) {
                                toolTipText = currentItem.getToolTipText();
                            }
                            if (currentItem.getType() != null
                                    && currentItem.getType().equals("ApplicationMenuItemType.CHECKBOX")) {

                                CmdJCheckBoxMenuItem cmdItem = new CmdJCheckBoxMenuItem(currentItem.getName(),
                                        icon, command, mnemonic, toolTipText, null);

                                if (mnemonic != null && currentItem.getModifier() != null) {

                                    if (currentItem.getModifier().equalsIgnoreCase("ctrl")) {
                                        cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic),
                                                InputEvent.CTRL_MASK, false));
                                    } else if (currentItem.getModifier().equalsIgnoreCase("alt")) {
                                        cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic),
                                                InputEvent.ALT_MASK, false));
                                    } else if (currentItem.getModifier().equalsIgnoreCase("shift")) {
                                        cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic),
                                                InputEvent.SHIFT_MASK, false));
                                    }

                                }

                                menu.add(cmdItem);

                            } else {

                                JMenuItem cmdItem = new JMenuItem(command);

                                if (mnemonic != null && currentItem.getModifier() != null) {

                                    if (currentItem.getModifier().equalsIgnoreCase("ctrl")) {
                                        cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic),
                                                InputEvent.CTRL_MASK, false));
                                    } else if (currentItem.getModifier().equalsIgnoreCase("alt")) {
                                        cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic),
                                                InputEvent.ALT_MASK, false));
                                    } else if (currentItem.getModifier().equalsIgnoreCase("shift")) {
                                        cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic),
                                                InputEvent.SHIFT_MASK, false));
                                    }

                                }

                                menu.add(cmdItem);

                            }

                        } catch (InstantiationException e) {
                            log.info("could not instanciate menuitem, skipping.");
                        } catch (IllegalAccessException e) {
                            log.info("could not access menuitem, skipping.");
                        }

                    }

                } catch (ClassNotFoundException e) {
                    log.info("could not find action class " + currentItem.getActionClass());
                }

            }

            if (currentMenu.getType() != null && currentMenu.getType().equalsIgnoreCase("file")) {

                JMenu openRecentMenu = new JMenu(resources.getResourceByKey("menu.recentfiles"));

                RecentFileList fileList = null;

                try {

                    String inputDir = System.getProperty("user.home") + "/." + AppContext.getName() + "/";
                    String inputFileName = "recentFiles.xml";
                    File inputFile = new File(inputDir + inputFileName);

                    if (inputFile.exists()) {
                        Unmarshaller u1 = JAXBContext.newInstance(RecentFileList.class).createUnmarshaller();
                        fileList = (RecentFileList) u1.unmarshal(inputFile);
                    }

                    if (fileList == null)
                        fileList = new RecentFileList();

                    ArrayList<String> recent = fileList.getRecentFiles();
                    Collections.reverse(recent);

                    for (String recentFile : fileList.getRecentFiles()) {
                        File file = new File(recentFile);
                        AbstractCommand openBoardAction = new OpenBoardCommand(file.getName(), file);
                        JMenuItem item = new JMenuItem(openBoardAction);
                        openRecentMenu.add(item);
                    }

                } catch (JAXBException e) {
                    e.printStackTrace();
                }

                menu.addSeparator();
                menu.add(openRecentMenu);

                JMenu openSamplesMenu = createSamplesMenu();

                menu.add(openSamplesMenu);

            }

            menu.setId("common");

            if (currentMenu.getType() != null && !currentMenu.getType().equalsIgnoreCase("help"))
                menubar.add(menu);
            else
                helpMenus.add(menu);

            menubar.setFont(new Font("SansSerif", Font.PLAIN, 12));

        }

        ApplicationPerspectiveProvider perspectiveProvider = ctx.getBean(ApplicationPerspectiveProvider.class);
        ArrayList<ApplicationPerspective> perspectives = perspectiveProvider.getPerspectives();

        JMenuWithId perspectivesMenu = new JMenuWithId("Perspectives");
        perspectivesMenu.setId("common");
        perspectivesMenu.setMnemonic('P');

        for (ApplicationPerspective perspective : perspectives) {

            ImageIcon icon = null;
            String mnemonic = null;
            String toolTipText = null;

            if (perspective.getPerspectiveIcon() != null) {

                InputStream is = getClass().getClassLoader()
                        .getResourceAsStream(perspective.getPerspectiveIcon());

                if (is != null) {
                    icon = new ImageIcon(ImageIO.read(is));
                } else {

                    is = getClass().getClassLoader().getResourceAsStream("icons/noresource_16x16.png");

                    if (is != null)
                        icon = new ImageIcon(ImageIO.read(is));

                }

            }
            if (perspective.getMnemonic() != null) {
                mnemonic = perspective.getMnemonic();
            }
            if (perspective.getToolTipText() != null) {
                toolTipText = perspective.getToolTipText();
            }

            log.info("mapping perspective class " + perspective.getPerspectiveClass());
            OpenPerspectiveCommand command = new OpenPerspectiveCommand(perspective.getId());

            JMenuItem item = new JMenuItem(command);

            if (mnemonic != null && perspective.getModifier() != null) {

                if (perspective.getModifier().equalsIgnoreCase("ctrl")) {
                    item.setAccelerator(
                            KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.CTRL_MASK, false));
                } else if (perspective.getModifier().equalsIgnoreCase("alt")) {
                    item.setAccelerator(
                            KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.ALT_MASK, false));
                } else if (perspective.getModifier().equalsIgnoreCase("shift")) {
                    item.setAccelerator(
                            KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.SHIFT_MASK, false));
                }

            }

            perspectivesMenu.add(item);

            for (ApplicationMenu pMenu : perspective.getMenubarContributions()) {

                JMenuWithId menu = new JMenuWithId(resources.getResourceByKey(pMenu.getName()));

                // if (pMenu.getMnemonic() != null && pMenu.getMnemonic().length() > 0)               
                menu.setMnemonic(resources.getResourceByKey(pMenu.getName()).charAt(0));

                for (ApplicationMenuItem currentItem : pMenu.getItems()) {

                    try {

                        if (currentItem.getActionClass() != null) {

                            if (currentItem.getActionClass().equals("separator")) {
                                menu.addSeparator();
                                continue;
                            }

                            log.info("Mapping action class : " + currentItem.getActionClass());

                            try {

                                AbstractCommand pCommand = null;
                                Class<?> clazz = Class.forName(currentItem.getActionClass());

                                if (currentItem.isBean()) {
                                    pCommand = (AbstractCommand) ctx.getBean(clazz);
                                } else {
                                    pCommand = (AbstractCommand) clazz.newInstance();
                                }

                                ImageIcon pIcon = null;
                                String pMnemonic = null;
                                String pToolTipText = null;

                                if (currentItem.getImageIcon() != null) {

                                    InputStream is = getClass().getClassLoader()
                                            .getResourceAsStream(currentItem.getImageIcon());
                                    pIcon = new ImageIcon(ImageIO.read(is));

                                }
                                if (currentItem.getMnemonic() != null) {
                                    pMnemonic = currentItem.getMnemonic();
                                }
                                if (currentItem.getToolTipText() != null) {
                                    pToolTipText = currentItem.getToolTipText();
                                }

                                if (currentItem.getType() != null
                                        && currentItem.getType().equals("ApplicationMenuItemType.CHECKBOX")) {

                                    log.info(
                                            "Creating menu checkbox for class " + currentItem.getActionClass());

                                    JCheckBoxMenuItem cmdItem = new JCheckBoxMenuItem(pCommand);

                                    if (pMnemonic != null && currentItem.getModifier() != null) {

                                        if (currentItem.getModifier().equalsIgnoreCase("ctrl")) {
                                            cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic),
                                                    InputEvent.CTRL_MASK, false));
                                        } else if (currentItem.getModifier().equalsIgnoreCase("alt")) {
                                            cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic),
                                                    InputEvent.ALT_MASK, false));
                                        } else if (currentItem.getModifier().equalsIgnoreCase("shift")) {
                                            cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic),
                                                    InputEvent.SHIFT_MASK, false));
                                        }

                                    }

                                    menu.add(cmdItem);
                                    cmdItem.setSelected(true);

                                } else {

                                    log.info("Creating menu entry for class " + currentItem.getActionClass());

                                    JMenuItem cmdItem = new JMenuItem(pCommand);

                                    if (pMnemonic != null && currentItem.getModifier() != null) {

                                        if (currentItem.getModifier().equalsIgnoreCase("ctrl")) {
                                            cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic),
                                                    InputEvent.CTRL_MASK, false));
                                        } else if (currentItem.getModifier().equalsIgnoreCase("alt")) {
                                            cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic),
                                                    InputEvent.ALT_MASK, false));
                                        } else if (currentItem.getModifier().equalsIgnoreCase("shift")) {
                                            cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic),
                                                    InputEvent.SHIFT_MASK, false));
                                        }

                                    }

                                    menu.add(cmdItem);

                                }

                            } catch (InstantiationException e) {
                                log.info("could not instanciate menuitem, skipping.");
                            } catch (IllegalAccessException e) {
                                log.info("could not access menuitem, skipping.");
                            }

                        }

                    } catch (ClassNotFoundException e) {
                        log.info("could not find action class " + currentItem.getActionClass());
                    }

                }

                menu.setId(perspective.getId());
                menu.setVisible(false);

                menubar.add(menu);

            }

        }

        if (perspectiveProvider.getPerspectives().size() > 1) {
            menubar.add(perspectivesMenu);
        }

        for (JMenuWithId helpmenu : helpMenus) {
            menubar.add(helpmenu);
        }

        menubar.setFont(new Font("SansSerif", Font.PLAIN, 12));

    } catch (JAXBException e) {
        log.info("could not deserialize menus.");
        throw new RuntimeException("could not deserialize menus.");
    } catch (IOException e) {
        log.info("could not load menus.");
        throw new RuntimeException("could not load menus.");
    }

}

From source file:net.sf.firemox.DeckBuilder.java

/**
 * Creates new form DeckBuilder/*w w w .jav a 2  s.c  om*/
 */
private DeckBuilder() {
    super("DeckBuilder");
    form = this;
    timerPanel = new TimerGlassPane();
    cardLoader = new CardLoader(timerPanel);
    timer = new Timer(200, cardLoader);
    setGlassPane(timerPanel);
    try {
        setIconImage(Picture.loadImage(IdConst.IMAGES_DIR + "deckbuilder.gif"));
    } catch (Exception e) {
        // IGNORING
    }

    // Load settings
    loadSettings();

    // Initialize components
    final JMenuItem newItem = UIHelper.buildMenu("menu_db_new", 'n', this);
    newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));

    final JMenuItem loadItem = UIHelper.buildMenu("menu_db_load", 'o', this);
    loadItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));

    final JMenuItem saveAsItem = UIHelper.buildMenu("menu_db_saveas", 'a', this);
    saveAsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0));

    final JMenuItem saveItem = UIHelper.buildMenu("menu_db_save", 's', this);
    saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));

    final JMenuItem quitItem = UIHelper.buildMenu("menu_db_exit", this);
    quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK));

    final JMenuItem deckConstraintsItem = UIHelper.buildMenu("menu_db_constraints", 'c', this);
    deckConstraintsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0));

    final JMenuItem aboutItem = UIHelper.buildMenu("menu_help_about", 'a', this);
    aboutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, InputEvent.SHIFT_MASK));

    final JMenuItem convertDCK = UIHelper.buildMenu("menu_convert_DCK_MP", this);

    final JMenu mainMenu = UIHelper.buildMenu("menu_file");
    mainMenu.add(newItem);
    mainMenu.add(loadItem);
    mainMenu.add(saveAsItem);
    mainMenu.add(saveItem);
    mainMenu.add(new JSeparator());
    mainMenu.add(quitItem);

    super.optionMenu = new JMenu("Options");

    final JMenu convertMenu = UIHelper.buildMenu("menu_convert");
    convertMenu.add(convertDCK);

    final JMenuItem helpItem = UIHelper.buildMenu("menu_help_help", 'h', this);
    helpItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));

    final JMenu helpMenu = new JMenu("?");
    helpMenu.add(helpItem);
    helpMenu.add(deckConstraintsItem);
    helpMenu.add(aboutItem);

    final JMenuBar menuBar = new JMenuBar();
    menuBar.add(mainMenu);
    initAbstractMenu();
    menuBar.add(optionMenu);
    menuBar.add(convertMenu);
    menuBar.add(helpMenu);
    setJMenuBar(menuBar);
    addWindowListener(this);

    // Build the panel containing amount of available cards
    final JLabel amountLeft = new JLabel("<html>0/?", SwingConstants.RIGHT);

    // Build the left list
    allListModel = new MListModel<MCardCompare>(amountLeft, false);
    leftList = new ThreadSafeJList(allListModel);
    leftList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    leftList.setLayoutOrientation(JList.VERTICAL);
    leftList.getSelectionModel().addListSelectionListener(this);
    leftList.addMouseListener(this);
    leftList.setVisibleRowCount(10);

    // Initialize the text field containing the amount to add
    addQtyTxt = new JTextField("1");

    // Build the "Add" button
    addButton = new JButton(LanguageManager.getString("db_add"));
    addButton.setMnemonic('a');
    addButton.setEnabled(false);

    // Build the panel containing : "Add" amount and "Add" button
    final Box addPanel = Box.createHorizontalBox();
    addPanel.add(addButton);
    addPanel.add(addQtyTxt);
    addPanel.setMaximumSize(new Dimension(32010, 26));

    // Build the panel containing the selected card name
    cardNameTxt = new JTextField();
    new HireListener(cardNameTxt, addButton, this, leftList);

    final JLabel searchLabel = new JLabel(LanguageManager.getString("db_search") + " : ");
    searchLabel.setLabelFor(cardNameTxt);

    // Build the panel containing search label and card name text field
    final Box searchPanel = Box.createHorizontalBox();
    searchPanel.add(searchLabel);
    searchPanel.add(cardNameTxt);
    searchPanel.setMaximumSize(new Dimension(32010, 26));

    listScrollerLeft = new JScrollPane(leftList);
    MToolKit.addOverlay(listScrollerLeft);

    // Build the left panel containing : list, available amount, "Add" panel
    final JPanel srcPanel = new JPanel(null);
    srcPanel.add(searchPanel);
    srcPanel.add(listScrollerLeft);
    srcPanel.add(amountLeft);
    srcPanel.add(addPanel);
    srcPanel.setMinimumSize(new Dimension(220, 200));
    srcPanel.setLayout(new BoxLayout(srcPanel, BoxLayout.Y_AXIS));

    // Initialize constraints
    constraintsChecker = new ConstraintsChecker();
    constraintsChecker.setBorder(new EtchedBorder());
    final JScrollPane constraintsCheckerScroll = new JScrollPane(constraintsChecker);
    MToolKit.addOverlay(constraintsCheckerScroll);

    // create a pane with the oracle text for the present card
    oracleText = new JLabel();
    oracleText.setPreferredSize(new Dimension(180, 200));
    oracleText.setVerticalAlignment(SwingConstants.TOP);

    final JScrollPane oracle = new JScrollPane(oracleText, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    MToolKit.addOverlay(oracle);

    // build some Pie Charts and a panel to display it
    initSets();
    datasets = new ChartSets();
    final JTabbedPane tabbedPane = new JTabbedPane();
    for (ChartFilter filter : ChartFilter.values()) {
        final Dataset dataSet = filter.createDataSet(this);
        final JFreeChart chart = new JFreeChart(null, null,
                filter.createPlot(dataSet, painterMapper.get(filter)), false);
        datasets.addDataSet(filter, dataSet);
        ChartPanel pieChartPanel = new ChartPanel(chart, true);
        tabbedPane.add(pieChartPanel, filter.getTitle());
    }
    // add the Constraints scroll panel and Oracle text Pane to the tabbedPane
    tabbedPane.add(constraintsCheckerScroll, LanguageManager.getString("db_constraints"));
    tabbedPane.add(oracle, LanguageManager.getString("db_text"));
    tabbedPane.setSelectedComponent(oracle);

    // The toollBar for color filtering
    toolBar = new JToolBar();
    toolBar.setFloatable(false);
    final JButton clearButton = UIHelper.buildButton("clear");
    clearButton.addActionListener(this);
    toolBar.add(clearButton);
    final JToggleButton toggleColorlessButton = new JToggleButton(
            UIHelper.getTbsIcon("mana/colorless/small/" + MdbLoader.unknownSmlMana), true);
    toggleColorlessButton.setActionCommand("0");
    toggleColorlessButton.addActionListener(this);
    toolBar.add(toggleColorlessButton);
    for (int index = 1; index < IdCardColors.CARD_COLOR_NAMES.length; index++) {
        final JToggleButton toggleButton = new JToggleButton(
                UIHelper.getTbsIcon("mana/colored/small/" + MdbLoader.coloredSmlManas[index]), true);
        toggleButton.setActionCommand(String.valueOf(index));
        toggleButton.addActionListener(this);
        toolBar.add(toggleButton);
    }

    // sorted card type combobox creation
    final List<String> idCards = new ArrayList<String>(Arrays.asList(CardFactory.exportedIdCardNames));
    Collections.sort(idCards);
    final Object[] cardTypes = ArrayUtils.addAll(new String[] { LanguageManager.getString("db_types.any") },
            idCards.toArray());
    idCardComboBox = new JComboBox(cardTypes);
    idCardComboBox.setSelectedIndex(0);
    idCardComboBox.addActionListener(this);
    idCardComboBox.setActionCommand("cardTypeFilter");

    // sorted card properties combobox creation
    final List<String> properties = new ArrayList<String>(
            CardFactory.getPropertiesName(DeckConstraints.getMinProperty(), DeckConstraints.getMaxProperty()));
    Collections.sort(properties);
    final Object[] cardProperties = ArrayUtils
            .addAll(new String[] { LanguageManager.getString("db_properties.any") }, properties.toArray());
    propertiesComboBox = new JComboBox(cardProperties);
    propertiesComboBox.setSelectedIndex(0);
    propertiesComboBox.addActionListener(this);
    propertiesComboBox.setActionCommand("propertyFilter");

    final JLabel colors = new JLabel(" " + LanguageManager.getString("colors") + " : ");
    final JLabel types = new JLabel(" " + LanguageManager.getString("types") + " : ");
    final JLabel property = new JLabel(" " + LanguageManager.getString("properties") + " : ");

    // filter Panel with colors toolBar and card type combobox
    final Box filterPanel = Box.createHorizontalBox();
    filterPanel.add(colors);
    filterPanel.add(toolBar);
    filterPanel.add(types);
    filterPanel.add(idCardComboBox);
    filterPanel.add(property);
    filterPanel.add(propertiesComboBox);

    getContentPane().add(filterPanel, BorderLayout.NORTH);

    // Destination section :

    // Build the panel containing amount of available cards
    final JLabel rightAmount = new JLabel("0/?", SwingConstants.RIGHT);
    rightAmount.setMaximumSize(new Dimension(220, 26));

    // Build the right list
    rightListModel = new MCardTableModel(new MListModel<MCardCompare>(rightAmount, true));
    rightListModel.addTableModelListener(this);
    rightList = new JTable(rightListModel);
    rightList.setShowGrid(false);
    rightList.setTableHeader(null);
    rightList.getSelectionModel().addListSelectionListener(this);
    rightList.getColumnModel().getColumn(0).setMaxWidth(25);
    rightList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

    // Build the panel containing the selected deck
    deckNameTxt = new JTextField("loading...");
    deckNameTxt.setEditable(false);
    deckNameTxt.setBorder(null);
    final JLabel deckLabel = new JLabel(LanguageManager.getString("db_deck") + " : ");
    deckLabel.setLabelFor(deckNameTxt);
    final Box deckNamePanel = Box.createHorizontalBox();
    deckNamePanel.add(deckLabel);
    deckNamePanel.add(deckNameTxt);
    deckNamePanel.setMaximumSize(new Dimension(220, 26));

    // Initialize the text field containing the amount to remove
    removeQtyTxt = new JTextField("1");

    // Build the "Remove" button
    removeButton = new JButton(LanguageManager.getString("db_remove"));
    removeButton.setMnemonic('r');
    removeButton.addMouseListener(this);
    removeButton.setEnabled(false);

    // Build the panel containing : "Remove" amount and "Remove" button
    final Box removePanel = Box.createHorizontalBox();
    removePanel.add(removeButton);
    removePanel.add(removeQtyTxt);
    removePanel.setMaximumSize(new Dimension(220, 26));

    // Build the right panel containing : list, available amount, constraints
    final JScrollPane deskListScroller = new JScrollPane(rightList);
    MToolKit.addOverlay(deskListScroller);
    deskListScroller.setBorder(BorderFactory.createLineBorder(Color.GRAY));
    deskListScroller.setMinimumSize(new Dimension(220, 200));
    deskListScroller.setMaximumSize(new Dimension(220, 32000));

    final Box destPanel = Box.createVerticalBox();
    destPanel.add(deckNamePanel);
    destPanel.add(deskListScroller);
    destPanel.add(rightAmount);
    destPanel.add(removePanel);
    destPanel.setMinimumSize(new Dimension(220, 200));
    destPanel.setMaximumSize(new Dimension(220, 32000));

    // Build the panel containing the name of card in picture
    cardPictureNameTxt = new JLabel("<html><i>no selected card</i>");
    final Box cardPictureNamePanel = Box.createHorizontalBox();
    cardPictureNamePanel.add(cardPictureNameTxt);
    cardPictureNamePanel.setMaximumSize(new Dimension(32010, 26));

    // Group the detail panels
    final JPanel viewCard = new JPanel(null);
    viewCard.add(cardPictureNamePanel);
    viewCard.add(CardView.getInstance());
    viewCard.add(tabbedPane);
    viewCard.setLayout(new BoxLayout(viewCard, BoxLayout.Y_AXIS));

    final Box mainPanel = Box.createHorizontalBox();
    mainPanel.add(destPanel);
    mainPanel.add(viewCard);

    // Add the main panel
    getContentPane().add(srcPanel, BorderLayout.WEST);
    getContentPane().add(mainPanel, BorderLayout.CENTER);

    // Size this frame
    getRootPane().setPreferredSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
    getRootPane().setMinimumSize(getRootPane().getPreferredSize());
    pack();
}

From source file:org.jcurl.demo.tactics.old.ActionRegistry.java

KeyStroke findAccelerator(final String acc) {
    if (acc == null || "".equals(acc))
        return null;
    final Matcher m = KeyPat.matcher(acc);
    if (m.matches()) {
        int modifiers = 0;
        {/*from  w w  w .  jav  a 2s .  c  om*/
            final String gr = m.group(1);
            if (!"".equals(gr)) {
                final String[] mod = gr.split("-");
                for (final String mm : mod)
                    if ("CTRL".equals(mm))
                        modifiers |= InputEvent.CTRL_MASK;
                    else if ("ALT".equals(mm))
                        modifiers |= InputEvent.ALT_MASK;
                    else if ("SHIFT".equals(mm))
                        modifiers |= InputEvent.SHIFT_MASK;
                    else
                        throw new IllegalStateException(mm);
            }
        }
        if (m.group(2).length() == 1)
            return KeyStroke.getKeyStroke(m.group(2).charAt(0), modifiers);
        final Integer kc = str2key.get(m.group(2));
        if (kc == null)
            throw new IllegalStateException(m.group(2));
        return KeyStroke.getKeyStroke(kc.intValue(), modifiers);
    } else {
        // swing syntax
        final KeyStroke k = KeyStroke.getKeyStroke(acc);
        if (k == null)
            throw new IllegalArgumentException(acc);
        return k;
    }
}

From source file:com.projity.pm.graphic.views.GanttView.java

public void init(ReferenceNodeModelCache cache, NodeModel model, CoordinatesConverter coord) {
    this.coord = coord;
    this.cache = NodeModelCacheFactory.getInstance().createFilteredCache((ReferenceNodeModelCache) cache,
            getViewName(), null);// www  . j a va  2 s.  c  om

    fieldContext = new FieldContext();
    fieldContext.setLeftAssociation(true);
    /*cellStyle=new CellStyle(){
       CellFormat cellProperties=new CellFormat();
       public CellFormat getCellProperties(GraphicNode node){
    cellProperties.setBold(node.isSummary());
    cellProperties.setItalic(node.isAssignment());
    //cellProperties.setBackground((node.isAssignment())?"NORMAL_LIGHT_YELLOW":"NORMAL_YELLOW");
    cellProperties.setCompositeIcon(node.isComposite());
    return cellProperties;
       }
            
    };*/
    super.init();
    updateHeight(project);
    updateSize();

    //sync the height of spreadsheet and gantt
    leftScrollPane.getViewport().addChangeListener(new ChangeListener() {
        private Dimension olddl = null;

        public void stateChanged(ChangeEvent e) {
            Dimension dl = leftScrollPane.getViewport().getViewSize();
            if (dl.equals(olddl))
                return;
            olddl = dl;
            //            Dimension dr=rightScrollPane.getViewport().getViewSize();
            //            ((Gantt)rightScrollPane.getViewport().getView()).setPreferredSize(new Dimension((int)dr.getWidth(),(int)dl.getHeight()));
            //            rightScrollPane.getViewport().revalidate();
            ((Gantt) rightScrollPane.getViewport().getView()).setPreferredSize(
                    new Dimension(rightScrollPane.getViewport().getViewSize().width, dl.height));
        }
    });

    //TODO automatic scrolling to add as an option
    //      spreadSheet.getRowHeader().getSelectionModel().addListSelectionListener(new ListSelectionListener(){
    //         public void valueChanged(ListSelectionEvent e) {
    //            if (!e.getValueIsAdjusting()&&spreadSheet.getRowHeader().getSelectedRowCount()==1){
    //               List impls=spreadSheet.getSelectedNodesImpl();
    //               if (impls.size()!=1) return;
    //               Object impl=impls.get(0);
    //               if (!(impl instanceof HasStartAndEnd)) return;
    //               HasStartAndEnd interval=(HasStartAndEnd)impl;
    //               gantt.scrollToTask(interval, true);
    //            }
    //         }
    //      });

    MouseWheelListener scrollManager = new MouseWheelListener() {
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (0 != (e.getModifiers() & InputEvent.ALT_MASK)) {
                Component c = e.getComponent();
                while ((c != null) && !(c instanceof JViewport))
                    c = c.getParent();
                JViewport vp = (JViewport) c;
                Point p = vp.getViewPosition();
                int newX = p.x + e.getUnitsToScroll() * getWidth() / 20;
                if (newX > 0) {
                    p.x = newX;
                } else {
                    p.x = 0;
                }
                vp.setViewPosition(p);
            } else if (0 != (e.getModifiers() & InputEvent.CTRL_MASK)) {
                zoom(-e.getUnitsToScroll() / 3);
            } else {
                //Vertical scroll allways on gantt chart
                JViewport vp = (JViewport) gantt.getParent();
                Point p = vp.getViewPosition();

                int newY = p.y + e.getUnitsToScroll() * gantt.getRowHeight();
                if (newY > 0) {
                    p.y = newY;
                } else {
                    p.y = 0;
                }
                vp.setViewPosition(p);
            }
        }
    };

    leftScrollPane.getViewport().addMouseWheelListener(scrollManager);

    gantt.addMouseWheelListener(scrollManager);

    cache.update();

    //Call this last to be sure everything is initialized
    //gantt.insertCacheData(); //useless?

}

From source file:org.eclipse.jubula.rc.common.driver.KeyTyper.java

/**
 * @param keyStroke KeyStroke whose modifiers are requested
 * @return a List of KeyCodes (hopefully) realising the ModifierMask contained in the KeyStroke
 *///  ww w .jav a 2 s  . c o m
private List modifierKeyCodes(KeyStroke keyStroke) {
    List l = new LinkedList();
    int modifiers = keyStroke.getModifiers();
    // this is jdk 1.3 - code.
    // use ALT_DOWN_MASK instead etc. with jdk 1.4 !
    if ((modifiers & InputEvent.ALT_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_ALT));
    }
    if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_ALT_GRAPH));
    }
    if ((modifiers & InputEvent.CTRL_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_CONTROL));
    }
    if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_SHIFT));
    }
    if ((modifiers & InputEvent.META_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_META));
    }
    return l;
}

From source file:com.googlecode.bpmn_simulator.gui.BPMNSimulatorFrame.java

private JMenu createMenuFile() {
    final JMenu menuFile = new JMenu(Messages.getString("Menu.file")); //$NON-NLS-1$

    final JMenuItem menuFileOpen = new JMenuItem(Messages.getString("Menu.fileOpen")); //$NON-NLS-1$
    menuFileOpen.setMnemonic(KeyEvent.VK_O);
    menuFileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.ALT_MASK));
    menuFileOpen.addActionListener(new ActionListener() {
        @Override//w  w  w  . j av a  2  s .co  m
        public void actionPerformed(final ActionEvent e) {
            openFile();
        }
    });
    menuFile.add(menuFileOpen);
    menuFile.add(menuFileRecent);

    final JMenuItem menuFileReload = new JMenuItem(Messages.getString("Menu.fileReload")); //$NON-NLS-1$
    menuFileReload.setMnemonic(KeyEvent.VK_R);
    menuFileReload.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_MASK));
    menuFileReload.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            reloadDefinition();
        }
    });
    menuFile.add(menuFileReload);

    final JMenuItem menuFileClose = new JMenuItem(Messages.getString("Menu.fileClose")); //$NON-NLS-1$
    menuFileClose.setMnemonic(KeyEvent.VK_C);
    menuFileClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK));
    menuFileClose.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            closeSource();
        }
    });
    menuFile.add(menuFileClose);

    menuFile.addSeparator();

    final JMenuItem menuFileProperties = new JMenuItem(Messages.getString("Menu.properties")); //$NON-NLS-1$
    menuFileProperties.setMnemonic(KeyEvent.VK_P);
    menuFileProperties.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_MASK));
    menuFileProperties.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showPropertiesDialog();
        }
    });
    menuFile.add(menuFileProperties);

    menuFile.addSeparator();

    final JMenuItem menuFileExport = createMenuFileExport();
    menuFile.add(menuFileExport);

    menuFile.addSeparator();

    final JMenuItem menuFilePreferences = new JMenuItem(Messages.getString("Menu.preferences")); //$NON-NLS-1$
    menuFilePreferences.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showPreferencesDialog();
        }
    });
    menuFile.add(menuFilePreferences);

    menuFile.addSeparator();

    final JMenuItem menuFileExit = new JMenuItem(Messages.getString("Menu.exit")); //$NON-NLS-1$
    menuFileExit.setMnemonic(KeyEvent.VK_E);
    menuFileExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK));
    menuFileExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            for (Frame frame : getFrames()) {
                if (frame.isActive()) {
                    frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
                }
            }
        }
    });
    menuFile.add(menuFileExit);

    menuFile.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(final MenuEvent e) {
            menuFileReload.setEnabled(isSourceOpen() && currentSource.canReopen());
            menuFileClose.setEnabled(isSourceOpen());
            menuFileProperties.setEnabled(isDefinitionOpen());
            menuFileExport.setEnabled(isDefinitionOpen());
        }

        @Override
        public void menuDeselected(final MenuEvent e) {
        }

        @Override
        public void menuCanceled(final MenuEvent e) {
        }
    });

    return menuFile;
}

From source file:uk.ac.abdn.csd.p2p.server.ServerGUI.java

/**
 * This method prepares all the graphical components that are contained with P2P Visualisation Server.
 *//*from  w ww. j a  v  a 2 s . c om*/
// <editor-fold defaultstate="collapsed" desc="...GUI">
private void initializeComponent() {
    listeningPort = 0;

    JFrame frame = new JFrame();
    BorderLayout layout = new BorderLayout();

    //create a graph
    overlay = new UndirectedSparseGraph<Vertex, Edge>();
    ObservableGraph<Vertex, Edge> og = new ObservableGraph<Vertex, Edge>(overlay);
    /*   og.addGraphEventListener(new GraphEventListener<Vertex, Edge>() {
       @Override
       public void handleGraphEvent(
       GraphEvent<Vertex, Edge> evt) {
    System.err.println("got " + evt);
            
       }
    });*/
    this.overlay = og;
    layout1 = new FRLayout2<Vertex, Edge>(overlay);
    vv = new VisualizationViewer<Vertex, Edge>(layout1, new Dimension(700, 200));
    vv.setGraphMouse(new DefaultModalGraphMouse<Vertex, Edge>());
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Vertex>());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<Edge>());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
    vv.getRenderContext().setVertexFillPaintTransformer(new VertexPainter());

    DefaultModalGraphMouse gm1 = new DefaultModalGraphMouse();
    gm1.setMode(ModalGraphMouse.Mode.TRANSFORMING);
    gm1.setMode(ModalGraphMouse.Mode.PICKING);
    gm1.add(new MyPopupGraphMousePlugin());
    vv.setGraphMouse(gm1);
    vv.addKeyListener(gm1.getModeKeyListener());

    contentPane = new JPanel(layout);

    displayPanel = new javax.swing.JPanel();

    consoleTextArea = new JTextArea();
    jScrollPane2 = new JScrollPane();
    clearButton = new JButton();
    consolePanel = new JPanel();
    clearButton = new javax.swing.JButton();

    nodeTextArea = new JTextArea();
    jScrollPane1 = new JScrollPane();
    nodePanel = new JPanel();

    linkTextArea = new JTextArea();
    jScrollPane3 = new JScrollPane();
    linkPanel = new JPanel();

    menuBar = new javax.swing.JMenuBar();
    serverMenu = new javax.swing.JMenu();
    startServerMenuItem = new javax.swing.JMenuItem();
    jSeparator1 = new javax.swing.JPopupMenu.Separator();
    exitMenuItem = new javax.swing.JMenuItem();
    editMenu = new javax.swing.JMenu();
    settingMenuItem = new javax.swing.JMenuItem();
    colorSettingMenuItem = new javax.swing.JMenuItem();
    toolMenuItem = new javax.swing.JMenu();
    clearMenuItem = new javax.swing.JMenuItem();
    helpMenu = new javax.swing.JMenu();
    aboutMenuItem = new javax.swing.JMenuItem();
    zoominMenuItem = new javax.swing.JMenuItem();
    zoomoutMenuItem = new javax.swing.JMenuItem();
    layoutSettingMenuItem = new javax.swing.JMenuItem();
    labelPositionMenuItem = new javax.swing.JMenuItem();
    speedSettingMenuItem = new javax.swing.JMenuItem();
    topologySettingMenuItem = new javax.swing.JMenuItem();
    findNodeMenuItem = new javax.swing.JMenuItem();

    serverMenu.setText("Server");
    serverMenu.setToolTipText("Server");

    startServerMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C,
            java.awt.event.InputEvent.ALT_MASK));
    startServerMenuItem.setText("Start Server");
    startServerMenuItem.setToolTipText("Start Server");
    startServerMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            startServerMenuItemActionPerformed(evt);
        }
    });
    serverMenu.add(startServerMenuItem);
    serverMenu.add(jSeparator1);

    exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X,
            java.awt.event.InputEvent.ALT_MASK));
    exitMenuItem.setText("Exit");
    exitMenuItem.setToolTipText("Exit");
    exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            exitMenuItemActionPerformed(evt);
        }
    });
    serverMenu.add(exitMenuItem);

    menuBar.add(serverMenu);

    editMenu.setText("Edit");
    editMenu.setToolTipText("Edit");

    settingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S,
            java.awt.event.InputEvent.ALT_MASK));
    settingMenuItem.setText("Server Settings");
    settingMenuItem.setToolTipText("Server Settings");
    settingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            settingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(settingMenuItem);

    colorSettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M,
            java.awt.event.InputEvent.ALT_MASK));
    colorSettingMenuItem.setText("Colour Settings");
    colorSettingMenuItem.setToolTipText("Colour Settings");
    colorSettingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            colorSettingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(colorSettingMenuItem);

    layoutSettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L,
            java.awt.event.InputEvent.ALT_MASK));
    layoutSettingMenuItem.setText("Layout Settings");
    layoutSettingMenuItem.setToolTipText("Layout Settings");
    layoutSettingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            layoutSettingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(layoutSettingMenuItem);

    speedSettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V,
            java.awt.event.InputEvent.ALT_MASK));
    speedSettingMenuItem.setText("Speed Settings");
    speedSettingMenuItem.setToolTipText("Speed Settings");
    speedSettingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            speedSettingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(speedSettingMenuItem);

    topologySettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T,
            java.awt.event.InputEvent.ALT_MASK));
    topologySettingMenuItem.setText("Topology Settings");
    topologySettingMenuItem.setToolTipText("Topology Settings");
    topologySettingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            topologySettingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(topologySettingMenuItem);

    menuBar.add(editMenu);

    toolMenuItem.setText("Tools");
    toolMenuItem.setToolTipText("Tools");

    labelPositionMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P,
            java.awt.event.InputEvent.ALT_MASK));
    labelPositionMenuItem.setText("Vertex Label Position");
    labelPositionMenuItem.setToolTipText("Vertex Label Position");
    toolMenuItem.add(labelPositionMenuItem);
    labelPositionMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            labelPositionMenuItemActionPerformed(evt);

        }
    });

    final ScalingControl scaler = new CrossoverScalingControl();

    zoominMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I,
            java.awt.event.InputEvent.ALT_MASK));
    zoominMenuItem.setText("Zoom-In");
    zoominMenuItem.setToolTipText("Zoom-In");
    toolMenuItem.add(zoominMenuItem);
    zoominMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    zoomoutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O,
            java.awt.event.InputEvent.ALT_MASK));
    zoomoutMenuItem.setText("Zoom-Out");
    zoomoutMenuItem.setToolTipText("Zoom-Out");
    toolMenuItem.add(zoomoutMenuItem);
    zoomoutMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            scaler.scale(vv, 0.9f, vv.getCenter());
        }
    });

    findNodeMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F,
            java.awt.event.InputEvent.ALT_MASK));
    findNodeMenuItem.setText("Find Node on Overlay");
    findNodeMenuItem.setToolTipText("Find Node");
    toolMenuItem.add(findNodeMenuItem);
    findNodeMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            findNodeMenuItemMenuItemActionPerformed(evt);
        }
    });

    menuBar.add(toolMenuItem);

    helpMenu.setText("Help");
    helpMenu.setToolTipText("Help");

    aboutMenuItem.setText("About");
    aboutMenuItem.setToolTipText("About");
    aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            aboutMenuItemActionPerformed(evt);
        }
    });
    helpMenu.add(aboutMenuItem);

    menuBar.add(helpMenu);

    displayPanel.setLayout(new BorderLayout());
    displayPanel.setBorder(new TitledBorder("P2P Overlay"));
    displayPanel.add(vv);
    validate();
    //
    // nodeTextArea
    //
    nodeTextArea.setEditable(false);
    nodeTextArea.setLineWrap(true);

    //
    // jScrollPane1
    //
    jScrollPane1.setViewportView(nodeTextArea);
    //jScrollPane1.setsi
    //
    // nodePanel
    //
    nodePanel.setLayout(new BoxLayout(nodePanel, BoxLayout.X_AXIS));
    nodePanel.add(jScrollPane1, 0);

    nodePanel.setBorder(new TitledBorder("Nodes Active"));
    //
    // linkTextArea
    //
    linkTextArea.setEditable(false);
    linkTextArea.setLineWrap(true);
    //
    // jScrollPane3
    //
    jScrollPane3.setViewportView(linkTextArea);
    //
    // linkPanel
    //
    linkPanel.setLayout(new BoxLayout(linkPanel, BoxLayout.X_AXIS));
    linkPanel.add(jScrollPane3, 0);
    linkPanel.setBorder(new TitledBorder("Node Links"));
    //
    // consoleTextArea
    //
    consoleTextArea.setEditable(false);
    consoleTextArea.setLineWrap(true);
    //
    // jScrollPane2
    //
    jScrollPane2.setViewportView(consoleTextArea);
    //
    // clearButton
    //
    clearButton.setText("Clear");
    clearButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            clearButton_actionPerformed(e);
        }

    });
    //
    // consolePanel
    //
    consolePanel.setLayout(new BoxLayout(consolePanel, BoxLayout.X_AXIS));
    consolePanel.add(jScrollPane2, 0);
    consolePanel.add(clearButton, 1);
    consolePanel.setBorder(new TitledBorder("Console"));
    //
    // ServerGUI
    //
    Dimension panelD = new Dimension(700, 330); // display Panel
    Dimension panelD1 = new Dimension(700, 134); // control Panel      
    Dimension panelD2 = new Dimension(350, 140); // nodepanel and linkpanel
    Dimension panelD3 = new Dimension(700, 140); // nodepanel and linkpanel togther
    consolePanel.setPreferredSize(panelD1);
    displayPanel.setPreferredSize(panelD);
    nodePanel.setPreferredSize(panelD2);
    linkPanel.setPreferredSize(panelD2);
    Box box = new Box(BoxLayout.X_AXIS); // put nodepanel and linkpanel in one box
    box.add(nodePanel);
    box.add(linkPanel);
    box.setSize(panelD3);

    //contentPane.add(BorderLayout.NORTH,displayPanel);
    //contentPane.add(BorderLayout.CENTER,box);
    contentPane.add(BorderLayout.NORTH, box);
    contentPane.add(BorderLayout.CENTER, displayPanel);
    contentPane.add(BorderLayout.SOUTH, consolePanel);

    frame.setJMenuBar(menuBar);
    frame.getContentPane().add(contentPane);
    frame.setTitle("P2P Visualisation Server");
    frame.setSize(new Dimension(800, 600));
    frame.setResizable(true);
    // This code has been adapted from http://lookass.ch/?id=4&area=art&art=47
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = frame.getSize();
    screenSize.height = screenSize.height / 2;
    screenSize.width = screenSize.width / 2;
    size.height = size.height / 2;
    size.width = size.width / 2;
    int y = screenSize.height - size.height;
    int x = screenSize.width - size.width;
    frame.setLocation(x, y);
    frame.setVisible(true);

    frame.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
        }
    });
}

From source file:JXButtonPanel.java

public JXButtonPanelDemo() {
    super("JXButtonPanel demo");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setResizable(false);//from  w w w. j  a v a 2  s. com
    JPanel topPanel = new JPanel(new GridLayout(1, 0));

    final JXButtonPanel radioGroupPanel = createRadioJXButtonPanel();
    topPanel.add(radioGroupPanel);

    final JXButtonPanel checkBoxPanel = createCheckBoxJXButtonPanel();
    topPanel.add(checkBoxPanel);

    add(topPanel);
    add(createButtonJXButtonPanel(), BorderLayout.SOUTH);
    pack();

    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("Options");
    JMenuItem item = new JMenuItem("Unselect radioButtons");
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // hack for 1.5 
            // in 1.6 ButtonGroup.clearSelection added
            JRadioButton b = new JRadioButton();
            radioGroup.add(b);
            b.setSelected(true);
            radioGroup.remove(b);
        }
    });
    menu.add(item);
    bar.add(menu);
    setJMenuBar(bar);

    setSize(300, 300);
    setLocationRelativeTo(null);
}

From source file:org.tros.logo.swing.LogoMenuBar.java

/**
 * Set up the export menu.//from  ww w  .  j  av a 2 s  . c  o m
 *
 * @return
 */
private JMenu setupExportMenu() {
    JMenu exportMenu = new JMenu(Localization.getLocalizedString("ExportMenu"));

    JMenuItem exportGif = new JMenuItem(Localization.getLocalizedString("ExportGIF"));
    JMenuItem exportPng = new JMenuItem(Localization.getLocalizedString("ExportPNG"));
    JMenuItem exportSvg = new JMenuItem(Localization.getLocalizedString("ExportSVG"));

    exportSvg.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser();
            chooser.setMultiSelectionEnabled(false);
            java.util.prefs.Preferences prefs = java.util.prefs.Preferences
                    .userNodeForPackage(LogoMenuBar.class);
            chooser.setCurrentDirectory(new File(prefs.get("export-directory", ".")));

            chooser.setVisible(true);
            int result = chooser.showSaveDialog(parent);

            if (result == JFileChooser.APPROVE_OPTION) {
                String filename = chooser.getSelectedFile().getPath();
                prefs.put("export-directory", chooser.getSelectedFile().getParent());
                if (Drawable.class.isAssignableFrom(canvas.getClass())) {
                    try (FileOutputStream fos = new FileOutputStream(new File(filename))) {
                        generateSVG((Drawable) canvas, fos);
                        fos.flush();
                    } catch (IOException ex) {
                        org.tros.utils.logging.Logging.getLogFactory().getLogger(LogoMenuBar.class).warn(null,
                                ex);
                    }
                }
            }
        }
    });

    exportGif.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser();
            chooser.setMultiSelectionEnabled(false);
            java.util.prefs.Preferences prefs = java.util.prefs.Preferences
                    .userNodeForPackage(LogoMenuBar.class);
            chooser.setCurrentDirectory(new File(prefs.get("export-directory", ".")));

            chooser.setVisible(true);
            int result = chooser.showSaveDialog(parent);

            if (result == JFileChooser.APPROVE_OPTION) {
                final String filename = chooser.getSelectedFile().getPath();
                prefs.put("export-directory", chooser.getSelectedFile().getParent());
                Thread t = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        if (Drawable.class.isAssignableFrom(canvas.getClass())
                                && BufferedImageProvider.class.isAssignableFrom((canvas.getClass()))) {
                            try {
                                generateGIF(((Drawable) canvas).cloneDrawable(), (BufferedImageProvider) canvas,
                                        filename);
                            } catch (SVGGraphics2DIOException ex) {
                                Logger.getLogger(LogoMenuBar.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (IOException ex) {
                                Logger.getLogger(LogoMenuBar.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    }
                });
                t.setDaemon(true);
                t.start();
            }
        }
    });
    exportPng.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser();
            chooser.setMultiSelectionEnabled(false);
            java.util.prefs.Preferences prefs = java.util.prefs.Preferences
                    .userNodeForPackage(LogoMenuBar.class);
            chooser.setCurrentDirectory(new File(prefs.get("export-directory", ".")));

            chooser.setVisible(true);
            int result = chooser.showSaveDialog(parent);

            if (result == JFileChooser.APPROVE_OPTION) {
                String filename = chooser.getSelectedFile().getPath();
                prefs.put("export-directory", chooser.getSelectedFile().getParent());
                // retrieve image
                if (BufferedImageProvider.class.isAssignableFrom(canvas.getClass())) {
                    generatePNG((BufferedImageProvider) canvas, filename);
                }
            }
        }
    });

    exportMenu.add(exportSvg);
    exportMenu.add(exportGif);
    exportMenu.add(exportPng);
    exportMenu.setMnemonic('X');
    exportSvg.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.ALT_MASK));
    exportGif.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.ALT_MASK));
    exportPng.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_MASK));
    return (exportMenu);
}