List of usage examples for javax.swing JTable getParent
public Container getParent()
From source file:Main.java
public static void scrollToVisible(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return;//from w ww. j a va 2 s .c om } JViewport viewport = (JViewport) table.getParent(); Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); Point pt = viewport.getViewPosition(); rect.setLocation(rect.x - pt.x, rect.y - pt.y); viewport.scrollRectToVisible(rect); }
From source file:Main.java
public static void scrollToCenter(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return;/*from www . j a v a 2 s. c om*/ } JViewport viewport = (JViewport) table.getParent(); Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); Rectangle viewRect = viewport.getViewRect(); rect.setLocation(rect.x - viewRect.x, rect.y - viewRect.y); int centerX = (viewRect.width - rect.width) / 2; int centerY = (viewRect.height - rect.height) / 2; if (rect.x < centerX) { centerX = -centerX; } if (rect.y < centerY) { centerY = -centerY; } rect.translate(centerX, centerY); viewport.scrollRectToVisible(rect); }
From source file:Main.java
public static boolean isCellVisible(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return false; }/*from w ww . j a va2 s . c o m*/ JViewport viewport = (JViewport) table.getParent(); Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); Point pt = viewport.getViewPosition(); rect.setLocation(rect.x - pt.x, rect.y - pt.y); return new Rectangle(viewport.getExtentSize()).contains(rect); }
From source file:Main.java
/** * Scrolls a table so that a certain cell becomes visible. * Source: http://javaalmanac.com/egs/javax.swing.table/Vis.html * @param table/* w w w . j a v a 2 s . c om*/ * @param rowIndex * @param vColIndex */ public static void scrollToVisible(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return; } JViewport viewport = (JViewport) table.getParent(); // This rectangle is relative to the table where the // northwest corner of cell (0,0) is always (0,0). Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); // The location of the viewport relative to the table Point pt = viewport.getViewPosition(); // Translate the cell location so that it is relative // to the view, assuming the northwest corner of the // view is (0,0) rect.setLocation(rect.x - pt.x, rect.y - pt.y); table.scrollRectToVisible(rect); // Scroll the area into view //viewport.scrollRectToVisible(rect); }
From source file:JTableHelper.java
public static void scrollToCenter(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return;// w w w . j av a2 s.c om } JViewport viewport = (JViewport) table.getParent(); Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); Rectangle viewRect = viewport.getViewRect(); rect.setLocation(rect.x - viewRect.x, rect.y - viewRect.y); int centerX = (viewRect.width - rect.width) / 2; int centerY = (viewRect.height - rect.height) / 2; if (rect.x < centerX) { centerX = -centerX; } if (rect.y < centerY) { centerY = -centerY; } rect.translate(centerX, centerY); viewport.scrollRectToVisible(rect); }
From source file:Main.java
/** * Assumes table is contained in a JScrollPane. * Scrolls the cell (rowIndex, vColIndex) so that it is visible * within the viewport./*from ww w . ja va 2s . c o m*/ */ public static void scrollToVisible(JTable table, int row, int col) { if (!(table.getParent() instanceof JViewport)) return; JViewport viewport = (JViewport) table.getParent(); // This rectangle is relative to the table where the // northwest corner of cell (0,0) is always (0,0). Rectangle rect = table.getCellRect(row, col, true); // The location of the viewport relative to the table Point pt = viewport.getViewPosition(); // Translate the cell location so that it is relative // to the view, assuming the northwest corner of the // view is (0,0) rect.setLocation(rect.x - pt.x, rect.y - pt.y); // Scroll the area into view viewport.scrollRectToVisible(rect); }
From source file:edu.harvard.mcz.imagecapture.ui.ButtonEditor.java
@Override public void actionPerformed(ActionEvent e) { // Action might not be event_button_pressed on all systems. log.debug("Button event actionCommand: " + e.getActionCommand()); if (e.getActionCommand().equals(EVENT_PRESSED)) { // Event is a click on the cell // Identify the row that was clicked on. JTable table = (JTable) ((JButton) e.getSource()).getParent(); log.debug(e.getSource());//ww w. j a va 2 s .c om log.debug(table); int row = table.getEditingRow(); // Stop editing - note, we need to have gotten e.getSource.getParent and getEditingRow first. fireEditingStopped(); //Make the renderer reappear. Singleton.getSingletonInstance().getMainFrame() .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); switch (formToOpen) { case OPEN_SPECIMEN_DETAILS: // Load the selected specimen record from its ID (the data value behind the button). //SpecimenLifeCycle sls = new SpecimenLifeCycle(); //Specimen specimen = sls.findById((Long)targetId); //if (specimen!=null) { if (targetId != null) { // a specimen with this ID exists, bring up the details editor. try { //SpecimenControler sc = new SpecimenControler(specimen); if (((Specimen) targetId).getSpecimenId() != null) { if (((Specimen) targetId).isStateDone()) { // Specimens in state_done are no longer editable JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "This Specimen record has been migrated and can no longer be edited here [" + ((Specimen) targetId).getLoadFlags() + "].\nSee: http://mczbase.mcz.harvard.edu/guid/MCZ:Ent:" + ((Specimen) targetId).getCatNum(), "Migrated Specimen", JOptionPane.WARNING_MESSAGE); } else { // Specimen is still editable if (table != null) { // Pass the specimen object for the row, the table model, and the row number on to the specimen controler. try { SpecimenControler sc = new SpecimenControler((Specimen) targetId, (SpecimenListTableModel) table.getModel(), table, row); if (table.getParent().getParent().getParent().getParent() .getClass() == SpecimenBrowser.class) { sc.addListener((DataChangeListener) table.getParent()); } else { Component x = table; boolean done = false; while (!done) { log.debug(x.getParent()); x = x.getParent(); if (x.getClass() == SpecimenBrowser.class) { sc.addListener((DataChangeListener) x); done = true; } } } sc.displayInEditor(); } catch (java.lang.ClassCastException eNotSp) { // Request isn't coming from a SpecimenListTableModel // View just the specimen record. SpecimenControler sc = new SpecimenControler((Specimen) targetId); sc.displayInEditor(); } } else { log.debug(e.getSource()); //SpecimenControler sc = new SpecimenControler((Specimen)targetId); //sc.displayInEditor(); } } } else { log.debug("User clicked on table row containing a new Specimen()"); JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "No Specimen for this image", "Load Specimen Failed", JOptionPane.WARNING_MESSAGE); } } catch (NoSuchRecordException e1) { log.error("Tested for specimen!=null, but SpecimenControler threw null specimen exception"); log.error(e1); } } else { log.debug("No matches found to specimen id=" + targetId); // TODO: Create new specimen record and bring up dialog JOptionPane.showMessageDialog(Singleton.getSingletonInstance().getMainFrame(), "No specimen record."); } break; case OPEN_TEMPLATE: // Load the selected specimen record from its ID (the data value behind the button). try { // a template with this targetID exists, display it. ((PositionTemplateEditor) parentComponent).setTemplate((String) targetId); } catch (NoSuchTemplateException e1) { log.error("No such template on button press on a template in list."); log.error(e1); log.trace(e1); } break; case OPEN_USER: //TODO: tie to user log.debug("Open user"); ((UserListBrowser) parentComponent).getEditUserPanel().setUser((Users) targetId); break; case OPEN_SPECIMEN_VERBATIM: log.debug("Open Verbatim Transcription"); SpecimenLifeCycle sls = new SpecimenLifeCycle(); List<Specimen> toTranscribe = sls.findForVerbatim(((GenusSpeciesCount) targetId).getGenus(), ((GenusSpeciesCount) targetId).getSpecificEpithet(), WorkFlowStatus.STAGE_1); log.debug(toTranscribe.size()); SpecimenListTableModel stm = new SpecimenListTableModel(toTranscribe); JTable stable = new JTable(); stable.setModel(stm); SpecimenControler verbCont; try { verbCont = new SpecimenControler(toTranscribe.get(0), stm, stable, 0); VerbatimCaptureDialog dialog = new VerbatimCaptureDialog(toTranscribe.get(0), verbCont); dialog.setVisible(true); } catch (NoSuchRecordException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } break; case OPEN_VERBATIM_CLASSIFY: log.debug("Open Verbatim Classify dialog"); try { VerbatimClassifyDialog dialog = new VerbatimClassifyDialog( (VerbatimCount) table.getModel().getValueAt(row, 0)); dialog.setVisible(true); } catch (ClassCastException e1) { log.error(e1.getMessage(), e1); } break; case ACTION_CANCEL_JOB: log.debug("Action Cancel requested on job " + targetId); Singleton.getSingletonInstance().getJobList().getJobAt((Integer) targetId).cancel(); break; case OPEN_SPECIMENPARTATTRIBUTES: SpecimenPartAttributeDialog attrDialog = new SpecimenPartAttributeDialog((SpecimenPart) targetId); attrDialog.setVisible(true); break; } Singleton.getSingletonInstance().getMainFrame() .setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); System.gc(); } }
From source file:org.yccheok.jstock.gui.JTableUtilities.java
public static void scrollToVisible(JTable table, int rowIndex, int vColIndex) { if (!(table.getParent() instanceof JViewport)) { return;// w ww. j a v a 2 s . c om } JViewport viewport = (JViewport) table.getParent(); // This rectangle is relative to the table where the // northwest corner of cell (0,0) is always (0,0). Rectangle rect = table.getCellRect(rowIndex, vColIndex, true); // The location of the viewport relative to the table Point pt = viewport.getViewPosition(); // Translate the cell location so that it is relative // to the view, assuming the northwest corner of the // view is (0,0) rect.setLocation(rect.x - pt.x, rect.y - pt.y); // Scroll the area into view viewport.scrollRectToVisible(rect); }
From source file:ro.nextreports.designer.util.TableUtil.java
/** * Creats a row header for the given table. The row number is displayed to * the left of the table ( starting with row 1). * * @param table the table to create the row header for * @param headerWidth the number of characters to size the header *//*from www . j ava2 s . c om*/ public static TableRowHeader setRowHeader(JTable table, int headerWidth) { TableRowHeader result = null; Container p = table.getParent(); if (p instanceof JViewport) { Container gp = p.getParent(); if (gp instanceof JScrollPane) { JScrollPane scrollPane = (JScrollPane) gp; result = new TableRowHeader(table); scrollPane.setRowHeaderView(result); } } return result; }
From source file:ro.nextreports.designer.util.TableUtil.java
/** * Creates row header for table with row number (starting with 1) displayed. *//*from w w w. j a v a 2 s . c om*/ public static void removeRowHeader(JTable table) { Container p = table.getParent(); if (p instanceof JViewport) { Container gp = p.getParent(); if (gp instanceof JScrollPane) { JScrollPane scrollPane = (JScrollPane) gp; scrollPane.setRowHeader(null); } } }