Example #1
1
 public MapBuilder(String name, File toLoad, File toSave, String tileDir) {
   super(name);
   currTileImg = null;
   currTileLoc = "";
   try {
     System.out.println(tileDir);
     currTileImg = new ImageIcon(getTile(tileDir, 0, 0, DISPLAY_SCALE));
     currTileLoc = "0_0";
   } catch (IOException e) {
     System.out.println("Generating current tile failed.");
     System.out.println(e);
     System.exit(0);
   }
   currTileDisplay = new JLabel(new ImageIcon(scaleImage(currTileImg.getImage(), 2)));
   this.input = toLoad;
   output = toSave;
   this.tileDir = tileDir;
   if (toLoad != null) {
     try {
       backEnd = loadMap(toLoad);
     } catch (FileNotFoundException e) {
       System.err.println("Could not find input file.");
       System.exit(0);
     }
   } else {
     backEnd = emptyMap(DEFAULT_WIDTH, DEFAULT_HEIGHT);
   }
   mapWidth = backEnd.getWidth();
   mapHeight = backEnd.getHeight();
 }
  /**
   * Reads image meta data.
   *
   * @param oimage
   * @return
   */
  public static Map<String, String> readImageData(IIOImage oimage) {
    Map<String, String> dict = new HashMap<String, String>();

    IIOMetadata imageMetadata = oimage.getMetadata();
    if (imageMetadata != null) {
      IIOMetadataNode dimNode = (IIOMetadataNode) imageMetadata.getAsTree("javax_imageio_1.0");
      NodeList nodes = dimNode.getElementsByTagName("HorizontalPixelSize");
      int dpiX;
      if (nodes.getLength() > 0) {
        float dpcWidth = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue());
        dpiX = (int) Math.round(25.4f / dpcWidth);
      } else {
        dpiX = Toolkit.getDefaultToolkit().getScreenResolution();
      }
      dict.put("dpiX", String.valueOf(dpiX));

      nodes = dimNode.getElementsByTagName("VerticalPixelSize");
      int dpiY;
      if (nodes.getLength() > 0) {
        float dpcHeight = Float.parseFloat(nodes.item(0).getAttributes().item(0).getNodeValue());
        dpiY = (int) Math.round(25.4f / dpcHeight);
      } else {
        dpiY = Toolkit.getDefaultToolkit().getScreenResolution();
      }
      dict.put("dpiY", String.valueOf(dpiY));
    }

    return dict;
  }
Example #3
0
  public Map loadMap(File input) throws FileNotFoundException {
    Scanner s = new Scanner(input);
    tileDir = s.nextLine();
    int width = s.nextInt();
    int height = s.nextInt();
    Map toReturn = new Map(width, height, tileDir);
    s.nextLine(); // eat up rest of line.
    for (int y = 0; y < height; y++) {
      String line = s.nextLine();
      Scanner lineReader = new Scanner(line);
      List<Tile> tList = new ArrayList<Tile>();
      for (int x = 0; x < width; x++) {
        String[] values = lineReader.next().split("/");
        String name = values[0];
        int[] picLocation = new int[2];
        for (int i = 0; i < picLocation.length; i++) {
          picLocation[i] = Integer.parseInt(values[1].split("_")[i]);
        }
        ImageIcon img = null;
        try {
          img = new ImageIcon(getTile(tileDir, picLocation[0], picLocation[1], DISPLAY_SCALE));
        } catch (IOException e) {
          System.out.println("Could not find image.");
          img =
              new ImageIcon(
                  new BufferedImage(
                      TILE_SIZE * DISPLAY_SCALE,
                      TILE_SIZE * DISPLAY_SCALE,
                      BufferedImage.TYPE_INT_RGB));
        }
        int avoid = Integer.parseInt(values[2]);
        int def = Integer.parseInt(values[3]);
        String[] movString = values[4].split(",");
        int[] moveCost = new int[movString.length];
        for (int i = 0; i < moveCost.length; i++) {
          moveCost[i] = Integer.parseInt(movString[i]);
        }
        String special = values[5];

        Tile t =
            new Tile(
                img,
                name,
                avoid,
                def,
                moveCost,
                special,
                true,
                "" + picLocation[0] + "_" + picLocation[1]);
        tList.add(t);
        t.setMaximumSize(new Dimension(TILE_SIZE * DISPLAY_SCALE, TILE_SIZE * DISPLAY_SCALE));
        t.setPreferredSize(new Dimension(TILE_SIZE * DISPLAY_SCALE, TILE_SIZE * DISPLAY_SCALE));
        t.addMouseListener(new MapButtonListener());
      }
      toReturn.addRow(tList);
    }
    return toReturn;
  }
 /** highlight a route (maybe to show it's in use...) */
 public void highlightRoute(String src, String dst) {
   Iterator i = rows.iterator();
   while (i.hasNext()) {
     Map temp = (Map) i.next();
     if (temp.get("Address").equals(dst) && temp.get("Pivot").equals(src)) {
       temp.put("Active", Boolean.TRUE);
     }
   }
 }
 /** show the meterpreter routes . :) */
 public void setRoutes(Route[] routes) {
   Iterator i = rows.iterator();
   while (i.hasNext()) {
     Map temp = (Map) i.next();
     for (int x = 0; x < routes.length; x++) {
       Route r = routes[x];
       if (r.shouldRoute(temp.get("Address") + "")) temp.put("Pivot", r.getGateway());
     }
   }
 }
