├── .gitignore ├── src ├── spyGui │ ├── spy.png │ ├── SpyMain.java │ ├── ComboToolTipRenderer.java │ ├── SpyServer.java │ ├── CommandComboBox.java │ ├── ProcessReader.java │ ├── ShortcutsDialog.java │ ├── AboutDialog.java │ ├── SpyFrame.java │ ├── SpyGuiPane.java │ ├── CmdInputDlg.java │ └── SpyClientReader.java ├── META-INF │ └── MANIFEST.MF ├── common │ ├── Constants.java │ └── Utilities.java └── spyAgent │ ├── WindowTracker.java │ ├── AgentPreMain.java │ ├── Communicator.java │ ├── WinEventDispatchListener.java │ ├── CompEnum.java │ ├── KeyboardListener.java │ ├── ListComponent.java │ ├── CompMouseListner.java │ └── HierarchyMap.java ├── doc └── img │ ├── jspy_big.png │ ├── jspy small.png │ ├── jspy_execute.png │ ├── build_artifacts.png │ └── project_structure.png ├── licence.txt └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | 3 | -------------------------------------------------------------------------------- /src/spyGui/spy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nokia/jspy/HEAD/src/spyGui/spy.png -------------------------------------------------------------------------------- /doc/img/jspy_big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nokia/jspy/HEAD/doc/img/jspy_big.png -------------------------------------------------------------------------------- /doc/img/jspy small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nokia/jspy/HEAD/doc/img/jspy small.png -------------------------------------------------------------------------------- /doc/img/jspy_execute.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nokia/jspy/HEAD/doc/img/jspy_execute.png -------------------------------------------------------------------------------- /doc/img/build_artifacts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nokia/jspy/HEAD/doc/img/build_artifacts.png -------------------------------------------------------------------------------- /doc/img/project_structure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nokia/jspy/HEAD/doc/img/project_structure.png -------------------------------------------------------------------------------- /src/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Main-Class: spyGui.SpyMain 3 | Premain-Class: spyAgent.AgentPreMain 4 | -------------------------------------------------------------------------------- /src/common/Constants.java: -------------------------------------------------------------------------------- 1 | package common; 2 | 3 | public class Constants { 4 | public static String COMMAND_HISTORY_FILENAME = ".command_history_jspy.txt"; 5 | } 6 | -------------------------------------------------------------------------------- /src/spyGui/SpyMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyGui; 8 | 9 | 10 | public class SpyMain { 11 | 12 | public static void main(String args[]) { 13 | Thread serverTH = new Thread(new SpyServer()); 14 | serverTH.start(); 15 | new SpyFrame(); 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /licence.txt: -------------------------------------------------------------------------------- 1 | Copyright 2015 Nokia Solutions and Networks 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /src/spyAgent/WindowTracker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyAgent; 8 | 9 | import java.awt.Window; 10 | import java.awt.event.WindowEvent; 11 | import java.awt.event.WindowFocusListener; 12 | 13 | public class WindowTracker implements WindowFocusListener { 14 | 15 | public Window activeWindow; 16 | 17 | public void windowGainedFocus(WindowEvent arg0) { 18 | activeWindow = (Window) arg0.getSource(); 19 | } 20 | 21 | public void windowLostFocus(WindowEvent arg0) { 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/spyGui/ComboToolTipRenderer.java: -------------------------------------------------------------------------------- 1 | package spyGui; 2 | 3 | 4 | import javax.swing.*; 5 | import java.awt.*; 6 | 7 | public class ComboToolTipRenderer extends DefaultListCellRenderer { 8 | 9 | @Override 10 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 11 | 12 | if (-1 < index && null != value) { 13 | if (list.getSelectedValue() != null) { 14 | list.setToolTipText(list.getSelectedValue().toString()); 15 | } 16 | } 17 | return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 18 | } 19 | } -------------------------------------------------------------------------------- /src/spyAgent/AgentPreMain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyAgent; 8 | 9 | import java.awt.*; 10 | import java.lang.instrument.Instrumentation; 11 | 12 | public class AgentPreMain { 13 | 14 | public static void premain(String agentArguments, Instrumentation inst) { 15 | 16 | Communicator.startCommunicator(Integer.parseInt(agentArguments)); 17 | WinEventDispatchListener winDispatcher = new WinEventDispatchListener(); 18 | 19 | Toolkit tk = Toolkit.getDefaultToolkit(); 20 | tk.addAWTEventListener(winDispatcher, AWTEvent.WINDOW_EVENT_MASK); 21 | 22 | Communicator.writeToServer("Client connected"); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/spyGui/SpyServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyGui; 8 | 9 | import java.io.IOException; 10 | import java.net.ServerSocket; 11 | import java.net.Socket; 12 | 13 | 14 | public class SpyServer implements Runnable { 15 | 16 | public static int serverPort = 0; 17 | 18 | public void run() { 19 | try { 20 | ServerSocket ss = new ServerSocket(serverPort); 21 | serverPort = ss.getLocalPort(); 22 | System.out.println("Server started..."); 23 | 24 | while (true) { 25 | Socket soc = ss.accept(); 26 | Thread cliTh = new Thread(new SpyClientReader(soc)); 27 | cliTh.start(); 28 | } 29 | } catch (IOException e) { 30 | System.out.println("I/O error " + e); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/spyGui/CommandComboBox.java: -------------------------------------------------------------------------------- 1 | package spyGui; 2 | 3 | import common.Utilities; 4 | 5 | import javax.swing.*; 6 | import java.util.ArrayList; 7 | 8 | public class CommandComboBox extends JComboBox { 9 | private ArrayList commands; 10 | 11 | public CommandComboBox() { 12 | setRenderer(new ComboToolTipRenderer()); 13 | commands = Utilities.getCommandHistory(); 14 | setItemsInCombo(commands); 15 | } 16 | 17 | public void addCommand(String cmd) { 18 | int cmdIndex = commands.indexOf(cmd); 19 | if (cmdIndex != -1) { 20 | commands.remove(cmdIndex); 21 | } 22 | commands.add(0, cmd); 23 | setItemsInCombo(commands); 24 | Utilities.writeCommandHistory(commands.toArray()); 25 | } 26 | 27 | private void setItemsInCombo(ArrayList cmds) { 28 | removeAllItems(); 29 | addItem(""); 30 | setSelectedIndex(0); 31 | for (String cmd : cmds) { 32 | addItem(cmd); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/spyAgent/Communicator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyAgent; 8 | 9 | import java.io.IOException; 10 | import java.io.OutputStreamWriter; 11 | import java.net.*; 12 | 13 | public class Communicator { 14 | 15 | public static OutputStreamWriter outStream; 16 | 17 | public static void startCommunicator(int port) { 18 | 19 | String machine = "localhost"; 20 | 21 | try { 22 | InetAddress addr = InetAddress.getByName(machine); 23 | SocketAddress sockaddr = new InetSocketAddress(addr, port); 24 | final Socket sock = new Socket(); 25 | sock.connect(sockaddr); 26 | outStream = new OutputStreamWriter(sock.getOutputStream()); 27 | } catch (SocketTimeoutException e) { 28 | System.out.println("Connection timed out"); 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | } 33 | 34 | public static void writeToServer(String s) { 35 | try { 36 | outStream.write(s + "\n"); 37 | outStream.flush(); 38 | } catch (IOException e) { 39 | e.printStackTrace(); 40 | } 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/spyAgent/WinEventDispatchListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyAgent; 8 | 9 | import java.awt.AWTEvent; 10 | import java.awt.Component; 11 | import java.awt.KeyboardFocusManager; 12 | import java.awt.Window; 13 | import java.awt.event.AWTEventListener; 14 | import java.awt.event.WindowEvent; 15 | import java.util.ArrayList; 16 | 17 | public class WinEventDispatchListener implements AWTEventListener { 18 | WindowTracker winTrack = new WindowTracker(); 19 | private static ArrayList activeFocusManagers = new ArrayList<>(); 20 | 21 | public void eventDispatched(AWTEvent evt) { 22 | 23 | if (evt.getID() == WindowEvent.WINDOW_OPENED) { 24 | Component compon = (Component) evt.getSource(); 25 | Thread enuTh = new Thread(new CompEnum(compon)); 26 | enuTh.start(); 27 | Window win = (Window) compon; 28 | winTrack.activeWindow = win; 29 | win.addWindowFocusListener(winTrack); 30 | KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); 31 | if (!activeFocusManagers.contains(manager)) { 32 | manager.addKeyEventDispatcher(new KeyboardListener(winTrack)); 33 | activeFocusManagers.add(manager); 34 | } 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/spyAgent/CompEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyAgent; 8 | 9 | import java.awt.Component; 10 | import javax.swing.JDialog; 11 | import javax.swing.JFileChooser; 12 | import javax.swing.JFrame; 13 | 14 | public class CompEnum implements Runnable { 15 | 16 | String title = ""; 17 | HierarchyMap hieMap = new HierarchyMap(); 18 | Component component; 19 | 20 | public CompEnum(Component compon) { 21 | component = compon; 22 | if (compon instanceof JFrame) { 23 | JFrame srcFrame = (JFrame) compon; 24 | title = srcFrame.getTitle(); 25 | } else if (compon instanceof JDialog) { 26 | JDialog srcDlg = (JDialog) compon; 27 | title = srcDlg.getTitle(); 28 | } else if (compon instanceof JFileChooser) { 29 | JFileChooser srcDlg = (JFileChooser) compon; 30 | title = srcDlg.getDialogTitle(); 31 | } 32 | 33 | hieMap.winTitle = title; 34 | 35 | } 36 | 37 | public void run() { 38 | 39 | try { 40 | Thread.sleep(2000); 41 | } catch (InterruptedException e) { 42 | e.printStackTrace(); 43 | } 44 | 45 | Communicator.writeToServer("Started Indexing Components"); 46 | ListComponent compList = new ListComponent(hieMap); 47 | compList.listComponentsInContext(component); 48 | Communicator.writeToServer("Finished Indexing Components"); 49 | 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/spyGui/ProcessReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyGui; 8 | 9 | import java.io.BufferedReader; 10 | import java.io.IOException; 11 | import java.io.InputStreamReader; 12 | 13 | public class ProcessReader implements Runnable { 14 | BufferedReader stdInput; 15 | BufferedReader stdErr; 16 | 17 | public ProcessReader(Process p) { 18 | stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); 19 | stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream())); 20 | } 21 | 22 | public void run() { 23 | 24 | String s = null; 25 | try { 26 | while ((s = stdInput.readLine()) != null || (s = stdErr.readLine()) != null) { 27 | System.out.println("CMD Out: " + s); 28 | } 29 | } catch (IOException e) { 30 | e.printStackTrace(); 31 | } finally { 32 | System.out.println("Exiting process read."); 33 | if (stdInput != null) { 34 | try { 35 | stdInput.close(); 36 | } catch (IOException e) { 37 | e.printStackTrace(); 38 | } 39 | } 40 | if (stdErr != null) { 41 | try { 42 | stdErr.close(); 43 | } catch (IOException e) { 44 | e.printStackTrace(); 45 | } 46 | } 47 | } 48 | 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/spyGui/ShortcutsDialog.java: -------------------------------------------------------------------------------- 1 | package spyGui; 2 | 3 | 4 | import common.Utilities; 5 | 6 | import javax.swing.*; 7 | import java.awt.*; 8 | 9 | public class ShortcutsDialog extends JDialog { 10 | 11 | public ShortcutsDialog(JFrame parent) { 12 | 13 | this.setName("Shortcuts"); 14 | this.setTitle("Keyboard shortcuts"); 15 | this.setForeground(Color.BLACK); 16 | setIconImage(new ImageIcon(getClass().getResource("spy.png")).getImage()); 17 | 18 | Container pane = this.getContentPane(); 19 | setLayout(new BoxLayout(pane, BoxLayout.PAGE_AXIS)); 20 | 21 | InfoTable table = new InfoTable(); 22 | pane.add(table); 23 | 24 | setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 25 | 26 | setResizable(false); 27 | setAlwaysOnTop(true); 28 | setLocationRelativeTo(parent); 29 | setVisible(true); 30 | pack(); 31 | } 32 | } 33 | 34 | class InfoTable extends JLabel { 35 | 36 | public InfoTable() { 37 | StringBuilder sb = new StringBuilder(); 38 | sb.append(""); 39 | 40 | for (Object[] row : data) { 41 | sb.append(""); 42 | for (Object value : row) { 43 | sb.append(""); 46 | 47 | } 48 | sb.append(""); 49 | } 50 | sb.append("
"); 44 | sb.append(value); 45 | sb.append("
"); 51 | setText(sb.toString()); 52 | } 53 | 54 | Object[][] data = { 55 | {"Ctrl+Alt+R", "Re-Index components"}, 56 | {"Ctrl+Alt+S", "Start/Stop component inspection"}, 57 | {"Ctrl+Alt+C", "Copy highlighted component name"} 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JSpy 2 | **JSpy** is a tool that displays the component properties of any java Swing application in the simplest way. To automate Swing applications, You generally need to venture into the application's sources to retrieve the component's properties. That's very time consuming and frustrating or even impossible. Using JSpy all You need to do to get the component's properties is to hover the coursor over the component. 3 | ![](https://raw.githubusercontent.com/nokia/jspy/master/doc/img/jspy_big.png "JSpy Big") 4 | 5 | ## Dependencies 6 | **JSpy** is operating system independent — it just needs Java 8 or newer. 7 | 8 | ## Building from sources 9 | We’ll go with IntelliJ for compiling this 10 | First clone the repository 11 | 12 | ```sh 13 | git clone github.com/nokia/JSpy.git 14 | ``` 15 | 16 | Open cloned JSpy directory in IntelliJ. Go to File\>Project Structure\>Artifact Add a jar artifact, point it to manifest file and set `spyGui.SpyMain` as Main Class 17 | ![](https://raw.githubusercontent.com/nokia/jspy/master/doc/img/project_structure.png "IntelliJ Project Structure") 18 | 19 | To compile build the jar Artifact with attached manifest. 20 | ![](https://raw.githubusercontent.com/nokia/jspy/master/doc/img/build_artifacts.png "Build Artifacts") 21 | 22 | ## Requirements 23 | If you want to use JSpy with Java WebStart applications, you should create `.java.policy` file in your home directory. 24 | Content of the file should be: 25 | ``` 26 | grant { 27 | permission java.security.AllPermission; 28 | }; 29 | ``` 30 | 31 | ## Running 32 | To execute jSpy call it from the console: 33 | ```sh 34 | java -jar JSpy.jar 35 | ``` 36 | 37 | ## Usage 38 | When started go into File \> Execute Command 39 | 40 | 41 | Execute Command: `javaws C:\path\to\file.jnlp` 42 | 43 | 44 | ## License 45 | 46 | This project is licensed under the Apache-2.0 license - see the [LICENSE](https://github.com/nokia/jspy/blob/master/licence.txt). -------------------------------------------------------------------------------- /src/common/Utilities.java: -------------------------------------------------------------------------------- 1 | package common; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.datatransfer.Clipboard; 6 | import java.awt.datatransfer.StringSelection; 7 | import java.io.BufferedReader; 8 | import java.io.FileReader; 9 | import java.io.IOException; 10 | import java.io.PrintStream; 11 | import java.nio.file.Files; 12 | import java.nio.file.Paths; 13 | import java.util.ArrayList; 14 | 15 | public class Utilities { 16 | public static void centerContainerComponents(Container c) { 17 | for (Component component : c.getComponents()) { 18 | JComponent jComponent = (JComponent) component; 19 | jComponent.setAlignmentX(Component.CENTER_ALIGNMENT); 20 | } 21 | } 22 | 23 | public static void copyStringToClipboard(String str) { 24 | StringSelection selection = new StringSelection(str); 25 | Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 26 | clipboard.setContents(selection, null); 27 | } 28 | 29 | public static ArrayList getCommandHistory() { 30 | ArrayList commands = new ArrayList<>(); 31 | 32 | if (!Files.exists(Paths.get(Constants.COMMAND_HISTORY_FILENAME))) { 33 | return commands; 34 | } 35 | 36 | try (BufferedReader bufferedReader = new BufferedReader(new FileReader(Constants.COMMAND_HISTORY_FILENAME))) { 37 | String line = null; 38 | while ((line = bufferedReader.readLine()) != null) { 39 | commands.add(line); 40 | } 41 | } catch (IOException e) { 42 | e.printStackTrace(); 43 | } 44 | return commands; 45 | } 46 | 47 | public static void writeCommandHistory(Object[] cmd) { 48 | try (PrintStream out = new PrintStream(Constants.COMMAND_HISTORY_FILENAME)) { 49 | for (Object com : cmd) { 50 | out.println(com); 51 | } 52 | } catch (IOException e) { 53 | e.printStackTrace(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/spyAgent/KeyboardListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyAgent; 8 | 9 | import common.Utilities; 10 | 11 | import java.awt.*; 12 | import java.awt.event.KeyEvent; 13 | 14 | public class KeyboardListener implements KeyEventDispatcher { 15 | public static String highlightedComponentName = ""; 16 | 17 | private WindowTracker winTrack; 18 | private boolean altPressed = false, ctrlPressed = false; 19 | 20 | public KeyboardListener(WindowTracker winTrack) { 21 | this.winTrack = winTrack; 22 | } 23 | 24 | public boolean dispatchKeyEvent(KeyEvent arg0) { 25 | if (arg0.getID() == KeyEvent.KEY_PRESSED) { 26 | if (arg0.getKeyCode() == KeyEvent.VK_ALT) { 27 | altPressed = true; 28 | } else if (arg0.getKeyCode() == KeyEvent.VK_CONTROL) { 29 | ctrlPressed = true; 30 | } else if (altPressed && ctrlPressed && arg0.getKeyCode() == KeyEvent.VK_R) { 31 | Communicator.writeToServer("Pressed ctrl+alt+R"); 32 | System.out.println("Re-Indexing the Components"); 33 | Thread enuTh = new Thread(new CompEnum(winTrack.activeWindow)); 34 | enuTh.start(); 35 | } else if (ctrlPressed && altPressed && arg0.getKeyCode() == KeyEvent.VK_C) { 36 | Utilities.copyStringToClipboard(highlightedComponentName); 37 | } else if (ctrlPressed && altPressed && arg0.getKeyCode() == KeyEvent.VK_S) { 38 | CompMouseListner.setActive = !CompMouseListner.setActive; 39 | } 40 | 41 | } else if (arg0.getID() == KeyEvent.KEY_RELEASED) { 42 | if (arg0.getKeyCode() == KeyEvent.VK_ALT) { 43 | altPressed = false; 44 | } else if (arg0.getKeyCode() == KeyEvent.VK_CONTROL) { 45 | ctrlPressed = false; 46 | } 47 | } 48 | return false; 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /src/spyGui/AboutDialog.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyGui; 8 | 9 | 10 | import common.Utilities; 11 | 12 | import javax.swing.*; 13 | import java.awt.*; 14 | 15 | public class AboutDialog extends JDialog { 16 | 17 | private static final long serialVersionUID = 1L; 18 | 19 | public AboutDialog(JFrame parent) { 20 | setName("About"); 21 | setTitle("About JSpy"); 22 | setForeground(Color.BLACK); 23 | 24 | setIconImage(new ImageIcon(getClass().getResource("spy.png")).getImage()); 25 | 26 | Container pane = this.getContentPane(); 27 | setLayout(new BoxLayout(pane, BoxLayout.PAGE_AXIS)); 28 | 29 | JLabel label1 = new JLabel("" 30 | + "
JSpy for ROBOT Framework
" 31 | + "
Version 3.0.0
" 32 | + "", JLabel.CENTER); 33 | JLabel label2 = new JLabel("Shows component details with an easy mouse move", JLabel.CENTER); 34 | JLabel label3 = new JLabel("" 35 | + "
By Arulraj Samuel
" 36 | + "
Maintained by Robot Team in Nokia
" 37 | + "", JLabel.CENTER); 38 | 39 | label1.setForeground(Color.BLUE); 40 | label2.setForeground(Color.BLUE); 41 | label3.setForeground(Color.BLUE); 42 | 43 | JLabel dumm1 = new JLabel("-------------------------", JLabel.CENTER); 44 | JLabel dumm2 = new JLabel("-----------------------", JLabel.CENTER); 45 | JLabel dumm3 = new JLabel("-------------------", JLabel.CENTER); 46 | 47 | pane.add(label1); 48 | pane.add(dumm1); 49 | pane.add(label2); 50 | pane.add(dumm2); 51 | pane.add(label3); 52 | pane.add(dumm3); 53 | 54 | Utilities.centerContainerComponents(pane); 55 | 56 | setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 57 | pack(); 58 | setLocationRelativeTo(parent); 59 | setAlwaysOnTop(true); 60 | setResizable(false); 61 | setVisible(true); 62 | 63 | this.validate(); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/spyAgent/ListComponent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyAgent; 8 | 9 | import java.awt.Component; 10 | import java.awt.Container; 11 | import java.util.ArrayList; 12 | 13 | import javax.swing.JInternalFrame; 14 | 15 | 16 | public class ListComponent { 17 | private java.util.List resultComponentList; 18 | Component srcComp; 19 | HierarchyMap compHieMap; 20 | 21 | private static abstract class ContainerIterator { 22 | 23 | public void iterate() { 24 | processComponent(container); 25 | } 26 | 27 | public abstract void operateOnComponent(Component component, int i); 28 | 29 | private void processComponent(Component component) { 30 | 31 | operateOnComponent(component, level); 32 | level++; 33 | if (component instanceof Container || component instanceof JInternalFrame) { 34 | Component subComponents[] = ((Container) component).getComponents(); 35 | for (int i = 0; i < subComponents.length; i++) { 36 | processComponent(subComponents[i]); 37 | level--; 38 | } 39 | } 40 | } 41 | 42 | private int level; 43 | private Container container; 44 | 45 | public ContainerIterator(Container container) { 46 | this.container = container; 47 | } 48 | } 49 | 50 | private class ContainerIteratorForListing extends ContainerIterator { 51 | 52 | String componentClass = ""; 53 | String componentName = ""; 54 | HierarchyMap myHieMap; 55 | 56 | public ContainerIteratorForListing(Container container, HierarchyMap compHieMap) { 57 | super(container); 58 | myHieMap = compHieMap; 59 | } 60 | 61 | public void operateOnComponent(Component component, int level) { 62 | componentName = componentToString(component); 63 | componentClass = myHieMap.getInstance(component); 64 | CompMouseListner mouseListner = new CompMouseListner(myHieMap.index, level, myHieMap.winTitle, componentClass, myHieMap.props); 65 | 66 | component.addMouseListener(mouseListner); 67 | } 68 | } 69 | 70 | public ListComponent(HierarchyMap compHieMap) { 71 | resultComponentList = new ArrayList(); 72 | this.compHieMap = compHieMap; 73 | } 74 | 75 | public String listComponentsInContext(Component cmp) { 76 | this.srcComp = cmp; 77 | (new ContainerIteratorForListing((Container) cmp, compHieMap)).iterate(); 78 | return resultComponentList.toString(); 79 | } 80 | 81 | private String componentToString(Component component) { 82 | String componentString = component.toString(); 83 | int indexToStartOfDetails = componentString.indexOf('['); 84 | if (indexToStartOfDetails == -1) 85 | return componentString; 86 | else 87 | return componentString.substring(0, indexToStartOfDetails); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/spyGui/SpyFrame.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyGui; 8 | 9 | import javax.swing.*; 10 | import java.awt.event.ActionEvent; 11 | import java.awt.event.ActionListener; 12 | import java.awt.event.KeyEvent; 13 | 14 | 15 | public class SpyFrame extends JFrame { 16 | 17 | private static final long serialVersionUID = 1L; 18 | 19 | private CmdInputDlg launchDlg = new CmdInputDlg(); 20 | private SpyGuiPane displayPane = new SpyGuiPane(); 21 | private JMenuBar menuBar = new JMenuBar(); 22 | 23 | public SpyFrame() { 24 | super("JSpy"); 25 | setIconImage(new ImageIcon(getClass().getResource("spy.png")).getImage()); 26 | setupMenuBar(); 27 | 28 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 29 | setJMenuBar(menuBar); 30 | 31 | setContentPane(displayPane); 32 | 33 | JFrame.setDefaultLookAndFeelDecorated(true); 34 | 35 | setLocationRelativeTo(null); 36 | pack(); 37 | setAlwaysOnTop(true); 38 | setVisible(true); 39 | } 40 | 41 | private void setupMenuBar() { 42 | JMenu fileMenu = new JMenu("File"); 43 | fileMenu.setMnemonic(KeyEvent.VK_F); 44 | JMenuItem launch = new JMenuItem("Launch"); 45 | launch.setMnemonic(KeyEvent.VK_L); 46 | JMenuItem quit = new JMenuItem("Quit"); 47 | quit.setMnemonic(KeyEvent.VK_Q); 48 | JMenu helpMenu = new JMenu("Help"); 49 | helpMenu.setMnemonic(KeyEvent.VK_H); 50 | JMenuItem about = new JMenuItem("About"); 51 | about.setMnemonic(KeyEvent.VK_A); 52 | JMenuItem shortcuts = new JMenuItem("Shortcuts"); 53 | shortcuts.setMnemonic(KeyEvent.VK_S); 54 | 55 | fileMenu.add(launch); 56 | fileMenu.add(quit); 57 | helpMenu.add(about); 58 | helpMenu.add(shortcuts); 59 | 60 | ActionListener menuAct = new ActionListener() { 61 | @Override 62 | public void actionPerformed(ActionEvent arg0) { 63 | System.out.println("Action " + arg0); 64 | if (arg0.getActionCommand().equals("Quit")) { 65 | System.exit(0); 66 | } else if (arg0.getActionCommand().equals("About")) { 67 | new AboutDialog(SpyFrame.this); 68 | } else if (arg0.getActionCommand().equals("Launch")) { 69 | launchDlg.pack(); 70 | launchDlg.setLocationRelativeTo(SpyFrame.this); 71 | launchDlg.setAlwaysOnTop(true); 72 | launchDlg.setVisible(true); 73 | } else if (arg0.getActionCommand().equals("Shortcuts")) { 74 | new ShortcutsDialog(SpyFrame.this); 75 | } 76 | 77 | } 78 | }; 79 | 80 | quit.addActionListener(menuAct); 81 | about.addActionListener(menuAct); 82 | launch.addActionListener(menuAct); 83 | shortcuts.addActionListener(menuAct); 84 | 85 | menuBar.add(fileMenu); 86 | menuBar.add(helpMenu); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/spyAgent/CompMouseListner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyAgent; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | import java.awt.event.MouseEvent; 12 | import java.awt.event.MouseListener; 13 | 14 | 15 | public class CompMouseListner implements MouseListener { 16 | public static Color highlightedComponentColor; 17 | 18 | String myIndex; 19 | int compHierarchy = -1; 20 | String winTitle; 21 | String classType; 22 | String compProps = ""; 23 | 24 | static boolean flag = false; 25 | static boolean setActive = true; 26 | 27 | 28 | public CompMouseListner(String index, int compHierarchy, String title, String objType, String srcCompProps) { 29 | myIndex = index; 30 | winTitle = title; 31 | classType = objType; 32 | compProps = srcCompProps; 33 | this.compHierarchy = compHierarchy; 34 | } 35 | 36 | public void mouseClicked(MouseEvent arg0) { 37 | if (!setActive) { 38 | return; 39 | } 40 | 41 | Component comp = arg0.getComponent(); 42 | if (comp instanceof JTabbedPane) { 43 | JTabbedPane tabpane = (JTabbedPane) comp; 44 | int tabIndex = tabpane.getSelectedIndex(); 45 | String tabName = tabpane.getTitleAt(tabIndex); 46 | String tabText = ",Tab Index - " + tabIndex + ",Tab Title- " + tabName; 47 | Communicator.writeToServer("Window Title - " + winTitle + ",Index - " + myIndex + ",Instance Of - " + classType + ",Comp. Hierarchy - " + compHierarchy + "," + tabpane.toString() + tabText); 48 | 49 | } 50 | if (comp instanceof JTree) { 51 | JTree tree = (JTree) comp; 52 | int nodeCount = tree.getLeadSelectionRow(); 53 | String nodePath = tree.getSelectionPath().toString(); 54 | String tabText = ",Node Count - " + nodeCount + ",Node Path- " + nodePath; 55 | Communicator.writeToServer("Window Title - " + winTitle + ",Index - " + myIndex + ",Instance Of - " + classType + ",Comp. Hierarchy - " + compHierarchy + "," + tree.toString() + tabText); 56 | 57 | } 58 | } 59 | 60 | public void mousePressed(MouseEvent arg0) { 61 | 62 | } 63 | 64 | public void mouseReleased(MouseEvent arg0) { 65 | 66 | } 67 | 68 | public void mouseEntered(MouseEvent arg0) { 69 | if (!flag && setActive) { 70 | try { 71 | int index = compProps.indexOf("["); 72 | String name = compProps.substring(index + 1, compProps.indexOf(',')); 73 | KeyboardListener.highlightedComponentName = name; 74 | Component comp = arg0.getComponent(); 75 | Communicator.writeToServer("Window Title - " + winTitle + ",Index - " + myIndex + ",Instance Of - " + classType + ",Comp. Hierarchy - " + compHierarchy + "," + compProps); 76 | highlightedComponentColor = comp.getBackground(); 77 | comp.setBackground(new Color(90, 100, 210)); 78 | flag = true; 79 | } catch (Exception e) { 80 | e.printStackTrace(); 81 | } 82 | } 83 | } 84 | 85 | public void mouseExited(MouseEvent arg0) { 86 | if (flag) { 87 | try { 88 | Component comp = arg0.getComponent(); 89 | comp.setBackground(highlightedComponentColor); 90 | flag = false; 91 | } catch (Exception e) { 92 | e.printStackTrace(); 93 | } 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/spyGui/SpyGuiPane.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyGui; 8 | 9 | import javax.swing.*; 10 | import java.awt.*; 11 | import javax.swing.table.*; 12 | 13 | public class SpyGuiPane extends JPanel { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | public static JScrollPane scrollPane; 18 | public static JTextPane topTextPane = new JTextPane(); 19 | public static JTextPane bottomTextPane = new JTextPane(); 20 | public static JTable table; 21 | private static DefaultTableModel tableModel; 22 | 23 | public SpyGuiPane() { 24 | 25 | setLayout(new BorderLayout()); 26 | Color backgroundColor = new Color(100, 149, 237); 27 | 28 | topTextPane.setText("Launch example-File->Launch->javaws some.jnlp"); 29 | topTextPane.setBackground(backgroundColor); 30 | topTextPane.setEditable(false); 31 | 32 | bottomTextPane.setText("JSpy Initialized..."); 33 | bottomTextPane.setBackground(backgroundColor); 34 | bottomTextPane.setEditable(false); 35 | 36 | tableModel = new DefaultTableModel() { 37 | @Override 38 | public boolean isCellEditable(int row, int column) { 39 | return false; 40 | } 41 | }; 42 | tableModel.addColumn("Name"); 43 | tableModel.addColumn("Value"); 44 | 45 | Color evenRowsColor = new Color(176, 196, 222); 46 | Color oddRowsColor = new Color(230, 230, 250); 47 | table = new JTable() { 48 | @Override 49 | public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { 50 | Component c = super.prepareRenderer(renderer, row, column); 51 | c.setBackground(row % 2 == 0 ? evenRowsColor : oddRowsColor); 52 | return c; 53 | } 54 | }; 55 | 56 | scrollPane = new JScrollPane(); 57 | scrollPane.getViewport().add(table); 58 | scrollPane.setVerticalScrollBarPolicy( 59 | JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); 60 | scrollPane.setPreferredSize(new Dimension(300, 440)); 61 | 62 | Font dataFont = new Font("Ariel", Font.BOLD, 12); 63 | table.setFont(dataFont); 64 | 65 | Font textFont = new Font("Ariel", Font.ITALIC, 12); 66 | topTextPane.setFont(textFont); 67 | bottomTextPane.setFont(textFont); 68 | 69 | setPreferredSize(new Dimension(300, 440)); 70 | Color color = Color.BLACK; 71 | 72 | table.setForeground(color); 73 | table.setAutoscrolls(true); 74 | 75 | //scrollPane 76 | this.add(topTextPane, BorderLayout.NORTH); 77 | this.add(bottomTextPane, BorderLayout.SOUTH); 78 | this.add(scrollPane, BorderLayout.CENTER); 79 | 80 | } 81 | 82 | private static boolean isProperty(String s) { 83 | return (s.contains("=") || s.contains(":") || s.contains("-") || s.matches("\\d+(X\\d+)?(x\\d+)?")); 84 | } 85 | 86 | public static void printText(String s) { 87 | if (s.equals("Clear")) { 88 | bottomTextPane.setText(""); 89 | tableModel.setRowCount(0); 90 | } else if (s.contains("Client Disconnected.")) { 91 | tableModel.setRowCount(0); 92 | bottomTextPane.setText(s); 93 | 94 | } else if (s.equals("new line")) { 95 | tableModel.addRow(new Object[]{null, null}); 96 | } else if (isProperty(s)) { 97 | String name_value[] = s.split("[=:-]"); 98 | if (name_value.length < 2) { 99 | String emptyFirst[] = {"", name_value[0]}; 100 | tableModel.addRow(emptyFirst); 101 | } else { 102 | tableModel.addRow(name_value); 103 | } 104 | } else { 105 | String splitText[] = s.split("\n"); 106 | bottomTextPane.setText(splitText[0]); 107 | } 108 | 109 | 110 | scrollPane.validate(); 111 | table.setModel(tableModel); 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/spyGui/CmdInputDlg.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyGui; 8 | 9 | 10 | import javax.swing.*; 11 | import javax.swing.text.JTextComponent; 12 | import java.awt.*; 13 | import java.awt.event.*; 14 | import java.io.File; 15 | import java.io.IOException; 16 | import java.net.URI; 17 | import java.net.URISyntaxException; 18 | import java.util.ArrayList; 19 | import java.util.Arrays; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | 24 | public class CmdInputDlg extends JDialog { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | private CommandComboBox commandCombo = new CommandComboBox(); 29 | private JButton btLaunch = new JButton("Run"); 30 | private JLabel label1 = new JLabel("Cmd to launch", JLabel.LEFT); 31 | 32 | public CmdInputDlg() { 33 | setName("execCmd"); 34 | setTitle("Execute Command"); 35 | setIconImage(new ImageIcon(getClass().getResource("spy.png")).getImage()); 36 | 37 | Container contentPane = this.getContentPane(); 38 | FlowLayout layout = new FlowLayout(); 39 | contentPane.setLayout(layout); 40 | 41 | setSize(200, 300); 42 | 43 | setupComboBox(); 44 | contentPane.add(label1); 45 | contentPane.add(commandCombo); 46 | contentPane.add(btLaunch); 47 | 48 | setupListeners(); 49 | 50 | pack(); 51 | setResizable(false); 52 | } 53 | 54 | private void setupListeners() { 55 | ActionListener btnAct = new ActionListener() { 56 | public void actionPerformed(ActionEvent arg0) { 57 | if (arg0.getActionCommand().equals("Run")) { 58 | executeCmd(); 59 | } 60 | } 61 | }; 62 | 63 | KeyListener kl = new KeyAdapter() { 64 | @Override 65 | public void keyPressed(KeyEvent e) { 66 | if (e.getKeyCode() == KeyEvent.VK_ENTER) { 67 | executeCmd(); 68 | } 69 | } 70 | }; 71 | 72 | btLaunch.addActionListener(btnAct); 73 | btLaunch.addKeyListener(kl); 74 | commandCombo.getEditor().getEditorComponent().addKeyListener(kl); 75 | } 76 | 77 | private void setupComboBox() { 78 | commandCombo.setEditable(true); 79 | commandCombo.setPreferredSize(new Dimension(200, 20)); 80 | } 81 | 82 | public void executeCmd() { 83 | String cmdStr = ((JTextComponent) (commandCombo.getEditor().getEditorComponent())).getText(); 84 | 85 | if (cmdStr != null && !cmdStr.trim().equals("")) { 86 | 87 | System.out.println("Executing command :" + cmdStr); 88 | List arguments = new ArrayList(); 89 | arguments.addAll(Arrays.asList(cmdStr.trim().split("\\s+"))); 90 | ProcessBuilder pb = new ProcessBuilder(arguments.toArray(new String[arguments.size()])); 91 | Map env = pb.environment(); 92 | 93 | URI jSpyJarUri = null; 94 | try { 95 | jSpyJarUri = spyAgent.AgentPreMain.class.getProtectionDomain() 96 | .getCodeSource().getLocation().toURI(); 97 | } catch (URISyntaxException e) { 98 | e.printStackTrace(); 99 | } 100 | String jSpyJarPath = new File(jSpyJarUri).getPath(); 101 | 102 | env.put("JAVA_TOOL_OPTIONS", "-javaagent:\"" + jSpyJarPath + "\"" + "=" + Integer.toString(SpyServer.serverPort)); 103 | 104 | pb.redirectErrorStream(true); 105 | try { 106 | Process p = pb.start(); 107 | Thread readProcTh = new Thread(new ProcessReader(p)); 108 | readProcTh.start(); 109 | commandCombo.addCommand(cmdStr); 110 | setVisible(false); 111 | } catch (IOException e) { 112 | e.printStackTrace(); 113 | JOptionPane.showMessageDialog(this, "Could not execute command", "Error", JOptionPane.ERROR_MESSAGE); 114 | } 115 | 116 | } 117 | } 118 | 119 | } -------------------------------------------------------------------------------- /src/spyGui/SpyClientReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyGui; 8 | 9 | 10 | import java.io.BufferedReader; 11 | import java.io.BufferedWriter; 12 | import java.io.InputStreamReader; 13 | import java.io.OutputStreamWriter; 14 | import java.net.Socket; 15 | 16 | public class SpyClientReader implements Runnable { 17 | public Socket client; 18 | 19 | public SpyClientReader(Socket sock) { 20 | client = sock; 21 | } 22 | 23 | public void run() { 24 | try { 25 | BufferedWriter out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); 26 | out.write("connected\n"); 27 | SpyGuiPane.topTextPane.setText("Select Window and press \"CTRL+ALT+R\" to Re-Index"); 28 | out.flush(); 29 | BufferedReader in; 30 | InputStreamReader inStream = new InputStreamReader(client.getInputStream()); 31 | in = new BufferedReader(inStream); 32 | String tempText; 33 | 34 | while (true) { 35 | while ((tempText = in.readLine()) != null) { 36 | out.write("test from server\n"); 37 | out.flush(); 38 | SpyGuiPane.printText("Clear"); 39 | System.out.println("From Client: " + tempText); 40 | String splitText[] = tempText.split(","); 41 | for (int i = 0; i < splitText.length; i++) { 42 | if (!(splitText[i].equals(""))) { 43 | if (i == 4) { 44 | int index = splitText[4].indexOf("["); 45 | String className = splitText[4].substring(0, index + 1).replace("[", ""); 46 | String name = splitText[4].substring(index + 1, splitText[4].length()); 47 | SpyGuiPane.printText("Name- " + name); 48 | SpyGuiPane.printText("Class Name- " + className); 49 | } else if (i == 5) { 50 | SpyGuiPane.printText("X: " + splitText[5]); 51 | } else if (i == 6) { 52 | SpyGuiPane.printText("Y: " + splitText[6]); 53 | } else if (i == 7) { 54 | SpyGuiPane.printText("Size: " + splitText[7]); 55 | } else { 56 | String temporary = splitText[i].replace("[", "\n"); 57 | String temp[] = temporary.split("\n"); 58 | for (int j = 0; j < temp.length; j++) { 59 | // skip empty properties 60 | // empty properties end with "=" 61 | String tempLastCharacter = temp[j].substring(temp[j].length() - 1, temp[j].length()); 62 | if ((!tempLastCharacter.equals("="))) { 63 | if (tempLastCharacter.equals("]")) { 64 | //properties without name 65 | String tempBeforeLastCharacter = temp[j].substring(temp[j].length() - 2, temp[j].length() - 1); 66 | if ((!tempBeforeLastCharacter.equals("="))) { 67 | SpyGuiPane.printText(temp[j].substring(0, temp[j].length() - 1)); 68 | SpyGuiPane.printText("new line"); 69 | } 70 | }else { 71 | SpyGuiPane.printText(temp[j]); 72 | } 73 | } 74 | } 75 | } 76 | } 77 | } 78 | } 79 | } 80 | } catch (Exception e) { 81 | System.out.println("ERROR3: " + e.getMessage()); 82 | SpyGuiPane.printText("Client Disconnected."); 83 | } 84 | 85 | } 86 | 87 | } 88 | 89 | 90 | -------------------------------------------------------------------------------- /src/spyAgent/HierarchyMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Nokia Solutions and Networks 3 | * Licensed under the Apache License, Version 2.0, 4 | * see licence.txt file for details. 5 | */ 6 | 7 | package spyAgent; 8 | 9 | 10 | import java.awt.*; 11 | import java.util.HashMap; 12 | 13 | import javax.swing.*; 14 | import javax.swing.table.JTableHeader; 15 | 16 | 17 | public class HierarchyMap { 18 | 19 | public String instance = ""; 20 | public String index = "-1"; 21 | public String winTitle = ""; 22 | public String props = ""; 23 | public HashMap compHash = new HashMap(); 24 | 25 | public void setIndex(String inst) { 26 | if (compHash.containsKey(inst)) { 27 | String tmpIndex = compHash.get(inst); 28 | index = "" + (Integer.parseInt(tmpIndex) + 1); 29 | compHash.put(inst, index); 30 | } else { 31 | compHash.put(inst, "0"); 32 | index = "0"; 33 | } 34 | 35 | } 36 | 37 | public String getInstance(Component comp) { 38 | if (comp instanceof JButton) { 39 | instance = "JButton"; 40 | } else if (comp instanceof JCheckBox) { 41 | instance = "JCheckBox"; 42 | } else if (comp instanceof JCheckBoxMenuItem) { 43 | instance = "JCheckBoxMenuItem"; 44 | } else if (comp instanceof JColorChooser) { 45 | instance = "JColorChooser"; 46 | } else if (comp instanceof JComboBox) { 47 | instance = "JComboBox"; 48 | } else if (comp instanceof JDesktopPane) { 49 | instance = "JDesktopPane"; 50 | } else if (comp instanceof JDialog) { 51 | instance = "JDialog"; 52 | } else if (comp instanceof JEditorPane) { 53 | instance = "JEditorPane"; 54 | } else if (comp instanceof JFileChooser) { 55 | instance = "JFileChooser"; 56 | } else if (comp instanceof JFrame) { 57 | instance = "JFrame"; 58 | } else if (comp instanceof JInternalFrame) { 59 | instance = "JInternalFrame"; 60 | } else if (comp instanceof JInternalFrame.JDesktopIcon) { 61 | instance = "JInternalFrame.JDesktopIcon"; 62 | } else if (comp instanceof JLabel) { 63 | instance = "JLabel"; 64 | } else if (comp instanceof JLayeredPane) { 65 | instance = "JLayeredPane"; 66 | } else if (comp instanceof JList) { 67 | instance = "JList"; 68 | } else if (comp instanceof JMenu) { 69 | instance = "JMenu"; 70 | } else if (comp instanceof JMenuBar) { 71 | instance = "JMenuBar"; 72 | } else if (comp instanceof JMenuItem) { 73 | instance = "JMenuItem"; 74 | } else if (comp instanceof JOptionPane) { 75 | instance = "JOptionPane"; 76 | } else if (comp instanceof JPanel) { 77 | instance = "JPanel"; 78 | } else if (comp instanceof JPopupMenu) { 79 | instance = "JPopupMenu"; 80 | } else if (comp instanceof JProgressBar) { 81 | instance = "JProgressBar"; 82 | } else if (comp instanceof JRadioButton) { 83 | instance = "JRadioButton"; 84 | } else if (comp instanceof JRadioButtonMenuItem) { 85 | instance = "JRadioButtonMenuItem"; 86 | } else if (comp instanceof JRootPane) { 87 | instance = "JRootPane"; 88 | } else if (comp instanceof JScrollBar) { 89 | instance = "JScrollBar"; 90 | } else if (comp instanceof JScrollPane) { 91 | instance = "JScrollPane"; 92 | } else if (comp instanceof JSeparator) { 93 | instance = "JSeparator"; 94 | } else if (comp instanceof JSlider) { 95 | instance = "JSlider"; 96 | } else if (comp instanceof JSpinner) { 97 | instance = "JSpinner"; 98 | } else if (comp instanceof JSplitPane) { 99 | instance = "JSplitPane"; 100 | } else if (comp instanceof JTabbedPane) { 101 | instance = "JTabbedPane"; 102 | } else if (comp instanceof JTable) { 103 | instance = "JTable"; 104 | } else if (comp instanceof JTextArea) { 105 | instance = "JTextArea"; 106 | } else if (comp instanceof JTextField) { 107 | instance = "JTextField"; 108 | } else if (comp instanceof JTextPane) { 109 | instance = "JTextPane"; 110 | } else if (comp instanceof JToggleButton) { 111 | instance = "JToggleButton"; 112 | } else if (comp instanceof JToolBar) { 113 | instance = "JToolBar"; 114 | } else if (comp instanceof JToolTip) { 115 | instance = "JToolTip"; 116 | } else if (comp instanceof JTree) { 117 | instance = "JTree"; 118 | } else if (comp instanceof JViewport) { 119 | instance = "JViewport"; 120 | } else if (comp instanceof JWindow) { 121 | instance = "JWindow"; 122 | } else if (comp instanceof JTableHeader) { 123 | instance = "JTableHeader"; 124 | } else if (comp instanceof JComponent) { 125 | instance = "JComponent"; 126 | } else if (comp instanceof TextField) { 127 | instance = "TextField"; 128 | } else { 129 | instance = null; 130 | } 131 | props = comp.toString(); 132 | setIndex(instance); 133 | return instance; 134 | } 135 | 136 | } 137 | --------------------------------------------------------------------------------