Class TopcatUtils
java.lang.Object
uk.ac.starlink.topcat.TopcatUtils
Class containing miscellaneous static methods and constants
for use in TOPCAT.
- Since:
- 19 Aug 2004
- Author:
- Mark Taylor
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final uk.ac.starlink.table.ValueInfoColumn auxiliary metadata key identifying the uniqe column identifier for use in algebraic expressions.static Stringstatic Stringstatic Stringstatic final uk.ac.starlink.table.ValueInfoColumn auxiliary metadata key identifying the text string which gives an expression for a synthetic column.static final uk.ac.starlink.table.ValueInfoColumn auxiliary metadata key identifying an object which can convert from non-numeric cell values to numeric ones.static final Stringstatic final uk.ac.starlink.table.ValueInfoData identifier for epoch-type data.static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddSubset(JComponent parent, TopcatModel tcModel, BitSet matchMask, String dfltName, String[] msgLines, String title) Using input from the user, adds a new (or reused) Row Subset to the given TopcatModel based on a given BitSet.static voidalignComponents(JComponent[] comps) Reshapes a set of components so that they all have the same preferred size (that of the largest one).static booleancanJel()Indicates if it's possible to use JEL to compile algebraic expressions.static TopcatModeldecodeSession(uk.ac.starlink.table.StarTable table, String location, ControlWindow controlWindow) Attempts to unpack a StarTable into a TopcatModel containing per-table application session information.static uk.ac.starlink.table.StarTableencodeSession(TopcatModel tcModel, boolean withGlobals) Encodes a TopcatModel as a StarTable including per-table session information, suitable for serialization.static voidAscertains the most recent release using an external connection, and reports through the logging system as appropriate.static voidensureRowIndexIsVisible(JTable jtab, int irow) Scrolls a JTable as necessary to ensure that a given row index is scrolled to the visible part of the viewport.static booleanDetermines whether two objects are equal in the sense ofObject.equals(Object).static StringformatLong(long num) Formats a long value for presentation as text.static String[]getAbout()Returns some lines of text describing this copy of the software including its version and versions of some important components.static StringReturns the name of this application.static StringgetBaseName(String origName, String baseSuffix) Returns the base name of a column; that is one without any suffix based onbaseSuffix.static DesktopReturns a browse-capable desktop instance, or null if none is available.static StringgetDistinctName(ColumnList colList, String origName, String baseSuffix) Returns a column name based on a given one which is guaranteed distinct from any others in the column list.Returns an object that will take documentation-type URLs and display them somehow, probably in an external browser window.static StringgetExpression(uk.ac.starlink.table.ColumnInfo info) Returns the expression text for a column.static StringReturns the version control revision number for TOPCAT and its dependencies.static List<uk.ac.starlink.table.DescribedValue> getRowAsParameters(TopcatModel tcModel, long lrow) Returns the values from a row of a given table as a list of DescribedValues, suitable for use as parameters (per-value metadata) of a StarTable.static uk.ac.starlink.table.StarTablegetSaveTable(TopcatModel tcModel) Returns the table represented by the current state of a given TopcatModel in a form suitable for persisting into one of the known serialization formats.static StringReturns the version string for the version of STIL being used here.static StringReturns the version string for this copy of TOPCAT.static StringidentityString(Object obj) Returns a string unique to an object's identity.static booleanisComponentVisible(JComponent component) Indicates whether the given component is currently visible.static booleanisWindowVisible(JFrame window) Indicates whether the given window is currently visible.static voidAlerts the user that the system has run out of memory, and provides the option of some useful tips.static voidQueues amemoryError(OutOfMemoryError)call for later execution on the event dispatch thread.static booleansetAboutHandler(Runnable doAbout) Invokes the java.awt.Desktop.setAboutHandler method.static voidsetClipboardText(String txt) Sets the text content of the system clipboard(s).static voidDisplays an informational About TOPCAT window.
-
Field Details
-
DEMO_LOCATION
-
DEMO_TABLE
-
DEMO_NODES
-
VERSION_RESOURCE
- See Also:
-
STATUS_URL
- See Also:
-
COLID_INFO
public static final uk.ac.starlink.table.ValueInfo COLID_INFOColumn auxiliary metadata key identifying the uniqe column identifier for use in algebraic expressions. -
EXPR_INFO
public static final uk.ac.starlink.table.ValueInfo EXPR_INFOColumn auxiliary metadata key identifying the text string which gives an expression for a synthetic column. -
NUMERIC_CONVERTER_INFO
public static final uk.ac.starlink.table.ValueInfo NUMERIC_CONVERTER_INFOColumn auxiliary metadata key identifying an object which can convert from non-numeric cell values to numeric ones. -
TIME_INFO
public static final uk.ac.starlink.table.ValueInfo TIME_INFOData identifier for epoch-type data.
-
-
Constructor Details
-
TopcatUtils
public TopcatUtils()
-
-
Method Details
-
getSaveTable
Returns the table represented by the current state of a given TopcatModel in a form suitable for persisting into one of the known serialization formats.This basicaly uses
TopcatModel.getApparentStarTable(), but may apply a few extra tweaks for a table that is known to be about to be saved.- Parameters:
tcModel- topcat model- Returns:
- saveable table
-
getExpression
Returns the expression text for a column. This should only have a non-null value for synthetic columns.- Parameters:
info- column info- Returns:
- synthetic expression string
-
getBaseName
Returns the base name of a column; that is one without any suffix based onbaseSuffix. This method is used in conjunction withgetDistinctName(ColumnList, String, String).- Parameters:
origName- full name, possibly including bits of suffixbaseSuffix- the base suffix string- Returns:
- name without any suffix-like elements of the sort
specified by
baseSuffix
-
getDistinctName
Returns a column name based on a given one which is guaranteed distinct from any others in the column list. If the submittedorigNameis already unique, it may be returned. Otherwise a new name may be made which involves appending the givenbaseSuffixto it.- Parameters:
colList- column list within which distinct naming is requiredorigName- initial namebaseSuffix- suffix used for deduplication- Returns:
- a name resembling
origNamewhich is not the same as any existing column names incolList - See Also:
-
getApplicationName
-
getAbout
Returns some lines of text describing this copy of the software including its version and versions of some important components.- Returns:
- lines of About text
-
getDocUrlHandler
-
getRowAsParameters
public static List<uk.ac.starlink.table.DescribedValue> getRowAsParameters(TopcatModel tcModel, long lrow) Returns the values from a row of a given table as a list of DescribedValues, suitable for use as parameters (per-value metadata) of a StarTable.- Parameters:
tcModel- table supplying valueslrow- row index- Returns:
- list of described values
-
setClipboardText
Sets the text content of the system clipboard(s). This is somewhat OS-dependent. X11 uses a PRIMARY selection (middle mouse button) alongside the CLIPBOARD selection (explicit cut'n'paste). JTextComponents fill both, though not under exactly the same circumstances. This method sets the text for both if both are available. This may not replicate exactly the behaviour expected by X clients, but I think it's what users would want to happen. I may be wrong.- Parameters:
txt- text to set as clipboard contents
-
ensureRowIndexIsVisible
Scrolls a JTable as necessary to ensure that a given row index is scrolled to the visible part of the viewport.- Parameters:
jtab- JTableirow- table index that must be visible- See Also:
-
memoryError
Alerts the user that the system has run out of memory, and provides the option of some useful tips.- Parameters:
e- exception, or null
-
memoryErrorLater
Queues amemoryError(OutOfMemoryError)call for later execution on the event dispatch thread.- Parameters:
e- exception, or null
-
canJel
public static boolean canJel()Indicates if it's possible to use JEL to compile algebraic expressions.This used to query the SecurityManager, but the
java.lang.SecurityManagerclass is deprecated for removal in later JREs, and I don't think it's likely that expression compilation will be blocked. So this method currently returns true unconditionally, but retain it in case it turns out there are circumstances we can test for that bear on this.- Returns:
- true iff JEL epxression compilation is expected to work
-
getBrowserDesktop
Returns a browse-capable desktop instance, or null if none is available.- Returns:
- desktop
-
getVersion
Returns the version string for this copy of TOPCAT.- Returns:
- version number only
-
getRevision
Returns the version control revision number for TOPCAT and its dependencies.- Returns:
- revision identifier
-
getSTILVersion
Returns the version string for the version of STIL being used here.- Returns:
- STIL version number
-
enquireLatestVersion
public static void enquireLatestVersion()Ascertains the most recent release using an external connection, and reports through the logging system as appropriate. -
equals
Determines whether two objects are equal in the sense ofObject.equals(Object). Unlike that method however, it returns true if both objects arenull, and won't throw a NullPointerException.- Parameters:
o1- first objecto2- second object- Returns:
- true if
o1.equals(o2)or they're both null
-
identityString
-
formatLong
Formats a long value for presentation as text. This typically puts separators between groups of three numbers for improved visibility. TOPCAT policy is usually to do this only for numbers which are, or might be expected to be, quite large.- Parameters:
num- number to format- Returns:
- formatted value
-
alignComponents
Reshapes a set of components so that they all have the same preferred size (that of the largest one).- Parameters:
comps- components to align
-
isWindowVisible
Indicates whether the given window is currently visible. If it's disposed or iconified, this will return false. It can't detect whether it's hidden behind other windows though.- Parameters:
window- window to test- Returns:
- true if the window is potentially visible to the user
-
isComponentVisible
Indicates whether the given component is currently visible. If its window is disposed or iconified, this will return false. It can't detect whether it's hidden behind other windows though.- Parameters:
component- component to test- Returns:
- true if the component is potentially visible to the user
-
showAbout
Displays an informational About TOPCAT window.- Parameters:
parent- parent component
-
setAboutHandler
Invokes the java.awt.Desktop.setAboutHandler method. Since that method was introduced at Java 9, and at time of writing the build and minimal target deployment platform is Java 8, this is done by reflection, and hence will only do useful work in a runtime environment of >=9. This method only does useful work anyway on certain platforms, notably MacOS, for which an About button is part of the standard application GUI. If for whatever reason the assignment doesn't work, it fails silently.If the target platform is upgraded one day to Java >= 9, this reflective code can be eliminated or replaced by something very much simpler.
- Parameters:
doAbout- callback to display an About Application window- Returns:
- true iff the handler installation apparently succeeded
-
addSubset
public static void addSubset(JComponent parent, TopcatModel tcModel, BitSet matchMask, String dfltName, String[] msgLines, String title) Using input from the user, adds a new (or reused) Row Subset to the given TopcatModel based on a given BitSet.- Parameters:
parent- parent component for dialoguetcModel- topcat modelmatchMask- mask for included rowsdfltName- default name for subsetmsgLines- lines of text to appear in dialogue windowtitle- dialogue window title
-
encodeSession
public static uk.ac.starlink.table.StarTable encodeSession(TopcatModel tcModel, boolean withGlobals) Encodes a TopcatModel as a StarTable including per-table session information, suitable for serialization. Optionally, the output table may include global information associated with the state of the application as a whole alongside state specific to the provided TopcatModel.- Parameters:
tcModel- modelwithGlobals- if true, include global state in the output- Returns:
- table
-
decodeSession
public static TopcatModel decodeSession(uk.ac.starlink.table.StarTable table, String location, ControlWindow controlWindow) Attempts to unpack a StarTable into a TopcatModel containing per-table application session information. For this to work it must have been written using one of the TopcatCodec formats that this application is aware of. If not, null is returned.- Parameters:
table- encoded tablelocation- table location stringcontrolWindow- control window, or null if necessary- Returns:
- topcat model, or null
-