Jump to content

Configuration Display: Crude but Functional


liverare

Recommended Posts

The existing Settings' UI is amazing as it helps identify the setting IDs of changed values. When examining the values produced by that particular setting...well... I made my own little gadget that'll provide you with the capability of isolating, reading and copying any specific setting.

ConfigDisplay_zps9f27eb36.png

  1. Input setting id into the JSpinner located at the top-left, and hit enter.
  2. The newest setting value will be displayed at the top. Copy that to clipboard specifically by clicking the copy button.
  3. Old values will be pushed into the JList located at the bottom. Copy single/multiple values via the Copy items... button.

SettingExplorerUI.java

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.Timer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import org.osbot.script.rs2.Client;

public abstract class SettingExplorerUI extends JFrame implements ClipboardOwner {

	public static final Dimension SCREEN_SIZE = Toolkit.getDefaultToolkit().getScreenSize();

	private int oldVal, newVal, index;
	private DefaultListModel<String> dlm;
	private JSpinner spnConfig;
	private JButton btnCopy, btnListCopy;
	private JLabel lblD, lblDV, lvlH, lblHV, lvlB, lblBV;
	private JPanel pnlTop, pnlBottom;
	private JList<String> lstOld;
	private JScrollPane scrListOld;
	private Timer timer;

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	{
		dlm = new DefaultListModel<>();
		pnlTop = new JPanel(new GridLayout(5, 2));
		pnlBottom = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		spnConfig = new JSpinner(new SpinnerNumberModel(1, 0, 5000, 1));
		btnCopy = new JButton("Copy");
		btnListCopy = new JButton("Copy items...");
		btnListCopy.setEnabled(false);
		lblD = new JLabel("Decimal:");
		lblDV = new JLabel("null");
		lvlH = new JLabel("Hexadecimal:");
		lblHV = new JLabel("null");
		lvlB = new JLabel("Binary:");
		lblBV = new JLabel("null");
		lstOld = new JList<>(dlm);
		scrListOld = new JScrollPane(lstOld);

		setSize(SCREEN_SIZE.width / 3, SCREEN_SIZE.height / 3);
		setTitle("Config Display...");
		setAlwaysOnTop(true);
		setResizable(false);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setLocationRelativeTo(getOwner());
		setLayout(new BorderLayout());
		setVisible(true);

		pnlTop.add(spnConfig);
		pnlTop.add(btnCopy);
		pnlTop.add(lblD);
		pnlTop.add(lblDV);
		pnlTop.add(lvlH);
		pnlTop.add(lblHV);
		pnlTop.add(lvlB);
		pnlTop.add(lblBV);
		pnlBottom.add(btnListCopy);
		
		add(pnlTop, BorderLayout.NORTH);
		add(scrListOld, BorderLayout.CENTER);
		add(pnlBottom, BorderLayout.SOUTH);

		lstOld.addListSelectionListener(new ListSelectionListener() {
			
			@Override
			public void valueChanged(ListSelectionEvent arg0) {
				btnListCopy.setEnabled(lstOld.getSelectedIndex() > 0);
			}
		});

		spnConfig.addChangeListener(new ChangeListener() {
			
			@Override
			public void stateChanged(ChangeEvent arg0) {
				dlm.clear();
				index = 0;
			}
		});

		btnCopy.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				setClipboardContents(toCopyString());
			}
		});

		btnListCopy.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				List<String> l = lstOld.getSelectedValuesList();
				StringBuilder sb = new StringBuilder();
				if (l.size() > 0) {
					for (String s : l)
						sb.append(s + "\n");
					setClipboardContents(sb.toString());
				}
			}
		});

		timer = new Timer(200, new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				try {
					oldVal = newVal;
					newVal = getClient().getConfig((Integer) spnConfig.getValue());
					printValue(oldVal);
					if (oldVal != newVal) {
						dlm.addElement((index++) + ": " + toCopyString());
						scrListOld.getVerticalScrollBar().setValue(scrListOld.getVerticalScrollBar().getMaximum());
					}
				} catch (Exception ex) {
					lblDV.setText("ERROR");
					lblHV.setText("ERROR");
					lblBV.setText("ERROR");
				}
			}
		});
		timer.setRepeats(true);
		timer.start();
	}

	@Override
	public void lostOwnership(Clipboard clipboard, Transferable contents) {		
	}

	public void printValue(int value) {
		lblDV.setText(value != -1 ? String.valueOf(value) : "null");
		lblHV.setText(value != -1 ? Integer.toHexString(value) : "null");
		lblBV.setText(value != -1 ? Integer.toBinaryString(value) : "null");
	}

	public void setClipboardContents(String aString) {
		StringSelection stringSelection = new StringSelection(aString);
		Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
		clipboard.setContents(stringSelection, this);
	}

	public String toCopyString() {
		return spnConfig.getValue() + " | " + lblDV.getText() + " | "
				+ lblHV.getText() + " | " + lblBV.getText();
	}

	public abstract Client getClient();
}

Main.java (Script to execute SettingExplorerUI)

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;
import org.osbot.script.rs2.Client;

import co.uk.liverare.framework.wrappers.SettingExplorerUI;

@ScriptManifest(name="Setting Isolator", author="LiveRare", info="Isolates setting values...", version=1.0)
public class Main extends Script {

	@Override
	public void onStart() {
		new SettingExplorerUI() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public Client getClient() {
				return client;
			}
		};
	}
}

I know the code-quality sucks, but I'm on a laptop tying with stubby, sticky keys. So deal with it.

 

That is all...

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...