mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Added dialog for specifying URL of library to install.
This commit is contained in:
@@ -74,6 +74,9 @@ public class Base {
|
||||
|
||||
// A single instance of the preferences window
|
||||
Preferences preferencesFrame;
|
||||
|
||||
// A single instance of the library manager window
|
||||
LibraryManager libraryManagerFrame;
|
||||
|
||||
// set to true after the first time the menu is built.
|
||||
// so that the errors while building don't show up again.
|
||||
@@ -1388,7 +1391,14 @@ public class Base {
|
||||
if (preferencesFrame == null) preferencesFrame = new Preferences();
|
||||
preferencesFrame.showFrame(activeEditor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the library installer window.
|
||||
*/
|
||||
public void handleAddOrRemoveLibrary() {
|
||||
if (libraryManagerFrame == null) libraryManagerFrame = new LibraryManager();
|
||||
libraryManagerFrame.showFrame(activeEditor);
|
||||
}
|
||||
|
||||
// ...................................................................
|
||||
|
||||
|
||||
@@ -763,7 +763,15 @@ public abstract class Editor extends JFrame implements RunnerListener {
|
||||
sketchMenu.addSeparator();
|
||||
|
||||
sketchMenu.add(mode.getImportMenu());
|
||||
|
||||
|
||||
item = new JMenuItem("Install Library...");
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
base.handleAddOrRemoveLibrary();
|
||||
}
|
||||
});
|
||||
sketchMenu.add(item);
|
||||
|
||||
item = Base.newJMenuItem("Show Sketch Folder", 'K');
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
|
||||
|
||||
/*
|
||||
Part of the Processing project - http://processing.org
|
||||
|
||||
Copyright (c) 2004-09 Ben Fry and Casey Reas
|
||||
Copyright (c) 2001-04 Massachusetts Institute of Technology
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package processing.app;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import processing.app.syntax.*;
|
||||
import processing.core.*;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class LibraryManager {
|
||||
|
||||
JFrame dialog;
|
||||
|
||||
JLabel uriLabel;
|
||||
JTextField libraryUri;
|
||||
JButton installButton;
|
||||
|
||||
// the calling editor, so updates can be applied
|
||||
|
||||
Editor editor;
|
||||
|
||||
public LibraryManager() {
|
||||
|
||||
// setup dialog for the prefs
|
||||
|
||||
//dialog = new JDialog(editor, "Preferences", true);
|
||||
dialog = new JFrame("Library Manager");
|
||||
dialog.setResizable(true);
|
||||
|
||||
Base.setIcon(dialog);
|
||||
|
||||
uriLabel = new JLabel("Library URI:");
|
||||
libraryUri = new JTextField(40);
|
||||
installButton = new JButton("Install");
|
||||
|
||||
ActionListener installLibAction = new ActionListener() {
|
||||
|
||||
public void actionPerformed(ActionEvent arg) {
|
||||
try {
|
||||
URI uri = new URI(libraryUri.getText());
|
||||
System.out.println("Installing library: " + uri);
|
||||
} catch (URISyntaxException e) {
|
||||
System.err.println("Malformed URI");
|
||||
}
|
||||
libraryUri.setText("");
|
||||
}
|
||||
};
|
||||
libraryUri.addActionListener(installLibAction);
|
||||
installButton.addActionListener(installLibAction);
|
||||
|
||||
Container pane = dialog.getContentPane();
|
||||
BoxLayout boxLayout = new BoxLayout(pane, BoxLayout.Y_AXIS);
|
||||
pane.setLayout(boxLayout);
|
||||
|
||||
Box horizontal = Box.createHorizontalBox();
|
||||
horizontal.add(Box.createVerticalStrut(2));
|
||||
horizontal.add(uriLabel);
|
||||
uriLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
horizontal.add(Box.createVerticalStrut(5));
|
||||
|
||||
horizontal.add(libraryUri);
|
||||
horizontal.add(installButton);
|
||||
|
||||
pane.add(horizontal);
|
||||
|
||||
dialog.pack();
|
||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
dialog.setLocation((screen.width - dialog.getWidth()) / 2,
|
||||
(screen.height - dialog.getHeight()) / 2);
|
||||
}
|
||||
|
||||
protected void showFrame(Editor editor) {
|
||||
this.editor = editor;
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user