List of usage examples for javax.swing BoxLayout LINE_AXIS
int LINE_AXIS
To view the source code for javax.swing BoxLayout LINE_AXIS.
Click Source Link
From source file:fungus.UtilizationChartFrame.java
public UtilizationChartFrame(String prefix) { simulationCycles = Configuration.getDouble(PAR_SIMULATION_CYCLES); this.setTitle("MycoNet Statistics Chart"); graph = JungGraphObserver.getGraph(); //data.add(-1,0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.setAutoWidth(false);/* w w w .ja va 2 s . co m*/ dataset.setIntervalWidth(simulationCycles); averageUtilizationData = new XYSeries("Average Utilization"); dataset.addSeries(averageUtilizationData); averageStableUtilizationData = new XYSeries("Avg Stable Util"); dataset.addSeries(averageStableUtilizationData); hyphaRatioData = new XYSeries("Hypha Ratio"); dataset.addSeries(hyphaRatioData); stableHyphaRatioData = new XYSeries("Stable Hypha Ratio"); dataset.addSeries(stableHyphaRatioData); //XYSeriesCollection dataset; JFreeChart utilizationChart = ChartFactory.createXYLineChart("Utilization Metrics", "Cycle", "Average Utilization", dataset, PlotOrientation.VERTICAL, true, false, false); ChartPanel utilizationChartPanel = new ChartPanel(utilizationChart); //chart.setBackgroundPaint(Color.white); //XYPlot plot = chart.getXYPlot(); // BufferedImage chartImage = chart.createBufferedImage(500,300); // chartLabel = new JLabel(); //chartLabel.setIcon(new ImageIcon(chartImage)); Container contentPane = getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); JPanel labelPane = new JPanel(); labelPane.setLayout(new GridLayout(1, 1)); //chartPane.setPreferredSize(new java.awt.Dimension(500, 300)); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); ////contentPane.add(labelPane,BorderLayout.PAGE_START); //contentPane.add(Box.createRigidArea(new Dimension(0,5))); contentPane.add(utilizationChartPanel, BorderLayout.CENTER); //contentPane.add(Box.createRigidArea(new Dimension(0,5))); ////contentPane.add(buttonPane, BorderLayout.PAGE_END); //data = node.getHyphaData(); //link = node.getHyphaLink(); //mycocast = node.getMycoCast(); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //chartPanel.add(chartLabel); /*JButton updateButton = new JButton("Refresh"); ActionListener updater = new ActionListener() { public void actionPerformed(ActionEvent e) { refreshData(); } }; updateButton.addActionListener(updater); JButton closeButton = new JButton("Close"); ActionListener closer = new ActionListener() { public void actionPerformed(ActionEvent e) { closeFrame(); } }; closeButton.addActionListener(closer); buttonPane.add(Box.createHorizontalGlue()); buttonPane.add(updateButton); buttonPane.add(Box.createRigidArea(new Dimension(5,0))); buttonPane.add(closeButton); refreshData(); */ //JungGraphObserver.addChangeListener(this); this.pack(); this.setVisible(true); }
From source file:TableSelectionDemo.java
public TableSelectionDemo() { super(new BorderLayout()); String[] columnNames = { "French", "Spanish", "Italian" }; String[][] tableData = { { "un", "uno", "uno" }, { "deux", "dos", "due" }, { "trois", "tres", "tre" }, { "quatre", "cuatro", "quattro" }, { "cinq", "cinco", "cinque" }, { "six", "seis", "sei" }, { "sept", "siete", "sette" } }; table = new JTable(tableData, columnNames); listSelectionModel = table.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); table.setSelectionModel(listSelectionModel); JScrollPane tablePane = new JScrollPane(table); // Build control area (use default FlowLayout). JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2);//from www . j a va 2 s.c o m comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newMode = (String) comboBox.getSelectedItem(); if (newMode.equals("SINGLE_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else { listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } output.append("----------" + "Mode: " + newMode + "----------" + newline); } }); controlPane.add(new JLabel("Selection mode:")); controlPane.add(comboBox); // Build output area. output = new JTextArea(1, 10); output.setEditable(false); JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); // Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); JPanel tableContainer = new JPanel(new GridLayout(1, 1)); tableContainer.setBorder(BorderFactory.createTitledBorder("Table")); tableContainer.add(tablePane); tablePane.setPreferredSize(new Dimension(420, 130)); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(250, 50)); topHalf.setPreferredSize(new Dimension(200, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.PAGE_START); bottomHalf.add(outputPane, BorderLayout.CENTER); // XXX: next line needed if bottomHalf is a scroll pane: // bottomHalf.setMinimumSize(new Dimension(400, 50)); bottomHalf.setPreferredSize(new Dimension(450, 110)); splitPane.add(bottomHalf); }
From source file:io.github.jeremgamer.editor.panels.Actions.java
public Actions(final JFrame frame, final ActionPanel ap) { this.frame = frame; this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;/*from w w w . j av a 2s . c o m*/ try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog(null, "Nommez l'action :", "Crer une action", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new ActionSave(name); OtherPanel.updateLists(); ButtonPanel.updateLists(); ActionPanel.updateLists(); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (actionList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/actions/" + actionList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog(null, "tes-vous sr de vouloir supprimer cette action?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { if (actionList.getSelectedValue().equals(ap.getFileName())) { ap.setFileName(""); } ap.hide(); file.delete(); data.remove(actionList.getSelectedIndex()); OtherPanel.updateLists(); ButtonPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); updateList(); actionList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { ap.show(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { ap.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { ap.hideThenShow(); previousSelection = list.getSelectedValue(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { ap.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { ap.show(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { ap.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { ap.hideThenShow(); previousSelection = list.getSelectedValue(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { ap.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(actionList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); OtherPanel.updateLists(); }
From source file:components.ConversionPanel.java
ConversionPanel(Converter myController, String myTitle, Unit[] myUnits, ConverterRangeModel myModel) { if (MULTICOLORED) { setOpaque(true);/* ww w .j a v a 2s.com*/ setBackground(new Color(0, 255, 255)); } setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(myTitle), BorderFactory.createEmptyBorder(5, 5, 5, 5))); //Save arguments in instance variables. controller = myController; units = myUnits; title = myTitle; sliderModel = myModel; //Create the text field format, and then the text field. numberFormat = NumberFormat.getNumberInstance(); numberFormat.setMaximumFractionDigits(2); NumberFormatter formatter = new NumberFormatter(numberFormat); formatter.setAllowsInvalid(false); formatter.setCommitsOnValidEdit(true);//seems to be a no-op -- //aha -- it changes the value property but doesn't cause the result to //be parsed (that happens on focus loss/return, I think). // textField = new JFormattedTextField(formatter); textField.setColumns(10); textField.setValue(new Double(sliderModel.getDoubleValue())); textField.addPropertyChangeListener(this); //Add the combo box. unitChooser = new JComboBox(); for (int i = 0; i < units.length; i++) { //Populate it. unitChooser.addItem(units[i].description); } unitChooser.setSelectedIndex(0); sliderModel.setMultiplier(units[0].multiplier); unitChooser.addActionListener(this); //Add the slider. slider = new JSlider(sliderModel); sliderModel.addChangeListener(this); //Make the text field/slider group a fixed size //to make stacked ConversionPanels nicely aligned. JPanel unitGroup = new JPanel() { public Dimension getMinimumSize() { return getPreferredSize(); } public Dimension getPreferredSize() { return new Dimension(150, super.getPreferredSize().height); } public Dimension getMaximumSize() { return getPreferredSize(); } }; unitGroup.setLayout(new BoxLayout(unitGroup, BoxLayout.PAGE_AXIS)); if (MULTICOLORED) { unitGroup.setOpaque(true); unitGroup.setBackground(new Color(0, 0, 255)); } unitGroup.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); unitGroup.add(textField); unitGroup.add(slider); //Create a subpanel so the combo box isn't too tall //and is sufficiently wide. JPanel chooserPanel = new JPanel(); chooserPanel.setLayout(new BoxLayout(chooserPanel, BoxLayout.PAGE_AXIS)); if (MULTICOLORED) { chooserPanel.setOpaque(true); chooserPanel.setBackground(new Color(255, 0, 255)); } chooserPanel.add(unitChooser); chooserPanel.add(Box.createHorizontalStrut(100)); //Put everything together. setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); add(unitGroup); add(chooserPanel); unitGroup.setAlignmentY(TOP_ALIGNMENT); chooserPanel.setAlignmentY(TOP_ALIGNMENT); }
From source file:fungus.PeerRatioChartFrame.java
public PeerRatioChartFrame(String prefix) { simulationCycles = Configuration.getDouble(PAR_SIMULATION_CYCLES); this.setTitle("MycoNet Statistics Chart"); graph = JungGraphObserver.getGraph(); //data.add(-1,0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.setAutoWidth(false);//from ww w. ja v a2 s . c o m dataset.setIntervalWidth(simulationCycles); //averageUtilizationData = new XYSeries("Average Utilization"); //dataset.addSeries(averageUtilizationData); //averageStableUtilizationData = new XYSeries("Avg Stable Util"); //dataset.addSeries(averageStableUtilizationData); bulwarkRatioData = new XYSeries("Bulwark Ratio"); dataset.addSeries(bulwarkRatioData); biomassRatioData = new XYSeries("Biomass Ratio"); dataset.addSeries(biomassRatioData); hyphaRatioData = new XYSeries("Hypha Ratio"); dataset.addSeries(hyphaRatioData); // stableHyphaRatioData = new XYSeries("Stable Hypha Ratio"); // dataset.addSeries(stableHyphaRatioData); //XYSeriesCollection dataset; JFreeChart peerRatioChart = ChartFactory.createXYLineChart("Bulwark Metrics", "Cycle", "Peer State Ratio", dataset, PlotOrientation.VERTICAL, true, false, false); ChartPanel peerRatioChartPanel = new ChartPanel(peerRatioChart); XYPlot xyplot = peerRatioChart.getXYPlot(); NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis(); NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis(); domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setRange(0, 1); //chart.setBackgroundPaint(Color.white); //XYPlot plot = chart.getXYPlot(); // BufferedImage chartImage = chart.createBufferedImage(500,300); // chartLabel = new JLabel(); //chartLabel.setIcon(new ImageIcon(chartImage)); Container contentPane = getContentPane(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS)); JPanel labelPane = new JPanel(); labelPane.setLayout(new GridLayout(1, 1)); //chartPane.setPreferredSize(new java.awt.Dimension(500, 300)); JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); ////contentPane.add(labelPane,BorderLayout.PAGE_START); //contentPane.add(Box.createRigidArea(new Dimension(0,5))); contentPane.add(peerRatioChartPanel, BorderLayout.CENTER); //contentPane.add(Box.createRigidArea(new Dimension(0,5))); ////contentPane.add(buttonPane, BorderLayout.PAGE_END); //data = node.getHyphaData(); //link = node.getHyphaLink(); //mycocast = node.getMycoCast(); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); //chartPanel.add(chartLabel); /*JButton updateButton = new JButton("Refresh"); ActionListener updater = new ActionListener() { public void actionPerformed(ActionEvent e) { refreshData(); } }; updateButton.addActionListener(updater); JButton closeButton = new JButton("Close"); ActionListener closer = new ActionListener() { public void actionPerformed(ActionEvent e) { closeFrame(); } }; closeButton.addActionListener(closer); buttonPane.add(Box.createHorizontalGlue()); buttonPane.add(updateButton); buttonPane.add(Box.createRigidArea(new Dimension(5,0))); buttonPane.add(closeButton); refreshData(); */ //JungGraphObserver.addChangeListener(this); this.pack(); this.setVisible(true); }
From source file:org.streamspinner.harmonica.application.CQGraphTerminal.java
private JPanel getJPanel2() { if (jPanel2 != null) return jPanel2; jPanel2 = new JPanel(); jPanel2.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); jPanel2.setLayout(new BoxLayout(jPanel2, BoxLayout.LINE_AXIS)); jPanel2.add(getJScrollPane1());//from ww w. jav a2 s .com jPanel2.setBackground(Color.RED); return jPanel2; }
From source file:io.github.jeremgamer.editor.panels.Panels.java
public Panels(final JFrame frame, final PanelsPanel pp) { this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;// ww w . ja v a2s. co m try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(panelList), "Nommez le panneau :", "Crer un panneau", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new PanelSave(name); PanelsPanel.updateLists(); mainPanel.addItem(name); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (panelList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/panels/" + panelList.getSelectedValue() + "/" + panelList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(panelList), "tes-vous sr de vouloir supprimer ce panneau?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { if (panelList.getSelectedValue().equals(pp.getFileName())) { pp.setFileName(""); } pp.hide(); file.delete(); File parent = new File(file.getParent()); for (File img : FileUtils.listFiles(parent, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { img.delete(); } parent.delete(); mainPanel.removeItem(panelList.getSelectedValue()); data.remove(panelList.getSelectedIndex()); ActionPanel.updateLists(); PanelsPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); mainPanel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @SuppressWarnings("unchecked") JComboBox<String> combo = (JComboBox<String>) event.getSource(); GeneralSave gs = new GeneralSave(); try { gs.load(new File("projects/" + Editor.getProjectName() + "/general.rbd")); gs.set("mainPanel", combo.getSelectedItem()); } catch (IOException e) { e.printStackTrace(); } } }); updateList(); panelList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); pp.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { pp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { pp.hideThenShow(); previousSelection = list.getSelectedValue(); pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); } } catch (NullPointerException npe) { pp.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); pp.show(); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { pp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { pp.hideThenShow(); previousSelection = list.getSelectedValue(); pp.load(new File("projects/" + Editor.getProjectName() + "/panels/" + list.getModel().getElementAt(index) + "/" + list.getModel().getElementAt(index) + ".rbd")); PanelsPanel.updateLists(); } } catch (NullPointerException npe) { pp.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(panelList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); JPanel mainPanelInput = new JPanel(); mainPanelInput.setPreferredSize(new Dimension(280, 35)); mainPanelInput.setMaximumSize(new Dimension(280, 35)); mainPanelInput.add(new JLabel("Panneau principal:")); mainPanel.setPreferredSize(new Dimension(150, 27)); mainPanelInput.add(mainPanel); this.add(mainPanelInput); }
From source file:io.github.jeremgamer.editor.panels.IconFrame.java
public IconFrame(JFrame parent) { this.setModal(true); this.setResizable(false); ArrayList<BufferedImage> icons = new ArrayList<BufferedImage>(); try {/* w w w .j av a 2 s . c o m*/ icons.add(ImageIO.read(ImageGetter.class.getResource("icon16.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon32.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon64.png"))); icons.add(ImageIO.read(ImageGetter.class.getResource("icon128.png"))); } catch (IOException e1) { e1.printStackTrace(); } this.setIconImages((List<? extends Image>) icons); this.setTitle("Icnes"); this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); JPanel content = new JPanel(); content.setLayout(new BoxLayout(content, BoxLayout.LINE_AXIS)); content.setBorder(BorderFactory.createTitledBorder("")); try { remove128.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); remove64.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); remove32.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); remove16.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } browse128.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "128.png"); try { x128.repaint(); x128.getGraphics().drawImage(ImageIO.read(new File(path)), 0 + 10, 0 + 20, 128, 128, null); } catch (IOException e) { e.printStackTrace(); } } } }); remove128.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File("projects/" + Editor.getProjectName() + "/128.png"); file.delete(); x128.repaint(); } }); browse64.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "64.png"); try { x64.repaint(); x64.getGraphics().drawImage(ImageIO.read(new File(path)), 32 + 10, 32 + 20, 64, 64, null); } catch (IOException e) { e.printStackTrace(); } } } }); remove64.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File("projects/" + Editor.getProjectName() + "/64.png"); file.delete(); x64.repaint(); } }); browse32.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "32.png"); try { x32.repaint(); x32.getGraphics().drawImage(ImageIO.read(new File(path)), 48 + 10, 48 + 20, 32, 32, null); } catch (IOException e) { e.printStackTrace(); } } } }); remove32.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File("projects/" + Editor.getProjectName() + "/32.png"); file.delete(); x32.repaint(); } }); browse16.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String path = null; JFileChooser chooser = new JFileChooser(Editor.lastPath); FileNameExtensionFilter filter = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "jpeg", "bmp"); chooser.setFileFilter(filter); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int option = chooser.showOpenDialog(null); if (option == JFileChooser.APPROVE_OPTION) { path = chooser.getSelectedFile().getAbsolutePath(); Editor.lastPath = chooser.getSelectedFile().getParent(); copyImage(new File(path), "16.png"); try { x16.repaint(); x16.getGraphics().drawImage(ImageIO.read(new File(path)), 56 + 10, 56 + 20, 16, 16, null); } catch (IOException e) { e.printStackTrace(); } } } }); remove16.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { File file = new File("projects/" + Editor.getProjectName() + "/16.png"); file.delete(); x16.repaint(); } }); content.add(x128); content.add(x64); content.add(x32); content.add(x16); this.setContentPane(content); this.pack(); this.setLocationRelativeTo(parent); this.setVisible(true); }
From source file:com.entertailion.java.fling.FlingFrame.java
public FlingFrame(String appId) { super();//from w w w . j a v a 2 s. c om this.appId = appId; rampClient = new RampClient(this); addWindowListener(this); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Locale locale = Locale.getDefault(); resourceBundle = ResourceBundle.getBundle("com/entertailion/java/fling/resources/resources", locale); setTitle(MessageFormat.format(resourceBundle.getString("fling.title"), Fling.VERSION)); JPanel listPane = new JPanel(); // show list of ChromeCast devices detected on the local network listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS)); JPanel devicePane = new JPanel(); devicePane.setLayout(new BoxLayout(devicePane, BoxLayout.LINE_AXIS)); deviceList = new JComboBox(); deviceList.addActionListener(this); devicePane.add(deviceList); URL url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/refresh.png"); ImageIcon icon = new ImageIcon(url, resourceBundle.getString("button.refresh")); refreshButton = new JButton(icon); refreshButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // refresh the list of devices if (deviceList.getItemCount() > 0) { deviceList.setSelectedIndex(0); } discoverDevices(); } }); refreshButton.setToolTipText(resourceBundle.getString("button.refresh")); devicePane.add(refreshButton); url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/settings.png"); icon = new ImageIcon(url, resourceBundle.getString("settings.title")); settingsButton = new JButton(icon); settingsButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JTextField transcodingExtensions = new JTextField(50); transcodingExtensions.setText(transcodingExtensionValues); JTextField transcodingParameters = new JTextField(50); transcodingParameters.setText(transcodingParameterValues); JPanel myPanel = new JPanel(new BorderLayout()); JPanel labelPanel = new JPanel(new GridLayout(3, 1)); JPanel fieldPanel = new JPanel(new GridLayout(3, 1)); myPanel.add(labelPanel, BorderLayout.WEST); myPanel.add(fieldPanel, BorderLayout.CENTER); labelPanel.add(new JLabel(resourceBundle.getString("transcoding.extensions"), JLabel.RIGHT)); fieldPanel.add(transcodingExtensions); labelPanel.add(new JLabel(resourceBundle.getString("transcoding.parameters"), JLabel.RIGHT)); fieldPanel.add(transcodingParameters); labelPanel.add(new JLabel(resourceBundle.getString("device.manual"), JLabel.RIGHT)); JPanel devicePanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); final JComboBox manualDeviceList = new JComboBox(); if (manualServers.size() == 0) { manualDeviceList.setVisible(false); } else { for (DialServer dialServer : manualServers) { manualDeviceList.addItem(dialServer); } } devicePanel.add(manualDeviceList); JButton addButton = new JButton(resourceBundle.getString("device.manual.add")); addButton.setToolTipText(resourceBundle.getString("device.manual.add.tooltip")); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JTextField name = new JTextField(); JTextField ipAddress = new JTextField(); Object[] message = { resourceBundle.getString("device.manual.name") + ":", name, resourceBundle.getString("device.manual.ipaddress") + ":", ipAddress }; int option = JOptionPane.showConfirmDialog(null, message, resourceBundle.getString("device.manual"), JOptionPane.OK_CANCEL_OPTION); if (option == JOptionPane.OK_OPTION) { try { manualServers.add( new DialServer(name.getText(), InetAddress.getByName(ipAddress.getText()))); Object selected = deviceList.getSelectedItem(); int selectedIndex = deviceList.getSelectedIndex(); deviceList.removeAllItems(); deviceList.addItem(resourceBundle.getString("devices.select")); for (DialServer dialServer : servers) { deviceList.addItem(dialServer); } for (DialServer dialServer : manualServers) { deviceList.addItem(dialServer); } deviceList.invalidate(); if (selectedIndex > 0) { deviceList.setSelectedItem(selected); } else { if (deviceList.getItemCount() == 2) { // Automatically select single device deviceList.setSelectedIndex(1); } } manualDeviceList.removeAllItems(); for (DialServer dialServer : manualServers) { manualDeviceList.addItem(dialServer); } manualDeviceList.setVisible(true); storeProperties(); } catch (UnknownHostException e1) { Log.e(LOG_TAG, "manual IP address", e1); JOptionPane.showMessageDialog(FlingFrame.this, resourceBundle.getString("device.manual.invalidip")); } } } }); devicePanel.add(addButton); JButton removeButton = new JButton(resourceBundle.getString("device.manual.remove")); removeButton.setToolTipText(resourceBundle.getString("device.manual.remove.tooltip")); removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object selected = manualDeviceList.getSelectedItem(); manualDeviceList.removeItem(selected); if (manualDeviceList.getItemCount() == 0) { manualDeviceList.setVisible(false); } deviceList.removeItem(selected); deviceList.invalidate(); manualServers.remove(selected); storeProperties(); } }); devicePanel.add(removeButton); fieldPanel.add(devicePanel); int result = JOptionPane.showConfirmDialog(FlingFrame.this, myPanel, resourceBundle.getString("settings.title"), JOptionPane.OK_CANCEL_OPTION); if (result == JOptionPane.OK_OPTION) { transcodingParameterValues = transcodingParameters.getText(); transcodingExtensionValues = transcodingExtensions.getText(); storeProperties(); } } }); settingsButton.setToolTipText(resourceBundle.getString("settings.title")); devicePane.add(settingsButton); listPane.add(devicePane); // TODO volume = new JSlider(JSlider.VERTICAL, 0, 100, 0); volume.setUI(new MySliderUI(volume)); volume.setMajorTickSpacing(25); // volume.setMinorTickSpacing(5); volume.setPaintTicks(true); volume.setEnabled(true); volume.setValue(100); volume.setToolTipText(resourceBundle.getString("volume.title")); volume.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (!source.getValueIsAdjusting()) { int position = (int) source.getValue(); rampClient.volume(position / 100.0f); } } }); JPanel centerPanel = new JPanel(new BorderLayout()); // centerPanel.add(volume, BorderLayout.WEST); centerPanel.add(DragHereIcon.makeUI(this), BorderLayout.CENTER); listPane.add(centerPanel); scrubber = new JSlider(JSlider.HORIZONTAL, 0, 100, 0); scrubber.addChangeListener(this); scrubber.setMajorTickSpacing(25); scrubber.setMinorTickSpacing(5); scrubber.setPaintTicks(true); scrubber.setEnabled(false); listPane.add(scrubber); // panel of playback buttons JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); label = new JLabel("00:00:00"); buttonPane.add(label); url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/play.png"); icon = new ImageIcon(url, resourceBundle.getString("button.play")); playButton = new JButton(icon); playButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { rampClient.play(); } }); buttonPane.add(playButton); url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/pause.png"); icon = new ImageIcon(url, resourceBundle.getString("button.pause")); pauseButton = new JButton(icon); pauseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { rampClient.pause(); } }); buttonPane.add(pauseButton); url = ClassLoader.getSystemResource("com/entertailion/java/fling/resources/stop.png"); icon = new ImageIcon(url, resourceBundle.getString("button.stop")); stopButton = new JButton(icon); stopButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { rampClient.stop(); setDuration(0); scrubber.setValue(0); scrubber.setEnabled(false); } }); buttonPane.add(stopButton); listPane.add(buttonPane); getContentPane().add(listPane); createProgressDialog(); startWebserver(); discoverDevices(); }
From source file:io.github.jeremgamer.editor.panels.Labels.java
public Labels(final JFrame frame, final LabelPanel lp, final PanelSave ps) { this.frame = frame; this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;/*from w w w .j a va 2s. c om*/ try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog((JFrame) SwingUtilities.windowForComponent(labelList), "Nommez le label :", "Crer un label", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new LabelSave(name); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (labelList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/labels/" + labelList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog((JFrame) SwingUtilities.windowForComponent(labelList), "tes-vous sr de vouloir supprimer ce label?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { File dir = new File("projects/" + Editor.getProjectName() + "/panels"); for (File f : FileUtils.listFilesAndDirs(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) { if (!f.isDirectory()) { try { ps.load(f); } catch (IOException e) { e.printStackTrace(); } for (String section : ps .getSectionsContaining(labelList.getSelectedValue() + " (Label)")) { ps.removeSection(section); try { ps.save(f); } catch (IOException e) { e.printStackTrace(); } } } } if (labelList.getSelectedValue().equals(lp.getFileName())) { lp.setFileName(""); } lp.hide(); file.delete(); data.remove(labelList.getSelectedIndex()); ActionPanel.updateLists(); OtherPanel.updateLists(); PanelsPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); updateList(); labelList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { lp.show(); lp.load(new File("projects/" + Editor.getProjectName() + "/labels/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { lp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { lp.hideThenShow(); previousSelection = list.getSelectedValue(); lp.load(new File("projects/" + Editor.getProjectName() + "/labels/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { lp.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { lp.show(); lp.load(new File("projects/" + Editor.getProjectName() + "/labels/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { lp.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { lp.hideThenShow(); previousSelection = list.getSelectedValue(); lp.load(new File("projects/" + Editor.getProjectName() + "/labels/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { lp.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(labelList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); }