Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Feb 9th, 2010 | Syntax: Java | Size: 8.49 KB | Hits: 29 | Expires: Never
Copy text to clipboard
  1. package org.AlbumGenerator.Misc;
  2.  
  3. import org.AlbumGenerator.Gui.Interface;
  4. import org.AlbumGenerator.List.Foto;
  5.  
  6. import javax.swing.*;
  7. import java.io.*;
  8. import java.net.URL;
  9. import java.util.ArrayList;
  10.  
  11. /**
  12.  * Created by IntelliJ IDEA.
  13.  * Author  : Serenity
  14.  * From    : Rune-server.org
  15.  * Date    : 9-feb-2010
  16.  * Time    : 19:31:43
  17.  * Package : org.AlbumGenerator.Misc
  18.  */
  19. public class Constant {
  20.  
  21.  
  22.     private Interface gui;
  23.  
  24.     public Constant(Interface gui) {
  25.         this.gui = gui;
  26.         for (int i = 0; i < 500; i++) {
  27.             fotolist.add(new Foto("dc500" + i));
  28.         }
  29.     }
  30.  
  31.     public void createFotoOverzicht() {
  32.         boolean shouldInsert = false;
  33.         InputStream instr = null;
  34.         String page = "";
  35.         try {
  36.             instr = new URL("http://www.boskabouters.nl/Foto's.html").openStream();
  37.             BufferedReader in = new BufferedReader(new InputStreamReader(instr));
  38.             for (String j = in.readLine(); j != null; j = in.readLine()) {
  39.  
  40.                 if (shouldInsert)
  41.                     if (!(j.contains(" <p><strong><a href=\"foto's/"))) {
  42.                         if (j.contains(" <p>&nbsp;</p>")) {
  43.                             j = "\t    <p><strong><a href=\"foto's/" + gui.getAlbumName() + "/index.html\">" + gui.getAlbumName() + "</a></strong></p>";
  44.                         } else {
  45.                             j += "\n\t    <p><strong><a href=\"foto's/" + gui.getAlbumName() + "/index.html\">" + gui.getAlbumName() + "</a></strong></p>";
  46.                         }
  47.                         shouldInsert = false;
  48.                     }
  49.                 page += j + "\n";
  50.  
  51.                 if (j.contains("<td colspan=\"11\" align=\"center\" valign=\"top\" background=\"afbeeldingen/Foto's_07.gif\"><p>&nbsp;</p>")) {
  52.                     shouldInsert = true;
  53.                 }
  54.             }
  55.         } catch (IOException e) {
  56.             e.printStackTrace();
  57.         }
  58.         BufferedWriter bf;
  59.         try {
  60.             bf = new BufferedWriter(new FileWriter(gui.getAlbumDestination() + "Foto's.html", false));
  61.             bf.write(page);
  62.             bf.flush();
  63.             bf.write(page);
  64.         } catch (IOException e) {
  65.             e.printStackTrace();
  66.         }
  67.     }
  68.  
  69.  
  70.     public void createAlbumIndexPage(int index) {
  71.  
  72.         InputStream instr = null;
  73.         String page = "";
  74.         int fotoIndex = 0;
  75.         int rowcount = 0;
  76.         boolean[] rows = new boolean[4];
  77.         boolean indexes = false;
  78.         try {
  79.             instr = new URL("http://www.boskabouters.nl/AlbumIndex.html").openStream();
  80.             BufferedReader in = new BufferedReader(new InputStreamReader(instr));
  81.             for (String j = in.readLine(); j != null; j = in.readLine()) {
  82.  
  83.                 if (rows[0]) {
  84.                     j = "  <td><a href=\"" + ((index * 16) + fotoIndex) + ".html" + "\"><img src=\"" + (fotolist.get((index * 16) + fotoIndex++).getFoto()) + ".jpg\" alt=\"-\" width=\"100\" height=\"75\"border=\"0\"></a></td>";
  85.                     rowcount++;
  86.                     if (rowcount == 4)
  87.                         rows[0] = false;
  88.                 }
  89.                 if (rows[1]) {
  90.                     j = "  <td><a href=\"" + ((index * 16) + fotoIndex) + ".html" + "\"><img src=\"" + (fotolist.get((index * 16) + fotoIndex++).getFoto()) + ".jpg\" alt=\"-\" width=\"100\" height=\"75\"border=\"0\"></a></td>";
  91.                     rowcount++;
  92.                     if (rowcount == 8)
  93.                         rows[1] = false;
  94.                 }
  95.                 if (rows[2]) {
  96.                     j = "  <td><a href=\"" + ((index * 16) + fotoIndex) + ".html" + "\"><img src=\"" + (fotolist.get((index * 16) + fotoIndex++).getFoto()) + ".jpg\" alt=\"-\" width=\"100\" height=\"75\"border=\"0\"></a></td>";
  97.                     rowcount++;
  98.                     if (rowcount == 12)
  99.                         rows[2] = false;
  100.                 }
  101.                 if (rows[3]) {
  102.                     j = "  <td><a href=\"" + ((index * 16) + fotoIndex) + ".html" + "\"><img src=\"" + (fotolist.get((index * 16) + fotoIndex++).getFoto()) + ".jpg\" alt=\"-\" width=\"100\" height=\"75\"border=\"0\"></a></td>";
  103.                     rowcount++;
  104.                     if (rowcount == 16)
  105.                         rows[3] = false;
  106.                 }
  107.                 if (indexes) {
  108.                     System.out.println("======================INdexes===================");
  109.                     j = "";
  110.                     int aantalIndexes = getAmountofIndexPages();
  111.                     for (int i = 0; i < aantalIndexes; i++) {
  112.                         if (i == (aantalIndexes / 2)) {
  113.                             j += "<br>\n";
  114.                         }
  115.                         j += "<a href=\"http://www.boskabouters.nl/foto's/" + gui.getAlbumName() + "/index" + (i == 0 ? "" : i) + ".html\" target=\"_self\">[" + (i + 1) + "]</a>\n";
  116.                     }
  117.                   indexes  = false;
  118.                 }
  119.                 page += j + "\n";
  120.                 if (j.contains("<!-- insert row1 -->"))
  121.                     rows[0] = true;
  122.                 if (j.contains("<!-- insert row2 -->"))
  123.                     rows[1] = true;
  124.                 if (j.contains("<!-- insert row3 -->"))
  125.                     rows[2] = true;
  126.                 if (j.contains("<!-- insert row4 -->"))
  127.                     rows[3] = true;
  128.                 if (j.contains("<!-- insert Indexes -->"))
  129.                     indexes = true;
  130.             }
  131.         } catch (IOException e) {
  132.             e.printStackTrace();
  133.         }
  134.         System.out.println(page);
  135.     }
  136.  
  137.  
  138.     public static int[] getTumbSize(ImageIcon image) {
  139.         return new int[]{image.getIconWidth(), image.getIconHeight()};
  140.     }
  141.  
  142.     public static int[] getFotoSize(ImageIcon image) {
  143.         return new int[]{image.getIconWidth(), image.getIconHeight()};
  144.     }
  145.  
  146.     public static ArrayList<Foto> fotolist = new ArrayList<Foto>();
  147.  
  148.     public int getAmountofIndexPages() {
  149.         int size = fotolist.size();
  150.         int pages = 0;
  151.         for (int i = 0; i < 40; i++) {
  152.             if (size > 16) {
  153.                 pages++;
  154.                 size -= 16;
  155.             } else {
  156.                 pages++;
  157.                 break;
  158.             }
  159.         }
  160.         return pages;
  161.     }
  162. }
  163. /*
  164.                 <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index.html" target="_self">[1]</a>
  165.                 <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index1.html" target="_self">[2]</a>
  166.                 <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index2.html" target="_self">[3]</a>
  167.                 <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index3.html" target="_self">[4]</a>
  168.                 <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index4.html" target="_self">[5]</a>
  169.                 <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index5.html" target="_self">[6]</a>
  170.                 <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index6.html" target="_self">[7]</a>
  171.                 <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index7.html" target="_self">[8]</a>
  172.                 <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index8.html" target="_self">[9]</a>
  173.                 <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index9.html" target="_self">[10]</a><br>
  174.                 <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index10.html" target="_self">[11]</a>
  175.             <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index11.html" target="_self">[12]</a>
  176.             <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index12.html" target="_self">[13]</a>
  177.             <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index13.html" target="_self">[14]</a>
  178.             <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index14.html" target="_self">[15]</a>
  179.             <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index15.html" target="_self">[16]</a>
  180.             <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index16.html" target="_self">[17]</a>
  181.             <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index17.html" target="_self">[18]</a>
  182.             <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index18.html" target="_self">[19]</a>
  183.             <a href="http://www.boskabouters.nl/foto's/Bulgarije%202009%20deel%201/index19.html" target="_self">[20]</a>
  184.              <br>
  185.              */