Update of /cvsroot/tn5250j/tn5250j/src/org/tn5250j
In directory sc8-pr-cvs1:/tmp/cvs-serv23242/src/org/tn5250j
Modified Files:
Gui5250.java
Log Message:
Make project use new SessionPopup module
Index: Gui5250.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/Gui5250.java,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -d -r1.50 -r1.51
*** Gui5250.java 30 Nov 2003 10:54:59 -0000 1.50
--- Gui5250.java 30 Nov 2003 11:11:07 -0000 1.51
***************
*** 345,349 ****
}
! protected void getFocusForMe() {
this.grabFocus();
}
--- 345,349 ----
}
! public void getFocusForMe() {
this.grabFocus();
}
***************
*** 1525,2016 ****
- /**
- * Title: Macronizer.java
- * Copyright: Copyright (c) 2001
- * Company:
- * @author Kenneth J. Pouncey
- * @version 0.1
- *
- * Description:
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this software; see the file COPYING. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307 USA
- *
- */
- package org.tn5250j.tools;
-
- import java.awt.BorderLayout;
- import java.awt.event.WindowAdapter;
- import java.awt.event.WindowEvent;
- import java.util.*;
- import java.io.*;
- import javax.swing.*;
-
- import org.tn5250j.Session;
- import org.tn5250j.GlobalConfigure;
- import org.tn5250j.scripting.InterpreterDriverManager;
- import org.tn5250j.interfaces.ConfigureFactory;
-
- public class Macronizer {
-
- private static String macroName;
- private static Properties macros;
- private static boolean macrosExist;
-
- public static void init() {
-
- if (macros != null)
- return;
-
- macrosExist = loadMacros();
-
- }
-
- private static boolean loadMacros() {
-
- macros = ConfigureFactory.getInstance().getProperties(GlobalConfigure.MACROS);
- if (macros != null && macros.size() > 0)
- return true;
-
- return checkScripts();
- }
-
- private final static void saveMacros() {
-
- ConfigureFactory.getInstance().saveSettings(
- GlobalConfigure.MACROS,"------ Macros --------");
- }
-
- public final static boolean isMacrosExist() {
- return macrosExist;
- }
-
- public final static int getNumOfMacros() {
-
- return macros.size();
-
- }
-
- public final static String[] getMacroList() {
-
- String[] macroList = new String[macros.size()];
- Set macroSet = macros.keySet();
- Iterator macroIterator = macroSet.iterator();
- String byName = null;
- int x = 0;
- while (macroIterator.hasNext()) {
- byName = (String)macroIterator.next();
- int period = byName.indexOf(".");
- macroList[x++] = byName.substring(period+1);
- }
-
- return macroList;
- }
-
- public final static String getMacroByNumber(int num) {
- String mac = "macro" + num + ".";
-
- Set macroSet = macros.keySet();
- Iterator macroIterator = macroSet.iterator();
- String byNum = null;
- while (macroIterator.hasNext()) {
- byNum = (String)macroIterator.next();
- if (byNum.startsWith(mac)) {
- return (String)macros.get(byNum);
- }
- }
- return null;
- }
-
- public final static String getMacroByName(String name) {
-
- Set macroSet = macros.keySet();
- Iterator macroIterator = macroSet.iterator();
- String byName = null;
- while (macroIterator.hasNext()) {
- byName = (String)macroIterator.next();
- if (byName.endsWith(name)) {
- return (String)macros.get(byName);
- }
- }
- return null;
- }
-
- public final static void removeMacroByName(String name) {
-
- Set macroSet = macros.keySet();
- Iterator macroIterator = macroSet.iterator();
- String byName = null;
- while (macroIterator.hasNext()) {
- byName = (String)macroIterator.next();
- if (byName.endsWith(name)) {
- macros.remove(byName);
- saveMacros();
- return;
- }
- }
- }
-
- public final static void setMacro(String name, String keyStrokes) {
-
- int x = 0;
-
- while (getMacroByNumber(++x) != null) {}
- macros.put("macro" + x + "." + name,keyStrokes);
- macrosExist = true;
- saveMacros();
-
- }
-
- public static void showRunScriptDialog(Session session) {
-
- JPanel rsp = new JPanel();
- rsp.setLayout(new BorderLayout());
- JLabel jl = new JLabel("Enter script to run");
- final JTextField rst = new JTextField();
- rsp.add(jl,BorderLayout.NORTH);
- rsp.add(rst,BorderLayout.CENTER);
- Object[] message = new Object[1];
- message[0] = rsp;
- String[] options = {"Run","Cancel"};
-
- final JOptionPane pane = new JOptionPane(
- message, // the dialog message array
- JOptionPane.QUESTION_MESSAGE, // message type
- JOptionPane.DEFAULT_OPTION, // option type
- null, // optional icon, use null to use the default icon
- options, // options string array, will be made into buttons//
- options[0]); // option that should be made into a default button
-
-
- // create a dialog wrapping the pane
- final JDialog dialog = pane.createDialog(session, // parent frame
- "Run Script" // dialog title
- );
-
- // add the listener that will set the focus to
- // the desired option
- dialog.addWindowListener( new WindowAdapter() {
- public void windowOpened( WindowEvent e) {
- super.windowOpened( e );
-
- // now we're setting the focus to the desired component
- // it's not the best solution as it depends on internals
- // of the OptionPane class, but you can use it temporarily
- // until the bug gets fixed
- // also you might want to iterate here thru the set of
- // the buttons and pick one to call requestFocus() for it
-
- rst.requestFocus();
- }
- });
- dialog.show();
-
- // now we can process the value selected
- String value = (String)pane.getValue();
-
- if (value.equals(options[0])) {
- // send option along with system request
- if (rst.getText().length() > 0) {
- invoke(rst.getText(),session);
- }
- }
-
-
- }
-
- public final static void invoke (String macro, Session session) {
-
- String keys = getMacroByName(macro);
- if (keys != null)
- session.getScreen().sendKeys(keys);
- else {
- try {
- if (!macro.endsWith(".py"))
- macro = macro + ".py";
- InterpreterDriverManager.executeScriptFile((Session)session,"scripts" +
- File.separatorChar + macro);
- }
- catch (Exception ex) {
- System.err.println(ex);
- }
- }
- }
- private static boolean checkScripts() {
-
- File directory = new File("scripts");
-
- File directory2 = new File(GlobalConfigure.instance().getProperty(
- "emulator.settingsDirectory") +
- "scripts");
-
-
- return directory.isDirectory() || directory2.isDirectory();
-
- }
-
- }
-
- package org.tn5250j.tools;
- /**
- * Title: tn5250J
- * Copyright: Copyright (c) 2001
- * Company:
- * @author Kenneth J. Pouncey
- * @version 0.5
- *
- * Description:
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this software; see the file COPYING. If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307 USA
- *
- */
-
- import javax.swing.*;
- import java.util.*;
- import java.io.*;
- import java.awt.event.*;
- import org.tn5250j.*;
- import org.tn5250j.scripting.ExecuteScriptAction;
- import org.tn5250j.scripting.InterpreterDriverManager;
-
- public final class LoadMacroMenu {
-
- private static Vector macroVector;
-
- static {
- macroVector = new Vector();
- }
-
- public static void loadMacros(Session session, Macronizer macros, JMenu menu) {
-
- final Session ses = session;
- Vector mv = new Vector();
- Action action;
-
- menu.addSeparator();
-
-
- String[] macrosList = Macronizer.getMacroList();
-
-
- for (int x = 0; x < macrosList.length; x++) {
- mv.add(macrosList[x]);
- }
-
- Collections.sort(mv);
-
-
- for (int x = 0; x < mv.size(); x++) {
- action = new AbstractAction((String)mv.get(x)) {
- public void actionPerformed(ActionEvent e) {
- ses.executeMeMacro(e);
- }
- };
-
- JMenuItem mi = menu.add(action);
-
- final Gui5250 ji = (Gui5250)session;
- mi.addMouseListener(new MouseAdapter() {
-
- public void mouseReleased(MouseEvent e) {
- if (SwingUtilities.isRightMouseButton(e)) {
- doOptionsPopup(e,ses);
- }
- }
-
- public void mousePressed(MouseEvent e) {
- if (SwingUtilities.isRightMouseButton(e)) {
- doOptionsPopup(e,ses);
- }
- }
- public void mouseClicked(MouseEvent e) {
- if (SwingUtilities.isRightMouseButton(e)) {
- doOptionsPopup(e,ses);
- }
- }
- });
-
- }
-
- scriptDir("scripts",menu,session);
-
- String conPath = "";
- String conPath2 = "";
-
- try {
- conPath = new File("scripts").getCanonicalPath();
- conPath2 = new File(GlobalConfigure.instance().getProperty(
- "emulator.settingsDirectory") +
- "scripts").getCanonicalPath();
- }
- catch (IOException ioe ) {
-
- }
-
- // lets not load the menu again if they point to the same place
- if (!conPath.equals(conPath2))
- scriptDir(GlobalConfigure.instance().getProperty(
- "emulator.settingsDirectory") +
- "scripts",menu,session);
- }
-
- private static void doOptionsPopup(MouseEvent e, Session session) {
-
- JPopupMenu j = new JPopupMenu("test");
- Action action = new AbstractAction("Delete " + ((JMenuItem)e.getSource()).getText()) {
- public void actionPerformed(ActionEvent e) {
- StringBuffer macro = new StringBuffer(((JMenuItem)e.getSource()).getText());
- macro.delete(0,"Delete".length()+1);
- Macronizer.removeMacroByName(macro.toString());
- }
- };
-
- j.add(action);
- j.add(new JMenuItem("Execute "+ ((JMenuItem)e.getSource()).getText()));
- MouseEvent et = SwingUtilities.convertMouseEvent((JMenuItem)e.getSource(),e,session);
- GUIGraphicsUtils.positionPopup(session,j,et.getX(),et.getY());
-
- }
-
- public static void scriptDir(String pathName, JMenu menu,Session session) {
-
- File root = new File(pathName);
-
- try {
-
- macroVector = new Vector();
-
- loadScripts(macroVector,root.getCanonicalPath(),root, session);
- createScriptsMenu(menu,macroVector,0);
-
- }
- catch (IOException ioe) {
- System.out.println(ioe.getMessage());
-
- }
-
- }
-
- /**
- * Recursively read the scripts directory and add them to our macros vector
- * holding area
- *
- * @param vector
- * @param path
- * @param directory
- * @param session
- */
- private static void loadScripts(Vector vector,
- String path,
- File directory,
- Session session) {
-
- ExecuteScriptAction action;
-
- File[] macroFiles = directory.listFiles();
- if(macroFiles == null || macroFiles.length == 0)
- return;
-
- Arrays.sort(macroFiles,new MacroCompare());
-
- for(int i = 0; i < macroFiles.length; i++) {
- File file = macroFiles[i];
- String fileName = file.getName();
- if(file.isHidden()) {
- /* do nothing! */
- continue;
- }
- else if(file.isDirectory()) {
- Vector submenu = new Vector();
- submenu.addElement(fileName.replace('_',' '));
- loadScripts(submenu,path + fileName + '/',file,session);
- // if we do not want empty directories to show up uncomment this
- // line.
- // if(submenu.size() != 1)
- vector.addElement(submenu);
- }
- else {
- if (InterpreterDriverManager.isScriptSupported(fileName)) {
- String fn = fileName.replace('_',' ');
- int index = fn.lastIndexOf('.');
- if (index > 0) {
- fn = fn.substring(0,index);
- }
- action = new ExecuteScriptAction(fn,
- file.getAbsolutePath(),
- session) {
- };
- vector.addElement(action);
- }
- }
- }
- }
-
- /**
- * Create the scripts menu(s) from the vector of macros provided
- *
- * @param menu
- * @param vector
- * @param start
- */
- private static void createScriptsMenu(JMenu menu, Vector vector, int start) {
-
- JPopupMenu jpop = new JPopupMenu();
- jpop.add("Delete");
-
- for (int i = start; i < vector.size(); i++) {
- Object obj = vector.elementAt(i);
- if (obj instanceof ExecuteScriptAction) {
- JMenuItem mi = menu.add((ExecuteScriptAction)obj);
- // mi.
- // mi.add(jpop);
- }
- else
- if (obj instanceof Vector) {
- Vector subvector = (Vector)obj;
- String name = (String)subvector.elementAt(0);
- JMenu submenu = new JMenu(name);
- createScriptsMenu(submenu,subvector,1);
- if(submenu.getMenuComponentCount() == 0) {
- submenu.add(LangTool.getString("popup.noScripts"));
- }
- menu.add(submenu);
- }
- }
- }
-
- public static class MacroCompare implements Comparator {
- public int compare(Object one, Object two) {
- String s1 = one.toString();
- String s2 = two.toString();
- return s1.compareToIgnoreCase(s2);
- }
-
- }
-
- }
--- 1525,1526 ----
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.