List of usage examples for javax.swing ListCellRenderer ListCellRenderer
ListCellRenderer
From source file:Main.java
private void setListCellRendererOf(JComboBox comboBox) { comboBox.setRenderer(new ListCellRenderer() { @Override//from w w w .j a v a2s . c o m public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component component = new DefaultListCellRenderer().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); component.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); return component; } }); }
From source file:net.sf.maltcms.chromaui.charts.GradientPaintScale.java
/** * * @param args//from w ww . j a v a 2s. co m */ public static void main(String[] args) { double[] st = ImageTools.createSampleTable(256); Logger.getLogger(GradientPaintScale.class.getName()).info(Arrays.toString(st)); double min = 564.648; double max = 24334.234; GradientPaintScale gps = new GradientPaintScale(st, min, max, new Color[] { Color.BLACK, Color.RED, Color.orange, Color.yellow, Color.white }); double val = min; double incr = (max - min) / (st.length - 1); Logger.getLogger(GradientPaintScale.class.getName()).log(Level.INFO, "Increment: {0}", incr); for (int i = 0; i < st.length; i++) { Logger.getLogger(GradientPaintScale.class.getName()).log(Level.INFO, "Value: {0}", val); gps.getPaint(val); val += incr; } Logger.getLogger(GradientPaintScale.class.getName()).info("Printing min and max values"); Logger.getLogger(GradientPaintScale.class.getName()).log(Level.INFO, "Min: {0} gps min: {1}", new Object[] { min, gps.getPaint(min) }); Logger.getLogger(GradientPaintScale.class.getName()).log(Level.INFO, "Max: {0} gps max: {1}", new Object[] { max, gps.getPaint(max) }); JList jl = new JList(); DefaultListModel dlm = new DefaultListModel(); jl.setModel(dlm); jl.setCellRenderer(new ListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value instanceof JLabel) { // Border b = // BorderFactory.createCompoundBorder(BorderFactory // .createEmptyBorder(0, 0, 5, 0), BorderFactory // .createLineBorder(Color.BLACK, 1)); // ((JLabel) value).setBorder(b); return (Component) value; } return new JLabel(value.toString()); } }); JFrame jf = new JFrame(); jf.add(new JScrollPane(jl)); jf.setVisible(true); jf.setSize(200, 400); for (int alpha = -10; alpha <= 10; alpha++) { for (int beta = 1; beta <= 20; beta++) { gps.setAlphaBeta(alpha, beta); // System.out.println(Arrays.toString(gps.st)); // System.out.println(Arrays.toString(gps.sampleTable)); BufferedImage bi = gps.getLookupImage(); ImageIcon ii = new ImageIcon(bi); dlm.addElement(new JLabel(ii)); } } }
From source file:entity.files.SYSFilesTools.java
public static ListCellRenderer getSYSFilesRenderer() { // final int v = verbosity; return new ListCellRenderer() { @Override//from w w w . ja v a2s.c o m public Component getListCellRendererComponent(JList jList, Object o, int i, boolean isSelected, boolean cellHasFocus) { String text; if (o == null) { text = SYSTools.toHTML("<i>Keine Auswahl</i>"); } else if (o instanceof SYSFiles) { SYSFiles sysfile = (SYSFiles) o; text = sysfile.getFilename() + SYSTools.catchNull(sysfile.getBeschreibung(), " (", ")"); } else { text = o.toString(); } return new DefaultListCellRenderer().getListCellRendererComponent(jList, text, i, isSelected, cellHasFocus); } }; }
From source file:userinterface.graph.GraphOptionsPanel.java
/** Creates new form GraphOptionsPanel */ public GraphOptionsPanel(GUIPlugin plugin, JFrame parent, JPanel theModel) { this.plugin = plugin; this.parent = parent; this.theModel = theModel; /* TODO: Use generic container. */ ArrayList own = new ArrayList(); own.add(theModel);//from w w w . jav a 2s . c om graphPropertiesTable = new SettingTable(parent); graphPropertiesTable.setOwners(own); if (theModel instanceof Graph) { ((Graph) theModel).setDisplay(graphPropertiesTable); xAxisSettings = ((Graph) theModel).getXAxisSettings(); yAxisSettings = ((Graph) theModel).getYAxisSettings(); zAxisSettings = null; displaySettings = ((Graph) theModel).getDisplaySettings(); } else if (theModel instanceof Histogram) { ((Histogram) theModel).setDisplay(graphPropertiesTable); xAxisSettings = ((Histogram) theModel).getXAxisSettings(); yAxisSettings = ((Histogram) theModel).getYAxisSettings(); zAxisSettings = null; displaySettings = ((Histogram) theModel).getDisplaySettings(); } else if (theModel instanceof Graph3D) { ((Graph3D) theModel).setDisplay(graphPropertiesTable); xAxisSettings = ((Graph3D) theModel).getxAxisSetting(); yAxisSettings = ((Graph3D) theModel).getyAxisSetting(); zAxisSettings = null; //zAxisSettings = ((Graph3D)theModel).getzAxisSetting(); displaySettings = ((Graph3D) theModel).getDisplaySettings(); } String[] axes = { "x-Axis", "y-Axis" }; axesList = new JList(axes); axesList.setSelectedIndex(0); axesList.addListSelectionListener(this); own = new ArrayList(); own.add(xAxisSettings); axisPropertiesTable = new SettingTable(parent); axisPropertiesTable.setOwners(own); if (theModel instanceof Graph) { ((AxisSettings) xAxisSettings).setDisplay(axisPropertiesTable); ((AxisSettings) yAxisSettings).setDisplay(axisPropertiesTable); } else if (theModel instanceof Histogram) { ((AxisSettingsHistogram) xAxisSettings).setDisplay(axisPropertiesTable); ((AxisSettingsHistogram) yAxisSettings).setDisplay(axisPropertiesTable); } else { ((AxisSettings3D) xAxisSettings).setDisplay(axisPropertiesTable); ((AxisSettings3D) yAxisSettings).setDisplay(axisPropertiesTable); } own = new ArrayList(); own.add(displaySettings); displayPropertiesTable = new SettingTable(parent); displayPropertiesTable.setOwners(own); if (theModel instanceof ChartPanel) ((DisplaySettings) displaySettings).setDisplay(displayPropertiesTable); else if (theModel instanceof Graph3D) ((DisplaySettings3D) displaySettings).setDisplay(displayPropertiesTable); if (theModel instanceof Graph) { seriesList = new JList(((Graph) theModel).getGraphSeriesList()); } else if (theModel instanceof Histogram) { seriesList = new JList(((Histogram) theModel).getGraphSeriesList()); } else if (theModel instanceof Graph3D) { seriesList = new JList(((Graph3D) theModel).getGraphSeriesList()); } seriesList.addListSelectionListener(this); seriesList.setCellRenderer(new ListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = new JLabel((value == null) ? "undefined" : value.toString()); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0)); if (isSelected) { panel.setBackground(list.getSelectionBackground()); panel.setForeground(list.getSelectionForeground()); } else { panel.setBackground(list.getBackground()); panel.setForeground(list.getForeground()); } if (value instanceof SeriesSettings) { SeriesSettings graphSeries = (SeriesSettings) value; panel.add(graphSeries.getIcon()); } panel.add(label); return panel; } }); seriesPropertiesTable = new SettingTable(parent); /*seriesList = theModel.getSeriesList(); seriesList.addListSelectionListener(this); //seriesModel = new PropertyTableModel(); ArrayList ss = seriesList.getSelectedSeries(); //seriesModel.setOwners(ss); seriesProperties = new SettingTable(parent); seriesProperties.setOwners(ss);*/ initComponents(); //addSeries.setEnabled(ss.size() > 0); /*removeSeries.setEnabled(ss.size() > 0); moveUp.setEnabled(ss.size() > 0); moveDown.setEnabled(ss.size() > 0); viewData.setEnabled(ss.size() > 0);*/ }
From source file:org.forester.archaeopteryx.ControlPanel.java
private void addSequenceRelationBlock() { final JLabel spacer = new JLabel(""); spacer.setSize(1, 1);//from w w w. j a v a2 s .com add(spacer); final JLabel mainLabel = new JLabel("Sequence relations to display"); final JLabel typeLabel = customizeLabel(new JLabel("(type) "), getConfiguration()); typeLabel.setFont(ControlPanel.js_font.deriveFont(7)); getSequenceRelationTypeBox().setFocusable(false); _sequence_relation_type_box.setFont(ControlPanel.js_font); if (!_configuration.isUseNativeUI()) { _sequence_relation_type_box.setBackground(Constants.BUTTON_BACKGROUND_COLOR_DEFAULT); _sequence_relation_type_box.setForeground(Constants.BUTTON_TEXT_COLOR_DEFAULT); } _sequence_relation_type_box.setRenderer(new ListCellRenderer() { @Override public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { final Component component = new DefaultListCellRenderer().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if ((value != null) && (value instanceof SequenceRelation.SEQUENCE_RELATION_TYPE)) { ((DefaultListCellRenderer) component).setText(SequenceRelation .getPrintableNameByType((SequenceRelation.SEQUENCE_RELATION_TYPE) value)); } return component; } }); final GridBagLayout gbl = new GridBagLayout(); _sequence_relation_type_box.setMinimumSize(new Dimension(115, 17)); _sequence_relation_type_box.setPreferredSize(new Dimension(115, 20)); final JPanel horizGrid = new JPanel(gbl); horizGrid.setBackground(getBackground()); horizGrid.add(typeLabel); horizGrid.add(_sequence_relation_type_box); add(customizeLabel(mainLabel, getConfiguration())); add(horizGrid); add(getSequenceRelationBox()); if (_configuration.doDisplayOption(Configuration.show_relation_confidence)) { addCheckbox(Configuration.show_relation_confidence, _configuration.getDisplayTitle(Configuration.show_relation_confidence)); setCheckbox(Configuration.show_relation_confidence, _configuration.doCheckOption(Configuration.show_relation_confidence)); } }
From source file:op.care.med.inventory.DlgCloseStock.java
private void initDialog() { String text = SYSTools.xx("nursingrecords.prescription.dlgCloseStock.youWantToClose1a") + medStock.getID() + SYSTools.xx("nursingrecords.prescription.dlgCloseStock.youWantToClose1b"); text += "<br/>" + MedStockTools.getTextASHTML(medStock) + "</br>"; text += "<br/>" + SYSTools.xx("nursingrecords.prescription.dlgCloseStock.chooseAReason") + ":"; txtInfo.setContentType("text/html"); txtInfo.setText(SYSTools.toHTML(SYSConst.html_div(text))); EntityManager em = OPDE.createEM();//from ww w . j av a 2 s . c om Query query = em.createQuery(" " + " SELECT b FROM MedStock b " + " WHERE b.inventory = :inventory AND b.out = :out AND b.opened = :opened " + " ORDER BY b.in, b.id "); query.setParameter("inventory", medStock.getInventory()); query.setParameter("out", SYSConst.DATE_UNTIL_FURTHER_NOTICE); query.setParameter("opened", SYSConst.DATE_UNTIL_FURTHER_NOTICE); DefaultComboBoxModel dcbm = new DefaultComboBoxModel(query.getResultList().toArray()); dcbm.insertElementAt(SYSTools.xx("misc.msg.none"), 0); cmbBestID.setModel(dcbm); cmbBestID.setRenderer(new ListCellRenderer() { @Override public Component getListCellRendererComponent(JList jList, Object o, int i, boolean b, boolean b1) { String text = o instanceof MedStock ? ((MedStock) o).getID().toString() : o.toString(); return new JLabel(text); } }); em.close(); int index = Math.min(2, cmbBestID.getItemCount()); cmbBestID.setSelectedIndex(index - 1); lblEinheiten.setText(SYSConst.UNITS[medStock.getTradeForm().getDosageForm().getPackUnit()] + " " + SYSTools.xx("misc.msg.usedup")); txtLetzte.setText(""); txtLetzte.setEnabled(false); // Das mit dem Vorabstellen nur bei Formen, die auf Stck basieren also APV = 1 rbStellen.setEnabled(medStock.getTradeForm().getDosageForm().getUPRState() == DosageFormTools.STATE_UPR1); }
From source file:op.care.prescription.DlgOnDemand.java
private ListCellRenderer getRenderer() { return new ListCellRenderer() { @Override/*from ww w . j a va2s . c om*/ public java.awt.Component getListCellRendererComponent(JList jList, Object o, int i, boolean isSelected, boolean cellHasFocus) { String text; if (o == null) { text = "<i>" + SYSTools.xx("nursingrecords.prescription.dlgOnDemand.noOutcomeCheck") + "</i>"; } else if (o instanceof BigDecimal) { if (o.equals(new BigDecimal("0.5"))) { text = "½ " + SYSTools.xx("misc.msg.Hour"); } else if (o.equals(BigDecimal.ONE)) { text = "1 " + SYSTools.xx("misc.msg.Hour"); } else { text = o.toString() + " " + SYSTools.xx("misc.msg.Hours"); } } else { text = o.toString(); } return new DefaultListCellRenderer().getListCellRendererComponent(jList, SYSTools.toHTMLForScreen(text), i, isSelected, cellHasFocus); } }; }
From source file:op.controlling.PnlControlling.java
private JPanel createContentPanel4Nursing() { JPanel pnlContent = new JPanel(new VerticalLayout()); /***//from www. ja va 2 s.com * __ __ _ * \ \ / /__ _ _ _ __ __| |___ * \ \ /\ / / _ \| | | | '_ \ / _` / __| * \ V V / (_) | |_| | | | | (_| \__ \ * \_/\_/ \___/ \__,_|_| |_|\__,_|___/ * */ JPanel pnlWounds = new JPanel(new BorderLayout()); final JButton btnWounds = GUITools.createHyperlinkButton("opde.controlling.nursing.wounds", null, null); int woundsMonthsBack; try { woundsMonthsBack = Integer.parseInt(OPDE.getProps().getProperty("opde.controlling::woundsMonthsBack")); } catch (NumberFormatException nfe) { woundsMonthsBack = 7; } final JTextField txtWoundsMonthsBack = GUITools.createIntegerTextField(1, 12, woundsMonthsBack); txtWoundsMonthsBack.setToolTipText(SYSTools.xx("misc.msg.monthsback")); btnWounds.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { SYSPropsTools.storeProp("opde.controlling::woundsMonthsBack", txtWoundsMonthsBack.getText(), OPDE.getLogin().getUser()); SYSFilesTools.print( getWounds(Integer.parseInt(txtWoundsMonthsBack.getText()), progressClosure), false); return null; } @Override protected void done() { OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); pnlWounds.add(btnWounds, BorderLayout.WEST); pnlWounds.add(txtWoundsMonthsBack, BorderLayout.EAST); pnlContent.add(pnlWounds); /*** * ____ _ _ _____ _ * / ___| ___ ___(_) __ _| | |_ _(_)_ __ ___ ___ ___ * \___ \ / _ \ / __| |/ _` | | | | | | '_ ` _ \ / _ \/ __| * ___) | (_) | (__| | (_| | | | | | | | | | | | __/\__ \ * |____/ \___/ \___|_|\__,_|_| |_| |_|_| |_| |_|\___||___/ * */ JPanel pblSocialTimes = new JPanel(new BorderLayout()); final JButton btnSocialTimes = GUITools.createHyperlinkButton("opde.controlling.nursing.social", null, null); final JComboBox cmbSocialTimes = new JComboBox( SYSCalendar.createMonthList(new LocalDate().minusYears(1), new LocalDate())); btnSocialTimes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { LocalDate month = (LocalDate) cmbSocialTimes.getSelectedItem(); SYSFilesTools.print(NReportTools.getTimes4SocialReports(month, progressClosure), false); return null; } @Override protected void done() { OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); cmbSocialTimes.setRenderer(new ListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return new DefaultListCellRenderer().getListCellRendererComponent(list, monthFormatter.format(((LocalDate) value).toDate()), index, isSelected, cellHasFocus); } }); cmbSocialTimes.setSelectedIndex(cmbSocialTimes.getItemCount() - 2); pblSocialTimes.add(btnSocialTimes, BorderLayout.WEST); pblSocialTimes.add(cmbSocialTimes, BorderLayout.EAST); pnlContent.add(pblSocialTimes); return pnlContent; }
From source file:op.controlling.PnlControlling.java
private JPanel createContentPanel4Nutrition() { JPanel pnlContent = new JPanel(new VerticalLayout()); /***/*from ww w .j a va 2 s. c o m*/ * _ _ _ _ _ _ * | (_) __ _ _ _(_) __| | | |__ __ _| | __ _ _ __ ___ ___ * | | |/ _` | | | | |/ _` | | '_ \ / _` | |/ _` | '_ \ / __/ _ \ * | | | (_| | |_| | | (_| | | |_) | (_| | | (_| | | | | (_| __/ * |_|_|\__, |\__,_|_|\__,_| |_.__/ \__,_|_|\__,_|_| |_|\___\___| * |_| */ JPanel pnlLiquidBalance = new JPanel(new BorderLayout()); final JButton btnLiquidBalance = GUITools.createHyperlinkButton("opde.controlling.nutrition.liquidbalance", null, null); final JComboBox cmbLiquidBalanceMonth = new JComboBox( SYSCalendar.createMonthList(new LocalDate().minusYears(1), new LocalDate())); btnLiquidBalance.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { LocalDate month = (LocalDate) cmbLiquidBalanceMonth.getSelectedItem(); SYSFilesTools.print(ResValueTools.getLiquidBalance(month, progressClosure), false); return null; } @Override protected void done() { OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); cmbLiquidBalanceMonth.setRenderer(new ListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return new DefaultListCellRenderer().getListCellRendererComponent(list, monthFormatter.format(((LocalDate) value).toDate()), index, isSelected, cellHasFocus); } }); cmbLiquidBalanceMonth.setSelectedIndex(cmbLiquidBalanceMonth.getItemCount() - 2); pnlLiquidBalance.add(btnLiquidBalance, BorderLayout.WEST); pnlLiquidBalance.add(cmbLiquidBalanceMonth, BorderLayout.EAST); pnlContent.add(pnlLiquidBalance); /*** * _ _ _ _ _ _ _ _ * __ _____(_) __ _| |__ | |_ ___| |_ __ _| |_(_)___| |_(_) ___ ___ * \ \ /\ / / _ \ |/ _` | '_ \| __| / __| __/ _` | __| / __| __| |/ __/ __| * \ V V / __/ | (_| | | | | |_ \__ \ || (_| | |_| \__ \ |_| | (__\__ \ * \_/\_/ \___|_|\__, |_| |_|\__| |___/\__\__,_|\__|_|___/\__|_|\___|___/ * |___/ */ JPanel pnlWeight = new JPanel(new BorderLayout()); final JButton btnWeightStats = GUITools.createHyperlinkButton("opde.controlling.nutrition.weightstats", null, null); int wsMonthsBack; try { wsMonthsBack = Integer.parseInt(OPDE.getProps().getProperty("opde.controlling::wsMonthsBack")); } catch (NumberFormatException nfe) { wsMonthsBack = 7; } final JTextField txtWSMonthsBack = GUITools.createIntegerTextField(1, 24, wsMonthsBack); txtWSMonthsBack.setToolTipText(SYSTools.xx("misc.msg.monthsback")); btnWeightStats.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OPDE.getMainframe().setBlocked(true); SwingWorker worker = new SwingWorker() { @Override protected Object doInBackground() throws Exception { SYSPropsTools.storeProp("opde.controlling::wsMonthsBack", txtWSMonthsBack.getText(), OPDE.getLogin().getUser()); SYSFilesTools.print(ResValueTools.getWeightStats( Integer.parseInt(txtWSMonthsBack.getText()), progressClosure), false); return null; } @Override protected void done() { OPDE.getDisplayManager().setProgressBarMessage(null); OPDE.getMainframe().setBlocked(false); } }; worker.execute(); } }); pnlWeight.add(btnWeightStats, BorderLayout.WEST); pnlWeight.add(txtWSMonthsBack, BorderLayout.EAST); pnlContent.add(pnlWeight); return pnlContent; }
From source file:op.tools.SYSCalendar.java
public static ListCellRenderer getTimeRenderer() { return new ListCellRenderer() { DateFormat timeFormat = DateFormat.getTimeInstance(DateFormat.SHORT); @Override/* w ww.java2 s . c om*/ public Component getListCellRendererComponent(JList jList, Object o, int i, boolean isSelected, boolean cellHasFocus) { String text; if (o == null) { text = SYSTools.xx("misc.commands.>>noselection<<"); } else if (o instanceof Date) { Date date = (Date) o; text = timeFormat.format(date) + " " + SYSTools.xx("misc.msg.Time.short"); } else { text = o.toString(); } return new DefaultListCellRenderer().getListCellRendererComponent(jList, text, i, isSelected, cellHasFocus); } }; }