KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > hyperlink > URLHyperlink


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jface.text.hyperlink;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.program.Program;
15
16 import org.eclipse.core.runtime.Assert;
17
18 import org.eclipse.jface.text.IRegion;
19
20
21 /**
22  * URL hyperlink.
23  *
24  * @since 3.1
25  */

26 public class URLHyperlink implements IHyperlink {
27
28     private String JavaDoc fURLString;
29     private IRegion fRegion;
30
31     /**
32      * Creates a new URL hyperlink.
33      *
34      * @param region
35      * @param urlString
36      */

37     public URLHyperlink(IRegion region, String JavaDoc urlString) {
38         Assert.isNotNull(urlString);
39         Assert.isNotNull(region);
40
41         fRegion= region;
42         fURLString= urlString;
43     }
44
45     /*
46      * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getHyperlinkRegion()
47      */

48     public IRegion getHyperlinkRegion() {
49         return fRegion;
50     }
51
52     /*
53      * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#open()
54      */

55     public void open() {
56         if (fURLString != null) {
57             String JavaDoc platform= SWT.getPlatform();
58             if ("motif".equals(platform) || "gtk".equals(platform)) { //$NON-NLS-1$ //$NON-NLS-2$
59
Program program= Program.findProgram("html"); //$NON-NLS-1$
60
if (program == null)
61                     program= Program.findProgram("htm"); //$NON-NLS-1$
62
if (program != null)
63                     program.execute(fURLString);
64             } else
65                 Program.launch(fURLString);
66             fURLString= null;
67             return;
68         }
69     }
70
71     /*
72      * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getTypeLabel()
73      */

74     public String JavaDoc getTypeLabel() {
75         return null;
76     }
77
78     /*
79      * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getHyperlinkText()
80      */

81     public String JavaDoc getHyperlinkText() {
82         return null;
83     }
84     
85     /**
86      * Returns the URL string of this hyperlink.
87      *
88      * @return the URL string
89      * @since 3.2
90      */

91     public String JavaDoc getURLString() {
92         return fURLString;
93     }
94
95 }
96
Popular Tags