There is a subtle difference, but it's not due to something being a single event or not.
I prefer to have a cup of coffee (this time).
This isn't talking about a particular event because of to have, it's a particular event because of the use of a in the sentence construction.
Contrast it with the following:
I prefer to have single cups of coffee (in general).
Now, it's no longer a single event. It's talking about an ongoing state of affairs and intentions.
So, let's compare those two sentences:
I prefer having single cups of coffee.
I prefer to have single cups of coffee.
The only real difference between the two, which is often not really thought about, is that the former talks more about those times during which a single cup of coffee is in the process of being had. Meanwhile, the latter talks more about the nature of how the coffee will be had.
It's a subtle distinction. In fact, most people would probably frame the statement differently, bypassing the distinction altogether:
I prefer single cups of coffee.
A similar analysis could be performed on your first sentence, although I need to rephrase it slightly:
I prefer swimming to running.
I would rather swim than run.
I would say that the distinction here is even more subtle and less present. But if it's to be made at all, it would again be that the first sentence talks more about being currently engaged in the process of the activity (perhaps in the context of enjoying it), while the second talks more about the idea of the activities (perhaps theorizing about their benefits).
In both cases, however, there is really no effective difference between the two. They are often used interchangeably.