Example usage for javax.swing JPanel setFocusable

List of usage examples for javax.swing JPanel setFocusable

Introduction

In this page you can find the example usage for javax.swing JPanel setFocusable.

Prototype

public void setFocusable(boolean focusable) 

Source Link

Document

Sets the focusable state of this Component to the specified value.

Usage

From source file:com.net2plan.gui.GUINet2Plan.java

private static JPanel showAbout() {
    final JPanel aboutPanel = new JPanel();

    ImageIcon image = new ImageIcon(
            ImageUtils.readImageFromURL(GUINet2Plan.class.getResource("/resources/gui/logo.png")));
    JLabel label = new JLabel("", image, JLabel.CENTER);

    aboutPanel.setLayout(new MigLayout("insets 0 0 0 0", "[grow]", "[grow][grow]"));
    aboutPanel.add(label, "alignx center, aligny bottom, wrap");
    aboutPanel.add(new JLabel(ABOUT_TEXT), "alignx center, aligny top");
    aboutPanel.setFocusable(true);
    aboutPanel.requestFocusInWindow();/*from w w  w . j  ava 2  s .  c  o m*/

    aboutPanel.addKeyListener(new KeyAdapter() {
        private final int[] sequence = new int[] { KeyEvent.VK_UP, KeyEvent.VK_UP, KeyEvent.VK_DOWN,
                KeyEvent.VK_DOWN, KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT, KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT,
                KeyEvent.VK_A, KeyEvent.VK_B };
        private int currentButton = 0;

        @Override
        public void keyPressed(KeyEvent e) {
            int keyPressed = e.getKeyCode();

            if (keyPressed == sequence[currentButton]) {
                currentButton++;

                if (currentButton == sequence.length) {
                    ErrorHandling.setDebug(true);
                    aboutPanel.removeKeyListener(this);
                }
            } else {
                currentButton = 0;
            }
        }
    });

    return aboutPanel;
}

From source file:components.ScrollDemo2.java

public ScrollDemo2() {
    super(new BorderLayout());

    area = new Dimension(0, 0);
    circles = new Vector<Rectangle>();

    //Set up the instructions.
    JLabel instructionsLeft = new JLabel("Click left mouse button to place a circle.");
    JLabel instructionsRight = new JLabel("Click right mouse button to clear drawing area.");
    JPanel instructionPanel = new JPanel(new GridLayout(0, 1));
    instructionPanel.setFocusable(true);
    instructionPanel.add(instructionsLeft);
    instructionPanel.add(instructionsRight);

    //Set up the drawing area.
    drawingPane = new DrawingPane();
    drawingPane.setBackground(Color.white);
    drawingPane.addMouseListener(this);

    //Put the drawing area in a scroll pane.
    JScrollPane scroller = new JScrollPane(drawingPane);
    scroller.setPreferredSize(new Dimension(200, 200));

    //Lay out this demo.
    add(instructionPanel, BorderLayout.PAGE_START);
    add(scroller, BorderLayout.CENTER);
}

From source file:eu.delving.sip.Application.java

