Let's use basic vector algebra. (This is extremely useful for any kind of graphics programmers, so if you are not familiar with the basics yet, I warmly recommend you look up some tutorials on the net first. Basics of linear algebra, namely matrices, and vector-matrix and matrix-matrix multiplication, is of tremendous help with transformations (rotations et cetera). If you add unit quaternions (also known as versors) describing rotations, and descriptive geometry basics (how to do projections), you've got a very powerful mathematical toolbox to work with all kinds of 2D and 3D graphics.)
Let's say you have a line segment between points $\vec{p}_1 = (x_1 , y_1)$ and $\vec{p}_2 = (x_2 , y_2)$, and you wish to do a parallel translation by $d$. (If $d$ is positive, when we look from $\vec{p}_1$ towards $\vec{p}_2$, the translation is to the left, if $x$ axis increases right and $y$ axis up; if $d$ is negative, to the right. This choice is arbitrary, but you'll see this choice made often in vector algebra tutorials, so it'll feel and look familiar to many.)
Step 1.
Let's define $\hat{n}$ as the unit direction vector from $\vec{p}_1$ towards $\vec{p}_2$. (Unit vector means its length is 1, i.e. $\left\lVert\hat{n}\right\rVert = 1$. The hat mark, $\hat{\cdot}$, is often (but not always) used to distinguish unit vectors from all other vectors, $\vec{\cdot}$; I use that convention here just to make that point, to convey the math clearer.)
We calculate $\hat{n}$ by
$$\hat{n} = \frac{\vec{p}_2 - \vec{p}_1}{\left\lVert \vec{p}_2 - \vec{p}_1 \right\rVert} \tag{1a}\label{NA1a}$$
If we use $\hat{n} = ( x_n , y_n )$, then in coordinate form,
$$\begin{cases}
x_n = \frac{x_2 - x_1}{\sqrt{ (x_2 - x_1)^2 + (y_2 - y_1)^2 }} \\
y_n = \frac{y_2 - y_1}{\sqrt{ (x_2 - x_1)^2 + (y_2 - y_1)^2 }} \end{cases} \tag{1b}\label{NA1b}$$
Step 2.
Rotating $\hat{n} = ( x_n , y_n )$ 90° counterclockwise yields $\hat{v} = ( -y_n , x_n )$.
Explanation:
In two dimensions, counterclockwise rotation (this is the choice I made above) by angle $\varphi$ is described by matrix $\mathbf{R}$,
$$\mathbf{R} = \left [ \begin{array}{cc} \cos\varphi & -\sin\varphi \\ \sin\varphi & \cos\varphi \end{array} \right ]$$
so that the rotation of a vector $\vec{p} = ( x , y )$ by $\varphi$ yields $\vec{p}^{,}$:
$$\vec{p}^{,} = \mathbf{R}\vec{p} \iff \begin{cases}
x^{,} = x \cos(\varphi) - y \sin(\varphi) \\
y^{,} = x \sin(\varphi) + y \cos(\varphi) \end{cases}$$
Note that a common "bug" in first implementations is to not realize that you must use the old coordinates for the entire calculation; you cannot do say $x$ first, and use the new $x^{,}$ when calculating $y^{,}$.
In our current particular situation, $\varphi = 90°$, and therefore
$$\mathbf{R} = \left [ \begin{array}{cc} 0 & -1 \\ 1 & 0 \end{array} \right ]$$
or, in coordinate form, $$\begin{cases} x^{,} = x 0 - y 1 = - y\\ y^{,} = x 1 + y 0 = x \end{cases}$$
Step 3.
Move the line segment along the rotated unit vector $\hat{v} = ( -y_n , x_n )$ by the desired distance $d$.
If we use $\vec{p}_3 = ( x_3 , y_3 )$ and $\vec{p}_4 = ( x_4 , y_4 )$ for the translated line segment endpoints $\vec{p}_1$ and $\vec{p}_2$, respectively, then
$$\begin{cases} \vec{p}_3 = \vec{p}_1 + d \hat{v} \\
\vec{p}_4 = \vec{p}_2 + d \hat{v} \end{cases} \tag{2}\label{NA2}$$
Summary:
In coordinate form, and summarizing all you need to calculate to do this programmatically:
$$\begin{array}{l}
r = \sqrt{ (x_2 - x_1)^2 + (y_2 - y_1)^2 } \\
x_\Delta = \frac{d}{r} ( y_1 - y_2 ) \\
y_\Delta = \frac{d}{r} ( x_2 - x_1 ) \\
x_3 = x_1 + x_\Delta \\
y_3 = y_1 + y_\Delta \\
x_4 = x_2 + x_\Delta \\
y_4 = y_2 + y_\Delta \end{array}\tag{3}\label{NA3}$$
with the translated line segment being from $( x_3 , y_3 )$ to $( x_4 , y_4 )$.