View Javadoc
1   package info.mikethomas.fahview.v6project;
2   
3   /*
4    * #%L
5    * This file is part of FAHView-v6project.
6    * %%
7    * Copyright (C) 2011 - 2017 Mike Thomas <mikepthomas@outlook.com>
8    * %%
9    * FAHView is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as published by
11   * the Free Software Foundation, either version 3 of the License, or
12   * (at your option) any later version.
13   * %
14   * FAHView is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * %
19   * You should have received a copy of the GNU General Public License
20   * along with FAHView.  If not, see <http://www.gnu.org/licenses/>.
21   * #L%
22   */
23  
24  import java.awt.Image;
25  import java.io.IOException;
26  import javax.swing.ImageIcon;
27  import org.netbeans.api.project.Project;
28  import org.netbeans.api.project.ProjectManager;
29  import org.netbeans.spi.project.ProjectFactory;
30  import org.netbeans.spi.project.ProjectFactory2;
31  import org.netbeans.spi.project.ProjectState;
32  import org.openide.filesystems.FileObject;
33  import org.openide.util.ImageUtilities;
34  import org.openide.util.lookup.ServiceProvider;
35  
36  /**
37   * <p>ClientProjectFactory class.</p>
38   *
39   * @author <a href="mailto:mikepthomas@outlook.com">Michael Thomas</a>
40   * @version $Id: $Id
41   */
42  @ServiceProvider(service = ProjectFactory.class)
43  public class ClientProjectFactory implements ProjectFactory2 {
44  
45      /** {@inheritDoc} */
46      @Override
47      public final ProjectManager.Result isProject2(
48              final FileObject projectDirectory) {
49  
50          if (isProject(projectDirectory)) {
51              Image image = ImageUtilities.loadImage(ClientProject.PROJECT_ICON);
52              return new ProjectManager.Result(new ImageIcon(image));
53          }
54          return null;
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public final boolean isProject(final FileObject projectDirectory) {
60          return projectDirectory.getFileObject(
61                  ClientProject.PROJECT_FILE) != null;
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public final Project loadProject(final FileObject projectDirectory,
67              final ProjectState state) throws IOException {
68  
69          if (isProject(projectDirectory)) {
70              return new ClientProject(projectDirectory, state);
71          }
72          return null;
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      public void saveProject(final Project project) throws IOException {
78          // leave unimplemented for the moment
79      }
80  }