RenameSheet in the Spreadsheet using Java code

to let user to change the name of the tab-title

Page 1 of 1

4 Replies - 1536 Views - Last Post: 27 August 2007 - 02:16 AM Rate Topic: -----

#1 imahman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-August 07

RenameSheet in the Spreadsheet using Java code

Post icon  Posted 20 August 2007 - 11:57 PM

 package Main.ui.ctrl;

import java.awt.event.ActionEvent;
import javax.swing.ImageIcon;
import javax.swing.JTabbedPane;
import javax.swing.JDialog;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import Main.JKMain;

/**
 * A spreadsheet insertion operation.
 */
@SuppressWarnings("serial")
public class RenameSpreadsheetAction extends FocusOwnerAction {

	/** The user interface controller */
	@SuppressWarnings("serial")
	private UIController uiController;
	private JTabbedPane tabbedPane;

	/**
	 * Creates a new spreadsheet insertion action.
	 * @param uiController the user interface controller.
	 */
	public RenameSpreadsheetAction(UIController uiController) {
		this.uiController = uiController;
	}

	protected String getName() {
		return "\u0646\u0627\u0645\u0020\u0633\u0645\u0648\u0644\u0627";//nama semula;
	}

	protected void defineProperties() {
		setEnabled(true);
		putValue(SMALL_ICON, new ImageIcon(JKMain.class.getResource("res/img/rename_sheet.gif")));
	}

	/**
	 * Renames the spreadsheet of the focus owner.
	 * @param event the event that was fired
	 */
	public void actionPerformed(ActionEvent event) {
		
	//String tab = JOptionPane.showInputDialog(null, "nama: ", "unhide", JOptionPane.PLAIN_MESSAGE);
	JDialog dialog = new JDialog();
	dialog.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
	int index = 0;
	RenameDialog r_dialog = new RenameDialog(dialog, index);
	r_dialog.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
	r_dialog.show();
	  //new RenameDialog();
	  //tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM, JTabbedPane.SCROLL_TAB_LAYOUT); 
	}
}
package Main.ui.ctrl;
/**
 * @(#)RenameDialog.java
 * @version 1.00 2007/6/09
 */ 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.EventObject;

import javax.swing.JComponent;
import javax.swing.AbstractAction;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.SwingConstants;
import javax.swing.event.ChangeEvent;
import java.awt.event.ActionListener;
import javax.swing.text.*;

//import Main.core.SpreadsheetImpl;

