Jump to content

My Current project - Notes Express


RSBDavid

Recommended Posts

Here is a little background on this script.

 

I wanted to create my own note taking program to use on my laptop at school instead of using notepad/word. This is because of two reasons: One, I learn more Java methods. Two, I create something useful.

 

 

 

Picture of GUI as of January 25, 2009:

[hide=GUI]

148fckg.png

[/hide]

 

I will post my source here and update on my progress.

 

Log:

January 25, 2010 - Source released

 

 

 

 

[hide=Original source]

 

import java.awt.Color;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.metal.DefaultMetalTheme;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.plaf.metal.OceanTheme;
import javax.swing.tree.DefaultMutableTreeNode;


/*  Author - David H.
*  Project: A note taking application
*  
*/

@SuppressWarnings("serial")
public class notes extends JFrame implements ActionListener{
//Variables
       String s;
       static File location = javax.swing.filechooser.FileSystemView.getFileSystemView().getDefaultDirectory();

       final static String LOOKANDFEEL = "Metal";
       final static String THEME = "Ocean";

       Action selectLine;

       Date now = new Date();
       //EOV section


       public notes() {
               //set a title for the application
               super("Notes Express - A free lite note taking application");
               setSize(800,600);


               JMenuBar mb = new JMenuBar();
               setJMenuBar(mb);


               JMenu fileMenu = new JMenu("File");
       JMenu editMenu = new JMenu("Edit");
       mb.add(fileMenu);
       mb.add(editMenu);
       JMenuItem newMenu = new JMenuItem("New");
       JMenuItem openMenu = new JMenuItem("Open");
       JMenuItem saveMenu = new JMenuItem("Save");
       JMenuItem exitMenu = new JMenuItem("Exit");
       JMenuItem cutMenu = new JMenuItem("Cut");
       JMenuItem copyMenu = new JMenuItem("Copy");
       JMenuItem pasteMenu = new JMenuItem("Paste");


       fileMenu.add(newMenu);
       fileMenu.add(openMenu);
       fileMenu.add(saveMenu);
       fileMenu.addSeparator();
       fileMenu.add(exitMenu);
       editMenu.add(cutMenu);
       editMenu.add(copyMenu);
       editMenu.add(pasteMenu);
       editMenu.addSeparator();

       exitMenu.addActionListener(new ActionListener() {

           public void actionPerformed(ActionEvent e) {
               System.exit(0);
           }
       });


      JButton hl = new JButton("Highlight");

      JLabel hi = new JLabel("Welcome to Notes Express!");
      hi.setFont(new Font("Arial",Font.BOLD,12));
      hi.setForeground(Color.WHITE);

      JTextField keyword = new JTextField(12);
      JLabel msg1 = new JLabel("Enter the keywords to highlight:   ");
      msg1.setFont(new Font("Arial",Font.BOLD,12));
      msg1.setForeground(Color.WHITE);

      JToolBar tb = new JToolBar();
      tb.setBackground(Color.BLUE);
      tb.setFloatable(false);
      tb.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));
      tb.add(msg1);
      tb.add(keyword);
      //temporary method
      keyword.setText("THIS IS NOT FUNCTIONAL");
      keyword.setMargin(new Insets(0,5,0,5));

    //  JScrollPane sp = new JScrollPane();

      DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
      DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child 1");
      root.add(child1);
      DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child 2");
      root.add(child2);
      JTree tree = new JTree(root);
      add(new JScrollPane(tree),"East");



      tb.add(hl);
               //create text area to type text into
               final JTextArea lol = new JTextArea();
               lol.setFont(new Font("Arial", Font.PLAIN, 12));
               lol.setLineWrap(true);
               lol.setWrapStyleWord(true);
               lol.setBorder(BorderFactory.createLineBorder(Color.BLACK,2));


               //add textarea and menubar to gui
               add(lol,"Center");
               add(tb,"North");



               hl.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {




                  }
                });


               openMenu.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {



                        JFileChooser fc = new JFileChooser();
                    int returnVal = fc.showOpenDialog( notes.this );
                    if( returnVal == JFileChooser.APPROVE_OPTION ) 
                    {
                      File file = fc.getSelectedFile();



                      //lolllllllllllllllllllll
                      FileReader fr = null;
                               try {
                                       fr = new FileReader(file);
                               } catch (FileNotFoundException e1) {
                                       // TODO Auto-generated catch block
                                       e1.printStackTrace();
                               } 
                      BufferedReader br = new BufferedReader(fr);
                      try {
                                       lol.read(br, notes.this);
                               } catch (IOException e1) {
                                       // TODO Auto-generated catch block
                                       e1.printStackTrace();
                               }
                      //lpolllllllllllllllllllll
                    } 
                  }
                });


               //java save file jfilechooser
       initLookAndFeel();
        saveMenu.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {



                JFileChooser fc = new JFileChooser();
            fc.setSelectedFile( new File( "Temporary Name" ) );
            int returnVal = fc.showSaveDialog( notes.this );
            if( returnVal == JFileChooser.APPROVE_OPTION ) 
            {
              File file = fc.getSelectedFile();
              //saveTextFile(lol.getText(), location + "/notes.txt");
              saveTextFile(lol.getText(), file + ".rtf");


            } 


        }


    });
       }





       public static void main(String[] args)throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
               //required stuff
               notes note = new notes();

       System.out.println(location);

               note.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
               note.setVisible(true);

       }

       public static String newline = System.getProperty("line.separator");

       public  void saveTextFile(String text, String string)
{

   try
   {



       FileWriter write = new FileWriter(string, true );
       PrintWriter text1 = new PrintWriter(write);

       text1.println();


       {
       text1.print("Notes typed on: " + newline + now);
       text1.print(newline);
       text1.print(text);
       }

       text1.flush();
       write.close();
       }
       catch (IOException ie)
       {
       System.out.println(ie);
       }

}

       //Graphics Crap
       //http://java.sun.com/docs/books/tutorial/uiswing/lookandfeel/plaf.html


  private static void initLookAndFeel() {




       String lookAndFeel = null;

       if (LOOKANDFEEL != null) {
           if (LOOKANDFEEL.equals("Metal")) {
               lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
             //  an alternative way to set the Metal L&F is to replace the 
             // previous line with:
             // lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel";

           }

           else if (LOOKANDFEEL.equals("System")) {
               lookAndFeel = UIManager.getSystemLookAndFeelClassName();
           } 

           else if (LOOKANDFEEL.equals("Motif")) {
               lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
           } 

           else if (LOOKANDFEEL.equals("GTK")) { 
               lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
           } 

           else {
               System.err.println("Unexpected value of LOOKANDFEEL specified: "
                                  + LOOKANDFEEL);
               lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
           }

           try {


               UIManager.setLookAndFeel(lookAndFeel);

               // If L&F = "Metal", set the theme

               if (LOOKANDFEEL.equals("Metal")) {
                 if (THEME.equals("DefaultMetal"))
                    MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
                 else if (THEME.equals("Ocean"))
                    MetalLookAndFeel.setCurrentTheme(new OceanTheme());



                 UIManager.setLookAndFeel(new MetalLookAndFeel()); 
               }       




           } 

           catch (ClassNotFoundException e) {
               System.err.println("Couldn't find class for specified look and feel");

               System.err.println("Did you include the L&F library in the class path?");
               System.err.println("Using the default look and feel.");
           } 

           catch (UnsupportedLookAndFeelException e) {
               System.err.println("Can't use the specified look and feel"); 
               System.err.println("Using the default look and feel.");
           } 

           catch (Exception e) {
               System.err.println("Couldn't get specified look and feel");

               System.err.println("Using the default look and feel.");
               e.printStackTrace();
           }
       }
   }





