List of usage examples for java.awt Component setForeground
public void setForeground(Color c)
From source file:nl.detoren.ijsco.ui.Mainscreen.java
public JPanel createDeelnemersPanel() { JPanel panel = new JPanel(false); panel.setBackground(Color.BLACK); //panel.setLayout(new GridLayout(1, 0)); panel.setLayout(new BorderLayout()); JPanel innerPanel = new JPanel(); JLabel lbAanwezig = new JLabel("Deelnemers: "); innerPanel.add(lbAanwezig, BorderLayout.NORTH); tfAanwezig = new JLabel(Integer.toString(status.deelnemers.aantalAanwezig()), 10); innerPanel.add(tfAanwezig, BorderLayout.NORTH); //innerPanel.setLayout(new GridLayout(1, 0)); innerPanel.add(new JLabel("Naam:"), BorderLayout.NORTH); JTextField deelnemer = new JTextField(15); ArrayList<String> words = new ArrayList<>(); if (status.OSBOSpelers != null) { for (Speler s : status.OSBOSpelers.values()) { words.add(s.getNaam().trim()); words.add(Integer.toString(s.getKnsbnummer())); }/* ww w .ja va 2 s .c o m*/ } @SuppressWarnings("unused") Suggesties suggesties = new Suggesties(deelnemer, this, words, 2); innerPanel.add(deelnemer, BorderLayout.NORTH); deelnemer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { actieVoegSpelerToe(deelnemer.getText().trim()); deelnemer.setText(""); } }); JButton btVoegToe = new JButton("Voeg toe"); btVoegToe.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { actieVoegSpelerToe(deelnemer.getText().trim()); deelnemer.setText(""); } }); innerPanel.add(btVoegToe); panel.add(innerPanel); // panel_deelnemers.add(new JLabel("Deelnemers IJSCO toernooi")); deelnemersModel = new DeelnemersModel(panel, status.deelnemers); JTable deelnemersTabel = new JTable(deelnemersModel) { private static final long serialVersionUID = -8293073016982337108L; @Override public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component c = super.prepareRenderer(renderer, row, column); DeelnemersModel model = (DeelnemersModel) getModel(); // Tooltip if (c instanceof JComponent) { ((JComponent) c) .setToolTipText(model.getToolTip(convertRowIndexToModel(row), column).toString()); } // Alternate row color if (!isRowSelected(row)) { c.setBackground(row % 2 == 0 ? Color.WHITE : Color.LIGHT_GRAY); } // Highlight overruled entries if (status.deelnemers.get(convertRowIndexToModel(row)).isOverruleNaam() || status.deelnemers.get(convertRowIndexToModel(row)).isOverruleNaam()) { c.setForeground(Color.BLUE); } else { c.setForeground(Color.BLACK); } return c; } }; deelnemersTabel.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent arg0) { status.groepen = null; status.schemas = null; status.schema = null; groepenText.setText(""); schemaModel.setSchemas(null); schemaModel.fireTableDataChanged(); if (status.deelnemers != null && tfAanwezig != null) { tfAanwezig.setText(Integer.toString(status.deelnemers.aantalAanwezig())); } panel.repaint(); } }); deelnemersTabel.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { logger.log(Level.INFO, "MouseEvent on table fired, type : " + e.toString()); logger.log(Level.INFO, "Popup trigger? : " + e.isPopupTrigger()); if (e.isPopupTrigger()) { int row = deelnemersTabel.rowAtPoint(e.getPoint()); JPopupMenu popup = new JPopupMenu(); JMenuItem menuItem = new JMenuItem("Bewerk speler"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { logger.log(Level.INFO, "Bewerk Speler : " + deelnemersTabel.convertRowIndexToModel(row)); Speler s = status.deelnemers.get(deelnemersTabel.convertRowIndexToModel(row)); BewerkSpelerDialoog rd = new BewerkSpelerDialoog(new JFrame(), "Bewerk Speler", s, deelnemersModel); rd.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { System.out.println("closing..."); } }); rd.setVisible(true); } }); popup.add(menuItem); menuItem = new JMenuItem("Verwijder Speler"); popup.add(menuItem); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { logger.log(Level.INFO, "Verwijder Speler : " + deelnemersTabel.convertRowIndexToModel(row)); Speler s = status.deelnemers.get(deelnemersTabel.convertRowIndexToModel(row)); status.deelnemers.remove(s); deelnemersModel.fireTableDataChanged(); } }); popup.show(e.getComponent(), e.getX(), e.getY()); } } }); JScrollPane scrollPane = new JScrollPane(); scrollPane.setViewportView(deelnemersTabel); innerPanel.add(scrollPane, BorderLayout.CENTER); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(deelnemersModel); deelnemersTabel.setRowSorter(sorter); innerPanel.add(new JLabel("Filter op : ")); JTextField tfFilter = new JTextField(10); tfFilter.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { String text = tfFilter.getText(); logger.log(Level.INFO, "Filter tabel op : " + text); if (text.length() == 0) { sorter.setRowFilter(null); } else { sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text)); } } }); innerPanel.add(tfFilter); JButton btPasToe = new JButton("Apply"); btPasToe.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { String text = tfFilter.getText(); logger.log(Level.INFO, "Filter tabel op : " + text); if (text.length() == 0) { sorter.setRowFilter(null); } else { sorter.setRowFilter(RowFilter.regexFilter("(?i)" + text)); } } }); innerPanel.add(btPasToe); JButton btWis = new JButton("Wis"); btWis.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { tfFilter.setText(""); logger.log(Level.INFO, "Wis filter"); sorter.setRowFilter(null); } }); innerPanel.add(btWis); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(0), 30); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(1), 55); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(2), 170); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(3), 40); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(4), 40); Utils.fixedColumSize(deelnemersTabel.getColumnModel().getColumn(5), 30); Utils.fixedComponentSize(scrollPane, 400, 580); return panel; }
From source file:org.eclipse.titanium.graph.visualization.NodeShape.java
/** * <b>Important: </b> This method is normally never called from our code, * Jung itself calls it inside while rendering graph. * /*from w ww . j a v a 2s .com*/ * @param vv * : The current context of visualizing (see * {@link CustomVisualizationViewer}) * @param value * : The value to assign to the label of the vertex * @param font * : A font object describing which font to use * @param isSelected * : Indicates whether the node is selected now * @param vertex * : A reference to the node to render * @return Returns an object describing the current rendering of node text */ @Override public <W extends Object> Component getVertexLabelRendererComponent(final JComponent vv, final Object value, final Font font, final boolean isSelected, final W vertex) { final Component comp = super.getVertexLabelRendererComponent(vv, value, font, isSelected, vertex); if (vertex instanceof NodeDescriptor) { final NodeDescriptor v = (NodeDescriptor) vertex; comp.setFont(v.getFontType()); if (!isSelected) { comp.setForeground(v.getFontColour()); } } return comp; }
From source file:org.micromanager.asidispim.AcquisitionPanel.java
/** * @param showWarnings true to warn user about needing to change slice period * @return/*from w w w . j a v a2 s . c o m*/ */ private SliceTiming getTimingFromPeriodAndLightExposure(boolean showWarnings) { // uses algorithm Jon worked out in Octave code; each slice period goes like this: // 1. camera readout time (none if in overlap mode, 0.25ms in pseudo-overlap) // 2. any extra delay time // 3. camera reset time // 4. start scan 0.25ms before camera global exposure and shifted up in time to account for delay introduced by Bessel filter // 5. turn on laser as soon as camera global exposure, leave laser on for desired light exposure time // 7. end camera exposure in final 0.25ms, post-filter scan waveform also ends now final float scanLaserBufferTime = MyNumberUtils.roundToQuarterMs(0.25f); // below assumed to be multiple of 0.25ms final Color foregroundColorOK = Color.BLACK; final Color foregroundColorError = Color.RED; final Component elementToColor = desiredSlicePeriod_.getEditor().getComponent(0); SliceTiming s = new SliceTiming(); final float cameraResetTime = computeCameraResetTime(); // recalculate for safety, 0 for light sheet final float cameraReadoutTime = computeCameraReadoutTime(); // recalculate for safety, 0 for overlap // can we use acquisition settings directly? because they may be in flux final AcquisitionSettings acqSettings = getCurrentAcquisitionSettings(); final float cameraReadout_max = MyNumberUtils.ceilToQuarterMs(cameraReadoutTime); final float cameraReset_max = MyNumberUtils.ceilToQuarterMs(cameraResetTime); // we will wait cameraReadout_max before triggering camera, then wait another cameraReset_max for global exposure // this will also be in 0.25ms increment final float globalExposureDelay_max = cameraReadout_max + cameraReset_max; final float laserDuration = MyNumberUtils.roundToQuarterMs(acqSettings.desiredLightExposure); final float scanDuration = laserDuration + 2 * scanLaserBufferTime; // scan will be longer than laser by 0.25ms at both start and end // account for delay in scan position due to Bessel filter by starting the scan slightly earlier // than we otherwise would (Bessel filter selected b/c stretches out pulse without any ripples) // delay to start is (empirically) 0.07ms + 0.25/(freq in kHz) // delay to midpoint is empirically 0.38/(freq in kHz) // group delay for 5th-order bessel filter ~0.39/freq from theory and ~0.4/freq from IC datasheet final float scanFilterFreq = Math.max( props_.getPropValueFloat(Devices.Keys.GALVOA, Properties.Keys.SCANNER_FILTER_X), props_.getPropValueFloat(Devices.Keys.GALVOB, Properties.Keys.SCANNER_FILTER_X)); float scanDelayFilter = 0; if (scanFilterFreq != 0) { scanDelayFilter = MyNumberUtils.roundToQuarterMs(0.39f / scanFilterFreq); } // If the PLogic card is used, account for 0.25ms delay it introduces to // the camera and laser trigger signals => subtract 0.25ms from the scanner delay // (start scanner 0.25ms later than it would be otherwise) // this time-shift opposes the Bessel filter delay // scanDelayFilter won't be negative unless scanFilterFreq is more than 3kHz which shouldn't happen if (devices_.isValidMMDevice(Devices.Keys.PLOGIC)) { scanDelayFilter -= 0.25f; } s.scanDelay = globalExposureDelay_max - scanLaserBufferTime // start scan 0.25ms before camera's global exposure - scanDelayFilter; // start galvo moving early due to card's Bessel filter and delay of TTL signals via PLC s.scanNum = 1; s.scanPeriod = scanDuration; s.laserDelay = globalExposureDelay_max; // turn on laser as soon as camera's global exposure is reached s.laserDuration = laserDuration; s.cameraDelay = cameraReadout_max; // camera must readout last frame before triggering again final Devices.Keys camKey = isFirstSideA() ? Devices.Keys.CAMERAA : Devices.Keys.CAMERAB; final Devices.Libraries camLibrary = devices_.getMMDeviceLibrary(camKey); // figure out desired time for camera to be exposing (including reset time) // because both camera trigger and laser on occur on 0.25ms intervals (i.e. we may not // trigger the laser until 0.24ms after global exposure) use cameraReset_max // special adjustment for Photometrics cameras that possibly has extra clear time which is counted in reset time // but not in the camera exposure time final float actualCameraResetTime = (camLibrary == Devices.Libraries.PVCAM && props_.getPropValueString(camKey, Properties.Keys.PVCAM_CHIPNAME) .equals(Properties.Values.PRIME_95B_CHIPNAME)) ? (float) props_.getPropValueInteger(camKey, Properties.Keys.PVCAM_READOUT_TIME) / 1e6f : cameraResetTime; // everything but Photometrics Prime 95B final float cameraExposure = MyNumberUtils.ceilToQuarterMs(actualCameraResetTime) + laserDuration; switch (acqSettings.cameraMode) { case EDGE: s.cameraDuration = 1; // doesn't really matter, 1ms should be plenty fast yet easy to see for debugging s.cameraExposure = cameraExposure + 0.1f; // add 0.1ms as safety margin, may require adding an additional 0.25ms to slice // slight delay between trigger and actual exposure start // is included in exposure time for Hamamatsu and negligible for Andor and PCO cameras // ensure not to miss triggers by not being done with readout in time for next trigger, add 0.25ms if needed if (getSliceDuration(s) < (s.cameraExposure + cameraReadoutTime)) { ReportingUtils.logDebugMessage( "Added 0.25ms in edge-trigger mode to make sure camera exposure long enough without dropping frames"); s.cameraDelay += 0.25f; s.laserDelay += 0.25f; s.scanDelay += 0.25f; } break; case LEVEL: // AKA "bulb mode", TTL rising starts exposure, TTL falling ends it s.cameraDuration = MyNumberUtils.ceilToQuarterMs(cameraExposure); s.cameraExposure = 1; // doesn't really matter, controlled by TTL break; case OVERLAP: // only Hamamatsu or Andor s.cameraDuration = 1; // doesn't really matter, 1ms should be plenty fast yet easy to see for debugging s.cameraExposure = 1; // doesn't really matter, controlled by interval between triggers break; case PSEUDO_OVERLAP: // PCO or Photometrics, enforce 0.25ms between end exposure and start of next exposure by triggering camera 0.25ms into the slice s.cameraDuration = 1; // doesn't really matter, 1ms should be plenty fast yet easy to see for debugging if (null != camLibrary) { switch (camLibrary) { case PCOCAM: s.cameraExposure = getSliceDuration(s) - s.cameraDelay; // s.cameraDelay should be 0.25ms for PCO break; case PVCAM: s.cameraExposure = cameraExposure; break; default: MyDialogUtils.showError("Unknown camera library for pseudo-overlap calculations"); break; } } if (s.cameraDelay < 0.24f) { MyDialogUtils.showError("Camera delay should be at least 0.25ms for pseudo-overlap mode."); } break; case LIGHT_SHEET: // each slice period goes like this: // 1. scan reset time (use to add any extra settling time to the start of each slice) // 2. start scan, wait scan settle time // 3. trigger camera/laser when scan settle time elapses // 4. scan for total of exposure time plus readout time (total time some row is exposing) plus settle time plus extra 0.25ms to prevent artifacts // 5. laser turns on 0.25ms before camera trigger and stays on until exposure is ending // TODO revisit this after further experimentation s.cameraDuration = 1; // only need to trigger camera final float shutterWidth = props_.getPropValueFloat(Devices.Keys.PLUGIN, Properties.Keys.PLUGIN_LS_SHUTTER_WIDTH); final int shutterSpeed = 1; // props_.getPropValueInteger(Devices.Keys.PLUGIN, Properties.Keys.PLUGIN_LS_SHUTTER_SPEED); float pixelSize = (float) core_.getPixelSizeUm(); if (pixelSize < 1e-6) { // can't compare equality directly with floating point values so call < 1e-9 is zero or negative pixelSize = 0.1625f; // default to pixel size of 40x with sCMOS = 6.5um/40 } final double rowReadoutTime = getRowReadoutTime(); s.cameraExposure = (float) (rowReadoutTime * shutterWidth / pixelSize * shutterSpeed); final float totalExposure_max = MyNumberUtils .ceilToQuarterMs(cameraReadoutTime + s.cameraExposure + 0.05f); // 50-300us extra cushion time final float scanSettle = props_.getPropValueFloat(Devices.Keys.PLUGIN, Properties.Keys.PLUGIN_LS_SCAN_SETTLE); final float scanReset = props_.getPropValueFloat(Devices.Keys.PLUGIN, Properties.Keys.PLUGIN_LS_SCAN_RESET); s.scanDelay = scanReset - scanDelayFilter; s.scanPeriod = scanSettle + totalExposure_max + scanLaserBufferTime; s.cameraDelay = scanReset + scanSettle; s.laserDelay = s.cameraDelay - scanLaserBufferTime; // trigger laser just before camera to make sure it's on already s.laserDuration = totalExposure_max + scanLaserBufferTime; // laser will turn off as exposure is ending break; case INTERNAL: default: if (showWarnings) { MyDialogUtils.showError("Invalid camera mode"); } s.valid = false; break; } // fix corner case of negative calculated scanDelay if (s.scanDelay < 0) { s.cameraDelay -= s.scanDelay; s.laserDelay -= s.scanDelay; s.scanDelay = 0; // same as (-= s.scanDelay) } // if a specific slice period was requested, add corresponding delay to scan/laser/camera elementToColor.setForeground(foregroundColorOK); if (!acqSettings.minimizeSlicePeriod) { float globalDelay = acqSettings.desiredSlicePeriod - getSliceDuration(s); // both should be in 0.25ms increments // TODO fix; if (acqSettings.cameraMode == CameraModes.Keys.LIGHT_SHEET) { globalDelay = 0; } if (globalDelay < 0) { globalDelay = 0; if (showWarnings) { // only true when user has specified period that is unattainable MyDialogUtils.showError("Increasing slice period to meet laser exposure constraint\n" + "(time required for camera readout; readout time depends on ROI)."); elementToColor.setForeground(foregroundColorError); } } s.scanDelay += globalDelay; s.cameraDelay += globalDelay; s.laserDelay += globalDelay; } // // Add 0.25ms to globalDelay if it is 0 and we are on overlap mode and scan has been shifted forward // // basically the last 0.25ms of scan time that would have determined the slice period isn't // // there any more because the scan time is moved up => add in the 0.25ms at the start of the slice // // in edge or level trigger mode the camera trig falling edge marks the end of the slice period // // not sure if PCO pseudo-overlap needs this, probably not because adding 0.25ms overhead in that case // if (MyNumberUtils.floatsEqual(cameraReadout_max, 0f) // true iff overlap being used // && (scanDelayFilter > 0.01f)) { // globalDelay += 0.25f; // } // fix corner case of (exposure time + readout time) being greater than the slice duration // most of the time the slice duration is already larger float globalDelay = MyNumberUtils .ceilToQuarterMs((s.cameraExposure + cameraReadoutTime) - getSliceDuration(s)); if (globalDelay > 0) { s.scanDelay += globalDelay; s.cameraDelay += globalDelay; s.laserDelay += globalDelay; } // update the slice duration based on our new values s.sliceDuration = getSliceDuration(s); return s; }
From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java
public static void setBackgroundColor(Component cellRendererComponent, JTable tbl, Object oValue, boolean bSelected, boolean bHasFocus, int iRow, int iColumn) { cellRendererComponent.setBackground(bSelected ? tbl.getSelectionBackground() : iRow % 2 == 0 ? tbl.getBackground() : NuclosThemeSettings.BACKGROUND_PANEL); cellRendererComponent.setForeground(bSelected ? tbl.getSelectionForeground() : tbl.getForeground()); final TableModel tm; final int adjustColIndex; if (tbl instanceof FixedColumnRowHeader.HeaderTable && ((FixedColumnRowHeader.HeaderTable) tbl).getExternalTable() != null) { tm = ((FixedColumnRowHeader.HeaderTable) tbl).getExternalTable().getModel(); adjustColIndex = FixedRowIndicatorTableModel.ROWMARKERCOLUMN_COUNT; } else {/*from w ww .j a va 2 s .c o m*/ tm = tbl.getModel(); adjustColIndex = 0; } // check whether the data of the component is readable for current user, by asking the security agent of the actual field if (tm instanceof SortableCollectableTableModel<?>) { final SortableCollectableTableModel<Collectable> tblModel = (SortableCollectableTableModel<Collectable>) tm; if (tblModel.getRowCount() > iRow) { final Collectable clct = tblModel.getCollectable(iRow); final Integer iTColumn = tbl.getColumnModel().getColumn(iColumn).getModelIndex() - adjustColIndex; final CollectableEntityField clctef = tblModel.getCollectableEntityField(iTColumn); if (clctef == null) { throw new NullPointerException("getTableCellRendererComponent failed to find field: " + clct + " tm index " + iTColumn); } boolean isEnabled = true; if (!clctef.isNullable() && isNull(oValue)) { cellRendererComponent.setBackground(getMandatoryColor()); cellRendererComponent.setForeground(tbl.getForeground()); } else { // if (clct.getId() == null) { // cellRendererComponent.setBackground(tbl.getBackground()); // cellRendererComponent.setForeground(tbl.getForeground()); // } else { if (tbl instanceof SubForm.SubFormTable) { SubFormTable subformtable = (SubForm.SubFormTable) tbl; Column subformcolumn = subformtable.getSubForm().getColumn(clctef.getName()); if (subformcolumn != null && !subformcolumn.isEnabled()) { isEnabled = false; if (bSelected) { cellRendererComponent .setBackground(NuclosThemeSettings.BACKGROUND_INACTIVESELECTEDCOLUMN); } else { cellRendererComponent.setBackground(NuclosThemeSettings.BACKGROUND_INACTIVECOLUMN); } } } // } try { EntityMetaDataVO meta = MetaDataClientProvider.getInstance() .getEntity(clctef.getEntityName()); if (meta.getRowColorScript() != null && !bSelected) { AbstractCollectableComponent.setBackground(cellRendererComponent, meta.getRowColorScript(), clct, meta, isEnabled); } } catch (CommonFatalException ex) { LOG.warn(ex); } } } } if (tbl instanceof TableRowMouseOverSupport) { TableRowMouseOverSupport trmos = (TableRowMouseOverSupport) tbl; if (trmos.isMouseOverRow(iRow)) { final Color bgColor = LangUtils.defaultIfNull(cellRendererComponent.getBackground(), Color.WHITE); cellRendererComponent .setBackground(new Color(Math.max(0, bgColor.getRed() - (bgColor.getRed() * 8 / 100)), Math.max(0, bgColor.getGreen() - (bgColor.getGreen() * 8 / 100)), Math.max(0, bgColor.getBlue() - (bgColor.getBlue() * 8 / 100)))); // cellRendererComponent.setBackground(UIManager.getColor("Table.selectionBackground")); } } }
From source file:org.revager.tools.GUITools.java
/** * Creates a new standard table.//from w w w . j a v a 2 s .co m * * @param model * the table model * @param showHeader * true if the header of the table should be visible * * @return the newly created table */ @SuppressWarnings("serial") public static JTable newStandardTable(TableModel model, boolean showHeader) { /* * Prep. for rollover */ if (lastRolloverKey == Integer.MAX_VALUE) { lastRolloverKey = 0; } else { lastRolloverKey++; } final int keyIdx = lastRolloverKey; rollOverRowIndex.put(keyIdx, -1); final JTable table = new JTable(model) { @Override public boolean editCellAt(int row, int column, java.util.EventObject e) { boolean result = super.editCellAt(row, column, e); final Component editor = getEditorComponent(); TableCellRenderer renderer = this.getColumnModel().getColumn(column).getCellRenderer(); Font cellFont = null; if (renderer instanceof DefaultTableCellRenderer) { cellFont = ((DefaultTableCellRenderer) renderer).getFont(); } if (editor != null && editor instanceof JTextComponent) { JTextComponent jTextComponent = (JTextComponent) editor; if (e == null) { jTextComponent.selectAll(); } else { SwingUtilities.invokeLater(jTextComponent::selectAll); } jTextComponent.setBorder(UI.MARKED_BORDER_INLINE); if (cellFont != null) { jTextComponent.setFont(cellFont); } editor.requestFocusInWindow(); } return result; } @Override public TableCellRenderer getCellRenderer(int row, int column) { TableCellRenderer renderer = super.getCellRenderer(row, column); if (renderer instanceof DefaultTableCellRenderer) { ((DefaultTableCellRenderer) renderer).setBorder(new EmptyBorder(3, 3, 3, 3)); } return renderer; } @Override public Component prepareRenderer(TableCellRenderer renderer, int row, int col) { Component comp = super.prepareRenderer(renderer, row, col); // Rollover comp.setBackground(getBackground()); comp = super.prepareRenderer(renderer, row, col); if (!isRowSelected(row) && row == rollOverRowIndex.get(keyIdx)) { comp.setForeground(getForeground()); comp.setBackground(UI.BLUE_BACKGROUND_COLOR); } // Tooltips JComponent jcomp = (JComponent) comp; if (renderer instanceof DefaultTableCellRenderer) { String toolTip = ((DefaultTableCellRenderer) renderer).getToolTipText(); if (!StringUtils.isEmpty(toolTip)) { jcomp.setToolTipText(toolTip); } } return comp; } }; // Table properties table.setRowHeight(UI.TABLE_ROW_HEIGHT); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setShowGrid(false); table.setShowHorizontalLines(true); table.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); // Rollover MouseInputAdapter rolloverListener = new MouseInputAdapter() { @Override public void mouseExited(MouseEvent e) { rollOverRowIndex.put(keyIdx, -1); table.repaint(); } @Override public void mouseMoved(MouseEvent e) { int row = table.rowAtPoint(e.getPoint()); if (row != rollOverRowIndex.get(keyIdx)) { rollOverRowIndex.put(keyIdx, row); table.repaint(); } } }; table.addMouseMotionListener(rolloverListener); table.addMouseListener(rolloverListener); // Header if (!showHeader) { table.setTableHeader(null); } return table; }
From source file:org.ut.biolab.medsavant.client.view.component.ListViewTablePanel.java
public ListViewTablePanel(Object[][] data, String[] columnNames, Class[] columnClasses, int[] hiddenColumns, boolean allowSearch, boolean allowSort, boolean allowPages, boolean allowSelection) { this.hiddenColumns = hiddenColumns; table = new SortableTable() { @Override//from ww w.j av a2 s. c om public Component prepareRenderer(TableCellRenderer renderer, int Index_row, int Index_col) { Component comp = super.prepareRenderer(renderer, Index_row, Index_col); //even index, selected or not selected if (isRowSelected(Index_row)) { comp.setBackground(ViewUtil.detailSelectedBackground); } else { if (Index_row % 2 == 0) { comp.setBackground(evenRowColor); } else { comp.setBackground(oddRowColor); } } comp.setForeground(ViewUtil.detailForeground); comp.setFont(comp.getFont().deriveFont(fontSize)); return comp; } }; table.setBorder(null); table.setSelectionForeground(Color.darkGray); table.setRowHeight(30); table.setClearSelectionOnTableDataChanges(true); table.setOptimized(true); table.setColumnAutoResizable(true); table.setAutoResort(false); //table.setDragEnabled(false); //table.setRowHeight(20); table.setSortable(allowSort); table.setSortingEnabled(allowSort); table.setFocusable(allowSelection); table.setCellSelectionEnabled(allowSelection); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setAutoResizeMode(SortableTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); //table.setMinimumSize(new Dimension(500,999)); //table.setPreferredSize(new Dimension(500,999)); //column chooser TableHeaderPopupMenuInstaller installer = new TableHeaderPopupMenuInstaller(table); installer.addTableHeaderPopupMenuCustomizer(new AutoResizePopupMenuCustomizer()); columnChooser = new ColumnChooser(table); installer.addTableHeaderPopupMenuCustomizer(columnChooser); AutoFilterTableHeader header = new AutoFilterTableHeader(table); header.setAutoFilterEnabled(true); header.setShowFilterIcon(true); header.setShowFilterName(true); table.setTableHeader(header); filterField = new QuickTableFilterField(model); filterField.setHintText("Type to search"); setLayout(new BorderLayout(3, 3)); fieldPanel = ViewUtil.getClearPanel(); fieldPanel.setLayout(new GridBagLayout()); setOpaque(false); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 1.0; //gbc.fill = GridBagConstraints.HORIZONTAL; gbc.fill = GridBagConstraints.BOTH; if (allowSearch) { fieldPanel.add(filterField, gbc); } if (columnNames.length > 1) { JButton chooseColumnButton = new JButton("Fields"); chooseColumnButton.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { columnChooser.showDialog(); } }); gbc.weightx = 0.0; gbc.fill = GridBagConstraints.NONE; fieldPanel.add(chooseColumnButton, gbc); } setTableModel(data, columnNames, columnClasses); if (allowSort) { add(fieldPanel, BorderLayout.NORTH); } JScrollPane jsp = new JScrollPane(table); jsp.setBorder(null); add(jsp, BorderLayout.CENTER); updateData(data); updateView(); }
From source file:plugins.ImageRectificationPanel.java
public final void createGui() { this.removeAll(); if (imageGCPsXCoords == null) { return;/*from w ww . j a va 2 s . c o m*/ } int i; int newN = 0; for (i = 0; i < imageGCPsXCoords.length; i++) { if (useGCP[i]) { newN++; } } double[] X1 = new double[newN]; double[] Y1 = new double[newN]; double[] X2 = new double[newN]; double[] Y2 = new double[newN]; int j = 0; for (i = 0; i < imageGCPsXCoords.length; i++) { if (useGCP[i]) { X1[j] = imageGCPsXCoords[i]; Y1[j] = imageGCPsYCoords[i]; X2[j] = mapGCPsXCoords[i]; Y2[j] = mapGCPsYCoords[i]; j++; } } calculateEquations(X1, Y1, X2, Y2); // gui stuff this.setLayout(new BorderLayout()); DecimalFormat df = new DecimalFormat("###,###,##0.000"); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); JButton btnOK = createButton(bundle.getString("OK"), bundle.getString("OK"), "ok"); JButton btnExit = createButton(bundle.getString("Close"), bundle.getString("Close"), "close"); //JButton btnRefresh = createButton("Cancel", "Cancel"); buttonPane.add(Box.createHorizontalStrut(10)); buttonPane.add(btnOK); buttonPane.add(Box.createHorizontalStrut(5)); //buttonPane.add(btnRefresh); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(btnExit); buttonPane.add(Box.createHorizontalGlue()); progressBar = new JProgressBar(0, 100); buttonPane.add(progressBar); buttonPane.add(Box.createHorizontalStrut(5)); cancel = new JLabel(bundle.getString("Cancel")); cancel.setForeground(Color.BLUE.darker()); cancel.addMouseListener(this); buttonPane.add(cancel); buttonPane.add(Box.createHorizontalStrut(10)); this.add(buttonPane, BorderLayout.SOUTH); Box mainBox = Box.createVerticalBox(); mainBox.add(Box.createVerticalStrut(10)); Box box1 = Box.createHorizontalBox(); box1.add(Box.createHorizontalStrut(10)); box1.add(new JLabel(bundle.getString("PolynomialOrder") + ": ")); SpinnerModel model = new SpinnerNumberModel(polyOrder, //initial value 1, //min 5, //max 1); //step polyOrderSpinner = new JSpinner(model); polyOrderSpinner.setPreferredSize(new Dimension(15, polyOrderSpinner.getPreferredSize().height)); polyOrderSpinner.addChangeListener(this); JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) polyOrderSpinner.getEditor(); editor.getTextField().setEnabled(true); editor.getTextField().setEditable(false); box1.add(polyOrderSpinner); box1.add(Box.createHorizontalGlue()); JLabel label = new JLabel("RMSE: " + df.format(overallRMSE)); box1.add(label); box1.add(Box.createHorizontalStrut(10)); mainBox.add(box1); mainBox.add(Box.createVerticalStrut(10)); // Create columns names int numPoints = imageGCPsXCoords.length; Object dataValues[][] = new Object[numPoints][7]; j = 0; for (i = 0; i < numPoints; i++) { dataValues[i][0] = i + 1; dataValues[i][1] = df.format(imageGCPsXCoords[i]); dataValues[i][2] = df.format(imageGCPsYCoords[i]); dataValues[i][3] = df.format(mapGCPsXCoords[i]); dataValues[i][4] = df.format(mapGCPsYCoords[i]); if (useGCP[i]) { dataValues[i][5] = df.format(residualsXY[j]); j++; } else { dataValues[i][5] = null; } dataValues[i][6] = useGCP[i]; } String columnNames[] = { "GCP", bundle.getString("Image") + " X", bundle.getString("Image") + " Y", bundle.getString("Map") + " X", bundle.getString("Map") + " Y", messages.getString("Error"), "Use" }; DefaultTableModel tableModel = new DefaultTableModel(dataValues, columnNames); dataTable = new JTable(tableModel) { private static final long serialVersionUID = 1L; @Override public Class getColumnClass(int column) { switch (column) { case 0: return Integer.class; case 1: return String.class; //Double.class; case 2: return String.class; //Double.class; case 3: return String.class; //Double.class; case 4: return String.class; //Double.class; case 5: return String.class; //Double.class; case 6: return Boolean.class; default: return String.class; //Double.class; } } @Override public Component prepareRenderer(TableCellRenderer renderer, int index_row, int index_col) { Component comp = super.prepareRenderer(renderer, index_row, index_col); //even index, selected or not selected if (index_row % 2 == 0) { comp.setBackground(Color.WHITE); comp.setForeground(Color.BLACK); } else { comp.setBackground(new Color(225, 245, 255)); //new Color(210, 230, 255)); comp.setForeground(Color.BLACK); } if (isCellSelected(index_row, index_col)) { comp.setForeground(Color.RED); } return comp; } }; tableModel.addTableModelListener(this); TableCellRenderer rend = dataTable.getTableHeader().getDefaultRenderer(); TableColumnModel tcm = dataTable.getColumnModel(); //for (int j = 0; j < tcm.getColumnCount(); j += 1) { TableColumn tc = tcm.getColumn(0); TableCellRenderer rendCol = tc.getHeaderRenderer(); // likely null if (rendCol == null) { rendCol = rend; } Component c = rendCol.getTableCellRendererComponent(dataTable, tc.getHeaderValue(), false, false, 0, 0); tc.setPreferredWidth(35); tc = tcm.getColumn(6); rendCol = tc.getHeaderRenderer(); // likely null if (rendCol == null) { rendCol = rend; } c = rendCol.getTableCellRendererComponent(dataTable, tc.getHeaderValue(), false, false, 0, 6); tc.setPreferredWidth(35); JScrollPane scroll = new JScrollPane(dataTable); mainBox.add(scroll); this.add(mainBox, BorderLayout.CENTER); this.validate(); }
From source file:psidev.psi.mi.tab.client.gui.DragAndDropConverter.java
/** * Drag and Drop MITAB25 Converter.// ww w . java 2 s . c o m */ public static void main(String[] args) throws FileNotFoundException { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { log.error("Failed to change Look and Feel.", e); } // Create and set up the window. final JFrame frame = new javax.swing.JFrame("MITAB25 Converter"); frame.setPreferredSize(new Dimension(400, 200)); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); frame.add(panel); addMenuBar(frame); Component label = new JLabel("Drag and drop your XML file(s) here"); label.setPreferredSize(new Dimension(400, 200)); label.setForeground(Color.red); panel.add(label); // Handle the dropped files PrintStream out = null; // could be System.out new DragAndDropComponent(out, panel, new FilesDroppedListener() { public void filesDropped(java.io.File[] files) { FilesProcessor processor = new FilesProcessor(); processor.process(frame, files, expansionStrategy, postProcessorStrategy, aggregateSelectedFiles); } }); // end FileDrop.Listener // Set up the window. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBounds(100, 100, 50, 50); // the size of the frame is defined by its internal component. frame.pack(); frame.setVisible(true); }