diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/.classpath b/ diy-layout-creator --username bancika@gmail.com/diylc-core/.classpath index c0ec8be1..ea6c1fc0 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-core/.classpath +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/.classpath @@ -8,6 +8,7 @@ + diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/lib/http-proxy.jar b/ diy-layout-creator --username bancika@gmail.com/diylc-core/lib/http-proxy.jar new file mode 100644 index 00000000..69e750cd Binary files /dev/null and b/ diy-layout-creator --username bancika@gmail.com/diylc-core/lib/http-proxy.jar differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/model/ProjectEntity.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/model/ProjectEntity.java similarity index 100% rename from diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/model/ProjectEntity.java rename to diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/model/ProjectEntity.java diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/ServiceAPI.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/model/ServiceAPI.java similarity index 92% rename from diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/ServiceAPI.java rename to diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/model/ServiceAPI.java index 4ace6d83..1da2b926 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/ServiceAPI.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/model/ServiceAPI.java @@ -1,10 +1,8 @@ -package org.diylc.swing.plugins.online.presenter; +package org.diylc.swing.plugins.online.model; import java.io.File; import java.util.List; -import org.diylc.swing.plugins.online.model.ProjectEntity; - import com.diyfever.httpproxy.ParamName; /*** @@ -123,7 +121,7 @@ public interface ServiceAPI { @ParamName("diylcVersion") String diylcVersion, @ParamName("keywords") String keywords, @ParamName("thumbnail") File thumbnail, - @ParamName("thumbnail") File project); + @ParamName("project") File project); /** * @return a {@link List} of available categories. diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/model/UserEntity.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/model/UserEntity.java new file mode 100644 index 00000000..fa34b057 --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/model/UserEntity.java @@ -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 + "]"; + } + +} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/DIYLCServiceException.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/presenter/DIYLCServiceException.java similarity index 100% rename from diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/DIYLCServiceException.java rename to diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/presenter/DIYLCServiceException.java diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/NotConnectedException.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/presenter/NotConnectedException.java similarity index 100% rename from diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/NotConnectedException.java rename to diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/presenter/NotConnectedException.java diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/NotExistsException.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/presenter/NotExistsException.java similarity index 100% rename from diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/NotExistsException.java rename to diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/presenter/NotExistsException.java diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/NotLoggedInException.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/presenter/NotLoggedInException.java similarity index 100% rename from diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/NotLoggedInException.java rename to diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/presenter/NotLoggedInException.java diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/presenter/OnlinePresenter.java b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/presenter/OnlinePresenter.java new file mode 100644 index 00000000..49c971c9 --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-core/src/org/diylc/swing/plugins/online/presenter/OnlinePresenter.java @@ -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; + } +} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-library/lib/diylc-core.jar b/ diy-layout-creator --username bancika@gmail.com/diylc-library/lib/diylc-core.jar index 11fc89f1..2423721d 100644 Binary files a/ diy-layout-creator --username bancika@gmail.com/diylc-library/lib/diylc-core.jar and b/ diy-layout-creator --username bancika@gmail.com/diylc-library/lib/diylc-core.jar differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/.classpath b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/.classpath index 93e615fe..41b32451 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/.classpath +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/.classpath @@ -8,9 +8,6 @@ - - - diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/.gitignore b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/.gitignore index ae3c1726..446108b8 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/.gitignore +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/.gitignore @@ -1 +1,2 @@ /bin/ +/.apt_generated diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/http-proxy.jar b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/http-proxy.jar index 9561b134..69e750cd 100644 Binary files a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/http-proxy.jar and b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/http-proxy.jar differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/org-openide-awt.jar b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/org-openide-awt.jar deleted file mode 100644 index 1f5db33a..00000000 Binary files a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/org-openide-awt.jar and /dev/null differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/org-openide-util-lookup.jar b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/org-openide-util-lookup.jar deleted file mode 100644 index 0c7ca6b9..00000000 Binary files a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/org-openide-util-lookup.jar and /dev/null differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/org-openide-util.jar b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/org-openide-util.jar deleted file mode 100644 index ccbad910..00000000 Binary files a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/lib/org-openide-util.jar and /dev/null differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/IconLoader.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/IconLoader.java index 15adbee6..5013c46e 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/IconLoader.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/IconLoader.java @@ -39,7 +39,7 @@ public enum IconLoader { "sort.png"), ElementsSelection("elements_selection.png"), BranchAdd( "branch_add.png"), BriefcaseAdd("briefcase_add.png"), BriefcaseInto( "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; diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/arrow.png b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/arrow.png new file mode 100644 index 00000000..f0be9843 Binary files /dev/null and b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/images/arrow.png differ diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/gui/DialogFactory.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/gui/DialogFactory.java index 373e0c3f..3a975ad7 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/gui/DialogFactory.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/gui/DialogFactory.java @@ -13,6 +13,7 @@ import org.diylc.common.PropertyWrapper; import org.diylc.swing.gui.components.OverwritePromptFileChooser; import org.diylc.swing.gui.editor.PropertyEditorDialog; 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.NewUserDialog; import org.diylc.swing.plugins.online.view.UploadDialog; @@ -130,8 +131,8 @@ public class DialogFactory { return dialog; } - public NewUserDialog createNewUserDialog() { - NewUserDialog dialog = new NewUserDialog(mainFrame); + public NewUserDialog createNewUserDialog(UserEntity existingUser) { + NewUserDialog dialog = new NewUserDialog(mainFrame, existingUser); return dialog; } diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/gui/MainFrame.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/gui/MainFrame.java index 1d53a7bc..8d3dfd29 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/gui/MainFrame.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/gui/MainFrame.java @@ -56,6 +56,7 @@ import org.diylc.swing.plugins.file.FileFilterEnum; import org.diylc.swing.plugins.file.FileMenuPlugin; import org.diylc.swing.plugins.help.HelpMenuPlugin; 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.toolbox.ToolBox; import org.diylc.swingframework.ButtonDialog; @@ -98,7 +99,7 @@ public class MainFrame extends JFrame implements ISwingUI { presenter.installPlugin(new EditMenuPlugin(this)); presenter.installPlugin(new ConfigPlugin(this)); presenter.installPlugin(new LayersMenuPlugin(this)); - // presenter.installPlugin(new OnlineManager()); + presenter.installPlugin(new OnlineManager(this)); presenter.installPlugin(new HelpMenuPlugin(this)); presenter.installPlugin(new StatusBar(this)); diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/OnlineManager.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/OnlineManager.java index 89df3425..7a5f0c61 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/OnlineManager.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/OnlineManager.java @@ -10,8 +10,9 @@ import org.diylc.common.EventType; import org.diylc.common.IPlugIn; import org.diylc.common.IPlugInPort; import org.diylc.images.IconLoader; +import org.diylc.swing.ISwingUI; 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.NewUserDialog; import org.diylc.swing.plugins.online.view.UploadDialog; @@ -19,25 +20,29 @@ import org.diylc.swingframework.ProgressDialog; public class OnlineManager implements IPlugIn { - private static final String ONLINE_TITLE = "Online"; + private static final String ONLINE_TITLE = "Project Cloud"; 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 public void connect(IPlugInPort plugInPort) { this.plugInPort = plugInPort; - this.libraryPresenter = new LibraryPresenter(); + this.onlinePresenter = new OnlinePresenter(); 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() { @@ -89,7 +94,7 @@ public class OnlineManager implements IPlugIn { public LoginAction() { super(); - putValue(AbstractAction.NAME, "Log in"); + putValue(AbstractAction.NAME, "Log In"); putValue(AbstractAction.SMALL_ICON, IconLoader.IdCard.getIcon()); } @@ -97,6 +102,7 @@ public class OnlineManager implements IPlugIn { public void actionPerformed(ActionEvent e) { LoginDialog dialog = DialogFactory.getInstance().createLoginDialog(); dialog.setVisible(true); + onlinePresenter.login(dialog.getName(), dialog.getPassword()); } } @@ -112,7 +118,7 @@ public class OnlineManager implements IPlugIn { @Override public void actionPerformed(ActionEvent e) { - NewUserDialog dialog = DialogFactory.getInstance().createNewUserDialog(); + NewUserDialog dialog = DialogFactory.getInstance().createNewUserDialog(null); dialog.setVisible(true); } } diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/LibraryPresenter.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/LibraryPresenter.java deleted file mode 100644 index 8d158808..00000000 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/presenter/LibraryPresenter.java +++ /dev/null @@ -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); - } - -} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/view/NewUserDialog.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/view/NewUserDialog.java index 752b6c70..2b7aab84 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/view/NewUserDialog.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/online/view/NewUserDialog.java @@ -12,10 +12,12 @@ import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPasswordField; +import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import org.diylc.swing.plugins.online.model.UserEntity; import org.diylc.swingframework.ButtonDialog; public class NewUserDialog extends ButtonDialog { @@ -28,17 +30,24 @@ public class NewUserDialog extends ButtonDialog { private JPasswordField passwordField; private JPasswordField confirmPasswordField; private JTextField emailField; + private JTextField websiteField; + private JTextArea bioArea; private String userName; private String password; 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 }); setMinimumSize(new Dimension(240, 32)); layoutGui(); refreshState(); userNameField.setText(System.getProperty("user.name")); + this.existingEntity = existingEntity; } public String getUserName() { @@ -53,6 +62,14 @@ public class NewUserDialog extends ButtonDialog { return email; } + public String getWebsite() { + return website; + } + + public String getBio() { + return bio; + } + @Override protected JComponent getMainComponent() { if (mainPanel == null) { @@ -78,6 +95,12 @@ public class NewUserDialog extends ButtonDialog { gbc.gridy = 3; 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.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 1; @@ -93,6 +116,12 @@ public class NewUserDialog extends ButtonDialog { gbc.gridy = 3; mainPanel.add(getEmailField(), gbc); + + gbc.gridy = 4; + mainPanel.add(getWebsiteField(), gbc); + + gbc.gridy = 5; + mainPanel.add(getBioArea(), gbc); } return mainPanel; } @@ -100,38 +129,46 @@ public class NewUserDialog extends ButtonDialog { private void refreshState() { this.userName = getUserNameField().getText(); String password = new String(getPasswordField().getPassword()); - String confirmPassword = new String(getConfirmPasswordField().getPassword()); + String confirmPassword = new String(getConfirmPasswordField() + .getPassword()); if (password.equals(confirmPassword)) { this.password = password; } else { this.password = null; } this.email = getEmailField().getText(); + this.website = getWebsiteField().getText(); + this.bio = getBioArea().getText(); JButton okButton = getButton(OK); - okButton.setEnabled((this.userName.length() > 0) && (this.password != null) - && (this.password.length() > 0)); + okButton.setEnabled((this.userName.length() > 0) + && (this.password != null) && (this.password.length() > 0)); } private JTextField getUserNameField() { if (userNameField == null) { userNameField = new JTextField(); - userNameField.getDocument().addDocumentListener(new DocumentListener() { + if (existingEntity != null) { + userNameField.setText(existingEntity.getUserName()); + userNameField.setEditable(false); + } + userNameField.getDocument().addDocumentListener( + new DocumentListener() { - @Override - public void removeUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void removeUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void insertUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void insertUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void changedUpdate(DocumentEvent e) { - refreshState(); - } - }); + @Override + public void changedUpdate(DocumentEvent e) { + refreshState(); + } + }); } return userNameField; } @@ -139,23 +176,24 @@ public class NewUserDialog extends ButtonDialog { private JPasswordField getPasswordField() { if (passwordField == null) { passwordField = new JPasswordField(); - passwordField.getDocument().addDocumentListener(new DocumentListener() { + passwordField.getDocument().addDocumentListener( + new DocumentListener() { - @Override - public void removeUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void removeUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void insertUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void insertUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void changedUpdate(DocumentEvent e) { - refreshState(); - } - }); + @Override + public void changedUpdate(DocumentEvent e) { + refreshState(); + } + }); } return passwordField; } @@ -163,23 +201,24 @@ public class NewUserDialog extends ButtonDialog { private JPasswordField getConfirmPasswordField() { if (confirmPasswordField == null) { confirmPasswordField = new JPasswordField(); - confirmPasswordField.getDocument().addDocumentListener(new DocumentListener() { + confirmPasswordField.getDocument().addDocumentListener( + new DocumentListener() { - @Override - public void removeUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void removeUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void insertUpdate(DocumentEvent e) { - refreshState(); - } + @Override + public void insertUpdate(DocumentEvent e) { + refreshState(); + } - @Override - public void changedUpdate(DocumentEvent e) { - refreshState(); - } - }); + @Override + public void changedUpdate(DocumentEvent e) { + refreshState(); + } + }); } return confirmPasswordField; } @@ -187,7 +226,63 @@ public class NewUserDialog extends ButtonDialog { private JTextField getEmailField() { if (emailField == null) { 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 public void removeUpdate(DocumentEvent e) { @@ -205,6 +300,6 @@ public class NewUserDialog extends ButtonDialog { } }); } - return emailField; + return bioArea; } } diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/ComponentButtonFactory.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/ComponentButtonFactory.java index 83107c00..f07f88e5 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/ComponentButtonFactory.java +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/ComponentButtonFactory.java @@ -25,7 +25,7 @@ import org.diylc.common.IPlugInPort; import org.diylc.core.IDIYComponent; import org.diylc.core.Template; 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 @@ -107,8 +107,8 @@ class ComponentButtonFactory { @Override public void keyPressed(KeyEvent e) { - plugInPort.keyPressed(e.getKeyCode(), e.isControlDown(), e - .isShiftDown(), e.isAltDown()); + plugInPort.keyPressed(e.getKeyCode(), e.isControlDown(), + e.isShiftDown(), e.isAltDown()); } }); // addKeyListener(new KeyAdapter() { @@ -163,8 +163,8 @@ class ComponentButtonFactory { JPopupMenu m = (JPopupMenu) c; m.setVisible(false); } - int result = JOptionPane.showConfirmDialog(SwingUtilities - .getRoot(item), + int result = JOptionPane.showConfirmDialog( + SwingUtilities.getRoot(item), "Are you sure you want to delete template \"" + template.getName() + "\"", "Delete", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/DropDownButton.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/DropDownButton.java new file mode 100644 index 00000000..01040734 --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/DropDownButton.java @@ -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 regIcons = new HashMap(5); + private Map arrowIcons = new HashMap(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); + } + } + +} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/DropDownButtonFactory.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/DropDownButtonFactory.java new file mode 100644 index 00000000..9e51bc38 --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/DropDownButtonFactory.java @@ -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); + } +} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/IconWithArrow.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/IconWithArrow.java new file mode 100644 index 00000000..f3acfd1c --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/IconWithArrow.java @@ -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; + } +} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/ImageUtilities.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/ImageUtilities.java new file mode 100644 index 00000000..cfb52a4a --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/ImageUtilities.java @@ -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 = "
"; + + private static final Set extraInitialSlashes = new HashSet(); + 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("
"); + } + 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; + } + } + +} + diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/Lookup.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/Lookup.java new file mode 100644 index 00000000..eb79e7a5 --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/Lookup.java @@ -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 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 lookup(Class paramClass); +// +// public abstract Result lookup(Template paramTemplate); +// +// public Item lookupItem(Template template) { +// Result res = lookup(template); +// Iterator> it = res.allItems().iterator(); +// return it.hasNext() ? (Item) it.next() : null; +// } +// +// public Result lookupResult(Class clazz) { +// return lookup(new Template(clazz)); +// } +// +// public Collection lookupAll(Class clazz) { +// return lookupResult(clazz).allInstances(); +// } +// +// public static final class Template { +// private int hashCode; +// private Class type; +// private String id; +// private T instance; +// +// @Deprecated +// public Template() { +// this(null); +// } +// +// public Template(Class type) { +// this(type, null, null); +// } +// +// public Template(Class type, String id, T instance) { +// this.type = extractType(type); +// this.id = id; +// this.instance = instance; +// } +// +// private Class extractType(Class type) { +// return type == null ? Object.class : type; +// } +// +// public Class 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 { +// public abstract void addLookupListener( +// LookupListener paramLookupListener); +// +// public abstract void removeLookupListener( +// LookupListener paramLookupListener); +// +// public abstract Collection allInstances(); +// +// public Set> allClasses() { +// return Collections.emptySet(); +// } +// +// public Collection> allItems() { +// return Collections.emptyList(); +// } +// } +// +// public static abstract class Item { +// public abstract T getInstance(); +// +// public abstract Class 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 lookup(Class clazz) { +// return null; +// } +// +// public Lookup.Result lookup(Lookup.Template template) { +// return NO_RESULT; +// } +// } +// +// public static abstract interface Provider { +// public abstract Lookup getLookup(); +// } +//} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/LookupEvent.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/LookupEvent.java new file mode 100644 index 00000000..138c9ede --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/LookupEvent.java @@ -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); +// } +//} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/LookupListener.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/LookupListener.java new file mode 100644 index 00000000..2c715ea7 --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/LookupListener.java @@ -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); +//} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/NbBundle.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/NbBundle.java new file mode 100644 index 00000000..f951664b --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/NbBundle.java @@ -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 getLocalizingSuffixes() { + return new LocaleIterator(Locale.getDefault()); + } + + private static class LocaleIterator implements Iterator { + 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(); + } + } +} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/Parameters.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/Parameters.java new file mode 100644 index 00000000..7df6901e --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/Parameters.java @@ -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"); + } + } +} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/Utilities.java b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/Utilities.java new file mode 100644 index 00000000..6126f72e --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/src/org/diylc/swing/plugins/toolbox/openide/Utilities.java @@ -0,0 +1,1175 @@ +package org.diylc.swing.plugins.toolbox.openide; + +import java.awt.Component; +import java.awt.Container; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsEnvironment; +import java.awt.Image; +import java.awt.Insets; +import java.awt.KeyboardFocusManager; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.awt.Window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InvalidObjectException; +import java.lang.ref.Reference; +import java.lang.ref.ReferenceQueue; +import java.lang.ref.SoftReference; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Collection; +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.Vector; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.lang.model.SourceVersion; +import javax.swing.Icon; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; +import javax.swing.Timer; + +public final class Utilities { + private static final Logger LOG = Logger.getLogger(Utilities.class + .getName()); + public static final int OS_WINNT = 1; + public static final int OS_WIN95 = 2; + public static final int OS_WIN98 = 4; + public static final int OS_SOLARIS = 8; + public static final int OS_LINUX = 16; + public static final int OS_HP = 32; + public static final int OS_AIX = 64; + public static final int OS_IRIX = 128; + public static final int OS_SUNOS = 256; + public static final int OS_TRU64 = 512; + @Deprecated + public static final int OS_DEC = 1024; + public static final int OS_OS2 = 2048; + public static final int OS_MAC = 4096; + public static final int OS_WIN2000 = 8192; + public static final int OS_VMS = 16384; + public static final int OS_WIN_OTHER = 32768; + public static final int OS_OTHER = 65536; + public static final int OS_FREEBSD = 131072; + public static final int OS_WINVISTA = 262144; + public static final int OS_UNIX_OTHER = 524288; + public static final int OS_OPENBSD = 1048576; + @Deprecated + public static final int OS_WINDOWS_MASK = 303111; + @Deprecated + public static final int OS_UNIX_MASK = 1709048; + public static final int TYPICAL_WINDOWS_TASKBAR_HEIGHT = 27; + private static final int TYPICAL_MACOSX_MENU_HEIGHT = 24; + private static int operatingSystem = -1; + private static Timer clearIntrospector; + private static ActionListener doClear; + private static final int CTRL_WILDCARD_MASK = 32768; + private static final int ALT_WILDCARD_MASK = 65536; + private static final Object TRANS_LOCK = new Object(); + private static Object transLoader; + private static RE transExp; + private static Reference namesAndValues; + private static Method fileToPath; + private static Method pathToUri; + private static Method pathsGet; + private static Method pathToFile; + + public static int getOperatingSystem() { + if (operatingSystem == -1) { + String osName = System.getProperty("os.name"); + if ("Windows NT".equals(osName)) { + operatingSystem = 1; + } else if ("Windows 95".equals(osName)) { + operatingSystem = 2; + } else if ("Windows 98".equals(osName)) { + operatingSystem = 4; + } else if ("Windows 2000".equals(osName)) { + operatingSystem = 8192; + } else if ("Windows Vista".equals(osName)) { + operatingSystem = 262144; + } else if (osName.startsWith("Windows ")) { + operatingSystem = 32768; + } else if ("Solaris".equals(osName)) { + operatingSystem = 8; + } else if (osName.startsWith("SunOS")) { + operatingSystem = 8; + } else if (osName.endsWith("Linux")) { + operatingSystem = 16; + } else if ("HP-UX".equals(osName)) { + operatingSystem = 32; + } else if ("AIX".equals(osName)) { + operatingSystem = 64; + } else if ("Irix".equals(osName)) { + operatingSystem = 128; + } else if ("SunOS".equals(osName)) { + operatingSystem = 256; + } else if ("Digital UNIX".equals(osName)) { + operatingSystem = 512; + } else if ("OS/2".equals(osName)) { + operatingSystem = 2048; + } else if ("OpenVMS".equals(osName)) { + operatingSystem = 16384; + } else if (osName.equals("Mac OS X")) { + operatingSystem = 4096; + } else if (osName.startsWith("Darwin")) { + operatingSystem = 4096; + } else if (osName.toLowerCase(Locale.US).startsWith("freebsd")) { + operatingSystem = 131072; + } else if ("OpenBSD".equals(osName)) { + operatingSystem = 1048576; + } else if (File.pathSeparatorChar == ':') { + operatingSystem = 524288; + } else { + operatingSystem = 65536; + } + } + return operatingSystem; + } + + public static boolean isWindows() { + return (getOperatingSystem() & 0x4A007) != 0; + } + + public static boolean isMac() { + return (getOperatingSystem() & 0x1000) != 0; + } + + public static boolean isUnix() { + return (getOperatingSystem() & 0x1A13F8) != 0; + } + + static void resetOperatingSystem() { + operatingSystem = -1; + } + + public static boolean isJavaIdentifier(String id) { + if (id == null) { + return false; + } + return (SourceVersion.isIdentifier(id)) + && (!SourceVersion.isKeyword(id)); + } + + public static BeanInfo getBeanInfo(Class clazz) + throws IntrospectionException { + BeanInfo bi; + try { + bi = Introspector.getBeanInfo(clazz); + } catch (IntrospectionException ie) { + throw ie; + } catch (Error e) { + throw e; + } + if (Component.class.isAssignableFrom(clazz)) { + PropertyDescriptor[] pds = bi.getPropertyDescriptors(); + for (int i = 0; i < pds.length; i++) { + if (pds[i].getName().equals("cursor")) { + try { + Method getter = Component.class.getDeclaredMethod( + "getCursor", new Class[0]); + Method setter = Component.class.getDeclaredMethod( + "setCursor", new Class[] { Cursor.class }); + pds[i] = new PropertyDescriptor("cursor", getter, + setter); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } + } + } + } + if (bi != null) { + if (clearIntrospector == null) { + doClear = new ActionListener() { + public void actionPerformed(ActionEvent ev) { + } + }; + clearIntrospector = new Timer(15000, doClear); + clearIntrospector.setRepeats(false); + } + clearIntrospector.restart(); + } + return bi; + } + + public static BeanInfo getBeanInfo(Class clazz, Class stopClass) + throws IntrospectionException { + return Introspector.getBeanInfo(clazz, stopClass); + } + + private static String trimString(String s) { + int idx = 0; + + int slen = s.length(); + if (slen == 0) { + return s; + } + char c; + do { + c = s.charAt(idx++); + } while (((c == '\n') || (c == '\r')) && (idx < slen)); + s = s.substring(--idx); + idx = s.length() - 1; + if (idx < 0) { + return s; + } + do { + c = s.charAt(idx--); + } while (((c == '\n') || (c == '\r')) && (idx >= 0)); + return s.substring(0, idx + 2); + } + + public static String pureClassName(String fullName) { + int index = fullName.indexOf('$'); + if ((index >= 0) && (index < fullName.length())) { + return fullName.substring(index + 1, fullName.length()); + } + return fullName; + } + + @Deprecated + public static boolean isLargeFrameIcons() { + return (getOperatingSystem() == 8) || (getOperatingSystem() == 32); + } + + @Deprecated + public static int arrayHashCode(Object[] arr) { + int c = 0; + int len = arr.length; + for (int i = 0; i < len; i++) { + Object o = arr[i]; + int v = o == null ? 1 : o.hashCode(); + c += (v ^ i); + } + return c; + } + + public static boolean compareObjects(Object o1, Object o2) { + return compareObjectsImpl(o1, o2, 1); + } + + public static boolean compareObjectsImpl(Object o1, Object o2, + int checkArraysDepth) { + if (o1 == null) { + return o2 == null; + } + if (o2 == null) { + return false; + } + if (checkArraysDepth > 0) { + if (((o1 instanceof Object[])) && ((o2 instanceof Object[]))) { + Object[] o1a = (Object[]) o1; + Object[] o2a = (Object[]) o2; + int l1 = o1a.length; + int l2 = o2a.length; + if (l1 != l2) { + return false; + } + for (int i = 0; i < l1; i++) { + if (!compareObjectsImpl(o1a[i], o2a[i], + checkArraysDepth - 1)) { + return false; + } + } + return true; + } + if (((o1 instanceof byte[])) && ((o2 instanceof byte[]))) { + byte[] o1a = (byte[]) o1; + byte[] o2a = (byte[]) o2; + int l1 = o1a.length; + int l2 = o2a.length; + if (l1 != l2) { + return false; + } + for (int i = 0; i < l1; i++) { + if (o1a[i] != o2a[i]) { + return false; + } + } + return true; + } + if (((o1 instanceof short[])) && ((o2 instanceof short[]))) { + short[] o1a = (short[]) o1; + short[] o2a = (short[]) o2; + int l1 = o1a.length; + int l2 = o2a.length; + if (l1 != l2) { + return false; + } + for (int i = 0; i < l1; i++) { + if (o1a[i] != o2a[i]) { + return false; + } + } + return true; + } + if (((o1 instanceof int[])) && ((o2 instanceof int[]))) { + int[] o1a = (int[]) o1; + int[] o2a = (int[]) o2; + int l1 = o1a.length; + int l2 = o2a.length; + if (l1 != l2) { + return false; + } + for (int i = 0; i < l1; i++) { + if (o1a[i] != o2a[i]) { + return false; + } + } + return true; + } + if (((o1 instanceof long[])) && ((o2 instanceof long[]))) { + long[] o1a = (long[]) o1; + long[] o2a = (long[]) o2; + int l1 = o1a.length; + int l2 = o2a.length; + if (l1 != l2) { + return false; + } + for (int i = 0; i < l1; i++) { + if (o1a[i] != o2a[i]) { + return false; + } + } + return true; + } + if (((o1 instanceof float[])) && ((o2 instanceof float[]))) { + float[] o1a = (float[]) o1; + float[] o2a = (float[]) o2; + int l1 = o1a.length; + int l2 = o2a.length; + if (l1 != l2) { + return false; + } + for (int i = 0; i < l1; i++) { + if (o1a[i] != o2a[i]) { + return false; + } + } + return true; + } + if (((o1 instanceof double[])) && ((o2 instanceof double[]))) { + double[] o1a = (double[]) o1; + double[] o2a = (double[]) o2; + int l1 = o1a.length; + int l2 = o2a.length; + if (l1 != l2) { + return false; + } + for (int i = 0; i < l1; i++) { + if (o1a[i] != o2a[i]) { + return false; + } + } + return true; + } + if (((o1 instanceof char[])) && ((o2 instanceof char[]))) { + char[] o1a = (char[]) o1; + char[] o2a = (char[]) o2; + int l1 = o1a.length; + int l2 = o2a.length; + if (l1 != l2) { + return false; + } + for (int i = 0; i < l1; i++) { + if (o1a[i] != o2a[i]) { + return false; + } + } + return true; + } + if (((o1 instanceof boolean[])) && ((o2 instanceof boolean[]))) { + boolean[] o1a = (boolean[]) o1; + boolean[] o2a = (boolean[]) o2; + int l1 = o1a.length; + int l2 = o2a.length; + if (l1 != l2) { + return false; + } + for (int i = 0; i < l1; i++) { + if (o1a[i] != o2a[i]) { + return false; + } + } + return true; + } + } + return o1.equals(o2); + } + + public static String getClassName(Class clazz) { + if (clazz.isArray()) { + return getClassName(clazz.getComponentType()) + "[]"; + } + return clazz.getName(); + } + + public static String getShortClassName(Class clazz) { + if (clazz.isArray()) { + return getShortClassName(clazz.getComponentType()) + "[]"; + } + String name = clazz.getName().replace('$', '.'); + + return name.substring(name.lastIndexOf('.') + 1, name.length()); + } + + public static Object[] toObjectArray(Object array) { + if ((array instanceof Object[])) { + return (Object[]) array; + } + if ((array instanceof int[])) { + int k = ((int[]) array).length; + Integer[] r = new Integer[k]; + for (int i = 0; i < k; i++) { + r[i] = Integer.valueOf(((int[]) (int[]) array)[i]); + } + return r; + } + if ((array instanceof boolean[])) { + int k = ((boolean[]) array).length; + Boolean[] r = new Boolean[k]; + for (int i = 0; i < k; i++) { + r[i] = Boolean.valueOf(((boolean[]) (boolean[]) array)[i]); + } + return r; + } + if ((array instanceof byte[])) { + int k = ((byte[]) array).length; + Byte[] r = new Byte[k]; + for (int i = 0; i < k; i++) { + r[i] = Byte.valueOf(((byte[]) (byte[]) array)[i]); + } + return r; + } + if ((array instanceof char[])) { + int k = ((char[]) array).length; + Character[] r = new Character[k]; + for (int i = 0; i < k; i++) { + r[i] = Character.valueOf(((char[]) (char[]) array)[i]); + } + return r; + } + if ((array instanceof double[])) { + int k = ((double[]) array).length; + Double[] r = new Double[k]; + for (int i = 0; i < k; i++) { + r[i] = Double.valueOf(((double[]) (double[]) array)[i]); + } + return r; + } + if ((array instanceof float[])) { + int k = ((float[]) array).length; + Float[] r = new Float[k]; + for (int i = 0; i < k; i++) { + r[i] = Float.valueOf(((float[]) (float[]) array)[i]); + } + return r; + } + if ((array instanceof long[])) { + int k = ((long[]) array).length; + Long[] r = new Long[k]; + for (int i = 0; i < k; i++) { + r[i] = Long.valueOf(((long[]) (long[]) array)[i]); + } + return r; + } + if ((array instanceof short[])) { + int k = ((short[]) array).length; + Short[] r = new Short[k]; + for (int i = 0; i < k; i++) { + r[i] = Short.valueOf(((short[]) (short[]) array)[i]); + } + return r; + } + throw new IllegalArgumentException(); + } + + public static Class getObjectType(Class c) { + if (!c.isPrimitive()) { + return c; + } + if (c == Integer.TYPE) { + return Integer.class; + } + if (c == Boolean.TYPE) { + return Boolean.class; + } + if (c == Byte.TYPE) { + return Byte.class; + } + if (c == Character.TYPE) { + return Character.class; + } + if (c == Double.TYPE) { + return Double.class; + } + if (c == Float.TYPE) { + return Float.class; + } + if (c == Long.TYPE) { + return Long.class; + } + if (c == Short.TYPE) { + return Short.class; + } + throw new IllegalArgumentException(); + } + + public static Class getPrimitiveType(Class c) { + if (!c.isPrimitive()) { + return c; + } + if (c == Integer.class) { + return Integer.TYPE; + } + if (c == Boolean.class) { + return Boolean.TYPE; + } + if (c == Byte.class) { + return Byte.TYPE; + } + if (c == Character.class) { + return Character.TYPE; + } + if (c == Double.class) { + return Double.TYPE; + } + if (c == Float.class) { + return Float.TYPE; + } + if (c == Long.class) { + return Long.TYPE; + } + if (c == Short.class) { + return Short.TYPE; + } + throw new IllegalArgumentException(); + } + + public static Component getFocusTraversableComponent(Component c) { + if (c.isFocusable()) { + return c; + } + if (!(c instanceof Container)) { + return null; + } + int k = ((Container) c).getComponentCount(); + for (int i = 0; i < k; i++) { + Component v = ((Container) c).getComponent(i); + if (v != null) { + return v; + } + } + return null; + } + + public static String[] parseParameters(String s) { + int NULL = 0; + int INPARAM = 1; + int INPARAMPENDING = 2; + int STICK = 4; + int STICKPENDING = 8; + Vector params = new Vector(5, 5); + + int state = NULL; + StringBuilder buff = new StringBuilder(20); + int slength = s.length(); + for (int i = 0; i < slength; i++) { + char c = s.charAt(i); + if (Character.isWhitespace(c)) { + if (state == NULL) { + if (buff.length() > 0) { + params.addElement(buff.toString()); + buff.setLength(0); + } + } else if (state == STICK) { + params.addElement(buff.toString()); + buff.setLength(0); + state = NULL; + } else if (state == STICKPENDING) { + buff.append('\\'); + params.addElement(buff.toString()); + buff.setLength(0); + state = NULL; + } else if (state == INPARAMPENDING) { + state = INPARAM; + buff.append('\\'); + buff.append(c); + } else { + buff.append(c); + } + } else if (c == '\\') { + if (state == NULL) { + i++; + if (i < slength) { + char cc = s.charAt(i); + if ((cc == '"') || (cc == '\\')) { + buff.append(cc); + } else if (Character.isWhitespace(cc)) { + buff.append(c); + i--; + } else { + buff.append(c); + buff.append(cc); + } + } else { + buff.append('\\'); + + break; + } + } else if (state == INPARAM) { + state = INPARAMPENDING; + } else if (state == INPARAMPENDING) { + buff.append('\\'); + state = INPARAM; + } else if (state == STICK) { + state = STICKPENDING; + } else if (state == STICKPENDING) { + buff.append('\\'); + state = STICK; + } + } else if (c == '"') { + if (state == NULL) { + state = INPARAM; + } else if (state == INPARAM) { + state = STICK; + } else if (state == STICK) { + state = INPARAM; + } else if (state == STICKPENDING) { + buff.append('"'); + state = STICK; + } else { + buff.append('"'); + state = INPARAM; + } + } else { + if (state == INPARAMPENDING) { + buff.append('\\'); + state = INPARAM; + } else if (state == STICKPENDING) { + buff.append('\\'); + state = STICK; + } + buff.append(c); + } + } + if (state == INPARAM) { + params.addElement(buff.toString()); + } else if ((state & (INPARAMPENDING | STICKPENDING)) != 0) { + buff.append('\\'); + params.addElement(buff.toString()); + } else if (buff.length() != 0) { + params.addElement(buff.toString()); + } + String[] ret = new String[params.size()]; + params.copyInto(ret); + + return ret; + } + + public static String escapeParameters(String[] params) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < params.length; i++) { + escapeString(params[i], sb); + sb.append(' '); + } + int len = sb.length(); + if (len > 0) { + sb.setLength(len - 1); + } + return sb.toString().trim(); + } + + private static void escapeString(String s, StringBuffer sb) { + if (s.length() == 0) { + sb.append("\"\""); + + return; + } + boolean hasSpace = false; + int sz = sb.length(); + int slen = s.length(); + for (int i = 0; i < slen; i++) { + char c = s.charAt(i); + if (Character.isWhitespace(c)) { + hasSpace = true; + sb.append(c); + } else if (c == '\\') { + sb.append('\\').append('\\'); + } else if (c == '"') { + sb.append('\\').append('"'); + } else { + sb.append(c); + } + } + if (hasSpace) { + sb.insert(sz, '"'); + sb.append('"'); + } + } + + private static final class NamesAndValues { + final Map keyToString; + final Map stringToKey; + + NamesAndValues(Map keyToString, + Map stringToKey) { + this.keyToString = keyToString; + this.stringToKey = stringToKey; + } + } + + private static synchronized NamesAndValues initNameAndValues() { + if (namesAndValues != null) { + NamesAndValues nav = (NamesAndValues) namesAndValues.get(); + if (nav != null) { + return nav; + } + } + Field[] fields = KeyEvent.class.getDeclaredFields(); + + Map names = new HashMap(fields.length * 4 / 3 + 5, + 0.75F); + Map values = new HashMap(fields.length * 4 / 3 + 5, + 0.75F); + for (Field f : fields) { + if (Modifier.isStatic(f.getModifiers())) { + String name = f.getName(); + if (name.startsWith("VK_")) { + name = name.substring(3); + try { + int numb = f.getInt(null); + names.put(name, Integer.valueOf(numb)); + values.put(Integer.valueOf(numb), name); + } catch (IllegalArgumentException ex) { + } catch (IllegalAccessException ex) { + } + } + } + } + if (names.get("CONTEXT_MENU") == null) { + names.put("CONTEXT_MENU", Integer.valueOf(524)); + values.put(Integer.valueOf(524), "CONTEXT_MENU"); + names.put("WINDOWS", Integer.valueOf(525)); + values.put(Integer.valueOf(525), "WINDOWS"); + } + names.put("MOUSE_WHEEL_UP", Integer.valueOf(656)); + names.put("MOUSE_WHEEL_DOWN", Integer.valueOf(657)); + values.put(Integer.valueOf(656), "MOUSE_WHEEL_UP"); + values.put(Integer.valueOf(657), "MOUSE_WHEEL_DOWN"); + + NamesAndValues nav = new NamesAndValues(values, names); + namesAndValues = new SoftReference(nav); + return nav; + } + + public static String keyToString(KeyStroke stroke) { + StringBuilder sb = new StringBuilder(); + if (addModifiers(sb, stroke.getModifiers())) { + sb.append('-'); + } + appendRest(sb, stroke); + return sb.toString(); + } + + private static void appendRest(StringBuilder sb, KeyStroke stroke) { + String c = (String) initNameAndValues().keyToString.get(Integer + .valueOf(stroke.getKeyCode())); + if (c == null) { + sb.append(stroke.getKeyChar()); + } else { + sb.append(c); + } + } + + public static String keyToString(KeyStroke stroke, boolean portable) { + if (portable) { + StringBuilder sb = new StringBuilder(); + if (addModifiersPortable(sb, stroke.getModifiers())) { + sb.append('-'); + } + appendRest(sb, stroke); + return sb.toString(); + } + return keyToString(stroke); + } + + private static boolean usableKeyOnMac(int key, int mask) { + if (key == 81) { + return false; + } + boolean isMeta = ((mask & 0x4) != 0) || ((mask & 0x80) != 0); + + boolean isAlt = ((mask & 0x8) != 0) || ((mask & 0x200) != 0); + + boolean isOnlyMeta = (isMeta) && ((mask & 0xFEFB) == 0); + if (isOnlyMeta) { + return (key != 72) && (key != 32) && (key != 9); + } + if ((key == 68) && (isMeta) && (isAlt)) { + return false; + } + if ((key == 32) && (isMeta) && ((mask & 0x2) != 0)) { + return false; + } + return true; + } + + private static int getMenuShortcutKeyMask() { + try { + if (!GraphicsEnvironment.isHeadless()) { + return Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); + } + } catch (Throwable ex) { + } + return 2; + } + + private static boolean addModifiers(StringBuilder buf, int modif) { + boolean b = false; + if ((modif & 0x2) != 0) { + buf.append("C"); + b = true; + } + if ((modif & 0x8) != 0) { + buf.append("A"); + b = true; + } + if ((modif & 0x1) != 0) { + buf.append("S"); + b = true; + } + if ((modif & 0x4) != 0) { + buf.append("M"); + b = true; + } + if ((modif & 0x8000) != 0) { + buf.append("D"); + b = true; + } + if ((modif & 0x10000) != 0) { + buf.append("O"); + b = true; + } + return b; + } + + private static boolean addModifiersPortable(StringBuilder buf, int modifiers) { + boolean b = false; + if ((modifiers & 0x1) != 0) { + buf.append('S'); + b = true; + } + if (((isMac()) && ((modifiers & 0x4) != 0)) + || ((!isMac()) && ((modifiers & 0x2) != 0))) { + buf.append('D'); + b = true; + } + if (((isMac()) && ((modifiers & 0x2) != 0)) + || ((!isMac()) && ((modifiers & 0x8) != 0))) { + buf.append('O'); + b = true; + } + if ((isMac()) && ((modifiers & 0x8) != 0)) { + buf.append('A'); + b = true; + } + return b; + } + + private static int readModifiers(String s) throws NoSuchElementException { + int m = 0; + for (int i = 0; i < s.length(); i++) { + switch (s.charAt(i)) { + case 'C': + m |= 0x2; + + break; + case 'A': + m |= 0x8; + + break; + case 'M': + m |= 0x4; + + break; + case 'S': + m |= 0x1; + + break; + case 'D': + m |= 0x8000; + + break; + case 'O': + m |= 0x10000; + + break; + case 'B': + case 'E': + case 'F': + case 'G': + case 'H': + case 'I': + case 'J': + case 'K': + case 'L': + case 'N': + case 'P': + case 'Q': + case 'R': + default: + throw new NoSuchElementException(s); + } + } + return m; + } + + private static GraphicsConfiguration getCurrentGraphicsConfiguration() { + Component focusOwner = KeyboardFocusManager + .getCurrentKeyboardFocusManager().getFocusOwner(); + if (focusOwner != null) { + Window w = SwingUtilities.getWindowAncestor(focusOwner); + if (w != null) { + return w.getGraphicsConfiguration(); + } + } + return GraphicsEnvironment.getLocalGraphicsEnvironment() + .getDefaultScreenDevice().getDefaultConfiguration(); + } + + public static Rectangle getUsableScreenBounds() { + return getUsableScreenBounds(getCurrentGraphicsConfiguration()); + } + + public static Rectangle getUsableScreenBounds(GraphicsConfiguration gconf) { + if (gconf == null) { + gconf = GraphicsEnvironment.getLocalGraphicsEnvironment() + .getDefaultScreenDevice().getDefaultConfiguration(); + } + Rectangle bounds = new Rectangle(gconf.getBounds()); + + String str = System.getProperty("netbeans.screen.insets"); + if (str != null) { + StringTokenizer st = new StringTokenizer(str, ", "); + if (st.countTokens() == 4) { + try { + bounds.y = Integer.parseInt(st.nextToken()); + bounds.x = Integer.parseInt(st.nextToken()); + bounds.height -= bounds.y + + Integer.parseInt(st.nextToken()); + bounds.width -= bounds.x + Integer.parseInt(st.nextToken()); + } catch (NumberFormatException ex) { + LOG.log(Level.WARNING, null, ex); + } + } + return bounds; + } + str = System.getProperty("netbeans.taskbar.height"); + if (str != null) { + bounds.height -= Integer.getInteger(str, 0).intValue(); + + return bounds; + } + try { + Toolkit toolkit = Toolkit.getDefaultToolkit(); + Insets insets = toolkit.getScreenInsets(gconf); + bounds.y += insets.top; + bounds.x += insets.left; + bounds.height -= insets.top + insets.bottom; + bounds.width -= insets.left + insets.right; + } catch (Exception ex) { + LOG.log(Level.WARNING, null, ex); + } + return bounds; + } + + public static Rectangle findCenterBounds(Dimension componentSize) { + return findCenterBounds(getCurrentGraphicsConfiguration(), + componentSize); + } + + private static Rectangle findCenterBounds(GraphicsConfiguration gconf, + Dimension componentSize) { + if (gconf == null) { + gconf = GraphicsEnvironment.getLocalGraphicsEnvironment() + .getDefaultScreenDevice().getDefaultConfiguration(); + } + Rectangle bounds = gconf.getBounds(); + + return new Rectangle(bounds.x + (bounds.width - componentSize.width) + / 2, bounds.y + (bounds.height - componentSize.height) / 2, + componentSize.width, componentSize.height); + } + + private static void loadTranslationFile(RE re, BufferedReader reader, + Set results) throws IOException { + for (;;) { + String line = reader.readLine(); + if (line == null) { + break; + } + if ((line.length() != 0) && (!line.startsWith("#"))) { + String[] pair = re.readPair(line); + if (pair == null) { + throw new InvalidObjectException("Line is invalid: " + line); + } + results.add(pair); + } + } + } + + @Deprecated + public static Image icon2Image(Icon icon) { + return ImageUtilities.icon2Image(icon); + } + + static { + try { + fileToPath = File.class.getMethod("toPath", new Class[0]); + } catch (NoSuchMethodException x) { + } + if (fileToPath != null) { + try { + Class path = Class.forName("java.nio.file.Path"); + pathToUri = path.getMethod("toUri", new Class[0]); + pathsGet = Class.forName("java.nio.file.Paths").getMethod( + "get", new Class[] { URI.class }); + pathToFile = path.getMethod("toFile", new Class[0]); + } catch (Exception x) { + throw new ExceptionInInitializerError(x); + } + } + } + + public static URI toURI(File f) { + if (fileToPath != null) { + try { + URI u = (URI) pathToUri.invoke( + fileToPath.invoke(f, new Object[0]), new Object[0]); + if (u.toString().startsWith("file:///")) { + } + return new URI(u.getScheme(), u.getUserInfo(), u.getHost(), + u.getPort(), u.getPath(), u.getQuery(), u.getFragment()); + } catch (Exception x) { + LOG.log(Level.FINE, "could not convert " + f + " to URI", x); + } + } + String path = f.getAbsolutePath(); + if (path.startsWith("\\\\")) { + if ((!path.endsWith("\\")) && (f.isDirectory())) { + path = path + "\\"; + } + try { + return new URI("file", null, path.replace('\\', '/'), null); + } catch (URISyntaxException x) { + LOG.log(Level.FINE, "could not convert " + f + " to URI", x); + } + } + return f.toURI(); + } + + public static File toFile(URI u) throws IllegalArgumentException { + if (pathsGet != null) { + try { + return (File) pathToFile.invoke( + pathsGet.invoke(null, new Object[] { u }), + new Object[0]); + } catch (Exception x) { + LOG.log(Level.FINE, "could not convert " + u + " to File", x); + } + } + String host = u.getHost(); + if ((host != null) && (!host.isEmpty()) + && ("file".equals(u.getScheme()))) { + return new File("\\\\" + host + u.getPath().replace('/', '\\')); + } + return new File(u); + } + + @Deprecated + public static URL toURL(File f) throws MalformedURLException { + if (f == null) { + throw new NullPointerException(); + } + if (!f.isAbsolute()) { + throw new IllegalArgumentException("Relative path: " + f); + } + URI uri = toURI(f); + + return uri.toURL(); + } + + @Deprecated + public static File toFile(URL u) { + if (u == null) { + throw new NullPointerException(); + } + try { + URI uri = u.toURI(); + + return toFile(uri); + } catch (URISyntaxException use) { + return null; + } catch (IllegalArgumentException iae) { + } + return null; + } + + static abstract interface RE { + public abstract void init(String[] paramArrayOfString1, + String[] paramArrayOfString2); + + public abstract String convert(String paramString); + + public abstract String[] readPair(String paramString); + } + + @Deprecated + public static class UnorderableException extends RuntimeException { + static final long serialVersionUID = 6749951134051806661L; + private Collection unorderable; + private Map deps; + + public UnorderableException(Collection unorderable, Map deps) { + this.unorderable = unorderable; + this.deps = deps; + } + + public UnorderableException(String message, Collection unorderable, + Map deps) { + super(); + this.unorderable = unorderable; + this.deps = deps; + } + + public Collection getUnorderable() { + return this.unorderable; + } + + public Map getDeps() { + return this.deps; + } + } +} diff --git a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/update.xml b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/update.xml index 4c828291..84504fa8 100644 --- a/ diy-layout-creator --username bancika@gmail.com/diylc-swing/update.xml +++ b/ diy-layout-creator --username bancika@gmail.com/diylc-swing/update.xml @@ -1295,7 +1295,7 @@ Potentiometer schematic symbol added - http://code.google.com/p/diy-layout-creator/downloads/list + https://github.com/bancika/diy-layout-creator/releases @@ -1311,7 +1311,7 @@ Improved potentiometer symbol appearance - http://code.google.com/p/diy-layout-creator/downloads/list + https://github.com/bancika/diy-layout-creator/releases @@ -1327,7 +1327,23 @@ Undo works only one level back (bug introduced in 3.29) - http://code.google.com/p/diy-layout-creator/downloads/list + https://github.com/bancika/diy-layout-creator/releases + + + + 3 + 32 + 0 + + 2016-05-09 20:00:00.000 CET + + + + IMPROVEMENT + Reduced DIYLC package size + + + https://github.com/bancika/diy-layout-creator/releases \ No newline at end of file