nText - A Simple Text Editor

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »

83 Replies - 7708 Views - Last Post: 16 July 2009 - 04:29 PM

#16 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Re: nText - A Simple Text Editor

Posted 27 September 2008 - 02:26 PM

I've decided that I'm gonna re-write nText because the NetBeans GUI designer isn't working for me when I'm editing it. But this won't set me back very long since I'm only re-writing the UI.
Was This Post Helpful? 0
  • +
  • -

#17 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: nText - A Simple Text Editor

Posted 03 October 2008 - 02:51 PM

So is it rewritten yet? :P

I just started learning Java, but I'm taking it in ridiculously quickly, so if you need some help, let me know and I'll take a look.
Was This Post Helpful? 0
  • +
  • -

#18 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Re: nText - A Simple Text Editor

Posted 03 October 2008 - 03:21 PM

I'm stopping my development of it for atleast a month because school (especially honours math (oh yes, I'm in honours)) is keeping me back.
Was This Post Helpful? 0
  • +
  • -

#19 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Re: nText - A Simple Text Editor

Posted 27 October 2008 - 10:25 AM

The attatchment is a .zip file with nText 0.0.5 beta in it, enjoy! :D

Attached File(s)

  • Attached File  nText.zip (4.18K)
    Number of downloads: 103

This post has been edited by abgorn: 27 October 2008 - 12:33 PM

Was This Post Helpful? 0
  • +
  • -

#20 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: nText - A Simple Text Editor

Posted 27 October 2008 - 12:53 PM

This might just be me being a total Java n00b, but I can't open the jar.

When I run java jar C:/nText.jar I just get some error saying it couldn't locate main.

:?:
Was This Post Helpful? 0
  • +
  • -

#21 GWatt  Icon User is offline

  • member icon

Reputation: 264
  • View blog
  • Posts: 3,059
  • Joined: 01-December 05

Re: nText - A Simple Text Editor

Posted 27 October 2008 - 01:13 PM

[edit]
Gabehabe, it's actually because you are a command prompt noob.
try java -jar nText.jar

the hyphen tells the program that the text 'jar' should be considered an option, not the class file to look for.

@abgorn:
It looks pretty nice, but when I resize the window the text area stays the same. It also doesn't properly detect line breaks (probably because I'm on a mac)

This post has been edited by GWatt: 27 October 2008 - 01:18 PM

Was This Post Helpful? 0
  • +
  • -

#22 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: nText - A Simple Text Editor

Posted 27 October 2008 - 01:18 PM

That's exactly what I got.
Was This Post Helpful? 0
  • +
  • -

#23 GWatt  Icon User is offline

  • member icon

Reputation: 264
  • View blog
  • Posts: 3,059
  • Joined: 01-December 05

Re: nText - A Simple Text Editor

Posted 27 October 2008 - 02:49 PM

Can you post updated source code?
Was This Post Helpful? 0
  • +
  • -

#24 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Re: nText - A Simple Text Editor

Posted 27 October 2008 - 03:03 PM

It's still beta, very beta, but I'm happy with it since it's only half a release and it isn't resizing because your on a Mac, it's because I haven't had the time today to do it . Here's the Java source:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*; 