Example #6
0
    V get(final K key) {
      if (refs == null) refs = new HashMap<>();

      final V cachedValue = refs.get(key);
      if (cachedValue != null) return cachedValue;

      final V value = getInstance(key);
      refs.put(key, value);
      return value;
    }
Example #7
0
 /**
  * Returns a map with the specified dimensions filled with the currTile image. The image should be
  * the upper-left tile of a given tileset if this is called from the constructor.
  */
 public Map emptyMap(int width, int height) {
   Map toReturn = new Map(width, height, tileDir);
   int[] mov = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
   for (int i = 0; i < height; i++) {
     List<Tile> tList = new ArrayList<Tile>();
     for (int j = 0; j < width; j++) {
       Tile t = new Tile(currTileImg, "Test", 0, 0, mov, "none", true, currTileLoc);
       tList.add(t);
       // t.setMargin(new Insets(0,0,0,0));
       t.setMaximumSize(new Dimension(TILE_SIZE * DISPLAY_SCALE, TILE_SIZE * DISPLAY_SCALE));
       t.setPreferredSize(new Dimension(TILE_SIZE * DISPLAY_SCALE, TILE_SIZE * DISPLAY_SCALE));
       // tile.setPreferredSize(new Dimension(TILE_SIZE*DISPLAY_SCALE, TILE_SIZE*DISPLAY_SCALE));
       t.addMouseListener(new MapButtonListener());
     }
     toReturn.addRow(tList);
   }
   return toReturn;
 }
