Skip to content
Snippets Groups Projects
Commit 946dc236 authored by Andrew Maclean's avatar Andrew Maclean Committed by GitHub
Browse files

Merge pull request #398 from chakravarthi589/Update_TextActor

Update text actor
parents 9622cbbc 434cc97b
No related branches found
No related tags found
No related merge requests found
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import vtk.vtkNativeLibrary;
import vtk.vtkPanel;
import vtk.vtkRenderWindow;
import vtk.vtkRenderWindowInteractor;
import vtk.vtkRenderer;
import vtk.vtkTextActor;
import vtk.vtkNamedColors;
public class TextActor extends JPanel implements ActionListener {
private static final long serialVersionUID = 1L;
private vtkPanel renWin;
private JButton exitButton;
// -----------------------------------------------------------------
public class TextActor
{
//-----------------------------------------------------------------
// Load VTK library and print which library was not properly loaded
static {
if (!vtkNativeLibrary.LoadAllNativeLibraries()) {
for (vtkNativeLibrary lib : vtkNativeLibrary.values()) {
if (!lib.IsLoaded()) {
static
{
if (!vtkNativeLibrary.LoadAllNativeLibraries())
{
for (vtkNativeLibrary lib : vtkNativeLibrary.values())
{
if (!lib.IsLoaded())
{
System.out.println(lib.GetLibraryName() + " not loaded");
}
}
}
vtkNativeLibrary.DisableOutputWindow(null);
}
// -----------------------------------------------------------------
//-----------------------------------------------------------------
public TextActor() {
super(new BorderLayout());
public static void main(String s[])
{
vtkNamedColors Color = new vtkNamedColors();
//For Actor Color
double ActorColor[] = new double[4];
//For Renderer Background Color
double BgColor[] = new double[4];
double Bgcolor[] = new double[4];
//Change Color Name to Use your own Color for Change Actor Color
Color.GetColor("Red",ActorColor);
//Change Color Name to Use your own Color for Renderer Background
Color.GetColor("Black",BgColor);
Color.GetColor("Black",Bgcolor);
vtkTextActor Text = new vtkTextActor();
Text.SetInput("Hello World");
Text.SetDisplayPosition(20, 30);
......@@ -60,39 +49,22 @@ public class TextActor extends JPanel implements ActionListener {
Text.GetTextProperty().ShadowOn();
Text.GetTextProperty().GetShadowOffset();
Text.GetTextProperty().SetColor(ActorColor);
renWin = new vtkPanel();
renWin.GetRenderer().AddActor(Text);
renWin.resetCamera();
renWin.GetRenderer().SetBackground(BgColor);
// Add Java UI components
exitButton = new JButton("Exit");
exitButton.addActionListener(this);
add(renWin, BorderLayout.CENTER);
add(exitButton, BorderLayout.SOUTH);
}
// Create the renderer, render window and interactor.
vtkRenderer ren = new vtkRenderer();
vtkRenderWindow renWin = new vtkRenderWindow();
renWin.AddRenderer(ren);
vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
iren.SetRenderWindow(renWin);
/** An ActionListener that listens to the button. */
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(exitButton)) {
System.exit(0);
}
}
// Visualize the Actor
ren.AddActor(Text);
ren.SetBackground(Bgcolor);
public static void main(String s[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("Text Actor");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(new TextActor(), BorderLayout.CENTER);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
renWin.SetSize(300, 300);
renWin.Render();
iren.Initialize();
iren.Start();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment