/** * Add a column to this schema. * @param name the column name * @param type the column type (as a Class instance) * @param defaultValue the column default value * @return the number of columns in the schema */ public int addColumn(String name, Class<?> type, Object defaultValue) { try { this.schema.addColumn(name, type, defaultValue); return this.getColumnCount(); } catch (IllegalStateException e) { prefuse.data.Schema schemaBis = new prefuse.data.Schema(0); for (int i = 0; i < schema.getColumnCount(); i++) { schemaBis.addColumn(schema.getColumnName(i), schema.getColumnType(i), schema.getDefault(i)); } schemaBis.addColumn(name, type, defaultValue); this.schema = schemaBis; return schemaBis.getColumnCount(); } catch (Exception e) { throw new ObviousRuntimeException(e); } }
/** * Indicates if values from a given Schema can be safely assigned to * data using this Schema. The input Schema must be less than or * equal in length to this Schema, and all contained columns in the * given Schema must have matching names and types to this Schema. * This method does not consider default values settings or the * locked status of the Schemas. For example, if the given Schema * has different default values than this one, this will have no * impact on the assignability of the two. * @param s the input Schema * @return true if data models using this Schema could be assigned values * directly from data using the input Schema, false otherwise. */ public boolean isAssignableFrom(Schema s) { int ssize = s.getColumnCount(); if ( ssize > m_size ) return false; for ( int i=0; i<ssize; ++i ) { int idx = getColumnIndex(s.getColumnName(i)); if ( idx < 0 ) return false; if ( !m_types[idx].equals(s.getColumnType(i)) ) return false; } return true; }
/** * Set the default value for the given field as a boolean. * @param field the name of column to set the default for * @param val the new default value */ public void setDefault(String field, boolean val) { setDefault(field, val ? Boolean.TRUE : Boolean.FALSE); }
@Override public void addColumns(Schema arg0) { for (int i = 0; i < arg0.getColumnCount(); i++) { this.addColumn(arg0.getColumnName(i), arg0.getColumnType(i), arg0.getDefault(i)); } }
Schema s = new Schema(); s.addColumn(VisualItem.VALIDATED, boolean.class, Boolean.FALSE); s.addColumn(VisualItem.VISIBLE, boolean.class, Boolean.TRUE); s.addColumn(VisualItem.STARTVISIBLE, boolean.class, Boolean.FALSE); s.addColumn(VisualItem.ENDVISIBLE, boolean.class, Boolean.TRUE); s.addColumn(VisualItem.INTERACTIVE, boolean.class, Boolean.TRUE); s.addColumn(VisualItem.EXPANDED, boolean.class, Boolean.TRUE); s.addColumn(VisualItem.FIXED, boolean.class, Boolean.FALSE); s.addColumn(VisualItem.HIGHLIGHT, boolean.class, Boolean.FALSE); s.addColumn(VisualItem.HOVER, boolean.class, Boolean.FALSE); s.addInterpolatedColumn(VisualItem.X, double.class); s.addInterpolatedColumn(VisualItem.Y, double.class); s.addColumn(VisualItem.BOUNDS, Rectangle2D.class, new Rectangle2D.Double()); s.addInterpolatedColumn(VisualItem.STROKECOLOR, int.class, defStroke); s.addInterpolatedColumn(VisualItem.FILLCOLOR, int.class, defFill); s.addInterpolatedColumn(VisualItem.TEXTCOLOR, int.class, defTextColor); s.addInterpolatedColumn(VisualItem.SIZE, double.class, new Double(1)); s.addColumn(VisualItem.SHAPE, int.class, new Integer(Constants.SHAPE_RECTANGLE)); s.addColumn(VisualItem.STROKE, Stroke.class, new BasicStroke());
/** * Returns this Table's schema. The returned schema will be * locked, which means that any attempts to edit the returned schema * by adding additional columns will result in a runtime exception. * * If this Table subsequently has columns added or removed, this will not * be reflected in the returned schema. Instead, this method will need to * be called again to get a current schema. Accordingly, it is not * recommended that Schema instances returned by this method be stored * or reused across scopes unless that exact schema snapshot is * desired. * * @return a copy of this Table's schema */ public Schema getSchema() { if ( m_schema == null ) { Schema s = new Schema(); for ( int i=0; i<getColumnCount(); ++i ) { s.addColumn(getColumnName(i), getColumnType(i), getColumn(i).getDefaultValue()); } s.lockSchema(); m_schema = s; } return m_schema; }
/** * Get the VisualItem Schema used for axis tick marks and labels. Extends * the VisualItem Schema with an additional end-point coordinate, a * String label field, and numeric value field for storing the value * which the axis label corresponds to. * @return the Schema for axis tick marks and labels. */ public static Schema getAxisLabelSchema() { Schema s = getVisualItemSchema(); s.setDefault(VisualItem.STARTVISIBLE, Boolean.FALSE); Integer defColor = new Integer(ColorLib.gray(230)); s.setInterpolatedDefault(VisualItem.STROKECOLOR, defColor); defColor = new Integer(ColorLib.gray(150)); s.setInterpolatedDefault(VisualItem.TEXTCOLOR, defColor); Double nan = new Double(Double.NaN); s.addInterpolatedColumn(VisualItem.X2, double.class); s.addInterpolatedColumn(VisualItem.Y2, double.class); s.addColumn(VisualItem.LABEL, String.class); s.addColumn(VisualItem.VALUE, double.class, nan); return s; }
/** * Add a column to this schema. * @param name the column name * @param type the column type (as a Class instance) * @throws IllegalArgumentException is either name or type are null or * the name already exists in this schema. */ public void addColumn(String name, Class type) { addColumn(name, type, null); }
/** * Returns an obvious node corresponding to a prefuse node. * @param node prefuse node * @return an obvious node */ private obvious.data.Node getObviousNode(Node node) { Object[] values = new Object[node.getSchema().getColumnCount()]; for (int i = 0; i < node.getSchema().getColumnCount(); i++) { values[i] = node.get(node.getSchema().getColumnName(i)); } return new NodeImpl(nodeSchema, values); }
String[] vals = new String[2]; for ( int i=0; i<ns.getColumnCount(); ++i ) { vals[0] = ns.getColumnName(i); vals[1] = (String)TYPES.get(ns.getColumnType(i)); xml.tag(Tokens.DECL, attr, vals, 2); if ( ns.getColumnCount() > 0 ) { for ( int i=0; i<ns.getColumnCount(); ++i ) { vals[0] = ns.getColumnName(i); vals[1] = n.getString(vals[0]); if (vals[1] != null) {
/** * Default Constructor. * It creates an empty Obvious Schema. */ public PrefuseObviousSchema() { this(new prefuse.data.Schema(0)); }
/** * Checks if all Schema types are compatible with the GraphML specification. * The GraphML spec only allows the types <code>int</code>, * <code>long</code>, <code>float</code>, <code>double</code>, * <code>boolean</code>, and <code>string</code>. * @param s the Schema to check */ private void checkGraphMLSchema(Schema s) throws DataIOException { for ( int i=0; i<s.getColumnCount(); ++i ) { Class type = s.getColumnType(i); if ( TYPES.get(type) == null ) { throw new DataIOException("Data type unsupported by the " + "GraphML format: " + type.getName()); } } }
} else { Schema s = t.getSchema(); if ( getSchema().isAssignableFrom(s) ) { int r = addRow(); for ( int i=0; i<s.getColumnCount(); ++i ) { String field = s.getColumnName(i); this.set(r, field, t.get(i));
/** * The column index for the column with the given name. * @param field the column name * @return the column index */ public int getColumnIndex(String field) { return this.schema.getColumnIndex(field); }
/** * The type of the column with the given name. * @param field the column name * @return the column type */ public Class<?> getColumnType(String field) { return this.schema.getColumnType(field); }
/** * The name of the column at the given position. * @param col the column index * @return the column name */ public String getColumnName(int col) { return this.schema.getColumnName(col); }
/** * The default value of the column at the given position. * @param col the column index * @return the column's default value */ public Object getColumnDefault(int col) { return this.schema.getDefault(col); }
/** * Get the number of columns in this schema. * @return the number of columns */ public int getColumnCount() { return this.schema.getColumnCount(); }
/** * Compares this schema with another one for equality. */ public boolean equals(Object o) { if ( !(o instanceof Schema) ) return false; Schema s = (Schema)o; if ( m_size != s.getColumnCount() ) return false; for ( int i=0; i<m_size; ++i ) { if ( !(m_names[i].equals(s.getColumnName(i)) && m_types[i].equals(s.getColumnType(i)) && m_dflts[i].equals(s.getDefault(i))) ) { return false; } } return true; }