bugged
stringlengths 6
599k
| fixed
stringlengths 10
599k
| __index_level_0__
int64 0
1.13M
|
|---|---|---|
public void testLoad() throws Exception { // StringReader r = new StringReader(testData); ByteArrayInputStream r = new ByteArrayInputStream(testData.getBytes()); project.load(r); assertFalse("Project starts out with undo history",project.getUndoManager().canUndoOrRedo()); DBTree tree = project.getSourceDatabases(); assertNotNull(tree); assertEquals(tree.getComponentCount(), 1 ); SQLDatabase target = project.getTargetDatabase(); assertNotNull(target); assertEquals(target.getName(), "Target Database"); assertEquals(target.getChildCount(), 2); }
|
public void testLoad() throws Exception { // StringReader r = new StringReader(testData); ByteArrayInputStream r = new ByteArrayInputStream(testData.getBytes()); project.load(r); assertFalse("Project starts out with undo history",project.getUndoManager().canUndoOrRedo()); DBTree tree = project.getSourceDatabases(); assertNotNull(tree); assertEquals(tree.getComponentCount(), 1 ); SQLDatabase target = project.getTargetDatabase(); assertNotNull(target); assertEquals(target.getName(), "Not Configured"); assertEquals(target.getChildCount(), 2); }
| 1,108,831
|
public void doTag(XMLOutput output) throws Exception { if (test == null && xpath == null) { throw new MissingAttributeException( "test" ); } if (test != null) { if (! test.evaluateAsBoolean(context)) { fail( getBodyText(), "evaluating test: "+ test.getExpressionText() ); } } else { Object xpathContext = getXPathContext(); if (! xpath.booleanValueOf(xpathContext)) { fail( getBodyText(), "evaluating xpath: "+ xpath ); } } }
|
public void doTag(XMLOutput output) throws JellyTagException { if (test == null && xpath == null) { throw new MissingAttributeException( "test" ); } if (test != null) { if (! test.evaluateAsBoolean(context)) { fail( getBodyText(), "evaluating test: "+ test.getExpressionText() ); } } else { Object xpathContext = getXPathContext(); if (! xpath.booleanValueOf(xpathContext)) { fail( getBodyText(), "evaluating xpath: "+ xpath ); } } }
| 1,108,832
|
public void doTag(XMLOutput output) throws Exception { if (test == null && xpath == null) { throw new MissingAttributeException( "test" ); } if (test != null) { if (! test.evaluateAsBoolean(context)) { fail( getBodyText(), "evaluating test: "+ test.getExpressionText() ); } } else { Object xpathContext = getXPathContext(); if (! xpath.booleanValueOf(xpathContext)) { fail( getBodyText(), "evaluating xpath: "+ xpath ); } } }
|
public void doTag(XMLOutput output) throws Exception { if (test == null && xpath == null) { throw new MissingAttributeException( "test" ); } if (test != null) { if (! test.evaluateAsBoolean(context)) { fail( getBodyText(), "evaluating test: "+ test.getExpressionText() ); } } else { Object xpathContext = getXPathContext(); if (! xpath.booleanValueOf(xpathContext)) { fail( getBodyText(), "evaluating xpath: "+ xpath ); } } }
| 1,108,833
|
public Query<S> and(Filter<S> filter) throws FetchException { FilterValues<S> newValues; if (mValues == null) { newValues = filter.initialFilterValues(); } else { newValues = mValues.getFilter().and(filter) .initialFilterValues().withValues(mValues.getValues()); } return createQuery(newValues, mOrdering); }
|
public Query<S> and(Filter<S> filter) throws FetchException { FilterValues<S> newValues; if (mValues == null) { newValues = filter.initialFilterValues(); } else { newValues = mValues.getFilter().and(filter) .initialFilterValues().withValues(mValues.getSuppliedValues()); } return createQuery(newValues, mOrdering); }
| 1,108,834
|
public Query<S> or(Filter<S> filter) throws FetchException { if (mValues == null) { throw new IllegalStateException("Query is already guaranteed to fetch everything"); } FilterValues<S> newValues = mValues.getFilter().or(filter) .initialFilterValues().withValues(mValues.getValues()); return createQuery(newValues, mOrdering); }
|
public Query<S> or(Filter<S> filter) throws FetchException { if (mValues == null) { throw new IllegalStateException("Query is already guaranteed to fetch everything"); } FilterValues<S> newValues = mValues.getFilter().or(filter) .initialFilterValues().withValues(mValues.getSuppliedValues()); return createQuery(newValues, mOrdering); }
| 1,108,835
|
public static ClassLoader getClassLoader(ClassLoader specifiedLoader, Class callingClass) { if (specifiedLoader != null) { return specifiedLoader; } return getClassLoader(callingClass); }
|
public static ClassLoader getClassLoader(ClassLoader specifiedLoader, boolean useContextClassLoader, Class callingClass) { if (specifiedLoader != null) { return specifiedLoader; } return getClassLoader(callingClass); }
| 1,108,837
|
static DataSource getDataSource(Object rawDataSource, JellyContext pc) throws JellyException { DataSource dataSource = null; if (log.isInfoEnabled() ) { log.info( "Attempting to deduce DataSource from: " + rawDataSource ); } if (rawDataSource == null) { rawDataSource = pc.getVariable("org.apache.commons.jelly.sql.DataSource"); } if (rawDataSource == null) { return null; } /* * If the 'dataSource' attribute's value resolves to a String * after rtexpr/EL evaluation, use the string as JNDI path to * a DataSource */ if (rawDataSource instanceof String) { log.info( "rawDataSource is a String" ); try { Context ctx = new InitialContext(); // relative to standard JNDI root for J2EE app Context envCtx = (Context) ctx.lookup("java:comp/env"); dataSource = (DataSource) envCtx.lookup((String) rawDataSource); } catch (NamingException ex) { dataSource = getDataSource((String) rawDataSource); } } else if (rawDataSource instanceof DataSource) { dataSource = (DataSource) rawDataSource; } else { throw new JellyException(Resources.getMessage("SQL_DATASOURCE_INVALID_TYPE")); } return dataSource; }
|
static DataSource getDataSource(Object rawDataSource, JellyContext pc) throws JellyException { DataSource dataSource = null; if (log.isInfoEnabled() ) { log.info( "Attempting to deduce DataSource from: " + rawDataSource ); } if (rawDataSource == null) { rawDataSource = pc.getVariable("org.apache.commons.jelly.sql.DataSource"); } if (rawDataSource == null) { return null; } /* * If the 'dataSource' attribute's value resolves to a String * after rtexpr/EL evaluation, use the string as JNDI path to * a DataSource */ if (rawDataSource instanceof String) { log.info( "rawDataSource is a String" ); try { Context ctx = new InitialContext(); // relative to standard JNDI root for J2EE app Context envCtx = (Context) ctx.lookup("java:comp/env"); dataSource = (DataSource) envCtx.lookup((String) rawDataSource); } catch (NamingException ex) { dataSource = getDataSource((String) rawDataSource); } } else if (rawDataSource instanceof DataSource) { dataSource = (DataSource) rawDataSource; } else { throw new JellyException(Resources.getMessage("SQL_DATASOURCE_INVALID_TYPE")); } return dataSource; }
| 1,108,839
|
static DataSource getDataSource(Object rawDataSource, JellyContext pc) throws JellyException { DataSource dataSource = null; if (log.isInfoEnabled() ) { log.info( "Attempting to deduce DataSource from: " + rawDataSource ); } if (rawDataSource == null) { rawDataSource = pc.getVariable("org.apache.commons.jelly.sql.DataSource"); } if (rawDataSource == null) { return null; } /* * If the 'dataSource' attribute's value resolves to a String * after rtexpr/EL evaluation, use the string as JNDI path to * a DataSource */ if (rawDataSource instanceof String) { log.info( "rawDataSource is a String" ); try { Context ctx = new InitialContext(); // relative to standard JNDI root for J2EE app Context envCtx = (Context) ctx.lookup("java:comp/env"); dataSource = (DataSource) envCtx.lookup((String) rawDataSource); } catch (NamingException ex) { dataSource = getDataSource((String) rawDataSource); } } else if (rawDataSource instanceof DataSource) { dataSource = (DataSource) rawDataSource; } else { throw new JellyException(Resources.getMessage("SQL_DATASOURCE_INVALID_TYPE")); } return dataSource; }
|
static DataSource getDataSource(Object rawDataSource, JellyContext pc) throws JellyException { DataSource dataSource = null; if (log.isInfoEnabled() ) { log.info( "Attempting to deduce DataSource from: " + rawDataSource ); } if (rawDataSource == null) { rawDataSource = pc.getVariable("org.apache.commons.jelly.sql.DataSource"); } if (rawDataSource == null) { return null; } /* * If the 'dataSource' attribute's value resolves to a String * after rtexpr/EL evaluation, use the string as JNDI path to * a DataSource */ if (rawDataSource instanceof String) { try { Context ctx = new InitialContext(); // relative to standard JNDI root for J2EE app Context envCtx = (Context) ctx.lookup("java:comp/env"); dataSource = (DataSource) envCtx.lookup((String) rawDataSource); } catch (NamingException ex) { dataSource = getDataSource((String) rawDataSource); } } else if (rawDataSource instanceof DataSource) { dataSource = (DataSource) rawDataSource; } else { throw new JellyException(Resources.getMessage("SQL_DATASOURCE_INVALID_TYPE")); } return dataSource; }
| 1,108,840
|
public void testCreateDB() { File confFile = null; File dbDir = null; // Create an empty configuration file & volume directory try { confFile = File.createTempFile( "photovault_settings_", ".xml" ); confFile.delete(); dbDir = File.createTempFile( "photovault_test_volume", "" ); dbDir.delete(); dbDir.mkdir(); } catch (IOException ex) { ex.printStackTrace(); fail( ex.getMessage() ); } System.setProperty( "photovault.configfile", confFile.getAbsolutePath() ); PhotovaultSettings settings = PhotovaultSettings.getSettings(); PVDatabase db = new PVDatabase(); db.setInstanceType( PVDatabase.TYPE_EMBEDDED ); db.setEmbeddedDirectory( dbDir );// Volume vol = new Volume( "testvolume", dbDir.getAbsolutePath() );// db.addVolume( vol ); settings.addDatabase( db ); settings.saveConfig(); db.createDatabase( "harri", "" ); try { // Verify that the database can be used by importing a file ODMG.initODMG( "harri", "", db ); } catch (PhotovaultException ex) { fail( ex.getMessage() ); } File photoFile = new File( "testfiles/test1.jpg" ); PhotoInfo photo = null; try { photo = PhotoInfo.addToDB(photoFile); } catch (PhotoNotFoundException ex) { ex.printStackTrace(); fail( ex.getMessage() ); } photo.setPhotographer( "test" ); try { PhotoInfo photo2 = PhotoInfo.retrievePhotoInfo( photo.getUid() ); Thumbnail thumb = photo2.getThumbnail(); this.assertFalse( "Default thumbnail returned", thumb == Thumbnail.getDefaultThumbnail() ); } catch (PhotoNotFoundException ex) { fail( "Photo not found in database" ); } }
|
public void testCreateDB() { File confFile = null; File dbDir = null; // Create an empty configuration file & volume directory try { confFile = File.createTempFile( "photovault_settings_", ".xml" ); confFile.delete(); dbDir = File.createTempFile( "photovault_test_volume", "" ); dbDir.delete(); dbDir.mkdir(); } catch (IOException ex) { ex.printStackTrace(); fail( ex.getMessage() ); } System.setProperty( "photovault.configfile", confFile.getAbsolutePath() ); PhotovaultSettings settings = PhotovaultSettings.getSettings(); PVDatabase db = new PVDatabase(); db.setInstanceType( PVDatabase.TYPE_EMBEDDED ); db.setEmbeddedDirectory( dbDir );// Volume vol = new Volume( "testvolume", dbDir.getAbsolutePath() );// db.addVolume( vol ); try { settings.addDatabase( db ); } catch (PhotovaultException ex) { fail( "Exception while creating database: " + ex.getMessage() ); } settings.saveConfig(); db.createDatabase( "harri", "" ); try { // Verify that the database can be used by importing a file ODMG.initODMG( "harri", "", db ); } catch (PhotovaultException ex) { fail( ex.getMessage() ); } File photoFile = new File( "testfiles/test1.jpg" ); PhotoInfo photo = null; try { photo = PhotoInfo.addToDB(photoFile); } catch (PhotoNotFoundException ex) { ex.printStackTrace(); fail( ex.getMessage() ); } photo.setPhotographer( "test" ); try { PhotoInfo photo2 = PhotoInfo.retrievePhotoInfo( photo.getUid() ); Thumbnail thumb = photo2.getThumbnail(); this.assertFalse( "Default thumbnail returned", thumb == Thumbnail.getDefaultThumbnail() ); } catch (PhotoNotFoundException ex) { fail( "Photo not found in database" ); } }
| 1,108,844
|
public void testNoSettingsFile() { try { File f = File.createTempFile( "photovault_settings", ".xml" ); f.delete(); System.setProperty( "photovault.configfile", f.getAbsolutePath() ); } catch ( Exception e ) { fail( e.getMessage() ); } PhotovaultSettings settings = PhotovaultSettings.getSettings(); Collection dbs = settings.getDatabases(); assertTrue( dbs.size() == 0 ); PVDatabase db = new PVDatabase(); db.setName( "testing" ); db.setDbHost( "thishost" ); settings.addDatabase( db ); settings.saveConfig(); PhotovaultSettings.settings = null; settings = PhotovaultSettings.getSettings(); PVDatabase db2 = settings.getDatabase( "testing" ); assertEquals( db2.getName(), db.getName() ); }
|
public void testNoSettingsFile() { try { File f = File.createTempFile( "photovault_settings", ".xml" ); f.delete(); System.setProperty( "photovault.configfile", f.getAbsolutePath() ); } catch ( Exception e ) { fail( e.getMessage() ); } PhotovaultSettings settings = PhotovaultSettings.getSettings(); Collection dbs = settings.getDatabases(); assertTrue( dbs.size() == 0 ); PVDatabase db = new PVDatabase(); db.setName( "testing" ); db.setDbHost( "thishost" ); try { settings.addDatabase( db ); } catch (PhotovaultException ex) { fail( "Exception while creating database: " + ex.getMessage() ); } settings.saveConfig(); PhotovaultSettings.settings = null; settings = PhotovaultSettings.getSettings(); PVDatabase db2 = settings.getDatabase( "testing" ); assertEquals( db2.getName(), db.getName() ); }
| 1,108,846
|
protected JPopupMenu setupPopupMenu() { JPopupMenu newMenu = new JPopupMenu(); JMenuItem popupNewDatabase = new JMenuItem("New Database Connection..."); popupNewDatabase.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DBConnectionSpec dbcs = new DBConnectionSpec(); dbcs.setName("New Connection"); dbcs.setDisplayName("New Connection"); SQLDatabase db = new SQLDatabase(dbcs); ((DBTreeModel.DBTreeRoot) getModel().getRoot()).addChild(db); ArchitectFrame.getMainInstance().getUserSettings().getConnections().add(dbcs); logger.debug("Setting new DBCS on panel: "+dbcs); dbcsPanel.setDbcs(dbcs); propDialog.setVisible(true); propDialog.requestFocus(); } }); newMenu.add(popupNewDatabase); // index 0 newMenu.addSeparator(); // index 1 JMenuItem popupProperties = new JMenuItem("Properties"); popupProperties.addActionListener(new PopupPropertiesListener()); newMenu.add(popupProperties); // index 2 return newMenu; }
|
protected JPopupMenu setupPopupMenu() { JPopupMenu newMenu = new JPopupMenu(); JMenuItem popupNewDatabase = new JMenuItem("New Database Connection..."); popupNewDatabase.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DBConnectionSpec dbcs = new DBConnectionSpec(); dbcs.setName("New Connection"); dbcs.setDisplayName("New Connection"); SQLDatabase db = new SQLDatabase(dbcs); ((DBTreeModel.DBTreeRoot) getModel().getRoot()).addChild(db); edittingDB = db; logger.debug("Setting new DBCS on panel: "+dbcs); dbcsPanel.setDbcs(dbcs); propDialog.setVisible(true); propDialog.requestFocus(); } }); newMenu.add(popupNewDatabase); // index 0 newMenu.addSeparator(); // index 1 JMenuItem popupProperties = new JMenuItem("Properties"); popupProperties.addActionListener(new PopupPropertiesListener()); newMenu.add(popupProperties); // index 2 return newMenu; }
| 1,108,847
|
public void actionPerformed(ActionEvent e) { DBConnectionSpec dbcs = new DBConnectionSpec(); dbcs.setName("New Connection"); dbcs.setDisplayName("New Connection"); SQLDatabase db = new SQLDatabase(dbcs); ((DBTreeModel.DBTreeRoot) getModel().getRoot()).addChild(db); ArchitectFrame.getMainInstance().getUserSettings().getConnections().add(dbcs); logger.debug("Setting new DBCS on panel: "+dbcs); dbcsPanel.setDbcs(dbcs); propDialog.setVisible(true); propDialog.requestFocus(); }
|
public void actionPerformed(ActionEvent e) { DBConnectionSpec dbcs = new DBConnectionSpec(); dbcs.setName("New Connection"); dbcs.setDisplayName("New Connection"); SQLDatabase db = new SQLDatabase(dbcs); ((DBTreeModel.DBTreeRoot) getModel().getRoot()).addChild(db); edittingDB = db; logger.debug("Setting new DBCS on panel: "+dbcs); dbcsPanel.setDbcs(dbcs); propDialog.setVisible(true); propDialog.requestFocus(); }
| 1,108,848
|
static TimeZone getTimeZone(JellyContext jc, Tag fromTag) { TimeZone tz = null; Tag t = findAncestorWithClass(fromTag, TimeZoneTag.class); if (t != null) { // use time zone from parent <timeZone> tag TimeZoneTag parent = (TimeZoneTag) t; tz = parent.getTimeZone(); } else { // get time zone from configuration setting Object obj = jc.getVariable(Config.FMT_TIME_ZONE); if (obj != null) { if (obj instanceof TimeZone) { tz = (TimeZone) obj; } else { tz = TimeZone.getTimeZone((String) obj); } } } return tz; }
|
static TimeZone getTimeZone(JellyContext jc, Tag fromTag) { TimeZone tz = null; Tag t = findAncestorWithClass(fromTag, TimeZoneTag.class); if (t != null) { // use time zone from parent <timeZone> tag TimeZoneTag parent = (TimeZoneTag) t; tz = parent.getTimeZone(); } else { // get time zone from configuration setting Object obj = jc.getVariable(Config.FMT_TIME_ZONE); if (obj != null) { if (obj instanceof TimeZone) { tz = (TimeZone) obj; } else { tz = TimeZone.getTimeZone((String) obj); } } } return tz; }
| 1,108,851
|
private boolean login( LoginDlg ld ) { boolean success = false; String user = ld.getUsername(); String passwd = ld.getPassword(); String dbName = ld.getDb(); log.debug( "Using configuration " + dbName ); settings.setConfiguration( dbName ); PVDatabase db = settings.getDatabase( dbName ); String sqldbName = db.getDbName(); log.debug( "Mysql DB name: " + sqldbName ); if ( sqldbName == null ) { JOptionPane.showMessageDialog( ld, "Could not find dbname for configuration " + db, "Configuration error", JOptionPane.ERROR_MESSAGE ); return false; } if ( ODMG.initODMG( user, passwd, db ) ) { log.debug( "Connection succesful!!!" ); // Login is succesfull // ld.setVisible( false ); success = true; } int schemaVersion = db.getSchemaVersion(); if ( schemaVersion < db.CURRENT_SCHEMA_VERSION ) { String options[] = {"Proceed", "Exit Photovault"}; if ( JOptionPane.YES_OPTION == JOptionPane.showOptionDialog( ld, "The database was created with an older version of Photovault\n" + "Photovault will upgrade the database format before starting.", "Upgrade database", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, null ) ) { final SchemaUpdateAction updater = new SchemaUpdateAction( db ); SchemaUpdateStatusDlg statusDlg = new SchemaUpdateStatusDlg( null, true ); updater.addSchemaUpdateListener( statusDlg ); Thread upgradeThread = new Thread() { public void run() { updater.upgradeDatabase(); } }; upgradeThread.start(); statusDlg.setVisible( true ); success = true; } } return success; }
|
private boolean login( LoginDlg ld ) { boolean success = false; String user = ld.getUsername(); String passwd = ld.getPassword(); String dbName = ld.getDb(); log.debug( "Using configuration " + dbName ); settings.setConfiguration( dbName ); PVDatabase db = settings.getDatabase( dbName ); String sqldbName = db.getDbName(); log.debug( "Mysql DB name: " + sqldbName ); if ( sqldbName == null ) { JOptionPane.showMessageDialog( ld, "Could not find dbname for configuration " + db, "Configuration error", JOptionPane.ERROR_MESSAGE ); return false; } if ( ODMG.initODMG( user, passwd, db ) ) { log.debug( "Connection succesful!!!" ); // Login is succesfull // ld.setVisible( false ); success = true; } int schemaVersion = db.getSchemaVersion(); if ( schemaVersion < db.CURRENT_SCHEMA_VERSION ) { String options[] = {"Proceed", "Exit Photovault"}; if ( JOptionPane.YES_OPTION == JOptionPane.showOptionDialog( ld, "The database was created with an older version of Photovault\n" + "Photovault will upgrade the database format before starting.", "Upgrade database", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, null ) ) { final SchemaUpdateAction updater = new SchemaUpdateAction( db ); SchemaUpdateStatusDlg statusDlg = new SchemaUpdateStatusDlg( null, true ); updater.addSchemaUpdateListener( statusDlg ); Thread upgradeThread = new Thread() { public void run() { updater.upgradeDatabase(); } }; upgradeThread.start(); statusDlg.setVisible( true ); success = true; } } return success; }
| 1,108,852
|
public void itemDeselected(SelectionEvent e) { changeToolTip(pp.getSelectedItems()); }
|
public void itemDeselected(SelectionEvent e) { try { setupAction(pp.getSelectedItems()); } catch (ArchitectException e1) { throw new ArchitectRuntimeException(e1); } }
| 1,108,853
|
public void itemSelected(SelectionEvent e) { changeToolTip(pp.getSelectedItems()); }
|
public void itemSelected(SelectionEvent e) { try { setupAction(pp.getSelectedItems()); } catch (ArchitectException e1) { throw new ArchitectRuntimeException(e1); } }
| 1,108,854
|
void export(Component c, int format, int start, int stop){ if (c == null) return; fc.setSelectedFile(new File("")); if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION){ File outfile = fc.getSelectedFile(); if (format == PNG_MODE || format == COMPRESSED_PNG_MODE){ BufferedImage image = null; if (c.equals(dPrimeDisplay)){ try { if (format == PNG_MODE){ image = dPrimeDisplay.export(start, stop, false); }else{ image = dPrimeDisplay.export(start, stop, true); } } catch(HaploViewException hve) { JOptionPane.showMessageDialog(this, hve.getMessage(), "Export Error", JOptionPane.ERROR_MESSAGE); } }else if (c.equals(hapDisplay)){ image = hapDisplay.export(); }else{ image = new BufferedImage(1,1,BufferedImage.TYPE_3BYTE_BGR); } if (image != null){ try{ String filename = outfile.getPath(); if (! (filename.endsWith(".png") || filename.endsWith(".PNG"))){ filename += ".png"; } Jimi.putImage("image/png", image, filename); }catch(JimiException je){ JOptionPane.showMessageDialog(this, je.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } else if (format == TXT_MODE){ try{ if (c.equals(dPrimeDisplay)){ theData.saveDprimeToText(outfile, TABLE_TYPE, start, stop); }else if (c.equals(hapDisplay)){ theData.saveHapsToText(hapDisplay.filteredHaplos,hapDisplay.multidprimeArray, outfile); }else if (c.equals(checkPanel)){ theData.getPedFile().saveCheckDataToText(outfile); }else if (c.equals(tdtPanel)){ tdtPanel.getTestSet().saveSNPsToText(outfile); }else if (c.equals(hapAssocPanel)){ hapAssocPanel.getTestSet().saveHapsToText(outfile); }else if (c.equals(permutationPanel)){ permutationPanel.export(outfile); }else if (c.equals(custAssocPanel)){ custAssocPanel.getTestSet().saveResultsToText(outfile); }else if (c.equals(taggerConfigPanel) || c.equals(taggerResultsPanel)){ taggerConfigPanel.export(outfile); }else if (c.equals(plinkPanel)){ plinkPanel.exportTable(outfile); } }catch(IOException ioe){ JOptionPane.showMessageDialog(this, ioe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); }catch(HaploViewException he){ JOptionPane.showMessageDialog(this, he.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } }
|
void export(Component c, int format, int start, int stop){ if (c == null) return; fc.setSelectedFile(new File("")); if (fc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION){ File outfile = fc.getSelectedFile(); if (format == PNG_MODE || format == COMPRESSED_PNG_MODE){ BufferedImage image = null; if (c.equals(dPrimeDisplay)){ try { if (format == PNG_MODE){ image = dPrimeDisplay.export(start, stop, false); }else{ image = dPrimeDisplay.export(start, stop, true); } } catch(HaploViewException hve) { JOptionPane.showMessageDialog(this, hve.getMessage(), "Export Error", JOptionPane.ERROR_MESSAGE); } }else if (c.equals(hapDisplay)){ image = hapDisplay.export(); }else{ image = new BufferedImage(1,1,BufferedImage.TYPE_3BYTE_BGR); } if (image != null){ try{ String filename = outfile.getPath(); if (! (filename.endsWith(".png") || filename.endsWith(".PNG"))){ filename += ".png"; } Jimi.putImage("image/png", image, filename); }catch(JimiException je){ JOptionPane.showMessageDialog(this, je.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } else if (format == TXT_MODE){ try{ if (c.equals(dPrimeDisplay)){ theData.saveDprimeToText(outfile, TABLE_TYPE, start, stop); }else if (c.equals(hapDisplay)){ theData.saveHapsToText(hapDisplay.filteredHaplos,hapDisplay.multidprimeArray, outfile); }else if (c.equals(checkPanel)){ checkPanel.saveTableToText(outfile); }else if (c.equals(tdtPanel)){ tdtPanel.getTestSet().saveSNPsToText(outfile); }else if (c.equals(hapAssocPanel)){ hapAssocPanel.getTestSet().saveHapsToText(outfile); }else if (c.equals(permutationPanel)){ permutationPanel.export(outfile); }else if (c.equals(custAssocPanel)){ custAssocPanel.getTestSet().saveResultsToText(outfile); }else if (c.equals(taggerConfigPanel) || c.equals(taggerResultsPanel)){ taggerConfigPanel.export(outfile); }else if (c.equals(plinkPanel)){ plinkPanel.exportTable(outfile); } }catch(IOException ioe){ JOptionPane.showMessageDialog(this, ioe.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); }catch(HaploViewException he){ JOptionPane.showMessageDialog(this, he.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } } }
| 1,108,855
|
public void parseWGA(String wga, String map, boolean embed) throws PlinkException { markers = new Vector(); results = new Vector(); columns = new Vector(); columns.add("Result"); columns.add("Chrom"); columns.add("Marker"); columns.add("Position"); final File wgaFile = new File(wga); final File mapFile = new File(map); Hashtable markerHash = new Hashtable(1,1); Vector ignoredMarkers = new Vector(); try{ if (wgaFile.length() < 1){ throw new PlinkException("plink file is empty or nonexistent."); } if (!embed){ if (mapFile.length() < 1){ throw new PlinkException("Map file is empty or nonexistent."); } BufferedReader mapReader = new BufferedReader(new FileReader(mapFile)); String mapLine; while((mapLine = mapReader.readLine())!=null) { if (mapLine.length() == 0){ //skip blank lines continue; } StringTokenizer st = new StringTokenizer(mapLine,"\t "); String chrom = st.nextToken(); String marker = new String(st.nextToken()); double mDistance = Double.parseDouble(st.nextToken()); long position = Long.parseLong(st.nextToken()); Marker mark = new Marker(chrom, marker, mDistance, position); markers.add(mark); markerHash.put(mark.getMarkerID(), mark); } } BufferedReader wgaReader = new BufferedReader(new FileReader(wgaFile)); int numColumns = 0; int markerColumn = -1; int chromColumn = -1; int positionColumn = -1; int morganColumn = -1; String headerLine = wgaReader.readLine(); StringTokenizer headerSt = new StringTokenizer(headerLine); while (headerSt.hasMoreTokens()){ String column = new String(headerSt.nextToken()); if (column.equals("SNP")){ markerColumn = numColumns; numColumns++; }else if (column.equals("CHR")){ chromColumn = numColumns; numColumns++; }else if (column.equals("POS")){ positionColumn = numColumns; numColumns++; }else if (column.equals("MORGAN")){ morganColumn = numColumns; numColumns++; } else{ columns.add(column); numColumns++; } } if (markerColumn == -1){ throw new PlinkException("Results file must contain a SNP column."); } if (embed){ if (chromColumn == -1 || positionColumn == -1 || morganColumn == -1){ throw new PlinkException("Results files with embedded map files must contain CHR, POS, and MORGAN columns."); } } String wgaLine; int lineNumber = 0; while((wgaLine = wgaReader.readLine())!=null){ if (wgaLine.length() == 0){ //skip blank lines continue; } int tokenNumber = 0; //StringTokenizer tokenizer = new StringTokenizer(wgaLine,"\t :"); StringTokenizer tokenizer = new StringTokenizer(wgaLine); String marker = null; String chromosome = null; long position = 0; double morganDistance = 0; Vector values = new Vector(); while(tokenizer.hasMoreTokens()){ if (tokenNumber == markerColumn){ marker = new String(tokenizer.nextToken()); }else if (tokenNumber == chromColumn){ chromosome = new String(tokenizer.nextToken()); if(chromosome.equals("23")){ chromosome = "X"; }else if(chromosome.equals("24")){ chromosome = "Y"; }else if(chromosome.equals("25")){ chromosome = "XY"; } }else if (tokenNumber == positionColumn){ position = (new Long(new String(tokenizer.nextToken()))).longValue(); }else if (tokenNumber == morganColumn){ morganDistance = (new Double(new String(tokenizer.nextToken()))).doubleValue(); } else{ values.add(new String(tokenizer.nextToken())); } tokenNumber++; } if (tokenNumber != numColumns){ throw new PlinkException("Inconsistent column number on line " + (lineNumber+1)); } Marker assocMarker; if (!embed){ assocMarker = (Marker)markerHash.get(marker); if (assocMarker == null){ ignoredMarkers.add(marker); lineNumber++; continue; }else if (!(assocMarker.getChromosome().equalsIgnoreCase(chromosome)) && chromosome != null){ throw new PlinkException("Incompatible chromsomes for marker " + marker + "\non line " + lineNumber); } }else{ assocMarker = new Marker(chromosome,marker,morganDistance,position); } AssociationResult result = new AssociationResult(lineNumber,assocMarker,values); results.add(result); lineNumber++; } }catch(IOException ioe){ throw new PlinkException("File error."); }catch(NumberFormatException nfe){ throw new PlinkException("File formatting error."); } if (ignoredMarkers.size() != 0){ IgnoredMarkersDialog imd = new IgnoredMarkersDialog(hv,"Ignored Markers",ignoredMarkers,false); imd.pack(); imd.setVisible(true); } hv.setPlinkData(results,columns); }
|
public void parseWGA(String wga, String map, boolean embed) throws PlinkException { markers = new Vector(); results = new Vector(); columns = new Vector(); columns.add("Result"); columns.add("Chrom"); columns.add("Marker"); columns.add("Position"); final File wgaFile = new File(wga); final File mapFile = new File(map); Hashtable markerHash = new Hashtable(1,1); Vector ignoredMarkers = new Vector(); try{ if (wgaFile.length() < 1){ throw new PlinkException("plink file is empty or nonexistent."); } if (!embed){ if (mapFile.length() < 1){ throw new PlinkException("Map file is empty or nonexistent."); } BufferedReader mapReader = new BufferedReader(new FileReader(mapFile)); String mapLine; while((mapLine = mapReader.readLine())!=null) { if (mapLine.length() == 0){ //skip blank lines continue; } StringTokenizer st = new StringTokenizer(mapLine,"\t "); String chrom = st.nextToken(); String marker = new String(st.nextToken()); double mDistance = Double.parseDouble(st.nextToken()); String pos = st.nextToken(); if (pos.startsWith("-")){ continue; } long position = Long.parseLong(pos); Marker mark = new Marker(chrom, marker, mDistance, position); markers.add(mark); markerHash.put(mark.getMarkerID(), mark); } } BufferedReader wgaReader = new BufferedReader(new FileReader(wgaFile)); int numColumns = 0; int markerColumn = -1; int chromColumn = -1; int positionColumn = -1; int morganColumn = -1; String headerLine = wgaReader.readLine(); StringTokenizer headerSt = new StringTokenizer(headerLine); while (headerSt.hasMoreTokens()){ String column = new String(headerSt.nextToken()); if (column.equals("SNP")){ markerColumn = numColumns; numColumns++; }else if (column.equals("CHR")){ chromColumn = numColumns; numColumns++; }else if (column.equals("POS")){ positionColumn = numColumns; numColumns++; }else if (column.equals("MORGAN")){ morganColumn = numColumns; numColumns++; } else{ columns.add(column); numColumns++; } } if (markerColumn == -1){ throw new PlinkException("Results file must contain a SNP column."); } if (embed){ if (chromColumn == -1 || positionColumn == -1 || morganColumn == -1){ throw new PlinkException("Results files with embedded map files must contain CHR, POS, and MORGAN columns."); } } String wgaLine; int lineNumber = 0; while((wgaLine = wgaReader.readLine())!=null){ if (wgaLine.length() == 0){ //skip blank lines continue; } int tokenNumber = 0; //StringTokenizer tokenizer = new StringTokenizer(wgaLine,"\t :"); StringTokenizer tokenizer = new StringTokenizer(wgaLine); String marker = null; String chromosome = null; long position = 0; double morganDistance = 0; Vector values = new Vector(); while(tokenizer.hasMoreTokens()){ if (tokenNumber == markerColumn){ marker = new String(tokenizer.nextToken()); }else if (tokenNumber == chromColumn){ chromosome = new String(tokenizer.nextToken()); if(chromosome.equals("23")){ chromosome = "X"; }else if(chromosome.equals("24")){ chromosome = "Y"; }else if(chromosome.equals("25")){ chromosome = "XY"; } }else if (tokenNumber == positionColumn){ position = (new Long(new String(tokenizer.nextToken()))).longValue(); }else if (tokenNumber == morganColumn){ morganDistance = (new Double(new String(tokenizer.nextToken()))).doubleValue(); } else{ values.add(new String(tokenizer.nextToken())); } tokenNumber++; } if (tokenNumber != numColumns){ throw new PlinkException("Inconsistent column number on line " + (lineNumber+1)); } Marker assocMarker; if (!embed){ assocMarker = (Marker)markerHash.get(marker); if (assocMarker == null){ ignoredMarkers.add(marker); lineNumber++; continue; }else if (!(assocMarker.getChromosome().equalsIgnoreCase(chromosome)) && chromosome != null){ throw new PlinkException("Incompatible chromsomes for marker " + marker + "\non line " + lineNumber); } }else{ assocMarker = new Marker(chromosome,marker,morganDistance,position); } AssociationResult result = new AssociationResult(lineNumber,assocMarker,values); results.add(result); lineNumber++; } }catch(IOException ioe){ throw new PlinkException("File error."); }catch(NumberFormatException nfe){ throw new PlinkException("File formatting error."); } if (ignoredMarkers.size() != 0){ IgnoredMarkersDialog imd = new IgnoredMarkersDialog(hv,"Ignored Markers",ignoredMarkers,false); imd.pack(); imd.setVisible(true); } hv.setPlinkData(results,columns); }
| 1,108,856
|
protected Document getXmlDocument(XMLOutput output) throws Exception { Document document = null; if (xml == null) { document = parseBody(output); } else { document = parse(xml); } return document; }
|
protected Document getXmlDocument(XMLOutput output) throws Exception { Document document = null; Object xmlObj = this.getXml(); if (xmlObj == null) { document = parseBody(output); } else { document = parse(xml); } return document; }
| 1,108,857
|
protected Document getXmlDocument(XMLOutput output) throws Exception { Document document = null; if (xml == null) { document = parseBody(output); } else { document = parse(xml); } return document; }
|
protected Document getXmlDocument(XMLOutput output) throws Exception { Document document = null; if (xml == null) { document = parseBody(output); } else { document = parse(xmlObj); } return document; }
| 1,108,858
|
public void paintComponent(Graphics graphics) { if (filteredHaplos == null){ super.paintComponent(graphics); return; } Graphics2D g = (Graphics2D) graphics; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //System.out.println(getSize()); Dimension size = getSize(); Dimension pref = getPreferredSize(); g.setColor(this.getBackground()); g.fillRect(0,0,pref.width, pref.height); if (!forExport){ g.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } //g.drawRect(0, 0, pref.width, pref.height); final BasicStroke thinStroke = new BasicStroke(0.5f); final BasicStroke thickStroke = new BasicStroke(2.0f); // width of one letter of the haplotype block //int letterWidth = haploMetrics.charWidth('G'); //int percentWidth = pctMetrics.stringWidth(".000"); //final int verticalOffset = 43; // room for tags and diamonds int left = BORDER; int top = BORDER; //verticalOffset; //int totalWidth = 0; // percentages for each haplotype NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(3); nf.setMaximumFractionDigits(3); nf.setMinimumIntegerDigits(0); nf.setMaximumIntegerDigits(0); // multi reading, between the columns NumberFormat nfMulti = NumberFormat.getInstance(); nfMulti.setMinimumFractionDigits(2); nfMulti.setMaximumFractionDigits(2); nfMulti.setMinimumIntegerDigits(0); nfMulti.setMaximumIntegerDigits(0); int[][] lookupPos = new int[filteredHaplos.length][]; for (int p = 0; p < lookupPos.length; p++) { lookupPos[p] = new int[filteredHaplos[p].length]; for (int q = 0; q < lookupPos[p].length; q++){ lookupPos[p][filteredHaplos[p][q].getListOrder()] = q; } } // set number formatter to pad with appropriate number of zeroes NumberFormat nfMarker = NumberFormat.getInstance(); int markerCount = Chromosome.getSize(); // the +0.0000001 is because there is // some suckage where log(1000) / log(10) isn't actually 3 int markerDigits = (int) (0.0000001 + Math.log(markerCount) / Math.log(10)) + 1; nfMarker.setMinimumIntegerDigits(markerDigits); nfMarker.setMaximumIntegerDigits(markerDigits); //int tagShapeX[] = new int[3]; //int tagShapeY[] = new int[3]; //Polygon tagShape; int textRight = 0; // gets updated for scooting over // i = 0 to number of columns - 1 for (int i = 0; i < filteredHaplos.length; i++) { int[] markerNums = filteredHaplos[i][0].getMarkers(); boolean[] tags = filteredHaplos[i][0].getTags(); //int headerX = x; for (int z = 0; z < markerNums.length; z++) { //int tagMiddle = tagMetrics.getAscent() / 2; //int tagLeft = x + z*letterWidth + tagMiddle; //g.translate(tagLeft, 20); // if tag snp, draw little triangle pooper if (tags[z]) { g.drawImage(tagImage, left + z*CHAR_WIDTH, top + markerDigits*MARKER_CHAR_WIDTH + -(CHAR_HEIGHT - TAG_SPAN), null); } //g.rotate(-Math.PI / 2.0); //g.drawLine(0, 0, 0, 0); //g.setColor(Color.black); //g.drawString(nfMarker.format(markerNums[z]), 0, tagMiddle); char markerChars[] = nfMarker.format(Chromosome.realIndex[markerNums[z]]+1).toCharArray(); for (int m = 0; m < markerDigits; m++) { g.drawImage(markerNumImages[markerChars[m] - '0'], left + z*CHAR_WIDTH + (1 + CHAR_WIDTH - MARKER_CHAR_HEIGHT)/2, top + (markerDigits-m-1)*MARKER_CHAR_WIDTH, null); } // undo the transform.. no push/pop.. arrgh //g.rotate(Math.PI / 2.0); //g.translate(-tagLeft, -20); } // y position of the first image for the haplotype letter // top + the size of the marker digits + the size of the tag + // the character height centered in the row's height int above = top + markerDigits*MARKER_CHAR_WIDTH + TAG_SPAN + (ROW_HEIGHT - CHAR_HEIGHT) / 2; for (int j = 0; j < filteredHaplos[i].length; j++){ int curHapNum = lookupPos[i][j]; //String theHap = new String(); //String thePercentage = new String(); int[] theGeno = filteredHaplos[i][curHapNum].getGeno(); //getGeno(); // j is the row of haplotype for (int k = 0; k < theGeno.length; k++) { // theGeno[k] will be 1,2,3,4 (acgt) or 8 (for bad) if (!numAlls){ g.drawImage(charImages[theGeno[k] - 1], left + k*CHAR_WIDTH, above + j*ROW_HEIGHT, null); }else{ g.drawImage(blackNumImages[theGeno[k]], left + k*CHAR_WIDTH, above + j*ROW_HEIGHT, null); } } //draw the percentage value in non mono font double percent = filteredHaplos[i][curHapNum].getPercentage(); //thePercentage = " " + nf.format(percent); char percentChars[] = nf.format(percent).toCharArray(); // perhaps need an exceptional case for 1.0 being the percent for (int m = 0; m < percentChars.length; m++) { g.drawImage(grayNumImages[(m == 0) ? 10 : percentChars[m]-'0'], left + theGeno.length*CHAR_WIDTH + m*CHAR_WIDTH, above + j*ROW_HEIGHT, null); } // 4 is the number of chars in .999 for the percent textRight = left + theGeno.length*CHAR_WIDTH + 4*CHAR_WIDTH; g.setColor(Color.black); if (i < filteredHaplos.length - 1) { //draw crossovers for (int crossCount = 0; crossCount < filteredHaplos[i+1].length; crossCount++) { double crossVal = filteredHaplos[i][curHapNum].getCrossover(crossCount); //draw thin and thick lines int crossValue = (int) (crossVal*100); if (crossValue > thinThresh) { g.setStroke(crossValue > thickThresh ? thickStroke : thinStroke); int connectTo = filteredHaplos[i+1][crossCount].getListOrder(); g.drawLine(textRight + LINE_LEFT, above + j*ROW_HEIGHT + ROW_HEIGHT/2, textRight + LINE_RIGHT, above + connectTo*ROW_HEIGHT + ROW_HEIGHT/2); } } } } left = textRight; // add the multilocus d prime if appropriate if (i < filteredHaplos.length - 1) { //put the numbers in the right place vertically int depth; if (filteredHaplos[i].length > filteredHaplos[i+1].length){ depth = filteredHaplos[i].length; }else{ depth = filteredHaplos[i+1].length; } char multiChars[] = nfMulti.format(multidprimeArray[i]).toCharArray(); if (multidprimeArray[i] > 0.99){ //draw 1.0 vals specially g.drawImage(blackNumImages[1], left + (LINE_SPAN - 7*CHAR_WIDTH/2)/2 + CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); g.drawImage(blackNumImages[10], left + (LINE_SPAN - 9*CHAR_WIDTH/2)/2 + 2*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); g.drawImage(blackNumImages[0], left + (LINE_SPAN - 9*CHAR_WIDTH/2)/2 + 3*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); }else{ for (int m = 0; m < 3; m++) { g.drawImage(blackNumImages[(m == 0) ? 10 : multiChars[m]-'0'], left + (LINE_SPAN - 7*CHAR_WIDTH/2)/2 + m*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); } } } left += LINE_SPAN; } }
|
public void paintComponent(Graphics graphics) { if (filteredHaplos == null){ super.paintComponent(graphics); return; } Graphics2D g = (Graphics2D) graphics; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //System.out.println(getSize()); Dimension size = getSize(); Dimension pref = getPreferredSize(); g.setColor(this.getBackground()); g.fillRect(0,0,pref.width, pref.height); if (!forExport){ g.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } //g.drawRect(0, 0, pref.width, pref.height); final BasicStroke thinStroke = new BasicStroke(0.5f); final BasicStroke thickStroke = new BasicStroke(2.0f); // width of one letter of the haplotype block //int letterWidth = haploMetrics.charWidth('G'); //int percentWidth = pctMetrics.stringWidth(".000"); //final int verticalOffset = 43; // room for tags and diamonds int left = BORDER; int top = BORDER; //verticalOffset; //int totalWidth = 0; // percentages for each haplotype NumberFormat nf = NumberFormat.getInstance(Locale.US); nf.setMinimumFractionDigits(3); nf.setMaximumFractionDigits(3); nf.setMinimumIntegerDigits(0); nf.setMaximumIntegerDigits(0); // multi reading, between the columns NumberFormat nfMulti = NumberFormat.getInstance(); nfMulti.setMinimumFractionDigits(2); nfMulti.setMaximumFractionDigits(2); nfMulti.setMinimumIntegerDigits(0); nfMulti.setMaximumIntegerDigits(0); int[][] lookupPos = new int[filteredHaplos.length][]; for (int p = 0; p < lookupPos.length; p++) { lookupPos[p] = new int[filteredHaplos[p].length]; for (int q = 0; q < lookupPos[p].length; q++){ lookupPos[p][filteredHaplos[p][q].getListOrder()] = q; } } // set number formatter to pad with appropriate number of zeroes NumberFormat nfMarker = NumberFormat.getInstance(); int markerCount = Chromosome.getSize(); // the +0.0000001 is because there is // some suckage where log(1000) / log(10) isn't actually 3 int markerDigits = (int) (0.0000001 + Math.log(markerCount) / Math.log(10)) + 1; nfMarker.setMinimumIntegerDigits(markerDigits); nfMarker.setMaximumIntegerDigits(markerDigits); //int tagShapeX[] = new int[3]; //int tagShapeY[] = new int[3]; //Polygon tagShape; int textRight = 0; // gets updated for scooting over // i = 0 to number of columns - 1 for (int i = 0; i < filteredHaplos.length; i++) { int[] markerNums = filteredHaplos[i][0].getMarkers(); boolean[] tags = filteredHaplos[i][0].getTags(); //int headerX = x; for (int z = 0; z < markerNums.length; z++) { //int tagMiddle = tagMetrics.getAscent() / 2; //int tagLeft = x + z*letterWidth + tagMiddle; //g.translate(tagLeft, 20); // if tag snp, draw little triangle pooper if (tags[z]) { g.drawImage(tagImage, left + z*CHAR_WIDTH, top + markerDigits*MARKER_CHAR_WIDTH + -(CHAR_HEIGHT - TAG_SPAN), null); } //g.rotate(-Math.PI / 2.0); //g.drawLine(0, 0, 0, 0); //g.setColor(Color.black); //g.drawString(nfMarker.format(markerNums[z]), 0, tagMiddle); char markerChars[] = nfMarker.format(Chromosome.realIndex[markerNums[z]]+1).toCharArray(); for (int m = 0; m < markerDigits; m++) { g.drawImage(markerNumImages[markerChars[m] - '0'], left + z*CHAR_WIDTH + (1 + CHAR_WIDTH - MARKER_CHAR_HEIGHT)/2, top + (markerDigits-m-1)*MARKER_CHAR_WIDTH, null); } // undo the transform.. no push/pop.. arrgh //g.rotate(Math.PI / 2.0); //g.translate(-tagLeft, -20); } // y position of the first image for the haplotype letter // top + the size of the marker digits + the size of the tag + // the character height centered in the row's height int above = top + markerDigits*MARKER_CHAR_WIDTH + TAG_SPAN + (ROW_HEIGHT - CHAR_HEIGHT) / 2; for (int j = 0; j < filteredHaplos[i].length; j++){ int curHapNum = lookupPos[i][j]; //String theHap = new String(); //String thePercentage = new String(); int[] theGeno = filteredHaplos[i][curHapNum].getGeno(); //getGeno(); // j is the row of haplotype for (int k = 0; k < theGeno.length; k++) { // theGeno[k] will be 1,2,3,4 (acgt) or 8 (for bad) if (!numAlls){ g.drawImage(charImages[theGeno[k] - 1], left + k*CHAR_WIDTH, above + j*ROW_HEIGHT, null); }else{ g.drawImage(blackNumImages[theGeno[k]], left + k*CHAR_WIDTH, above + j*ROW_HEIGHT, null); } } //draw the percentage value in non mono font double percent = filteredHaplos[i][curHapNum].getPercentage(); //thePercentage = " " + nf.format(percent); char percentChars[] = nf.format(percent).toCharArray(); // perhaps need an exceptional case for 1.0 being the percent for (int m = 0; m < percentChars.length; m++) { g.drawImage(grayNumImages[(m == 0) ? 10 : percentChars[m]-'0'], left + theGeno.length*CHAR_WIDTH + m*CHAR_WIDTH, above + j*ROW_HEIGHT, null); } // 4 is the number of chars in .999 for the percent textRight = left + theGeno.length*CHAR_WIDTH + 4*CHAR_WIDTH; g.setColor(Color.black); if (i < filteredHaplos.length - 1) { //draw crossovers for (int crossCount = 0; crossCount < filteredHaplos[i+1].length; crossCount++) { double crossVal = filteredHaplos[i][curHapNum].getCrossover(crossCount); //draw thin and thick lines int crossValue = (int) (crossVal*100); if (crossValue > thinThresh) { g.setStroke(crossValue > thickThresh ? thickStroke : thinStroke); int connectTo = filteredHaplos[i+1][crossCount].getListOrder(); g.drawLine(textRight + LINE_LEFT, above + j*ROW_HEIGHT + ROW_HEIGHT/2, textRight + LINE_RIGHT, above + connectTo*ROW_HEIGHT + ROW_HEIGHT/2); } } } } left = textRight; // add the multilocus d prime if appropriate if (i < filteredHaplos.length - 1) { //put the numbers in the right place vertically int depth; if (filteredHaplos[i].length > filteredHaplos[i+1].length){ depth = filteredHaplos[i].length; }else{ depth = filteredHaplos[i+1].length; } char multiChars[] = nfMulti.format(multidprimeArray[i]).toCharArray(); if (multidprimeArray[i] > 0.99){ //draw 1.0 vals specially g.drawImage(blackNumImages[1], left + (LINE_SPAN - 7*CHAR_WIDTH/2)/2 + CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); g.drawImage(blackNumImages[10], left + (LINE_SPAN - 9*CHAR_WIDTH/2)/2 + 2*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); g.drawImage(blackNumImages[0], left + (LINE_SPAN - 9*CHAR_WIDTH/2)/2 + 3*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); }else{ for (int m = 0; m < 3; m++) { g.drawImage(blackNumImages[(m == 0) ? 10 : multiChars[m]-'0'], left + (LINE_SPAN - 7*CHAR_WIDTH/2)/2 + m*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); } } } left += LINE_SPAN; } }
| 1,108,859
|
public void paintComponent(Graphics graphics) { if (filteredHaplos == null){ super.paintComponent(graphics); return; } Graphics2D g = (Graphics2D) graphics; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //System.out.println(getSize()); Dimension size = getSize(); Dimension pref = getPreferredSize(); g.setColor(this.getBackground()); g.fillRect(0,0,pref.width, pref.height); if (!forExport){ g.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } //g.drawRect(0, 0, pref.width, pref.height); final BasicStroke thinStroke = new BasicStroke(0.5f); final BasicStroke thickStroke = new BasicStroke(2.0f); // width of one letter of the haplotype block //int letterWidth = haploMetrics.charWidth('G'); //int percentWidth = pctMetrics.stringWidth(".000"); //final int verticalOffset = 43; // room for tags and diamonds int left = BORDER; int top = BORDER; //verticalOffset; //int totalWidth = 0; // percentages for each haplotype NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(3); nf.setMaximumFractionDigits(3); nf.setMinimumIntegerDigits(0); nf.setMaximumIntegerDigits(0); // multi reading, between the columns NumberFormat nfMulti = NumberFormat.getInstance(); nfMulti.setMinimumFractionDigits(2); nfMulti.setMaximumFractionDigits(2); nfMulti.setMinimumIntegerDigits(0); nfMulti.setMaximumIntegerDigits(0); int[][] lookupPos = new int[filteredHaplos.length][]; for (int p = 0; p < lookupPos.length; p++) { lookupPos[p] = new int[filteredHaplos[p].length]; for (int q = 0; q < lookupPos[p].length; q++){ lookupPos[p][filteredHaplos[p][q].getListOrder()] = q; } } // set number formatter to pad with appropriate number of zeroes NumberFormat nfMarker = NumberFormat.getInstance(); int markerCount = Chromosome.getSize(); // the +0.0000001 is because there is // some suckage where log(1000) / log(10) isn't actually 3 int markerDigits = (int) (0.0000001 + Math.log(markerCount) / Math.log(10)) + 1; nfMarker.setMinimumIntegerDigits(markerDigits); nfMarker.setMaximumIntegerDigits(markerDigits); //int tagShapeX[] = new int[3]; //int tagShapeY[] = new int[3]; //Polygon tagShape; int textRight = 0; // gets updated for scooting over // i = 0 to number of columns - 1 for (int i = 0; i < filteredHaplos.length; i++) { int[] markerNums = filteredHaplos[i][0].getMarkers(); boolean[] tags = filteredHaplos[i][0].getTags(); //int headerX = x; for (int z = 0; z < markerNums.length; z++) { //int tagMiddle = tagMetrics.getAscent() / 2; //int tagLeft = x + z*letterWidth + tagMiddle; //g.translate(tagLeft, 20); // if tag snp, draw little triangle pooper if (tags[z]) { g.drawImage(tagImage, left + z*CHAR_WIDTH, top + markerDigits*MARKER_CHAR_WIDTH + -(CHAR_HEIGHT - TAG_SPAN), null); } //g.rotate(-Math.PI / 2.0); //g.drawLine(0, 0, 0, 0); //g.setColor(Color.black); //g.drawString(nfMarker.format(markerNums[z]), 0, tagMiddle); char markerChars[] = nfMarker.format(Chromosome.realIndex[markerNums[z]]+1).toCharArray(); for (int m = 0; m < markerDigits; m++) { g.drawImage(markerNumImages[markerChars[m] - '0'], left + z*CHAR_WIDTH + (1 + CHAR_WIDTH - MARKER_CHAR_HEIGHT)/2, top + (markerDigits-m-1)*MARKER_CHAR_WIDTH, null); } // undo the transform.. no push/pop.. arrgh //g.rotate(Math.PI / 2.0); //g.translate(-tagLeft, -20); } // y position of the first image for the haplotype letter // top + the size of the marker digits + the size of the tag + // the character height centered in the row's height int above = top + markerDigits*MARKER_CHAR_WIDTH + TAG_SPAN + (ROW_HEIGHT - CHAR_HEIGHT) / 2; for (int j = 0; j < filteredHaplos[i].length; j++){ int curHapNum = lookupPos[i][j]; //String theHap = new String(); //String thePercentage = new String(); int[] theGeno = filteredHaplos[i][curHapNum].getGeno(); //getGeno(); // j is the row of haplotype for (int k = 0; k < theGeno.length; k++) { // theGeno[k] will be 1,2,3,4 (acgt) or 8 (for bad) if (!numAlls){ g.drawImage(charImages[theGeno[k] - 1], left + k*CHAR_WIDTH, above + j*ROW_HEIGHT, null); }else{ g.drawImage(blackNumImages[theGeno[k]], left + k*CHAR_WIDTH, above + j*ROW_HEIGHT, null); } } //draw the percentage value in non mono font double percent = filteredHaplos[i][curHapNum].getPercentage(); //thePercentage = " " + nf.format(percent); char percentChars[] = nf.format(percent).toCharArray(); // perhaps need an exceptional case for 1.0 being the percent for (int m = 0; m < percentChars.length; m++) { g.drawImage(grayNumImages[(m == 0) ? 10 : percentChars[m]-'0'], left + theGeno.length*CHAR_WIDTH + m*CHAR_WIDTH, above + j*ROW_HEIGHT, null); } // 4 is the number of chars in .999 for the percent textRight = left + theGeno.length*CHAR_WIDTH + 4*CHAR_WIDTH; g.setColor(Color.black); if (i < filteredHaplos.length - 1) { //draw crossovers for (int crossCount = 0; crossCount < filteredHaplos[i+1].length; crossCount++) { double crossVal = filteredHaplos[i][curHapNum].getCrossover(crossCount); //draw thin and thick lines int crossValue = (int) (crossVal*100); if (crossValue > thinThresh) { g.setStroke(crossValue > thickThresh ? thickStroke : thinStroke); int connectTo = filteredHaplos[i+1][crossCount].getListOrder(); g.drawLine(textRight + LINE_LEFT, above + j*ROW_HEIGHT + ROW_HEIGHT/2, textRight + LINE_RIGHT, above + connectTo*ROW_HEIGHT + ROW_HEIGHT/2); } } } } left = textRight; // add the multilocus d prime if appropriate if (i < filteredHaplos.length - 1) { //put the numbers in the right place vertically int depth; if (filteredHaplos[i].length > filteredHaplos[i+1].length){ depth = filteredHaplos[i].length; }else{ depth = filteredHaplos[i+1].length; } char multiChars[] = nfMulti.format(multidprimeArray[i]).toCharArray(); if (multidprimeArray[i] > 0.99){ //draw 1.0 vals specially g.drawImage(blackNumImages[1], left + (LINE_SPAN - 7*CHAR_WIDTH/2)/2 + CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); g.drawImage(blackNumImages[10], left + (LINE_SPAN - 9*CHAR_WIDTH/2)/2 + 2*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); g.drawImage(blackNumImages[0], left + (LINE_SPAN - 9*CHAR_WIDTH/2)/2 + 3*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); }else{ for (int m = 0; m < 3; m++) { g.drawImage(blackNumImages[(m == 0) ? 10 : multiChars[m]-'0'], left + (LINE_SPAN - 7*CHAR_WIDTH/2)/2 + m*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); } } } left += LINE_SPAN; } }
|
public void paintComponent(Graphics graphics) { if (filteredHaplos == null){ super.paintComponent(graphics); return; } Graphics2D g = (Graphics2D) graphics; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //System.out.println(getSize()); Dimension size = getSize(); Dimension pref = getPreferredSize(); g.setColor(this.getBackground()); g.fillRect(0,0,pref.width, pref.height); if (!forExport){ g.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } //g.drawRect(0, 0, pref.width, pref.height); final BasicStroke thinStroke = new BasicStroke(0.5f); final BasicStroke thickStroke = new BasicStroke(2.0f); // width of one letter of the haplotype block //int letterWidth = haploMetrics.charWidth('G'); //int percentWidth = pctMetrics.stringWidth(".000"); //final int verticalOffset = 43; // room for tags and diamonds int left = BORDER; int top = BORDER; //verticalOffset; //int totalWidth = 0; // percentages for each haplotype NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(3); nf.setMaximumFractionDigits(3); nf.setMinimumIntegerDigits(0); nf.setMaximumIntegerDigits(0); // multi reading, between the columns NumberFormat nfMulti = NumberFormat.getInstance(Locale.US); nfMulti.setMinimumFractionDigits(2); nfMulti.setMaximumFractionDigits(2); nfMulti.setMinimumIntegerDigits(0); nfMulti.setMaximumIntegerDigits(0); int[][] lookupPos = new int[filteredHaplos.length][]; for (int p = 0; p < lookupPos.length; p++) { lookupPos[p] = new int[filteredHaplos[p].length]; for (int q = 0; q < lookupPos[p].length; q++){ lookupPos[p][filteredHaplos[p][q].getListOrder()] = q; } } // set number formatter to pad with appropriate number of zeroes NumberFormat nfMarker = NumberFormat.getInstance(); int markerCount = Chromosome.getSize(); // the +0.0000001 is because there is // some suckage where log(1000) / log(10) isn't actually 3 int markerDigits = (int) (0.0000001 + Math.log(markerCount) / Math.log(10)) + 1; nfMarker.setMinimumIntegerDigits(markerDigits); nfMarker.setMaximumIntegerDigits(markerDigits); //int tagShapeX[] = new int[3]; //int tagShapeY[] = new int[3]; //Polygon tagShape; int textRight = 0; // gets updated for scooting over // i = 0 to number of columns - 1 for (int i = 0; i < filteredHaplos.length; i++) { int[] markerNums = filteredHaplos[i][0].getMarkers(); boolean[] tags = filteredHaplos[i][0].getTags(); //int headerX = x; for (int z = 0; z < markerNums.length; z++) { //int tagMiddle = tagMetrics.getAscent() / 2; //int tagLeft = x + z*letterWidth + tagMiddle; //g.translate(tagLeft, 20); // if tag snp, draw little triangle pooper if (tags[z]) { g.drawImage(tagImage, left + z*CHAR_WIDTH, top + markerDigits*MARKER_CHAR_WIDTH + -(CHAR_HEIGHT - TAG_SPAN), null); } //g.rotate(-Math.PI / 2.0); //g.drawLine(0, 0, 0, 0); //g.setColor(Color.black); //g.drawString(nfMarker.format(markerNums[z]), 0, tagMiddle); char markerChars[] = nfMarker.format(Chromosome.realIndex[markerNums[z]]+1).toCharArray(); for (int m = 0; m < markerDigits; m++) { g.drawImage(markerNumImages[markerChars[m] - '0'], left + z*CHAR_WIDTH + (1 + CHAR_WIDTH - MARKER_CHAR_HEIGHT)/2, top + (markerDigits-m-1)*MARKER_CHAR_WIDTH, null); } // undo the transform.. no push/pop.. arrgh //g.rotate(Math.PI / 2.0); //g.translate(-tagLeft, -20); } // y position of the first image for the haplotype letter // top + the size of the marker digits + the size of the tag + // the character height centered in the row's height int above = top + markerDigits*MARKER_CHAR_WIDTH + TAG_SPAN + (ROW_HEIGHT - CHAR_HEIGHT) / 2; for (int j = 0; j < filteredHaplos[i].length; j++){ int curHapNum = lookupPos[i][j]; //String theHap = new String(); //String thePercentage = new String(); int[] theGeno = filteredHaplos[i][curHapNum].getGeno(); //getGeno(); // j is the row of haplotype for (int k = 0; k < theGeno.length; k++) { // theGeno[k] will be 1,2,3,4 (acgt) or 8 (for bad) if (!numAlls){ g.drawImage(charImages[theGeno[k] - 1], left + k*CHAR_WIDTH, above + j*ROW_HEIGHT, null); }else{ g.drawImage(blackNumImages[theGeno[k]], left + k*CHAR_WIDTH, above + j*ROW_HEIGHT, null); } } //draw the percentage value in non mono font double percent = filteredHaplos[i][curHapNum].getPercentage(); //thePercentage = " " + nf.format(percent); char percentChars[] = nf.format(percent).toCharArray(); // perhaps need an exceptional case for 1.0 being the percent for (int m = 0; m < percentChars.length; m++) { g.drawImage(grayNumImages[(m == 0) ? 10 : percentChars[m]-'0'], left + theGeno.length*CHAR_WIDTH + m*CHAR_WIDTH, above + j*ROW_HEIGHT, null); } // 4 is the number of chars in .999 for the percent textRight = left + theGeno.length*CHAR_WIDTH + 4*CHAR_WIDTH; g.setColor(Color.black); if (i < filteredHaplos.length - 1) { //draw crossovers for (int crossCount = 0; crossCount < filteredHaplos[i+1].length; crossCount++) { double crossVal = filteredHaplos[i][curHapNum].getCrossover(crossCount); //draw thin and thick lines int crossValue = (int) (crossVal*100); if (crossValue > thinThresh) { g.setStroke(crossValue > thickThresh ? thickStroke : thinStroke); int connectTo = filteredHaplos[i+1][crossCount].getListOrder(); g.drawLine(textRight + LINE_LEFT, above + j*ROW_HEIGHT + ROW_HEIGHT/2, textRight + LINE_RIGHT, above + connectTo*ROW_HEIGHT + ROW_HEIGHT/2); } } } } left = textRight; // add the multilocus d prime if appropriate if (i < filteredHaplos.length - 1) { //put the numbers in the right place vertically int depth; if (filteredHaplos[i].length > filteredHaplos[i+1].length){ depth = filteredHaplos[i].length; }else{ depth = filteredHaplos[i+1].length; } char multiChars[] = nfMulti.format(multidprimeArray[i]).toCharArray(); if (multidprimeArray[i] > 0.99){ //draw 1.0 vals specially g.drawImage(blackNumImages[1], left + (LINE_SPAN - 7*CHAR_WIDTH/2)/2 + CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); g.drawImage(blackNumImages[10], left + (LINE_SPAN - 9*CHAR_WIDTH/2)/2 + 2*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); g.drawImage(blackNumImages[0], left + (LINE_SPAN - 9*CHAR_WIDTH/2)/2 + 3*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); }else{ for (int m = 0; m < 3; m++) { g.drawImage(blackNumImages[(m == 0) ? 10 : multiChars[m]-'0'], left + (LINE_SPAN - 7*CHAR_WIDTH/2)/2 + m*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); } } } left += LINE_SPAN; } }
| 1,108,860
|
public void paintComponent(Graphics graphics) { if (filteredHaplos == null){ super.paintComponent(graphics); return; } Graphics2D g = (Graphics2D) graphics; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //System.out.println(getSize()); Dimension size = getSize(); Dimension pref = getPreferredSize(); g.setColor(this.getBackground()); g.fillRect(0,0,pref.width, pref.height); if (!forExport){ g.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } //g.drawRect(0, 0, pref.width, pref.height); final BasicStroke thinStroke = new BasicStroke(0.5f); final BasicStroke thickStroke = new BasicStroke(2.0f); // width of one letter of the haplotype block //int letterWidth = haploMetrics.charWidth('G'); //int percentWidth = pctMetrics.stringWidth(".000"); //final int verticalOffset = 43; // room for tags and diamonds int left = BORDER; int top = BORDER; //verticalOffset; //int totalWidth = 0; // percentages for each haplotype NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(3); nf.setMaximumFractionDigits(3); nf.setMinimumIntegerDigits(0); nf.setMaximumIntegerDigits(0); // multi reading, between the columns NumberFormat nfMulti = NumberFormat.getInstance(); nfMulti.setMinimumFractionDigits(2); nfMulti.setMaximumFractionDigits(2); nfMulti.setMinimumIntegerDigits(0); nfMulti.setMaximumIntegerDigits(0); int[][] lookupPos = new int[filteredHaplos.length][]; for (int p = 0; p < lookupPos.length; p++) { lookupPos[p] = new int[filteredHaplos[p].length]; for (int q = 0; q < lookupPos[p].length; q++){ lookupPos[p][filteredHaplos[p][q].getListOrder()] = q; } } // set number formatter to pad with appropriate number of zeroes NumberFormat nfMarker = NumberFormat.getInstance(); int markerCount = Chromosome.getSize(); // the +0.0000001 is because there is // some suckage where log(1000) / log(10) isn't actually 3 int markerDigits = (int) (0.0000001 + Math.log(markerCount) / Math.log(10)) + 1; nfMarker.setMinimumIntegerDigits(markerDigits); nfMarker.setMaximumIntegerDigits(markerDigits); //int tagShapeX[] = new int[3]; //int tagShapeY[] = new int[3]; //Polygon tagShape; int textRight = 0; // gets updated for scooting over // i = 0 to number of columns - 1 for (int i = 0; i < filteredHaplos.length; i++) { int[] markerNums = filteredHaplos[i][0].getMarkers(); boolean[] tags = filteredHaplos[i][0].getTags(); //int headerX = x; for (int z = 0; z < markerNums.length; z++) { //int tagMiddle = tagMetrics.getAscent() / 2; //int tagLeft = x + z*letterWidth + tagMiddle; //g.translate(tagLeft, 20); // if tag snp, draw little triangle pooper if (tags[z]) { g.drawImage(tagImage, left + z*CHAR_WIDTH, top + markerDigits*MARKER_CHAR_WIDTH + -(CHAR_HEIGHT - TAG_SPAN), null); } //g.rotate(-Math.PI / 2.0); //g.drawLine(0, 0, 0, 0); //g.setColor(Color.black); //g.drawString(nfMarker.format(markerNums[z]), 0, tagMiddle); char markerChars[] = nfMarker.format(Chromosome.realIndex[markerNums[z]]+1).toCharArray(); for (int m = 0; m < markerDigits; m++) { g.drawImage(markerNumImages[markerChars[m] - '0'], left + z*CHAR_WIDTH + (1 + CHAR_WIDTH - MARKER_CHAR_HEIGHT)/2, top + (markerDigits-m-1)*MARKER_CHAR_WIDTH, null); } // undo the transform.. no push/pop.. arrgh //g.rotate(Math.PI / 2.0); //g.translate(-tagLeft, -20); } // y position of the first image for the haplotype letter // top + the size of the marker digits + the size of the tag + // the character height centered in the row's height int above = top + markerDigits*MARKER_CHAR_WIDTH + TAG_SPAN + (ROW_HEIGHT - CHAR_HEIGHT) / 2; for (int j = 0; j < filteredHaplos[i].length; j++){ int curHapNum = lookupPos[i][j]; //String theHap = new String(); //String thePercentage = new String(); int[] theGeno = filteredHaplos[i][curHapNum].getGeno(); //getGeno(); // j is the row of haplotype for (int k = 0; k < theGeno.length; k++) { // theGeno[k] will be 1,2,3,4 (acgt) or 8 (for bad) if (!numAlls){ g.drawImage(charImages[theGeno[k] - 1], left + k*CHAR_WIDTH, above + j*ROW_HEIGHT, null); }else{ g.drawImage(blackNumImages[theGeno[k]], left + k*CHAR_WIDTH, above + j*ROW_HEIGHT, null); } } //draw the percentage value in non mono font double percent = filteredHaplos[i][curHapNum].getPercentage(); //thePercentage = " " + nf.format(percent); char percentChars[] = nf.format(percent).toCharArray(); // perhaps need an exceptional case for 1.0 being the percent for (int m = 0; m < percentChars.length; m++) { g.drawImage(grayNumImages[(m == 0) ? 10 : percentChars[m]-'0'], left + theGeno.length*CHAR_WIDTH + m*CHAR_WIDTH, above + j*ROW_HEIGHT, null); } // 4 is the number of chars in .999 for the percent textRight = left + theGeno.length*CHAR_WIDTH + 4*CHAR_WIDTH; g.setColor(Color.black); if (i < filteredHaplos.length - 1) { //draw crossovers for (int crossCount = 0; crossCount < filteredHaplos[i+1].length; crossCount++) { double crossVal = filteredHaplos[i][curHapNum].getCrossover(crossCount); //draw thin and thick lines int crossValue = (int) (crossVal*100); if (crossValue > thinThresh) { g.setStroke(crossValue > thickThresh ? thickStroke : thinStroke); int connectTo = filteredHaplos[i+1][crossCount].getListOrder(); g.drawLine(textRight + LINE_LEFT, above + j*ROW_HEIGHT + ROW_HEIGHT/2, textRight + LINE_RIGHT, above + connectTo*ROW_HEIGHT + ROW_HEIGHT/2); } } } } left = textRight; // add the multilocus d prime if appropriate if (i < filteredHaplos.length - 1) { //put the numbers in the right place vertically int depth; if (filteredHaplos[i].length > filteredHaplos[i+1].length){ depth = filteredHaplos[i].length; }else{ depth = filteredHaplos[i+1].length; } char multiChars[] = nfMulti.format(multidprimeArray[i]).toCharArray(); if (multidprimeArray[i] > 0.99){ //draw 1.0 vals specially g.drawImage(blackNumImages[1], left + (LINE_SPAN - 7*CHAR_WIDTH/2)/2 + CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); g.drawImage(blackNumImages[10], left + (LINE_SPAN - 9*CHAR_WIDTH/2)/2 + 2*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); g.drawImage(blackNumImages[0], left + (LINE_SPAN - 9*CHAR_WIDTH/2)/2 + 3*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); }else{ for (int m = 0; m < 3; m++) { g.drawImage(blackNumImages[(m == 0) ? 10 : multiChars[m]-'0'], left + (LINE_SPAN - 7*CHAR_WIDTH/2)/2 + m*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); } } } left += LINE_SPAN; } }
|
public void paintComponent(Graphics graphics) { if (filteredHaplos == null){ super.paintComponent(graphics); return; } Graphics2D g = (Graphics2D) graphics; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //System.out.println(getSize()); Dimension size = getSize(); Dimension pref = getPreferredSize(); g.setColor(this.getBackground()); g.fillRect(0,0,pref.width, pref.height); if (!forExport){ g.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); } //g.drawRect(0, 0, pref.width, pref.height); final BasicStroke thinStroke = new BasicStroke(0.5f); final BasicStroke thickStroke = new BasicStroke(2.0f); // width of one letter of the haplotype block //int letterWidth = haploMetrics.charWidth('G'); //int percentWidth = pctMetrics.stringWidth(".000"); //final int verticalOffset = 43; // room for tags and diamonds int left = BORDER; int top = BORDER; //verticalOffset; //int totalWidth = 0; // percentages for each haplotype NumberFormat nf = NumberFormat.getInstance(); nf.setMinimumFractionDigits(3); nf.setMaximumFractionDigits(3); nf.setMinimumIntegerDigits(0); nf.setMaximumIntegerDigits(0); // multi reading, between the columns NumberFormat nfMulti = NumberFormat.getInstance(); nfMulti.setMinimumFractionDigits(2); nfMulti.setMaximumFractionDigits(2); nfMulti.setMinimumIntegerDigits(0); nfMulti.setMaximumIntegerDigits(0); int[][] lookupPos = new int[filteredHaplos.length][]; for (int p = 0; p < lookupPos.length; p++) { lookupPos[p] = new int[filteredHaplos[p].length]; for (int q = 0; q < lookupPos[p].length; q++){ lookupPos[p][filteredHaplos[p][q].getListOrder()] = q; } } // set number formatter to pad with appropriate number of zeroes NumberFormat nfMarker = NumberFormat.getInstance(Locale.US); int markerCount = Chromosome.getSize(); // the +0.0000001 is because there is // some suckage where log(1000) / log(10) isn't actually 3 int markerDigits = (int) (0.0000001 + Math.log(markerCount) / Math.log(10)) + 1; nfMarker.setMinimumIntegerDigits(markerDigits); nfMarker.setMaximumIntegerDigits(markerDigits); //int tagShapeX[] = new int[3]; //int tagShapeY[] = new int[3]; //Polygon tagShape; int textRight = 0; // gets updated for scooting over // i = 0 to number of columns - 1 for (int i = 0; i < filteredHaplos.length; i++) { int[] markerNums = filteredHaplos[i][0].getMarkers(); boolean[] tags = filteredHaplos[i][0].getTags(); //int headerX = x; for (int z = 0; z < markerNums.length; z++) { //int tagMiddle = tagMetrics.getAscent() / 2; //int tagLeft = x + z*letterWidth + tagMiddle; //g.translate(tagLeft, 20); // if tag snp, draw little triangle pooper if (tags[z]) { g.drawImage(tagImage, left + z*CHAR_WIDTH, top + markerDigits*MARKER_CHAR_WIDTH + -(CHAR_HEIGHT - TAG_SPAN), null); } //g.rotate(-Math.PI / 2.0); //g.drawLine(0, 0, 0, 0); //g.setColor(Color.black); //g.drawString(nfMarker.format(markerNums[z]), 0, tagMiddle); char markerChars[] = nfMarker.format(Chromosome.realIndex[markerNums[z]]+1).toCharArray(); for (int m = 0; m < markerDigits; m++) { g.drawImage(markerNumImages[markerChars[m] - '0'], left + z*CHAR_WIDTH + (1 + CHAR_WIDTH - MARKER_CHAR_HEIGHT)/2, top + (markerDigits-m-1)*MARKER_CHAR_WIDTH, null); } // undo the transform.. no push/pop.. arrgh //g.rotate(Math.PI / 2.0); //g.translate(-tagLeft, -20); } // y position of the first image for the haplotype letter // top + the size of the marker digits + the size of the tag + // the character height centered in the row's height int above = top + markerDigits*MARKER_CHAR_WIDTH + TAG_SPAN + (ROW_HEIGHT - CHAR_HEIGHT) / 2; for (int j = 0; j < filteredHaplos[i].length; j++){ int curHapNum = lookupPos[i][j]; //String theHap = new String(); //String thePercentage = new String(); int[] theGeno = filteredHaplos[i][curHapNum].getGeno(); //getGeno(); // j is the row of haplotype for (int k = 0; k < theGeno.length; k++) { // theGeno[k] will be 1,2,3,4 (acgt) or 8 (for bad) if (!numAlls){ g.drawImage(charImages[theGeno[k] - 1], left + k*CHAR_WIDTH, above + j*ROW_HEIGHT, null); }else{ g.drawImage(blackNumImages[theGeno[k]], left + k*CHAR_WIDTH, above + j*ROW_HEIGHT, null); } } //draw the percentage value in non mono font double percent = filteredHaplos[i][curHapNum].getPercentage(); //thePercentage = " " + nf.format(percent); char percentChars[] = nf.format(percent).toCharArray(); // perhaps need an exceptional case for 1.0 being the percent for (int m = 0; m < percentChars.length; m++) { g.drawImage(grayNumImages[(m == 0) ? 10 : percentChars[m]-'0'], left + theGeno.length*CHAR_WIDTH + m*CHAR_WIDTH, above + j*ROW_HEIGHT, null); } // 4 is the number of chars in .999 for the percent textRight = left + theGeno.length*CHAR_WIDTH + 4*CHAR_WIDTH; g.setColor(Color.black); if (i < filteredHaplos.length - 1) { //draw crossovers for (int crossCount = 0; crossCount < filteredHaplos[i+1].length; crossCount++) { double crossVal = filteredHaplos[i][curHapNum].getCrossover(crossCount); //draw thin and thick lines int crossValue = (int) (crossVal*100); if (crossValue > thinThresh) { g.setStroke(crossValue > thickThresh ? thickStroke : thinStroke); int connectTo = filteredHaplos[i+1][crossCount].getListOrder(); g.drawLine(textRight + LINE_LEFT, above + j*ROW_HEIGHT + ROW_HEIGHT/2, textRight + LINE_RIGHT, above + connectTo*ROW_HEIGHT + ROW_HEIGHT/2); } } } } left = textRight; // add the multilocus d prime if appropriate if (i < filteredHaplos.length - 1) { //put the numbers in the right place vertically int depth; if (filteredHaplos[i].length > filteredHaplos[i+1].length){ depth = filteredHaplos[i].length; }else{ depth = filteredHaplos[i+1].length; } char multiChars[] = nfMulti.format(multidprimeArray[i]).toCharArray(); if (multidprimeArray[i] > 0.99){ //draw 1.0 vals specially g.drawImage(blackNumImages[1], left + (LINE_SPAN - 7*CHAR_WIDTH/2)/2 + CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); g.drawImage(blackNumImages[10], left + (LINE_SPAN - 9*CHAR_WIDTH/2)/2 + 2*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); g.drawImage(blackNumImages[0], left + (LINE_SPAN - 9*CHAR_WIDTH/2)/2 + 3*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); }else{ for (int m = 0; m < 3; m++) { g.drawImage(blackNumImages[(m == 0) ? 10 : multiChars[m]-'0'], left + (LINE_SPAN - 7*CHAR_WIDTH/2)/2 + m*CHAR_WIDTH, above + (depth * ROW_HEIGHT), null); } } } left += LINE_SPAN; } }
| 1,108,861
|
public void doTag(final XMLOutput output) throws Exception { AttainTag attainTag = (AttainTag) findAncestorWithClass( AttainTag.class ); Session session = null; if ( attainTag == null ) { session = new JellySession( output ); } else { session = attainTag.getSession(); } ProjectTag projectTag = (ProjectTag) findAncestorWithClass( ProjectTag.class ); Project project = projectTag.getProject(); getBody().run(context, output); project.attainGoal( getName(), session ); }
|
public void doTag(final XMLOutput output) throws Exception { AttainTag attainTag = (AttainTag) findAncestorWithClass( AttainTag.class ); Session session = null; if ( attainTag == null ) { session = new JellySession( output ); } else { session = attainTag.getSession(); } ProjectTag projectTag = (ProjectTag) findAncestorWithClass( ProjectTag.class ); Project project = projectTag.getProject(); invokeBody(output); project.attainGoal( getName(), session ); }
| 1,108,863
|
public void doTag(XMLOutput output) throws Exception { Test test = getTest(); if ( test == null ) { test = (Test) context.getVariable("org.apache.commons.jelly.junit.suite"); } if ( test == null ) { throw new MissingAttributeException( "test" ); } TestResult result = getResult(); if ( result == null ) { result = createResult(output); } TestListener listener = getListener(); if ( listener == null ) { listener = createTestListener(output); } result.addListener(listener); test.run(result); }
|
public void doTag(XMLOutput output) throws JellyTagException { Test test = getTest(); if ( test == null ) { test = (Test) context.getVariable("org.apache.commons.jelly.junit.suite"); } if ( test == null ) { throw new MissingAttributeException( "test" ); } TestResult result = getResult(); if ( result == null ) { result = createResult(output); } TestListener listener = getListener(); if ( listener == null ) { listener = createTestListener(output); } result.addListener(listener); test.run(result); }
| 1,108,865
|
DPrimeDisplay(HaploData h){ theData=h; this.setDoubleBuffered(true); addMouseListener(new PopMouseListener(this)); }
|
DPrimeDisplay(HaploData h){ theData=h; this.setDoubleBuffered(true); addMouseListener(this); addMouseMotionListener(this); }
| 1,108,868
|
public Dimension getPreferredSize() { //loop through table to find deepest non-null comparison PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; int count = 0; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] != null){ if (count < y-x){ count = y-x; } } } } //add one so we don't clip bottom box count ++; int high = 2*V_BORDER + count*boxSize/2; chartSize = new Dimension(2*H_BORDER + boxSize*(dPrimeTable.length-1),high); //this dimension is just the area taken up by the dprime chart //it is used in drawing the worldmap if (theData.infoKnown){ infoHeight = TICK_BOTTOM + widestMarkerName + TEXT_GAP; high += infoHeight; }else{ infoHeight=0; } return new Dimension(2*H_BORDER + boxSize*(dPrimeTable.length-1), high); }
|
public Dimension getPreferredSize() { //loop through table to find deepest non-null comparison PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; int count = 0; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] != null){ if (count < y-x){ count = y-x; } } } } //add one so we don't clip bottom box count ++; Graphics g = this.getGraphics(); g.setFont(markerNameFont); FontMetrics fm = g.getFontMetrics(); blockDispHeight = boxSize/2 + fm.getAscent(); int high = 2*V_BORDER + count*boxSize/2 + blockDispHeight; chartSize = new Dimension(2*H_BORDER + boxSize*(dPrimeTable.length-1),high); //this dimension is just the area taken up by the dprime chart //it is used in drawing the worldmap if (theData.infoKnown){ infoHeight = TICK_BOTTOM + widestMarkerName + TEXT_GAP; high += infoHeight; }else{ infoHeight=0; } return new Dimension(2*H_BORDER + boxSize*(dPrimeTable.length-1), high); }
| 1,108,869
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[Chromosome.realIndex[j]]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
| 1,108,870
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
| 1,108,871
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/wmMaxWidth; CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
| 1,108,872
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/scalefactor)+wmBorder.getBorderInsets(this).top*2+WM_BD_TOTAL, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
| 1,108,873
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-1,worldmap.getHeight()-1); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
| 1,108,874
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
| 1,108,875
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top + WM_BD_TOTAL; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
| 1,108,876
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top+WM_BD_GAP, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
| 1,108,877
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
|
public void paintComponent(Graphics g){ PairwiseLinkage[][] dPrimeTable = theData.filteredDPrimeTable; Vector blocks = theData.blocks; Graphics2D g2 = (Graphics2D) g; Dimension size = getSize(); Dimension pref = getPreferredSize(); Rectangle visRect = getVisibleRect(); /* boxSize = ((clipRect.width-2*H_BORDER)/dPrimeTable.length-1); if (boxSize < 12){boxSize=12;} if (boxSize < 25){ printDetails = false; boxRadius = boxSize/2; }else{ boxRadius = boxSize/2 - 1; } */ //okay so this dumb if block is to prevent the ugly repainting //bug when loading markers after the data are already being displayed, //results in a little off-centering for small datasets, but not too bad. //clickxshift and clickyshift are used later to translate from x,y coords //to the pair of markers comparison at those coords if (!(theData.infoKnown)){ g2.translate((size.width - pref.width) / 2, (size.height - pref.height) / 2); clickXShift = left + (size.width-pref.width)/2; clickYShift = top + (size.height - pref.height)/2; } else { g2.translate((size.width - pref.width) / 2, 0); clickXShift = left + (size.width-pref.width)/2; clickYShift = top; } FontMetrics boxFontMetrics = g2.getFontMetrics(boxFont); int diamondX[] = new int[4]; int diamondY[] = new int[4]; Polygon diamond; left = H_BORDER; top = V_BORDER; FontMetrics metrics; int ascent; g2.setColor(this.getBackground()); g2.fillRect(0,0,pref.width,pref.height); g2.setColor(Color.black); BasicStroke thickerStroke = new BasicStroke(1); BasicStroke thinnerStroke = new BasicStroke(0.35f); BasicStroke fatStroke = new BasicStroke(2.5f); float dash1[] = {5.0f}; BasicStroke dashedFatStroke = new BasicStroke(2.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 5.0f, dash1, 0.0f); g2.setFont(markerNameFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); if (theData.infoKnown) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //// draw the marker locations int wide = (dPrimeTable.length-1) * boxSize; //TODO: talk to kirby about locusview scaling gizmo int lineLeft = wide/20; int lineSpan = (wide/10)*9; long minpos = Chromosome.getMarker(0).getPosition(); long maxpos = Chromosome.getMarker(Chromosome.getSize()-1).getPosition(); double spanpos = maxpos - minpos; g2.setStroke(thinnerStroke); g2.setColor(Color.white); g2.fillRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); g2.setColor(Color.black); g2.drawRect(left + lineLeft, 5, lineSpan, TICK_HEIGHT); for (int i = 0; i < Chromosome.getFilteredSize(); i++) { double pos = (Chromosome.getFilteredMarker(i).getPosition() - minpos) / spanpos; int xx = (int) (left + lineLeft + lineSpan*pos); g2.setStroke(thickerStroke); g2.drawLine(xx, 5, xx, 5 + TICK_HEIGHT); g2.setStroke(thinnerStroke); g2.drawLine(xx, 5 + TICK_HEIGHT, left + i*boxSize, TICK_BOTTOM); } top += TICK_BOTTOM; //// draw the marker names if (printDetails){ widestMarkerName = metrics.stringWidth(Chromosome.getFilteredMarker(0).getName()); for (int x = 1; x < dPrimeTable.length; x++) { int thiswide = metrics.stringWidth(Chromosome.getFilteredMarker(x).getName()); if (thiswide > widestMarkerName) widestMarkerName = thiswide; } g2.translate(left, top + widestMarkerName); g2.rotate(-Math.PI / 2.0); for (int x = 0; x < dPrimeTable.length; x++) { if (theData.isInBlock[Chromosome.realIndex[x]]){ g2.setFont(boldMarkerNameFont); }else{ g2.setFont(markerNameFont); } g2.drawString(Chromosome.getFilteredMarker(x).getName(),TEXT_GAP, x*boxSize + ascent/3); } g2.rotate(Math.PI / 2.0); g2.translate(-left, -(top + widestMarkerName)); // move everybody down top += widestMarkerName + TEXT_GAP; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } blockDispHeight = ascent+boxSize/2; top += blockDispHeight; //// draw the marker numbers if (printDetails){ g2.setFont(markerNumFont); metrics = g2.getFontMetrics(); ascent = metrics.getAscent(); for (int x = 0; x < dPrimeTable.length; x++) { String mark = String.valueOf(Chromosome.realIndex[x] + 1); g2.drawString(mark, left + x*boxSize - metrics.stringWidth(mark)/2, top + ascent); } top += boxRadius/2; // give a little space between numbers and boxes } //the following values are the bounds on the boxes we want to //display given that the current window is 'visRect' lowX = (visRect.x-clickXShift-(visRect.y + visRect.height-clickYShift))/boxSize; if (lowX < 0) { lowX = 0; } highX = ((visRect.x + visRect.width)/boxSize)+1; if (highX > dPrimeTable.length-1){ highX = dPrimeTable.length-1; } lowY = ((visRect.x-clickXShift)+(visRect.y-clickYShift))/boxSize; if (lowY < lowX+1){ lowY = lowX+1; } highY = (((visRect.x-clickXShift+visRect.width) + (visRect.y-clickYShift+visRect.height))/boxSize)+1; if (highY > dPrimeTable.length){ highY = dPrimeTable.length; } // draw table column by column for (int x = lowX; x < highX; x++) { //always draw the fewest possible boxes if (lowY < x+1){ lowY = x+1; } for (int y = lowY; y < highY; y++) { if (dPrimeTable[x][y] == null){ continue; } double d = dPrimeTable[x][y].getDPrime(); //double l = dPrimeTable[x][y].getLOD(); Color boxColor = dPrimeTable[x][y].getColor(); // draw markers above int xx = left + (x + y) * boxSize / 2; int yy = top + (y - x) * boxSize / 2; diamondX[0] = xx; diamondY[0] = yy - boxRadius; diamondX[1] = xx + boxRadius; diamondY[1] = yy; diamondX[2] = xx; diamondY[2] = yy + boxRadius; diamondX[3] = xx - boxRadius; diamondY[3] = yy; diamond = new Polygon(diamondX, diamondY, 4); g2.setColor(boxColor); g2.fillPolygon(diamond); if (boxColor == Color.white) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.lightGray); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } if(printDetails){ g2.setFont(boxFont); ascent = boxFontMetrics.getAscent(); int val = (int) (d * 100); g2.setColor((val < 50) ? Color.gray : Color.black); if (val != 100) { String valu = String.valueOf(val); int widf = boxFontMetrics.stringWidth(valu); g.drawString(valu, xx - widf/2, yy + ascent/2); } } } } //highlight blocks boolean even = true; g2.setFont(markerNameFont); ascent = g2.getFontMetrics().getAscent(); //g.setColor(new Color(153,255,153)); g2.setColor(Color.black); //g.setColor(new Color(51,153,51)); for (int i = 0; i < blocks.size(); i++){ int[] theBlock = (int[])blocks.elementAt(i); int first = theBlock[0]; int last = theBlock[theBlock.length-1]; //big vee around whole thing g2.setStroke(fatStroke); g2.drawLine(left + (2*first) * boxSize/2 - boxRadius, top, left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius); g2.drawLine(left + (first + last) * boxSize/2, top + (last - first) * boxSize/2 + boxRadius, left + (2*last) * boxSize/2+boxRadius, top); for (int j = first; j <= last; j++){ if (theData.isInBlock[j]){ g2.setStroke(fatStroke); }else{ g2.setStroke(dashedFatStroke); } g2.drawLine(left+j*boxSize-boxSize/2, top-blockDispHeight, left+j*boxSize+boxSize/2, top-blockDispHeight); /* //little vees on top of each marker g2.drawLine(left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]) * boxSize/2 + boxRadius, top+1); g2.drawLine (left + (2*theBlock[j+1]) * boxSize/2, top + boxSize/2, left + (2*theBlock[j+1]-1) * boxSize/2, top); */ } //special lines for fencepost markers /*g2.drawLine(left+first*boxSize+1, top+boxRadius, left+first*boxSize+boxRadius, top+1); g2.drawLine(left+last*boxSize-1, top+boxRadius, left+last*boxSize-boxRadius, top+1); */ //lines to connect to block display g2.setStroke(fatStroke); g2.drawLine(left + first*boxSize-boxSize/2, top-1, left+first*boxSize-boxSize/2, top-blockDispHeight); g2.drawLine(left+last*boxSize+boxSize/2, top-1, left+last*boxSize+boxSize/2, top-blockDispHeight); String labelString = new String ("Block " + (i+1)); g2.drawString(labelString, left+first*boxSize-boxSize/2+TEXT_GAP, top-boxSize/2); } g2.setStroke(thickerStroke); if (pref.getWidth() > (2*visRect.width)){ //dataset is big enough to require worldmap if (noImage){ //first time through draw a worldmap if dataset is big: final int WM_BD_HEIGHT = 4; final int WM_MAX_WIDTH = visRect.width/3; double sizingScalefactor; sizingScalefactor = (double) (chartSize.width)/WM_MAX_WIDTH; double scalefactor; scalefactor = (double)(chartSize.width)/(WM_MAX_WIDTH-WM_BD_HEIGHT*4); CompoundBorder wmBorder = new CompoundBorder(BorderFactory.createRaisedBevelBorder(), BorderFactory.createLoweredBevelBorder()); worldmap = new BufferedImage((int)(chartSize.width/scalefactor)+wmBorder.getBorderInsets(this).left*2, (int)(chartSize.height/sizingScalefactor)+wmBorder.getBorderInsets(this).top*2, BufferedImage.TYPE_3BYTE_BGR); Graphics gw = worldmap.getGraphics(); Graphics2D gw2 = (Graphics2D)(gw); gw2.setColor(this.getBackground()); gw2.fillRect(1,1,worldmap.getWidth()-2,worldmap.getHeight()-2); //make a pretty border gw2.setColor(Color.black); wmBorder.paintBorder(this,gw2,0,0,worldmap.getWidth()-1,worldmap.getHeight()-1); ir = wmBorder.getInteriorRectangle(this,0,0,worldmap.getWidth()-1, worldmap.getHeight()-1); ir.height -= WM_BD_HEIGHT; double prefBoxSize = boxSize/scalefactor; float[] smallDiamondX = new float[4]; float[] smallDiamondY = new float[4]; GeneralPath gp; for (int x = 0; x < dPrimeTable.length-1; x++){ for (int y = x+1; y < dPrimeTable.length; y++){ if (dPrimeTable[x][y] == null){ continue; } double xx = (x + y)*prefBoxSize/2+wmBorder.getBorderInsets(this).left; double yy = (y - x)*prefBoxSize/2+wmBorder.getBorderInsets(this).top+WM_BD_HEIGHT; smallDiamondX[0] = (float)xx; smallDiamondY[0] = (float)(yy - prefBoxSize/2); smallDiamondX[1] = (float)(xx + prefBoxSize/2); smallDiamondY[1] = (float)yy; smallDiamondX[2] = (float)xx; smallDiamondY[2] = (float)(yy + prefBoxSize/2); smallDiamondX[3] = (float)(xx - prefBoxSize/2); smallDiamondY[3] = (float)yy; gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, smallDiamondX.length); gp.moveTo(smallDiamondX[0],smallDiamondY[0]); for (int i = 1; i < smallDiamondX.length; i++){ gp.lineTo(smallDiamondX[i], smallDiamondY[i]); } gp.closePath(); gw2.setColor(dPrimeTable[x][y].getColor()); gw2.fill(gp); } } //draw block display in worldmap gw2.setColor(this.getBackground()); gw2.fillRect(wmBorder.getBorderInsets(this).left, wmBorder.getBorderInsets(this).top, ir.width, WM_BD_HEIGHT); gw2.setColor(Color.black); even = true; for (int i = 0; i < blocks.size(); i++){ int first = ((int[])blocks.elementAt(i))[0]; int last = ((int[])blocks.elementAt(i))[((int[])blocks.elementAt(i)).length-1]; int voffset; if (even){ voffset = 0; }else{ voffset = WM_BD_HEIGHT/2; } gw2.fillRect(wmBorder.getBorderInsets(this).left+(int)(prefBoxSize*first), wmBorder.getBorderInsets(this).top+voffset, (int)((last-first)*prefBoxSize), WM_BD_HEIGHT/2); even = !even; } noImage = false; } g2.drawImage(worldmap,visRect.x, visRect.y + visRect.height - worldmap.getHeight(), this); worldmapRect = new Rectangle(visRect.x, visRect.y+visRect.height-worldmap.getHeight(), worldmap.getWidth(), worldmap.getHeight()); //draw the outline of the viewport g2.setColor(Color.black); double hRatio = ir.getWidth()/pref.getWidth(); double vRatio = ir.getHeight()/pref.getHeight(); int hBump = worldmap.getWidth()-ir.width; int vBump = worldmap.getHeight()-ir.height; //bump a few pixels to avoid drawing on the border g2.drawRect((int)(visRect.x*hRatio)+hBump/2+visRect.x, (int)(visRect.y*vRatio)+vBump/2+(visRect.y + visRect.height - worldmap.getHeight()), (int)(visRect.width*hRatio), (int)(visRect.height*vRatio)); } }
| 1,108,878
|
private void processFile(String fileName, int fileType, String infoFileName){ try { HaploData textData; File OutputFile; File inputFile; if(!quietMode && fileName != null){ System.out.println("Using data file " + fileName); } inputFile = new File(fileName); if(!inputFile.exists()){ System.out.println("input file: " + fileName + " does not exist"); System.exit(1); } textData = new HaploData(); Vector result = null; if(fileType == HAPS){ //read in haps file textData.prepareHapsInput(inputFile); } else if (fileType == PED) { //read in ped file /* if(this.arg_ignoreMarkers.size()>0) { for(int i=0;i<this.arg_ignoreMarkers.size();i++){ int index = Integer.parseInt((String)this.arg_ignoreMarkers.get(i)); if(index>0 && index<markerResultArray.length){ markerResultArray[index] = false; if(!this.quietMode) { System.out.println("Ignoring marker " + (index)); } } } }*/ result = textData.linkageToChrom(inputFile, 3, skipCheck); if(textData.getPedFile().isBogusParents()) { System.out.println("Error: One or more individuals in the file reference non-existent parents.\nThese references have been ignored."); } }else{ //read in hapmapfile result = textData.linkageToChrom(inputFile,4,skipCheck); } File infoFile = null; if (infoFileName != null){ infoFile = new File(infoFileName); } if (result != null){ textData.prepareMarkerInput(infoFile,textData.getPedFile().getHMInfo()); }else{ textData.prepareMarkerInput(infoFile,null); } if(!quietMode && infoFile != null){ System.out.println("Using marker file " + infoFile.getName()); } if(outputCheck && result != null){ CheckDataPanel cp = new CheckDataPanel(textData); cp.printTable(validateOutputFile(fileName + ".CHECK")); } Vector cust = new Vector(); if(outputType != -1){ textData.generateDPrimeTable(); Haplotype[][] haplos; switch(outputType){ case BLOX_GABRIEL: OutputFile = validateOutputFile(fileName + ".GABRIELblocks"); break; case BLOX_4GAM: OutputFile = validateOutputFile(fileName + ".4GAMblocks"); break; case BLOX_SPINE: OutputFile = validateOutputFile(fileName + ".SPINEblocks"); break; case BLOX_CUSTOM: OutputFile = validateOutputFile(fileName + ".CUSTblocks"); //read in the blocks file File blocksFile = new File(blockFileName); cust = textData.readBlocks(blocksFile); break; default: OutputFile = validateOutputFile(fileName + ".GABRIELblocks"); break; } //this handles output type ALL if(outputType == BLOX_ALL) { OutputFile = validateOutputFile(fileName + ".GABRIELblocks"); textData.guessBlocks(BLOX_GABRIEL); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); OutputFile = validateOutputFile(fileName + ".4GAMblocks"); textData.guessBlocks(BLOX_4GAM); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); OutputFile = validateOutputFile(fileName + ".SPINEblocks"); textData.guessBlocks(BLOX_SPINE); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); }else{ textData.guessBlocks(outputType, cust); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); } //todo: should this output hap assoc for each block type if they do more than one? if(Options.getAssocTest() == ASSOC_TRIO || Options.getAssocTest() == ASSOC_CC) { //Haplotype[][] orderedHaps = orderHaps(textData.getHaplotypes()); HaploData.saveHapAssocToText(haplos, fileName + ".HAPASSOC"); } } if(outputDprime) { OutputFile = validateOutputFile(fileName + ".LD"); if (textData.dpTable != null){ textData.saveDprimeToText(OutputFile, TABLE_TYPE, 0, Chromosome.getSize()); }else{ textData.saveDprimeToText(OutputFile, LIVE_TYPE, 0, Chromosome.getSize()); } } if (outputPNG || outputCompressedPNG){ OutputFile = validateOutputFile(fileName + ".LD.PNG"); if (textData.dpTable == null){ textData.generateDPrimeTable(); textData.guessBlocks(BLOX_CUSTOM, new Vector()); } if (trackFileName != null){ textData.readAnalysisTrack(new File(trackFileName)); } DPrimeDisplay dpd = new DPrimeDisplay(textData); BufferedImage i = dpd.export(0,Chromosome.getSize(),outputCompressedPNG); try{ Jimi.putImage("image/png", i, OutputFile.getName()); }catch(JimiException je){ System.out.println(je.getMessage()); } } if(Options.getAssocTest() == ASSOC_TRIO){ Vector tdtResults = TDT.calcTrioTDT(textData.getPedFile()); HaploData.saveMarkerAssocToText(tdtResults, fileName + ".ASSOC"); } else if(Options.getAssocTest() == ASSOC_CC) { Vector ccResults = TDT.calcCCTDT(textData.getPedFile()); HaploData.saveMarkerAssocToText(ccResults, fileName + ".ASSOC"); } } catch(IOException e){ System.err.println("An error has occured. This probably has to do with file input or output"); } catch(HaploViewException e){ System.err.println(e.getMessage()); } catch(PedFileException pfe) { System.err.println(pfe.getMessage()); } }
|
private void processFile(String fileName, int fileType, String infoFileName){ try { HaploData textData; File OutputFile; File inputFile; if(!quietMode && fileName != null){ System.out.println("Using data file " + fileName); } inputFile = new File(fileName); if(!inputFile.exists()){ System.out.println("input file: " + fileName + " does not exist"); System.exit(1); } textData = new HaploData(); Vector result = null; if(fileType == HAPS){ //read in haps file textData.prepareHapsInput(inputFile); } else if (fileType == PED) { //read in ped file /* if(this.arg_ignoreMarkers.size()>0) { for(int i=0;i<this.arg_ignoreMarkers.size();i++){ int index = Integer.parseInt((String)this.arg_ignoreMarkers.get(i)); if(index>0 && index<markerResultArray.length){ markerResultArray[index] = false; if(!this.quietMode) { System.out.println("Ignoring marker " + (index)); } } } }*/ result = textData.linkageToChrom(inputFile, 3, skipCheck); if(textData.getPedFile().isBogusParents()) { System.out.println("Error: One or more individuals in the file reference non-existent parents.\nThese references have been ignored."); } }else{ //read in hapmapfile result = textData.linkageToChrom(inputFile,4,skipCheck); } File infoFile = null; if (infoFileName != null){ infoFile = new File(infoFileName); } if (result != null){ textData.prepareMarkerInput(infoFile,textData.getPedFile().getHMInfo()); }else{ textData.prepareMarkerInput(infoFile,null); } if(!quietMode && infoFile != null){ System.out.println("Using marker file " + infoFile.getName()); } if(outputCheck && result != null){ CheckDataPanel cp = new CheckDataPanel(textData); cp.printTable(validateOutputFile(fileName + ".CHECK")); } Vector cust = new Vector(); if(outputType != -1){ textData.generateDPrimeTable(); Haplotype[][] haplos; switch(outputType){ case BLOX_GABRIEL: OutputFile = validateOutputFile(fileName + ".GABRIELblocks"); break; case BLOX_4GAM: OutputFile = validateOutputFile(fileName + ".4GAMblocks"); break; case BLOX_SPINE: OutputFile = validateOutputFile(fileName + ".SPINEblocks"); break; case BLOX_CUSTOM: OutputFile = validateOutputFile(fileName + ".CUSTblocks"); //read in the blocks file File blocksFile = new File(blockFileName); cust = textData.readBlocks(blocksFile); break; default: OutputFile = validateOutputFile(fileName + ".GABRIELblocks"); break; } //this handles output type ALL if(outputType == BLOX_ALL) { OutputFile = validateOutputFile(fileName + ".GABRIELblocks"); textData.guessBlocks(BLOX_GABRIEL); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); OutputFile = validateOutputFile(fileName + ".4GAMblocks"); textData.guessBlocks(BLOX_4GAM); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); OutputFile = validateOutputFile(fileName + ".SPINEblocks"); textData.guessBlocks(BLOX_SPINE); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); }else{ textData.guessBlocks(outputType, cust); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); } //todo: should this output hap assoc for each block type if they do more than one? if(Options.getAssocTest() == ASSOC_TRIO || Options.getAssocTest() == ASSOC_CC) { //Haplotype[][] orderedHaps = orderHaps(textData.getHaplotypes()); HaploData.saveHapAssocToText(haplos, fileName + ".HAPASSOC"); } } if(outputDprime) { OutputFile = validateOutputFile(fileName + ".LD"); if (textData.dpTable != null){ textData.saveDprimeToText(OutputFile, TABLE_TYPE, 0, Chromosome.getSize()); }else{ textData.saveDprimeToText(OutputFile, LIVE_TYPE, 0, Chromosome.getSize()); } } if (outputPNG || outputCompressedPNG){ OutputFile = validateOutputFile(fileName + ".LD.PNG"); if (textData.dpTable == null){ textData.generateDPrimeTable(); textData.guessBlocks(BLOX_CUSTOM, new Vector()); } if (trackFileName != null){ textData.readAnalysisTrack(new File(trackFileName)); } DPrimeDisplay dpd = new DPrimeDisplay(textData); BufferedImage i = dpd.export(0,Chromosome.getSize(),outputCompressedPNG); try{ Jimi.putImage("image/png", i, OutputFile.getName()); }catch(JimiException je){ System.out.println(je.getMessage()); } } if(Options.getAssocTest() == ASSOC_TRIO){ Vector tdtResults = TDT.calcTrioTDT(textData.getPedFile()); HaploData.saveMarkerAssocToText(tdtResults, fileName + ".ASSOC"); } else if(Options.getAssocTest() == ASSOC_CC) { Vector ccResults = TDT.calcCCTDT(textData.getPedFile()); HaploData.saveMarkerAssocToText(ccResults, fileName + ".ASSOC"); } } catch(IOException e){ System.err.println("An error has occured. This probably has to do with file input or output"); } catch(HaploViewException e){ System.err.println(e.getMessage()); } catch(PedFileException pfe) { System.err.println(pfe.getMessage()); } }
| 1,108,880
|
private void processFile(String fileName, int fileType, String infoFileName){ try { HaploData textData; File OutputFile; File inputFile; if(!quietMode && fileName != null){ System.out.println("Using data file " + fileName); } inputFile = new File(fileName); if(!inputFile.exists()){ System.out.println("input file: " + fileName + " does not exist"); System.exit(1); } textData = new HaploData(); Vector result = null; if(fileType == HAPS){ //read in haps file textData.prepareHapsInput(inputFile); } else if (fileType == PED) { //read in ped file /* if(this.arg_ignoreMarkers.size()>0) { for(int i=0;i<this.arg_ignoreMarkers.size();i++){ int index = Integer.parseInt((String)this.arg_ignoreMarkers.get(i)); if(index>0 && index<markerResultArray.length){ markerResultArray[index] = false; if(!this.quietMode) { System.out.println("Ignoring marker " + (index)); } } } }*/ result = textData.linkageToChrom(inputFile, 3, skipCheck); if(textData.getPedFile().isBogusParents()) { System.out.println("Error: One or more individuals in the file reference non-existent parents.\nThese references have been ignored."); } }else{ //read in hapmapfile result = textData.linkageToChrom(inputFile,4,skipCheck); } File infoFile = null; if (infoFileName != null){ infoFile = new File(infoFileName); } if (result != null){ textData.prepareMarkerInput(infoFile,textData.getPedFile().getHMInfo()); }else{ textData.prepareMarkerInput(infoFile,null); } if(!quietMode && infoFile != null){ System.out.println("Using marker file " + infoFile.getName()); } if(outputCheck && result != null){ CheckDataPanel cp = new CheckDataPanel(textData); cp.printTable(validateOutputFile(fileName + ".CHECK")); } Vector cust = new Vector(); if(outputType != -1){ textData.generateDPrimeTable(); Haplotype[][] haplos; switch(outputType){ case BLOX_GABRIEL: OutputFile = validateOutputFile(fileName + ".GABRIELblocks"); break; case BLOX_4GAM: OutputFile = validateOutputFile(fileName + ".4GAMblocks"); break; case BLOX_SPINE: OutputFile = validateOutputFile(fileName + ".SPINEblocks"); break; case BLOX_CUSTOM: OutputFile = validateOutputFile(fileName + ".CUSTblocks"); //read in the blocks file File blocksFile = new File(blockFileName); cust = textData.readBlocks(blocksFile); break; default: OutputFile = validateOutputFile(fileName + ".GABRIELblocks"); break; } //this handles output type ALL if(outputType == BLOX_ALL) { OutputFile = validateOutputFile(fileName + ".GABRIELblocks"); textData.guessBlocks(BLOX_GABRIEL); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); OutputFile = validateOutputFile(fileName + ".4GAMblocks"); textData.guessBlocks(BLOX_4GAM); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); OutputFile = validateOutputFile(fileName + ".SPINEblocks"); textData.guessBlocks(BLOX_SPINE); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); }else{ textData.guessBlocks(outputType, cust); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); } //todo: should this output hap assoc for each block type if they do more than one? if(Options.getAssocTest() == ASSOC_TRIO || Options.getAssocTest() == ASSOC_CC) { //Haplotype[][] orderedHaps = orderHaps(textData.getHaplotypes()); HaploData.saveHapAssocToText(haplos, fileName + ".HAPASSOC"); } } if(outputDprime) { OutputFile = validateOutputFile(fileName + ".LD"); if (textData.dpTable != null){ textData.saveDprimeToText(OutputFile, TABLE_TYPE, 0, Chromosome.getSize()); }else{ textData.saveDprimeToText(OutputFile, LIVE_TYPE, 0, Chromosome.getSize()); } } if (outputPNG || outputCompressedPNG){ OutputFile = validateOutputFile(fileName + ".LD.PNG"); if (textData.dpTable == null){ textData.generateDPrimeTable(); textData.guessBlocks(BLOX_CUSTOM, new Vector()); } if (trackFileName != null){ textData.readAnalysisTrack(new File(trackFileName)); } DPrimeDisplay dpd = new DPrimeDisplay(textData); BufferedImage i = dpd.export(0,Chromosome.getSize(),outputCompressedPNG); try{ Jimi.putImage("image/png", i, OutputFile.getName()); }catch(JimiException je){ System.out.println(je.getMessage()); } } if(Options.getAssocTest() == ASSOC_TRIO){ Vector tdtResults = TDT.calcTrioTDT(textData.getPedFile()); HaploData.saveMarkerAssocToText(tdtResults, fileName + ".ASSOC"); } else if(Options.getAssocTest() == ASSOC_CC) { Vector ccResults = TDT.calcCCTDT(textData.getPedFile()); HaploData.saveMarkerAssocToText(ccResults, fileName + ".ASSOC"); } } catch(IOException e){ System.err.println("An error has occured. This probably has to do with file input or output"); } catch(HaploViewException e){ System.err.println(e.getMessage()); } catch(PedFileException pfe) { System.err.println(pfe.getMessage()); } }
|
private void processFile(String fileName, int fileType, String infoFileName){ try { HaploData textData; File OutputFile; File inputFile; if(!quietMode && fileName != null){ System.out.println("Using data file " + fileName); } inputFile = new File(fileName); if(!inputFile.exists()){ System.out.println("input file: " + fileName + " does not exist"); System.exit(1); } textData = new HaploData(); Vector result = null; if(fileType == HAPS){ //read in haps file textData.prepareHapsInput(inputFile); } else if (fileType == PED) { //read in ped file /* if(this.arg_ignoreMarkers.size()>0) { for(int i=0;i<this.arg_ignoreMarkers.size();i++){ int index = Integer.parseInt((String)this.arg_ignoreMarkers.get(i)); if(index>0 && index<markerResultArray.length){ markerResultArray[index] = false; if(!this.quietMode) { System.out.println("Ignoring marker " + (index)); } } } }*/ result = textData.linkageToChrom(inputFile, 3, skipCheck); if(textData.getPedFile().isBogusParents()) { System.out.println("Error: One or more individuals in the file reference non-existent parents.\nThese references have been ignored."); } }else{ //read in hapmapfile result = textData.linkageToChrom(inputFile,4,skipCheck); } File infoFile = null; if (infoFileName != null){ infoFile = new File(infoFileName); } if (result != null){ textData.prepareMarkerInput(infoFile,textData.getPedFile().getHMInfo()); }else{ textData.prepareMarkerInput(infoFile,null); } if(!quietMode && infoFile != null){ System.out.println("Using marker file " + infoFile.getName()); } if(outputCheck && result != null){ CheckDataPanel cp = new CheckDataPanel(textData); cp.printTable(validateOutputFile(fileName + ".CHECK")); } Vector cust = new Vector(); if(outputType != -1){ textData.generateDPrimeTable(); Haplotype[][] haplos; switch(outputType){ case BLOX_GABRIEL: OutputFile = validateOutputFile(fileName + ".GABRIELblocks"); break; case BLOX_4GAM: OutputFile = validateOutputFile(fileName + ".4GAMblocks"); break; case BLOX_SPINE: OutputFile = validateOutputFile(fileName + ".SPINEblocks"); break; case BLOX_CUSTOM: OutputFile = validateOutputFile(fileName + ".CUSTblocks"); //read in the blocks file File blocksFile = new File(blockFileName); cust = textData.readBlocks(blocksFile); break; default: OutputFile = validateOutputFile(fileName + ".GABRIELblocks"); break; } //this handles output type ALL if(outputType == BLOX_ALL) { OutputFile = validateOutputFile(fileName + ".GABRIELblocks"); textData.guessBlocks(BLOX_GABRIEL); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); OutputFile = validateOutputFile(fileName + ".4GAMblocks"); textData.guessBlocks(BLOX_4GAM); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); OutputFile = validateOutputFile(fileName + ".SPINEblocks"); textData.guessBlocks(BLOX_SPINE); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); }else{ textData.guessBlocks(outputType, cust); haplos = textData.generateHaplotypes(textData.blocks, false); textData.pickTags(haplos); textData.saveHapsToText(haplos, textData.computeMultiDprime(haplos), OutputFile); } //todo: should this output hap assoc for each block type if they do more than one? if(Options.getAssocTest() == ASSOC_TRIO || Options.getAssocTest() == ASSOC_CC) { //Haplotype[][] orderedHaps = orderHaps(textData.getHaplotypes()); HaploData.saveHapAssocToText(haplos, fileName + ".HAPASSOC"); } } if(outputDprime) { OutputFile = validateOutputFile(fileName + ".LD"); if (textData.dpTable != null){ textData.saveDprimeToText(OutputFile, TABLE_TYPE, 0, Chromosome.getSize()); }else{ textData.saveDprimeToText(OutputFile, LIVE_TYPE, 0, Chromosome.getSize()); } } if (outputPNG || outputCompressedPNG){ OutputFile = validateOutputFile(fileName + ".LD.PNG"); if (textData.dpTable == null){ textData.generateDPrimeTable(); textData.guessBlocks(BLOX_CUSTOM, new Vector()); } if (trackFileName != null){ textData.readAnalysisTrack(new File(trackFileName)); } DPrimeDisplay dpd = new DPrimeDisplay(textData); BufferedImage i = dpd.export(0,Chromosome.getSize(),outputCompressedPNG); try{ Jimi.putImage("image/png", i, OutputFile.getName()); }catch(JimiException je){ System.out.println(je.getMessage()); } } if(Options.getAssocTest() == ASSOC_TRIO){ Vector tdtResults = TDT.calcTrioTDT(textData.getPedFile()); HaploData.saveMarkerAssocToText(tdtResults, fileName + ".ASSOC"); } else if(Options.getAssocTest() == ASSOC_CC) { Vector ccResults = TDT.calcCCTDT(textData.getPedFile()); HaploData.saveMarkerAssocToText(ccResults, fileName + ".ASSOC"); } } catch(IOException e){ System.err.println("An error has occured. This probably has to do with file input or output"); } catch(HaploViewException e){ System.err.println(e.getMessage()); } catch(PedFileException pfe) { System.err.println(pfe.getMessage()); } }
| 1,108,881
|
public ImportTag() { this.shouldInherit = false; }
|
public ImportTag() { }
| 1,108,882
|
public void doTag(XMLOutput output) throws Exception { if (uri == null) { throw new MissingAttributeException( "uri" ); } // we need to create a new JellyContext of the URI // take off the script name from the URL context.runScript(uri, output, true, getInherit() ); }
|
public void doTag(XMLOutput output) throws Exception { if (uri == null) { throw new MissingAttributeException( "uri" ); } // we need to create a new JellyContext of the URI // take off the script name from the URL context.runScript(uri, output, true, isInherit() ); }
| 1,108,883
|
public void setInherit(String inherit) { if ( "true".equals( inherit ) ) { this.shouldInherit = true; } }
|
public void setInherit(String inherit) { if ( "true".equals( inherit ) ) { this.shouldInherit = true; } }
| 1,108,884
|
protected Action createAction() { return new Action() { public void run(Node node) throws Exception { xpathSource = node; if (log.isDebugEnabled()) { log.debug( "Firing template body for match: " + match + " and node: " + node ); } getBody().run(context, output); } }; }
|
protected Action createAction() { return new Action() { public void run(Node node) throws Exception { xpathSource = node; if (log.isDebugEnabled()) { log.debug( "Firing template body for match: " + match + " and node: " + node ); } invokeBody(output); } }; }
| 1,108,885
|
public void run(Node node) throws Exception { xpathSource = node; if (log.isDebugEnabled()) { log.debug( "Firing template body for match: " + match + " and node: " + node ); } getBody().run(context, output); }
|
public void run(Node node) throws Exception { xpathSource = node; if (log.isDebugEnabled()) { log.debug( "Firing template body for match: " + match + " and node: " + node ); } invokeBody(output); }
| 1,108,886
|
public HaploView(){ //menu setup JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenuItem menuItem; //file menu JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); menuItem = new JMenuItem(READ_GENOTYPES); setAccelerator(menuItem, 'O', false); menuItem.addActionListener(this); fileMenu.add(menuItem); /* viewGenotypesItem = new JMenuItem(VIEW_GENOTYPES); viewGenotypesItem.addActionListener(this); //viewGenotypesItem.setEnabled(false); fileMenu.add(viewGenotypesItem); */ readMarkerItem = new JMenuItem(READ_MARKERS); setAccelerator(readMarkerItem, 'I', false); readMarkerItem.addActionListener(this); readMarkerItem.setEnabled(false); fileMenu.add(readMarkerItem); /* viewMarkerItem = new JMenuItem(VIEW_MARKERS); viewMarkerItem.addActionListener(this); //viewMarkerItem.setEnabled(false); fileMenu.add(viewMarkerItem); */ fileMenu.addSeparator(); exportMenuItems = new JMenuItem[exportItems.length]; for (int i = 0; i < exportItems.length; i++) { exportMenuItems[i] = new JMenuItem(exportItems[i]); exportMenuItems[i].addActionListener(this); exportMenuItems[i].setEnabled(false); fileMenu.add(exportMenuItems[i]); } fileMenu.addSeparator(); menuItem = new JMenuItem(QUIT); setAccelerator(menuItem, 'Q', false); menuItem.addActionListener(this); fileMenu.add(menuItem); /// display menu JMenu displayMenu = new JMenu("Display"); menuBar.add(displayMenu); ButtonGroup group = new ButtonGroup(); viewMenuItems = new JRadioButtonMenuItem[viewItems.length]; for (int i = 0; i < viewItems.length; i++) { viewMenuItems[i] = new JRadioButtonMenuItem(viewItems[i], i == 0); viewMenuItems[i].addActionListener(this); KeyStroke ks = KeyStroke.getKeyStroke('1' + i, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); viewMenuItems[i].setAccelerator(ks); displayMenu.add(viewMenuItems[i]); group.add(viewMenuItems[i]); } //this is the checkdata menu button viewMenuItems[VIEW_CHECK_NUM].setEnabled(false); //analysis menu JMenu analysisMenu = new JMenu("Analysis"); menuBar.add(analysisMenu); defineBlocksItem = new JMenuItem(DEFINE_BLOCKS); setAccelerator(defineBlocksItem, 'B', false); defineBlocksItem.addActionListener(this); defineBlocksItem.setEnabled(false); analysisMenu.add(defineBlocksItem); clearBlocksItem = new JMenuItem(CLEAR_BLOCKS); setAccelerator(clearBlocksItem, 'C', false); clearBlocksItem.addActionListener(this); clearBlocksItem.setEnabled(false); analysisMenu.add(clearBlocksItem); // maybe //displayMenu.addSeparator(); //displayOptionsItem = new JMenuItem(DISPLAY_OPTIONS); //setAccelerator(displayOptionsItem, 'D', false); /** NEEDS FIXING helpMenu = new JMenu("Help"); menuBar.add(Box.createHorizontalGlue()); menuBar.add(helpMenu); menuItem = new JMenuItem("Tutorial"); menuItem.addActionListener(this); helpMenu.add(menuItem); **/ /* clearBlocksMenuItem.addActionListener(this); clearBlocksMenuItem.setEnabled(false); toolMenu.add(clearBlocksMenuItem); */ addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ quit(); } }); }
|
public HaploView(){ //menu setup JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenuItem menuItem; //file menu JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); menuItem = new JMenuItem(READ_GENOTYPES); setAccelerator(menuItem, 'O', false); menuItem.addActionListener(this); fileMenu.add(menuItem); /* viewGenotypesItem = new JMenuItem(VIEW_GENOTYPES); viewGenotypesItem.addActionListener(this); //viewGenotypesItem.setEnabled(false); fileMenu.add(viewGenotypesItem); */ readMarkerItem = new JMenuItem(READ_MARKERS); setAccelerator(readMarkerItem, 'I', false); readMarkerItem.addActionListener(this); readMarkerItem.setEnabled(false); fileMenu.add(readMarkerItem); /* viewMarkerItem = new JMenuItem(VIEW_MARKERS); viewMarkerItem.addActionListener(this); //viewMarkerItem.setEnabled(false); fileMenu.add(viewMarkerItem); */ fileMenu.addSeparator(); exportMenuItems = new JMenuItem[exportItems.length]; for (int i = 0; i < exportItems.length; i++) { exportMenuItems[i] = new JMenuItem(exportItems[i]); exportMenuItems[i].addActionListener(this); exportMenuItems[i].setEnabled(false); fileMenu.add(exportMenuItems[i]); } fileMenu.addSeparator(); menuItem = new JMenuItem(QUIT); setAccelerator(menuItem, 'Q', false); menuItem.addActionListener(this); fileMenu.add(menuItem); /// display menu JMenu displayMenu = new JMenu("Display"); menuBar.add(displayMenu); ButtonGroup group = new ButtonGroup(); viewMenuItems = new JRadioButtonMenuItem[viewItems.length]; for (int i = 0; i < viewItems.length; i++) { viewMenuItems[i] = new JRadioButtonMenuItem(viewItems[i], i == 0); viewMenuItems[i].addActionListener(this); KeyStroke ks = KeyStroke.getKeyStroke('1' + i, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); viewMenuItems[i].setAccelerator(ks); displayMenu.add(viewMenuItems[i]); group.add(viewMenuItems[i]); } //this is the checkdata menu button //analysis menu JMenu analysisMenu = new JMenu("Analysis"); menuBar.add(analysisMenu); defineBlocksItem = new JMenuItem(DEFINE_BLOCKS); setAccelerator(defineBlocksItem, 'B', false); defineBlocksItem.addActionListener(this); defineBlocksItem.setEnabled(false); analysisMenu.add(defineBlocksItem); clearBlocksItem = new JMenuItem(CLEAR_BLOCKS); setAccelerator(clearBlocksItem, 'C', false); clearBlocksItem.addActionListener(this); clearBlocksItem.setEnabled(false); analysisMenu.add(clearBlocksItem); // maybe //displayMenu.addSeparator(); //displayOptionsItem = new JMenuItem(DISPLAY_OPTIONS); //setAccelerator(displayOptionsItem, 'D', false); /** NEEDS FIXING helpMenu = new JMenu("Help"); menuBar.add(Box.createHorizontalGlue()); menuBar.add(helpMenu); menuItem = new JMenuItem("Tutorial"); menuItem.addActionListener(this); helpMenu.add(menuItem); **/ /* clearBlocksMenuItem.addActionListener(this); clearBlocksMenuItem.setEnabled(false); toolMenu.add(clearBlocksMenuItem); */ addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ quit(); } }); }
| 1,108,889
|
void processData() { maxCompDist = Long.parseLong(inputOptions[2])*1000; try{ this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); final SwingWorker worker = new SwingWorker(){ public Object construct(){ dPrimeDisplay=null; theData.infoKnown = false; if (!(inputOptions[1].equals(""))){ readMarkers(new File(inputOptions[1])); } theData.generateDPrimeTable(maxCompDist); theData.guessBlocks(0); //drawPicture(theData); //void drawPicture(HaploData theData) { Container contents = getContentPane(); contents.removeAll(); int currentTab = 0; /*if (!(tabs == null)){ currentTab = tabs.getSelectedIndex(); } */ tabs = new JTabbedPane(); tabs.addChangeListener(new TabChangeListener()); //first, draw the D' picture JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); dPrimeDisplay = new DPrimeDisplay(theData); JScrollPane dPrimeScroller = new JScrollPane(dPrimeDisplay); dPrimeScroller.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE); dPrimeScroller.getVerticalScrollBar().setUnitIncrement(60); dPrimeScroller.getHorizontalScrollBar().setUnitIncrement(60); panel.add(dPrimeScroller); tabs.addTab(viewItems[VIEW_D_NUM], panel); //compute and show haps on next tab panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); try { hapDisplay = new HaplotypeDisplay(theData); } catch(HaploViewException e) { JOptionPane.showMessageDialog(window, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } HaplotypeDisplayController hdc = new HaplotypeDisplayController(hapDisplay); hapScroller = new JScrollPane(hapDisplay); panel.add(hapScroller); panel.add(hdc); tabs.addTab(viewItems[VIEW_HAP_NUM], panel); //check data panel if (checkPanel != null){ tabs.addTab(viewItems[VIEW_CHECK_NUM], checkPanel); viewMenuItems[VIEW_CHECK_NUM].setEnabled(true); currentTab=VIEW_CHECK_NUM; } if(doTDT) { tdtPanel = new TDTPanel(theData.chromosomes); tabs.addTab(viewItems[VIEW_TDT_NUM], tdtPanel); } tabs.setSelectedIndex(currentTab); contents.add(tabs); //next add a little spacer //ontents.add(Box.createRigidArea(new Dimension(0,5))); //and then add the block display //theBlocks = new BlockDisplay(theData.markerInfo, theData.blocks, dPrimeDisplay, infoKnown); //contents.setBackground(Color.black); //put the block display in a scroll pane in case the data set is very large. //JScrollPane blockScroller = new JScrollPane(theBlocks, // JScrollPane.VERTICAL_SCROLLBAR_NEVER, // JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); //blockScroller.getHorizontalScrollBar().setUnitIncrement(60); //blockScroller.setMinimumSize(new Dimension(800, 100)); //contents.add(blockScroller); repaint(); setVisible(true); //} theData.finished = true; return ""; } }; timer = new javax.swing.Timer(50, new ActionListener(){ public void actionPerformed(ActionEvent evt){ if (theData.finished){ timer.stop(); defineBlocksItem.setEnabled(true); clearBlocksItem.setEnabled(true); readMarkerItem.setEnabled(true); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } }); worker.start(); timer.start(); }catch (RuntimeException rtexec){ JOptionPane.showMessageDialog(this, "An error has occured. It is probably related to file format:\n"+rtexec.toString(), "Error", JOptionPane.ERROR_MESSAGE); } }
|
void processData() { maxCompDist = Long.parseLong(inputOptions[2])*1000; try{ this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); final SwingWorker worker = new SwingWorker(){ public Object construct(){ dPrimeDisplay=null; theData.infoKnown = false; if (!(inputOptions[1].equals(""))){ readMarkers(new File(inputOptions[1])); } theData.generateDPrimeTable(maxCompDist); theData.guessBlocks(0); //drawPicture(theData); //void drawPicture(HaploData theData) { Container contents = getContentPane(); contents.removeAll(); int currentTab = 0; /*if (!(tabs == null)){ currentTab = tabs.getSelectedIndex(); } */ tabs = new JTabbedPane(); tabs.addChangeListener(new TabChangeListener()); //first, draw the D' picture JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); dPrimeDisplay = new DPrimeDisplay(theData); JScrollPane dPrimeScroller = new JScrollPane(dPrimeDisplay); dPrimeScroller.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE); dPrimeScroller.getVerticalScrollBar().setUnitIncrement(60); dPrimeScroller.getHorizontalScrollBar().setUnitIncrement(60); panel.add(dPrimeScroller); tabs.addTab(viewItems[VIEW_D_NUM], panel); //compute and show haps on next tab panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); try { hapDisplay = new HaplotypeDisplay(theData); } catch(HaploViewException e) { JOptionPane.showMessageDialog(window, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } HaplotypeDisplayController hdc = new HaplotypeDisplayController(hapDisplay); hapScroller = new JScrollPane(hapDisplay); panel.add(hapScroller); panel.add(hdc); tabs.addTab(viewItems[VIEW_HAP_NUM], panel); //check data panel if (checkPanel != null){ tabs.addTab(viewItems[VIEW_CHECK_NUM], checkPanel); viewMenuItems[VIEW_CHECK_NUM].setEnabled(true); currentTab=VIEW_CHECK_NUM; } if(doTDT) { tdtPanel = new TDTPanel(theData.chromosomes); tabs.addTab(viewItems[VIEW_TDT_NUM], tdtPanel); } tabs.setSelectedIndex(currentTab); contents.add(tabs); //next add a little spacer //ontents.add(Box.createRigidArea(new Dimension(0,5))); //and then add the block display //theBlocks = new BlockDisplay(theData.markerInfo, theData.blocks, dPrimeDisplay, infoKnown); //contents.setBackground(Color.black); //put the block display in a scroll pane in case the data set is very large. //JScrollPane blockScroller = new JScrollPane(theBlocks, // JScrollPane.VERTICAL_SCROLLBAR_NEVER, // JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); //blockScroller.getHorizontalScrollBar().setUnitIncrement(60); //blockScroller.setMinimumSize(new Dimension(800, 100)); //contents.add(blockScroller); repaint(); setVisible(true); //} theData.finished = true; return ""; } }; timer = new javax.swing.Timer(50, new ActionListener(){ public void actionPerformed(ActionEvent evt){ if (theData.finished){ timer.stop(); defineBlocksItem.setEnabled(true); clearBlocksItem.setEnabled(true); readMarkerItem.setEnabled(true); setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } }); worker.start(); timer.start(); }catch (RuntimeException rtexec){ JOptionPane.showMessageDialog(this, "An error has occured. It is probably related to file format:\n"+rtexec.toString(), "Error", JOptionPane.ERROR_MESSAGE); } }
| 1,108,890
|
public Object construct(){ dPrimeDisplay=null; theData.infoKnown = false; if (!(inputOptions[1].equals(""))){ readMarkers(new File(inputOptions[1])); } theData.generateDPrimeTable(maxCompDist); theData.guessBlocks(0); //drawPicture(theData); //void drawPicture(HaploData theData) { Container contents = getContentPane(); contents.removeAll(); int currentTab = 0; /*if (!(tabs == null)){ currentTab = tabs.getSelectedIndex(); } */ tabs = new JTabbedPane(); tabs.addChangeListener(new TabChangeListener()); //first, draw the D' picture JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); dPrimeDisplay = new DPrimeDisplay(theData); JScrollPane dPrimeScroller = new JScrollPane(dPrimeDisplay); dPrimeScroller.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE); dPrimeScroller.getVerticalScrollBar().setUnitIncrement(60); dPrimeScroller.getHorizontalScrollBar().setUnitIncrement(60); panel.add(dPrimeScroller); tabs.addTab(viewItems[VIEW_D_NUM], panel); //compute and show haps on next tab panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); try { hapDisplay = new HaplotypeDisplay(theData); } catch(HaploViewException e) { JOptionPane.showMessageDialog(window, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } HaplotypeDisplayController hdc = new HaplotypeDisplayController(hapDisplay); hapScroller = new JScrollPane(hapDisplay); panel.add(hapScroller); panel.add(hdc); tabs.addTab(viewItems[VIEW_HAP_NUM], panel); //check data panel if (checkPanel != null){ tabs.addTab(viewItems[VIEW_CHECK_NUM], checkPanel); viewMenuItems[VIEW_CHECK_NUM].setEnabled(true); currentTab=VIEW_CHECK_NUM; } if(doTDT) { tdtPanel = new TDTPanel(theData.chromosomes); tabs.addTab(viewItems[VIEW_TDT_NUM], tdtPanel); } tabs.setSelectedIndex(currentTab); contents.add(tabs); //next add a little spacer //ontents.add(Box.createRigidArea(new Dimension(0,5))); //and then add the block display //theBlocks = new BlockDisplay(theData.markerInfo, theData.blocks, dPrimeDisplay, infoKnown); //contents.setBackground(Color.black); //put the block display in a scroll pane in case the data set is very large. //JScrollPane blockScroller = new JScrollPane(theBlocks, // JScrollPane.VERTICAL_SCROLLBAR_NEVER, // JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); //blockScroller.getHorizontalScrollBar().setUnitIncrement(60); //blockScroller.setMinimumSize(new Dimension(800, 100)); //contents.add(blockScroller); repaint(); setVisible(true); //} theData.finished = true; return ""; }
|
public Object construct(){ dPrimeDisplay=null; theData.infoKnown = false; if (!(inputOptions[1].equals(""))){ readMarkers(new File(inputOptions[1])); } theData.generateDPrimeTable(maxCompDist); theData.guessBlocks(0); //drawPicture(theData); //void drawPicture(HaploData theData) { Container contents = getContentPane(); contents.removeAll(); int currentTab = 0; /*if (!(tabs == null)){ currentTab = tabs.getSelectedIndex(); } */ tabs = new JTabbedPane(); tabs.addChangeListener(new TabChangeListener()); //first, draw the D' picture JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); dPrimeDisplay = new DPrimeDisplay(theData); JScrollPane dPrimeScroller = new JScrollPane(dPrimeDisplay); dPrimeScroller.getViewport().setScrollMode(JViewport.BLIT_SCROLL_MODE); dPrimeScroller.getVerticalScrollBar().setUnitIncrement(60); dPrimeScroller.getHorizontalScrollBar().setUnitIncrement(60); panel.add(dPrimeScroller); tabs.addTab(viewItems[VIEW_D_NUM], panel); //compute and show haps on next tab panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); try { hapDisplay = new HaplotypeDisplay(theData); } catch(HaploViewException e) { JOptionPane.showMessageDialog(window, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } HaplotypeDisplayController hdc = new HaplotypeDisplayController(hapDisplay); hapScroller = new JScrollPane(hapDisplay); panel.add(hapScroller); panel.add(hdc); tabs.addTab(viewItems[VIEW_HAP_NUM], panel); //check data panel if (checkPanel != null){ tabs.addTab(viewItems[VIEW_CHECK_NUM], checkPanel); viewMenuItems[VIEW_CHECK_NUM].setEnabled(true); currentTab=VIEW_CHECK_NUM; } if(doTDT) { tdtPanel = new TDTPanel(theData.chromosomes); tabs.addTab(viewItems[VIEW_TDT_NUM], tdtPanel); } tabs.setSelectedIndex(currentTab); contents.add(tabs); //next add a little spacer //ontents.add(Box.createRigidArea(new Dimension(0,5))); //and then add the block display //theBlocks = new BlockDisplay(theData.markerInfo, theData.blocks, dPrimeDisplay, infoKnown); //contents.setBackground(Color.black); //put the block display in a scroll pane in case the data set is very large. //JScrollPane blockScroller = new JScrollPane(theBlocks, // JScrollPane.VERTICAL_SCROLLBAR_NEVER, // JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); //blockScroller.getHorizontalScrollBar().setUnitIncrement(60); //blockScroller.setMinimumSize(new Dimension(800, 100)); //contents.add(blockScroller); repaint(); setVisible(true); //} theData.finished = true; return ""; }
| 1,108,891
|
public synchronized boolean equals(int status) { return this.status == status; }
|
public synchronized boolean equals(int status) { return this.status == status; }
| 1,108,894
|
public void actionPerformed(ActionEvent e) { if (dbTree == null) { logger.debug("dbtree was null when actionPerformed called"); return; } if ( dbTree.getSelectionPaths() == null ) { logger.debug("dbtree path selection was null when actionPerformed called"); return; } try { Set<SQLObject> sqlObject = new HashSet<SQLObject>(); for ( TreePath tp : dbTree.getSelectionPaths() ) { if ( tp.getLastPathComponent() instanceof SQLDatabase ) { sqlObject.add((SQLDatabase)tp.getLastPathComponent()); } else if ( tp.getLastPathComponent() instanceof SQLCatalog ) { SQLCatalog cat = (SQLCatalog)tp.getLastPathComponent(); sqlObject.add(cat); SQLDatabase db = ArchitectUtils.getAncestor(cat,SQLDatabase.class); if ( db != null && sqlObject.contains(db)) sqlObject.remove(db); } else if ( tp.getLastPathComponent() instanceof SQLSchema ) { SQLSchema sch = (SQLSchema)tp.getLastPathComponent(); sqlObject.add(sch); SQLCatalog cat = ArchitectUtils.getAncestor(sch,SQLCatalog.class); if ( cat != null && sqlObject.contains(cat)) sqlObject.remove(cat); SQLDatabase db = ArchitectUtils.getAncestor(sch,SQLDatabase.class); if ( db != null && sqlObject.contains(db)) sqlObject.remove(db); } else if ( tp.getLastPathComponent() instanceof SQLTable ) { SQLTable tab = (SQLTable)tp.getLastPathComponent(); sqlObject.add(tab); SQLSchema sch = ArchitectUtils.getAncestor(tab,SQLSchema.class); if ( sch != null && sqlObject.contains(sch)) sqlObject.remove(sch); SQLCatalog cat = ArchitectUtils.getAncestor(sch,SQLCatalog.class); if ( cat != null && sqlObject.contains(cat)) sqlObject.remove(cat); SQLDatabase db = ArchitectUtils.getAncestor(sch,SQLDatabase.class); if ( db != null && sqlObject.contains(db)) sqlObject.remove(db); } else if ( tp.getLastPathComponent() instanceof SQLTable.Folder ) { SQLTable tab = ArchitectUtils.getAncestor((Folder)tp.getLastPathComponent(),SQLTable.class); sqlObject.add(tab); SQLSchema sch = ArchitectUtils.getAncestor(tab,SQLSchema.class); if ( sch != null && sqlObject.contains(sch)) sqlObject.remove(sch); SQLCatalog cat = ArchitectUtils.getAncestor(sch,SQLCatalog.class); if ( cat != null && sqlObject.contains(cat)) sqlObject.remove(cat); SQLDatabase db = ArchitectUtils.getAncestor(sch,SQLDatabase.class); if ( db != null && sqlObject.contains(db)) sqlObject.remove(db); } else if ( tp.getLastPathComponent() instanceof SQLColumn ) { SQLTable tab = ((SQLColumn)tp.getLastPathComponent()).getParentTable(); sqlObject.add((SQLColumn)tp.getLastPathComponent()); SQLSchema sch = ArchitectUtils.getAncestor(tab,SQLSchema.class); if ( sch != null && sqlObject.contains(sch)) sqlObject.remove(sch); SQLCatalog cat = ArchitectUtils.getAncestor(sch,SQLCatalog.class); if ( cat != null && sqlObject.contains(cat)) sqlObject.remove(cat); SQLDatabase db = ArchitectUtils.getAncestor(sch,SQLDatabase.class); if ( db != null && sqlObject.contains(db)) sqlObject.remove(db); } } final ArrayList<SQLObject> filter = new ArrayList<SQLObject>(); final Set<SQLTable> tables = new HashSet<SQLTable>(); for ( SQLObject o : sqlObject ) { if ( o instanceof SQLColumn){ tables.add(((SQLColumn)o).getParentTable()); } else { tables.addAll(ArchitectUtils.tablesUnder(o)); } if (! (o instanceof Folder)){ filter.add(o); } } profileManager.setCancelled(false); d = new JDialog(ArchitectFrame.getMainInstance(), "Table Profiles"); Action closeAction = new AbstractAction() { public void actionPerformed(ActionEvent evt) { profileManager.setCancelled(true); d.setVisible(false); } }; closeAction.putValue(Action.NAME, "Close"); final JDefaultButton closeButton = new JDefaultButton(closeAction); final JPanel progressViewPanel = new JPanel(new BorderLayout()); final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.add(closeButton); progressViewPanel.add(buttonPanel, BorderLayout.SOUTH); final JProgressBar progressBar = new JProgressBar(); progressBar.setPreferredSize(new Dimension(450,20)); progressViewPanel.add(progressBar, BorderLayout.CENTER); final JLabel workingOn = new JLabel("Profiling:"); progressViewPanel.add(workingOn, BorderLayout.NORTH); ArchitectPanelBuilder.makeJDialogCancellable( d, new CommonCloseAction(d)); d.getRootPane().setDefaultButton(closeButton); d.setContentPane(progressViewPanel); d.pack(); d.setLocationRelativeTo(ArchitectFrame.getMainInstance()); d.setVisible(true); new ProgressWatcher(progressBar,profileManager,workingOn); new Thread( new Runnable() { public void run() { try { List<SQLTable> toBeProfiled = new ArrayList<SQLTable>(); for (SQLTable t: tables) { if (profileManager.getResult(t)== null) { toBeProfiled.add(t); workingOn.setText("Adding "+t.getName()+ " ("+toBeProfiled.size()+")"); } } profileManager.createProfiles(toBeProfiled, workingOn); progressBar.setVisible(false); JLabel status = new JLabel("Generating reports, Please wait......"); progressViewPanel.add(status, BorderLayout.NORTH); status.setVisible(true); JTabbedPane tabPane = new JTabbedPane(); ProfileTableModel tm = new ProfileTableModel(); for (SQLObject sqo: filter){ tm.addFilter(sqo); } tm.setProfileManager(profileManager); TableModelSortDecorator tableModelSortDecorator = new TableModelSortDecorator(tm); final JTable viewTable = new ProfileTable(tableModelSortDecorator); JTableHeader tableHeader = viewTable.getTableHeader(); tableModelSortDecorator.setTableHeader(tableHeader); viewTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); ProfilePanelMouseListener profilePanelMouseListener = new ProfilePanelMouseListener(); profilePanelMouseListener.setTabPane(tabPane); viewTable.addMouseListener( profilePanelMouseListener); JScrollPane editorScrollPane = new JScrollPane(viewTable); editorScrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorScrollPane.setPreferredSize(new Dimension(800, 600)); editorScrollPane.setMinimumSize(new Dimension(10, 10)); // reset column widths tableModelSortDecorator.initColumnSizes(viewTable); JPanel tableViewPane = new JPanel(new BorderLayout()); tableViewPane.add(editorScrollPane,BorderLayout.CENTER); ButtonBarBuilder buttonBuilder = new ButtonBarBuilder(); JButton save = new JButton(new AbstractAction("Save") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.addChoosableFileFilter(ASUtils.PDF_FILE_FILTER); chooser.addChoosableFileFilter(ASUtils.HTML_FILE_FILTER); chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter()); int response = chooser.showSaveDialog(d); if (response != JFileChooser.APPROVE_OPTION) { return; } else { File file = chooser.getSelectedFile(); final FileFilter fileFilter = chooser.getFileFilter(); if (fileFilter == ASUtils.HTML_FILE_FILTER) { if (!file.getPath().endsWith(".html")) { file = new File(file.getPath()+".html"); } } else { if (!file.getPath().endsWith(".pdf")) { file = new File(file.getPath()+".pdf"); } } if (file.exists()) { response = JOptionPane.showConfirmDialog( d, "The file\n\n"+file.getPath()+"\n\nalready exists. Do you want to overwrite it?", "File Exists", JOptionPane.YES_NO_OPTION); if (response == JOptionPane.NO_OPTION) { actionPerformed(e); return; } } final File file2 = new File(file.getPath()); Runnable saveTask = new Runnable() { public void run() { List tabList = new ArrayList(tables); OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(file2)); if (fileFilter == ASUtils.HTML_FILE_FILTER){ final String encoding = "utf-8"; ProfileHTMLFormat prf = new ProfileHTMLFormat(encoding); OutputStreamWriter osw = new OutputStreamWriter(out, encoding); osw.append(prf.format(tabList,profileManager)); osw.flush(); } else { new ProfilePDFFormat().createPdf(out, tabList, profileManager); } } catch (Exception ex) { ASUtils.showExceptionDialog(d,"Could not save PDF File", ex); } finally { if ( out != null ) { try { out.flush(); out.close(); } catch (IOException ex) { ASUtils.showExceptionDialog(d,"Could not close PDF File", ex); } } } } }; new Thread(saveTask).start(); } } }); JButton refresh = new JButton(new AbstractAction("Refresh"){ public void actionPerformed(ActionEvent e) { Set<SQLTable> uniqueTables = new HashSet(); for (int i: viewTable.getSelectedRows()) { Object o = viewTable.getValueAt(i,3); System.out.println(o.getClass()); SQLTable table = (SQLTable) o ; uniqueTables.add(table); } try { profileManager.setCancelled(false); profileManager.createProfiles(uniqueTables); } catch (SQLException e1) { throw new RuntimeException(e1); } catch (ArchitectException e1) { throw new ArchitectRuntimeException(e1); } ((ProfileTableModel)viewTable.getModel()).refresh(); } }); JButton delete = new JButton(new AbstractAction("Delete"){ public void actionPerformed(ActionEvent e) { int[] killMe = viewTable.getSelectedRows(); Arrays.sort(killMe); // iterate backwards so the rows don't shift away on us! for (int i = killMe.length-1; i >= 0; i--) { logger.debug("Deleting row "+killMe[i]+": "+viewTable.getValueAt(killMe[i],4)); SQLColumn col = (SQLColumn) viewTable.getValueAt(killMe[i], 4); try { profileManager.remove(col); } catch (ArchitectException e1) { ASUtils.showExceptionDialog(d,"Could delete column:", e1); } } ((ProfileTableModel)viewTable.getModel()).refresh(); } }); JButton deleteAll = new JButton(new AbstractAction("Delete All"){ public void actionPerformed(ActionEvent e) { profileManager.clear(); ((ProfileTableModel)viewTable.getModel()).refresh(); } }); JButton[] buttonArray = {refresh,delete,deleteAll,save,closeButton}; buttonBuilder.addGriddedButtons(buttonArray); tableViewPane.add(buttonBuilder.getPanel(),BorderLayout.SOUTH); tabPane.addTab("Table View", tableViewPane ); ProfilePanel p = new ProfilePanel(profileManager); tabPane.addTab("Graph View",p); profilePanelMouseListener.setProfilePanel(p); List<SQLTable> list = new ArrayList(tables); p.setTables(list); p.setChartType(ChartTypes.PIE); d.setVisible(false); d.remove(progressViewPanel); d.setContentPane(tabPane); d.pack(); d.setLocationRelativeTo(ArchitectFrame.getMainInstance()); d.setVisible(true); } catch (SQLException e) { logger.error("Error in Profile Action ", e); ASUtils.showExceptionDialogNoReport(dbTree, "Error during profile run", e); } catch (ArchitectException e) { logger.error("Error in Profile Action", e); ASUtils.showExceptionDialog(dbTree, "Error during profile run", e); } } }).start(); } catch (Exception ex) { logger.error("Error in Profile Action ", ex); ASUtils.showExceptionDialog(dbTree, "Error during profile run", ex); } }
|
public void actionPerformed(ActionEvent e) { if (dbTree == null) { logger.debug("dbtree was null when actionPerformed called"); return; } if ( dbTree.getSelectionPaths() == null ) { logger.debug("dbtree path selection was null when actionPerformed called"); return; } try { Set<SQLObject> sqlObject = new HashSet<SQLObject>(); for ( TreePath tp : dbTree.getSelectionPaths() ) { if ( tp.getLastPathComponent() instanceof SQLDatabase ) { sqlObject.add((SQLDatabase)tp.getLastPathComponent()); } else if ( tp.getLastPathComponent() instanceof SQLCatalog ) { SQLCatalog cat = (SQLCatalog)tp.getLastPathComponent(); sqlObject.add(cat); SQLDatabase db = ArchitectUtils.getAncestor(cat,SQLDatabase.class); if ( db != null && sqlObject.contains(db)) sqlObject.remove(db); } else if ( tp.getLastPathComponent() instanceof SQLSchema ) { SQLSchema sch = (SQLSchema)tp.getLastPathComponent(); sqlObject.add(sch); SQLCatalog cat = ArchitectUtils.getAncestor(sch,SQLCatalog.class); if ( cat != null && sqlObject.contains(cat)) sqlObject.remove(cat); SQLDatabase db = ArchitectUtils.getAncestor(sch,SQLDatabase.class); if ( db != null && sqlObject.contains(db)) sqlObject.remove(db); } else if ( tp.getLastPathComponent() instanceof SQLTable ) { SQLTable tab = (SQLTable)tp.getLastPathComponent(); sqlObject.add(tab); SQLSchema sch = ArchitectUtils.getAncestor(tab,SQLSchema.class); if ( sch != null && sqlObject.contains(sch)) sqlObject.remove(sch); SQLCatalog cat = ArchitectUtils.getAncestor(sch,SQLCatalog.class); if ( cat != null && sqlObject.contains(cat)) sqlObject.remove(cat); SQLDatabase db = ArchitectUtils.getAncestor(sch,SQLDatabase.class); if ( db != null && sqlObject.contains(db)) sqlObject.remove(db); } else if ( tp.getLastPathComponent() instanceof SQLTable.Folder ) { SQLTable tab = ArchitectUtils.getAncestor((Folder)tp.getLastPathComponent(),SQLTable.class); sqlObject.add(tab); SQLSchema sch = ArchitectUtils.getAncestor(tab,SQLSchema.class); if ( sch != null && sqlObject.contains(sch)) sqlObject.remove(sch); SQLCatalog cat = ArchitectUtils.getAncestor(sch,SQLCatalog.class); if ( cat != null && sqlObject.contains(cat)) sqlObject.remove(cat); SQLDatabase db = ArchitectUtils.getAncestor(sch,SQLDatabase.class); if ( db != null && sqlObject.contains(db)) sqlObject.remove(db); } else if ( tp.getLastPathComponent() instanceof SQLColumn ) { SQLTable tab = ((SQLColumn)tp.getLastPathComponent()).getParentTable(); sqlObject.add((SQLColumn)tp.getLastPathComponent()); SQLSchema sch = ArchitectUtils.getAncestor(tab,SQLSchema.class); if ( sch != null && sqlObject.contains(sch)) sqlObject.remove(sch); SQLCatalog cat = ArchitectUtils.getAncestor(sch,SQLCatalog.class); if ( cat != null && sqlObject.contains(cat)) sqlObject.remove(cat); SQLDatabase db = ArchitectUtils.getAncestor(sch,SQLDatabase.class); if ( db != null && sqlObject.contains(db)) sqlObject.remove(db); } } final ArrayList<SQLObject> filter = new ArrayList<SQLObject>(); final Set<SQLTable> tables = new HashSet<SQLTable>(); for ( SQLObject o : sqlObject ) { if ( o instanceof SQLColumn){ tables.add(((SQLColumn)o).getParentTable()); } else { tables.addAll(ArchitectUtils.tablesUnder(o)); } if (! (o instanceof Folder)){ filter.add(o); } } profileManager.setCancelled(false); d = new JDialog(ArchitectFrame.getMainInstance(), "Table Profiles"); Action closeAction = new AbstractAction() { public void actionPerformed(ActionEvent evt) { profileManager.setCancelled(true); d.setVisible(false); } }; closeAction.putValue(Action.NAME, "Close"); final JDefaultButton closeButton = new JDefaultButton(closeAction); final JPanel progressViewPanel = new JPanel(new BorderLayout()); final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.add(closeButton); progressViewPanel.add(buttonPanel, BorderLayout.SOUTH); final JProgressBar progressBar = new JProgressBar(); progressBar.setPreferredSize(new Dimension(450,20)); progressViewPanel.add(progressBar, BorderLayout.CENTER); final JLabel workingOn = new JLabel("Profiling:"); progressViewPanel.add(workingOn, BorderLayout.NORTH); ArchitectPanelBuilder.makeJDialogCancellable( d, new CommonCloseAction(d)); d.getRootPane().setDefaultButton(closeButton); d.setContentPane(progressViewPanel); d.pack(); d.setLocationRelativeTo(ArchitectFrame.getMainInstance()); d.setVisible(true); new ProgressWatcher(progressBar,profileManager,workingOn); new Thread( new Runnable() { public void run() { try { List<SQLTable> toBeProfiled = new ArrayList<SQLTable>(); for (SQLTable t: tables) { if (profileManager.getResult(t)== null) { toBeProfiled.add(t); workingOn.setText("Adding "+t.getName()+ " ("+toBeProfiled.size()+")"); } } profileManager.createProfiles(toBeProfiled, workingOn); progressBar.setVisible(false); JLabel status = new JLabel("Generating reports, Please wait......"); progressViewPanel.add(status, BorderLayout.NORTH); status.setVisible(true); JTabbedPane tabPane = new JTabbedPane(); ProfileTableModel tm = new ProfileTableModel(); for (SQLObject sqo: filter){ tm.addFilter(sqo); } tm.setProfileManager(profileManager); TableModelSortDecorator tableModelSortDecorator = new TableModelSortDecorator(tm); final JTable viewTable = new ProfileTable(tableModelSortDecorator); JTableHeader tableHeader = viewTable.getTableHeader(); tableModelSortDecorator.setTableHeader(tableHeader); viewTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); ProfilePanelMouseListener profilePanelMouseListener = new ProfilePanelMouseListener(); profilePanelMouseListener.setTabPane(tabPane); viewTable.addMouseListener( profilePanelMouseListener); JScrollPane editorScrollPane = new JScrollPane(viewTable); editorScrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorScrollPane.setPreferredSize(new Dimension(800, 600)); editorScrollPane.setMinimumSize(new Dimension(10, 10)); // reset column widths tableModelSortDecorator.initColumnSizes(viewTable); JPanel tableViewPane = new JPanel(new BorderLayout()); tableViewPane.add(editorScrollPane,BorderLayout.CENTER); ButtonBarBuilder buttonBuilder = new ButtonBarBuilder(); JButton save = new JButton(new AbstractAction("Save") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.addChoosableFileFilter(ASUtils.PDF_FILE_FILTER); chooser.addChoosableFileFilter(ASUtils.HTML_FILE_FILTER); chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter()); int response = chooser.showSaveDialog(d); if (response != JFileChooser.APPROVE_OPTION) { return; } else { File file = chooser.getSelectedFile(); final FileFilter fileFilter = chooser.getFileFilter(); if (fileFilter == ASUtils.HTML_FILE_FILTER) { if (!file.getPath().endsWith(".html")) { file = new File(file.getPath()+".html"); } } else { if (!file.getPath().endsWith(".pdf")) { file = new File(file.getPath()+".pdf"); } } if (file.exists()) { response = JOptionPane.showConfirmDialog( d, "The file\n\n"+file.getPath()+"\n\nalready exists. Do you want to overwrite it?", "File Exists", JOptionPane.YES_NO_OPTION); if (response == JOptionPane.NO_OPTION) { actionPerformed(e); return; } } final File file2 = new File(file.getPath()); Runnable saveTask = new Runnable() { public void run() { List tabList = new ArrayList(tables); OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(file2)); if (fileFilter == ASUtils.HTML_FILE_FILTER){ final String encoding = "utf-8"; ProfileHTMLFormat prf = new ProfileHTMLFormat(encoding); OutputStreamWriter osw = new OutputStreamWriter(out, encoding); osw.append(prf.format(tabList,profileManager)); osw.flush(); } else { new ProfilePDFFormat().createPdf(out, tabList, profileManager); } } catch (Exception ex) { ASUtils.showExceptionDialog(d,"Could not save PDF File", ex); } finally { if ( out != null ) { try { out.flush(); out.close(); } catch (IOException ex) { ASUtils.showExceptionDialog(d,"Could not close PDF File", ex); } } } } }; new Thread(saveTask).start(); } } }); JButton refresh = new JButton(new AbstractAction("Refresh"){ public void actionPerformed(ActionEvent e) { Set<SQLTable> uniqueTables = new HashSet(); for (int i: viewTable.getSelectedRows()) { Object o = viewTable.getValueAt(i,3); System.out.println(o.getClass()); SQLTable table = (SQLTable) o ; uniqueTables.add(table); } try { profileManager.setCancelled(false); profileManager.createProfiles(uniqueTables); } catch (SQLException e1) { throw new RuntimeException(e1); } catch (ArchitectException e1) { throw new ArchitectRuntimeException(e1); } TableModelSortDecorator t = (TableModelSortDecorator) viewTable.getModel(); ProfileTableModel t2 = (ProfileTableModel) t.getTableModel(); t2.refresh(); } }); JButton delete = new JButton(new AbstractAction("Delete"){ public void actionPerformed(ActionEvent e) { int[] killMe = viewTable.getSelectedRows(); Arrays.sort(killMe); // iterate backwards so the rows don't shift away on us! for (int i = killMe.length-1; i >= 0; i--) { logger.debug("Deleting row "+killMe[i]+": "+viewTable.getValueAt(killMe[i],4)); SQLColumn col = (SQLColumn) viewTable.getValueAt(killMe[i], 4); try { profileManager.remove(col); } catch (ArchitectException e1) { ASUtils.showExceptionDialog(d,"Could delete column:", e1); } } TableModelSortDecorator t = (TableModelSortDecorator) viewTable.getModel(); ProfileTableModel t2 = (ProfileTableModel) t.getTableModel(); t2.refresh(); } }); JButton deleteAll = new JButton(new AbstractAction("Delete All"){ public void actionPerformed(ActionEvent e) { profileManager.clear(); TableModelSortDecorator t = (TableModelSortDecorator) viewTable.getModel(); ProfileTableModel t2 = (ProfileTableModel) t.getTableModel(); t2.refresh(); } }); JButton[] buttonArray = {refresh,delete,deleteAll,save,closeButton}; buttonBuilder.addGriddedButtons(buttonArray); tableViewPane.add(buttonBuilder.getPanel(),BorderLayout.SOUTH); tabPane.addTab("Table View", tableViewPane ); ProfilePanel p = new ProfilePanel(profileManager); tabPane.addTab("Graph View",p); profilePanelMouseListener.setProfilePanel(p); List<SQLTable> list = new ArrayList(tables); p.setTables(list); p.setChartType(ChartTypes.PIE); d.setVisible(false); d.remove(progressViewPanel); d.setContentPane(tabPane); d.pack(); d.setLocationRelativeTo(ArchitectFrame.getMainInstance()); d.setVisible(true); } catch (SQLException e) { logger.error("Error in Profile Action ", e); ASUtils.showExceptionDialogNoReport(dbTree, "Error during profile run", e); } catch (ArchitectException e) { logger.error("Error in Profile Action", e); ASUtils.showExceptionDialog(dbTree, "Error during profile run", e); } } }).start(); } catch (Exception ex) { logger.error("Error in Profile Action ", ex); ASUtils.showExceptionDialog(dbTree, "Error during profile run", ex); } }
| 1,108,895
|
public void run() { try { List<SQLTable> toBeProfiled = new ArrayList<SQLTable>(); for (SQLTable t: tables) { if (profileManager.getResult(t)== null) { toBeProfiled.add(t); workingOn.setText("Adding "+t.getName()+ " ("+toBeProfiled.size()+")"); } } profileManager.createProfiles(toBeProfiled, workingOn); progressBar.setVisible(false); JLabel status = new JLabel("Generating reports, Please wait......"); progressViewPanel.add(status, BorderLayout.NORTH); status.setVisible(true); JTabbedPane tabPane = new JTabbedPane(); ProfileTableModel tm = new ProfileTableModel(); for (SQLObject sqo: filter){ tm.addFilter(sqo); } tm.setProfileManager(profileManager); TableModelSortDecorator tableModelSortDecorator = new TableModelSortDecorator(tm); final JTable viewTable = new ProfileTable(tableModelSortDecorator); JTableHeader tableHeader = viewTable.getTableHeader(); tableModelSortDecorator.setTableHeader(tableHeader); viewTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); ProfilePanelMouseListener profilePanelMouseListener = new ProfilePanelMouseListener(); profilePanelMouseListener.setTabPane(tabPane); viewTable.addMouseListener( profilePanelMouseListener); JScrollPane editorScrollPane = new JScrollPane(viewTable); editorScrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorScrollPane.setPreferredSize(new Dimension(800, 600)); editorScrollPane.setMinimumSize(new Dimension(10, 10)); // reset column widths tableModelSortDecorator.initColumnSizes(viewTable); JPanel tableViewPane = new JPanel(new BorderLayout()); tableViewPane.add(editorScrollPane,BorderLayout.CENTER); ButtonBarBuilder buttonBuilder = new ButtonBarBuilder(); JButton save = new JButton(new AbstractAction("Save") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.addChoosableFileFilter(ASUtils.PDF_FILE_FILTER); chooser.addChoosableFileFilter(ASUtils.HTML_FILE_FILTER); chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter()); int response = chooser.showSaveDialog(d); if (response != JFileChooser.APPROVE_OPTION) { return; } else { File file = chooser.getSelectedFile(); final FileFilter fileFilter = chooser.getFileFilter(); if (fileFilter == ASUtils.HTML_FILE_FILTER) { if (!file.getPath().endsWith(".html")) { file = new File(file.getPath()+".html"); } } else { if (!file.getPath().endsWith(".pdf")) { file = new File(file.getPath()+".pdf"); } } if (file.exists()) { response = JOptionPane.showConfirmDialog( d, "The file\n\n"+file.getPath()+"\n\nalready exists. Do you want to overwrite it?", "File Exists", JOptionPane.YES_NO_OPTION); if (response == JOptionPane.NO_OPTION) { actionPerformed(e); return; } } final File file2 = new File(file.getPath()); Runnable saveTask = new Runnable() { public void run() { List tabList = new ArrayList(tables); OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(file2)); if (fileFilter == ASUtils.HTML_FILE_FILTER){ final String encoding = "utf-8"; ProfileHTMLFormat prf = new ProfileHTMLFormat(encoding); OutputStreamWriter osw = new OutputStreamWriter(out, encoding); osw.append(prf.format(tabList,profileManager)); osw.flush(); } else { new ProfilePDFFormat().createPdf(out, tabList, profileManager); } } catch (Exception ex) { ASUtils.showExceptionDialog(d,"Could not save PDF File", ex); } finally { if ( out != null ) { try { out.flush(); out.close(); } catch (IOException ex) { ASUtils.showExceptionDialog(d,"Could not close PDF File", ex); } } } } }; new Thread(saveTask).start(); } } }); JButton refresh = new JButton(new AbstractAction("Refresh"){ public void actionPerformed(ActionEvent e) { Set<SQLTable> uniqueTables = new HashSet(); for (int i: viewTable.getSelectedRows()) { Object o = viewTable.getValueAt(i,3); System.out.println(o.getClass()); SQLTable table = (SQLTable) o ; uniqueTables.add(table); } try { profileManager.setCancelled(false); profileManager.createProfiles(uniqueTables); } catch (SQLException e1) { throw new RuntimeException(e1); } catch (ArchitectException e1) { throw new ArchitectRuntimeException(e1); } ((ProfileTableModel)viewTable.getModel()).refresh(); } }); JButton delete = new JButton(new AbstractAction("Delete"){ public void actionPerformed(ActionEvent e) { int[] killMe = viewTable.getSelectedRows(); Arrays.sort(killMe); // iterate backwards so the rows don't shift away on us! for (int i = killMe.length-1; i >= 0; i--) { logger.debug("Deleting row "+killMe[i]+": "+viewTable.getValueAt(killMe[i],4)); SQLColumn col = (SQLColumn) viewTable.getValueAt(killMe[i], 4); try { profileManager.remove(col); } catch (ArchitectException e1) { ASUtils.showExceptionDialog(d,"Could delete column:", e1); } } ((ProfileTableModel)viewTable.getModel()).refresh(); } }); JButton deleteAll = new JButton(new AbstractAction("Delete All"){ public void actionPerformed(ActionEvent e) { profileManager.clear(); ((ProfileTableModel)viewTable.getModel()).refresh(); } }); JButton[] buttonArray = {refresh,delete,deleteAll,save,closeButton}; buttonBuilder.addGriddedButtons(buttonArray); tableViewPane.add(buttonBuilder.getPanel(),BorderLayout.SOUTH); tabPane.addTab("Table View", tableViewPane ); ProfilePanel p = new ProfilePanel(profileManager); tabPane.addTab("Graph View",p); profilePanelMouseListener.setProfilePanel(p); List<SQLTable> list = new ArrayList(tables); p.setTables(list); p.setChartType(ChartTypes.PIE); d.setVisible(false); d.remove(progressViewPanel); d.setContentPane(tabPane); d.pack(); d.setLocationRelativeTo(ArchitectFrame.getMainInstance()); d.setVisible(true); } catch (SQLException e) { logger.error("Error in Profile Action ", e); ASUtils.showExceptionDialogNoReport(dbTree, "Error during profile run", e); } catch (ArchitectException e) { logger.error("Error in Profile Action", e); ASUtils.showExceptionDialog(dbTree, "Error during profile run", e); } }
|
public void run() { try { List<SQLTable> toBeProfiled = new ArrayList<SQLTable>(); for (SQLTable t: tables) { if (profileManager.getResult(t)== null) { toBeProfiled.add(t); workingOn.setText("Adding "+t.getName()+ " ("+toBeProfiled.size()+")"); } } profileManager.createProfiles(toBeProfiled, workingOn); progressBar.setVisible(false); JLabel status = new JLabel("Generating reports, Please wait......"); progressViewPanel.add(status, BorderLayout.NORTH); status.setVisible(true); JTabbedPane tabPane = new JTabbedPane(); ProfileTableModel tm = new ProfileTableModel(); for (SQLObject sqo: filter){ tm.addFilter(sqo); } tm.setProfileManager(profileManager); TableModelSortDecorator tableModelSortDecorator = new TableModelSortDecorator(tm); final JTable viewTable = new ProfileTable(tableModelSortDecorator); JTableHeader tableHeader = viewTable.getTableHeader(); tableModelSortDecorator.setTableHeader(tableHeader); viewTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); ProfilePanelMouseListener profilePanelMouseListener = new ProfilePanelMouseListener(); profilePanelMouseListener.setTabPane(tabPane); viewTable.addMouseListener( profilePanelMouseListener); JScrollPane editorScrollPane = new JScrollPane(viewTable); editorScrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); editorScrollPane.setPreferredSize(new Dimension(800, 600)); editorScrollPane.setMinimumSize(new Dimension(10, 10)); // reset column widths tableModelSortDecorator.initColumnSizes(viewTable); JPanel tableViewPane = new JPanel(new BorderLayout()); tableViewPane.add(editorScrollPane,BorderLayout.CENTER); ButtonBarBuilder buttonBuilder = new ButtonBarBuilder(); JButton save = new JButton(new AbstractAction("Save") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); chooser.addChoosableFileFilter(ASUtils.PDF_FILE_FILTER); chooser.addChoosableFileFilter(ASUtils.HTML_FILE_FILTER); chooser.removeChoosableFileFilter(chooser.getAcceptAllFileFilter()); int response = chooser.showSaveDialog(d); if (response != JFileChooser.APPROVE_OPTION) { return; } else { File file = chooser.getSelectedFile(); final FileFilter fileFilter = chooser.getFileFilter(); if (fileFilter == ASUtils.HTML_FILE_FILTER) { if (!file.getPath().endsWith(".html")) { file = new File(file.getPath()+".html"); } } else { if (!file.getPath().endsWith(".pdf")) { file = new File(file.getPath()+".pdf"); } } if (file.exists()) { response = JOptionPane.showConfirmDialog( d, "The file\n\n"+file.getPath()+"\n\nalready exists. Do you want to overwrite it?", "File Exists", JOptionPane.YES_NO_OPTION); if (response == JOptionPane.NO_OPTION) { actionPerformed(e); return; } } final File file2 = new File(file.getPath()); Runnable saveTask = new Runnable() { public void run() { List tabList = new ArrayList(tables); OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(file2)); if (fileFilter == ASUtils.HTML_FILE_FILTER){ final String encoding = "utf-8"; ProfileHTMLFormat prf = new ProfileHTMLFormat(encoding); OutputStreamWriter osw = new OutputStreamWriter(out, encoding); osw.append(prf.format(tabList,profileManager)); osw.flush(); } else { new ProfilePDFFormat().createPdf(out, tabList, profileManager); } } catch (Exception ex) { ASUtils.showExceptionDialog(d,"Could not save PDF File", ex); } finally { if ( out != null ) { try { out.flush(); out.close(); } catch (IOException ex) { ASUtils.showExceptionDialog(d,"Could not close PDF File", ex); } } } } }; new Thread(saveTask).start(); } } }); JButton refresh = new JButton(new AbstractAction("Refresh"){ public void actionPerformed(ActionEvent e) { Set<SQLTable> uniqueTables = new HashSet(); for (int i: viewTable.getSelectedRows()) { Object o = viewTable.getValueAt(i,3); System.out.println(o.getClass()); SQLTable table = (SQLTable) o ; uniqueTables.add(table); } try { profileManager.setCancelled(false); profileManager.createProfiles(uniqueTables); } catch (SQLException e1) { throw new RuntimeException(e1); } catch (ArchitectException e1) { throw new ArchitectRuntimeException(e1); } TableModelSortDecorator t = (TableModelSortDecorator) viewTable.getModel(); ProfileTableModel t2 = (ProfileTableModel) t.getTableModel(); t2.refresh(); } }); JButton delete = new JButton(new AbstractAction("Delete"){ public void actionPerformed(ActionEvent e) { int[] killMe = viewTable.getSelectedRows(); Arrays.sort(killMe); // iterate backwards so the rows don't shift away on us! for (int i = killMe.length-1; i >= 0; i--) { logger.debug("Deleting row "+killMe[i]+": "+viewTable.getValueAt(killMe[i],4)); SQLColumn col = (SQLColumn) viewTable.getValueAt(killMe[i], 4); try { profileManager.remove(col); } catch (ArchitectException e1) { ASUtils.showExceptionDialog(d,"Could delete column:", e1); } } TableModelSortDecorator t = (TableModelSortDecorator) viewTable.getModel(); ProfileTableModel t2 = (ProfileTableModel) t.getTableModel(); t2.refresh(); } }); JButton deleteAll = new JButton(new AbstractAction("Delete All"){ public void actionPerformed(ActionEvent e) { profileManager.clear(); TableModelSortDecorator t = (TableModelSortDecorator) viewTable.getModel(); ProfileTableModel t2 = (ProfileTableModel) t.getTableModel(); t2.refresh(); } }); JButton[] buttonArray = {refresh,delete,deleteAll,save,closeButton}; buttonBuilder.addGriddedButtons(buttonArray); tableViewPane.add(buttonBuilder.getPanel(),BorderLayout.SOUTH); tabPane.addTab("Table View", tableViewPane ); ProfilePanel p = new ProfilePanel(profileManager); tabPane.addTab("Graph View",p); profilePanelMouseListener.setProfilePanel(p); List<SQLTable> list = new ArrayList(tables); p.setTables(list); p.setChartType(ChartTypes.PIE); d.setVisible(false); d.remove(progressViewPanel); d.setContentPane(tabPane); d.pack(); d.setLocationRelativeTo(ArchitectFrame.getMainInstance()); d.setVisible(true); } catch (SQLException e) { logger.error("Error in Profile Action ", e); ASUtils.showExceptionDialogNoReport(dbTree, "Error during profile run", e); } catch (ArchitectException e) { logger.error("Error in Profile Action", e); ASUtils.showExceptionDialog(dbTree, "Error during profile run", e); } }
| 1,108,896
|
public void actionPerformed(ActionEvent e) { int[] killMe = viewTable.getSelectedRows(); Arrays.sort(killMe); // iterate backwards so the rows don't shift away on us! for (int i = killMe.length-1; i >= 0; i--) { logger.debug("Deleting row "+killMe[i]+": "+viewTable.getValueAt(killMe[i],4)); SQLColumn col = (SQLColumn) viewTable.getValueAt(killMe[i], 4); try { profileManager.remove(col); } catch (ArchitectException e1) { ASUtils.showExceptionDialog(d,"Could delete column:", e1); } } ((ProfileTableModel)viewTable.getModel()).refresh(); }
|
public void actionPerformed(ActionEvent e) { int[] killMe = viewTable.getSelectedRows(); Arrays.sort(killMe); // iterate backwards so the rows don't shift away on us! for (int i = killMe.length-1; i >= 0; i--) { logger.debug("Deleting row "+killMe[i]+": "+viewTable.getValueAt(killMe[i],4)); SQLColumn col = (SQLColumn) viewTable.getValueAt(killMe[i], 4); try { profileManager.remove(col); } catch (ArchitectException e1) { ASUtils.showExceptionDialog(d,"Could delete column:", e1); } } TableModelSortDecorator t = (TableModelSortDecorator) viewTable.getModel(); ProfileTableModel t2 = (ProfileTableModel) t.getTableModel(); t2.refresh(); }
| 1,108,897
|
public void actionPerformed(ActionEvent e) { profileManager.clear(); ((ProfileTableModel)viewTable.getModel()).refresh(); }
|
public void actionPerformed(ActionEvent e) { profileManager.clear(); TableModelSortDecorator t = (TableModelSortDecorator) viewTable.getModel(); ProfileTableModel t2 = (ProfileTableModel) t.getTableModel(); t2.refresh(); }
| 1,108,898
|
public TableModelSortDecorator(TableModel tableModel) { this(); setTableModel(tableModel); }
|
public TableModelSortDecorator(TableModel tableModel) { this(); setTableModel(tableModel); }
| 1,108,899
|
public void initColumnSizes(JTable table) { AbstractTableModel model = (AbstractTableModel)table.getModel(); TableColumn column = null; Component comp = null; int headerWidth = 0; int cellWidth = 0; TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); for (int i = 0; i < model.getColumnCount(); i++) { int colNo = table.convertColumnIndexToModel(i); column = table.getColumnModel().getColumn(colNo); cellWidth = 0; comp = headerRenderer.getTableCellRendererComponent( null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; for (int j = 0; j < table.getRowCount(); j++) { comp = table.getDefaultRenderer(model.getColumnClass(colNo)). getTableCellRendererComponent( table, table.getValueAt(j,colNo), false, false, j, colNo); cellWidth = Math.max(cellWidth, comp.getPreferredSize().width); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
|
public void initColumnSizes(JTable table) { AbstractTableModel model = (AbstractTableModel)table.getModel(); TableColumn column = null; Component comp = null; int headerWidth = 0; int cellWidth = 0; TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); for (int i = 0; i < model.getColumnCount(); i++) { int colNo = table.convertColumnIndexToModel(i); column = table.getColumnModel().getColumn(colNo); cellWidth = 0; comp = headerRenderer.getTableCellRendererComponent( null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; for (int j = 0; j < table.getRowCount(); j++) { comp = table.getDefaultRenderer(model.getColumnClass(colNo)). getTableCellRendererComponent( table, table.getValueAt(j,colNo), false, false, j, colNo); cellWidth = Math.max(cellWidth, comp.getPreferredSize().width); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
| 1,108,900
|
public void initColumnSizes(JTable table) { AbstractTableModel model = (AbstractTableModel)table.getModel(); TableColumn column = null; Component comp = null; int headerWidth = 0; int cellWidth = 0; TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); for (int i = 0; i < model.getColumnCount(); i++) { int colNo = table.convertColumnIndexToModel(i); column = table.getColumnModel().getColumn(colNo); cellWidth = 0; comp = headerRenderer.getTableCellRendererComponent( null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; for (int j = 0; j < table.getRowCount(); j++) { comp = table.getDefaultRenderer(model.getColumnClass(colNo)). getTableCellRendererComponent( table, table.getValueAt(j,colNo), false, false, j, colNo); cellWidth = Math.max(cellWidth, comp.getPreferredSize().width); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
|
public void initColumnSizes(JTable table) { AbstractTableModel model = (AbstractTableModel)table.getModel(); TableColumn column = null; Component comp = null; int headerWidth = 0; int cellWidth = 0; TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); for (int i = 0; i < model.getColumnCount(); i++) { int colNo = table.convertColumnIndexToModel(i); column = table.getColumnModel().getColumn(colNo); cellWidth = 0; comp = headerRenderer.getTableCellRendererComponent( table, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; for (int j = 0; j < table.getRowCount(); j++) { comp = table.getDefaultRenderer(model.getColumnClass(colNo)). getTableCellRendererComponent( table, table.getValueAt(j,colNo), false, false, j, colNo); cellWidth = Math.max(cellWidth, comp.getPreferredSize().width); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
| 1,108,901
|
public void initColumnSizes(JTable table) { AbstractTableModel model = (AbstractTableModel)table.getModel(); TableColumn column = null; Component comp = null; int headerWidth = 0; int cellWidth = 0; TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); for (int i = 0; i < model.getColumnCount(); i++) { int colNo = table.convertColumnIndexToModel(i); column = table.getColumnModel().getColumn(colNo); cellWidth = 0; comp = headerRenderer.getTableCellRendererComponent( null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; for (int j = 0; j < table.getRowCount(); j++) { comp = table.getDefaultRenderer(model.getColumnClass(colNo)). getTableCellRendererComponent( table, table.getValueAt(j,colNo), false, false, j, colNo); cellWidth = Math.max(cellWidth, comp.getPreferredSize().width); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
|
public void initColumnSizes(JTable table) { AbstractTableModel model = (AbstractTableModel)table.getModel(); TableColumn column = null; Component comp = null; int headerWidth = 0; int cellWidth = 0; TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); for (int i = 0; i < model.getColumnCount(); i++) { int colNo = table.convertColumnIndexToModel(i); column = table.getColumnModel().getColumn(colNo); cellWidth = 0; comp = headerRenderer.getTableCellRendererComponent( null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; for (int j = 0; j < table.getRowCount(); j++) { comp = table.getDefaultRenderer(model.getColumnClass(i)). getTableCellRendererComponent( table, table.getValueAt(j,colNo), false, false, j, colNo); cellWidth = Math.max(cellWidth, comp.getPreferredSize().width); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
| 1,108,902
|
public void initColumnSizes(JTable table) { AbstractTableModel model = (AbstractTableModel)table.getModel(); TableColumn column = null; Component comp = null; int headerWidth = 0; int cellWidth = 0; TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); for (int i = 0; i < model.getColumnCount(); i++) { int colNo = table.convertColumnIndexToModel(i); column = table.getColumnModel().getColumn(colNo); cellWidth = 0; comp = headerRenderer.getTableCellRendererComponent( null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; for (int j = 0; j < table.getRowCount(); j++) { comp = table.getDefaultRenderer(model.getColumnClass(colNo)). getTableCellRendererComponent( table, table.getValueAt(j,colNo), false, false, j, colNo); cellWidth = Math.max(cellWidth, comp.getPreferredSize().width); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
|
public void initColumnSizes(JTable table) { AbstractTableModel model = (AbstractTableModel)table.getModel(); TableColumn column = null; Component comp = null; int headerWidth = 0; int cellWidth = 0; TableCellRenderer headerRenderer = table.getTableHeader().getDefaultRenderer(); for (int i = 0; i < model.getColumnCount(); i++) { int colNo = table.convertColumnIndexToModel(i); column = table.getColumnModel().getColumn(colNo); cellWidth = 0; comp = headerRenderer.getTableCellRendererComponent( null, column.getHeaderValue(), false, false, 0, 0); headerWidth = comp.getPreferredSize().width; for (int j = 0; j < table.getRowCount(); j++) { comp = table.getDefaultRenderer(model.getColumnClass(colNo)). getTableCellRendererComponent( table, table.getValueAt(j,colNo), false, false, j, colNo); cellWidth = Math.max(cellWidth, comp.getPreferredSize().width); } column.setPreferredWidth(Math.max(headerWidth, cellWidth)); } }
| 1,108,903
|
public ProfilePanel(ProfileManager pm) { this.pm = pm; displayPanel = new ProfileGraphPanel(this, 0,pm); setup(); }
|
public ProfilePanel(ProfileManager pm) { displayPanel = new ProfileGraphPanel(this, 0,pm); setup(); }
| 1,108,904
|
public void linkageToChrom(boolean[] markerResults, PedFile pedFile, String[][] hmInfo) throws IllegalArgumentException, HaploViewException, PedFileException{ if(markerResults == null){ throw new IllegalArgumentException(); } Vector indList = pedFile.getOrder(); int numMarkers = 0; numSingletons = 0; numTrios = 0; numPeds = pedFile.getNumFamilies(); Individual currentInd; Family currentFamily; Vector chrom = new Vector(); for(int x=0; x < indList.size(); x++){ String[] indAndFamID = (String[])indList.elementAt(x); currentFamily = pedFile.getFamily(indAndFamID[0]); currentInd = currentFamily.getMember(indAndFamID[1]); if(currentInd.getIsTyped()){ //singleton //if only one indiv in fam AND no assoc test OR this is case control (assocTest=2) if((currentFamily.getNumMembers() == 1 && assocTest == 0) || assocTest == 2){ numMarkers = currentInd.getNumMarkers(); byte[] chrom1 = new byte[numMarkers]; byte[] chrom2 = new byte[numMarkers]; for (int i = 0; i < numMarkers; i++){ byte[] thisMarker = currentInd.getMarker(i); if (thisMarker[0] == thisMarker[1]){ chrom1[i] = thisMarker[0]; chrom2[i] = thisMarker[1]; }else{ chrom1[i] = 5; chrom2[i] = 5; } } chrom.add(new Chromosome(currentInd.getFamilyID(),currentInd.getIndividualID(),chrom1,currentInd.getAffectedStatus()==2)); chrom.add(new Chromosome(currentInd.getFamilyID(),currentInd.getIndividualID(),chrom2,currentInd.getAffectedStatus()==2)); numSingletons++; }else{ //trio //if indiv has both parents AND is affected OR no assoc test if (!(currentInd.getMomID().equals("0") || currentInd.getDadID().equals("0")) && (currentInd.getAffectedStatus() == 2 || assocTest == 0)){ numMarkers = currentInd.getNumMarkers(); byte[] dadTb = new byte[numMarkers]; byte[] dadUb = new byte[numMarkers]; byte[] momTb = new byte[numMarkers]; byte[] momUb = new byte[numMarkers]; boolean[] kidMissing = new boolean[numMarkers]; for (int i = 0; i < numMarkers; i++){ byte[] thisMarker = currentInd.getMarker(i); byte kid1 = thisMarker[0]; byte kid2 = thisMarker[1]; thisMarker = (currentFamily.getMember(currentInd.getMomID())).getMarker(i); byte mom1 = thisMarker[0]; byte mom2 = thisMarker[1]; thisMarker = (currentFamily.getMember(currentInd.getDadID())).getMarker(i); byte dad1 = thisMarker[0]; byte dad2 = thisMarker[1]; if (kid1 == 0 || kid2 == 0) { kidMissing[i] = true; //kid missing if (dad1 == dad2) { dadTb[i] = dad1; dadUb[i] = dad1; } else { dadTb[i] = 5; dadUb[i] = 5; } if (mom1 == mom2) { momTb[i] = mom1; momUb[i] = mom1; } else { momTb[i] = 5; momUb[i] = 5; } } else if (kid1 == kid2) { //kid homozygous if (dad1 == 0) { dadTb[i] = kid1; dadUb[i] = 0; } else if (dad1 == kid1) { dadTb[i] = dad1; dadUb[i] = dad2; } else { dadTb[i] = dad2; dadUb[i] = dad1; } if (mom1 == 0) { momTb[i] = kid1; momUb[i] = 0; } else if (mom1 == kid1) { momTb[i] = mom1; momUb[i] = mom2; } else { momTb[i] = mom2; momUb[i] = mom1; } } else { //kid heterozygous and this if tree's a bitch if (dad1 == 0 && mom1 == 0) { //both missing dadTb[i] = 0; dadUb[i] = 0; momTb[i] = 0; momUb[i] = 0; } else if (dad1 == 0 && mom1 != mom2) { //dad missing mom het dadTb[i] = 0; dadUb[i] = 0; momTb[i] = 5; momUb[i] = 5; } else if (mom1 == 0 && dad1 != dad2) { //dad het mom missing dadTb[i] = 5; dadUb[i] = 5; momTb[i] = 0; momUb[i] = 0; } else if (dad1 == 0 && mom1 == mom2) { //dad missing mom hom momTb[i] = mom1; momUb[i] = mom1; dadUb[i] = 0; if (kid1 == mom1) { dadTb[i] = kid2; } else { dadTb[i] = kid1; } } else if (mom1 == 0 && dad1 == dad2) { //mom missing dad hom dadTb[i] = dad1; dadUb[i] = dad1; momUb[i] = 0; if (kid1 == dad1) { momTb[i] = kid2; } else { momTb[i] = kid1; } } else if (dad1 == dad2 && mom1 != mom2) { //dad hom mom het dadTb[i] = dad1; dadUb[i] = dad2; if (kid1 == dad1) { momTb[i] = kid2; momUb[i] = kid1; } else { momTb[i] = kid1; momUb[i] = kid2; } } else if (mom1 == mom2 && dad1 != dad2) { //dad het mom hom momTb[i] = mom1; momUb[i] = mom2; if (kid1 == mom1) { dadTb[i] = kid2; dadUb[i] = kid1; } else { dadTb[i] = kid1; dadUb[i] = kid2; } } else if (dad1 == dad2 && mom1 == mom2) { //mom & dad hom dadTb[i] = dad1; dadUb[i] = dad1; momTb[i] = mom1; momUb[i] = mom1; } else { //everybody het dadTb[i] = 5; dadUb[i] = 5; momTb[i] = 5; momUb[i] = 5; } } } chrom.add(new Chromosome(currentInd.getFamilyID(),currentInd.getIndividualID(), dadTb,currentInd.getAffectedStatus()==2,kidMissing)); chrom.add(new Chromosome(currentInd.getFamilyID(),currentInd.getIndividualID(), dadUb,currentInd.getAffectedStatus()==2,kidMissing)); chrom.add(new Chromosome(currentInd.getFamilyID(),currentInd.getIndividualID(), momTb,currentInd.getAffectedStatus()==2,kidMissing)); chrom.add(new Chromosome(currentInd.getFamilyID(),currentInd.getIndividualID(), momUb,currentInd.getAffectedStatus()==2,kidMissing)); numTrios++; } } } } //set up the indexing to take into account skipped markers. Need //to loop through twice because first time we just count number of //unskipped markers int count = 0; for (int i = 0; i < numMarkers; i++){ if (markerResults[i]){ count++; } } Chromosome.realIndex = new int[count]; int k = 0; for (int i =0; i < numMarkers; i++){ if (markerResults[i]){ Chromosome.realIndex[k] = i; k++; } } chromosomes = chrom; try{ prepareMarkerInput(null,0,hmInfo); }catch(HaploViewException e){ }catch(IOException e){ } }
|
public void linkageToChrom(boolean[] markerResults, PedFile pedFile, String[][] hmInfo) throws IllegalArgumentException, HaploViewException, PedFileException{ if(markerResults == null){ throw new IllegalArgumentException(); } Vector indList = pedFile.getOrder(); int numMarkers = 0; numSingletons = 0; numTrios = 0; numPeds = pedFile.getNumFamilies(); Individual currentInd; Family currentFamily; Vector chrom = new Vector(); for(int x=0; x < indList.size(); x++){ String[] indAndFamID = (String[])indList.elementAt(x); currentFamily = pedFile.getFamily(indAndFamID[0]); currentInd = currentFamily.getMember(indAndFamID[1]); if(currentInd.getIsTyped()){ //singleton //if only one indiv in fam AND no assoc test OR this is case control (assocTest=2) if((currentFamily.getNumMembers() == 1 && assocTest == 0) || assocTest == 2){ numMarkers = currentInd.getNumMarkers(); byte[] chrom1 = new byte[numMarkers]; byte[] chrom2 = new byte[numMarkers]; for (int i = 0; i < numMarkers; i++){ byte[] thisMarker = currentInd.getMarker(i); if (thisMarker[0] == thisMarker[1]){ chrom1[i] = thisMarker[0]; chrom2[i] = thisMarker[1]; }else{ chrom1[i] = 5; chrom2[i] = 5; } } chrom.add(new Chromosome(currentInd.getFamilyID(),currentInd.getIndividualID(),chrom1,currentInd.getAffectedStatus()==2)); chrom.add(new Chromosome(currentInd.getFamilyID(),currentInd.getIndividualID(),chrom2,currentInd.getAffectedStatus()==2)); numSingletons++; }else{ //trio //if indiv has both parents AND is affected OR no assoc test if (!(currentInd.getMomID().equals("0") || currentInd.getDadID().equals("0")) && (currentInd.getAffectedStatus() == 2 || assocTest == 0)){ numMarkers = currentInd.getNumMarkers(); byte[] dadTb = new byte[numMarkers]; byte[] dadUb = new byte[numMarkers]; byte[] momTb = new byte[numMarkers]; byte[] momUb = new byte[numMarkers]; boolean[] kidMissing = new boolean[numMarkers]; for (int i = 0; i < numMarkers; i++){ byte[] thisMarker = currentInd.getMarker(i); byte kid1 = thisMarker[0]; byte kid2 = thisMarker[1]; thisMarker = (currentFamily.getMember(currentInd.getMomID())).getMarker(i); byte mom1 = thisMarker[0]; byte mom2 = thisMarker[1]; thisMarker = (currentFamily.getMember(currentInd.getDadID())).getMarker(i); byte dad1 = thisMarker[0]; byte dad2 = thisMarker[1]; if (kid1 == 0 || kid2 == 0) { kidMissing[i] = true; //kid missing if (dad1 == dad2) { dadTb[i] = dad1; dadUb[i] = dad1; } else { dadTb[i] = 5; dadUb[i] = 5; } if (mom1 == mom2) { momTb[i] = mom1; momUb[i] = mom1; } else { momTb[i] = 5; momUb[i] = 5; } } else if (kid1 == kid2) { //kid homozygous if (dad1 == 0) { dadTb[i] = kid1; dadUb[i] = 0; } else if (dad1 == kid1) { dadTb[i] = dad1; dadUb[i] = dad2; } else { dadTb[i] = dad2; dadUb[i] = dad1; } if (mom1 == 0) { momTb[i] = kid1; momUb[i] = 0; } else if (mom1 == kid1) { momTb[i] = mom1; momUb[i] = mom2; } else { momTb[i] = mom2; momUb[i] = mom1; } } else { //kid heterozygous and this if tree's a bitch if (dad1 == 0 && mom1 == 0) { //both missing dadTb[i] = 0; dadUb[i] = 0; momTb[i] = 0; momUb[i] = 0; } else if (dad1 == 0 && mom1 != mom2) { //dad missing mom het dadTb[i] = 0; dadUb[i] = 0; momTb[i] = 5; momUb[i] = 5; } else if (mom1 == 0 && dad1 != dad2) { //dad het mom missing dadTb[i] = 5; dadUb[i] = 5; momTb[i] = 0; momUb[i] = 0; } else if (dad1 == 0 && mom1 == mom2) { //dad missing mom hom momTb[i] = mom1; momUb[i] = mom1; dadUb[i] = 0; if (kid1 == mom1) { dadTb[i] = kid2; } else { dadTb[i] = kid1; } } else if (mom1 == 0 && dad1 == dad2) { //mom missing dad hom dadTb[i] = dad1; dadUb[i] = dad1; momUb[i] = 0; if (kid1 == dad1) { momTb[i] = kid2; } else { momTb[i] = kid1; } } else if (dad1 == dad2 && mom1 != mom2) { //dad hom mom het dadTb[i] = dad1; dadUb[i] = dad2; if (kid1 == dad1) { momTb[i] = kid2; momUb[i] = kid1; } else { momTb[i] = kid1; momUb[i] = kid2; } } else if (mom1 == mom2 && dad1 != dad2) { //dad het mom hom momTb[i] = mom1; momUb[i] = mom2; if (kid1 == mom1) { dadTb[i] = kid2; dadUb[i] = kid1; } else { dadTb[i] = kid1; dadUb[i] = kid2; } } else if (dad1 == dad2 && mom1 == mom2) { //mom & dad hom dadTb[i] = dad1; dadUb[i] = dad1; momTb[i] = mom1; momUb[i] = mom1; } else { //everybody het dadTb[i] = 5; dadUb[i] = 5; momTb[i] = 5; momUb[i] = 5; } } } chrom.add(new Chromosome(currentInd.getFamilyID(),currentInd.getIndividualID(), dadTb,currentInd.getAffectedStatus()==2,kidMissing)); chrom.add(new Chromosome(currentInd.getFamilyID(),currentInd.getIndividualID(), dadUb,currentInd.getAffectedStatus()==2,kidMissing)); chrom.add(new Chromosome(currentInd.getFamilyID(),currentInd.getIndividualID(), momTb,currentInd.getAffectedStatus()==2,kidMissing)); chrom.add(new Chromosome(currentInd.getFamilyID(),currentInd.getIndividualID(), momUb,currentInd.getAffectedStatus()==2,kidMissing)); numTrios++; } } } } //set up the indexing to take into account skipped markers. Need //to loop through twice because first time we just count number of //unskipped markers int count = 0; for (int i = 0; i < numMarkers; i++){ if (markerResults[i]){ count++; } } Chromosome.realIndex = new int[count]; int k = 0; for (int i =0; i < numMarkers; i++){ if (markerResults[i]){ Chromosome.realIndex[k] = i; k++; } } chromosomes = chrom; try{ prepareMarkerInput(null,0,hmInfo); }catch(HaploViewException e){ }catch(IOException e){ } }
| 1,108,905
|
public void saveDprimeToText(File dumpDprimeFile) throws IOException{ FileWriter saveDprimeWriter = new FileWriter(dumpDprimeFile); if (infoKnown){ saveDprimeWriter.write("L1\tL2\tD'\tLOD\tr^2\tCIlow\tCIhi\tDist\tT-int\n"); long dist; for (int i = 0; i < filteredDPrimeTable.length; i++){ for (int j = 0; j < filteredDPrimeTable[i].length; j++){ //many "slots" in table aren't filled in because it is a 1/2 matrix if (i < j){ if(filteredDPrimeTable[i][j] != null) { double LODSum = 0; String tInt = "-"; if (i == j-1){ //this belongs somewhere else really... //these are adjacent markers so we'll put in the t-int stat for (int x = 0; x < 5; x++){ for (int y = 1; y < 6; y++){ if (i-x < 0 || i+y >= filteredDPrimeTable.length){ continue; } LODSum += filteredDPrimeTable[i-x][i+y].getLOD(); } } tInt = String.valueOf(roundDouble(LODSum)); } dist = (Chromosome.getFilteredMarker(j)).getPosition() - (Chromosome.getFilteredMarker(i)).getPosition(); saveDprimeWriter.write(Chromosome.getFilteredMarker(i).getName() + "\t" + Chromosome.getFilteredMarker(j).getName() + "\t" + filteredDPrimeTable[i][j].toString() + "\t" + dist + "\t" + tInt +"\n"); } } } } }else{ saveDprimeWriter.write("L1\tL2\tD'\tLOD\tr^2\tCIlow\tCIhi\tT-int\n"); for (int i = 0; i < filteredDPrimeTable.length; i++){ for (int j = 0; j < filteredDPrimeTable[i].length; j++){ //many "slots" in table aren't filled in because it is a 1/2 matrix if (i < j){ if(filteredDPrimeTable[i][j] != null) { double LODSum = 0; String tInt = "-"; if (i == j-1){ //this belongs somewhere else really... //these are adjacent markers so we'll put in the t-int stat int numGaps = filteredDPrimeTable.length; double prev = 0; for (int gap = 0; gap < numGaps; gap++){ for (int x = 0; x < 5; x++){ for (int y = 1; y < 6; y++){ if (gap-x < 0 || gap+y >= numGaps){ continue; } LODSum += filteredDPrimeTable[gap-x][gap+y].getLOD(); } } } tInt = String.valueOf(roundDouble(LODSum)); } saveDprimeWriter.write((Chromosome.realIndex[i]+1) + "\t" + (Chromosome.realIndex[j]+1) + "\t" + filteredDPrimeTable[i][j] + "\t" + tInt + "\n"); } } } } } saveDprimeWriter.close(); }
|
public void saveDprimeToText(File dumpDprimeFile) throws IOException{ FileWriter saveDprimeWriter = new FileWriter(dumpDprimeFile); if (infoKnown){ saveDprimeWriter.write("L1\tL2\tD'\tLOD\tr^2\tCIlow\tCIhi\tDist\tT-int\n"); long dist; for (int i = 0; i < filteredDPrimeTable.length; i++){ for (int j = 0; j < filteredDPrimeTable[i].length; j++){ //many "slots" in table aren't filled in because it is a 1/2 matrix if (i < j){ if(filteredDPrimeTable[i][j] != null) { double LODSum = 0; String tInt = "-"; if (i == j-1){ //this belongs somewhere else really... //these are adjacent markers so we'll put in the t-int stat for (int x = 0; x < 5; x++){ for (int y = 1; y < 6; y++){ if (i-x < 0 || i+y >= filteredDPrimeTable.length){ continue; } LODSum += filteredDPrimeTable[i-x][i+y].getLOD(); } } tInt = String.valueOf(roundDouble(LODSum)); } dist = (Chromosome.getFilteredMarker(j)).getPosition() - (Chromosome.getFilteredMarker(i)).getPosition(); saveDprimeWriter.write(Chromosome.getFilteredMarker(i).getName() + "\t" + Chromosome.getFilteredMarker(j).getName() + "\t" + filteredDPrimeTable[i][j].toString() + "\t" + dist + "\t" + tInt +"\n"); } } } } }else{ saveDprimeWriter.write("L1\tL2\tD'\tLOD\tr^2\tCIlow\tCIhi\tT-int\n"); for (int i = 0; i < filteredDPrimeTable.length; i++){ for (int j = 0; j < filteredDPrimeTable[i].length; j++){ //many "slots" in table aren't filled in because it is a 1/2 matrix if (i < j){ if(filteredDPrimeTable[i][j] != null) { double LODSum = 0; String tInt = "-"; if (i == j-1){ //this belongs somewhere else really... //these are adjacent markers so we'll put in the t-int stat int numGaps = filteredDPrimeTable.length; double prev = 0; for (int gap = 0; gap < numGaps; gap++){ for (int x = 0; x < 5; x++){ for (int y = 1; y < 6; y++){ if (gap-x < 0 || gap+y >= numGaps){ continue; } LODSum += filteredDPrimeTable[gap-x][gap+y].getLOD(); } } } tInt = String.valueOf(roundDouble(LODSum)); } saveDprimeWriter.write((Chromosome.realIndex[i]+1) + "\t" + (Chromosome.realIndex[j]+1) + "\t" + filteredDPrimeTable[i][j] + "\t" + tInt + "\n"); } } } } } saveDprimeWriter.close(); }
| 1,108,906
|
public String toString() { return "[TableProfileResult: col: ??; dataType: ??" + "; distinctValues: "+distinctValueCount+ "; minLength: "+minLength+ "; maxLength: "+maxLength+ "; avgLength: "+avgLength+ "; minValue: "+minValue+ "; maxValue: "+maxValue+ "; avgValue: "+avgValue+"]"; }
|
public String toString() { return "[ColumnProfileResult:" + "; distinctValues: "+distinctValueCount+ "; minLength: "+minLength+ "; maxLength: "+maxLength+ "; avgLength: "+avgLength+ "; minValue: "+minValue+ "; maxValue: "+maxValue+ "; avgValue: "+avgValue+"]"; }
| 1,108,909
|
public String toString() { return "[TableProfileResult: col: ??; dataType: ??" + "; distinctValues: "+distinctValueCount+ "; minLength: "+minLength+ "; maxLength: "+maxLength+ "; avgLength: "+avgLength+ "; minValue: "+minValue+ "; maxValue: "+maxValue+ "; avgValue: "+avgValue+"]"; }
|
public String toString() { return "[TableProfileResult: col: ??; dataType: ??" + "; distinctValues: "+distinctValueCount+ "; minLength: "+minLength+ "; maxLength: "+maxLength+ "; avgLength: "+avgLength+ "; minValue: "+minValue+ "; maxValue: "+maxValue+ "; avgValue: "+avgValue+ "; nullCount: "+getNullCount()+ "]"; }
| 1,108,910
|
protected abstract void init(Map<String, String> properties);
|
public void init(Element componentConfig) { id = componentConfig.getAttribute(ID).getValue(); properties = new Properties(componentConfig); init(properties); Element eventElement = componentConfig.getChild("event"); if(eventElement != null){ event = new Event(eventElement); } }
| 1,108,911
|
protected XMLOutput createXMLOutput() throws Exception { OutputFormat format = null; if (prettyPrint) { format = OutputFormat.createPrettyPrint(); } else { format = new OutputFormat(); } if ( encoding != null ) { format.setEncoding( encoding ); } if ( omitXmlDeclaration ) { format.setSuppressDeclaration(true); } OutputStream out = new FileOutputStream(name); boolean isHtml = outputMode != null && outputMode.equalsIgnoreCase( "html" ); final XMLWriter xmlWriter = (isHtml) ? new HTMLWriter(out, format) : new XMLWriter(out, format); XMLOutput answer = new XMLOutput() { public void close() throws IOException { xmlWriter.close(); } }; answer.setContentHandler(xmlWriter); answer.setLexicalHandler(xmlWriter); return answer; }
|
protected XMLOutput createXMLOutput(Writer writer) throws Exception { OutputFormat format = null; if (prettyPrint) { format = OutputFormat.createPrettyPrint(); } else { format = new OutputFormat(); } if ( encoding != null ) { format.setEncoding( encoding ); } if ( omitXmlDeclaration ) { format.setSuppressDeclaration(true); } OutputStream out = new FileOutputStream(name); boolean isHtml = outputMode != null && outputMode.equalsIgnoreCase( "html" ); final XMLWriter xmlWriter = (isHtml) ? new HTMLWriter(out, format) : new XMLWriter(out, format); XMLOutput answer = new XMLOutput() { public void close() throws IOException { xmlWriter.close(); } }; answer.setContentHandler(xmlWriter); answer.setLexicalHandler(xmlWriter); return answer; }
| 1,108,912
|
protected XMLOutput createXMLOutput() throws Exception { OutputFormat format = null; if (prettyPrint) { format = OutputFormat.createPrettyPrint(); } else { format = new OutputFormat(); } if ( encoding != null ) { format.setEncoding( encoding ); } if ( omitXmlDeclaration ) { format.setSuppressDeclaration(true); } OutputStream out = new FileOutputStream(name); boolean isHtml = outputMode != null && outputMode.equalsIgnoreCase( "html" ); final XMLWriter xmlWriter = (isHtml) ? new HTMLWriter(out, format) : new XMLWriter(out, format); XMLOutput answer = new XMLOutput() { public void close() throws IOException { xmlWriter.close(); } }; answer.setContentHandler(xmlWriter); answer.setLexicalHandler(xmlWriter); return answer; }
|
protected XMLOutput createXMLOutput() throws Exception { OutputFormat format = null; if (prettyPrint) { format = OutputFormat.createPrettyPrint(); } else { format = new OutputFormat(); } if ( encoding != null ) { format.setEncoding( encoding ); } if ( omitXmlDeclaration ) { format.setSuppressDeclaration(true); } boolean isHtml = outputMode != null && outputMode.equalsIgnoreCase( "html" ); final XMLWriter xmlWriter = (isHtml) ? new HTMLWriter(out, format) : new XMLWriter(out, format); XMLOutput answer = new XMLOutput() { public void close() throws IOException { xmlWriter.close(); } }; answer.setContentHandler(xmlWriter); answer.setLexicalHandler(xmlWriter); return answer; }
| 1,108,913
|
protected XMLOutput createXMLOutput() throws Exception { OutputFormat format = null; if (prettyPrint) { format = OutputFormat.createPrettyPrint(); } else { format = new OutputFormat(); } if ( encoding != null ) { format.setEncoding( encoding ); } if ( omitXmlDeclaration ) { format.setSuppressDeclaration(true); } OutputStream out = new FileOutputStream(name); boolean isHtml = outputMode != null && outputMode.equalsIgnoreCase( "html" ); final XMLWriter xmlWriter = (isHtml) ? new HTMLWriter(out, format) : new XMLWriter(out, format); XMLOutput answer = new XMLOutput() { public void close() throws IOException { xmlWriter.close(); } }; answer.setContentHandler(xmlWriter); answer.setLexicalHandler(xmlWriter); return answer; }
|
protected XMLOutput createXMLOutput() throws Exception { OutputFormat format = null; if (prettyPrint) { format = OutputFormat.createPrettyPrint(); } else { format = new OutputFormat(); } if ( encoding != null ) { format.setEncoding( encoding ); } if ( omitXmlDeclaration ) { format.setSuppressDeclaration(true); } OutputStream out = new FileOutputStream(name); boolean isHtml = outputMode != null && outputMode.equalsIgnoreCase( "html" ); final XMLWriter xmlWriter = (isHtml) ? new HTMLWriter(out, format) : new XMLWriter(out, format); XMLOutput answer = new XMLOutput() { public void close() throws IOException { xmlWriter.close(); } }; answer.setContentHandler(xmlWriter); answer.setLexicalHandler(xmlWriter); return answer; }
| 1,108,914
|
public void doTag(final XMLOutput output) throws Exception { if ( name == null ) { throw new MissingAttributeException( "name" ); } XMLOutput newOutput = createXMLOutput(); try { newOutput.startDocument(); invokeBody(newOutput); newOutput.endDocument(); } finally { newOutput.close(); } }
|
public void doTag(final XMLOutput output) throws Exception { if ( name == null ) { throw new MissingAttributeException( "name" ); } XMLOutput newOutput = createXMLOutput(); try { newOutput.startDocument(); invokeBody(newOutput); newOutput.endDocument(); } finally { newOutput.close(); } }
| 1,108,915
|
public void doTag(final XMLOutput output) throws Exception { if ( name == null ) { throw new MissingAttributeException( "name" ); } XMLOutput newOutput = createXMLOutput(); try { newOutput.startDocument(); invokeBody(newOutput); newOutput.endDocument(); } finally { newOutput.close(); } }
|
public void doTag(final XMLOutput output) throws Exception { if ( name == null ) { throw new MissingAttributeException( "name" ); } XMLOutput newOutput = createXMLOutput(); try { newOutput.startDocument(); invokeBody(newOutput); newOutput.endDocument(); } finally { newOutput.close(); } }
| 1,108,916
|
public void doTag(final XMLOutput output) throws Exception { if ( name == null ) { throw new MissingAttributeException( "name" ); } XMLOutput newOutput = createXMLOutput(); try { newOutput.startDocument(); invokeBody(newOutput); newOutput.endDocument(); } finally { newOutput.close(); } }
|
public void doTag(final XMLOutput output) throws Exception { if ( name == null ) { throw new MissingAttributeException( "name" ); } XMLOutput newOutput = createXMLOutput(); try { newOutput.startDocument(); invokeBody(newOutput); newOutput.endDocument(); } finally { newOutput.close(); } }
| 1,108,917
|
public void testDatabaseCollection() { PhotovaultDatabases pvd = new PhotovaultDatabases(); PVDatabase db1 = new PVDatabase(); db1.setName( "test1" ); db1.setDbName( "database1" ); db1.setDbHost( "machine" ); pvd.addDatabase( db1 ); PVDatabase db2 = new PVDatabase(); db2.setName( "test2" ); db2.setDbName( "database2" ); db2.setDbHost( "machine2" ); pvd.addDatabase( db2 ); File f = null; try { f = File.createTempFile( "photovault_settings_", ".xml" ); } catch ( Exception e ) { fail( e.getMessage()); } pvd.save( f ); PhotovaultDatabases pvd2 = PhotovaultDatabases.loadDatabases( f ); }
|
public void testDatabaseCollection() { PhotovaultDatabases pvd = new PhotovaultDatabases(); PVDatabase db1 = new PVDatabase(); db1.setName( "test1" ); db1.setDbName( "database1" ); db1.setDbHost( "machine" ); try { pvd.addDatabase( db1 ); } catch (PhotovaultException ex) { fail( "Exception while registering database: " + ex.getMessage() ); } PVDatabase db2 = new PVDatabase(); db2.setName( "test2" ); db2.setDbName( "database2" ); db2.setDbHost( "machine2" ); pvd.addDatabase( db2 ); File f = null; try { f = File.createTempFile( "photovault_settings_", ".xml" ); } catch ( Exception e ) { fail( e.getMessage()); } pvd.save( f ); PhotovaultDatabases pvd2 = PhotovaultDatabases.loadDatabases( f ); }
| 1,108,919
|
public void testDatabaseCollection() { PhotovaultDatabases pvd = new PhotovaultDatabases(); PVDatabase db1 = new PVDatabase(); db1.setName( "test1" ); db1.setDbName( "database1" ); db1.setDbHost( "machine" ); pvd.addDatabase( db1 ); PVDatabase db2 = new PVDatabase(); db2.setName( "test2" ); db2.setDbName( "database2" ); db2.setDbHost( "machine2" ); pvd.addDatabase( db2 ); File f = null; try { f = File.createTempFile( "photovault_settings_", ".xml" ); } catch ( Exception e ) { fail( e.getMessage()); } pvd.save( f ); PhotovaultDatabases pvd2 = PhotovaultDatabases.loadDatabases( f ); }
|
public void testDatabaseCollection() { PhotovaultDatabases pvd = new PhotovaultDatabases(); PVDatabase db1 = new PVDatabase(); db1.setName( "test1" ); db1.setDbName( "database1" ); db1.setDbHost( "machine" ); pvd.addDatabase( db1 ); PVDatabase db2 = new PVDatabase(); db2.setName( "test2" ); db2.setDbName( "database2" ); db2.setDbHost( "machine2" ); try { pvd.addDatabase( db2 ); } catch (PhotovaultException ex) { fail( "Exception while registering database: " + ex.getMessage() ); } File f = null; try { f = File.createTempFile( "photovault_settings_", ".xml" ); } catch ( Exception e ) { fail( e.getMessage()); } pvd.save( f ); PhotovaultDatabases pvd2 = PhotovaultDatabases.loadDatabases( f ); }
| 1,108,920
|
protected static Thumbnail createThumbnail( PhotoInfo photo, File thumbnailFile ) { Thumbnail thumb = new Thumbnail(); thumb.photo = photo; log.debug( "Creating thumbnail for " + photo.getUid() ); log.debug( " - " + thumbnailFile.getPath() ); try { thumb.image = ImageIO.read( thumbnailFile ); } catch ( IOException e ) { log.warn( "Error reading thumbnail image: " + e.getMessage() ); return null; } return thumb; }
|
protected static Thumbnail createThumbnail( PhotoInfo photo, File thumbnailFile ) { Thumbnail thumb = new Thumbnail(); thumb.photo = photo; log.debug( "Creating thumbnail for " + photo.getUid() ); log.debug( " - " + thumbnailFile.getPath() ); try { thumb.image = ImageIO.read( thumbnailFile ); } catch ( IOException e ) { log.warn( "Error reading thumbnail image: " + e.getMessage() ); return getDefaultThumbnail(); } return thumb; }
| 1,108,922
|
Vector do4Gamete(){ Vector blocks = new Vector(); for (int x = 0; x < dPrime.length-1; x++){ String thisOne = new String(x + " "); boolean start = false; for (int y = x+1; y < dPrime.length; y++){ PairwiseLinkage thisPair = dPrime[x][y]; double[] freqs = thisPair.getFreqs(); int numGam = 0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam++; } if (numGam == 4){ if (start){ boolean isABlock = true; /** FIX THIS for (int xx = x+1; x < y-1; xx++){ for (int yy = xx+1; yy < y; yy++){ int numGam2=0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam2++; } if(numGam2 == 4){ isABlock = false; } } } **/ if (isABlock){ thisOne += y-1; blocks.add(thisOne); x=y-1; } } break; } start = true; } } return stringVec2intVec(blocks); }
|
Vector do4Gamete(){ Vector blocks = new Vector(); for (int x = 0; x < dPrime.length-1; x++){ String thisOne = new String(x + " "); boolean start = false; for (int y = x+1; y < dPrime.length; y++){ PairwiseLinkage thisPair = dPrime[x][y]; double[] freqs = thisPair.getFreqs(); int numGam = 0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam++; } if (numGam == 4){ if (start){ boolean isABlock = true; /** FIX THIS for (int xx = x+1; x < y-1; xx++){ for (int yy = xx+1; yy < y; yy++){ int numGam2=0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam2++; } if(numGam2 == 4){ isABlock = false; } } } **/ if (isABlock){ thisOne += y-1; blocks.add(thisOne); x=y-1; } } break; } start = true; } } return stringVec2intVec(blocks); }
| 1,108,923
|
Vector do4Gamete(){ Vector blocks = new Vector(); for (int x = 0; x < dPrime.length-1; x++){ String thisOne = new String(x + " "); boolean start = false; for (int y = x+1; y < dPrime.length; y++){ PairwiseLinkage thisPair = dPrime[x][y]; double[] freqs = thisPair.getFreqs(); int numGam = 0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam++; } if (numGam == 4){ if (start){ boolean isABlock = true; /** FIX THIS for (int xx = x+1; x < y-1; xx++){ for (int yy = xx+1; yy < y; yy++){ int numGam2=0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam2++; } if(numGam2 == 4){ isABlock = false; } } } **/ if (isABlock){ thisOne += y-1; blocks.add(thisOne); x=y-1; } } break; } start = true; } } return stringVec2intVec(blocks); }
|
Vector do4Gamete(){ Vector blocks = new Vector(); for (int x = 0; x < dPrime.length-1; x++){ String thisOne = new String(x + " "); boolean start = false; for (int y = x+1; y < dPrime.length; y++){ PairwiseLinkage thisPair = dPrime[x][y]; double[] freqs = thisPair.getFreqs(); int numGam = 0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam++; } if (numGam == 4){ if (start){ boolean isABlock = true; /** FIX THIS for (int xx = x+1; x < y-1; xx++){ for (int yy = xx+1; yy < y; yy++){ int numGam2=0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam2++; } if(numGam2 == 4){ isABlock = false; } } } **/ if (isABlock){ thisOne += y-1; blocks.add(thisOne); x=y-1; } } break; } start = true; } } return stringVec2intVec(blocks); }
| 1,108,924
|
Vector do4Gamete(){ Vector blocks = new Vector(); for (int x = 0; x < dPrime.length-1; x++){ String thisOne = new String(x + " "); boolean start = false; for (int y = x+1; y < dPrime.length; y++){ PairwiseLinkage thisPair = dPrime[x][y]; double[] freqs = thisPair.getFreqs(); int numGam = 0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam++; } if (numGam == 4){ if (start){ boolean isABlock = true; /** FIX THIS for (int xx = x+1; x < y-1; xx++){ for (int yy = xx+1; yy < y; yy++){ int numGam2=0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam2++; } if(numGam2 == 4){ isABlock = false; } } } **/ if (isABlock){ thisOne += y-1; blocks.add(thisOne); x=y-1; } } break; } start = true; } } return stringVec2intVec(blocks); }
|
Vector do4Gamete(){ Vector blocks = new Vector(); for (int x = 0; x < dPrime.length-1; x++){ String thisOne = new String(x + " "); boolean start = false; for (int y = x+1; y < dPrime.length; y++){ PairwiseLinkage thisPair = dPrime[x][y]; double[] freqs = thisPair.getFreqs(); int numGam = 0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam++; } if (numGam == 4){ if (start){ boolean isABlock = true; /** FIX THIS for (int xx = x+1; x < y-1; xx++){ for (int yy = xx+1; yy < y; yy++){ int numGam2=0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam2++; } if(numGam2 == 4){ isABlock = false; } } } **/ if (isABlock){ thisOne += y-1; blocks.add(thisOne); x=y-1; } } } start = true; } } return stringVec2intVec(blocks); }
| 1,108,925
|
Vector do4Gamete(){ Vector blocks = new Vector(); for (int x = 0; x < dPrime.length-1; x++){ String thisOne = new String(x + " "); boolean start = false; for (int y = x+1; y < dPrime.length; y++){ PairwiseLinkage thisPair = dPrime[x][y]; double[] freqs = thisPair.getFreqs(); int numGam = 0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam++; } if (numGam == 4){ if (start){ boolean isABlock = true; /** FIX THIS for (int xx = x+1; x < y-1; xx++){ for (int yy = xx+1; yy < y; yy++){ int numGam2=0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam2++; } if(numGam2 == 4){ isABlock = false; } } } **/ if (isABlock){ thisOne += y-1; blocks.add(thisOne); x=y-1; } } break; } start = true; } } return stringVec2intVec(blocks); }
|
Vector do4Gamete(){ Vector blocks = new Vector(); for (int x = 0; x < dPrime.length-1; x++){ String thisOne = new String(x + " "); boolean start = false; for (int y = x+1; y < dPrime.length; y++){ PairwiseLinkage thisPair = dPrime[x][y]; double[] freqs = thisPair.getFreqs(); int numGam = 0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam++; } if (numGam == 4){ if (start){ boolean isABlock = true; /** FIX THIS for (int xx = x+1; x < y-1; xx++){ for (int yy = xx+1; yy < y; yy++){ int numGam2=0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam2++; } if(numGam2 == 4){ isABlock = false; } } } **/ if (isABlock){ thisOne += y-1; blocks.add(thisOne); x=y-1; } } break; } } } boolean[] usedInBlock = new boolean[dPrime.length + 1]; for (int v = 0; v < strongPairs.size(); v++){ boolean isABlock = true; int first = Integer.parseInt((String)((Vector)strongPairs.elementAt(v)).elementAt(0)); int last = Integer.parseInt((String)((Vector)strongPairs.elementAt(v)).elementAt(1)); if (usedInBlock[first] || usedInBlock[last]) continue; for (int y = first+1; y <= last; y++){ for (int x = first; x < y; x++){ PairwiseLinkage thisPair = dPrime[x][y]; double[] freqs = thisPair.getFreqs(); int numGam = 0; for (int i = 0; i < freqs.length; i++){ if (freqs[i] > fourGameteCutoff) numGam++; } if (numGam > 3){ isABlock = false; } } } if (isABlock){ if (blocks.size() == 0){ blocks.add(first + " " + last); }else{ boolean placed = false; for (int b = 0; b < blocks.size(); b ++){ StringTokenizer st = new StringTokenizer((String)blocks.elementAt(b)); if (first < Integer.parseInt(st.nextToken())){ blocks.insertElementAt(first + " " + last, b); placed = true; break; } } if (!placed) blocks.add(first + " " + last); } for (int used = first; used <= last; used++){ usedInBlock[used] = true; } } } return stringVec2intVec(blocks); }
| 1,108,926
|
public void run(Context context, XMLOutput output) throws Exception { DefineTagLibTag tag = (DefineTagLibTag) findAncestorWithClass(this, DefineTagLibTag.class); if ( tag == null ) { throw new JellyException( "<define:tag> must be inside <define:taglib>" ); } tag.getTagLibrary().registerDynamicTag( getName(), getBody() ); }
|
public void run(JellyContext context, XMLOutput output) throws Exception { DefineTagLibTag tag = (DefineTagLibTag) findAncestorWithClass(this, DefineTagLibTag.class); if ( tag == null ) { throw new JellyException( "<define:tag> must be inside <define:taglib>" ); } tag.getTagLibrary().registerDynamicTag( getName(), getBody() ); }
| 1,108,927
|
public Object evaluate(Context context) { this.context = context; xpath.setVariableContext( this ); return xpath; }
|
public Object evaluate(JellyContext context) { this.context = context; xpath.setVariableContext( this ); return xpath; }
| 1,108,928
|
public void doTag(XMLOutput output) throws JellyTagException { // lets find any attributes that are not set and for ( Iterator iter = attributes.values().iterator(); iter.hasNext(); ) { Attribute attribute = (Attribute) iter.next(); String name = attribute.getName(); if ( ! setAttributesSet.contains( name ) ) { if ( attribute.isRequired() ) { throw new MissingAttributeException(name); } // lets get the default value Object value = null; Expression expression = attribute.getDefaultValue(); if ( expression != null ) { value = expression.evaluate(context); } // only set non-null values? if ( value != null ) { super.setAttribute(name, value); } } } // If the dynamic bean is itself a tag, let it execute itself if (bean instanceof Tag) { Tag tag = (Tag) bean; tag.setBody(getBody()); tag.setContext(getContext()); tag.setParent(getParent()); ((Tag) bean).doTag(output); return; } invokeBody(output); // export the bean if required if ( var != null ) { context.setVariable(var, bean); } // now, I may invoke the 'execute' method if I have one if ( method != null ) { try { method.invoke( bean, emptyArgs ); } catch (IllegalAccessException e) { methodInvocationException(bean, method, e); } catch (IllegalArgumentException e) { methodInvocationException(bean, method, e); } catch (InvocationTargetException e) { // methodInvocationError(bean, method, e); Throwable inner = e.getTargetException(); throw new JellyTagException(e); } } }
|
public void doTag(XMLOutput output) throws JellyTagException { // lets find any attributes that are not set and for ( Iterator iter = attributes.values().iterator(); iter.hasNext(); ) { Attribute attribute = (Attribute) iter.next(); String name = attribute.getName(); if ( ! setAttributesSet.contains( name ) ) { if ( attribute.isRequired() ) { throw new MissingAttributeException(name); } // lets get the default value Object value = null; Expression expression = attribute.getDefaultValue(); if ( expression != null ) { value = expression.evaluate(context); } // only set non-null values? if ( value != null ) { super.setAttribute(name, value); } } } // If the dynamic bean is itself a tag, let it execute itself if (bean instanceof Tag) { Tag tag = (Tag) bean; tag.setBody(getBody()); tag.setContext(getContext()); tag.setParent(getParent()); ((Tag) bean).doTag(output); return; } invokeBody(output); // export the bean if required if ( var != null ) { context.setVariable(var, bean); } // now, I may invoke the 'execute' method if I have one if ( method != null ) { try { method.invoke( bean, emptyArgs ); } catch (IllegalAccessException e) { methodInvocationException(bean, method, e); } catch (IllegalArgumentException e) { methodInvocationException(bean, method, e); } catch (InvocationTargetException e) { // methodInvocationError(bean, method, e); Throwable inner = e.getTargetException(); throw new JellyTagException(inner); } } }
| 1,108,929
|
public Vector check() throws PedFileException{ //before we perform the check we want to prune out individuals with too much missing data //or trios which contain individuals with too much missing data Iterator fitr = families.values().iterator(); Vector useable = new Vector(); while (fitr.hasNext()){ Family curFam = (Family) fitr.next(); Enumeration indIDEnum = curFam.getMemberList(); Vector victor = new Vector(); while (indIDEnum.hasMoreElements()){ victor.add(curFam.getMember((String) indIDEnum.nextElement())); } if (victor.size() > 1){ PedParser pp = new PedParser(); try { SimpleGraph sg = pp.buildGraph(victor, Options.getMissingThreshold()); Vector indStrings = pp.parsePed(sg); if (indStrings != null){ Iterator sitr = indStrings.iterator(); while (sitr.hasNext()){ useable.add(curFam.getMember((String)sitr.next())); } } }catch (PedigreeException pe){ throw new PedFileException(pe.getMessage() + "\nin family " + curFam.getFamilyName()); } }else{ useable.addAll(victor); } } unrelatedIndividuals = useable; Vector indList = (Vector)allIndividuals.clone(); Individual currentInd; Family currentFamily; //deal with individuals who are missing too much data for(int x=0; x < indList.size(); x++){ currentInd = (Individual)indList.elementAt(x); currentFamily = getFamily(currentInd.getFamilyID()); if (currentInd.getGenoPC() < 1 - Options.getMissingThreshold()){ allIndividuals.removeElement(currentInd); axedPeople.add(currentInd); currentInd.setReasonImAxed("% Genotypes: " + new Double(currentInd.getGenoPC()*100).intValue()); currentFamily.removeMember(currentInd.getIndividualID()); if (currentFamily.getNumMembers() == 0){ //if everyone in a family is gone, we remove it from the list families.remove(currentInd.getFamilyID()); } }else if (!useable.contains(currentInd)){ axedPeople.add(currentInd); currentInd.setReasonImAxed("Not a member of maximum unrelated subset."); } } CheckData cd = new CheckData(this); Vector results = cd.check(); this.results = results; return results; }
|
public Vector check() throws PedFileException{ //before we perform the check we want to prune out individuals with too much missing data //or trios which contain individuals with too much missing data Iterator fitr = families.values().iterator(); Vector useable = new Vector(); while (fitr.hasNext()){ Family curFam = (Family) fitr.next(); Enumeration indIDEnum = curFam.getMemberList(); Vector victor = new Vector(); while (indIDEnum.hasMoreElements()){ victor.add(curFam.getMember((String) indIDEnum.nextElement())); } if (victor.size() > 1){ PedParser pp = new PedParser(); try { SimpleGraph sg = pp.buildGraph(victor, Options.getMissingThreshold()); Vector indStrings = pp.parsePed(sg); if (indStrings != null){ Iterator sitr = indStrings.iterator(); while (sitr.hasNext()){ useable.add(curFam.getMember((String)sitr.next())); } } }catch (PedigreeException pe){ throw new PedFileException(pe.getMessage() + "\nin family " + curFam.getFamilyName()); } }else{ useable.addAll(victor); } } unrelatedIndividuals = useable; Vector indList = (Vector)allIndividuals.clone(); Individual currentInd; Family currentFamily; //deal with individuals who are missing too much data for(int x=0; x < indList.size(); x++){ currentInd = (Individual)indList.elementAt(x); currentFamily = getFamily(currentInd.getFamilyID()); if (currentInd.getGenoPC() < 1 - Options.getMissingThreshold()){ allIndividuals.removeElement(currentInd); axedPeople.add(currentInd); currentInd.setReasonImAxed("% Genotypes: " + new Double(currentInd.getGenoPC()*100).intValue()); currentFamily.removeMember(currentInd.getIndividualID()); if (currentFamily.getNumMembers() == 0){ //if everyone in a family is gone, we remove it from the list families.remove(currentInd.getFamilyID()); } }else if (!useable.contains(currentInd)){ axedPeople.add(currentInd); currentInd.setReasonImAxed("Not a member of maximum unrelated subset."); } } CheckData cd = new CheckData(this); Vector results = cd.check(); this.results = results; return results; }
| 1,108,930
|
protected void createThumbnail( Volume volume ) { ODMGXAWrapper txw = new ODMGXAWrapper(); txw.lock( this, Transaction.WRITE ); // Find the original image to use as a staring point ImageInstance original = null; for ( int n = 0; n < instances.size(); n++ ) { ImageInstance instance = (ImageInstance) instances.get( n ); if ( instance.getInstanceType() == ImageInstance.INSTANCE_TYPE_ORIGINAL ) { original = instance; txw.lock( original, Transaction.READ ); break; } } if ( original == null || original.getImageFile() == null || !original.getImageFile().exists() ) { // If there are uncorrupted instances, no thumbnail can be created log.warn( "Error - no original image was found!!!" ); txw.commit(); return; } // Read the image BufferedImage origImage = null; try { origImage = ImageIO.read( original.getImageFile() ); } catch ( IOException e ) { log.warn( "Error reading image: " + e.getMessage() ); txw.abort(); return; } // Find where to store the file in the target volume File thumbnailFile = volume.getInstanceName( this, "jpg" ); // Shrink the image to desired state and save it // Find first the correct transformation for doing this int origWidth = origImage.getWidth(); int origHeight = origImage.getHeight(); int maxThumbWidth = 100; int maxThumbHeight = 100; AffineTransform xform = photovault.image.ImageXform.getFittingXform( maxThumbWidth, maxThumbHeight, prefRotation -original.getRotated(), origWidth, origHeight ); // Create the target image AffineTransformOp atOp = new AffineTransformOp( xform, AffineTransformOp.TYPE_BILINEAR ); BufferedImage thumbImage = atOp.filter( origImage, null ); // Save it try { ImageIO.write( thumbImage, "jpg", thumbnailFile ); } catch ( IOException e ) { log.warn( "Error writing thumbnail: " + e.getMessage() ); txw.abort(); return; } // add the created instance to this persistent object ImageInstance thumbInstance = addInstance( volume, thumbnailFile, ImageInstance.INSTANCE_TYPE_THUMBNAIL ); thumbInstance.setRotated( prefRotation -original.getRotated() ); thumbnail = Thumbnail.createThumbnail( this, thumbnailFile ); txw.commit(); }
|
protected void createThumbnail( Volume volume ) { ODMGXAWrapper txw = new ODMGXAWrapper(); txw.lock( this, Transaction.WRITE ); // Find the original image to use as a staring point ImageInstance original = null; for ( int n = 0; n < instances.size(); n++ ) { ImageInstance instance = (ImageInstance) instances.get( n ); if ( instance.getInstanceType() == ImageInstance.INSTANCE_TYPE_ORIGINAL ) { original = instance; txw.lock( original, Transaction.READ ); break; } } if ( original == null || original.getImageFile() == null || !original.getImageFile().exists() ) { // If there are uncorrupted instances, no thumbnail can be created log.warn( "Error - no original image was found!!!" ); txw.commit(); return; } // Read the image BufferedImage origImage = null; try { origImage = ImageIO.read( original.getImageFile() ); } catch ( IOException e ) { log.warn( "Error reading image: " + e.getMessage() ); txw.abort(); return; } // Find where to store the file in the target volume File thumbnailFile = volume.getInstanceName( this, "jpg" ); // Shrink the image to desired state and save it // Find first the correct transformation for doing this int origWidth = origImage.getWidth(); int origHeight = origImage.getHeight(); int maxThumbWidth = 100; int maxThumbHeight = 100; AffineTransform xform = photovault.image.ImageXform.getFittingXform( maxThumbWidth, maxThumbHeight, prefRotation -original.getRotated(), origWidth, origHeight ); // Create the target image AffineTransformOp atOp = new AffineTransformOp( xform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR ); log.warn( "Filtering..." ); BufferedImage thumbImage = atOp.filter( origImage, null ); // Save it try { ImageIO.write( thumbImage, "jpg", thumbnailFile ); } catch ( IOException e ) { log.warn( "Error writing thumbnail: " + e.getMessage() ); txw.abort(); return; } // add the created instance to this persistent object ImageInstance thumbInstance = addInstance( volume, thumbnailFile, ImageInstance.INSTANCE_TYPE_THUMBNAIL ); thumbInstance.setRotated( prefRotation -original.getRotated() ); thumbnail = Thumbnail.createThumbnail( this, thumbnailFile ); txw.commit(); }
| 1,108,931
|
public Thumbnail getThumbnail() { log.debug( "Finding thumbnail for " + uid ); if ( thumbnail == null ) { // First try to find an instance from existing instances ImageInstance original = null; for ( int n = 0; n < instances.size(); n++ ) { ImageInstance instance = (ImageInstance) instances.get( n ); if ( instance.getInstanceType() == ImageInstance.INSTANCE_TYPE_THUMBNAIL && instance.getRotated() == prefRotation ) { thumbnail = Thumbnail.createThumbnail( this, instance.getImageFile() ); break; } } if ( thumbnail == null ) { // Next try to create a new thumbnail instance createThumbnail(); } } if ( thumbnail == null ) { // Thumbnail creating was not successful, most probably because there is no available instance return Thumbnail.getDefaultThumbnail(); } return thumbnail; }
|
public Thumbnail getThumbnail() { log.debug( "Finding thumbnail for " + uid ); if ( thumbnail == null ) { // First try to find an instance from existing instances ImageInstance original = null; for ( int n = 0; n < instances.size(); n++ ) { ImageInstance instance = (ImageInstance) instances.get( n ); if ( instance.getInstanceType() == ImageInstance.INSTANCE_TYPE_THUMBNAIL && instance.getRotated() == prefRotation ) { thumbnail = Thumbnail.createThumbnail( this, instance.getImageFile() ); break; } } if ( thumbnail == null ) { // Next try to create a new thumbnail instance createThumbnail(); } } if ( thumbnail == null ) { // Thumbnail creating was not successful, most probably because there is no available instance thumbnail = Thumbnail.getDefaultThumbnail(); } return thumbnail; }
| 1,108,933
|
Haplotype[][] generateCrossovers(Haplotype[][] haplos) throws HaploViewException{ Vector crossBlock = new Vector(); double CROSSOVER_THRESHOLD = 0.01; //to what percentage do we want to consider crossings? if (haplos.length == 0) return null; //seed first block with ordering numbers for (int u = 0; u < haplos[0].length; u++){ haplos[0][u].setListOrder(u); } for (int i = 0; i < haplos.length; i++){ haplos[i][0].clearTags(); } multidprimeArray = new double[haplos.length]; //get "tag" SNPS if there is only one block: if (haplos.length==1){ Vector theBestSubset = getBestSubset(haplos[0]); for (int i = 0; i < theBestSubset.size(); i++){ haplos[0][0].addTag(((Integer)theBestSubset.elementAt(i)).intValue()); } } for (int gap = 0; gap < haplos.length - 1; gap++){ //compute crossovers for each inter-block gap Vector preGapSubset = getBestSubset(haplos[gap]); Vector postGapSubset = getBestSubset(haplos[gap+1]); int[] preMarkerID = haplos[gap][0].getMarkers(); //index haplos to markers in whole dataset int[] postMarkerID = haplos[gap+1][0].getMarkers(); crossBlock.clear(); //make a "block" of the markers which id the pre- and post- gap haps for (int i = 0; i < preGapSubset.size(); i++){ crossBlock.add(new Integer(preMarkerID[((Integer)preGapSubset.elementAt(i)).intValue()])); //mark tags haplos[gap][0].addTag(((Integer)preGapSubset.elementAt(i)).intValue()); } for (int i = 0; i < postGapSubset.size(); i++){ crossBlock.add(new Integer(postMarkerID[((Integer)postGapSubset.elementAt(i)).intValue()])); //mark tags haplos[gap+1][0].addTag(((Integer)postGapSubset.elementAt(i)).intValue()); } Vector inputVector = new Vector(); int[] intArray = new int[crossBlock.size()]; for (int i = 0; i < crossBlock.size(); i++){ //input format for hap generating routine intArray[i] = ((Integer)crossBlock.elementAt(i)).intValue(); } inputVector.add(intArray); Haplotype[] crossHaplos = generateHaplotypes(inputVector, 1)[0]; //get haplos of gap double[][] multilocusTable = new double[haplos[gap].length][]; double[] rowSum = new double[haplos[gap].length]; double[] colSum = new double[haplos[gap+1].length]; double multilocusTotal = 0; for (int i = 0; i < haplos[gap].length; i++){ double[] crossPercentages = new double[haplos[gap+1].length]; StringBuffer firstHapCodeB = new StringBuffer(preGapSubset.size()); for (int j = 0; j < preGapSubset.size(); j++){ //make a string out of uniquely identifying genotypes for this hap firstHapCodeB.append(haplos[gap][i].getGeno()[((Integer)preGapSubset.elementAt(j)).intValue()]); } String firstHapCode = firstHapCodeB.toString(); for (int gapHaplo = 0; gapHaplo < crossHaplos.length; gapHaplo++){ //look at each crossover hap if (crossHaplos[gapHaplo].getPercentage() > CROSSOVER_THRESHOLD){ StringBuffer gapBeginHapCodeB = new StringBuffer(preGapSubset.size()); for (int j = 0; j < preGapSubset.size(); j++){ //make a string as above gapBeginHapCodeB.append(crossHaplos[gapHaplo].getGeno()[j]); } String gapBeginHapCode = gapBeginHapCodeB.toString(); if (gapBeginHapCode.equals(firstHapCode)){ //if this crossover hap corresponds to this pregap hap StringBuffer gapEndHapCodeB = new StringBuffer(preGapSubset.size()); for (int j = preGapSubset.size(); j < crossHaplos[gapHaplo].getGeno().length; j++){ gapEndHapCodeB.append(crossHaplos[gapHaplo].getGeno()[j]); } String gapEndHapCode = gapEndHapCodeB.toString(); for (int j = 0; j < haplos[gap+1].length; j++){ StringBuffer endHapCodeB = new StringBuffer(); for (int k = 0; k < postGapSubset.size(); k++){ endHapCodeB.append(haplos[gap+1][j].getGeno()[((Integer)postGapSubset.elementAt(k)).intValue()]); } String endHapCode = endHapCodeB.toString(); if (gapEndHapCode.equals(endHapCode)){ crossPercentages[j] = crossHaplos[gapHaplo].getPercentage(); } } } } } //thought i needed to fix these percentages, but the raw values are just as good. /* double percentageSum = 0; double[] fixedCross = new double[crossPercentages.length]; for (int y = 0; y < crossPercentages.length; y++){ percentageSum += crossPercentages[y]; } for (int y = 0; y < crossPercentages.length; y++){ fixedCross[y] = crossPercentages[y]/percentageSum; }*/ haplos[gap][i].addCrossovers(crossPercentages); multilocusTable[i] = crossPercentages; } //sort based on "straight line" crossings int hilimit; int lolimit; if (haplos[gap+1].length > haplos[gap].length) { hilimit = haplos[gap+1].length; lolimit = haplos[gap].length; }else{ hilimit = haplos[gap].length; lolimit = haplos[gap+1].length; } boolean[] unavailable = new boolean[hilimit]; int[] prevBlockLocs = new int[haplos[gap].length]; for (int q = 0; q < prevBlockLocs.length; q++){ prevBlockLocs[haplos[gap][q].getListOrder()] = q; } for (int u = 0; u < haplos[gap+1].length; u++){ double currentBestVal = 0; int currentBestLoc = -1; for (int v = 0; v < lolimit; v++){ if (!(unavailable[v])){ if (haplos[gap][prevBlockLocs[v]].getCrossover(u) >= currentBestVal) { currentBestLoc = haplos[gap][prevBlockLocs[v]].getListOrder(); currentBestVal = haplos[gap][prevBlockLocs[v]].getCrossover(u); } } } //it didn't get lined up with any of the previous block's markers //put it at the end of the list if (currentBestLoc == -1){ for (int v = 0; v < unavailable.length; v++){ if (!(unavailable[v])){ currentBestLoc = v; break; } } } haplos[gap+1][u].setListOrder(currentBestLoc); unavailable[currentBestLoc] = true; } //compute multilocus D' for (int i = 0; i < rowSum.length; i++){ for (int j = 0; j < colSum.length; j++){ rowSum[i] += multilocusTable[i][j]; colSum[j] += multilocusTable[i][j]; multilocusTotal += multilocusTable[i][j]; if (rowSum[i] == 0) rowSum[i] = 0.0001; if (colSum[j] == 0) colSum[j] = 0.0001; } } double multidprime = 0; for (int i = 0; i < rowSum.length; i++){ for (int j = 0; j < colSum.length; j++){ double num = (multilocusTable[i][j]/multilocusTotal) - (rowSum[i]/multilocusTotal)*(colSum[j]/multilocusTotal); double denom; if (num < 0){ double denom1 = (rowSum[i]/multilocusTotal)*(colSum[j]/multilocusTotal); double denom2 = (1.0 - (rowSum[i]/multilocusTotal))*(1.0 - (colSum[j]/multilocusTotal)); if (denom1 < denom2) { denom = denom1; }else{ denom = denom2; } }else{ double denom1 = (rowSum[i]/multilocusTotal)*(1.0 -(colSum[j]/multilocusTotal)); double denom2 = (1.0 - (rowSum[i]/multilocusTotal))*(colSum[j]/multilocusTotal); if (denom1 < denom2){ denom = denom1; }else{ denom = denom2; } } multidprime += (rowSum[i]/multilocusTotal)*(colSum[j]/multilocusTotal)*Math.abs(num/denom); } } multidprimeArray[gap] = multidprime; } return haplos; }
|
Haplotype[][] generateCrossovers(Haplotype[][] haplos) throws HaploViewException{ Vector crossBlock = new Vector(); double CROSSOVER_THRESHOLD = 0.01; //to what percentage do we want to consider crossings? if (haplos.length == 0) return null; //seed first block with ordering numbers for (int u = 0; u < haplos[0].length; u++){ haplos[0][u].setListOrder(u); } for (int i = 0; i < haplos.length; i++){ haplos[i][0].clearTags(); } multidprimeArray = new double[haplos.length]; //get "tag" SNPS if there is only one block: if (haplos.length==1){ Vector theBestSubset = getBestSubset(haplos[0]); for (int i = 0; i < theBestSubset.size(); i++){ haplos[0][0].addTag(((Integer)theBestSubset.elementAt(i)).intValue()); } } for (int gap = 0; gap < haplos.length - 1; gap++){ //compute crossovers for each inter-block gap Vector preGapSubset = getBestSubset(haplos[gap]); Vector postGapSubset = getBestSubset(haplos[gap+1]); int[] preMarkerID = haplos[gap][0].getMarkers(); //index haplos to markers in whole dataset int[] postMarkerID = haplos[gap+1][0].getMarkers(); crossBlock.clear(); //make a "block" of the markers which id the pre- and post- gap haps for (int i = 0; i < preGapSubset.size(); i++){ crossBlock.add(new Integer(preMarkerID[((Integer)preGapSubset.elementAt(i)).intValue()])); //mark tags haplos[gap][0].addTag(((Integer)preGapSubset.elementAt(i)).intValue()); } for (int i = 0; i < postGapSubset.size(); i++){ crossBlock.add(new Integer(postMarkerID[((Integer)postGapSubset.elementAt(i)).intValue()])); //mark tags haplos[gap+1][0].addTag(((Integer)postGapSubset.elementAt(i)).intValue()); } Vector inputVector = new Vector(); int[] intArray = new int[crossBlock.size()]; for (int i = 0; i < crossBlock.size(); i++){ //input format for hap generating routine intArray[i] = ((Integer)crossBlock.elementAt(i)).intValue(); } inputVector.add(intArray); Haplotype[] crossHaplos = generateHaplotypes(inputVector, 1)[0]; //get haplos of gap double[][] multilocusTable = new double[haplos[gap].length][]; double[] rowSum = new double[haplos[gap].length]; double[] colSum = new double[haplos[gap+1].length]; double multilocusTotal = 0; for (int i = 0; i < haplos[gap].length; i++){ double[] crossPercentages = new double[haplos[gap+1].length]; StringBuffer firstHapCodeB = new StringBuffer(preGapSubset.size()); for (int j = 0; j < preGapSubset.size(); j++){ //make a string out of uniquely identifying genotypes for this hap firstHapCodeB.append(haplos[gap][i].getGeno()[((Integer)preGapSubset.elementAt(j)).intValue()]); } String firstHapCode = firstHapCodeB.toString(); for (int gapHaplo = 0; gapHaplo < crossHaplos.length; gapHaplo++){ //look at each crossover hap if (crossHaplos[gapHaplo].getPercentage() > CROSSOVER_THRESHOLD){ StringBuffer gapBeginHapCodeB = new StringBuffer(preGapSubset.size()); for (int j = 0; j < preGapSubset.size(); j++){ //make a string as above gapBeginHapCodeB.append(crossHaplos[gapHaplo].getGeno()[j]); } String gapBeginHapCode = gapBeginHapCodeB.toString(); if (gapBeginHapCode.equals(firstHapCode)){ //if this crossover hap corresponds to this pregap hap StringBuffer gapEndHapCodeB = new StringBuffer(preGapSubset.size()); for (int j = preGapSubset.size(); j < crossHaplos[gapHaplo].getGeno().length; j++){ gapEndHapCodeB.append(crossHaplos[gapHaplo].getGeno()[j]); } String gapEndHapCode = gapEndHapCodeB.toString(); for (int j = 0; j < haplos[gap+1].length; j++){ StringBuffer endHapCodeB = new StringBuffer(); for (int k = 0; k < postGapSubset.size(); k++){ endHapCodeB.append(haplos[gap+1][j].getGeno()[((Integer)postGapSubset.elementAt(k)).intValue()]); } String endHapCode = endHapCodeB.toString(); if (gapEndHapCode.equals(endHapCode)){ crossPercentages[j] = crossHaplos[gapHaplo].getPercentage(); } } } } } //thought i needed to fix these percentages, but the raw values are just as good. /* double percentageSum = 0; double[] fixedCross = new double[crossPercentages.length]; for (int y = 0; y < crossPercentages.length; y++){ percentageSum += crossPercentages[y]; } for (int y = 0; y < crossPercentages.length; y++){ fixedCross[y] = crossPercentages[y]/percentageSum; }*/ haplos[gap][i].addCrossovers(crossPercentages); multilocusTable[i] = crossPercentages; } //sort based on "straight line" crossings int hilimit; int lolimit; if (haplos[gap+1].length > haplos[gap].length) { hilimit = haplos[gap+1].length; lolimit = haplos[gap].length; }else{ hilimit = haplos[gap].length; lolimit = haplos[gap+1].length; } boolean[] unavailable = new boolean[hilimit]; int[] prevBlockLocs = new int[haplos[gap].length]; for (int q = 0; q < prevBlockLocs.length; q++){ prevBlockLocs[haplos[gap][q].getListOrder()] = q; } for (int u = 0; u < haplos[gap+1].length; u++){ double currentBestVal = 0; int currentBestLoc = -1; for (int v = 0; v < lolimit; v++){ if (!(unavailable[v])){ if (haplos[gap][prevBlockLocs[v]].getCrossover(u) >= currentBestVal) { currentBestLoc = haplos[gap][prevBlockLocs[v]].getListOrder(); currentBestVal = haplos[gap][prevBlockLocs[v]].getCrossover(u); } } } //it didn't get lined up with any of the previous block's markers //put it at the end of the list if (currentBestLoc == -1){ for (int v = 0; v < unavailable.length; v++){ if (!(unavailable[v])){ currentBestLoc = v; break; } } } haplos[gap+1][u].setListOrder(currentBestLoc); unavailable[currentBestLoc] = true; } //compute multilocus D' for (int i = 0; i < rowSum.length; i++){ for (int j = 0; j < colSum.length; j++){ rowSum[i] += multilocusTable[i][j]; colSum[j] += multilocusTable[i][j]; multilocusTotal += multilocusTable[i][j]; if (rowSum[i] == 0) rowSum[i] = 0.0001; if (colSum[j] == 0) colSum[j] = 0.0001; } } double multidprime = 0; for (int i = 0; i < rowSum.length; i++){ for (int j = 0; j < colSum.length; j++){ double num = (multilocusTable[i][j]/multilocusTotal) - (rowSum[i]/multilocusTotal)*(colSum[j]/multilocusTotal); double denom; if (num < 0){ double denom1 = (rowSum[i]/multilocusTotal)*(colSum[j]/multilocusTotal); double denom2 = (1.0 - (rowSum[i]/multilocusTotal))*(1.0 - (colSum[j]/multilocusTotal)); if (denom1 < denom2) { denom = denom1; }else{ denom = denom2; } }else{ double denom1 = (rowSum[i]/multilocusTotal)*(1.0 -(colSum[j]/multilocusTotal)); double denom2 = (1.0 - (rowSum[i]/multilocusTotal))*(colSum[j]/multilocusTotal); if (denom1 < denom2){ denom = denom1; }else{ denom = denom2; } } if (denom != 0){ noDivByZero = true; multidprime += (rowSum[i]/multilocusTotal)*(colSum[j]/multilocusTotal)*Math.abs(num/denom); } } } multidprimeArray[gap] = multidprime; } return haplos; }
| 1,108,934
|
Haplotype[][] generateCrossovers(Haplotype[][] haplos) throws HaploViewException{ Vector crossBlock = new Vector(); double CROSSOVER_THRESHOLD = 0.01; //to what percentage do we want to consider crossings? if (haplos.length == 0) return null; //seed first block with ordering numbers for (int u = 0; u < haplos[0].length; u++){ haplos[0][u].setListOrder(u); } for (int i = 0; i < haplos.length; i++){ haplos[i][0].clearTags(); } multidprimeArray = new double[haplos.length]; //get "tag" SNPS if there is only one block: if (haplos.length==1){ Vector theBestSubset = getBestSubset(haplos[0]); for (int i = 0; i < theBestSubset.size(); i++){ haplos[0][0].addTag(((Integer)theBestSubset.elementAt(i)).intValue()); } } for (int gap = 0; gap < haplos.length - 1; gap++){ //compute crossovers for each inter-block gap Vector preGapSubset = getBestSubset(haplos[gap]); Vector postGapSubset = getBestSubset(haplos[gap+1]); int[] preMarkerID = haplos[gap][0].getMarkers(); //index haplos to markers in whole dataset int[] postMarkerID = haplos[gap+1][0].getMarkers(); crossBlock.clear(); //make a "block" of the markers which id the pre- and post- gap haps for (int i = 0; i < preGapSubset.size(); i++){ crossBlock.add(new Integer(preMarkerID[((Integer)preGapSubset.elementAt(i)).intValue()])); //mark tags haplos[gap][0].addTag(((Integer)preGapSubset.elementAt(i)).intValue()); } for (int i = 0; i < postGapSubset.size(); i++){ crossBlock.add(new Integer(postMarkerID[((Integer)postGapSubset.elementAt(i)).intValue()])); //mark tags haplos[gap+1][0].addTag(((Integer)postGapSubset.elementAt(i)).intValue()); } Vector inputVector = new Vector(); int[] intArray = new int[crossBlock.size()]; for (int i = 0; i < crossBlock.size(); i++){ //input format for hap generating routine intArray[i] = ((Integer)crossBlock.elementAt(i)).intValue(); } inputVector.add(intArray); Haplotype[] crossHaplos = generateHaplotypes(inputVector, 1)[0]; //get haplos of gap double[][] multilocusTable = new double[haplos[gap].length][]; double[] rowSum = new double[haplos[gap].length]; double[] colSum = new double[haplos[gap+1].length]; double multilocusTotal = 0; for (int i = 0; i < haplos[gap].length; i++){ double[] crossPercentages = new double[haplos[gap+1].length]; StringBuffer firstHapCodeB = new StringBuffer(preGapSubset.size()); for (int j = 0; j < preGapSubset.size(); j++){ //make a string out of uniquely identifying genotypes for this hap firstHapCodeB.append(haplos[gap][i].getGeno()[((Integer)preGapSubset.elementAt(j)).intValue()]); } String firstHapCode = firstHapCodeB.toString(); for (int gapHaplo = 0; gapHaplo < crossHaplos.length; gapHaplo++){ //look at each crossover hap if (crossHaplos[gapHaplo].getPercentage() > CROSSOVER_THRESHOLD){ StringBuffer gapBeginHapCodeB = new StringBuffer(preGapSubset.size()); for (int j = 0; j < preGapSubset.size(); j++){ //make a string as above gapBeginHapCodeB.append(crossHaplos[gapHaplo].getGeno()[j]); } String gapBeginHapCode = gapBeginHapCodeB.toString(); if (gapBeginHapCode.equals(firstHapCode)){ //if this crossover hap corresponds to this pregap hap StringBuffer gapEndHapCodeB = new StringBuffer(preGapSubset.size()); for (int j = preGapSubset.size(); j < crossHaplos[gapHaplo].getGeno().length; j++){ gapEndHapCodeB.append(crossHaplos[gapHaplo].getGeno()[j]); } String gapEndHapCode = gapEndHapCodeB.toString(); for (int j = 0; j < haplos[gap+1].length; j++){ StringBuffer endHapCodeB = new StringBuffer(); for (int k = 0; k < postGapSubset.size(); k++){ endHapCodeB.append(haplos[gap+1][j].getGeno()[((Integer)postGapSubset.elementAt(k)).intValue()]); } String endHapCode = endHapCodeB.toString(); if (gapEndHapCode.equals(endHapCode)){ crossPercentages[j] = crossHaplos[gapHaplo].getPercentage(); } } } } } //thought i needed to fix these percentages, but the raw values are just as good. /* double percentageSum = 0; double[] fixedCross = new double[crossPercentages.length]; for (int y = 0; y < crossPercentages.length; y++){ percentageSum += crossPercentages[y]; } for (int y = 0; y < crossPercentages.length; y++){ fixedCross[y] = crossPercentages[y]/percentageSum; }*/ haplos[gap][i].addCrossovers(crossPercentages); multilocusTable[i] = crossPercentages; } //sort based on "straight line" crossings int hilimit; int lolimit; if (haplos[gap+1].length > haplos[gap].length) { hilimit = haplos[gap+1].length; lolimit = haplos[gap].length; }else{ hilimit = haplos[gap].length; lolimit = haplos[gap+1].length; } boolean[] unavailable = new boolean[hilimit]; int[] prevBlockLocs = new int[haplos[gap].length]; for (int q = 0; q < prevBlockLocs.length; q++){ prevBlockLocs[haplos[gap][q].getListOrder()] = q; } for (int u = 0; u < haplos[gap+1].length; u++){ double currentBestVal = 0; int currentBestLoc = -1; for (int v = 0; v < lolimit; v++){ if (!(unavailable[v])){ if (haplos[gap][prevBlockLocs[v]].getCrossover(u) >= currentBestVal) { currentBestLoc = haplos[gap][prevBlockLocs[v]].getListOrder(); currentBestVal = haplos[gap][prevBlockLocs[v]].getCrossover(u); } } } //it didn't get lined up with any of the previous block's markers //put it at the end of the list if (currentBestLoc == -1){ for (int v = 0; v < unavailable.length; v++){ if (!(unavailable[v])){ currentBestLoc = v; break; } } } haplos[gap+1][u].setListOrder(currentBestLoc); unavailable[currentBestLoc] = true; } //compute multilocus D' for (int i = 0; i < rowSum.length; i++){ for (int j = 0; j < colSum.length; j++){ rowSum[i] += multilocusTable[i][j]; colSum[j] += multilocusTable[i][j]; multilocusTotal += multilocusTable[i][j]; if (rowSum[i] == 0) rowSum[i] = 0.0001; if (colSum[j] == 0) colSum[j] = 0.0001; } } double multidprime = 0; for (int i = 0; i < rowSum.length; i++){ for (int j = 0; j < colSum.length; j++){ double num = (multilocusTable[i][j]/multilocusTotal) - (rowSum[i]/multilocusTotal)*(colSum[j]/multilocusTotal); double denom; if (num < 0){ double denom1 = (rowSum[i]/multilocusTotal)*(colSum[j]/multilocusTotal); double denom2 = (1.0 - (rowSum[i]/multilocusTotal))*(1.0 - (colSum[j]/multilocusTotal)); if (denom1 < denom2) { denom = denom1; }else{ denom = denom2; } }else{ double denom1 = (rowSum[i]/multilocusTotal)*(1.0 -(colSum[j]/multilocusTotal)); double denom2 = (1.0 - (rowSum[i]/multilocusTotal))*(colSum[j]/multilocusTotal); if (denom1 < denom2){ denom = denom1; }else{ denom = denom2; } } multidprime += (rowSum[i]/multilocusTotal)*(colSum[j]/multilocusTotal)*Math.abs(num/denom); } } multidprimeArray[gap] = multidprime; } return haplos; }
|
Haplotype[][] generateCrossovers(Haplotype[][] haplos) throws HaploViewException{ Vector crossBlock = new Vector(); double CROSSOVER_THRESHOLD = 0.01; //to what percentage do we want to consider crossings? if (haplos.length == 0) return null; //seed first block with ordering numbers for (int u = 0; u < haplos[0].length; u++){ haplos[0][u].setListOrder(u); } for (int i = 0; i < haplos.length; i++){ haplos[i][0].clearTags(); } multidprimeArray = new double[haplos.length]; //get "tag" SNPS if there is only one block: if (haplos.length==1){ Vector theBestSubset = getBestSubset(haplos[0]); for (int i = 0; i < theBestSubset.size(); i++){ haplos[0][0].addTag(((Integer)theBestSubset.elementAt(i)).intValue()); } } for (int gap = 0; gap < haplos.length - 1; gap++){ //compute crossovers for each inter-block gap Vector preGapSubset = getBestSubset(haplos[gap]); Vector postGapSubset = getBestSubset(haplos[gap+1]); int[] preMarkerID = haplos[gap][0].getMarkers(); //index haplos to markers in whole dataset int[] postMarkerID = haplos[gap+1][0].getMarkers(); crossBlock.clear(); //make a "block" of the markers which id the pre- and post- gap haps for (int i = 0; i < preGapSubset.size(); i++){ crossBlock.add(new Integer(preMarkerID[((Integer)preGapSubset.elementAt(i)).intValue()])); //mark tags haplos[gap][0].addTag(((Integer)preGapSubset.elementAt(i)).intValue()); } for (int i = 0; i < postGapSubset.size(); i++){ crossBlock.add(new Integer(postMarkerID[((Integer)postGapSubset.elementAt(i)).intValue()])); //mark tags haplos[gap+1][0].addTag(((Integer)postGapSubset.elementAt(i)).intValue()); } Vector inputVector = new Vector(); int[] intArray = new int[crossBlock.size()]; for (int i = 0; i < crossBlock.size(); i++){ //input format for hap generating routine intArray[i] = ((Integer)crossBlock.elementAt(i)).intValue(); } inputVector.add(intArray); Haplotype[] crossHaplos = generateHaplotypes(inputVector, 1)[0]; //get haplos of gap double[][] multilocusTable = new double[haplos[gap].length][]; double[] rowSum = new double[haplos[gap].length]; double[] colSum = new double[haplos[gap+1].length]; double multilocusTotal = 0; for (int i = 0; i < haplos[gap].length; i++){ double[] crossPercentages = new double[haplos[gap+1].length]; StringBuffer firstHapCodeB = new StringBuffer(preGapSubset.size()); for (int j = 0; j < preGapSubset.size(); j++){ //make a string out of uniquely identifying genotypes for this hap firstHapCodeB.append(haplos[gap][i].getGeno()[((Integer)preGapSubset.elementAt(j)).intValue()]); } String firstHapCode = firstHapCodeB.toString(); for (int gapHaplo = 0; gapHaplo < crossHaplos.length; gapHaplo++){ //look at each crossover hap if (crossHaplos[gapHaplo].getPercentage() > CROSSOVER_THRESHOLD){ StringBuffer gapBeginHapCodeB = new StringBuffer(preGapSubset.size()); for (int j = 0; j < preGapSubset.size(); j++){ //make a string as above gapBeginHapCodeB.append(crossHaplos[gapHaplo].getGeno()[j]); } String gapBeginHapCode = gapBeginHapCodeB.toString(); if (gapBeginHapCode.equals(firstHapCode)){ //if this crossover hap corresponds to this pregap hap StringBuffer gapEndHapCodeB = new StringBuffer(preGapSubset.size()); for (int j = preGapSubset.size(); j < crossHaplos[gapHaplo].getGeno().length; j++){ gapEndHapCodeB.append(crossHaplos[gapHaplo].getGeno()[j]); } String gapEndHapCode = gapEndHapCodeB.toString(); for (int j = 0; j < haplos[gap+1].length; j++){ StringBuffer endHapCodeB = new StringBuffer(); for (int k = 0; k < postGapSubset.size(); k++){ endHapCodeB.append(haplos[gap+1][j].getGeno()[((Integer)postGapSubset.elementAt(k)).intValue()]); } String endHapCode = endHapCodeB.toString(); if (gapEndHapCode.equals(endHapCode)){ crossPercentages[j] = crossHaplos[gapHaplo].getPercentage(); } } } } } //thought i needed to fix these percentages, but the raw values are just as good. /* double percentageSum = 0; double[] fixedCross = new double[crossPercentages.length]; for (int y = 0; y < crossPercentages.length; y++){ percentageSum += crossPercentages[y]; } for (int y = 0; y < crossPercentages.length; y++){ fixedCross[y] = crossPercentages[y]/percentageSum; }*/ haplos[gap][i].addCrossovers(crossPercentages); multilocusTable[i] = crossPercentages; } //sort based on "straight line" crossings int hilimit; int lolimit; if (haplos[gap+1].length > haplos[gap].length) { hilimit = haplos[gap+1].length; lolimit = haplos[gap].length; }else{ hilimit = haplos[gap].length; lolimit = haplos[gap+1].length; } boolean[] unavailable = new boolean[hilimit]; int[] prevBlockLocs = new int[haplos[gap].length]; for (int q = 0; q < prevBlockLocs.length; q++){ prevBlockLocs[haplos[gap][q].getListOrder()] = q; } for (int u = 0; u < haplos[gap+1].length; u++){ double currentBestVal = 0; int currentBestLoc = -1; for (int v = 0; v < lolimit; v++){ if (!(unavailable[v])){ if (haplos[gap][prevBlockLocs[v]].getCrossover(u) >= currentBestVal) { currentBestLoc = haplos[gap][prevBlockLocs[v]].getListOrder(); currentBestVal = haplos[gap][prevBlockLocs[v]].getCrossover(u); } } } //it didn't get lined up with any of the previous block's markers //put it at the end of the list if (currentBestLoc == -1){ for (int v = 0; v < unavailable.length; v++){ if (!(unavailable[v])){ currentBestLoc = v; break; } } } haplos[gap+1][u].setListOrder(currentBestLoc); unavailable[currentBestLoc] = true; } //compute multilocus D' for (int i = 0; i < rowSum.length; i++){ for (int j = 0; j < colSum.length; j++){ rowSum[i] += multilocusTable[i][j]; colSum[j] += multilocusTable[i][j]; multilocusTotal += multilocusTable[i][j]; if (rowSum[i] == 0) rowSum[i] = 0.0001; if (colSum[j] == 0) colSum[j] = 0.0001; } } double multidprime = 0; for (int i = 0; i < rowSum.length; i++){ for (int j = 0; j < colSum.length; j++){ double num = (multilocusTable[i][j]/multilocusTotal) - (rowSum[i]/multilocusTotal)*(colSum[j]/multilocusTotal); double denom; if (num < 0){ double denom1 = (rowSum[i]/multilocusTotal)*(colSum[j]/multilocusTotal); double denom2 = (1.0 - (rowSum[i]/multilocusTotal))*(1.0 - (colSum[j]/multilocusTotal)); if (denom1 < denom2) { denom = denom1; }else{ denom = denom2; } }else{ double denom1 = (rowSum[i]/multilocusTotal)*(1.0 -(colSum[j]/multilocusTotal)); double denom2 = (1.0 - (rowSum[i]/multilocusTotal))*(colSum[j]/multilocusTotal); if (denom1 < denom2){ denom = denom1; }else{ denom = denom2; } } multidprime += (rowSum[i]/multilocusTotal)*(colSum[j]/multilocusTotal)*Math.abs(num/denom); } } if (noDivByZero){ multidprimeArray[gap] = multidprime; }else{ multidprimeArray[gap] = 1.00; } } return haplos; }
| 1,108,935
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
|
static public void doCreateRelationship(SQLTable pkTable,SQLTable fkTable,PlayPen pp, boolean identifying) { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
| 1,108,938
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getName()+"_"+fkTable.getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
| 1,108,939
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
| 1,108,940
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
| 1,108,941
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
| 1,108,942
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
| 1,108,943
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
| 1,108,944
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable)); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
| 1,108,945
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
| 1,108,946
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getModel().getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
|
protected void doCreateRelationship() { try { SQLRelationship model = new SQLRelationship(); // XXX: need to ensure uniqueness of setName(), but // to_identifier should take care of this... model.setName(pkTable.getModel().getName()+"_"+fkTable.getModel().getName()+"_fk"); model.setIdentifying(identifying); model.setPkTable(pkTable.getModel()); model.setFkTable(fkTable.getModel()); pkTable.getModel().addExportedKey(model); fkTable.getModel().addImportedKey(model); // iterate over a copy of pktable's column list to avoid comodification // when creating a self-referencing table java.util.List pkColListCopy = new ArrayList(pkTable.getModel().getColumns().size()); pkColListCopy.addAll(pkTable.getModel().getColumns()); Iterator pkCols = pkColListCopy.iterator(); while (pkCols.hasNext()) { SQLColumn pkCol = (SQLColumn) pkCols.next(); if (pkCol.getPrimaryKeySeq() == null) break; SQLColumn fkCol = (SQLColumn) pkCol.clone(); // check to see if the FK table already has this column SQLColumn match = fkTable.getModel().getColumnByName(pkCol.getName()); if (match != null) { // there is already a column of this name if (match.getType() == pkCol.getType() && match.getPrecision() == pkCol.getPrecision() && match.getScale() == pkCol.getScale()) { // column is an exact match, so we don't have to recreate it fkCol = match; fkCol.addReference(); // reference counting, stops column from being removed if relationship is removed } else { // ask the user if they would like to rename the column // or cancel the creation of the relationship int decision = JOptionPane.showConfirmDialog(pp, "The primary key column " + pkCol.getName() + " already exists " + " in the child table. Continue using new name " + pkCol.getName() + "_1 ?", "Column Name Conflict", JOptionPane.YES_NO_OPTION); if (decision == JOptionPane.YES_OPTION) { // XXX: need to ensure uniqueness of setName(), // but to_identifier in DDLGenerator should take // care of this fkCol.setName(generateUniqueColumnName(pkCol,fkTable.getModel())); } else { model = null; return; // abort the creation of this relationship } fkTable.getModel().addColumn(fkCol); } } else { // no match, so we need to import this column from PK table fkTable.getModel().addColumn(fkCol); } if (identifying && fkCol.getPrimaryKeySeq() == null) { // add column to primary key (but only if it's not already there!!! fkCol.setPrimaryKeySeq(new Integer(fkTable.getPkSize())); } model.addMapping(pkCol, fkCol); } Relationship r = new Relationship(pp, model); pp.addRelationship(r); r.repaint(); // XXX: shouldn't be necessary, but it is. } catch (ArchitectException ex) { logger.error("Couldn't create relationship", ex); JOptionPane.showMessageDialog(pp, "Couldn't create relationship: "+ex.getMessage()); } }
| 1,108,947
|
public void setPlSchema(String schema) { put(PL_SCHEMA_OWNER, schema); }
|
public void setPlSchema(String schema) { putImpl(PL_SCHEMA_OWNER, schema, "plSchema"); }
| 1,108,948
|
public void setPlDbType(String type) { put(PL_TYPE, type); }
|
public void setPlDbType(String type) { putImpl(PL_TYPE, type, "plDbType"); }
| 1,108,949
|
public void setOdbcDsn(String dsn) { put(PL_DSN, dsn); }
|
public void setOdbcDsn(String dsn) { putImpl(PL_DSN, dsn, "odbcDsn"); }
| 1,108,950
|
protected void handleException(JellyException e) throws JellyTagException { if (log.isTraceEnabled()) { log.trace( "Caught exception: " + e, e ); } applyLocation(e); throw new JellyTagException(e); }
|
protected void handleException(JellyTagException e) throws JellyTagException { if (log.isTraceEnabled()) { log.trace( "Caught exception: " + e, e ); } applyLocation(e); throw new JellyTagException(e); }
| 1,108,951
|
protected void handleException(JellyException e) throws JellyTagException { if (log.isTraceEnabled()) { log.trace( "Caught exception: " + e, e ); } applyLocation(e); throw new JellyTagException(e); }
|
protected void handleException(JellyException e) throws JellyTagException { if (log.isTraceEnabled()) { log.trace( "Caught exception: " + e, e ); } applyLocation(e); throw e; }
| 1,108,952
|
public HaploView(){ try{ fc = new JFileChooser(System.getProperty("user.dir")); }catch(NullPointerException n){ try{ UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); fc = new JFileChooser(System.getProperty("user.dir")); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){ } } //menu setup JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenuItem menuItem; //file menu JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); menuItem = new JMenuItem(READ_GENOTYPES); setAccelerator(menuItem, 'O', false); menuItem.addActionListener(this); fileMenu.add(menuItem); /* viewGenotypesItem = new JMenuItem(VIEW_GENOTYPES); viewGenotypesItem.addActionListener(this); //viewGenotypesItem.setEnabled(false); fileMenu.add(viewGenotypesItem); */ readMarkerItem = new JMenuItem(READ_MARKERS); setAccelerator(readMarkerItem, 'I', false); readMarkerItem.addActionListener(this); readMarkerItem.setEnabled(false); fileMenu.add(readMarkerItem); /* viewMarkerItem = new JMenuItem(VIEW_MARKERS); viewMarkerItem.addActionListener(this); //viewMarkerItem.setEnabled(false); fileMenu.add(viewMarkerItem); */ fileMenu.addSeparator(); exportMenuItems = new JMenuItem[exportItems.length]; for (int i = 0; i < exportItems.length; i++) { exportMenuItems[i] = new JMenuItem(exportItems[i]); exportMenuItems[i].addActionListener(this); exportMenuItems[i].setEnabled(false); fileMenu.add(exportMenuItems[i]); } exportMenuItems[2].setEnabled(true); fileMenu.addSeparator(); fileMenu.setMnemonic(KeyEvent.VK_F); menuItem = new JMenuItem("Quit"); setAccelerator(menuItem, 'Q', false); menuItem.addActionListener(this); fileMenu.add(menuItem); /// display menu JMenu displayMenu = new JMenu("Display"); displayMenu.setMnemonic(KeyEvent.VK_D); menuBar.add(displayMenu); ButtonGroup group = new ButtonGroup(); viewMenuItems = new JRadioButtonMenuItem[viewItems.length]; for (int i = 0; i < viewItems.length; i++) { viewMenuItems[i] = new JRadioButtonMenuItem(viewItems[i], i == 0); viewMenuItems[i].addActionListener(this); KeyStroke ks = KeyStroke.getKeyStroke('1' + i, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); viewMenuItems[i].setAccelerator(ks); displayMenu.add(viewMenuItems[i]); viewMenuItems[i].setEnabled(false); group.add(viewMenuItems[i]); } displayMenu.addSeparator(); //a submenu ButtonGroup zg = new ButtonGroup(); JMenu zoomMenu = new JMenu("D prime zoom"); zoomMenu.setMnemonic(KeyEvent.VK_Z); zoomMenuItems = new JRadioButtonMenuItem[zoomItems.length]; for (int i = 0; i < zoomItems.length; i++){ zoomMenuItems[i] = new JRadioButtonMenuItem(zoomItems[i], i==0); zoomMenuItems[i].addActionListener(this); zoomMenuItems[i].setActionCommand("zoom" + i); zoomMenu.add(zoomMenuItems[i]); zg.add(zoomMenuItems[i]); } displayMenu.add(zoomMenu); //another submenu ButtonGroup cg = new ButtonGroup(); JMenu colorMenu = new JMenu("D prime color scheme"); colorMenu.setMnemonic(KeyEvent.VK_C); colorMenuItems = new JRadioButtonMenuItem[colorItems.length]; for (int i = 0; i< colorItems.length; i++){ colorMenuItems[i] = new JRadioButtonMenuItem(colorItems[i],i==0); colorMenuItems[i].addActionListener(this); colorMenuItems[i].setActionCommand("color" + i); colorMenu.add(colorMenuItems[i]); cg.add(colorMenuItems[i]); } displayMenu.add(colorMenu); //analysis menu JMenu analysisMenu = new JMenu("Analysis"); analysisMenu.setMnemonic(KeyEvent.VK_A); menuBar.add(analysisMenu); //a submenu ButtonGroup bg = new ButtonGroup(); JMenu blockMenu = new JMenu("Define Blocks"); blockMenu.setMnemonic(KeyEvent.VK_B); blockMenuItems = new JRadioButtonMenuItem[blockItems.length]; for (int i = 0; i < blockItems.length; i++){ blockMenuItems[i] = new JRadioButtonMenuItem(blockItems[i], i==0); blockMenuItems[i].addActionListener(this); blockMenuItems[i].setActionCommand("block" + i); blockMenu.add(blockMenuItems[i]); bg.add(blockMenuItems[i]); } blockMenuItems[3].setEnabled(false); analysisMenu.add(blockMenu); clearBlocksItem = new JMenuItem(CLEAR_BLOCKS); setAccelerator(clearBlocksItem, 'C', false); clearBlocksItem.addActionListener(this); clearBlocksItem.setEnabled(false); analysisMenu.add(clearBlocksItem); JMenuItem customizeBlocksItem = new JMenuItem(CUST_BLOCKS); customizeBlocksItem.addActionListener(this); analysisMenu.add(customizeBlocksItem); //color key keyMenu = new JMenu("Key"); menuBar.add(Box.createHorizontalGlue()); menuBar.add(keyMenu); /** NEEDS FIXING helpMenu = new JMenu("Help"); menuBar.add(Box.createHorizontalGlue()); menuBar.add(helpMenu); menuItem = new JMenuItem("Tutorial"); menuItem.addActionListener(this); helpMenu.add(menuItem); **/ /* clearBlocksMenuItem.addActionListener(this); clearBlocksMenuItem.setEnabled(false); toolMenu.add(clearBlocksMenuItem); */ addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ quit(); } }); addComponentListener(new ResizeListener()); }
|
public HaploView(){ try{ fc = new JFileChooser(System.getProperty("user.dir")); }catch(NullPointerException n){ try{ UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); fc = new JFileChooser(System.getProperty("user.dir")); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){ } } //menu setup JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenuItem menuItem; //file menu JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); menuItem = new JMenuItem(READ_GENOTYPES); setAccelerator(menuItem, 'O', false); menuItem.addActionListener(this); fileMenu.add(menuItem); /* viewGenotypesItem = new JMenuItem(VIEW_GENOTYPES); viewGenotypesItem.addActionListener(this); //viewGenotypesItem.setEnabled(false); fileMenu.add(viewGenotypesItem); */ readMarkerItem = new JMenuItem(READ_MARKERS); setAccelerator(readMarkerItem, 'I', false); readMarkerItem.addActionListener(this); readMarkerItem.setEnabled(false); fileMenu.add(readMarkerItem); /* viewMarkerItem = new JMenuItem(VIEW_MARKERS); viewMarkerItem.addActionListener(this); //viewMarkerItem.setEnabled(false); fileMenu.add(viewMarkerItem); */ fileMenu.addSeparator(); exportMenuItems = new JMenuItem[exportItems.length]; for (int i = 0; i < exportItems.length; i++) { exportMenuItems[i] = new JMenuItem(exportItems[i]); exportMenuItems[i].addActionListener(this); exportMenuItems[i].setEnabled(false); fileMenu.add(exportMenuItems[i]); } exportMenuItems[2].setEnabled(true); fileMenu.addSeparator(); fileMenu.setMnemonic(KeyEvent.VK_F); menuItem = new JMenuItem("Quit"); setAccelerator(menuItem, 'Q', false); menuItem.addActionListener(this); fileMenu.add(menuItem); /// display menu JMenu displayMenu = new JMenu("Display"); displayMenu.setMnemonic(KeyEvent.VK_D); menuBar.add(displayMenu); ButtonGroup group = new ButtonGroup(); viewMenuItems = new JRadioButtonMenuItem[viewItems.length]; for (int i = 0; i < viewItems.length; i++) { viewMenuItems[i] = new JRadioButtonMenuItem(viewItems[i], i == 0); viewMenuItems[i].addActionListener(this); KeyStroke ks = KeyStroke.getKeyStroke('1' + i, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); viewMenuItems[i].setAccelerator(ks); displayMenu.add(viewMenuItems[i]); viewMenuItems[i].setEnabled(false); group.add(viewMenuItems[i]); } displayMenu.addSeparator(); //a submenu ButtonGroup zg = new ButtonGroup(); JMenu zoomMenu = new JMenu("LD zoom"); zoomMenu.setMnemonic(KeyEvent.VK_Z); zoomMenuItems = new JRadioButtonMenuItem[zoomItems.length]; for (int i = 0; i < zoomItems.length; i++){ zoomMenuItems[i] = new JRadioButtonMenuItem(zoomItems[i], i==0); zoomMenuItems[i].addActionListener(this); zoomMenuItems[i].setActionCommand("zoom" + i); zoomMenu.add(zoomMenuItems[i]); zg.add(zoomMenuItems[i]); } displayMenu.add(zoomMenu); //another submenu ButtonGroup cg = new ButtonGroup(); JMenu colorMenu = new JMenu("D prime color scheme"); colorMenu.setMnemonic(KeyEvent.VK_C); colorMenuItems = new JRadioButtonMenuItem[colorItems.length]; for (int i = 0; i< colorItems.length; i++){ colorMenuItems[i] = new JRadioButtonMenuItem(colorItems[i],i==0); colorMenuItems[i].addActionListener(this); colorMenuItems[i].setActionCommand("color" + i); colorMenu.add(colorMenuItems[i]); cg.add(colorMenuItems[i]); } displayMenu.add(colorMenu); //analysis menu JMenu analysisMenu = new JMenu("Analysis"); analysisMenu.setMnemonic(KeyEvent.VK_A); menuBar.add(analysisMenu); //a submenu ButtonGroup bg = new ButtonGroup(); JMenu blockMenu = new JMenu("Define Blocks"); blockMenu.setMnemonic(KeyEvent.VK_B); blockMenuItems = new JRadioButtonMenuItem[blockItems.length]; for (int i = 0; i < blockItems.length; i++){ blockMenuItems[i] = new JRadioButtonMenuItem(blockItems[i], i==0); blockMenuItems[i].addActionListener(this); blockMenuItems[i].setActionCommand("block" + i); blockMenu.add(blockMenuItems[i]); bg.add(blockMenuItems[i]); } blockMenuItems[3].setEnabled(false); analysisMenu.add(blockMenu); clearBlocksItem = new JMenuItem(CLEAR_BLOCKS); setAccelerator(clearBlocksItem, 'C', false); clearBlocksItem.addActionListener(this); clearBlocksItem.setEnabled(false); analysisMenu.add(clearBlocksItem); JMenuItem customizeBlocksItem = new JMenuItem(CUST_BLOCKS); customizeBlocksItem.addActionListener(this); analysisMenu.add(customizeBlocksItem); //color key keyMenu = new JMenu("Key"); menuBar.add(Box.createHorizontalGlue()); menuBar.add(keyMenu); /** NEEDS FIXING helpMenu = new JMenu("Help"); menuBar.add(Box.createHorizontalGlue()); menuBar.add(helpMenu); menuItem = new JMenuItem("Tutorial"); menuItem.addActionListener(this); helpMenu.add(menuItem); **/ /* clearBlocksMenuItem.addActionListener(this); clearBlocksMenuItem.setEnabled(false); toolMenu.add(clearBlocksMenuItem); */ addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ quit(); } }); addComponentListener(new ResizeListener()); }
| 1,108,953
|
public HaploView(){ try{ fc = new JFileChooser(System.getProperty("user.dir")); }catch(NullPointerException n){ try{ UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); fc = new JFileChooser(System.getProperty("user.dir")); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){ } } //menu setup JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenuItem menuItem; //file menu JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); menuItem = new JMenuItem(READ_GENOTYPES); setAccelerator(menuItem, 'O', false); menuItem.addActionListener(this); fileMenu.add(menuItem); /* viewGenotypesItem = new JMenuItem(VIEW_GENOTYPES); viewGenotypesItem.addActionListener(this); //viewGenotypesItem.setEnabled(false); fileMenu.add(viewGenotypesItem); */ readMarkerItem = new JMenuItem(READ_MARKERS); setAccelerator(readMarkerItem, 'I', false); readMarkerItem.addActionListener(this); readMarkerItem.setEnabled(false); fileMenu.add(readMarkerItem); /* viewMarkerItem = new JMenuItem(VIEW_MARKERS); viewMarkerItem.addActionListener(this); //viewMarkerItem.setEnabled(false); fileMenu.add(viewMarkerItem); */ fileMenu.addSeparator(); exportMenuItems = new JMenuItem[exportItems.length]; for (int i = 0; i < exportItems.length; i++) { exportMenuItems[i] = new JMenuItem(exportItems[i]); exportMenuItems[i].addActionListener(this); exportMenuItems[i].setEnabled(false); fileMenu.add(exportMenuItems[i]); } exportMenuItems[2].setEnabled(true); fileMenu.addSeparator(); fileMenu.setMnemonic(KeyEvent.VK_F); menuItem = new JMenuItem("Quit"); setAccelerator(menuItem, 'Q', false); menuItem.addActionListener(this); fileMenu.add(menuItem); /// display menu JMenu displayMenu = new JMenu("Display"); displayMenu.setMnemonic(KeyEvent.VK_D); menuBar.add(displayMenu); ButtonGroup group = new ButtonGroup(); viewMenuItems = new JRadioButtonMenuItem[viewItems.length]; for (int i = 0; i < viewItems.length; i++) { viewMenuItems[i] = new JRadioButtonMenuItem(viewItems[i], i == 0); viewMenuItems[i].addActionListener(this); KeyStroke ks = KeyStroke.getKeyStroke('1' + i, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); viewMenuItems[i].setAccelerator(ks); displayMenu.add(viewMenuItems[i]); viewMenuItems[i].setEnabled(false); group.add(viewMenuItems[i]); } displayMenu.addSeparator(); //a submenu ButtonGroup zg = new ButtonGroup(); JMenu zoomMenu = new JMenu("D prime zoom"); zoomMenu.setMnemonic(KeyEvent.VK_Z); zoomMenuItems = new JRadioButtonMenuItem[zoomItems.length]; for (int i = 0; i < zoomItems.length; i++){ zoomMenuItems[i] = new JRadioButtonMenuItem(zoomItems[i], i==0); zoomMenuItems[i].addActionListener(this); zoomMenuItems[i].setActionCommand("zoom" + i); zoomMenu.add(zoomMenuItems[i]); zg.add(zoomMenuItems[i]); } displayMenu.add(zoomMenu); //another submenu ButtonGroup cg = new ButtonGroup(); JMenu colorMenu = new JMenu("D prime color scheme"); colorMenu.setMnemonic(KeyEvent.VK_C); colorMenuItems = new JRadioButtonMenuItem[colorItems.length]; for (int i = 0; i< colorItems.length; i++){ colorMenuItems[i] = new JRadioButtonMenuItem(colorItems[i],i==0); colorMenuItems[i].addActionListener(this); colorMenuItems[i].setActionCommand("color" + i); colorMenu.add(colorMenuItems[i]); cg.add(colorMenuItems[i]); } displayMenu.add(colorMenu); //analysis menu JMenu analysisMenu = new JMenu("Analysis"); analysisMenu.setMnemonic(KeyEvent.VK_A); menuBar.add(analysisMenu); //a submenu ButtonGroup bg = new ButtonGroup(); JMenu blockMenu = new JMenu("Define Blocks"); blockMenu.setMnemonic(KeyEvent.VK_B); blockMenuItems = new JRadioButtonMenuItem[blockItems.length]; for (int i = 0; i < blockItems.length; i++){ blockMenuItems[i] = new JRadioButtonMenuItem(blockItems[i], i==0); blockMenuItems[i].addActionListener(this); blockMenuItems[i].setActionCommand("block" + i); blockMenu.add(blockMenuItems[i]); bg.add(blockMenuItems[i]); } blockMenuItems[3].setEnabled(false); analysisMenu.add(blockMenu); clearBlocksItem = new JMenuItem(CLEAR_BLOCKS); setAccelerator(clearBlocksItem, 'C', false); clearBlocksItem.addActionListener(this); clearBlocksItem.setEnabled(false); analysisMenu.add(clearBlocksItem); JMenuItem customizeBlocksItem = new JMenuItem(CUST_BLOCKS); customizeBlocksItem.addActionListener(this); analysisMenu.add(customizeBlocksItem); //color key keyMenu = new JMenu("Key"); menuBar.add(Box.createHorizontalGlue()); menuBar.add(keyMenu); /** NEEDS FIXING helpMenu = new JMenu("Help"); menuBar.add(Box.createHorizontalGlue()); menuBar.add(helpMenu); menuItem = new JMenuItem("Tutorial"); menuItem.addActionListener(this); helpMenu.add(menuItem); **/ /* clearBlocksMenuItem.addActionListener(this); clearBlocksMenuItem.setEnabled(false); toolMenu.add(clearBlocksMenuItem); */ addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ quit(); } }); addComponentListener(new ResizeListener()); }
|
public HaploView(){ try{ fc = new JFileChooser(System.getProperty("user.dir")); }catch(NullPointerException n){ try{ UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); fc = new JFileChooser(System.getProperty("user.dir")); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); }catch(Exception e){ } } //menu setup JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenuItem menuItem; //file menu JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); menuItem = new JMenuItem(READ_GENOTYPES); setAccelerator(menuItem, 'O', false); menuItem.addActionListener(this); fileMenu.add(menuItem); /* viewGenotypesItem = new JMenuItem(VIEW_GENOTYPES); viewGenotypesItem.addActionListener(this); //viewGenotypesItem.setEnabled(false); fileMenu.add(viewGenotypesItem); */ readMarkerItem = new JMenuItem(READ_MARKERS); setAccelerator(readMarkerItem, 'I', false); readMarkerItem.addActionListener(this); readMarkerItem.setEnabled(false); fileMenu.add(readMarkerItem); /* viewMarkerItem = new JMenuItem(VIEW_MARKERS); viewMarkerItem.addActionListener(this); //viewMarkerItem.setEnabled(false); fileMenu.add(viewMarkerItem); */ fileMenu.addSeparator(); exportMenuItems = new JMenuItem[exportItems.length]; for (int i = 0; i < exportItems.length; i++) { exportMenuItems[i] = new JMenuItem(exportItems[i]); exportMenuItems[i].addActionListener(this); exportMenuItems[i].setEnabled(false); fileMenu.add(exportMenuItems[i]); } exportMenuItems[2].setEnabled(true); fileMenu.addSeparator(); fileMenu.setMnemonic(KeyEvent.VK_F); menuItem = new JMenuItem("Quit"); setAccelerator(menuItem, 'Q', false); menuItem.addActionListener(this); fileMenu.add(menuItem); /// display menu JMenu displayMenu = new JMenu("Display"); displayMenu.setMnemonic(KeyEvent.VK_D); menuBar.add(displayMenu); ButtonGroup group = new ButtonGroup(); viewMenuItems = new JRadioButtonMenuItem[viewItems.length]; for (int i = 0; i < viewItems.length; i++) { viewMenuItems[i] = new JRadioButtonMenuItem(viewItems[i], i == 0); viewMenuItems[i].addActionListener(this); KeyStroke ks = KeyStroke.getKeyStroke('1' + i, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); viewMenuItems[i].setAccelerator(ks); displayMenu.add(viewMenuItems[i]); viewMenuItems[i].setEnabled(false); group.add(viewMenuItems[i]); } displayMenu.addSeparator(); //a submenu ButtonGroup zg = new ButtonGroup(); JMenu zoomMenu = new JMenu("D prime zoom"); zoomMenu.setMnemonic(KeyEvent.VK_Z); zoomMenuItems = new JRadioButtonMenuItem[zoomItems.length]; for (int i = 0; i < zoomItems.length; i++){ zoomMenuItems[i] = new JRadioButtonMenuItem(zoomItems[i], i==0); zoomMenuItems[i].addActionListener(this); zoomMenuItems[i].setActionCommand("zoom" + i); zoomMenu.add(zoomMenuItems[i]); zg.add(zoomMenuItems[i]); } displayMenu.add(zoomMenu); //another submenu ButtonGroup cg = new ButtonGroup(); JMenu colorMenu = new JMenu("LD color scheme"); colorMenu.setMnemonic(KeyEvent.VK_C); colorMenuItems = new JRadioButtonMenuItem[colorItems.length]; for (int i = 0; i< colorItems.length; i++){ colorMenuItems[i] = new JRadioButtonMenuItem(colorItems[i],i==0); colorMenuItems[i].addActionListener(this); colorMenuItems[i].setActionCommand("color" + i); colorMenu.add(colorMenuItems[i]); cg.add(colorMenuItems[i]); } displayMenu.add(colorMenu); //analysis menu JMenu analysisMenu = new JMenu("Analysis"); analysisMenu.setMnemonic(KeyEvent.VK_A); menuBar.add(analysisMenu); //a submenu ButtonGroup bg = new ButtonGroup(); JMenu blockMenu = new JMenu("Define Blocks"); blockMenu.setMnemonic(KeyEvent.VK_B); blockMenuItems = new JRadioButtonMenuItem[blockItems.length]; for (int i = 0; i < blockItems.length; i++){ blockMenuItems[i] = new JRadioButtonMenuItem(blockItems[i], i==0); blockMenuItems[i].addActionListener(this); blockMenuItems[i].setActionCommand("block" + i); blockMenu.add(blockMenuItems[i]); bg.add(blockMenuItems[i]); } blockMenuItems[3].setEnabled(false); analysisMenu.add(blockMenu); clearBlocksItem = new JMenuItem(CLEAR_BLOCKS); setAccelerator(clearBlocksItem, 'C', false); clearBlocksItem.addActionListener(this); clearBlocksItem.setEnabled(false); analysisMenu.add(clearBlocksItem); JMenuItem customizeBlocksItem = new JMenuItem(CUST_BLOCKS); customizeBlocksItem.addActionListener(this); analysisMenu.add(customizeBlocksItem); //color key keyMenu = new JMenu("Key"); menuBar.add(Box.createHorizontalGlue()); menuBar.add(keyMenu); /** NEEDS FIXING helpMenu = new JMenu("Help"); menuBar.add(Box.createHorizontalGlue()); menuBar.add(helpMenu); menuItem = new JMenuItem("Tutorial"); menuItem.addActionListener(this); helpMenu.add(menuItem); **/ /* clearBlocksMenuItem.addActionListener(this); clearBlocksMenuItem.setEnabled(false); toolMenu.add(clearBlocksMenuItem); */ addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e){ quit(); } }); addComponentListener(new ResizeListener()); }
| 1,108,954
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.