Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ttools: ConfigException is now checked, not unchecked
Reparent ConfigException to inherit from Exception not RuntimeException. It's really necessary to have it as a checked exception to make it clear when you have to handle it. It was only unchecked before because I was in a tearing hurry when I put did it in the first place. Added some code in topcat to behave sensibly when such an exception is caught, but this is not much tested so far; currently these are not often thrown.
- Loading branch information
Showing
23 changed files
with
151 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
topcat/src/main/uk/ac/starlink/topcat/plot2/ConfigStyler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package uk.ac.starlink.topcat.plot2; | ||
|
||
import java.awt.Component; | ||
import javax.swing.JOptionPane; | ||
import uk.ac.starlink.ttools.plot.Style; | ||
import uk.ac.starlink.ttools.plot2.DataGeom; | ||
import uk.ac.starlink.ttools.plot2.PlotLayer; | ||
import uk.ac.starlink.ttools.plot2.Plotter; | ||
import uk.ac.starlink.ttools.plot2.config.ConfigException; | ||
import uk.ac.starlink.ttools.plot2.config.ConfigMap; | ||
import uk.ac.starlink.ttools.plot2.data.DataSpec; | ||
|
||
/** | ||
* Manages creation of PlotLayers from Plotters by turning ConfigMaps into | ||
* appropriate Style instances. | ||
* This would be just a case of calling the relevant Plotter method, | ||
* except that method can throw a ConfigException, and we have to manage | ||
* behaviour in the case that that happens. | ||
* | ||
* This is currently done by popping up a dialogue window the first time the | ||
* error occurs. | ||
* | ||
* @author Mark Taylor | ||
* @since 25 Feb 2015 | ||
*/ | ||
public class ConfigStyler { | ||
|
||
private final Component parent_; | ||
private boolean lastFailed_; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param parent parent component for dialogue windows | ||
*/ | ||
public ConfigStyler( Component parent ) { | ||
parent_ = parent; | ||
} | ||
|
||
/** | ||
* Creates a new layer from a plotter. | ||
* | ||
* @param plotter plotter | ||
* @param geom data geom | ||
* @param dataSpec data spec | ||
* @param config style configuration | ||
* @return layer, or null in case of failure | ||
*/ | ||
public <S extends Style> PlotLayer createLayer( Plotter<S> plotter, | ||
DataGeom geom, | ||
DataSpec dataSpec, | ||
ConfigMap config ) { | ||
S style; | ||
try { | ||
style = plotter.createStyle( config ); | ||
lastFailed_ = false; | ||
} | ||
catch ( ConfigException e ) { | ||
if ( ! lastFailed_ ) { | ||
String name = e.getConfigKey().getMeta().getLongName(); | ||
String[] msg = new String[] { name + ": ", e.getMessage() }; | ||
JOptionPane.showMessageDialog( parent_, msg, name + " Error", | ||
JOptionPane.ERROR_MESSAGE ); | ||
lastFailed_ = true; | ||
} | ||
return null; | ||
} | ||
try { | ||
S dupStyle = plotter.createStyle( config ); | ||
assert style.equals( dupStyle ); | ||
assert style.hashCode() == dupStyle.hashCode(); | ||
} | ||
catch ( ConfigException e ) { | ||
assert false : "Shouldn't happen"; | ||
} | ||
return plotter.createLayer( geom, dataSpec, style ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.