public void init() { vlog.debug("init called"); setBackground(Color.white); ClassLoader cl = this.getClass().getClassLoader(); ImageIcon icon = new ImageIcon(cl.getResource("com/tigervnc/vncviewer/tigervnc.png")); logo = icon.getImage(); }
public void start() { vlog.debug("start called"); if (version == null || build == null) { ClassLoader cl = this.getClass().getClassLoader(); InputStream stream = cl.getResourceAsStream("com/tigervnc/vncviewer/timestamp"); try { Manifest manifest = new Manifest(stream); Attributes attributes = manifest.getMainAttributes(); version = attributes.getValue("Version"); build = attributes.getValue("Build"); } catch (java.io.IOException e) { } } nViewers++; if (firstApplet) { alwaysShowServerDialog.setParam(true); Configuration.readAppletParams(this); String host = getCodeBase().getHost(); if (vncServerName.getValue() == null && vncServerPort.getValue() != 0) { int port = vncServerPort.getValue(); vncServerName.setParam( host + ((port >= 5900 && port <= 5999) ? (":" + (port - 5900)) : ("::" + port))); } } thread = new Thread(this); thread.start(); }
/** @param frameName title name for frame */ public ShowSavedResults(String frameName) { super(frameName); aboutRes = new JTextArea( "Select a result set from" + "\nthose listed and details" + "\nof that analysis will be" + "\nshown here. Then you can" + "\neither delete or view those" + "\nresults using the buttons below."); aboutScroll = new JScrollPane(aboutRes); ss = new JScrollPane(sp); ss.getViewport().setBackground(Color.white); // resMenu.setLayout(new FlowLayout(FlowLayout.LEFT,10,1)); ClassLoader cl = getClass().getClassLoader(); rfii = new ImageIcon(cl.getResource("images/Refresh_button.gif")); // results status resButtonStatus = new JPanel(new BorderLayout()); Border loweredbevel = BorderFactory.createLoweredBevelBorder(); Border raisedbevel = BorderFactory.createRaisedBevelBorder(); Border compound = BorderFactory.createCompoundBorder(raisedbevel, loweredbevel); statusField = new JTextField(); statusField.setBorder(compound); statusField.setEditable(false); }
/** Use the given ClassLoader rather than using the system class */ protected Class resolveClass(ObjectStreamClass classDesc) throws IOException, ClassNotFoundException { String cname = classDesc.getName(); if (cname.startsWith("[")) { // An array Class component; // component class int dcount; // dimension for (dcount = 1; cname.charAt(dcount) == '['; dcount++) ; if (cname.charAt(dcount) == 'L') { component = loader.loadClass(cname.substring(dcount + 1, cname.length() - 1)); } else { if (cname.length() != dcount + 1) { throw new ClassNotFoundException(cname); // malformed } component = primitiveType(cname.charAt(dcount)); } int dim[] = new int[dcount]; for (int i = 0; i < dcount; i++) { dim[i] = 1; } return Array.newInstance(component, dim).getClass(); } else { return loader.loadClass(cname); } }
public About() { cl = ClassLoader.getSystemClassLoader(); // ----------------------------------------CENTER--------------------------------// imgAbout = new ImageIcon(cl.getResource("om.png")); lblAbout = new JLabel(imgAbout); lblAbout.setBounds(0, 0, 450, 263); JPanel pnlCenter = new JPanel(); pnlCenter.setLayout(null); pnlCenter.add(lblAbout); btnOk = new JButton(new ImageIcon(cl.getResource("ok.png"))); btnOk.setBounds(390, 215, 40, 30); pnlCenter.add(btnOk); btnOk.addActionListener(this); // -----------------------------------CONTAINER----------------------------------// Container c = getContentPane(); c.setLayout(new BorderLayout()); c.add(pnlCenter, BorderLayout.CENTER); setSize(450, 280); setVisible(true); setResizable(false); setLocation(580, 280); // setDefaultCloseOperation(EXIT_ON_CLOSE); }
/** Install Add and Remove Buttons into the toolbar */ private void installAddRemovePointButtons() { URL imgURL = ClassLoader.getSystemResource("ch/tbe/pics/plus.gif"); ImageIcon plus = new ImageIcon(imgURL); imgURL = ClassLoader.getSystemResource("ch/tbe/pics/minus.gif"); ImageIcon minus = new ImageIcon(imgURL); add = new JButton(plus); rem = new JButton(minus); add.setToolTipText(workingViewLabels.getString("plus")); rem.setToolTipText(workingViewLabels.getString("minus")); add.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { WorkingView.this.addRemovePoint(true); } }); rem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { WorkingView.this.addRemovePoint(false); } }); add.setContentAreaFilled(false); add.setBorderPainted(false); rem.setContentAreaFilled(false); rem.setBorderPainted(false); toolbar.add(add); toolbar.add(rem); }
public String readFileFromJAR(String filepath) { String out = ""; try { // setup input buffer ClassLoader cl = this.getClass().getClassLoader(); InputStream instream = cl.getResourceAsStream(filepath); BufferedReader filereader = new BufferedReader(new InputStreamReader(instream)); // read lines String line = filereader.readLine(); while (line != null) { out += "\n" + line; line = filereader.readLine(); } filereader.close(); } catch (Exception e) { // e.printStackTrace(); } return out; }
public static Icon getIcon(String iconName) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); URL url = cl.getResource("test/check/icons/" + iconName + ".gif"); if (url != null) return new ImageIcon(url); url = cl.getResource("test/check/icons/" + iconName + ".png"); if (url != null) return new ImageIcon(url); return null; }
private static Clip getClip(String wavFile) { String soundName = "sound\\" + wavFile + ".wav"; InputStream sound = null; Clip clip = null; try { sound = new FileInputStream(soundName); } catch (FileNotFoundException ex) { sound = ClassLoader.getSystemResourceAsStream(soundName); if (sound == null) { System.out.println("Cant open file " + soundName); return null; } } try { AudioInputStream audioIn = AudioSystem.getAudioInputStream(sound); clip = AudioSystem.getClip(); clip.open(audioIn); } catch (Exception ex) { System.out.println("Error in sound " + wavFile); System.out.println(ex.getMessage()); if (clip != null) { clip.close(); return null; } try { sound.close(); } catch (IOException e) { } } return clip; }
// initialize data hash table servers // read server addresses from file and initialize the servers private void initServers() { try { java.net.URL path = ClassLoader.getSystemResource(clientSettingFile); FileReader fr = new FileReader(path.getFile()); BufferedReader br = new BufferedReader(fr); try { String[] portMap = br.readLine().split(","); mServerCount = portMap.length; mPortMap = new int[mServerCount]; for (int i = 0; i < mServerCount; i++) { mPortMap[i] = Integer.parseInt(portMap[i]); } } catch (IOException e) { e.printStackTrace(); System.exit(-1); } } catch (FileNotFoundException e2) { e2.printStackTrace(); System.exit(-1); } mDhtServerArray = new IDistributedHashTable[mServerCount]; for (int i = 0; i < mServerCount; i++) { try { mDhtServerArray[i] = (IDistributedHashTable) Naming.lookup("rmi://localhost:" + mPortMap[i] + "/DistributedHashTable"); appendOutput("server: " + (i + 1) + " is connected"); } catch (Exception e) { appendOutput("initServers: " + (i + 1) + " " + e.getMessage()); } } }
/** Creates new form display window */ public PZWindow( final PZManager manager, int screenX, int screenY, int width, int height, int drawX, int drawY) { this.manager = manager; java.net.URL url = ClassLoader.getSystemClassLoader().getResource("images/dgu.gif"); if (url != null) setIconImage(java.awt.Toolkit.getDefaultToolkit().getImage(url)); setBounds(screenX, screenY, width, height); setMySize(width, height, 1.0f); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); // setup the canvas for the window to draw final Container cp = getContentPane(); cp.setLayout(null); cp.add(lblCanvas); lblCanvas.setBorder(BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); lblCanvas.setDoubleBuffered(true); lblCanvas.setFocusable(true); initEventListeners(); drawOffset.set(drawX, drawY); }
public NodeSettingsPanel() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } // Try to get icons for the toolbar buttons try { ClassLoader loader = getClass().getClassLoader(); mClusterIcon = new ImageIcon(loader.getResource(COMMON_IMG_ROOT + "/ClusterIcon.png")); mIconLabel.setIcon(mClusterIcon); } catch (Exception e) { // Ack! No icons. Use text labels instead mIconLabel.setText(""); } }
@Nullable public static Icon findIcon(@NotNull String path, @NotNull ClassLoader classLoader) { path = undeprecate(path); if (isReflectivePath(path)) return getReflectiveIcon(path, classLoader); if (!StringUtil.startsWithChar(path, '/')) return null; final URL url = classLoader.getResource(path.substring(1)); return findIcon(url); }
private MultiMap<String, ProjectTemplate> loadLocalTemplates() { ConcurrentMultiMap<String, ProjectTemplate> map = new ConcurrentMultiMap<String, ProjectTemplate>(); ProjectTemplateEP[] extensions = ProjectTemplateEP.EP_NAME.getExtensions(); for (ProjectTemplateEP ep : extensions) { ClassLoader classLoader = ep.getLoaderForClass(); URL url = classLoader.getResource(ep.templatePath); if (url != null) { LocalArchivedTemplate template = new LocalArchivedTemplate(url, classLoader); if (ep.category) { TemplateBasedCategory category = new TemplateBasedCategory(template, ep.projectType); myTemplatesMap.putValue(new TemplatesGroup(category), template); } else { map.putValue(ep.projectType, template); } } } return map; }
public SidebarOption(String labelTxt, String rsc) { label = new JLabel(labelTxt); label.setForeground(Color.WHITE); label.setFont(font); add(label); setOpaque(false); setMaximumSize(new Dimension(1000, label.getPreferredSize().height + 5)); this.rsc = ClassLoader.getSystemClassLoader().getResource(rsc); }
boolean tryDir(String d) { ClassLoader L = getClass().getClassLoader(); File p = new File(d, PACKAGE); // System.out.println("Try "+p); if (!p.exists() || !p.isDirectory()) return false; for (File f : p.listFiles()) { String s = f.getName(); if (!s.endsWith(".class")) continue; String name = s.substring(0, s.length() - 6); try { Class<?> c = L.loadClass(PACKAGE + "." + name); if (!Quotation.class.isAssignableFrom(c)) continue; Q.put(name, (Quotation) c.newInstance()); System.out.println(" " + name); // ClassNotFoundException InstantiationException IllegalAccessException } catch (Exception e) { continue; } } return Q.size() > 0; }
/** * Creates a new FlowClient * * @throws IOException */ private FlowClient() { // loads things super("Flow"); // sets the icon in the task bar try { this.setIconImage(ImageIO.read(ClassLoader.getSystemResource("images/icon.png"))); } catch (IOException e) { JOptionPane.showConfirmDialog( this, "Window icon not found", "Missing Image", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); } // Sets up communications with the server Communicator.initComms(JOptionPane.showInputDialog(null, "TEMP: ENTER IP", "127.0.0.1")); // Creates a new PanelManager manager = PanelManager.createNewInstance(this); this.add(manager); // JFrame setup this.setResizable(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Logs off the client when the "big red X" is pressed Runtime.getRuntime() .addShutdownHook( new Thread( new Runnable() { @Override public void run() { // Generates a new data packet and sends to server Data logOff = new Data("end_session"); UUID sessionID = Communicator.getSessionID(); if (sessionID == null) return; Communicator.killAsync(); Communicator.communicate(logOff); } })); this.setSize( (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() * 0.8), (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() * 0.8)); this.setLocation( (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() * 0.1), (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight() * 0.1)); this.setVisible(true); }
Sidebar() { super(BoxLayout.Y_AXIS); try { back = ImageIO.read( ClassLoader.getSystemClassLoader() .getResource("org/madeirahs/editor/ui/help_sidebar.png")); scaleImage(); setPreferredSize(new Dimension(back.getWidth(), back.getHeight())); } catch (IOException e) { e.printStackTrace(); } }
/** * Enumerates the resouces in a give package name. This works even if the resources are loaded * from a jar file! * * <p>Adapted from code by mikewse on the java.sun.com message boards. * http://forum.java.sun.com/thread.jsp?forum=22&thread=30984 * * @param packageName The package to enumerate * @return A Set of Strings for each resouce in the package. */ public static Set getResoucesInPackage(String packageName) throws IOException { String localPackageName; if (packageName.endsWith("/")) { localPackageName = packageName; } else { localPackageName = packageName + '/'; } Enumeration dirEnum = ClassLoader.getSystemResources(localPackageName); Set names = new HashSet(); // Loop CLASSPATH directories while (dirEnum.hasMoreElements()) { URL resUrl = (URL) dirEnum.nextElement(); // Pointing to filesystem directory if (resUrl.getProtocol().equals("file")) { File dir = new File(resUrl.getFile()); File[] files = dir.listFiles(); if (files != null) { for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.isDirectory()) continue; names.add(localPackageName + file.getName()); } } // Pointing to Jar file } else if (resUrl.getProtocol().equals("jar")) { JarURLConnection jconn = (JarURLConnection) resUrl.openConnection(); JarFile jfile = jconn.getJarFile(); Enumeration entryEnum = jfile.entries(); while (entryEnum.hasMoreElements()) { JarEntry entry = (JarEntry) entryEnum.nextElement(); String entryName = entry.getName(); // Exclude our own directory if (entryName.equals(localPackageName)) continue; String parentDirName = entryName.substring(0, entryName.lastIndexOf('/') + 1); if (!parentDirName.equals(localPackageName)) continue; names.add(entryName); } } else { // Invalid classpath entry } } return names; }
public static ToolBox fromFile( String filename, Board board, int toolHeight, int toolReserveBarWidth, int toolTextWidth) { InputStream fis = null; try { fis = new FileInputStream(filename); } catch (FileNotFoundException e) { fis = ClassLoader.getSystemClassLoader().getResourceAsStream(filename); } ToolBox toolBox = fromStream(fis, board); toolBox.toolHeight = toolHeight; toolBox.toolReserveBarWidth = toolReserveBarWidth; toolBox.toolTextWidth = toolTextWidth; return toolBox; }
public ProgressDialog(Frame frame, String s, URL url, String s1) { super(s); bytesTransferred = -1L; properties = HJBProperties.getHJBProperties("hjbrowser"); java.awt.Color color = properties.getColor("hotjava.background", null); if (color != null) setBackground(color); GridBagLayout gridbaglayout = new GridBagLayout(); setLayout(gridbaglayout); GridBagConstraints gridbagconstraints = new GridBagConstraints(); gridbagconstraints.gridx = 0; gridbagconstraints.anchor = 17; gridbagconstraints.weightx = 1.0D; String s2 = properties.getProperty("progressDialog.url.label", "Source:"); addComponent(gridbaglayout, gridbagconstraints, new Label(s2 + " " + url)); s2 = properties.getProperty("progressDialog.saveInto.label", "Destination:"); addComponent(gridbaglayout, gridbagconstraints, new Label(s2 + " " + s1)); gridbagconstraints.ipady = 2; bytesTransferredPrefix = properties.getProperty("progressDialog.transfer.label", "Bytes transferred:") + " "; bytesTransferredInd = new BytesTransferredInd(); addComponent(gridbaglayout, gridbagconstraints, bytesTransferredInd); bpsInd = new BPSIndicator(); addComponent(gridbaglayout, gridbagconstraints, bpsInd); gridbagconstraints.weighty = 1.0D; gridbagconstraints.anchor = 15; gridbagconstraints.insets = new Insets(0, 0, 5, 0); stopButton = new UIHJButton("progressDialog.stop", true, properties); stopButton.addActionListener(this); addComponent(gridbaglayout, gridbagconstraints, stopButton); pack(); centerOnScreen(frame); Toolkit toolkit = Toolkit.getDefaultToolkit(); try { URL url1 = ClassLoader.getSystemResource("lib/images/hotjava.icon.gif"); java.awt.Image image = toolkit.getImage(url1); setIconImage(image); return; } catch (Exception _ex) { return; } }
public WalletSumPanel(BigInteger balance) { this.setBackground(Color.WHITE); double width = this.getSize().getWidth(); this.setPreferredSize(new Dimension(500, 50)); Border line = BorderFactory.createLineBorder(Color.LIGHT_GRAY); Border empty = new EmptyBorder(5, 8, 5, 8); CompoundBorder border = new CompoundBorder(line, empty); JLabel addressField = new JLabel(); addressField.setPreferredSize(new Dimension(300, 35)); this.add(addressField); JTextField amount = new JTextField(); amount.setBorder(border); amount.setEnabled(true); amount.setEditable(false); amount.setText(Utils.getValueShortString(balance)); amount.setPreferredSize(new Dimension(100, 35)); amount.setForeground(new Color(143, 170, 220)); amount.setHorizontalAlignment(SwingConstants.RIGHT); amount.setFont(new Font("Monospaced", 0, 13)); amount.setBackground(Color.WHITE); this.add(amount); URL payoutIconURL = ClassLoader.getSystemResource("buttons/wallet-pay.png"); ImageIcon payOutIcon = new ImageIcon(payoutIconURL); JLabel payOutLabel = new JLabel(payOutIcon); payOutLabel.setToolTipText("Payout for all address list"); payOutLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); payOutLabel.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { JOptionPane.showMessageDialog(null, "Under construction"); } }); this.add(payOutLabel); }
/** * Constructor del juego que inicializa los valores. * * @param juga * @param jugadorActual */ public Juego(ArrayList<Jugador> juga, Jugador jugadorActual) { jugadores = new ArrayList<>(); this.jugadores = juga; this.jugador = jugadorActual; loader = Juego.class.getClassLoader(); utilidades = new Util(); claseTime = new Time(); ventana = new JFrame("Concéntrese - Juan S."); ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ventana.setSize(520, 475); ventana.setLayout(null); ventana.setResizable(false); contadorJugadas = 0; cartaPorDefecto = new ImageIcon(loader.getResource("recursos/carta8.gif")); panel = new JPanel(); panel.setSize(300, 450); panel.setLayout(new GridLayout(4, 4)); intentos = new JLabel("Intento : 0"); etiquetaTiempoPartida = new JLabel("Tiempo: "); tiempoPartida = new JLabel("00.00.000"); etiquetaTiempoPartida.setFont(etiquetaTiempoPartida.getFont().deriveFont(20.0f)); tiempoPartida.setFont(tiempoPartida.getFont().deriveFont(20.0f)); intentos.setFont(intentos.getFont().deriveFont(20.0f)); intentos.setBounds(320, 50, 200, 30); tiempoPartida.setBounds(420, 5, 200, 30); etiquetaTiempoPartida.setBounds(320, 5, 200, 30); ventana.add(tiempoPartida); ventana.add(etiquetaTiempoPartida); ventana.add(intentos); ventana.add(panel); crearMenuSuperior(); crearMatrizIconos(); crearArrayBotones(); crearTemporizador(); ventana.setLocationRelativeTo(null); ventana.setVisible(true); }
/** Éste método crea una matriz con íconos y los asigna a cada botón. */ private void crearMatrizIconos() { ImageIcon[][] miMatrizIconos = new ImageIcon[4][4]; iconos = new ArrayList<>(); int indice = 0; for (int i = 0; i < 4; ++i) { for (int j = 0; j < 4; j++) { if (indice >= nombreCartas.length) { indice = 0; } miMatrizIconos[i][j] = new ImageIcon(loader.getResource("recursos/" + nombreCartas[indice])); miMatrizIconos[i][j].setDescription( nombreCartas[ indice]); // set description sirve para dar al usuario una breve explicacion textual // de la imagen. iconos.add(miMatrizIconos[i][j]); ++indice; } } Collections.shuffle( iconos); // el metodo shuffle de la clase collections sirve para bajarar las cartas, es un // randomizador de arraylist. }
/** Look on disk for an editor with the class name 'ocName'. */ PluggableEditor loadEditorFromDisk(String ocName) { // if here, we need to look on disk for a pluggable editor class... log.finer("looking for ocName: " + ocName); try { Class c = myLoader.loadClass(ocName); Constructor constructor = c.getConstructor(new Class[0]); // XXX If the pluggable editor has an error in the constructor, under some // XXX circumstances it can fail so badly that this call never returns, and // XXX the thread hangs! It doesn't even get to the exception handler below... // XXX but sometimes if the constructor fails everything works as expected. Wierd. PluggableEditor editor = (PluggableEditor) constructor.newInstance(new Object[0]); editors.put(ocName, editor); // add the new editor to our list return editor; } catch (Exception e) // expected condition - just means no pluggable editor available { if (e instanceof InvocationTargetException) // rare exception - an error was encountered in the plugin's // constructor. { log.warning("unable to load special editor for: '" + ocName + "' " + e); if (JXConfig.debugLevel >= 1) { log.warning("Error loading plugin class: "); ((InvocationTargetException) e).getTargetException().printStackTrace(); } } log.log(Level.FINEST, "'Expected' Error loading " + ocName, e); editors.put(ocName, NONE); // add a blank place holder - we can't load // an editor for this, and there's no point looking again. (change if want dynamic loading, // i.e. look *every* time) } return null; // only here if an error has occured. }
public static MetaDataLoader getV2ResourceMetaDataLoader(String resourceFile) { if (resourceFile == null) resourceFile = ""; else resourceFile = resourceFile.trim(); // if (v2Loader == null) System.out.println("CCC v3 meta loader (1) : " + resourceFile); // else System.out.println("CCC v3 meta loader (2) : " + v2Loader.getPath() + ", " + // resourceFile); if (resourceFile.equalsIgnoreCase("null")) resourceFile = ""; if (!resourceFile.equals("")) { MetaDataLoader loader = null; File ff = new File(resourceFile); if (!ff.exists()) { System.out.println( "HL7MessageTreeException00 : This is not a valid file or directory path => " + resourceFile); return null; } if (ff.isFile()) { try { loader = new MetaDataLoader( resourceFile, edu.knu.medinfo.hl7.v2tree.util.Config.DEFAULT_VERSION); } catch (HL7MessageTreeException he) { System.out.println("HL7MessageTreeException01 : " + he.getMessage()); // he.printStackTrace(); try { loader = new MetaDataLoader( resourceFile, null, edu.knu.medinfo.hl7.v2tree.util.Config.DEFAULT_VERSION); } catch (HL7MessageTreeException he1) { System.out.println("HL7MessageTreeException02 : " + he1.getMessage()); return null; } } } else { try { loader = new MetaDataLoader( resourceFile, null, edu.knu.medinfo.hl7.v2tree.util.Config.DEFAULT_VERSION); } catch (HL7MessageTreeException he1) { System.out.println("HL7MessageTreeException03 : " + he1.getMessage()); return null; } } if (loader != null) { v2Loader = loader; return loader; } } if (v2Loader == null) { MetaDataLoader loader = null; try { loader = new MetaDataLoader(); } catch (HL7MessageTreeException he) { loader = null; } if (loader != null) { v2Loader = loader; return loader; } String name = "v2Meta/version2.4/MessageStructure/ADT_A01.dat"; Enumeration<URL> fileURLs = null; try { fileURLs = ClassLoader.getSystemResources(name); } catch (IOException ie) { System.out.println("IOException #1 : " + ie.getMessage()); } if (fileURLs == null) { System.out.println("ClassLoader Result : " + name + " : Not Found"); return null; } // System.out.println("Number of Result : " + fileURLs.toString()); boolean found = false; while (fileURLs.hasMoreElements()) { URL fileURL = fileURLs.nextElement(); String url = fileURL.toString(); if ((url.toLowerCase().startsWith("jar:")) || (url.toLowerCase().startsWith("zip:"))) { int idx = url.indexOf("!"); if (idx < 0) { System.err.println("Invalid jar file url : " + url); continue; } String jarFileName = url.substring(4, idx); try { v2Loader = new MetaDataLoader(jarFileName); found = true; } catch (HL7MessageTreeException he) { continue; } } if ((found) && (v2Loader != null)) return v2Loader; } v2Loader = null; return null; } else return v2Loader; }
/** * Creates a new <code>java.awt.Frame</code>. This frame is the root for the AWT components that * will be embedded within the composite. In order for the embedding to succeed, the composite * must have been created with the SWT.EMBEDDED style. * * <p>IMPORTANT: As of JDK1.5, the embedded frame does not receive mouse events. When a * lightweight component is added as a child of the embedded frame, the cursor does not change. In * order to work around both these problems, it is strongly recommended that a heavyweight * component such as <code>java.awt.Panel</code> be added to the frame as the root of all * components. * * @param parent the parent <code>Composite</code> of the new <code>java.awt.Frame</code> * @return a <code>java.awt.Frame</code> to be the parent of the embedded AWT components * @exception IllegalArgumentException * <ul> * <li>ERROR_NULL_ARGUMENT - if the parent is null * <li>ERROR_INVALID_ARGUMENT - if the parent Composite does not have the SWT.EMBEDDED style * </ul> * * @since 3.0 */ public static Frame new_Frame(final Composite parent) { if (parent == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if ((parent.getStyle() & SWT.EMBEDDED) == 0) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } final int /*long*/ handle = parent.view.id; Class clazz = null; try { String className = embeddedFrameClass != null ? embeddedFrameClass : "apple.awt.CEmbeddedFrame"; if (embeddedFrameClass == null) { clazz = Class.forName(className, true, ClassLoader.getSystemClassLoader()); } else { clazz = Class.forName(className); } } catch (ClassNotFoundException cne) { SWT.error(SWT.ERROR_NOT_IMPLEMENTED, cne); } catch (Throwable e) { SWT.error(SWT.ERROR_UNSPECIFIED, e, " [Error while starting AWT]"); } initializeSwing(); Object value = null; Constructor constructor = null; try { constructor = clazz.getConstructor(new Class[] {long.class}); value = constructor.newInstance(new Object[] {new Long(handle)}); } catch (Throwable e) { SWT.error(SWT.ERROR_NOT_IMPLEMENTED, e); } final Frame frame = (Frame) value; frame.addNotify(); parent.setData(EMBEDDED_FRAME_KEY, frame); /* Forward the iconify and deiconify events */ final Listener shellListener = new Listener() { public void handleEvent(Event e) { switch (e.type) { case SWT.Deiconify: EventQueue.invokeLater( new Runnable() { public void run() { frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_DEICONIFIED)); } }); break; case SWT.Iconify: EventQueue.invokeLater( new Runnable() { public void run() { frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_ICONIFIED)); } }); break; } } }; Shell shell = parent.getShell(); shell.addListener(SWT.Deiconify, shellListener); shell.addListener(SWT.Iconify, shellListener); /* * Generate the appropriate events to activate and deactivate * the embedded frame. This is needed in order to make keyboard * focus work properly for lightweights. */ Listener listener = new Listener() { public void handleEvent(Event e) { switch (e.type) { case SWT.Dispose: Shell shell = parent.getShell(); shell.removeListener(SWT.Deiconify, shellListener); shell.removeListener(SWT.Iconify, shellListener); parent.setVisible(false); EventQueue.invokeLater( new Runnable() { public void run() { try { frame.dispose(); } catch (Throwable e) { } } }); break; case SWT.FocusIn: EventQueue.invokeLater( new Runnable() { public void run() { if (frame.isActive()) return; try { Class clazz = frame.getClass(); Method method = clazz.getMethod( "synthesizeWindowActivation", new Class[] {boolean.class}); if (method != null) method.invoke(frame, new Object[] {new Boolean(true)}); } catch (Throwable e) { e.printStackTrace(); } } }); break; case SWT.Deactivate: EventQueue.invokeLater( new Runnable() { public void run() { if (!frame.isActive()) return; try { Class clazz = frame.getClass(); Method method = clazz.getMethod( "synthesizeWindowActivation", new Class[] {boolean.class}); if (method != null) method.invoke(frame, new Object[] {new Boolean(false)}); } catch (Throwable e) { e.printStackTrace(); } } }); break; } } }; parent.addListener(SWT.FocusIn, listener); parent.addListener(SWT.Deactivate, listener); parent.addListener(SWT.Dispose, listener); parent .getDisplay() .asyncExec( new Runnable() { public void run() { if (parent.isDisposed()) return; final Rectangle clientArea = parent.getClientArea(); EventQueue.invokeLater( new Runnable() { public void run() { frame.setSize(clientArea.width, clientArea.height); frame.validate(); // Bug in Cocoa AWT? For some reason the frame isn't showing up on first // draw. // Toggling visibility seems to be the only thing that works. frame.setVisible(false); frame.setVisible(true); } }); } }); return frame; }
/** * Instantiate a JavaBean. * * @param classLoader the class-loader from which we should create the bean. If this is null, then * the system class-loader is used. * @param beanName the name of the bean within the class-loader. For example "sun.beanbox.foobah" * @exception java.lang.ClassNotFoundException if the class of a serialized object could not be * found. * @exception java.io.IOException if an I/O error occurs. */ public static Object instantiate(ClassLoader cls, String beanName) throws java.io.IOException, ClassNotFoundException { java.io.InputStream ins; java.io.ObjectInputStream oins = null; Object result = null; boolean serialized = false; java.io.IOException serex = null; // If the given classloader is null, we check if an // system classloader is available and (if so) // use that instead. // Note that calls on the system class loader will // look in the bootstrap class loader first. if (cls == null) { try { cls = ClassLoader.getSystemClassLoader(); } catch (SecurityException ex) { // We're not allowed to access the system class loader. // Drop through. } } // Try to find a serialized object with this name final String serName = beanName.replace('.', '/').concat(".ser"); final ClassLoader loader = cls; ins = (InputStream) java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { public Object run() { if (loader == null) return ClassLoader.getSystemResourceAsStream(serName); else return loader.getResourceAsStream(serName); } }); if (ins != null) { try { if (cls == null) { oins = new ObjectInputStream(ins); } else { oins = new ObjectInputStreamWithLoader(ins, cls); } result = oins.readObject(); serialized = true; oins.close(); } catch (java.io.IOException ex) { ins.close(); // Drop through and try opening the class. But remember // the exception in case we can't find the class either. serex = ex; } catch (ClassNotFoundException ex) { ins.close(); throw ex; } } if (result == null) { // No serialized object, try just instantiating the class Class cl; try { if (cls == null) { cl = Class.forName(beanName); } else { cl = cls.loadClass(beanName); } } catch (ClassNotFoundException ex) { // There is no appropriate class. If we earlier tried to // deserialize an object and got an IO exception, throw that, // otherwise rethrow the ClassNotFoundException. if (serex != null) { throw serex; } throw ex; } /* * Try to instantiate the class. */ try { result = cl.newInstance(); } catch (Exception ex) { // We have to remap the exception to one in our signature. // But we pass extra information in the detail message. throw new ClassNotFoundException("" + cl + " : " + ex); } } if (result != null) { // Ok, if the result is an applet initialize it. AppletStub stub = null; if (result instanceof Applet) { Applet applet = (Applet) result; // Figure our the codebase and docbase URLs. We do this // by locating the URL for a known resource, and then // massaging the URL. // First find the "resource name" corresponding to the bean // itself. So a serialzied bean "a.b.c" would imply a // resource name of "a/b/c.ser" and a classname of "x.y" // would imply a resource name of "x/y.class". final String resourceName; if (serialized) { // Serialized bean resourceName = beanName.replace('.', '/').concat(".ser"); } else { // Regular class resourceName = beanName.replace('.', '/').concat(".class"); } URL objectUrl = null; URL codeBase = null; URL docBase = null; // Now get the URL correponding to the resource name. final ClassLoader cloader = cls; objectUrl = (URL) java.security.AccessController.doPrivileged( new java.security.PrivilegedAction() { public Object run() { if (cloader == null) return ClassLoader.getSystemResource(resourceName); else return cloader.getResource(resourceName); } }); // If we found a URL, we try to locate the docbase by taking // of the final path name component, and the code base by taking // of the complete resourceName. // So if we had a resourceName of "a/b/c.class" and we got an // objectURL of "file://bert/classes/a/b/c.class" then we would // want to set the codebase to "file://bert/classes/" and the // docbase to "file://bert/classes/a/b/" if (objectUrl != null) { String s = objectUrl.toExternalForm(); if (s.endsWith(resourceName)) { int ix = s.length() - resourceName.length(); codeBase = new URL(s.substring(0, ix)); docBase = codeBase; ix = s.lastIndexOf('/'); if (ix >= 0) { docBase = new URL(s.substring(0, ix + 1)); } } } // Setup a default context and stub. BeansAppletContext context = new BeansAppletContext(applet); stub = (AppletStub) new BeansAppletStub(applet, context, codeBase, docBase); applet.setStub(stub); // If it was deserialized then it was already init-ed. // Otherwise we need to initialize it. if (!serialized) { // We need to set a reasonable initial size, as many // applets are unhappy if they are started without // having been explicitly sized. applet.setSize(100, 100); applet.init(); } ((BeansAppletStub) stub).active = true; } } return result; }
private void jbInit() throws Exception { titledBorder1 = new TitledBorder(""); this.setLayout(baseLayout); double[][] lower_size = { {TableLayout.PREFERRED, TableLayout.FILL, 25}, {25, 25, TableLayout.FILL} }; mLowerPanelLayout = new TableLayout(lower_size); mLowerPanel.setLayout(mLowerPanelLayout); double[][] dir_size = { {TableLayout.FILL, TableLayout.PREFERRED}, {TableLayout.PREFERRED, TableLayout.FILL} }; mDirectionsPanelLayout = new TableLayout(dir_size); mDirectionsPanel.setLayout(mDirectionsPanelLayout); // Try to get icons for the toolbar buttons try { ClassLoader loader = getClass().getClassLoader(); mAddIcon = new ImageIcon(loader.getResource(COMMON_IMG_ROOT + "/add.gif")); mRemoveIcon = new ImageIcon(loader.getResource(COMMON_IMG_ROOT + "/remove.gif")); mDisabledRemoveIcon = new ImageIcon(loader.getResource(COMMON_IMG_ROOT + "/remove_disabled.gif")); mAddNodeBtn.setIcon(mAddIcon); mRemoveNodeBtn.setIcon(mRemoveIcon); mRemoveNodeBtn.setDisabledIcon(mDisabledRemoveIcon); } catch (Exception e) { // Ack! No icons. Use text labels instead mAddNodeBtn.setText("Add"); mRemoveNodeBtn.setText("Remove"); } /* mAddNodeBtn.setMaximumSize(new Dimension(130, 33)); mAddNodeBtn.setMinimumSize(new Dimension(130, 33)); mAddNodeBtn.setPreferredSize(new Dimension(130, 33)); mAddNodeBtn.setText("Add Node"); */ mAddNodeBtn.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { mAddNodeBtn_actionPerformed(e); } }); /* mRemoveNodeBtn.setMaximumSize(new Dimension(130, 33)); mRemoveNodeBtn.setMinimumSize(new Dimension(130, 33)); mRemoveNodeBtn.setPreferredSize(new Dimension(130, 33)); mRemoveNodeBtn.setText("Remove Node"); */ mRemoveNodeBtn.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { mRemoveNode(); } }); mHostnameLabel.setHorizontalAlignment(SwingConstants.TRAILING); mHostnameLabel.setLabelFor(mHostnameField); mHostnameLabel.setText("Hostname:"); mHostnameField.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { mAddNodeBtn_actionPerformed(e); } }); mDirectionsPanel.setBorder(BorderFactory.createEtchedBorder()); mTitleLabel.setFont(new java.awt.Font("Serif", 1, 20)); mTitleLabel.setHorizontalAlignment(SwingConstants.CENTER); mTitleLabel.setText("Add Cluster Nodes"); mDirectionsLabel.setText("Click on the add button to add nodes to your cluster configuration."); mDirectionsLabel.setLineWrap(true); mDirectionsLabel.setEditable(false); mDirectionsLabel.setBackground(mTitleLabel.getBackground()); baseLayout.setHgap(5); baseLayout.setVgap(5); mLowerPanel.add( mHostnameLabel, new TableLayoutConstraints(0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL)); mLowerPanel.add( mHostnameField, new TableLayoutConstraints(1, 0, 1, 0, TableLayout.FULL, TableLayout.FULL)); mLowerPanel.add( mListScrollPane1, new TableLayoutConstraints(0, 1, 1, 2, TableLayout.FULL, TableLayout.FULL)); mLowerPanel.add( mAddNodeBtn, new TableLayoutConstraints(2, 0, 2, 0, TableLayout.FULL, TableLayout.FULL)); mLowerPanel.add( mRemoveNodeBtn, new TableLayoutConstraints(2, 1, 2, 1, TableLayout.FULL, TableLayout.FULL)); this.add(mLowerPanel, BorderLayout.CENTER); mListScrollPane1.getViewport().add(lstNodes, null); mDirectionsPanel.add( mTitleLabel, new TableLayoutConstraints(0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL)); mDirectionsPanel.add( mDirectionsLabel, new TableLayoutConstraints(0, 1, 0, 1, TableLayout.FULL, TableLayout.FULL)); mDirectionsPanel.add( mIconLabel, new TableLayoutConstraints(1, 0, 1, 1, TableLayout.FULL, TableLayout.FULL)); this.add(mDirectionsPanel, BorderLayout.NORTH); }
/** * ERROR (exceptions) WARN (when something happens that's not supposed to) INFO (wire output) * DEBUG (test/displaying intermediate values), TRACE (start/end method) */ public ConnectionConsoleWindow(ToolBar toolBar) { final ConnectionConsoleWindow thisConsole = this; this.toolBar = toolBar; java.net.URL url = ClassLoader.getSystemResource("ethereum-icon.png"); Toolkit kit = Toolkit.getDefaultToolkit(); Image img = kit.createImage(url); this.setIconImage(img); addCloseAction(); JPanel cp = new JPanel(new BorderLayout()); AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance(); atmf.putMapping("text/console", "org.ethereum.gui.ConsoleTokenMaker"); textArea = new RSyntaxTextArea(16, 44); textArea.setSyntaxEditingStyle("text/console"); // textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_LISP); textArea.setCodeFoldingEnabled(true); textArea.setAntiAliasingEnabled(true); changeStyleProgrammatically(); RTextScrollPane sp = new RTextScrollPane(textArea); cp.add(sp); setContentPane(cp); setTitle("Connection Console"); // setDefaultCloseOperation(EXIT_ON_CLOSE); pack(); setLocation(802, 460); if (CONFIG.peerDiscovery()) UIEthereumManager.ethereum.startPeerDiscovery(); Thread t = new Thread() { public void run() { UIEthereumManager.ethereum.connect( SystemProperties.CONFIG.activePeerIP(), SystemProperties.CONFIG.activePeerPort()); } }; UIEthereumManager.ethereum.addListener( new EthereumListenerAdapter() { @Override public void trace(final String output) { SwingUtilities.invokeLater( new Runnable() { public void run() { textArea.append(output); textArea.append("\n"); if (autoScroll) textArea.setCaretPosition(textArea.getText().length()); } }); } }); t.start(); }