Changeset 655


Ignore:
Timestamp:
01/07/14 10:59:52 (10 years ago)
Author:
jts21
Message:

Switch to using specialised objects for settings so they make more a bit more sense (now each setting is a single object instead of multiple, and setter functions and default values are less hackish)
Also added tooltips (help strings) to settings, will need to add a way of displaying these (maybe add the idea of a tooltip which is a text item which only appears when hovering over another item?)
Converted all settings over to new format, everything seems to be working fine

Location:
trunk/src/org/expeditee
Files:
7 added
30 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Misc.java

    r645 r655  
    11601160                if(!FreeItems.textOnlyAttachedToCursor()) {
    11611161                        text = DisplayIO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(),
    1162                                         NetworkSettings.homePage, null);
     1162                                        NetworkSettings.HomePage.get(), null);
    11631163                        text.setParent(DisplayIO.getCurrentFrame());    // set parent of text source for InteractiveWidget.createWidget()
    11641164                        FrameMouseActions.pickup(text);                                 // Attach new text link to cursor
     
    13721372         */
    13731373        public static void resetHomeFrame() {
    1374                 Frame homeFrame = FrameIO.LoadFrame(UserSettings.HomeFrame);
     1374                Frame homeFrame = FrameIO.LoadFrame(UserSettings.HomeFrame.get());
    13751375                homeFrame.removeAllItems(homeFrame.getItems());
    13761376                homeFrame.addText(0, 0, "title", null);
    1377                 FrameUtils.CreateDefaultProfile(UserSettings.UserName, homeFrame);
     1377                FrameUtils.CreateDefaultProfile(UserSettings.UserName.get(), homeFrame);
    13781378        }
    13791379       
     
    13981398                        // If no text with url is passed to action create a new text item
    13991399                        if(!FreeItems.textOnlyAttachedToCursor()) {
    1400                                 url = NetworkSettings.homePage;                                 // use home page specified by settings
     1400                                url = NetworkSettings.HomePage.get();                                   // use home page specified by settings
    14011401                                text = DisplayIO.getCurrentFrame().addText(FrameMouseActions.getX(), FrameMouseActions.getY(),
    14021402                                                "Web Browser Session", null);
  • trunk/src/org/expeditee/actions/Navigation.java

    r570 r655  
    4242         */
    4343        public static void GotoHome() {
    44                 FrameUtils.DisplayFrame(UserSettings.HomeFrame);
     44                FrameUtils.DisplayFrame(UserSettings.HomeFrame.get());
    4545        }
    4646
     
    5454         */
    5555        public static void GotoProfile() {
    56                 FrameUtils.DisplayFrame(UserSettings.ProfileName + '1');
     56                FrameUtils.DisplayFrame(UserSettings.ProfileName.get() + '1');
    5757        }
    5858
  • trunk/src/org/expeditee/actions/Spelling.java

    r570 r655  
    2828                }
    2929                if (path == null) {
    30                         for (String possiblePath : UserSettings.FrameDirs) {
     30                        for (String possiblePath : UserSettings.FrameDirs.get()) {
    3131                                fullPath = FrameIO
    3232                                                .getFrameFullPathName(possiblePath, frameName);
  • trunk/src/org/expeditee/agents/SearchTree.java

    r570 r655  
    7070
    7171                String fullPath = null;
    72                 for (String possiblePath : UserSettings.FrameDirs) {
     72                for (String possiblePath : UserSettings.FrameDirs.get()) {
    7373                        fullPath = FrameIO.getFrameFullPathName(possiblePath, frameName);
    7474                        if (fullPath != null)
  • trunk/src/org/expeditee/agents/SearchTreeNoResults.java

    r570 r655  
    5353               
    5454                String fullPath = null;
    55                 for (String possiblePath : UserSettings.FrameDirs) {
     55                for (String possiblePath : UserSettings.FrameDirs.get()) {
    5656                        fullPath = FrameIO.getFrameFullPathName(possiblePath, frameName);
    5757                        if (fullPath != null)
  • trunk/src/org/expeditee/gui/Browser.java

    r618 r655  
    151151        private Browser() {
    152152                // Use the default values initially so we can load the profile frame
    153                 setSizes(new Dimension(UserSettings.InitialWidth,
    154                                 UserSettings.InitialHeight));
     153                setSizes(new Dimension(UserSettings.InitialWidth.get(),
     154                                UserSettings.InitialHeight.get()));
    155155                // center the frame on the screen
    156156                Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    157157                double xpos = screen.getWidth() / 2;
    158158                double ypos = screen.getHeight() / 2;
    159                 setLocation((int) (xpos - (UserSettings.InitialWidth / 2)),
    160                                 (int) (ypos - (UserSettings.InitialHeight / 2)));
     159                setLocation((int) (xpos - (UserSettings.InitialWidth.get() / 2)),
     160                                (int) (ypos - (UserSettings.InitialHeight.get() / 2)));
    161161
    162162                addWindowListener(this);
     
    182182        }
    183183           
    184                 UserSettings.ProfileName = FrameIO.ConvertToValidFramesetName(System
    185                                 .getProperty("user.name"));
    186                 String userName = UserSettings.ProfileName;
    187                 UserSettings.UserName = UserSettings.ProfileName;
     184                // UserSettings.ProfileName.set(FrameIO.ConvertToValidFramesetName(System.getProperty("user.name")));
     185                String userName = UserSettings.ProfileName.get();
     186                //UserSettings.UserName.set(UserSettings.ProfileName.get());
    188187
    189188                Frame profile = loadProfile(userName);
     
    226225                // Reset windows to user specified size
    227226                // Must be done after initialising the content pane above!
    228                 setSizes(new Dimension(UserSettings.InitialWidth,
    229                                 UserSettings.InitialHeight));
     227                setSizes(new Dimension(UserSettings.InitialWidth.get(),
     228                                UserSettings.InitialHeight.get()));
    230229
    231230                /*
  • trunk/src/org/expeditee/gui/DisplayIO.java

    r570 r655  
    791791                        if (_VisitedFrames[opposite].size() == 0) {
    792792                                FrameIO.SuspendCache();
    793                                 setCurrentFrame(FrameIO.LoadFrame(UserSettings.HomeFrame), true);
     793                                setCurrentFrame(FrameIO.LoadFrame(UserSettings.HomeFrame.get()), true);
    794794                                FrameIO.ResumeCache();
    795795                        } else {
  • trunk/src/org/expeditee/gui/Frame.java

    r602 r655  
    135135        private Collection<Item> _vectorItems = new LinkedHashSet<Item>();
    136136
    137         private Text _dotTemplate = UserSettings.DotTemplate.copy();
     137        private Text _dotTemplate = UserSettings.DotTemplate.get().copy();
    138138
    139139        /**
     
    421421
    422422                if (frameTitle == null) {
    423                         if (UserSettings.TitleTemplate == null) {
     423                        if (UserSettings.TitleTemplate.get() == null) {
    424424                                frameTitle = new Text(getNextItemID(), title);
    425425                                /*
     
    430430                                frameTitle.resetTitlePosition();
    431431                        } else {
    432                                 frameTitle = UserSettings.TitleTemplate.copy();
     432                                frameTitle = UserSettings.TitleTemplate.get().copy();
    433433                                frameTitle.setID(this.getNextItemID());
    434434                                frameTitle.setText(title);
     435                                frameTitle.resetTitlePosition();
    435436                        }
    436437                        addItem(frameTitle);
     
    464465                List<Item> items = getVisibleItems();
    465466                for (Item i : items) {
    466                         if (i instanceof Text && i.getX() < UserSettings.TitlePosition
    467                                         && i.getY() < UserSettings.TitlePosition)
     467                        if (i instanceof Text && i.getX() < UserSettings.TitlePosition.get()
     468                                        && i.getY() < UserSettings.TitlePosition.get())
    468469                                return (Text) i;
    469470                }
     
    485486
    486487        public Text getItemTemplate() {
    487                 return getTemplate(UserSettings.ItemTemplate,
     488                return getTemplate(UserSettings.ItemTemplate.get(),
    488489                                ItemUtils.TAG_ITEM_TEMPLATE);
    489490        }
    490491
    491492        public Text getAnnotationTemplate() {
    492                 Text t = getTemplate(UserSettings.AnnotationTemplate,
     493                Text t = getTemplate(UserSettings.AnnotationTemplate.get(),
    493494                                ItemUtils.TAG_ANNOTATION_TEMPLATE);
    494495
     
    502503        public Text getStatTemplate() {
    503504                SessionStats.CreatedText();
    504                 Text t = getTemplate(UserSettings.StatTemplate,
     505                Text t = getTemplate(UserSettings.StatTemplate.get(),
    505506                                ItemUtils.TAG_STAT_TEMPLATE);
    506507
     
    533534
    534535        public Text getCodeCommentTemplate() {
    535                 Text t = getTemplate(UserSettings.CodeCommentTemplate,
     536                Text t = getTemplate(UserSettings.CodeCommentTemplate.get(),
    536537                                ItemUtils.TAG_CODE_COMMENT_TEMPLATE);
    537538
  • trunk/src/org/expeditee/gui/FrameCreator.java

    r427 r655  
    77import org.expeditee.items.Text;
    88
     9/**
     10 *  TODO: merge with @see org.expeditee.settings.Settings.generateSettingsTree
     11 */
    912public class FrameCreator {
    1013        public static final int INDENT_FROM_TITLE = 20;
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r616 r655  
    339339                // Nicer looking lines, but may be too jerky while
    340340                // rubber-banding on older machines
    341                 if (UserSettings.AntiAlias)
     341                if (UserSettings.AntiAlias.get())
    342342                        bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    343343                                        RenderingHints.VALUE_ANTIALIAS_ON);
  • trunk/src/org/expeditee/gui/FrameIO.java

    r614 r655  
    215215                } else {
    216216
    217                         for (String path : UserSettings.FrameDirs) {
     217                        for (String path : UserSettings.FrameDirs.get()) {
    218218                                loaded = LoadKnowPath(path, framename);
    219219                                if (loaded != null) {
     
    243243                StringBuffer list = new StringBuffer();
    244244
    245                 for (String path : UserSettings.FrameDirs) {
     245                for (String path : UserSettings.FrameDirs.get()) {
    246246                        File files = new File(path);
    247247                        if (!files.exists())
     
    305305                }
    306306
    307                 for (String path : UserSettings.FrameDirs) {
     307                for (String path : UserSettings.FrameDirs.get()) {
    308308                        if (getFrameFullPathName(path, frameName) != null)
    309309                                return true;
     
    316316                String fullPath = null;
    317317                if (path == null) {
    318                         for (String possiblePath : UserSettings.FrameDirs) {
     318                        for (String possiblePath : UserSettings.FrameDirs.get()) {
    319319                                fullPath = getFrameFullPathName(possiblePath, frameName);
    320320                                if (fullPath != null)
     
    666666                                + template.getName() + " from TDFC");
    667667
    668                 template.setOwner(UserSettings.UserName);
     668                template.setOwner(UserSettings.UserName.get());
    669669                template.reset();
    670670                template.resetDateCreated();
     
    12421242        public static Boolean canAccessFrameset(String framesetName) {
    12431243                framesetName = framesetName.toLowerCase();
    1244                 for (String path : UserSettings.FrameDirs) {
     1244                for (String path : UserSettings.FrameDirs.get()) {
    12451245                        if ((new File(path + framesetName)).exists())
    12461246                                return true;
     
    13001300                Frame base = null;
    13011301                try {
    1302                         base = LoadFrame(UserSettings.DefaultFrame);
     1302                        base = LoadFrame(UserSettings.DefaultFrame.get());
    13031303                } catch (Exception e) {
    13041304                }
     
    13181318                base.setPath(path);
    13191319                base.change();
    1320                 base.setOwner(UserSettings.UserName);
     1320                base.setOwner(UserSettings.UserName.get());
    13211321                SaveFrame(base, false);
    13221322
     
    13261326                base.setTitle(frameset);
    13271327                base.change();
    1328                 base.setOwner(UserSettings.UserName);
     1328                base.setOwner(UserSettings.UserName.get());
    13291329                SaveFrame(base, true);
    13301330
     
    13791379
    13801380                // Search all the available directories for the directory
    1381                 for (String path : UserSettings.FrameDirs) {
     1381                for (String path : UserSettings.FrameDirs.get()) {
    13821382                        String source = path + framesetName.toLowerCase() + File.separator;
    13831383                        File framesetDirectory = new File(source);
     
    14191419                // search through all the directories to find the frameset we are
    14201420                // copying
    1421                 for (String path : UserSettings.FrameDirs) {
     1421                for (String path : UserSettings.FrameDirs.get()) {
    14221422                        String source = path + framesetToCopy.toLowerCase()
    14231423                                        + File.separator;
     
    15761576        public static void setSavedProperties(Frame toSave) {
    15771577                toSave.setLastModifyDate(Formatter.getDateTime());
    1578                 toSave.setLastModifyUser(UserSettings.UserName);
     1578                toSave.setLastModifyUser(UserSettings.UserName.get());
    15791579                toSave.setVersion(toSave.getVersion() + 1);
    15801580                Time darkTime = new Time(SessionStats.getFrameDarkTime().getTime()
  • trunk/src/org/expeditee/gui/FrameKeyboardActions.java

    r626 r655  
    10421042                        case SizeDown:
    10431043                                if (isControlDown) {
    1044                                         UserSettings.ScaleFactor -= 0.05;
     1044                                        UserSettings.ScaleFactor.set(UserSettings.ScaleFactor.get() - 0.05f);
    10451045                                        Misc.repaint();
    10461046                                        return;
     
    10481048                        case SizeUp:
    10491049                                if (isControlDown) {
    1050                                         UserSettings.ScaleFactor += 0.05;
     1050                                        UserSettings.ScaleFactor.set(UserSettings.ScaleFactor.get() + 0.05f);
    10511051                                        Misc.repaint();
    10521052                                        return;
  • trunk/src/org/expeditee/gui/FrameMouseActions.java

    r637 r655  
    250250                }
    251251               
    252                 if(ExperimentalFeatures.MousePan) {
     252                if(ExperimentalFeatures.MousePan.get()) {
    253253                // don't pan if we're not over the frame
    254254                _overFrame = FrameUtils.getCurrentItem() == null;
     
    522522                        if(!_isPanOp) {
    523523                                MessageBay.displayMessage("Action cancelled, mouse moved more than "
    524                                                         + UserSettings.NoOpThreshold + " pixels.");
     524                                                        + UserSettings.NoOpThreshold.get() + " pixels.");
    525525                        }
    526526                        FrameGraphics.Repaint();
     
    16901690               
    16911691                // panning the frame when dragging the mouse while shift-leftclicking
    1692                 if(ExperimentalFeatures.MousePan && _overFrame && e.isShiftDown() &&
     1692                if(ExperimentalFeatures.MousePan.get() && _overFrame && e.isShiftDown() &&
    16931693                                (e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) != 0 &&
    16941694                                (_isPanOp || (Math.max(Math.abs(panStartX - e.getX()), Math.abs(panStartY - e.getY())) > 5))) {
     
    17131713                                                - _lastRanged.getBoundsHeight();
    17141714
    1715                         if (distance > UserSettings.NoOpThreshold) {
     1715                        if (distance > UserSettings.NoOpThreshold.get()) {
    17161716                                _lastRanged.clearSelectionEnd();
    17171717                                _isNoOp = true;
     
    17831783                // Use the below calculation for better speed. If it causes problems
    17841784                // switch back to the Euclidean distance calculation
    1785                 if (Math.abs(MouseX - e.getX()) > UserSettings.NoOpThreshold
    1786                                 || Math.abs(MouseY - e.getY()) > UserSettings.NoOpThreshold)
     1785                if (Math.abs(MouseX - e.getX()) > UserSettings.NoOpThreshold.get()
     1786                                || Math.abs(MouseY - e.getY()) > UserSettings.NoOpThreshold.get())
    17871787                        _isNoOp = true;
    17881788
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r618 r655  
    6767        public static int MINIMUM_INTERITEM_SPACING = -6;
    6868
    69         public static Double MAXIMUM_SPACING_RATIO = null;
    70 
    71         public static Double MINIMUM_SPACING_RATIO = null;
    72 
    7369        public static float getResponseTimeTotal() {
    7470                return _ResponseTimeSum;
     
    241237                                space = MINIMUM_INTERITEM_SPACING;
    242238
    243                         if (MAXIMUM_SPACING_RATIO != null) {
    244                                 double maxSpace = MAXIMUM_SPACING_RATIO * above.getSize();
     239                        if (UserSettings.FormatSpacingMax.get() != null) {
     240                                double maxSpace = UserSettings.FormatSpacingMax.get() * above.getSize();
    245241                                if (maxSpace < space) {
    246242                                        space = (int) Math.round(maxSpace);
     
    248244                        }
    249245
    250                         if (MINIMUM_SPACING_RATIO != null) {
    251                                 double minSpace = MINIMUM_SPACING_RATIO * above.getSize();
     246                        if (UserSettings.FormatSpacingMin.get() != null) {
     247                                double minSpace = UserSettings.FormatSpacingMin.get() * above.getSize();
    252248                                if (minSpace > space) {
    253249                                        space = (int) Math.round(minSpace);
     
    594590                DisplayIO.setCursor(Item.DEFAULT_CURSOR);
    595591
    596                 UserSettings.TitleTemplate = profile.getTitleItem();
     592                UserSettings.TitleTemplate.set(profile.getTitleItem());
    597593
    598594                // check for settings tags
     
    632628         */
    633629        public static void loadFirstFrame(Frame profile) {
    634                 if (UserSettings.HomeFrame == null)
    635                         UserSettings.HomeFrame = profile.getName();
    636 
    637                 Frame firstFrame = FrameIO.LoadFrame(UserSettings.HomeFrame);
     630                if (UserSettings.HomeFrame.get() == null)
     631                        UserSettings.HomeFrame.set(profile.getName());
     632
     633                Frame firstFrame = FrameIO.LoadFrame(UserSettings.HomeFrame.get());
    638634                if (firstFrame == null) {
    639635                        MessageBay.warningMessage("Home frame not found: "
    640636                                        + UserSettings.HomeFrame);
    641                         UserSettings.HomeFrame = profile.getName();
     637                        UserSettings.HomeFrame.set(profile.getName());
    642638                        DisplayIO.setCurrentFrame(profile, true);
    643639                } else {
     
    647643        }
    648644
    649         public static Color[] getColorWheel(Item item) {
    650                 Frame child = item.getChild();
    651                 if (child != null) {
    652                         List<Text> textItems = child.getBodyTextItems(false);
     645        public static Color[] getColorWheel(Frame frame) {
     646                if (frame != null) {
     647                        List<Text> textItems = frame.getBodyTextItems(false);
    653648                        Color[] colorList = new Color[textItems.size() + 1];
    654649                        for (int i = 0; i < textItems.size(); i++) {
     
    670665                assert (avp != null);
    671666
    672                 if (avp.hasPair()) {
     667                if (avp.hasPair() && avp.getValue().trim().length() != 0) {
    673668                        item.setLink(avp.getValue());
    674669                        return avp.getValue();
  • trunk/src/org/expeditee/io/AbstractHTMLWriter.java

    r570 r655  
    4848
    4949                // Go through all the styles
    50                 List<Text> style = UserSettings.Style;
     50                List<Text> style = UserSettings.Style.get();
    5151
    5252                writeStyleInfo(_writer, "P", style.get(0));
  • trunk/src/org/expeditee/io/PDF2Writer.java

    r570 r655  
    4949                        _pdfDocument.open();
    5050                        _pdfDocument.addCreationDate();
    51                         _pdfDocument.addAuthor(UserSettings.UserName);
     51                        _pdfDocument.addAuthor(UserSettings.UserName.get());
    5252                        _pdfDocument.addCreator("Expeditee");
    5353                } catch (DocumentException e) {
  • trunk/src/org/expeditee/io/PDFWriter.java

    r570 r655  
    3333
    3434        public PDFWriter() {
    35                 assert(UserSettings.Style != null);
    36                 if (UserSettings.Style.size() > 0) {
    37                         Text text = UserSettings.Style.get(0);
     35                assert(UserSettings.Style.get() != null);
     36                if (UserSettings.Style.get().size() > 0) {
     37                        Text text = UserSettings.Style.get().get(0);
    3838                        _bodyFont = FontFactory.getFont(Conversion.getPdfFont(text
    3939                                        .getFamily()), text.getSize(), text.getPaintFont()
     
    5252                        _pdfDocument.open();
    5353                        _pdfDocument.addCreationDate();
    54                         _pdfDocument.addAuthor(UserSettings.UserName);
     54                        _pdfDocument.addAuthor(UserSettings.UserName.get());
    5555                        _pdfDocument.addCreator("Expeditee");
    5656                        _pdfDocument.addTitle(start.getTitle());
     
    6868                        return;
    6969
    70                 if (indent < UserSettings.Style.size()) {
     70                if (indent < UserSettings.Style.get().size()) {
    7171                        String text = toWrite.getText();
    72                         toWrite = UserSettings.Style.get(indent).getTemplateForm();
     72                        toWrite = UserSettings.Style.get().get(indent).getTemplateForm();
    7373                        toWrite.setText(text);
    7474                }
  • trunk/src/org/expeditee/io/PdfFramesetWriter.java

    r570 r655  
    7272                        _pdfDocument.open();
    7373                        _pdfDocument.addCreationDate();
    74                         _pdfDocument.addAuthor(UserSettings.UserName);
     74                        _pdfDocument.addAuthor(UserSettings.UserName.get());
    7575                        _pdfDocument.addCreator("Expeditee");
    7676                } catch (DocumentException e) {
  • trunk/src/org/expeditee/items/Item.java

    r632 r655  
    229229
    230230                if (parent != null && !UserSettings.UserName.equals(parent.getOwner())) {
    231                         dest.setOwner(UserSettings.UserName);
     231                        dest.setOwner(UserSettings.UserName.get());
    232232                }
    233233        }
     
    254254                        return 2;
    255255                }
    256                 return org.expeditee.settings.UserSettings.Gravity;
     256                return UserSettings.Gravity.get();
    257257        }
    258258
    259259        public static boolean showLineHighlight() {
    260                 return org.expeditee.settings.UserSettings.LineHighlight;
     260                return UserSettings.LineHighlight.get();
    261261        }
    262262
     
    16961696                if (_parent != null && UserSettings.UserName != null
    16971697                                && !UserSettings.UserName.equals(_parent.getOwner())) {
    1698                         setOwner(UserSettings.UserName);
     1698                        setOwner(UserSettings.UserName.get());
    16991699                }
    17001700        }
  • trunk/src/org/expeditee/items/ItemUtils.java

    r601 r655  
    371371                        File file = null;
    372372
    373                         for (String dir : org.expeditee.settings.UserSettings.ImageDirs) {
     373                        for (String dir : org.expeditee.settings.UserSettings.ImageDirs.get()) {
    374374                                file = new File(dir + path);
    375375                                if (file.exists() && !file.isDirectory())
  • trunk/src/org/expeditee/items/Text.java

    r635 r655  
    14341434                List<Point[]> lines = null;
    14351435               
    1436                 if(_autoWrap || ExperimentalFeatures.AutoWrap) {
     1436                if(_autoWrap || ExperimentalFeatures.AutoWrap.get()) {
    14371437                lines = new LinkedList<Point[]>();
    14381438                if(DisplayIO.getCurrentFrame() == null) {
     
    14721472                while (_lineBreaker.getPosition() < _text.length()) {
    14731473                       
    1474                         if(_autoWrap || ExperimentalFeatures.AutoWrap) {
     1474                        if(_autoWrap || ExperimentalFeatures.AutoWrap.get()) {
    14751475                                requireNextWord = width < FrameGraphics.getMaxFrameSize().width - getX();
    14761476                        }
     
    15051505                        _textLayouts.add(layout);
    15061506                                               
    1507                         if(_autoWrap || ExperimentalFeatures.AutoWrap) {
     1507                        if(_autoWrap || ExperimentalFeatures.AutoWrap.get()) {
    15081508                               
    15091509                        if(lineHeight != Float.NaN) {
     
    16501650                        return;
    16511651               
    1652                 if(_autoWrap || ExperimentalFeatures.AutoWrap) {
     1652                if(_autoWrap || ExperimentalFeatures.AutoWrap.get()) {
    16531653                        invalidateAll();
    16541654               
     
    21192119               
    21202120                // if autowrap is on, wrapping is done every time we draw
    2121                 if(ExperimentalFeatures.AutoWrap) {
     2121                if(ExperimentalFeatures.AutoWrap.get()) {
    21222122                        return;
    21232123                }
  • trunk/src/org/expeditee/items/widgets/JfxBrowser.java

    r645 r655  
    407407        public JfxBrowser(Text source, String[] args) {
    408408                // Initial page is either the page stored in the arguments (if there is one stored) or the homepage
    409                 super(source, new WebBrowserPanel((args != null && args.length > 0) ? args[0] : NetworkSettings.homePage), -1, 500, -1, -1, 300, -1);
     409                super(source, new WebBrowserPanel((args != null && args.length > 0) ? args[0] : NetworkSettings.HomePage.get()), -1, 500, -1, -1, 300, -1);
    410410                _browser = (WebBrowserPanel) _swingComponent;
    411411                _browser.owner = this;
     
    434434                                (firstSpace != -1 && firstSpace < firstSQ)) {      // no '/' or '?'             -> search
    435435                                // make it a search
    436                                 actualURL = NetworkSettings.searchEngine + url;
     436                                actualURL = NetworkSettings.SearchEngine.get() + url;
    437437                        } else {
    438438                                // add the missing protocol
  • trunk/src/org/expeditee/settings/Settings.java

    r641 r655  
    33import java.lang.reflect.Field;
    44import java.lang.reflect.Method;
    5 import java.lang.reflect.Modifier;
    65import java.util.HashMap;
    76import java.util.LinkedList;
     
    1312import org.expeditee.gui.FrameIO;
    1413import org.expeditee.gui.FrameUtils;
     14import org.expeditee.items.Item;
    1515import org.expeditee.items.Text;
    1616import org.expeditee.items.widgets.Password;
    1717import org.expeditee.reflection.PackageLoader;
     18import org.expeditee.setting.GenericSetting;
     19import org.expeditee.setting.Setting;
     20import org.expeditee.setting.VariableSetting;
    1821
    1922public abstract class Settings {
     
    2427        private static final class PageDescriptor {
    2528               
    26                 private static final class FieldSet {
    27                        
    28                         private final Field field;
    29                         private final Method method;
    30                        
    31                         private FieldSet(Field field, Method method) {
    32                                 this.field = field;
    33                                 this.method = method;
    34                         }
    35                 }
    36                
    37                 private final HashMap<String, FieldSet> settings = new HashMap<String, FieldSet>();
    38                 private final List<Field> hasDefault = new LinkedList<Field>();
     29                private final HashMap<String, Setting> settings = new HashMap<String, Setting>();
    3930                private final List<String> orderedEntries = new LinkedList<String>();
     31                private final List<VariableSetting> hasDefault = new LinkedList<VariableSetting>();
    4032                private final Method onParsed;
    4133               
    4234                private PageDescriptor(Class<?> clazz) {
    4335                       
    44                         // populate map of settings with methods
    45                         for(Method m : clazz.getMethods()) {
    46                                 // method name must start with "set", and method must take 1 Text item as parameter
    47                                 if(m.getName().toLowerCase().startsWith("set") && m.getParameterTypes().length == 1 && m.getParameterTypes()[0] == Text.class) {
    48                                         // System.out.println(m.getName().toLowerCase());
    49                                         settings.put(m.getName().substring(3).toLowerCase(), new FieldSet(null, m));
    50                                         if(!orderedEntries.contains(m.getName().substring(3))) {
    51                                                 orderedEntries.add(m.getName().substring(3));
    52                                         }
    53                                 }
    54                         }
    55                         // populate map of settings with fields
     36                        // populate map of settings
    5637                        for(Field f : clazz.getFields()) {
    57                                 Class<?> type = f.getType();
    5838                                // only allow valid types
    59                                 if(type != String.class &&
    60                                                 type != Boolean.class && type != boolean.class &&
    61                                                 type != Integer.class && type != int.class &&
    62                                                 type != Double.class && type != double.class &&
    63                                                 type != Float.class && type != float.class) {
    64                                         continue;
    65                                 }
    66                                 FieldSet fs = settings.get(f.getName().toLowerCase());
    67                                 if(fs == null) {
    68                                         settings.put(f.getName().toLowerCase(), new FieldSet(f, null));
    69                                 } else {
    70                                         settings.put(f.getName().toLowerCase(), new FieldSet(f, fs.method));
    71                                 }
    72                                 if(!orderedEntries.contains(f.getName())) {
    73                                         orderedEntries.add(f.getName());
    74                                 }
    75                         }
    76                         // check which fields have default values
    77                         for(Field f : clazz.getFields()) {
    78                                 if(!Modifier.isFinal(f.getModifiers())) {
    79                                         if(this.settings.get("default" + f.getName().toLowerCase()) != null) {
    80                                                 this.hasDefault.add(f);
    81                                         }
    82                                 }
     39                                if(! Setting.class.isAssignableFrom(f.getType())) {
     40                                        continue;
     41                                }
     42                                try {
     43                                        Setting s = (Setting) f.get(null);
     44                        settings.put(f.getName().toLowerCase(), s);
     45                        if(s instanceof VariableSetting && ((VariableSetting) s).hasDefault()) {
     46                                hasDefault.add((VariableSetting) s);
     47                        }
     48                        orderedEntries.add(f.getName());
     49                } catch (Exception e) {
     50                        e.printStackTrace();
     51                }
    8352                        }
    8453                        Method m = null;
     
    10877                        e.printStackTrace();
    10978                }
    110                 FrameUtils.ParseProfile(FrameIO.LoadProfile(UserSettings.ProfileName));
     79                FrameUtils.ParseProfile(FrameIO.LoadProfile(UserSettings.ProfileName.get()));
    11180        }
    11281       
     
    136105                                return;
    137106                        }
    138                         List<Field> toDefault = new LinkedList<Field>(pd.hasDefault);
     107                        List<VariableSetting> toDefault = new LinkedList<VariableSetting>(pd.hasDefault);
    139108                        // set the fields
    140109                        for (Text t : text.getChild().getBodyTextItems(true)) {
     
    142111                                try {
    143112                                        // System.out.println(avp.getAttributeOrValue().trim().toLowerCase().replaceAll("^@", ""));
    144                                         PageDescriptor.FieldSet fs = pd.settings.get(avp.getAttributeOrValue().trim().toLowerCase().replaceAll("^@", ""));
    145                                         if(fs == null) {
     113                                        Setting s = pd.settings.get(avp.getAttributeOrValue().trim().toLowerCase().replaceAll("^@", ""));
     114                                        if(s == null) {
    146115                                                continue;
    147116                                        }
    148                                         Field f = fs.field;
    149                                         Method m = fs.method;
    150                                         if(m != null) {
    151                                                 m.invoke(null, t);
    152                                                 // System.out.println("Set " + avp.getAttributeOrValue() + " by method");
    153                                                 // we're setting this field, so remove it from the list of fields to default
    154                                                 toDefault.remove(f);
    155                                         } else {
    156                                                 if (f != null) {
    157                                                         // if the value is empty, set it to the default
    158                                                         if(avp.getValue() == null || avp.getValue().trim().length() == 0) {
    159                                                                 continue;
    160                                                         }
    161                                                         Class<?> type = f.getType();
    162                                                         if(type == String.class) {
    163                                                                 f.set(null, avp.getValue());
    164                                                         } else if(type == Boolean.class || type == boolean.class) {
    165                                                                 f.set(null, avp.getBooleanValue());
    166                                                         } else if(type == Integer.class || type == int.class) {
    167                                                                 f.set(null, avp.getIntegerValue());
    168                                                         } else if(type == Double.class || type == double.class) {
    169                                                                 f.set(null, avp.getDoubleValue());
    170                                                         } else if(type == Float.class || type == float.class) {
    171                                                                 f.set(null, avp.getDoubleValue().floatValue());
    172                                                         } else {
    173                                                                 System.err.println("Failed to set " + f.getName() + " of " + type);
    174                                                                 continue;
    175                                                         }
    176                                                         // we're setting this field, so remove it from the list of fields to default
    177                                                         toDefault.remove(f);
    178                                                         // System.out.println("Set " + f.getName() + " to " + f.get(null));
    179                                                 }
     117                                        if(s.setSetting(t)) {
     118                                                toDefault.remove(s);
    180119                                        }
    181120                                } catch (Exception e) {
     
    184123                        }
    185124                        // set any unset fields to their default
    186                         for(Field f : toDefault) {
     125                        for(VariableSetting s : toDefault) {
    187126                                try {
    188                             f.set(null, pd.settings.get("default" + f.getName().toLowerCase()).field.get(null));
     127                                        // System.out.println("Resetting " + s.getTooltip());
     128                            s.reset();
    189129                            // System.out.println("Set " + f.getName() + " to default value " + f.get(null));
    190130                    } catch (Exception e) {
     
    210150        }
    211151       
     152        /**
     153         *
     154         * Generates settings tree
     155         * TODO: merge with @see FrameCreator
     156         *
     157         */
    212158        private static Text generateSettingsTree(String page, Text text) {
    213159                Frame frame = FrameIO.CreateNewFrame(text);
     
    215161               
    216162                int x = 50, y = 100;
    217                 int dY = UserSettings.ItemTemplate.getPolygon().getBounds().height + 1;
    218                 int maxY = UserSettings.InitialHeight - 150;
     163                int dY = UserSettings.ItemTemplate.get().getPolygon().getBounds().height + 1;
     164                int maxY = UserSettings.InitialHeight.get() - 150;
    219165               
    220166                // add subpages of the current page
     
    243189                        for(String str : pd.orderedEntries) {
    244190                                String key = str.toLowerCase();
    245                                 if(key.startsWith("default")) {
    246                                         continue;
    247                                 }
    248                                 PageDescriptor.FieldSet fs = pd.settings.get(key);
    249                                 String name = null;
    250                                 Object value = "";
    251                                 name = str.substring(0, 1).toUpperCase() + str.substring(1);
    252                                 if(fs.method == null && fs.field != null) {
    253                                 try {
    254                                         if(pd.hasDefault.contains(fs.field)) {
    255                                                 value = ": " + pd.settings.get("default" + key).field.get(null);
    256                                         } else {
    257                                                 value = ": " + fs.field.get(null);
    258                                         }
    259                                 } catch (Exception e) {
    260                         e.printStackTrace();
    261                     }
    262                                 } else if(fs.method == null) {
    263                                         continue;
     191                                Setting s = pd.settings.get(key);
     192                                if(s == null) {
     193                                        continue;
     194                                }
     195                                String name = str.substring(0, 1).toUpperCase() + str.substring(1);
     196                                String value = "";
     197                                if(s instanceof GenericSetting && ((GenericSetting) s).isPrimitive()) {
     198                                        System.out.println("VALUE: " + ((GenericSetting) s).get());
     199                                        if(((GenericSetting) s).get() != null) {
     200                                                value = ": " + ((GenericSetting) s).get();
     201                                        } else {
     202                                                value = ": ";
     203                                        }
    264204                                }
    265205                                if(key.equals("pass")) {
    266                                         Password pw = new Password(frame.createNewText("@iw: org.expeditee.items.widgets.Password"), null);
     206                                        Text t = frame.addText(x, y, "iw: org.expeditee.items.widgets.Password", null);
     207                                        Password pw = new Password(t, null);
    267208                                        pw.setPassword((String) value);
    268                                         pw.setPosition(x, y);
     209                                        frame.removeItem(t);
    269210                                        frame.addAllItems(pw.getItems());
    270211                                        y += pw.getHeight();
     212                                } else if(s instanceof GenericSetting && ((GenericSetting) s).getType().equals(Text.class)) {
     213                                        Text t = ((GenericSetting<Text>) s).get();
     214                                        if(t == null) continue;
     215                                        t = t.copy();
     216                                        int h = t.getPolygon().getBounds().height + 1;
     217                                        t.setID(frame.getNextItemID());
     218                                        t.setX(x);
     219                                        t.setY(y + h / 2);
     220                                        t.setText(name);
     221                                        frame.addItem(t);
     222                                        y += h;
    271223                                } else {
    272                                         frame.addText(x, y, name + value, null);
    273                                 }
    274                                 y += dY;
     224                                        frame.addText(x, y + dY / 2, name + value, null);
     225                                        y += dY;
     226                                }
    275227                                if(y >= maxY) {
    276228                                        x += 300;
  • trunk/src/org/expeditee/settings/UserSettings.java

    r642 r655  
    11package org.expeditee.settings;
    22
     3import java.awt.Color;
    34import java.io.File;
    45import java.io.FileNotFoundException;
     
    1819import org.expeditee.gui.FreeItems;
    1920import org.expeditee.gui.MessageBay;
    20 import org.expeditee.gui.Reminders;
    2121import org.expeditee.items.Item;
    2222import org.expeditee.items.ItemUtils;
    2323import org.expeditee.items.Text;
     24import org.expeditee.setting.FrameSetting;
     25import org.expeditee.setting.FunctionSetting;
     26import org.expeditee.setting.GenericSetting;
     27import org.expeditee.setting.ListSetting;
     28import org.expeditee.setting.Setting;
    2429
    2530/**
     
    3540         * General settings (no setter functions)
    3641         */
    37         public static final int defaultGravity = 3;
    38         public static int Gravity = defaultGravity;
    39        
    40         public static final float defaultScaleFactor = 1F;
    41         public static float ScaleFactor = defaultScaleFactor;
    42 
    43         public static final int defaultLineStraightenThreshold = 15;
    44         public static int LineStraightenThreshold = defaultLineStraightenThreshold;
    45 
    46         public static final int defaultNoOpThreshold = 60;
    47         public static int NoOpThreshold = defaultNoOpThreshold;
    48        
    49         public static final int defaultTitlePosition = 150;
    50         public static int TitlePosition = defaultTitlePosition;
    51 
    52         public static final int defaultInitialWidth = 1024;
    53         public static int InitialWidth = defaultInitialWidth;
    54        
    55         public static final int defaultInitialHeight = 768;
    56         public static int InitialHeight = defaultInitialHeight;
    57        
    58         public static String ProfileName;
    59        
    60         public static String UserName;
    61        
    62         public static final boolean defaultAntiAlias = false;
    63         public static boolean AntiAlias = defaultAntiAlias;
    64 
    65         public static final boolean defaultLineHighlight = false;
    66         public static boolean LineHighlight = defaultLineHighlight;
    67 
    68         public static final boolean defaultLogging = false;
    69         public static boolean Logging = defaultLogging;
    70 
    71         public static final boolean defaultLogStats = true;
    72         public static boolean LogStats = defaultLogStats;
    73 
    74         public static final boolean defaultThreading = true;
    75         public static boolean Threading = defaultThreading;
     42       
     43        public static final GenericSetting<Float> ScaleFactor = new GenericSetting<Float>(Float.class, "Scale Factor for drawing (TODO: does this even do anything?)", 1F);
     44       
     45        public static final GenericSetting<Float> FormatSpacingMin = new GenericSetting<Float>(Float.class, "Minimum spacing ratio", null);
     46       
     47        public static final GenericSetting<Float> FormatSpacingMax = new GenericSetting<Float>(Float.class, "Maximum spacing ratio", null);
     48       
     49        public static final GenericSetting<Integer> Gravity = new GenericSetting<Integer>(Integer.class, "Distance the cursor has to be from a text item to select the text item", 3);
     50
     51        public static final GenericSetting<Integer> LineStraightenThreshold = new GenericSetting<Integer>(Integer.class, "Threshold for straightening a line (TODO: does this even do anything?)", 15);
     52
     53        public static final GenericSetting<Integer> NoOpThreshold = new GenericSetting<Integer>(Integer.class, "Distance the cursor may be dragged while clicking before the operation is cancelled", 60);
     54       
     55        public static final GenericSetting<Integer> TitlePosition = new GenericSetting<Integer>(Integer.class, "Position of title item in frame (TODO: find whether this is x-offset or y-offset)", 150);
     56       
     57        public static final GenericSetting<Integer> InitialWidth = new GenericSetting<Integer>(Integer.class, "Initial width of Expeditee window", 1024);
     58       
     59        public static final GenericSetting<Integer> InitialHeight = new GenericSetting<Integer>(Integer.class, "Initial height of Expeditee window", 768);
     60       
     61        public static final GenericSetting<String> ProfileName = new GenericSetting<String>(String.class, "Profile name", FrameIO.ConvertToValidFramesetName(System.getProperty("user.name")));
     62       
     63        public static final GenericSetting<String> UserName = new GenericSetting<String>(String.class, "User name", ProfileName.get());
     64       
     65        public static final GenericSetting<Boolean> AntiAlias = new GenericSetting<Boolean>(Boolean.class, "Whether anti-aliasing should be enabled", false);
     66
     67        public static final GenericSetting<Boolean> LineHighlight = new GenericSetting<Boolean>(Boolean.class, "Whether lines should be highlighted", false);
     68
     69        public static final GenericSetting<Boolean> Logging = new GenericSetting<Boolean>(Boolean.class, "Whether logging should be enabled", false);
     70
     71        public static final GenericSetting<Boolean> LogStats = new GenericSetting<Boolean>(Boolean.class, "Whether stats should be logged", true);
     72
     73        public static final GenericSetting<Boolean> Threading = new GenericSetting<Boolean>(Boolean.class, "Whether threading should be enabled", true);
    7674       
    7775       
     
    7977         * Frames
    8078         */
    81         public static String DefaultFrame = null;
    82         public static void setDefaultFrame(Text t) {
    83                 UserSettings.DefaultFrame = FrameUtils.getLink(t, UserSettings.DefaultFrame);
    84         }
    85        
    86         public static String StatisticsFrameset = null;
    87 
    88         public static String MenuFrame = null;
    89 
    90         public static String HomeFrame = null;
    91         public static void setHomeFrame(Text t) {
    92                 if(t.getText().indexOf(':') == -1 || !t.hasLink()) {
    93                         t.setLink(FrameIO.LoadProfile(UserSettings.ProfileName).getName());
    94                 }
    95                 String first = FrameUtils.getLink(t, UserSettings.HomeFrame);
    96                 // do not use non-existant frames as the first frame
    97                 if (FrameIO.isValidFrameName(first)) {
    98                         UserSettings.HomeFrame = first;
    99                 }
    100                 // warn the user
    101                 else {
    102                         // MessageBay.warningMessage("Home frame: " + first
    103                         // + " is not a valid frame.");
    104                         UserSettings.HomeFrame = FrameIO.LoadProfile(UserSettings.ProfileName).getName();
    105                 }
    106         }
     79        public static final GenericSetting<String> DefaultFrame = new GenericSetting<String>(String.class, "The default frame", null) {
     80                @Override
     81                public boolean setSetting(Text text) {
     82                        _value = FrameUtils.getLink(text, _value);
     83                        return true;
     84                }
     85        };
     86       
     87        public static final GenericSetting<String> StatisticsFrameset = new GenericSetting<String>(String.class, "The statistics frameset", null);
     88
     89        public static final GenericSetting<String> MenuFrame = new GenericSetting<String>(String.class, "The menu frame", null);
     90
     91        public static final GenericSetting<String> HomeFrame = new GenericSetting<String>(String.class, "The home frame", null) {
     92                @Override
     93                public boolean setSetting(Text text) {
     94                if(text.getText().indexOf(':') == -1 || !text.hasLink()) {
     95                        text.setLink(FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName());
     96                }
     97                String first = FrameUtils.getLink(text, UserSettings.HomeFrame.get());
     98                // do not use non-existant frames as the first frame
     99                if (FrameIO.isValidFrameName(first)) {
     100                        _value = first;
     101                }
     102                // warn the user
     103                else {
     104                        // MessageBay.warningMessage("Home frame: " + first
     105                        // + " is not a valid frame.");
     106                        _value = FrameIO.LoadProfile(UserSettings.ProfileName.get()).getName();
     107                }
     108                return true;
     109                }
     110        };
    107111
    108112        /*
    109113         *  Directories
    110114         */
    111         public static List<String> FrameDirs = new LinkedList<String>();
    112         public static void setFrameDirs(Text t) {
    113                 UserSettings.FrameDirs.addAll(FrameUtils.getDirs(t));
    114         }
    115         public static void setFramesetDir(Text t) {
    116                 if(t.getText().indexOf(':') == -1) {
    117                         return;
    118                 }
    119                 String dir = null;
    120                 AttributeValuePair avp = new AttributeValuePair(t.getText());
    121                 if(avp.getValue().trim().length() != 0) {
    122                         dir = FrameUtils.getDir(avp.getValue());
    123                 }
    124                 if (dir != null) {
    125                         UserSettings.FrameDirs.add(dir);
    126                 }
    127         }
    128 
    129         public static List<String> ImageDirs = new LinkedList<String>();
    130         public static void setImageDirs(Text t) {
    131                 UserSettings.ImageDirs.addAll(FrameUtils.getDirs(t));
    132         }
    133         public static void setImageDir(Text t) {
    134                 if(t.getText().indexOf(':') == -1) {
    135                         return;
    136                 }
    137                 String dir = null;
    138                 AttributeValuePair avp = new AttributeValuePair(t.getText());
    139                 if(avp.getValue().trim().length() != 0) {
    140                         dir = FrameUtils.getDir(avp.getValue());
    141                 }
    142                 if (dir != null) {
    143                         UserSettings.ImageDirs.add(0, dir);
    144                 }
    145         }
    146        
    147         public static void setLogDir(Text t) {
    148                 if(t.getText().indexOf(':') == -1) {
    149                         return;
    150                 }
    151                 AttributeValuePair avp = new AttributeValuePair(t.getText());
    152                 if(avp.getValue().trim().length() != 0) {
    153                         FrameIO.LOGS_DIR = FrameUtils.getDir(avp.getValue());
    154                 }
    155         }
     115        public static final ListSetting<String> FrameDirs = new ListSetting<String>("Directories to look in for frames") {
     116                @Override
     117                public boolean setSetting(Text text) {
     118                        _value.addAll(FrameUtils.getDirs(text));
     119                        return true;
     120                }
     121        };
     122        public static final Setting FramesetDir = new Setting("Adds a directory to look in for frames") {
     123                @Override
     124                public boolean setSetting(Text text) {
     125                        if(text.getText().indexOf(':') == -1) {
     126                                return false;
     127                }
     128                AttributeValuePair avp = new AttributeValuePair(text.getText());
     129                if(avp.getValue().trim().length() != 0) {
     130                        String dir = FrameUtils.getDir(avp.getValue());
     131                        if (dir != null) {
     132                                UserSettings.FrameDirs.get().add(dir);
     133                                return true;
     134                        }
     135                }
     136                return false;
     137                }
     138        };
     139
     140        public static ListSetting<String> ImageDirs = new ListSetting<String>("Directories to look in for images") {
     141                @Override
     142                public boolean setSetting(Text text) {
     143                        _value.addAll(FrameUtils.getDirs(text));
     144                        return true;
     145                }
     146        };
     147        public static final Setting ImageDir = new Setting("Adds a directory to look in for images") {
     148                @Override
     149                public boolean setSetting(Text text) {
     150                if(text.getText().indexOf(':') == -1) {
     151                        return false;
     152                }
     153                AttributeValuePair avp = new AttributeValuePair(text.getText());
     154                if(avp.getValue().trim().length() != 0) {
     155                        String dir = FrameUtils.getDir(avp.getValue());
     156                        if(dir != null) {
     157                                UserSettings.ImageDirs.get().add(0, dir);
     158                                return true;
     159                        }
     160                }
     161                return false;
     162                }
     163        };
     164       
     165        public static final Setting LogDir = new Setting("Set the directory to save logs") {
     166                @Override
     167                public boolean setSetting(Text text) {
     168                        if(text.getText().indexOf(':') == -1) {
     169                        return false;
     170                }
     171                AttributeValuePair avp = new AttributeValuePair(text.getText());
     172                if(avp.getValue().trim().length() != 0) {
     173                        FrameIO.LOGS_DIR = FrameUtils.getDir(avp.getValue());
     174                }
     175                return true;
     176                }
     177        };
    156178
    157179        /*
    158180         *  Templates
    159181         */
    160         public static Text TitleTemplate = null;
    161        
    162         public static Text ItemTemplate = new Text("@ItemTemplate");
    163         public static void setItemTemplate(Text t) {
    164                 UserSettings.ItemTemplate = t.getTemplateForm();
    165         }
    166        
    167         public static Text DotTemplate = new Text("@DotTemplate");
    168         public static void setDotTemplate(Text t) {
    169                 UserSettings.DotTemplate = t.getTemplateForm();
    170         }
    171 
    172         public static Text AnnotationTemplate = null;
    173         public static void setAnnotationTemplate(Text t) {
    174                 UserSettings.AnnotationTemplate = t.getTemplateForm();
    175         }
    176 
    177         public static Text CodeCommentTemplate = null;
    178         public static void setCommentTemplate(Text t) {
    179                 UserSettings.CodeCommentTemplate = t.getTemplateForm();
    180         }
    181 
    182         public static Text StatTemplate = null;
    183         public static void setStatsTemplate(Text t) {
    184                 UserSettings.StatTemplate = t.getTemplateForm();
    185         }
     182        public static final GenericSetting<Text> TitleTemplate = new GenericSetting<Text>(Text.class, "Template for Title text item");
     183       
     184        public static final GenericSetting<Text> ItemTemplate = new GenericSetting<Text>(Text.class, "Template for normal text items", new Text("@ItemTemplate")) {
     185                @Override
     186                public boolean setSetting(Text text) {
     187                        _value = text.getTemplateForm();
     188                        return true;
     189                }
     190        };
     191       
     192        public static final GenericSetting<Text> DotTemplate = new GenericSetting<Text>(Text.class, "Template for dot items", new Text("@DotTemplate")) {
     193                @Override
     194                public boolean setSetting(Text text) {
     195                        _value = text.getTemplateForm();
     196                        return true;
     197                }
     198        };
     199
     200        private static final Text annotationTemplate() {
     201                Text t = new Text("@AnnotationTemplate");
     202                t.setColor(Color.gray);
     203                return t;
     204        }
     205        public static final GenericSetting<Text> AnnotationTemplate = new GenericSetting<Text>(Text.class, "Template for annotation text items", annotationTemplate()) {
     206                @Override
     207                public boolean setSetting(Text text) {
     208                        _value = text.getTemplateForm();
     209                        return true;
     210                }
     211        };
     212
     213        private static final Text codeCommentTemplate() {
     214                Text t = new Text("@CommentTemplate");
     215                t.setColor(Color.green.darker());
     216                return t;
     217        }
     218        public static final GenericSetting<Text> CodeCommentTemplate = new GenericSetting<Text>(Text.class, "Template for code comment text items", codeCommentTemplate()) {
     219                @Override
     220                public boolean setSetting(Text text) {
     221                        _value = text.getTemplateForm();
     222                        return true;
     223                }
     224        };
     225
     226        private static final Text statTemplate() {
     227                Text t = new Text("@StatsTemplate");
     228                t.setColor(Color.BLACK);
     229                t.setBackgroundColor(new Color(0.9F, 0.9F, 0.9F));
     230                t.setFamily(Text.MONOSPACED_FONT);
     231                t.setSize(14);
     232                return t;
     233        }
     234        public static final GenericSetting<Text> StatTemplate = new GenericSetting<Text>(Text.class, "Template for statistics (e.g. extracted attributes) text items", statTemplate()) {
     235                @Override
     236                public boolean setSetting(Text text) {
     237                        _value = text.getTemplateForm();
     238                        return true;
     239                }
     240        };
    186241       
    187242        /*
    188243         * Colorwheels
    189244         */
    190         public static void setColorWheel(Text t) {
    191                 if(t.getChild() != null) Item.COLOR_WHEEL = FrameUtils.getColorWheel(t);
    192         }
    193        
    194         public static void setFillColorWheel(Text t) {
    195                 if(t.getChild() != null) Item.FILL_COLOR_WHEEL = FrameUtils.getColorWheel(t);
    196         }
    197        
    198         public static void setBackgroundColorWheel(Text t) {
    199                 if(t.getChild() != null) Frame.COLOR_WHEEL = FrameUtils.getColorWheel(t);
    200         }
     245        public static final FrameSetting ColorWheel = new FrameSetting("The colours of items in the child frame are used to populate the colour wheel") {
     246                @Override
     247                protected void run(Frame frame) {
     248                        Item.COLOR_WHEEL = FrameUtils.getColorWheel(frame);
     249                }
     250        };
     251       
     252        public static final FrameSetting FillColorWheel = new FrameSetting("The colours of items in the child frame are used to populate the colour wheel") {
     253                @Override
     254                protected void run(Frame frame) {
     255                        Item.FILL_COLOR_WHEEL = FrameUtils.getColorWheel(frame);
     256                }
     257        };
     258       
     259        public static final FrameSetting BackgroundColorWheel = new FrameSetting("The colours of items in the child frame are used to populate the colour wheel") {
     260                @Override
     261                protected void run(Frame frame) {
     262                        Frame.COLOR_WHEEL = FrameUtils.getColorWheel(frame);
     263                }
     264        };
    201265       
    202266        /*
    203267         * Other
    204268         */
    205         public static List<Text> Style = new LinkedList<Text>();
    206         public static void setStyle(Text t) {
    207                 Frame child = t.getChild();
    208                 if (child == null) {
    209                         UserSettings.Style = new LinkedList<Text>();
    210                         return;
    211                 }
    212                
    213 
    214                 List<Text> style = new ArrayList<Text>(8);
    215                 for (int i = 0; i < 10; i++) {
    216                         style.add(null);
    217                 }
    218 
    219                 for (Text text : child.getBodyTextItems(false)) {
    220                         String type = text.getText();
    221                         char lastChar = type.charAt(type.length() - 1);
    222                         if (Character.isDigit(lastChar)) {
    223                                 style.set(lastChar - '0', text);
    224                         } else {
    225                                 style.set(0, text);
    226                         }
    227                 }
    228                 UserSettings.Style = style;
    229         }
    230        
    231         public static void setSpellChecker(Text t) {
    232                 AttributeValuePair avp = new AttributeValuePair(t.getText());
    233                 if(avp.getBooleanValue()) {
    234                 try {
     269        public static final ListSetting<Text> Style = new ListSetting<Text>("Set the style (TODO: what does this do?)") {               
     270                @Override
     271                public boolean setSetting(Text text) {
     272                        Frame child = text.getChild();
     273                if (child == null) {
     274                        _value = new LinkedList<Text>();
     275                        return true;
     276                }
     277               
     278   
     279                List<Text> style = new ArrayList<Text>(8);
     280                for (int i = 0; i < 10; i++) {
     281                        style.add(null);
     282                }
     283   
     284                for (Text t : child.getBodyTextItems(false)) {
     285                        String type = t.getText();
     286                        char lastChar = type.charAt(type.length() - 1);
     287                        if (Character.isDigit(lastChar)) {
     288                                style.set(lastChar - '0', t);
     289                        } else {
     290                                style.set(0, t);
     291                        }
     292                }
     293                _value = style;
     294                return true;
     295                }
     296        };
     297       
     298        public static final FunctionSetting SpellChecker = new FunctionSetting("Enables the dictionary with the default dictionary") {
     299                @Override
     300                public void run() {
     301                        try {
    235302                        JSpellChecker.create();
    236303                } catch (FileNotFoundException e) {
    237                         MessageBay.errorMessage("Could not find dictionary: "
    238                                         + e.getMessage());
     304                        MessageBay.errorMessage("Could not find dictionary: " + e.getMessage());
    239305                } catch (IOException e) {
    240306                        e.printStackTrace();
    241307                }
    242308                }
    243         }
    244         public static void setSpelling(Text t) {
    245                 if(t.getChild() != null) {
    246                 try {
    247                 JSpellChecker.create(t.getChild());
    248             } catch (Exception e) {
    249                 e.printStackTrace();
    250             }
    251                 }
    252         }
    253        
    254         public static void setGreenstoneSettings(Text t) {
    255                 if(t.getChild() != null) SearchGreenstone.init(t.getChild());
    256         }
    257        
    258         public static void setReminders(Text t) {
    259                 if(t.getChild() != null) Reminders.init(t.getChild());
    260         }
    261        
    262         public static void setFormatSpacingMin(Text t) {
    263                 double value = new AttributeValuePair(t.getText()).getDoubleValue();
    264                 if(value != Double.NaN) {
    265                         FrameUtils.MINIMUM_SPACING_RATIO = value;
    266                 }
    267         }
    268        
    269         public static void setFormatSpacingMax(Text t) {
    270                 double value = new AttributeValuePair(t.getText()).getDoubleValue();
    271                 if(value != Double.NaN) {
    272                         FrameUtils.MAXIMUM_SPACING_RATIO = value;
    273                 }
    274         }
    275        
    276         public static void setMailSettings(Text t) {
    277                 if(t.getChild() != null) MailSession.init(t.getChild());
    278         }
    279        
    280         public static void setCursorFrame(Text t) {
    281                 if (t.getChild() != null) {
    282                         FreeItems.getCursor().addAll(ItemUtils.CopyItems(t.getChild().getAllItems()));
     309        };
     310        public static final FrameSetting Spelling = new FrameSetting("Enables the dictionary and adds the items in the child frame to the dictionary") {
     311                @Override
     312                public void run(Frame frame) {
     313                try {
     314                JSpellChecker.create(frame);
     315                } catch (Exception e) {
     316                        e.printStackTrace();
     317                        }
     318                }
     319        };
     320       
     321        public static final FrameSetting GreenstoneSettings = new FrameSetting("Greenstone settings (TODO: What are these for?)") {
     322                @Override
     323                public void run(Frame frame) {
     324                        SearchGreenstone.init(frame);
     325                }
     326        };
     327       
     328        public static final FrameSetting Reminders = new FrameSetting("Reminders (TODO: What are these for?)") {
     329                @Override
     330                public void run(Frame frame) {
     331                        org.expeditee.gui.Reminders.init(frame);
     332                }
     333        };
     334       
     335        public static final FrameSetting MailSettings = new FrameSetting("Mail Settings (TODO: How does this work?)") {
     336                @Override
     337                public void run(Frame frame) {
     338                        MailSession.init(frame);
     339                }
     340        };
     341       
     342        public static final FrameSetting CursorFrame = new FrameSetting("Items on this frame will be used as the cursor (clearing the frame or removing the link will default back to a normal cursor)") {
     343                @Override
     344                public void run(Frame frame) {
     345                        FreeItems.getCursor().addAll(ItemUtils.CopyItems(frame.getAllItems()));
    283346                        for (Item i : FreeItems.getCursor()) {
    284347                                i.setParent(null);
     
    287350                        DisplayIO.setCursor(Item.DEFAULT_CURSOR);
    288351                }
    289         }
     352        };
    290353       
    291354       
     
    299362        }
    300363         
    301                 UserSettings.FrameDirs.add(FrameIO.FRAME_PATH);
    302                 UserSettings.FrameDirs.add(FrameIO.PUBLIC_PATH);
    303                 UserSettings.FrameDirs.add(FrameIO.PROFILE_PATH);
    304                 UserSettings.FrameDirs.add(FrameIO.HELP_PATH);
    305                 UserSettings.ImageDirs.add(FrameIO.IMAGES_PATH);
    306                 UserSettings.FrameDirs.add(FrameIO.MESSAGES_PATH);
     364                UserSettings.FrameDirs.get().add(FrameIO.FRAME_PATH);
     365                UserSettings.FrameDirs.get().add(FrameIO.PUBLIC_PATH);
     366                UserSettings.FrameDirs.get().add(FrameIO.PROFILE_PATH);
     367                UserSettings.FrameDirs.get().add(FrameIO.HELP_PATH);
     368                UserSettings.ImageDirs.get().add(FrameIO.IMAGES_PATH);
     369                UserSettings.FrameDirs.get().add(FrameIO.MESSAGES_PATH);
    307370        }
    308371
  • trunk/src/org/expeditee/settings/experimental/ExperimentalFeatures.java

    r632 r655  
    11package org.expeditee.settings.experimental;
     2
     3import org.expeditee.setting.GenericSetting;
    24
    35public class ExperimentalFeatures {
    46
    5         public static final boolean defaultAutoWrap = false;
    6         public static boolean AutoWrap = defaultAutoWrap;
     7        public static final GenericSetting<Boolean> AutoWrap = new GenericSetting<Boolean>(Boolean.class, "Enable auto wrapping of text", false);
    78       
    8         public static final boolean defaultMousePan = false;
    9         public static boolean MousePan = defaultMousePan;
     9        public static final GenericSetting<Boolean> MousePan = new GenericSetting<Boolean>(Boolean.class, "Enable panning of the frame by shift-click and dragging the mouse", false);
    1010       
    1111}
  • trunk/src/org/expeditee/settings/network/NetworkSettings.java

    r629 r655  
    11package org.expeditee.settings.network;
    22
     3
     4import org.expeditee.gui.Frame;
    35import org.expeditee.items.Text;
    46import org.expeditee.network.FrameShare;
     7import org.expeditee.setting.FrameSetting;
     8import org.expeditee.setting.GenericSetting;
    59
    610public abstract class NetworkSettings {
    711       
    812        // The URL to prepend to web searches
    9         public static final String defaultSearchEngine = "https://duckduckgo.com/?q=";
    10         public static String searchEngine = defaultSearchEngine;
     13        public static final GenericSetting<String> SearchEngine = new GenericSetting<String>(String.class, "The search engine for the JfxBrowser", "https://duckduckgo.com/?q=");
    1114       
    12         public static final String defaultHomePage = "https://duckduckgo.com";
    13         public static String homePage = defaultHomePage;
     15        public static final GenericSetting<String> HomePage = new GenericSetting<String>(String.class, "The home page for the JfxBrowser", "https://duckduckgo.com");
    1416       
    15        
    16         public static void setFrameShare(Text t) {
    17                 FrameShare.init(t.getChild());
    18         }
     17        public static final FrameSetting FrameShare = new FrameSetting("Enable accessing remote frames") {
     18                @Override
     19                public void run(Frame frame) {
     20                        org.expeditee.network.FrameShare.init(frame);
     21                }
     22        };
    1923       
    2024        public static void onParsed(Text text) {
  • trunk/src/org/expeditee/settings/network/proxy/ProxySettings.java

    r652 r655  
    11package org.expeditee.settings.network.proxy;
    2 
    3 import java.awt.Color;
    42
    53import org.expeditee.gui.Browser;
     
    119import org.expeditee.items.widgets.WidgetCorner;
    1210import org.expeditee.items.widgets.WidgetEdge;
     11import org.expeditee.setting.GenericSetting;
    1312
    1413public abstract class ProxySettings {
    1514
    16         public static String host = null;
    17         public static String port = null;
    18         public static String user = null;
    19         public static String pass = null;
     15        public static final GenericSetting<String> Host = new GenericSetting<String>(String.class, "The host for the proxy", null);
     16        public static final GenericSetting<String> Port = new GenericSetting<String>(String.class, "The port for the proxy (e.g. port 80)", "80");
     17        public static final GenericSetting<String> User = new GenericSetting<String>(String.class, "Your username for the proxy", null);
     18        public static final GenericSetting<String> Pass = new GenericSetting<String>(String.class, "Your password for the proxy", null);
    2019
    2120        public static void onParsed(Text text) {
     
    3534                                                        try {
    3635                                                                passwordWidget = (Password) InteractiveWidget.createWidget((Text) i);
    37                                                                 if (pass != null) {
     36                                                                if (Pass.get() != null) {
    3837                                                                        // MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
    3938                                                                }
    40                                                                 pass = passwordWidget.getPassword();
     39                                                                Pass.set(passwordWidget.getPassword());
    4140                                                        } catch (Exception e) {
    4241                                                                e.printStackTrace();
     
    5655                                                passwordWidget = (Password) iw;
    5756                                        }
    58                                         if(pass != null) {
     57                                        if(Pass.get() != null) {
    5958                                                // MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
    6059                                        }
    61                                         pass = passwordWidget.getPassword();
     60                                        Pass.set(passwordWidget.getPassword());
    6261                                }
    6362                        }
    6463                }
    6564               
    66                 if(host == null) {
     65                if(Host.get() == null) {
    6766                        MessageBay.warningMessage("proxy host was not defined");
    6867                        return;
    6968                }
    70                 if(port == null) {
     69                if(Port.get() == null) {
    7170                        MessageBay.warningMessage("proxy port was not defined (defaulted to 80)");
    72                         port = "80";
     71                        Port.set("80");
    7372                }
    74                 if(user == null) {
     73                if(User.get() == null) {
    7574                        MessageBay.warningMessage("proxy user was not defined");
    7675                        return;
    7776                }
    78                 if(pass == null) {
     77                if(Pass.get() == null) {
    7978                        MessageBay.warningMessage("proxy pass was not defined");
    8079                        return;
    8180                }
    8281                // TODO: Is it possible to have different host/port for http/https protocols for a proxy server?
    83                 System.setProperty("http.proxyHost", host);
    84                 System.setProperty("http.proxyPort", port);
    85                 System.setProperty("https.proxyHost", host);
    86                 System.setProperty("https.proxyPort", port);
    87                 Browser.proxyAuth.setup(user, pass);
     82                System.setProperty("http.proxyHost", Host.get());
     83                System.setProperty("http.proxyPort", Port.get());
     84                System.setProperty("https.proxyHost", Host.get());
     85                System.setProperty("https.proxyPort", Port.get());
     86                Browser.proxyAuth.setup(User.get(), Pass.get());
    8887               
    8988                // System.out.println("proxy parsed");
  • trunk/src/org/expeditee/stats/DocumentStatsFast.java

    r570 r655  
    5757
    5858                String fullPath = null;
    59                 for (String possiblePath : UserSettings.FrameDirs) {
     59                for (String possiblePath : UserSettings.FrameDirs.get()) {
    6060                        fullPath = FrameIO.getFrameFullPathName(possiblePath, _name);
    6161                        if (fullPath != null)
  • trunk/src/org/expeditee/stats/Logger.java

    r570 r655  
    7878         */
    7979        public static void Init() {
    80                 if (!org.expeditee.settings.UserSettings.Logging)
     80                if (!org.expeditee.settings.UserSettings.Logging.get())
    8181                        return;
    8282
     
    148148
    149149        private static void WriteToFile(String toWrite) {
    150                 if (!org.expeditee.settings.UserSettings.Logging)
     150                if (!org.expeditee.settings.UserSettings.Logging.get())
    151151                        return;
    152152
  • trunk/src/org/expeditee/stats/StatsLogger.java

    r570 r655  
    3535         */
    3636        private static void Init() {
    37                 if (!org.expeditee.settings.UserSettings.LogStats)
     37                if (!org.expeditee.settings.UserSettings.LogStats.get())
    3838                        return;
    3939
     
    5050         */
    5151        public static void WriteStatsFile() {
    52                 if (!org.expeditee.settings.UserSettings.LogStats)
     52                if (!org.expeditee.settings.UserSettings.LogStats.get())
    5353                        return;
    5454
    5555                Init();
    5656
    57                 String statsFrameset = UserSettings.StatisticsFrameset;
     57                String statsFrameset = UserSettings.StatisticsFrameset.get();
    5858                if (statsFrameset != null) {
    5959                        try {
Note: See TracChangeset for help on using the changeset viewer.