public class Main extends JFrame implements ActionListener, 
		ItemListener {
	
	public static JTextArea tA = new JTextArea("", 20, 50);
	JScrollPane scroller = new JScrollPane(tA,
			ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
			ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
	JMenuBar mB = new JMenuBar();
	JMenu fM = new JMenu("File");
	JMenuItem newFile = new JMenuItem("New");
	JMenuItem openFile = new JMenuItem("Open...");
	JMenuItem saveFile = new JMenuItem("Save...");
	JMenuItem exit = new JMenuItem("Exit");  
	JMenu eM = new JMenu("Edit");
	JMenuItem cut = new JMenuItem("Cut");
	JMenuItem copy = new JMenuItem("Copy");
	JMenuItem paste = new JMenuItem("Paste");
	JMenuItem selectAll = new JMenuItem("Select All");
	JMenuItem time = new JMenuItem("Time & Date");
	JMenu foM = new JMenu("Format");
	JCheckBoxMenuItem wordWrap = new JCheckBoxMenuItem("Word Wrap", true);
	
	public static void getTime() {
		String time;
		Calendar now = Calendar.getInstance();
		int hour = now.get(Calendar.HOUR_OF_DAY);
		int minute = now.get(Calendar.MINUTE);
		int month = now.get(Calendar.MONTH) + 1;
		int day = now.get(Calendar.DAY_OF_MONTH);
		int year = now.get(Calendar.YEAR);

		String monthName = "";
		switch (month) {
			case (1):
				monthName = "January";
				break;
			case (2):
				monthName = "February";
				break;
			case (3):
				monthName = "March";
				break;
			case (4):
				monthName = "April";
				break;
			case (5):
				monthName = "May";
				break;
			case (6):
				monthName = "June";
				break;
			case (7):
				monthName = "July";
				break;
			case (8):
				monthName = "August";
				break;
			case (9):
				monthName = "September";
				break;
			case (10):
				monthName = "October";
				break;
			case (11):
				monthName = "November";
				break;
			case (12):
				monthName = "December";
		}
		time = monthName + " " + day + ", " + year + " "
			+ hour + ":" + minute;
	tA.append(time);
	}
	
	public Main() {
		super("nText 0.0.5");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		newFile.setToolTipText("Create a New File");
		openFile.setToolTipText("Open a File");
		saveFile.setToolTipText("Save Current File");
		exit.setToolTipText("Exit nText");
		
		copy.setToolTipText("Copy Selected Text");
		paste.setToolTipText("Paste Text");
		cut.setToolTipText("Cut Current Text");
		time.setToolTipText("Add Time & Date");
		
		newFile.addActionListener(this);
		openFile.addActionListener(this);
		saveFile.addActionListener(this);
		exit.addActionListener(this);
		copy.addActionListener(this);
		paste.addActionListener(this);
		cut.addActionListener(this);
		selectAll.addActionListener(this);
		time.addActionListener(this);
		
		wordWrap.addItemListener(this);
		
		
		eM.add(copy);
		eM.add(paste);
		eM.add(cut);
		eM.addSeparator();
		eM.add(selectAll);
		eM.add(time);
		
		fM.add(newFile);
		fM.add(openFile);
		fM.add(saveFile);
		fM.addSeparator();
		fM.add(exit);
		
		foM.add(wordWrap);
		
		mB.add(fM);
		mB.add(eM);
		mB.add(foM);
		
		tA.setWrapStyleWord(true);
		tA.setLineWrap(true);
		
		BorderLayout bord = new BorderLayout();
		setLayout(bord);
		JPanel pane = new JPanel();
		pane.add(scroller, BorderLayout.CENTER);
		add(pane);
		setJMenuBar(mB);
		pack();
		setVisible(true);
	}
	
	public void itemStateChanged(ItemEvent ie) {
		Object itemSource = ie.getSource();
		if (itemSource == wordWrap) {
			if (wordWrap.getState() == true) {
				tA.setLineWrap(true);
			} else if (wordWrap.getState() == false) {
				tA.setLineWrap(false);
			}
		}
	}
	
	public void actionPerformed(ActionEvent evt) {
		Object source = evt.getSource();
		if (source == exit) {
			System.exit(0);
		} else if (source == saveFile) {
			 new saveFileClass();
		} else if (source == openFile) {
			new openFileClass();
		} else if (source == newFile) {
			tA.setText("");
		} else if (source == copy) {
			tA.copy();
		} else if (source == paste) {
			tA.paste();
		} else if (source == cut) {
			tA.cut();
		} else if (source == selectAll) {
			tA.selectAll();
		} else if (source == time) {
			getTime();
		} 
	}
	
	public static void main(String[] args) {
		Main mW = new Main();
	}
}

class openFileClass {
	
	openFileClass() {
		final JFileChooser fc = new JFileChooser();
		int returnVal = fc.showOpenDialog(fc);
		if (returnVal == JFileChooser.APPROVE_OPTION) {  
			Main.tA.setText("");
			try {
				Scanner scan = new Scanner(new FileReader(fc.getSelectedFile().getPath())); 
				while (scan.hasNext())
					Main.tA.append(scan.nextLine() + "\n");
			}
			catch (Exception ex) { 
			}  
		} 
	}
}

class saveFileClass {
	
	saveFileClass() {
		final JFileChooser fc = new JFileChooser();
		int returnVal = fc.showSaveDialog(fc);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			try {
				BufferedWriter out = new BufferedWriter(new FileWriter(fc.getSelectedFile().getPath()));  
				out.write(Main.tA.getText());
				out.close();
			}
			catch (Exception ex) {
			}
		}
	}
}


