List of usage examples for javax.swing JSeparator JSeparator
public JSeparator()
From source file:processing.app.Base.java
public void rebuildBoardsMenu() throws Exception { boardsCustomMenus = new LinkedList<>(); // The first custom menu is the "Board" selection submenu JMenu boardMenu = new JMenu(tr("Board")); boardMenu.putClientProperty("removeOnWindowDeactivation", true); MenuScroller.setScrollerFor(boardMenu).setTopFixedCount(1); boardMenu.add(new JMenuItem(new AbstractAction(tr("Boards Manager...")) { public void actionPerformed(ActionEvent actionevent) { String filterText = ""; String dropdownItem = ""; if (actionevent instanceof Event) { filterText = ((Event) actionevent).getPayload().get("filterText").toString(); dropdownItem = ((Event) actionevent).getPayload().get("dropdownItem").toString(); }/* w ww . ja v a2 s . c o m*/ try { openBoardsManager(filterText, dropdownItem); } catch (Exception e) { //TODO show error e.printStackTrace(); } } })); boardsCustomMenus.add(boardMenu); // If there are no platforms installed we are done if (BaseNoGui.packages.size() == 0) return; // Separate "Install boards..." command from installed boards boardMenu.add(new JSeparator()); // Generate custom menus for all platforms Set<String> customMenusTitles = new LinkedHashSet<>(); for (TargetPackage targetPackage : BaseNoGui.packages.values()) { for (TargetPlatform targetPlatform : targetPackage.platforms()) { customMenusTitles.addAll(targetPlatform.getCustomMenus().values()); } } for (String customMenuTitle : customMenusTitles) { JMenu customMenu = new JMenu(tr(customMenuTitle)); customMenu.putClientProperty("removeOnWindowDeactivation", true); boardsCustomMenus.add(customMenu); } List<JMenuItem> menuItemsToClickAfterStartup = new LinkedList<>(); ButtonGroup boardsButtonGroup = new ButtonGroup(); Map<String, ButtonGroup> buttonGroupsMap = new HashMap<>(); // Cycle through all packages boolean first = true; for (TargetPackage targetPackage : BaseNoGui.packages.values()) { // For every package cycle through all platform for (TargetPlatform targetPlatform : targetPackage.platforms()) { // Add a separator from the previous platform if (!first) boardMenu.add(new JSeparator()); first = false; // Add a title for each platform String platformLabel = targetPlatform.getPreferences().get("name"); if (platformLabel != null && !targetPlatform.getBoards().isEmpty()) { JMenuItem menuLabel = new JMenuItem(tr(platformLabel)); menuLabel.setEnabled(false); boardMenu.add(menuLabel); } // Cycle through all boards of this platform for (TargetBoard board : targetPlatform.getBoards().values()) { if (board.getPreferences().get("hide") != null) continue; JMenuItem item = createBoardMenusAndCustomMenus(boardsCustomMenus, menuItemsToClickAfterStartup, buttonGroupsMap, board, targetPlatform, targetPackage); boardMenu.add(item); boardsButtonGroup.add(item); } } } if (menuItemsToClickAfterStartup.isEmpty()) { menuItemsToClickAfterStartup.add(selectFirstEnabledMenuItem(boardMenu)); } for (JMenuItem menuItemToClick : menuItemsToClickAfterStartup) { menuItemToClick.setSelected(true); menuItemToClick.getAction().actionPerformed(new ActionEvent(this, -1, "")); } }
From source file:rita.ui.component.DialogSelectEnemies.java
/** * Initialize the contents of the frame. * /*from w w w .j ava 2 s.c om*/ * @throws NoEnemiesException */ private void initialize() throws NoEnemiesException { this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.getContentPane().setLayout(new BorderLayout(6, 6)); this.setTitle(Language.get("selectEnemies")); randomMode = new JCheckBox(Language.get("robotsBattleMode.random")); randomMode.setSelected(true); randomMode.addActionListener(new SelectUnselectPositionAction()); icon = new ImageIcon(DialogSelectEnemies.class.getResource("/images/icons/target.jpg")); JPanel panelRobots = new JPanel(); panelRobots.setBorder(new EmptyBorder(0, 12, 12, 0)); panelRobots.setLayout(new BorderLayout(0, 0)); JPanel panelSelectAllNone = new JPanel(); panelSelectAllNone.setBorder(new EmptyBorder(0, 12, 0, 12)); panelRobots.add(panelSelectAllNone, BorderLayout.EAST); this.getContentPane().add(panelRobots, BorderLayout.CENTER); GridBagLayout gbl_panelSelectAllNone = new GridBagLayout(); gbl_panelSelectAllNone.columnWidths = new int[] { 0, 0 }; gbl_panelSelectAllNone.rowHeights = new int[] { 0, 0, 8 }; gbl_panelSelectAllNone.columnWeights = new double[] { 0.0, Double.MIN_VALUE }; gbl_panelSelectAllNone.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE }; panelSelectAllNone.setLayout(gbl_panelSelectAllNone); JButton btnSelectAll = new JButton(Language.get("selectAllEnemies")); GridBagConstraints gbc_btnSelectAll = new GridBagConstraints(); gbc_btnSelectAll.fill = GridBagConstraints.HORIZONTAL; gbc_btnSelectAll.insets = new Insets(0, 0, 5, 0); gbc_btnSelectAll.gridx = 0; gbc_btnSelectAll.gridy = 0; panelSelectAllNone.add(btnSelectAll, gbc_btnSelectAll); JButton btnSelectNone = new JButton(Language.get("selectNoEnemies")); GridBagConstraints gbc_btnSelectNone = new GridBagConstraints(); gbc_btnSelectNone.fill = GridBagConstraints.HORIZONTAL; gbc_btnSelectNone.gridx = 0; gbc_btnSelectNone.gridy = 1; panelSelectAllNone.add(btnSelectNone, gbc_btnSelectNone); /* * btnInitialPositionsConfig = new * JButton(Language.get("selectRobotsInitialPositions")); * GridBagConstraints gbc_btnInitialPositionsConfig = new * GridBagConstraints(); gbc_btnSelectNone.fill = * GridBagConstraints.HORIZONTAL; gbc_btnSelectNone.gridx = 0; * gbc_btnSelectNone.gridy = 1; * panelSelectAllNone.add(btnInitialPositionsConfig, * gbc_btnInitialPositionsConfig); * btnInitialPositionsConfig.addActionListener(new ActionListener() { * public void actionPerformed(ActionEvent evt) { * selectRobotsInitialPositions(); } }); */ JLabel label = new JLabel(String.format(Language.get("youtRobotAgainst"), HelperEditor.currentRobotName)); label.setBorder(new EmptyBorder(12, 12, 0, 12)); label.setIcon(new ImageIcon(DialogSelectEnemies.class.getResource("/images/icons/compite2.png"))); label.setVerticalAlignment(SwingConstants.TOP); label.setFont(label.getFont().deriveFont(Font.BOLD, 14)); panelSelectRobots = new JPanel(); panelSelectRobots.setLayout(new GridLayout(0, 2)); panelSelectRobots.setAutoscrolls(true); panelRobots.add(label, BorderLayout.NORTH); panelRobots.add(panelSelectRobots, BorderLayout.CENTER); // posicion de mi robot JPanel panelSetMyRobotPosition = new JPanel(); // panelRobots.add(panelSetMyRobotPosition, BorderLayout.PAGE_END); panelSetMyRobotPosition.setLayout(new FlowLayout()); JLabel ownPosition = new JLabel(Language.get("myRobotPosition") + " " + HelperEditor.currentRobotName); ownPosition.setFont(new Font("sansserif", Font.BOLD, 12)); panelSetMyRobotPosition.add(ownPosition); // Posicion de mi robot buttonPos = new JButton(icon); buttonPos.addActionListener(new PosicionRobotAction(HelperEditor.currentRobotName)); // el nombre aqui es solo a // modo informativo buttonPos.setPreferredSize(new Dimension(30, 30)); panelSetMyRobotPosition.add(buttonPos); positionComponents.add(buttonPos); // Matas JPanel panelSelectRoundsNumber = new JPanel(); // panelRobots.add(panelSelectRoundsNumber, BorderLayout.SOUTH); panelSelectRoundsNumber.setLayout(new FlowLayout()); panelSelectRoundsNumber.add(new JLabel(Language.get("selectRoundsNumber"))); // this.roundsNumberTextField = new JTextField( // Integer.toString(Batalla.NUMBER_OF_ROUNDS), 5); this.roundsNumberSpinner = new JSpinner(new SpinnerNumberModel(Batalla.NUMBER_OF_ROUNDS, Batalla.MIN_NUMBER_OF_ROUNDS, Batalla.MAX_NUMBER_OF_ROUNDS, 1)); panelSelectRoundsNumber.add(this.roundsNumberSpinner); JPanel panelSouth = new JPanel(); panelSouth.setLayout(new GridLayout(4, 1)); panelSouth.add(panelSetMyRobotPosition); //this.getContentPane().add(randomMode, BorderLayout.SOUTH); panelSouth.add(randomMode); panelSouth.add(new JSeparator()); panelSouth.add(panelSelectRoundsNumber); panelRobots.add(panelSouth, BorderLayout.SOUTH); JPanel panelOkCancel = new JPanel(); this.getContentPane().add(panelOkCancel, BorderLayout.SOUTH); panelOkCancel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 12)); btnOK = new JButton(Language.get("selectStartBattle")); btnOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { startBattle(panelSelectRobots); } }); // comienza deshabilitado hasta que se seleccione 1 enemigo // btnOK.setEnabled(false); panelOkCancel.add(btnOK); JButton btnCancel = new JButton(Language.get("cancel")); btnCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { closeDialog(); } }); panelOkCancel.add(btnCancel); btnSelectAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { selectChecks(panelSelectRobots, true); // btnOK.setEnabled(true); } }); btnSelectNone.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { selectChecks(panelSelectRobots, false); // btnOK.setEnabled(false); } }); // TODO Agregar funcionalidad de elegir las posiciones iniciales de los // robots. // TODO Averiguar como pasar las posiciones para que se elijan de manera // random, probar (0,0,0) try { robotNameClicked = new RobotNameClickedEvent(btnOK); addRobotsToPanel(panelSelectRobots); this.setResizable(false); this.pack(); PositionCalc.centerDialog(this); enablePositionOptions(false); this.setVisible(true); } catch (FileNotFoundException e) { throw new NoEnemiesException(e.getMessage()); } }
From source file:savant.controller.RecentTracksController.java
private void updateMenuList() { menu.removeAll();/*from w w w .java2 s . co m*/ for (final String s : queue) { JMenuItem item = new JMenuItem(); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { FrameController.getInstance().addTrackFromPath(s, null, null); } catch (Exception ex) { LOG.error("Unable to open file.", ex); DialogUtils.displayError("Problem opening track from file " + s); } } }); item.setText(s); menu.add(item); } menu.add(new JSeparator()); JMenuItem item = new JMenuItem(); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { RecentTracksController.getInstance().clearRecents(); } catch (Exception ex) { } } }); item.setText("Clear Recents"); menu.add(item); }
From source file:savant.selection.VariantPopup.java
@Override protected void initInfo() { if (record instanceof LDRecord) { LDRecord ldRec = (LDRecord) record; float dPrime = ldRec.getDPrime(); if (!Float.isNaN(dPrime)) { add(new JLabel(String.format("D\u2032: %.2f", dPrime))); }//from ww w . ja v a2 s .c o m add(new JLabel(String.format("r\u00B2: %.2f", ldRec.getRSquared()))); List<VariantRecord> varRecs = ldRec.getConstituents(); VariantRecord varRec0 = varRecs.get(0); VariantRecord varRec1 = varRecs.get(1); add(new JSeparator()); initVariantRecord(varRec0, null); add(new JSeparator()); initVariantRecord(varRec1, null); name = VariationController.getDisplayName(varRec0) + " vs. " + VariationController.getDisplayName(varRec1); start = Math.min(varRec0.getPosition(), varRec1.getPosition()); end = Math.max(varRec0.getPosition(), varRec1.getPosition()); } else { VariantRecord varRec; ParticipantRecord partRec = null; if (record instanceof VariantRecord) { varRec = (VariantRecord) record; } else { partRec = (ParticipantRecord) record; varRec = partRec.getVariantRecord(); } name = varRec.getName(); start = end = varRec.getPosition(); initVariantRecord(varRec, partRec); } }
From source file:savant.selection.VariantPopup.java
private void initVariantRecord(VariantRecord varRec, ParticipantRecord partRec) { if (varRec.getName() != null) { add(new JLabel("Variant Name: " + varRec.getName())); }//from w w w .ja v a2 s . c o m add(new JLabel("Type: " + varRec.getVariantType().getDescription())); add(new JLabel("Position: " + varRec.getPosition())); add(new PopupLabel("Reference: " + varRec.getRefBases())); if (partRec == null) { add(new PopupLabel("Alt: " + StringUtils.join(varRec.getAltAlleles(), ','))); } else { add(new JSeparator()); add(new JLabel("Participant: " + partRec.getName())); add(new PopupLabel("Alleles: " + StringUtils.join(partRec.getAlleles(), ','))); } }
From source file:savant.view.swing.FrameCommandBar.java
/** * Create Tools menu for commandBar. This is common to all track types. *//*w w w . j a va 2 s .c o m*/ private JMenu createToolsMenu() { JMenu menu = new JMenu("Tools"); JMenuItem item = new JCheckBoxMenuItem("Lock X Axis"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { graphPane.setLocked(!graphPane.isLocked()); } }); menu.add(item); // TODO: experimental feature which doesn't quite work yet final JMenuItem itemy = new JCheckBoxMenuItem("Lock Y Axis"); itemy.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Trying to locking Y max: " + !itemy.isSelected()); graphPane.setYMaxLocked(itemy.isSelected()); } }); //menu.add(itemy); item = new JMenuItem("Copy URL to Clipboard"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Toolkit.getDefaultToolkit().getSystemClipboard() .setContents(new StringSelection(mainTrack.getDataSource().getURI().toString()), null); } }); menu.add(item); DataFormat df = mainTrack.getDataFormat(); if (df == DataFormat.SEQUENCE) { menu.add(new JSeparator()); JMenuItem copyItem = new JMenuItem("Copy Sequence to Clipboard"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { try { LocationController lc = LocationController.getInstance(); byte[] seq = ((SequenceTrack) mainTrack).getSequence(lc.getReferenceName(), lc.getRange()); Toolkit.getDefaultToolkit().getSystemClipboard() .setContents(new StringSelection(new String(seq)), null); } catch (Throwable x) { LOG.error(x); DialogUtils.displayError("Unable to copy sequence to clipboard."); } } }); menu.add(copyItem); setAsGenomeButton = new JCheckBoxMenuItem("Set as Genome"); setAsGenomeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Genome newGenome = Genome.createFromTrack(mainTrack); GenomeController.getInstance().setGenome(newGenome); } }); menu.add(setAsGenomeButton); menu.addMenuListener(new MenuAdapter() { @Override public void menuSelected(MenuEvent me) { Track seqTrack = (Track) GenomeController.getInstance().getGenome().getSequenceTrack(); if (seqTrack == mainTrack) { setAsGenomeButton.setSelected(true); setAsGenomeButton.setEnabled(false); setAsGenomeButton.setToolTipText("This track is already the reference sequence"); } else { setAsGenomeButton.setSelected(false); setAsGenomeButton.setEnabled(true); setAsGenomeButton.setToolTipText("Use this track as the reference sequence"); } } }); } else if (df == DataFormat.ALIGNMENT) { menu.add(new JSeparator()); item = new JMenuItem("Filter..."); item.setToolTipText("Control how records are filtered"); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new BAMFilterDialog(DialogUtils.getMainWindow(), (BAMTrack) mainTrack).setVisible(true); } }); menu.add(item); } else if (df == DataFormat.RICH_INTERVAL) { menu.add(new JSeparator()); final JMenuItem bookmarkAll = new JMenuItem("Bookmark All Features"); bookmarkAll.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { DataSource ds = (DataSource) mainTrack.getDataSource(); if (DialogUtils.askYesNo("Bookmark All Features ", String.format("This will create %d bookmarks. Are you sure you want to do this?", ds.getDictionaryCount())) == DialogUtils.YES) { ds.addDictionaryToBookmarks(); Savant.getInstance().displayBookmarksPanel(); } } }); menu.add(bookmarkAll); menu.addMenuListener(new MenuAdapter() { @Override public void menuSelected(MenuEvent me) { bookmarkAll.setEnabled(mainTrack.getDataSource() instanceof DataSource && ((DataSource) mainTrack.getDataSource()).getDictionaryCount() > 0); } }); } return menu; }
From source file:savant.view.swing.FrameCommandBar.java
private JMenu createAppearanceMenu() { JMenu menu = new JMenu("Appearance"); JMenuItem item = new JMenuItem("Colour Settings..."); item.addActionListener(new ActionListener() { @Override/* www . j av a2 s .c om*/ public void actionPerformed(ActionEvent e) { SettingsDialog dlg = new SettingsDialog(DialogUtils.getMainWindow(), "Colour Settings", new TrackColourSchemePanel(mainTrack)); dlg.setVisible(true); } }); menu.add(item); DataFormat df = mainTrack.getDataFormat(); if (df != DataFormat.SEQUENCE) { scaleToFitItem = new JCheckBoxMenuItem("Scale to Fit"); scaleToFitItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { if (scaleToFitItem.isSelected()) { graphPane.setScaledToFit(true); } else { // This check is kinda ugly, but we only want to set the interval height from the slider // if we're showing intervals (i.e. not arc mode and not coverage). if (intervalSlider != null && mainTrack.getDrawingMode() != DrawingMode.ARC && mainTrack.getDrawingMode() != DrawingMode.ARC_PAIRED && mainTrack.getResolution( LocationController.getInstance().getRange()) == Resolution.HIGH) { int h = getIntervalHeight(); graphPane.setUnitHeight(h); } graphPane.setScaledToFit(false); } } }); scaleToFitItem .setToolTipText("If selected, the track's display will be scaled to fit the available height."); menu.addMenuListener(new MenuAdapter() { @Override public void menuSelected(MenuEvent me) { scaleToFitItem.setSelected(graphPane.isScaledToFit()); } }); menu.add(scaleToFitItem); } if (df == DataFormat.RICH_INTERVAL) { menu.add(new JSeparator()); JCheckBoxMenuItem itemRGB = new JCheckBoxMenuItem("Enable ItemRGB"); itemRGB.setState(false); itemRGB.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ((RichIntervalTrack) mainTrack).toggleItemRGBEnabled(); graphPane.setRenderForced(); graphPane.repaint(); } }); menu.add(itemRGB); JCheckBoxMenuItem score = new JCheckBoxMenuItem("Enable Score"); score.setState(false); score.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ((RichIntervalTrack) mainTrack).toggleScoreEnabled(); graphPane.setRenderForced(); graphPane.repaint(); } }); menu.add(score); JCheckBoxMenuItem alternate = new JCheckBoxMenuItem("Display Alternate Name"); alternate.setState(((RichIntervalTrack) mainTrack).isUsingAlternateName()); alternate.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ((RichIntervalTrack) mainTrack).toggleAlternateName(); graphPane.setRenderForced(); graphPane.repaint(); } }); menu.add(alternate); } else if (df == DataFormat.ALIGNMENT) { menu.add(new JSeparator()); baseQualityItem = new JCheckBoxMenuItem("Enable Base Quality"); baseQualityItem.setState(false); baseQualityItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (((BAMTrack) mainTrack).toggleBaseQualityEnabled()) { mappingQualityItem.setState(false); } graphPane.setRenderForced(); graphPane.repaint(); } }); menu.add(baseQualityItem); mappingQualityItem = new JCheckBoxMenuItem("Enable Mapping Quality"); mappingQualityItem.setState(false); mappingQualityItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (((BAMTrack) mainTrack).toggleMappingQualityEnabled()) { baseQualityItem.setState(false); } graphPane.setRenderForced(); graphPane.repaint(); } }); menu.add(mappingQualityItem); } return menu; }
From source file:se.llbit.chunky.renderer.ui.RenderControls.java
private JPanel buildAdvancedPane() { rayDepth.update();/*from ww w. ja v a 2 s . com*/ JSeparator sep1 = new JSeparator(); JSeparator sep2 = new JSeparator(); numThreads.update(); cpuLoad.update(); mergeDumpBtn.setToolTipText("Merge an existing render dump with the current render"); mergeDumpBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { CenteredFileDialog fileDialog = new CenteredFileDialog(null, "Select Render Dump", FileDialog.LOAD); fileDialog.setFilenameFilter(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".dump"); } }); fileDialog.setDirectory(PersistentSettings.getSceneDirectory().getAbsolutePath()); fileDialog.setVisible(true); File selectedFile = fileDialog.getSelectedFile(); if (selectedFile != null) { sceneMan.mergeRenderDump(selectedFile); } } }); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setHorizontalGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup().addGroup(numThreads.horizontalGroup(layout)) .addGroup(cpuLoad.horizontalGroup(layout)).addComponent(sep1) .addGroup(rayDepth.horizontalGroup(layout)).addComponent(sep2).addComponent(mergeDumpBtn) .addComponent(shutdownWhenDoneCB)) .addContainerGap()); layout.setVerticalGroup(layout.createSequentialGroup().addContainerGap() .addGroup(numThreads.verticalGroup(layout)).addPreferredGap(ComponentPlacement.RELATED) .addGroup(cpuLoad.verticalGroup(layout)).addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(sep1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED).addGroup(rayDepth.verticalGroup(layout)) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(sep2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(mergeDumpBtn) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(shutdownWhenDoneCB).addContainerGap()); return panel; }
From source file:se.llbit.chunky.renderer.ui.RenderControls.java
private JPanel buildGeneralPane() { JLabel canvasSizeLbl = new JLabel("Canvas size:"); JLabel canvasSizeAdvisory = new JLabel("Note: Actual image size may not be the same as the window size!"); canvasSizeCB.setEditable(true);/*www. j a va 2s.c om*/ canvasSizeCB.addItem("400x400"); canvasSizeCB.addItem("1024x768"); canvasSizeCB.addItem("960x540"); canvasSizeCB.addItem("1920x1080"); canvasSizeCB.addActionListener(canvasSizeListener); final JTextField canvasSizeEditor = (JTextField) canvasSizeCB.getEditor().getEditorComponent(); canvasSizeEditor.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { } @Override public void focusGained(FocusEvent e) { canvasSizeEditor.selectAll(); } }); updateCanvasSizeField(); loadSceneBtn.setText("Load Scene"); loadSceneBtn.setIcon(Icon.load.imageIcon()); loadSceneBtn.addActionListener(loadSceneListener); JButton loadSelectedChunksBtn = new JButton("Load Selected Chunks"); loadSelectedChunksBtn.setToolTipText("Load the chunks that are currently selected in the map view"); loadSelectedChunksBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { sceneMan.loadChunks(chunky.getWorld(), chunky.getSelectedChunks()); } }); JButton reloadChunksBtn = new JButton("Reload Chunks"); reloadChunksBtn.setIcon(Icon.reload.imageIcon()); reloadChunksBtn.setToolTipText("Reload all chunks in the scene"); reloadChunksBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { sceneMan.reloadChunks(); } }); openSceneDirBtn.setText("Open Scene Directory"); openSceneDirBtn.setToolTipText("Open the directory where Chunky stores scene descriptions and renders"); openSceneDirBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { try { if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(context.getSceneDirectory()); } } catch (IOException e) { Log.warn("Failed to open scene directory", e); } } }); openSceneDirBtn.setVisible(Desktop.isDesktopSupported()); loadSceneBtn.setToolTipText("This replaces the current scene!"); JButton setCanvasSizeBtn = new JButton("Apply"); setCanvasSizeBtn.setToolTipText("Set the canvas size to the value in the field"); setCanvasSizeBtn.addActionListener(canvasSizeListener); JButton halveCanvasSizeBtn = new JButton("Halve"); halveCanvasSizeBtn.setToolTipText("Halve the canvas width and height"); halveCanvasSizeBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int width = renderMan.scene().canvasWidth() / 2; int height = renderMan.scene().canvasHeight() / 2; setCanvasSize(width, height); } }); JButton doubleCanvasSizeBtn = new JButton("Double"); doubleCanvasSizeBtn.setToolTipText("Double the canvas width and height"); doubleCanvasSizeBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int width = renderMan.scene().canvasWidth() * 2; int height = renderMan.scene().canvasHeight() * 2; setCanvasSize(width, height); } }); JButton makeDefaultBtn = new JButton("Make Default"); makeDefaultBtn.setToolTipText("Make the current canvas size the default"); makeDefaultBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { PersistentSettings.set3DCanvasSize(renderMan.scene().canvasWidth(), renderMan.scene().canvasHeight()); } }); JSeparator sep1 = new JSeparator(); JSeparator sep2 = new JSeparator(); biomeColorsCB.setText("enable biome colors"); updateBiomeColorsCB(); saveDumpsCB.setText("save dump once every "); saveDumpsCB.addActionListener(saveDumpsListener); updateSaveDumpsCheckBox(); String[] frequencyStrings = new String[dumpFrequencies.length]; for (int i = 0; i < dumpFrequencies.length; ++i) { frequencyStrings[i] = Integer.toString(dumpFrequencies[i]); } dumpFrequencyCB.setModel(new DefaultComboBoxModel(frequencyStrings)); dumpFrequencyCB.setEditable(true); dumpFrequencyCB.addActionListener(dumpFrequencyListener); updateDumpFrequencyField(); saveSnapshotsCB.addActionListener(saveSnapshotListener); updateSaveSnapshotCheckBox(); yCutoff.update(); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setHorizontalGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup() .addGroup(layout.createSequentialGroup().addComponent(loadSceneBtn) .addPreferredGap(ComponentPlacement.RELATED).addComponent(openSceneDirBtn)) .addGroup(layout.createSequentialGroup().addComponent(loadSelectedChunksBtn) .addPreferredGap(ComponentPlacement.RELATED).addComponent(reloadChunksBtn)) .addComponent(sep1) .addGroup(layout.createSequentialGroup().addComponent(canvasSizeLbl) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(canvasSizeCB, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED).addComponent(setCanvasSizeBtn) .addPreferredGap(ComponentPlacement.RELATED).addComponent(makeDefaultBtn)) .addGroup(layout.createSequentialGroup().addComponent(halveCanvasSizeBtn) .addPreferredGap(ComponentPlacement.RELATED).addComponent(doubleCanvasSizeBtn)) .addComponent(canvasSizeAdvisory).addComponent(sep2).addComponent(biomeColorsCB) .addGroup(layout.createSequentialGroup().addComponent(saveDumpsCB) .addComponent(dumpFrequencyCB, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(dumpFrequencyLbl).addGap(0, 0, Short.MAX_VALUE)) .addComponent(saveSnapshotsCB).addGroup(yCutoff.horizontalGroup(layout))) .addContainerGap()); layout.setVerticalGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup().addComponent(loadSceneBtn).addComponent(openSceneDirBtn)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout .createParallelGroup().addComponent(loadSelectedChunksBtn).addComponent(reloadChunksBtn)) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent( sep1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(canvasSizeLbl) .addComponent(canvasSizeCB, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(setCanvasSizeBtn).addComponent(makeDefaultBtn)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup().addComponent(halveCanvasSizeBtn) .addComponent(doubleCanvasSizeBtn)) .addPreferredGap(ComponentPlacement.RELATED).addComponent(canvasSizeAdvisory) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent(sep2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(biomeColorsCB) .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(saveDumpsCB) .addComponent(dumpFrequencyCB).addComponent(dumpFrequencyLbl)) .addComponent(saveSnapshotsCB).addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(yCutoff.verticalGroup(layout)).addContainerGap()); return panel; }
From source file:se.llbit.chunky.renderer.ui.RenderControls.java
private JPanel buildCameraPane() { JLabel projectionModeLbl = new JLabel("Projection"); fov.update();/*from ww w.ja v a2 s.c om*/ dof = new DoFAdjuster(renderMan); dof.update(); subjectDistance.update(); JLabel presetLbl = new JLabel("Preset:"); CameraPreset[] presets = { CameraPreset.NONE, CameraPreset.ISO_WEST_NORTH, CameraPreset.ISO_NORTH_EAST, CameraPreset.ISO_EAST_SOUTH, CameraPreset.ISO_SOUTH_WEST, CameraPreset.SKYBOX_RIGHT, CameraPreset.SKYBOX_LEFT, CameraPreset.SKYBOX_UP, CameraPreset.SKYBOX_DOWN, CameraPreset.SKYBOX_FRONT, CameraPreset.SKYBOX_BACK, }; cameraPreset.setModel(new DefaultComboBoxModel(presets)); cameraPreset.setMaximumRowCount(presets.length); final int presetHeight = cameraPreset.getPreferredSize().height; final int presetWidth = cameraPreset.getPreferredSize().width; cameraPreset.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); label.setPreferredSize(new Dimension(presetWidth, presetHeight)); CameraPreset preset = (CameraPreset) value; label.setIcon(preset.getIcon()); return label; } }); cameraPreset.addActionListener(cameraPresetListener); JLabel customPresetLbl = new JLabel("Custom preset:"); customPreset.setEditable(true); updateCustomPresets(); JButton savePreset = new JButton("save"); savePreset.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String name = ""; int selected = customPreset.getSelectedIndex(); if (selected == -1) { // select name name = (String) customPreset.getEditor().getItem(); name = (name == null) ? "" : name.trim(); if (name.isEmpty()) { // auto-assign name int nextIndex = customPreset.getItemCount() + 1; outer: while (true) { name = "custom-" + (nextIndex++); for (int i = 0; i < customPreset.getItemCount(); ++i) { String item = (String) customPreset.getItemAt(i); if (name.equals(item)) { continue outer; } } break; } } else { for (int i = 0; i < customPreset.getItemCount(); ++i) { String item = (String) customPreset.getItemAt(i); if (name.equals(item)) { selected = i; break; } } } if (selected == -1) { // add new preset selected = customPreset.getItemCount(); customPreset.addItem(name); } customPreset.setSelectedIndex(selected); } else { name = (String) customPreset.getSelectedItem(); } renderMan.scene().saveCameraPreset(name); } }); JButton loadPreset = new JButton("load"); loadPreset.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String name = ""; int selected = customPreset.getSelectedIndex(); if (selected == -1) { // select name name = (String) customPreset.getEditor().getItem(); name = (name == null) ? "" : name.trim(); } else { name = ((String) customPreset.getSelectedItem()).trim(); } if (!name.isEmpty()) { renderMan.scene().loadCameraPreset(name); } } }); JButton deletePreset = new JButton("delete"); deletePreset.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String name = ""; int selected = customPreset.getSelectedIndex(); if (selected == -1) { // select name name = (String) customPreset.getEditor().getItem(); name = (name == null) ? "" : name.trim(); } else { name = ((String) customPreset.getSelectedItem()).trim(); } if (!name.isEmpty()) { renderMan.scene().deleteCameraPreset(name); if (selected != -1) { customPreset.removeItemAt(selected); } else { for (int i = 0; i < customPreset.getItemCount(); ++i) { if (name.equals(customPreset.getItemAt(i))) { customPreset.removeItemAt(i); break; } } } } } }); ProjectionMode[] projectionModes = ProjectionMode.values(); projectionMode.setModel(new DefaultComboBoxModel(projectionModes)); projectionMode.addActionListener(projectionModeListener); updateProjectionMode(); JButton autoFocusBtn = new JButton("Autofocus"); autoFocusBtn.setToolTipText("Focuses on the object right in the center, under the crosshairs"); autoFocusBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { renderMan.scene().autoFocus(); dof.update(); subjectDistance.update(); } }); JButton cameraToPlayerBtn = new JButton("Camera to player"); cameraToPlayerBtn.setToolTipText("Move camera to player position"); cameraToPlayerBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { renderMan.scene().moveCameraToPlayer(); } }); JLabel posLbl = new JLabel("Position:"); cameraX.setColumns(10); cameraX.setHorizontalAlignment(JTextField.RIGHT); cameraX.addActionListener(cameraPositionListener); cameraY.setColumns(10); cameraY.setHorizontalAlignment(JTextField.RIGHT); cameraY.addActionListener(cameraPositionListener); cameraZ.setColumns(10); cameraZ.setHorizontalAlignment(JTextField.RIGHT); cameraZ.addActionListener(cameraPositionListener); updateCameraPosition(); JLabel dirLbl = new JLabel("Direction:"); cameraYaw.setColumns(10); cameraYaw.setHorizontalAlignment(JTextField.RIGHT); cameraYaw.addActionListener(cameraDirectionListener); cameraPitch.setColumns(10); cameraPitch.setHorizontalAlignment(JTextField.RIGHT); cameraPitch.addActionListener(cameraDirectionListener); cameraRoll.setColumns(10); cameraRoll.setHorizontalAlignment(JTextField.RIGHT); cameraRoll.addActionListener(cameraDirectionListener); updateCameraDirection(); JButton centerCameraBtn = new JButton("Center camera"); centerCameraBtn.setToolTipText("Center camera above loaded chunks"); centerCameraBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { renderMan.scene().moveCameraToCenter(); } }); JSeparator sep1 = new JSeparator(); JPanel panel = new JPanel(); GroupLayout layout = new GroupLayout(panel); panel.setLayout(layout); layout.setHorizontalGroup( layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup().addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(posLbl).addComponent(dirLbl)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup() .addComponent(cameraX, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(cameraYaw, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup() .addComponent(cameraY, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(cameraPitch, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup() .addComponent(cameraZ, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(cameraRoll, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))) .addGroup(layout.createSequentialGroup().addComponent(presetLbl) .addPreferredGap(ComponentPlacement.RELATED).addComponent(cameraPreset)) .addGroup(layout.createSequentialGroup().addComponent(customPresetLbl) .addPreferredGap(ComponentPlacement.RELATED).addComponent(customPreset) .addPreferredGap(ComponentPlacement.RELATED).addComponent(savePreset) .addPreferredGap(ComponentPlacement.RELATED).addComponent(loadPreset) .addPreferredGap(ComponentPlacement.RELATED).addComponent(deletePreset)) .addGroup(layout.createSequentialGroup().addComponent(cameraToPlayerBtn) .addPreferredGap(ComponentPlacement.RELATED).addComponent(centerCameraBtn)) .addComponent(sep1) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup().addComponent(projectionModeLbl) .addComponent(fov.getLabel()).addComponent(dof.getLabel()) .addComponent(subjectDistance.getLabel())) .addGroup(layout.createParallelGroup().addComponent(projectionMode) .addComponent(fov.getSlider()).addComponent(dof.getSlider()) .addComponent(subjectDistance.getSlider())) .addGroup(layout.createParallelGroup().addComponent(fov.getField()) .addComponent(dof.getField()) .addComponent(subjectDistance.getField()))) .addComponent(autoFocusBtn)) .addContainerGap()); layout.setVerticalGroup(layout.createSequentialGroup().addContainerGap() .addGroup(layout .createParallelGroup(Alignment.BASELINE).addComponent(presetLbl).addComponent(cameraPreset)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(customPresetLbl) .addComponent(customPreset).addComponent(savePreset).addComponent(loadPreset) .addComponent(deletePreset)) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(posLbl).addComponent(cameraX) .addComponent(cameraY).addComponent(cameraZ)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(dirLbl) .addComponent(cameraYaw).addComponent(cameraPitch).addComponent(cameraRoll)) .addPreferredGap(ComponentPlacement.RELATED) .addGroup( layout.createParallelGroup().addComponent(cameraToPlayerBtn).addComponent(centerCameraBtn)) .addPreferredGap(ComponentPlacement.UNRELATED) .addComponent( sep1, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(projectionModeLbl) .addComponent(projectionMode)) .addPreferredGap(ComponentPlacement.RELATED).addGroup(fov.verticalGroup(layout)) .addGroup(dof.verticalGroup(layout)).addGroup(subjectDistance.verticalGroup(layout)) .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(autoFocusBtn).addContainerGap()); return panel; }