public void actionPerformed(ActionEvent e) {
       //I am putting this method here because the application requires it, but I use inline action events where needed

}








}



[/hide]

 

Feature List:

[ ] = non working

[x] = working

 

[x]Save text

[x]Open text

[ ]Search for keywords

[ ]Organize notes in a tree form.

[ ]Enhance important facts with prefix symbols

-With this feature, if I was to post something like:

"**George Washington was the first president of the United States"

It would appear in the notes as:

George Washington was the first president of the United States

 

"*blue*George Washington was the first president of the United States"

would appear as:

George Washington was the first president of the United States

 

 

As you can probably tell, I am still a ways from being finished. I hope to have it finished sometime within the first two weeks of February.

 

If you have any ideas feel free to post.

wii_wheaton.png

[software Engineer] -

[Ability Bar Suggestion] - [Gaming Enthusiast]

Link to comment
Share on other sites

Looks pretty good so far.

 

What sort of storage method are you looking at using for the end result? I know plenty of people don't stray from their original method.. just wondering if you'd do something like XML that they can fire up in a reader/portable device

 

 

And, auto-save?

 

 

Also, are you sticking with like *blue* *green* etc for font.. or ever plan to support hex code instead (both full and short - eg 00ff00 v 0f0)?

Link to comment
Share on other sites