But it's actually much longer than needed.
Was This Post Helpful? 0
  • +
  • -

#25 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Re: nText - A Simple Text Editor

Posted 28 October 2008 - 11:35 AM

Has anyone got it working and tested it?
Was This Post Helpful? 0
  • +
  • -

#26 GWatt  Icon User is offline

  • member icon

Reputation: 264
  • View blog
  • Posts: 3,059
  • Joined: 01-December 05

Re: nText - A Simple Text Editor

Posted 28 October 2008 - 12:22 PM

JDK 6 isn't available on macs (AFAIK) so i can't compile, but I have run the DL you provided.
It works OK.

I think you could stand to add some sort of file type detection. (mac,unix,win & utf8,utf16)
I opened some files and a couple had funny characters where whitespace should have been.
Was This Post Helpful? 0
  • +
  • -

#27 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Re: nText - A Simple Text Editor

Posted 28 October 2008 - 12:57 PM

Strange, but thanks for the feed back. I'll get right on it.
Was This Post Helpful? 0
  • +
  • -

#28 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Re: nText - A Simple Text Editor

Posted 29 October 2008 - 09:25 AM

nText 0.0.6 Beta is available (the download) and here's the source:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Font.*;
import java.io.*;
import java.util.*; 

public class Main extends JFrame implements ActionListener, 
        ItemListener {
    
    public static JTextArea tA = new JTextArea("", 20, 50);
    JScrollPane scroller = new JScrollPane(tA,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    
    JMenuBar mB = new JMenuBar();
    JMenu fM = new JMenu("File");
    JMenuItem newFile = new JMenuItem("New");
    JMenuItem openFile = new JMenuItem("Open...");
    JMenuItem saveFile = new JMenuItem("Save...");
    JMenuItem exit = new JMenuItem("Exit");  
    JMenu eM = new JMenu("Edit");
    JMenuItem cut = new JMenuItem("Cut");
    JMenuItem copy = new JMenuItem("Copy");
    JMenuItem paste = new JMenuItem("Paste");
    JMenuItem selectAll = new JMenuItem("Select All");
    JMenuItem time = new JMenuItem("Time & Date");
    JMenu foM = new JMenu("Format");
    JCheckBoxMenuItem wordWrap = new JCheckBoxMenuItem("Word Wrap", true);
    JMenuItem font = new JMenuItem("Fonts...");
    
    JToolBar toolBar = new JToolBar();
    JButton button = new JButton();
    
    public static void getTime() {
        String time;
        Calendar now = Calendar.getInstance();
        int hour = now.get(Calendar.HOUR_OF_DAY);
        int minute = now.get(Calendar.MINUTE);
        int month = now.get(Calendar.MONTH) + 1;
        int day = now.get(Calendar.DAY_OF_MONTH);
        int year = now.get(Calendar.YEAR);

        String monthName = "";
        switch (month) {
            case (1):
                monthName = "January";
                break;
            case (2):
                monthName = "February";
                break;
            case (3):
                monthName = "March";
                break;
            case (4):
                monthName = "April";
                break;
            case (5):
                monthName = "May";
                break;
            case (6):
                monthName = "June";
                break;
            case (7):
                monthName = "July";
                break;
            case (8):
                monthName = "August";
                break;
            case (9):
                monthName = "September";
                break;
            case (10):
                monthName = "October";
                break;
            case (11):
                monthName = "November";
                break;
            case (12):
                monthName = "December";
        }
        time = monthName + " " + day + ", " + year + " "
            + hour + ":" + minute;
    tA.append(time);
    }
    
    public Main() {
        super("nText 0.0.6");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400, 600);
        
        toolBar.add(button);
        
        tA.setWrapStyleWord(true);
        tA.setLineWrap(true);
        this.getContentPane().setLayout(new BorderLayout());
        this.getContentPane().add(toolBar);
        this.getContentPane().add(scroller);
        
        newFile.setToolTipText("Create a New File");
        openFile.setToolTipText("Open a File");
        saveFile.setToolTipText("Save Current File");
        exit.setToolTipText("Exit nText");
        
        copy.setToolTipText("Copy Selected Text");
        paste.setToolTipText("Paste Text");
        cut.setToolTipText("Cut Current Text");
        time.setToolTipText("Add Time & Date");
        
        wordWrap.setToolTipText("");
        font.setToolTipText("Change Current Font");
        
        newFile.addActionListener(this);
        openFile.addActionListener(this);
        saveFile.addActionListener(this);
        exit.addActionListener(this);
        copy.addActionListener(this);
        paste.addActionListener(this);
        cut.addActionListener(this);
        selectAll.addActionListener(this);
        time.addActionListener(this);
        
        wordWrap.addItemListener(this);
        font.addActionListener(this);
        
        eM.add(copy);
        eM.add(paste);
        eM.add(cut);
        eM.addSeparator();
        eM.add(selectAll);
        eM.add(time);
        
        fM.add(newFile);
        fM.add(openFile);
        fM.add(saveFile);
        fM.addSeparator();
        fM.add(exit);
        
        foM.add(wordWrap);
        foM.add(font);
        
        mB.add(fM);
        mB.add(eM);
        mB.add(foM);
        
        setJMenuBar(mB);
        pack(); 
        setVisible(true);
    }
    
    public void itemStateChanged(ItemEvent ie) {
        Object itemSource = ie.getSource();
        if (itemSource == wordWrap) {
            if (wordWrap.getState() == true) {
                tA.setLineWrap(true);
            } else if (wordWrap.getState() == false) {
                tA.setLineWrap(false);
            }
        }
    }
    
    public void actionPerformed(ActionEvent evt) {
        Object source = evt.getSource();
        if (source == exit) {
            System.exit(0);
        } else if (source == saveFile) {
             new saveFileClass();
        } else if (source == openFile) {
            new openFileClass();
        } else if (source == newFile) {
            tA.setText("");
        } else if (source == copy) {
            tA.copy();
        } else if (source == paste) {
            tA.paste();
        } else if (source == cut) {
            tA.cut();
        } else if (source == selectAll) {
            tA.selectAll();
        } else if (source == time) {
            getTime();
        }  else if (source == font) {
            new fonts();
        }
    }
    
    public static void main(String[] args) {
        Main mW = new Main();
    }
}

