Android Open Source - wannabe Swing Wannabe






From Project

Back to project page wannabe.

License

The source code is released under:

MIT License

If you think the Android project wannabe listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

// Copyright 2013 Patrick Forhan.
package wannabe.swing;
/* w  w w  .ja  v a 2s.c o  m*/
import java.awt.BorderLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import wannabe.Camera;
import wannabe.grid.Grid;
import wannabe.projection.Projection;
import wannabe.projection.Projections;
import wannabe.swing.SettingsPanel.Listener;
import wannabe.swing.WannabePanel.RenderType;
import wannabe.util.SampleGrids;

public class SwingWannabe {
  public static void main(String[] args) throws InterruptedException {
    JFrame frame = new JFrame("SwingWannabe");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel mainLayout = new JPanel(new BorderLayout());
    frame.setContentPane(mainLayout);

    final WannabePanel panel = new WannabePanel();
    final SettingsPanel settings = new SettingsPanel();
    settings.setListener(new Listener() {
      @Override public void onRenderTypeChanged(RenderType newType) {
        panel.setRenderType(newType);
      }

      @Override public void onProjectionChanged(Projection newProjection) {
        panel.setProjection(newProjection);
      }

      @Override public void onGridChanged(Grid newGrid) {
        panel.setGrid(newGrid);
      }
    });

    mainLayout.add(panel, BorderLayout.CENTER);
    mainLayout.add(settings, BorderLayout.EAST);

    panel.setGrid(SampleGrids.GRIDS.get(0));
    settings.gridSelected(SampleGrids.GRIDS.get(0));
    panel.setProjection(Projections.PROJECTIONS.get(0));
    settings.projectionSelected(Projections.PROJECTIONS.get(0));
    settings.renderTypeSelected(panel.getRenderType());

    frame.setSize(mainLayout.getPreferredSize());
    frame.setVisible(true);

    final Camera camera = panel.getCamera();
    panel.addKeyListener(new KeyAdapter() {
      @Override public void keyPressed(KeyEvent e) {
        switch (e.getKeyCode()) {
          case KeyEvent.VK_UP:
            camera.position.y--;
            break;
          case KeyEvent.VK_DOWN:
            camera.position.y++;
            break;
          case KeyEvent.VK_LEFT:
            camera.position.x--;
            break;
          case KeyEvent.VK_RIGHT:
            camera.position.x++;
            break;
          case KeyEvent.VK_Z:
            camera.position.z--;
            break;
          case KeyEvent.VK_X:
            camera.position.z++;
            break;
          case KeyEvent.VK_G:
            Grid nextGrid = SampleGrids.next(panel.getGrid());
            panel.setGrid(nextGrid);
            settings.gridSelected(nextGrid);
            break;
          case KeyEvent.VK_R:
            RenderType nextRenderType = panel.getRenderType().next();
            panel.setRenderType(nextRenderType);
            settings.renderTypeSelected(nextRenderType);
            break;
          case KeyEvent.VK_P:
            Projection next = Projections.next(panel.getProjection());
            panel.setProjection(next);
            settings.projectionSelected(next);
          default:
            // Don't care.
            break;
        }
      }
    });


    while (true) {
      panel.render();
      Thread.sleep(200);
    }
  }
}




Java Source Code List

android.util.ArrayUtils.java
android.util.SparseArray.java
android.util.SparseIntArray.java
wannabe.Camera.java
wannabe.Position.java
wannabe.Rendered.java
wannabe.UI.java
wannabe.Voxel.java
wannabe.android.MainActivity.java
wannabe.grid.FixedGrid.java
wannabe.grid.Grid.java
wannabe.grid.SimpleGrid.java
wannabe.projection.Flat.java
wannabe.projection.Isometric.java
wannabe.projection.Projection.java
wannabe.projection.Projections.java
wannabe.projection.PseudoPerspective.java
wannabe.swing.SettingsPanel.java
wannabe.swing.SwingWannabe.java
wannabe.swing.WannabePanel.java
wannabe.util.SampleGrids.java
wannabe.util.UIs.java