This has just reminded me of how much I wimp out with gui's, I use netbeans gui builder lol. And metal is the uglies L&F ever :(

 

Other than that I like it, not too complicated but useful!

 

Its been on my mind for a while to develop a basic library application, since my parents have 10k+ books lying around the house.

polvCwJ.gif
"It's not a rest for me, it's a rest for the weights." - Dom Mazzetti

Link to comment
Share on other sites

Looks pretty good so far.

 

What sort of storage method are you looking at using for the end result? I know plenty of people don't stray from their original method.. just wondering if you'd do something like XML that they can fire up in a reader/portable device

 

 

And, auto-save?

 

 

Also, are you sticking with like *blue* *green* etc for font.. or ever plan to support hex code instead (both full and short - eg 00ff00 v 0f0)?

 

 

I started with plain text when setting everything up, I plan on eventually switching over to XML. I will also have an auto-save feature which will save notes every 5 minutes. I am also thinking about writing a backup of the notes to my web site so if my computer ever fails, is lost, or gets stolen, I have backups.

 

Thanks for the feedback so far!

 

I am still working out the color system.

wii_wheaton.png

[software Engineer] -

[Ability Bar Suggestion] - [Gaming Enthusiast]

Link to comment
Share on other sites

Its a nice idea and looks good.

Its making really want to learn java.

[hide=Drops]

  • Dragon Axe x11
    Berserker Ring x9
    Warrior Ring x8
    Seercull
    Dragon Med
    Dragon Boots x4 - all less then 30 kc
    Godsword Shard (bandos)
    Granite Maul x 3

Solo only - doesn't include barrows[/hide][hide=Stats]

joe_da_studd.png[/hide]

Link to comment
Share on other sites

Did you build the GUI from scratch or use a GUI builder?

Also, pet peeve, condense your imports ;)

Last comment: don't make your main method throw exceptions. Handle them in their respective methods.

 

 

I did the GUI by scratch. If it involved a lot more areas, I would do it half and half. It is hard to get the exact positions of where some components will go, but I would generally use Net beans or something to help with that I will condense my imports in a later stage.

wii_wheaton.png

[software Engineer] -

[Ability Bar Suggestion] - [Gaming Enthusiast]

Link to comment
Share on other sites

Just to give you a heads up, I guess this in some ways is a bug, but when you try to overwrite a previous file (Like if you click on the file you want to save it as), it will add a .rtf extension to it even to it even if it already is a .rtf type. I'm liking this program though, looks like it be great when it is complete.

~Dan

 

[Edit]: A more major problem I found is that there is no scroll bar if you go past the bottom of the page. The text will continue to be typed, but you can never get to it.

overall-1.png: 1437 combat.png: 173
Lowest Combat to 1,000 Total in F2P (23 Combat)
2r8i4.png
Check me out on YouTube!

Link to comment
Share on other sites

I am working on an XML+HTML/CSS way to store the data and format it.

 

For example:

 




<NOTES>

     <SUBJECT>HISTORY</SUBJECT>
     <NOTE>
     <DATE>insert date here</DATE>
     <NOTEDATA>here is where the notes would be</NOTEDATA>
     </NOTE> 

 <SUBJECT>Math</SUBJECT>
     <NOTE>
     <DATE>3/2/10</DATE>
     <NOTEDATA><

The formula for solving right triangles is<div id="important" color= "blue">a^2 + b^2 = c^2
</div>
/NOTEDATA>
     </NOTE> 

</NOTES>

 

I could easily create a tree system to access the notes and load them in a text area in either read-only or write mode.

wii_wheaton.png

[software Engineer] -

[Ability Bar Suggestion] - [Gaming Enthusiast]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.