class openFileClass {
    
    openFileClass() {
        final JFileChooser fc = new JFileChooser();
        int returnVal = fc.showOpenDialog(fc);
        if (returnVal == JFileChooser.APPROVE_OPTION) {  
            Main.tA.setText("");
            try {
                Scanner scan = new Scanner(new FileReader(fc.getSelectedFile().getPath())); 
                while (scan.hasNext())
                    Main.tA.append(scan.nextLine() + "\n");
            }
            catch (Exception ex) { 
            }  
        } 
    }
}

class saveFileClass {
    
    saveFileClass() {
        final JFileChooser fc = new JFileChooser();
        int returnVal = fc.showSaveDialog(fc);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            try {
                BufferedWriter out = new BufferedWriter(new FileWriter(fc.getSelectedFile().getPath()));  
                out.write(Main.tA.getText());
                out.close();
            }
            catch (Exception ex) {
            }
        }
    }
}

class fonts extends JFrame implements ActionListener {
    String[] fontStyle = {"Bold", "Italic", "Plain"};
    
    Vector<String> vectorFonts = new Vector();
    Vector<String> vectorSize = new Vector();
    Vector<String> vectorStyle = new Vector();
    
    JList fontTypeList = new JList(vectorFonts);
    JList fontSizeList = new JList(vectorSize);
    JList fontStyleList = new JList(vectorStyle);
    
    JScrollPane scroll1 = new JScrollPane(fontTypeList);
    JScrollPane scroll2 = new JScrollPane(fontSizeList);
    JScrollPane scroll3 = new JScrollPane(fontStyleList);
    
    JLabel fontLabel = new JLabel("Fonts:");
    
    JButton ok = new JButton("Ok");
    JButton cancel = new JButton("Cancel");
    