//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

 public class RenameDialog extends JComponent implements ActionListener{
	
	JFrame parent;
	JPanel panel = new JPanel();
	JPanel panel1 = new JPanel();
	JPanel panel2 = new JPanel();
	
	JButton buttonOK = new JButton("\u064A\u0627");//ok:ya
	JButton buttonCANCEL = new JButton("\u0628\u0637\u0644");//cancel:batal
	
	JTextField nameTF = new JTextField(15);
	
	JLabel nameL = new JLabel("\u0646\u0627\u0645 :");//name:nama
	JLabel output = new JLabel();
	
	//rename dialog constructor
	
	public RenameDialog(JComponent owner, int index){
		
	   super(owner, "\u0646\u0627\u0645\u0020\u0633\u0645\u0648\u0644\u0627", false);	
		 
		 //set font size for label, textfield, button	
		nameL.setFont(new java.awt.Font("Arial Jawi KUTPM", 0, 18));
		nameTF.setEditable(true);	
		nameTF.setFont(new java.awt.Font("Arial Jawi KUTPM", 0, 18));
		nameTF.setHorizontalAlignment(JTextField.RIGHT);
		buttonOK.setFont(new java.awt.Font("Arial Jawi KUTPM", 0, 18));			 	
		buttonCANCEL.setFont(new java.awt.Font("Arial Jawi KUTPM", 0, 18));	
		
		
		Container pane = getContentPane();
		pane.setLayout(new BorderLayout());
		
		//put label on the panel
		panel1.setLayout(new FlowLayout());
		panel1.add(nameL);
		panel1.add(nameTF);
		
		//put button at the panel
		panel2.setLayout(new FlowLayout());
		panel2.add(buttonOK);
		panel2.add(buttonCANCEL);
		
		pane.add(panel,"North");
		pane.add(panel1,"Center");
		pane.add(panel2,"South");
		
		//nameTF.addActionListener(this);
		buttonOK.addActionListener(this);
		  buttonCANCEL.addActionListener(this);
		  
		  //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
		  nameTF.addKeyListener(new java.awt.event.KeyAdapter() {
			public void keyTyped(java.awt.event.KeyEvent evt) {
				jTexArea1KeyTyped(evt);
			}
		});
 
		Keymap parent = nameTF.getKeymap();
		Keymap jawi = nameTF.addKeymap("Jawi", parent);
		JTextComponent.loadKeymap( jawi, jawiBindings, jawiActions );
		TextAction a = new putJawiAction("Jawi");
		nameTF.setKeymap(jawi);
		
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	  
		  //Dialog frame
		//setTitle("\u0646\u0627\u0645\u0020\u0633\u0645\u0648\u0644\u0627");//nama semula
		setSize(300,200);
		setVisible(true);
		applyComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
		setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);		 
		
	 //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	}
	  
	private void jTexArea1KeyTyped(java.awt.event.KeyEvent evt) {
		nameTF.repaint();
	}
 
	static final JTextComponent.KeyBinding[] jawiBindings =
	{
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('q'),"putJawi \u0636"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('w'),"putJawi \u0635"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('e'),"putJawi \u062B"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('r'),"putJawi \u0642"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('t'),"putJawi \uu0641"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('y'),"putJawi \u063A"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('u'),"putJawi \u0639"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('i'),"putJawi \u06BE"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('o'),"putJawi \u062E"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('p'),"putJawi \u062D"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('P'),"putJawi \u061B"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('['),"putJawi \u062C"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(']'),"putJawi \u062F"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('a'),"putJawi \u0634"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('s'),"putJawi \u0633"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('d'),"putJawi \u064A"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('f'),"putJawi \u0628"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('g'),"putJawi \u0644"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('h'),"putJawi \u0627"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('j'),"putJawi \u062A"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('k'),"putJawi \u0646"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('l'),"putJawi \u0645"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(';'),"putJawi \u06A9"),
		   		   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('"'),"putJawi \u0637"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('z'),"putJawi \u0626"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('x'),"putJawi \u0621"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('c'),"putJawi \u0624"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('v'),"putJawi \u0631"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('b'),"putJawi \u0644\u0627"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('n'),"putJawi \u0649"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('m'),"putJawi \u0629"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(','),"putJawi \u0648"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('.'),"putJawi \u0632"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('/'),"putJawi \u0638"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('`'),"putJawi \u0630"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('1'),"putJawi \u0661"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('2'),"putJawi \u0662"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('3'),"putJawi \u0663"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('4'),"putJawi \u0664"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('5'),"putJawi \u0665"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('6'),"putJawi \u0666"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('7'),"putJawi \u0667"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('8'),"putJawi \u0668"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('9'),"putJawi \u0669"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('0'),"putJawi \u0660"),//changed!
		   		   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('?'),"putJawi \u061F"),
		   		   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('<'),"putJawi \u060C"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('Q'),"putJawi \u0686"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('W'),"putJawi \u06AF"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('E'),"putJawi \u06A4"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('R'),"putJawi \u06A0"),
		   		   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('T'),"putJawi \u06CF"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('Y'),"putJawi \u0625"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('U'),"putJawi \u066C"),												 
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('S'),"putJawi \u0643"),		   		 
		   		   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('K'),"putJawi \u06BD"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('G'),"putJawi \u0674"),												 
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('H'),"putJawi \u0623"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('X'),"putJawi \u06D5"),
		   		   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('>'),"putJawi \u002E"),
				   new JTextComponent.KeyBinding(KeyStroke.getKeyStroke('-'),"putJawi \u002D")
					};

	static final Action[] jawiActions =
	{
		new putJawiAction("\uFE95"),
		new putJawiAction("\uFEB1"),
		new putJawiAction("\uFB8E"),
		new putJawiAction("\uFEA1"),
		new putJawiAction("\u0627"),
		new putJawiAction("\u0628"),
		new putJawiAction("\u062A"),
		new putJawiAction("\u062B"),
		new putJawiAction("\u062C"),
		new putJawiAction("\u062D"),
		new putJawiAction("\u062E"),
		new putJawiAction("\u062F"),
		new putJawiAction("\u0630"),
		new putJawiAction("\u0631"),
		new putJawiAction("\u0632"),
		new putJawiAction("\u0633"),
		new putJawiAction("\u0634"),
		new putJawiAction("\u0635"),
		new putJawiAction("\u0636"),
		new putJawiAction("\u0637"),
		new putJawiAction("\u0638"),
		new putJawiAction("\u0639"),
		new putJawiAction("\u063A"),
		new putJawiAction("\u0641"),
		new putJawiAction("\u0642"),
		new putJawiAction("\u06A9"),
		new putJawiAction("\u0644"),
		new putJawiAction("\u0645"),
		new putJawiAction("\u0646"),
		new putJawiAction("\u0648"),
		new putJawiAction("\u06BE"),
		new putJawiAction("\u0644\u0627"),
		new putJawiAction("\u0623"),
		new putJawiAction("\u0625"),
		new putJawiAction("\u0626"),
		new putJawiAction("\u0674"),
		new putJawiAction("\u0621"),
		new putJawiAction("\u064A"),
		new putJawiAction("\u06CF"),
		new putJawiAction("\u0686"),
		new putJawiAction("\u06A0"),
		new putJawiAction("\u06A4"),
		new putJawiAction("\u0647"),
		new putJawiAction("\u06D5"),
		new putJawiAction("\u06AF"),
		new putJawiAction("\u06BD"),
		new putJawiAction("\u06CC"),
		new putJawiAction("\u0649"),
		new putJawiAction("\u0629"),
		new putJawiAction("\u002D"),
		new putJawiAction("\u0624"),
		new putJawiAction("\u066C"),
		new putJawiAction("\u061B"),
		new putJawiAction("\u0660"),
		new putJawiAction("\u0661"),
		new putJawiAction("\u0662"),
		new putJawiAction("\u0663"),
		new putJawiAction("\u0664"),
		new putJawiAction("\u0665"),
		new putJawiAction("\u0666"),
		new putJawiAction("\u0667"),
		new putJawiAction("\u0668"),
		new putJawiAction("\u0669"),
		new putJawiAction("\uFDF2"),
		new putJawiAction("\u060C"),
		new putJawiAction("\u061B"),
		new putJawiAction("\u061F"),
		new putJawiAction("\u0020"),
		new putJawiAction("\u0640")
		};
	static class putJawiAction extends TextAction {
 
		public putJawiAction( String s ) {
			super("putJawi "+s);
			//System.out.println(s);
			this.s = s;
		}
 
		public void actionPerformed(ActionEvent e) {
			JTextComponent target = getTextComponent(e);
			if (target != null) {
				target.replaceSelection(s);
			}
		}
 
		private String s;
	}
	
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	
	public void actionPerformed(ActionEvent event)
	{
		if(event.getSource() == buttonOK){
				String s = nameTF.getText();
				System.out.println(s);
				setVisible(false);  
		}else 
		{
		   if(event.getSource()==buttonCANCEL)
				  setVisible(false);
		}	
	}
	/*public static void main(String[]args)
	{
		JDialog dialog = new JDialog();
		dialog.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
		int index = 0;
		RenameDialog r_dialog = new RenameDialog(dialog, index);
		r_dialog.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT);
		r_dialog.show();
	}*/   
}