private Application(final File storageDir) throws StorageException {
    GroovyCodeResource groovyCodeResource = new GroovyCodeResource(getClass().getClassLoader());
    final ImageIcon backgroundIcon = new ImageIcon(getClass().getResource("/delving-background.png"));
    desktop = new JDesktopPane() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(backgroundIcon.getImage(), 0, 0, desktop);
        }/*from www .  ja v a2  s  .c om*/
    };
    desktop.setMinimumSize(new Dimension(MINIMUM_DESKTOP_SIZE));
    resizeTimer = new Timer(DEFAULT_RESIZE_INTERVAL, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            resizeTimer.stop();
            for (JInternalFrame frame : desktop.getAllFrames()) {
                if (frame instanceof FrameBase) {
                    ((FrameBase) frame).ensureOnScreen();
                }
            }
        }
    });
    desktop.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent componentEvent) {
            resizeTimer.restart();
        }
    });
    Preferences preferences = Preferences.userNodeForPackage(SipModel.class);
    feedback = new VisualFeedback(home, desktop, preferences);
    HttpClient httpClient = createHttpClient(storageDir);
    SchemaRepository schemaRepository;
    try {
        schemaRepository = new SchemaRepository(new SchemaFetcher(httpClient));
    } catch (IOException e) {
        throw new StorageException("Unable to create Schema Repository", e);
    }
    ResolverContext context = new ResolverContext();
    Storage storage = new StorageImpl(storageDir, schemaRepository, new CachedResourceResolver(context));
    context.setStorage(storage);
    context.setHttpClient(httpClient);
    sipModel = new SipModel(desktop, storage, groovyCodeResource, feedback, preferences);
    CultureHubClient cultureHubClient = isStandalone(storageDir) ? null
            : new CultureHubClient(sipModel, httpClient);
    if (cultureHubClient != null)
        uploadAction = new UploadAction(sipModel, cultureHubClient);
    expertMenu = new ExpertMenu(desktop, sipModel, cultureHubClient, allFrames);
    statusPanel = new StatusPanel(sipModel);
    home = new JFrame(titleString());
    home.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent componentEvent) {
            allFrames.getViewSelector().refreshView();
        }
    });
    JPanel content = (JPanel) home.getContentPane();
    content.setFocusable(true);
    FrameBase dataSetFrame = cultureHubClient != null ? new DataSetHubFrame(sipModel, cultureHubClient)
            : new DataSetStandaloneFrame(sipModel, schemaRepository);
    LogFrame logFrame = new LogFrame(sipModel);
    feedback.setLog(logFrame.getLog());
    allFrames = new AllFrames(sipModel, content, dataSetFrame, logFrame);
    desktop.setBackground(new Color(190, 190, 200));
    content.add(desktop, BorderLayout.CENTER);
    sipModel.getMappingModel().addChangeListener(new MappingModel.ChangeListener() {
        @Override
        public void lockChanged(MappingModel mappingModel, final boolean locked) {
            sipModel.exec(new Swing() {
                @Override
                public void run() {
                    unlockMappingAction.setEnabled(locked);
                }
            });
        }

        @Override
        public void functionChanged(MappingModel mappingModel, MappingFunction function) {
        }

        @Override
        public void nodeMappingChanged(MappingModel mappingModel, RecDefNode node, NodeMapping nodeMapping,
                NodeMappingChange change) {
        }

        @Override
        public void nodeMappingAdded(MappingModel mappingModel, RecDefNode node, NodeMapping nodeMapping) {
        }

        @Override
        public void nodeMappingRemoved(MappingModel mappingModel, RecDefNode node, NodeMapping nodeMapping) {
        }

        @Override
        public void populationChanged(MappingModel mappingModel, RecDefNode node) {
        }
    });
    importAction = new ImportAction(desktop, sipModel);
    attachAccelerator(importAction, home);
    validateAction = new ValidateAction(sipModel, allFrames.prepareForInvestigation(desktop));
    unlockMappingAction = new UnlockMappingAction(sipModel);
    attachAccelerator(unlockMappingAction, home);
    selectAnotherMappingAction = new SelectAnotherMappingAction(sipModel);
    attachAccelerator(selectAnotherMappingAction, home);
    content.add(createStatePanel(), BorderLayout.SOUTH);
    content.add(allFrames.getSidePanel(), BorderLayout.WEST);
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    screen.height -= 30;
    home.setSize(screen);
    home.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    ImageIcon logo = new ImageIcon(getClass().getResource("/sip-creator-logo.png"));
    home.setIconImage(logo.getImage());
    home.setJMenuBar(createMenuBar());
    home.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent windowEvent) {
            quit();
        }
    });
    home.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    sipModel.getDataSetModel().addListener(new DataSetModel.SwingListener() {
        @Override
        public void stateChanged(DataSetModel model, DataSetState state) {
            statusPanel.setState(state);
            switch (state) {
            case ABSENT:
                sipModel.exec(new Work() {
                    @Override
                    public void run() {
                        sipModel.getDataSetFacts().set(null);
                        sipModel.getStatsModel().setStatistics(null);
                    }

                    @Override
                    public Job getJob() {
                        return Job.CLEAR_FACTS_STATS;
                    }
                });
                home.setTitle(titleString());
                sipModel.seekReset();
                break;
            default:
                DataSetModel dataSetModel = sipModel.getDataSetModel();
                home.setTitle(String.format(titleString() + " - [%s -> %s]",
                        dataSetModel.getDataSet().getSpec(), dataSetModel.getPrefix().toUpperCase()));
                sipModel.getReportFileModel().refresh();
                break;
            }
        }
    });
    attachAccelerator(new QuitAction(), home);
    attachAccelerator(statusPanel.getButtonAction(), home);
}

