protected void displayNewTxf(String strLabel, String strValue) { strLabel = (strLabel == null) ? "" : strLabel.trim(); strValue = (strValue == null) ? "" : strValue.trim(); JCheckBox chkBox1 = new JCheckBox(Util.getImageIcon("boxGray.gif")); DataField txf1 = new DataField(strLabel); DataField txf2 = new DataField(strValue); JPanel pnlTxf = new JPanel(m_gbl); m_nRow = m_nRow + 1; txf1.setName("label"); txf2.setName("value"); /* 1st line of text field*/ m_gbc.weightx = 0; showComp(m_gbl, m_gbc, 0, m_nRow, 1, chkBox1); m_gbc.weightx = 1; showComp(m_gbl, m_gbc, GridBagConstraints.RELATIVE, m_nRow, 1, txf1); // showSpaces( gbl, gbc, 2, 6 ); showComp(m_gbl, m_gbc, GridBagConstraints.RELATIVE, m_nRow, 1, txf2); m_gbc.weightx = 0; txf1.addFocusListener(this); txf2.addFocusListener(this); m_objTxfValue.addToLabel(txf1); m_objTxfValue.addToValue(txf2); }
static { noProbeImage = Util.getImageIcon("probeNone.gif"); wrongProbeImage = Util.getImageIcon("probeWrong.gif"); untunedProbeImage = Util.getImageIcon("probeUntuned.gif"); readyProbeImage = Util.getImageIcon("probeReady.gif"); errorProbeImage = Util.getImageIcon("probeError.gif"); }
public void switchLayout(int newId, boolean bLayout) { if (layoutId == newId) return; if (newId >= nviews) updateVpInfo(newId + 1); if (bSwitching) { return; } bSwitching = true; int oldId = layoutId; vpId = newId; layoutId = newId; recordCurrentLayout(); VpLayoutInfo vInfo = Util.getViewArea().getLayoutInfo(oldId); if (vInfo != null) { // save current layout info vInfo.tp_selectedTab = tp_selectedTab; vInfo.setVerticalTabName(selectedTabName); // copyCurrentLayout(vInfo); } vInfo = Util.getViewArea().getLayoutInfo(newId); putHsLayout(oldId); if (bLayout) getHsLayout(vpId); for (int i = 0; i < toolList.size(); i++) ((VToolPanel) toolList.get(i)).switchLayout(newId, bLayout); if (bLayout) setCurrentLayout(); /* if(comparePanelLayout(oldId, newId)) { setCurrentLayout(); } if ((vInfo != null) && vInfo.bAvailable && compareCurrentLayout(vInfo)) { setCurrentLayout(vInfo); } for(int i=0; i< toolList.size(); i++) ((VToolPanel) toolList.get(i)).switchLayout(newId); */ // setViewPort(newId); if (bLayout) setCurrentLayout(vInfo); updateValue(); if (bLayout) { if (pinPanel.isOpen()) { if (!pinPanel.isVisible()) pinPanel.setVisible(true); } else pinPanel.setVisible(false); } validate(); repaint(); bSwitching = false; }
private void openNmrFile() { if (fileName.equals("text")) { try { Runtime.getRuntime().exec("notepad " + fullPath); } catch (Exception e) { } } else if (fileName.equals("fid")) { directory = UtilB.windowsPathToUnix(directory); if (directory.charAt(directory.length() - 1) == '/') { directory = directory.substring(0, directory.length() - 1); } Util.sendToVnmr("rt (\'" + directory + "\')"); Util.sendToVnmr("write(\'line3\',\'fid retrieved\')"); } else if (fileName.equals("procpar")) { directory = UtilB.windowsPathToUnix(directory); if (directory.charAt(directory.length() - 1) == '/') { directory = directory.substring(0, directory.length() - 1); } Util.sendToVnmr("rtp (\'" + directory + "\')"); Util.sendToVnmr("write(\'line3\',\'parameters retrieved\')"); } else { Util.sendToVnmr("write(\'error\',\'unknown file -- open ignored\')"); } return; }
protected void setBgColor(Color bgColor) { setBackgroundColor(bgColor); panelForBtns.setBackground(Util.getBgColor()); addButton.setBackground(Util.getBgColor()); removeButton.setBackground(Util.getBgColor()); }
public void init() { String host = util.getHost(); String bindAddr = util.getBindAddress(); int port = util.getPort(ListeningContextFace.DEFAULT_TRAP_PORT); String socketType = util.getSocketType(); // String oid = util.getOid(); String community = util.getCommunity(); try { context = new SnmpContextv2c(host, port, bindAddr, socketType); context.setCommunity(community); pdu = new TrapPduv2(context); pdu.addOid(sysUpTime, new AsnUnsInteger(5)); pdu.addOid(snmpTrapOID, new AsnObjectId(warmStart)); System.out.println(pdu.toString()); pdu.send(); // when calling destroy, the pdu might not be sent // context.destroy(); } catch (java.io.IOException exc) { System.out.println("IOException " + exc.getMessage()); } catch (uk.co.westhawk.snmp.stack.PduException exc) { System.out.println("PduException " + exc.getMessage()); } // System.exit(0); }
void draw(Graphics g) { g.setColor(new Color(0, 96, 0)); g.fillOval(x - 25, y - 10, 50, 50); g.setColor(new Color(0, 128, 0)); g.fillOval(x - 40, y + 5, 80, 40); g.setColor(new Color(0, 192, 0)); g.fillOval(x - 10, y - 50, 20, 100); g.fillOval(x - 25, y - 10, 5, 55); g.fillOval(x + 20, y - 10, 5, 55); g.fillOval(x - 40, y + 5, 5, 35); g.fillOval(x + 35, y + 5, 5, 35); g.setColor(new Color(64, 255, 255)); g.fillOval(x - 5, y - 25, 10, 30); g.setColor(Color.RED); g.fillOval(x - 40, y, 5, 10); g.fillOval(x - 25, y - 15, 5, 10); g.fillOval(x + 20, y - 15, 5, 10); g.fillOval(x + 35, y, 5, 10); if (state == ME_ST_BLAST) { for (int i = 1; i < count; i++) { g.setColor(Util.randColor(128, 255)); int x0 = Util.rand(-40, 40); int y0 = Util.rand(-40, 40); int r0 = Util.rand(5, 40); g.fillOval(x - x0 - r0 / 2, y - y0 - r0 / 2, r0, r0); } count--; if (count == 0) state = ME_ST_ALIVE; } }
/** * Gets the imageicon. If the user has a predefined icon, get that, otherwise get the varian icon. * * @return the imageicon */ protected ImageIcon getImageIcon() { ImageIcon icon = null; String strPath = WOperators.getDefIcon(); if (strPath != null) { icon = Util.getImageIcon(strPath); } if (icon == null) icon = Util.getImageIcon(WOperators.ICON); return icon; }
/** * Performs a search. * * @param sc search context * @param jump jump to next hit */ final void search(final SearchContext sc, final boolean jump) { try { rend.search(sc); if (!sc.search.isEmpty()) gui.status.setText(Util.info(Text.STRINGS_FOUND_X, sc.nr())); if (jump) jump(SearchDir.CURRENT, false); } catch (final Exception ex) { final String msg = Util.message(ex).replaceAll(Prop.NL + ".*", ""); gui.status.setError(Text.REGULAR_EXPR + Text.COLS + msg); } }
/** * constructor * * @param sshare session share */ public SpotterButton(SessionShare sshare) { JMenuItem item; this.sshare = sshare; // setBackground(Global.BGCOLOR); setContentAreaFilled(false); // setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); setMargin(new Insets(0, 0, 0, 0)); setBorder(new VButtonBorder()); setUnderline(false); setIcon(Util.getImageIcon("search_20.png")); setToolTipText(Util.getLabel("_Locator_Statements")); addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent evt) { // Save startup time by not filling this menu until // it is first clicked. fillPopupMenu(); } }); addPopListener( new PopListener() { public void popHappened(String popStr) { SessionShare sshare = ResultTable.getSshare(); if (popStr.startsWith("save:")) { String saveName = popStr.substring(5); StatementHistory history = sshare.statementHistory(); history.readNamedStatement(saveName); } else if (popStr.startsWith("command:")) { String commandName = popStr.substring(8); int index = commandName.indexOf('/'); String objType = commandName.substring(0, index); LocatorHistory lh = sshare.getLocatorHistory(); // Set History Active Object type to this type. lh.setActiveObjType(objType); // Now get history for this type. StatementHistory history = sshare.statementHistory(); history.appendLastOfType(commandName); } else if (popStr.startsWith("title:")) { String objType = popStr.substring(6); LocatorHistory lh = sshare.getLocatorHistory(); // Update locator to the most recent statement for this type lh.setHistoryToThisType(objType); } } }); DisplayOptions.addChangeListener(this); } // SpotterButton()
protected void layoutUIComponents(String strPath, boolean bDefaultFile) { JLabel label = null; // i18n // label = new JLabel( "File names can be constructed from a template. The LABEL field is " ); label = new JLabel( Util.getAdmLabel( "_admin_File_names_can_be_constructed_from_a_template._The_LABEL_field_is_")); label.setForeground(Color.black); // m_gbc.weightx = 0.5; showInstruction(m_gbl, m_gbc, 0, 0, 7, label); // i18n // label = new JLabel( "presented as the choice to the user in the \"Data save\" pop-up." ); label = new JLabel( Util.getAdmLabel( "_admin_presented_as_the_choice_to_the_user_in_the_Data_save_pop-up.")); showInstruction(m_gbl, m_gbc, 0, 1, 7, label); showInstruction(m_gbl, m_gbc, 0, 2, 1, new JLabel("")); label = new JLabel(Util.getAdmLabel("_adm_LABEL")); label.setForeground(Color.black); m_gbc.gridx = 1; m_gbc.gridy = 2; m_gbc.ipadx = 10; m_gbl.setConstraints(label, m_gbc); m_pnlDisplay.add(label); label = new JLabel(" "); m_gbc.gridx = 2; m_gbc.gridy = 2; m_gbc.ipadx = 0; // reset to default m_gbc.gridwidth = 5; m_gbl.setConstraints(label, m_gbc); // add( label ); showInstruction(m_gbl, m_gbc, 2, 2, 1, new JLabel(Util.getAdmLabel("_admin_TEMPLATE"))); m_nRow = 3; m_bDefaultFile = bDefaultFile; m_objTxfValue.clearArrays(); displayNewTxf(strPath); m_pnlDisplay.setBorder( new CompoundBorder( BorderFactory.createTitledBorder(Util.getAdmLabel("_admin_User_Directories")), BorderFactory.createEmptyBorder(10, 10, 10, 10))); }
/** * Returns the specified image. * * @param url image url * @return image */ public static Image get(final URL url) { try { return ImageIO.read(url); } catch (final IOException ex) { throw Util.notExpected(ex); } }
/** * Shows a quit dialog for the specified editor. * * @param edit editor to be saved * @return {@code false} if confirmation was canceled */ private boolean confirm(final EditorArea edit) { if (edit.modified && (edit.opened() || edit.getText().length != 0)) { final Boolean ok = BaseXDialog.yesNoCancel(gui, Util.info(CLOSE_FILE_X, edit.file.name())); if (ok == null || ok && !save()) return false; } return true; }
/** * This method sets the color that represents tranparent for the generated image * * @param s DOCUMENT ME! */ public void setTransparentColor(String s) { Color c = Util.stringToColor(s); if (c != null) { setTransparentColor(c); } }
/** * Draws the specified string. * * @param g graphics reference * @param s text * @param x x coordinate * @param y y coordinate * @param w width * @param fs font size */ public static void chopString( final Graphics g, final byte[] s, final int x, final int y, final int w, final int fs) { if (w < 12) return; final int[] cw = fontWidths(g.getFont()); int j = s.length; try { int l = 0; int fw = 0; for (int k = 0; k < j; k += l) { final int ww = width(g, cw, cp(s, k)); if (fw + ww >= w - 4) { j = Math.max(1, k - l); if (k > 1) fw -= width(g, cw, cp(s, k - 1)); g.drawString("..", x + fw, y + fs); break; } fw += ww; l = cl(s, k); } } catch (final Exception ex) { Util.debug(ex); } g.drawString(string(s, 0, j), x, y + fs); }
/** * This method sets the bottom and right border color for the generated image * * @param s DOCUMENT ME! */ public void setBottomRightColor(String s) { Color c = Util.stringToColor(s); if (c != null) { setBottomRightColor(c); } }
/** * This method sets the top and left border color for the generated image * * @param s DOCUMENT ME! */ public void setTopLeftColor(String s) { Color c = Util.stringToColor(s); if (c != null) { setTopLeftColor(c); } }
/** Saves the displayed text. */ private void save() { final BaseXFileChooser fc = new BaseXFileChooser(SAVE_AS, gui.gopts.get(GUIOptions.WORKPATH), gui).suffix(IO.XMLSUFFIX); final IO file = fc.select(Mode.FSAVE); if (file == null) return; gui.gopts.set(GUIOptions.WORKPATH, file.path()); gui.cursor(CURSORWAIT, true); final MainOptions opts = gui.context.options; final int mh = opts.get(MainOptions.MAXHITS); opts.set(MainOptions.MAXHITS, -1); opts.set(MainOptions.CACHEQUERY, false); try (final PrintOutput out = new PrintOutput(file.toString())) { if (cmd != null) { cmd.execute(gui.context, out); } else if (ns != null) { ns.serialize(Serializer.get(out)); } else { final byte[] txt = text.getText(); for (final byte t : txt) if (t < 0 || t > ' ' || ws(t)) out.write(t); } } catch (final IOException ex) { BaseXDialog.error(gui, Util.info(FILE_NOT_SAVED_X, file)); } finally { opts.set(MainOptions.MAXHITS, mh); opts.set(MainOptions.CACHEQUERY, true); gui.cursor(CURSORARROW, true); } }
public void start() { running = Util.isRunning(); if (!running) { clearLogsDir(); run(); } }
/** * Returns a <code>java.awt.Color</code> runtime object * * @param type <code>Class</code> not used * @param attr <code>Attribute</code> value needs to provide a String * @return runtime type is subclass of <code>java.awt.Color</code> */ public static Object conv(final Class type, final Attribute attr) { if (attr != null) { try { Field field = Color.class.getField(attr.getValue()); if (Color.class.equals(field.getType()) && Modifier.isStatic(field.getModifiers())) return field.get(Color.class); } catch (NoSuchFieldException e) { } catch (SecurityException e) { } catch (IllegalAccessException e) { } StringTokenizer st = new StringTokenizer(attr.getValue(), ","); if (1 == st.countTokens()) { try { return new Color(Integer.parseInt(st.nextToken().trim(), 16)); } catch (NumberFormatException e) { if (SwingEngine.DEBUG_MODE) System.err.println(e); return null; } } int[] para = Util.ia(st); if (4 <= para.length) return new Color(para[0], para[1], para[2], para[3]); if (3 <= para.length) return new Color(para[0], para[1], para[2]); if (1 <= para.length) return new Color(para[0]); } return null; }
/** When a new set of saved statements come in, refresh the menu of saved statements. */ private void refreshSaveMenu() { ArrayList list; // first, delete what's already there for (; ; ) { Component comp = popup.getComponent(1); if (!(comp instanceof JMenuItem)) break; JMenuItem item = (JMenuItem) comp; if (item.getActionCommand().startsWith("save:")) popup.remove(1); else break; } StatementHistory history; history = sshare.statementHistory(); // now insert the new list of saved statements list = history.getNamedStatementList(); Color bgColor = Util.getBgColor(); for (int i = 0; i < list.size(); i++) { ArrayList nameNlabel = (ArrayList) list.get(i); JMenuItem item = new JMenuItem(" " + (String) nameNlabel.get(1)); item.setActionCommand("save:" + (String) nameNlabel.get(0)); popup.add(item, 1); // item.setBackground(bgColor); item.addActionListener(popActionListener); } } // refreshSaveMenu()
public boolean popdnTool(String name) { JComponent obj = searchTool(name); if (obj == null) return false; if (obj instanceof VToolPanel) { if (!((VToolPanel) obj).popdnTool(name)) return false; } else { if (obj instanceof PushpinIF) { PushpinIF pobj = (PushpinIF) obj; pobj.pinPopup(false); } boolean bContain = containTool(obj); if (!bContain) return false; } bChangeTool = true; setCurrentLayout(); if (previous_selectedTab >= 1 && tabbedPane != null) { if (tabbedPane.getTabCount() > previous_selectedTab) tabbedPane.setSelectedIndex(previous_selectedTab); } VnmrjIF vif = Util.getVjIF(); if (vif != null) vif.raiseToolPanel(false); if (!pinPanel.isOpen()) pinPanel.setVisible(false); bChangeTool = false; updateSelectedObj(); repaint(); return true; }
/** Notifies all views of a data reference change. */ public void init() { final Data data = initHistory(gui.context); if (data != null) { // if a large database is opened, the user is asked if complex /// visualizations should be closed first final long size = data.meta.dbsize(); boolean open = false; for (final View v : view) open |= v.visible() && v.db(); if (open && size > LARGEDB && BaseXDialog.confirm(gui, Util.info(H_LARGE_DB, Performance.format(size)))) { for (final View v : view) if (v.visible() && v.db()) v.visible(false); } } else { // database closed: close open dialogs for (final Window w : gui.getOwnedWindows()) { if (w.isVisible() && w instanceof BaseXDialog) ((BaseXDialog) w).cancel(); } } gui.context.focused = -1; for (final View v : view) v.refreshInit(); gui.layoutViews(); gui.setTitle(data != null ? data.meta.name : null); }
private void clearLogsDir() { if (clearLogs.cb.isSelected()) { File logs = new File("logs"); Util.deleteAll(logs); IOPanel.out.clear(); } }
/** * Returns a keystroke for the specified string. * * @param cmd command * @return keystroke */ public static KeyStroke keyStroke(final GUICommand cmd) { final Object sc = cmd.shortcuts(); if (sc == null) return null; final String scut; if (sc instanceof BaseXKeys[]) { final BaseXKeys[] scs = (BaseXKeys[]) sc; if (scs.length == 0) return null; scut = scs[0].shortCut(); } else { scut = Util.info(sc, META); } final KeyStroke ks = KeyStroke.getKeyStroke(scut); if (ks == null) Util.errln("Could not assign shortcut: " + sc + " / " + scut); return ks; }
/** * This method sets the background color for the generated image * * @param s DOCUMENT ME! */ public void setBackgroundColor(String s) { Color c = Util.stringToColor(s); if (c != null) { setBackgroundColor(c); } }
public boolean popupTool(String name) { JComponent obj = searchTool(name); if (obj == null) return false; if (obj instanceof VToolPanel) { if (!((VToolPanel) obj).popupTool(name)) return false; } else { if (obj instanceof PushpinIF) { PushpinIF pobj = (PushpinIF) obj; if (!pobj.isOpen()) pobj.pinPopup(true); } } bChangeTool = true; setCurrentLayout(); if (!pinPanel.isOpen()) { pinPanel.setVisible(false); bChangeTool = false; return false; } displayTool((Component) obj); VnmrjIF vif = Util.getVjIF(); if (vif != null) vif.raiseToolPanel(true); bChangeTool = false; validate(); repaint(); return true; }
@Override public void execute(final GUI gui) { final DialogExport dialog = new DialogExport(gui); if (!dialog.ok()) return; final IOFile root = new IOFile(dialog.path()); // check if existing files will be overwritten if (root.exists()) { IO file = null; boolean overwrite = false; final Data d = gui.context.data(); final IntList il = d.resources.docs(); final int is = il.size(); for (int i = 0; i < is; i++) { file = root.merge(Token.string(d.text(il.get(i), true))); if (file.exists()) { if (overwrite) { // more than one file will be overwritten; check remaining tests file = null; break; } overwrite = true; } } if (overwrite) { // show message for overwriting files or directories final String msg = file == null ? FILES_REPLACE_X : FILE_EXISTS_X; if (file == null) file = root; if (!BaseXDialog.confirm(gui, Util.info(msg, file))) return; } } DialogProgress.execute(gui, new Export(root.path())); }
@Override public void action(final Object comp) { final boolean valid = general.action(comp, true); ft.action(ftxindex.isSelected()); // ...must be located before remaining checks if (comp == general.browse || comp == general.input) dbname.setText(general.dbname); final String nm = dbname.getText().trim(); ok = valid && !nm.isEmpty(); String inf = valid ? ok ? null : ENTER_DB_NAME : RES_NOT_FOUND; Msg icon = Msg.ERROR; if (ok) { ok = Databases.validName(nm); if (ok) gui.gopts.set(GUIOptions.DBNAME, nm); if (!ok) { // name of database is invalid inf = Util.info(INVALID_X, NAME); } else if (general.input.getText().trim().isEmpty()) { // database will be empty inf = EMPTY_DB; icon = Msg.WARN; } else if (db.contains(nm)) { // old database will be overwritten inf = OVERWRITE_DB; icon = Msg.WARN; } } general.info.setText(inf, icon); enableOK(buttons, B_OK, ok); }
/** Returns the tool bar for the panel. */ protected JComponent getToolBar() { JToolBar tbarDir = new JToolBar(); JButton btnNew = new JButton(); // m_btnSave = new JButton("Save File"); // i118n // btnNew.setText("New Label"); btnNew.setText(Util.getAdmLabel("_adm_New_Label")); btnNew.setActionCommand("new"); // m_btnSave.setActionCommand("save"); ActionListener alTool = new ActionListener() { public void actionPerformed(ActionEvent e) { doAction(e); } }; btnNew.addActionListener(alTool); // m_btnSave.addActionListener(alTool); tbarDir.setFloatable(false); tbarDir.add(btnNew); /*tbarDir.add(new JLabel(" ")); tbarDir.add(m_btnSave);*/ return tbarDir; }