Is This A Good Question/Topic? 0
  • +

Replies To: RenameSheet in the Spreadsheet using Java code

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1642
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: RenameSheet in the Spreadsheet using Java code

Posted 21 August 2007 - 09:20 AM

Welcome to </dream.in.code> imahman, glad you could join us! By the way, this post should be in the Java Forum not here, Ill get one of the mods to move it for you :)
Was This Post Helpful? 0
  • +
  • -

#3 MarkoDaGeek  Icon User is offline

  • Dirty Technophile
  • member icon

Reputation: 11
  • View blog
  • Posts: 11,158
  • Joined: 13-October 01

Re: RenameSheet in the Spreadsheet using Java code

Posted 21 August 2007 - 09:50 AM

imahman I will go ahead and move this to the Java forum, however please explain more specifically what you need help doing rather then just posting a bunch of code.
Was This Post Helpful? 0
  • +
  • -

#4 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: RenameSheet in the Spreadsheet using Java code

Posted 22 August 2007 - 05:09 PM

Hi imahman, maybe you want to post this as a code snippet, if not then please tell what is the problem.
Was This Post Helpful? 0
  • +
  • -

#5 imahman  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-August 07

Re: RenameSheet in the Spreadsheet using Java code

Posted 27 August 2007 - 02:16 AM

View PostPsychoCoder, on 21 Aug, 2007 - 09:20 AM, said:

Welcome to </dream.in.code> imahman, glad you could join us! By the way, this post should be in the Java Forum not here, Ill get one of the mods to move it for you :)


what i trying to ask is how can i make the renamesheet function in the spreadsheet using java code. Actually, system that i build are using the java package and in this system we distributed the coding based on the function such to show interface we create i folder name as ui, to make the actionperform we create one folder tht hold all control in the system.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1