Example #8
0
  /** Constructs a panel containing an options menu, then returns said panel. */
  public JPanel buildOptionsMenu() {
    JPanel options = new JPanel();

    // Create the height/width section
    JPanel dimensions = new JPanel();
    dimensions.setLayout(new BoxLayout(dimensions, BoxLayout.Y_AXIS));

    JLabel widthLabel = new JLabel("X:");
    JTextField widthBox = new JTextField(10);
    widthField = widthBox;
    JPanel width = new JPanel();
    width.add(widthLabel);
    width.add(widthBox);

    JLabel heightLabel = new JLabel("Y:");
    JTextField heightBox = new JTextField(10);
    heightField = heightBox;
    JPanel height = new JPanel();
    height.add(heightLabel);
    height.add(heightBox);

    dimensions.add(width);
    dimensions.add(height);

    // "Apply changes" button
    JButton apply = new JButton("Apply Changes");
    apply.addActionListener(new ApplyHWChanges());

    // Fill option
    JButton fill = new JButton("Fill with current tile");
    fill.addActionListener(new FillButton());
    options.add(fill);

    // Current selected tile
    JPanel tileArea = new JPanel();
    tileArea.setLayout(new BoxLayout(tileArea, BoxLayout.Y_AXIS));
    tileArea.add(new JLabel("Current Tile"));

    tileArea.add(currTileDisplay);

    // remove once testing is done
    backEnd.setTestImage(currTileImg);

    // Save button
    JButton save = new JButton("Save");
    save.addActionListener(new SaveButton());

    options.add(dimensions);
    options.add(apply);
    options.add(tileArea);
    options.add(save);
    return options;
  }
  // Constructor connection receiving a socket number
  public ClientGUI(String host, int port, int udpPort) {

    super("Clash of Clans");
    defaultPort = port;
    defaultUDPPort = udpPort;
    defaultHost = host;

    // the server name and the port number
    JPanel serverAndPort = new JPanel(new GridLayout(1, 5, 1, 3));
    tfServer = new JTextField(host);
    tfPort = new JTextField("" + port);
    tfPort.setHorizontalAlignment(SwingConstants.RIGHT);

    // CHAT COMPONENTS
    chatStatus = new JLabel("Please login first", SwingConstants.LEFT);
    chatField = new JTextField(18);
    chatField.setBackground(Color.WHITE);

    JPanel chatControls = new JPanel();
    chatControls.add(chatStatus);
    chatControls.add(chatField);
    chatControls.setBounds(0, 0, 200, 50);

    chatArea = new JTextArea("Welcome to the Chat room\n", 80, 80);
    chatArea.setEditable(false);
    JScrollPane jsp = new JScrollPane(chatArea);
    jsp.setBounds(0, 50, 200, 550);

    JPanel chatPanel = new JPanel(null);
    chatPanel.setSize(1000, 600);
    chatPanel.add(chatControls);
    chatPanel.add(jsp);

    // LOGIN COMPONENTS
    mainLogin = new MainPanel();
    mainLogin.add(new JLabel("Main Login"));

    usernameField = new JTextField("user", 15);
    passwordField = new JTextField("password", 15);
    login = new CButton("Login");
    login.addActionListener(this);

    sideLogin = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    sideLogin.add(usernameField);
    sideLogin.add(passwordField);
    sideLogin.add(login);

    // MAIN MENU COMPONENTS
    mainMenu = new MainPanel();
    mmLabel = new JLabel("Main Menu");
    timer = new javax.swing.Timer(1000, this);
    mainMenu.add(mmLabel);

    sideMenu = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    cmButton = new CButton("Customize Map");
    tmButton = new CButton("Troop Movement");
    gsButton = new CButton("Game Start");
    logout = new CButton("Logout");
    cmButton.addActionListener(this);
    tmButton.addActionListener(this);
    gsButton.addActionListener(this);
    logout.addActionListener(this);
    sideMenu.add(cmButton);
    // sideMenu.add(tmButton);
    sideMenu.add(gsButton);
    sideMenu.add(logout);

    // CM COMPONENTS
    mainCM = new MainPanel(new GridLayout(mapSize, mapSize));
    tiles = new Tile[mapSize][mapSize];
    int tileSize = mainCM.getWidth() / mapSize;
    for (int i = 0; i < mapSize; i++) {
      tiles[i] = new Tile[mapSize];
      for (int j = 0; j < mapSize; j++) {
        tiles[i][j] = new Tile(i, j);
        tiles[i][j].setPreferredSize(new Dimension(tileSize, tileSize));
        tiles[i][j].setSize(tileSize, tileSize);
        tiles[i][j].addActionListener(this);

        if ((i + j) % 2 == 0) tiles[i][j].setBackground(new Color(102, 255, 51));
        else tiles[i][j].setBackground(new Color(51, 204, 51));

        mainCM.add(tiles[i][j]);
      }
    }

    sideCM = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    cmBack = new CButton("Main Menu");
    cmBack.setSize(150, 30);
    cmBack.setPreferredSize(new Dimension(150, 30));
    cmBack.addActionListener(this);
    sideCM.add(cmBack);

    // TM COMPONENTS
    mainTM = new MainPanel(null);
    mapTM = new Map(600);
    mapTM.setPreferredSize(new Dimension(600, 600));
    mapTM.setSize(600, 600);
    mapTM.setBounds(0, 0, 600, 600);
    mainTM.add(mapTM);

    sideTM = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    tmBack = new CButton("Main Menu");
    tmBack.setSize(150, 30);
    tmBack.setPreferredSize(new Dimension(150, 30));
    tmBack.addActionListener(this);
    sideTM.add(tmBack);

    JRadioButton button;
    ButtonGroup group;

    ub = new ArrayList<JRadioButton>();
    group = new ButtonGroup();

    button = new JRadioButton("Barbarian");
    button.addActionListener(this);
    ub.add(button);
    sideTM.add(button);
    group.add(button);

    button = new JRadioButton("Archer");
    button.addActionListener(this);
    ub.add(button);
    sideTM.add(button);
    group.add(button);

    createBuildings();
    bb = new ArrayList<JRadioButton>();

    group = new ButtonGroup();

    JRadioButton removeButton = new JRadioButton("Remove Building");
    bb.add(removeButton);
    sideCM.add(removeButton);
    group.add(removeButton);

    for (int i = 0; i < bList.size(); i++) {
      button = new JRadioButton(bList.get(i).getName() + '-' + bList.get(i).getQuantity());
      bb.add(button);
      sideCM.add(button);
      group.add(button);
    }

    mainPanels = new MainPanel(new CardLayout());
    mainPanels.add(mainLogin, "Login");
    mainPanels.add(mainMenu, "Menu");
    mainPanels.add(mainCM, "CM");
    mainPanels.add(mainTM, "TM");

    sidePanels = new SidePanel(new CardLayout());
    sidePanels.add(sideLogin, "Login");
    sidePanels.add(sideMenu, "Menu");
    sidePanels.add(sideCM, "CM");
    sidePanels.add(sideTM, "TM");

    JPanel mainPanel = new JPanel(null);
    mainPanel.setSize(1000, 600);
    mainPanel.add(sidePanels);
    mainPanel.add(mainPanels);
    mainPanel.add(chatPanel);

    add(mainPanel, BorderLayout.CENTER);

    try {
      setIconImage(ImageIO.read(new File("images/logo.png")));
    } catch (IOException exc) {
      exc.printStackTrace();
    }

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(1000, 600);
    setVisible(true);
    setResizable(false);
    chatField.requestFocus();
  }
  public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();

    for (JRadioButton u : ub) {
      if (o == u) {
        mapTM.setUnitType(u.getText());
        System.out.println("Set unit type - " + u.getText());
        return;
      }
    }

    if (o == timer) {

      /*
      mmLabel.setText("Main Menu ("+(cdTime--)+")");

      if(cdTime == 0){
      	timer.stop();
      	gsButton.setText("Game Start");
      	mmLabel.setText("Main Menu");

      	ArrayList<Building> bArr = new ArrayList<Building>();

      	String temp = "Elixir Collector-24,8-960|Elixir Collector-31,8-960|Gold Mine-17,10-960|Elixir Collector-25,21-960|Elixir Collector-11,22-960";
      	String[] bs = temp.split("\\|");
      	for(String b : bs){
      		String[] bParts = b.split("-");
      		String[] cParts = bParts[1].split(",");
      		int x = Integer.parseInt(cParts[0].trim());
      		int y = Integer.parseInt(cParts[1].trim());

      		Building tb = new Building(bParts[0], new Coordinate(x,y));
      		tb.setHp(Integer.parseInt(bParts[2].trim()));

      		bArr.add(tb);
      	}



      	mapTM.setBuildings(bArr);
      	switchCards("TM");
      }
      */

      return;
    }

    if (o == gsButton) {

      if (timer.isRunning()) {
        // timer.stop();
        gsButton.setText("Game Start");
        mmLabel.setText("Main Menu");
        // sends the leave command
        client.sendUDP("leave~" + unameUDP);
        return;
      }
      // sends the joinlobby command
      client.sendUDP("joinlobby~" + unameUDP);
      // gsButton.setText("Game Stop");
      String serverResp = client.receiveUDP();

      if (serverResp.trim().equals("false")) {

        // place false handler here

      } else {

        String[] enemies = serverResp.trim().split(",");
        ArrayList<Building> bArr = new ArrayList<Building>();
        String mapConfig = getBaseConfig(enemies[0]);
        String[] bs = mapConfig.split("\\|");
        for (String b : bs) {

          String[] bParts = b.split("-");
          String[] cParts = bParts[1].split(",");
          int x = Integer.parseInt(cParts[0].trim());
          int y = Integer.parseInt(cParts[1].trim());

          Building tb = new Building(bParts[0], new Coordinate(x, y));
          tb.setHp(Integer.parseInt(bParts[2].trim()));
          bArr.add(tb);
        }

        mapTM.setBuildings(bArr);
        switchCards("TM");
      }

      // System.out.println(serverResp);
      // cdTime = 10;
      // timer.start();
      return;
    }

    if (o == logout) {
      client.sendMessage(new ChatMessage(ChatMessage.LOGOUT, ""));
      chatArea.setText("");

      switchCards("Login");
      return;
    }

    if (o == cmButton) {
      String baseConfig = getBaseConfig();
      System.out.println("base config: " + baseConfig);

      for (int i = 0; i < mapSize; i++) {
        for (int j = 0; j < mapSize; j++) {
          tiles[i][j].setValue("");
        }
      }

      if (!baseConfig.equals("")) {

        String[] bs = baseConfig.split("\\|");
        for (String b : bs) {
          String[] bParts = b.split("-");
          String[] cParts = bParts[1].split(",");
          int x = Integer.parseInt(cParts[0].trim());
          int y = Integer.parseInt(cParts[1].trim());

          int index = 0;
          for (int i = 0; i < bb.size(); i++) {
            if (bb.get(i).getText().split("-")[0].trim().equals(bParts[0])) {
              index = i;
              break;
            }
          }
          insertBuilding(y, x, index);
        }
      }

      switchCards("CM");

      return;
    }

    if (o == tmButton) {

      ArrayList<Building> bArr = new ArrayList<Building>();

      for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 40; j++) {
          if (tiles[i][j].getValue().equals("") || tiles[i][j].getValue().contains("-")) {
            continue;
          }
          // weird part here
          bArr.add(new Building(tiles[i][j].getValue(), new Coordinate(j, i)));
        }
      }

      mapTM.setBuildings(bArr);

      switchCards("TM");
      return;
    }

    // if it the who is in button
    if (o == whoIsIn) {
      client.sendMessage(new ChatMessage(ChatMessage.WHOISIN, ""));
      return;
    }

    if (o == cmBack) {
      ArrayList<Building> bArr = new ArrayList<Building>();
      for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 40; j++) {
          if (tiles[i][j].getValue().equals("") || tiles[i][j].getValue().contains("-")) {
            continue;
          }
          // weird part here
          bArr.add(new Building(tiles[i][j].getValue(), new Coordinate(j, i)));
        }
      }

      String temp = "mapdata~" + unameUDP + "~";
      int tileCount = 40;
      int dim = 600;
      int tileDim = (int) (dim / tileCount);
      int counter = 0;
      for (Building b : bArr) {
        int x, y, hp;
        x = b.getPos().getX() / tileDim;
        y = b.getPos().getY() / tileDim;
        hp = b.getHp();
        temp += b.getName() + "-" + x + "," + y + "-" + hp + "|";
        counter += 1;
      }
      if (counter > 0) {
        temp = temp.substring(0, temp.length() - 1); // removes the last '|'
      } else {
        temp += "none";
      }

      client.sendUDP(temp); // allows saving of the current state of the map into the user's account

      switchCards("Menu");

      return;
    }
    if (o == tmBack) {
      switchCards("Menu");

      return;
    }

    for (int i = 0; i < 40; i++) {
      for (int j = 0; j < 40; j++) {
        if (o == tiles[i][j]) {
          for (int k = 0; k < bb.size(); k++) {
            if (bb.get(k).isSelected()) {
              if (bb.get(k).getText().equals("Remove Building")) {
                removeBuilding(i, j);
                return;
              }

              insertBuilding(i, j, k);
              // JOptionPane.showMessageDialog(null, bb.get(k).getText());
              return;
            }
          }

          // JOptionPane.showMessageDialog(null, "i-"+i+" j-"+j);
          return;
        }
      }
    }

    // ok it is coming from the JTextField
    if (connected) {
      // just have to send the message
      client.sendMessage(new ChatMessage(ChatMessage.MESSAGE, chatField.getText()));
      chatField.setText("");
      return;
    }

    if (o == login) {
      // ok it is a connection request
      String username = usernameField.getText().trim();
      String password = passwordField.getText().trim();
      // empty username ignore it
      if (username.length() == 0) return;
      // empty serverAddress ignore it
      String server = tfServer.getText().trim();
      if (server.length() == 0) return;
      // empty or invalid port numer, ignore it
      String portNumber = tfPort.getText().trim();
      if (portNumber.length() == 0) return;
      int port = 0;
      try {
        port = Integer.parseInt(portNumber);
      } catch (Exception en) {
        return; // nothing I can do if port number is not valid
      }

      // try creating a new Client with GUI
      client = new Client(server, port, username, password, this);
      // test if we can start the Client
      if (!client.start()) return;

      unameUDP = username;

      switchCards("Menu");
      // fetching of the base_config string from the database

      chatField.setText("");
      chatArea.setText("");
    }
  }
