List of usage examples for javax.swing.text DefaultEditorKit copyAction
String copyAction
To view the source code for javax.swing.text DefaultEditorKit copyAction.
Click Source Link
From source file:TextCutPaste.java
/** * Create an Edit menu to support cut/copy/paste. *///w w w . ja v a2 s . co m public JMenuBar createMenuBar() { JMenuItem menuItem = null; JMenuBar menuBar = new JMenuBar(); JMenu mainMenu = new JMenu("Edit"); mainMenu.setMnemonic(KeyEvent.VK_E); menuItem = new JMenuItem(new DefaultEditorKit.CutAction()); menuItem.setText("Cut"); menuItem.setMnemonic(KeyEvent.VK_T); mainMenu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.CopyAction()); menuItem.setText("Copy"); menuItem.setMnemonic(KeyEvent.VK_C); mainMenu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.PasteAction()); menuItem.setText("Paste"); menuItem.setMnemonic(KeyEvent.VK_P); mainMenu.add(menuItem); menuBar.add(mainMenu); return menuBar; }
From source file:com.mirth.connect.client.ui.Mirth.java
/** * Create the alternate key bindings for the menu shortcut key mask. This is called if the menu * shortcut key mask is not the CTRL key (i.e. COMMAND on OSX) */// w w w. j a va 2s . co m private static void createAlternateKeyBindings() { int acceleratorKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); // Add the common KeyBindings for macs KeyBinding[] defaultBindings = { new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_C, acceleratorKey), DefaultEditorKit.copyAction), new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_V, acceleratorKey), DefaultEditorKit.pasteAction), new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_X, acceleratorKey), DefaultEditorKit.cutAction), new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_A, acceleratorKey), DefaultEditorKit.selectAllAction), // deleteNextWordAction and deletePrevWordAction were not available in Java 1.5 new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, acceleratorKey), DefaultEditorKit.deleteNextWordAction), new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, acceleratorKey), DefaultEditorKit.deletePrevWordAction), new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, acceleratorKey), DefaultEditorKit.nextWordAction), new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT, acceleratorKey), DefaultEditorKit.nextWordAction), new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, acceleratorKey), DefaultEditorKit.previousWordAction), new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT, acceleratorKey), DefaultEditorKit.previousWordAction), new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, acceleratorKey | InputEvent.SHIFT_MASK), DefaultEditorKit.selectionNextWordAction), new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT, acceleratorKey | InputEvent.SHIFT_MASK), DefaultEditorKit.selectionNextWordAction), new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, acceleratorKey | InputEvent.SHIFT_MASK), DefaultEditorKit.selectionPreviousWordAction), new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT, acceleratorKey | InputEvent.SHIFT_MASK), DefaultEditorKit.selectionPreviousWordAction) }; keyMapBindings(new javax.swing.JTextField(), defaultBindings); keyMapBindings(new javax.swing.JPasswordField(), defaultBindings); keyMapBindings(new javax.swing.JTextPane(), defaultBindings); keyMapBindings(new javax.swing.JTextArea(), defaultBindings); keyMapBindings(new com.mirth.connect.client.ui.components.MirthTextField(), defaultBindings); keyMapBindings(new com.mirth.connect.client.ui.components.MirthPasswordField(), defaultBindings); keyMapBindings(new com.mirth.connect.client.ui.components.MirthTextPane(), defaultBindings); keyMapBindings(new com.mirth.connect.client.ui.components.MirthTextArea(), defaultBindings); }
From source file:net.sf.maltcms.chromaui.jmztab.ui.validation.MzTabValidationElement.java
public MzTabValidationElement(Lookup lkp) { obj = lkp.lookup(MzTabDataObject.class); assert obj != null; initComponents();//w ww. ja v a 2 s .c o m view = new OutlineView(); view.setQuickSearchAllowed(true); view.setTreeSortable(true); view.setPropertyColumns("message", "Message"); view.getOutline().setRootVisible(false); add(view, BorderLayout.CENTER); ActionMap map = this.getActionMap(); map.put(DefaultEditorKit.copyAction, ExplorerUtils.actionCopy(manager)); associateLookup(ExplorerUtils.createLookup(manager, map)); }
From source file:DragColorTextFieldDemo.java
public JMenuBar createMenuBar() { JMenuItem menuItem = null;/* www .j a v a 2s.com*/ JMenuBar menuBar = new JMenuBar(); JMenu mainMenu = new JMenu("Edit"); mainMenu.setMnemonic(KeyEvent.VK_E); menuItem = new JMenuItem(new DefaultEditorKit.CutAction()); menuItem.setText("Cut"); menuItem.setMnemonic(KeyEvent.VK_T); mainMenu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.CopyAction()); menuItem.setText("Copy"); menuItem.setMnemonic(KeyEvent.VK_C); mainMenu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.PasteAction()); menuItem.setText("Paste"); menuItem.setMnemonic(KeyEvent.VK_P); mainMenu.add(menuItem); menuBar.add(mainMenu); return menuBar; }
From source file:uk.ac.lkl.cram.ui.ModuleFrame.java
/** * Creates new form ModuleFrame/* w ww . ja v a 2s . c o m*/ * @param module the module that this window displays * @param file */ public ModuleFrame(final Module module, File file) { this.module = module; this.moduleFile = file; this.setTitle(module.getModuleName()); initComponents(); //Add undo mechanism undoHandler = new UndoHandler(); JMenuItem undoMI = editMenu.add(undoHandler.getUndoAction()); JMenuItem redoMI = editMenu.add(undoHandler.getRedoAction()); //Listen to the undo handler for when there is something to undo undoHandler.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { //We're assuming there's only one property //If the new value is true, then there's something to undo //And thus the save menu item should be enabled Boolean newValue = (Boolean) evt.getNewValue(); if (moduleFile != null) { saveMI.setEnabled(newValue); } } }); editMenu.addSeparator(); //Add cut, copy & paste menu items JMenuItem cutMI = editMenu.add(new JMenuItem(new DefaultEditorKit.CutAction())); cutMI.setText("Cut"); JMenuItem copyMI = editMenu.add(new JMenuItem(new DefaultEditorKit.CopyAction())); copyMI.setText("Copy"); JMenuItem pasteMI = editMenu.add(new JMenuItem(new DefaultEditorKit.PasteAction())); pasteMI.setText("Paste"); //Listen for changes to the shared selection model sharedSelectionModel.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { //Update the menu items modifyLineItemMI.setEnabled(evt.getNewValue() != null); removeLineItemMI.setEnabled(evt.getNewValue() != null); } }); doubleClickListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { //If the user double clicks, then treat this as a shortcut to modify the selected line item if (e.getClickCount() == 2) { modifySelectedLineItem(); } } }; //Set Accelerator keys undoMI.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); redoMI.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); cutMI.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); copyMI.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); pasteMI.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); newMI.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); openMI.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); saveMI.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); quitMI.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); //Remove quit menu item and separator from file menu on Mac if (Utilities.isMac()) { fileMenu.remove(quitSeparator); fileMenu.remove(quitMI); } leftTaskPaneContainer.add(createCourseDataPane()); leftTaskPaneContainer.add(createLineItemPane()); leftTaskPaneContainer.add(createTutorHoursPane()); leftTaskPaneContainer.add(createTutorCostPane()); rightTaskPaneContainer.add(createLearningTypeChartPane()); rightTaskPaneContainer.add(createLearningExperienceChartPane()); rightTaskPaneContainer.add(createLearnerFeedbackChartPane()); rightTaskPaneContainer.add(createHoursChartPane()); rightTaskPaneContainer.add(createTotalCostsPane()); }
From source file:dmh.kuebiko.view.NoteStackFrame.java
/** * Create the frame./*from www .j a v a 2 s . co m*/ */ public NoteStackFrame(NoteManager noteMngr) { this.noteMngr = noteMngr; // Setup the various actions for the frame. noteMngr.addObserver(new Observer() { @Override public void update(Observable o, Object arg) { boolean stackChanged = (Boolean) arg; toggleUnsavedChangeIndicator(stackChanged); if (!stackChanged) { notePanel.getHuxleyUiManager().resetTextChanged(); } } }); ActionObserverUtil.registerEnMass(actionMngr, observable, new NewNoteAction(this), new OpenNoteAction(this), new DeleteNoteAction(this), new RenameNoteAction(this), new SaveStackAction(this)); // Build the menus. menuBar = new JMenuBar(); setJMenuBar(menuBar); fileMenu = new JMenu("File"); menuBar.add(fileMenu); newNoteMenuItem = new JMenuItem(actionMngr.getAction(NewNoteAction.class)); fileMenu.add(newNoteMenuItem); JMenuItem openNoteMenuItem = new JMenuItem(actionMngr.getAction(OpenNoteAction.class)); fileMenu.add(openNoteMenuItem); deleteNoteMenuItem = new JMenuItem(actionMngr.getAction(DeleteNoteAction.class)); fileMenu.add(deleteNoteMenuItem); renameNoteMenuItem = new JMenuItem(actionMngr.getAction(RenameNoteAction.class)); fileMenu.add(renameNoteMenuItem); fileMenu.addSeparator(); newStackMenuItem = new JMenuItem(actionMngr.getAction(NewStackAction.class)); fileMenu.add(newStackMenuItem); openStackMenuItem = new JMenuItem(actionMngr.getAction(OpenStackAction.class)); fileMenu.add(openStackMenuItem); fileMenu.addSeparator(); closeMenuItem = new JMenuItem("Close"); closeMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); closeMenuItem.setEnabled(false); fileMenu.add(closeMenuItem); closeAllMenuItem = new JMenuItem("Close All"); closeAllMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.SHIFT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); closeAllMenuItem.setEnabled(false); fileMenu.add(closeAllMenuItem); fileMenu.addSeparator(); saveMenuItem = new JMenuItem(actionMngr.getAction(SaveStackAction.class)); fileMenu.add(saveMenuItem); saveAllMenuItem = new JMenuItem("Save All"); saveAllMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.SHIFT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); saveAllMenuItem.setEnabled(false); fileMenu.add(saveAllMenuItem); editMenu = new JMenu("Edit"); menuBar.add(editMenu); undoMenuItem = new JMenuItem("Undo"); undoMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); editMenu.add(undoMenuItem); redoMenuItem = new JMenuItem("Redo"); // FIXME mac-specific keyboard shortcut redoMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.SHIFT_MASK | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); editMenu.add(redoMenuItem); editMenu.addSeparator(); cutMenuItem = new JMenuItem(actionMngr.getAction(DefaultEditorKit.CutAction.class)); cutMenuItem.setText("Cut"); cutMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); editMenu.add(cutMenuItem); copyMenuItem = new JMenuItem(actionMngr.getAction(DefaultEditorKit.CopyAction.class)); copyMenuItem.setText("Copy"); copyMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); editMenu.add(copyMenuItem); pasteMenuItem = new JMenuItem(actionMngr.getAction(DefaultEditorKit.PasteAction.class)); pasteMenuItem.setText("Paste"); pasteMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); editMenu.add(pasteMenuItem); textMenu = new JMenu("Text"); menuBar.add(textMenu); JMenu windowMenu = new JMenu("Window"); menuBar.add(windowMenu); initialize(); additionalSetup(); }
From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java
/** * Helper method to add a contextual menu on a text component that will allow for Copy & Select All text actions. *///from w ww .j a va 2 s.c o m protected void addCopyMenu(final JTextComponent component) { Preconditions.checkNotNull(component); if (!component.isEditable()) { component.setCursor(new Cursor(Cursor.TEXT_CURSOR)); } final JPopupMenu contextMenu = new JPopupMenu(); JMenuItem copy = new JMenuItem(component.getActionMap().get(DefaultEditorKit.copyAction)); copy.setText(i18n.getString(I18n.TEXT_COPY_ID)); contextMenu.add(copy); contextMenu.addSeparator(); JMenuItem selectAll = new JMenuItem(component.getActionMap().get(DefaultEditorKit.selectAllAction)); selectAll.setText(i18n.getString(I18n.TEXT_SELECT_ALL_ID)); contextMenu.add(selectAll); component.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { contextMenu.show(component, e.getX(), e.getY()); } } }); }
From source file:TextComponentDemo.java
protected JMenu createEditMenu() { JMenu menu = new JMenu("Edit"); // Undo and redo are actions of our own creation. undoAction = new UndoAction(); menu.add(undoAction);// www . j a v a2 s .c om redoAction = new RedoAction(); menu.add(redoAction); menu.addSeparator(); // These actions come from the default editor kit. // Get the ones we want and stick them in the menu. menu.add(getActionByName(DefaultEditorKit.cutAction)); menu.add(getActionByName(DefaultEditorKit.copyAction)); menu.add(getActionByName(DefaultEditorKit.pasteAction)); menu.addSeparator(); menu.add(getActionByName(DefaultEditorKit.selectAllAction)); return menu; }
From source file:TextComponentDemo.java
protected JMenu createEditMenu() { JMenu menu = new JMenu("Edit"); //Undo and redo are actions of our own creation. undoAction = new UndoAction(); menu.add(undoAction);//from w ww .j a v a 2 s. c o m redoAction = new RedoAction(); menu.add(redoAction); menu.addSeparator(); //These actions come from the default editor kit. //Get the ones we want and stick them in the menu. menu.add(getActionByName(DefaultEditorKit.cutAction)); menu.add(getActionByName(DefaultEditorKit.copyAction)); menu.add(getActionByName(DefaultEditorKit.pasteAction)); menu.addSeparator(); menu.add(getActionByName(DefaultEditorKit.selectAllAction)); return menu; }
From source file:com.nbt.TreeFrame.java
private void createActions() { newAction = new NBTAction("New", "New", "New", KeyEvent.VK_N) { {// w ww. ja va 2 s . co m putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('N', Event.CTRL_MASK)); } @Override public void actionPerformed(ActionEvent e) { updateTreeTable(new CompoundTag("")); } }; browseAction = new NBTAction("Browse...", "Open", "Browse...", KeyEvent.VK_O) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('O', Event.CTRL_MASK)); } @Override public void actionPerformed(ActionEvent e) { JFileChooser fc = createFileChooser(); switch (fc.showOpenDialog(TreeFrame.this)) { case JFileChooser.APPROVE_OPTION: File file = fc.getSelectedFile(); Preferences prefs = getPreferences(); prefs.put(KEY_FILE, file.getAbsolutePath()); doImport(file); break; } } }; saveAction = new NBTAction("Save", "Save", "Save", KeyEvent.VK_S) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('S', Event.CTRL_MASK)); } @Override public void actionPerformed(ActionEvent e) { String path = textFile.getText(); File file = new File(path); if (file.canWrite()) { doExport(file); } else { saveAsAction.actionPerformed(e); } } }; saveAsAction = new NBTAction("Save As...", "SaveAs", "Save As...", KeyEvent.VK_UNDEFINED) { public void actionPerformed(ActionEvent e) { JFileChooser fc = createFileChooser(); switch (fc.showSaveDialog(TreeFrame.this)) { case JFileChooser.APPROVE_OPTION: File file = fc.getSelectedFile(); Preferences prefs = getPreferences(); prefs.put(KEY_FILE, file.getAbsolutePath()); doExport(file); break; } } }; refreshAction = new NBTAction("Refresh", "Refresh", "Refresh", KeyEvent.VK_F5) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("F5")); } public void actionPerformed(ActionEvent e) { String path = textFile.getText(); File file = new File(path); if (file.canRead()) doImport(file); else showErrorDialog("The file could not be read."); } }; exitAction = new NBTAction("Exit", "Exit", KeyEvent.VK_ESCAPE) { @Override public void actionPerformed(ActionEvent e) { // TODO: this should check to see if any changes have been made // before exiting System.exit(0); } }; cutAction = new DefaultEditorKit.CutAction() { { String name = "Cut"; putValue(NAME, name); putValue(SHORT_DESCRIPTION, name); putValue(MNEMONIC_KEY, KeyEvent.VK_X); putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('X', Event.CTRL_MASK)); ImageFactory factory = new ImageFactory(); try { putValue(SMALL_ICON, new ImageIcon(factory.readGeneralImage(name, NBTAction.smallIconSize))); } catch (IOException e) { e.printStackTrace(); } try { putValue(LARGE_ICON_KEY, new ImageIcon(factory.readGeneralImage(name, NBTAction.largeIconSize))); } catch (IOException e) { e.printStackTrace(); } } }; copyAction = new DefaultEditorKit.CopyAction() { { String name = "Copy"; putValue(NAME, name); putValue(SHORT_DESCRIPTION, name); putValue(MNEMONIC_KEY, KeyEvent.VK_C); putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('C', Event.CTRL_MASK)); ImageFactory factory = new ImageFactory(); try { putValue(SMALL_ICON, new ImageIcon(factory.readGeneralImage(name, NBTAction.smallIconSize))); } catch (IOException e) { e.printStackTrace(); } try { putValue(LARGE_ICON_KEY, new ImageIcon(factory.readGeneralImage(name, NBTAction.largeIconSize))); } catch (IOException e) { e.printStackTrace(); } } }; pasteAction = new DefaultEditorKit.CutAction() { { String name = "Paste"; putValue(NAME, name); putValue(SHORT_DESCRIPTION, name); putValue(MNEMONIC_KEY, KeyEvent.VK_V); putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('V', Event.CTRL_MASK)); ImageFactory factory = new ImageFactory(); try { putValue(SMALL_ICON, new ImageIcon(factory.readGeneralImage(name, NBTAction.smallIconSize))); } catch (IOException e) { e.printStackTrace(); } try { putValue(LARGE_ICON_KEY, new ImageIcon(factory.readGeneralImage(name, NBTAction.largeIconSize))); } catch (IOException e) { e.printStackTrace(); } } }; deleteAction = new NBTAction("Delete", "Delete", "Delete", KeyEvent.VK_DELETE) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("DELETE")); } public void actionPerformed(ActionEvent e) { int row = treeTable.getSelectedRow(); TreePath path = treeTable.getPathForRow(row); Object last = path.getLastPathComponent(); if (last instanceof NBTFileBranch) { NBTFileBranch branch = (NBTFileBranch) last; File file = branch.getFile(); String name = file.getName(); String message = "Are you sure you want to delete " + name + "?"; String title = "Continue?"; int option = JOptionPane.showConfirmDialog(TreeFrame.this, message, title, JOptionPane.OK_CANCEL_OPTION); switch (option) { case JOptionPane.CANCEL_OPTION: return; } if (!FileUtils.deleteQuietly(file)) { showErrorDialog(name + " could not be deleted."); return; } } TreePath parentPath = path.getParentPath(); Object parentLast = parentPath.getLastPathComponent(); NBTTreeTableModel model = treeTable.getTreeTableModel(); int index = model.getIndexOfChild(parentLast, last); if (parentLast instanceof Mutable<?>) { Mutable<?> mutable = (Mutable<?>) parentLast; if (last instanceof ByteWrapper) { ByteWrapper wrapper = (ByteWrapper) last; index = wrapper.getIndex(); } mutable.remove(index); } else { System.err.println(last.getClass()); return; } updateTreeTable(); treeTable.expandPath(parentPath); scrollTo(parentLast); treeTable.setRowSelectionInterval(row, row); } }; openAction = new NBTAction("Open...", "Open...", KeyEvent.VK_T) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('T', Event.CTRL_MASK)); final int diamondPickaxe = 278; SpriteRecord record = NBTTreeTable.register.getRecord(diamondPickaxe); BufferedImage image = record.getImage(); setSmallIcon(image); int width = 24, height = 24; Dimension size = new Dimension(width, height); Map<RenderingHints.Key, ?> hints = Thumbnail.createRenderingHints(Thumbnail.QUALITY); BufferedImage largeImage = Thumbnail.createThumbnail(image, size, hints); setLargeIcon(largeImage); } public void actionPerformed(ActionEvent e) { TreePath path = treeTable.getPath(); if (path == null) return; Object last = path.getLastPathComponent(); if (last instanceof Region) { Region region = (Region) last; createAndShowTileCanvas(new TileCanvas.TileWorld(region)); return; } else if (last instanceof World) { World world = (World) last; createAndShowTileCanvas(world); return; } if (last instanceof NBTFileBranch) { NBTFileBranch fileBranch = (NBTFileBranch) last; File file = fileBranch.getFile(); try { open(file); } catch (IOException ex) { ex.printStackTrace(); showErrorDialog(ex.getMessage()); } } } private void open(File file) throws IOException { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) { desktop.open(file); } } } }; addByteAction = new NBTAction("Add Byte", NBTConstants.TYPE_BYTE, "Add Byte", KeyEvent.VK_1) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('1', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new ByteTag("new byte", (byte) 0)); } }; addShortAction = new NBTAction("Add Short", NBTConstants.TYPE_SHORT, "Add Short", KeyEvent.VK_2) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('2', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new ShortTag("new short", (short) 0)); } }; addIntAction = new NBTAction("Add Integer", NBTConstants.TYPE_INT, "Add Integer", KeyEvent.VK_3) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('3', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new IntTag("new int", 0)); } }; addLongAction = new NBTAction("Add Long", NBTConstants.TYPE_LONG, "Add Long", KeyEvent.VK_4) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('4', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new LongTag("new long", 0)); } }; addFloatAction = new NBTAction("Add Float", NBTConstants.TYPE_FLOAT, "Add Float", KeyEvent.VK_5) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('5', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new FloatTag("new float", 0)); } }; addDoubleAction = new NBTAction("Add Double", NBTConstants.TYPE_DOUBLE, "Add Double", KeyEvent.VK_6) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('6', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new DoubleTag("new double", 0)); } }; addByteArrayAction = new NBTAction("Add Byte Array", NBTConstants.TYPE_BYTE_ARRAY, "Add Byte Array", KeyEvent.VK_7) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('7', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new ByteArrayTag("new byte array")); } }; addStringAction = new NBTAction("Add String", NBTConstants.TYPE_STRING, "Add String", KeyEvent.VK_8) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('8', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new StringTag("new string", "...")); } }; addListAction = new NBTAction("Add List Tag", NBTConstants.TYPE_LIST, "Add List Tag", KeyEvent.VK_9) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('9', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { Class<? extends Tag> type = queryType(); if (type != null) addTag(new ListTag("new list", null, type)); } private Class<? extends Tag> queryType() { Object[] items = { NBTConstants.TYPE_BYTE, NBTConstants.TYPE_SHORT, NBTConstants.TYPE_INT, NBTConstants.TYPE_LONG, NBTConstants.TYPE_FLOAT, NBTConstants.TYPE_DOUBLE, NBTConstants.TYPE_BYTE_ARRAY, NBTConstants.TYPE_STRING, NBTConstants.TYPE_LIST, NBTConstants.TYPE_COMPOUND }; JComboBox comboBox = new JComboBox(new DefaultComboBoxModel(items)); comboBox.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof Integer) { Integer i = (Integer) value; Class<? extends Tag> c = NBTUtils.getTypeClass(i); String name = NBTUtils.getTypeName(c); setText(name); } return this; } }); Object[] message = { new JLabel("Please select a type."), comboBox }; String title = "Title goes here"; int result = JOptionPane.showOptionDialog(TreeFrame.this, message, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); switch (result) { case JOptionPane.OK_OPTION: ComboBoxModel model = comboBox.getModel(); Object item = model.getSelectedItem(); if (item instanceof Integer) { Integer i = (Integer) item; return NBTUtils.getTypeClass(i); } } return null; } }; addCompoundAction = new NBTAction("Add Compound Tag", NBTConstants.TYPE_COMPOUND, "Add Compound Tag", KeyEvent.VK_0) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke('0', Event.CTRL_MASK)); } public void actionPerformed(ActionEvent e) { addTag(new CompoundTag()); } }; String name = "About " + TITLE; helpAction = new NBTAction(name, "Help", name, KeyEvent.VK_F1) { { putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("F1")); } public void actionPerformed(ActionEvent e) { Object[] message = { new JLabel(TITLE + " " + VERSION), new JLabel("\u00A9 Copyright Taggart Spilman 2011. All rights reserved."), new Hyperlink("<html><a href=\"#\">NamedBinaryTag.com</a></html>", "http://www.namedbinarytag.com"), new Hyperlink("<html><a href=\"#\">Contact</a></html>", "mailto:tagadvance@gmail.com"), new JLabel(" "), new Hyperlink("<html><a href=\"#\">JNBT was written by Graham Edgecombe</a></html>", "http://jnbt.sf.net"), new Hyperlink("<html><a href=\"#\">Available open-source under the BSD license</a></html>", "http://jnbt.sourceforge.net/LICENSE.TXT"), new JLabel(" "), new JLabel("This product includes software developed by"), new Hyperlink("<html><a href=\"#\">The Apache Software Foundation</a>.</html>", "http://www.apache.org"), new JLabel(" "), new JLabel("Default texture pack:"), new Hyperlink("<html><a href=\"#\">SOLID COLOUR. SOLID STYLE.</a></html>", "http://www.minecraftforum.net/topic/72253-solid-colour-solid-style/"), new JLabel("Bundled with the permission of Trigger_Proximity."), }; String title = "About"; JOptionPane.showMessageDialog(TreeFrame.this, message, title, JOptionPane.INFORMATION_MESSAGE); } }; }