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>WorkProjectFactory 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 WorkProjectFactory 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(WorkProject.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(WorkProject.PROJECT_FILE) != null;
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public final Project loadProject(final FileObject projectDirectory,
66              final ProjectState state) throws IOException {
67  
68          if (isProject(projectDirectory)) {
69              return new WorkProject(projectDirectory, state);
70          }
71          return null;
72      }
73  
74      /** {@inheritDoc} */
75      @Override
76      public void saveProject(final Project project) throws IOException {
77          // leave unimplemented for the moment
78      }
79  }