List of usage examples for javax.swing JList JList
public JList(final Vector<? extends E> listData)
JList
that displays the elements in the specified Vector
. From source file:com.rapidminer.gui.properties.RegexpPropertyDialog.java
public RegexpPropertyDialog(final Collection<String> items, String predefinedRegexp, String description) { super(ApplicationFrame.getApplicationFrame(), "parameter.regexp", ModalityType.APPLICATION_MODAL, new Object[] {}); this.items = items; this.supportsItems = items != null; this.infoText = "<html>" + I18N.getMessage(I18N.getGUIBundle(), getKey() + ".title") + ": <br/>" + description + "</html>"; Dimension size = new Dimension(420, 500); this.setMinimumSize(size); this.setPreferredSize(size); JPanel panel = new JPanel(createGridLayout(1, supportsItems ? 2 : 1)); // create regexp text field regexpTextField = new JTextField(predefinedRegexp); regexpTextField.setToolTipText(// w ww . j a v a 2 s . c o m I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.tip")); regexpTextField.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { fireRegularExpressionUpdated(); } @Override public void keyTyped(KeyEvent e) { } }); regexpTextField.requestFocus(); // create replacement text field replacementTextField = new JTextField(); replacementTextField.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.replacement.tip")); replacementTextField.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { fireRegularExpressionUpdated(); } @Override public void keyTyped(KeyEvent e) { } }); // create inline search documents inlineSearchDocument = new RegexpSearchStyledDocument(); inlineReplaceDocument = new RegexpReplaceStyledDocument(); // create search results list DefaultListCellRenderer resultCellRenderer = new DefaultListCellRenderer() { private static final long serialVersionUID = 1L; @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); setBackground(list.getBackground()); setForeground(list.getForeground()); setBorder(getNoFocusBorder()); return this; } private Border getNoFocusBorder() { Border border = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray); return border; } }; JList<RegExpResult> regexpFindingsList = new JList<RegExpResult>(resultsListModel); regexpFindingsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); regexpFindingsList.setLayoutOrientation(JList.VERTICAL); regexpFindingsList.setCellRenderer(resultCellRenderer); // regexp panel on left side of dialog JPanel regexpPanel = new JPanel(new GridBagLayout()); regexpPanel.setBorder(createTitledBorder( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.border"))); GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(4, 4, 4, 0); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.fill = GridBagConstraints.BOTH; regexpPanel.add(regexpTextField, c); // make shortcut button final Action nullAction = new DefaultAction(); PlainArrowDropDownButton autoWireDropDownButton = PlainArrowDropDownButton.makeDropDownButton(nullAction); for (String[] popupItem : (String[][]) ArrayUtils.addAll(regexpConstructs, regexpShortcuts)) { String shortcut = popupItem[0].length() > 14 ? popupItem[0].substring(0, 14) + "..." : popupItem[0]; autoWireDropDownButton .add(new InsertionAction("<html><table border=0 cellpadding=0 cellspacing=0><tr><td width=100>" + shortcut + "</td><td>" + popupItem[1] + "</td></tr></table></html>", popupItem[0])); } c.insets = new Insets(4, 0, 4, 0); c.gridx = 1; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; regexpPanel.add(autoWireDropDownButton.getDropDownArrowButton(), c); // make delete button c.insets = new Insets(4, 0, 4, 4); c.gridx = 2; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; JButton clearRegexpTextFieldButton = new JButton(SwingTools.createIcon("16/delete2.png")); clearRegexpTextFieldButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { regexpTextField.setText(""); fireRegularExpressionUpdated(); regexpTextField.requestFocusInWindow(); } }); regexpPanel.add(clearRegexpTextFieldButton, c); errorMessage = new JLabel(NO_ERROR_MESSAGE, NO_ERROR_ICON, SwingConstants.LEFT); errorMessage.setFocusable(false); c.insets = new Insets(4, 8, 4, 4); c.gridx = 0; c.gridy = 1; c.weightx = 0; c.weighty = 0; c.gridwidth = GridBagConstraints.REMAINDER; regexpPanel.add(errorMessage, c); // create replacement panel JPanel replacementPanel = new JPanel(new GridBagLayout()); replacementPanel.setBorder(createTitledBorder( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.replacement.border"))); JPanel testerPanel = new JPanel(new GridBagLayout()); c.insets = new Insets(4, 4, 4, 0); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; replacementPanel.add(replacementTextField, c); // create inline search panel JPanel inlineSearchPanel = new JPanel(new GridBagLayout()); c.insets = new Insets(8, 4, 4, 4); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; inlineSearchPanel.add( new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.inline_search.search")), c); c.insets = new Insets(0, 0, 0, 0); c.gridx = 0; c.gridy = 1; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; inlineSearchPanel.add(new JScrollPane(new JTextPane(inlineSearchDocument)), c); c.insets = new Insets(8, 4, 4, 4); c.gridx = 0; c.gridy = 2; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; inlineSearchPanel.add( new JLabel( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.inline_search.replaced")), c); c.insets = new Insets(0, 0, 0, 0); c.gridx = 0; c.gridy = 3; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; JTextPane replaceTextPane = new JTextPane(inlineReplaceDocument); replaceTextPane.setEditable(false); inlineSearchPanel.add(new JScrollPane(replaceTextPane), c); // create regexp options panel ItemListener defaultOptionListener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { fireRegexpOptionsChanged(); } }; cbCaseInsensitive = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.case_insensitive")); cbCaseInsensitive.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.case_insensitive.tip")); cbCaseInsensitive.addItemListener(defaultOptionListener); cbMultiline = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.multiline_mode")); cbMultiline.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.multiline_mode.tip")); cbMultiline.addItemListener(defaultOptionListener); cbDotall = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.dotall_mode")); cbDotall.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.dotall_mode.tip")); cbDotall.addItemListener(defaultOptionListener); cbUnicodeCase = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.unicode_case")); cbUnicodeCase.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.unicode_case.tip")); cbUnicodeCase.addItemListener(defaultOptionListener); JPanel regexpOptionsPanelWrapper = new JPanel(new BorderLayout()); JPanel regexpOptionsPanel = new JPanel(new GridBagLayout()); regexpOptionsPanelWrapper.add(regexpOptionsPanel, BorderLayout.NORTH); c.insets = new Insets(12, 4, 0, 4); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; regexpOptionsPanel.add(cbMultiline, c); c.insets = new Insets(8, 4, 0, 4); c.gridy = 1; regexpOptionsPanel.add(cbCaseInsensitive, c); c.gridy = 2; regexpOptionsPanel.add(cbUnicodeCase, c); c.gridy = 3; regexpOptionsPanel.add(cbDotall, c); // create tabbed panel c.insets = new Insets(8, 4, 4, 4); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.BOTH; testExp = new JTabbedPane(); testExp.add( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.inline_search.title"), new JScrollPane(inlineSearchPanel)); testExp.add( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.result_list.title"), new JScrollPane(regexpFindingsList)); testExp.add( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.regexp_options.title"), regexpOptionsPanelWrapper); testerPanel.add(testExp, c); JPanel groupPanel = new JPanel(new GridBagLayout()); c.insets = new Insets(4, 4, 4, 4); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; groupPanel.add(regexpPanel, c); c.insets = new Insets(4, 4, 4, 4); c.gridx = 0; c.gridy = 1; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; groupPanel.add(replacementPanel, c); c.insets = new Insets(4, 4, 4, 4); c.gridx = 0; c.gridy = 2; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; groupPanel.add(testerPanel, c); panel.add(groupPanel, 1, 0); if (supportsItems) { // item shortcuts list itemShortcutsList = new JList<String>(items.toArray(new String[items.size()])); itemShortcutsList.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.item_shortcuts.tip")); itemShortcutsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); itemShortcutsList.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { String text = regexpTextField.getText(); int cursorPosition = regexpTextField.getCaretPosition(); int index = itemShortcutsList.getSelectedIndex(); if (index > -1 && index < itemShortcutsList.getModel().getSize()) { String insertionString = itemShortcutsList.getModel().getElementAt(index).toString(); String newText = text.substring(0, cursorPosition) + insertionString + (cursorPosition < text.length() ? text.substring(cursorPosition) : ""); regexpTextField.setText(newText); regexpTextField.setCaretPosition(cursorPosition + insertionString.length()); regexpTextField.requestFocus(); fireRegularExpressionUpdated(); } } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); JScrollPane itemShortcutsPane = new JScrollPane(itemShortcutsList); itemShortcutsPane.setBorder(createTitledBorder( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.item_shortcuts.border"))); // matched items list matchedItemsListModel = new DefaultListModel<String>(); JList<String> matchedItemsList = new JList<String>(matchedItemsListModel); matchedItemsList.setToolTipText( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.matched_items.tip")); // add custom cell renderer to disallow selections matchedItemsList.setCellRenderer(new DefaultListCellRenderer() { private static final long serialVersionUID = -5795848004756768378L; @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return super.getListCellRendererComponent(list, value, index, false, false); } }); JScrollPane matchedItemsPanel = new JScrollPane(matchedItemsList); matchedItemsPanel.setBorder(createTitledBorder( I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.matched_items.border"))); // item panel on right side of dialog JPanel itemPanel = new JPanel(createGridLayout(1, 2)); itemPanel.add(itemShortcutsPane, 0, 0); itemPanel.add(matchedItemsPanel, 0, 1); panel.add(itemPanel, 0, 1); } okButton = makeOkButton("regexp_property_dialog_apply"); fireRegularExpressionUpdated(); layoutDefault(panel, supportsItems ? NORMAL : NARROW, okButton, makeCancelButton()); }
From source file:edu.ucla.stat.SOCR.chart.SuperPieChart.java
public void initMapPanel() { listIndex = new int[dataTable.getColumnCount()]; for (int j = 0; j < listIndex.length; j++) listIndex[j] = 1;//from w w w .j a v a 2 s. co m bPanel = new JPanel(new BorderLayout()); mapPanel = new JPanel(new GridLayout(2, 5, 50, 50)); bPanel.add(mapPanel, BorderLayout.CENTER); // bPanel.add(new JPanel(),BorderLayout.NORTH); addButton1.addActionListener(this); addButton2.addActionListener(this); addButton3.addActionListener(this); removeButton1.addActionListener(this); removeButton2.addActionListener(this); removeButton3.addActionListener(this); lModelAdded = new DefaultListModel(); lModelDep = new DefaultListModel(); lModelIndep = new DefaultListModel(); lModelPullout = new DefaultListModel(); int cellWidth = 10; listAdded = new JList(lModelAdded); listAdded.setSelectedIndex(0); listDepRemoved = new JList(lModelDep); listIndepRemoved = new JList(lModelIndep); listPulloutRemoved = new JList(lModelPullout); paintTable(listIndex); listAdded.setFixedCellWidth(cellWidth); listDepRemoved.setFixedCellWidth(cellWidth); listIndepRemoved.setFixedCellWidth(cellWidth); listPulloutRemoved.setFixedCellWidth(cellWidth); tools1 = new JToolBar(JToolBar.VERTICAL); tools2 = new JToolBar(JToolBar.VERTICAL); tools3 = new JToolBar(JToolBar.VERTICAL); if (mapDep) { tools1.add(depLabel); tools1.add(addButton1); tools1.add(removeButton1); } if (mapIndep) { tools2.add(indLabel); tools2.add(addButton2); tools2.add(removeButton2); } if (mapPullout) { tools3.add(pulloutLabel); tools3.add(addButton3); tools3.add(removeButton3); } tools1.setFloatable(false); tools2.setFloatable(false); tools3.setFloatable(false); /* topPanel.add(listAdded); topPanel.add(addButton); topPanel.add(listDepRemoved); bottomPanel.add(listIndepRemoved); bottomPanel.add(addButton2); bottomPanel.add(list4); */ JRadioButton legendPanelOnSwitch; JRadioButton legendPanelOffSwitch; // JPanel choicesPanel = new JPanel(); choicesPanel.setLayout(new BoxLayout(choicesPanel, BoxLayout.Y_AXIS)); legendPanelOnSwitch = new JRadioButton("On"); legendPanelOnSwitch.addActionListener(this); legendPanelOnSwitch.setActionCommand(LEGENDON); legendPanelOnSwitch.setSelected(false); legendPanelOn = false; legendPanelOffSwitch = new JRadioButton("Off"); legendPanelOffSwitch.addActionListener(this); legendPanelOffSwitch.setActionCommand(LEGENDOFF); legendPanelOffSwitch.setSelected(true); ButtonGroup group = new ButtonGroup(); group.add(legendPanelOnSwitch); group.add(legendPanelOffSwitch); choicesPanel.add(new JLabel("Turn the legend panel:")); choicesPanel.add(legendPanelOnSwitch); choicesPanel.add(legendPanelOffSwitch); choicesPanel.setPreferredSize(new Dimension(200, 100)); JRadioButton rotateOnSwitch; JRadioButton rotateOffSwitch; // JPanel rotateChoicesPanel = new JPanel(); rotateChoicesPanel.setLayout(new BoxLayout(rotateChoicesPanel, BoxLayout.Y_AXIS)); rotateOnSwitch = new JRadioButton("On"); rotateOnSwitch.addActionListener(this); rotateOnSwitch.setActionCommand(ROTATEON); rotateOnSwitch.setSelected(false); rotateOn = false; rotateOffSwitch = new JRadioButton("Off"); rotateOffSwitch.addActionListener(this); rotateOffSwitch.setActionCommand(ROTATEOFF); rotateOffSwitch.setSelected(true); ButtonGroup group2 = new ButtonGroup(); group2.add(rotateOnSwitch); group2.add(rotateOffSwitch); choicesPanel.add(new JLabel("Turn the rotator:")); choicesPanel.add(rotateOnSwitch); choicesPanel.add(rotateOffSwitch); choicesPanel.setPreferredSize(new Dimension(200, 100)); JPanel emptyPanel = new JPanel(); JPanel emptyPanel2 = new JPanel(); JPanel emptyPanel3 = new JPanel(); //2X5 //first line mapPanel.add(new JScrollPane(listAdded)); mapPanel.add(tools1); mapPanel.add(new JScrollPane(listDepRemoved)); mapPanel.add(tools3); if (mapPullout) mapPanel.add(new JScrollPane(listPulloutRemoved)); else mapPanel.add(emptyPanel); //second line-- mapPanel.add(choicesPanel); mapPanel.add(tools2); mapPanel.add(new JScrollPane(listIndepRemoved)); mapPanel.add(emptyPanel2); mapPanel.add(emptyPanel3); }
From source file:edu.ku.brc.specify.utilapps.RegisterApp.java
/** * @return//from w w w .j a va2s .com */ 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.ucla.stat.SOCR.chart.SuperXYChart_QQ.java
public void initMapPanel() { listIndex = new int[dataTable.getColumnCount()]; for (int j = 0; j < listIndex.length; j++) listIndex[j] = 1;//from w ww . j a v a 2 s. c o m bPanel = new JPanel(new BorderLayout()); mapPanel = new JPanel(new GridLayout(2, 3, 50, 50)); bPanel.add(mapPanel, BorderLayout.CENTER); addButton1.addActionListener(this); addButton2.addActionListener(this); removeButton1.addActionListener(this); removeButton2.addActionListener(this); lModelAdded = new DefaultListModel(); lModelDep = new DefaultListModel(); lModelIndep = new DefaultListModel(); int cellWidth = 10; listAdded = new JList(lModelAdded); listAdded.setSelectedIndex(0); listDepRemoved = new JList(lModelDep); listIndepRemoved = new JList(lModelIndep); paintMappingLists(listIndex); listAdded.setFixedCellWidth(cellWidth); listDepRemoved.setFixedCellWidth(cellWidth); listIndepRemoved.setFixedCellWidth(cellWidth); tools1 = new JToolBar(JToolBar.VERTICAL); tools2 = new JToolBar(JToolBar.VERTICAL); tools1.add(depLabel); // tools2.add(indLabel); tools1.setFloatable(false); tools2.setFloatable(false); tools1.add(addButton1); tools1.add(removeButton1); // tools2.add(addButton2); // tools2.add(removeButton2); JRadioButton disChoices_normal; JRadioButton disChoices_poisson; // JPanel choicesPanel = new JPanel(); disChoices_normal = new JRadioButton("Normal"); disChoices_normal.addActionListener(this); disChoices_normal.setActionCommand(NORMAL); disChoices_normal.setSelected(true); disChoice = NORMAL; disChoices_poisson = new JRadioButton("Poisson"); disChoices_poisson.addActionListener(this); disChoices_poisson.setActionCommand(POISSON); ButtonGroup group = new ButtonGroup(); group.add(disChoices_normal); group.add(disChoices_poisson); choicesPanel.add(new JLabel("Choices of distribution:")); choicesPanel.add(disChoices_normal); choicesPanel.add(disChoices_poisson); choicesPanel.setPreferredSize(new Dimension(200, 100)); mapPanel.add(new JScrollPane(listAdded)); mapPanel.add(tools1); mapPanel.add(new JScrollPane(listDepRemoved)); // JPanel emptyPanel = new JPanel(new GridLayout(0,1)); // mapPanel.add(emptyPanel); mapPanel.add(choicesPanel); mapPanel.add(tools2); mapPanel.add(new JScrollPane(listIndepRemoved)); }
From source file:Main_Window.java
public void Send_Receive_Data_Google_Service(boolean State) { try {// w w w . j a v a 2 s . c o m ServerAddress = new URL("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + Double.parseDouble(Latitude_TextField.getText()) + "," + Double.parseDouble(Longitude_TextField.getText()) + "&radius=" + Double.parseDouble(Radius_TextField.getText()) + "&opennow=" + Boolean.toString(State) + "&types=" + Categories.getSelectedItem().toString() + "&key=" + API_KEY); //DELTE String str = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=" + Double.parseDouble(Latitude_TextField.getText()) + "," + Double.parseDouble(Longitude_TextField.getText()) + "&radius=" + Double.parseDouble(Radius_TextField.getText()) + "&opennow=" + Boolean.toString(State) + "&types=" + Categories.getSelectedItem().toString() + "&key=" + API_KEY; System.out.println(" To url einai -> " + str); //set up out communications stuff Connection = null; //Set up the initial connection Connection = (HttpURLConnection) ServerAddress.openConnection(); Connection.setRequestMethod("GET"); Connection.setDoOutput(true); //Set the DoOutput flag to true if you intend to use the URL connection for output Connection.setDoInput(true); Connection.setRequestProperty("Content-type", "text/xml"); //Sets the general request property Connection.setAllowUserInteraction(false); Encode_String = URLEncoder.encode("test", "UTF-8"); Connection.setRequestProperty("Content-length", "" + Encode_String.length()); Connection.setReadTimeout(10000); // A non-zero value specifies the timeout when reading from Input stream when a connection is established to a resource. //If the timeout expires before there is data available for read, a java.net.SocketTimeoutException is raised. } catch (IOException IOE) { JOptionPane.showMessageDialog(null, "Error -> " + IOE.getLocalizedMessage(), "Exception - IOException", JOptionPane.ERROR_MESSAGE, null); } try { wr = new DataOutputStream(Connection.getOutputStream()); //open output stream to write } catch (IOException IOE) { JOptionPane.showMessageDialog(null, "Error -> " + IOE.getLocalizedMessage(), "Exception - IOException", JOptionPane.ERROR_MESSAGE, null); } try { wr.writeBytes("q=" + strData); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error -> " + ex.getLocalizedMessage(), "Exception - IOException", JOptionPane.ERROR_MESSAGE, null); } try { wr.flush(); //Force all data to write in channel } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error -> " + ex.getLocalizedMessage(), "Exception - IOException", JOptionPane.ERROR_MESSAGE, null); } try { //read the result from the server Buffered_Reader = new BufferedReader(new InputStreamReader(Connection.getInputStream())); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error -> " + ex.getLocalizedMessage(), "Exception - IOException", JOptionPane.ERROR_MESSAGE, null); } jsonParser = new JSONParser(); //JSON Parser try { JsonObject = (JSONObject) jsonParser.parse(Buffered_Reader); //Parse whole BuffererReader IN Object JSONArray Results_Array_Json = (JSONArray) JsonObject.get("results"); //take whole array - from json format //results - is as string unique that contains all the essential information such as arrays, and strings. So to extract all info we extract results into JSONarray //And this comes up due to json format for (int i = 0; i < Results_Array_Json.size(); i++) // Loop over each each part of array that contains info we must extract { JSONObject o = (JSONObject) Results_Array_Json.get(i); try { //We assume that for every POI exists for sure an address !!! thats why the code is not insida a try-catch Temp_Name = (String) o.get("name"); Temp_Address = (String) o.get("vicinity"); JSONObject Str_1 = (JSONObject) o.get("geometry"); //Geometry is object so extract geometry JSONArray Photo_1 = (JSONArray) o.get("photos"); JSONObject Photo_2 = (JSONObject) Photo_1.get(0); String Photo_Ref = (String) Photo_2.get("photo_reference"); JSONObject Str_2 = (JSONObject) Str_1.get("location"); Temp_X = (double) Str_2.get("lat"); Temp_Y = (double) Str_2.get("lng"); //In case some POI has no Rating try { //Inside try-catch block because may some POI has no rating Temp_Rating = (double) o.get("rating"); Point POI_Object = new Point(Temp_Name, Temp_Address, Photo_Ref, Temp_Rating, Temp_X, Temp_Y); POI_List.add(POI_Object); //Add POI in List to keep it } catch (Exception Er) { //JOptionPane.showMessageDialog ( null, "No rating for this POI " ) ; Point POI_Object_2 = new Point(Temp_Name, Temp_Address, Photo_Ref, 0.0, Temp_X, Temp_Y); POI_List.add(POI_Object_2); //Add POI in List to keep it } } catch (Exception E) { //JOptionPane.showMessageDialog ( this, "Error -> " + E.getLocalizedMessage ( ) + ", " + E.getMessage ( ) ) ; } o.clear(); } } catch (ParseException PE) { JOptionPane.showMessageDialog(this, "Error -> " + PE.getLocalizedMessage(), "Parse, inside while JSON ERROR", JOptionPane.ERROR_MESSAGE, null); } catch (IOException IOE) { JOptionPane.showMessageDialog(this, "Error -> " + IOE.getLocalizedMessage(), "IOExcpiton", JOptionPane.ERROR_MESSAGE, null); } if (POI_List.isEmpty()) { JOptionPane.showMessageDialog(this, "No Results"); } else { //Calculate Distance every POI from Longitude and latitude of User for (int k = 0; k < POI_List.size(); k++) { double D1 = Double.parseDouble(Latitude_TextField.getText()) - POI_List.get(k).Get_Distance_X(); double D2 = Double.parseDouble(Longitude_TextField.getText()) - POI_List.get(k).Get_Distance_Y(); double a = pow(sin(D1 / 2), 2) + cos(POI_List.get(k).Get_Distance_X()) * cos(Double.parseDouble(Latitude_TextField.getText())) * pow(sin(D2 / 2), 2); double c = 2 * atan2(sqrt(a), sqrt(1 - a)); double d = 70000 * c; // (where R is the radius of the Earth) in meters //add to list Distances_List.add(d); } //COPY array because Distances_List will be corrupted for (int g = 0; g < Distances_List.size(); g++) { Distances_List_2.add(Distances_List.get(g)); } for (int l = 0; l < Distances_List.size(); l++) { int Dou = Distances_List.indexOf(Collections.min(Distances_List)); //Take the min , but the result is the position that the min is been placed Number_Name N = new Number_Name(POI_List.get(Dou).Get_Name()); //Create an object with the name of POI in the min position in the POI_List Temp_List.add(N); Distances_List.set(Dou, 9999.99); //Make the number in the min position so large so be able to find the next min } String[] T = new String[Temp_List.size()]; //String array to holds all names of POIS that are going to be dispayled in ascending order //DISPLAY POI IN JLIST - Create String Array with Names in ascending order to create JList for (int h = 0; h < Temp_List.size(); h++) { T[h] = Temp_List.get(h).Get_Name(); } //System.out.println ( " Size T -> " + T.length ) ; //Make JList and put String names list = new JList(T); list.setForeground(Color.BLACK); list.setBackground(Color.GRAY); list.setBounds(550, 140, 400, 400); //list.setSelectionMode ( ListSelectionModel.SINGLE_SELECTION ) ; JScrollPane p = new JScrollPane(list); P.add(p); setContentPane(pane); //OK list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { String selected = list.getSelectedValue().toString(); System.out.println("Selected string" + selected); for (int n = 0; n < POI_List.size(); n++) { if (selected.equals(POI_List.get(n).Get_Name())) { try { //read the result from the server BufferedImage img = null; URL u = new URL( "https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=" + POI_List.get(n).Get_Photo_Ref() + "&key=" + API_KEY); Image image = ImageIO.read(u); IMAGE_LABEL.setText(""); IMAGE_LABEL.setIcon(new ImageIcon(image)); IMAGE_LABEL.setBounds(550, 310, 500, 200); //SOSOSOSOSOS pane.add(IMAGE_LABEL); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Error -> " + ex.getLocalizedMessage(), "Exception - IOException", JOptionPane.ERROR_MESSAGE, null); } Distance_L.setBounds(550, 460, 350, 150); Distance_L.setText(""); Distance_L.setText( "Distance from the current location: " + Distances_List_2.get(n) + "m"); pane.add(Distance_L); Address_L.setBounds(550, 500, 350, 150); Address_L.setText(""); Address_L.setText("Address: " + POI_List.get(n).Get_Address()); pane.add(Address_L); Rating_L.setBounds(550, 540, 350, 150); Rating_L.setText(""); Rating_L.setText("Rating: " + POI_List.get(n).Get_Rating()); pane.add(Rating_L); } } } }); } //Else not empty }
From source file:edu.ku.brc.specify.tools.StrLocalizerApp.java
/** * /* w w w . j av a 2s .c o m*/ */ private void createUI() { IconManager.setApplicationClass(Specify.class); IconManager.loadIcons(XMLHelper.getConfigDir("icons_datamodel.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_plugins.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_disciplines.xml")); //$NON-NLS-1$ System.setProperty("edu.ku.brc.ui.db.PickListDBAdapterFactory", //$NON-NLS-1$ "edu.ku.brc.specify.tools.StrLocPickListFactory"); // Needed By the Auto Cosmplete UI //$NON-NLS-1$ CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,10px,f:p:g", "p,4px,f:p:g,4px,p"), this); pb.addSeparator("Localize", cc.xyw(1, 1, 3)); termList = new JList(new ItemModel(srcFile)); newTermList = new JList(newKeyList); srcLbl = UIHelper.createTextArea(3, 40); srcLbl.setBorder(new LineBorder(srcLbl.getForeground())); textField = UIHelper.createTextField(40); textField.getDocument().addDocumentListener(new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { hasChanged = true; } }); statusBar = new JStatusBar(); statusBar.setSectionText(1, " "); //$NON-NLS-1$ //$NON-NLS-2$ UIRegistry.setStatusBar(statusBar); srcLbl.setEditable(false); rsController = new ResultSetController(null, false, false, false, "", 1, true); //transBtn = UIHelper.createButton(getResourceString("StrLocalizerApp.Translate")); PanelBuilder pbr = new PanelBuilder( new FormLayout("r:p,2px,f:p:g", "p, 4px, c:p,4px,p,4px,p,4px,p,4px,p,10px,p,2px,f:p:g")); pbr.add(UIHelper.createLabel(getResourceString("StrLocalizerApp.FileLbl")), cc.xy(1, 1)); fileLbl = UIHelper.createLabel(" "); pbr.add(fileLbl, cc.xy(3, 1)); pbr.add(UIHelper.createLabel("English:"), cc.xy(1, 3)); pbr.add(srcLbl, cc.xy(3, 3)); destLbl = UIHelper.createFormLabel(destLanguage.getEnglishName()); pbr.add(destLbl, cc.xy(1, 5)); pbr.add(textField, cc.xy(3, 5)); pbr.add(rsController.getPanel(), cc.xyw(1, 7, 3)); //pbr.add(transBtn, cc.xy(1, 9)); pbr.addSeparator("Searching", cc.xyw(1, 11, 3)); searchBtn = createButton(getResourceString("SEARCH")); searchBtn.setToolTipText(getResourceString("ExpressSearchTT")); searchText = new JAutoCompTextField(15, PickListDBAdapterFactory.getInstance().create("ExpressSearch", true)); searchText.setAskBeforeSave(false); searchBox = new SearchBox(searchText, null, true); searchText.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { fndKeyHash.clear(); results.clear(); String txt = searchText.getText(); if (!txt.isEmpty()) { doSearch(txt, "key"); doSearch(txt, "src"); doSearch(txt, "dst"); } model.fireChanges(); } } }); pbr.add(searchBox, cc.xyw(1, 13, 3)); model = new SearchResultsModel(); searchResultsTbl = new JTable(model); pbr.add(UIHelper.createScrollPane(searchResultsTbl), cc.xyw(1, 15, 3)); searchResultsTbl.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { //tableRowSelected(); if (results != null && results.size() > 0 && searchResultsTbl.getSelectedRow() > -1) { StrLocaleEntry entry = (StrLocaleEntry) results.get(searchResultsTbl.getSelectedRow()); if (entry != null) { int listIndex = srcFile.getInxForKey(entry.getKey()); termList.setSelectedIndex(listIndex); termList.ensureIndexIsVisible(listIndex); } } } }); PanelBuilder pbl = new PanelBuilder(new FormLayout("f:p:g", "f:p:g,10px,p,4px,f:p:g")); JScrollPane sp = UIHelper.createScrollPane(termList); JScrollPane nsp = UIHelper.createScrollPane(newTermList); pbl.add(sp, cc.xy(1, 1)); pbl.addSeparator("New Items", cc.xy(1, 3)); pbl.add(nsp, cc.xy(1, 5)); pb.add(pbl.getPanel(), cc.xy(1, 3)); pb.add(pbr.getPanel(), cc.xy(3, 3)); pb.add(statusBar, cc.xyw(1, 5, 3)); ResultSetController.setBackStopRS(rsController); pb.setDefaultDialogBorder(); mainPane = pb.getPanel(); termList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { listSelected(); } }); newTermList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { newListSelected(); } }); transBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String txt = srcLbl.getText(); String newText = translate(txt); if (StringUtils.isNotEmpty(newText)) { newText = newText.replace("'", "'"); textField.setText(newText); StrLocaleEntry entry = srcFile.getKey(termList.getSelectedIndex()); entry.setDstStr(textField.getText()); } } }); rscListener = new ResultSetControllerListener() { @Override public void newRecordAdded() { } @Override public void indexChanged(int newIndex) { termList.setSelectedIndex(newIndex); } @Override public boolean indexAboutToChange(int oldIndex, int newIndex) { return true; } }; rsController.addListener(rscListener); frame.pack(); }
From source file:com.vgi.mafscaling.LogView.java
private void createLogViewPanel() { logViewPanel = new JPanel(); GridBagLayout gbl_logViewPanel = new GridBagLayout(); gbl_logViewPanel.columnWidths = new int[] { 0 }; gbl_logViewPanel.rowHeights = new int[] { 0, 0 }; gbl_logViewPanel.columnWeights = new double[] { 1.0 }; gbl_logViewPanel.rowWeights = new double[] { 1.0, 0.0 }; logViewPanel.setLayout(gbl_logViewPanel); try {//from w w w . j av a 2 s . c om logDataTable = new DBTable(); logDataTable.copyColumnHeaderNames = true; logDataTable.defaultClickCountToStartEditor = 2; logDataTable.doNotUseDatabaseSort = true; logDataTable.listenKeyPressEventsWholeWindow = true; logDataTable.createControlPanel(DBTable.READ_NAVIGATION); logDataTable.enableExcelCopyPaste(); logDataTable.setSortEnabled(false); logDataTable.setSkin(new TableSkin()); logDataTable.refresh(new String[1][25]); logDataTable.setComparator(new DoubleComparator()); logDataTable.getTable().setCellSelectionEnabled(true); logDataTable.getTable().setColumnSelectionAllowed(true); logDataTable.getTable().setRowSelectionAllowed(true); logDataTable.getTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JTextField rowTextField = ((JTextField) logDataTable.getControlPanel().getComponent(3)); rowTextField.setPreferredSize(null); rowTextField.setColumns(5); GridBagConstraints gbc_logDataTable = new GridBagConstraints(); gbc_logDataTable.insets = insets0; gbc_logDataTable.anchor = GridBagConstraints.PAGE_START; gbc_logDataTable.fill = GridBagConstraints.BOTH; gbc_logDataTable.gridx = 0; gbc_logDataTable.gridy = 0; logViewPanel.add(logDataTable, gbc_logDataTable); listModel = new DefaultListModel<JLabel>(); selectionCombo.removeAllItems(); String name; JTableHeader tableHeader = logDataTable.getTableHeader(); for (int i = 0; i < logDataTable.getColumnCount(); ++i) { Column col = logDataTable.getColumn(i); col.setNullable(true); col.setHeaderRenderer(new CheckboxHeaderRenderer(i + 1, tableHeader)); name = col.getHeaderValue().toString(); selectionCombo.addItem(name); listModel.addElement(new JLabel(name, new CheckBoxIcon(), JLabel.LEFT)); } JList<JLabel> menuList = new JList<JLabel>(listModel); menuList.setOpaque(false); menuList.setCellRenderer(new ImageListCellRenderer()); menuList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); menuList.setLayoutOrientation(JList.VERTICAL); menuList.setFixedCellHeight(25); menuList.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { if (e.getClickCount() == 1 && colors.size() > 0) { JList<?> list = (JList<?>) e.getSource(); int index = list.locationToIndex(e.getPoint()); if (index >= 0) { int colIdx = logDataTable.getCurrentIndexForOriginalColumn(index); Column col = logDataTable.getColumn(colIdx); if (col.getHeaderRenderer() instanceof CheckboxHeaderRenderer) { CheckboxHeaderRenderer renderer = (CheckboxHeaderRenderer) col .getHeaderRenderer(); JLabel label = (JLabel) list.getModel().getElementAt(index); CheckBoxIcon checkIcon = (CheckBoxIcon) label.getIcon(); checkIcon.setChecked(!checkIcon.isChecked()); if (checkIcon.isChecked()) { checkIcon.setColor(colors.pop()); JTable table = logDataTable.getTable(); TableModel model = table.getModel(); addXYSeries(model, index, col.getHeaderValue().toString(), checkIcon.getColor()); } else { colors.push(checkIcon.getColor()); checkIcon.setColor(renderer.getDefaultColor()); removeXYSeries(index); } list.repaint(); } } } } catch (Exception ex) { ex.printStackTrace(); } } }); headerScrollPane = new JScrollPane(menuList); GridBagConstraints gbc_headersTree = new GridBagConstraints(); gbc_headersTree.insets = insets0; gbc_headersTree.anchor = GridBagConstraints.PAGE_START; gbc_headersTree.fill = GridBagConstraints.BOTH; gbc_headersTree.gridx = 0; gbc_headersTree.gridy = 1; logViewPanel.add(headerScrollPane, gbc_headersTree); headerScrollPane.setVisible(false); } catch (Exception e) { e.printStackTrace(); logger.error(e); } }
From source file:jboost.visualization.HistogramFrame.java
private JScrollPane getJScrollPane1() { if (jScrollPane1 == null) { jScrollPane1 = new JScrollPane(); jList1 = new JList(infoParser.iterNoList); jList1.setLayout(new FlowLayout()); jList1.setFocusable(false);//w w w. jav a 2 s. c o m jList1.setIgnoreRepaint(false); jList1.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { JList list = (JList) evt.getSource(); iter = list.getSelectedIndex(); loadIteration(iter); } } }); jScrollPane1.getViewport().add(jList1); } return jScrollPane1; }
From source file:edu.ku.brc.specify.extras.ViewToSchemaReview.java
/** * // w w w . j av a 2 s .c o m */ protected void fix(final CustomDialog parentDlg) { final Vector<String> fixedNames = new Vector<String>(); int fixCnt = 0; for (Object[] rowData : modelList) { boolean wasFixed = false; boolean isOnForm = (Boolean) rowData[3]; boolean isHidden = (Boolean) rowData[4]; if (!isOnForm && !isHidden) { rowData[4] = true; wasFixed = true; } else if (isOnForm && isHidden) { rowData[4] = false; wasFixed = true; } if (wasFixed) { fixCnt++; fixedNames.add(String.format("%s / %s", rowData[0], rowData[1])); } } viewModel.fireTableRowsUpdated(0, modelList.size() - 1); final int fixCount = fixCnt; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,4px,f:p:g")); CellConstraints cc = new CellConstraints(); JList list = new JList(fixedNames); pb.add(UIHelper.createLabel(String.format("%d items fixed.", fixCount)), cc.xy(1, 1)); pb.add(UIHelper.createScrollPane(list), cc.xy(1, 3)); pb.setDefaultDialogBorder(); CustomDialog dlg = new CustomDialog(parentDlg, "Fixed Items", true, CustomDialog.OK_BTN, pb.getPanel()); UIHelper.centerAndShow(dlg); } }); }
From source file:com.frostwire.gui.library.LibraryFilesTableMediator.java
/** * Creates a JList of files and sets and makes it non-selectable. *//* w ww . j a va 2s . c o m*/ private static JList<String> createFileList(List<String> fileNames) { JList<String> fileList = new JList<String>(fileNames.toArray(new String[0])); fileList.setVisibleRowCount(5); fileList.setCellRenderer(new FileNameListCellRenderer()); //fileList.setSelectionForeground(fileList.getForeground()); //fileList.setSelectionBackground(fileList.getBackground()); fileList.setFocusable(false); return fileList; }