Example #11
0
  public void decode() throws IOException {
    readTagDescriptors();

    final MessageDigest md;
    try {
      md = MessageDigest.getInstance("SHA-512");
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
      return;
    }

    final ComponentColorModel colorModel =
        new ComponentColorModel(
            ColorSpace.getInstance(ColorSpace.CS_sRGB),
            true,
            false,
            Transparency.TRANSLUCENT,
            DataBuffer.TYPE_BYTE);
    final int[] bandOffsets = {2, 1, 0, 3};
    final Map<String, String> duplicateGuard = new HashMap<String, String>();
    final byte[] bytes = data.array();
    final int[] tags = new int[8];

    final List<String> symLinkCommand = new ArrayList<String>(4);
    symLinkCommand.add("ln");
    symLinkCommand.add("-s");
    symLinkCommand.add(null);
    symLinkCommand.add(null);

    for (int fileIndex = 0; fileIndex < fileCount; fileIndex++) {
      data.position(fileDescriptorsOffset + ((4 + 8) * fileIndex));
      final int fileDataOffset = data.getInt();
      int numOfTags = 8;
      for (int i = 0; i < 8; i++) {
        int tag = data.get() & 0xff;
        if (tag == 0) {
          numOfTags = i;
          break;
        }
        tags[i] = tag;
      }

      data.position(fileDataSectionOffset + fileDataOffset);
      final int artRows = data.getShort();
      final int artColumns = data.getShort();
      // skip unknown
      data.position(data.position() + 28);

      final int[] subimageOffsets = readNumericArray(9, false);
      final int[] subimageWidths = readNumericArray(9, true);
      final int[] subimageHeights = readNumericArray(9, true);

      assert numOfTags >= 2;
      final File dir;
      final int tagStartIndexForFilename;
      if (numOfTags == 2) {
        tagStartIndexForFilename = 1;
        dir = new File(outputDir, names[tags[0]].toString());
      } else {
        tagStartIndexForFilename = 2;
        dir = new File(outputDir, names[tags[0]] + "/" + names[tags[1]]);
      }

      boolean dirCreated = false;

      final int imageCount = artRows * artColumns;
      for (int subImageIndex = 0; subImageIndex < imageCount; subImageIndex++) {
        final int w = subimageWidths[subImageIndex];
        final int h = subimageHeights[subImageIndex];
        if (w <= 0 || h <= 0) {
          continue;
        }

        final int srcPos = fileDataSectionOffset + fileDataOffset + subimageOffsets[subImageIndex];
        final int srcLength = w * h * 4;

        md.update(bytes, srcPos, srcLength);
        md.update((byte) w);
        md.update((byte) h);
        final String digest = convertToHex(md.digest());
        md.reset();

        if (!dirCreated) {
          //noinspection ResultOfMethodCallIgnored
          dir.mkdirs();
          dirCreated = true;
        }

        final byte[] bgra = new byte[srcLength];
        // cannot pass bytes directly, offset in DataBufferByte is not working
        System.arraycopy(bytes, srcPos, bgra, 0, bgra.length);
        BufferedImage image =
            new BufferedImage(
                colorModel,
                (WritableRaster)
                    Raster.createRaster(
                        new PixelInterleavedSampleModel(
                            DataBuffer.TYPE_BYTE, w, h, 4, w * 4, bandOffsets),
                        new DataBufferByte(bgra, bgra.length),
                        null),
                false,
                null);

        final StringBuilder outFilename =
            createOutpuFile(
                numOfTags, tags, tagStartIndexForFilename, imageCount > 0, subImageIndex);
        final String oldOutFilename = duplicateGuard.get(digest);
        if (oldOutFilename == null) {
          File file = new File(dir, outFilename.toString());
          duplicateGuard.put(digest, file.getPath());
          ImageIO.write(image, "png", file);
        } else {
          symLinkCommand.set(2, oldOutFilename);
          symLinkCommand.set(3, dir + "/" + outFilename);
          Process process = new ProcessBuilder(symLinkCommand).start();
          try {
            if (process.waitFor() != 0) {
              throw new IOException(
                  "Can't create symlink " + symLinkCommand.get(2) + " " + symLinkCommand.get(3));
            }
          } catch (InterruptedException e) {
            throw new IOException(e);
          }
        }
      }
    }
  }
