//
// ResSwitcher.java
//
/*
VisAD system for interactive analysis and visualization of numerical
data. Copyright (C) 1996 - 2017 Bill Hibbard, Curtis Rueden, Tom
Rink, Dave Glowacki, Steve Emmerson, Tom Whittaker, Don Murray, and
Tommy Jasmin.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA
*/
package visad.util;
import java.awt.event.*;
import javax.swing.*;
import java.rmi.RemoteException;
import java.util.Vector;
import visad.*;
import visad.data.DefaultFamily;
import visad.java3d.DisplayImplJ3D;
/**
* Handles automatic toggling between a high-resolution representation
* and a low-resolution one for a data object. When the display is
* busy, the low-resolution representation is used for faster response
* time. When the display is idle, the high-resolution representation
* is used for greater detail.
*/
public class ResSwitcher extends DualRes implements ActivityHandler {
/** Display affected by resolution switcher. */
private LocalDisplay display;
/** High-resolution data renderer toggled by resolution switcher. */
private DataRenderer hi_rend;
/** Low-resolution data renderer toggled by resolution switcher. */
private DataRenderer lo_rend;
/**
* Constructs a resolution switcher for swapping between high- and low-
* resolution representations for the referenced data on the given display.
*/
public ResSwitcher(LocalDisplay d, DataReferenceImpl ref)
throws VisADException, RemoteException
{
this(d, ref, null, null);
}
/**
* Constructs a resolution switcher for swapping between high- and low-
* resolution representations for the referenced data on the given display.
*
* @param renderer The data renderer to be used for the low-res rendering.
* @param cmaps The ConstantMaps to be used for the low-res rendering.
*/
public ResSwitcher(LocalDisplay d, DataReferenceImpl ref,
DataRenderer renderer, ConstantMap[] cmaps)
throws VisADException, RemoteException
{
super(ref);
display = d;
if (renderer == null) display.addReference(lo_ref, cmaps);
else display.addReferences(renderer, lo_ref, cmaps);
// get data renderers
Vector dataRenderers = display.getRendererVector();
int len = dataRenderers == null ? 0 : dataRenderers.size();
int flags = 0;
for (int i=0; i 1) {
try { rs.setResolutionScale(Double.parseDouble(args[1])); }
catch (NumberFormatException exc) { }
}
JFrame frame = new JFrame("ResSwitcher test");
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
p.setAlignmentY(JPanel.TOP_ALIGNMENT);
p.setAlignmentX(JPanel.LEFT_ALIGNMENT);
frame.setContentPane(p);
p.add(display.getComponent());
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.pack();
frame.show();
}
}
Ads help maintain this website.