-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
topcat: refactor CoordPanel/PositionCoordPanel
PositionCoordPanel was an interface with a wrapper implementation rather than an extension of the CoordPanel class, which was silly. Made it sensible; less jumping through hoops required.
- Loading branch information
Showing
8 changed files
with
130 additions
and
205 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
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
109 changes: 74 additions & 35 deletions
109
topcat/src/main/uk/ac/starlink/topcat/plot2/PositionCoordPanel.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 |
---|---|---|
@@ -1,65 +1,104 @@ | ||
package uk.ac.starlink.topcat.plot2; | ||
|
||
import java.awt.event.ActionListener; | ||
import javax.swing.JComponent; | ||
import uk.ac.starlink.topcat.TopcatModel; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import uk.ac.starlink.table.DefaultValueInfo; | ||
import uk.ac.starlink.table.DomainMapper; | ||
import uk.ac.starlink.table.ValueInfo; | ||
import uk.ac.starlink.ttools.plot2.DataGeom; | ||
import uk.ac.starlink.ttools.plot2.data.Coord; | ||
import uk.ac.starlink.ttools.plot2.data.StorageType; | ||
|
||
/** | ||
* GUI component for obtaining data position coordinates. | ||
* | ||
* @author Mark Taylor | ||
* @since 13 Mar 2013 | ||
*/ | ||
public interface PositionCoordPanel { | ||
public abstract class PositionCoordPanel extends CoordPanel { | ||
|
||
/** | ||
* Returns the graphical component for user interaction. | ||
* Constructor. | ||
* | ||
* @return component | ||
* @param coords coordinate definitions for which values are required | ||
* @param autoPopulate if true, some attempt will be made to | ||
* fill in the fields with non-blank values | ||
* when a table is selected | ||
*/ | ||
JComponent getComponent(); | ||
|
||
/** | ||
* Sets the table with reference to which this panel will resolve | ||
* coordinate descriptions. | ||
* | ||
* @param tcModel table from which coordinate values will be drawn | ||
*/ | ||
void setTable( TopcatModel tcModel ); | ||
|
||
/** | ||
* Returns the coordinate values currently selected in this panel. | ||
* If there is insufficient information to contribute to a plot | ||
* (not all of the | ||
* {@link uk.ac.starlink.ttools.plot2.data.Coord#isRequired required} | ||
* coord values are filled in) | ||
* then null will be returned. | ||
* | ||
* @return nCoord-element array of coord contents, or null | ||
*/ | ||
GuiCoordContent[] getContents(); | ||
protected PositionCoordPanel( Coord[] coords, boolean autoPopulate ) { | ||
super( coords, autoPopulate ); | ||
} | ||
|
||
/** | ||
* Returns the position geometry that defines the mapping of input | ||
* to data coordinates. | ||
* | ||
* @return data geom | ||
*/ | ||
DataGeom getDataGeom(); | ||
public abstract DataGeom getDataGeom(); | ||
|
||
/** | ||
* Adds a listener which will be notified when the coordinate selection | ||
* changes. | ||
* Returns a list of coordinates which is like multiple copies of a | ||
* supplied group. The returned coords have metadata which | ||
* distinguish them from each other, currently an integer appended | ||
* to their name. The returned coords are not totally respectable, | ||
* but their metadata is OK. | ||
* | ||
* @param listener listener | ||
* @param coords basic coordinates | ||
* @param ncopy number of copies to make | ||
* @return array of ncopy copies of coords | ||
*/ | ||
void addActionListener( ActionListener listener ); | ||
public static Coord[] multiplyCoords( Coord[] coords, int ncopy ) { | ||
List<Coord> coordList = new ArrayList<Coord>(); | ||
for ( int ig = 0; ig < ncopy; ig++ ) { | ||
for ( int ic = 0; ic < coords.length; ic++ ) { | ||
Coord coord = coords[ ic ]; | ||
coordList.add( ncopy == 1 ? coord : relabel( coord, ig ) ); | ||
} | ||
} | ||
return coordList.toArray( new Coord[ 0 ] ); | ||
} | ||
|
||
/** | ||
* Removes a listener which was added previously. | ||
* Returns a Coord like a given one but with modified metadata. | ||
* | ||
* <p>The returned Coord is not of the right subclass, hence does not | ||
* have the appropriate type-specific read*Coord method. | ||
* However that doesn't matter, because we're just using the results | ||
* from this call to represent coordinate metadata, not for reading data. | ||
* | ||
* @param listener listener | ||
* @param baseCoord coord on which to base the copy | ||
* @param iPoint point index, used to label the coordinate | ||
* @return new coord like the input one | ||
*/ | ||
void removeActionListener( ActionListener listener ); | ||
private static Coord relabel( final Coord baseCoord, int iPoint ) { | ||
String iptxt = Integer.toString( iPoint + 1 ); | ||
final ValueInfo[] infos = baseCoord.getUserInfos().clone(); | ||
int nuc = infos.length; | ||
for ( int iuc = 0; iuc < nuc; iuc++ ) { | ||
DefaultValueInfo info = new DefaultValueInfo( infos[ iuc ] ); | ||
info.setName( info.getName() + iptxt ); | ||
info.setDescription( info.getDescription() | ||
+ " for point " + iptxt ); | ||
infos[ iuc ] = info; | ||
} | ||
return new Coord() { | ||
public ValueInfo[] getUserInfos() { | ||
return infos; | ||
} | ||
public boolean isRequired() { | ||
return true; | ||
} | ||
public StorageType getStorageType() { | ||
return baseCoord.getStorageType(); | ||
} | ||
public List<Class<? extends DomainMapper>> getUserDomains() { | ||
return baseCoord.getUserDomains(); | ||
} | ||
public Object userToStorage( Object[] userCoords, | ||
DomainMapper[] userMappers ) { | ||
return baseCoord.userToStorage( userCoords, userMappers ); | ||
} | ||
}; | ||
} | ||
} |
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.