Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 
 
 package org.apache.cayenne.modeler;
 
 import java.awt.Color;
 import java.awt.Font;
 import java.util.List;
 
 
Main frame of CayenneModeler. Responsibilities include coordination of enabling/disabling of menu and toolbar.
public class CayenneModelerFrame extends JFrame implements DataNodeDisplayListener,
    protected EditorView view;
    protected RecentFileMenu recentFileMenu;
    protected ActionManager actionManager;
    protected JLabel status;
    
    
Menu which shows/hides log console
    protected JCheckBoxMenuItem logMenu;
    
    
Split panel, where main project editor and external component, like log console, are located
    protected JSplitPane splitPane;
    
    
Component, plugged into this frame
    protected Component dockComponent;
    
    
Listeners for changes in recent file menu
    protected List<RecentFileListListenerrecentFileListeners;
    
    
Welcome screen, shown when no project is open
    protected WelcomeScreen welcomeScreen;
    
    public CayenneModelerFrame(ActionManager actionManager) {
        super(.);
        this. = actionManager;
        
        setIconImage(ModelerUtil.buildIcon("CayenneModeler.jpg").getImage());
        initMenus();
        initToolbar();
        initStatusBar();
        initWelcome();
        
        fireRecentFileListChanged(); //start filling list in welcome screen and in menu
        
        setView(null);
    }

    
Returns an action object associated with the key.
    private CayenneAction getAction(String key) {
        return .getAction(key);
    }
    protected void initMenus() {
        getContentPane().setLayout(new BorderLayout());
        JMenu fileMenu = new JMenu("File");
        JMenu editMenu = new JMenu("Edit");
        JMenu projectMenu = new JMenu("Project");
        JMenu toolMenu = new JMenu("Tools");
        JMenu helpMenu = new JMenu("Help");
        if (OperatingSystem.getOS() != .) {
            fileMenu.setMnemonic(.);
            editMenu.setMnemonic(.);
            projectMenu.setMnemonic(.);
            toolMenu.setMnemonic(.);
            helpMenu.setMnemonic(.);
        }
        fileMenu.add(getAction(NewProjectAction.getActionName()).buildMenu());
        fileMenu.add(getAction(OpenProjectAction.getActionName()).buildMenu());
        fileMenu.add(getAction(ProjectAction.getActionName()).buildMenu());
        fileMenu.add(getAction(ImportDataMapAction.getActionName()).buildMenu());
        fileMenu.addSeparator();
        fileMenu.add(getAction(SaveAction.getActionName()).buildMenu());
        fileMenu.add(getAction(SaveAsAction.getActionName()).buildMenu());
        fileMenu.add(getAction(RevertAction.getActionName()).buildMenu());
        fileMenu.addSeparator();
        
        editMenu.add(getAction(UndoAction.getActionName()).buildMenu());
        editMenu.add(getAction(RedoAction.getActionName()).buildMenu());
        editMenu.add(getAction(CutAction.getActionName()).buildMenu());
        editMenu.add(getAction(CopyAction.getActionName()).buildMenu());
        editMenu.add(getAction(PasteAction.getActionName()).buildMenu());
         = new RecentFileMenu("Recent Projects");
        fileMenu.add();
        // Mac OS X doesn't use File->Exit, it uses CayenneModeler->Quit (command-Q)
        if (OperatingSystem.getOS() != .) {
            fileMenu.addSeparator();
            fileMenu.add(getAction(ExitAction.getActionName()).buildMenu());
        }
        projectMenu.add(getAction(ValidateAction.getActionName()).buildMenu());
        projectMenu.addSeparator();
        projectMenu.add(getAction(CreateDomainAction.getActionName()).buildMenu());
        projectMenu.add(getAction(CreateNodeAction.getActionName()).buildMenu());
        projectMenu.add(getAction(CreateDataMapAction.getActionName()).buildMenu());
        projectMenu.add(getAction(CreateObjEntityAction.getActionName()).buildMenu());
        projectMenu.add(getAction(CreateEmbeddableAction.getActionName()).buildMenu());
        projectMenu.add(getAction(CreateDbEntityAction.getActionName()).buildMenu());
        
        projectMenu.add(getAction(CreateProcedureAction.getActionName()).buildMenu());
        projectMenu.add(getAction(CreateQueryAction.getActionName()).buildMenu());
        
        projectMenu.addSeparator();
        projectMenu.add(getAction(ObjEntitySyncAction.getActionName()).buildMenu());
        projectMenu.addSeparator();
        projectMenu.add(getAction(RemoveAction.getActionName()).buildMenu());
        toolMenu.add(getAction(ImportDBAction.getActionName()).buildMenu());
        toolMenu.add(getAction(InferRelationshipsAction.getActionName()).buildMenu());
        toolMenu.add(getAction(ImportEOModelAction.getActionName()).buildMenu());
        toolMenu.addSeparator();
        toolMenu.add(getAction(GenerateCodeAction.getActionName()).buildMenu());
        toolMenu.add(getAction(GenerateDBAction.getActionName()).buildMenu());
        toolMenu.add(getAction(MigrateAction.getActionName()).buildMenu());
        
        
Menu for opening Log console
        toolMenu.addSeparator();
        
         = getAction(ShowLogConsoleAction.getActionName()).buildCheckBoxMenu();
        updateLogConsoleMenu();
        toolMenu.add();
        
        // Mac OS X has it's own Preferences menu item under the application menu
        if (OperatingSystem.getOS() != .) {
            toolMenu.addSeparator();
            toolMenu.add(getAction(ConfigurePreferencesAction.getActionName()).buildMenu());
        }
        // Mac OS X "About CayenneModeler" appears under the application menu, per Apple GUI standards
        if (OperatingSystem.getOS() != .)
            helpMenu.add(getAction(AboutAction.getActionName()).buildMenu());
        helpMenu.add(getAction(DocumentationAction.getActionName()).buildMenu());
        
        JMenuBar menuBar = new JMenuBar();
        menuBar.add(fileMenu);
        menuBar.add(editMenu);
        menuBar.add(projectMenu);
        menuBar.add(toolMenu);
        menuBar.add(helpMenu);
        setJMenuBar(menuBar);
    }
    
    
