private void readFile() {
   try {
     ResourceLoader rl = ResourceLoader.getResourceLoader();
     BufferedReader reader = rl.getBufferedReader(Values.MainMap, "settings.txt");
     String line = "";
     line = reader.readLine();
     StringTokenizer st = new StringTokenizer(line);
     int size = st.countTokens();
     for (int i = 0; i < size; i++) {
       String s = st.nextToken();
       String[] list;
       if (s.contains("=")) {
         list = s.split("=");
       } else {
         list = new String[2];
         list[0] = s;
         list[1] = "";
       }
       settings.put(list[0], list[1]);
     }
     reader.close();
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
  /** Load synonyms with the given {@link SynonymMap.Parser} class. */
  private SynonymMap loadSynonyms(
      ResourceLoader loader, String cname, boolean dedup, Analyzer analyzer)
      throws IOException, ParseException {
    CharsetDecoder decoder =
        Charset.forName("UTF-8")
            .newDecoder()
            .onMalformedInput(CodingErrorAction.REPORT)
            .onUnmappableCharacter(CodingErrorAction.REPORT);

    SynonymMap.Parser parser;
    Class<? extends SynonymMap.Parser> clazz = loader.findClass(cname, SynonymMap.Parser.class);
    try {
      parser =
          clazz
              .getConstructor(boolean.class, boolean.class, Analyzer.class)
              .newInstance(dedup, expand, analyzer);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    File synonymFile = new File(synonyms);
    if (synonymFile.exists()) {
      decoder.reset();
      parser.parse(new InputStreamReader(loader.openResource(synonyms), decoder));
    } else {
      List<String> files = splitFileNames(synonyms);
      for (String file : files) {
        decoder.reset();
        parser.parse(new InputStreamReader(loader.openResource(file), decoder));
      }
    }
    return parser.build();
  }
  /**
   * @param _sResource
   * @return
   */
  private <T extends Resource> T loadResource(final Class<T> type, final String resourcePath) {
    T resource = null;

    ResourceLoader<?> loader = loaders.get(type);
    if (loader != null) {
      InputStream inputStream;

      String fullQualifiedPath = rootPath + resourcePath;

      // inputStream = new FileInputStream(fullQualifiedPath);
      inputStream =
          Thread.currentThread().getContextClassLoader().getResourceAsStream(fullQualifiedPath);
      if (inputStream != null) {
        // @SuppressWarnings("unchecked")
        resource = (T) loader.load(inputStream);
        resource.onLoaded();
      } else {
        System.err.printf("No file for path '%s'", fullQualifiedPath);
      }
    } else {
      System.err.printf("No resource loader for class '%s'", type.getName());
    }

    return resource;
  }
  public GLTextureManager() {
    final ResourceLoader<Texture> loader = getResourceLoader();
    loader.add(
        new ResourceDelegate<Texture>() {
          public boolean isLoadable(final String _file) {
            return true;
          }

          public Texture load(final String _file, final Settings _settings) {
            return loadTextureASync(_file);
          }

          protected Texture loadTextureASync(final String _file) {
            // We want to allocate the key for the resource so the texture
            // is not reloaded if another object wishes to use it before
            // the texture has fully loaded.
            // The Renderer should skip the texture, until it is finally
            // available to render/
            add(_file, null);

            TextureThread load = new TextureThread("LOAD_TEXTURE", _file);
            load.start();

            return null;
          }
        });
  }
  /**
   * Gets the loader specified in the configuration file.
   *
   * @return TemplateLoader
   */
  public static ResourceLoader getLoader(RuntimeServices rs, String loaderClassName)
      throws Exception {
    ResourceLoader loader = null;

    try {
      loader = ((ResourceLoader) Class.forName(loaderClassName).newInstance());

      rs.info("Resource Loader Instantiated: " + loader.getClass().getName());

      return loader;
    } catch (Exception e) {
      rs.error(
          "Problem instantiating the template loader.\n"
              + "Look at your properties file and make sure the\n"
              + "name of the template loader is correct. Here is the\n"
              + "error: "
              + StringUtils.stackTrace(e));

      throw new Exception(
          "Problem initializing template loader: "
              + loaderClassName
              + "\nError is: "
              + StringUtils.stackTrace(e));
    }
  }
Exemple #6
0
 public Racket(float x, float y) {
   super(x, y, 80, 16);
   resources = ResourceLoader.getInstance();
   xSpeed = 0;
   ySpeed = 0;
   image = resources.getImage("racket.png");
 }
Exemple #7
0
 public static Image loadImage(RelativePath relativePath) {
   if (relativePath == AgnosticUIConfiguration.NO_ICON) {
     return NO_IMAGE;
   }
   ResourceLoader resourceLoader = new ResourceLoader();
   InputStream imageStream = resourceLoader.loadResource(relativePath);
   return new Image(imageStream, 16, 16, true, true);
 }
Exemple #8
0
 /**
  * Called when switching between skyBox and spaceBox
  *
  * @param enable true if spaceBox. false if skyBox.
  */
 public void enableSpaceBox(boolean enable) {
   if (enable) {
     rootNode.detachChild(loader.getSky());
     rootNode.attachChild(loader.getSpace());
   } else {
     rootNode.detachChild(loader.getSpace());
     rootNode.attachChild(loader.getSky());
   }
 }
Exemple #9
0
 @Override
 public URI getUri() {
   try {
     ResourceLoader loader = ResourceLoader.Type.valueOf(resourceType.toUpperCase()).get();
     return loader.getResource(getResource()).toURI();
   } catch (URISyntaxException use) {
     log.warn(use);
     return null;
   }
 }
  @Lock(LockType.WRITE)
  public Object get(String type, String id) {

    String composedId = type + "/" + id;
    if (store.get(composedId) == null) {
      store.put(composedId, resourceLoader.getResource().getContents().get(0));
      return resourceLoader.getResource().getContents().get(0);
    } else {
      return store.get(composedId);
    }
  }
/** The MessageQueueClearAction class defines the action of clearing a message queue. */
class MessageQueueClearAction extends ConfirmedAction {
  private static final String copyright =
      "Copyright (C) 1997-2000 International Business Machines Corporation and others.";

  // MRI.
  private static final String confirmTitleText_ = ResourceLoader.getText("DLG_CONFIRM_CLEAR_TITLE");
  private static final String confirmMessageText_ = ResourceLoader.getText("DLG_CONFIRM_CLEAR");
  private static final String text_ = ResourceLoader.getText("ACTION_CLEAR");

  // Private data.
  private JComboBox messageType_;
  private VMessageQueue object_;
  private MessageQueue queue_;

  /**
   * Constructs a MessageQueueClearAction object.
   *
   * @param object The object.
   * @param queue The message queue.
   */
  public MessageQueueClearAction(VMessageQueue object, MessageQueue queue) {
    super(object, confirmTitleText_, confirmMessageText_);
    object_ = object;
    queue_ = queue;
  }

  /**
   * Returns the text for the action.
   *
   * @return The text.
   */
  public String getText() {
    return text_;
  }

  /** Performs the action. */
  public void perform2(VActionContext context) {
    fireStartWorking();

    try {
      int count = object_.getDetailsChildCount();
      VObject[] detailsChildren = new VObject[count];
      for (int i = 0; i < count; ++i) detailsChildren[i] = object_.getDetailsChildAt(i);

      queue_.remove();

      for (int i = 0; i < count; ++i) fireObjectDeleted(detailsChildren[i]);
    } catch (Exception e) {
      fireError(e);
    }

    fireStopWorking();
  }
}
 private Resource getResourceWithinContext(String uri) {
   if (resourceLoader == null)
     throw new IllegalStateException(
         "TemplateEngine not initialised correctly, no [resourceLoader] specified!");
   if (Environment.getCurrent().isReloadEnabled() && Metadata.getCurrent().isWarDeployed()) {
     return resourceLoader.getResource(uri);
   }
   Resource r = servletContextLoader.getResource(uri);
   if (r.exists()) return r;
   return resourceLoader.getResource(uri);
 }
 private List<ResourceLoaderInfo> doGetResourceLoaders(final Module module) {
   final ModuleClassLoader classLoader = module.getClassLoaderPrivate();
   final ResourceLoader[] loaders = classLoader.getResourceLoaders();
   final ArrayList<ResourceLoaderInfo> list = new ArrayList<ResourceLoaderInfo>(loaders.length);
   for (ResourceLoader resourceLoader : loaders) {
     list.add(
         new ResourceLoaderInfo(
             resourceLoader.getClass().getName(),
             new ArrayList<String>(resourceLoader.getPaths())));
   }
   return list;
 }
  @Override
  public void processExcption(BeetlException ex, Writer writer) {

    ErrorInfo error = new ErrorInfo(ex);
    int line = error.getErrorTokenLine();
    StringBuilder sb =
        new StringBuilder(">>")
            .append(error.getType())
            .append(":")
            .append(error.getErrorTokenText())
            .append(" 位于")
            .append(line)
            .append("行")
            .append(" 资源:")
            .append(getResourceName(ex.resourceId));
    ;
    println(writer, sb.toString());
    if (error.getErrorCode().equals(BeetlException.TEMPLATE_LOAD_ERROR)) {
      printCause(error, writer);
      return;
    }

    ResourceLoader resLoader = ex.gt.getResourceLoader();
    // 潜在问题,此时可能得到是一个新的模板,不过可能性很小,忽略!

    String content = null;
    ;
    try {
      Resource res = resLoader.getResource(ex.resourceId);
      // 显示前后三行的内容
      int[] range = this.getRange(line);
      content = res.getContent(range[0], range[1]);
      if (content != null) {
        String[] strs = content.split(ex.cr);
        int lineNumber = range[0];
        for (int i = 0; i < strs.length; i++) {
          print(writer, "" + lineNumber);
          print(writer, "|");
          println(writer, strs[i]);
          lineNumber++;
        }
      }
    } catch (IOException e) {

      // ingore

    }

    printCause(error, writer);
  }
  @Override
  public void onSurfaceCreated(GL10 unused, EGLConfig config) {

    // Set the background frame color
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    ResourceLoader loader = ResourceLoader.getResourceLoader();
    mMesh = loader.getMeshByName("hammer");
    mMesh.initialize();

    GLES20.glEnable(GL10.GL_CULL_FACE);
    // GLES20.glCullFace(GL10.GL_BACK);

    // mTriangle = new Triangle();
    // mSquare   = new Square();
  }
  @Test
  public void getResourceTest() throws IOException {
    org.springframework.core.io.Resource resource =
        resourceLoader.getResource("classpath:log/log4j.xml");

    Assert.assertNotNull(resource);
  }
  @Test
  public void getResourcesTest() throws IOException {
    org.springframework.core.io.Resource[] resourceArray =
        resourceLoader.getResources("classpath:log/log4j.xml");

    Assert.assertTrue(ArrayUtils.isNotEmpty(resourceArray) && resourceArray.length == 1);
  }
Exemple #18
0
  public PhongShader() {
    super();

    addVertexShader(ResourceLoader.loadShader("phongVertex.vs"));
    addFragmentShader(ResourceLoader.loadShader("phongFragment.fs"));
    compileShader();

    addUniform("transform");
    addUniform("transformProjected");
    addUniform("baseColor");
    addUniform("ambientLight");

    addUniform("directionalLight.base.color");
    addUniform("directionalLight.base.intensity");
    addUniform("directionalLight.direction");
  }
  @Lock(LockType.WRITE)
  public void put(String id, EObject value) {
    if (store.get(id) == null) {
      EObject obj = getEObjectByID(id);
      store.put(id, obj);
    }

    EObject obj = store.get(id);
    EList<EAttribute> eAttributes = obj.eClass().getEAllAttributes();
    for (EAttribute eAttribute : eAttributes) {
      obj.eSet(eAttribute, value.eGet(eAttribute));
      store.remove(id);
    }
    if (validation.getFlag()) {
      Diagnostic d = Diagnostician.INSTANCE.validate(obj);
      if (d.getSeverity() == Diagnostic.ERROR)
        throw new WebApplicationException(Status.BAD_REQUEST);
    }
    try {
      resourceLoader.getResource().save(Collections.EMPTY_MAP);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  public Medkit(Transform transform) {
    if (mesh == null) {
      mesh = new Mesh();

      float sizeY = 0.4f;
      float sizeX = (float) ((double) sizeY / (0.67857142857142857142857142857143 * 4.0));

      float offsetX = 0.05f;
      float offsetY = 0.00f;

      float texMinX = -offsetX;
      float texMaxX = -1 - offsetX;
      float texMinY = -offsetY;
      float texMaxY = 1 - offsetY;

      Vertex[] verts =
          new Vertex[] {
            new Vertex(new Vector3f(-sizeX, 0, 0), new Vector2f(texMaxX, texMaxY)),
            new Vertex(new Vector3f(-sizeX, sizeY, 0), new Vector2f(texMaxX, texMinY)),
            new Vertex(new Vector3f(sizeX, sizeY, 0), new Vector2f(texMinX, texMinY)),
            new Vertex(new Vector3f(sizeX, 0, 0), new Vector2f(texMinX, texMaxY))
          };

      int[] indices = new int[] {0, 1, 2, 0, 2, 3};

      mesh.addVertices(verts, indices);
    }

    if (material == null) {
      material = new Material(ResourceLoader.loadTexture("MEDIA0.png"));
    }

    this.transform = transform;
  }
  /**
   * Creates a new GraphicUI with the given title.
   *
   * @param title the title of the JFrame.
   */
  public GraphicUI(String title) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    f = new JFrame("BackgroundBorderExample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final Container cp = f.getContentPane();
    final JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    BufferedImage im =
        ResourceLoader.getResourceLoader().getBufferedImage(Values.MenuImages + "backsmall.jpg");
    Dimension size = new Dimension(im.getWidth(null), im.getHeight(null));
    f.setPreferredSize(size);
    f.setMinimumSize(size);
    f.setMaximumSize(size);
    f.setSize(size);
    final Border bkgrnd = new CentredBackgroundBorder(im);
    Runnable r =
        new Runnable() {
          public void run() {
            p.setBorder(bkgrnd);
            cp.repaint();
          }
        };
    SwingUtilities.invokeLater(r);
    readFile();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    p.add(createResolution(), BorderLayout.CENTER);
    p.add(createStartButton(), BorderLayout.SOUTH);

    cp.add(p);

    f.setLocationRelativeTo(null);
    f.pack();
    f.setVisible(true);
  }
 /**
  * same as {@link #getWordSet(ResourceLoader, String, boolean)}, except the input is in snowball
  * format.
  */
 protected final CharArraySet getSnowballWordSet(
     ResourceLoader loader, String wordFiles, boolean ignoreCase) throws IOException {
   List<String> files = splitFileNames(wordFiles);
   CharArraySet words = null;
   if (files.size() > 0) {
     // default stopwords list has 35 or so words, but maybe don't make it that
     // big to start
     words = new CharArraySet(files.size() * 10, ignoreCase);
     for (String file : files) {
       InputStream stream = null;
       Reader reader = null;
       try {
         stream = loader.openResource(file.trim());
         CharsetDecoder decoder =
             StandardCharsets.UTF_8
                 .newDecoder()
                 .onMalformedInput(CodingErrorAction.REPORT)
                 .onUnmappableCharacter(CodingErrorAction.REPORT);
         reader = new InputStreamReader(stream, decoder);
         WordlistLoader.getSnowballWordSet(reader, words);
       } finally {
         IOUtils.closeWhileHandlingException(reader, stream);
       }
     }
   }
   return words;
 }
  /**
   * Adds the keys/properties from an application-specific properties file to the System Properties.
   * The application-specific properties file MUST reside in a directory listed on the CLASSPATH.
   *
   * @param propsFileName The name of an application-specific properties file.
   */
  public static void addToSystemPropertiesFromPropsFile(String propsFileName) {
    Properties props = ResourceLoader.getAsProperties(propsFileName),
        sysProps = System.getProperties();

    // Add the keys/properties from the application-specific properties  to the System Properties.

    sysProps.putAll(props);
  }
 private EObject getEObjectByID(String id) {
   TreeIterator<EObject> eAllContents = resourceLoader.getResource().getAllContents();
   while (eAllContents.hasNext()) {
     EObject next = eAllContents.next();
     if (EcoreUtil.getIdentification(next).equals(id)) return next;
   }
   throw new WebApplicationException(Response.Status.NOT_FOUND);
 }
  panel() { // this is the game screen

    setLayout(new BorderLayout());
    setBackground(Color.white);

    rabbit = ResourceLoader.getImage("rabbit.jpg");
    rabbitHit = ResourceLoader.getImage("rabbitHit.png");
    gunRR = ResourceLoader.getImage("gunRR.jpg");
    gunRC = ResourceLoader.getImage("gunRC.jpg");
    gunCC = ResourceLoader.getImage("gunCC.jpg");
    gunLC = ResourceLoader.getImage("gunLC.jpg");
    gunLL = ResourceLoader.getImage("gunLL.jpg");
    currentImage = gunCC;

    timer = new Timer(5, new MoveRabbit());
    timer2 = new Timer(5, new MovePlus());

    ImageIcon gunIcon = new ImageIcon(currentImage);
    ImageIcon rabbitIcon = new ImageIcon(rabbit);

    JLabel rabbitLabel = new JLabel(rabbitIcon);
    JLabel gunLabel = new JLabel(gunIcon);

    addMouseListener(new ClickTarget());
    addMouseMotionListener(new MouseMovement());

    timer.start();
  }
  public boolean isFileResource() throws GenericConfigException {
    ResourceLoader loader = ResourceLoader.getLoader(this.xmlFilename, this.loaderName);

    if (loader instanceof FileLoader) {
      return true;
    } else {
      return false;
    }
  }
Exemple #27
0
  protected void refreshCacheTab() {
    // refresh list of cache hosts
    cacheBox.removeAll();
    ArrayList<JLabel> labels = new ArrayList<JLabel>();
    File cache = ResourceLoader.getOSPCache();
    File[] hosts = cache == null ? new File[0] : cache.listFiles(ResourceLoader.OSP_CACHE_FILTER);
    clearCacheButton.setEnabled(hosts.length > 0);

    if (hosts.length == 0) {
      JLabel label = new JLabel(ToolsRes.getString("LibraryManager.Cache.IsEmpty")); // $NON-NLS-1$
      label.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
      Box box = Box.createHorizontalBox();
      box.add(label);
      box.add(Box.createHorizontalGlue());
      cacheBox.add(box);
      return;
    }

    for (File hostFile : hosts) {
      // eliminate the "osp-" that starts all cache host filenames
      String hostText = hostFile.getName().substring(4).replace('_', '.');
      long bytes = getFileSize(hostFile);
      long size = bytes / (1024 * 1024);
      if (bytes > 0) {
        if (size > 0) hostText += " (" + size + " MB)"; // $NON-NLS-1$ //$NON-NLS-2$
        else hostText += " (" + bytes / 1024 + " kB)"; // $NON-NLS-1$ //$NON-NLS-2$
      }
      JLabel label = new JLabel(hostText);
      label.setToolTipText(hostFile.getAbsolutePath());
      labels.add(label);

      ClearHostButton button = new ClearHostButton(hostFile);

      Box bar = Box.createHorizontalBox();
      bar.add(label);
      bar.add(button);
      bar.add(Box.createHorizontalGlue());

      cacheBox.add(bar);
      FontSizer.setFonts(cacheBox, FontSizer.getLevel());
    }

    // set label sizes
    FontRenderContext frc = new FontRenderContext(null, false, false);
    Font font = labels.get(0).getFont();
    int w = 0;
    for (JLabel next : labels) {
      Rectangle2D rect = font.getStringBounds(next.getText(), frc);
      w = Math.max(w, (int) rect.getWidth());
    }
    Dimension labelSize = new Dimension(w + 48, 20);
    for (JLabel next : labels) {
      next.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
      next.setPreferredSize(labelSize);
    }
  }
  @Lock(LockType.WRITE)
  public void save() {

    try {
      resourceLoader.getResource().save(Collections.EMPTY_MAP);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Exemple #29
0
  /** Does some basic initialization to get the application started */
  @Override
  public void simpleInitApp() {

    loader = new ResourceLoader(assetManager, cam, rootNode);
    rootNode.attachChild(loader.getSky());

    cam.setFrustumFar(9000);

    gui = new GuiAppState();
    stateManager.attach(gui);
  }
 @Lock(LockType.WRITE)
 private EObject getEObjectByID(String type, String id) {
   TreeIterator<EObject> eAllContents = resourceLoader.getResource().getAllContents();
   while (eAllContents.hasNext()) {
     EObject next = eAllContents.next();
     if (next.eClass().getInstanceTypeName().equals(type)
         && EcoreUtil.getID(next) != null
         && EcoreUtil.getID(next).equals(id)) return next;
   }
   throw new WebApplicationException(Response.Status.NOT_FOUND);
 }