Skip to content

Commit

Permalink
topcat: added a little plus sign to control action icons
Browse files Browse the repository at this point in the history
Plot2 actions which add items to a stack of controls now have a little
plus sign added to their action icons.  Also reword the names and
descriptions slightly.  This (hopefully) makes it clearer what those
actions are there for.
  • Loading branch information
mbtaylor authored and mmpcn committed Nov 27, 2014
1 parent aacd5c8 commit 550801e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
38 changes: 38 additions & 0 deletions topcat/src/main/uk/ac/starlink/topcat/ResourceIcon.java
Expand Up @@ -5,6 +5,7 @@
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -244,6 +245,7 @@ public class ResourceIcon implements Icon {
NAV_HELP = makeIcon( "navhelp.gif" ),
NAV_DEC = makeIcon( "navdec1.gif" ),
SMALL_CLOSE = makeIcon( "x9.gif" ),
ADD_CONTROL = makeIcon( "addlayer4.png" ),

/* Datanode (hierarchy browser) icons. */
COLLAPSED = makeIcon( "handle1.gif" ),
Expand Down Expand Up @@ -373,6 +375,42 @@ private Icon readBaseIcon() {
return icon;
}

/**
* Paints a stack of icons on top of each other and returns the result.
* Later elements obscure earlier ones
*
* @param icons icon array
* @return combination
*/
public static ImageIcon combineIcons( Icon[] icons ) {
int width = 0;
int height = 0;
for ( int i = 0; i < icons.length; i++ ) {
width = Math.max( width, icons[ i ].getIconWidth() );
height = Math.max( height, icons[ i ].getIconHeight() );
}
BufferedImage image =
new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB );
Component c = null;
Graphics g = image.createGraphics();
for ( int i = 0; i < icons.length; i++ ) {
icons[ i ].paintIcon( c, g, 0, 0 );
}
g.dispose();
return new ImageIcon( image );
}

/**
* Doctors an icon representing a control to look like it means adding
* that control. Currently, it puts a little plus sign in the corner.
*
* @param baseIcon standard sized (24x24) base icon
* @return doctored icon
*/
public static ImageIcon toAddIcon( Icon baseIcon ) {
return combineIcons( new Icon[] { baseIcon, ADD_CONTROL } );
}

/**
* Returns a full-size TOPCAT logo for display.
*
Expand Down
Expand Up @@ -96,7 +96,7 @@ public GangControlManager( ControlStack stack, PlotType plotType,
if ( ! plotterMap_.get( 1 ).isEmpty() ) {
final Icon icon1 = ResourceIcon.PLOT_DATA;
stackActList.add( new LayerControlAction(
"Add Position Plot", icon1,
"Add Position Control", icon1,
"Add a new positional plot control"
+ " to the stack", stack_ ) {
public LayerControl createLayerControl() {
Expand All @@ -109,7 +109,7 @@ public LayerControl createLayerControl() {
if ( ! plotterMap_.get( 2 ).isEmpty() ) {
final Icon icon2 = ResourceIcon.PLOT_PAIR;
stackActList.add( new LayerControlAction(
"Add Pair Plot", icon2,
"Add Pair Control", icon2,
"Add a new pair position plot control"
+ " to the stack", stack_ ) {
public LayerControl createLayerControl() {
Expand Down
Expand Up @@ -4,6 +4,7 @@
import javax.swing.Action;
import javax.swing.Icon;
import uk.ac.starlink.topcat.BasicAction;
import uk.ac.starlink.topcat.ResourceIcon;
import uk.ac.starlink.topcat.TopcatListener;
import uk.ac.starlink.ttools.plot2.Plotter;
import uk.ac.starlink.ttools.plot2.data.CoordGroup;
Expand All @@ -25,13 +26,15 @@ public abstract class LayerControlAction extends BasicAction {
* Constructs a LayerControlAction from name, icon and description.
*
* @param name action name
* @param icon action icon
* @param layerIcon icon representing the type of layer the action
* will add; it may get doctored to generate the
* icon for this action
* @param descrip action description
* @param stack plot stack
*/
public LayerControlAction( String name, Icon icon, String descrip,
public LayerControlAction( String name, Icon layerIcon, String descrip,
ControlStack stack ) {
super( name, icon, descrip );
super( name, ResourceIcon.toAddIcon( layerIcon ), descrip );
stack_ = stack;
}

Expand All @@ -42,7 +45,7 @@ public LayerControlAction( String name, Icon icon, String descrip,
* @param stack plot stack
*/
public LayerControlAction( Plotter plotter, ControlStack stack ) {
this( "Add " + plotter.getPlotterName() + " Layer",
this( "Add " + plotter.getPlotterName() + " Control",
plotter.getPlotterIcon(),
"Add a new " + plotter.getPlotterName().toLowerCase()
+ " layer control to the stack",
Expand Down
Expand Up @@ -16,6 +16,7 @@
import javax.swing.JToolBar;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import uk.ac.starlink.topcat.ResourceIcon;
import uk.ac.starlink.topcat.TopcatListener;
import uk.ac.starlink.ttools.plot2.Plotter;
import uk.ac.starlink.ttools.plot2.config.ConfigKey;
Expand Down Expand Up @@ -278,7 +279,8 @@ private class SingleFormAction extends AbstractAction {
* @param plotter object that generates plot layers
*/
public SingleFormAction( Plotter plotter ) {
super( plotter.getPlotterName(), plotter.getPlotterIcon() );
super( plotter.getPlotterName(),
ResourceIcon.toAddIcon( plotter.getPlotterIcon() ) );
putValue( SHORT_DESCRIPTION,
"Add new " + plotter.getPlotterName() + " form" );
plotter_ = plotter;
Expand All @@ -304,7 +306,8 @@ private class ModeFormAction extends AbstractAction {
* @param form common form
*/
public ModeFormAction( ModePlotter[] plotters, ModePlotter.Form form ) {
super( form.getFormName(), form.getFormIcon() );
super( form.getFormName(),
ResourceIcon.toAddIcon( form.getFormIcon() ) );
putValue( SHORT_DESCRIPTION,
"Add new " + form.getFormName() + " form" );
plotters_ = plotters;
Expand Down
Expand Up @@ -343,7 +343,7 @@ public void modelChanged( TopcatEvent evt ) {

/* Action for deleting a control from the stack. */
Action removeAction =
stack_.createRemoveAction( "Remove Current Layer",
stack_.createRemoveAction( "Remove Current Control",
"Delete the current layer control"
+ " from the stack" );

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 550801e

Please sign in to comment.