    fonts() {
        super("Choose Font");
        setSize(310, 300);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.getContentPane().setLayout(new BorderLayout());
        ok.addActionListener(this);
        cancel.addActionListener(this);
        
        vectorFonts.add("Arial");
        vectorFonts.add("Monospaced");
        vectorFonts.add("Dialog");
        vectorFonts.add("DialofInput");
        vectorFonts.add("Serif");
        vectorFonts.add("SansSerif");
        vectorFonts.add("Courier New");
        vectorFonts.add("Times New Roman");
        vectorFonts.add("Lucida Bright");
        vectorFonts.add("Lucida Sans");
        vectorFonts.add("Lucida Sans Typewriter");
        
        vectorSize.add("1");
        vectorSize.add("2");
        vectorSize.add("3");
        vectorSize.add("4");
        vectorSize.add("5");
        vectorSize.add("6");
        vectorSize.add("7");
        vectorSize.add("8");
        vectorSize.add("9");
        vectorSize.add("10");
        vectorSize.add("11");
        vectorSize.add("12");
        vectorSize.add("13");
        vectorSize.add("14");
        vectorSize.add("15");
        vectorSize.add("16");
        vectorSize.add("17");
        vectorSize.add("18");
        vectorSize.add("19");
        vectorSize.add("20");
        vectorSize.add("21");
        vectorSize.add("22");
        vectorSize.add("23");
        vectorSize.add("24");
        vectorSize.add("25");
        vectorSize.add("26");
        vectorSize.add("27");
        vectorSize.add("28");
        vectorSize.add("29");
        vectorSize.add("30");
        
        vectorStyle.add("Regular");
        vectorStyle.add("Bold");
        vectorStyle.add("Italic");
        
        GridLayout bor= new GridLayout();
        setLayout(bor);
        JPanel panel = new JPanel();
 
        fontTypeList.setVisibleRowCount(10);
        fontSizeList.setVisibleRowCount(10);
        fontStyleList.setVisibleRowCount(10);
        panel.add(scroll1);
        panel.add(scroll2);
        panel.add(scroll3);
        panel.add(ok, BorderLayout.SOUTH);
        panel.add(cancel, BorderLayout.SOUTH);
        add(panel);
        setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        Object gotSource = e.getSource();
        if (gotSource == ok) {
            String fontS =  vectorSize.get(fontSizeList.getLeadSelectionIndex());
            int fontSN = Integer.parseInt(fontS);
            
            String fontName = vectorFonts.get(fontTypeList.getSelectedIndex());
            
            String fontType = vectorStyle.get(fontStyleList.getMaxSelectionIndex());
            if (fontType == "Regular") {
                Font currentFont = new Font(fontName, Font.PLAIN, fontSN);
                Main.tA.setFont(currentFont);
            } else if (fontType == "Bold") {
                Font currentFont = new Font(fontName, Font.PLAIN, fontSN);
                Main.tA.setFont(currentFont);
            } else if (fontType == "Italic") {
                Font currentFont = new Font(fontName, Font.PLAIN, fontSN);
                Main.tA.setFont(currentFont);
            }
        } else if (gotSource == cancel) {
            
        } else {
            
        }
    }
}

Attached File(s)

  • Attached File  nText.zip (6.32K)
    Number of downloads: 75

Was This Post Helpful? 0
  • +
  • -

#29 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: nText - A Simple Text Editor

Posted 29 October 2008 - 01:50 PM

I still can't run the jar~ Still getting the same errors :(

Looking over the code, it seems pretty good though. Could you post a few print screens of each feature?

I'd particularly like to see the font dialog~

I don't know if you've seen my font dialog snippet, but a tip for the font list:
Instead of adding individual fonts, you could get a whole list of each available font:
 String[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();


:)


EDIT:
Also, for your font size list, you could do this:
for (int i = 1; i <= 30; i++) {
    this.vectorSize.add(i.toString());
}

To get rid of those 30 lines of repetitive code. :)
Was This Post Helpful? 1
  • +
  • -

#30 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Re: nText - A Simple Text Editor

Posted 29 October 2008 - 02:20 PM

Thanks, I'll add that now ^_^
Was This Post Helpful? 0
  • +
  • -

  • (6 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »