refactor drop down button to avoid 3 libs

service API
This commit is contained in:
bancika
2016-10-21 17:08:27 +02:00
parent 05207700fe
commit eef4988177
36 changed files with 2769 additions and 104 deletions
@@ -8,6 +8,7 @@
<classpathentry kind="lib" path="lib/app-framework.jar"/> <classpathentry kind="lib" path="lib/app-framework.jar"/>
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/> <classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/> <classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/>
<classpathentry kind="lib" path="lib/http-proxy.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_45"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_45"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
@@ -1,10 +1,8 @@
package org.diylc.swing.plugins.online.presenter; package org.diylc.swing.plugins.online.model;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import org.diylc.swing.plugins.online.model.ProjectEntity;
import com.diyfever.httpproxy.ParamName; import com.diyfever.httpproxy.ParamName;
/*** /***
@@ -123,7 +121,7 @@ public interface ServiceAPI {
@ParamName("diylcVersion") String diylcVersion, @ParamName("diylcVersion") String diylcVersion,
@ParamName("keywords") String keywords, @ParamName("keywords") String keywords,
@ParamName("thumbnail") File thumbnail, @ParamName("thumbnail") File thumbnail,
@ParamName("thumbnail") File project); @ParamName("project") File project);
/** /**
* @return a {@link List} of available categories. * @return a {@link List} of available categories.
@@ -0,0 +1,134 @@
package org.diylc.swing.plugins.online.model;
import java.io.Serializable;
public class UserEntity implements Serializable {
private static final long serialVersionUID = 1L;
private int id;
private String userName;
private String password;
private String email;
private String website;
private String bio;
public UserEntity(int id, String userName, String password, String email,
String website, String bio) {
super();
this.id = id;
this.userName = userName;
this.password = password;
this.email = email;
this.website = website;
this.bio = bio;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
public String getBio() {
return bio;
}
public void setBio(String bio) {
this.bio = bio;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((bio == null) ? 0 : bio.hashCode());
result = prime * result + ((email == null) ? 0 : email.hashCode());
result = prime * result + id;
result = prime * result
+ ((password == null) ? 0 : password.hashCode());
result = prime * result
+ ((userName == null) ? 0 : userName.hashCode());
result = prime * result + ((website == null) ? 0 : website.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
UserEntity other = (UserEntity) obj;
if (bio == null) {
if (other.bio != null)
return false;
} else if (!bio.equals(other.bio))
return false;
if (email == null) {
if (other.email != null)
return false;
} else if (!email.equals(other.email))
return false;
if (id != other.id)
return false;
if (password == null) {
if (other.password != null)
return false;
} else if (!password.equals(other.password))
return false;
if (userName == null) {
if (other.userName != null)
return false;
} else if (!userName.equals(other.userName))
return false;
if (website == null) {
if (other.website != null)
return false;
} else if (!website.equals(other.website))
return false;
return true;
}
@Override
public String toString() {
return "UserEntity [userName=" + userName + "]";
}
}
@@ -0,0 +1,63 @@
package org.diylc.swing.plugins.online.presenter;
import java.net.InetAddress;
import java.net.NetworkInterface;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.swing.plugins.online.model.ServiceAPI;
import com.diyfever.httpproxy.PhpFlatProxy;
import com.diyfever.httpproxy.ProxyFactory;
public class OnlinePresenter {
private final static Logger LOG = Logger.getLogger(OnlinePresenter.class);
private ServiceAPI service;
private String serviceUrl;
private String machineId;
public OnlinePresenter() {
serviceUrl = ConfigurationManager.getInstance().readString(
ServiceAPI.URL_KEY, "http://www.diy-fever.com/diylc/api");
ProxyFactory factory = new ProxyFactory(new PhpFlatProxy());
service = factory.createProxy(ServiceAPI.class, serviceUrl);
}
public boolean login(String username, String password) {
String res = service.login(username, password, getMachineId());
if (res.equals("Error"))
{
return false;
}
else {
return true;
}
}
public String getMachineId() {
if (machineId == null) {
try {
InetAddress ip = InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface
.getByInetAddress(ip);
byte[] mac = network.getHardwareAddress();
StringBuilder sb = new StringBuilder(18);
for (byte b : mac) {
if (sb.length() > 0)
sb.append(':');
sb.append(String.format("%02x", b));
}
machineId = sb.toString();
} catch (Exception e) {
machineId = "Generic";
}
}
return machineId;
}
}
@@ -8,9 +8,6 @@
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/> <classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/poi-3.5-FINAL-20090928.jar"/> <classpathentry kind="lib" path="lib/poi-3.5-FINAL-20090928.jar"/>
<classpathentry kind="lib" path="library/main.jar" sourcepath="/diylc-library"/> <classpathentry kind="lib" path="library/main.jar" sourcepath="/diylc-library"/>
<classpathentry kind="lib" path="lib/org-openide-awt.jar"/>
<classpathentry kind="lib" path="lib/org-openide-util.jar"/>
<classpathentry kind="lib" path="lib/org-openide-util-lookup.jar"/>
<classpathentry kind="lib" path="lib/app-framework.jar"/> <classpathentry kind="lib" path="lib/app-framework.jar"/>
<classpathentry kind="lib" path="lib/swing-framework.jar"/> <classpathentry kind="lib" path="lib/swing-framework.jar"/>
<classpathentry kind="lib" path="lib/http-proxy.jar"/> <classpathentry kind="lib" path="lib/http-proxy.jar"/>
@@ -1 +1,2 @@
/bin/ /bin/
/.apt_generated
@@ -39,7 +39,7 @@ public enum IconLoader {
"sort.png"), ElementsSelection("elements_selection.png"), BranchAdd( "sort.png"), ElementsSelection("elements_selection.png"), BranchAdd(
"branch_add.png"), BriefcaseAdd("briefcase_add.png"), BriefcaseInto( "branch_add.png"), BriefcaseAdd("briefcase_add.png"), BriefcaseInto(
"briefcase_into.png"), RotateCW("rotate_cw.png"), RotateCCW( "briefcase_into.png"), RotateCW("rotate_cw.png"), RotateCCW(
"rotate_ccw.png"), ElementInto("element_into.png"); "rotate_ccw.png"), ElementInto("element_into.png"), Arrow("arrow.png");
protected String name; protected String name;
Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

@@ -13,6 +13,7 @@ import org.diylc.common.PropertyWrapper;
import org.diylc.swing.gui.components.OverwritePromptFileChooser; import org.diylc.swing.gui.components.OverwritePromptFileChooser;
import org.diylc.swing.gui.editor.PropertyEditorDialog; import org.diylc.swing.gui.editor.PropertyEditorDialog;
import org.diylc.swing.plugins.file.BomDialog; import org.diylc.swing.plugins.file.BomDialog;
import org.diylc.swing.plugins.online.model.UserEntity;
import org.diylc.swing.plugins.online.view.LoginDialog; import org.diylc.swing.plugins.online.view.LoginDialog;
import org.diylc.swing.plugins.online.view.NewUserDialog; import org.diylc.swing.plugins.online.view.NewUserDialog;
import org.diylc.swing.plugins.online.view.UploadDialog; import org.diylc.swing.plugins.online.view.UploadDialog;
@@ -130,8 +131,8 @@ public class DialogFactory {
return dialog; return dialog;
} }
public NewUserDialog createNewUserDialog() { public NewUserDialog createNewUserDialog(UserEntity existingUser) {
NewUserDialog dialog = new NewUserDialog(mainFrame); NewUserDialog dialog = new NewUserDialog(mainFrame, existingUser);
return dialog; return dialog;
} }
@@ -56,6 +56,7 @@ import org.diylc.swing.plugins.file.FileFilterEnum;
import org.diylc.swing.plugins.file.FileMenuPlugin; import org.diylc.swing.plugins.file.FileMenuPlugin;
import org.diylc.swing.plugins.help.HelpMenuPlugin; import org.diylc.swing.plugins.help.HelpMenuPlugin;
import org.diylc.swing.plugins.layers.LayersMenuPlugin; import org.diylc.swing.plugins.layers.LayersMenuPlugin;
import org.diylc.swing.plugins.online.OnlineManager;
import org.diylc.swing.plugins.statusbar.StatusBar; import org.diylc.swing.plugins.statusbar.StatusBar;
import org.diylc.swing.plugins.toolbox.ToolBox; import org.diylc.swing.plugins.toolbox.ToolBox;
import org.diylc.swingframework.ButtonDialog; import org.diylc.swingframework.ButtonDialog;
@@ -98,7 +99,7 @@ public class MainFrame extends JFrame implements ISwingUI {
presenter.installPlugin(new EditMenuPlugin(this)); presenter.installPlugin(new EditMenuPlugin(this));
presenter.installPlugin(new ConfigPlugin(this)); presenter.installPlugin(new ConfigPlugin(this));
presenter.installPlugin(new LayersMenuPlugin(this)); presenter.installPlugin(new LayersMenuPlugin(this));
// presenter.installPlugin(new OnlineManager()); presenter.installPlugin(new OnlineManager(this));
presenter.installPlugin(new HelpMenuPlugin(this)); presenter.installPlugin(new HelpMenuPlugin(this));
presenter.installPlugin(new StatusBar(this)); presenter.installPlugin(new StatusBar(this));
@@ -10,8 +10,9 @@ import org.diylc.common.EventType;
import org.diylc.common.IPlugIn; import org.diylc.common.IPlugIn;
import org.diylc.common.IPlugInPort; import org.diylc.common.IPlugInPort;
import org.diylc.images.IconLoader; import org.diylc.images.IconLoader;
import org.diylc.swing.ISwingUI;
import org.diylc.swing.gui.DialogFactory; import org.diylc.swing.gui.DialogFactory;
import org.diylc.swing.plugins.online.presenter.LibraryPresenter; import org.diylc.swing.plugins.online.presenter.OnlinePresenter;
import org.diylc.swing.plugins.online.view.LoginDialog; import org.diylc.swing.plugins.online.view.LoginDialog;
import org.diylc.swing.plugins.online.view.NewUserDialog; import org.diylc.swing.plugins.online.view.NewUserDialog;
import org.diylc.swing.plugins.online.view.UploadDialog; import org.diylc.swing.plugins.online.view.UploadDialog;
@@ -19,25 +20,29 @@ import org.diylc.swingframework.ProgressDialog;
public class OnlineManager implements IPlugIn { public class OnlineManager implements IPlugIn {
private static final String ONLINE_TITLE = "Online"; private static final String ONLINE_TITLE = "Project Cloud";
private IPlugInPort plugInPort; private IPlugInPort plugInPort;
private LibraryPresenter libraryPresenter; private OnlinePresenter onlinePresenter;
public OnlineManager(ISwingUI swingUI) {
super();
// plugInPort.injectMenuAction(new LibraryAction(), ONLINE_TITLE);
// plugInPort.injectMenuAction(null, ONLINE_TITLE);
swingUI.injectMenuAction(new LoginAction(), ONLINE_TITLE);
swingUI.injectMenuAction(new CreateAccountAction(), ONLINE_TITLE);
swingUI.injectMenuAction(null, ONLINE_TITLE);
swingUI.injectMenuAction(new UploadAction(), ONLINE_TITLE);
swingUI.injectMenuAction(new ManageProjectsAction(), ONLINE_TITLE);
}
@Override @Override
public void connect(IPlugInPort plugInPort) { public void connect(IPlugInPort plugInPort) {
this.plugInPort = plugInPort; this.plugInPort = plugInPort;
this.libraryPresenter = new LibraryPresenter(); this.onlinePresenter = new OnlinePresenter();
initialize(); initialize();
// plugInPort.injectMenuAction(new LibraryAction(), ONLINE_TITLE);
// plugInPort.injectMenuAction(null, ONLINE_TITLE);
// plugInPort.injectMenuAction(new LoginAction(), ONLINE_TITLE);
// plugInPort.injectMenuAction(new CreateAccountAction(), ONLINE_TITLE);
// plugInPort.injectMenuAction(null, ONLINE_TITLE);
// plugInPort.injectMenuAction(new UploadAction(), ONLINE_TITLE);
// plugInPort.injectMenuAction(new ManageProjectsAction(), ONLINE_TITLE);
} }
private void initialize() { private void initialize() {
@@ -89,7 +94,7 @@ public class OnlineManager implements IPlugIn {
public LoginAction() { public LoginAction() {
super(); super();
putValue(AbstractAction.NAME, "Log in"); putValue(AbstractAction.NAME, "Log In");
putValue(AbstractAction.SMALL_ICON, IconLoader.IdCard.getIcon()); putValue(AbstractAction.SMALL_ICON, IconLoader.IdCard.getIcon());
} }
@@ -97,6 +102,7 @@ public class OnlineManager implements IPlugIn {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
LoginDialog dialog = DialogFactory.getInstance().createLoginDialog(); LoginDialog dialog = DialogFactory.getInstance().createLoginDialog();
dialog.setVisible(true); dialog.setVisible(true);
onlinePresenter.login(dialog.getName(), dialog.getPassword());
} }
} }
@@ -112,7 +118,7 @@ public class OnlineManager implements IPlugIn {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
NewUserDialog dialog = DialogFactory.getInstance().createNewUserDialog(); NewUserDialog dialog = DialogFactory.getInstance().createNewUserDialog(null);
dialog.setVisible(true); dialog.setVisible(true);
} }
} }
@@ -1,23 +0,0 @@
package org.diylc.swing.plugins.online.presenter;
import org.apache.log4j.Logger;
import org.diylc.appframework.miscutils.ConfigurationManager;
import com.diyfever.httpproxy.PhpFlatProxy;
import com.diyfever.httpproxy.ProxyFactory;
public class LibraryPresenter {
private final static Logger LOG = Logger.getLogger(LibraryPresenter.class);
private ServiceAPI service;
private String serviceUrl;
public LibraryPresenter() {
serviceUrl = ConfigurationManager.getInstance().readString(
ServiceAPI.URL_KEY, "http://www.diy-fever.com/diylc/api");
ProxyFactory factory = new ProxyFactory(new PhpFlatProxy());
service = factory.createProxy(ServiceAPI.class, serviceUrl);
}
}
@@ -12,10 +12,12 @@ import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JPasswordField; import javax.swing.JPasswordField;
import javax.swing.JTextArea;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import org.diylc.swing.plugins.online.model.UserEntity;
import org.diylc.swingframework.ButtonDialog; import org.diylc.swingframework.ButtonDialog;
public class NewUserDialog extends ButtonDialog { public class NewUserDialog extends ButtonDialog {
@@ -28,17 +30,24 @@ public class NewUserDialog extends ButtonDialog {
private JPasswordField passwordField; private JPasswordField passwordField;
private JPasswordField confirmPasswordField; private JPasswordField confirmPasswordField;
private JTextField emailField; private JTextField emailField;
private JTextField websiteField;
private JTextArea bioArea;
private String userName; private String userName;
private String password; private String password;
private String email; private String email;
private String website;
private String bio;
public NewUserDialog(JFrame owner) { private UserEntity existingEntity;
public NewUserDialog(JFrame owner, UserEntity existingEntity) {
super(owner, "New Account", new String[] { OK, CANCEL }); super(owner, "New Account", new String[] { OK, CANCEL });
setMinimumSize(new Dimension(240, 32)); setMinimumSize(new Dimension(240, 32));
layoutGui(); layoutGui();
refreshState(); refreshState();
userNameField.setText(System.getProperty("user.name")); userNameField.setText(System.getProperty("user.name"));
this.existingEntity = existingEntity;
} }
public String getUserName() { public String getUserName() {
@@ -53,6 +62,14 @@ public class NewUserDialog extends ButtonDialog {
return email; return email;
} }
public String getWebsite() {
return website;
}
public String getBio() {
return bio;
}
@Override @Override
protected JComponent getMainComponent() { protected JComponent getMainComponent() {
if (mainPanel == null) { if (mainPanel == null) {
@@ -78,6 +95,12 @@ public class NewUserDialog extends ButtonDialog {
gbc.gridy = 3; gbc.gridy = 3;
mainPanel.add(new JLabel("eMail:"), gbc); mainPanel.add(new JLabel("eMail:"), gbc);
gbc.gridy = 4;
mainPanel.add(new JLabel("Website:"), gbc);
gbc.gridy = 5;
mainPanel.add(new JLabel("Short Bio:"), gbc);
gbc.gridx = 1; gbc.gridx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL; gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1; gbc.weightx = 1;
@@ -93,6 +116,12 @@ public class NewUserDialog extends ButtonDialog {
gbc.gridy = 3; gbc.gridy = 3;
mainPanel.add(getEmailField(), gbc); mainPanel.add(getEmailField(), gbc);
gbc.gridy = 4;
mainPanel.add(getWebsiteField(), gbc);
gbc.gridy = 5;
mainPanel.add(getBioArea(), gbc);
} }
return mainPanel; return mainPanel;
} }
@@ -100,38 +129,46 @@ public class NewUserDialog extends ButtonDialog {
private void refreshState() { private void refreshState() {
this.userName = getUserNameField().getText(); this.userName = getUserNameField().getText();
String password = new String(getPasswordField().getPassword()); String password = new String(getPasswordField().getPassword());
String confirmPassword = new String(getConfirmPasswordField().getPassword()); String confirmPassword = new String(getConfirmPasswordField()
.getPassword());
if (password.equals(confirmPassword)) { if (password.equals(confirmPassword)) {
this.password = password; this.password = password;
} else { } else {
this.password = null; this.password = null;
} }
this.email = getEmailField().getText(); this.email = getEmailField().getText();
this.website = getWebsiteField().getText();
this.bio = getBioArea().getText();
JButton okButton = getButton(OK); JButton okButton = getButton(OK);
okButton.setEnabled((this.userName.length() > 0) && (this.password != null) okButton.setEnabled((this.userName.length() > 0)
&& (this.password.length() > 0)); && (this.password != null) && (this.password.length() > 0));
} }
private JTextField getUserNameField() { private JTextField getUserNameField() {
if (userNameField == null) { if (userNameField == null) {
userNameField = new JTextField(); userNameField = new JTextField();
userNameField.getDocument().addDocumentListener(new DocumentListener() { if (existingEntity != null) {
userNameField.setText(existingEntity.getUserName());
userNameField.setEditable(false);
}
userNameField.getDocument().addDocumentListener(
new DocumentListener() {
@Override @Override
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
refreshState(); refreshState();
} }
@Override @Override
public void insertUpdate(DocumentEvent e) { public void insertUpdate(DocumentEvent e) {
refreshState(); refreshState();
} }
@Override @Override
public void changedUpdate(DocumentEvent e) { public void changedUpdate(DocumentEvent e) {
refreshState(); refreshState();
} }
}); });
} }
return userNameField; return userNameField;
} }
@@ -139,23 +176,24 @@ public class NewUserDialog extends ButtonDialog {
private JPasswordField getPasswordField() { private JPasswordField getPasswordField() {
if (passwordField == null) { if (passwordField == null) {
passwordField = new JPasswordField(); passwordField = new JPasswordField();
passwordField.getDocument().addDocumentListener(new DocumentListener() { passwordField.getDocument().addDocumentListener(
new DocumentListener() {
@Override @Override
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
refreshState(); refreshState();
} }
@Override @Override
public void insertUpdate(DocumentEvent e) { public void insertUpdate(DocumentEvent e) {
refreshState(); refreshState();
} }
@Override @Override
public void changedUpdate(DocumentEvent e) { public void changedUpdate(DocumentEvent e) {
refreshState(); refreshState();
} }
}); });
} }
return passwordField; return passwordField;
} }
@@ -163,23 +201,24 @@ public class NewUserDialog extends ButtonDialog {
private JPasswordField getConfirmPasswordField() { private JPasswordField getConfirmPasswordField() {
if (confirmPasswordField == null) { if (confirmPasswordField == null) {
confirmPasswordField = new JPasswordField(); confirmPasswordField = new JPasswordField();
confirmPasswordField.getDocument().addDocumentListener(new DocumentListener() { confirmPasswordField.getDocument().addDocumentListener(
new DocumentListener() {
@Override @Override
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
refreshState(); refreshState();
} }
@Override @Override
public void insertUpdate(DocumentEvent e) { public void insertUpdate(DocumentEvent e) {
refreshState(); refreshState();
} }
@Override @Override
public void changedUpdate(DocumentEvent e) { public void changedUpdate(DocumentEvent e) {
refreshState(); refreshState();
} }
}); });
} }
return confirmPasswordField; return confirmPasswordField;
} }
@@ -187,7 +226,63 @@ public class NewUserDialog extends ButtonDialog {
private JTextField getEmailField() { private JTextField getEmailField() {
if (emailField == null) { if (emailField == null) {
emailField = new JTextField(); emailField = new JTextField();
emailField.getDocument().addDocumentListener(new DocumentListener() { if (existingEntity != null)
emailField.setText(existingEntity.getEmail());
emailField.getDocument().addDocumentListener(
new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return emailField;
}
public JTextField getWebsiteField() {
if (websiteField == null) {
websiteField = new JTextField();
if (existingEntity != null)
websiteField.setText(existingEntity.getWebsite());
websiteField.getDocument().addDocumentListener(
new DocumentListener() {
@Override
public void removeUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void insertUpdate(DocumentEvent e) {
refreshState();
}
@Override
public void changedUpdate(DocumentEvent e) {
refreshState();
}
});
}
return websiteField;
}
public JTextArea getBioArea() {
if (bioArea == null) {
bioArea = new JTextArea();
if (existingEntity != null)
bioArea.setText(existingEntity.getBio());
bioArea.getDocument().addDocumentListener(new DocumentListener() {
@Override @Override
public void removeUpdate(DocumentEvent e) { public void removeUpdate(DocumentEvent e) {
@@ -205,6 +300,6 @@ public class NewUserDialog extends ButtonDialog {
} }
}); });
} }
return emailField; return bioArea;
} }
} }
@@ -25,7 +25,7 @@ import org.diylc.common.IPlugInPort;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
import org.diylc.core.Template; import org.diylc.core.Template;
import org.diylc.images.IconLoader; import org.diylc.images.IconLoader;
import org.openide.awt.DropDownButtonFactory; import org.diylc.swing.plugins.toolbox.openide.DropDownButtonFactory;
/** /**
* {@link JButton} that displays component type icon and instantiates the * {@link JButton} that displays component type icon and instantiates the
@@ -107,8 +107,8 @@ class ComponentButtonFactory {
@Override @Override
public void keyPressed(KeyEvent e) { public void keyPressed(KeyEvent e) {
plugInPort.keyPressed(e.getKeyCode(), e.isControlDown(), e plugInPort.keyPressed(e.getKeyCode(), e.isControlDown(),
.isShiftDown(), e.isAltDown()); e.isShiftDown(), e.isAltDown());
} }
}); });
// addKeyListener(new KeyAdapter() { // addKeyListener(new KeyAdapter() {
@@ -163,8 +163,8 @@ class ComponentButtonFactory {
JPopupMenu m = (JPopupMenu) c; JPopupMenu m = (JPopupMenu) c;
m.setVisible(false); m.setVisible(false);
} }
int result = JOptionPane.showConfirmDialog(SwingUtilities int result = JOptionPane.showConfirmDialog(
.getRoot(item), SwingUtilities.getRoot(item),
"Are you sure you want to delete template \"" "Are you sure you want to delete template \""
+ template.getName() + "\"", "Delete", + template.getName() + "\"", "Delete",
JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
@@ -0,0 +1,388 @@
package org.diylc.swing.plugins.toolbox.openide;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
import java.util.Map;
import javax.swing.DefaultButtonModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPopupMenu;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
class DropDownButton extends JButton {
private boolean mouseInButton = false;
private boolean mouseInArrowArea = false;
private Map<String, Icon> regIcons = new HashMap<String, Icon>(5);
private Map<String, Icon> arrowIcons = new HashMap<String, Icon>(5);
private static final String ICON_NORMAL = "normal";
private static final String ICON_PRESSED = "pressed";
private static final String ICON_ROLLOVER = "rollover";
private static final String ICON_ROLLOVER_SELECTED = "rolloverSelected";
private static final String ICON_SELECTED = "selected";
private static final String ICON_DISABLED = "disabled";
private static final String ICON_DISABLED_SELECTED = "disabledSelected";
private static final String ICON_ROLLOVER_LINE = "rolloverLine";
private static final String ICON_ROLLOVER_SELECTED_LINE = "rolloverSelectedLine";
private PopupMenuListener menuListener;
public DropDownButton(Icon icon, JPopupMenu popup) {
Parameters.notNull((CharSequence) "icon", (Object) icon);
assert (null != icon);
this.putClientProperty("dropDownMenu", popup);
this.setIcon(icon);
this.setDisabledIcon(ImageUtilities.createDisabledIcon((Icon) icon));
this.resetIcons();
this.addPropertyChangeListener("dropDownMenu",
new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
DropDownButton.this.resetIcons();
}
});
this.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
if (null != DropDownButton.this.getPopupMenu()) {
DropDownButton.this.mouseInArrowArea = DropDownButton.this
.isInArrowArea(e.getPoint());
DropDownButton.this.updateRollover(
DropDownButton.this._getRolloverIcon(),
DropDownButton.this._getRolloverSelectedIcon());
}
}
});
this.addMouseListener(new MouseAdapter() {
private boolean popupMenuOperation;
@Override
public void mousePressed(MouseEvent e) {
this.popupMenuOperation = false;
JPopupMenu menu = DropDownButton.this.getPopupMenu();
if (menu != null
&& DropDownButton.this.getModel() instanceof Model) {
Model model = (Model) DropDownButton.this.getModel();
if (!model._isPressed()) {
if (DropDownButton.this.isInArrowArea(e.getPoint())
&& menu.getComponentCount() > 0) {
model._press();
menu.addPopupMenuListener(DropDownButton.this
.getMenuListener());
menu.show(DropDownButton.this, 0,
DropDownButton.this.getHeight());
this.popupMenuOperation = true;
}
} else {
model._release();
menu.removePopupMenuListener(DropDownButton.this
.getMenuListener());
this.popupMenuOperation = true;
}
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (this.popupMenuOperation) {
this.popupMenuOperation = false;
e.consume();
}
}
@Override
public void mouseEntered(MouseEvent e) {
DropDownButton.this.mouseInButton = true;
if (DropDownButton.this.hasPopupMenu()) {
DropDownButton.this.mouseInArrowArea = DropDownButton.this
.isInArrowArea(e.getPoint());
DropDownButton.this.updateRollover(
DropDownButton.this._getRolloverIcon(),
DropDownButton.this._getRolloverSelectedIcon());
}
}
@Override
public void mouseExited(MouseEvent e) {
DropDownButton.this.mouseInButton = false;
DropDownButton.this.mouseInArrowArea = false;
if (DropDownButton.this.hasPopupMenu()) {
DropDownButton.this.updateRollover(
DropDownButton.this._getRolloverIcon(),
DropDownButton.this._getRolloverSelectedIcon());
}
}
});
this.setModel(new Model());
}
private PopupMenuListener getMenuListener() {
if (null == this.menuListener) {
this.menuListener = new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
JPopupMenu menu;
if (DropDownButton.this.getModel() instanceof Model) {
((Model) DropDownButton.this.getModel())._release();
}
if (null != (menu = DropDownButton.this.getPopupMenu())) {
menu.removePopupMenuListener(this);
}
}
@Override
public void popupMenuCanceled(PopupMenuEvent e) {
}
};
}
return this.menuListener;
}
private void updateRollover(Icon rollover, Icon rolloverSelected) {
super.setRolloverIcon(rollover);
super.setRolloverSelectedIcon(rolloverSelected);
}
private void resetIcons() {
Icon icon = this.regIcons.get("normal");
if (null != icon) {
this.setIcon(icon);
}
if (null != (icon = this.regIcons.get("pressed"))) {
this.setPressedIcon(icon);
}
if (null != (icon = this.regIcons.get("rollover"))) {
this.setRolloverIcon(icon);
}
if (null != (icon = this.regIcons.get("rolloverSelected"))) {
this.setRolloverSelectedIcon(icon);
}
if (null != (icon = this.regIcons.get("selected"))) {
this.setSelectedIcon(icon);
}
if (null != (icon = this.regIcons.get("disabled"))) {
this.setDisabledIcon(icon);
}
if (null != (icon = this.regIcons.get("disabledSelected"))) {
this.setDisabledSelectedIcon(icon);
}
}
private Icon _getRolloverIcon() {
Icon icon = null;
icon = this.arrowIcons.get(this.mouseInArrowArea ? "rollover"
: "rolloverLine");
if (null == icon) {
Icon orig = this.regIcons.get("rollover");
if (null == orig) {
orig = this.regIcons.get("normal");
}
icon = new IconWithArrow(orig, !this.mouseInArrowArea);
this.arrowIcons.put(this.mouseInArrowArea ? "rollover"
: "rolloverLine", icon);
}
return icon;
}
private Icon _getRolloverSelectedIcon() {
Icon icon = null;
icon = this.arrowIcons.get(this.mouseInArrowArea ? "rolloverSelected"
: "rolloverSelectedLine");
if (null == icon) {
Icon orig = this.regIcons.get("rolloverSelected");
if (null == orig) {
orig = this.regIcons.get("rollover");
}
if (null == orig) {
orig = this.regIcons.get("normal");
}
icon = new IconWithArrow(orig, !this.mouseInArrowArea);
this.arrowIcons.put(this.mouseInArrowArea ? "rolloverSelected"
: "rolloverSelectedLine", icon);
}
return icon;
}
JPopupMenu getPopupMenu() {
Object menu = this.getClientProperty("dropDownMenu");
if (menu instanceof JPopupMenu) {
return (JPopupMenu) menu;
}
return null;
}
boolean hasPopupMenu() {
return null != this.getPopupMenu();
}
private boolean isInArrowArea(Point p) {
return p.getLocation().x >= this.getWidth()
- IconWithArrow.getArrowAreaWidth() - this.getInsets().right;
}
@Override
public void setIcon(Icon icon) {
assert (null != icon);
Icon arrow = this.updateIcons(icon, "normal");
this.arrowIcons.remove("rolloverLine");
this.arrowIcons.remove("rolloverSelectedLine");
this.arrowIcons.remove("rollover");
this.arrowIcons.remove("rolloverSelected");
super.setIcon(this.hasPopupMenu() ? arrow : icon);
}
private Icon updateIcons(Icon orig, String iconType) {
ImageIcon arrow = null;
if (null == orig) {
this.regIcons.remove(iconType);
this.arrowIcons.remove(iconType);
} else {
this.regIcons.put(iconType, orig);
arrow = new ImageIcon(
ImageUtilities.icon2Image((Icon) new IconWithArrow(orig,
false)));
this.arrowIcons.put(iconType, arrow);
}
return arrow;
}
@Override
public void setPressedIcon(Icon icon) {
Icon arrow = this.updateIcons(icon, "pressed");
super.setPressedIcon(this.hasPopupMenu() ? arrow : icon);
}
@Override
public void setSelectedIcon(Icon icon) {
Icon arrow = this.updateIcons(icon, "selected");
super.setSelectedIcon(this.hasPopupMenu() ? arrow : icon);
}
@Override
public void setRolloverIcon(Icon icon) {
Icon arrow = this.updateIcons(icon, "rollover");
this.arrowIcons.remove("rolloverLine");
this.arrowIcons.remove("rolloverSelectedLine");
super.setRolloverIcon(this.hasPopupMenu() ? arrow : icon);
}
@Override
public void setRolloverSelectedIcon(Icon icon) {
Icon arrow = this.updateIcons(icon, "rolloverSelected");
this.arrowIcons.remove("rolloverSelectedLine");
super.setRolloverSelectedIcon(this.hasPopupMenu() ? arrow : icon);
}
@Override
public void setDisabledIcon(Icon icon) {
Icon arrow = this.updateIcons(icon, "disabled");
super.setDisabledIcon(this.hasPopupMenu() ? arrow : icon);
}
@Override
public void setDisabledSelectedIcon(Icon icon) {
Icon arrow = this.updateIcons(icon, "disabledSelected");
super.setDisabledSelectedIcon(this.hasPopupMenu() ? arrow : icon);
}
@Override
public void setText(String text) {
}
@Override
public String getText() {
return null;
}
private class Model extends DefaultButtonModel {
private boolean _pressed;
private Model() {
this._pressed = false;
}
@Override
public void setPressed(boolean b) {
if (DropDownButton.this.mouseInArrowArea || this._pressed) {
return;
}
super.setPressed(b);
}
public void _press() {
if (this.isPressed() || !this.isEnabled()) {
return;
}
this.stateMask |= 5;
this.fireStateChanged();
this._pressed = true;
}
public void _release() {
this._pressed = false;
DropDownButton.this.mouseInArrowArea = false;
this.setArmed(false);
this.setPressed(false);
this.setRollover(false);
this.setSelected(false);
}
public boolean _isPressed() {
return this._pressed;
}
@Override
protected void fireStateChanged() {
if (this._pressed) {
return;
}
super.fireStateChanged();
}
@Override
public void setArmed(boolean b) {
if (this._pressed) {
return;
}
super.setArmed(b);
}
@Override
public void setEnabled(boolean b) {
if (this._pressed) {
return;
}
super.setEnabled(b);
}
@Override
public void setSelected(boolean b) {
if (this._pressed) {
return;
}
super.setSelected(b);
}
@Override
public void setRollover(boolean b) {
if (this._pressed) {
return;
}
super.setRollover(b);
}
}
}
@@ -0,0 +1,14 @@
package org.diylc.swing.plugins.toolbox.openide;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JPopupMenu;
public final class DropDownButtonFactory {
public static final String PROP_DROP_DOWN_MENU = "dropDownMenu";
public static JButton createDropDownButton(Icon icon,
JPopupMenu dropDownMenu) {
return new DropDownButton(icon, dropDownMenu);
}
}
@@ -0,0 +1,61 @@
package org.diylc.swing.plugins.toolbox.openide;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.Icon;
import javax.swing.UIManager;
import org.diylc.images.IconLoader;
class IconWithArrow implements Icon {
private Icon orig;
private Icon arrow = IconLoader.Arrow.getIcon();
private boolean paintRollOver;
private static final int GAP = 6;
public IconWithArrow(Icon orig, boolean paintRollOver) {
Parameters.notNull("original icon", orig);
this.orig = orig;
this.paintRollOver = paintRollOver;
}
public void paintIcon(Component c, Graphics g, int x, int y) {
int height = getIconHeight();
this.orig.paintIcon(c, g, x, y + (height - this.orig.getIconHeight())
/ 2);
this.arrow.paintIcon(c, g, x + 6 + this.orig.getIconWidth(), y
+ (height - this.arrow.getIconHeight()) / 2);
if (this.paintRollOver) {
Color brighter = UIManager.getColor("controlHighlight");
Color darker = UIManager.getColor("controlShadow");
if ((null == brighter) || (null == darker)) {
brighter = c.getBackground().brighter();
darker = c.getBackground().darker();
}
if ((null != brighter) && (null != darker)) {
g.setColor(brighter);
g.drawLine(x + this.orig.getIconWidth() + 1, y,
x + this.orig.getIconWidth() + 1, y + getIconHeight());
g.setColor(darker);
g.drawLine(x + this.orig.getIconWidth() + 2, y,
x + this.orig.getIconWidth() + 2, y + getIconHeight());
}
}
}
public int getIconWidth() {
return this.orig.getIconWidth() + 6 + this.arrow.getIconWidth();
}
public int getIconHeight() {
return Math.max(this.orig.getIconHeight(), this.arrow.getIconHeight());
}
public static int getArrowAreaWidth() {
return 8;
}
}
@@ -0,0 +1,349 @@
package org.diylc.swing.plugins.toolbox.openide;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.HeadlessException;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageObserver;
import java.awt.image.RGBImageFilter;
import java.awt.image.WritableRaster;
import java.net.URL;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
public final class ImageUtilities {
static final String TOOLTIP_SEPAR = "<br>";
private static final Set<String> extraInitialSlashes = new HashSet<String>();
private static volatile Object currentLoader;
private static boolean noLoaderWarned;
private static final Component component;
private static final MediaTracker tracker;
private static int mediaTrackerID;
private static ImageReader PNG_READER;
private static final Logger ERR;
private ImageUtilities() {
}
public static final Icon image2Icon(Image image) {
if (image instanceof ToolTipImage) {
return ((ToolTipImage)image).getIcon();
}
return new ImageIcon(image);
}
public static final Image icon2Image(Icon icon) {
if (icon instanceof ImageIcon) {
return ((ImageIcon)icon).getImage();
}
ToolTipImage image = new ToolTipImage("", icon.getIconWidth(), icon.getIconHeight(), 2);
Graphics g = image.getGraphics();
icon.paintIcon(new JLabel(), g, 0, 0);
g.dispose();
return image;
}
public static final String getImageToolTip(Image image) {
if (image instanceof ToolTipImage) {
return ((ToolTipImage)image).toolTipText;
}
return "";
}
public static Icon createDisabledIcon(Icon icon) {
Parameters.notNull("icon", icon);
return new LazyDisabledIcon(ImageUtilities.icon2Image(icon));
}
public static Image createDisabledImage(Image image) {
Parameters.notNull("image", image);
return LazyDisabledIcon.createDisabledImage(image);
}
static final Image toBufferedImage(Image img) {
new ImageIcon(img, "");
if (img.getHeight(null) * img.getWidth(null) > 576) {
return img;
}
BufferedImage rep = ImageUtilities.createBufferedImage(img.getWidth(null), img.getHeight(null));
Graphics2D g = rep.createGraphics();
g.drawImage(img, 0, 0, null);
g.dispose();
img.flush();
return rep;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private static void ensureLoaded(Image image) {
if ((Toolkit.getDefaultToolkit().checkImage(image, -1, -1, null) & 48) != 0) {
return;
}
MediaTracker mediaTracker = tracker;
synchronized (mediaTracker) {
int id = ++mediaTrackerID;
tracker.addImage(image, id);
try {
tracker.waitForID(id, 0);
}
catch (InterruptedException e) {
System.out.println("INTERRUPTED while loading Image");
}
assert (tracker.statusID(id, false) == 8);
tracker.removeImage(image, id);
}
}
private static final Image doMergeImages(Image image1, Image image2, int x, int y) {
ImageUtilities.ensureLoaded(image1);
ImageUtilities.ensureLoaded(image2);
int w = Math.max(image1.getWidth(null), x + image2.getWidth(null));
int h = Math.max(image1.getHeight(null), y + image2.getHeight(null));
boolean bitmask = image1 instanceof Transparency && ((Transparency)((Object)image1)).getTransparency() != 3 && image2 instanceof Transparency && ((Transparency)((Object)image2)).getTransparency() != 3;
StringBuilder str = new StringBuilder(image1 instanceof ToolTipImage ? ((ToolTipImage)image1).toolTipText : "");
if (image2 instanceof ToolTipImage) {
String toolTip = ((ToolTipImage)image2).toolTipText;
if (str.length() > 0 && toolTip.length() > 0) {
str.append("<br>");
}
str.append(toolTip);
}
ColorModel model = ImageUtilities.colorModel(bitmask ? 2 : 3);
ToolTipImage buffImage = new ToolTipImage(str.toString(), model, model.createCompatibleWritableRaster(w, h), model.isAlphaPremultiplied(), null, null);
Graphics2D g = buffImage.createGraphics();
g.drawImage(image1, 0, 0, null);
g.drawImage(image2, x, y, null);
g.dispose();
return buffImage;
}
static final BufferedImage createBufferedImage(int width, int height) {
if (Utilities.isMac()) {
return new BufferedImage(width, height, 3);
}
ColorModel model = ImageUtilities.colorModel(3);
BufferedImage buffImage = new BufferedImage(model, model.createCompatibleWritableRaster(width, height), model.isAlphaPremultiplied(), null);
return buffImage;
}
private static ColorModel colorModel(int transparency) {
ColorModel model;
try {
model = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getColorModel(transparency);
}
catch (HeadlessException he) {
model = ColorModel.getRGBdefault();
}
return model;
}
static {
noLoaderWarned = false;
component = new Component(){};
tracker = new MediaTracker(component);
ERR = Logger.getLogger(ImageUtilities.class.getName());
ImageIO.setUseCache(false);
PNG_READER = ImageIO.getImageReadersByMIMEType("image/png").next();
}
private static class CompositeImageKey {
Image baseImage;
Image overlayImage;
int x;
int y;
CompositeImageKey(Image base, Image overlay, int x, int y) {
this.x = x;
this.y = y;
this.baseImage = base;
this.overlayImage = overlay;
}
public boolean equals(Object other) {
if (!(other instanceof CompositeImageKey)) {
return false;
}
CompositeImageKey k = (CompositeImageKey)other;
return this.x == k.x && this.y == k.y && this.baseImage == k.baseImage && this.overlayImage == k.overlayImage;
}
public int hashCode() {
int hash = (this.x << 3 ^ this.y) << 4;
hash = hash ^ this.baseImage.hashCode() ^ this.overlayImage.hashCode();
return hash;
}
public String toString() {
return "Composite key for " + this.baseImage + " + " + this.overlayImage + " at [" + this.x + ", " + this.y + "]";
}
}
private static class DisabledButtonFilter
extends RGBImageFilter {
DisabledButtonFilter() {
this.canFilterIndexColorModel = true;
}
@Override
public int filterRGB(int x, int y, int rgb) {
return (rgb & -16777216) + 8947848 + ((rgb >> 16 & 255) >> 2 << 16) + ((rgb >> 8 & 255) >> 2 << 8) + ((rgb & 255) >> 2);
}
public void setProperties(Hashtable props) {
props = (Hashtable)props.clone();
this.consumer.setProperties(props);
}
}
private static class LazyDisabledIcon
implements Icon {
private static final RGBImageFilter DISABLED_BUTTON_FILTER = new DisabledButtonFilter();
private Image img;
private Icon disabledIcon;
public LazyDisabledIcon(Image img) {
assert (null != img);
this.img = img;
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
this.getDisabledIcon().paintIcon(c, g, x, y);
}
@Override
public int getIconWidth() {
return this.getDisabledIcon().getIconWidth();
}
@Override
public int getIconHeight() {
return this.getDisabledIcon().getIconHeight();
}
private synchronized Icon getDisabledIcon() {
if (null == this.disabledIcon) {
this.disabledIcon = new ImageIcon(LazyDisabledIcon.createDisabledImage(this.img));
}
return this.disabledIcon;
}
static Image createDisabledImage(Image img) {
FilteredImageSource prod = new FilteredImageSource(img.getSource(), DISABLED_BUTTON_FILTER);
return Toolkit.getDefaultToolkit().createImage(prod);
}
}
private static class ToolTipImage
extends BufferedImage
implements Icon {
final String toolTipText;
ImageIcon imageIcon;
final URL url;
public static ToolTipImage createNew(String toolTipText, Image image, URL url) {
ImageUtilities.ensureLoaded(image);
boolean bitmask = image instanceof Transparency && ((Transparency)((Object)image)).getTransparency() != 3;
ColorModel model = ImageUtilities.colorModel(bitmask ? 2 : 3);
int w = image.getWidth(null);
int h = image.getHeight(null);
ToolTipImage newImage = new ToolTipImage(toolTipText, model, model.createCompatibleWritableRaster(w, h), model.isAlphaPremultiplied(), null, url);
Graphics2D g = newImage.createGraphics();
g.drawImage(image, 0, 0, null);
g.dispose();
return newImage;
}
public ToolTipImage(String toolTipText, ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable<?, ?> properties, URL url) {
super(cm, raster, isRasterPremultiplied, properties);
this.toolTipText = toolTipText;
this.url = url;
}
public ToolTipImage(String toolTipText, int width, int height, int imageType) {
super(width, height, imageType);
this.toolTipText = toolTipText;
this.url = null;
}
synchronized ImageIcon getIcon() {
if (this.imageIcon == null) {
this.imageIcon = new ImageIcon(this);
}
return this.imageIcon;
}
@Override
public int getIconHeight() {
return super.getHeight();
}
@Override
public int getIconWidth() {
return super.getWidth();
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
g.drawImage(this, x, y, null);
}
@Override
public Object getProperty(String name, ImageObserver observer) {
if ("url".equals(name)) {
if (this.url != null) {
return this.url;
}
return this.imageIcon.getImage().getProperty("url", observer);
}
return super.getProperty(name, observer);
}
}
private static class ToolTipImageKey {
Image image;
String str;
ToolTipImageKey(Image image, String str) {
this.image = image;
this.str = str;
}
public boolean equals(Object other) {
if (!(other instanceof ToolTipImageKey)) {
return false;
}
ToolTipImageKey k = (ToolTipImageKey)other;
return this.str.equals(k.str) && this.image == k.image;
}
public int hashCode() {
int hash = this.image.hashCode() ^ this.str.hashCode();
return hash;
}
public String toString() {
return "ImageStringKey for " + this.image + " + " + this.str;
}
}
}
@@ -0,0 +1,233 @@
//package org.diylc.swing.plugins.toolbox.openide;
//
//import java.util.ArrayList;
//import java.util.Collection;
//import java.util.Collections;
//import java.util.Iterator;
//import java.util.List;
//import java.util.Set;
//
//public abstract class Lookup {
// public static final Lookup EMPTY = new Empty();
// private static Lookup defaultLookup;
//
// public static synchronized Lookup getDefault() {
// if (defaultLookup != null) {
// return defaultLookup;
// }
// String className = System.getProperty("org.openide.util.Lookup");
// if ("-".equals(className)) {
// return EMPTY;
// }
// ClassLoader l = Thread.currentThread().getContextClassLoader();
// try {
// if (className != null) {
// defaultLookup = (Lookup) Class.forName(className, true, l)
// .newInstance();
//
// return defaultLookup;
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// Lookup misl = Lookups.metaInfServices(l);
// defaultLookup = (Lookup) misl.lookup(Lookup.class);
// if (defaultLookup != null) {
// return defaultLookup;
// }
// Provider prov = (Provider) misl.lookup(Provider.class);
// if (prov != null) {
// defaultLookup = Lookups.proxy(prov);
//
// return defaultLookup;
// }
// DefLookup def = new DefLookup();
// def.init(l, misl, false);
// defaultLookup = def;
// def.init(l, misl, true);
// return defaultLookup;
// }
//
// private static final class DefLookup extends ProxyLookup {
// public DefLookup() {
// super();
// }
//
// public void init(ClassLoader loader, Lookup metaInfLookup,
// boolean addPath) {
// Lookup clLookup = Lookups.singleton(loader);
// List<Lookup> arr = new ArrayList();
// arr.add(metaInfLookup);
// arr.add(clLookup);
// String paths = System.getProperty("org.openide.util.Lookup.paths");
// if ((addPath) && (paths != null)) {
// for (String p : paths.split(":")) {
// arr.add(Lookups.forPath(p));
// }
// }
// setLookups((Lookup[]) arr.toArray(new Lookup[0]));
// }
// }
//
// private static void resetDefaultLookup() {
// if ((defaultLookup instanceof DefLookup)) {
// DefLookup def = (DefLookup) defaultLookup;
// ClassLoader l = Thread.currentThread().getContextClassLoader();
// def.init(l, Lookups.metaInfServices(l), true);
// }
// }
//
// public abstract <T> T lookup(Class<T> paramClass);
//
// public abstract <T> Result<T> lookup(Template<T> paramTemplate);
//
// public <T> Item<T> lookupItem(Template<T> template) {
// Result<T> res = lookup(template);
// Iterator<? extends Item<T>> it = res.allItems().iterator();
// return it.hasNext() ? (Item) it.next() : null;
// }
//
// public <T> Result<T> lookupResult(Class<T> clazz) {
// return lookup(new Template(clazz));
// }
//
// public <T> Collection<? extends T> lookupAll(Class<T> clazz) {
// return lookupResult(clazz).allInstances();
// }
//
// public static final class Template<T> {
// private int hashCode;
// private Class<T> type;
// private String id;
// private T instance;
//
// @Deprecated
// public Template() {
// this(null);
// }
//
// public Template(Class<T> type) {
// this(type, null, null);
// }
//
// public Template(Class<T> type, String id, T instance) {
// this.type = extractType(type);
// this.id = id;
// this.instance = instance;
// }
//
// private Class<T> extractType(Class<T> type) {
// return type == null ? Object.class : type;
// }
//
// public Class<T> getType() {
// return this.type;
// }
//
// public String getId() {
// return this.id;
// }
//
// public T getInstance() {
// return (T) this.instance;
// }
//
// public int hashCode() {
// if (this.hashCode != 0) {
// return this.hashCode;
// }
// this.hashCode = ((this.type == null ? 1 : this.type.hashCode())
// + (this.id == null ? 2 : this.id.hashCode()) + (this.instance == null ? 3
// : 0));
//
// return this.hashCode;
// }
//
// public boolean equals(Object obj) {
// if (!(obj instanceof Template)) {
// return false;
// }
// Template t = (Template) obj;
// if (hashCode() != t.hashCode()) {
// return false;
// }
// if (this.type != t.type) {
// return false;
// }
// if (this.id == null) {
// if (t.id != null) {
// return false;
// }
// } else if (!this.id.equals(t.id)) {
// return false;
// }
// if (this.instance == null) {
// return t.instance == null;
// }
// return this.instance.equals(t.instance);
// }
//
// public String toString() {
// return "Lookup.Template[type=" + this.type + ",id=" + this.id
// + ",instance=" + this.instance + "]";
// }
// }
//
// public static abstract class Result<T> {
// public abstract void addLookupListener(
// LookupListener paramLookupListener);
//
// public abstract void removeLookupListener(
// LookupListener paramLookupListener);
//
// public abstract Collection<? extends T> allInstances();
//
// public Set<Class<? extends T>> allClasses() {
// return Collections.emptySet();
// }
//
// public Collection<? extends Lookup.Item<T>> allItems() {
// return Collections.emptyList();
// }
// }
//
// public static abstract class Item<T> {
// public abstract T getInstance();
//
// public abstract Class<? extends T> getType();
//
// public abstract String getId();
//
// public abstract String getDisplayName();
//
// public String toString() {
// return getId();
// }
// }
//
// private static final class Empty extends Lookup {
// private static final Lookup.Result NO_RESULT = new Lookup.Result() {
// public void addLookupListener(LookupListener l) {
// }
//
// public void removeLookupListener(LookupListener l) {
// }
//
// public Collection allInstances() {
// return Collections.EMPTY_SET;
// }
// };
//
// public <T> T lookup(Class<T> clazz) {
// return null;
// }
//
// public <T> Lookup.Result<T> lookup(Lookup.Template<T> template) {
// return NO_RESULT;
// }
// }
//
// public static abstract interface Provider {
// public abstract Lookup getLookup();
// }
//}
@@ -0,0 +1,9 @@
//package org.diylc.swing.plugins.toolbox.openide;
//
//import java.util.EventObject;
//
//public final class LookupEvent extends EventObject {
// public LookupEvent(Lookup.Result source) {
// super(source);
// }
//}
@@ -0,0 +1,9 @@
//package org.diylc.swing.plugins.toolbox.openide;
//
//import java.util.EventListener;
//
//public abstract interface LookupListener
// extends EventListener
//{
// public abstract void resultChanged(LookupEvent paramLookupEvent);
//}
@@ -0,0 +1,96 @@
package org.diylc.swing.plugins.toolbox.openide;
import java.util.Iterator;
import java.util.Locale;
import java.util.NoSuchElementException;
public class NbBundle {
private static String brandingToken = null;
public static String getBranding() {
return brandingToken;
}
public static Iterator<String> getLocalizingSuffixes() {
return new LocaleIterator(Locale.getDefault());
}
private static class LocaleIterator implements Iterator<String> {
private boolean defaultInProgress = false;
private boolean empty = false;
private Locale locale;
private Locale initLocale;
private String current;
private String branding;
public LocaleIterator(Locale locale) {
this.locale = (this.initLocale = locale);
if (locale.equals(Locale.getDefault())) {
this.defaultInProgress = true;
}
this.current = ('_' + locale.toString());
if (NbBundle.brandingToken == null) {
this.branding = null;
} else {
this.branding = ("_" + NbBundle.brandingToken);
}
}
public String next() throws NoSuchElementException {
if (this.current == null) {
throw new NoSuchElementException();
}
String ret;
if (this.branding == null) {
ret = this.current;
} else {
ret = this.branding + this.current;
}
int lastUnderbar = this.current.lastIndexOf('_');
if (lastUnderbar == 0) {
if (this.empty) {
reset();
} else {
this.current = "";
this.empty = true;
}
} else if (lastUnderbar == -1) {
if (this.defaultInProgress) {
reset();
} else {
this.locale = Locale.getDefault();
this.current = ('_' + this.locale.toString());
this.defaultInProgress = true;
}
} else {
this.current = this.current.substring(0, lastUnderbar);
}
return ret;
}
private void reset() {
if (this.branding != null) {
this.current = ('_' + this.initLocale.toString());
int idx = this.branding.lastIndexOf('_');
if (idx == 0) {
this.branding = null;
} else {
this.branding = this.branding.substring(0, idx);
}
this.empty = false;
} else {
this.current = null;
}
}
public boolean hasNext() {
return this.current != null;
}
public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
}
}
@@ -0,0 +1,41 @@
package org.diylc.swing.plugins.toolbox.openide;
public class Parameters {
public static void notNull(CharSequence name, Object value) {
if (value == null) {
throw new NullPointerException("The " + name
+ " parameter cannot be null");
}
}
public static void notEmpty(CharSequence name, CharSequence value) {
notNull(name, value);
if (value.length() == 0) {
throw new IllegalArgumentException("The " + name
+ " parameter cannot be an empty character sequence");
}
}
public static void notWhitespace(CharSequence name, CharSequence value) {
notNull(name, value);
if (value.toString().trim().length() == 0) {
throw new IllegalArgumentException(
"The "
+ name
+ " parameter must contain at least one non-whitespace character");
}
}
public static void javaIdentifier(CharSequence name, CharSequence value) {
notNull(name, value);
javaIdentifierOrNull(name, value);
}
public static void javaIdentifierOrNull(CharSequence name,
CharSequence value) {
if ((value != null) && (!Utilities.isJavaIdentifier(value.toString()))) {
throw new IllegalArgumentException("The " + name + " parameter ('"
+ value + "') is not a valid Java identifier");
}
}
}
@@ -1295,7 +1295,7 @@
<description>Potentiometer schematic symbol added</description> <description>Potentiometer schematic symbol added</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
</changes> </changes>
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url> <url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version> </org.diylc.appframework.update.Version>
<org.diylc.appframework.update.Version> <org.diylc.appframework.update.Version>
<versionNumber> <versionNumber>
@@ -1311,7 +1311,7 @@
<description>Improved potentiometer symbol appearance</description> <description>Improved potentiometer symbol appearance</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
</changes> </changes>
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url> <url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version> </org.diylc.appframework.update.Version>
<org.diylc.appframework.update.Version> <org.diylc.appframework.update.Version>
<versionNumber> <versionNumber>
@@ -1327,7 +1327,23 @@
<description>Undo works only one level back (bug introduced in 3.29)</description> <description>Undo works only one level back (bug introduced in 3.29)</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
</changes> </changes>
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url> <url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>
<org.diylc.appframework.update.Version>
<versionNumber>
<major>3</major>
<minor>32</minor>
<build>0</build>
</versionNumber>
<releaseDate>2016-05-09 20:00:00.000 CET</releaseDate>
<name></name>
<changes>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Reduced DIYLC package size</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version> </org.diylc.appframework.update.Version>
</a> </a>
</java.util.Arrays_-ArrayList> </java.util.Arrays_-ArrayList>