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 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;
Welcome screen (CAY-894) is a panel shown when no project is open. User can quickly create new project or open an existing one.
 public class WelcomeScreen extends JPanel implements RecentFileListListener {

Top color of gradient background
     private static final Color TOP_GRADIENT = new Color(153, 153, 153);

Bottom color of gradient background
     private static final Color BOTTOM_GRADIENT = new Color(230, 230, 230);
List of recent projects
     private JList recentsList;
     public WelcomeScreen() {

Creates all neccesary components
     protected void initView() {
         setLayout(new GridBagLayout());
         ImageIcon welcome = ModelerUtil.buildIcon("welcome.jpg");
         JLabel imageLabel = new JLabel(welcome);
         ImageIcon newOutIcon = ModelerUtil.buildIcon("icon-welcome-new.png");
         ImageIcon newOverIcon = ModelerUtil.buildIcon("icon-welcome-new-over.png");
         ImageIcon openOutIcon = ModelerUtil.buildIcon("icon-welcome-open.png");
         ImageIcon openOverIcon = ModelerUtil.buildIcon("icon-welcome-open-over.png");
         JPanel buttonsPane = new JPanel(null);
         buttonsPane.setPreferredSize(new Dimension(300, 30));
         JButton newButton = createButton(newOutIconnewOverIcon);
         JLabel newLabel = new JLabel(NewProjectAction.getActionName(), .);
        JButton openButton = createButton(openOutIconopenOverIcon);
        JLabel openLabel = new JLabel(OpenProjectAction.getActionName(), .);
        imageLabel.setLayout(new BorderLayout());
        newButton.setLocation(10, 130);
                + newButton.getWidth() / 2 - newLabel.getPreferredSize(). / 2, 
                newButton.getY() + newButton.getHeight());
        openButton.setLocation(120, newButton.getY());
                + openButton.getWidth() / 2 - openLabel.getPreferredSize(). / 2, 
                openButton.getY() + openButton.getHeight());
        JLabel recents = new JLabel("Recent Projects:");
        recents.setLocation(207, newButton.getY());
         = new JList();
        .setLocation(recents.getX(), recents.getY() + 2 * recents.getHeight());
        .setSize(welcome.getIconWidth() - .getX() - 1, 
                welcome.getIconHeight() - .getY());

Creates welcome screen-specific button
    private JButton createButton(Icon outIconIcon overIcon) {
        JButton button = new JButton();
        button.setSize(outIcon.getIconWidth(), outIcon.getIconHeight());
        return button;

Paints gradient background
    public void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2Dg.create();
        g2.setPaint(new GradientPaint(
        g2.fillRect(0, 0, getWidth(), getHeight());
    public void recentFileListChanged() {
        ModelerPreferences pref = ModelerPreferences.getPreferences();
        final Vector<?> arr = (Vector<?>) pref.getVector(.).clone();
            new AbstractListModel() {
                public int getSize() { return arr.size(); }
                public Object getElementAt(int i) { return arr.elementAt(i); }
Renderer for the list of last files. Ignores the selection, instead paints with ROLLOVER_BACKGROUND (currently red) the row mouse is hovering over
    class RecentFileListRenderer extends DefaultListCellRenderer implements MouseInputListener {
Color for background of row mouse is over
        final Color ROLLOVER_BACKGROUND = .;
Color for foreground of row mouse is over
        final Color ROLLOVER_FOREGROUND = .;
List which is rendered
        private JList list;
Row mouse is over
        private int rolloverRow;
        public RecentFileListRenderer(JList list) {
            this. = list;
             = -1;
        public Component getListCellRendererComponent(
                JList list,
                Object value,
                int index,
                boolean isSelected,
                boolean cellHasFocus) {
            //selection is ignored
            if ( == index) {
            else {
            return this;
        public void mouseClicked(MouseEvent e) {
        public void mouseEntered(MouseEvent e) {
        public void mouseExited(MouseEvent e) {
             = -1;
        public void mousePressed(MouseEvent e) {
        public void mouseReleased(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e) &&  != -1) {
                File file = new File((String.getModel().getElementAt());
Fire an action with the file as source
                        new ActionEvent(file, 0, null));
                 = -1; //clear selection
        public void mouseDragged(MouseEvent e) {
        public void mouseMoved(MouseEvent e) {
            int newRow;
Check that a row boundary contains the mouse point, so that rolloverRow would be -1 if we are below last row
            if (.getModel().getSize() > 0 && 
                    !.getCellBounds(0, .getModel().getSize() - 1).contains(e.getPoint())) {
                newRow = -1;
            else {
                newRow = .locationToIndex(e.getPoint()); 
            if ( != newRow) {
                 = newRow;