Example #12
0
  /**
   * Builds a blank display. Eventually I'll have to add loading from a map, though right now it
   * builds the map itself. I should separate that out.
   */
  public JComponent buildDisplay() {
    JPanel holder = new JPanel(new GridBagLayout());
    map = holder;

    // holder.setLayout(new GridLayout(mapHeight,mapWidth));
    // holder.setPreferredSize(new Dimension(mapWidth * TILE_SIZE * DISPLAY_SCALE,
    // 									mapHeight * TILE_SIZE * DISPLAY_SCALE));
    // holder.setMaximumSize(new Dimension(mapWidth * TILE_SIZE * DISPLAY_SCALE,
    //  									mapHeight * TILE_SIZE * DISPLAY_SCALE));
    // backEnd = emptyMap(mapWidth, mapHeight);

    GridBagConstraints gbc = new GridBagConstraints();

    // for(int i = 0; i < mapHeight; i++){
    // 	List<Tile> tList = new ArrayList<Tile>();
    // 	gbc.gridy = i;
    // 	for(int j = 0; j < mapWidth; j++){
    // 		gbc.gridx = j;
    // 		Tile t = new Tile(currTileImg, "Test", 0, 0, mov,"none",true, "0_0");
    // 		tList.add(t);
    // 		//t.setMargin(new Insets(0,0,0,0));
    // 		t.setMaximumSize(new Dimension(TILE_SIZE*DISPLAY_SCALE,TILE_SIZE*DISPLAY_SCALE));
    // 		t.setPreferredSize(new Dimension(TILE_SIZE*DISPLAY_SCALE, TILE_SIZE*DISPLAY_SCALE));
    // 		//tile.setPreferredSize(new Dimension(TILE_SIZE*DISPLAY_SCALE, TILE_SIZE*DISPLAY_SCALE));
    // 		t.addMouseListener(new MapButtonListener());
    // 		holder.add(t,gbc);

    // 	}
    // 	backEnd.addRow(tList);
    // }

    for (int i = 0; i < mapHeight; i++) {
      gbc.gridy = i;
      for (int j = 0; j < mapWidth; j++) {
        gbc.gridx = j;
        holder.add(backEnd.getTile(j, i), gbc);
      }
    }
    // gbc.gridy = 0;
    // gbc.gridx = mapWidth;
    // gbc.gridheight = GridBagConstraints.REMAINDER;
    // gbc.weightx = 1;
    // gbc.weighty = 1;
    // gbc.fill = GridBagConstraints.BOTH;
    // holder.add(new JPanel(), gbc);
    // gbc.gridx = 0;
    // gbc.gridy = mapHeight;
    // gbc.gridheight = 1;
    // gbc.gridwidth = GridBagConstraints.REMAINDER;
    // holder.add(new JPanel(), gbc);
    // System.out.println(backEnd);

    // Container panel to prevent stretching
    JPanel outer = new JPanel();
    outer.add(holder);

    // BoxLayout ensures that maxSize is honored
    // JPanel displaySizeRegulator = new JPanel();
    // displaySizeRegulator.setLayout(new BoxLayout(displaySizeRegulator, BoxLayout.X_AXIS));

    JScrollPane displayScroll =
        new JScrollPane(
            outer,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    mapScroll = displayScroll;

    // displaySizeRegulator.add(displayScroll);
    // displayRefresher = displaySizeRegulator;
    return displayScroll;
  }