Selects/deselects menu item, depending on status of log console
    public void updateLogConsoleMenu() {
                .));
    }
    protected void initStatusBar() {
         = new JLabel();
        .setFont(.getFont().deriveFont(., 10));
        
        .getInsets(). = 5;
        .getInsets(). = 5;
        
        .setResizeWeight(0.7);
        
        
Moving this to try-catch block per CAY-940. Exception will be stack-traced
        try {
            Domain domain = Application.getInstance().getPreferenceDomain().getSubdomain(
                this.getClass());
            ComponentGeometry geometry = (ComponentGeometrydomain.getDetail(
                "splitPane.divider",
                ComponentGeometry.class,
                true);
            geometry.bindIntProperty(., 400);
        }
        catch (Exception ex) {
            LogFactory.getLog(getClass()).error("Cannot bind divider property"ex);
        }
        JPanel statusBar = new JPanel(new FlowLayout(., 3, 1));
        // add placeholder
        statusBar.add(Box.createVerticalStrut(16));
        statusBar.add();
        getContentPane().add(statusBar.);
    }
    
    
Initializes welcome screen
    protected void initWelcome() {
         = new WelcomeScreen();
    }
    
    
Plugs a component in the frame, between main area and status bar
    public void setDockComponent(Component c) {
        if ( == c) {
            return;
        }
        
        if ( != null) {
            .setBottomComponent(null);
        }
        
         = c;
        
        if ( != null) {
        }
        
        .validate();
    }
    
    

Returns:
Dock component
    public Component getDockComponent() {
        return ;
    }

    
Initializes main toolbar.
    protected void initToolbar() {
        JToolBar toolBar = new JToolBar();
        toolBar.add(getAction(NewProjectAction.getActionName()).buildButton());
        toolBar.add(getAction(OpenProjectAction.getActionName()).buildButton());
        toolBar.add(getAction(SaveAction.getActionName()).buildButton());
        
        toolBar.addSeparator();
        toolBar.add(getAction(RemoveAction.getActionName()).buildButton());
        
        toolBar.addSeparator();
        
        toolBar.add(getAction(CutAction.getActionName()).buildButton());
        toolBar.add(getAction(CopyAction.getActionName()).buildButton());
        toolBar.add(getAction(PasteAction.getActionName()).buildButton());
        toolBar.addSeparator();
        
        toolBar.add(getAction(UndoAction.getActionName()).buildButton());
        toolBar.add(getAction(RedoAction.getActionName()).buildButton());
        
        toolBar.addSeparator();
        toolBar.add(getAction(CreateDomainAction.getActionName()).buildButton());
        toolBar.add(getAction(CreateNodeAction.getActionName()).buildButton());
        toolBar.add(getAction(CreateDataMapAction.getActionName()).buildButton());
        toolBar.addSeparator();
        toolBar.add(getAction(CreateDbEntityAction.getActionName()).buildButton());
        toolBar.add(getAction(CreateProcedureAction.getActionName()).buildButton());
        toolBar.addSeparator();
        
        toolBar.add(getAction(CreateObjEntityAction.getActionName()).buildButton());
        toolBar.add(getAction(CreateEmbeddableAction.getActionName()).buildButton());
        toolBar.add(getAction(CreateQueryAction.getActionName()).buildButton());
 
        toolBar.addSeparator();
        toolBar.add(getAction(NavigateBackwardAction.getActionName()).buildButton());
        toolBar.add(getAction(NavigateForwardAction.getActionName()).buildButton());
        JPanel east = new JPanel(new BorderLayout());   // is used to place search feature components the most right on a toolbar  
        final JTextField findField = new JTextField(10);
        findField.addKeyListener(new KeyListener(){
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() != .){
                     findField.setBackground(.);
                }
            }
            public void keyReleased(KeyEvent e) {
            }
            public void keyTyped(KeyEvent e) {
            }
            
        });
        findField.setAction(getAction(FindAction.getActionName()));
        JLabel findLabel = new JLabel("Search:");
        findLabel.setLabelFor(findField);
        Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
            public void eventDispatched(AWTEvent event) {
               
                
                if (event instanceof KeyEvent) {
                   
                   if (((KeyEventevent).getModifiers() == Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
                            && ((KeyEventevent).getKeyCode() == .){                               
                               findField.requestFocus();                               
                   }                    
                }                      
            }    
            
        }, .);
        
        
        JPanel box = new JPanel();  // is used to place label and text field one after another
        box.setLayout(new BoxLayout(box.));
        box.add(findLabel);
        box.add(findField);
        east.add(box.);
        toolBar.add(east);
        getContentPane().add(toolBar.);
    }
    public void currentDataNodeChanged(DataNodeDisplayEvent e) {
    }
    public void currentDataMapChanged(DataMapDisplayEvent e) {
    }
    public void currentObjEntityChanged(EntityDisplayEvent e) {
    }
    public void currentDbEntityChanged(EntityDisplayEvent e) {
    }
    public void currentQueryChanged(QueryDisplayEvent e) {
        .querySelected();
    }
    }
    
    }
    
    }

    
Returns the right side view panel.

Returns:
EditorView
    public EditorView getView() {
        return ;
    }
    public JLabel getStatus() {
        return ;
    }

    
Returns the recentFileMenu.

Returns:
RecentFileMenu
    public RecentFileMenu getRecentFileMenu() {
        return ;
    }

    
Adds editor view to the frame.
    public void setView(EditorView view) {
        int oldLocation = .getDividerLocation();
        
        this. = view;
        if (view != null) {
            .setTopComponent(view);
        }
        else {
            .setTopComponent();
        }
        validate();
        .setDividerLocation(oldLocation);
    }
    
    
Adds listener for recent menu changes
    public void addRecentFileListListener(RecentFileListListener listener) {
        .add(listener);
    }
    
    
Notifies all listeners that recent file list has changed
    public void fireRecentFileListChanged() {
        for (RecentFileListListener recentFileListener : ) {
            recentFileListener.recentFileListChanged();
        }
    }
New to GrepCode? Check out our FAQ X