From source file:com.igormaznitsa.sciareto.ui.MainFrame.java

public MainFrame(@Nonnull @MustNotContainNull final String... args) {
    super();/*w  w  w  .j  av a2  s  .  c  o m*/
    initComponents();

    this.stackPanel = new JPanel();
    this.stackPanel.setFocusable(false);
    this.stackPanel.setOpaque(false);
    this.stackPanel.setBorder(BorderFactory.createEmptyBorder(32, 32, 16, 32));
    this.stackPanel.setLayout(new BoxLayout(this.stackPanel, BoxLayout.Y_AXIS));

    final JPanel glassPanel = (JPanel) this.getGlassPane();
    glassPanel.setOpaque(false);

    this.setGlassPane(glassPanel);

    glassPanel.setLayout(new BorderLayout(8, 8));
    glassPanel.add(Box.createGlue(), BorderLayout.CENTER);

    final JPanel ppanel = new JPanel(new BorderLayout(0, 0));
    ppanel.setFocusable(false);
    ppanel.setOpaque(false);
    ppanel.setCursor(null);
    ppanel.add(this.stackPanel, BorderLayout.SOUTH);

    glassPanel.add(ppanel, BorderLayout.EAST);

    this.stackPanel.add(Box.createGlue());

    glassPanel.setVisible(false);

    this.setTitle("Scia Reto");

    setIconImage(UiUtils.loadImage("logo256x256.png"));

    this.stateless = args.length > 0;

    final MainFrame theInstance = this;

    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(@Nonnull final WindowEvent e) {
            if (doClosing()) {
                dispose();
            }
        }
    });

    this.tabPane = new EditorTabPane(this);

    this.explorerTree = new ExplorerTree(this);

    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(250);
    splitPane.setResizeWeight(0.0d);
    splitPane.setLeftComponent(this.explorerTree);
    splitPane.setRightComponent(this.tabPane);

    add(splitPane, BorderLayout.CENTER);

    this.menuOpenRecentProject.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedProjects = FileHistoryManager.getInstance().getLastOpenedProjects();
            if (lastOpenedProjects.length > 0) {
                for (final File folder : lastOpenedProjects) {
                    final JMenuItem item = new JMenuItem(folder.getName());
                    item.setToolTipText(folder.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openProject(folder, false);
                        }
                    });
                    menuOpenRecentProject.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentProject.removeAll();
        }

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

    this.menuOpenRecentFile.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedFiles = FileHistoryManager.getInstance().getLastOpenedFiles();
            if (lastOpenedFiles.length > 0) {
                for (final File file : lastOpenedFiles) {
                    final JMenuItem item = new JMenuItem(file.getName());
                    item.setToolTipText(file.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openFileAsTab(file);
                        }
                    });
                    menuOpenRecentFile.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentFile.removeAll();
        }

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

    if (!this.stateless) {
        restoreState();
    } else {
        boolean openedProject = false;
        for (final String filePath : args) {
            final File file = new File(filePath);
            if (file.isDirectory()) {
                openedProject = true;
                openProject(file, true);
            } else if (file.isFile()) {
                openFileAsTab(file);
            }
        }
        if (!openedProject) {
            //TODO try to hide project panel!
        }
    }

    final LookAndFeel current = UIManager.getLookAndFeel();
    final ButtonGroup lfGroup = new ButtonGroup();
    final String currentLFClassName = current.getClass().getName();
    for (final UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(info.getName());
        lfGroup.add(menuItem);
        if (currentLFClassName.equals(info.getClassName())) {
            menuItem.setSelected(true);
        }
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(@Nonnull final ActionEvent e) {
                try {
                    UIManager.setLookAndFeel(info.getClassName());
                    SwingUtilities.updateComponentTreeUI(theInstance);
                    PreferencesManager.getInstance().getPreferences().put(Main.PROPERTY_LOOKANDFEEL,
                            info.getClassName());
                    PreferencesManager.getInstance().flush();
                } catch (Exception ex) {
                    LOGGER.error("Can't change LF", ex);
                }
            }
        });
        this.menuLookAndFeel.add(menuItem);
    }
}