Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.TextArea;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyEvent;
- import java.io.*;
- import java.net.*;
- import java.util.ArrayList;
- import javax.swing.BorderFactory;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JMenu;
- import javax.swing.JMenuBar;
- import javax.swing.JMenuItem;
- import javax.swing.JPanel;
- import javax.swing.JPopupMenu;
- import javax.swing.JSplitPane;
- import javax.swing.JTextField;
- public class Switchfo
- {
- static int INFOBOXNUMBER = 3;
- static final Dimension d = new Dimension(600,500);
- static final Dimension d2 = new Dimension(530,50);
- static final Dimension d3 = new Dimension(500,50);
- static final Dimension d4 = new Dimension(500,380);
- static final Font CSMS = new Font(Font.SANS_SERIF, 0, 11);
- static final Color LIGHTG = new Color(238,238,238);
- static final TextArea source = new TextArea("", 0, 0,TextArea.SCROLLBARS_VERTICAL_ONLY);
- static final JFrame frame = new JFrame("Switchfobox");
- static final JTextField input = new JTextField("Aviansie");
- static final JButton MONSTER = new JButton("Monster");
- static final JButton NPC = new JButton("NPC");
- static final JButton BONUSES = new JButton("Bonuses");
- static final JButton[] BUTTONS = new JButton[]{ MONSTER, NPC, BONUSES };
- static final JButton start = new JButton("Go");
- static final JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
- static final JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
- public static void main(String[] args)
- {
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(d);
- frame.setResizable(false);
- start.setEnabled(true);
- source.setFont(CSMS);
- source.setBackground(LIGHTG);
- input.setSize(d4);
- JPanel inputPanel = new JPanel(new BorderLayout());
- JPanel wrapperPanel = new JPanel(new BorderLayout());
- final JPanel outputPanel = new JPanel(new BorderLayout());
- wrapperPanel.add(input, BorderLayout.CENTER);
- wrapperPanel.add(start, BorderLayout.SOUTH);
- inputPanel.add(wrapperPanel, BorderLayout.NORTH);
- outputPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 0, 0));
- outputPanel.add(source);
- start.setMnemonic(KeyEvent.VK_C);
- enableOtherButtons(MONSTER);
- MONSTER.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent arg0) {
- INFOBOXNUMBER = 3;
- enableOtherButtons(MONSTER);
- }});
- NPC.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent arg0) {
- enableOtherButtons(NPC);
- INFOBOXNUMBER = 2;
- }});
- BONUSES.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent arg0) {
- enableOtherButtons(BONUSES);
- INFOBOXNUMBER = 1;
- }});
- start.addActionListener(new ActionListener(){
- public void actionPerformed(ActionEvent arg0) {
- try {
- source.setText(runstuff(input.getText()));
- } catch (IOException e) {
- source.setText("Error trying [[" + input.getText() + "]]");
- }
- }});
- splitPane.setTopComponent(inputPanel);
- inputPanel.setPreferredSize(d2);
- inputPanel.setMinimumSize(d2);
- inputPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
- splitPane.setBottomComponent(outputPanel);
- JPanel c = new JPanel();
- inputPanel.add(c);
- JPanel frame2 = new JPanel();
- //frame2.add(start);
- for (JButton b : BUTTONS) {
- frame2.add(b);
- }
- splitPane.setPreferredSize(d3);
- sp.setBottomComponent(splitPane);
- sp.setTopComponent(frame2);
- frame.add(sp);
- frame.setLocation(100,200);
- frame.setVisible(true);
- }
- private static void enableOtherButtons(JButton a) {
- for (JButton b : BUTTONS) {
- if (a != b)
- b.setEnabled(true);
- else
- b.setEnabled(false);
- }
- }
- public static String runstuff(String page) throws IOException
- {
- String[] paramnames = new String[0];
- String INFOBOX = "";
- switch ( INFOBOXNUMBER ) {
- case 1 :
- paramnames = BONUSESPARAMS;
- INFOBOX = "Infobox bonuses multi";
- break;
- case 2 :
- paramnames = NPCPARAMS;
- INFOBOX = "Infobox npc multi";
- break;
- case 3 :
- paramnames = MONSTERPARAMS;
- INFOBOX = "Infobox monster multi";
- break;
- }
- URL oracle;
- URLConnection yc;
- BufferedReader in;
- String inputLine;
- oracle = new URL("http://runescape.wikia.com/wiki/" + page.replace(" ","_") + "?action=raw");
- yc = oracle.openConnection();
- yc.connect();
- in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
- ArrayList<ArrayList<String>> infoboxes = new ArrayList<ArrayList<String>>();
- ArrayList<String> infobox = null;
- boolean started = false;
- int extrabraces = 0;
- String text = null;
- int textn = 0;
- int infoboxn = 0;
- boolean neverStarted = true;
- while ((inputLine = in.readLine()) != null) { //System.out.println(inputLine);
- if (inputLine.matches(".*\\{\\{(?:[Tt]emplate:)?[Ss]witch.*")) {
- started = true;
- }
- if (inputLine.matches(".*\\|\\s*text\\d+\\s*=\\s*.*")) {
- String txtx = inputLine.replaceFirst(".*\\|\\s*text\\d+\\s*=\\s*(.*?)(\\}\\})?","$1");
- text = txtx;
- textn++;
- }
- if (started) {
- if (inputLine.matches(".*\\|\\s*item\\d+\\s*=.*")) {
- infobox = new ArrayList<String>();
- neverStarted = false;
- infoboxes.add(infobox);
- infoboxn++;
- }
- if (infobox instanceof ArrayList<?>) {
- // Just in case
- inputLine = inputLine.replaceAll("\\{\\{(.|[Ss]kill.*?)\\}\\}", "-&o&-$1-&c&-");
- infobox.add(inputLine);
- }
- if (inputLine.matches(".*\\{\\{.*"))
- extrabraces++;
- if (inputLine.matches(".*\\}\\}\\}\\}.*"))
- extrabraces -= 2;
- else if (inputLine.matches(".*\\}\\}.*"))
- extrabraces--;
- if (extrabraces == 0)
- started = false;
- if ( text != null && infobox != null && infoboxn == textn ) {
- infobox.add("|version="+text);
- text = null;
- }
- }
- }
- in.close();
- if (neverStarted)
- return "No switchfobox found on [[" + page + "]].";
- ArrayList<ArrayList<String>> params = new ArrayList<ArrayList<String>>();
- for (String a : paramnames) {
- ArrayList<String> b = new ArrayList<String>();
- b.add(a);
- params.add(b);
- }
- int infox = 0;
- for (ArrayList<String> a : infoboxes) {
- infox++;
- for (String b : a) {
- int pos = -1;
- String prm = null;
- for (int i = 0; i < paramnames.length; i++) {
- String px = paramnames[i];
- if (b.matches(".*\\|\\s*"+px+"\\s*=.*")) {
- pos = i;
- prm = b.replaceAll(".*?"+px+"\\s*=\\s*(.*?)\\s*", "$1");
- }
- }
- if (pos > -1) {
- ArrayList<String> inff = params.get(pos);
- inff.add(prm);
- if (infox == 1)
- inff.add(prm);
- }
- }
- }
- for (ArrayList<String> a : params) {
- if (a.get(0).equals("version"))
- a.set(1,null);
- else {
- int dupes = 0;
- for (int i = 2; i < a.size(); i++) {
- String px = a.get(i);
- if (px.equals(a.get(1)))
- dupes++;
- }
- if (dupes < a.size()-2)
- a.set(1, null);
- else if (dupes > 1 && dupes == a.size()-2) {
- for (int i = 2; i < a.size(); i++) {
- a.set(i,null);
- }
- }
- for (int i = 2; i < a.size(); i++) {
- String px = a.get(i);
- for (int j = i+1; j < a.size(); j++) {
- String px2 = a.get(j);
- if (px == null || px2 == null) {
- }
- else if (px.equals(px2) && !px2.matches("\\s*\\$\\d+\\s*") && j!=i) {
- a.set(j, "$"+(i-1));
- }
- }
- }
- }
- }
- String ret = "";
- ret += "{{" + INFOBOX;
- for (ArrayList<String> a : params) {
- String paramname = a.get(0);
- if (a.size() > 1)
- ret += "\n";
- for (int i = 1; i < a.size(); i++) {
- String paramx = a.get(i);
- if (paramx != null) {
- paramx = paramx.replaceAll("\\s*(.*?)\\}\\}$","$1")
- .replaceAll("-&o&-", "{{")
- .replaceAll("-&c&-", "}}");
- if (i == 1)
- ret += "|"+paramname+" = "+paramx;
- else
- ret += "|"+paramname+(i-1)+" = "+paramx;
- }
- }
- }
- ret += "\n}}";
- return ret;
- }
- static final String[] MONSTERPARAMS = {
- "version",
- "name",
- "image",
- "aka",
- "release",
- "update",
- "level",
- "LP",
- "experience",
- "slaylvl",
- "slayxp",
- "assigned",
- "turael",
- "spria",
- "mazchna",
- "achtryn",
- "chaeldar",
- "sumona",
- "vannaka",
- "duradel",
- "lapalok",
- "kuradal",
- "Turael",
- "Spria",
- "Mazchna",
- "Achtryn",
- "Chaeldar",
- "Sumona",
- "Vannaka",
- "Duradel",
- "Lapalok",
- "Kuradal",
- "members",
- "aggressive",
- "poisonous",
- "immune to stun",
- "immune to poison",
- "attack",
- "defence",
- "ranged",
- "magic",
- "attack style",
- "attack speed",
- "max hit",
- "weakness",
- "always drops",
- "examine",
- "abilities"
- };
- static final String[] BONUSESPARAMS = {
- "version",
- "requirements",
- "class",
- "slot",
- "degrades",
- "mainDamage",
- "mainAccuracy",
- "offDamage",
- "offAccuracy",
- "style",
- "armour",
- "life",
- "prayer",
- "strength",
- "ranged",
- "magic",
- "aspeed",
- "image",
- "caption",
- "image2",
- "caption2"
- };
- static final String[] NPCPARAMS = {
- "version",
- "name",
- "aka",
- "image",
- "release",
- "update",
- "race",
- "members",
- "quest",
- "location",
- "shop",
- "gender",
- "examine",
- "map"
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement