src/main/java/RecentFileMenu.java
private void addEntry(String filePath,boolean updateFile){
		//check if this is disabled 
		if(!this.isEnabled()){
			this.setEnabled(true);
		}
		//clear the existing items
		this.removeAll();
		//move everything down one slot
		int count=this.itemCount-1;
		for(int index=count;index>0;index--){
			//check for duplicate entry
			if(!this.recentEntries[index-1].equalsIgnoreCase(filePath)){
				this.recentEntries[index]=new String(this.recentEntries[index-1]);
			}
		}
		//add the new item, check if it's not alredy the first item
		if(!this.recentEntries[0].equalsIgnoreCase(filePath)){
			this.recentEntries[0]=new String(filePath);
		}
		//add items back to the menu
		for(int index=0;index<this.itemCount;index++){
        	JMenuItem menuItem=new JMenuItem();
			menuItem.setText(this.recentEntries[index]);
			if(this.recentEntries[index].equals(defaultText)){
				menuItem.setVisible(false);
			} else{
				menuItem.setVisible(true);
				menuItem.setToolTipText(this.recentEntries[index]);
				menuItem.setActionCommand(this.recentEntries[index]);
				menuItem.addActionListener(new ActionListener(){
		            public void actionPerformed(ActionEvent actionEvent){
		                onSelectFile(actionEvent.getActionCommand());
		            }
		        });
	        }
        	this.add(menuItem);
        }
        //update the file
		if(updateFile){
			try{
				FileWriter writer=new FileWriter(new File(this.pathToSavedFile));
				int topIndex=this.itemCount-1;
				for(int index=topIndex;index>=0;index--){
					if(!this.recentEntries[index].equals(defaultText)){
						writer.write(this.recentEntries[index]);
						writer.write("\n");
					}
				}
				writer.flush();
				writer.close();
			} catch(Exception x){
				x.printStackTrace();
			}
		}
	}
/**
	 * Adds a new entry to the menu. Moves everything "down" one row.
	 * @param filePath The new path to add.
	 * @param updateFile Whether to update the saved file, only false when called from constructor.
	 */
Adds a new entry to the menu. Moves everything "down" one row.
@param filePath The new path to add.
@param updateFile Whether to update the saved file, only false when called from constructor.
Adds a new entry to the menu . Moves everything " down " one row . @param filePath The new path to add . @param updateFile Whether to update the saved file only false when called from constructor .
private void addEntry(String filePath,boolean updateFile){
		if(!this.isEnabled()){
			this.setEnabled(true);
		}
		this.removeAll();
		int count=this.itemCount-1;
		for(int index=count;index>0;index--){
			if(!this.recentEntries[index-1].equalsIgnoreCase(filePath)){
				this.recentEntries[index]=new String(this.recentEntries[index-1]);
			}
		}
		if(!this.recentEntries[0].equalsIgnoreCase(filePath)){
			this.recentEntries[0]=new String(filePath);
		}
		for(int index=0;index<this.itemCount;index++){
        	JMenuItem menuItem=new JMenuItem();
			menuItem.setText(this.recentEntries[index]);
			if(this.recentEntries[index].equals(defaultText)){
				menuItem.setVisible(false);
			} else{
				menuItem.setVisible(true);
				menuItem.setToolTipText(this.recentEntries[index]);
				menuItem.setActionCommand(this.recentEntries[index]);
				menuItem.addActionListener(new ActionListener(){
		            public void actionPerformed(ActionEvent actionEvent){
		                onSelectFile(actionEvent.getActionCommand());
		            }
		        });
	        }
        	this.add(menuItem);
        }
		if(updateFile){
			try{
				FileWriter writer=new FileWriter(new File(this.pathToSavedFile));
				int topIndex=this.itemCount-1;
				for(int index=topIndex;index>=0;index--){
					if(!this.recentEntries[index].equals(defaultText)){
						writer.write(this.recentEntries[index]);
						writer.write("\n");
					}
				}
				writer.flush();
				writer.close();
			} catch(Exception x){
				x.printStackTrace();
			}
		}
	}
private void addEntry ( String filePath , boolean updateFile ) { if ( ! this . isEnabled ( ) ) { this . setEnabled ( true ) ; } this . removeAll ( ) ; int count = this . itemCount - 1 ; for ( int index = count ; index > 0 ; index -- ) { if ( ! this . recentEntries [ index - 1 ] . equalsIgnoreCase ( filePath ) ) { this . recentEntries [ index ] = new String ( this . recentEntries [ index - 1 ] ) ; } } if ( ! this . recentEntries [ 0 ] . equalsIgnoreCase ( filePath ) ) { this . recentEntries [ 0 ] = new String ( filePath ) ; } for ( int index = 0 ; index < this . itemCount ; index ++ ) { JMenuItem menuItem = new JMenuItem ( ) ; menuItem . setText ( this . recentEntries [ index ] ) ; if ( this . recentEntries [ index ] . equals ( defaultText ) ) { menuItem . setVisible ( false ) ; } else { menuItem . setVisible ( true ) ; menuItem . setToolTipText ( this . recentEntries [ index ] ) ; menuItem . setActionCommand ( this . recentEntries [ index ] ) ; menuItem . addActionListener ( new ActionListener ( ) { public void actionPerformed ( ActionEvent actionEvent ) { onSelectFile ( actionEvent . getActionCommand ( ) ) ; } } ) ; } this . add ( menuItem ) ; } if ( updateFile ) { try { FileWriter writer = new FileWriter ( new File ( this . pathToSavedFile ) ) ; int topIndex = this . itemCount - 1 ; for ( int index = topIndex ; index >= 0 ; index -- ) { if ( ! this . recentEntries [ index ] . equals ( defaultText ) ) { writer . write ( this . recentEntries [ index ] ) ; writer . write ( "\n" ) ; } } writer . flush ( ) ; writer . close ( ) ; } catch ( Exception x ) { x . printStackTrace ( ) ; } } }
Adds a new entry to the menu.
Adds a new entry to the menu .
//check if this is disabled  //clear the existing items //move everything down one slot //check for duplicate entry //add the new item, check if it's not alredy the first item //add items back to the menu //update the file