List of usage examples for javax.swing JList getSelectedValue
@BeanProperty(bound = false)
public E getSelectedValue()
From source file:edu.ku.brc.specify.config.ResourceImportExportDlg.java
/** * Enables the Import / Export and Revert Buttons *//* ww w . j a v a 2 s .c o m*/ protected void enableUI() { int currentTabIndex = tabbedPane.getModel().getSelectedIndex(); if (currentTabIndex == 0) // Views { boolean enable = !viewSetsList.isSelectionEmpty(); importBtn.setEnabled(enable && levelCBX.getSelectedIndex() < 5); exportBtn.setEnabled(enable && viewSetsModel.size() > 0); if (viewSetsList.getSelectedValue() instanceof SpViewSetObj) { SpViewSetObj vso = (SpViewSetObj) viewSetsList.getSelectedValue(); revertBtn.setEnabled(vso != null && vso.getId() != null); } else { revertBtn.setEnabled(false); } } else if (currentTabIndex != -1) { JList activeList = tabbedPane.getSelectedComponent() == resPanel ? resList : repList; if (activeList.getSelectedValue() instanceof String) { importBtn.setEnabled(true); exportBtn.setEnabled(false); revertBtn.setEnabled(false); } else { boolean hasOthersTab = tabbedPane.getTabCount() > 2; boolean enable = !activeList.isSelectionEmpty(); int numItems = ((DefaultListModel) activeList.getModel()).size(); importBtn.setEnabled(enable && (levelCBX.getSelectedIndex() < 2 || (numItems > 1 && hasOthersTab))); exportBtn.setEnabled(enable && numItems > 1); SpAppResource appRes = (SpAppResource) activeList.getSelectedValue(); enable = false; if (appRes != null && appRes.getId() != null) { if (appRes.getMimeType() != null && (appRes.getMimeType().equals(ReportsBaseTask.REPORTS_MIME) || appRes.getMimeType().equals(ReportsBaseTask.LABELS_MIME))) { //if (!isSpReportResource((SpAppResource )appRes)) { //XXX what if appres is imported report with no config file??? enable = true; //revert not currently working } } else { enable = true; } } revertBtn.setEnabled(enable); } } }
From source file:homenetapp.HomeNetAppGui.java
private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged int index = evt.getFirstIndex(); JList j = (JList) evt.getSource(); homenet.Packet p = (homenet.Packet) j.getSelectedValue(); //homenet.Packet p = (homenet.Packet)packetListModel.getElementAt(index); displayPacket(p);//www .j av a2s . com }
From source file:md.mclama.com.ModManager.java
protected void checkDependency(JList<String> list) { checkDependency(util.getModDependency(list.getSelectedValue()).replace("[", "").replace("]", "") .replace("\"", "").split(",")); }
From source file:edu.ku.brc.specify.config.ResourceImportExportDlg.java
/** * /*from w w w . j a v a 2s . c o m*/ */ protected void exportResource() { int index = levelCBX.getSelectedIndex(); if (index > -1) { String exportedName = null; String data = null; String fileName = null; AppResourceIFace appRes = null; if (tabbedPane.getSelectedComponent() == viewsPanel) { if (viewSetsList.getSelectedIndex() > -1) { SpViewSetObj vso = (SpViewSetObj) viewSetsList.getSelectedValue(); exportedName = vso.getName(); fileName = FilenameUtils.getName(vso.getFileName()); data = vso.getDataAsString(true); } } else { JList theList = tabbedPane.getSelectedComponent() == repPanel ? repList : resList; if (theList.getSelectedIndex() > 0) { appRes = (AppResourceIFace) theList.getSelectedValue(); exportedName = appRes.getName(); fileName = FilenameUtils.getName(exportedName); data = appRes.getDataAsString(); } } if (StringUtils.isNotEmpty(data)) { final String EXP_DIR_PREF = "RES_LAST_EXPORT_DIR"; String initalExportDir = AppPreferences.getLocalPrefs().get(EXP_DIR_PREF, getUserHomeDir()); FileDialog fileDlg = new FileDialog(this, getResourceString("RIE_ExportResource"), FileDialog.SAVE); File expDir = new File(initalExportDir); if (StringUtils.isNotEmpty(initalExportDir) && expDir.exists()) { fileDlg.setDirectory(initalExportDir); } fileDlg.setFile(fileName); UIHelper.centerAndShow(fileDlg); String dirStr = fileDlg.getDirectory(); fileName = fileDlg.getFile(); if (StringUtils.isNotEmpty(dirStr) && StringUtils.isNotEmpty(fileName)) { AppPreferences.getLocalPrefs().put(EXP_DIR_PREF, dirStr); File expFile = new File(dirStr + File.separator + fileName); try { if (isReportResource((SpAppResource) appRes) && isSpReportResource((SpAppResource) appRes)) { writeSpReportResToZipFile(expFile, data, appRes); } else { FileUtils.writeStringToFile(expFile, data); } } catch (FileNotFoundException ex) { showLocalizedMsg("RIE_NOFILEPERM"); } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ResourceImportExportDlg.class, ex); } } } if (exportedName != null) { getStatusBar().setText(getLocalizedMessage("RIE_RES_EXPORTED", exportedName)); } } }
From source file:edu.ku.brc.specify.utilapps.RegisterApp.java
/** * @return//from www. jav a 2 s . c o m */ private JPanel getStatsPane(final String chartPrefixTitle, final Collection<RegProcEntry> entries, final String tableName) { CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g")); final Hashtable<String, String> keyDescPairsHash = rp.getAllDescPairsHash(); final Hashtable<String, String> desc2KeyPairsHash = new Hashtable<String, String>(); for (String key : keyDescPairsHash.keySet()) { desc2KeyPairsHash.put(keyDescPairsHash.get(key), key); } Vector<String> keywords = new Vector<String>(); for (String keyword : getKeyWordsList(entries)) { if (keyword.endsWith("_name") || keyword.endsWith("_type") || keyword.endsWith("ISA_Number") || keyword.endsWith("reg_isa")) { //keywords.add(keyword); } else { String desc = keyDescPairsHash.get(keyword); //System.out.println("["+keyword+"]->["+desc+"]"); if (desc != null) { keywords.add(desc); } else { System.out.println("Desc for keyword[" + keyword + "] is null."); } } } Vector<Object[]> rvList = BasicSQLUtils .query("SELECT DISTINCT(Name) FROM registeritem WHERE SUBSTRING(Name, 1, 4) = 'num_'"); for (Object[] array : rvList) { keywords.add((String) array[0]); } Collections.sort(keywords); final JList list = new JList(keywords); pb.add(UIHelper.createScrollPane(list), cc.xy(1, 1)); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { String statName = (String) list.getSelectedValue(); if (desc2KeyPairsHash.get(statName) != null) { statName = desc2KeyPairsHash.get(statName); } DateType dateType = convertDateType(statName); if (dateType == DateType.None) { Vector<Pair<String, Integer>> values; if (statName.startsWith("num_")) { values = getCollNumValuesFromList(statName); Hashtable<String, Boolean> hash = new Hashtable<String, Boolean>(); for (Pair<String, Integer> p : values) { if (hash.get(p.first) == null) { hash.put(p.first, true); } else { int i = 0; String name = p.first; while (hash.get(p.first) != null) { p.first = name + " _" + i; i++; } hash.put(p.first, true); } //p.first += "(" + p.second.toString() + ")"; } } else { values = getCollValuesFromList(statName); } Collections.sort(values, countComparator); Vector<Pair<String, Integer>> top10Values = new Vector<Pair<String, Integer>>(); for (int i = 1; i < Math.min(11, values.size()); i++) { top10Values.insertElementAt(values.get(values.size() - i), 0); } createBarChart(chartPrefixTitle + " " + statName, statName, top10Values); } else { String desc = getByDateDesc(dateType); Vector<Pair<String, Integer>> values = tableName.equals("track") ? getDateValuesFromListByTable(dateType, tableName) : getDateValuesFromList(dateType); Collections.sort(values, titleComparator); createBarChart(chartPrefixTitle + " " + desc, desc, values); } } } }); return pb.getPanel(); }
From source file:edu.ku.brc.specify.config.ResourceImportExportDlg.java
/** * Revert a resource. Re-read it from the disk. *//* ww w . jav a2s . co m*/ protected void revertResource() { int index = levelCBX.getSelectedIndex(); if (index > -1) { String exportedName = null; String virtualDirName = SpecifyAppContextMgr.getVirtualDirName(index); if (tabbedPane.getSelectedComponent() == viewsPanel) { SpViewSetObj vso = (SpViewSetObj) viewSetsList.getSelectedValue(); if (vso != null) { exportedName = vso.getName(); index = viewSetsList.getSelectedIndex(); if (index > -1) { viewSetsModel.remove(index); contextMgr.revertViewSet(virtualDirName, vso.getName()); setHasChanged(true); } } } else { JList theList = tabbedPane.getSelectedComponent() == repPanel ? repList : resList; DefaultListModel theModel = theList == repList ? repModel : resModel; index = theList.getSelectedIndex(); if (index > 0) { AppResourceIFace appRes = (AppResourceIFace) theList.getSelectedValue(); AppResourceIFace revertedNewAR = contextMgr.revertResource(virtualDirName, appRes); setHasChanged(true); if (revertedNewAR != null) { theModel.insertElementAt(revertedNewAR, index); theList.setSelectedIndex(index); } else { theModel.removeElementAt(index); theList.clearSelection(); } levelSelected(); } } if (exportedName != null) { completeMsg = getLocalizedMessage("RIE_RES_REVERTED", exportedName); } enableUI(); } }
From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerFrame.java
/** * Export data //from ww w.ja v a2 s . c om */ protected void exportSingleLocale() { statusBar.setText(getResourceString("SchemaLocalizerFrame.EXPORTING")); //$NON-NLS-1$ statusBar.paintImmediately(statusBar.getBounds()); schemaLocPanel.getAllDataFromUI(); if (localizableIO.hasChanged()) { if (UIRegistry.askYesNoLocalized("SAVE", "CANCEL", UIRegistry.getResourceString("SchemaLocalizerFrame.NEEDS_SAVING"), "SAVE") == JOptionPane.YES_NO_OPTION) { localizableIO.save(); } else { return; } } Vector<Locale> stdLocales = SchemaI18NService.getInstance().getStdLocaleList(false); final JList list = new JList(stdLocales); list.setCellRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value != null) { setText(((Locale) value).getDisplayName()); } return this; } }); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "f:p:g")); pb.add(UIHelper.createScrollPane(list), (new CellConstraints()).xy(1, 1)); pb.setDefaultDialogBorder(); final CustomDialog dlg = new CustomDialog((Frame) UIRegistry.getTopWindow(), getResourceString("SchemaLocalizerFrame.CHOOSE_LOCALE"), true, pb.getPanel()); list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { dlg.getOkBtn().setEnabled(list.getSelectedValue() != null); } } }); dlg.createUI(); dlg.getOkBtn().setEnabled(false); UIHelper.centerAndShow(dlg); if (!dlg.isCancelled()) { Locale locale = (Locale) list.getSelectedValue(); if (locale != null) { FileDialog fileDlg = new FileDialog((Frame) UIRegistry.getTopWindow(), getResourceString("SchemaLocalizerFrame.SVFILENAME"), FileDialog.SAVE); fileDlg.setVisible(true); String fileName = fileDlg.getFile(); if (StringUtils.isNotEmpty(fileName)) { File outFile = new File(fileDlg.getDirectory() + File.separator + fileName); boolean savedOK = localizableIO.exportSingleLanguageToDirectory(outFile, locale); if (savedOK) { String msg = UIRegistry.getLocalizedMessage("SchemaLocalizerFrame.EXPORTEDTO", locale.getDisplayName(), outFile.getAbsolutePath()); UIRegistry.displayInfoMsgDlg(msg); } else { String msg = UIRegistry.getLocalizedMessage("SchemaLocalizerFrame.EXPORTING_ERR", outFile.getAbsolutePath()); UIRegistry.showError(msg); } } } } }
From source file:edu.ku.brc.specify.config.ResourceImportExportDlg.java
/** * /*from www .j ava 2 s. co m*/ */ protected void importResource() { int levelIndex = levelCBX.getSelectedIndex(); if (levelIndex > -1) { String importedName = null; final String IMP_DIR_PREF = "RES_LAST_IMPORT_DIR"; String initalImportDir = AppPreferences.getLocalPrefs().get(IMP_DIR_PREF, getUserHomeDir()); FileDialog fileDlg = new FileDialog(this, getResourceString("RIE_IMPORT_RES"), FileDialog.LOAD); File impDir = new File(initalImportDir); if (StringUtils.isNotEmpty(initalImportDir) && impDir.exists()) { fileDlg.setDirectory(initalImportDir); } UIHelper.centerAndShow(fileDlg); String dirStr = fileDlg.getDirectory(); String fileName = fileDlg.getFile(); if (StringUtils.isNotEmpty(dirStr) && StringUtils.isNotEmpty(fileName)) { AppPreferences.getLocalPrefs().put(IMP_DIR_PREF, dirStr); String data = null; String fullFileName = dirStr + File.separator + fileName; File importFile = new File(fullFileName); if (importFile.exists()) { String repResourceName = getSpReportResourceName(importFile); boolean isSpReportRes = repResourceName != null; boolean isJRReportRes = false; try { data = FileUtils.readFileToString(importFile); isJRReportRes = isJasperReport(data); } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ResourceImportExportDlg.class, ex); return; } boolean isReportRes = isJRReportRes || isSpReportRes; if (tabbedPane.getSelectedComponent() == viewsPanel) { int viewIndex = viewSetsList.getSelectedIndex(); if (viewIndex > -1) { boolean isAddItemForImport = viewSetsList.getSelectedValue() instanceof String; boolean isOK = false; SpViewSetObj vso = null; DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); session.beginTransaction(); if (!isAddItemForImport) { vso = (SpViewSetObj) viewSetsList.getSelectedValue(); SpAppResourceDir appResDir = vso.getSpAppResourceDir(); importedName = vso.getName(); if (vso.getSpViewSetObjId() == null) { appResDir.getSpPersistedViewSets().add(vso); vso.setSpAppResourceDir(appResDir); } vso.setDataAsString(data, true); session.saveOrUpdate(appResDir); } else { SpAppResourceDir appResDir = dirs.get(levelIndex); vso = new SpViewSetObj(); vso.initialize(); vso.setLevel((short) levelIndex); vso.setName(FilenameUtils.getBaseName(importFile.getName())); appResDir.getSpPersistedViewSets().add(vso); vso.setSpAppResourceDir(appResDir); vso.setDataAsString(data); session.saveOrUpdate(appResDir); } session.saveOrUpdate(vso); for (SpAppResourceData ard : vso.getSpAppResourceDatas()) { session.saveOrUpdate(ard); } session.commit(); session.flush(); setHasChanged(true); isOK = true; completeMsg = getLocalizedMessage("RIE_RES_IMPORTED", importedName == null ? fileName : importedName); } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance() .capture(ResourceImportExportDlg.class, ex); session.rollback(); } finally { try { session.close(); } catch (Exception ex) { ex.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance() .capture(ResourceImportExportDlg.class, ex); } } if (isOK) { if (isAddItemForImport) { viewSetsModel.clear(); viewSetsModel.addElement(vso); } else { viewSetsModel.remove(viewIndex); viewSetsModel.insertElementAt(vso, viewIndex); } viewSetsList.repaint(); } } } else { boolean isResourcePanel = tabbedPane.getSelectedComponent() == repPanel; JList theList = isResourcePanel ? repList : resList; int resIndex = theList.getSelectedIndex(); Object selObj = theList.getSelectedValue(); if (resIndex > -1) { if (resIndex == 0) // means we are adding a new resource { try { SpecifyUser user = contextMgr.getClassObject(SpecifyUser.class); Agent agent = contextMgr.getClassObject(Agent.class); SpAppResourceDir dir = dirs.get(levelIndex); SpAppResource appRes = new SpAppResource(); appRes.initialize(); appRes.setName(fileName); appRes.setCreatedByAgent(agent); appRes.setSpecifyUser(user); if (dir.getId() == null) { dir.mergeTransientResourceAndViewSets(); } Pair<SpAppResource, String> retValues = checkForOverwriteOrNewName(dir, isSpReportRes ? repResourceName : fileName, isSpReportRes); if (retValues != null && retValues.first == null && retValues.second == null) { return; // Dialog was Cancelled } SpAppResource fndAppRes = retValues != null && retValues.first != null ? retValues.first : null; String newResName = retValues != null && retValues.second != null ? retValues.second : null; if (isReportRes) { if (fndAppRes != null) { if (isSpReportRes) { ReportsBaseTask.deleteReportAndResource(null, fndAppRes.getId()); } else { //XXX ??????????? if (fndAppRes.getSpAppResourceId() != null) { contextMgr.removeAppResourceSp(fndAppRes.getSpAppResourceDir(), fndAppRes); } } } /*else if (newResName == null) { return; }*/ if (isSpReportRes) { appRes = importSpReportZipResource(importFile, appRes, dir, newResName); if (appRes != null) { importedName = appRes.getName(); } } else { if (MainFrameSpecify.importJasperReport(importFile, false, newResName)) { importedName = importFile.getName(); } else { return; } } if (importedName != null) { CommandDispatcher.dispatch(new CommandAction(ReportsBaseTask.REPORTS, ReportsBaseTask.REFRESH, null)); CommandDispatcher.dispatch(new CommandAction(QueryTask.QUERY, QueryTask.REFRESH_QUERIES, null)); levelSelected(); } } else if (fndAppRes != null) // overriding { appRes.setMetaData(fndAppRes.getMetaData()); appRes.setDescription(fndAppRes.getDescription()); appRes.setFileName(fileName); appRes.setMimeType(appRes.getMimeType()); appRes.setName(fileName); appRes.setLevel(fndAppRes.getLevel()); } else if (!getMetaInformation(appRes, fileName)) { return; } if (!isReportRes) { appRes.setSpAppResourceDir(dir); dir.getSpAppResources().add(appRes); appRes.setDataAsString(data); contextMgr.saveResource(appRes); completeMsg = getLocalizedMessage("RIE_RES_IMPORTED", importedName == null ? fileName : importedName); } setHasChanged(true); } catch (Exception e) { e.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance() .capture(ResourceImportExportDlg.class, e); } } else if (selObj instanceof AppResourceIFace) { //if (isResourcePanel) resIndex++; AppResourceIFace fndAppRes = null; for (AppResourceIFace appRes : resources) { if (appRes == selObj) { fndAppRes = appRes; break; } } if (fndAppRes != null) { String importedFileName = fndAppRes.getFileName(); String fName = FilenameUtils.getName(importedFileName); String dbBaseName = FilenameUtils.getBaseName(fileName); //log.debug("["+fName+"]["+dbBaseName+"]"); boolean doOverwrite = true; if (!dbBaseName.equals(fName)) { String msg = getLocalizedMessage("RIE_OVRDE_MSG", dbBaseName, fName); doOverwrite = displayConfirm(getResourceString("RIE_OVRDE_TITLE"), msg, getResourceString("RIE_OVRDE"), getResourceString("CANCEL"), JOptionPane.QUESTION_MESSAGE); } if (doOverwrite) { fndAppRes.setDataAsString(data); contextMgr.saveResource(fndAppRes); completeMsg = getLocalizedMessage("RIE_RES_IMPORTED", importedName == null ? fileName : importedName); } } else { UIRegistry.showError("Strange error - Couldn't resource."); } } } } if (importedName != null) { completeMsg = getLocalizedMessage("RIE_RES_IMPORTED", importedName == null ? fileName : importedName); } if (hasChanged()) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { okBtn.doClick(); } }); } } else { UIRegistry.showLocalizedError("FILE_NO_EXISTS", fullFileName); } } enableUI(); } }
From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java
@SuppressWarnings("unchecked") private void addRenderers() { try {/*w w w . j ava2s . c om*/ setDefaultRenderer(Class.forName("java.lang.Object"), new JBDefaultTableCellRenderer()); setDefaultRenderer(Class.forName("java.util.Collection"), new CollectionRenderer()); final JList<Object> list = new JList<Object>(); list.setVisibleRowCount(3); list.setOpaque(true); list.setCellRenderer(new ListDefaultRenderer()); list.addListSelectionListener(new ListSelectionListener() { @SuppressWarnings({ "static-access", "unused" }) public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { Object obj = list.getSelectedValue(); obj = RegistryObjectsTable.this.convertValue(obj); if (obj instanceof URL) { HyperLinker.displayURL(obj.toString()); } else if (obj instanceof String) { //Check if URL is valid URL _url = null; try { _url = new URL(obj.toString()); HyperLinker.displayURL(obj.toString()); } catch (MalformedURLException exc) { //No need to do anything. It is normal for text to not be a URL _url = null; } } } } }); JScrollPane listPane = new JScrollPane(list); setDefaultEditor(Class.forName("java.util.Collection"), new JBDefaultCellEditor(listPane)); HyperLinkLabel hyperLinkLabel = new HyperLinkLabel(); hyperLinkLabel.setHorizontalAlignment(SwingConstants.TRAILING); setDefaultEditor(Class.forName("java.lang.Object"), new JBDefaultCellEditor(hyperLinkLabel)); } catch (ClassNotFoundException e) { return; } }
From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java
/** * @return/*from w w w. ja v a 2 s . co m*/ */ private JPanel createColorCategoriesPanel() { JPanel categoryColorsConfigurationPanel = new JPanel(new GridBagLayout()); categoryColorsConfigurationPanel.setPreferredSize(new Dimension(180, 200)); GridBagConstraints itemConstraint = new GridBagConstraints(); JLabel categoryColorsLabel = new ResourceLabel( "plotter.configuration_dialog.color_scheme_dialog.category_colors"); { itemConstraint.fill = GridBagConstraints.HORIZONTAL; itemConstraint.anchor = GridBagConstraints.WEST; itemConstraint.gridwidth = GridBagConstraints.RELATIVE; itemConstraint.insets = new Insets(0, 5, 5, 5); itemConstraint.weightx = 1.0; categoryColorsConfigurationPanel.add(categoryColorsLabel, itemConstraint); } // add button panel { JPanel buttonPanel = new JPanel(new GridBagLayout()); // remove scheme button { removeCategoryColorButton = new JButton(new ResourceAction(true, "plotter.configuration_dialog.color_scheme_dialog.remove_category_color_button") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { removeSelectedColorAction(); } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.RELATIVE; itemConstraint.fill = GridBagConstraints.NONE; buttonPanel.add(removeCategoryColorButton, itemConstraint); } { addCategoryButton = new JButton(new ResourceAction(true, "plotter.configuration_dialog.color_scheme_dialog.add_category_color_button") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { Color oldColor = Color.white; Color newSchemeColor = createColorDialog(oldColor); if (newSchemeColor != null && !newSchemeColor.equals(oldColor)) { addColorAction(newSchemeColor); } } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.fill = GridBagConstraints.NONE; buttonPanel.add(addCategoryButton, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.anchor = GridBagConstraints.EAST; itemConstraint.insets = new Insets(0, 5, 5, 5); categoryColorsConfigurationPanel.add(buttonPanel, itemConstraint); } { JPanel categoryListPanel = new JPanel(new GridBagLayout()); // add list of categorie colors { colorList = new JList<Color>(nominalColorListModel); categoryColorsLabel.setLabelFor(colorList); colorList.setCellRenderer(new ColorListCellRenderer()); colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); MouseAdapter ma = new MouseAdapter() { private void myPopupEvent(MouseEvent e) { int x = e.getX(); int y = e.getY(); JList<?> list = (JList<?>) e.getSource(); list.setSelectedIndex(list.locationToIndex(e.getPoint())); Color selectedColor = (Color) list.getSelectedValue(); if (selectedColor == null) { return; } removeMenuItem.setEnabled(nominalColorListModel.getSize() > 2); popupMenu.show(list, x, y); } @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { myPopupEvent(e); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { myPopupEvent(e); } } }; colorList.addMouseListener(ma); colorList.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { return; // Nothing to be done } @Override public void keyReleased(KeyEvent e) { return; // Nothing to be done } @Override public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_DELETE) { if (nominalColorListModel.getSize() > 2) { removeSelectedColorAction(); } } if (key == KeyEvent.VK_F2) { replaceSelectedColorAction(); } if (key == KeyEvent.VK_UP && SwingTools.isControlOrMetaDown(e)) { moveSelectedColorUpAction(); } if (key == KeyEvent.VK_DOWN && SwingTools.isControlOrMetaDown(e)) { moveSelectedColorDownAction(); } } }); colorListScrollPane = new JScrollPane(colorList); colorListScrollPane.setPreferredSize(new Dimension(170, 200)); colorListScrollPane.setMaximumSize(new Dimension(170, 200)); colorListScrollPane.setMinimumSize(new Dimension(170, 180)); colorListScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); colorListScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); itemConstraint = new GridBagConstraints(); itemConstraint.fill = GridBagConstraints.BOTH; itemConstraint.weightx = 0.0; itemConstraint.weighty = 0.5; itemConstraint.gridwidth = GridBagConstraints.RELATIVE; categoryListPanel.add(colorListScrollPane, itemConstraint); } // add up/down button panel { JPanel upAndDownButtonPanel = new JPanel(new GridBagLayout()); // add up button { JButton upButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.move_color_up") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { moveSelectedColorUpAction(); } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 0; itemConstraint.weighty = 0; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.insets = new Insets(0, 2, 0, 12); upAndDownButtonPanel.add(upButton, itemConstraint); } // add down button { JButton downButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.move_color_down") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { moveSelectedColorDownAction(); } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 0; itemConstraint.weighty = 0; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.insets = new Insets(0, 2, 0, 12); upAndDownButtonPanel.add(downButton, itemConstraint); } // add spacer panel { JPanel spacer = new JPanel(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 0; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.VERTICAL; upAndDownButtonPanel.add(spacer, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.VERTICAL; categoryListPanel.add(upAndDownButtonPanel, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.BOTH; categoryColorsConfigurationPanel.add(categoryListPanel, itemConstraint); } return categoryColorsConfigurationPanel; }