List of usage examples for javax.swing JToggleButton JToggleButton
public JToggleButton(Action a)
From source file:net.itransformers.topologyviewer.gui.GraphViewerPanel.java
private JToggleButton createMouseModeButton(final AbstractModalGraphMouse graphMouse) { final String selectText = "Move graph"; final JToggleButton button = new JToggleButton(selectText); button.setToolTipText("If toggled then you can move the entire graph."); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (button.isSelected()) { graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); } else { graphMouse.setMode(ModalGraphMouse.Mode.PICKING); }/*from w w w . j a v a 2 s .c o m*/ } }); return button; }
From source file:br.edu.unifei.mestrado.view.GraphPartitioningVisualization.java
private JToggleButton getGroupCircleVertices() { if (groupCircleVertices == null) { groupCircleVertices = new JToggleButton("Group Circle Clusters"); groupCircleVertices.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { clusterAndRecolor(layout, e.getStateChange() == ItemEvent.SELECTED, groupCircleVertices.isSelected()); vv.repaint();/*from w w w .j ava2 s .co m*/ } }); } return groupCircleVertices; }
From source file:com.eviware.soapui.SoapUI.java
private JComponent buildToolbar() { mainToolbar = new JXToolBar(); mainToolbar.setFloatable(false);/*from ww w .jav a2 s.c o m*/ mainToolbar.setRollover(true); mainToolbar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH); mainToolbar.add(new NewWsdlProjectActionDelegate()); mainToolbar.add(new ImportWsdlProjectActionDelegate()); mainToolbar.add(new SaveAllActionDelegate()); mainToolbar.addSpace(2); mainToolbar.add(new ShowOnlineHelpAction("User Guide", HelpUrls.USERGUIDE_HELP_URL, "Opens the soapUI User-Guide in a browser")); mainToolbar.add(new ShowOnlineHelpAction("Forum", HelpUrls.FORUMS_HELP_URL, "Opens the soapUI Forum in a browser", "/group_go.png")); mainToolbar.addSpace(2); mainToolbar.add(new ShowOnlineHelpAction("Trial", HelpUrls.TRIAL_URL, "Apply for soapUI Pro Trial License", "/favicon.png")); mainToolbar.addSpace(2); mainToolbar.add(new PreferencesActionDelegate()); applyProxyButton = (JToggleButton) mainToolbar.add(new JToggleButton(new ApplyProxyButtonAction())); ProxyUtils.setProxyEnabled(getSettings().getBoolean(ProxySettings.ENABLE_PROXY)); if (ProxyUtils.isProxyEnabled()) { applyProxyButton.setIcon(UISupport.createImageIcon(PROXY_ENABLED_ICON)); applyProxyButton.setSelected(true); ProxyUtils.setProxyEnabled(true); } else { applyProxyButton.setIcon(UISupport.createImageIcon(PROXY_DISABLED_ICON)); ProxyUtils.setProxyEnabled(false); } launchLoadUIButton = mainToolbar.add(new LaunchLoadUIButtonAction()); // mainToolbar.add( new ExitButtonAction() ); mainToolbar.addGlue(); searchField = new JTextField(20); searchField.addKeyListener(new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { if (e.getKeyChar() == '\n') { doForumSearch(searchField.getText()); } } }); mainToolbar.addLabeledFixed("Search Forum", searchField); mainToolbar.add(new ToolbarForumSearchAction()); mainToolbar.add(new ShowOnlineHelpAction(HelpUrls.USERGUIDE_HELP_URL)); for (int i = 0; i < mainToolbar.getComponentCount(); i++) { if (mainToolbar.getComponent(i) instanceof JComponent) { ((JComponent) mainToolbar.getComponent(i)).setBorder(BorderFactory.createEmptyBorder(4, 2, 4, 2)); } } mainToolbar.setBorder(BorderFactory.createEmptyBorder(3, 1, 3, 1)); return mainToolbar; }
From source file:net.schweerelos.parrot.CombinedParrotApp.java
@SuppressWarnings("serial") private JToggleButton setupNavigatorButton(final String name, final String accelerator, final NavigatorComponent navigator) { final Component component = navigator.asJComponent(); AbstractAction showNavigatorAction = new AbstractAction(name) { @Override/*w w w . jav a2 s. co m*/ public void actionPerformed(ActionEvent e) { if (!(e.getSource() instanceof JToggleButton)) { return; } final Window window; if (component instanceof Window) { window = (Window) component; } else { window = SwingUtilities.getWindowAncestor(component); } JToggleButton button = (JToggleButton) e.getSource(); boolean show = button.isSelected(); if (show) { if (window != CombinedParrotApp.this && preferredFrameLocations.containsKey(window)) { window.setLocation(preferredFrameLocations.get(window)); } } if (navigator.tellSelectionWhenShown()) { Collection<NodeWrapper> selectedNodes = activeMainView.getSelectedNodes(); navigator.setSelectedNodes(selectedNodes); } component.setVisible(show); if (show) { window.setVisible(true); } else if (window != CombinedParrotApp.this) { window.setVisible(false); } } }; showNavigatorAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control " + accelerator)); final JToggleButton button = new JToggleButton(showNavigatorAction); button.setToolTipText("Show " + name.toLowerCase()); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { button.setToolTipText((button.isSelected() ? "Hide " : "Show ") + name.toLowerCase()); } }); final Window window; if (component instanceof Window) { window = (Window) component; } else { window = SwingUtilities.getWindowAncestor(component); } if (window != null) { window.addComponentListener(new ComponentAdapter() { @Override public void componentHidden(ComponentEvent e) { button.setSelected(false); if (window != CombinedParrotApp.this) { preferredFrameLocations.put(window, window.getLocation()); } } @Override public void componentShown(ComponentEvent e) { button.setSelected(true); } }); } return button; }
From source file:io.gameover.utilities.pixeleditor.Pixelizer.java
private void addSelectFrameButtonToPanel(int index) { JToggleButton button = new JToggleButton("" + index); button.setPreferredSize(new Dimension(20, 20)); button.setMargin(new Insets(0, 0, 0, 0)); button.setFont(button.getFont().deriveFont(9f)); button.setActionCommand("" + (index - 1)); button.addActionListener(getSelectFrameActionListener()); button.addMouseListener(new SelectFramePopClickListener(this, index - 1)); this.selectFrameButtons.add(button); this.selectFramePanel.add(button, LayoutUtils.xyi((index - 1) % 4 + 1, (index - 1) / 4 + 1, 0d, 0d, new Insets(1, 1, 1, 1))); }
From source file:de.huxhorn.lilith.swing.ViewActions.java
public ViewActions(MainFrame mainFrame) { this.mainFrame = mainFrame; containerChangeListener = new ChangeListener() { /**/*from ww w . jav a 2 s . c om*/ * Invoked when the target of the listener has changed its state. * * @param e a ChangeEvent object */ public void stateChanged(ChangeEvent e) { updateActions(); } }; containerPropertyChangeListener = new PropertyChangeListener() { /** * This method gets called when a bound property is changed. * * @param evt A PropertyChangeEvent object describing the event source * and the property that has changed. */ public void propertyChange(PropertyChangeEvent evt) { if (ViewContainer.SELECTED_EVENT_PROPERTY_NAME.equals(evt.getPropertyName())) { setEventWrapper((EventWrapper) evt.getNewValue()); } } }; keyStrokeActionMapping = new HashMap<KeyStroke, CopyToClipboardAction>(); // ##### Menu Actions ##### // File OpenMenuAction openMenuAction = new OpenMenuAction(); clearRecentFilesAction = new ClearRecentFilesAction(); OpenInactiveLogMenuAction openInactiveLogMenuAction = new OpenInactiveLogMenuAction(); ImportMenuAction importMenuAction = new ImportMenuAction(); exportMenuAction = new ExportMenuAction(); CleanAllInactiveLogsMenuAction cleanAllInactiveLogsMenuAction = new CleanAllInactiveLogsMenuAction(); preferencesMenuAction = new PreferencesMenuAction(); ExitMenuAction exitMenuAction = new ExitMenuAction(); // Edit showUnfilteredEventAction = new ShowUnfilteredEventAction(); gotoSourceAction = new GotoSourceAction(); copySelectionAction = new CopySelectionAction(); copyEventAction = new CopyToClipboardAction(new EventFormatter()); copyLoggingActions = new ArrayList<CopyToClipboardAction>(); copyLoggingActions.add(new CopyToClipboardAction(new EventJsonFormatter())); copyLoggingActions.add(new CopyToClipboardAction(new EventXmlFormatter())); copyLoggingActions.add(new CopyToClipboardAction(new LoggingMessageFormatter())); copyLoggingActions.add(new CopyToClipboardAction(new LoggingMessagePatternFormatter())); copyLoggingActions.add(new CopyToClipboardAction(new LoggingLoggerNameFormatter())); copyLoggingActions.add(new CopyToClipboardAction(new LoggingThrowableFormatter())); copyLoggingActions.add(new CopyToClipboardAction(new LoggingCallStackFormatter())); copyLoggingActions.add(new CopyToClipboardAction(new LoggingCallLocationFormatter())); copyLoggingActions.add(new CopyToClipboardAction(new LoggingMarkerFormatter())); copyLoggingActions.add(new CopyToClipboardAction(new LoggingMdcFormatter())); copyLoggingActions.add(new CopyToClipboardAction(new LoggingNdcFormatter())); copyAccessActions = new ArrayList<CopyToClipboardAction>(); copyAccessActions.add(new CopyToClipboardAction(new AccessUriFormatter())); prepareClipboardActions(copyLoggingActions, keyStrokeActionMapping); prepareClipboardActions(copyAccessActions, keyStrokeActionMapping); // Search findMenuAction = new FindMenuAction(); findPreviousAction = new FindPreviousAction(); findNextAction = new FindNextAction(); findPreviousActiveAction = new FindPreviousActiveAction(); findNextActiveAction = new FindNextActiveAction(); resetFindAction = new ResetFindAction(); // View scrollToBottomMenuAction = new ScrollToBottomMenuAction(); pauseMenuAction = new PauseMenuAction(); clearMenuAction = new ClearMenuAction(); attachMenuAction = new AttachMenuAction(); disconnectMenuAction = new DisconnectMenuAction(); focusMessageAction = new FocusMessageAction(); focusEventsAction = new FocusEventsAction(); //statisticsMenuAction = new StatisticsMenuAction(); editSourceNameMenuAction = new EditSourceNameMenuAction(); saveLayoutAction = new SaveLayoutAction(); resetLayoutAction = new ResetLayoutAction(); saveConditionMenuAction = new SaveConditionMenuAction(); zoomInMenuAction = new ZoomInMenuAction(); zoomOutMenuAction = new ZoomOutMenuAction(); resetZoomMenuAction = new ResetZoomMenuAction(); previousTabAction = new PreviousTabAction(); nextTabAction = new NextTabAction(); closeFilterAction = new CloseFilterAction(); closeOtherFiltersAction = new CloseOtherFiltersAction(); closeAllFiltersAction = new CloseAllFiltersAction(); // Window ShowTaskManagerAction showTaskManagerAction = new ShowTaskManagerAction(); closeAllAction = new CloseAllAction(); closeOtherAction = new CloseOtherAction(); minimizeAllAction = new MinimizeAllAction(); minimizeAllOtherAction = new MinimizeAllOtherAction(); removeInactiveAction = new RemoveInactiveAction(); //clearAndRemoveInactiveAction=new ClearAndRemoveInactiveAction(); // Help KeyboardHelpAction keyboardHelpAction = new KeyboardHelpAction(); ShowLoveMenuAction showLoveMenuAction = new ShowLoveMenuAction(); TipOfTheDayAction tipOfTheDayAction = new TipOfTheDayAction(); DebugAction debugAction = new DebugAction(); aboutAction = new AboutAction(); CheckForUpdateAction checkForUpdateAction = new CheckForUpdateAction(); TroubleshootingAction troubleshootingAction = new TroubleshootingAction(); // ##### ToolBar Actions ##### scrollToBottomToolBarAction = new ScrollToBottomToolBarAction(); pauseToolBarAction = new PauseToolBarAction(); clearToolBarAction = new ClearToolBarAction(); findToolBarAction = new FindToolBarAction(); //statisticsToolBarAction = new StatisticsToolBarAction(); attachToolBarAction = new AttachToolBarAction(); disconnectToolBarAction = new DisconnectToolBarAction(); showTaskManagerItem = new JMenuItem(showTaskManagerAction); closeAllItem = new JMenuItem(closeAllAction); closeAllOtherItem = new JMenuItem(closeOtherAction); minimizeAllItem = new JMenuItem(minimizeAllAction); minimizeAllOtherItem = new JMenuItem(minimizeAllOtherAction); removeInactiveItem = new JMenuItem(removeInactiveAction); //clearAndRemoveInactiveItem = new JMenuItem(clearAndRemoveInactiveAction); toolbar = new JToolBar(SwingConstants.HORIZONTAL); toolbar.setFloatable(false); scrollToBottomButton = new JToggleButton(scrollToBottomToolBarAction); toolbar.add(scrollToBottomButton); JButton pauseButton = new JButton(pauseToolBarAction); toolbar.add(pauseButton); JButton clearButton = new JButton(clearToolBarAction); toolbar.add(clearButton); JButton findButton = new JButton(findToolBarAction); toolbar.add(findButton); JButton disconnectButton = new JButton(disconnectToolBarAction); toolbar.add(disconnectButton); toolbar.addSeparator(); //JButton statisticsButton = new JButton(statisticsToolBarAction); //toolbar.add(statisticsButton); //toolbar.addSeparator(); JButton attachButton = new JButton(attachToolBarAction); toolbar.add(attachButton); toolbar.addSeparator(); PreferencesToolBarAction preferencesToolBarAction = new PreferencesToolBarAction(); JButton preferencesButton = new JButton(preferencesToolBarAction); toolbar.add(preferencesButton); toolbar.addSeparator(); ShowLoveToolbarAction showLoveToolbarAction = new ShowLoveToolbarAction(); JButton showLoveButton = new JButton(showLoveToolbarAction); toolbar.add(showLoveButton); recentFilesMenu = new JMenu("Recent Files"); Application app = mainFrame.getApplication(); menubar = new JMenuBar(); // File JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic('f'); fileMenu.add(openMenuAction); fileMenu.add(recentFilesMenu); fileMenu.add(openInactiveLogMenuAction); fileMenu.add(cleanAllInactiveLogsMenuAction); fileMenu.add(importMenuAction); fileMenu.add(exportMenuAction); if (!app.isMac()) { fileMenu.addSeparator(); fileMenu.add(preferencesMenuAction); fileMenu.addSeparator(); fileMenu.add(exitMenuAction); } // Edit editMenu = new JMenu("Edit"); editMenu.setMnemonic('e'); editMenu.add(copySelectionAction); editMenu.addSeparator(); editMenu.add(copyEventAction); editMenu.addSeparator(); for (CopyToClipboardAction current : copyLoggingActions) { editMenu.add(current); } editMenu.addSeparator(); for (CopyToClipboardAction current : copyAccessActions) { editMenu.add(current); } editMenu.addSeparator(); customCopyMenu = new JMenu("Custom copy"); customCopyPopupMenu = new JMenu("Custom copy"); editMenu.add(customCopyMenu); editMenu.addSeparator(); PasteStackTraceElementAction pasteStackTraceElementAction = new PasteStackTraceElementAction(); editMenu.add(pasteStackTraceElementAction); // Search searchMenu = new JMenu("Search"); searchMenu.setMnemonic('s'); searchMenu.add(findMenuAction); searchMenu.add(resetFindAction); searchMenu.add(findPreviousAction); searchMenu.add(findNextAction); searchMenu.add(findPreviousActiveAction); searchMenu.add(findNextActiveAction); searchMenu.addSeparator(); searchMenu.add(saveConditionMenuAction); searchMenu.addSeparator(); focusMenu = new FocusMenu(mainFrame.getApplicationPreferences()); excludeMenu = new ExcludeMenu(mainFrame.getApplicationPreferences()); searchMenu.add(focusMenu); searchMenu.add(excludeMenu); // View viewMenu = new JMenu("View"); viewMenu.setMnemonic('v'); viewMenu.add(scrollToBottomMenuAction); viewMenu.add(pauseMenuAction); viewMenu.add(clearMenuAction); viewMenu.add(attachMenuAction); viewMenu.add(disconnectMenuAction); viewMenu.add(focusEventsAction); viewMenu.add(focusMessageAction); //viewMenu.add(statisticsMenuAction); viewMenu.add(editSourceNameMenuAction); viewMenu.addSeparator(); viewMenu.add(zoomInMenuAction); viewMenu.add(zoomOutMenuAction); viewMenu.add(resetZoomMenuAction); viewMenu.addSeparator(); JMenu layoutMenu = new JMenu("Layout"); columnsMenu = new JMenu("Columns"); layoutMenu.add(columnsMenu); layoutMenu.addSeparator(); layoutMenu.add(saveLayoutAction); layoutMenu.add(resetLayoutAction); viewMenu.add(layoutMenu); viewMenu.addSeparator(); viewMenu.add(previousTabAction); viewMenu.add(nextTabAction); viewMenu.addSeparator(); viewMenu.add(closeFilterAction); viewMenu.add(closeOtherFiltersAction); viewMenu.add(closeAllFiltersAction); // Window windowMenu = new JMenu("Window"); windowMenu.setMnemonic('w'); // Help JMenu helpMenu = new JMenu("Help"); helpMenu.setMnemonic('h'); helpMenu.add(keyboardHelpAction); helpMenu.add(showLoveMenuAction); helpMenu.add(tipOfTheDayAction); helpMenu.add(checkForUpdateAction); helpMenu.add(troubleshootingAction); helpMenu.addSeparator(); helpMenu.add(debugAction); if (!app.isMac()) { helpMenu.addSeparator(); helpMenu.add(aboutAction); } menubar.add(fileMenu); menubar.add(editMenu); menubar.add(searchMenu); menubar.add(viewMenu); menubar.add(windowMenu); menubar.add(helpMenu); updateWindowMenu(); updateRecentFiles(); updateActions(); }
From source file:com.declarativa.interprolog.gui.Ini2BCKP.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree();// w w w .ja v a 2 s . com layout = new TreeLayout<String, Integer>(graph); radialLayout = new BalloonLayout<String, Integer>(graph); radialLayout.setSize(new Dimension(900, 900)); vv = new VisualizationViewer<String, Integer>(layout, new Dimension(600, 600)); vv.setBackground(Color.white); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); rings = new Ini2BCKP.Rings(radialLayout); System.out.println("test"); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); Container content = getContentPane(); content.add(panel); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); hyperbolicViewSupport = new ViewLensSupport<String, Integer>(vv, new HyperbolicShapeTransformer(vv, vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)), new ModalLensGraphMouse()); graphMouse.addItemListener(hyperbolicViewSupport.getGraphMouse().getModeListener()); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); vv.scaleToLayout(scaler); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton radial = new JToggleButton("Balloon"); radial.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, layout, radialLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity(); vv.addPreRenderPaintable(rings); } else { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, radialLayout, layout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); final JRadioButton hyperView = new JRadioButton("Hyperbolic View"); hyperView.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { hyperbolicViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); // content.add(controls, BorderLayout.SOUTH); //JFrame frame = new JFrame(); //content = frame.getContentPane(); //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jLayeredPane1.add(vv); jLayeredPane1.updateUI(); jLayeredPane1.setVisible(true); }
From source file:es.darkhogg.hazelnutt.EditorFrame.java
private void initializeGui() { setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); setBounds(100, 100, 640, 480);/*from w w w. ja va 2 s.c o m*/ addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent arg0) { actionExit(); } }); fileChooser = new JFileChooser(); //fileChooser.setFileFilter( hlfFileFilter ); hlfFileChooser = new JFileChooser(); hlfFileChooser.setFileFilter(hlfFileFilter); JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); mnFile.setMnemonic('F'); menuBar.add(mnFile); menuLoadRom = new JMenuItem("Load ROM..."); menuLoadRom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK)); menuLoadRom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionOpenRom(null); } }); menuLoadRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_open.png"))); menuLoadRom.setMnemonic('O'); mnFile.add(menuLoadRom); menuSaveRom = new JMenuItem("Save ROM"); menuSaveRom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionSaveRom(); } }); menuSaveRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save.png"))); menuSaveRom.setMnemonic('S'); menuSaveRom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK)); mnFile.add(menuSaveRom); menuSaveRomAs = new JMenuItem("Save ROM As..."); menuSaveRomAs.setMnemonic('a'); menuSaveRomAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK)); menuSaveRomAs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionSaveRomAs(); } }); menuSaveRomAs .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save_as.png"))); mnFile.add(menuSaveRomAs); mnFile.addSeparator(); menuLoadLevel = new JMenuItem("Load Level..."); menuLoadLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0)); menuLoadLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionLoadLevel(); } }); menuLoadLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_load_level.png"))); menuLoadLevel.setMnemonic('L'); mnFile.add(menuLoadLevel); menuReloadLevel = new JMenuItem("Reload Level"); menuReloadLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0)); menuReloadLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionReloadLevel(); } }); menuReloadLevel.setMnemonic('R'); menuReloadLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_reload_level.png"))); mnFile.add(menuReloadLevel); menuSaveLevel = new JMenuItem("Save Level"); menuSaveLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0)); menuSaveLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionSaveLevel(); } }); menuSaveLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save_level.png"))); menuSaveLevel.setMnemonic('v'); mnFile.add(menuSaveLevel); //* mnFile.addSeparator(); menuImportLevel = new JMenuItem("Import Level..."); menuImportLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0)); menuImportLevel.setMnemonic('i'); menuImportLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionImportLevel(); } }); menuImportLevel .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_import.png"))); mnFile.add(menuImportLevel); menuExportLevel = new JMenuItem("Export Level..."); menuExportLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0)); menuExportLevel.setMnemonic('e'); menuExportLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionExportLevel(); } }); menuExportLevel .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_export.png"))); mnFile.add(menuExportLevel); //*/ mnFile.addSeparator(); menuExit = new JMenuItem("Exit"); menuExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)); menuExit.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_exit.png"))); menuExit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { actionExit(); } }); menuRecentFiles = new JMenu("Recent Files..."); mnFile.add(menuRecentFiles); mnFile.addSeparator(); menuExit.setMnemonic('X'); mnFile.add(menuExit); JMenu mnEdit = new JMenu("Edit"); mnEdit.setMnemonic('E'); menuBar.add(mnEdit); menuViewSpawn = new JCheckBoxMenuItem("View Spawn Point"); menuViewSpawn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, 0)); menuViewSpawn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(false); } }); menuClearLevel = new JMenuItem("Clear Level"); menuClearLevel.setMnemonic('c'); menuClearLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK)); menuClearLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionClearLevel(); } }); menuClearLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_clear_level.png"))); mnEdit.add(menuClearLevel); mnEdit.addSeparator(); menuViewSpawn .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_spawn.png"))); menuViewSpawn.setMnemonic('S'); menuViewSpawn.setSelected(true); mnEdit.add(menuViewSpawn); menuViewItems = new JCheckBoxMenuItem("View Items"); menuViewItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, 0)); menuViewItems.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(false); } }); menuViewItems.setSelected(true); menuViewItems .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_items.png"))); menuViewItems.setMnemonic('I'); mnEdit.add(menuViewItems); menuViewDoorItems = new JCheckBoxMenuItem("View Door Items"); menuViewDoorItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, 0)); menuViewDoorItems.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(false); } }); menuViewDoorItems.setSelected(true); menuViewDoorItems.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_door_items.png"))); menuViewDoorItems.setMnemonic('D'); mnEdit.add(menuViewDoorItems); menuViewEnemies = new JCheckBoxMenuItem("View Enemies"); menuViewEnemies.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, 0)); menuViewEnemies.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(false); } }); menuViewEnemies.setSelected(true); menuViewEnemies .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_enemies.png"))); menuViewEnemies.setMnemonic('E'); mnEdit.add(menuViewEnemies); menuViewTypes = new JCheckBoxMenuItem("View Combo Types"); menuViewTypes.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_5, 0)); menuViewTypes.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(false); } }); menuViewTypes.setSelected(true); menuViewTypes.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_combo_infos.png"))); menuViewTypes.setMnemonic('C'); mnEdit.add(menuViewTypes); mnEdit.addSeparator(); scaleMenuItem = new JCheckBoxMenuItem("Scale Level Display"); scaleMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_6, 0)); scaleMenuItem.setMnemonic('l'); scaleMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionScale(false); } }); scaleMenuItem.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_x2.png"))); mnEdit.add(scaleMenuItem); gridMenuItem = new JCheckBoxMenuItem("Display grid"); gridMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_7, 0)); gridMenuItem.setMnemonic('G'); gridMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionGrid(false); } }); gridMenuItem.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_grid.png"))); mnEdit.add(gridMenuItem); //mnEdit.addSeparator(); mntmPreferences = new JMenuItem("Preferences..."); mntmPreferences.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionPreferences(); } }); mntmPreferences.setMnemonic('P'); mntmPreferences.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_preferences.png"))); //mnEdit.add(mntmPreferences); mnHelp = new JMenu("Help"); mnHelp.setMnemonic('H'); menuBar.add(mnHelp); mntmCheckUpdates = new JMenuItem("Check for Updates..."); mntmCheckUpdates.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK)); mntmCheckUpdates.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionCheckUpdates(); } }); mntmCheckUpdates.setMnemonic('c'); mntmCheckUpdates .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_update.png"))); mnHelp.add(mntmCheckUpdates); mntmAbout = new JMenuItem("Readme..."); mntmAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); mntmAbout.setMnemonic('r'); mntmAbout.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/about.png"))); mntmAbout.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionAbout(); } }); mnHelp.addSeparator(); mnHelp.add(mntmAbout); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); JToolBar toolBar = new JToolBar(); toolBar.setRollover(true); toolBar.setFloatable(false); contentPane.add(toolBar, BorderLayout.NORTH); barLoadRom = new JButton(""); barLoadRom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionOpenRom(null); } }); barLoadRom.setToolTipText("Open"); barLoadRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_open.png"))); toolBar.add(barLoadRom); barSaveRom = new JButton(""); barSaveRom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionSaveRom(); } }); barSaveRom.setToolTipText("Save"); barSaveRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save.png"))); toolBar.add(barSaveRom); toolBar.addSeparator(); barImportLevel = new JButton(""); barImportLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionImportLevel(); } }); barImportLevel.setToolTipText("Import Level"); barImportLevel .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_import.png"))); toolBar.add(barImportLevel); barExportLevel = new JButton(""); barExportLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionExportLevel(); } }); barExportLevel.setToolTipText("Export Level"); barExportLevel .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_export.png"))); toolBar.add(barExportLevel); toolBar.addSeparator(); barLoadLevel = new JButton(""); barLoadLevel.setToolTipText("Load Level"); barLoadLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionLoadLevel(); } }); barLoadLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_load_level.png"))); toolBar.add(barLoadLevel); barReloadLevel = new JButton(""); barReloadLevel.setToolTipText("Reload Current Level"); barReloadLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionReloadLevel(); } }); barReloadLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_reload_level.png"))); toolBar.add(barReloadLevel); barSaveLevel = new JButton(""); barSaveLevel.setToolTipText("Save Level"); barSaveLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionSaveLevel(); } }); barSaveLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save_level.png"))); toolBar.add(barSaveLevel); toolBar.addSeparator(); barViewItems = new JToggleButton(""); barViewItems.setToolTipText("Toggle View Items"); barViewItems.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(true); } }); barViewSpawn = new JToggleButton(""); barViewSpawn.setToolTipText("Toggle View Spawn"); barViewSpawn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(true); } }); barClearLevel = new JButton(""); barClearLevel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionClearLevel(); } }); barClearLevel.setToolTipText("Clear Level"); barClearLevel.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_clear_level.png"))); toolBar.add(barClearLevel); toolBar.addSeparator(); barViewSpawn.setSelected(true); barViewSpawn.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_spawn.png"))); toolBar.add(barViewSpawn); barViewItems.setSelected(true); barViewItems.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_items.png"))); toolBar.add(barViewItems); barViewDoorItems = new JToggleButton(""); barViewDoorItems.setToolTipText("Toggle View Door Items"); barViewDoorItems.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(true); } }); barViewDoorItems.setSelected(true); barViewDoorItems.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_door_items.png"))); toolBar.add(barViewDoorItems); barViewEnemies = new JToggleButton(""); barViewEnemies.setToolTipText("toggle View Enemies"); barViewEnemies.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(true); } }); barViewEnemies.setSelected(true); barViewEnemies .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_enemies.png"))); toolBar.add(barViewEnemies); barViewTypes = new JToggleButton(""); barViewTypes.setToolTipText("Toggle view Combo Help"); barViewTypes.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionToggle(true); } }); barViewTypes.setSelected(true); barViewTypes.setIcon( new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_combo_infos.png"))); toolBar.add(barViewTypes); barViewSpawn.setSelected(config.getBoolean("Hazelnutt.gui.viewSpawn", true)); barViewItems.setSelected(config.getBoolean("Hazelnutt.gui.viewItems", true)); barViewDoorItems.setSelected(config.getBoolean("Hazelnutt.gui.viewDoorItems", true)); barViewEnemies.setSelected(config.getBoolean("Hazelnutt.gui.viewEnemies", true)); barViewTypes.setSelected(config.getBoolean("Hazelnutt.gui.viewHelp", true)); panel = new JPanel(); contentPane.add(panel, BorderLayout.EAST); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); selectorPanel = new SelectorPanel(); selectorPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Combo & Entity Selector", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213))); panel.add(selectorPanel); propertiesPanel = new PropertiesPanel(null); propertiesPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Level Properties", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213))); panel.add(propertiesPanel); toolBar.addSeparator(); scaleButton = new JToggleButton(""); scaleButton.setToolTipText("Toggle Scale Display"); scaleButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionScale(true); } }); scaleButton.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_x2.png"))); toolBar.add(scaleButton); scaleButton.setSelected(config.getBoolean("Hazelnutt.gui.scaled", false)); gridButton = new JToggleButton(""); gridButton.setToolTipText("Display Grid"); gridButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { actionGrid(true); } }); gridButton.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_grid.png"))); toolBar.add(gridButton); gridButton.setSelected(config.getBoolean("Hazelnutt.gui.grid", false)); Component horizontalGlue = Box.createHorizontalGlue(); toolBar.add(horizontalGlue); Component verticalGlue = Box.createVerticalGlue(); panel.add(verticalGlue); levelWrapper = new JPanel(); levelWrapper.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Level", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213))); contentPane.add(levelWrapper, BorderLayout.CENTER); levelWrapper.setLayout(new BorderLayout(0, 0)); scrollPane = new JScrollPane(); scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0)); levelWrapper.add(scrollPane); levelDisplay = new LevelDisplay(); levelDisplay.addEditListener(new EditListener() { @Override public void leftPressed(int x, int y) { SelectionType st = selectorPanel.getSelectionType(); Object so = selectorPanel.getSelectedObject(); if (st == SelectionType.COMBO) { paintComboAt(x, y, ((Byte) so).byteValue()); } else if (st == SelectionType.SPAWN) { selectedLevel.getRomLevel().setSpawn(new IntVector(x, y)); levelHasChanged = true; } else if (st == SelectionType.ITEM) { Item ent = new Item((ItemType) so, x, y); EntityCollection<Item> ents = selectedLevel.getRomLevel().getItems(); for (Iterator<Item> it = ents.iterator(); it.hasNext();) { Item item = it.next(); if (item.getX() == x && item.getY() == y) { it.remove(); } } if (ents.size() <= ents.maxSize()) { ents.add(ent); levelHasChanged = true; } } else if (st == SelectionType.DOOR_ITEM) { Item ent = new Item((ItemType) so, x, y); EntityCollection<Item> ents = selectedLevel.getRomLevel().getDoorItems(); for (Iterator<Item> it = ents.iterator(); it.hasNext();) { Item item = it.next(); if (item.getX() == x && item.getY() == y) { it.remove(); } } if (ents.size() <= ents.maxSize()) { ents.add(ent); levelHasChanged = true; } } else if (st == SelectionType.ENEMY) { Enemy ent = new Enemy((EnemyType) so, x, y); EntityCollection<Enemy> ents = selectedLevel.getRomLevel().getEnemies(); for (Iterator<Enemy> it = ents.iterator(); it.hasNext();) { Enemy enem = it.next(); if (enem.getX() == x && enem.getY() == y) { it.remove(); } } if (ents.size() <= ents.maxSize()) { ents.add(ent); levelHasChanged = true; } } updateTitle(); levelDisplay.repaint(); levelHasChanged = true; } @Override public void centerPressed(int x, int y) { selectorPanel.forceComboSelection(selectedLevel.getRomLevel().getData()[x][y]); } @Override public void rightPressed(int x, int y) { deleteVisibleEntitiesAt(x, y); } @Override public void leftDragged(int x, int y) { if (selectorPanel.getSelectionType() == SelectionType.COMBO) { paintComboAt(x, y, ((Byte) selectorPanel.getSelectedObject()).byteValue()); } } @Override public void centerDragged(int x, int y) { // Nothing to de here } @Override public void rightDragged(int x, int y) { deleteVisibleEntitiesAt(x, y); } // Utility methods /*private void selectComboAt ( int x, int y ) { }/**/ private void paintComboAt(int x, int y, byte value) { selectedLevel.getRomLevel().getData()[x][y] = value; levelHasChanged = true; updateTitle(); levelDisplay.repaint(); } private void deleteVisibleEntitiesAt(int x, int y) { Collection<Item> items = selectedLevel.getRomLevel().getItems(); Collection<Item> doorItems = selectedLevel.getRomLevel().getDoorItems(); Collection<Enemy> enemies = selectedLevel.getRomLevel().getEnemies(); if (barViewItems.isSelected()) { for (Iterator<Item> it = items.iterator(); it.hasNext();) { Item item = it.next(); if (item.getX() == x && item.getY() == y) { it.remove(); levelHasChanged = true; } } } if (barViewDoorItems.isSelected()) { for (Iterator<Item> it = doorItems.iterator(); it.hasNext();) { Item doorItem = it.next(); if (doorItem.getX() == x && doorItem.getY() == y) { it.remove(); levelHasChanged = true; } } } if (barViewEnemies.isSelected()) { for (Iterator<Enemy> it = enemies.iterator(); it.hasNext();) { Enemy enem = it.next(); if (enem.getX() == x && enem.getY() == y) { it.remove(); levelHasChanged = true; } } } updateTitle(); levelDisplay.repaint(); } }); scrollPane.setViewportView(levelDisplay); updateTitle(); actionToggle(true); actionScale(true); actionGrid(true); setIconImage(Toolkit.getDefaultToolkit() .getImage(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/witch_hazel_big.png"))); setRomFeaturesEnabled(false); setLevelFeaturesEnabled(false); if (config.getBoolean("Hazelnutt.gui.maximum", false)) { setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH); } else { int x = config.getInt("Hazelnutt.gui.location.x", Integer.MIN_VALUE); int y = config.getInt("Hazelnutt.gui.location.y", Integer.MIN_VALUE); int w = config.getInt("Hazelnutt.gui.size.width", Integer.MIN_VALUE); int h = config.getInt("Hazelnutt.gui.size.height", Integer.MIN_VALUE); if (x == Integer.MIN_VALUE || x == Integer.MIN_VALUE || w == Integer.MIN_VALUE || h == Integer.MIN_VALUE) { setLocationRelativeTo(null); } else { setLocation(x, y); setSize(w, h); } } propertiesPanel.addApplyListener(new PropertiesPanel.ApplyListener() { @Override public void apply() { levelHasChanged = true; updateTitle(); updateDisplay(); } }); if (config.containsKey("Hazelnutt.gui.lastDirectory")) { File lastDir = new File(config.getString("Hazelnutt.gui.lastDirectory")); if (lastDir.exists() && lastDir.isDirectory()) { //logger.debug( "Resetting the last directory: '" + lastDir + "'" ); fileChooser.setCurrentDirectory(lastDir); } } // Configure the PgUp and PgDn shortcuts InputMap im = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "PgUp"); im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "PgDn"); ActionMap am = contentPane.getActionMap(); am.put("PgUp", new AbstractAction() { @Override public void actionPerformed(ActionEvent arg0) { actionLevelUp(); } }); am.put("PgDn", new AbstractAction() { @Override public void actionPerformed(ActionEvent arg0) { actionLevelDown(); } }); // Get the recent files recentFiles = new LinkedList<String>(Arrays.asList(config.getStringArray("Hazelnutt.gui.recentFiles"))); updateRecentFiles(); }
From source file:md.mclama.com.ModManager.java
/** * Create the frame./*from w w w.j av a 2 s . co m*/ */ @SuppressWarnings("serial") public ModManager() throws MalformedURLException { setResizable(false); setTitle("McLauncher " + McVersion); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 700, 400); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); tabbedPane.setBounds(0, 0, 694, 372); contentPane.add(tabbedPane); profileListMdl = new DefaultListModel<String>(); ModListModel = new DefaultListModel<String>(); listModel = new DefaultListModel<String>(); getCurrentMods(); panelLauncher = new JPanel(); tabbedPane.addTab("Launcher", null, panelLauncher, null); panelLauncher.setLayout(null); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBounds(556, 36, 132, 248); panelLauncher.add(scrollPane); profileList = new JList<String>(profileListMdl); profileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); scrollPane.setViewportView(profileList); btnNewProfile = new JButton("New"); btnNewProfile.setFont(new Font("SansSerif", Font.PLAIN, 12)); btnNewProfile.setBounds(479, 4, 76, 20); panelLauncher.add(btnNewProfile); btnNewProfile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { newProfile(txtProfile.getText()); } }); btnNewProfile.setToolTipText("Click to create a new profile."); JButton btnRenameProfile = new JButton("Rename"); btnRenameProfile.setBounds(479, 25, 76, 20); panelLauncher.add(btnRenameProfile); btnRenameProfile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { renameProfile(); } }); btnRenameProfile.setToolTipText("Click to rename the selected profile"); JButton btnDelProfile = new JButton("Delete"); btnDelProfile.setBounds(479, 50, 76, 20); panelLauncher.add(btnDelProfile); btnDelProfile.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { deleteProfile(); } }); btnDelProfile.setToolTipText("Click to delete the selected profile."); JButton btnLaunch = new JButton("Launch"); btnLaunch.setBounds(605, 319, 89, 23); panelLauncher.add(btnLaunch); btnLaunch.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (selProfile != null) { LaunchFactorioWithSelectedMods(false); //dont ignore } } }); btnLaunch.setToolTipText("Click to launch factorio with the selected mod profile."); lblAvailableMods = new JLabel("Available Mods"); lblAvailableMods.setBounds(4, 155, 144, 14); panelLauncher.add(lblAvailableMods); lblAvailableMods.setFont(new Font("SansSerif", Font.PLAIN, 10)); lblAvailableMods.setText("Available Mods: " + -1); txtGamePath = new JTextField(); txtGamePath.setBounds(4, 5, 211, 23); panelLauncher.add(txtGamePath); txtGamePath.setToolTipText("Select tha path to your game!"); txtGamePath.setFont(new Font("Tahoma", Font.PLAIN, 8)); txtGamePath.setText("Game Path"); txtGamePath.setColumns(10); JButton btnFind = new JButton("find"); btnFind.setBounds(227, 3, 32, 23); panelLauncher.add(btnFind); txtProfile = new JTextField(); txtProfile.setBounds(556, 2, 132, 22); panelLauncher.add(txtProfile); txtProfile.setToolTipText("The name of NEW or RENAME profiles"); txtProfile.setText("Profile1"); txtProfile.setColumns(10); lblModsEnabled = new JLabel("Mods Enabled: -1"); lblModsEnabled.setBounds(335, 155, 95, 16); panelLauncher.add(lblModsEnabled); lblModsEnabled.setFont(new Font("SansSerif", Font.PLAIN, 10)); JScrollPane scrollPane_1 = new JScrollPane(); scrollPane_1.setBounds(0, 167, 211, 165); panelLauncher.add(scrollPane_1); modsList = new JList<String>(listModel); modsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); modsList.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { String modName = util.getModVersion(modsList.getSelectedValue()); lblModVersion.setText("Mod Version: " + modName); checkDependency(modsList); if (modName.contains(".zip")) { new File(System.getProperty("java.io.tmpdir") + modName.replace(".zip", "")).delete(); } if (System.currentTimeMillis() - lastClickTime <= 300) { //Double click addMod(); } lastClickTime = System.currentTimeMillis(); } }); scrollPane_1.setViewportView(modsList); modsList.setFont(new Font("Tahoma", Font.PLAIN, 9)); JScrollPane scrollPane_2 = new JScrollPane(); scrollPane_2.setBounds(333, 167, 211, 165); panelLauncher.add(scrollPane_2); enabledModsList = new JList<String>(ModListModel); enabledModsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); enabledModsList.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { lblModVersion.setText("Mod Version: " + util.getModVersion(enabledModsList.getSelectedValue())); checkDependency(enabledModsList); if (System.currentTimeMillis() - lastClickTime <= 300) { //Double click removeMod(); } lastClickTime = System.currentTimeMillis(); } }); enabledModsList.setFont(new Font("SansSerif", Font.PLAIN, 10)); scrollPane_2.setViewportView(enabledModsList); JButton btnEnable = new JButton("Enable"); btnEnable.setBounds(223, 200, 90, 28); panelLauncher.add(btnEnable); btnEnable.setToolTipText("Add mod -->"); JButton btnDisable = new JButton("Disable"); btnDisable.setBounds(223, 240, 90, 28); panelLauncher.add(btnDisable); btnDisable.setToolTipText("Disable mod "); JLabel lblModsAvailable = new JLabel("Mods available"); lblModsAvailable.setBounds(4, 329, 89, 14); panelLauncher.add(lblModsAvailable); lblModsAvailable.setFont(new Font("SansSerif", Font.PLAIN, 10)); JLabel lblEnabledMods = new JLabel("Enabled Mods"); lblEnabledMods.setBounds(337, 329, 89, 16); panelLauncher.add(lblEnabledMods); lblEnabledMods.setFont(new Font("SansSerif", Font.PLAIN, 10)); lblModVersion = new JLabel("Mod Version: (select a mod first)"); lblModVersion.setBounds(4, 117, 183, 14); panelLauncher.add(lblModVersion); lblModVersion.setFont(new Font("SansSerif", Font.PLAIN, 10)); lblRequiredMods = new JLabel("Required Mods: " + reqModsStr); lblRequiredMods.setBounds(6, 143, 538, 14); panelLauncher.add(lblRequiredMods); lblRequiredMods.setHorizontalAlignment(SwingConstants.RIGHT); lblRequiredMods.setFont(new Font("SansSerif", Font.PLAIN, 10)); JButton btnNewButton = new JButton("TEST"); btnNewButton.setVisible(testBtnEnabled); btnNewButton.setEnabled(testBtnEnabled); btnNewButton.setBounds(338, 61, 90, 28); panelLauncher.add(btnNewButton); btnUpdate.setBounds(218, 322, 103, 20); panelLauncher.add(btnUpdate); btnUpdate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { util.updateLauncher(); } }); btnUpdate.setVisible(false); btnUpdate.setFont(new Font("SansSerif", Font.PLAIN, 9)); lblModRequires = new JLabel("Mod Requires: (Select a mod first)"); lblModRequires.setBounds(4, 127, 317, 16); panelLauncher.add(lblModRequires); btnLaunchIgnore = new JButton("Launch + ignore"); btnLaunchIgnore.setToolTipText("Ignore any errors that McLauncher may not correctly account for."); btnLaunchIgnore.setFont(new Font("SansSerif", Font.PLAIN, 11)); btnLaunchIgnore.setBounds(556, 284, 133, 23); panelLauncher.add(btnLaunchIgnore); JButton btnConsole = new JButton("Console"); btnConsole.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean changeto = !con.isVisible(); con.setVisible(changeto); con.updateConsole(); } }); btnConsole.setBounds(335, 0, 90, 28); panelLauncher.add(btnConsole); JPanel panelDownloadMods = new JPanel(); tabbedPane.addTab("Download Mods", null, panelDownloadMods, null); panelDownloadMods.setLayout(null); scrollPane_3 = new JScrollPane(); scrollPane_3.setBounds(0, 0, 397, 303); panelDownloadMods.add(scrollPane_3); dlModel = new DefaultTableModel(new Object[][] {}, new String[] { "Mod Name", "Author", "Version", "Tags" }) { Class[] columnTypes = new Class[] { String.class, String.class, String.class, Object.class }; public Class getColumnClass(int columnIndex) { return columnTypes[columnIndex]; } boolean[] columnEditables = new boolean[] { false, false, false, false }; public boolean isCellEditable(int row, int column) { return columnEditables[column]; }; }; tSorter = new TableRowSorter<DefaultTableModel>(dlModel); tableDownloads = new JTable(); tableDownloads.setRowSorter(tSorter); tableDownloads.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { trow = tableDownloads.getSelectedRow(); trow = tableDownloads.getRowSorter().convertRowIndexToModel(trow); getDlModData(); canDownloadMod = true; } }); tableDownloads.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { trow = tableDownloads.getSelectedRow(); trow = tableDownloads.getRowSorter().convertRowIndexToModel(trow); getDlModData(); canDownloadMod = true; } }); tableDownloads.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); tableDownloads.setShowVerticalLines(true); tableDownloads.setShowHorizontalLines(true); tableDownloads.setModel(dlModel); tableDownloads.getColumnModel().getColumn(0).setPreferredWidth(218); tableDownloads.getColumnModel().getColumn(1).setPreferredWidth(97); tableDownloads.getColumnModel().getColumn(2).setPreferredWidth(77); scrollPane_3.setViewportView(tableDownloads); btnDownload = new JButton("Download"); btnDownload.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (canDownloadMod && !CurrentlyDownloading) { String dlUrl = getModDownloadUrl(); try { if (dlUrl.equals("") || dlUrl.equals(" ") || dlUrl == null) { con.log("Log", "No download link for mod, got... '" + dlUrl + "'"); } else { CurrentlyDownloading = true; CurrentDownload = new Download(new URL(dlUrl), McLauncher); } } catch (MalformedURLException e1) { con.log("Log", "Failed to download mod... No download URL?"); } } } }); btnDownload.setBounds(307, 308, 90, 28); panelDownloadMods.add(btnDownload); btnGotoMod = new JButton("Mod Page"); btnGotoMod.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { util.openWebpage(modPageUrl); } }); btnGotoMod.setEnabled(false); btnGotoMod.setBounds(134, 308, 90, 28); panelDownloadMods.add(btnGotoMod); pBarDownloadMod = new JProgressBar(); pBarDownloadMod.setBounds(538, 308, 150, 10); panelDownloadMods.add(pBarDownloadMod); pBarExtractMod = new JProgressBar(); pBarExtractMod.setBounds(538, 314, 150, 10); panelDownloadMods.add(pBarExtractMod); lblDownloadModInfo = new JLabel("Download progress"); lblDownloadModInfo.setBounds(489, 326, 199, 16); panelDownloadMods.add(lblDownloadModInfo); lblDownloadModInfo.setHorizontalAlignment(SwingConstants.TRAILING); panelModImg = new JPanel(); panelModImg.setBounds(566, 0, 128, 128); panelDownloadMods.add(panelModImg); txtFilterText = new JTextField(); txtFilterText.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { if (txtFilterText.getText().equals("Filter Text")) { txtFilterText.setText(""); newFilter(); } } }); txtFilterText.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (!txtFilterText.getText().equals("Filter Text")) { newFilter(); } } }); txtFilterText.setText("Filter Text"); txtFilterText.setBounds(0, 308, 122, 28); panelDownloadMods.add(txtFilterText); txtFilterText.setColumns(10); comboBox = new JComboBox(); comboBox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { newFilter(); } }); comboBox.setModel(new DefaultComboBoxModel(new String[] { "No tag filter", "Vanilla", "Machine", "Mechanic", "New Ore", "Module", "Big Mod", "Power", "GUI", "Map-Gen", "Must-Have", "Equipment" })); comboBox.setBounds(403, 44, 150, 26); panelDownloadMods.add(comboBox); lblModDlCounter = new JLabel("Mod database: "); lblModDlCounter.setFont(new Font("SansSerif", Font.PLAIN, 10)); lblModDlCounter.setBounds(403, 5, 162, 16); panelDownloadMods.add(lblModDlCounter); txtrDMModDescription = new JTextArea(); txtrDMModDescription.setBackground(Color.LIGHT_GRAY); txtrDMModDescription.setBorder(new LineBorder(new Color(0, 0, 0))); txtrDMModDescription.setFocusable(false); txtrDMModDescription.setEditable(false); txtrDMModDescription.setLineWrap(true); txtrDMModDescription.setWrapStyleWord(true); txtrDMModDescription.setText("Mod Description: "); txtrDMModDescription.setBounds(403, 132, 285, 75); panelDownloadMods.add(txtrDMModDescription); lblDMModTags = new JTextArea(); lblDMModTags.setFocusable(false); lblDMModTags.setEditable(false); lblDMModTags.setBorder(new LineBorder(new Color(0, 0, 0))); lblDMModTags.setWrapStyleWord(true); lblDMModTags.setLineWrap(true); lblDMModTags.setBackground(Color.LIGHT_GRAY); lblDMModTags.setText("Mod Tags: "); lblDMModTags.setBounds(403, 71, 160, 60); panelDownloadMods.add(lblDMModTags); lblDMRequiredMods = new JTextArea(); lblDMRequiredMods.setFocusable(false); lblDMRequiredMods.setEditable(false); lblDMRequiredMods.setText("Required Mods: "); lblDMRequiredMods.setWrapStyleWord(true); lblDMRequiredMods.setLineWrap(true); lblDMRequiredMods.setBorder(new LineBorder(new Color(0, 0, 0))); lblDMRequiredMods.setBackground(Color.LIGHT_GRAY); lblDMRequiredMods.setBounds(403, 208, 285, 57); panelDownloadMods.add(lblDMRequiredMods); lblDLModLicense = new JLabel(""); lblDLModLicense.setHorizontalAlignment(SwingConstants.RIGHT); lblDLModLicense.setBounds(403, 294, 285, 16); panelDownloadMods.add(lblDLModLicense); lblWipmod = new JLabel(""); lblWipmod.setBounds(395, 314, 64, 16); panelDownloadMods.add(lblWipmod); JButton btnCancel = new JButton("Cancel"); btnCancel.setToolTipText("Stop downloading"); btnCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { CurrentDownload.cancel(); } }); btnCancel.setBounds(230, 308, 72, 28); panelDownloadMods.add(btnCancel); panelOptions = new JPanel(); tabbedPane.addTab("Options", null, panelOptions, null); panelOptions.setLayout(null); scrollPane_4.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane_4.setBounds(0, 0, 694, 342); panelOptions.add(scrollPane_4); panel = new JPanel(); scrollPane_4.setViewportView(panel); panel.setLayout(null); lblCloseMclauncherAfter = new JLabel("Close McLauncher after launching Factorio?"); lblCloseMclauncherAfter.setBounds(6, 6, 274, 16); panel.add(lblCloseMclauncherAfter); lblCloseMclauncherAfter_1 = new JLabel("Close McLauncher after updating?"); lblCloseMclauncherAfter_1.setBounds(6, 34, 274, 16); panel.add(lblCloseMclauncherAfter_1); lblSortNewestDownloadable = new JLabel("Sort newest downloadable mods first?"); lblSortNewestDownloadable.setBounds(6, 62, 274, 16); panel.add(lblSortNewestDownloadable); tglbtnNewModsFirst = new JToggleButton("Toggle"); tglbtnNewModsFirst.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { lblNeedrestart.setText("McLauncher needs to restart for that to work"); writeData(); } }); tglbtnNewModsFirst.setSelected(true); tglbtnNewModsFirst.setBounds(281, 56, 66, 28); panel.add(tglbtnNewModsFirst); tglbtnCloseAfterUpdate = new JToggleButton("Toggle"); tglbtnCloseAfterUpdate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { writeData(); } }); tglbtnCloseAfterUpdate.setBounds(281, 28, 66, 28); panel.add(tglbtnCloseAfterUpdate); tglbtnCloseAfterLaunch = new JToggleButton("Toggle"); tglbtnCloseAfterLaunch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { writeData(); } }); tglbtnCloseAfterLaunch.setBounds(281, 0, 66, 28); panel.add(tglbtnCloseAfterLaunch); tglbtnDisplayon = new JToggleButton("On"); tglbtnDisplayon.setFont(new Font("SansSerif", Font.PLAIN, 10)); tglbtnDisplayon.setSelected(true); tglbtnDisplayon.setBounds(588, 308, 44, 28); panel.add(tglbtnDisplayon); tglbtnDisplayoff = new JToggleButton("Off"); tglbtnDisplayoff.setFont(new Font("SansSerif", Font.PLAIN, 10)); tglbtnDisplayoff.setBounds(644, 308, 44, 28); panel.add(tglbtnDisplayoff); lblInfo = new JLabel("What enabled and disabled look like"); lblInfo.setFont(new Font("SansSerif", Font.PLAIN, 10)); lblInfo.setHorizontalAlignment(SwingConstants.TRAILING); lblInfo.setBounds(359, 314, 231, 16); panel.add(lblInfo); JSeparator separator = new JSeparator(); separator.setBounds(6, 55, 676, 24); panel.add(separator); JSeparator separator_1 = new JSeparator(); separator_1.setBounds(6, 27, 676, 18); panel.add(separator_1); JSeparator separator_2 = new JSeparator(); separator_2.setBounds(6, 84, 676, 24); panel.add(separator_2); JSeparator separator_3 = new JSeparator(); separator_3.setOrientation(SwingConstants.VERTICAL); separator_3.setBounds(346, 0, 16, 336); panel.add(separator_3); lblNeedrestart = new JLabel(""); lblNeedrestart.setBounds(6, 314, 341, 16); panel.add(lblNeedrestart); tglbtnSendAnonData = new JToggleButton("Toggle"); tglbtnSendAnonData.setToolTipText("Information regarding the activity of McLauncher."); tglbtnSendAnonData.setSelected(true); //set enabled by default. tglbtnSendAnonData.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { writeData(); } }); tglbtnSendAnonData.setBounds(622, 0, 66, 28); panel.add(tglbtnSendAnonData); lblSendAnonymousUse = new JLabel("Send anonymous use data?"); lblSendAnonymousUse.setBounds(359, 6, 251, 16); panel.add(lblSendAnonymousUse); lblDeleteOldMod = new JLabel("Delete old mod before updating?"); lblDeleteOldMod.setBounds(359, 34, 251, 16); panel.add(lblDeleteOldMod); tglbtnDeleteBeforeUpdate = new JToggleButton("Toggle"); tglbtnDeleteBeforeUpdate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { writeData(); } }); tglbtnDeleteBeforeUpdate.setBounds(622, 28, 66, 28); panel.add(tglbtnDeleteBeforeUpdate); tglbtnAlertOnModUpdateAvailable = new JToggleButton("Toggle"); tglbtnAlertOnModUpdateAvailable.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { writeData(); } }); tglbtnAlertOnModUpdateAvailable.setSelected(true); tglbtnAlertOnModUpdateAvailable.setBounds(281, 86, 66, 28); panel.add(tglbtnAlertOnModUpdateAvailable); separator_4 = new JSeparator(); separator_4.setBounds(0, 112, 676, 24); panel.add(separator_4); JLabel lblAlertModHas = new JLabel("Alert mod has update on launch?"); lblAlertModHas.setBounds(6, 92, 231, 16); panel.add(lblAlertModHas); panelChangelog = new JPanel(); tabbedPane.addTab("Changelog", null, panelChangelog, null); panelChangelog.setLayout(new BoxLayout(panelChangelog, BoxLayout.X_AXIS)); scrollPane_6 = new JScrollPane(); panelChangelog.add(scrollPane_6); textChangelog = new JTextArea(); scrollPane_6.setViewportView(textChangelog); textChangelog.setEditable(false); textChangelog.setText( "v0.4.6\r\n\r\n+Fix problem where config file would not save in the correct location. (Thanks Arano-kai)\r\n+McLauncher will now save when you select a path, or profile. (Thanks Arano-kai)\r\n+Fixed an issue where McLauncher could not get the version from a .zip mod. (Thanks Arano-kai)\r\n+Added a Cancel button to stop downloading the current mod. (Suggested by Arano-kai)\r\n\r\n\r\n\r\nv0.4.5\r\n\r\n+McLauncher should now correctly warn you on failed write/read access.\r\n+McLauncher should now work when a user has both zip and installer versions of factorio. (Thanks Jeroon)\r\n+Attempt to fix an error with dependency and .zip files, With versions. (Thanks Arano-kai)\r\n+Fix only allow single selection of mods. (Thanks Arano-kai)\r\n+Fix for the Launch+Ignore button problem on linux being cut off. (Thanks Arano-kai)\r\n+Display download progress.\r\n+Fixed an error that was thrown when clicking on some mods that had a single dependency mod.\r\n+Double clicking on a mod will now enable or disable the mod. (Thanks Arano-kai)"); btnLaunchIgnore.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (selProfile != null) { LaunchFactorioWithSelectedMods(true); //ignore errors, launch. } } }); btnLaunchIgnore.setVisible(false); //This is my test button. I use this to test things then implement them into the swing. btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { testButtonCode(e); } }); //Disable mods button. (from profile) btnDisable.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { removeMod(); } }); //Enable mods button. (to profile) btnEnable.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addMod(); } }); //Game path button btnFind.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { findPath(); } }); //mouseClick event lister for when you click on a new profile profileList.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { selectedProfile(); } }); readData(); //Load settings init(); //some extra init getMods(); //Get the mods the user has installed }